1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/checkbox.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "checkbox.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/checkbox.h"
36 #include "wx/dcscreen.h"
37 #include "wx/settings.h"
40 #include "wx/msw/private.h"
43 #define BST_CHECKED 0x0001
46 // ============================================================================
48 // ============================================================================
50 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 bool wxCheckBox::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
58 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId
);
59 event
.SetInt(GetValue());
60 event
.SetEventObject(this);
61 ProcessCommand(event
);
65 bool wxCheckBox::Create(wxWindow
*parent
,
67 const wxString
& label
,
69 const wxSize
& size
, long style
,
70 const wxValidator
& validator
,
73 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
76 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
;
77 if ( style
& wxALIGN_RIGHT
)
78 msStyle
|= BS_LEFTTEXT
;
80 return MSWCreateControl(wxT("BUTTON"), msStyle
, pos
, size
, label
, 0);
83 void wxCheckBox::SetLabel(const wxString
& label
)
85 SetWindowText(GetHwnd(), label
);
88 wxSize
wxCheckBox::DoGetBestSize() const
90 static int s_checkSize
= 0;
95 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
97 s_checkSize
= dc
.GetCharHeight();
100 wxString str
= wxGetWindowText(GetHWND());
102 int wCheckbox
, hCheckbox
;
103 if ( !str
.IsEmpty() )
105 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
106 wCheckbox
+= s_checkSize
+ GetCharWidth();
108 if ( hCheckbox
< s_checkSize
)
109 hCheckbox
= s_checkSize
;
113 wCheckbox
= s_checkSize
;
114 hCheckbox
= s_checkSize
;
117 return wxSize(wCheckbox
, hCheckbox
);
120 void wxCheckBox::SetValue(bool val
)
122 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
125 bool wxCheckBox::GetValue() const
127 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) & BST_CHECKED
) != 0;
130 void wxCheckBox::Command(wxCommandEvent
& event
)
132 SetValue(event
.GetInt() != 0);
133 ProcessCommand(event
);
136 #endif // wxUSE_CHECKBOX