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"
32 #include "wx/checkbox.h"
34 #include "wx/dcscreen.h"
35 #include "wx/settings.h"
38 #include "wx/msw/private.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
45 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
47 // ============================================================================
49 // ============================================================================
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 bool wxCheckBox::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
57 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId
);
58 event
.SetInt(GetValue());
59 event
.SetEventObject(this);
60 ProcessCommand(event
);
64 // Single check box item
65 bool wxCheckBox::Create(wxWindow
*parent
,
67 const wxString
& label
,
69 const wxSize
& size
, long style
,
70 const wxValidator
& validator
,
75 SetValidator(validator
);
76 #endif // wxUSE_VALIDATORS
77 if (parent
) parent
->AddChild(this);
79 SetBackgroundColour(parent
->GetBackgroundColour()) ;
80 SetForegroundColour(parent
->GetForegroundColour()) ;
82 m_windowStyle
= style
;
84 // VZ: disabling this ugliness which completely breaks checkboxes in wxGrid
85 // whoever did it, please tell me where and how does the checkbox fail
88 wxString Label
= label
;
90 Label
= wxT(" "); // Apparently needed or checkbox won't show
94 m_windowId
= NewControlId();
103 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
104 if ( style
& wxALIGN_RIGHT
)
105 msStyle
|= BS_LEFTTEXT
;
107 if ( style
& wxCLIP_SIBLINGS
)
108 msStyle
|= WS_CLIPSIBLINGS
;
110 // We perhaps have different concepts of 3D here - a 3D border,
111 // versus a 3D button.
112 // So we only wish to give a border if this is specified
115 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
117 // Even with extended styles, need to combine with WS_BORDER
118 // for them to look right.
120 if ( want3D || wxStyleHasBorder(m_windowStyle) )
121 msStyle |= WS_BORDER;
124 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
, wxT("BUTTON"), label
,
127 (HWND
)parent
->GetHWND(), (HMENU
)m_windowId
,
128 wxGetInstance(), NULL
);
133 Ctl3dSubclassCtl(GetHwnd());
138 // Subclass again for purposes of dialog editing mode
141 SetFont(parent
->GetFont());
143 SetSize(x
, y
, width
, height
);
148 void wxCheckBox::SetLabel(const wxString
& label
)
150 SetWindowText(GetHwnd(), label
);
153 wxSize
wxCheckBox::DoGetBestSize() const
155 static int s_checkSize
= 0;
160 dc
.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
162 s_checkSize
= (3*dc
.GetCharHeight())/2;
165 wxString str
= wxGetWindowText(GetHWND());
167 int wCheckbox
, hCheckbox
;
168 if ( !str
.IsEmpty() )
170 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
171 wCheckbox
+= s_checkSize
+ GetCharWidth();
173 if ( hCheckbox
< s_checkSize
)
174 hCheckbox
= s_checkSize
;
178 wCheckbox
= s_checkSize
;
179 hCheckbox
= s_checkSize
;
182 return wxSize(wCheckbox
, hCheckbox
);
185 void wxCheckBox::SetValue(bool val
)
187 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
191 #define BST_CHECKED 0x0001
194 bool wxCheckBox::GetValue() const
197 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
199 return ((0x001 & SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0)) == 0x001);
203 void wxCheckBox::Command (wxCommandEvent
& event
)
205 SetValue ((event
.GetInt() != 0));
206 ProcessCommand (event
);
209 // ----------------------------------------------------------------------------
211 // ----------------------------------------------------------------------------
213 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*WXUNUSED(label
),
215 const wxSize
& size
, long style
,
216 const wxValidator
& validator
,
217 const wxString
& name
)
221 SetValidator(validator
);
222 #endif // wxUSE_VALIDATORS
223 if (parent
) parent
->AddChild(this);
225 SetBackgroundColour(parent
->GetBackgroundColour()) ;
226 SetForegroundColour(parent
->GetForegroundColour()) ;
227 m_windowStyle
= style
;
230 m_windowId
= NewControlId();
241 long msStyle
= CHECK_FLAGS
;
243 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, wxT("toggle"),
245 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
246 wxGetInstance(), NULL
);
249 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
251 Ctl3dSubclassCtl(wx_button
);
256 m_hWnd
= (WXHWND
)wx_button
;
258 // Subclass again for purposes of dialog editing mode
259 SubclassWin((WXHWND
)wx_button
);
261 SetSize(x
, y
, width
, height
);
263 ShowWindow(wx_button
, SW_SHOW
);
268 void wxBitmapCheckBox::SetLabel(const wxBitmap
& WXUNUSED(bitmap
))
270 wxFAIL_MSG(wxT("not implemented"));