1 | /* $Id: static.cpp,v 1.10 1999-11-21 14:37:17 achimha Exp $ */
|
---|
2 | /*
|
---|
3 | * Static control
|
---|
4 | *
|
---|
5 | * Copyright 1999 Christoph Bratschi
|
---|
6 | *
|
---|
7 | * Copyright David W. Metcalfe, 1993
|
---|
8 | *
|
---|
9 | * WINE version: 990923
|
---|
10 | *
|
---|
11 | * Status: complete
|
---|
12 | * Version: 5.00
|
---|
13 | */
|
---|
14 |
|
---|
15 | #include <stdlib.h>
|
---|
16 | #include <os2win.h>
|
---|
17 | #include "controls.h"
|
---|
18 | #include "static.h"
|
---|
19 |
|
---|
20 | //Prototypes
|
---|
21 |
|
---|
22 | static void STATIC_PaintTextfn( HWND hwnd, HDC hdc );
|
---|
23 | static void STATIC_PaintRectfn( HWND hwnd, HDC hdc );
|
---|
24 | static void STATIC_PaintIconfn( HWND hwnd, HDC hdc );
|
---|
25 | static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc );
|
---|
26 | static void STATIC_PaintMetafilefn(HWND hwnd,HDC hdc);
|
---|
27 | static void STATIC_PaintOwnerDrawfn(HWND hwnd,HDC hdc);
|
---|
28 | static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc );
|
---|
29 |
|
---|
30 | static COLORREF color_windowframe, color_background, color_window;
|
---|
31 |
|
---|
32 |
|
---|
33 | typedef void (*pfPaint)( HWND, HDC );
|
---|
34 |
|
---|
35 | static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
|
---|
36 | {
|
---|
37 | STATIC_PaintTextfn, /* SS_LEFT */
|
---|
38 | STATIC_PaintTextfn, /* SS_CENTER */
|
---|
39 | STATIC_PaintTextfn, /* SS_RIGHT */
|
---|
40 | STATIC_PaintIconfn, /* SS_ICON */
|
---|
41 | STATIC_PaintRectfn, /* SS_BLACKRECT */
|
---|
42 | STATIC_PaintRectfn, /* SS_GRAYRECT */
|
---|
43 | STATIC_PaintRectfn, /* SS_WHITERECT */
|
---|
44 | STATIC_PaintRectfn, /* SS_BLACKFRAME */
|
---|
45 | STATIC_PaintRectfn, /* SS_GRAYFRAME */
|
---|
46 | STATIC_PaintRectfn, /* SS_WHITEFRAME */
|
---|
47 | NULL, /* SS_USERITEM */
|
---|
48 | STATIC_PaintTextfn, /* SS_SIMPLE */
|
---|
49 | STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
|
---|
50 | STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
|
---|
51 | STATIC_PaintBitmapfn, /* SS_BITMAP */
|
---|
52 | STATIC_PaintMetafilefn, /* SS_ENHMETAFILE */
|
---|
53 | STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
|
---|
54 | STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
|
---|
55 | STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
|
---|
56 | };
|
---|
57 |
|
---|
58 | static void STATIC_ResizeWindow(HWND hwnd,DWORD dwStyle,INT w,INT h)
|
---|
59 | {
|
---|
60 | if (dwStyle & SS_RIGHTJUST)
|
---|
61 | {
|
---|
62 | RECT rect;
|
---|
63 |
|
---|
64 | GetWindowRect(hwnd,&rect);
|
---|
65 | SetWindowPos(hwnd,0,rect.right-w,rect.bottom-h,w,h,SWP_NOACTIVATE | SWP_NOZORDER);
|
---|
66 | } else SetWindowPos(hwnd,0,0,0,w,h,SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
|
---|
67 | }
|
---|
68 |
|
---|
69 | /***********************************************************************
|
---|
70 | * STATIC_SetIcon
|
---|
71 | *
|
---|
72 | * Set the icon for an SS_ICON control.
|
---|
73 | */
|
---|
74 | static HICON STATIC_SetIcon( HWND hwnd, HICON hicon )
|
---|
75 | {
|
---|
76 | HICON prevIcon;
|
---|
77 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
78 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
79 | ICONINFO ii;
|
---|
80 | BITMAP bmp;
|
---|
81 |
|
---|
82 | if (infoPtr == NULL)
|
---|
83 | return 0;
|
---|
84 |
|
---|
85 | if ((dwStyle & SS_TYPEMASK) != SS_ICON) return 0;
|
---|
86 |
|
---|
87 | if (infoPtr->hIcon) DestroyIcon(infoPtr->hIcon);
|
---|
88 | prevIcon = infoPtr->hIcon;
|
---|
89 | infoPtr->hIcon = hicon;
|
---|
90 |
|
---|
91 | if (!GetIconInfo(hicon,&ii)) return prevIcon;
|
---|
92 | GetObjectA(ii.hbmColor,sizeof(BITMAP),(LPVOID)&bmp);
|
---|
93 |
|
---|
94 | if (!(dwStyle & (SS_CENTERIMAGE | SS_REALSIZEIMAGE))) STATIC_ResizeWindow(hwnd,dwStyle,bmp.bmWidth,bmp.bmHeight);
|
---|
95 |
|
---|
96 | return prevIcon;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /***********************************************************************
|
---|
100 | * STATIC_SetBitmap
|
---|
101 | *
|
---|
102 | * Set the bitmap for an SS_BITMAP control.
|
---|
103 | */
|
---|
104 | static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap )
|
---|
105 | {
|
---|
106 | HBITMAP hOldBitmap;
|
---|
107 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
108 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
109 |
|
---|
110 | if ((dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0;
|
---|
111 |
|
---|
112 | if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
|
---|
113 | //ERR("huh? hBitmap!=0, but not bitmap\n");
|
---|
114 | return 0;
|
---|
115 | }
|
---|
116 | hOldBitmap = infoPtr->hIcon;
|
---|
117 | infoPtr->hIcon = hBitmap;
|
---|
118 | if (hBitmap && !(dwStyle & (SS_CENTERIMAGE | SS_REALSIZEIMAGE)))
|
---|
119 | {
|
---|
120 | BITMAP bm;
|
---|
121 |
|
---|
122 | GetObjectA(hBitmap,sizeof(bm),&bm);
|
---|
123 | STATIC_ResizeWindow(hwnd,dwStyle,bm.bmWidth,bm.bmHeight);
|
---|
124 | }
|
---|
125 |
|
---|
126 | return hOldBitmap;
|
---|
127 | }
|
---|
128 |
|
---|
129 | static HENHMETAFILE STATIC_SetMetafile(HWND hwnd,HENHMETAFILE hMetafile)
|
---|
130 | {
|
---|
131 | HENHMETAFILE hOldMetafile;
|
---|
132 |
|
---|
133 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
134 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
135 |
|
---|
136 | if ((dwStyle & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
|
---|
137 |
|
---|
138 | hOldMetafile = infoPtr->hIcon;
|
---|
139 | infoPtr->hIcon = hMetafile;
|
---|
140 |
|
---|
141 | return hOldMetafile;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /***********************************************************************
|
---|
145 | * STATIC_LoadIcon
|
---|
146 | *
|
---|
147 | * Load the icon for an SS_ICON control.
|
---|
148 | */
|
---|
149 | static HICON STATIC_LoadIcon( HWND hwnd, LPCSTR name )
|
---|
150 | {
|
---|
151 | HICON hicon;
|
---|
152 |
|
---|
153 | hicon = LoadIconA(GetWindowLongA(hwnd,GWL_HINSTANCE),name);
|
---|
154 |
|
---|
155 | if (!hicon)
|
---|
156 | hicon = LoadIconA(0, name);
|
---|
157 |
|
---|
158 | return hicon;
|
---|
159 | }
|
---|
160 |
|
---|
161 | /***********************************************************************
|
---|
162 | * STATIC_LoadBitmap
|
---|
163 | *
|
---|
164 | * Load the bitmap for an SS_BITMAP control.
|
---|
165 | */
|
---|
166 | static HBITMAP STATIC_LoadBitmap( HWND hwnd, LPCSTR name )
|
---|
167 | {
|
---|
168 | HBITMAP hbitmap;
|
---|
169 |
|
---|
170 | hbitmap = LoadBitmapA(GetWindowLongA(hwnd,GWL_HINSTANCE),name);
|
---|
171 |
|
---|
172 | if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
|
---|
173 | hbitmap = LoadBitmapA(0,name);
|
---|
174 |
|
---|
175 | return hbitmap;
|
---|
176 | }
|
---|
177 |
|
---|
178 | static HBITMAP STATIC_LoadMetafile(HWND hwnd,LPCSTR name)
|
---|
179 | {
|
---|
180 | HENHMETAFILE hMetafile;
|
---|
181 |
|
---|
182 | hMetafile = GetEnhMetaFileA(name); //CB: right?
|
---|
183 |
|
---|
184 | return hMetafile;
|
---|
185 | }
|
---|
186 |
|
---|
187 | /* message handler */
|
---|
188 |
|
---|
189 | LRESULT STATIC_NCCreate(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
190 | {
|
---|
191 | CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
|
---|
192 | STATICINFO* infoPtr;
|
---|
193 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
194 | DWORD style = dwStyle & SS_TYPEMASK;
|
---|
195 | DWORD dwExStyle = GetWindowLongA(hwnd,GWL_EXSTYLE);
|
---|
196 |
|
---|
197 | infoPtr = (STATICINFO*)malloc(sizeof(STATICINFO));
|
---|
198 | infoPtr->hFont = 0;
|
---|
199 | infoPtr->dummy = 0;
|
---|
200 | infoPtr->hIcon = 0;
|
---|
201 | SetInfoPtr(hwnd,(DWORD)infoPtr);
|
---|
202 |
|
---|
203 | if (dwStyle & SS_SUNKEN)
|
---|
204 | {
|
---|
205 | dwExStyle |= WS_EX_STATICEDGE;
|
---|
206 | SetWindowLongA(hwnd,GWL_EXSTYLE,dwExStyle);
|
---|
207 | }
|
---|
208 |
|
---|
209 | if (style == SS_ICON)
|
---|
210 | {
|
---|
211 | if (cs->lpszName) //CB: is 0 a valid icon id? winhlp32: lpszName = NULL
|
---|
212 | {
|
---|
213 | if (!HIWORD(cs->lpszName) || cs->lpszName[0])
|
---|
214 | STATIC_SetIcon(hwnd,STATIC_LoadIcon(hwnd,cs->lpszName));
|
---|
215 | }
|
---|
216 | return TRUE;
|
---|
217 | }
|
---|
218 | if (style == SS_BITMAP)
|
---|
219 | {
|
---|
220 | if (cs->lpszName)
|
---|
221 | STATIC_SetBitmap(hwnd,STATIC_LoadBitmap(hwnd,cs->lpszName));
|
---|
222 | return TRUE;
|
---|
223 | }
|
---|
224 | if (style == SS_ENHMETAFILE)
|
---|
225 | {
|
---|
226 | if (cs->lpszName) STATIC_SetMetafile(hwnd,STATIC_LoadMetafile(hwnd,cs->lpszName));
|
---|
227 | return TRUE;
|
---|
228 | }
|
---|
229 | if (!HIWORD(cs->lpszName) && (cs->lpszName)) return TRUE;
|
---|
230 |
|
---|
231 | return DefWindowProcA(hwnd,WM_NCCREATE,wParam,lParam);
|
---|
232 | }
|
---|
233 |
|
---|
234 | LRESULT STATIC_Create(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
235 | {
|
---|
236 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
---|
237 |
|
---|
238 | if (style < 0L || style > SS_TYPEMASK)
|
---|
239 | {
|
---|
240 | //Unknown style
|
---|
241 | return (LRESULT)-1;
|
---|
242 | }
|
---|
243 |
|
---|
244 | /* initialise colours */
|
---|
245 | color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
|
---|
246 | color_background = GetSysColor(COLOR_BACKGROUND);
|
---|
247 | color_window = GetSysColor(COLOR_WINDOW);
|
---|
248 |
|
---|
249 | return 0;
|
---|
250 | }
|
---|
251 |
|
---|
252 | LRESULT STATIC_NCDestroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
253 | {
|
---|
254 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
---|
255 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
---|
256 |
|
---|
257 | if (style == SS_ICON && infoPtr->hIcon)
|
---|
258 | {
|
---|
259 | DestroyIcon(infoPtr->hIcon);
|
---|
260 | } else if (style == SS_BITMAP && infoPtr->hIcon)
|
---|
261 | {
|
---|
262 | DeleteObject(infoPtr->hIcon);
|
---|
263 | } else if (style == SS_ENHMETAFILE && infoPtr->hIcon)
|
---|
264 | {
|
---|
265 | DeleteEnhMetaFile((HENHMETAFILE)infoPtr->hIcon);
|
---|
266 | }
|
---|
267 |
|
---|
268 | free(infoPtr);
|
---|
269 |
|
---|
270 | return DefWindowProcA(hwnd,WM_NCDESTROY,wParam,lParam);
|
---|
271 | }
|
---|
272 |
|
---|
273 | LRESULT STATIC_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
274 | {
|
---|
275 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
---|
276 | PAINTSTRUCT ps;
|
---|
277 |
|
---|
278 | BeginPaint(hwnd,&ps);
|
---|
279 | if (staticPaintFunc[style]) (staticPaintFunc[style])(hwnd,ps.hdc);
|
---|
280 | EndPaint(hwnd,&ps);
|
---|
281 |
|
---|
282 | return 0;
|
---|
283 | }
|
---|
284 |
|
---|
285 | LRESULT STATIC_Enable(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
286 | {
|
---|
287 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
288 |
|
---|
289 | if (dwStyle & SS_NOTIFY) SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),wParam ? STN_ENABLE:STN_DISABLE),hwnd);
|
---|
290 |
|
---|
291 | InvalidateRect(hwnd,NULL,FALSE);
|
---|
292 |
|
---|
293 | return 0;
|
---|
294 | }
|
---|
295 |
|
---|
296 | LRESULT STATIC_SysColorChange(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
297 | {
|
---|
298 | color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
|
---|
299 | color_background = GetSysColor(COLOR_BACKGROUND);
|
---|
300 | color_window = GetSysColor(COLOR_WINDOW);
|
---|
301 |
|
---|
302 | InvalidateRect(hwnd,NULL,TRUE);
|
---|
303 |
|
---|
304 | return 0;
|
---|
305 | }
|
---|
306 |
|
---|
307 | LRESULT STATIC_SetText(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
308 | {
|
---|
309 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
---|
310 |
|
---|
311 | if (style == SS_ICON)
|
---|
312 | STATIC_SetIcon(hwnd,STATIC_LoadIcon(hwnd,(LPCSTR)lParam));
|
---|
313 | else if (style == SS_BITMAP)
|
---|
314 | STATIC_SetBitmap(hwnd,STATIC_LoadBitmap(hwnd,(LPCSTR)lParam));
|
---|
315 | else if (style == SS_ENHMETAFILE)
|
---|
316 | STATIC_SetMetafile(hwnd,STATIC_LoadMetafile(hwnd,(LPCSTR)lParam));
|
---|
317 | else
|
---|
318 | DefWindowProcA(hwnd,WM_SETTEXT,wParam,lParam);
|
---|
319 |
|
---|
320 | InvalidateRect(hwnd,NULL,FALSE);
|
---|
321 | UpdateWindow(hwnd);
|
---|
322 |
|
---|
323 | return 0;
|
---|
324 | }
|
---|
325 |
|
---|
326 | LRESULT STATIC_SetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
327 | {
|
---|
328 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
---|
329 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
---|
330 |
|
---|
331 | if (style == SS_ICON) return 0;
|
---|
332 | if (style == SS_BITMAP) return 0;
|
---|
333 | if (style == SS_ENHMETAFILE) return 0;
|
---|
334 |
|
---|
335 | infoPtr->hFont = (HFONT)wParam;
|
---|
336 |
|
---|
337 | if (LOWORD(lParam))
|
---|
338 | {
|
---|
339 | InvalidateRect(hwnd,NULL,FALSE);
|
---|
340 | UpdateWindow(hwnd);
|
---|
341 | }
|
---|
342 |
|
---|
343 | return 0;
|
---|
344 | }
|
---|
345 |
|
---|
346 | LRESULT STATIC_GetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
347 | {
|
---|
348 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
---|
349 |
|
---|
350 | return infoPtr->hFont;
|
---|
351 | }
|
---|
352 |
|
---|
353 | LRESULT STATIC_NCHitTest(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
354 | {
|
---|
355 | return HTTRANSPARENT;
|
---|
356 | }
|
---|
357 |
|
---|
358 | LRESULT STATIC_GetDlgCode(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
359 | {
|
---|
360 | return DLGC_STATIC;
|
---|
361 | }
|
---|
362 |
|
---|
363 | LRESULT STATIC_GetIcon(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
364 | {
|
---|
365 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
---|
366 |
|
---|
367 | return infoPtr->hIcon;
|
---|
368 | }
|
---|
369 |
|
---|
370 | LRESULT STATIC_GetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
371 | {
|
---|
372 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
---|
373 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
---|
374 |
|
---|
375 | switch (wParam)
|
---|
376 | {
|
---|
377 | case IMAGE_BITMAP:
|
---|
378 | if (style & SS_BITMAP) return infoPtr->hIcon;
|
---|
379 | break;
|
---|
380 |
|
---|
381 | case IMAGE_CURSOR:
|
---|
382 | case IMAGE_ICON:
|
---|
383 | if (style & SS_ICON) return infoPtr->hIcon;
|
---|
384 | break;
|
---|
385 |
|
---|
386 | case IMAGE_ENHMETAFILE:
|
---|
387 | if (style & SS_ENHMETAFILE) return infoPtr->hIcon;
|
---|
388 | break;
|
---|
389 |
|
---|
390 | default:
|
---|
391 | break;
|
---|
392 | }
|
---|
393 |
|
---|
394 | return 0;
|
---|
395 | }
|
---|
396 |
|
---|
397 | LRESULT STATIC_SetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
398 | {
|
---|
399 | LRESULT lResult = 0;
|
---|
400 |
|
---|
401 | switch (wParam)
|
---|
402 | {
|
---|
403 | case IMAGE_CURSOR:
|
---|
404 | case IMAGE_ICON:
|
---|
405 | lResult = STATIC_SetIcon(hwnd,(HICON)lParam);
|
---|
406 | break;
|
---|
407 |
|
---|
408 | case IMAGE_BITMAP:
|
---|
409 | lResult = STATIC_SetBitmap(hwnd,(HBITMAP)lParam);
|
---|
410 | break;
|
---|
411 |
|
---|
412 | case IMAGE_ENHMETAFILE:
|
---|
413 | lResult = STATIC_SetMetafile(hwnd,(HENHMETAFILE)lParam);
|
---|
414 | break;
|
---|
415 |
|
---|
416 | default:
|
---|
417 | return 0;
|
---|
418 | }
|
---|
419 |
|
---|
420 | if (lResult) InvalidateRect(hwnd,NULL,FALSE);
|
---|
421 |
|
---|
422 | return lResult;
|
---|
423 | }
|
---|
424 |
|
---|
425 | LRESULT STATIC_SetIconMsg(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
426 | {
|
---|
427 | LRESULT lResult;
|
---|
428 |
|
---|
429 | lResult = STATIC_SetIcon(hwnd,(HICON)wParam);
|
---|
430 |
|
---|
431 | InvalidateRect(hwnd,NULL,FALSE);
|
---|
432 |
|
---|
433 | return lResult;
|
---|
434 | }
|
---|
435 |
|
---|
436 | LRESULT STATIC_Click(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
---|
437 | {
|
---|
438 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
439 |
|
---|
440 | if (dwStyle & SS_NOTIFY) SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),STN_CLICKED),hwnd);
|
---|
441 |
|
---|
442 | return DefWindowProcA(hwnd,uMsg,wParam,lParam);
|
---|
443 | }
|
---|
444 |
|
---|
445 | LRESULT STATIC_DoubleClick(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
---|
446 | {
|
---|
447 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
448 |
|
---|
449 | if (dwStyle & SS_NOTIFY) SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),STN_DBLCLK),hwnd);
|
---|
450 |
|
---|
451 | return DefWindowProcA(hwnd,uMsg,wParam,lParam);
|
---|
452 | }
|
---|
453 |
|
---|
454 | /***********************************************************************
|
---|
455 | * StaticWndProc
|
---|
456 | */
|
---|
457 | LRESULT WINAPI StaticWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
---|
458 | {
|
---|
459 | switch (uMsg)
|
---|
460 | {
|
---|
461 | case WM_NCCREATE:
|
---|
462 | return STATIC_NCCreate(hwnd,wParam,lParam);
|
---|
463 |
|
---|
464 | case WM_CREATE:
|
---|
465 | return STATIC_Create(hwnd,wParam,lParam);
|
---|
466 |
|
---|
467 | case WM_NCDESTROY:
|
---|
468 | return STATIC_NCDestroy(hwnd,wParam,lParam);
|
---|
469 |
|
---|
470 | case WM_PAINT:
|
---|
471 | return STATIC_Paint(hwnd,wParam,lParam);
|
---|
472 |
|
---|
473 | case WM_ENABLE:
|
---|
474 | return STATIC_Enable(hwnd,wParam,lParam);
|
---|
475 |
|
---|
476 | case WM_SYSCOLORCHANGE:
|
---|
477 | return STATIC_SysColorChange(hwnd,wParam,lParam);
|
---|
478 |
|
---|
479 | case WM_SETTEXT:
|
---|
480 | return STATIC_SetText(hwnd,wParam,lParam);
|
---|
481 |
|
---|
482 | case WM_SETFONT:
|
---|
483 | return STATIC_SetFont(hwnd,wParam,lParam);
|
---|
484 |
|
---|
485 | case WM_GETFONT:
|
---|
486 | return STATIC_GetFont(hwnd,wParam,lParam);
|
---|
487 |
|
---|
488 | case WM_NCHITTEST:
|
---|
489 | return STATIC_NCHitTest(hwnd,wParam,lParam);
|
---|
490 |
|
---|
491 | case WM_GETDLGCODE:
|
---|
492 | return STATIC_GetDlgCode(hwnd,wParam,lParam);
|
---|
493 |
|
---|
494 | case WM_LBUTTONDOWN:
|
---|
495 | case WM_NCLBUTTONDOWN:
|
---|
496 | return STATIC_Click(hwnd,uMsg,wParam,lParam);
|
---|
497 |
|
---|
498 | case WM_LBUTTONDBLCLK:
|
---|
499 | case WM_NCLBUTTONDBLCLK:
|
---|
500 | return STATIC_DoubleClick(hwnd,uMsg,wParam,lParam);
|
---|
501 |
|
---|
502 | case STM_GETIMAGE:
|
---|
503 | return STATIC_GetImage(hwnd,wParam,lParam);
|
---|
504 |
|
---|
505 | case STM_GETICON:
|
---|
506 | return STATIC_GetIcon(hwnd,wParam,lParam);
|
---|
507 |
|
---|
508 | case STM_SETIMAGE:
|
---|
509 | return STATIC_SetImage(hwnd,wParam,lParam);
|
---|
510 |
|
---|
511 | case STM_SETICON:
|
---|
512 | return STATIC_SetIconMsg(hwnd,wParam,lParam);
|
---|
513 |
|
---|
514 | case STM_MSGMAX:
|
---|
515 | return 0; //CB: undocumented!
|
---|
516 |
|
---|
517 | default:
|
---|
518 | return DefWindowProcA(hwnd,uMsg,wParam,lParam);
|
---|
519 | break;
|
---|
520 | }
|
---|
521 |
|
---|
522 | return DefWindowProcA(hwnd,uMsg,wParam,lParam);
|
---|
523 | }
|
---|
524 |
|
---|
525 |
|
---|
526 | static void STATIC_PaintTextfn(HWND hwnd, HDC hdc )
|
---|
527 | {
|
---|
528 | RECT rc;
|
---|
529 | HBRUSH hBrush;
|
---|
530 | WORD wFormat;
|
---|
531 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
532 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
533 | INT textLen;
|
---|
534 |
|
---|
535 | GetClientRect(hwnd,&rc);
|
---|
536 |
|
---|
537 | switch (dwStyle & SS_TYPEMASK)
|
---|
538 | {
|
---|
539 | case SS_LEFT:
|
---|
540 | wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
|
---|
541 | break;
|
---|
542 |
|
---|
543 | case SS_CENTER:
|
---|
544 | case SS_CENTERIMAGE:
|
---|
545 | wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
|
---|
546 | break;
|
---|
547 |
|
---|
548 | case SS_RIGHT:
|
---|
549 | wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
|
---|
550 | break;
|
---|
551 |
|
---|
552 | case SS_SIMPLE:
|
---|
553 | wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
|
---|
554 | break;
|
---|
555 |
|
---|
556 | case SS_LEFTNOWORDWRAP:
|
---|
557 | wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
|
---|
558 | break;
|
---|
559 |
|
---|
560 | default:
|
---|
561 | return;
|
---|
562 | }
|
---|
563 |
|
---|
564 | if (dwStyle & SS_NOPREFIX) wFormat |= DT_NOPREFIX;
|
---|
565 | if (dwStyle & SS_ENDELLIPSIS) wFormat |= DT_END_ELLIPSIS;
|
---|
566 | if (dwStyle & SS_PATHELLIPSIS) wFormat |= DT_PATH_ELLIPSIS;
|
---|
567 | if (dwStyle & SS_WORDELLIPSIS) wFormat |= DT_WORD_ELLIPSIS;
|
---|
568 |
|
---|
569 | if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
|
---|
570 | hBrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
|
---|
571 | hdc, hwnd );
|
---|
572 | if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
|
---|
573 | FillRect( hdc, &rc, hBrush );
|
---|
574 |
|
---|
575 | if (!IsWindowEnabled(hwnd)) SetTextColor(hdc,GetSysColor(COLOR_GRAYTEXT));
|
---|
576 |
|
---|
577 | textLen = GetWindowTextLengthA(hwnd);
|
---|
578 | if (textLen > 0)
|
---|
579 | {
|
---|
580 | char* text;
|
---|
581 |
|
---|
582 | textLen++;
|
---|
583 | text = (char*)malloc(textLen);
|
---|
584 | GetWindowTextA(hwnd,text,textLen);
|
---|
585 | DrawTextExA(hdc,text,-1,&rc,wFormat,NULL);
|
---|
586 | free(text);
|
---|
587 | }
|
---|
588 | }
|
---|
589 |
|
---|
590 | static void STATIC_PaintRectfn( HWND hwnd, HDC hdc )
|
---|
591 | {
|
---|
592 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
593 | RECT rc;
|
---|
594 | HBRUSH hBrush;
|
---|
595 |
|
---|
596 | GetClientRect( hwnd, &rc);
|
---|
597 |
|
---|
598 | switch (dwStyle & SS_TYPEMASK)
|
---|
599 | {
|
---|
600 | case SS_BLACKRECT:
|
---|
601 | hBrush = CreateSolidBrush(color_windowframe);
|
---|
602 | FillRect( hdc, &rc, hBrush );
|
---|
603 | break;
|
---|
604 | case SS_GRAYRECT:
|
---|
605 | hBrush = CreateSolidBrush(color_background);
|
---|
606 | FillRect( hdc, &rc, hBrush );
|
---|
607 | break;
|
---|
608 | case SS_WHITERECT:
|
---|
609 | hBrush = CreateSolidBrush(color_window);
|
---|
610 | FillRect( hdc, &rc, hBrush );
|
---|
611 | break;
|
---|
612 | case SS_BLACKFRAME:
|
---|
613 | hBrush = CreateSolidBrush(color_windowframe);
|
---|
614 | FrameRect( hdc, &rc, hBrush );
|
---|
615 | break;
|
---|
616 | case SS_GRAYFRAME:
|
---|
617 | hBrush = CreateSolidBrush(color_background);
|
---|
618 | FrameRect( hdc, &rc, hBrush );
|
---|
619 | break;
|
---|
620 | case SS_WHITEFRAME:
|
---|
621 | hBrush = CreateSolidBrush(color_window);
|
---|
622 | FrameRect( hdc, &rc, hBrush );
|
---|
623 | break;
|
---|
624 | default:
|
---|
625 | return;
|
---|
626 | }
|
---|
627 | DeleteObject( hBrush );
|
---|
628 | }
|
---|
629 |
|
---|
630 |
|
---|
631 | static void STATIC_PaintIconfn( HWND hwnd, HDC hdc )
|
---|
632 | {
|
---|
633 | RECT rc;
|
---|
634 | HBRUSH hbrush;
|
---|
635 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
636 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
637 |
|
---|
638 | GetClientRect( hwnd, &rc );
|
---|
639 | hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
|
---|
640 | hdc, hwnd );
|
---|
641 | FillRect( hdc, &rc, hbrush );
|
---|
642 | if (dwStyle & SS_CENTERIMAGE)
|
---|
643 | {
|
---|
644 | ICONINFO ii;
|
---|
645 | BITMAP bmp;
|
---|
646 |
|
---|
647 | if (!GetIconInfo(infoPtr->hIcon,&ii)) return;
|
---|
648 | GetObjectA(ii.hbmColor,sizeof(BITMAP),(LPVOID)&bmp);
|
---|
649 | DrawIcon(hdc,(rc.right-bmp.bmWidth)/2,(rc.bottom-bmp.bmHeight)/2,infoPtr->hIcon);
|
---|
650 | } else if (infoPtr->hIcon) DrawIcon(hdc,rc.left,rc.top,infoPtr->hIcon);
|
---|
651 | }
|
---|
652 |
|
---|
653 | static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc )
|
---|
654 | {
|
---|
655 | RECT rc;
|
---|
656 | HBRUSH hbrush;
|
---|
657 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
658 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
659 | HDC hMemDC;
|
---|
660 | HBITMAP oldbitmap;
|
---|
661 |
|
---|
662 | GetClientRect( hwnd, &rc );
|
---|
663 | hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
|
---|
664 | hdc, hwnd );
|
---|
665 | FillRect( hdc, &rc, hbrush );
|
---|
666 |
|
---|
667 | if (infoPtr->hIcon) {
|
---|
668 | BITMAP bm;
|
---|
669 | SIZE sz;
|
---|
670 |
|
---|
671 | if(GetObjectType(infoPtr->hIcon) != OBJ_BITMAP)
|
---|
672 | return;
|
---|
673 | if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
|
---|
674 | GetObjectA(infoPtr->hIcon, sizeof(bm), &bm);
|
---|
675 | GetBitmapDimensionEx(infoPtr->hIcon, &sz);
|
---|
676 | oldbitmap = SelectObject(hMemDC, infoPtr->hIcon);
|
---|
677 | if (dwStyle & SS_CENTERIMAGE)
|
---|
678 | BitBlt(hdc,sz.cx,sz.cy,bm.bmWidth,bm.bmHeight,hMemDC,(rc.right-bm.bmWidth)/2,(rc.bottom-bm.bmHeight)/2,SRCCOPY);
|
---|
679 | else
|
---|
680 | BitBlt(hdc,sz.cx,sz.cy,bm.bmWidth,bm.bmHeight,hMemDC,0,0,SRCCOPY);
|
---|
681 | SelectObject(hMemDC, oldbitmap);
|
---|
682 | DeleteDC(hMemDC);
|
---|
683 | }
|
---|
684 | }
|
---|
685 |
|
---|
686 | static void STATIC_PaintMetafilefn(HWND hwnd,HDC hdc)
|
---|
687 | {
|
---|
688 | RECT rect;
|
---|
689 | HBRUSH hbrush;
|
---|
690 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
691 |
|
---|
692 | GetClientRect(hwnd,&rect);
|
---|
693 | hbrush = SendMessageA(GetParent(hwnd),WM_CTLCOLORSTATIC,hdc,hwnd);
|
---|
694 | FillRect(hdc,&rect,hbrush);
|
---|
695 |
|
---|
696 | if (infoPtr->hIcon) PlayEnhMetaFile(hdc,(HENHMETAFILE)infoPtr->hIcon,&rect);
|
---|
697 | }
|
---|
698 |
|
---|
699 | static void STATIC_PaintOwnerDrawfn(HWND hwnd,HDC hdc)
|
---|
700 | {
|
---|
701 | DRAWITEMSTRUCT di;
|
---|
702 |
|
---|
703 | di.CtlType = ODT_STATIC;
|
---|
704 | di.CtlID = GetWindowLongA(hwnd,GWL_ID);
|
---|
705 | di.itemID = 0;
|
---|
706 | di.itemAction = ODA_DRAWENTIRE;
|
---|
707 | di.itemState = ODS_DEFAULT;
|
---|
708 | di.hwndItem = hwnd;
|
---|
709 | di.hDC = hdc;
|
---|
710 | GetClientRect(hwnd,&di.rcItem);
|
---|
711 | di.itemData = 0;
|
---|
712 |
|
---|
713 | SendMessageA(GetParent(hwnd),WM_DRAWITEM,GetWindowLongA(hwnd,GWL_ID),(LPARAM)&di);
|
---|
714 | }
|
---|
715 |
|
---|
716 | static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc )
|
---|
717 | {
|
---|
718 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
719 | RECT rc;
|
---|
720 |
|
---|
721 | GetClientRect( hwnd, &rc );
|
---|
722 | switch (dwStyle & SS_TYPEMASK)
|
---|
723 | {
|
---|
724 | case SS_ETCHEDHORZ:
|
---|
725 | DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
|
---|
726 | break;
|
---|
727 | case SS_ETCHEDVERT:
|
---|
728 | DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
|
---|
729 | break;
|
---|
730 | case SS_ETCHEDFRAME:
|
---|
731 | DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
|
---|
732 | break;
|
---|
733 | }
|
---|
734 | }
|
---|
735 |
|
---|
736 | BOOL STATIC_Register()
|
---|
737 | {
|
---|
738 | WNDCLASSA wndClass;
|
---|
739 |
|
---|
740 | //SvL: Don't check this now
|
---|
741 | // if (GlobalFindAtomA(STATICCLASSNAME)) return FALSE;
|
---|
742 |
|
---|
743 | ZeroMemory(&wndClass,sizeof(WNDCLASSA));
|
---|
744 | wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_PARENTDC;
|
---|
745 | wndClass.lpfnWndProc = (WNDPROC)StaticWndProc;
|
---|
746 | wndClass.cbClsExtra = 0;
|
---|
747 | wndClass.cbWndExtra = sizeof(STATICINFO);
|
---|
748 | wndClass.hCursor = LoadCursorA (0,IDC_ARROWA);
|
---|
749 | wndClass.hbrBackground = (HBRUSH)0;
|
---|
750 | wndClass.lpszClassName = STATICCLASSNAME;
|
---|
751 |
|
---|
752 | return RegisterClassA(&wndClass);
|
---|
753 | }
|
---|
754 |
|
---|
755 |
|
---|
756 | BOOL STATIC_Unregister()
|
---|
757 | {
|
---|
758 | if (GlobalFindAtomA (STATICCLASSNAME))
|
---|
759 | return UnregisterClassA(STATICCLASSNAME,(HINSTANCE)NULL);
|
---|
760 | else return FALSE;
|
---|
761 | }
|
---|