Release 950319
[wine/multimedia.git] / controls / static.c
blob063ad237ebfcae8c48f0eb1ffdbcd3d2dd7a1e7f
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 *)PTR_SEG_TO_LIN(lParam);
92 if (createStruct->lpszName)
93 STATIC_SetIcon( hWnd, LoadIcon( createStruct->hInstance,
94 (SEGPTR)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 if (style == SS_ICON)
138 STATIC_SetIcon( hWnd, LoadIcon( wndPtr->hInstance,
139 (SEGPTR)lParam ));
140 else
141 DEFWND_SetText( hWnd, (LPSTR)PTR_SEG_TO_LIN(lParam) );
142 InvalidateRect( hWnd, NULL, FALSE );
143 UpdateWindow( hWnd );
144 break;
146 case WM_SETFONT:
147 if (style == SS_ICON) return 0;
148 infoPtr->hFont = wParam;
149 if (LOWORD(lParam))
151 InvalidateRect( hWnd, NULL, FALSE );
152 UpdateWindow( hWnd );
154 break;
156 case WM_GETFONT:
157 return infoPtr->hFont;
159 case WM_NCHITTEST:
160 return HTTRANSPARENT;
162 case WM_GETDLGCODE:
163 return DLGC_STATIC;
165 case STM_GETICON:
166 return infoPtr->hIcon;
168 case STM_SETICON:
169 STATIC_SetIcon( hWnd, wParam );
170 InvalidateRect( hWnd, NULL, FALSE );
171 UpdateWindow( hWnd );
172 return 0;
174 default:
175 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
176 break;
179 return lResult;
183 static void PaintTextfn( HWND hwnd, HDC hdc )
185 RECT rc;
186 HBRUSH hBrush;
187 char *text;
188 WORD wFormat;
190 WND *wndPtr = WIN_FindWndPtr(hwnd);
191 LONG style = wndPtr->dwStyle;
192 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
194 GetClientRect(hwnd, &rc);
195 text = USER_HEAP_LIN_ADDR( wndPtr->hText );
197 switch (style & 0x0000000F)
199 case SS_LEFT:
200 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
201 break;
203 case SS_CENTER:
204 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
205 break;
207 case SS_RIGHT:
208 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
209 break;
211 case SS_SIMPLE:
212 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER;
213 break;
215 case SS_LEFTNOWORDWRAP:
216 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER;
217 break;
219 default:
220 return;
223 if (style & SS_NOPREFIX)
224 wFormat |= DT_NOPREFIX;
226 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
227 hBrush = SendMessage( wndPtr->hwndParent, WM_CTLCOLOR, (WORD)hdc,
228 MAKELONG(hwnd, CTLCOLOR_STATIC));
229 if (hBrush == (HBRUSH)NULL) hBrush = GetStockObject(WHITE_BRUSH);
230 FillRect(hdc, &rc, hBrush);
231 if (text)
232 DrawText(hdc, text, -1, &rc, wFormat);
235 static void PaintRectfn( HWND hwnd, HDC hdc )
237 RECT rc;
238 HBRUSH hBrush;
240 WND *wndPtr = WIN_FindWndPtr(hwnd);
242 GetClientRect(hwnd, &rc);
244 switch (wndPtr->dwStyle & 0x0000000F)
246 case SS_BLACKRECT:
247 hBrush = CreateSolidBrush(color_windowframe);
248 break;
250 case SS_GRAYRECT:
251 hBrush = CreateSolidBrush(color_background);
252 break;
254 case SS_WHITERECT:
255 hBrush = CreateSolidBrush(color_window);
256 break;
258 default:
259 return;
261 FillRect( hdc, &rc, hBrush );
264 static void PaintFramefn( HWND hwnd, HDC hdc )
266 RECT rc;
267 HPEN hOldPen, hPen;
268 HBRUSH hOldBrush, hBrush;
270 WND *wndPtr = WIN_FindWndPtr(hwnd);
272 GetClientRect(hwnd, &rc);
274 switch (wndPtr->dwStyle & 0x0000000F)
276 case SS_BLACKFRAME:
277 hPen = CreatePen(PS_SOLID, 1, color_windowframe);
278 break;
280 case SS_GRAYFRAME:
281 hPen = CreatePen(PS_SOLID, 1, color_background);
282 break;
284 case SS_WHITEFRAME:
285 hPen = CreatePen(PS_SOLID, 1, color_window);
286 break;
288 default:
289 return;
292 hBrush = CreateSolidBrush(color_window);
293 hOldPen = (HPEN)SelectObject(hdc, (HANDLE)hPen);
294 hOldBrush = (HBRUSH)SelectObject(hdc, (HANDLE)hBrush);
295 Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
297 SelectObject(hdc, (HANDLE)hOldPen);
298 SelectObject(hdc, (HANDLE)hOldBrush);
299 DeleteObject((HANDLE)hPen);
300 DeleteObject((HANDLE)hBrush);
304 static void PaintIconfn( HWND hwnd, HDC hdc )
306 RECT rc;
307 HBRUSH hbrush;
308 WND *wndPtr = WIN_FindWndPtr(hwnd);
309 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
311 GetClientRect(hwnd, &rc);
312 hbrush = SendMessage( wndPtr->hwndParent, WM_CTLCOLOR, hdc,
313 MAKELONG(hwnd, CTLCOLOR_STATIC));
314 FillRect( hdc, &rc, hbrush );
315 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );