Release 970824
[wine/multimedia.git] / controls / static.c
blobecd4a02f89c5027d960a062ea743c16b73ec44ca
1 /*
2 * Static control
4 * Copyright David W. Metcalfe, 1993
6 */
8 #include <stdio.h>
9 #include "windows.h"
10 #include "win.h"
11 #include "static.h"
12 #include "heap.h"
14 static void STATIC_PaintTextfn( WND *wndPtr, HDC32 hdc );
15 static void STATIC_PaintRectfn( WND *wndPtr, HDC32 hdc );
16 static void STATIC_PaintIconfn( WND *wndPtr, HDC32 hdc );
19 static COLORREF color_windowframe, color_background, color_window;
22 typedef void (*pfPaint)( WND *, HDC32 );
24 #define LAST_STATIC_TYPE SS_LEFTNOWORDWRAP
26 static pfPaint staticPaintFunc[LAST_STATIC_TYPE+1] =
28 STATIC_PaintTextfn, /* SS_LEFT */
29 STATIC_PaintTextfn, /* SS_CENTER */
30 STATIC_PaintTextfn, /* SS_RIGHT */
31 STATIC_PaintIconfn, /* SS_ICON */
32 STATIC_PaintRectfn, /* SS_BLACKRECT */
33 STATIC_PaintRectfn, /* SS_GRAYRECT */
34 STATIC_PaintRectfn, /* SS_WHITERECT */
35 STATIC_PaintRectfn, /* SS_BLACKFRAME */
36 STATIC_PaintRectfn, /* SS_GRAYFRAME */
37 STATIC_PaintRectfn, /* SS_WHITEFRAME */
38 NULL, /* Not defined */
39 STATIC_PaintTextfn, /* SS_SIMPLE */
40 STATIC_PaintTextfn /* SS_LEFTNOWORDWRAP */
44 /***********************************************************************
45 * STATIC_SetIcon
47 * Set the icon for an SS_ICON control.
49 static HICON16 STATIC_SetIcon( WND *wndPtr, HICON16 hicon )
51 HICON16 prevIcon;
52 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
53 CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16( hicon ):NULL;
55 if ((wndPtr->dwStyle & 0x0f) != SS_ICON) return 0;
56 if (hicon && !info) {
57 fprintf(stderr,"STATIC_SetIcon: huh? hicon!=0, but info=0???\n");
58 return 0;
60 prevIcon = infoPtr->hIcon;
61 infoPtr->hIcon = hicon;
62 if (hicon)
64 SetWindowPos32( wndPtr->hwndSelf, 0, 0, 0, info->nWidth, info->nHeight,
65 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
66 GlobalUnlock16( hicon );
68 return prevIcon;
72 /***********************************************************************
73 * STATIC_LoadIcon
75 * Load the icon for an SS_ICON control.
77 static HICON16 STATIC_LoadIcon( WND *wndPtr, LPCSTR name )
79 HICON16 hicon;
81 if (wndPtr->flags & WIN_ISWIN32)
83 hicon = LoadIcon32A( wndPtr->hInstance, name );
84 if (!hicon) /* Try OEM icon (FIXME: is this right?) */
85 hicon = LoadIcon32A( 0, name );
87 else
89 LPSTR segname = SEGPTR_STRDUP(name);
90 hicon = LoadIcon16( wndPtr->hInstance, SEGPTR_GET(segname) );
91 if (!hicon) /* Try OEM icon (FIXME: is this right?) */
92 hicon = LoadIcon32A( 0, segname );
93 SEGPTR_FREE(segname);
95 return hicon;
99 /***********************************************************************
100 * StaticWndProc
102 LRESULT WINAPI StaticWndProc( HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam,
103 LPARAM lParam )
105 LRESULT lResult = 0;
106 WND *wndPtr = WIN_FindWndPtr(hWnd);
107 LONG style = wndPtr->dwStyle & 0x0000000F;
108 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
110 switch (uMsg)
112 case WM_NCCREATE:
113 if (style == SS_ICON)
115 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)lParam;
116 if (cs->lpszName)
117 STATIC_SetIcon( wndPtr,
118 STATIC_LoadIcon( wndPtr, cs->lpszName ));
119 return 1;
121 return DefWindowProc32A( hWnd, uMsg, wParam, lParam );
123 case WM_CREATE:
124 if (style < 0L || style > LAST_STATIC_TYPE)
126 fprintf( stderr, "STATIC: Unknown style 0x%02lx\n", style );
127 lResult = -1L;
128 break;
130 /* initialise colours */
131 color_windowframe = GetSysColor32(COLOR_WINDOWFRAME);
132 color_background = GetSysColor32(COLOR_BACKGROUND);
133 color_window = GetSysColor32(COLOR_WINDOW);
134 break;
136 case WM_NCDESTROY:
137 if (style == SS_ICON)
138 DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
139 else
140 lResult = DefWindowProc32A( hWnd, uMsg, wParam, lParam );
141 break;
143 case WM_PAINT:
145 PAINTSTRUCT32 ps;
146 BeginPaint32( hWnd, &ps );
147 if (staticPaintFunc[style])
148 (staticPaintFunc[style])( wndPtr, ps.hdc );
149 EndPaint32( hWnd, &ps );
151 break;
153 case WM_ENABLE:
154 InvalidateRect32( hWnd, NULL, FALSE );
155 break;
157 case WM_SYSCOLORCHANGE:
158 color_windowframe = GetSysColor32(COLOR_WINDOWFRAME);
159 color_background = GetSysColor32(COLOR_BACKGROUND);
160 color_window = GetSysColor32(COLOR_WINDOW);
161 InvalidateRect32( hWnd, NULL, TRUE );
162 break;
164 case WM_SETTEXT:
165 if (style == SS_ICON)
166 /* FIXME : should we also return the previous hIcon here ??? */
167 STATIC_SetIcon( wndPtr, STATIC_LoadIcon( wndPtr, (LPCSTR)lParam ));
168 else
169 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
170 InvalidateRect32( hWnd, NULL, FALSE );
171 UpdateWindow32( hWnd );
172 break;
174 case WM_SETFONT:
175 if (style == SS_ICON) return 0;
176 infoPtr->hFont = (HFONT16)wParam;
177 if (LOWORD(lParam))
179 InvalidateRect32( hWnd, NULL, FALSE );
180 UpdateWindow32( hWnd );
182 break;
184 case WM_GETFONT:
185 return infoPtr->hFont;
187 case WM_NCHITTEST:
188 return HTTRANSPARENT;
190 case WM_GETDLGCODE:
191 return DLGC_STATIC;
193 case STM_GETICON:
194 return infoPtr->hIcon;
196 case STM_SETICON:
197 lResult = STATIC_SetIcon( wndPtr, (HICON16)wParam );
198 InvalidateRect32( hWnd, NULL, FALSE );
199 UpdateWindow32( hWnd );
200 break;
202 default:
203 lResult = DefWindowProc32A(hWnd, uMsg, wParam, lParam);
204 break;
207 return lResult;
211 static void STATIC_PaintTextfn( WND *wndPtr, HDC32 hdc )
213 RECT32 rc;
214 HBRUSH32 hBrush;
215 WORD wFormat;
217 LONG style = wndPtr->dwStyle;
218 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
220 GetClientRect32( wndPtr->hwndSelf, &rc);
222 switch (style & 0x0000000F)
224 case SS_LEFT:
225 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
226 break;
228 case SS_CENTER:
229 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
230 break;
232 case SS_RIGHT:
233 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
234 break;
236 case SS_SIMPLE:
237 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
238 break;
240 case SS_LEFTNOWORDWRAP:
241 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER | DT_NOCLIP;
242 break;
244 default:
245 return;
248 if (style & SS_NOPREFIX)
249 wFormat |= DT_NOPREFIX;
251 if (infoPtr->hFont) SelectObject32( hdc, infoPtr->hFont );
252 hBrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
253 hdc, wndPtr->hwndSelf );
254 if (!hBrush) hBrush = GetStockObject32(WHITE_BRUSH);
255 FillRect32( hdc, &rc, hBrush );
256 if (wndPtr->text) DrawText32A( hdc, wndPtr->text, -1, &rc, wFormat );
259 static void STATIC_PaintRectfn( WND *wndPtr, HDC32 hdc )
261 RECT32 rc;
262 HBRUSH32 hBrush;
264 GetClientRect32( wndPtr->hwndSelf, &rc);
266 switch (wndPtr->dwStyle & 0x0f)
268 case SS_BLACKRECT:
269 hBrush = CreateSolidBrush32(color_windowframe);
270 FillRect32( hdc, &rc, hBrush );
271 break;
272 case SS_GRAYRECT:
273 hBrush = CreateSolidBrush32(color_background);
274 FillRect32( hdc, &rc, hBrush );
275 break;
276 case SS_WHITERECT:
277 hBrush = CreateSolidBrush32(color_window);
278 FillRect32( hdc, &rc, hBrush );
279 break;
280 case SS_BLACKFRAME:
281 hBrush = CreateSolidBrush32(color_windowframe);
282 FrameRect32( hdc, &rc, hBrush );
283 break;
284 case SS_GRAYFRAME:
285 hBrush = CreateSolidBrush32(color_background);
286 FrameRect32( hdc, &rc, hBrush );
287 break;
288 case SS_WHITEFRAME:
289 hBrush = CreateSolidBrush32(color_window);
290 FrameRect32( hdc, &rc, hBrush );
291 break;
292 default:
293 return;
295 DeleteObject32( hBrush );
299 static void STATIC_PaintIconfn( WND *wndPtr, HDC32 hdc )
301 RECT32 rc;
302 HBRUSH32 hbrush;
303 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
305 GetClientRect32( wndPtr->hwndSelf, &rc );
306 hbrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
307 hdc, wndPtr->hwndSelf );
308 FillRect32( hdc, &rc, hbrush );
309 if (infoPtr->hIcon) DrawIcon32( hdc, rc.left, rc.top, infoPtr->hIcon );