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 wxBEGIN_FLAGS( wxCheckBoxStyle
)
54 // new style border flags, we put them first to
55 // use them for streaming out
56 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
57 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
58 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
59 wxFLAGS_MEMBER(wxBORDER_RAISED
)
60 wxFLAGS_MEMBER(wxBORDER_STATIC
)
61 wxFLAGS_MEMBER(wxBORDER_NONE
)
63 // old style border flags
64 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
65 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
66 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
67 wxFLAGS_MEMBER(wxRAISED_BORDER
)
68 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
69 wxFLAGS_MEMBER(wxBORDER
)
71 // standard window styles
72 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
73 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
74 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
75 wxFLAGS_MEMBER(wxWANTS_CHARS
)
76 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
77 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
78 wxFLAGS_MEMBER(wxVSCROLL
)
79 wxFLAGS_MEMBER(wxHSCROLL
)
81 wxEND_FLAGS( wxCheckBoxStyle
)
83 IMPLEMENT_DYNAMIC_CLASS_XTI(wxCheckBox
, wxControl
,"wx/checkbox.h")
85 wxBEGIN_PROPERTIES_TABLE(wxCheckBox
)
86 wxEVENT_PROPERTY( Click
, wxEVT_COMMAND_CHECKBOX_CLICKED
, wxCommandEvent
)
88 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
89 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
90 wxPROPERTY( Value
,bool, SetValue
, GetValue
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
91 wxPROPERTY_FLAGS( WindowStyle
, wxCheckBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
92 wxEND_PROPERTIES_TABLE()
94 wxBEGIN_HANDLERS_TABLE(wxCheckBox
)
95 wxEND_HANDLERS_TABLE()
97 wxCONSTRUCTOR_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