4 * Copyright David W. Metcalfe, 1993
10 #include "wine/winuser16.h"
12 #include "cursoricon.h"
15 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(static);
20 static void STATIC_PaintOwnerDrawfn( WND *wndPtr, HDC hdc );
21 static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc );
22 static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc );
23 static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc );
24 static void STATIC_PaintBitmapfn( WND *wndPtr, HDC hdc );
25 static void STATIC_PaintEtchedfn( WND *wndPtr, HDC hdc );
27 static COLORREF color_windowframe, color_background, color_window;
30 typedef void (*pfPaint)( WND *, HDC );
32 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
34 STATIC_PaintTextfn, /* SS_LEFT */
35 STATIC_PaintTextfn, /* SS_CENTER */
36 STATIC_PaintTextfn, /* SS_RIGHT */
37 STATIC_PaintIconfn, /* SS_ICON */
38 STATIC_PaintRectfn, /* SS_BLACKRECT */
39 STATIC_PaintRectfn, /* SS_GRAYRECT */
40 STATIC_PaintRectfn, /* SS_WHITERECT */
41 STATIC_PaintRectfn, /* SS_BLACKFRAME */
42 STATIC_PaintRectfn, /* SS_GRAYFRAME */
43 STATIC_PaintRectfn, /* SS_WHITEFRAME */
44 NULL, /* Not defined */
45 STATIC_PaintTextfn, /* SS_SIMPLE */
46 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
47 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
48 STATIC_PaintBitmapfn, /* SS_BITMAP */
49 NULL, /* SS_ENHMETAFILE */
50 STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
51 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
52 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
56 /***********************************************************************
59 * Set the icon for an SS_ICON control.
61 static HICON16 STATIC_SetIcon( WND *wndPtr, HICON16 hicon )
64 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
65 CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16( hicon ):NULL;
67 if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_ICON) return 0;
69 ERR("huh? hicon!=0, but info=0???\n");
72 prevIcon = infoPtr->hIcon;
73 infoPtr->hIcon = hicon;
76 SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, info->nWidth, info->nHeight,
77 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
78 GlobalUnlock16( hicon );
83 /***********************************************************************
86 * Set the bitmap for an SS_BITMAP control.
88 static HBITMAP16 STATIC_SetBitmap( WND *wndPtr, HBITMAP16 hBitmap )
91 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
93 if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0;
94 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
95 ERR("huh? hBitmap!=0, but not bitmap\n");
98 hOldBitmap = infoPtr->hIcon;
99 infoPtr->hIcon = hBitmap;
103 GetObjectA(hBitmap, sizeof(bm), &bm);
104 SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, bm.bmWidth, bm.bmHeight,
105 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
111 /***********************************************************************
114 * Load the icon for an SS_ICON control.
116 static HICON STATIC_LoadIcon( WND *wndPtr, LPCSTR name )
118 HICON hicon = LoadIconA( wndPtr->hInstance, name );
119 if (!hicon) hicon = LoadIconA( 0, name );
123 /***********************************************************************
126 * Load the bitmap for an SS_BITMAP control.
128 static HBITMAP STATIC_LoadBitmap( WND *wndPtr, LPCSTR name )
130 HBITMAP hbitmap = LoadBitmapA( wndPtr->hInstance, name );
131 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
132 hbitmap = LoadBitmapA( 0, name );
137 /***********************************************************************
140 LRESULT WINAPI StaticWndProc( HWND hWnd, UINT uMsg, WPARAM wParam,
144 WND *wndPtr = WIN_FindWndPtr(hWnd);
145 LONG style = wndPtr->dwStyle & SS_TYPEMASK;
146 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
151 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
153 if ((TWEAK_WineLook > WIN31_LOOK) && (wndPtr->dwStyle & SS_SUNKEN))
154 wndPtr->dwExStyle |= WS_EX_STATICEDGE;
156 if (style == SS_ICON)
160 if (!HIWORD(cs->lpszName) || cs->lpszName[0])
161 STATIC_SetIcon( wndPtr,
162 STATIC_LoadIcon( wndPtr, cs->lpszName ));
167 if (style == SS_BITMAP)
170 STATIC_SetBitmap( wndPtr,
171 STATIC_LoadBitmap( wndPtr, cs->lpszName ));
172 WARN("style SS_BITMAP, dwStyle is 0x%08lx\n",
177 if (!HIWORD(cs->lpszName) && (cs->lpszName))
179 FIXME("windowName is 0x%04x, not doing DefWindowProc\n",
180 LOWORD(cs->lpszName));
184 lResult = DefWindowProcA( hWnd, uMsg, wParam, lParam );
188 if (style < 0L || style > SS_TYPEMASK)
190 ERR("Unknown style 0x%02lx\n", style );
194 /* initialise colours */
195 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
196 color_background = GetSysColor(COLOR_BACKGROUND);
197 color_window = GetSysColor(COLOR_WINDOW);
201 if (style == SS_ICON) {
204 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
206 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
207 * had already been loaded by the application the last thing we want to do is
208 * GlobalFree16 the handle.
211 lResult = DefWindowProcA( hWnd, uMsg, wParam, lParam );
218 BeginPaint( hWnd, &ps );
219 if (staticPaintFunc[style])
220 (staticPaintFunc[style])( wndPtr, ps.hdc );
221 EndPaint( hWnd, &ps );
226 InvalidateRect( hWnd, NULL, FALSE );
229 case WM_SYSCOLORCHANGE:
230 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
231 color_background = GetSysColor(COLOR_BACKGROUND);
232 color_window = GetSysColor(COLOR_WINDOW);
233 InvalidateRect( hWnd, NULL, TRUE );
237 if (style == SS_ICON)
238 /* FIXME : should we also return the previous hIcon here ??? */
239 STATIC_SetIcon( wndPtr, STATIC_LoadIcon( wndPtr, (LPCSTR)lParam ));
240 else if (style == SS_BITMAP)
241 STATIC_SetBitmap(wndPtr,STATIC_LoadBitmap(wndPtr,(LPCSTR)lParam ));
243 DEFWND_SetTextA( wndPtr, (LPCSTR)lParam );
244 InvalidateRect( hWnd, NULL, FALSE );
245 lResult = 1; /* success. FIXME: check text length */
249 if (style == SS_ICON)
254 if (style == SS_BITMAP)
259 infoPtr->hFont = (HFONT16)wParam;
262 InvalidateRect( hWnd, NULL, FALSE );
263 UpdateWindow( hWnd );
268 lResult = infoPtr->hFont;
272 if (wndPtr->dwStyle & SS_NOTIFY)
275 lResult = HTTRANSPARENT;
279 lResult = DLGC_STATIC;
285 lResult = infoPtr->hIcon;
291 lResult = STATIC_SetBitmap( wndPtr, (HBITMAP)lParam );
294 lResult = STATIC_SetIcon( wndPtr, (HICON16)lParam );
297 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
300 InvalidateRect( hWnd, NULL, FALSE );
301 UpdateWindow( hWnd );
306 lResult = STATIC_SetIcon( wndPtr, (HICON16)wParam );
307 InvalidateRect( hWnd, NULL, FALSE );
308 UpdateWindow( hWnd );
312 lResult = DefWindowProcA(hWnd, uMsg, wParam, lParam);
317 WIN_ReleaseWndPtr(wndPtr);
321 static void STATIC_PaintOwnerDrawfn( WND *wndPtr, HDC hdc )
325 dis.CtlType = ODT_STATIC;
326 dis.CtlID = wndPtr->wIDmenu;
328 dis.itemAction = ODA_DRAWENTIRE;
330 dis.hwndItem = wndPtr->hwndSelf;
333 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
335 SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
336 hdc, wndPtr->hwndSelf );
337 SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
338 wndPtr->wIDmenu, (LPARAM)&dis );
341 static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc )
347 LONG style = wndPtr->dwStyle;
348 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
350 GetClientRect( wndPtr->hwndSelf, &rc);
352 switch (style & SS_TYPEMASK)
355 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
359 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
363 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
367 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
370 case SS_LEFTNOWORDWRAP:
371 wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
378 if (style & SS_NOPREFIX)
379 wFormat |= DT_NOPREFIX;
381 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
383 if ((style & SS_NOPREFIX) || ((style & SS_TYPEMASK) != SS_SIMPLE))
385 hBrush = SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
386 hdc, wndPtr->hwndSelf );
387 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
388 FillRect( hdc, &rc, hBrush );
390 if (!IsWindowEnabled(wndPtr->hwndSelf))
391 SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
393 if (wndPtr->text) DrawTextW( hdc, wndPtr->text, -1, &rc, wFormat );
396 static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc )
401 GetClientRect( wndPtr->hwndSelf, &rc);
403 switch (wndPtr->dwStyle & SS_TYPEMASK)
406 hBrush = CreateSolidBrush(color_windowframe);
407 FillRect( hdc, &rc, hBrush );
410 hBrush = CreateSolidBrush(color_background);
411 FillRect( hdc, &rc, hBrush );
414 hBrush = CreateSolidBrush(color_window);
415 FillRect( hdc, &rc, hBrush );
418 hBrush = CreateSolidBrush(color_windowframe);
419 FrameRect( hdc, &rc, hBrush );
422 hBrush = CreateSolidBrush(color_background);
423 FrameRect( hdc, &rc, hBrush );
426 hBrush = CreateSolidBrush(color_window);
427 FrameRect( hdc, &rc, hBrush );
432 DeleteObject( hBrush );
436 static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc )
440 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
442 GetClientRect( wndPtr->hwndSelf, &rc );
443 hbrush = SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
444 hdc, wndPtr->hwndSelf );
445 FillRect( hdc, &rc, hbrush );
446 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );
449 static void STATIC_PaintBitmapfn(WND *wndPtr, HDC hdc )
453 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
457 GetClientRect( wndPtr->hwndSelf, &rc );
458 hbrush = SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
459 hdc, wndPtr->hwndSelf );
460 FillRect( hdc, &rc, hbrush );
462 if (infoPtr->hIcon) {
466 if(GetObjectType(infoPtr->hIcon) != OBJ_BITMAP)
468 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
469 GetObjectA(infoPtr->hIcon, sizeof(bm), &bm);
470 GetBitmapDimensionEx(infoPtr->hIcon, &sz);
471 oldbitmap = SelectObject(hMemDC, infoPtr->hIcon);
472 BitBlt(hdc, sz.cx, sz.cy, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
474 SelectObject(hMemDC, oldbitmap);
480 static void STATIC_PaintEtchedfn( WND *wndPtr, HDC hdc )
484 if (TWEAK_WineLook == WIN31_LOOK)
487 GetClientRect( wndPtr->hwndSelf, &rc );
488 switch (wndPtr->dwStyle & SS_TYPEMASK)
491 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
494 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
497 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);