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