Release 951226
[wine/gsoc-2012-control.git] / controls / static.c
blobce812523766cfe9d471d18170f17a2c3c2433809
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 /* FIXME: is this OK?
59 if (infoPtr->hIcon) DestroyIcon( infoPtr->hIcon ); */
60 infoPtr->hIcon = hicon;
61 if (hicon)
63 CURSORICONINFO *info = (CURSORICONINFO *) GlobalLock( hicon );
64 SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
65 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
66 GlobalUnlock( hicon );
71 /***********************************************************************
72 * StaticWndProc
74 LONG StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
76 LONG lResult = 0;
77 WND *wndPtr = WIN_FindWndPtr(hWnd);
78 LONG style = wndPtr->dwStyle & 0x0000000F;
79 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
81 switch (uMsg) {
82 case WM_ENABLE:
83 InvalidateRect(hWnd, NULL, FALSE);
84 break;
86 case WM_NCCREATE:
87 if (style == SS_ICON)
89 CREATESTRUCT * createStruct = (CREATESTRUCT *)PTR_SEG_TO_LIN(lParam);
90 if (createStruct->lpszName)
91 STATIC_SetIcon( hWnd, LoadIcon( createStruct->hInstance,
92 (SEGPTR)createStruct->lpszName ));
93 return 1;
95 return DefWindowProc(hWnd, uMsg, wParam, lParam);
97 case WM_CREATE:
98 if (style < 0L || style > LAST_STATIC_TYPE)
100 fprintf( stderr, "STATIC: Unknown style 0x%02lx\n", style );
101 lResult = -1L;
102 break;
104 /* initialise colours */
105 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
106 color_background = GetSysColor(COLOR_BACKGROUND);
107 color_window = GetSysColor(COLOR_WINDOW);
108 break;
110 case WM_NCDESTROY:
111 if (style == SS_ICON)
112 STATIC_SetIcon( hWnd, 0 ); /* Destroy the current icon */
113 else
114 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
115 break;
117 case WM_PAINT:
119 PAINTSTRUCT ps;
120 BeginPaint( hWnd, &ps );
121 if (staticPaintFunc[style])
122 (staticPaintFunc[style])( hWnd, ps.hdc );
123 EndPaint( hWnd, &ps );
125 break;
127 case WM_SYSCOLORCHANGE:
128 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
129 color_background = GetSysColor(COLOR_BACKGROUND);
130 color_window = GetSysColor(COLOR_WINDOW);
131 InvalidateRect(hWnd, NULL, TRUE);
132 break;
134 case WM_SETTEXT:
135 if (style == SS_ICON)
136 STATIC_SetIcon( hWnd, LoadIcon( wndPtr->hInstance,
137 (SEGPTR)lParam ));
138 else
139 DEFWND_SetText( hWnd, (LPSTR)PTR_SEG_TO_LIN(lParam) );
140 InvalidateRect( hWnd, NULL, FALSE );
141 UpdateWindow( hWnd );
142 break;
144 case WM_SETFONT:
145 if (style == SS_ICON) return 0;
146 infoPtr->hFont = (HFONT)wParam;
147 if (LOWORD(lParam))
149 InvalidateRect( hWnd, NULL, FALSE );
150 UpdateWindow( hWnd );
152 break;
154 case WM_GETFONT:
155 return (LONG)infoPtr->hFont;
157 case WM_NCHITTEST:
158 return HTTRANSPARENT;
160 case WM_GETDLGCODE:
161 return DLGC_STATIC;
163 case STM_GETICON:
164 return (LONG)infoPtr->hIcon;
166 case STM_SETICON:
167 STATIC_SetIcon( hWnd, (HICON)wParam );
168 InvalidateRect( hWnd, NULL, FALSE );
169 UpdateWindow( hWnd );
170 return 0;
172 default:
173 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
174 break;
177 return lResult;
181 static void PaintTextfn( HWND hwnd, HDC hdc )
183 RECT rc;
184 HBRUSH hBrush;
185 char *text;
186 WORD wFormat;
188 WND *wndPtr = WIN_FindWndPtr(hwnd);
189 LONG style = wndPtr->dwStyle;
190 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
192 GetClientRect(hwnd, &rc);
193 text = USER_HEAP_LIN_ADDR( wndPtr->hText );
195 switch (style & 0x0000000F)
197 case SS_LEFT:
198 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
199 break;
201 case SS_CENTER:
202 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
203 break;
205 case SS_RIGHT:
206 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
207 break;
209 case SS_SIMPLE:
210 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER;
211 break;
213 case SS_LEFTNOWORDWRAP:
214 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER;
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 = (HBRUSH)SendMessage( wndPtr->hwndParent, WM_CTLCOLORSTATIC,
227 (WPARAM)hdc, (LPARAM)hwnd );
228 #else
229 hBrush = SendMessage( wndPtr->hwndParent, WM_CTLCOLOR, (WORD)hdc,
230 MAKELONG(hwnd, CTLCOLOR_STATIC));
231 #endif
232 if (hBrush == (HBRUSH)NULL) hBrush = GetStockObject(WHITE_BRUSH);
233 FillRect(hdc, &rc, hBrush);
234 if (text)
235 DrawText(hdc, text, -1, &rc, wFormat);
238 static void PaintRectfn( HWND hwnd, HDC hdc )
240 RECT rc;
241 HBRUSH hBrush;
243 WND *wndPtr = WIN_FindWndPtr(hwnd);
245 GetClientRect(hwnd, &rc);
247 switch (wndPtr->dwStyle & 0x0f)
249 case SS_BLACKRECT:
250 hBrush = CreateSolidBrush(color_windowframe);
251 FillRect( hdc, &rc, hBrush );
252 break;
253 case SS_GRAYRECT:
254 hBrush = CreateSolidBrush(color_background);
255 FillRect( hdc, &rc, hBrush );
256 break;
257 case SS_WHITERECT:
258 hBrush = CreateSolidBrush(color_window);
259 FillRect( hdc, &rc, hBrush );
260 break;
261 case SS_BLACKFRAME:
262 hBrush = CreateSolidBrush(color_windowframe);
263 FrameRect( hdc, &rc, hBrush );
264 break;
265 case SS_GRAYFRAME:
266 hBrush = CreateSolidBrush(color_background);
267 FrameRect( hdc, &rc, hBrush );
268 break;
269 case SS_WHITEFRAME:
270 hBrush = CreateSolidBrush(color_window);
271 FrameRect( hdc, &rc, hBrush );
272 break;
273 default:
274 return;
276 DeleteObject( hBrush );
280 static void PaintIconfn( HWND hwnd, HDC hdc )
282 RECT rc;
283 HBRUSH hbrush;
284 WND *wndPtr = WIN_FindWndPtr(hwnd);
285 STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
287 GetClientRect(hwnd, &rc);
288 #ifdef WINELIB32
289 hbrush = (HBRUSH)SendMessage( wndPtr->hwndParent, WM_CTLCOLORSTATIC,
290 (WPARAM)hdc, (LPARAM)hwnd );
291 #else
292 hbrush = SendMessage( wndPtr->hwndParent, WM_CTLCOLOR, hdc,
293 MAKELONG(hwnd, CTLCOLOR_STATIC));
294 #endif
295 FillRect( hdc, &rc, hbrush );
296 if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );