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