1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
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"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
47 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
49 // ============================================================================
51 // ============================================================================
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 bool wxCheckBox::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
59 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId
);
60 event
.SetInt(GetValue());
61 event
.SetEventObject(this);
62 ProcessCommand(event
);
66 // Single check box item
67 bool wxCheckBox::Create(wxWindow
*parent
,
69 const wxString
& label
,
71 const wxSize
& size
, long style
,
72 const wxValidator
& validator
,
77 SetValidator(validator
);
78 #endif // wxUSE_VALIDATORS
79 if (parent
) parent
->AddChild(this);
81 SetBackgroundColour(parent
->GetBackgroundColour()) ;
82 SetForegroundColour(parent
->GetForegroundColour()) ;
84 m_windowStyle
= style
;
86 // VZ: disabling this ugliness which completely breaks checkboxes in wxGrid
87 // whoever did it, please tell me where and how does the checkbox fail
90 wxString Label
= label
;
92 Label
= wxT(" "); // Apparently needed or checkbox won't show
96 m_windowId
= NewControlId();
105 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
106 if ( style
& wxALIGN_RIGHT
)
107 msStyle
|= BS_LEFTTEXT
;
109 if ( style
& wxCLIP_SIBLINGS
)
110 msStyle
|= WS_CLIPSIBLINGS
;
112 // We perhaps have different concepts of 3D here - a 3D border,
113 // versus a 3D button.
114 // So we only wish to give a border if this is specified
117 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
119 // Even with extended styles, need to combine with WS_BORDER
120 // for them to look right.
122 if ( want3D || wxStyleHasBorder(m_windowStyle) )
123 msStyle |= WS_BORDER;
126 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
, wxT("BUTTON"), label
,
129 (HWND
)parent
->GetHWND(), (HMENU
)m_windowId
,
130 wxGetInstance(), NULL
);
135 Ctl3dSubclassCtl(GetHwnd());
140 // Subclass again for purposes of dialog editing mode
143 SetFont(parent
->GetFont());
145 SetSize(x
, y
, width
, height
);
150 void wxCheckBox::SetLabel(const wxString
& label
)
152 SetWindowText(GetHwnd(), label
);
155 wxSize
wxCheckBox::DoGetBestSize() const
157 static int s_checkSize
= 0;
162 dc
.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
164 s_checkSize
= (3*dc
.GetCharHeight())/2;
167 wxString str
= wxGetWindowText(GetHWND());
169 int wCheckbox
, hCheckbox
;
170 if ( !str
.IsEmpty() )
172 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
173 wCheckbox
+= s_checkSize
+ GetCharWidth();
175 if ( hCheckbox
< s_checkSize
)
176 hCheckbox
= s_checkSize
;
180 wCheckbox
= s_checkSize
;
181 hCheckbox
= s_checkSize
;
184 return wxSize(wCheckbox
, hCheckbox
);
187 void wxCheckBox::SetValue(bool val
)
189 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
193 #define BST_CHECKED 0x0001
196 bool wxCheckBox::GetValue() const
199 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
201 return ((0x001 & SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0)) == 0x001);
205 void wxCheckBox::Command (wxCommandEvent
& event
)
207 SetValue ((event
.GetInt() != 0));
208 ProcessCommand (event
);
211 // ----------------------------------------------------------------------------
213 // ----------------------------------------------------------------------------
215 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*WXUNUSED(label
),
217 const wxSize
& size
, long style
,
218 const wxValidator
& validator
,
219 const wxString
& name
)
223 SetValidator(validator
);
224 #endif // wxUSE_VALIDATORS
225 if (parent
) parent
->AddChild(this);
227 SetBackgroundColour(parent
->GetBackgroundColour()) ;
228 SetForegroundColour(parent
->GetForegroundColour()) ;
229 m_windowStyle
= style
;
232 m_windowId
= NewControlId();
243 long msStyle
= CHECK_FLAGS
;
245 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, wxT("toggle"),
247 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
248 wxGetInstance(), NULL
);
251 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
253 Ctl3dSubclassCtl(wx_button
);
258 m_hWnd
= (WXHWND
)wx_button
;
260 // Subclass again for purposes of dialog editing mode
261 SubclassWin((WXHWND
)wx_button
);
263 SetSize(x
, y
, width
, height
);
265 ShowWindow(wx_button
, SW_SHOW
);
270 void wxBitmapCheckBox::SetLabel(const wxBitmap
& WXUNUSED(bitmap
))
272 wxFAIL_MSG(wxT("not implemented"));
275 #endif // wxUSE_CHECKBOX