1 /* File: button.c -- Button type widgets
3 * Copyright (C) 1993 Johannes Ruscheinski
4 * Copyright (C) 1993 David Metcalfe
7 static char Copyright1
[] = "Copyright Johannes Ruscheinski, 1993";
8 static char Copyright2
[] = "Copyright David Metcalfe, 1993";
15 LONG
ButtonWndProc(HWND hWnd
, WORD uMsg
, WORD wParam
, LONG lParam
);
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
);
58 LONG (*lButtonDownfn
)();
59 LONG (*lButtonUpfn
)();
60 LONG (*lButtonDblClkfn
)();
61 LONG (*killFocusfn
)();
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
,
80 (LONG(*)())PB_Paint
, /* BS_DEFPUSHBUTTON */
81 (LONG(*)())PB_LButtonDown
,
82 (LONG(*)())PB_LButtonUp
,
83 (LONG(*)())PB_LButtonDblClk
,
84 (LONG(*)())PB_KillFocus
,
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 */
143 (LONG(*)())UB_Paint
, /* BS_USERBUTTON */
144 (LONG(*)())UB_LButtonDown
,
145 (LONG(*)())UB_LButtonUp
,
147 (LONG(*)())UB_KillFocus
,
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 */
170 (LONG(*)())OB_Paint
, /* BS_OWNERDRAW */
171 (LONG(*)())OB_LButtonDown
,
172 (LONG(*)())OB_LButtonUp
,
174 (LONG(*)())OB_KillFocus
,
181 LONG
ButtonWndProc(HWND hWnd
, WORD uMsg
, WORD wParam
, LONG lParam
)
187 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
188 LONG style
= wndPtr
->dwStyle
& 0x0000000F;
191 /* case WM_GETDLGCODE:
192 lResult = DLGC_BUTTON;
196 InvalidateRect(hWnd
, NULL
, FALSE
);
200 if (style
< 0L || style
>= (LONG
)DIM(btnfn
))
204 (WORD
)(*(wndPtr
->wExtra
)) = 0;
211 if (btnfn
[style
].paintfn
)
212 (btnfn
[style
].paintfn
)(hWnd
);
216 if (btnfn
[style
].lButtonDownfn
)
217 (btnfn
[style
].lButtonDownfn
)(hWnd
, wParam
, lParam
);
221 if (btnfn
[style
].lButtonUpfn
)
222 (btnfn
[style
].lButtonUpfn
)(hWnd
, wParam
, lParam
);
225 case WM_LBUTTONDBLCLK
:
226 if (btnfn
[style
].lButtonDblClkfn
)
227 (btnfn
[style
].lButtonDblClkfn
)(hWnd
, wParam
, lParam
);
234 if (btnfn
[style
].killFocusfn
)
235 (btnfn
[style
].killFocusfn
)(hWnd
);
238 case WM_SYSCOLORCHANGE
:
239 InvalidateRect(hWnd
, NULL
, TRUE
);
243 if (btnfn
[style
].setCheckfn
)
244 (btnfn
[style
].setCheckfn
)(hWnd
, wParam
);
248 if (btnfn
[style
].getCheckfn
)
249 return (btnfn
[style
].getCheckfn
)(hWnd
);
253 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
261 /**********************************************************************
262 * Push Button Functions
265 static LONG
PB_Paint(HWND hWnd
)
271 hDC
= BeginPaint(hWnd
, &ps
);
272 GetClientRect(hWnd
, &rc
);
274 DrawPressedPushButton(hDC
, hWnd
, rc
);
276 DrawRaisedPushButton(hDC
, hWnd
, rc
);
280 static LONG
PB_LButtonDown(HWND hWnd
, WORD wParam
, LONG lParam
)
285 InvalidateRect(hWnd
, NULL
, FALSE
);
289 static LONG
PB_LButtonUp(HWND hWnd
, WORD wParam
, LONG lParam
)
295 GetClientRect(hWnd
, &rc
);
296 if (PtInRect(&rc
, MAKEPOINT(lParam
)))
297 NOTIFY_PARENT(hWnd
, BN_CLICKED
);
298 InvalidateRect(hWnd
, NULL
, FALSE
);
302 static LONG
PB_LButtonDblClk(HWND hWnd
, WORD wParam
, LONG lParam
)
306 GetClientRect(hWnd
, &rc
);
307 if (PtInRect(&rc
, MAKEPOINT(lParam
)))
308 NOTIFY_PARENT(hWnd
, BN_DOUBLECLICKED
);
311 static LONG
PB_KillFocus(HWND hWnd
)
314 InvalidateRect(hWnd
, NULL
, FALSE
);
318 static void DrawRaisedPushButton(HDC hDC
, HWND hButton
, RECT rc
)
322 HRGN rgn1
, rgn2
, rgn
;
324 static char text
[50+1];
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
);
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
)
407 static char text
[50+1];
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
);
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
)
460 HBRUSH hBrush
, hGrayBrush
;
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
);
487 Rectangle(hDC
, 1, rc
.top
+ delta
+ 1, tm
.tmHeight
- 1,
488 tm
.tmHeight
+ delta
- 1);
490 switch ((WORD
)(*(wndPtr
->wExtra
)))
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
);
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
);
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
);
516 rc
.bottom
-= delta
+ 1;
518 rc
.right
= rc
.left
+ size
.cx
+ 2;
519 DrawFocusRect(hDC
, &rc
);
522 SelectObject(hDC
, hOldPen
);
523 USER_HEAP_FREE(hText
);
527 static LONG
CB_LButtonDown(HWND hWnd
, WORD wParam
, LONG lParam
)
535 GetTextMetrics(hDC
, &tm
);
536 ReleaseDC(hWnd
, hDC
);
537 GetClientRect(hWnd
, &rc
);
538 delta
= (rc
.bottom
- rc
.top
- tm
.tmHeight
) >> 1;
540 rc
.bottom
= tm
.tmHeight
+ delta
;
541 if (PtInRect(&rc
, MAKEPOINT(lParam
)))
546 InvalidateRect(hWnd
, NULL
, FALSE
);
551 static LONG
CB_LButtonUp(HWND hWnd
, WORD wParam
, LONG lParam
)
557 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
563 GetTextMetrics(hDC
, &tm
);
564 ReleaseDC(hWnd
, hDC
);
565 GetClientRect(hWnd
, &rc
);
566 delta
= (rc
.bottom
- rc
.top
- tm
.tmHeight
) >> 1;
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
)))
578 (WORD
)(*(wndPtr
->wExtra
)) = 1;
582 (WORD
)(*(wndPtr
->wExtra
)) = 0;
586 else if (style
== BS_AUTO3STATE
)
588 switch ((WORD
)(*(wndPtr
->wExtra
)))
591 (WORD
)(*(wndPtr
->wExtra
)) = 1;
595 (WORD
)(*(wndPtr
->wExtra
)) = 2;
599 (WORD
)(*(wndPtr
->wExtra
)) = 0;
603 NOTIFY_PARENT(hWnd
, BN_CLICKED
);
605 InvalidateRect(hWnd
, NULL
, FALSE
);
609 static LONG
CB_LButtonDblClk(HWND hWnd
, WORD wParam
, LONG lParam
)
617 GetTextMetrics(hDC
, &tm
);
618 ReleaseDC(hWnd
, hDC
);
619 GetClientRect(hWnd
, &rc
);
620 delta
= (rc
.bottom
- rc
.top
- tm
.tmHeight
) >> 1;
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
)
630 InvalidateRect(hWnd
, NULL
, FALSE
);
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
);
646 static LONG
CB_GetCheck(HWND hWnd
)
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
)
666 HBRUSH hBrush
, hOldBrush
;
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
);
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
);
713 rc
.bottom
-= delta
+ 1;
715 rc
.right
= rc
.left
+ size
.cx
+ 2;
716 DrawFocusRect(hDC
, &rc
);
719 SelectObject(hDC
, hOldPen
);
720 USER_HEAP_FREE(hText
);
724 static LONG
RB_LButtonDown(HWND hWnd
, WORD wParam
, LONG lParam
)
732 GetTextMetrics(hDC
, &tm
);
733 ReleaseDC(hWnd
, hDC
);
734 GetClientRect(hWnd
, &rc
);
735 delta
= (rc
.bottom
- rc
.top
- tm
.tmHeight
) >> 1;
737 rc
.bottom
= tm
.tmHeight
+ delta
;
738 if (PtInRect(&rc
, MAKEPOINT(lParam
)))
743 InvalidateRect(hWnd
, NULL
, FALSE
);
748 static LONG
RB_LButtonUp(HWND hWnd
, WORD wParam
, LONG lParam
)
754 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
760 GetTextMetrics(hDC
, &tm
);
761 ReleaseDC(hWnd
, hDC
);
762 GetClientRect(hWnd
, &rc
);
763 delta
= (rc
.bottom
- rc
.top
- tm
.tmHeight
) >> 1;
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
);
778 static LONG
RB_LButtonDblClk(HWND hWnd
, WORD wParam
, LONG lParam
)
786 GetTextMetrics(hDC
, &tm
);
787 ReleaseDC(hWnd
, hDC
);
788 GetClientRect(hWnd
, &rc
);
789 delta
= (rc
.bottom
- rc
.top
- tm
.tmHeight
) >> 1;
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
)
799 InvalidateRect(hWnd
, NULL
, FALSE
);
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
);
815 static LONG
RB_GetCheck(HWND hWnd
)
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
)
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
);
857 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
860 rc
.right
= rc
.left
+ size
.cx
+ 1;
862 DrawText(hDC
, text
, textlen
, &rc
, DT_SINGLELINE
);
864 SelectObject(hDC
, hOldPen
);
865 USER_HEAP_FREE(hText
);
870 /**********************************************************************
871 * User Button Functions
874 static LONG
UB_Paint(HWND hWnd
)
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
);
897 static LONG
UB_LButtonDown(HWND hWnd
, WORD wParam
, LONG lParam
)
903 GetClientRect(hWnd
, &rc
);
904 if (PtInRect(&rc
, MAKEPOINT(lParam
)))
905 NOTIFY_PARENT(hWnd
, BN_HILITE
);
906 InvalidateRect(hWnd
, NULL
, FALSE
);
910 static LONG
UB_LButtonUp(HWND hWnd
, WORD wParam
, LONG lParam
)
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
);
925 static LONG
UB_KillFocus(HWND hWnd
)
927 InvalidateRect(hWnd
, NULL
, FALSE
);
932 /**********************************************************************
933 * Ownerdrawn Button Functions
936 static LONG
OB_Paint(HWND hWnd
)
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
);
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
);
960 static LONG
OB_LButtonDown(HWND hWnd
, WORD wParam
, LONG lParam
)
965 LPDRAWITEMSTRUCT lpdis
;
966 WND
*wndPtr
= WIN_FindWndPtr(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
);
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
)
992 LPDRAWITEMSTRUCT lpdis
;
993 WND
*wndPtr
= WIN_FindWndPtr(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
);
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
);