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 WX_DEFINE_FLAGS( wxCheckBoxStyle
)
53 WX_BEGIN_FLAGS( wxCheckBoxStyle
)
54 // new style border flags, we put them first to
55 // use them for streaming out
56 WX_FLAGS_MEMBER(wxBORDER_SIMPLE
)
57 WX_FLAGS_MEMBER(wxBORDER_SUNKEN
)
58 WX_FLAGS_MEMBER(wxBORDER_DOUBLE
)
59 WX_FLAGS_MEMBER(wxBORDER_RAISED
)
60 WX_FLAGS_MEMBER(wxBORDER_STATIC
)
61 WX_FLAGS_MEMBER(wxBORDER_NONE
)
63 // old style border flags
64 WX_FLAGS_MEMBER(wxSIMPLE_BORDER
)
65 WX_FLAGS_MEMBER(wxSUNKEN_BORDER
)
66 WX_FLAGS_MEMBER(wxDOUBLE_BORDER
)
67 WX_FLAGS_MEMBER(wxRAISED_BORDER
)
68 WX_FLAGS_MEMBER(wxSTATIC_BORDER
)
69 WX_FLAGS_MEMBER(wxNO_BORDER
)
71 // standard window styles
72 WX_FLAGS_MEMBER(wxTAB_TRAVERSAL
)
73 WX_FLAGS_MEMBER(wxCLIP_CHILDREN
)
74 WX_FLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
75 WX_FLAGS_MEMBER(wxWANTS_CHARS
)
76 WX_FLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE
)
77 WX_FLAGS_MEMBER(wxALWAYS_SHOW_SB
)
78 WX_FLAGS_MEMBER(wxVSCROLL
)
79 WX_FLAGS_MEMBER(wxHSCROLL
)
81 WX_END_FLAGS( wxCheckBoxStyle
)
83 IMPLEMENT_DYNAMIC_CLASS_XTI(wxCheckBox
, wxControl
,"wx/checkbox.h")
85 WX_BEGIN_PROPERTIES_TABLE(wxCheckBox
)
86 WX_EVENT_PROPERTY( Click
, wxEVT_COMMAND_CHECKBOX_CLICKED
, wxCommandEvent
)
88 WX_PROPERTY( Font
, wxFont
, SetFont
, GetFont
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
89 WX_PROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
90 WX_PROPERTY( Value
,bool, SetValue
, GetValue
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
91 WX_PROPERTY_FLAGS( WindowStyle
, wxCheckBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
92 WX_END_PROPERTIES_TABLE()
94 WX_BEGIN_HANDLERS_TABLE(wxCheckBox
)
95 WX_END_HANDLERS_TABLE()
97 WX_CONSTRUCTOR_6( wxCheckBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Label
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
99 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 bool wxCheckBox::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
109 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId
);
110 event
.SetInt(GetValue());
111 event
.SetEventObject(this);
112 ProcessCommand(event
);
116 bool wxCheckBox::Create(wxWindow
*parent
,
118 const wxString
& label
,
120 const wxSize
& size
, long style
,
121 const wxValidator
& validator
,
122 const wxString
& name
)
124 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
127 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
;
128 if ( style
& wxALIGN_RIGHT
)
129 msStyle
|= BS_LEFTTEXT
;
131 return MSWCreateControl(wxT("BUTTON"), msStyle
, pos
, size
, label
, 0);
134 void wxCheckBox::SetLabel(const wxString
& label
)
136 SetWindowText(GetHwnd(), label
);
139 wxSize
wxCheckBox::DoGetBestSize() const
141 static int s_checkSize
= 0;
146 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
148 s_checkSize
= dc
.GetCharHeight();
151 wxString str
= wxGetWindowText(GetHWND());
153 int wCheckbox
, hCheckbox
;
154 if ( !str
.IsEmpty() )
156 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
157 wCheckbox
+= s_checkSize
+ GetCharWidth();
159 if ( hCheckbox
< s_checkSize
)
160 hCheckbox
= s_checkSize
;
164 wCheckbox
= s_checkSize
;
165 hCheckbox
= s_checkSize
;
168 return wxSize(wCheckbox
, hCheckbox
);
171 void wxCheckBox::SetValue(bool val
)
173 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
176 bool wxCheckBox::GetValue() const
178 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) & BST_CHECKED
) != 0;
181 void wxCheckBox::Command(wxCommandEvent
& event
)
183 SetValue(event
.GetInt() != 0);
184 ProcessCommand(event
);
187 #endif // wxUSE_CHECKBOX