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 wxString Label
= label
;
84 Label
= wxT(" "); // Apparently needed or checkbox won't show
87 m_windowId
= NewControlId();
96 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
97 if ( style
& wxALIGN_RIGHT
)
98 msStyle
|= BS_LEFTTEXT
;
100 // We perhaps have different concepts of 3D here - a 3D border,
101 // versus a 3D button.
102 // So we only wish to give a border if this is specified
105 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
107 // Even with extended styles, need to combine with WS_BORDER
108 // for them to look right.
110 if ( want3D || wxStyleHasBorder(m_windowStyle) )
111 msStyle |= WS_BORDER;
114 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
, wxT("BUTTON"), Label
,
117 (HWND
)parent
->GetHWND(), (HMENU
)m_windowId
,
118 wxGetInstance(), NULL
);
123 Ctl3dSubclassCtl(GetHwnd());
128 // Subclass again for purposes of dialog editing mode
131 SetFont(parent
->GetFont());
133 SetSize(x
, y
, width
, height
);
138 void wxCheckBox::SetLabel(const wxString
& label
)
140 SetWindowText(GetHwnd(), label
);
143 wxSize
wxCheckBox::DoGetBestSize() const
145 int wCheckbox
, hCheckbox
;
147 wxString str
= wxGetWindowText(GetHWND());
149 if ( !str
.IsEmpty() )
151 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
152 wCheckbox
+= RADIO_SIZE
;
154 if ( hCheckbox
< RADIO_SIZE
)
155 hCheckbox
= RADIO_SIZE
;
159 wCheckbox
= RADIO_SIZE
;
160 hCheckbox
= RADIO_SIZE
;
163 return wxSize(wCheckbox
, hCheckbox
);
166 void wxCheckBox::SetValue(bool val
)
168 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
172 #define BST_CHECKED 0x0001
175 bool wxCheckBox::GetValue() const
178 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
180 return ((0x003 & SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0)) == 0x003);
184 void wxCheckBox::Command (wxCommandEvent
& event
)
186 SetValue ((event
.GetInt() != 0));
187 ProcessCommand (event
);
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*label
,
196 const wxSize
& size
, long style
,
197 const wxValidator
& validator
,
198 const wxString
& name
)
202 SetValidator(validator
);
203 #endif // wxUSE_VALIDATORS
204 if (parent
) parent
->AddChild(this);
206 SetBackgroundColour(parent
->GetBackgroundColour()) ;
207 SetForegroundColour(parent
->GetForegroundColour()) ;
208 m_windowStyle
= style
;
211 m_windowId
= NewControlId();
222 long msStyle
= CHECK_FLAGS
;
224 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, wxT("toggle"),
226 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
227 wxGetInstance(), NULL
);
230 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
232 Ctl3dSubclassCtl(wx_button
);
237 m_hWnd
= (WXHWND
)wx_button
;
239 // Subclass again for purposes of dialog editing mode
240 SubclassWin((WXHWND
)wx_button
);
242 SetSize(x
, y
, width
, height
);
244 ShowWindow(wx_button
, SW_SHOW
);
249 void wxBitmapCheckBox::SetLabel(const wxBitmap
& bitmap
)
251 wxFAIL_MSG(wxT("not implemented"));