1 | /* $Id: button.cpp,v 1.21 1999-12-02 16:34:42 cbratschi Exp $ */
|
---|
2 | /* File: button.cpp -- Button type widgets
|
---|
3 | *
|
---|
4 | * Copyright (C) 1993 Johannes Ruscheinski
|
---|
5 | * Copyright (C) 1993 David Metcalfe
|
---|
6 | * Copyright (C) 1994 Alexandre Julliard
|
---|
7 | * Copyright (c) 1999 Christoph Bratschi
|
---|
8 | *
|
---|
9 | * WINE version: 991031
|
---|
10 | *
|
---|
11 | * Status: complete
|
---|
12 | * Version: 5.00
|
---|
13 | */
|
---|
14 |
|
---|
15 | #include <string.h>
|
---|
16 | #include <stdlib.h>
|
---|
17 |
|
---|
18 | #include <os2win.h>
|
---|
19 | #include "controls.h"
|
---|
20 | #include "button.h"
|
---|
21 | #include <misc.h>
|
---|
22 | #include "initterm.h"
|
---|
23 |
|
---|
24 | #ifdef DEBUG
|
---|
25 | char *GetMsgText(int Msg);
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | //Prototypes
|
---|
29 |
|
---|
30 | static void DrawDisabledText(HDC hdc,char* text,RECT* rtext,UINT format);
|
---|
31 |
|
---|
32 | static void PB_Paint(HWND hwnd,HDC hDC,WORD action);
|
---|
33 | static void CB_Paint(HWND hwnd,HDC hDC,WORD action);
|
---|
34 | static void GB_Paint(HWND hwnd,HDC hDC,WORD action);
|
---|
35 | static void UB_Paint(HWND hwnd,HDC hDC,WORD action);
|
---|
36 | static void OB_Paint(HWND hwnd,HDC hDC,WORD action);
|
---|
37 | static void BUTTON_CheckAutoRadioButton(HWND hwnd);
|
---|
38 | static void BUTTON_DrawPushButton(HWND hwnd,HDC hDC,WORD action,BOOL pushedState);
|
---|
39 | static LRESULT BUTTON_LButtonDown(HWND hwnd,WPARAM wParam,LPARAM lParam);
|
---|
40 |
|
---|
41 | #define MAX_BTN_TYPE 12
|
---|
42 |
|
---|
43 | static const WORD maxCheckState[MAX_BTN_TYPE] =
|
---|
44 | {
|
---|
45 | BUTTON_UNCHECKED, /* BS_PUSHBUTTON */
|
---|
46 | BUTTON_UNCHECKED, /* BS_DEFPUSHBUTTON */
|
---|
47 | BUTTON_CHECKED, /* BS_CHECKBOX */
|
---|
48 | BUTTON_CHECKED, /* BS_AUTOCHECKBOX */
|
---|
49 | BUTTON_CHECKED, /* BS_RADIOBUTTON */
|
---|
50 | BUTTON_3STATE, /* BS_3STATE */
|
---|
51 | BUTTON_3STATE, /* BS_AUTO3STATE */
|
---|
52 | BUTTON_UNCHECKED, /* BS_GROUPBOX */
|
---|
53 | BUTTON_UNCHECKED, /* BS_USERBUTTON */
|
---|
54 | BUTTON_CHECKED, /* BS_AUTORADIOBUTTON */
|
---|
55 | BUTTON_UNCHECKED, /* Not defined */
|
---|
56 | BUTTON_UNCHECKED /* BS_OWNERDRAW */
|
---|
57 | };
|
---|
58 |
|
---|
59 | typedef void (*pfPaint)(HWND hwnd,HDC hdc,WORD action);
|
---|
60 |
|
---|
61 | static const pfPaint btnPaintFunc[MAX_BTN_TYPE] =
|
---|
62 | {
|
---|
63 | PB_Paint, /* BS_PUSHBUTTON */
|
---|
64 | PB_Paint, /* BS_DEFPUSHBUTTON */
|
---|
65 | CB_Paint, /* BS_CHECKBOX */
|
---|
66 | CB_Paint, /* BS_AUTOCHECKBOX */
|
---|
67 | CB_Paint, /* BS_RADIOBUTTON */
|
---|
68 | CB_Paint, /* BS_3STATE */
|
---|
69 | CB_Paint, /* BS_AUTO3STATE */
|
---|
70 | GB_Paint, /* BS_GROUPBOX */
|
---|
71 | UB_Paint, /* BS_USERBUTTON */
|
---|
72 | CB_Paint, /* BS_AUTORADIOBUTTON */
|
---|
73 | NULL, /* Not defined */
|
---|
74 | OB_Paint /* BS_OWNERDRAW */
|
---|
75 | };
|
---|
76 |
|
---|
77 | #define PAINT_BUTTON(hwnd,style,action) \
|
---|
78 | if (btnPaintFunc[style]) { \
|
---|
79 | HDC hdc = GetDC(hwnd); \
|
---|
80 | (btnPaintFunc[style])(hwnd,hdc,action); \
|
---|
81 | ReleaseDC(hwnd,hdc); }
|
---|
82 |
|
---|
83 | #define BUTTON_SEND_CTLCOLOR(hwnd,hdc) \
|
---|
84 | SendMessageA( GetParent(hwnd), WM_CTLCOLORBTN, \
|
---|
85 | (hdc),hwnd)
|
---|
86 |
|
---|
87 | static HBITMAP hbitmapCheckBoxes = 0;
|
---|
88 | static WORD checkBoxWidth = 0, checkBoxHeight = 0;
|
---|
89 |
|
---|
90 | static LRESULT BUTTON_SendNotify(HWND hwnd,DWORD code)
|
---|
91 | {
|
---|
92 | return SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),code),hwnd);
|
---|
93 | }
|
---|
94 |
|
---|
95 | static LRESULT BUTTON_GetDlgCode(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
96 | {
|
---|
97 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
98 |
|
---|
99 | switch (dwStyle & 0x0f)
|
---|
100 | {
|
---|
101 | case BS_AUTOCHECKBOX:
|
---|
102 | case BS_CHECKBOX:
|
---|
103 | return DLGC_WANTCHARS | DLGC_BUTTON;
|
---|
104 |
|
---|
105 | case BS_PUSHBUTTON:
|
---|
106 | return DLGC_UNDEFPUSHBUTTON;
|
---|
107 |
|
---|
108 | case BS_DEFPUSHBUTTON:
|
---|
109 | return DLGC_DEFPUSHBUTTON;
|
---|
110 |
|
---|
111 | case BS_AUTORADIOBUTTON:
|
---|
112 | case BS_RADIOBUTTON:
|
---|
113 | return DLGC_RADIOBUTTON;
|
---|
114 |
|
---|
115 | case BS_GROUPBOX:;
|
---|
116 | return DLGC_STATIC;
|
---|
117 |
|
---|
118 | default:
|
---|
119 | return DLGC_BUTTON;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | static LRESULT BUTTON_Enable(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
124 | {
|
---|
125 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
126 |
|
---|
127 | if (dwStyle & BS_NOTIFY && !wParam) BUTTON_SendNotify(hwnd,BN_DISABLE);
|
---|
128 |
|
---|
129 | //PAINT_BUTTON(hwnd,dwStyle & 0x0f,ODA_DRAWENTIRE);
|
---|
130 | //SvL: 09/10/99 Force it to redraw properly
|
---|
131 | InvalidateRect( hwnd, NULL, FALSE );
|
---|
132 |
|
---|
133 | return 0;
|
---|
134 | }
|
---|
135 |
|
---|
136 | static LRESULT BUTTON_Create(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
137 | {
|
---|
138 | BUTTONINFO* infoPtr;
|
---|
139 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
|
---|
140 |
|
---|
141 | if (!hbitmapCheckBoxes)
|
---|
142 | {
|
---|
143 | BITMAP bmp;
|
---|
144 |
|
---|
145 | hbitmapCheckBoxes = LoadBitmapA(hInstanceUser32, MAKEINTRESOURCEA(OBM_CHECKBOXES));
|
---|
146 | GetObjectA( hbitmapCheckBoxes, sizeof(bmp), &bmp );
|
---|
147 | if (GetObjectA(hbitmapCheckBoxes,sizeof(bmp),&bmp))
|
---|
148 | {
|
---|
149 | checkBoxWidth = bmp.bmWidth / 4;
|
---|
150 | checkBoxHeight = bmp.bmHeight / 3;
|
---|
151 | } else checkBoxWidth = checkBoxHeight = 0;
|
---|
152 | }
|
---|
153 | if (style < 0L || style >= MAX_BTN_TYPE) return -1; /* abort */
|
---|
154 |
|
---|
155 | infoPtr = (BUTTONINFO*)malloc(sizeof(BUTTONINFO));
|
---|
156 | infoPtr->state = BUTTON_UNCHECKED;
|
---|
157 | infoPtr->hFont = 0;
|
---|
158 | infoPtr->hImage = NULL;
|
---|
159 | SetInfoPtr(hwnd,(DWORD)infoPtr);
|
---|
160 |
|
---|
161 | return 0;
|
---|
162 | }
|
---|
163 |
|
---|
164 | static LRESULT BUTTON_Destroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
165 | {
|
---|
166 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
167 |
|
---|
168 | free(infoPtr);
|
---|
169 |
|
---|
170 | return 0;
|
---|
171 | }
|
---|
172 |
|
---|
173 | static LRESULT BUTTON_EraseBkgnd(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
174 | {
|
---|
175 | //SvL: Erase background for groupboxes as the paint function only draws
|
---|
176 | // a box
|
---|
177 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
|
---|
178 | // if(style == BS_GROUPBOX) {
|
---|
179 | return DefWindowProcA(hwnd, WM_ERASEBKGND, wParam, lParam);
|
---|
180 | // }
|
---|
181 | // return 1;
|
---|
182 | }
|
---|
183 |
|
---|
184 | static LRESULT BUTTON_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
185 | {
|
---|
186 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
187 | DWORD style = dwStyle & 0x0f;
|
---|
188 |
|
---|
189 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_PAINT);
|
---|
190 |
|
---|
191 | if (btnPaintFunc[style])
|
---|
192 | {
|
---|
193 | PAINTSTRUCT ps;
|
---|
194 |
|
---|
195 | HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd,&ps);
|
---|
196 | SetBkMode(hdc,OPAQUE);
|
---|
197 | (btnPaintFunc[style])(hwnd,hdc,ODA_DRAWENTIRE);
|
---|
198 | if(!wParam) EndPaint(hwnd,&ps);
|
---|
199 | } else return DefWindowProcA(hwnd,WM_PAINT,wParam,lParam);
|
---|
200 |
|
---|
201 | return 0;
|
---|
202 | }
|
---|
203 |
|
---|
204 | static LRESULT BUTTON_LButtonDblClk(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
205 | {
|
---|
206 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
207 | DWORD style = dwStyle & 0x0f;
|
---|
208 |
|
---|
209 | if(dwStyle & BS_NOTIFY || style == BS_RADIOBUTTON ||
|
---|
210 | style == BS_USERBUTTON || style == BS_OWNERDRAW)
|
---|
211 | BUTTON_SendNotify(hwnd,BN_DOUBLECLICKED);
|
---|
212 | else BUTTON_LButtonDown(hwnd,wParam,lParam);
|
---|
213 |
|
---|
214 | return 0;
|
---|
215 | }
|
---|
216 |
|
---|
217 | static LRESULT BUTTON_LButtonDown(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
218 | {
|
---|
219 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
220 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
221 |
|
---|
222 | SetCapture(hwnd);
|
---|
223 | SetFocus(hwnd);
|
---|
224 | SendMessageA(hwnd,BM_SETSTATE,TRUE,0);
|
---|
225 | infoPtr->state |= BUTTON_BTNPRESSED;
|
---|
226 |
|
---|
227 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_HILITE);
|
---|
228 |
|
---|
229 | return 0;
|
---|
230 | }
|
---|
231 |
|
---|
232 | static LRESULT BUTTON_LButtonUp(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
233 | {
|
---|
234 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
235 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
236 | RECT rect;
|
---|
237 | POINT pt;
|
---|
238 |
|
---|
239 | pt.x = LOWORD(lParam);
|
---|
240 | pt.y = HIWORD(lParam);
|
---|
241 |
|
---|
242 | if (!(infoPtr->state & BUTTON_BTNPRESSED)) return 0;
|
---|
243 | infoPtr->state &= BUTTON_NSTATES;
|
---|
244 | if (!(infoPtr->state & BUTTON_HIGHLIGHTED))
|
---|
245 | {
|
---|
246 | ReleaseCapture();
|
---|
247 | return 0;
|
---|
248 | }
|
---|
249 | SendMessageA(hwnd,BM_SETSTATE,FALSE,0);
|
---|
250 | ReleaseCapture();
|
---|
251 | GetClientRect(hwnd,&rect);
|
---|
252 | if (PtInRect(&rect,pt))
|
---|
253 | {
|
---|
254 | switch(dwStyle & 0x0f)
|
---|
255 | {
|
---|
256 | case BS_AUTOCHECKBOX:
|
---|
257 | SendMessageA(hwnd,BM_SETCHECK,!(infoPtr->state & BUTTON_CHECKED),0);
|
---|
258 | break;
|
---|
259 | case BS_AUTORADIOBUTTON:
|
---|
260 | SendMessageA(hwnd,BM_SETCHECK,TRUE,0);
|
---|
261 | break;
|
---|
262 | case BS_AUTO3STATE:
|
---|
263 | SendMessageA(hwnd,BM_SETCHECK,
|
---|
264 | (infoPtr->state & BUTTON_3STATE) ? 0 :
|
---|
265 | ((infoPtr->state & 3)+1),0);
|
---|
266 | break;
|
---|
267 | }
|
---|
268 | BUTTON_SendNotify(hwnd,BN_CLICKED);
|
---|
269 | }
|
---|
270 |
|
---|
271 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_UNHILITE);
|
---|
272 |
|
---|
273 | return 0;
|
---|
274 | }
|
---|
275 |
|
---|
276 | static LRESULT BUTTON_CaptureChanged(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
277 | {
|
---|
278 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
279 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
280 |
|
---|
281 | if (infoPtr->state & BUTTON_BTNPRESSED)
|
---|
282 | {
|
---|
283 | infoPtr->state &= BUTTON_NSTATES;
|
---|
284 | if (infoPtr->state & BUTTON_HIGHLIGHTED)
|
---|
285 | SendMessageA( hwnd, BM_SETSTATE, FALSE, 0 );
|
---|
286 | }
|
---|
287 |
|
---|
288 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_UNHILITE);
|
---|
289 |
|
---|
290 | return 0;
|
---|
291 | }
|
---|
292 |
|
---|
293 | static LRESULT BUTTON_MouseMove(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
294 | {
|
---|
295 | if (GetCapture() == hwnd)
|
---|
296 | {
|
---|
297 | RECT rect;
|
---|
298 | POINT pt;
|
---|
299 |
|
---|
300 | pt.x = LOWORD(lParam);
|
---|
301 | pt.y = HIWORD(lParam);
|
---|
302 |
|
---|
303 | GetClientRect(hwnd,&rect);
|
---|
304 | SendMessageA(hwnd,BM_SETSTATE,PtInRect(&rect,pt),0);
|
---|
305 | }
|
---|
306 |
|
---|
307 | return 0;
|
---|
308 | }
|
---|
309 |
|
---|
310 | static LRESULT BUTTON_NCHitTest(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
311 | {
|
---|
312 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
|
---|
313 |
|
---|
314 | if (style == BS_GROUPBOX) return HTTRANSPARENT;
|
---|
315 |
|
---|
316 | return DefWindowProcA(hwnd,WM_NCHITTEST,wParam,lParam);
|
---|
317 | }
|
---|
318 |
|
---|
319 | static LRESULT BUTTON_SetText(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
320 | {
|
---|
321 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
322 |
|
---|
323 | DefWindowProcA(hwnd,WM_SETTEXT,wParam,lParam);
|
---|
324 | if (dwStyle & WS_VISIBLE) PAINT_BUTTON(hwnd,dwStyle & 0x0f,ODA_DRAWENTIRE);
|
---|
325 |
|
---|
326 | return 0;
|
---|
327 | }
|
---|
328 |
|
---|
329 | static LRESULT BUTTON_SetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
330 | {
|
---|
331 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
332 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
333 |
|
---|
334 | infoPtr->hFont = (HFONT)wParam;
|
---|
335 | if (lParam && (dwStyle & WS_VISIBLE)) PAINT_BUTTON(hwnd,dwStyle & 0x0f,ODA_DRAWENTIRE);
|
---|
336 |
|
---|
337 | return 0;
|
---|
338 | }
|
---|
339 |
|
---|
340 | static LRESULT BUTTON_GetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
341 | {
|
---|
342 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
343 |
|
---|
344 | return infoPtr->hFont;
|
---|
345 | }
|
---|
346 |
|
---|
347 | static LRESULT BUTTON_KeyDown(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
348 | {
|
---|
349 | if (wParam == VK_SPACE)
|
---|
350 | {
|
---|
351 | SendMessageA(hwnd,BM_SETSTATE,TRUE,0);
|
---|
352 | SetFocus(hwnd);
|
---|
353 | SetCapture(hwnd);
|
---|
354 | }
|
---|
355 |
|
---|
356 | return 0;
|
---|
357 | }
|
---|
358 |
|
---|
359 | static LRESULT BUTTON_KeyUp(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
360 | {
|
---|
361 | if (wParam == VK_SPACE)
|
---|
362 | {
|
---|
363 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
364 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
365 |
|
---|
366 | ReleaseCapture();
|
---|
367 | if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) return 0;
|
---|
368 | SendMessageA(hwnd,BM_SETSTATE,FALSE,0);
|
---|
369 |
|
---|
370 | switch(dwStyle & 0x0f)
|
---|
371 | {
|
---|
372 | case BS_AUTOCHECKBOX:
|
---|
373 | SendMessageA(hwnd,BM_SETCHECK,!(infoPtr->state & BUTTON_CHECKED),0);
|
---|
374 | break;
|
---|
375 | case BS_AUTORADIOBUTTON:
|
---|
376 | SendMessageA(hwnd,BM_SETCHECK,TRUE,0);
|
---|
377 | break;
|
---|
378 | case BS_AUTO3STATE:
|
---|
379 | SendMessageA(hwnd,BM_SETCHECK,
|
---|
380 | (infoPtr->state & BUTTON_3STATE) ? 0 :
|
---|
381 | ((infoPtr->state & 3)+1),0);
|
---|
382 | break;
|
---|
383 | }
|
---|
384 | BUTTON_SendNotify(hwnd,BN_CLICKED);
|
---|
385 | } else if (wParam != VK_TAB) ReleaseCapture();
|
---|
386 |
|
---|
387 | return 0;
|
---|
388 | }
|
---|
389 |
|
---|
390 | static LRESULT BUTTON_SysKeyUp(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
391 | {
|
---|
392 | if (wParam != VK_TAB) ReleaseCapture();
|
---|
393 |
|
---|
394 | return 0;
|
---|
395 | }
|
---|
396 |
|
---|
397 | static LRESULT BUTTON_SetFocus(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
398 | {
|
---|
399 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
400 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
401 | DWORD style = dwStyle & 0x0f;
|
---|
402 |
|
---|
403 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_SETFOCUS);
|
---|
404 |
|
---|
405 | if ((style == BS_AUTORADIOBUTTON || style == BS_RADIOBUTTON) &&
|
---|
406 | (GetCapture() != hwnd) && !(SendMessageA(hwnd,BM_GETCHECK,0,0) & BST_CHECKED))
|
---|
407 | {
|
---|
408 | /* The notification is sent when the button (BS_AUTORADIOBUTTON)
|
---|
409 | is unckecked and the focus was not given by a mouse click. */
|
---|
410 | if (style == BS_AUTORADIOBUTTON) SendMessageA(hwnd,BM_SETCHECK,TRUE,0);
|
---|
411 | BUTTON_SendNotify(hwnd,BN_CLICKED);
|
---|
412 | }
|
---|
413 |
|
---|
414 | infoPtr->state |= BUTTON_HASFOCUS;
|
---|
415 | PAINT_BUTTON(hwnd,style,ODA_FOCUS);
|
---|
416 |
|
---|
417 | return 0;
|
---|
418 | }
|
---|
419 |
|
---|
420 | static LRESULT BUTTON_KillFocus(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
421 | {
|
---|
422 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
423 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
424 | DWORD style = dwStyle & 0x0f;
|
---|
425 |
|
---|
426 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_KILLFOCUS);
|
---|
427 |
|
---|
428 | if (infoPtr->state & BUTTON_HASFOCUS)
|
---|
429 | {
|
---|
430 | infoPtr->state &= ~BUTTON_HASFOCUS;
|
---|
431 | PAINT_BUTTON(hwnd,style,ODA_FOCUS);
|
---|
432 | }
|
---|
433 |
|
---|
434 | return 0;
|
---|
435 | }
|
---|
436 |
|
---|
437 | static LRESULT BUTTON_SysColorChange(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
438 | {
|
---|
439 | InvalidateRect(hwnd,NULL,FALSE);
|
---|
440 |
|
---|
441 | return 0;
|
---|
442 | }
|
---|
443 |
|
---|
444 | static LRESULT BUTTON_Click(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
445 | {
|
---|
446 | RECT rect;
|
---|
447 | LPARAM point;
|
---|
448 |
|
---|
449 | GetClientRect(hwnd,&rect);
|
---|
450 | point = MAKELPARAM(rect.right/2,rect.bottom/2);
|
---|
451 | SendMessageA(hwnd,WM_LBUTTONDOWN,MK_LBUTTON,point);
|
---|
452 | Sleep(100);
|
---|
453 | SendMessageA(hwnd,WM_LBUTTONUP,0,point);
|
---|
454 |
|
---|
455 | return 0;
|
---|
456 | }
|
---|
457 |
|
---|
458 | static LRESULT BUTTON_SetStyle(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
459 | {
|
---|
460 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
461 |
|
---|
462 | if ((wParam & 0x0f) >= MAX_BTN_TYPE) return 0;
|
---|
463 | dwStyle = (dwStyle & 0xfffffff0) | (wParam & 0x0000000f);
|
---|
464 | SetWindowLongA(hwnd,GWL_STYLE,dwStyle);
|
---|
465 | PAINT_BUTTON(hwnd,dwStyle & 0x0f,ODA_DRAWENTIRE);
|
---|
466 |
|
---|
467 | return 0;
|
---|
468 | }
|
---|
469 |
|
---|
470 | static LRESULT BUTTON_SetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
471 | {
|
---|
472 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
473 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
474 | HANDLE oldHbitmap = infoPtr->hImage;
|
---|
475 |
|
---|
476 | if (dwStyle & BS_BITMAP || dwStyle & BS_ICON) infoPtr->hImage = (HANDLE)lParam;
|
---|
477 |
|
---|
478 | return oldHbitmap;
|
---|
479 | }
|
---|
480 |
|
---|
481 | static LRESULT BUTTON_GetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
482 | {
|
---|
483 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
484 |
|
---|
485 | switch(wParam)
|
---|
486 | {
|
---|
487 | case IMAGE_BITMAP:
|
---|
488 | return (HBITMAP)infoPtr->hImage;
|
---|
489 | case IMAGE_ICON:
|
---|
490 | return (HICON)infoPtr->hImage;
|
---|
491 | default:
|
---|
492 | return NULL;
|
---|
493 | }
|
---|
494 | }
|
---|
495 |
|
---|
496 | static LRESULT BUTTON_GetCheck(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
497 | {
|
---|
498 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
499 |
|
---|
500 | return infoPtr->state & 3;
|
---|
501 | }
|
---|
502 |
|
---|
503 | static LRESULT BUTTON_SetCheck(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
504 | {
|
---|
505 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
506 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
507 | DWORD style = dwStyle & 0x0f;
|
---|
508 |
|
---|
509 | if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
|
---|
510 | if ((infoPtr->state & 3) != wParam)
|
---|
511 | {
|
---|
512 | if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
|
---|
513 | {
|
---|
514 | DWORD oldStyle = dwStyle;
|
---|
515 |
|
---|
516 | if (wParam)
|
---|
517 | dwStyle |= WS_TABSTOP;
|
---|
518 | else
|
---|
519 | dwStyle &= ~WS_TABSTOP;
|
---|
520 |
|
---|
521 | //if (oldStyle != dwStyle) SetWindowLongA(hwnd,GWL_STYLE,dwStyle);
|
---|
522 | }
|
---|
523 | infoPtr->state = (infoPtr->state & ~3) | wParam;
|
---|
524 | PAINT_BUTTON(hwnd,style,ODA_SELECT);
|
---|
525 | }
|
---|
526 | if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
|
---|
527 | BUTTON_CheckAutoRadioButton(hwnd);
|
---|
528 |
|
---|
529 | return 0;
|
---|
530 | }
|
---|
531 |
|
---|
532 | static LRESULT BUTTON_GetState(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
533 | {
|
---|
534 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
535 |
|
---|
536 | return infoPtr->state;
|
---|
537 | }
|
---|
538 |
|
---|
539 | static LRESULT BUTTON_SetState(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
540 | {
|
---|
541 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
542 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
|
---|
543 |
|
---|
544 | if (wParam)
|
---|
545 | {
|
---|
546 | if (infoPtr->state & BUTTON_HIGHLIGHTED) return 0;
|
---|
547 | infoPtr->state |= BUTTON_HIGHLIGHTED;
|
---|
548 | } else
|
---|
549 | {
|
---|
550 | if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) return 0;
|
---|
551 | infoPtr->state &= ~BUTTON_HIGHLIGHTED;
|
---|
552 | }
|
---|
553 | PAINT_BUTTON(hwnd,style,ODA_SELECT);
|
---|
554 |
|
---|
555 | return 0;
|
---|
556 | }
|
---|
557 |
|
---|
558 | /***********************************************************************
|
---|
559 | * ButtonWndProc
|
---|
560 | */
|
---|
561 | static
|
---|
562 | LRESULT WINAPI ButtonWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
---|
563 | {
|
---|
564 | // dprintf(("ButtonWndProc hwnd: %04x, msg %s, wp %08x lp %08lx\n",
|
---|
565 | // hwnd, GetMsgText(uMsg), wParam, lParam));
|
---|
566 |
|
---|
567 | switch (uMsg)
|
---|
568 | {
|
---|
569 | case WM_GETDLGCODE:
|
---|
570 | return BUTTON_GetDlgCode(hwnd,wParam,lParam);
|
---|
571 |
|
---|
572 | case WM_ENABLE:
|
---|
573 | return BUTTON_Enable(hwnd,wParam,lParam);
|
---|
574 |
|
---|
575 | case WM_CREATE:
|
---|
576 | return BUTTON_Create(hwnd,wParam,lParam);
|
---|
577 |
|
---|
578 | case WM_DESTROY:
|
---|
579 | return BUTTON_Destroy(hwnd,wParam,lParam);
|
---|
580 |
|
---|
581 | case WM_ERASEBKGND:
|
---|
582 | return BUTTON_EraseBkgnd(hwnd,wParam,lParam);
|
---|
583 |
|
---|
584 | case WM_PAINT:
|
---|
585 | return BUTTON_Paint(hwnd,wParam,lParam);
|
---|
586 |
|
---|
587 | case WM_LBUTTONDBLCLK:
|
---|
588 | return BUTTON_LButtonDblClk(hwnd,wParam,lParam);
|
---|
589 |
|
---|
590 | case WM_LBUTTONDOWN:
|
---|
591 | return BUTTON_LButtonDown(hwnd,wParam,lParam);
|
---|
592 |
|
---|
593 | case WM_LBUTTONUP:
|
---|
594 | return BUTTON_LButtonUp(hwnd,wParam,lParam);
|
---|
595 |
|
---|
596 | case WM_CAPTURECHANGED:
|
---|
597 | return BUTTON_CaptureChanged(hwnd,wParam,lParam);
|
---|
598 |
|
---|
599 | case WM_MOUSEMOVE:
|
---|
600 | return BUTTON_MouseMove(hwnd,wParam,lParam);
|
---|
601 |
|
---|
602 | case WM_NCHITTEST:
|
---|
603 | return BUTTON_NCHitTest(hwnd,wParam,lParam);
|
---|
604 |
|
---|
605 | case WM_SETTEXT:
|
---|
606 | return BUTTON_SetText(hwnd,wParam,lParam);
|
---|
607 |
|
---|
608 | case WM_SETFONT:
|
---|
609 | return BUTTON_SetFont(hwnd,wParam,lParam);
|
---|
610 |
|
---|
611 | case WM_GETFONT:
|
---|
612 | return BUTTON_GetFont(hwnd,wParam,lParam);
|
---|
613 |
|
---|
614 | case WM_KEYDOWN:
|
---|
615 | return BUTTON_KeyDown(hwnd,wParam,lParam);
|
---|
616 |
|
---|
617 | case WM_KEYUP:
|
---|
618 | return BUTTON_KeyUp(hwnd,wParam,lParam);
|
---|
619 |
|
---|
620 | case WM_SYSKEYUP:
|
---|
621 | return BUTTON_SysKeyUp(hwnd,wParam,lParam);
|
---|
622 |
|
---|
623 | case WM_SETFOCUS:
|
---|
624 | return BUTTON_SetFocus(hwnd,wParam,lParam);
|
---|
625 |
|
---|
626 | case WM_KILLFOCUS:
|
---|
627 | return BUTTON_KillFocus(hwnd,wParam,lParam);
|
---|
628 |
|
---|
629 | case WM_SYSCOLORCHANGE:
|
---|
630 | return BUTTON_SysColorChange(hwnd,wParam,lParam);
|
---|
631 |
|
---|
632 | case BM_CLICK:
|
---|
633 | return BUTTON_Click(hwnd,wParam,lParam);
|
---|
634 |
|
---|
635 | case BM_SETSTYLE:
|
---|
636 | return BUTTON_SetStyle(hwnd,wParam,lParam);
|
---|
637 |
|
---|
638 | case BM_SETIMAGE:
|
---|
639 | return BUTTON_SetImage(hwnd,wParam,lParam);
|
---|
640 |
|
---|
641 | case BM_GETIMAGE:
|
---|
642 | return BUTTON_GetImage(hwnd,wParam,lParam);
|
---|
643 |
|
---|
644 | case BM_GETCHECK:
|
---|
645 | return BUTTON_GetCheck(hwnd,wParam,lParam);
|
---|
646 |
|
---|
647 | case BM_SETCHECK:
|
---|
648 | return BUTTON_SetCheck(hwnd,wParam,lParam);
|
---|
649 |
|
---|
650 | case BM_GETSTATE:
|
---|
651 | return BUTTON_GetState(hwnd,wParam,lParam);
|
---|
652 |
|
---|
653 | case BM_SETSTATE:
|
---|
654 | return BUTTON_SetState(hwnd,wParam,lParam);
|
---|
655 |
|
---|
656 | default:
|
---|
657 | return DefWindowProcA(hwnd,uMsg,wParam,lParam);
|
---|
658 | }
|
---|
659 |
|
---|
660 | return 0;
|
---|
661 | }
|
---|
662 |
|
---|
663 |
|
---|
664 | /**********************************************************************
|
---|
665 | * Push Button Functions
|
---|
666 | */
|
---|
667 | static void PB_Paint( HWND hwnd, HDC hDC, WORD action )
|
---|
668 | {
|
---|
669 | BUTTONINFO *infoPtr = (BUTTONINFO *)GetInfoPtr(hwnd);
|
---|
670 | BOOL bHighLighted = (infoPtr->state & BUTTON_HIGHLIGHTED);
|
---|
671 |
|
---|
672 | /*
|
---|
673 | * Delegate this to the more generic pushbutton painting
|
---|
674 | * method.
|
---|
675 | */
|
---|
676 | BUTTON_DrawPushButton(hwnd,
|
---|
677 | hDC,
|
---|
678 | action,
|
---|
679 | bHighLighted);
|
---|
680 | }
|
---|
681 |
|
---|
682 | static INT BUTTON_GetTextFormat(DWORD dwStyle,INT defHorz,INT defVert)
|
---|
683 | {
|
---|
684 | INT format = 0;
|
---|
685 |
|
---|
686 | if (dwStyle & BS_LEFT) format = DT_LEFT;
|
---|
687 | else if (dwStyle & BS_CENTER) format = DT_CENTER;
|
---|
688 | else if (dwStyle & BS_RIGHT) format = DT_RIGHT;
|
---|
689 | else format = defHorz;
|
---|
690 |
|
---|
691 | if (dwStyle & BS_TOP) format |= DT_TOP;
|
---|
692 | else if (dwStyle & BS_VCENTER) format |= DT_VCENTER;
|
---|
693 | else if (dwStyle & BS_BOTTOM) format |= DT_BOTTOM;
|
---|
694 | else format |= defVert;
|
---|
695 |
|
---|
696 | if (!(dwStyle & BS_MULTILINE)) format |= DT_SINGLELINE;
|
---|
697 |
|
---|
698 | return format;
|
---|
699 | }
|
---|
700 |
|
---|
701 | /**********************************************************************
|
---|
702 | * This method will actually do the drawing of the pushbutton
|
---|
703 | * depending on it's state and the pushedState parameter.
|
---|
704 | */
|
---|
705 | static void BUTTON_DrawPushButton(
|
---|
706 | HWND hwnd,
|
---|
707 | HDC hDC,
|
---|
708 | WORD action,
|
---|
709 | BOOL pushedState )
|
---|
710 | {
|
---|
711 | RECT rc, focus_rect;
|
---|
712 | HPEN hOldPen;
|
---|
713 | HBRUSH hOldBrush;
|
---|
714 | BUTTONINFO *infoPtr = (BUTTONINFO *)GetInfoPtr(hwnd);
|
---|
715 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
716 | int xBorderOffset, yBorderOffset;
|
---|
717 | xBorderOffset = yBorderOffset = 0;
|
---|
718 | INT textLen;
|
---|
719 | char* text;
|
---|
720 |
|
---|
721 | GetClientRect( hwnd, &rc );
|
---|
722 |
|
---|
723 | /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
|
---|
724 | if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
|
---|
725 | BUTTON_SEND_CTLCOLOR( hwnd, hDC );
|
---|
726 | hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
|
---|
727 | hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
|
---|
728 | SetBkMode(hDC, TRANSPARENT);
|
---|
729 |
|
---|
730 | if ((dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
|
---|
731 | {
|
---|
732 | Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
|
---|
733 | InflateRect( &rc, -1, -1 );
|
---|
734 | }
|
---|
735 |
|
---|
736 | UINT uState = DFCS_BUTTONPUSH;
|
---|
737 |
|
---|
738 | if (pushedState)
|
---|
739 | {
|
---|
740 | if ( (dwStyle & 0x000f) == BS_DEFPUSHBUTTON )
|
---|
741 | uState |= DFCS_FLAT;
|
---|
742 | else
|
---|
743 | uState |= DFCS_PUSHED;
|
---|
744 | }
|
---|
745 |
|
---|
746 | if (dwStyle & BS_FLAT) uState |= DFCS_FLAT;
|
---|
747 |
|
---|
748 | DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
|
---|
749 | InflateRect( &rc, -2, -2 );
|
---|
750 |
|
---|
751 | focus_rect = rc;
|
---|
752 |
|
---|
753 | if (pushedState)
|
---|
754 | {
|
---|
755 | rc.left += 2; /* To position the text down and right */
|
---|
756 | rc.top += 2;
|
---|
757 | }
|
---|
758 |
|
---|
759 |
|
---|
760 | /* draw button label, if any:
|
---|
761 | *
|
---|
762 | * In win9x we don't show text if there is a bitmap or icon.
|
---|
763 | * I don't know about win31 so I leave it as it was for win31.
|
---|
764 | * Dennis Björklund 12 Jul, 99
|
---|
765 | */
|
---|
766 | textLen = GetWindowTextLengthA(hwnd);
|
---|
767 | if (textLen > 0 && (!(dwStyle & (BS_ICON|BS_BITMAP))))
|
---|
768 | {
|
---|
769 | INT format = BUTTON_GetTextFormat(dwStyle,DT_CENTER,DT_VCENTER);
|
---|
770 |
|
---|
771 | textLen++;
|
---|
772 | text = (char*)malloc(textLen);
|
---|
773 | GetWindowTextA(hwnd,text,textLen);
|
---|
774 |
|
---|
775 | if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rc,format); else
|
---|
776 | {
|
---|
777 | SetTextColor(hDC,GetSysColor(COLOR_BTNTEXT));
|
---|
778 | DrawTextA(hDC,text,-1,&rc,format);
|
---|
779 | /* do we have the focus?
|
---|
780 | * Win9x draws focus last with a size prop. to the button
|
---|
781 | */
|
---|
782 | }
|
---|
783 | free(text);
|
---|
784 | }
|
---|
785 | if ( ((dwStyle & BS_ICON) || (dwStyle & BS_BITMAP) ) &&
|
---|
786 | (infoPtr->hImage != NULL) )
|
---|
787 | {
|
---|
788 | int yOffset, xOffset;
|
---|
789 | int imageWidth, imageHeight;
|
---|
790 |
|
---|
791 | /*
|
---|
792 | * We extract the size of the image from the handle.
|
---|
793 | */
|
---|
794 | if (dwStyle & BS_ICON)
|
---|
795 | {
|
---|
796 | ICONINFO iconInfo;
|
---|
797 | BITMAP bm;
|
---|
798 |
|
---|
799 | GetIconInfo((HICON)infoPtr->hImage, &iconInfo);
|
---|
800 | GetObjectA (iconInfo.hbmColor, sizeof(BITMAP), &bm);
|
---|
801 |
|
---|
802 | imageWidth = bm.bmWidth;
|
---|
803 | imageHeight = bm.bmHeight;
|
---|
804 |
|
---|
805 | DeleteObject(iconInfo.hbmColor);
|
---|
806 | DeleteObject(iconInfo.hbmMask);
|
---|
807 |
|
---|
808 | }
|
---|
809 | else
|
---|
810 | {
|
---|
811 | BITMAP bm;
|
---|
812 |
|
---|
813 | GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm);
|
---|
814 |
|
---|
815 | imageWidth = bm.bmWidth;
|
---|
816 | imageHeight = bm.bmHeight;
|
---|
817 | }
|
---|
818 |
|
---|
819 | /* Center the bitmap */
|
---|
820 | xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - imageWidth ) / 2;
|
---|
821 | yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - imageHeight) / 2;
|
---|
822 |
|
---|
823 | /* If the image is too big for the button then create a region*/
|
---|
824 | if(xOffset < 0 || yOffset < 0)
|
---|
825 | {
|
---|
826 | HRGN hBitmapRgn = NULL;
|
---|
827 | hBitmapRgn = CreateRectRgn(
|
---|
828 | rc.left + xBorderOffset, rc.top +yBorderOffset,
|
---|
829 | rc.right - xBorderOffset, rc.bottom - yBorderOffset);
|
---|
830 | SelectClipRgn(hDC, hBitmapRgn);
|
---|
831 | DeleteObject(hBitmapRgn);
|
---|
832 | }
|
---|
833 |
|
---|
834 | /* Let minimum 1 space from border */
|
---|
835 | xOffset++, yOffset++;
|
---|
836 |
|
---|
837 | /*
|
---|
838 | * Draw the image now.
|
---|
839 | */
|
---|
840 | if (dwStyle & BS_ICON)
|
---|
841 | {
|
---|
842 | DrawIcon(hDC,
|
---|
843 | rc.left + xOffset, rc.top + yOffset,
|
---|
844 | (HICON)infoPtr->hImage);
|
---|
845 | }
|
---|
846 | else
|
---|
847 | {
|
---|
848 | HDC hdcMem;
|
---|
849 |
|
---|
850 | hdcMem = CreateCompatibleDC (hDC);
|
---|
851 | SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
|
---|
852 | BitBlt(hDC,
|
---|
853 | rc.left + xOffset,
|
---|
854 | rc.top + yOffset,
|
---|
855 | imageWidth, imageHeight,
|
---|
856 | hdcMem, 0, 0, SRCCOPY);
|
---|
857 |
|
---|
858 | DeleteDC (hdcMem);
|
---|
859 | }
|
---|
860 |
|
---|
861 | if(xOffset < 0 || yOffset < 0)
|
---|
862 | {
|
---|
863 | SelectClipRgn(hDC, NULL);
|
---|
864 | }
|
---|
865 | }
|
---|
866 |
|
---|
867 | SelectObject( hDC, hOldPen );
|
---|
868 | SelectObject( hDC, hOldBrush );
|
---|
869 |
|
---|
870 | if (infoPtr->state & BUTTON_HASFOCUS && IsWindowEnabled(hwnd))
|
---|
871 | {
|
---|
872 | InflateRect( &focus_rect, -1, -1 );
|
---|
873 | DrawFocusRect( hDC, &focus_rect );
|
---|
874 | }
|
---|
875 | }
|
---|
876 |
|
---|
877 |
|
---|
878 | static void DrawDisabledText(HDC hdc,char* text,RECT* rtext,UINT format)
|
---|
879 | {
|
---|
880 | COLORREF textColor = (GetSysColor(COLOR_GRAYTEXT) == GetBkColor(hdc)) ? COLOR_BTNTEXT:COLOR_GRAYTEXT;
|
---|
881 | RECT rect = *rtext;
|
---|
882 | COLORREF oldMode;
|
---|
883 |
|
---|
884 | //CB: bug in Open32 DrawText: underscore is always black! -> two black lines!
|
---|
885 | SetTextColor(hdc,GetSysColor(COLOR_3DHILIGHT));
|
---|
886 | DrawTextA(hdc,text,-1,&rect,format);
|
---|
887 | SetTextColor(hdc,GetSysColor(COLOR_GRAYTEXT));
|
---|
888 | oldMode = SetBkMode(hdc,TRANSPARENT);
|
---|
889 | OffsetRect(&rect,-1,-1);
|
---|
890 | DrawTextA(hdc,text,-1,&rect,format);
|
---|
891 | SetBkMode(hdc,oldMode);
|
---|
892 | }
|
---|
893 |
|
---|
894 | /**********************************************************************
|
---|
895 | * Check Box & Radio Button Functions
|
---|
896 | */
|
---|
897 |
|
---|
898 | static void CB_Paint(HWND hwnd,HDC hDC,WORD action)
|
---|
899 | {
|
---|
900 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
901 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
902 | RECT rbox, rtext, client;
|
---|
903 | HBRUSH hBrush;
|
---|
904 | int textLen, delta;
|
---|
905 | char* text = NULL;
|
---|
906 |
|
---|
907 | /*
|
---|
908 | * if the button has a bitmap/icon, draw a normal pushbutton
|
---|
909 | * instead of a radion button.
|
---|
910 | */
|
---|
911 | if (infoPtr->hImage!=NULL)
|
---|
912 | {
|
---|
913 | BOOL bHighLighted = ((infoPtr->state & BUTTON_HIGHLIGHTED) ||
|
---|
914 | (infoPtr->state & BUTTON_CHECKED));
|
---|
915 |
|
---|
916 | BUTTON_DrawPushButton(hwnd,
|
---|
917 | hDC,
|
---|
918 | action,
|
---|
919 | bHighLighted);
|
---|
920 | return;
|
---|
921 | }
|
---|
922 |
|
---|
923 | textLen = 0;
|
---|
924 | GetClientRect(hwnd, &client);
|
---|
925 | rbox = rtext = client;
|
---|
926 |
|
---|
927 | if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
|
---|
928 |
|
---|
929 | /* Something is still not right, checkboxes (and edit controls)
|
---|
930 | * in wsping32 have white backgrounds instead of dark grey.
|
---|
931 | * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
|
---|
932 | * particular case and the background is not painted at all.
|
---|
933 | */
|
---|
934 | //SvL: 20/09/99: This works well for us. Now the background of
|
---|
935 | // the dialog button strings in Solitaire is gray
|
---|
936 | SendMessageA(GetParent(hwnd),WM_CTLCOLORBTN,hDC,hwnd);
|
---|
937 |
|
---|
938 | hBrush = GetSysColorBrush(COLOR_BTNFACE);
|
---|
939 |
|
---|
940 | if (dwStyle & BS_LEFTTEXT)
|
---|
941 | {
|
---|
942 | /* magic +4 is what CTL3D expects */
|
---|
943 |
|
---|
944 | rtext.right -= checkBoxWidth + 4;
|
---|
945 | rbox.left = rbox.right - checkBoxWidth;
|
---|
946 | }
|
---|
947 | else
|
---|
948 | {
|
---|
949 | rtext.left += checkBoxWidth + 4;
|
---|
950 | rbox.right = checkBoxWidth;
|
---|
951 | }
|
---|
952 |
|
---|
953 | /* Draw the check-box bitmap */
|
---|
954 |
|
---|
955 | textLen = GetWindowTextLengthA(hwnd);
|
---|
956 | if (textLen > 0)
|
---|
957 | {
|
---|
958 | textLen++;
|
---|
959 | text = (char*)malloc(textLen);
|
---|
960 | GetWindowTextA(hwnd,text,textLen);
|
---|
961 | }
|
---|
962 | if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
|
---|
963 | {
|
---|
964 | UINT state;
|
---|
965 |
|
---|
966 | if (((dwStyle & 0x0f) == BS_RADIOBUTTON) ||
|
---|
967 | ((dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) state = DFCS_BUTTONRADIO;
|
---|
968 | else if (infoPtr->state & BUTTON_3STATE) state = DFCS_BUTTON3STATE;
|
---|
969 | else state = DFCS_BUTTONCHECK;
|
---|
970 |
|
---|
971 | if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) state |= DFCS_CHECKED;
|
---|
972 |
|
---|
973 | if (infoPtr->state & BUTTON_HIGHLIGHTED) state |= DFCS_PUSHED;
|
---|
974 |
|
---|
975 | if (dwStyle & WS_DISABLED) state |= DFCS_INACTIVE;
|
---|
976 |
|
---|
977 | if (dwStyle & BS_FLAT) state |= DFCS_FLAT;
|
---|
978 |
|
---|
979 | DrawFrameControl( hDC, &rbox, DFC_BUTTON, state );
|
---|
980 |
|
---|
981 | if( text && action != ODA_SELECT )
|
---|
982 | {
|
---|
983 | INT format = BUTTON_GetTextFormat(dwStyle,DT_TOP,DT_VCENTER);
|
---|
984 |
|
---|
985 | if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rtext,format);
|
---|
986 | else DrawTextA(hDC,text,-1,&rtext,format);
|
---|
987 | }
|
---|
988 | }
|
---|
989 |
|
---|
990 | if ((action == ODA_FOCUS) ||
|
---|
991 | ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS) && IsWindowEnabled(hwnd)))
|
---|
992 | {
|
---|
993 | /* again, this is what CTL3D expects */
|
---|
994 |
|
---|
995 | SetRectEmpty(&rbox);
|
---|
996 | if(textLen > 0)
|
---|
997 | DrawTextA(hDC,text,-1,&rbox,DT_SINGLELINE | DT_CALCRECT);
|
---|
998 | textLen = rbox.bottom - rbox.top;
|
---|
999 | delta = ((rtext.bottom - rtext.top) - textLen)/2;
|
---|
1000 | rbox.bottom = (rbox.top = rtext.top + delta - 1) + textLen + 2;
|
---|
1001 | textLen = rbox.right - rbox.left;
|
---|
1002 | rbox.right = (rbox.left += --rtext.left) + textLen + 2;
|
---|
1003 | IntersectRect(&rbox, &rbox, &rtext);
|
---|
1004 | DrawFocusRect( hDC, &rbox );
|
---|
1005 | }
|
---|
1006 | if (text) free(text);
|
---|
1007 | }
|
---|
1008 |
|
---|
1009 |
|
---|
1010 | /**********************************************************************
|
---|
1011 | * BUTTON_CheckAutoRadioButton
|
---|
1012 | *
|
---|
1013 | * wndPtr is checked, uncheck every other auto radio button in group
|
---|
1014 | */
|
---|
1015 | static void BUTTON_CheckAutoRadioButton(HWND hwnd)
|
---|
1016 | {
|
---|
1017 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
1018 | HWND parent, sibling, start;
|
---|
1019 |
|
---|
1020 | if (!(dwStyle & WS_CHILD)) return;
|
---|
1021 | parent = GetParent(hwnd);
|
---|
1022 | /* assure that starting control is not disabled or invisible */
|
---|
1023 | //start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
|
---|
1024 | //@YD: bugfix
|
---|
1025 | //CB: doesn't work!
|
---|
1026 | start = sibling = GetNextDlgGroupItem( parent, hwnd, FALSE );
|
---|
1027 | do
|
---|
1028 | {
|
---|
1029 | if (!sibling) break;
|
---|
1030 | if ((hwnd != sibling) &&
|
---|
1031 | ((GetWindowLongA(sibling,GWL_STYLE) & 0x0f) == BS_AUTORADIOBUTTON))
|
---|
1032 | SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
|
---|
1033 | sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
|
---|
1034 | } while (sibling != start);
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 |
|
---|
1038 | /**********************************************************************
|
---|
1039 | * Group Box Functions
|
---|
1040 | */
|
---|
1041 |
|
---|
1042 | static void GB_Paint(HWND hwnd,HDC hDC,WORD action)
|
---|
1043 | {
|
---|
1044 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
1045 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
1046 | RECT rc, rcFrame;
|
---|
1047 | TEXTMETRICA tm;
|
---|
1048 | INT textLen;
|
---|
1049 | char* text;
|
---|
1050 |
|
---|
1051 | if (action != ODA_DRAWENTIRE) return;
|
---|
1052 |
|
---|
1053 | SendMessageA(GetParent(hwnd),WM_CTLCOLORBTN,hDC,hwnd);
|
---|
1054 |
|
---|
1055 | GetClientRect(hwnd,&rc);
|
---|
1056 |
|
---|
1057 | rcFrame = rc;
|
---|
1058 |
|
---|
1059 | if (infoPtr->hFont)
|
---|
1060 | SelectObject (hDC, infoPtr->hFont);
|
---|
1061 | GetTextMetricsA (hDC, &tm);
|
---|
1062 | rcFrame.top += (tm.tmHeight / 2) - 1;
|
---|
1063 | DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
|
---|
1064 |
|
---|
1065 | textLen = GetWindowTextLengthA(hwnd);
|
---|
1066 | if (textLen > 0)
|
---|
1067 | {
|
---|
1068 | INT format = BUTTON_GetTextFormat(dwStyle,DT_LEFT,DT_TOP) | DT_NOCLIP | DT_SINGLELINE;
|
---|
1069 |
|
---|
1070 | textLen++;
|
---|
1071 | text = (char*)malloc(textLen);
|
---|
1072 | GetWindowTextA(hwnd,text,textLen);
|
---|
1073 | if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
|
---|
1074 | rc.left += 10;
|
---|
1075 |
|
---|
1076 | if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rc,format); else
|
---|
1077 | {
|
---|
1078 | SetTextColor(hDC,GetSysColor(COLOR_BTNTEXT));
|
---|
1079 | DrawTextA(hDC,text,-1,&rc,format);
|
---|
1080 | }
|
---|
1081 |
|
---|
1082 | free(text);
|
---|
1083 | }
|
---|
1084 | }
|
---|
1085 |
|
---|
1086 |
|
---|
1087 | /**********************************************************************
|
---|
1088 | * User Button Functions
|
---|
1089 | */
|
---|
1090 |
|
---|
1091 | static void UB_Paint(HWND hwnd,HDC hDC,WORD action)
|
---|
1092 | {
|
---|
1093 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
1094 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
1095 | RECT rc;
|
---|
1096 | HBRUSH hBrush;
|
---|
1097 | if (action == ODA_SELECT) return;
|
---|
1098 |
|
---|
1099 | GetClientRect(hwnd,&rc);
|
---|
1100 |
|
---|
1101 | if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
|
---|
1102 | hBrush = GetSysColorBrush(COLOR_BTNFACE);
|
---|
1103 |
|
---|
1104 | if ((action == ODA_FOCUS) ||
|
---|
1105 | ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS) && IsWindowEnabled(hwnd)))
|
---|
1106 | {
|
---|
1107 | DrawFocusRect( hDC, &rc );
|
---|
1108 | InflateRect(&rc,-1,-1);
|
---|
1109 | }
|
---|
1110 | FillRect( hDC, &rc, hBrush );
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 |
|
---|
1114 | /**********************************************************************
|
---|
1115 | * Ownerdrawn Button Functions
|
---|
1116 | */
|
---|
1117 |
|
---|
1118 | static void OB_Paint(HWND hwnd,HDC hDC,WORD action)
|
---|
1119 | {
|
---|
1120 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
---|
1121 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
1122 | DRAWITEMSTRUCT dis;
|
---|
1123 |
|
---|
1124 | dis.CtlType = ODT_BUTTON;
|
---|
1125 | dis.CtlID = GetWindowLongA(hwnd,GWL_ID);
|
---|
1126 | dis.itemID = 0;
|
---|
1127 | dis.itemAction = action;
|
---|
1128 | dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
|
---|
1129 | ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
|
---|
1130 | ((dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
|
---|
1131 | dis.hwndItem = hwnd;
|
---|
1132 | dis.hDC = hDC;
|
---|
1133 | dis.itemData = 0;
|
---|
1134 | GetClientRect( hwnd, &dis.rcItem );
|
---|
1135 |
|
---|
1136 | SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
|
---|
1137 |
|
---|
1138 | dprintf(("OWNERDRAW button %x, enabled %d", hwnd, !(dwStyle & WS_DISABLED)));
|
---|
1139 | SendMessageA( GetParent(hwnd), WM_DRAWITEM,
|
---|
1140 | GetWindowLongA(hwnd,GWL_ID), (LPARAM)&dis );
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | BOOL BUTTON_Register()
|
---|
1144 | {
|
---|
1145 | WNDCLASSA wndClass;
|
---|
1146 |
|
---|
1147 | //SvL: Don't check this now
|
---|
1148 | // if (GlobalFindAtomA(BUTTONCLASSNAME)) return FALSE;
|
---|
1149 |
|
---|
1150 | ZeroMemory(&wndClass,sizeof(WNDCLASSA));
|
---|
1151 | wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW | CS_PARENTDC | CS_DBLCLKS;
|
---|
1152 | wndClass.lpfnWndProc = (WNDPROC)ButtonWndProc;
|
---|
1153 | wndClass.cbClsExtra = 0;
|
---|
1154 | wndClass.cbWndExtra = sizeof(BUTTONINFO);
|
---|
1155 | wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);
|
---|
1156 | // wndClass.hbrBackground = (HBRUSH)0;
|
---|
1157 | wndClass.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
|
---|
1158 | wndClass.lpszClassName = BUTTONCLASSNAME;
|
---|
1159 |
|
---|
1160 | return RegisterClassA(&wndClass);
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | BOOL BUTTON_Unregister()
|
---|
1164 | {
|
---|
1165 | if (GlobalFindAtomA(BUTTONCLASSNAME))
|
---|
1166 | return UnregisterClassA(BUTTONCLASSNAME,(HINSTANCE)NULL);
|
---|
1167 | else return FALSE;
|
---|
1168 | }
|
---|