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 #if wxUSE_EXTENDED_RTTI
51 IMPLEMENT_DYNAMIC_CLASS_XTI(wxCheckBox
, wxControl
,"wx/checkbox.h")
53 WX_BEGIN_PROPERTIES_TABLE(wxCheckBox
)
54 WX_DELEGATE( OnClick
, wxEVT_COMMAND_CHECKBOX_CLICKED
, wxCommandEvent
)
56 WX_PROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
57 WX_PROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxT("") )
58 WX_PROPERTY( Value
,bool, SetValue
, GetValue
, )
59 WX_END_PROPERTIES_TABLE()
61 WX_BEGIN_HANDLERS_TABLE(wxCheckBox
)
62 WX_END_HANDLERS_TABLE()
64 WX_CONSTRUCTOR_6( wxCheckBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Label
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
66 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 bool wxCheckBox::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
76 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId
);
77 event
.SetInt(GetValue());
78 event
.SetEventObject(this);
79 ProcessCommand(event
);
83 bool wxCheckBox::Create(wxWindow
*parent
,
85 const wxString
& label
,
87 const wxSize
& size
, long style
,
88 const wxValidator
& validator
,
91 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
94 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
;
95 if ( style
& wxALIGN_RIGHT
)
96 msStyle
|= BS_LEFTTEXT
;
98 return MSWCreateControl(wxT("BUTTON"), msStyle
, pos
, size
, label
, 0);
101 void wxCheckBox::SetLabel(const wxString
& label
)
103 SetWindowText(GetHwnd(), label
);
106 wxSize
wxCheckBox::DoGetBestSize() const
108 static int s_checkSize
= 0;
113 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
115 s_checkSize
= dc
.GetCharHeight();
118 wxString str
= wxGetWindowText(GetHWND());
120 int wCheckbox
, hCheckbox
;
121 if ( !str
.IsEmpty() )
123 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
124 wCheckbox
+= s_checkSize
+ GetCharWidth();
126 if ( hCheckbox
< s_checkSize
)
127 hCheckbox
= s_checkSize
;
131 wCheckbox
= s_checkSize
;
132 hCheckbox
= s_checkSize
;
135 return wxSize(wCheckbox
, hCheckbox
);
138 void wxCheckBox::SetValue(bool val
)
140 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
143 bool wxCheckBox::GetValue() const
145 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) & BST_CHECKED
) != 0;
148 void wxCheckBox::Command(wxCommandEvent
& event
)
150 SetValue(event
.GetInt() != 0);
151 ProcessCommand(event
);
154 #endif // wxUSE_CHECKBOX