Release 960528
[wine/gsoc-2012-control.git] / controls / static.c
blob93840408090d1f1c1965466ee127de4948cdd20b
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 HICON hicon = LoadIcon( cs->hInstance, cs->lpszName );
91 if (!hicon) /* Try OEM icon (FIXME: is this right?) */
92 hicon = LoadIcon( 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, LoadIcon( 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 #ifdef WINELIB32
226 hBrush = SendMessage32A( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
227 hdc, wndPtr->hwndSelf );
228 #else
229 hBrush = SendMessage16( GetParent(wndPtr->hwndSelf), WM_CTLCOLOR, (WORD)hdc,
230 MAKELONG(wndPtr->hwndSelf, CTLCOLOR_STATIC));
231 #endif
232 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
233 FillRect16(hdc, &rc, hBrush);
234 if (wndPtr->text) DrawText16( hdc, wndPtr->text, -1, &rc, wFormat );
237 static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc )
239 RECT16 rc;
240 HBRUSH hBrush;
242 GetClientRect16( wndPtr->hwndSelf, &rc);
244 switch (wndPtr->dwStyle & 0x0f)
246 case SS_BLACKRECT:
247 hBrush = CreateSolidBrush(color_windowframe);
248 FillRect16( hdc, &rc, hBrush );
249 break;
250 case SS_GRAYRECT:
251 hBrush = CreateSolidBrush(color_background);
252 FillRect16( hdc, &rc, hBrush );
253 break;
254 case SS_WHITERECT:
255 hBrush = CreateSolidBrush(color_window);
256 FillRect16( hdc, &rc, hBrush );
257 break;
258 case SS_BLACKFRAME:
259 hBrush = CreateSolidBrush(color_windowframe);
260 FrameRect16( hdc, &rc, hBrush );
261 break;
262 case SS_GRAYFRAME:
263 hBrush = CreateSolidBrush(color_background);
264 FrameRect16( hdc, &rc, hBrush );
265 break;
266 case SS_WHITEFRAME:
267 hBrush = CreateSolidBrush(color_window);
268 FrameRect16( hdc, &rc, hBrush );
269 break;
270 default:
271 return;
273 DeleteObject( hBrush );
277 static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc )
279 RECT16 rc;
280 HBRUSH hbrush;
281 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
283 GetClientRect16( wndPtr->hwndSelf, &rc);
284 #ifdef WINELIB32
285 hbrush = SendMessage32A( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
286 hdc, wndPtr->hwndSelf );
287 #else
288 hbrush = SendMessage16( GetParent(wndPtr->hwndSelf), WM_CTLCOLOR, hdc,
289 MAKELONG(wndPtr->hwndSelf, CTLCOLOR_STATIC));
290 #endif
291 FillRect16( hdc, &rc, hbrush );
292 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );