Release 951003
[wine/multimedia.git] / controls / static.c
blobb88dd2ff6382c6e3c471c6cb46f95819e6b3e1a0
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"
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 /***********************************************************************
48 * STATIC_SetIcon
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;
58 if (infoPtr->hIcon) DestroyIcon( infoPtr->hIcon );
59 infoPtr->hIcon = hicon;
60 if (hicon)
62 CURSORICONINFO *info = (CURSORICONINFO *) GlobalLock( hicon );
63 SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
64 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
65 GlobalUnlock( hicon );
70 /***********************************************************************
71 * StaticWndProc
73 LONG StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
75 LONG lResult = 0;
76 WND *wndPtr = WIN_FindWndPtr(hWnd);
77 LONG style = wndPtr->dwStyle & 0x0000000F;
78 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
80 switch (uMsg) {
81 case WM_ENABLE:
82 InvalidateRect(hWnd, NULL, FALSE);
83 break;
85 case WM_NCCREATE:
86 if (style == SS_ICON)
88 CREATESTRUCT * createStruct = (CREATESTRUCT *)PTR_SEG_TO_LIN(lParam);
89 if (createStruct->lpszName)
90 STATIC_SetIcon( hWnd, LoadIcon( createStruct->hInstance,
91 (SEGPTR)createStruct->lpszName ));
92 return 1;
94 return DefWindowProc(hWnd, uMsg, wParam, lParam);
96 case WM_CREATE:
97 if (style < 0L || style > LAST_STATIC_TYPE)
99 fprintf( stderr, "STATIC: Unknown style 0x%02lx\n", style );
100 lResult = -1L;
101 break;
103 /* initialise colours */
104 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
105 color_background = GetSysColor(COLOR_BACKGROUND);
106 color_window = GetSysColor(COLOR_WINDOW);
107 break;
109 case WM_NCDESTROY:
110 if (style == SS_ICON)
111 STATIC_SetIcon( hWnd, 0 ); /* Destroy the current icon */
112 else
113 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
114 break;
116 case WM_PAINT:
118 PAINTSTRUCT ps;
119 BeginPaint( hWnd, &ps );
120 if (staticPaintFunc[style])
121 (staticPaintFunc[style])( hWnd, ps.hdc );
122 EndPaint( hWnd, &ps );
124 break;
126 case WM_SYSCOLORCHANGE:
127 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
128 color_background = GetSysColor(COLOR_BACKGROUND);
129 color_window = GetSysColor(COLOR_WINDOW);
130 InvalidateRect(hWnd, NULL, TRUE);
131 break;
133 case WM_SETTEXT:
134 if (style == SS_ICON)
135 STATIC_SetIcon( hWnd, LoadIcon( wndPtr->hInstance,
136 (SEGPTR)lParam ));
137 else
138 DEFWND_SetText( hWnd, (LPSTR)PTR_SEG_TO_LIN(lParam) );
139 InvalidateRect( hWnd, NULL, FALSE );
140 UpdateWindow( hWnd );
141 break;
143 case WM_SETFONT:
144 if (style == SS_ICON) return 0;
145 infoPtr->hFont = (HFONT)wParam;
146 if (LOWORD(lParam))
148 InvalidateRect( hWnd, NULL, FALSE );
149 UpdateWindow( hWnd );
151 break;
153 case WM_GETFONT:
154 return (LONG)infoPtr->hFont;
156 case WM_NCHITTEST:
157 return HTTRANSPARENT;
159 case WM_GETDLGCODE:
160 return DLGC_STATIC;
162 case STM_GETICON:
163 return (LONG)infoPtr->hIcon;
165 case STM_SETICON:
166 STATIC_SetIcon( hWnd, (HICON)wParam );
167 InvalidateRect( hWnd, NULL, FALSE );
168 UpdateWindow( hWnd );
169 return 0;
171 default:
172 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
173 break;
176 return lResult;
180 static void PaintTextfn( HWND hwnd, HDC hdc )
182 RECT rc;
183 HBRUSH hBrush;
184 char *text;
185 WORD wFormat;
187 WND *wndPtr = WIN_FindWndPtr(hwnd);
188 LONG style = wndPtr->dwStyle;
189 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
191 GetClientRect(hwnd, &rc);
192 text = USER_HEAP_LIN_ADDR( wndPtr->hText );
194 switch (style & 0x0000000F)
196 case SS_LEFT:
197 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
198 break;
200 case SS_CENTER:
201 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
202 break;
204 case SS_RIGHT:
205 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
206 break;
208 case SS_SIMPLE:
209 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER;
210 break;
212 case SS_LEFTNOWORDWRAP:
213 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER;
214 break;
216 default:
217 return;
220 if (style & SS_NOPREFIX)
221 wFormat |= DT_NOPREFIX;
223 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
224 #ifdef WINELIB32
225 hBrush = (HBRUSH)SendMessage( wndPtr->hwndParent, WM_CTLCOLORSTATIC,
226 (WPARAM)hdc, (LPARAM)hwnd );
227 #else
228 hBrush = SendMessage( wndPtr->hwndParent, WM_CTLCOLOR, (WORD)hdc,
229 MAKELONG(hwnd, CTLCOLOR_STATIC));
230 #endif
231 if (hBrush == (HBRUSH)NULL) hBrush = GetStockObject(WHITE_BRUSH);
232 FillRect(hdc, &rc, hBrush);
233 if (text)
234 DrawText(hdc, text, -1, &rc, wFormat);
237 static void PaintRectfn( HWND hwnd, HDC hdc )
239 RECT rc;
240 HBRUSH hBrush;
242 WND *wndPtr = WIN_FindWndPtr(hwnd);
244 GetClientRect(hwnd, &rc);
246 switch (wndPtr->dwStyle & 0x0f)
248 case SS_BLACKRECT:
249 hBrush = CreateSolidBrush(color_windowframe);
250 FillRect( hdc, &rc, hBrush );
251 break;
252 case SS_GRAYRECT:
253 hBrush = CreateSolidBrush(color_background);
254 FillRect( hdc, &rc, hBrush );
255 break;
256 case SS_WHITERECT:
257 hBrush = CreateSolidBrush(color_window);
258 FillRect( hdc, &rc, hBrush );
259 break;
260 case SS_BLACKFRAME:
261 hBrush = CreateSolidBrush(color_windowframe);
262 FrameRect( hdc, &rc, hBrush );
263 break;
264 case SS_GRAYFRAME:
265 hBrush = CreateSolidBrush(color_background);
266 FrameRect( hdc, &rc, hBrush );
267 break;
268 case SS_WHITEFRAME:
269 hBrush = CreateSolidBrush(color_window);
270 FrameRect( hdc, &rc, hBrush );
271 break;
272 default:
273 return;
275 DeleteObject( hBrush );
279 static void PaintIconfn( HWND hwnd, HDC hdc )
281 RECT rc;
282 HBRUSH hbrush;
283 WND *wndPtr = WIN_FindWndPtr(hwnd);
284 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
286 GetClientRect(hwnd, &rc);
287 #ifdef WINELIB32
288 hbrush = (HBRUSH)SendMessage( wndPtr->hwndParent, WM_CTLCOLORSTATIC,
289 (WPARAM)hdc, (LPARAM)hwnd );
290 #else
291 hbrush = SendMessage( wndPtr->hwndParent, WM_CTLCOLOR, hdc,
292 MAKELONG(hwnd, CTLCOLOR_STATIC));
293 #endif
294 FillRect( hdc, &rc, hbrush );
295 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );