1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/checkbox.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
)
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 bool wxCheckBox::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
64 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId
);
65 event
.SetInt(GetValue());
66 event
.SetEventObject(this);
67 ProcessCommand(event
);
71 bool wxCheckBox::Create(wxWindow
*parent
,
73 const wxString
& label
,
75 const wxSize
& size
, long style
,
76 const wxValidator
& validator
,
79 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
82 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
;
83 if ( style
& wxALIGN_RIGHT
)
84 msStyle
|= BS_LEFTTEXT
;
86 return MSWCreateControl(wxT("BUTTON"), msStyle
, pos
, size
, label
, 0);
89 void wxCheckBox::SetLabel(const wxString
& label
)
91 SetWindowText(GetHwnd(), label
);
94 wxSize
wxCheckBox::DoGetBestSize() const
96 static int s_checkSize
= 0;
101 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
103 s_checkSize
= dc
.GetCharHeight();
106 wxString str
= wxGetWindowText(GetHWND());
108 int wCheckbox
, hCheckbox
;
109 if ( !str
.IsEmpty() )
111 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
112 wCheckbox
+= s_checkSize
+ GetCharWidth();
114 if ( hCheckbox
< s_checkSize
)
115 hCheckbox
= s_checkSize
;
119 wCheckbox
= s_checkSize
;
120 hCheckbox
= s_checkSize
;
123 return wxSize(wCheckbox
, hCheckbox
);
126 void wxCheckBox::SetValue(bool val
)
128 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
131 bool wxCheckBox::GetValue() const
133 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) & BST_CHECKED
) != 0;
136 void wxCheckBox::Command(wxCommandEvent
& event
)
138 SetValue(event
.GetInt() != 0);
139 ProcessCommand(event
);
142 #endif // wxUSE_CHECKBOX