4 * Copyright David W. Metcalfe, 1993
10 #include "wine/winuser16.h"
12 #include "cursoricon.h"
16 #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 );
26 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
27 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
29 static COLORREF color_windowframe, color_background, color_window;
33 HFONT16 hFont; /* Control font (or 0 for system font) */
34 WORD dummy; /* Don't know what MS-Windows puts in there */
35 HICON16 hIcon; /* Icon handle for SS_ICON controls */
38 typedef void (*pfPaint)( WND *, HDC );
40 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
42 STATIC_PaintTextfn, /* SS_LEFT */
43 STATIC_PaintTextfn, /* SS_CENTER */
44 STATIC_PaintTextfn, /* SS_RIGHT */
45 STATIC_PaintIconfn, /* SS_ICON */
46 STATIC_PaintRectfn, /* SS_BLACKRECT */
47 STATIC_PaintRectfn, /* SS_GRAYRECT */
48 STATIC_PaintRectfn, /* SS_WHITERECT */
49 STATIC_PaintRectfn, /* SS_BLACKFRAME */
50 STATIC_PaintRectfn, /* SS_GRAYFRAME */
51 STATIC_PaintRectfn, /* SS_WHITEFRAME */
52 NULL, /* Not defined */
53 STATIC_PaintTextfn, /* SS_SIMPLE */
54 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
55 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
56 STATIC_PaintBitmapfn, /* SS_BITMAP */
57 NULL, /* SS_ENHMETAFILE */
58 STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
59 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
60 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
64 /*********************************************************************
65 * static class descriptor
67 const struct builtin_class_descr STATIC_builtin_class =
70 CS_GLOBALCLASS | CS_DBLCLKS | CS_PARENTDC, /* style */
71 StaticWndProcA, /* procA */
72 StaticWndProcW, /* procW */
73 sizeof(STATICINFO), /* extra */
74 IDC_ARROWA, /* cursor */
79 /***********************************************************************
82 * Set the icon for an SS_ICON control.
84 static HICON16 STATIC_SetIcon( WND *wndPtr, HICON16 hicon )
87 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
88 CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16( hicon ):NULL;
90 if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_ICON) return 0;
92 ERR("huh? hicon!=0, but info=0???\n");
95 prevIcon = infoPtr->hIcon;
96 infoPtr->hIcon = hicon;
99 SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, info->nWidth, info->nHeight,
100 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
101 GlobalUnlock16( hicon );
106 /***********************************************************************
109 * Set the bitmap for an SS_BITMAP control.
111 static HBITMAP16 STATIC_SetBitmap( WND *wndPtr, HBITMAP16 hBitmap )
113 HBITMAP16 hOldBitmap;
114 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
116 if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0;
117 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
118 ERR("huh? hBitmap!=0, but not bitmap\n");
121 hOldBitmap = infoPtr->hIcon;
122 infoPtr->hIcon = hBitmap;
126 GetObjectW(hBitmap, sizeof(bm), &bm);
127 SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, bm.bmWidth, bm.bmHeight,
128 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
133 /***********************************************************************
136 * Load the icon for an SS_ICON control.
138 static HICON STATIC_LoadIconA( WND *wndPtr, LPCSTR name )
140 HICON hicon = LoadIconA( wndPtr->hInstance, name );
141 if (!hicon) hicon = LoadIconA( 0, name );
145 /***********************************************************************
148 * Load the icon for an SS_ICON control.
150 static HICON STATIC_LoadIconW( WND *wndPtr, LPCWSTR name )
152 HICON hicon = LoadIconW( wndPtr->hInstance, name );
153 if (!hicon) hicon = LoadIconW( 0, name );
157 /***********************************************************************
160 * Load the bitmap for an SS_BITMAP control.
162 static HBITMAP STATIC_LoadBitmapA( WND *wndPtr, LPCSTR name )
164 HBITMAP hbitmap = LoadBitmapA( wndPtr->hInstance, name );
165 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
166 hbitmap = LoadBitmapA( 0, name );
170 /***********************************************************************
173 * Load the bitmap for an SS_BITMAP control.
175 static HBITMAP STATIC_LoadBitmapW( WND *wndPtr, LPCWSTR name )
177 HBITMAP hbitmap = LoadBitmapW( wndPtr->hInstance, name );
178 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
179 hbitmap = LoadBitmapW( 0, name );
183 /***********************************************************************
184 * StaticWndProc_locked
186 static LRESULT StaticWndProc_locked( WND *wndPtr, UINT uMsg, WPARAM wParam,
187 LPARAM lParam, BOOL unicode )
190 LONG style = wndPtr->dwStyle & SS_TYPEMASK;
191 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
196 if (style < 0L || style > SS_TYPEMASK)
198 ERR("Unknown style 0x%02lx\n", style );
202 /* initialise colours */
203 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
204 color_background = GetSysColor(COLOR_BACKGROUND);
205 color_window = GetSysColor(COLOR_WINDOW);
209 if (style == SS_ICON) {
212 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
214 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
215 * had already been loaded by the application the last thing we want to do is
216 * GlobalFree16 the handle.
219 lResult = unicode ? DefWindowProcW(wndPtr->hwndSelf, uMsg, wParam, lParam) :
220 DefWindowProcA(wndPtr->hwndSelf, uMsg, wParam, lParam);
227 BeginPaint(wndPtr->hwndSelf, &ps);
228 if (staticPaintFunc[style])
229 (staticPaintFunc[style])( wndPtr, ps.hdc );
230 EndPaint(wndPtr->hwndSelf, &ps);
235 InvalidateRect(wndPtr->hwndSelf, NULL, FALSE);
238 case WM_SYSCOLORCHANGE:
239 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
240 color_background = GetSysColor(COLOR_BACKGROUND);
241 color_window = GetSysColor(COLOR_WINDOW);
242 InvalidateRect(wndPtr->hwndSelf, NULL, TRUE);
246 if ((TWEAK_WineLook > WIN31_LOOK) && (wndPtr->dwStyle & SS_SUNKEN))
247 wndPtr->dwExStyle |= WS_EX_STATICEDGE;
250 lParam = (LPARAM)(((LPCREATESTRUCTW)lParam)->lpszName);
252 lParam = (LPARAM)(((LPCREATESTRUCTA)lParam)->lpszName);
255 if (style == SS_ICON)
259 hIcon = STATIC_LoadIconW(wndPtr, (LPCWSTR)lParam);
261 hIcon = STATIC_LoadIconA(wndPtr, (LPCSTR)lParam);
262 /* FIXME : should we also return the previous hIcon here ??? */
263 STATIC_SetIcon(wndPtr, hIcon);
265 else if (style == SS_BITMAP)
269 hBitmap = STATIC_LoadBitmapW(wndPtr, (LPCWSTR)lParam);
271 hBitmap = STATIC_LoadBitmapA(wndPtr, (LPCSTR)lParam);
272 STATIC_SetBitmap(wndPtr, hBitmap);
274 else if(lParam && HIWORD(lParam))
277 DEFWND_SetTextW(wndPtr, (LPCWSTR)lParam);
279 DEFWND_SetTextA(wndPtr, (LPCSTR)lParam);
281 if(uMsg == WM_SETTEXT)
282 InvalidateRect(wndPtr->hwndSelf, NULL, FALSE);
283 lResult = 1; /* success. FIXME: check text length */
287 if (style == SS_ICON)
292 if (style == SS_BITMAP)
297 infoPtr->hFont = (HFONT16)wParam;
299 InvalidateRect( wndPtr->hwndSelf, NULL, FALSE );
303 lResult = infoPtr->hFont;
307 if (wndPtr->dwStyle & SS_NOTIFY)
310 lResult = HTTRANSPARENT;
314 lResult = DLGC_STATIC;
320 lResult = infoPtr->hIcon;
326 lResult = STATIC_SetBitmap( wndPtr, (HBITMAP)lParam );
329 lResult = STATIC_SetIcon( wndPtr, (HICON16)lParam );
332 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
335 InvalidateRect( wndPtr->hwndSelf, NULL, FALSE );
340 lResult = STATIC_SetIcon( wndPtr, (HICON16)wParam );
341 InvalidateRect( wndPtr->hwndSelf, NULL, FALSE );
345 lResult = unicode ? DefWindowProcW(wndPtr->hwndSelf, uMsg, wParam, lParam) :
346 DefWindowProcA(wndPtr->hwndSelf, uMsg, wParam, lParam);
354 /***********************************************************************
357 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
360 WND *wndPtr = WIN_FindWndPtr(hWnd);
362 lResult = StaticWndProc_locked(wndPtr, uMsg, wParam, lParam, FALSE);
364 WIN_ReleaseWndPtr(wndPtr);
368 /***********************************************************************
371 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
374 WND *wndPtr = WIN_FindWndPtr(hWnd);
376 lResult = StaticWndProc_locked(wndPtr, uMsg, wParam, lParam, TRUE);
378 WIN_ReleaseWndPtr(wndPtr);
382 static void STATIC_PaintOwnerDrawfn( WND *wndPtr, HDC hdc )
386 dis.CtlType = ODT_STATIC;
387 dis.CtlID = wndPtr->wIDmenu;
389 dis.itemAction = ODA_DRAWENTIRE;
391 dis.hwndItem = wndPtr->hwndSelf;
394 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
396 SendMessageW( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
397 hdc, wndPtr->hwndSelf );
398 SendMessageW( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
399 wndPtr->wIDmenu, (LPARAM)&dis );
402 static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc )
408 LONG style = wndPtr->dwStyle;
409 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
411 GetClientRect( wndPtr->hwndSelf, &rc);
413 switch (style & SS_TYPEMASK)
416 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
420 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
424 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
428 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
431 case SS_LEFTNOWORDWRAP:
432 wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
439 if (style & SS_NOPREFIX)
440 wFormat |= DT_NOPREFIX;
442 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
444 if ((style & SS_NOPREFIX) || ((style & SS_TYPEMASK) != SS_SIMPLE))
446 hBrush = SendMessageW( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
447 hdc, wndPtr->hwndSelf );
448 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
449 FillRect( hdc, &rc, hBrush );
451 if (!IsWindowEnabled(wndPtr->hwndSelf))
452 SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
454 if (wndPtr->text) DrawTextW( hdc, wndPtr->text, -1, &rc, wFormat );
457 static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc )
462 GetClientRect( wndPtr->hwndSelf, &rc);
464 switch (wndPtr->dwStyle & SS_TYPEMASK)
467 hBrush = CreateSolidBrush(color_windowframe);
468 FillRect( hdc, &rc, hBrush );
471 hBrush = CreateSolidBrush(color_background);
472 FillRect( hdc, &rc, hBrush );
475 hBrush = CreateSolidBrush(color_window);
476 FillRect( hdc, &rc, hBrush );
479 hBrush = CreateSolidBrush(color_windowframe);
480 FrameRect( hdc, &rc, hBrush );
483 hBrush = CreateSolidBrush(color_background);
484 FrameRect( hdc, &rc, hBrush );
487 hBrush = CreateSolidBrush(color_window);
488 FrameRect( hdc, &rc, hBrush );
493 DeleteObject( hBrush );
497 static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc )
501 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
503 GetClientRect( wndPtr->hwndSelf, &rc );
504 hbrush = SendMessageW( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
505 hdc, wndPtr->hwndSelf );
506 FillRect( hdc, &rc, hbrush );
507 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );
510 static void STATIC_PaintBitmapfn(WND *wndPtr, HDC hdc )
514 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
518 GetClientRect( wndPtr->hwndSelf, &rc );
519 hbrush = SendMessageW( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
520 hdc, wndPtr->hwndSelf );
521 FillRect( hdc, &rc, hbrush );
523 if (infoPtr->hIcon) {
527 if(GetObjectType(infoPtr->hIcon) != OBJ_BITMAP)
529 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
530 GetObjectW(infoPtr->hIcon, sizeof(bm), &bm);
531 GetBitmapDimensionEx(infoPtr->hIcon, &sz);
532 oldbitmap = SelectObject(hMemDC, infoPtr->hIcon);
533 BitBlt(hdc, sz.cx, sz.cy, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
535 SelectObject(hMemDC, oldbitmap);
541 static void STATIC_PaintEtchedfn( WND *wndPtr, HDC hdc )
545 if (TWEAK_WineLook == WIN31_LOOK)
548 GetClientRect( wndPtr->hwndSelf, &rc );
549 switch (wndPtr->dwStyle & SS_TYPEMASK)
552 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
555 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
558 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);