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"
36 #include "wx/msw/private.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
43 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
45 // ============================================================================
47 // ============================================================================
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 bool wxCheckBox::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
55 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId
);
56 event
.SetInt(GetValue());
57 event
.SetEventObject(this);
58 ProcessCommand(event
);
62 // Single check box item
63 bool wxCheckBox::Create(wxWindow
*parent
,
65 const wxString
& label
,
67 const wxSize
& size
, long style
,
68 const wxValidator
& validator
,
73 SetValidator(validator
);
74 #endif // wxUSE_VALIDATORS
75 if (parent
) parent
->AddChild(this);
77 SetBackgroundColour(parent
->GetBackgroundColour()) ;
78 SetForegroundColour(parent
->GetForegroundColour()) ;
80 m_windowStyle
= style
;
82 // VZ: disabling this ugliness which completely breaks checkboxes in wxGrid
83 // whoever did it, please tell me where and how does the checkbox fail
86 wxString Label
= label
;
88 Label
= wxT(" "); // Apparently needed or checkbox won't show
92 m_windowId
= NewControlId();
101 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
102 if ( style
& wxALIGN_RIGHT
)
103 msStyle
|= BS_LEFTTEXT
;
105 // We perhaps have different concepts of 3D here - a 3D border,
106 // versus a 3D button.
107 // So we only wish to give a border if this is specified
110 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
112 // Even with extended styles, need to combine with WS_BORDER
113 // for them to look right.
115 if ( want3D || wxStyleHasBorder(m_windowStyle) )
116 msStyle |= WS_BORDER;
119 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
, wxT("BUTTON"), label
,
122 (HWND
)parent
->GetHWND(), (HMENU
)m_windowId
,
123 wxGetInstance(), NULL
);
128 Ctl3dSubclassCtl(GetHwnd());
133 // Subclass again for purposes of dialog editing mode
136 SetFont(parent
->GetFont());
138 SetSize(x
, y
, width
, height
);
143 void wxCheckBox::SetLabel(const wxString
& label
)
145 SetWindowText(GetHwnd(), label
);
148 #define CHECK_SIZE 13
150 wxSize
wxCheckBox::DoGetBestSize() const
152 int wCheckbox
, hCheckbox
;
154 wxString str
= wxGetWindowText(GetHWND()) + " ";
156 if ( !str
.IsEmpty() )
158 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
159 wCheckbox
+= CHECK_SIZE
;
161 if ( hCheckbox
< CHECK_SIZE
)
162 hCheckbox
= CHECK_SIZE
;
166 wCheckbox
= CHECK_SIZE
;
167 hCheckbox
= CHECK_SIZE
;
170 return wxSize(wCheckbox
, hCheckbox
);
173 void wxCheckBox::SetValue(bool val
)
175 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
179 #define BST_CHECKED 0x0001
182 bool wxCheckBox::GetValue() const
185 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
187 return ((0x003 & SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0)) == 0x003);
191 void wxCheckBox::Command (wxCommandEvent
& event
)
193 SetValue ((event
.GetInt() != 0));
194 ProcessCommand (event
);
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
201 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*label
,
203 const wxSize
& size
, long style
,
204 const wxValidator
& validator
,
205 const wxString
& name
)
209 SetValidator(validator
);
210 #endif // wxUSE_VALIDATORS
211 if (parent
) parent
->AddChild(this);
213 SetBackgroundColour(parent
->GetBackgroundColour()) ;
214 SetForegroundColour(parent
->GetForegroundColour()) ;
215 m_windowStyle
= style
;
218 m_windowId
= NewControlId();
229 long msStyle
= CHECK_FLAGS
;
231 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, wxT("toggle"),
233 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
234 wxGetInstance(), NULL
);
237 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
239 Ctl3dSubclassCtl(wx_button
);
244 m_hWnd
= (WXHWND
)wx_button
;
246 // Subclass again for purposes of dialog editing mode
247 SubclassWin((WXHWND
)wx_button
);
249 SetSize(x
, y
, width
, height
);
251 ShowWindow(wx_button
, SW_SHOW
);
256 void wxBitmapCheckBox::SetLabel(const wxBitmap
& bitmap
)
258 wxFAIL_MSG(wxT("not implemented"));