4 * Copyright David W. Metcalfe, 1993
10 #include "wine/winuser16.h"
11 #include "cursoricon.h"
14 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(static);
18 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
19 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
20 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
21 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
22 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
23 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
24 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
25 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
27 static COLORREF color_windowframe, color_background, color_window;
29 /* offsets for GetWindowLong for static private information */
30 #define HFONT_GWL_OFFSET 0
31 #define HICON_GWL_OFFSET (sizeof(HFONT))
32 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
34 typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
36 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
38 STATIC_PaintTextfn, /* SS_LEFT */
39 STATIC_PaintTextfn, /* SS_CENTER */
40 STATIC_PaintTextfn, /* SS_RIGHT */
41 STATIC_PaintIconfn, /* SS_ICON */
42 STATIC_PaintRectfn, /* SS_BLACKRECT */
43 STATIC_PaintRectfn, /* SS_GRAYRECT */
44 STATIC_PaintRectfn, /* SS_WHITERECT */
45 STATIC_PaintRectfn, /* SS_BLACKFRAME */
46 STATIC_PaintRectfn, /* SS_GRAYFRAME */
47 STATIC_PaintRectfn, /* SS_WHITEFRAME */
48 NULL, /* Not defined */
49 STATIC_PaintTextfn, /* SS_SIMPLE */
50 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
51 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
52 STATIC_PaintBitmapfn, /* SS_BITMAP */
53 NULL, /* SS_ENHMETAFILE */
54 STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
55 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
56 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
60 /*********************************************************************
61 * static class descriptor
63 const struct builtin_class_descr STATIC_builtin_class =
66 CS_GLOBALCLASS | CS_DBLCLKS | CS_PARENTDC, /* style */
67 StaticWndProcA, /* procA */
68 StaticWndProcW, /* procW */
69 STATIC_EXTRA_BYTES, /* extra */
70 IDC_ARROWA, /* cursor */
75 /***********************************************************************
78 * Set the icon for an SS_ICON control.
80 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
83 CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16( hicon ):NULL;
85 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
87 ERR("huh? hicon!=0, but info=0???\n");
90 prevIcon = SetWindowLongA( hwnd, HICON_GWL_OFFSET, hicon );
93 SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
94 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
95 GlobalUnlock16( hicon );
100 /***********************************************************************
103 * Set the bitmap for an SS_BITMAP control.
105 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
109 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
110 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
111 ERR("huh? hBitmap!=0, but not bitmap\n");
114 hOldBitmap = SetWindowLongA( hwnd, HICON_GWL_OFFSET, hBitmap );
118 GetObjectW(hBitmap, sizeof(bm), &bm);
119 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
120 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
125 /***********************************************************************
128 * Load the icon for an SS_ICON control.
130 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name )
132 HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE );
133 HICON hicon = LoadIconA( hInstance, name );
134 if (!hicon) hicon = LoadIconA( 0, name );
138 /***********************************************************************
141 * Load the icon for an SS_ICON control.
143 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name )
145 HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE );
146 HICON hicon = LoadIconW( hInstance, name );
147 if (!hicon) hicon = LoadIconW( 0, name );
151 /***********************************************************************
154 * Load the bitmap for an SS_BITMAP control.
156 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
158 HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE );
159 HBITMAP hbitmap = LoadBitmapA( hInstance, name );
160 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
161 hbitmap = LoadBitmapA( 0, name );
165 /***********************************************************************
168 * Load the bitmap for an SS_BITMAP control.
170 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
172 HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE );
173 HBITMAP hbitmap = LoadBitmapW( hInstance, name );
174 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
175 hbitmap = LoadBitmapW( 0, name );
179 /***********************************************************************
180 * StaticWndProc_common
182 static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
183 LPARAM lParam, BOOL unicode )
186 LONG full_style = GetWindowLongA( hwnd, GWL_STYLE );
187 LONG style = full_style & SS_TYPEMASK;
192 if (style < 0L || style > SS_TYPEMASK)
194 ERR("Unknown style 0x%02lx\n", style );
197 /* initialise colours */
198 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
199 color_background = GetSysColor(COLOR_BACKGROUND);
200 color_window = GetSysColor(COLOR_WINDOW);
204 if (style == SS_ICON) {
207 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
209 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
210 * had already been loaded by the application the last thing we want to do is
211 * GlobalFree16 the handle.
215 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
216 DefWindowProcA(hwnd, uMsg, wParam, lParam);
221 BeginPaint(hwnd, &ps);
222 if (staticPaintFunc[style])
223 (staticPaintFunc[style])( hwnd, ps.hdc, full_style );
229 InvalidateRect(hwnd, NULL, FALSE);
232 case WM_SYSCOLORCHANGE:
233 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
234 color_background = GetSysColor(COLOR_BACKGROUND);
235 color_window = GetSysColor(COLOR_WINDOW);
236 InvalidateRect(hwnd, NULL, TRUE);
240 if ((TWEAK_WineLook > WIN31_LOOK) && (full_style & SS_SUNKEN))
241 SetWindowLongA( hwnd, GWL_EXSTYLE,
242 GetWindowLongA( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
245 lParam = (LPARAM)(((LPCREATESTRUCTW)lParam)->lpszName);
247 lParam = (LPARAM)(((LPCREATESTRUCTA)lParam)->lpszName);
250 if (style == SS_ICON)
254 hIcon = STATIC_LoadIconW(hwnd, (LPCWSTR)lParam);
256 hIcon = STATIC_LoadIconA(hwnd, (LPCSTR)lParam);
257 /* FIXME : should we also return the previous hIcon here ??? */
258 STATIC_SetIcon(hwnd, hIcon, style);
260 else if (style == SS_BITMAP)
264 hBitmap = STATIC_LoadBitmapW(hwnd, (LPCWSTR)lParam);
266 hBitmap = STATIC_LoadBitmapA(hwnd, (LPCSTR)lParam);
267 STATIC_SetBitmap(hwnd, hBitmap, style);
269 else if (HIWORD(lParam))
272 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
274 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
276 if(uMsg == WM_SETTEXT)
277 InvalidateRect(hwnd, NULL, FALSE);
278 return 1; /* success. FIXME: check text length */
281 if ((style == SS_ICON) || (style == SS_BITMAP)) return 0;
282 SetWindowLongA( hwnd, HFONT_GWL_OFFSET, wParam );
284 InvalidateRect( hwnd, NULL, FALSE );
288 return GetWindowLongA( hwnd, HFONT_GWL_OFFSET );
291 if (full_style & SS_NOTIFY)
294 return HTTRANSPARENT;
302 return GetWindowLongA( hwnd, HICON_GWL_OFFSET );
307 lResult = STATIC_SetBitmap( hwnd, (HBITMAP)lParam, style );
310 lResult = STATIC_SetIcon( hwnd, (HICON)lParam, style );
313 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
316 InvalidateRect( hwnd, NULL, FALSE );
321 lResult = STATIC_SetIcon( hwnd, (HICON)wParam, style );
322 InvalidateRect( hwnd, NULL, FALSE );
326 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
327 DefWindowProcA(hwnd, uMsg, wParam, lParam);
332 /***********************************************************************
335 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
337 if (!IsWindow( hWnd )) return 0;
338 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
341 /***********************************************************************
344 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
346 if (!IsWindow( hWnd )) return 0;
347 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
350 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
353 LONG id = GetWindowLongA( hwnd, GWL_ID );
355 dis.CtlType = ODT_STATIC;
358 dis.itemAction = ODA_DRAWENTIRE;
363 GetClientRect( hwnd, &dis.rcItem );
365 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
366 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
369 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
378 GetClientRect( hwnd, &rc);
380 switch (style & SS_TYPEMASK)
383 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
387 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
391 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
395 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
398 case SS_LEFTNOWORDWRAP:
399 wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
406 if (style & SS_NOPREFIX)
407 wFormat |= DT_NOPREFIX;
409 if ((hFont = GetWindowLongA( hwnd, HFONT_GWL_OFFSET ))) SelectObject( hdc, hFont );
411 if ((style & SS_NOPREFIX) || ((style & SS_TYPEMASK) != SS_SIMPLE))
413 hBrush = SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
414 if (!hBrush) /* did the app forget to call defwindowproc ? */
415 hBrush = DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd);
416 FillRect( hdc, &rc, hBrush );
418 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
420 if (!(len = SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 ))) return;
421 if (!(text = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return;
422 SendMessageW( hwnd, WM_GETTEXT, len + 1, (LPARAM)text );
423 DrawTextW( hdc, text, -1, &rc, wFormat );
424 HeapFree( GetProcessHeap(), 0, text );
427 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
432 GetClientRect( hwnd, &rc);
434 switch (style & SS_TYPEMASK)
437 hBrush = CreateSolidBrush(color_windowframe);
438 FillRect( hdc, &rc, hBrush );
441 hBrush = CreateSolidBrush(color_background);
442 FillRect( hdc, &rc, hBrush );
445 hBrush = CreateSolidBrush(color_window);
446 FillRect( hdc, &rc, hBrush );
449 hBrush = CreateSolidBrush(color_windowframe);
450 FrameRect( hdc, &rc, hBrush );
453 hBrush = CreateSolidBrush(color_background);
454 FrameRect( hdc, &rc, hBrush );
457 hBrush = CreateSolidBrush(color_window);
458 FrameRect( hdc, &rc, hBrush );
463 DeleteObject( hBrush );
467 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
473 GetClientRect( hwnd, &rc );
474 hbrush = SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
475 FillRect( hdc, &rc, hbrush );
476 if ((hIcon = GetWindowLongA( hwnd, HICON_GWL_OFFSET )))
477 DrawIcon( hdc, rc.left, rc.top, hIcon );
480 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
488 GetClientRect( hwnd, &rc );
489 hbrush = SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
490 FillRect( hdc, &rc, hbrush );
492 if ((hIcon = GetWindowLongA( hwnd, HICON_GWL_OFFSET )))
497 if(GetObjectType(hIcon) != OBJ_BITMAP) return;
498 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
499 GetObjectW(hIcon, sizeof(bm), &bm);
500 GetBitmapDimensionEx(hIcon, &sz);
501 oldbitmap = SelectObject(hMemDC, hIcon);
502 BitBlt(hdc, sz.cx, sz.cy, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
504 SelectObject(hMemDC, oldbitmap);
510 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
514 if (TWEAK_WineLook == WIN31_LOOK)
517 GetClientRect( hwnd, &rc );
518 switch (style & SS_TYPEMASK)
521 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
524 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
527 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);