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 /***********************************************************************
182 * Try to immediately paint the control.
184 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
186 LONG style = full_style & SS_TYPEMASK;
189 GetClientRect( hwnd, &rc );
190 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
194 (staticPaintFunc[style])( hwnd, hdc, full_style );
195 ReleaseDC( hwnd, hdc );
199 /***********************************************************************
200 * StaticWndProc_common
202 static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
203 LPARAM lParam, BOOL unicode )
206 LONG full_style = GetWindowLongA( hwnd, GWL_STYLE );
207 LONG style = full_style & SS_TYPEMASK;
212 if (style < 0L || style > SS_TYPEMASK)
214 ERR("Unknown style 0x%02lx\n", style );
217 /* initialise colours */
218 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
219 color_background = GetSysColor(COLOR_BACKGROUND);
220 color_window = GetSysColor(COLOR_WINDOW);
224 if (style == SS_ICON) {
227 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
229 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
230 * had already been loaded by the application the last thing we want to do is
231 * GlobalFree16 the handle.
235 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
236 DefWindowProcA(hwnd, uMsg, wParam, lParam);
241 BeginPaint(hwnd, &ps);
242 if (staticPaintFunc[style])
243 (staticPaintFunc[style])( hwnd, ps.hdc, full_style );
249 InvalidateRect(hwnd, NULL, FALSE);
252 case WM_SYSCOLORCHANGE:
253 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
254 color_background = GetSysColor(COLOR_BACKGROUND);
255 color_window = GetSysColor(COLOR_WINDOW);
256 InvalidateRect(hwnd, NULL, TRUE);
260 if ((TWEAK_WineLook > WIN31_LOOK) && (full_style & SS_SUNKEN))
261 SetWindowLongA( hwnd, GWL_EXSTYLE,
262 GetWindowLongA( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
265 lParam = (LPARAM)(((LPCREATESTRUCTW)lParam)->lpszName);
267 lParam = (LPARAM)(((LPCREATESTRUCTA)lParam)->lpszName);
275 hIcon = STATIC_LoadIconW(hwnd, (LPCWSTR)lParam);
277 hIcon = STATIC_LoadIconA(hwnd, (LPCSTR)lParam);
278 /* FIXME : should we also return the previous hIcon here ??? */
279 STATIC_SetIcon(hwnd, hIcon, style);
286 hBitmap = STATIC_LoadBitmapW(hwnd, (LPCWSTR)lParam);
288 hBitmap = STATIC_LoadBitmapA(hwnd, (LPCSTR)lParam);
289 STATIC_SetBitmap(hwnd, hBitmap, style);
296 case SS_LEFTNOWORDWRAP:
301 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
303 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
305 if (uMsg == WM_SETTEXT)
306 STATIC_TryPaintFcn( hwnd, full_style );
313 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
315 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
317 if(uMsg == WM_SETTEXT)
318 InvalidateRect(hwnd, NULL, FALSE);
320 return 1; /* success. FIXME: check text length */
323 if ((style == SS_ICON) || (style == SS_BITMAP)) return 0;
324 SetWindowLongA( hwnd, HFONT_GWL_OFFSET, wParam );
325 if (!LOWORD(lParam)) break; /* don't refresh */
331 case SS_LEFTNOWORDWRAP:
332 STATIC_TryPaintFcn( hwnd, full_style );
335 InvalidateRect( hwnd, NULL, FALSE );
341 return GetWindowLongA( hwnd, HFONT_GWL_OFFSET );
344 if (full_style & SS_NOTIFY)
347 return HTTRANSPARENT;
355 return GetWindowLongA( hwnd, HICON_GWL_OFFSET );
360 lResult = STATIC_SetBitmap( hwnd, (HBITMAP)lParam, style );
363 lResult = STATIC_SetIcon( hwnd, (HICON)lParam, style );
366 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
369 InvalidateRect( hwnd, NULL, FALSE );
374 lResult = STATIC_SetIcon( hwnd, (HICON)wParam, style );
375 InvalidateRect( hwnd, NULL, FALSE );
379 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
380 DefWindowProcA(hwnd, uMsg, wParam, lParam);
385 /***********************************************************************
388 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
390 if (!IsWindow( hWnd )) return 0;
391 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
394 /***********************************************************************
397 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
399 if (!IsWindow( hWnd )) return 0;
400 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
403 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
406 LONG id = GetWindowLongA( hwnd, GWL_ID );
408 dis.CtlType = ODT_STATIC;
411 dis.itemAction = ODA_DRAWENTIRE;
416 GetClientRect( hwnd, &dis.rcItem );
418 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
419 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
422 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
431 GetClientRect( hwnd, &rc);
433 switch (style & SS_TYPEMASK)
436 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
440 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
444 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
448 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
451 case SS_LEFTNOWORDWRAP:
452 wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
459 if (style & SS_NOPREFIX)
460 wFormat |= DT_NOPREFIX;
462 if ((hFont = GetWindowLongA( hwnd, HFONT_GWL_OFFSET ))) SelectObject( hdc, hFont );
464 if ((style & SS_NOPREFIX) || ((style & SS_TYPEMASK) != SS_SIMPLE))
466 hBrush = SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
467 if (!hBrush) /* did the app forget to call defwindowproc ? */
468 hBrush = DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd);
469 FillRect( hdc, &rc, hBrush );
471 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
473 if (!(len = SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 ))) return;
474 if (!(text = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return;
475 SendMessageW( hwnd, WM_GETTEXT, len + 1, (LPARAM)text );
476 DrawTextW( hdc, text, -1, &rc, wFormat );
477 HeapFree( GetProcessHeap(), 0, text );
480 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
485 GetClientRect( hwnd, &rc);
487 switch (style & SS_TYPEMASK)
490 hBrush = CreateSolidBrush(color_windowframe);
491 FillRect( hdc, &rc, hBrush );
494 hBrush = CreateSolidBrush(color_background);
495 FillRect( hdc, &rc, hBrush );
498 hBrush = CreateSolidBrush(color_window);
499 FillRect( hdc, &rc, hBrush );
502 hBrush = CreateSolidBrush(color_windowframe);
503 FrameRect( hdc, &rc, hBrush );
506 hBrush = CreateSolidBrush(color_background);
507 FrameRect( hdc, &rc, hBrush );
510 hBrush = CreateSolidBrush(color_window);
511 FrameRect( hdc, &rc, hBrush );
516 DeleteObject( hBrush );
520 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
526 GetClientRect( hwnd, &rc );
527 hbrush = SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
528 FillRect( hdc, &rc, hbrush );
529 if ((hIcon = GetWindowLongA( hwnd, HICON_GWL_OFFSET )))
530 DrawIcon( hdc, rc.left, rc.top, hIcon );
533 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
541 GetClientRect( hwnd, &rc );
542 hbrush = SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
543 FillRect( hdc, &rc, hbrush );
545 if ((hIcon = GetWindowLongA( hwnd, HICON_GWL_OFFSET )))
550 if(GetObjectType(hIcon) != OBJ_BITMAP) return;
551 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
552 GetObjectW(hIcon, sizeof(bm), &bm);
553 GetBitmapDimensionEx(hIcon, &sz);
554 oldbitmap = SelectObject(hMemDC, hIcon);
555 BitBlt(hdc, sz.cx, sz.cy, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
557 SelectObject(hMemDC, oldbitmap);
563 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
567 if (TWEAK_WineLook == WIN31_LOOK)
570 GetClientRect( hwnd, &rc );
571 switch (style & SS_TYPEMASK)
574 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
577 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
580 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);