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 wxSize
wxCheckBox::DoGetBestSize() const
150 int wCheckbox
, hCheckbox
;
152 wxString str
= wxGetWindowText(GetHWND());
154 if ( !str
.IsEmpty() )
156 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
157 wCheckbox
+= RADIO_SIZE
;
159 if ( hCheckbox
< RADIO_SIZE
)
160 hCheckbox
= RADIO_SIZE
;
164 wCheckbox
= RADIO_SIZE
;
165 hCheckbox
= RADIO_SIZE
;
168 return wxSize(wCheckbox
, hCheckbox
);
171 void wxCheckBox::SetValue(bool val
)
173 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
177 #define BST_CHECKED 0x0001
180 bool wxCheckBox::GetValue() const
183 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
185 return ((0x003 & SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0)) == 0x003);
189 void wxCheckBox::Command (wxCommandEvent
& event
)
191 SetValue ((event
.GetInt() != 0));
192 ProcessCommand (event
);
195 // ----------------------------------------------------------------------------
197 // ----------------------------------------------------------------------------
199 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*label
,
201 const wxSize
& size
, long style
,
202 const wxValidator
& validator
,
203 const wxString
& name
)
207 SetValidator(validator
);
208 #endif // wxUSE_VALIDATORS
209 if (parent
) parent
->AddChild(this);
211 SetBackgroundColour(parent
->GetBackgroundColour()) ;
212 SetForegroundColour(parent
->GetForegroundColour()) ;
213 m_windowStyle
= style
;
216 m_windowId
= NewControlId();
227 long msStyle
= CHECK_FLAGS
;
229 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, wxT("toggle"),
231 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
232 wxGetInstance(), NULL
);
235 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
237 Ctl3dSubclassCtl(wx_button
);
242 m_hWnd
= (WXHWND
)wx_button
;
244 // Subclass again for purposes of dialog editing mode
245 SubclassWin((WXHWND
)wx_button
);
247 SetSize(x
, y
, width
, height
);
249 ShowWindow(wx_button
, SW_SHOW
);
254 void wxBitmapCheckBox::SetLabel(const wxBitmap
& bitmap
)
256 wxFAIL_MSG(wxT("not implemented"));