Release 940815
[wine/gsoc-2012-control.git] / controls / button.c
bloba5d39469446698add18d758dca24f134b95d6356
1 /* File: button.c -- Button type widgets
3 * Copyright (C) 1993 Johannes Ruscheinski
4 * Copyright (C) 1993 David Metcalfe
5 */
7 static char Copyright1[] = "Copyright Johannes Ruscheinski, 1993";
8 static char Copyright2[] = "Copyright David Metcalfe, 1993";
10 #include <windows.h>
11 #include "win.h"
12 #include "user.h"
13 #include "syscolor.h"
15 LONG ButtonWndProc(HWND hWnd, WORD uMsg, WORD wParam, LONG lParam);
17 static BOOL pressed;
19 #define NOTIFY_PARENT(hWndCntrl, wNotifyCode) \
20 SendMessage(GetParent(hWndCntrl), WM_COMMAND, \
21 GetDlgCtrlID(hWndCntrl), MAKELPARAM(hWndCntrl, wNotifyCode));
22 #define DIM(array) ((sizeof array)/(sizeof array[0]))
24 static LONG PB_Paint(HWND hWnd);
25 static LONG PB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam);
26 static LONG PB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam);
27 static LONG PB_LButtonDblClk(HWND hWnd, WORD wParam, LONG lParam);
28 static LONG PB_KillFocus(HWND hwnd);
29 static void DrawRaisedPushButton(HDC hDC, HWND hButton, RECT rc);
30 static void DrawPressedPushButton(HDC hDC, HWND hButton, RECT rc);
31 static LONG CB_Paint(HWND hWnd);
32 static LONG CB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam);
33 static LONG CB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam);
34 static LONG CB_LButtonDblClk(HWND hWnd, WORD wParam, LONG lParam);
35 static LONG CB_KillFocus(HWND hWnd);
36 static LONG CB_SetCheck(HWND hWnd, WORD wParam);
37 static LONG CB_GetCheck(HWND hWnd);
38 static LONG RB_Paint(HWND hWnd);
39 static LONG RB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam);
40 static LONG RB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam);
41 static LONG RB_LButtonDblClk(HWND hWnd, WORD wParam, LONG lParam);
42 static LONG RB_KillFocus(HWND hWnd);
43 static LONG RB_SetCheck(HWND hWnd, WORD wParam);
44 static LONG RB_GetCheck(HWND hWnd);
45 static LONG GB_Paint(HWND hWnd);
46 static LONG UB_Paint(HWND hWnd);
47 static LONG UB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam);
48 static LONG UB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam);
49 static LONG UB_KillFocus(HWND hWnd);
50 static LONG OB_Paint(HWND hWnd);
51 static LONG OB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam);
52 static LONG OB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam);
53 static LONG OB_KillFocus(HWND hWnd);
55 typedef struct
57 LONG (*paintfn)();
58 LONG (*lButtonDownfn)();
59 LONG (*lButtonUpfn)();
60 LONG (*lButtonDblClkfn)();
61 LONG (*killFocusfn)();
62 LONG (*setCheckfn)();
63 LONG (*getCheckfn)();
64 } BTNFN;
66 #define MAX_BTN_TYPE 12
68 static BTNFN btnfn[MAX_BTN_TYPE] =
71 (LONG(*)())PB_Paint, /* BS_PUSHBUTTON */
72 (LONG(*)())PB_LButtonDown,
73 (LONG(*)())PB_LButtonUp,
74 (LONG(*)())PB_LButtonDblClk,
75 (LONG(*)())PB_KillFocus,
76 (LONG(*)())NULL,
77 (LONG(*)())NULL
80 (LONG(*)())PB_Paint, /* BS_DEFPUSHBUTTON */
81 (LONG(*)())PB_LButtonDown,
82 (LONG(*)())PB_LButtonUp,
83 (LONG(*)())PB_LButtonDblClk,
84 (LONG(*)())PB_KillFocus,
85 (LONG(*)())NULL,
86 (LONG(*)())NULL
89 (LONG(*)())CB_Paint, /* BS_CHECKBOX */
90 (LONG(*)())CB_LButtonDown,
91 (LONG(*)())CB_LButtonUp,
92 (LONG(*)())CB_LButtonDblClk,
93 (LONG(*)())CB_KillFocus,
94 (LONG(*)())CB_SetCheck,
95 (LONG(*)())CB_GetCheck
98 (LONG(*)())CB_Paint, /* BS_AUTOCHECKBOX */
99 (LONG(*)())CB_LButtonDown,
100 (LONG(*)())CB_LButtonUp,
101 (LONG(*)())CB_LButtonDblClk,
102 (LONG(*)())CB_KillFocus,
103 (LONG(*)())CB_SetCheck,
104 (LONG(*)())CB_GetCheck
107 (LONG(*)())RB_Paint, /* BS_RADIOBUTTON */
108 (LONG(*)())RB_LButtonDown,
109 (LONG(*)())RB_LButtonUp,
110 (LONG(*)())RB_LButtonDblClk,
111 (LONG(*)())RB_KillFocus,
112 (LONG(*)())RB_SetCheck,
113 (LONG(*)())RB_GetCheck
116 (LONG(*)())CB_Paint, /* BS_3STATE */
117 (LONG(*)())CB_LButtonDown,
118 (LONG(*)())CB_LButtonUp,
119 (LONG(*)())CB_LButtonDblClk,
120 (LONG(*)())CB_KillFocus,
121 (LONG(*)())CB_SetCheck,
122 (LONG(*)())CB_GetCheck
125 (LONG(*)())CB_Paint, /* BS_AUTO3STATE */
126 (LONG(*)())CB_LButtonDown,
127 (LONG(*)())CB_LButtonUp,
128 (LONG(*)())CB_LButtonDblClk,
129 (LONG(*)())CB_KillFocus,
130 (LONG(*)())CB_SetCheck,
131 (LONG(*)())CB_GetCheck
134 (LONG(*)())GB_Paint, /* BS_GROUPBOX */
135 (LONG(*)())NULL,
136 (LONG(*)())NULL,
137 (LONG(*)())NULL,
138 (LONG(*)())NULL,
139 (LONG(*)())NULL,
140 (LONG(*)())NULL
143 (LONG(*)())UB_Paint, /* BS_USERBUTTON */
144 (LONG(*)())UB_LButtonDown,
145 (LONG(*)())UB_LButtonUp,
146 (LONG(*)())NULL,
147 (LONG(*)())UB_KillFocus,
148 (LONG(*)())NULL,
149 (LONG(*)())NULL
152 (LONG(*)())RB_Paint, /* BS_AUTORADIOBUTTON */
153 (LONG(*)())RB_LButtonDown,
154 (LONG(*)())RB_LButtonUp,
155 (LONG(*)())RB_LButtonDblClk,
156 (LONG(*)())RB_KillFocus,
157 (LONG(*)())RB_SetCheck,
158 (LONG(*)())RB_GetCheck
161 (LONG(*)())NULL, /* Not defined */
162 (LONG(*)())NULL,
163 (LONG(*)())NULL,
164 (LONG(*)())NULL,
165 (LONG(*)())NULL,
166 (LONG(*)())NULL,
167 (LONG(*)())NULL
170 (LONG(*)())OB_Paint, /* BS_OWNERDRAW */
171 (LONG(*)())OB_LButtonDown,
172 (LONG(*)())OB_LButtonUp,
173 (LONG(*)())NULL,
174 (LONG(*)())OB_KillFocus,
175 (LONG(*)())NULL,
176 (LONG(*)())NULL
181 LONG ButtonWndProc(HWND hWnd, WORD uMsg, WORD wParam, LONG lParam)
183 LONG lResult = 0;
184 HDC hDC;
185 RECT rc;
187 WND *wndPtr = WIN_FindWndPtr(hWnd);
188 LONG style = wndPtr->dwStyle & 0x0000000F;
190 switch (uMsg) {
191 /* case WM_GETDLGCODE:
192 lResult = DLGC_BUTTON;
193 break;
195 case WM_ENABLE:
196 InvalidateRect(hWnd, NULL, FALSE);
197 break;
199 case WM_CREATE:
200 if (style < 0L || style >= (LONG)DIM(btnfn))
201 lResult = -1L;
202 else
204 (WORD)(*(wndPtr->wExtra)) = 0;
205 pressed = FALSE;
206 lResult = 0L;
208 break;
210 case WM_PAINT:
211 if (btnfn[style].paintfn)
212 (btnfn[style].paintfn)(hWnd);
213 break;
215 case WM_LBUTTONDOWN:
216 if (btnfn[style].lButtonDownfn)
217 (btnfn[style].lButtonDownfn)(hWnd, wParam, lParam);
218 break;
220 case WM_LBUTTONUP:
221 if (btnfn[style].lButtonUpfn)
222 (btnfn[style].lButtonUpfn)(hWnd, wParam, lParam);
223 break;
225 case WM_LBUTTONDBLCLK:
226 if (btnfn[style].lButtonDblClkfn)
227 (btnfn[style].lButtonDblClkfn)(hWnd, wParam, lParam);
228 break;
230 case WM_SETFOCUS:
231 break;
233 case WM_KILLFOCUS:
234 if (btnfn[style].killFocusfn)
235 (btnfn[style].killFocusfn)(hWnd);
236 break;
238 case WM_SYSCOLORCHANGE:
239 InvalidateRect(hWnd, NULL, TRUE);
240 break;
242 case BM_SETCHECK:
243 if (btnfn[style].setCheckfn)
244 (btnfn[style].setCheckfn)(hWnd, wParam);
245 break;
247 case BM_GETCHECK:
248 if (btnfn[style].getCheckfn)
249 return (btnfn[style].getCheckfn)(hWnd);
250 break;
252 default:
253 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
254 break;
257 return lResult;
261 /**********************************************************************
262 * Push Button Functions
265 static LONG PB_Paint(HWND hWnd)
267 PAINTSTRUCT ps;
268 RECT rc;
269 HDC hDC;
271 hDC = BeginPaint(hWnd, &ps);
272 GetClientRect(hWnd, &rc);
273 if (pressed)
274 DrawPressedPushButton(hDC, hWnd, rc);
275 else
276 DrawRaisedPushButton(hDC, hWnd, rc);
277 EndPaint(hWnd, &ps);
280 static LONG PB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam)
282 SetFocus(hWnd);
283 SetCapture(hWnd);
284 pressed = TRUE;
285 InvalidateRect(hWnd, NULL, FALSE);
286 UpdateWindow(hWnd);
289 static LONG PB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam)
291 RECT rc;
293 pressed = FALSE;
294 ReleaseCapture();
295 GetClientRect(hWnd, &rc);
296 if (PtInRect(&rc, MAKEPOINT(lParam)))
297 NOTIFY_PARENT(hWnd, BN_CLICKED);
298 InvalidateRect(hWnd, NULL, FALSE);
299 UpdateWindow(hWnd);
302 static LONG PB_LButtonDblClk(HWND hWnd, WORD wParam, LONG lParam)
304 RECT rc;
306 GetClientRect(hWnd, &rc);
307 if (PtInRect(&rc, MAKEPOINT(lParam)))
308 NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
311 static LONG PB_KillFocus(HWND hWnd)
313 pressed = FALSE;
314 InvalidateRect(hWnd, NULL, FALSE);
315 UpdateWindow(hWnd);
318 static void DrawRaisedPushButton(HDC hDC, HWND hButton, RECT rc)
320 HPEN hOldPen;
321 HBRUSH hOldBrush;
322 HRGN rgn1, rgn2, rgn;
323 int len;
324 static char text[50+1];
325 POINT points[6];
326 DWORD dwTextSize;
327 int delta;
328 TEXTMETRIC tm;
330 hOldPen = (HPEN)SelectObject(hDC, sysColorObjects.hpenWindowFrame);
331 hOldBrush = (HBRUSH)SelectObject(hDC, sysColorObjects.hbrushBtnFace);
332 SetBkMode(hDC, TRANSPARENT);
334 rgn = CreateRectRgn(0, 0, 0, 0);
335 rgn1 = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
337 SendMessage(GetParent(hButton), WM_CTLCOLOR, (WORD)hDC,
338 MAKELPARAM(hButton, CTLCOLOR_BTN));
339 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
341 /* draw button label, if any: */
342 len = GetWindowText(hButton, text, sizeof text);
343 if (len >= 1) {
344 rc.left--; rc.bottom--;
345 DrawText(hDC, text, len, &rc,
346 DT_SINGLELINE | DT_CENTER| DT_VCENTER);
349 /* draw button highlight */
350 points[0].x = rc.left+2;
351 points[0].y = rc.bottom;
352 points[1].x = rc.left+4;
353 points[1].y = rc.bottom-2;
354 points[2].x = rc.left+4;
355 points[2].y = rc.top+3;
356 points[3].x = rc.right-3;
357 points[3].y = rc.top+3;
358 points[4].x = rc.right-1;
359 points[4].y = rc.top+1;
360 points[5].x = rc.left+2;
361 points[5].y = rc.top+1;
362 rgn2 = CreatePolygonRgn(points, DIM(points), ALTERNATE);
363 CombineRgn(rgn, rgn1, rgn2, RGN_AND);
364 FillRgn(hDC, rgn2, sysColorObjects.hbrushBtnHighlight);
366 /* draw button shadow: */
367 points[0].x = rc.left+2;
368 points[0].y = rc.bottom;
369 points[1].x = rc.left+4;
370 points[1].y = rc.bottom-2;
371 points[2].x = rc.right-3;
372 points[2].y = rc.bottom-2;
373 points[3].x = rc.right-3;
374 points[3].y = rc.top+3;
375 points[4].x = rc.right-1;
376 points[4].y = rc.top;
377 points[5].x = rc.right-1;
378 points[5].y = rc.bottom;
379 rgn2 = CreatePolygonRgn(points, DIM(points), ALTERNATE);
380 CombineRgn(rgn, rgn1, rgn2, RGN_AND);
381 FillRgn(hDC, rgn2, sysColorObjects.hbrushBtnShadow);
383 /* do we have the focus? */
384 if (len >= 1 && GetFocus() == hButton) {
385 dwTextSize = GetTextExtent(hDC, text, len);
386 delta = ((rc.right - rc.left) - LOWORD(dwTextSize) - 1) >> 1;
387 rc.left += delta; rc.right -= delta;
388 GetTextMetrics(hDC, &tm);
389 delta = ((rc.bottom - rc.top) - tm.tmHeight - 1) >> 1;
390 rc.top += delta; rc.bottom -= delta;
391 DrawFocusRect(hDC, &rc);
394 SelectObject(hDC, (HANDLE)hOldPen);
395 SelectObject(hDC, (HANDLE)hOldBrush);
396 DeleteObject((HANDLE)rgn1);
397 DeleteObject((HANDLE)rgn2);
398 DeleteObject((HANDLE)rgn);
402 static void DrawPressedPushButton(HDC hDC, HWND hButton, RECT rc)
404 HPEN hOldPen;
405 HBRUSH hOldBrush;
406 int len;
407 static char text[50+1];
408 DWORD dwTextSize;
409 int delta;
410 TEXTMETRIC tm;
412 hOldBrush = (HBRUSH)SelectObject(hDC, sysColorObjects.hbrushBtnFace);
413 hOldPen = (HPEN)SelectObject(hDC, sysColorObjects.hpenWindowFrame);
414 SetBkMode(hDC, TRANSPARENT);
416 /* give parent a chance to alter parameters: */
417 SendMessage(GetParent(hButton), WM_CTLCOLOR, (WORD)hDC,
418 MAKELPARAM(hButton, CTLCOLOR_BTN));
419 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
421 /* draw button shadow: */
422 SelectObject(hDC, sysColorObjects.hbrushBtnShadow );
423 PatBlt(hDC, rc.left+1, rc.top+1, 1, rc.bottom-rc.top-2, PATCOPY );
424 PatBlt(hDC, rc.left+1, rc.top+1, rc.right-rc.left-2, 1, PATCOPY );
426 /* draw button label, if any: */
427 len = GetWindowText(hButton, text, sizeof text);
428 if (len >= 1) {
429 rc.top++; rc.left++;
430 DrawText(hDC, text, len, &rc,
431 DT_SINGLELINE | DT_CENTER| DT_VCENTER);
434 /* do we have the focus? */
435 if (len >= 1 && GetFocus() == hButton) {
436 dwTextSize = GetTextExtent(hDC, text, len);
437 delta = ((rc.right - rc.left) - LOWORD(dwTextSize) - 1) >> 1;
438 rc.left += delta; rc.right -= delta;
439 GetTextMetrics(hDC, &tm);
440 delta = ((rc.bottom - rc.top) - tm.tmHeight - 1) >> 1;
441 rc.top += delta; rc.bottom -= delta;
442 DrawFocusRect(hDC, &rc);
445 SelectObject(hDC, (HANDLE)hOldPen);
446 SelectObject(hDC, (HANDLE)hOldBrush);
450 /**********************************************************************
451 * Check Box Functions
454 static LONG CB_Paint(HWND hWnd)
456 PAINTSTRUCT ps;
457 RECT rc, rc3;
458 HDC hDC;
459 HPEN hOldPen;
460 HBRUSH hBrush, hGrayBrush;
461 int textlen, delta;
462 char *text;
463 HANDLE hText;
464 TEXTMETRIC tm;
465 SIZE size;
466 WND *wndPtr = WIN_FindWndPtr(hWnd);
468 hDC = BeginPaint(hWnd, &ps);
469 GetClientRect(hWnd, &rc);
471 hOldPen = (HPEN)SelectObject(hDC, sysColorObjects.hpenWindowText);
472 hGrayBrush = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
474 hBrush = SendMessage(GetParent(hWnd), WM_CTLCOLOR, (WORD)hDC,
475 MAKELPARAM(hWnd, CTLCOLOR_BTN));
476 FillRect(hDC, &rc, hBrush);
478 textlen = GetWindowTextLength(hWnd);
479 hText = USER_HEAP_ALLOC(0, textlen+1);
480 text = USER_HEAP_ADDR(hText);
481 GetWindowText(hWnd, text, textlen+1);
482 GetTextMetrics(hDC, &tm);
484 delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
485 Rectangle(hDC, 0, rc.top + delta, tm.tmHeight, tm.tmHeight + delta);
486 if (pressed)
487 Rectangle(hDC, 1, rc.top + delta + 1, tm.tmHeight - 1,
488 tm.tmHeight + delta - 1);
490 switch ((WORD)(*(wndPtr->wExtra)))
492 case 1:
493 MoveTo(hDC, 0, rc.top + delta);
494 LineTo(hDC, tm.tmHeight - 1, tm.tmHeight + delta - 1);
495 MoveTo(hDC, 0, tm.tmHeight + delta - 1);
496 LineTo(hDC, tm.tmHeight - 1, rc.top + delta);
497 break;
499 case 2:
500 rc3.left = 1;
501 rc3.top = rc.top + delta + 1;
502 rc3.right = tm.tmHeight - 1;
503 rc3.bottom = tm.tmHeight + delta - 1;
504 FillRect(hDC, &rc3, hGrayBrush);
505 break;
508 rc.left = tm.tmHeight + tm.tmAveCharWidth / 2;
509 DrawText(hDC, text, textlen, &rc, DT_SINGLELINE | DT_VCENTER);
511 /* do we have the focus? */
512 if (GetFocus() == hWnd)
514 GetTextExtentPoint(hDC, text, textlen, &size);
515 rc.top += delta - 1;
516 rc.bottom -= delta + 1;
517 rc.left--;
518 rc.right = rc.left + size.cx + 2;
519 DrawFocusRect(hDC, &rc);
522 SelectObject(hDC, hOldPen);
523 USER_HEAP_FREE(hText);
524 EndPaint(hWnd, &ps);
527 static LONG CB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam)
529 RECT rc;
530 HDC hDC;
531 TEXTMETRIC tm;
532 int delta;
534 hDC = GetDC(hWnd);
535 GetTextMetrics(hDC, &tm);
536 ReleaseDC(hWnd, hDC);
537 GetClientRect(hWnd, &rc);
538 delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
539 rc.top += delta;
540 rc.bottom = tm.tmHeight + delta;
541 if (PtInRect(&rc, MAKEPOINT(lParam)))
543 SetFocus(hWnd);
544 SetCapture(hWnd);
545 pressed = TRUE;
546 InvalidateRect(hWnd, NULL, FALSE);
547 UpdateWindow(hWnd);
551 static LONG CB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam)
553 RECT rc;
554 HDC hDC;
555 TEXTMETRIC tm;
556 int delta;
557 WND *wndPtr = WIN_FindWndPtr(hWnd);
558 LONG style;
560 pressed = FALSE;
561 ReleaseCapture();
562 hDC = GetDC(hWnd);
563 GetTextMetrics(hDC, &tm);
564 ReleaseDC(hWnd, hDC);
565 GetClientRect(hWnd, &rc);
566 delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
567 rc.top += delta;
568 rc.bottom = tm.tmHeight + delta;
570 if (PtInRect(&rc, MAKEPOINT(lParam)))
572 style = wndPtr->dwStyle & 0x0000000F;
573 if (style == BS_AUTOCHECKBOX)
575 switch ((WORD)(*(wndPtr->wExtra)))
577 case 0:
578 (WORD)(*(wndPtr->wExtra)) = 1;
579 break;
581 case 1:
582 (WORD)(*(wndPtr->wExtra)) = 0;
583 break;
586 else if (style == BS_AUTO3STATE)
588 switch ((WORD)(*(wndPtr->wExtra)))
590 case 0:
591 (WORD)(*(wndPtr->wExtra)) = 1;
592 break;
594 case 1:
595 (WORD)(*(wndPtr->wExtra)) = 2;
596 break;
598 case 2:
599 (WORD)(*(wndPtr->wExtra)) = 0;
600 break;
603 NOTIFY_PARENT(hWnd, BN_CLICKED);
605 InvalidateRect(hWnd, NULL, FALSE);
606 UpdateWindow(hWnd);
609 static LONG CB_LButtonDblClk(HWND hWnd, WORD wParam, LONG lParam)
611 RECT rc;
612 HDC hDC;
613 TEXTMETRIC tm;
614 int delta;
616 hDC = GetDC(hWnd);
617 GetTextMetrics(hDC, &tm);
618 ReleaseDC(hWnd, hDC);
619 GetClientRect(hWnd, &rc);
620 delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
621 rc.top += delta;
622 rc.bottom = tm.tmHeight + delta;
623 if (PtInRect(&rc, MAKEPOINT(lParam)))
624 NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
627 static LONG CB_KillFocus(HWND hWnd)
629 pressed = FALSE;
630 InvalidateRect(hWnd, NULL, FALSE);
631 UpdateWindow(hWnd);
634 static LONG CB_SetCheck(HWND hWnd, WORD wParam)
636 WND *wndPtr = WIN_FindWndPtr(hWnd);
638 if ((WORD)(*(wndPtr->wExtra)) != wParam)
640 (WORD)(*(wndPtr->wExtra)) = wParam;
641 InvalidateRect(hWnd, NULL, FALSE);
642 UpdateWindow(hWnd);
646 static LONG CB_GetCheck(HWND hWnd)
648 WORD wResult;
649 WND *wndPtr = WIN_FindWndPtr(hWnd);
651 wResult = (WORD)(*(wndPtr->wExtra));
652 return (LONG)wResult;
656 /**********************************************************************
657 * Radio Button Functions
660 static LONG RB_Paint(HWND hWnd)
662 PAINTSTRUCT ps;
663 RECT rc;
664 HDC hDC;
665 HPEN hOldPen;
666 HBRUSH hBrush, hOldBrush;
667 int textlen, delta;
668 char *text;
669 HANDLE hText;
670 TEXTMETRIC tm;
671 SIZE size;
672 WND *wndPtr = WIN_FindWndPtr(hWnd);
674 hDC = BeginPaint(hWnd, &ps);
675 GetClientRect(hWnd, &rc);
677 hOldPen = (HPEN)SelectObject(hDC, sysColorObjects.hpenWindowText);
679 hBrush = SendMessage(GetParent(hWnd), WM_CTLCOLOR, (WORD)hDC,
680 MAKELPARAM(hWnd, CTLCOLOR_BTN));
681 FillRect(hDC, &rc, hBrush);
683 textlen = GetWindowTextLength(hWnd);
684 hText = USER_HEAP_ALLOC(0, textlen+1);
685 text = USER_HEAP_ADDR(hText);
686 GetWindowText(hWnd, text, textlen+1);
687 GetTextMetrics(hDC, &tm);
689 delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
690 Ellipse(hDC, 0, rc.top + delta, tm.tmHeight, tm.tmHeight + delta);
691 if (pressed)
692 Ellipse(hDC, 1, rc.top + delta + 1, tm.tmHeight - 1,
693 tm.tmHeight + delta - 1);
695 if ((WORD)(*(wndPtr->wExtra)) == 1)
697 hBrush = CreateSolidBrush( GetNearestColor(hDC, GetSysColor(COLOR_WINDOWTEXT)));
698 hOldBrush = (HBRUSH)SelectObject(hDC, (HANDLE)hBrush);
699 Ellipse(hDC, 3, rc.top + delta + 3, tm.tmHeight - 3,
700 tm.tmHeight + delta -3);
701 SelectObject(hDC, (HANDLE)hOldBrush);
702 DeleteObject((HANDLE)hBrush);
705 rc.left = tm.tmHeight + tm.tmAveCharWidth / 2;
706 DrawText(hDC, text, textlen, &rc, DT_SINGLELINE | DT_VCENTER);
708 /* do we have the focus? */
709 if (GetFocus() == hWnd)
711 GetTextExtentPoint(hDC, text, textlen, &size);
712 rc.top += delta - 1;
713 rc.bottom -= delta + 1;
714 rc.left--;
715 rc.right = rc.left + size.cx + 2;
716 DrawFocusRect(hDC, &rc);
719 SelectObject(hDC, hOldPen );
720 USER_HEAP_FREE(hText);
721 EndPaint(hWnd, &ps);
724 static LONG RB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam)
726 RECT rc;
727 HDC hDC;
728 TEXTMETRIC tm;
729 int delta;
731 hDC = GetDC(hWnd);
732 GetTextMetrics(hDC, &tm);
733 ReleaseDC(hWnd, hDC);
734 GetClientRect(hWnd, &rc);
735 delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
736 rc.top += delta;
737 rc.bottom = tm.tmHeight + delta;
738 if (PtInRect(&rc, MAKEPOINT(lParam)))
740 SetFocus(hWnd);
741 SetCapture(hWnd);
742 pressed = TRUE;
743 InvalidateRect(hWnd, NULL, FALSE);
744 UpdateWindow(hWnd);
748 static LONG RB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam)
750 RECT rc;
751 HDC hDC;
752 TEXTMETRIC tm;
753 int delta;
754 WND *wndPtr = WIN_FindWndPtr(hWnd);
755 LONG style;
757 pressed = FALSE;
758 ReleaseCapture();
759 hDC = GetDC(hWnd);
760 GetTextMetrics(hDC, &tm);
761 ReleaseDC(hWnd, hDC);
762 GetClientRect(hWnd, &rc);
763 delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
764 rc.top += delta;
765 rc.bottom = tm.tmHeight + delta;
767 if (PtInRect(&rc, MAKEPOINT(lParam)))
769 style = wndPtr->dwStyle & 0x0000000F;
770 if (style == BS_AUTORADIOBUTTON)
771 (WORD)(*(wndPtr->wExtra)) = 1;
772 NOTIFY_PARENT(hWnd, BN_CLICKED);
774 InvalidateRect(hWnd, NULL, FALSE);
775 UpdateWindow(hWnd);
778 static LONG RB_LButtonDblClk(HWND hWnd, WORD wParam, LONG lParam)
780 RECT rc;
781 HDC hDC;
782 TEXTMETRIC tm;
783 int delta;
785 hDC = GetDC(hWnd);
786 GetTextMetrics(hDC, &tm);
787 ReleaseDC(hWnd, hDC);
788 GetClientRect(hWnd, &rc);
789 delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
790 rc.top += delta;
791 rc.bottom = tm.tmHeight + delta;
792 if (PtInRect(&rc, MAKEPOINT(lParam)))
793 NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
796 static LONG RB_KillFocus(HWND hWnd)
798 pressed = FALSE;
799 InvalidateRect(hWnd, NULL, FALSE);
800 UpdateWindow(hWnd);
803 static LONG RB_SetCheck(HWND hWnd, WORD wParam)
805 WND *wndPtr = WIN_FindWndPtr(hWnd);
807 if ((WORD)(*(wndPtr->wExtra)) != wParam)
809 (WORD)(*(wndPtr->wExtra)) = wParam;
810 InvalidateRect(hWnd, NULL, FALSE);
811 UpdateWindow(hWnd);
815 static LONG RB_GetCheck(HWND hWnd)
817 WORD wResult;
818 WND *wndPtr = WIN_FindWndPtr(hWnd);
820 wResult = (WORD)(*(wndPtr->wExtra));
821 return (LONG)wResult;
825 /**********************************************************************
826 * Group Box Functions
829 static LONG GB_Paint(HWND hWnd)
831 PAINTSTRUCT ps;
832 RECT rc;
833 HDC hDC;
834 HPEN hOldPen;
835 HBRUSH hBrush;
836 int textlen;
837 char *text;
838 HANDLE hText;
839 SIZE size;
841 hDC = BeginPaint(hWnd, &ps);
842 GetClientRect(hWnd, &rc);
844 hOldPen = (HPEN)SelectObject(hDC, sysColorObjects.hpenWindowText);
846 hBrush = SendMessage(GetParent(hWnd), WM_CTLCOLOR, (WORD)hDC,
847 MAKELPARAM(hWnd, CTLCOLOR_BTN));
848 FillRect(hDC, &rc, hBrush);
850 textlen = GetWindowTextLength(hWnd);
851 hText = USER_HEAP_ALLOC(0, textlen+1);
852 text = USER_HEAP_ADDR(hText);
853 GetWindowText(hWnd, text, textlen+1);
854 GetTextExtentPoint(hDC, text, textlen, &size);
856 rc.top = 5;
857 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
858 rc.left = 10;
859 rc.top = 0;
860 rc.right = rc.left + size.cx + 1;
861 rc.bottom = size.cy;
862 DrawText(hDC, text, textlen, &rc, DT_SINGLELINE);
864 SelectObject(hDC, hOldPen );
865 USER_HEAP_FREE(hText);
866 EndPaint(hWnd, &ps);
870 /**********************************************************************
871 * User Button Functions
874 static LONG UB_Paint(HWND hWnd)
876 PAINTSTRUCT ps;
877 HDC hDC;
878 RECT rc;
879 HBRUSH hBrush;
881 hDC = BeginPaint(hWnd, &ps);
882 GetClientRect(hWnd, &rc);
884 hBrush = SendMessage(GetParent(hWnd), WM_CTLCOLOR, (WORD)hDC,
885 MAKELPARAM(hWnd, CTLCOLOR_BTN));
886 FillRect(hDC, &rc, hBrush);
888 NOTIFY_PARENT(hWnd, BN_PAINT);
890 /* do we have the focus? */
891 if (GetFocus() == hWnd)
892 DrawFocusRect(hDC, &rc);
894 EndPaint(hWnd, &ps);
897 static LONG UB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam)
899 RECT rc;
901 SetFocus(hWnd);
902 SetCapture(hWnd);
903 GetClientRect(hWnd, &rc);
904 if (PtInRect(&rc, MAKEPOINT(lParam)))
905 NOTIFY_PARENT(hWnd, BN_HILITE);
906 InvalidateRect(hWnd, NULL, FALSE);
907 UpdateWindow(hWnd);
910 static LONG UB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam)
912 RECT rc;
914 ReleaseCapture();
915 GetClientRect(hWnd, &rc);
916 if (PtInRect(&rc, MAKEPOINT(lParam)))
918 NOTIFY_PARENT(hWnd, BN_CLICKED);
919 NOTIFY_PARENT(hWnd, BN_UNHILITE);
921 InvalidateRect(hWnd, NULL, FALSE);
922 UpdateWindow(hWnd);
925 static LONG UB_KillFocus(HWND hWnd)
927 InvalidateRect(hWnd, NULL, FALSE);
928 UpdateWindow(hWnd);
932 /**********************************************************************
933 * Ownerdrawn Button Functions
936 static LONG OB_Paint(HWND hWnd)
938 PAINTSTRUCT ps;
939 HDC hDC;
940 RECT rc;
941 HANDLE hDis;
942 LPDRAWITEMSTRUCT lpdis;
943 WND *wndPtr = WIN_FindWndPtr(hWnd);
944 hDC = BeginPaint(hWnd, &ps);
945 GetClientRect(hWnd, &rc);
946 hDis = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(DRAWITEMSTRUCT));
947 lpdis = (LPDRAWITEMSTRUCT)USER_HEAP_ADDR(hDis);
948 lpdis->hDC = hDC;
949 lpdis->itemID = 0;
950 CopyRect(&lpdis->rcItem, &rc);
951 lpdis->CtlID = wndPtr->wIDmenu;
952 lpdis->CtlType = ODT_BUTTON;
953 lpdis->itemAction = ODA_DRAWENTIRE;
954 /* printf("ownerdrawn button WM_DRAWITEM CtrlID=%X\n", lpdis->CtlID);*/
955 SendMessage(GetParent(hWnd), WM_DRAWITEM, 1, (LPARAM)lpdis);
956 USER_HEAP_FREE(hDis);
957 EndPaint(hWnd, &ps);
960 static LONG OB_LButtonDown(HWND hWnd, WORD wParam, LONG lParam)
962 HDC hDC;
963 RECT rc;
964 HANDLE hDis;
965 LPDRAWITEMSTRUCT lpdis;
966 WND *wndPtr = WIN_FindWndPtr(hWnd);
967 SetFocus(hWnd);
968 SetCapture(hWnd);
969 hDC = GetDC(hWnd);
970 GetClientRect(hWnd, &rc);
971 if (PtInRect(&rc, MAKEPOINT(lParam)))
972 NOTIFY_PARENT(hWnd, BN_CLICKED);
973 GetClientRect(hWnd, &rc);
974 hDis = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(DRAWITEMSTRUCT));
975 lpdis = (LPDRAWITEMSTRUCT)USER_HEAP_ADDR(hDis);
976 lpdis->hDC = hDC;
977 lpdis->itemID = 0;
978 CopyRect(&lpdis->rcItem, &rc);
979 lpdis->CtlID = wndPtr->wIDmenu;
980 lpdis->CtlType = ODT_BUTTON;
981 lpdis->itemAction = ODA_SELECT;
982 SendMessage(GetParent(hWnd), WM_DRAWITEM, 1, (LPARAM)lpdis);
983 USER_HEAP_FREE(hDis);
984 ReleaseDC(hWnd, hDC);
987 static LONG OB_LButtonUp(HWND hWnd, WORD wParam, LONG lParam)
989 HDC hDC;
990 RECT rc;
991 HANDLE hDis;
992 LPDRAWITEMSTRUCT lpdis;
993 WND *wndPtr = WIN_FindWndPtr(hWnd);
994 ReleaseCapture();
995 hDC = GetDC(hWnd);
996 GetClientRect(hWnd, &rc);
997 if (PtInRect(&rc, MAKEPOINT(lParam)))
998 NOTIFY_PARENT(hWnd, BN_CLICKED);
999 GetClientRect(hWnd, &rc);
1000 hDis = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(DRAWITEMSTRUCT));
1001 lpdis = (LPDRAWITEMSTRUCT)USER_HEAP_ADDR(hDis);
1002 lpdis->hDC = hDC;
1003 lpdis->itemID = 0;
1004 CopyRect(&lpdis->rcItem, &rc);
1005 lpdis->CtlID = wndPtr->wIDmenu;
1006 lpdis->CtlType = ODT_BUTTON;
1007 lpdis->itemAction = ODA_SELECT;
1008 SendMessage(GetParent(hWnd), WM_DRAWITEM, 1, (LPARAM)lpdis);
1009 USER_HEAP_FREE(hDis);
1010 ReleaseDC(hWnd, hDC);
1013 static LONG OB_KillFocus(HWND hWnd)
1015 InvalidateRect(hWnd, NULL, FALSE);
1016 UpdateWindow(hWnd);