4 * Copyright David W. Metcalfe, 1993
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/winuser16.h"
24 #include "cursoricon.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(static);
31 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
32 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
33 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
34 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
35 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
36 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
37 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
38 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
40 static COLORREF color_windowframe, color_background, color_window;
42 /* offsets for GetWindowLong for static private information */
43 #define HFONT_GWL_OFFSET 0
44 #define HICON_GWL_OFFSET (sizeof(HFONT))
45 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
47 typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
49 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
51 STATIC_PaintTextfn, /* SS_LEFT */
52 STATIC_PaintTextfn, /* SS_CENTER */
53 STATIC_PaintTextfn, /* SS_RIGHT */
54 STATIC_PaintIconfn, /* SS_ICON */
55 STATIC_PaintRectfn, /* SS_BLACKRECT */
56 STATIC_PaintRectfn, /* SS_GRAYRECT */
57 STATIC_PaintRectfn, /* SS_WHITERECT */
58 STATIC_PaintRectfn, /* SS_BLACKFRAME */
59 STATIC_PaintRectfn, /* SS_GRAYFRAME */
60 STATIC_PaintRectfn, /* SS_WHITEFRAME */
61 NULL, /* Not defined */
62 STATIC_PaintTextfn, /* SS_SIMPLE */
63 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
64 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
65 STATIC_PaintBitmapfn, /* SS_BITMAP */
66 NULL, /* SS_ENHMETAFILE */
67 STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
68 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
69 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
73 /*********************************************************************
74 * static class descriptor
76 const struct builtin_class_descr STATIC_builtin_class =
79 CS_GLOBALCLASS | CS_DBLCLKS | CS_PARENTDC, /* style */
80 StaticWndProcA, /* procA */
81 StaticWndProcW, /* procW */
82 STATIC_EXTRA_BYTES, /* extra */
83 IDC_ARROWA, /* cursor */
88 /***********************************************************************
91 * Set the icon for an SS_ICON control.
93 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
96 CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16( hicon ):NULL;
98 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
100 ERR("huh? hicon!=0, but info=0???\n");
103 prevIcon = SetWindowLongA( hwnd, HICON_GWL_OFFSET, hicon );
106 SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
107 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
108 GlobalUnlock16( hicon );
113 /***********************************************************************
116 * Set the bitmap for an SS_BITMAP control.
118 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
122 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
123 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
124 ERR("huh? hBitmap!=0, but not bitmap\n");
127 hOldBitmap = SetWindowLongA( hwnd, HICON_GWL_OFFSET, hBitmap );
131 GetObjectW(hBitmap, sizeof(bm), &bm);
132 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
133 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
138 /***********************************************************************
141 * Load the icon for an SS_ICON control.
143 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name )
145 HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE );
146 HICON hicon = LoadIconA( hInstance, name );
147 if (!hicon) hicon = LoadIconA( 0, name );
151 /***********************************************************************
154 * Load the icon for an SS_ICON control.
156 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name )
158 HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE );
159 HICON hicon = LoadIconW( hInstance, name );
160 if (!hicon) hicon = LoadIconW( 0, name );
164 /***********************************************************************
167 * Load the bitmap for an SS_BITMAP control.
169 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
171 HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE );
172 HBITMAP hbitmap = LoadBitmapA( hInstance, name );
173 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
174 hbitmap = LoadBitmapA( 0, name );
178 /***********************************************************************
181 * Load the bitmap for an SS_BITMAP control.
183 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
185 HINSTANCE hInstance = GetWindowLongA( hwnd, GWL_HINSTANCE );
186 HBITMAP hbitmap = LoadBitmapW( hInstance, name );
187 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
188 hbitmap = LoadBitmapW( 0, name );
192 /***********************************************************************
195 * Try to immediately paint the control.
197 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
199 LONG style = full_style & SS_TYPEMASK;
202 GetClientRect( hwnd, &rc );
203 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
207 (staticPaintFunc[style])( hwnd, hdc, full_style );
208 ReleaseDC( hwnd, hdc );
212 /***********************************************************************
213 * StaticWndProc_common
215 static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
216 LPARAM lParam, BOOL unicode )
219 LONG full_style = GetWindowLongA( hwnd, GWL_STYLE );
220 LONG style = full_style & SS_TYPEMASK;
225 if (style < 0L || style > SS_TYPEMASK)
227 ERR("Unknown style 0x%02lx\n", style );
230 /* initialise colours */
231 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
232 color_background = GetSysColor(COLOR_BACKGROUND);
233 color_window = GetSysColor(COLOR_WINDOW);
237 if (style == SS_ICON) {
240 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
242 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
243 * had already been loaded by the application the last thing we want to do is
244 * GlobalFree16 the handle.
248 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
249 DefWindowProcA(hwnd, uMsg, wParam, lParam);
254 BeginPaint(hwnd, &ps);
255 if (staticPaintFunc[style])
256 (staticPaintFunc[style])( hwnd, ps.hdc, full_style );
262 InvalidateRect(hwnd, NULL, TRUE);
265 case WM_SYSCOLORCHANGE:
266 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
267 color_background = GetSysColor(COLOR_BACKGROUND);
268 color_window = GetSysColor(COLOR_WINDOW);
269 InvalidateRect(hwnd, NULL, TRUE);
273 if ((TWEAK_WineLook > WIN31_LOOK) && (full_style & SS_SUNKEN))
274 SetWindowLongA( hwnd, GWL_EXSTYLE,
275 GetWindowLongA( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
278 lParam = (LPARAM)(((LPCREATESTRUCTW)lParam)->lpszName);
280 lParam = (LPARAM)(((LPCREATESTRUCTA)lParam)->lpszName);
288 hIcon = STATIC_LoadIconW(hwnd, (LPCWSTR)lParam);
290 hIcon = STATIC_LoadIconA(hwnd, (LPCSTR)lParam);
291 /* FIXME : should we also return the previous hIcon here ??? */
292 STATIC_SetIcon(hwnd, hIcon, style);
299 hBitmap = STATIC_LoadBitmapW(hwnd, (LPCWSTR)lParam);
301 hBitmap = STATIC_LoadBitmapA(hwnd, (LPCSTR)lParam);
302 STATIC_SetBitmap(hwnd, hBitmap, style);
309 case SS_LEFTNOWORDWRAP:
314 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
316 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
318 if (uMsg == WM_SETTEXT)
319 STATIC_TryPaintFcn( hwnd, full_style );
326 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
328 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
330 if(uMsg == WM_SETTEXT)
331 InvalidateRect(hwnd, NULL, TRUE);
333 return 1; /* success. FIXME: check text length */
336 if ((style == SS_ICON) || (style == SS_BITMAP)) return 0;
337 SetWindowLongA( hwnd, HFONT_GWL_OFFSET, wParam );
339 InvalidateRect( hwnd, NULL, TRUE );
343 return GetWindowLongA( hwnd, HFONT_GWL_OFFSET );
346 if (full_style & SS_NOTIFY)
349 return HTTRANSPARENT;
357 return GetWindowLongA( hwnd, HICON_GWL_OFFSET );
362 lResult = STATIC_SetBitmap( hwnd, (HBITMAP)lParam, style );
365 lResult = STATIC_SetIcon( hwnd, (HICON)lParam, style );
368 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
371 InvalidateRect( hwnd, NULL, TRUE );
376 lResult = STATIC_SetIcon( hwnd, (HICON)wParam, style );
377 InvalidateRect( hwnd, NULL, TRUE );
381 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
382 DefWindowProcA(hwnd, uMsg, wParam, lParam);
387 /***********************************************************************
390 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
392 if (!IsWindow( hWnd )) return 0;
393 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
396 /***********************************************************************
399 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
401 if (!IsWindow( hWnd )) return 0;
402 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
405 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
408 LONG id = GetWindowLongA( hwnd, GWL_ID );
410 dis.CtlType = ODT_STATIC;
413 dis.itemAction = ODA_DRAWENTIRE;
418 GetClientRect( hwnd, &dis.rcItem );
420 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
421 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
424 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
433 GetClientRect( hwnd, &rc);
435 switch (style & SS_TYPEMASK)
438 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
442 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
446 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
450 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
453 case SS_LEFTNOWORDWRAP:
454 wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
461 if (style & SS_NOPREFIX)
462 wFormat |= DT_NOPREFIX;
464 if ((hFont = GetWindowLongA( hwnd, HFONT_GWL_OFFSET ))) SelectObject( hdc, hFont );
466 if ((style & SS_NOPREFIX) || ((style & SS_TYPEMASK) != SS_SIMPLE))
468 hBrush = SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
469 if (!hBrush) /* did the app forget to call defwindowproc ? */
470 hBrush = DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd);
471 FillRect( hdc, &rc, hBrush );
473 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
475 if (!(len = SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 ))) return;
476 if (!(text = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return;
477 SendMessageW( hwnd, WM_GETTEXT, len + 1, (LPARAM)text );
478 DrawTextW( hdc, text, -1, &rc, wFormat );
479 HeapFree( GetProcessHeap(), 0, text );
482 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
487 GetClientRect( hwnd, &rc);
489 switch (style & SS_TYPEMASK)
492 hBrush = CreateSolidBrush(color_windowframe);
493 FillRect( hdc, &rc, hBrush );
496 hBrush = CreateSolidBrush(color_background);
497 FillRect( hdc, &rc, hBrush );
500 hBrush = CreateSolidBrush(color_window);
501 FillRect( hdc, &rc, hBrush );
504 hBrush = CreateSolidBrush(color_windowframe);
505 FrameRect( hdc, &rc, hBrush );
508 hBrush = CreateSolidBrush(color_background);
509 FrameRect( hdc, &rc, hBrush );
512 hBrush = CreateSolidBrush(color_window);
513 FrameRect( hdc, &rc, hBrush );
518 DeleteObject( hBrush );
522 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
528 GetClientRect( hwnd, &rc );
529 hbrush = SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
530 FillRect( hdc, &rc, hbrush );
531 if ((hIcon = GetWindowLongA( hwnd, HICON_GWL_OFFSET )))
532 DrawIcon( hdc, rc.left, rc.top, hIcon );
535 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
543 GetClientRect( hwnd, &rc );
544 hbrush = SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hdc, hwnd );
545 FillRect( hdc, &rc, hbrush );
547 if ((hIcon = GetWindowLongA( hwnd, HICON_GWL_OFFSET )))
552 if(GetObjectType(hIcon) != OBJ_BITMAP) return;
553 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
554 GetObjectW(hIcon, sizeof(bm), &bm);
555 GetBitmapDimensionEx(hIcon, &sz);
556 oldbitmap = SelectObject(hMemDC, hIcon);
557 BitBlt(hdc, sz.cx, sz.cy, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
559 SelectObject(hMemDC, oldbitmap);
565 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
569 if (TWEAK_WineLook == WIN31_LOOK)
572 GetClientRect( hwnd, &rc );
573 switch (style & SS_TYPEMASK)
576 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
579 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
582 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);