4 * Copyright David W. Metcalfe, 1993
6 static char Copyright[] = "Copyright David W. Metcalfe, 1993";
15 extern void DEFWND_SetText( HWND hwnd
, LPSTR text
); /* windows/defwnd.c */
17 static void PaintTextfn( HWND hwnd
, HDC hdc
);
18 static void PaintRectfn( HWND hwnd
, HDC hdc
);
19 static void PaintIconfn( HWND hwnd
, HDC hdc
);
22 static COLORREF color_windowframe
, color_background
, color_window
;
25 typedef void (*pfPaint
)(HWND
, HDC
);
27 #define LAST_STATIC_TYPE SS_LEFTNOWORDWRAP
29 static pfPaint staticPaintFunc
[LAST_STATIC_TYPE
+1] =
31 PaintTextfn
, /* SS_LEFT */
32 PaintTextfn
, /* SS_CENTER */
33 PaintTextfn
, /* SS_RIGHT */
34 PaintIconfn
, /* SS_ICON */
35 PaintRectfn
, /* SS_BLACKRECT */
36 PaintRectfn
, /* SS_GRAYRECT */
37 PaintRectfn
, /* SS_WHITERECT */
38 PaintRectfn
, /* SS_BLACKFRAME */
39 PaintRectfn
, /* SS_GRAYFRAME */
40 PaintRectfn
, /* SS_WHITEFRAME */
41 NULL
, /* Not defined */
42 PaintTextfn
, /* SS_SIMPLE */
43 PaintTextfn
/* SS_LEFTNOWORDWRAP */
47 /***********************************************************************
50 * Set the icon for an SS_ICON control.
52 static void STATIC_SetIcon( HWND hwnd
, HICON hicon
)
54 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
55 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
57 if ((wndPtr
->dwStyle
& 0x0f) != SS_ICON
) return;
59 if (infoPtr->hIcon) DestroyIcon( infoPtr->hIcon ); */
60 infoPtr
->hIcon
= hicon
;
63 CURSORICONINFO
*info
= (CURSORICONINFO
*) GlobalLock( hicon
);
64 SetWindowPos( hwnd
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
65 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
66 GlobalUnlock( hicon
);
71 /***********************************************************************
74 LONG
StaticWndProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
77 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
78 LONG style
= wndPtr
->dwStyle
& 0x0000000F;
79 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
83 InvalidateRect(hWnd
, NULL
, FALSE
);
89 CREATESTRUCT
* createStruct
= (CREATESTRUCT
*)PTR_SEG_TO_LIN(lParam
);
90 if (createStruct
->lpszName
)
91 STATIC_SetIcon( hWnd
, LoadIcon( createStruct
->hInstance
,
92 (SEGPTR
)createStruct
->lpszName
));
95 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
98 if (style
< 0L || style
> LAST_STATIC_TYPE
)
100 fprintf( stderr
, "STATIC: Unknown style 0x%02lx\n", style
);
104 /* initialise colours */
105 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
106 color_background
= GetSysColor(COLOR_BACKGROUND
);
107 color_window
= GetSysColor(COLOR_WINDOW
);
111 if (style
== SS_ICON
)
112 STATIC_SetIcon( hWnd
, 0 ); /* Destroy the current icon */
114 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
120 BeginPaint( hWnd
, &ps
);
121 if (staticPaintFunc
[style
])
122 (staticPaintFunc
[style
])( hWnd
, ps
.hdc
);
123 EndPaint( hWnd
, &ps
);
127 case WM_SYSCOLORCHANGE
:
128 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
129 color_background
= GetSysColor(COLOR_BACKGROUND
);
130 color_window
= GetSysColor(COLOR_WINDOW
);
131 InvalidateRect(hWnd
, NULL
, TRUE
);
135 if (style
== SS_ICON
)
136 STATIC_SetIcon( hWnd
, LoadIcon( wndPtr
->hInstance
,
139 DEFWND_SetText( hWnd
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
140 InvalidateRect( hWnd
, NULL
, FALSE
);
141 UpdateWindow( hWnd
);
145 if (style
== SS_ICON
) return 0;
146 infoPtr
->hFont
= (HFONT
)wParam
;
149 InvalidateRect( hWnd
, NULL
, FALSE
);
150 UpdateWindow( hWnd
);
155 return (LONG
)infoPtr
->hFont
;
158 return HTTRANSPARENT
;
164 return (LONG
)infoPtr
->hIcon
;
167 STATIC_SetIcon( hWnd
, (HICON
)wParam
);
168 InvalidateRect( hWnd
, NULL
, FALSE
);
169 UpdateWindow( hWnd
);
173 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
181 static void PaintTextfn( HWND hwnd
, HDC hdc
)
188 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
189 LONG style
= wndPtr
->dwStyle
;
190 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
192 GetClientRect(hwnd
, &rc
);
193 text
= USER_HEAP_LIN_ADDR( wndPtr
->hText
);
195 switch (style
& 0x0000000F)
198 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
202 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
206 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
210 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
;
213 case SS_LEFTNOWORDWRAP
:
214 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_EXPANDTABS
| DT_VCENTER
;
221 if (style
& SS_NOPREFIX
)
222 wFormat
|= DT_NOPREFIX
;
224 if (infoPtr
->hFont
) SelectObject( hdc
, infoPtr
->hFont
);
226 hBrush
= (HBRUSH
)SendMessage( wndPtr
->hwndParent
, WM_CTLCOLORSTATIC
,
227 (WPARAM
)hdc
, (LPARAM
)hwnd
);
229 hBrush
= SendMessage( wndPtr
->hwndParent
, WM_CTLCOLOR
, (WORD
)hdc
,
230 MAKELONG(hwnd
, CTLCOLOR_STATIC
));
232 if (hBrush
== (HBRUSH
)NULL
) hBrush
= GetStockObject(WHITE_BRUSH
);
233 FillRect(hdc
, &rc
, hBrush
);
235 DrawText(hdc
, text
, -1, &rc
, wFormat
);
238 static void PaintRectfn( HWND hwnd
, HDC hdc
)
243 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
245 GetClientRect(hwnd
, &rc
);
247 switch (wndPtr
->dwStyle
& 0x0f)
250 hBrush
= CreateSolidBrush(color_windowframe
);
251 FillRect( hdc
, &rc
, hBrush
);
254 hBrush
= CreateSolidBrush(color_background
);
255 FillRect( hdc
, &rc
, hBrush
);
258 hBrush
= CreateSolidBrush(color_window
);
259 FillRect( hdc
, &rc
, hBrush
);
262 hBrush
= CreateSolidBrush(color_windowframe
);
263 FrameRect( hdc
, &rc
, hBrush
);
266 hBrush
= CreateSolidBrush(color_background
);
267 FrameRect( hdc
, &rc
, hBrush
);
270 hBrush
= CreateSolidBrush(color_window
);
271 FrameRect( hdc
, &rc
, hBrush
);
276 DeleteObject( hBrush
);
280 static void PaintIconfn( HWND hwnd
, HDC hdc
)
284 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
285 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
287 GetClientRect(hwnd
, &rc
);
289 hbrush
= (HBRUSH
)SendMessage( wndPtr
->hwndParent
, WM_CTLCOLORSTATIC
,
290 (WPARAM
)hdc
, (LPARAM
)hwnd
);
292 hbrush
= SendMessage( wndPtr
->hwndParent
, WM_CTLCOLOR
, hdc
,
293 MAKELONG(hwnd
, CTLCOLOR_STATIC
));
295 FillRect( hdc
, &rc
, hbrush
);
296 if (infoPtr
->hIcon
) DrawIcon( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);