Release 950109
[wine/multimedia.git] / controls / static.c
blob85345d8edeaca94c849b4a3be47cc30d3fe9081a
1 /*
2 * Static control
4 * Copyright David W. Metcalfe, 1993
6 static char Copyright[] = "Copyright David W. Metcalfe, 1993";
7 */
9 #include <stdio.h>
10 #include <windows.h>
11 #include "win.h"
12 #include "user.h"
13 #include "static.h"
14 #include "icon.h"
16 extern void DEFWND_SetText( HWND hwnd, LPSTR text ); /* windows/defwnd.c */
18 static void PaintTextfn( HWND hwnd, HDC hdc );
19 static void PaintRectfn( HWND hwnd, HDC hdc );
20 static void PaintFramefn( HWND hwnd, HDC hdc );
21 static void PaintIconfn( HWND hwnd, HDC hdc );
24 static COLORREF color_windowframe, color_background, color_window;
27 typedef void (*pfPaint)(HWND, HDC);
29 #define LAST_STATIC_TYPE SS_LEFTNOWORDWRAP
31 static pfPaint staticPaintFunc[LAST_STATIC_TYPE+1] =
33 PaintTextfn, /* SS_LEFT */
34 PaintTextfn, /* SS_CENTER */
35 PaintTextfn, /* SS_RIGHT */
36 PaintIconfn, /* SS_ICON */
37 PaintRectfn, /* SS_BLACKRECT */
38 PaintRectfn, /* SS_GRAYRECT */
39 PaintRectfn, /* SS_WHITERECT */
40 PaintFramefn, /* SS_BLACKFRAME */
41 PaintFramefn, /* SS_GRAYFRAME */
42 PaintFramefn, /* SS_WHITEFRAME */
43 NULL, /* Not defined */
44 PaintTextfn, /* SS_SIMPLE */
45 PaintTextfn /* SS_LEFTNOWORDWRAP */
49 /***********************************************************************
50 * STATIC_SetIcon
52 * Set the icon for an SS_ICON control.
54 static void STATIC_SetIcon( HWND hwnd, HICON hicon )
56 WND *wndPtr = WIN_FindWndPtr( hwnd );
57 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
59 if ((wndPtr->dwStyle & 0x0f) != SS_ICON) return;
60 if (infoPtr->hIcon) DestroyIcon( infoPtr->hIcon );
61 infoPtr->hIcon = hicon;
62 if (hicon)
64 ICONALLOC *icon = (ICONALLOC *) GlobalLock( hicon );
65 SetWindowPos( hwnd, 0, 0, 0,
66 icon->descriptor.Width, icon->descriptor.Height,
67 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
68 GlobalUnlock( hicon );
73 /***********************************************************************
74 * StaticWndProc
76 LONG StaticWndProc(HWND hWnd, WORD uMsg, WORD wParam, LONG lParam)
78 LONG lResult = 0;
79 WND *wndPtr = WIN_FindWndPtr(hWnd);
80 LONG style = wndPtr->dwStyle & 0x0000000F;
81 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
83 switch (uMsg) {
84 case WM_ENABLE:
85 InvalidateRect(hWnd, NULL, FALSE);
86 break;
88 case WM_NCCREATE:
89 if (style == SS_ICON)
91 CREATESTRUCT * createStruct = (CREATESTRUCT *)lParam;
92 if (createStruct->lpszName)
93 STATIC_SetIcon( hWnd, LoadIcon( createStruct->hInstance,
94 createStruct->lpszName ));
95 return 1;
97 return DefWindowProc(hWnd, uMsg, wParam, lParam);
99 case WM_CREATE:
100 if (style < 0L || style > LAST_STATIC_TYPE)
102 fprintf( stderr, "STATIC: Unknown style 0x%02lx\n", style );
103 lResult = -1L;
104 break;
106 /* initialise colours */
107 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
108 color_background = GetSysColor(COLOR_BACKGROUND);
109 color_window = GetSysColor(COLOR_WINDOW);
110 break;
112 case WM_NCDESTROY:
113 if (style == SS_ICON)
114 STATIC_SetIcon( hWnd, 0 ); /* Destroy the current icon */
115 else
116 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
117 break;
119 case WM_PAINT:
121 PAINTSTRUCT ps;
122 BeginPaint( hWnd, &ps );
123 if (staticPaintFunc[style])
124 (staticPaintFunc[style])( hWnd, ps.hdc );
125 EndPaint( hWnd, &ps );
127 break;
129 case WM_SYSCOLORCHANGE:
130 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
131 color_background = GetSysColor(COLOR_BACKGROUND);
132 color_window = GetSysColor(COLOR_WINDOW);
133 InvalidateRect(hWnd, NULL, TRUE);
134 break;
136 case WM_SETTEXT:
137 DEFWND_SetText( hWnd, (LPSTR)lParam );
138 InvalidateRect( hWnd, NULL, FALSE );
139 UpdateWindow( hWnd );
140 break;
142 case WM_SETFONT:
143 if (style == SS_ICON) return 0;
144 infoPtr->hFont = wParam;
145 if (LOWORD(lParam))
147 InvalidateRect( hWnd, NULL, FALSE );
148 UpdateWindow( hWnd );
150 break;
152 case WM_GETFONT:
153 return infoPtr->hFont;
155 case WM_NCHITTEST:
156 return HTTRANSPARENT;
158 case WM_GETDLGCODE:
159 return DLGC_STATIC;
161 case STM_GETICON:
162 return infoPtr->hIcon;
164 case STM_SETICON:
165 STATIC_SetIcon( hWnd, wParam );
166 InvalidateRect( hWnd, NULL, FALSE );
167 UpdateWindow( hWnd );
168 return 0;
170 default:
171 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
172 break;
175 return lResult;
179 static void PaintTextfn( HWND hwnd, HDC hdc )
181 RECT rc;
182 HBRUSH hBrush;
183 char *text;
184 WORD wFormat;
186 WND *wndPtr = WIN_FindWndPtr(hwnd);
187 LONG style = wndPtr->dwStyle;
188 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
190 GetClientRect(hwnd, &rc);
191 text = USER_HEAP_ADDR( wndPtr->hText );
193 switch (style & 0x0000000F)
195 case SS_LEFT:
196 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
197 break;
199 case SS_CENTER:
200 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
201 break;
203 case SS_RIGHT:
204 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
205 break;
207 case SS_SIMPLE:
208 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER;
209 break;
211 case SS_LEFTNOWORDWRAP:
212 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER;
213 break;
215 default:
216 return;
219 if (style & SS_NOPREFIX)
220 wFormat |= DT_NOPREFIX;
222 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
223 hBrush = SendMessage( wndPtr->hwndParent, WM_CTLCOLOR, (WORD)hdc,
224 MAKELONG(hwnd, CTLCOLOR_STATIC));
225 if (hBrush == (HBRUSH)NULL) hBrush = GetStockObject(WHITE_BRUSH);
226 FillRect(hdc, &rc, hBrush);
227 if (text)
228 DrawText(hdc, text, -1, &rc, wFormat);
231 static void PaintRectfn( HWND hwnd, HDC hdc )
233 RECT rc;
234 HBRUSH hBrush;
236 WND *wndPtr = WIN_FindWndPtr(hwnd);
238 GetClientRect(hwnd, &rc);
240 switch (wndPtr->dwStyle & 0x0000000F)
242 case SS_BLACKRECT:
243 hBrush = CreateSolidBrush(color_windowframe);
244 break;
246 case SS_GRAYRECT:
247 hBrush = CreateSolidBrush(color_background);
248 break;
250 case SS_WHITERECT:
251 hBrush = CreateSolidBrush(color_window);
252 break;
254 default:
255 return;
257 FillRect( hdc, &rc, hBrush );
260 static void PaintFramefn( HWND hwnd, HDC hdc )
262 RECT rc;
263 HPEN hOldPen, hPen;
264 HBRUSH hOldBrush, hBrush;
266 WND *wndPtr = WIN_FindWndPtr(hwnd);
268 GetClientRect(hwnd, &rc);
270 switch (wndPtr->dwStyle & 0x0000000F)
272 case SS_BLACKFRAME:
273 hPen = CreatePen(PS_SOLID, 1, color_windowframe);
274 break;
276 case SS_GRAYFRAME:
277 hPen = CreatePen(PS_SOLID, 1, color_background);
278 break;
280 case SS_WHITEFRAME:
281 hPen = CreatePen(PS_SOLID, 1, color_window);
282 break;
284 default:
285 return;
288 hBrush = CreateSolidBrush(color_window);
289 hOldPen = (HPEN)SelectObject(hdc, (HANDLE)hPen);
290 hOldBrush = (HBRUSH)SelectObject(hdc, (HANDLE)hBrush);
291 Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
293 SelectObject(hdc, (HANDLE)hOldPen);
294 SelectObject(hdc, (HANDLE)hOldBrush);
295 DeleteObject((HANDLE)hPen);
296 DeleteObject((HANDLE)hBrush);
300 static void PaintIconfn( HWND hwnd, HDC hdc )
302 RECT rc;
303 HBRUSH hbrush;
304 WND *wndPtr = WIN_FindWndPtr(hwnd);
305 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
307 GetClientRect(hwnd, &rc);
308 hbrush = SendMessage( wndPtr->hwndParent, WM_CTLCOLOR, hdc,
309 MAKELONG(hwnd, CTLCOLOR_STATIC));
310 FillRect( hdc, &rc, hbrush );
311 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );