Release 980628
[wine/multimedia.git] / controls / static.c
blob255f01f974447978d052986eaf91789feb461899
1 /*
2 * Static control
4 * Copyright David W. Metcalfe, 1993
6 */
8 #include "windows.h"
9 #include "win.h"
10 #include "bitmap.h"
11 #include "cursoricon.h"
12 #include "static.h"
13 #include "heap.h"
14 #include "debug.h"
15 #include "tweak.h"
17 static void STATIC_PaintTextfn( WND *wndPtr, HDC32 hdc );
18 static void STATIC_PaintRectfn( WND *wndPtr, HDC32 hdc );
19 static void STATIC_PaintIconfn( WND *wndPtr, HDC32 hdc );
20 static void STATIC_PaintBitmapfn( WND *wndPtr, HDC32 hdc );
21 static void STATIC_PaintEtchedfn( WND *wndPtr, HDC32 hdc );
23 static COLORREF color_windowframe, color_background, color_window;
26 typedef void (*pfPaint)( WND *, HDC32 );
28 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
30 STATIC_PaintTextfn, /* SS_LEFT */
31 STATIC_PaintTextfn, /* SS_CENTER */
32 STATIC_PaintTextfn, /* SS_RIGHT */
33 STATIC_PaintIconfn, /* SS_ICON */
34 STATIC_PaintRectfn, /* SS_BLACKRECT */
35 STATIC_PaintRectfn, /* SS_GRAYRECT */
36 STATIC_PaintRectfn, /* SS_WHITERECT */
37 STATIC_PaintRectfn, /* SS_BLACKFRAME */
38 STATIC_PaintRectfn, /* SS_GRAYFRAME */
39 STATIC_PaintRectfn, /* SS_WHITEFRAME */
40 NULL, /* Not defined */
41 STATIC_PaintTextfn, /* SS_SIMPLE */
42 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
43 NULL, /* SS_OWNERDRAW */
44 STATIC_PaintBitmapfn, /* SS_BITMAP */
45 NULL, /* SS_ENHMETAFILE */
46 STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
47 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
48 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
52 /***********************************************************************
53 * STATIC_SetIcon
55 * Set the icon for an SS_ICON control.
57 static HICON16 STATIC_SetIcon( WND *wndPtr, HICON16 hicon )
59 HICON16 prevIcon;
60 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
61 CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16( hicon ):NULL;
63 if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_ICON) return 0;
64 if (hicon && !info) {
65 ERR(static, "huh? hicon!=0, but info=0???\n");
66 return 0;
68 prevIcon = infoPtr->hIcon;
69 infoPtr->hIcon = hicon;
70 if (hicon)
72 SetWindowPos32( wndPtr->hwndSelf, 0, 0, 0, info->nWidth, info->nHeight,
73 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
74 GlobalUnlock16( hicon );
76 return prevIcon;
79 /***********************************************************************
80 * STATIC_SetBitmap
82 * Set the bitmap for an SS_BITMAP control.
84 static HICON16 STATIC_SetBitmap( WND *wndPtr, HICON16 hicon )
86 HICON16 prevIcon;
87 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
88 BITMAPOBJ *info = (BITMAPOBJ *)GDI_HEAP_LOCK(hicon);
90 if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0;
91 if (hicon && !info) {
92 ERR(static, "huh? hicon!=0, but info=0???\n");
93 return 0;
95 prevIcon = infoPtr->hIcon;
96 infoPtr->hIcon = hicon;
97 if (hicon)
99 SetWindowPos32( wndPtr->hwndSelf, 0, 0, 0, info->bitmap.bmWidth, info->bitmap.bmHeight,
100 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
102 GDI_HEAP_UNLOCK( hicon );
103 return prevIcon;
107 /***********************************************************************
108 * STATIC_LoadIcon
110 * Load the icon for an SS_ICON control.
112 static HICON16 STATIC_LoadIcon( WND *wndPtr, LPCSTR name )
114 HICON16 hicon;
116 if (wndPtr->flags & WIN_ISWIN32)
118 hicon = LoadIcon32A( wndPtr->hInstance, name );
119 if (!hicon) /* Try OEM icon (FIXME: is this right?) */
120 hicon = LoadIcon32A( 0, name );
122 else
124 LPSTR segname = SEGPTR_STRDUP(name);
125 hicon = LoadIcon16( wndPtr->hInstance, SEGPTR_GET(segname) );
126 if (!hicon) /* Try OEM icon (FIXME: is this right?) */
127 hicon = LoadIcon32A( 0, segname );
128 SEGPTR_FREE(segname);
130 return hicon;
133 /***********************************************************************
134 * STATIC_LoadBitmap
136 * Load the bitmap for an SS_BITMAP control.
138 static HBITMAP16 STATIC_LoadBitmap( WND *wndPtr, LPCSTR name )
140 HBITMAP16 hbitmap;
142 if (wndPtr->flags & WIN_ISWIN32)
144 hbitmap = LoadBitmap32A( wndPtr->hInstance, name );
145 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
146 hbitmap = LoadBitmap32A( 0, name );
148 else
150 LPSTR segname = SEGPTR_STRDUP(name);
151 hbitmap = LoadBitmap16( wndPtr->hInstance, SEGPTR_GET(segname) );
152 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
153 hbitmap = LoadBitmap32A( 0, segname );
154 SEGPTR_FREE(segname);
156 return hbitmap;
160 /***********************************************************************
161 * StaticWndProc
163 LRESULT WINAPI StaticWndProc( HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam,
164 LPARAM lParam )
166 LRESULT lResult = 0;
167 WND *wndPtr = WIN_FindWndPtr(hWnd);
168 LONG style = wndPtr->dwStyle & SS_TYPEMASK;
169 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
171 switch (uMsg)
173 case WM_NCCREATE:
174 if (TWEAK_Win95Look && (wndPtr->dwStyle & SS_SUNKEN))
175 wndPtr->dwExStyle |= WS_EX_STATICEDGE;
177 if (style == SS_ICON)
179 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)lParam;
180 if (cs->lpszName)
181 STATIC_SetIcon( wndPtr,
182 STATIC_LoadIcon( wndPtr, cs->lpszName ));
183 return 1;
185 if (style == SS_BITMAP)
187 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)lParam;
188 if (cs->lpszName)
189 STATIC_SetBitmap( wndPtr,
190 STATIC_LoadBitmap( wndPtr, cs->lpszName ));
191 WARN(static, "style SS_BITMAP, dwStyle is 0x%08lx\n",
192 wndPtr->dwStyle);
193 return 1;
195 return DefWindowProc32A( hWnd, uMsg, wParam, lParam );
197 case WM_CREATE:
198 if (style < 0L || style > SS_TYPEMASK)
200 ERR(static, "Unknown style 0x%02lx\n", style );
201 lResult = -1L;
202 break;
204 /* initialise colours */
205 color_windowframe = GetSysColor32(COLOR_WINDOWFRAME);
206 color_background = GetSysColor32(COLOR_BACKGROUND);
207 color_window = GetSysColor32(COLOR_WINDOW);
208 break;
210 case WM_NCDESTROY:
211 if (style == SS_ICON)
212 DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
213 else
214 lResult = DefWindowProc32A( hWnd, uMsg, wParam, lParam );
215 break;
217 case WM_PAINT:
219 PAINTSTRUCT32 ps;
220 BeginPaint32( hWnd, &ps );
221 if (staticPaintFunc[style])
222 (staticPaintFunc[style])( wndPtr, ps.hdc );
223 EndPaint32( hWnd, &ps );
225 break;
227 case WM_ENABLE:
228 InvalidateRect32( hWnd, NULL, FALSE );
229 break;
231 case WM_SYSCOLORCHANGE:
232 color_windowframe = GetSysColor32(COLOR_WINDOWFRAME);
233 color_background = GetSysColor32(COLOR_BACKGROUND);
234 color_window = GetSysColor32(COLOR_WINDOW);
235 InvalidateRect32( hWnd, NULL, TRUE );
236 break;
238 case WM_SETTEXT:
239 if (style == SS_ICON)
240 /* FIXME : should we also return the previous hIcon here ??? */
241 STATIC_SetIcon( wndPtr, STATIC_LoadIcon( wndPtr, (LPCSTR)lParam ));
242 else if (style == SS_BITMAP)
243 STATIC_SetBitmap(wndPtr,STATIC_LoadBitmap(wndPtr,(LPCSTR)lParam ));
244 else
245 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
246 InvalidateRect32( hWnd, NULL, FALSE );
247 UpdateWindow32( hWnd );
248 break;
250 case WM_SETFONT:
251 if (style == SS_ICON) return 0;
252 if (style == SS_BITMAP) return 0;
253 infoPtr->hFont = (HFONT16)wParam;
254 if (LOWORD(lParam))
256 InvalidateRect32( hWnd, NULL, FALSE );
257 UpdateWindow32( hWnd );
259 break;
261 case WM_GETFONT:
262 return infoPtr->hFont;
264 case WM_NCHITTEST:
265 return HTTRANSPARENT;
267 case WM_GETDLGCODE:
268 return DLGC_STATIC;
270 return infoPtr->hIcon;
271 case STM_GETIMAGE:
272 case STM_GETICON16:
273 case STM_GETICON32:
274 return infoPtr->hIcon;
276 case STM_SETIMAGE:
277 /* FIXME: handle wParam */
278 lResult = STATIC_SetBitmap( wndPtr, (HBITMAP32)lParam );
279 InvalidateRect32( hWnd, NULL, FALSE );
280 UpdateWindow32( hWnd );
281 break;
282 case STM_SETICON16:
283 case STM_SETICON32:
284 lResult = STATIC_SetIcon( wndPtr, (HICON16)wParam );
285 InvalidateRect32( hWnd, NULL, FALSE );
286 UpdateWindow32( hWnd );
287 break;
289 default:
290 lResult = DefWindowProc32A(hWnd, uMsg, wParam, lParam);
291 break;
294 return lResult;
298 static void STATIC_PaintTextfn( WND *wndPtr, HDC32 hdc )
300 RECT32 rc;
301 HBRUSH32 hBrush;
302 WORD wFormat;
304 LONG style = wndPtr->dwStyle;
305 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
307 GetClientRect32( wndPtr->hwndSelf, &rc);
309 switch (style & SS_TYPEMASK)
311 case SS_LEFT:
312 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
313 break;
315 case SS_CENTER:
316 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
317 break;
319 case SS_RIGHT:
320 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
321 break;
323 case SS_SIMPLE:
324 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
325 break;
327 case SS_LEFTNOWORDWRAP:
328 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER | DT_NOCLIP;
329 break;
331 default:
332 return;
335 if (style & SS_NOPREFIX)
336 wFormat |= DT_NOPREFIX;
338 if (infoPtr->hFont) SelectObject32( hdc, infoPtr->hFont );
339 hBrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
340 hdc, wndPtr->hwndSelf );
341 if (!hBrush) hBrush = GetStockObject32(WHITE_BRUSH);
342 FillRect32( hdc, &rc, hBrush );
343 if (wndPtr->text) DrawText32A( hdc, wndPtr->text, -1, &rc, wFormat );
346 static void STATIC_PaintRectfn( WND *wndPtr, HDC32 hdc )
348 RECT32 rc;
349 HBRUSH32 hBrush;
351 GetClientRect32( wndPtr->hwndSelf, &rc);
353 switch (wndPtr->dwStyle & SS_TYPEMASK)
355 case SS_BLACKRECT:
356 hBrush = CreateSolidBrush32(color_windowframe);
357 FillRect32( hdc, &rc, hBrush );
358 break;
359 case SS_GRAYRECT:
360 hBrush = CreateSolidBrush32(color_background);
361 FillRect32( hdc, &rc, hBrush );
362 break;
363 case SS_WHITERECT:
364 hBrush = CreateSolidBrush32(color_window);
365 FillRect32( hdc, &rc, hBrush );
366 break;
367 case SS_BLACKFRAME:
368 hBrush = CreateSolidBrush32(color_windowframe);
369 FrameRect32( hdc, &rc, hBrush );
370 break;
371 case SS_GRAYFRAME:
372 hBrush = CreateSolidBrush32(color_background);
373 FrameRect32( hdc, &rc, hBrush );
374 break;
375 case SS_WHITEFRAME:
376 hBrush = CreateSolidBrush32(color_window);
377 FrameRect32( hdc, &rc, hBrush );
378 break;
379 default:
380 return;
382 DeleteObject32( hBrush );
386 static void STATIC_PaintIconfn( WND *wndPtr, HDC32 hdc )
388 RECT32 rc;
389 HBRUSH32 hbrush;
390 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
392 GetClientRect32( wndPtr->hwndSelf, &rc );
393 hbrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
394 hdc, wndPtr->hwndSelf );
395 FillRect32( hdc, &rc, hbrush );
396 if (infoPtr->hIcon) DrawIcon32( hdc, rc.left, rc.top, infoPtr->hIcon );
399 static void STATIC_PaintBitmapfn(WND *wndPtr, HDC32 hdc )
401 RECT32 rc;
402 HBRUSH32 hbrush;
403 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
404 HDC32 hMemDC;
405 HBITMAP32 oldbitmap;
407 GetClientRect32( wndPtr->hwndSelf, &rc );
408 hbrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
409 hdc, wndPtr->hwndSelf );
410 FillRect32( hdc, &rc, hbrush );
411 if (infoPtr->hIcon) {
412 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_HEAP_LOCK( infoPtr->hIcon );
414 if (!bmp) return;
415 if (!(hMemDC = CreateCompatibleDC32( hdc ))) return;
417 oldbitmap = SelectObject32(hMemDC,infoPtr->hIcon);
418 BitBlt32(hdc,bmp->size.cx,bmp->size.cy,bmp->bitmap.bmWidth,bmp->bitmap.bmHeight,hMemDC,0,0,SRCCOPY);
419 DeleteDC32(hMemDC);
420 GDI_HEAP_UNLOCK(infoPtr->hIcon);
425 static void STATIC_PaintEtchedfn( WND *wndPtr, HDC32 hdc )
427 RECT32 rc;
428 HBRUSH32 hbrush;
429 HPEN32 hpen;
431 if (!TWEAK_Win95Look) return;
433 GetClientRect32( wndPtr->hwndSelf, &rc );
434 hbrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
435 hdc, wndPtr->hwndSelf );
436 FillRect32( hdc, &rc, hbrush );
438 switch (wndPtr->dwStyle & SS_TYPEMASK)
440 case SS_ETCHEDHORZ:
441 hpen = SelectObject32 (hdc, GetSysColorPen32 (COLOR_3DSHADOW));
442 MoveToEx32 (hdc, rc.left, rc.bottom / 2 - 1, NULL);
443 LineTo32 (hdc, rc.right - 1, rc.bottom / 2 - 1);
444 SelectObject32 (hdc, GetSysColorPen32 (COLOR_3DHIGHLIGHT));
445 MoveToEx32 (hdc, rc.left, rc.bottom / 2, NULL);
446 LineTo32 (hdc, rc.right, rc.bottom / 2);
447 LineTo32 (hdc, rc.right, rc.bottom / 2 - 1);
448 SelectObject32 (hdc, hpen);
449 break;
451 case SS_ETCHEDVERT:
452 hpen = SelectObject32 (hdc, GetSysColorPen32 (COLOR_3DSHADOW));
453 MoveToEx32 (hdc, rc.right / 2 - 1, rc.top, NULL);
454 LineTo32 (hdc, rc.right / 2 - 1, rc.bottom - 1);
455 SelectObject32 (hdc, GetSysColorPen32 (COLOR_3DHIGHLIGHT));
456 MoveToEx32 (hdc, rc.right / 2, rc.top, NULL);
457 LineTo32 (hdc, rc.right / 2, rc.bottom);
458 LineTo32 (hdc, rc.right / 2 -1 , rc.bottom);
459 SelectObject32 (hdc, hpen);
460 break;
462 case SS_ETCHEDFRAME:
463 DrawEdge32 (hdc, &rc, EDGE_ETCHED, BF_RECT);
464 break;