Release 960717
[wine/multimedia.git] / controls / static.c
blob72ded6450db4a99c0d3932e8468d7e1a538f6565
1 /*
2 * Static control
4 * Copyright David W. Metcalfe, 1993
6 */
8 #include <stdio.h>
9 #include <windows.h>
10 #include "win.h"
11 #include "user.h"
12 #include "static.h"
14 static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc );
15 static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc );
16 static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc );
19 static COLORREF color_windowframe, color_background, color_window;
22 typedef void (*pfPaint)( WND *, HDC);
24 #define LAST_STATIC_TYPE SS_LEFTNOWORDWRAP
26 static pfPaint staticPaintFunc[LAST_STATIC_TYPE+1] =
28 STATIC_PaintTextfn, /* SS_LEFT */
29 STATIC_PaintTextfn, /* SS_CENTER */
30 STATIC_PaintTextfn, /* SS_RIGHT */
31 STATIC_PaintIconfn, /* SS_ICON */
32 STATIC_PaintRectfn, /* SS_BLACKRECT */
33 STATIC_PaintRectfn, /* SS_GRAYRECT */
34 STATIC_PaintRectfn, /* SS_WHITERECT */
35 STATIC_PaintRectfn, /* SS_BLACKFRAME */
36 STATIC_PaintRectfn, /* SS_GRAYFRAME */
37 STATIC_PaintRectfn, /* SS_WHITEFRAME */
38 NULL, /* Not defined */
39 STATIC_PaintTextfn, /* SS_SIMPLE */
40 STATIC_PaintTextfn /* SS_LEFTNOWORDWRAP */
44 /***********************************************************************
45 * STATIC_SetIcon
47 * Set the icon for an SS_ICON control.
49 static HICON STATIC_SetIcon( WND *wndPtr, HICON hicon )
51 HICON prevIcon;
52 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
54 if ((wndPtr->dwStyle & 0x0f) != SS_ICON) return 0;
55 prevIcon = infoPtr->hIcon;
56 infoPtr->hIcon = hicon;
57 if (hicon)
59 CURSORICONINFO *info = (CURSORICONINFO *) GlobalLock16( hicon );
60 SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, info->nWidth, info->nHeight,
61 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
62 GlobalUnlock16( hicon );
64 return prevIcon;
68 /***********************************************************************
69 * StaticWndProc
71 LRESULT StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
73 LRESULT lResult = 0;
74 WND *wndPtr = WIN_FindWndPtr(hWnd);
75 LONG style = wndPtr->dwStyle & 0x0000000F;
76 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
78 switch (uMsg)
80 case WM_ENABLE:
81 InvalidateRect32( hWnd, NULL, FALSE );
82 break;
84 case WM_NCCREATE:
85 if (style == SS_ICON)
87 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
88 if (cs->lpszName)
90 HICON16 hicon = LoadIcon16( cs->hInstance, cs->lpszName );
91 if (!hicon) /* Try OEM icon (FIXME: is this right?) */
92 hicon = LoadIcon16( 0, cs->lpszName );
93 STATIC_SetIcon( wndPtr, hicon );
95 return 1;
97 return DefWindowProc16(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 DestroyIcon( STATIC_SetIcon( wndPtr, 0 ) );
115 else
116 lResult = DefWindowProc16(hWnd, uMsg, wParam, lParam);
117 break;
119 case WM_PAINT:
121 PAINTSTRUCT16 ps;
122 BeginPaint16( hWnd, &ps );
123 if (staticPaintFunc[style])
124 (staticPaintFunc[style])( wndPtr, ps.hdc );
125 EndPaint16( 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 InvalidateRect32( hWnd, NULL, TRUE );
134 break;
136 case WM_SETTEXT:
137 if (style == SS_ICON)
138 /* FIXME : should we also return the previous hIcon here ??? */
139 STATIC_SetIcon( wndPtr, LoadIcon16( wndPtr->hInstance,
140 (SEGPTR)lParam ));
141 else
142 DEFWND_SetText( wndPtr, (LPSTR)PTR_SEG_TO_LIN(lParam) );
143 InvalidateRect32( hWnd, NULL, FALSE );
144 UpdateWindow( hWnd );
145 break;
147 case WM_SETFONT:
148 if (style == SS_ICON) return 0;
149 infoPtr->hFont = (HFONT)wParam;
150 if (LOWORD(lParam))
152 InvalidateRect32( hWnd, NULL, FALSE );
153 UpdateWindow( hWnd );
155 break;
157 case WM_GETFONT:
158 return infoPtr->hFont;
160 case WM_NCHITTEST:
161 return HTTRANSPARENT;
163 case WM_GETDLGCODE:
164 return DLGC_STATIC;
166 case STM_GETICON:
167 return infoPtr->hIcon;
169 case STM_SETICON:
170 lResult = STATIC_SetIcon( wndPtr, (HICON)wParam );
171 InvalidateRect32( hWnd, NULL, FALSE );
172 UpdateWindow( hWnd );
173 break;
175 default:
176 lResult = DefWindowProc16(hWnd, uMsg, wParam, lParam);
177 break;
180 return lResult;
184 static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc )
186 RECT16 rc;
187 HBRUSH hBrush;
188 WORD wFormat;
190 LONG style = wndPtr->dwStyle;
191 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
193 GetClientRect16( wndPtr->hwndSelf, &rc);
195 switch (style & 0x0000000F)
197 case SS_LEFT:
198 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
199 break;
201 case SS_CENTER:
202 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
203 break;
205 case SS_RIGHT:
206 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
207 break;
209 case SS_SIMPLE:
210 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
211 break;
213 case SS_LEFTNOWORDWRAP:
214 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER | DT_NOCLIP;
215 break;
217 default:
218 return;
221 if (style & SS_NOPREFIX)
222 wFormat |= DT_NOPREFIX;
224 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
225 hBrush = SendMessage32A( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
226 hdc, wndPtr->hwndSelf );
227 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
228 FillRect16(hdc, &rc, hBrush);
229 if (wndPtr->text) DrawText16( hdc, wndPtr->text, -1, &rc, wFormat );
232 static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc )
234 RECT16 rc;
235 HBRUSH hBrush;
237 GetClientRect16( wndPtr->hwndSelf, &rc);
239 switch (wndPtr->dwStyle & 0x0f)
241 case SS_BLACKRECT:
242 hBrush = CreateSolidBrush(color_windowframe);
243 FillRect16( hdc, &rc, hBrush );
244 break;
245 case SS_GRAYRECT:
246 hBrush = CreateSolidBrush(color_background);
247 FillRect16( hdc, &rc, hBrush );
248 break;
249 case SS_WHITERECT:
250 hBrush = CreateSolidBrush(color_window);
251 FillRect16( hdc, &rc, hBrush );
252 break;
253 case SS_BLACKFRAME:
254 hBrush = CreateSolidBrush(color_windowframe);
255 FrameRect16( hdc, &rc, hBrush );
256 break;
257 case SS_GRAYFRAME:
258 hBrush = CreateSolidBrush(color_background);
259 FrameRect16( hdc, &rc, hBrush );
260 break;
261 case SS_WHITEFRAME:
262 hBrush = CreateSolidBrush(color_window);
263 FrameRect16( hdc, &rc, hBrush );
264 break;
265 default:
266 return;
268 DeleteObject( hBrush );
272 static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc )
274 RECT16 rc;
275 HBRUSH hbrush;
276 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
278 GetClientRect16( wndPtr->hwndSelf, &rc);
279 hbrush = SendMessage32A( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
280 hdc, wndPtr->hwndSelf );
281 FillRect16( hdc, &rc, hbrush );
282 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );