Release 960506
[wine/multimedia.git] / controls / static.c
blob9b88116db8940c64038b934f131fdfb46aadfed8
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 extern void DEFWND_SetText( WND *wndPtr, LPSTR text ); /* windows/defwnd.c */
16 static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc );
17 static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc );
18 static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc );
21 static COLORREF color_windowframe, color_background, color_window;
24 typedef void (*pfPaint)( WND *, HDC);
26 #define LAST_STATIC_TYPE SS_LEFTNOWORDWRAP
28 static pfPaint staticPaintFunc[LAST_STATIC_TYPE+1] =
30 STATIC_PaintTextfn, /* SS_LEFT */
31 STATIC_PaintTextfn, /* SS_CENTER */
32 STATIC_PaintTextfn, /* SS_RIGHT */
33 STATIC_PaintIconfn, /* SS_ICON */
34 STATIC_PaintRectfn, /* SS_BLACKRECT */
35 STATIC_PaintRectfn, /* SS_GRAYRECT */
36 STATIC_PaintRectfn, /* SS_WHITERECT */
37 STATIC_PaintRectfn, /* SS_BLACKFRAME */
38 STATIC_PaintRectfn, /* SS_GRAYFRAME */
39 STATIC_PaintRectfn, /* SS_WHITEFRAME */
40 NULL, /* Not defined */
41 STATIC_PaintTextfn, /* SS_SIMPLE */
42 STATIC_PaintTextfn /* SS_LEFTNOWORDWRAP */
46 /***********************************************************************
47 * STATIC_SetIcon
49 * Set the icon for an SS_ICON control.
51 static HICON STATIC_SetIcon( WND *wndPtr, HICON hicon )
53 HICON prevIcon;
54 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
56 if ((wndPtr->dwStyle & 0x0f) != SS_ICON) return 0;
57 prevIcon = infoPtr->hIcon;
58 infoPtr->hIcon = hicon;
59 if (hicon)
61 CURSORICONINFO *info = (CURSORICONINFO *) GlobalLock16( hicon );
62 SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, info->nWidth, info->nHeight,
63 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
64 GlobalUnlock16( hicon );
66 return prevIcon;
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)
91 HICON hicon = LoadIcon( createStruct->hInstance,
92 createStruct->lpszName );
93 if (!hicon) /* Try OEM icon (FIXME: is this right?) */
94 hicon = LoadIcon( 0, createStruct->lpszName );
95 STATIC_SetIcon( wndPtr, hicon );
97 return 1;
99 return DefWindowProc(hWnd, uMsg, wParam, lParam);
101 case WM_CREATE:
102 if (style < 0L || style > LAST_STATIC_TYPE)
104 fprintf( stderr, "STATIC: Unknown style 0x%02lx\n", style );
105 lResult = -1L;
106 break;
108 /* initialise colours */
109 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
110 color_background = GetSysColor(COLOR_BACKGROUND);
111 color_window = GetSysColor(COLOR_WINDOW);
112 break;
114 case WM_NCDESTROY:
115 if (style == SS_ICON)
116 DestroyIcon( STATIC_SetIcon( wndPtr, 0 ) );
117 else
118 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
119 break;
121 case WM_PAINT:
123 PAINTSTRUCT ps;
124 BeginPaint( hWnd, &ps );
125 if (staticPaintFunc[style])
126 (staticPaintFunc[style])( wndPtr, ps.hdc );
127 EndPaint( hWnd, &ps );
129 break;
131 case WM_SYSCOLORCHANGE:
132 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
133 color_background = GetSysColor(COLOR_BACKGROUND);
134 color_window = GetSysColor(COLOR_WINDOW);
135 InvalidateRect(hWnd, NULL, TRUE);
136 break;
138 case WM_SETTEXT:
139 if (style == SS_ICON)
140 /* FIXME : should we also return the previous hIcon here ??? */
141 STATIC_SetIcon( wndPtr, LoadIcon( wndPtr->hInstance,
142 (SEGPTR)lParam ));
143 else
144 DEFWND_SetText( wndPtr, (LPSTR)PTR_SEG_TO_LIN(lParam) );
145 InvalidateRect( hWnd, NULL, FALSE );
146 UpdateWindow( hWnd );
147 break;
149 case WM_SETFONT:
150 if (style == SS_ICON) return 0;
151 infoPtr->hFont = (HFONT)wParam;
152 if (LOWORD(lParam))
154 InvalidateRect( hWnd, NULL, FALSE );
155 UpdateWindow( hWnd );
157 break;
159 case WM_GETFONT:
160 return infoPtr->hFont;
162 case WM_NCHITTEST:
163 return HTTRANSPARENT;
165 case WM_GETDLGCODE:
166 return DLGC_STATIC;
168 case STM_GETICON:
169 return infoPtr->hIcon;
171 case STM_SETICON:
172 lResult = STATIC_SetIcon( wndPtr, (HICON)wParam );
173 InvalidateRect( hWnd, NULL, FALSE );
174 UpdateWindow( hWnd );
175 break;
177 default:
178 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
179 break;
182 return lResult;
186 static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc )
188 RECT rc;
189 HBRUSH hBrush;
190 char *text;
191 WORD wFormat;
193 LONG style = wndPtr->dwStyle;
194 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
196 GetClientRect( wndPtr->hwndSelf, &rc);
197 text = USER_HEAP_LIN_ADDR( wndPtr->hText );
199 switch (style & 0x0000000F)
201 case SS_LEFT:
202 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
203 break;
205 case SS_CENTER:
206 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
207 break;
209 case SS_RIGHT:
210 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
211 break;
213 case SS_SIMPLE:
214 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
215 break;
217 case SS_LEFTNOWORDWRAP:
218 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER | DT_NOCLIP;
219 break;
221 default:
222 return;
225 if (style & SS_NOPREFIX)
226 wFormat |= DT_NOPREFIX;
228 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
229 #ifdef WINELIB32
230 hBrush = SendMessage( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
231 hdc, wndPtr->hwndSelf );
232 #else
233 hBrush = SendMessage( GetParent(wndPtr->hwndSelf), WM_CTLCOLOR, (WORD)hdc,
234 MAKELONG(wndPtr->hwndSelf, CTLCOLOR_STATIC));
235 #endif
236 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
237 FillRect(hdc, &rc, hBrush);
238 if (text) DrawText( hdc, text, -1, &rc, wFormat );
241 static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc )
243 RECT rc;
244 HBRUSH hBrush;
246 GetClientRect( wndPtr->hwndSelf, &rc);
248 switch (wndPtr->dwStyle & 0x0f)
250 case SS_BLACKRECT:
251 hBrush = CreateSolidBrush(color_windowframe);
252 FillRect( hdc, &rc, hBrush );
253 break;
254 case SS_GRAYRECT:
255 hBrush = CreateSolidBrush(color_background);
256 FillRect( hdc, &rc, hBrush );
257 break;
258 case SS_WHITERECT:
259 hBrush = CreateSolidBrush(color_window);
260 FillRect( hdc, &rc, hBrush );
261 break;
262 case SS_BLACKFRAME:
263 hBrush = CreateSolidBrush(color_windowframe);
264 FrameRect( hdc, &rc, hBrush );
265 break;
266 case SS_GRAYFRAME:
267 hBrush = CreateSolidBrush(color_background);
268 FrameRect( hdc, &rc, hBrush );
269 break;
270 case SS_WHITEFRAME:
271 hBrush = CreateSolidBrush(color_window);
272 FrameRect( hdc, &rc, hBrush );
273 break;
274 default:
275 return;
277 DeleteObject( hBrush );
281 static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc )
283 RECT rc;
284 HBRUSH hbrush;
285 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
287 GetClientRect( wndPtr->hwndSelf, &rc);
288 #ifdef WINELIB32
289 hbrush = SendMessage( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
290 hdc, wndPtr->hwndSelf );
291 #else
292 hbrush = SendMessage( GetParent(wndPtr->hwndSelf), WM_CTLCOLOR, hdc,
293 MAKELONG(wndPtr->hwndSelf, CTLCOLOR_STATIC));
294 #endif
295 FillRect( hdc, &rc, hbrush );
296 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );