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