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