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