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 );
26 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
28 static COLORREF color_windowframe, color_background, color_window;
32 HFONT16 hFont; /* Control font (or 0 for system font) */
33 WORD dummy; /* Don't know what MS-Windows puts in there */
34 HICON16 hIcon; /* Icon handle for SS_ICON controls */
37 typedef void (*pfPaint)( WND *, HDC );
39 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
41 STATIC_PaintTextfn, /* SS_LEFT */
42 STATIC_PaintTextfn, /* SS_CENTER */
43 STATIC_PaintTextfn, /* SS_RIGHT */
44 STATIC_PaintIconfn, /* SS_ICON */
45 STATIC_PaintRectfn, /* SS_BLACKRECT */
46 STATIC_PaintRectfn, /* SS_GRAYRECT */
47 STATIC_PaintRectfn, /* SS_WHITERECT */
48 STATIC_PaintRectfn, /* SS_BLACKFRAME */
49 STATIC_PaintRectfn, /* SS_GRAYFRAME */
50 STATIC_PaintRectfn, /* SS_WHITEFRAME */
51 NULL, /* Not defined */
52 STATIC_PaintTextfn, /* SS_SIMPLE */
53 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
54 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
55 STATIC_PaintBitmapfn, /* SS_BITMAP */
56 NULL, /* SS_ENHMETAFILE */
57 STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
58 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
59 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
63 /*********************************************************************
64 * static class descriptor
66 const struct builtin_class_descr STATIC_builtin_class =
69 CS_GLOBALCLASS | CS_DBLCLKS | CS_PARENTDC, /* style */
70 StaticWndProcA, /* procA */
71 NULL, /* procW (FIXME) */
72 sizeof(STATICINFO), /* extra */
73 IDC_ARROWA, /* cursor */
78 /***********************************************************************
81 * Set the icon for an SS_ICON control.
83 static HICON16 STATIC_SetIcon( WND *wndPtr, HICON16 hicon )
86 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
87 CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16( hicon ):NULL;
89 if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_ICON) return 0;
91 ERR("huh? hicon!=0, but info=0???\n");
94 prevIcon = infoPtr->hIcon;
95 infoPtr->hIcon = hicon;
98 SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, info->nWidth, info->nHeight,
99 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
100 GlobalUnlock16( hicon );
105 /***********************************************************************
108 * Set the bitmap for an SS_BITMAP control.
110 static HBITMAP16 STATIC_SetBitmap( WND *wndPtr, HBITMAP16 hBitmap )
112 HBITMAP16 hOldBitmap;
113 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
115 if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0;
116 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
117 ERR("huh? hBitmap!=0, but not bitmap\n");
120 hOldBitmap = infoPtr->hIcon;
121 infoPtr->hIcon = hBitmap;
125 GetObjectA(hBitmap, sizeof(bm), &bm);
126 SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, bm.bmWidth, bm.bmHeight,
127 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
133 /***********************************************************************
136 * Load the icon for an SS_ICON control.
138 static HICON STATIC_LoadIcon( WND *wndPtr, LPCSTR name )
140 HICON hicon = LoadIconA( wndPtr->hInstance, name );
141 if (!hicon) hicon = LoadIconA( 0, name );
145 /***********************************************************************
148 * Load the bitmap for an SS_BITMAP control.
150 static HBITMAP STATIC_LoadBitmap( WND *wndPtr, LPCSTR name )
152 HBITMAP hbitmap = LoadBitmapA( wndPtr->hInstance, name );
153 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
154 hbitmap = LoadBitmapA( 0, name );
159 /***********************************************************************
162 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
165 WND *wndPtr = WIN_FindWndPtr(hWnd);
166 LONG style = wndPtr->dwStyle & SS_TYPEMASK;
167 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
172 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
174 if ((TWEAK_WineLook > WIN31_LOOK) && (wndPtr->dwStyle & SS_SUNKEN))
175 wndPtr->dwExStyle |= WS_EX_STATICEDGE;
177 if (style == SS_ICON)
181 if (!HIWORD(cs->lpszName) || cs->lpszName[0])
182 STATIC_SetIcon( wndPtr,
183 STATIC_LoadIcon( wndPtr, cs->lpszName ));
188 if (style == SS_BITMAP)
191 STATIC_SetBitmap( wndPtr,
192 STATIC_LoadBitmap( wndPtr, cs->lpszName ));
193 WARN("style SS_BITMAP, dwStyle is 0x%08lx\n",
198 if (!HIWORD(cs->lpszName) && (cs->lpszName))
200 FIXME("windowName is 0x%04x, not doing DefWindowProc\n",
201 LOWORD(cs->lpszName));
205 lResult = DefWindowProcA( hWnd, uMsg, wParam, lParam );
209 if (style < 0L || style > SS_TYPEMASK)
211 ERR("Unknown style 0x%02lx\n", style );
215 /* initialise colours */
216 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
217 color_background = GetSysColor(COLOR_BACKGROUND);
218 color_window = GetSysColor(COLOR_WINDOW);
222 if (style == SS_ICON) {
225 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
227 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
228 * had already been loaded by the application the last thing we want to do is
229 * GlobalFree16 the handle.
232 lResult = DefWindowProcA( hWnd, uMsg, wParam, lParam );
239 BeginPaint( hWnd, &ps );
240 if (staticPaintFunc[style])
241 (staticPaintFunc[style])( wndPtr, ps.hdc );
242 EndPaint( hWnd, &ps );
247 InvalidateRect( hWnd, NULL, FALSE );
250 case WM_SYSCOLORCHANGE:
251 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
252 color_background = GetSysColor(COLOR_BACKGROUND);
253 color_window = GetSysColor(COLOR_WINDOW);
254 InvalidateRect( hWnd, NULL, TRUE );
258 if (style == SS_ICON)
259 /* FIXME : should we also return the previous hIcon here ??? */
260 STATIC_SetIcon( wndPtr, STATIC_LoadIcon( wndPtr, (LPCSTR)lParam ));
261 else if (style == SS_BITMAP)
262 STATIC_SetBitmap(wndPtr,STATIC_LoadBitmap(wndPtr,(LPCSTR)lParam ));
264 DEFWND_SetTextA( wndPtr, (LPCSTR)lParam );
265 InvalidateRect( hWnd, NULL, FALSE );
266 lResult = 1; /* success. FIXME: check text length */
270 if (style == SS_ICON)
275 if (style == SS_BITMAP)
280 infoPtr->hFont = (HFONT16)wParam;
283 InvalidateRect( hWnd, NULL, FALSE );
284 UpdateWindow( hWnd );
289 lResult = infoPtr->hFont;
293 if (wndPtr->dwStyle & SS_NOTIFY)
296 lResult = HTTRANSPARENT;
300 lResult = DLGC_STATIC;
306 lResult = infoPtr->hIcon;
312 lResult = STATIC_SetBitmap( wndPtr, (HBITMAP)lParam );
315 lResult = STATIC_SetIcon( wndPtr, (HICON16)lParam );
318 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
321 InvalidateRect( hWnd, NULL, FALSE );
322 UpdateWindow( hWnd );
327 lResult = STATIC_SetIcon( wndPtr, (HICON16)wParam );
328 InvalidateRect( hWnd, NULL, FALSE );
329 UpdateWindow( hWnd );
333 lResult = DefWindowProcA(hWnd, uMsg, wParam, lParam);
338 WIN_ReleaseWndPtr(wndPtr);
342 static void STATIC_PaintOwnerDrawfn( WND *wndPtr, HDC hdc )
346 dis.CtlType = ODT_STATIC;
347 dis.CtlID = wndPtr->wIDmenu;
349 dis.itemAction = ODA_DRAWENTIRE;
351 dis.hwndItem = wndPtr->hwndSelf;
354 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
356 SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
357 hdc, wndPtr->hwndSelf );
358 SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
359 wndPtr->wIDmenu, (LPARAM)&dis );
362 static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc )
368 LONG style = wndPtr->dwStyle;
369 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
371 GetClientRect( wndPtr->hwndSelf, &rc);
373 switch (style & SS_TYPEMASK)
376 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
380 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
384 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
388 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
391 case SS_LEFTNOWORDWRAP:
392 wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
399 if (style & SS_NOPREFIX)
400 wFormat |= DT_NOPREFIX;
402 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
404 if ((style & SS_NOPREFIX) || ((style & SS_TYPEMASK) != SS_SIMPLE))
406 hBrush = SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
407 hdc, wndPtr->hwndSelf );
408 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
409 FillRect( hdc, &rc, hBrush );
411 if (!IsWindowEnabled(wndPtr->hwndSelf))
412 SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
414 if (wndPtr->text) DrawTextW( hdc, wndPtr->text, -1, &rc, wFormat );
417 static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc )
422 GetClientRect( wndPtr->hwndSelf, &rc);
424 switch (wndPtr->dwStyle & SS_TYPEMASK)
427 hBrush = CreateSolidBrush(color_windowframe);
428 FillRect( hdc, &rc, hBrush );
431 hBrush = CreateSolidBrush(color_background);
432 FillRect( hdc, &rc, hBrush );
435 hBrush = CreateSolidBrush(color_window);
436 FillRect( hdc, &rc, hBrush );
439 hBrush = CreateSolidBrush(color_windowframe);
440 FrameRect( hdc, &rc, hBrush );
443 hBrush = CreateSolidBrush(color_background);
444 FrameRect( hdc, &rc, hBrush );
447 hBrush = CreateSolidBrush(color_window);
448 FrameRect( hdc, &rc, hBrush );
453 DeleteObject( hBrush );
457 static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc )
461 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
463 GetClientRect( wndPtr->hwndSelf, &rc );
464 hbrush = SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
465 hdc, wndPtr->hwndSelf );
466 FillRect( hdc, &rc, hbrush );
467 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );
470 static void STATIC_PaintBitmapfn(WND *wndPtr, HDC hdc )
474 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
478 GetClientRect( wndPtr->hwndSelf, &rc );
479 hbrush = SendMessageA( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
480 hdc, wndPtr->hwndSelf );
481 FillRect( hdc, &rc, hbrush );
483 if (infoPtr->hIcon) {
487 if(GetObjectType(infoPtr->hIcon) != OBJ_BITMAP)
489 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
490 GetObjectA(infoPtr->hIcon, sizeof(bm), &bm);
491 GetBitmapDimensionEx(infoPtr->hIcon, &sz);
492 oldbitmap = SelectObject(hMemDC, infoPtr->hIcon);
493 BitBlt(hdc, sz.cx, sz.cy, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
495 SelectObject(hMemDC, oldbitmap);
501 static void STATIC_PaintEtchedfn( WND *wndPtr, HDC hdc )
505 if (TWEAK_WineLook == WIN31_LOOK)
508 GetClientRect( wndPtr->hwndSelf, &rc );
509 switch (wndPtr->dwStyle & SS_TYPEMASK)
512 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
515 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
518 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);