4 * Copyright David W. Metcalfe, 1993
13 static void STATIC_PaintTextfn( WND *wndPtr, HDC32 hdc );
14 static void STATIC_PaintRectfn( WND *wndPtr, HDC32 hdc );
15 static void STATIC_PaintIconfn( WND *wndPtr, HDC32 hdc );
18 static COLORREF color_windowframe, color_background, color_window;
21 typedef void (*pfPaint)( WND *, HDC32 );
23 #define LAST_STATIC_TYPE SS_LEFTNOWORDWRAP
25 static pfPaint staticPaintFunc[LAST_STATIC_TYPE+1] =
27 STATIC_PaintTextfn, /* SS_LEFT */
28 STATIC_PaintTextfn, /* SS_CENTER */
29 STATIC_PaintTextfn, /* SS_RIGHT */
30 STATIC_PaintIconfn, /* SS_ICON */
31 STATIC_PaintRectfn, /* SS_BLACKRECT */
32 STATIC_PaintRectfn, /* SS_GRAYRECT */
33 STATIC_PaintRectfn, /* SS_WHITERECT */
34 STATIC_PaintRectfn, /* SS_BLACKFRAME */
35 STATIC_PaintRectfn, /* SS_GRAYFRAME */
36 STATIC_PaintRectfn, /* SS_WHITEFRAME */
37 NULL, /* Not defined */
38 STATIC_PaintTextfn, /* SS_SIMPLE */
39 STATIC_PaintTextfn /* SS_LEFTNOWORDWRAP */
43 /***********************************************************************
46 * Set the icon for an SS_ICON control.
48 static HICON16 STATIC_SetIcon( WND *wndPtr, HICON16 hicon )
51 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
53 if ((wndPtr->dwStyle & 0x0f) != SS_ICON) return 0;
54 prevIcon = infoPtr->hIcon;
55 infoPtr->hIcon = hicon;
58 CURSORICONINFO *info = (CURSORICONINFO *) GlobalLock16( hicon );
59 SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, info->nWidth, info->nHeight,
60 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
61 GlobalUnlock16( hicon );
67 /***********************************************************************
70 LRESULT StaticWndProc(HWND hWnd, UINT uMsg, WPARAM16 wParam, LPARAM lParam)
73 WND *wndPtr = WIN_FindWndPtr(hWnd);
74 LONG style = wndPtr->dwStyle & 0x0000000F;
75 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
80 InvalidateRect32( hWnd, NULL, FALSE );
86 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
89 HICON16 hicon = LoadIcon16( cs->hInstance, cs->lpszName );
90 if (!hicon) /* Try OEM icon (FIXME: is this right?) */
91 hicon = LoadIcon16( 0, cs->lpszName );
92 STATIC_SetIcon( wndPtr, hicon );
96 return DefWindowProc16(hWnd, uMsg, wParam, lParam);
99 if (style < 0L || style > LAST_STATIC_TYPE)
101 fprintf( stderr, "STATIC: Unknown style 0x%02lx\n", style );
105 /* initialise colours */
106 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
107 color_background = GetSysColor(COLOR_BACKGROUND);
108 color_window = GetSysColor(COLOR_WINDOW);
112 if (style == SS_ICON)
113 DestroyIcon( STATIC_SetIcon( wndPtr, 0 ) );
115 lResult = DefWindowProc16(hWnd, uMsg, wParam, lParam);
121 BeginPaint16( hWnd, &ps );
122 if (staticPaintFunc[style])
123 (staticPaintFunc[style])( wndPtr, ps.hdc );
124 EndPaint16( hWnd, &ps );
128 case WM_SYSCOLORCHANGE:
129 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
130 color_background = GetSysColor(COLOR_BACKGROUND);
131 color_window = GetSysColor(COLOR_WINDOW);
132 InvalidateRect32( hWnd, NULL, TRUE );
136 if (style == SS_ICON)
137 /* FIXME : should we also return the previous hIcon here ??? */
138 STATIC_SetIcon( wndPtr, LoadIcon16( wndPtr->hInstance,
141 DEFWND_SetText( wndPtr, (LPSTR)PTR_SEG_TO_LIN(lParam) );
142 InvalidateRect32( hWnd, NULL, FALSE );
143 UpdateWindow( hWnd );
147 if (style == SS_ICON) return 0;
148 infoPtr->hFont = (HFONT16)wParam;
151 InvalidateRect32( hWnd, NULL, FALSE );
152 UpdateWindow( hWnd );
157 return infoPtr->hFont;
160 return HTTRANSPARENT;
166 return infoPtr->hIcon;
169 lResult = STATIC_SetIcon( wndPtr, (HICON16)wParam );
170 InvalidateRect32( hWnd, NULL, FALSE );
171 UpdateWindow( hWnd );
175 lResult = DefWindowProc16(hWnd, uMsg, wParam, lParam);
183 static void STATIC_PaintTextfn( WND *wndPtr, HDC32 hdc )
189 LONG style = wndPtr->dwStyle;
190 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
192 GetClientRect16( wndPtr->hwndSelf, &rc);
194 switch (style & 0x0000000F)
197 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
201 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
205 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
209 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
212 case SS_LEFTNOWORDWRAP:
213 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER | DT_NOCLIP;
220 if (style & SS_NOPREFIX)
221 wFormat |= DT_NOPREFIX;
223 if (infoPtr->hFont) SelectObject32( hdc, infoPtr->hFont );
224 hBrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
225 hdc, wndPtr->hwndSelf );
226 if (!hBrush) hBrush = GetStockObject32(WHITE_BRUSH);
227 FillRect16(hdc, &rc, hBrush);
228 if (wndPtr->text) DrawText16( hdc, wndPtr->text, -1, &rc, wFormat );
231 static void STATIC_PaintRectfn( WND *wndPtr, HDC32 hdc )
236 GetClientRect16( wndPtr->hwndSelf, &rc);
238 switch (wndPtr->dwStyle & 0x0f)
241 hBrush = CreateSolidBrush32(color_windowframe);
242 FillRect16( hdc, &rc, hBrush );
245 hBrush = CreateSolidBrush32(color_background);
246 FillRect16( hdc, &rc, hBrush );
249 hBrush = CreateSolidBrush32(color_window);
250 FillRect16( hdc, &rc, hBrush );
253 hBrush = CreateSolidBrush32(color_windowframe);
254 FrameRect16( hdc, &rc, hBrush );
257 hBrush = CreateSolidBrush32(color_background);
258 FrameRect16( hdc, &rc, hBrush );
261 hBrush = CreateSolidBrush32(color_window);
262 FrameRect16( hdc, &rc, hBrush );
267 DeleteObject32( hBrush );
271 static void STATIC_PaintIconfn( WND *wndPtr, HDC32 hdc )
275 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
277 GetClientRect16( wndPtr->hwndSelf, &rc);
278 hbrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
279 hdc, wndPtr->hwndSelf );
280 FillRect16( hdc, &rc, hbrush );
281 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );