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