We don't yet want the static control to call DestroyIcon.
[wine/testsucceed.git] / controls / static.c
blob817120238f0bd9a69cfbc0d71fcd8064d9d7d36d
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 if (!HIWORD(wndPtr->hInstance)) {
119 LPSTR segname = SEGPTR_STRDUP(name);
120 hicon = LoadIcon16( wndPtr->hInstance, SEGPTR_GET(segname) );
121 SEGPTR_FREE(segname);
122 } else
123 hicon = LoadIcon32A( wndPtr->hInstance, name );
124 } else {
125 LPSTR segname = SEGPTR_STRDUP(name);
127 if (HIWORD(wndPtr->hInstance))
128 FIXME(static,"win16 window class, but win32 hinstance??\n");
129 hicon = LoadIcon16( wndPtr->hInstance, SEGPTR_GET(segname) );
130 SEGPTR_FREE(segname);
132 if (!hicon)
133 hicon = LoadIcon32A( 0, name );
134 return hicon;
137 /***********************************************************************
138 * STATIC_LoadBitmap
140 * Load the bitmap for an SS_BITMAP control.
142 static HBITMAP16 STATIC_LoadBitmap( WND *wndPtr, LPCSTR name )
144 HBITMAP16 hbitmap;
146 if (wndPtr->flags & WIN_ISWIN32)
148 hbitmap = LoadBitmap32A( wndPtr->hInstance, name );
149 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
150 hbitmap = LoadBitmap32A( 0, name );
152 else
154 LPSTR segname = SEGPTR_STRDUP(name);
155 hbitmap = LoadBitmap16( wndPtr->hInstance, SEGPTR_GET(segname) );
156 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
157 hbitmap = LoadBitmap32A( 0, segname );
158 SEGPTR_FREE(segname);
160 return hbitmap;
164 /***********************************************************************
165 * StaticWndProc
167 LRESULT WINAPI StaticWndProc( HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam,
168 LPARAM lParam )
170 LRESULT lResult = 0;
171 WND *wndPtr = WIN_FindWndPtr(hWnd);
172 LONG style = wndPtr->dwStyle & SS_TYPEMASK;
173 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
175 switch (uMsg)
177 case WM_NCCREATE: {
178 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)lParam;
180 if ((TWEAK_WineLook > WIN31_LOOK) && (wndPtr->dwStyle & SS_SUNKEN))
181 wndPtr->dwExStyle |= WS_EX_STATICEDGE;
183 if (style == SS_ICON)
185 if (cs->lpszName)
186 STATIC_SetIcon( wndPtr,
187 STATIC_LoadIcon( wndPtr, cs->lpszName ));
188 return 1;
190 if (style == SS_BITMAP)
192 if (cs->lpszName)
193 STATIC_SetBitmap( wndPtr,
194 STATIC_LoadBitmap( wndPtr, cs->lpszName ));
195 WARN(static, "style SS_BITMAP, dwStyle is 0x%08lx\n",
196 wndPtr->dwStyle);
197 return 1;
199 if (!HIWORD(cs->lpszName) && (cs->lpszName)) {
200 FIXME(static,"windowName is 0x%04x, not doing DefWindowProc\n",
201 LOWORD(cs->lpszName)
203 return 1;
205 return DefWindowProc32A( hWnd, uMsg, wParam, lParam );
207 case WM_CREATE:
208 if (style < 0L || style > SS_TYPEMASK)
210 ERR(static, "Unknown style 0x%02lx\n", style );
211 lResult = -1L;
212 break;
214 /* initialise colours */
215 color_windowframe = GetSysColor32(COLOR_WINDOWFRAME);
216 color_background = GetSysColor32(COLOR_BACKGROUND);
217 color_window = GetSysColor32(COLOR_WINDOW);
218 break;
220 case WM_NCDESTROY:
221 if (style == SS_ICON) {
223 * FIXME
224 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
226 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
227 * had already been loaded by the application the last thing we want to do is
228 * GlobalFree16 the handle.
230 } else {
231 lResult = DefWindowProc32A( hWnd, uMsg, wParam, lParam );
233 break;
235 case WM_PAINT:
237 PAINTSTRUCT32 ps;
238 BeginPaint32( hWnd, &ps );
239 if (staticPaintFunc[style])
240 (staticPaintFunc[style])( wndPtr, ps.hdc );
241 EndPaint32( hWnd, &ps );
243 break;
245 case WM_ENABLE:
246 InvalidateRect32( hWnd, NULL, FALSE );
247 break;
249 case WM_SYSCOLORCHANGE:
250 color_windowframe = GetSysColor32(COLOR_WINDOWFRAME);
251 color_background = GetSysColor32(COLOR_BACKGROUND);
252 color_window = GetSysColor32(COLOR_WINDOW);
253 InvalidateRect32( hWnd, NULL, TRUE );
254 break;
256 case WM_SETTEXT:
257 if (style == SS_ICON)
258 /* FIXME : should we also return the previous hIcon here ??? */
259 STATIC_SetIcon( wndPtr, STATIC_LoadIcon( wndPtr, (LPCSTR)lParam ));
260 else if (style == SS_BITMAP)
261 STATIC_SetBitmap(wndPtr,STATIC_LoadBitmap(wndPtr,(LPCSTR)lParam ));
262 else
263 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
264 InvalidateRect32( hWnd, NULL, FALSE );
265 UpdateWindow32( hWnd );
266 break;
268 case WM_SETFONT:
269 if (style == SS_ICON) return 0;
270 if (style == SS_BITMAP) return 0;
271 infoPtr->hFont = (HFONT16)wParam;
272 if (LOWORD(lParam))
274 InvalidateRect32( hWnd, NULL, FALSE );
275 UpdateWindow32( hWnd );
277 break;
279 case WM_GETFONT:
280 return infoPtr->hFont;
282 case WM_NCHITTEST:
283 return HTTRANSPARENT;
285 case WM_GETDLGCODE:
286 return DLGC_STATIC;
288 case STM_GETIMAGE:
289 case STM_GETICON16:
290 case STM_GETICON32:
291 return infoPtr->hIcon;
293 case STM_SETIMAGE:
294 /* FIXME: handle wParam */
295 lResult = STATIC_SetBitmap( wndPtr, (HBITMAP32)lParam );
296 InvalidateRect32( hWnd, NULL, FALSE );
297 UpdateWindow32( hWnd );
298 break;
300 case STM_SETICON16:
301 case STM_SETICON32:
302 lResult = STATIC_SetIcon( wndPtr, (HICON16)wParam );
303 InvalidateRect32( hWnd, NULL, FALSE );
304 UpdateWindow32( hWnd );
305 break;
307 default:
308 lResult = DefWindowProc32A(hWnd, uMsg, wParam, lParam);
309 break;
312 return lResult;
316 static void STATIC_PaintTextfn( WND *wndPtr, HDC32 hdc )
318 RECT32 rc;
319 HBRUSH32 hBrush;
320 WORD wFormat;
322 LONG style = wndPtr->dwStyle;
323 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
325 GetClientRect32( wndPtr->hwndSelf, &rc);
327 switch (style & SS_TYPEMASK)
329 case SS_LEFT:
330 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
331 break;
333 case SS_CENTER:
334 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
335 break;
337 case SS_RIGHT:
338 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
339 break;
341 case SS_SIMPLE:
342 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
343 break;
345 case SS_LEFTNOWORDWRAP:
346 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER | DT_NOCLIP;
347 break;
349 default:
350 return;
353 if (style & SS_NOPREFIX)
354 wFormat |= DT_NOPREFIX;
356 if (infoPtr->hFont) SelectObject32( hdc, infoPtr->hFont );
357 hBrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
358 hdc, wndPtr->hwndSelf );
359 if (!hBrush) hBrush = GetStockObject32(WHITE_BRUSH);
360 FillRect32( hdc, &rc, hBrush );
361 if (wndPtr->text) DrawText32A( hdc, wndPtr->text, -1, &rc, wFormat );
364 static void STATIC_PaintRectfn( WND *wndPtr, HDC32 hdc )
366 RECT32 rc;
367 HBRUSH32 hBrush;
369 GetClientRect32( wndPtr->hwndSelf, &rc);
371 switch (wndPtr->dwStyle & SS_TYPEMASK)
373 case SS_BLACKRECT:
374 hBrush = CreateSolidBrush32(color_windowframe);
375 FillRect32( hdc, &rc, hBrush );
376 break;
377 case SS_GRAYRECT:
378 hBrush = CreateSolidBrush32(color_background);
379 FillRect32( hdc, &rc, hBrush );
380 break;
381 case SS_WHITERECT:
382 hBrush = CreateSolidBrush32(color_window);
383 FillRect32( hdc, &rc, hBrush );
384 break;
385 case SS_BLACKFRAME:
386 hBrush = CreateSolidBrush32(color_windowframe);
387 FrameRect32( hdc, &rc, hBrush );
388 break;
389 case SS_GRAYFRAME:
390 hBrush = CreateSolidBrush32(color_background);
391 FrameRect32( hdc, &rc, hBrush );
392 break;
393 case SS_WHITEFRAME:
394 hBrush = CreateSolidBrush32(color_window);
395 FrameRect32( hdc, &rc, hBrush );
396 break;
397 default:
398 return;
400 DeleteObject32( hBrush );
404 static void STATIC_PaintIconfn( WND *wndPtr, HDC32 hdc )
406 RECT32 rc;
407 HBRUSH32 hbrush;
408 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
410 GetClientRect32( wndPtr->hwndSelf, &rc );
411 hbrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
412 hdc, wndPtr->hwndSelf );
413 FillRect32( hdc, &rc, hbrush );
414 if (infoPtr->hIcon) DrawIcon32( hdc, rc.left, rc.top, infoPtr->hIcon );
417 static void STATIC_PaintBitmapfn(WND *wndPtr, HDC32 hdc )
419 RECT32 rc;
420 HBRUSH32 hbrush;
421 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
422 HDC32 hMemDC;
423 HBITMAP32 oldbitmap;
425 GetClientRect32( wndPtr->hwndSelf, &rc );
426 hbrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
427 hdc, wndPtr->hwndSelf );
428 FillRect32( hdc, &rc, hbrush );
429 if (infoPtr->hIcon) {
430 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_HEAP_LOCK( infoPtr->hIcon );
432 if (!bmp) return;
433 if (!(hMemDC = CreateCompatibleDC32( hdc ))) return;
435 oldbitmap = SelectObject32(hMemDC,infoPtr->hIcon);
436 BitBlt32(hdc,bmp->size.cx,bmp->size.cy,bmp->bitmap.bmWidth,bmp->bitmap.bmHeight,hMemDC,0,0,SRCCOPY);
437 DeleteDC32(hMemDC);
438 GDI_HEAP_UNLOCK(infoPtr->hIcon);
443 static void STATIC_PaintEtchedfn( WND *wndPtr, HDC32 hdc )
445 RECT32 rc;
446 HBRUSH32 hbrush;
447 HPEN32 hpen;
449 if (TWEAK_WineLook == WIN31_LOOK)
450 return;
452 GetClientRect32( wndPtr->hwndSelf, &rc );
453 hbrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
454 hdc, wndPtr->hwndSelf );
455 FillRect32( hdc, &rc, hbrush );
457 switch (wndPtr->dwStyle & SS_TYPEMASK)
459 case SS_ETCHEDHORZ:
460 hpen = SelectObject32 (hdc, GetSysColorPen32 (COLOR_3DSHADOW));
461 MoveToEx32 (hdc, rc.left, rc.bottom / 2 - 1, NULL);
462 LineTo32 (hdc, rc.right - 1, rc.bottom / 2 - 1);
463 SelectObject32 (hdc, GetSysColorPen32 (COLOR_3DHIGHLIGHT));
464 MoveToEx32 (hdc, rc.left, rc.bottom / 2, NULL);
465 LineTo32 (hdc, rc.right, rc.bottom / 2);
466 LineTo32 (hdc, rc.right, rc.bottom / 2 - 1);
467 SelectObject32 (hdc, hpen);
468 break;
470 case SS_ETCHEDVERT:
471 hpen = SelectObject32 (hdc, GetSysColorPen32 (COLOR_3DSHADOW));
472 MoveToEx32 (hdc, rc.right / 2 - 1, rc.top, NULL);
473 LineTo32 (hdc, rc.right / 2 - 1, rc.bottom - 1);
474 SelectObject32 (hdc, GetSysColorPen32 (COLOR_3DHIGHLIGHT));
475 MoveToEx32 (hdc, rc.right / 2, rc.top, NULL);
476 LineTo32 (hdc, rc.right / 2, rc.bottom);
477 LineTo32 (hdc, rc.right / 2 -1 , rc.bottom);
478 SelectObject32 (hdc, hpen);
479 break;
481 case SS_ETCHEDFRAME:
482 DrawEdge32 (hdc, &rc, EDGE_ETCHED, BF_RECT);
483 break;