Release 970720
[wine/gsoc-2012-control.git] / controls / static.c
blob6a547e2da359fff08c8abaaa54a95f58238cac78
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 "static.h"
12 #include "heap.h"
14 static void STATIC_PaintTextfn( WND *wndPtr, HDC32 hdc );
15 static void STATIC_PaintRectfn( WND *wndPtr, HDC32 hdc );
16 static void STATIC_PaintIconfn( WND *wndPtr, HDC32 hdc );
19 static COLORREF color_windowframe, color_background, color_window;
22 typedef void (*pfPaint)( WND *, HDC32 );
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 HICON16 STATIC_SetIcon( WND *wndPtr, HICON16 hicon )
51 HICON16 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 SetWindowPos32( wndPtr->hwndSelf, 0, 0, 0, info->nWidth, info->nHeight,
61 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
62 GlobalUnlock16( hicon );
64 return prevIcon;
68 /***********************************************************************
69 * STATIC_LoadIcon
71 * Load the icon for an SS_ICON control.
73 static HICON16 STATIC_LoadIcon( WND *wndPtr, LPCSTR name )
75 HICON16 hicon;
77 if (wndPtr->flags & WIN_ISWIN32)
79 hicon = LoadIcon32A( wndPtr->hInstance, name );
80 if (!hicon) /* Try OEM icon (FIXME: is this right?) */
81 hicon = LoadIcon32A( 0, name );
83 else
85 LPSTR segname = SEGPTR_STRDUP(name);
86 hicon = LoadIcon16( wndPtr->hInstance, SEGPTR_GET(segname) );
87 if (!hicon) /* Try OEM icon (FIXME: is this right?) */
88 hicon = LoadIcon32A( 0, segname );
89 SEGPTR_FREE(segname);
91 return hicon;
95 /***********************************************************************
96 * StaticWndProc
98 LRESULT StaticWndProc( HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam,
99 LPARAM lParam )
101 LRESULT lResult = 0;
102 WND *wndPtr = WIN_FindWndPtr(hWnd);
103 LONG style = wndPtr->dwStyle & 0x0000000F;
104 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
106 switch (uMsg)
108 case WM_NCCREATE:
109 if (style == SS_ICON)
111 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)lParam;
112 if (cs->lpszName)
113 STATIC_SetIcon( wndPtr,
114 STATIC_LoadIcon( wndPtr, cs->lpszName ));
115 return 1;
117 return DefWindowProc32A( hWnd, uMsg, wParam, lParam );
119 case WM_CREATE:
120 if (style < 0L || style > LAST_STATIC_TYPE)
122 fprintf( stderr, "STATIC: Unknown style 0x%02lx\n", style );
123 lResult = -1L;
124 break;
126 /* initialise colours */
127 color_windowframe = GetSysColor32(COLOR_WINDOWFRAME);
128 color_background = GetSysColor32(COLOR_BACKGROUND);
129 color_window = GetSysColor32(COLOR_WINDOW);
130 break;
132 case WM_NCDESTROY:
133 if (style == SS_ICON)
134 DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
135 else
136 lResult = DefWindowProc32A( hWnd, uMsg, wParam, lParam );
137 break;
139 case WM_PAINT:
141 PAINTSTRUCT32 ps;
142 BeginPaint32( hWnd, &ps );
143 if (staticPaintFunc[style])
144 (staticPaintFunc[style])( wndPtr, ps.hdc );
145 EndPaint32( hWnd, &ps );
147 break;
149 case WM_ENABLE:
150 InvalidateRect32( hWnd, NULL, FALSE );
151 break;
153 case WM_SYSCOLORCHANGE:
154 color_windowframe = GetSysColor32(COLOR_WINDOWFRAME);
155 color_background = GetSysColor32(COLOR_BACKGROUND);
156 color_window = GetSysColor32(COLOR_WINDOW);
157 InvalidateRect32( hWnd, NULL, TRUE );
158 break;
160 case WM_SETTEXT:
161 if (style == SS_ICON)
162 /* FIXME : should we also return the previous hIcon here ??? */
163 STATIC_SetIcon( wndPtr, STATIC_LoadIcon( wndPtr, (LPCSTR)lParam ));
164 else
165 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
166 InvalidateRect32( hWnd, NULL, FALSE );
167 UpdateWindow32( hWnd );
168 break;
170 case WM_SETFONT:
171 if (style == SS_ICON) return 0;
172 infoPtr->hFont = (HFONT16)wParam;
173 if (LOWORD(lParam))
175 InvalidateRect32( hWnd, NULL, FALSE );
176 UpdateWindow32( hWnd );
178 break;
180 case WM_GETFONT:
181 return infoPtr->hFont;
183 case WM_NCHITTEST:
184 return HTTRANSPARENT;
186 case WM_GETDLGCODE:
187 return DLGC_STATIC;
189 case STM_GETICON:
190 return infoPtr->hIcon;
192 case STM_SETICON:
193 lResult = STATIC_SetIcon( wndPtr, (HICON16)wParam );
194 InvalidateRect32( hWnd, NULL, FALSE );
195 UpdateWindow32( hWnd );
196 break;
198 default:
199 lResult = DefWindowProc32A(hWnd, uMsg, wParam, lParam);
200 break;
203 return lResult;
207 static void STATIC_PaintTextfn( WND *wndPtr, HDC32 hdc )
209 RECT32 rc;
210 HBRUSH32 hBrush;
211 WORD wFormat;
213 LONG style = wndPtr->dwStyle;
214 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
216 GetClientRect32( wndPtr->hwndSelf, &rc);
218 switch (style & 0x0000000F)
220 case SS_LEFT:
221 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
222 break;
224 case SS_CENTER:
225 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
226 break;
228 case SS_RIGHT:
229 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
230 break;
232 case SS_SIMPLE:
233 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
234 break;
236 case SS_LEFTNOWORDWRAP:
237 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER | DT_NOCLIP;
238 break;
240 default:
241 return;
244 if (style & SS_NOPREFIX)
245 wFormat |= DT_NOPREFIX;
247 if (infoPtr->hFont) SelectObject32( hdc, infoPtr->hFont );
248 hBrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
249 hdc, wndPtr->hwndSelf );
250 if (!hBrush) hBrush = GetStockObject32(WHITE_BRUSH);
251 FillRect32( hdc, &rc, hBrush );
252 if (wndPtr->text) DrawText32A( hdc, wndPtr->text, -1, &rc, wFormat );
255 static void STATIC_PaintRectfn( WND *wndPtr, HDC32 hdc )
257 RECT32 rc;
258 HBRUSH32 hBrush;
260 GetClientRect32( wndPtr->hwndSelf, &rc);
262 switch (wndPtr->dwStyle & 0x0f)
264 case SS_BLACKRECT:
265 hBrush = CreateSolidBrush32(color_windowframe);
266 FillRect32( hdc, &rc, hBrush );
267 break;
268 case SS_GRAYRECT:
269 hBrush = CreateSolidBrush32(color_background);
270 FillRect32( hdc, &rc, hBrush );
271 break;
272 case SS_WHITERECT:
273 hBrush = CreateSolidBrush32(color_window);
274 FillRect32( hdc, &rc, hBrush );
275 break;
276 case SS_BLACKFRAME:
277 hBrush = CreateSolidBrush32(color_windowframe);
278 FrameRect32( hdc, &rc, hBrush );
279 break;
280 case SS_GRAYFRAME:
281 hBrush = CreateSolidBrush32(color_background);
282 FrameRect32( hdc, &rc, hBrush );
283 break;
284 case SS_WHITEFRAME:
285 hBrush = CreateSolidBrush32(color_window);
286 FrameRect32( hdc, &rc, hBrush );
287 break;
288 default:
289 return;
291 DeleteObject32( hBrush );
295 static void STATIC_PaintIconfn( WND *wndPtr, HDC32 hdc )
297 RECT32 rc;
298 HBRUSH32 hbrush;
299 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
301 GetClientRect32( wndPtr->hwndSelf, &rc );
302 hbrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
303 hdc, wndPtr->hwndSelf );
304 FillRect32( hdc, &rc, hbrush );
305 if (infoPtr->hIcon) DrawIcon32( hdc, rc.left, rc.top, infoPtr->hIcon );