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 #if !USE_SHARED_LIBRARY
43 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
44 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
, wxWindowID id
, const wxString
& label
,
67 const wxSize
& size
, long style
,
68 const wxValidator
& validator
,
72 SetValidator(validator
);
73 if (parent
) parent
->AddChild(this);
75 SetBackgroundColour(parent
->GetBackgroundColour()) ;
76 SetForegroundColour(parent
->GetForegroundColour()) ;
78 m_windowStyle
= style
;
80 wxString Label
= label
;
82 Label
= wxT(" "); // Apparently needed or checkbox won't show
85 m_windowId
= NewControlId();
94 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
95 if ( style
& wxALIGN_RIGHT
)
96 msStyle
|= BS_LEFTTEXT
;
98 // We perhaps have different concepts of 3D here - a 3D border,
99 // versus a 3D button.
100 // So we only wish to give a border if this is specified
103 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
105 // Even with extended styles, need to combine with WS_BORDER
106 // for them to look right.
108 if ( want3D || wxStyleHasBorder(m_windowStyle) )
109 msStyle |= WS_BORDER;
112 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
, wxT("BUTTON"), Label
,
115 (HWND
)parent
->GetHWND(), (HMENU
)m_windowId
,
116 wxGetInstance(), NULL
);
121 Ctl3dSubclassCtl(GetHwnd());
126 // Subclass again for purposes of dialog editing mode
129 SetFont(parent
->GetFont());
131 SetSize(x
, y
, width
, height
);
136 void wxCheckBox::SetLabel(const wxString
& label
)
138 SetWindowText(GetHwnd(), label
);
141 wxSize
wxCheckBox::DoGetBestSize() const
143 int wCheckbox
, hCheckbox
;
145 wxString str
= wxGetWindowText(GetHWND());
147 if ( !str
.IsEmpty() )
149 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
150 wCheckbox
+= RADIO_SIZE
;
152 if ( hCheckbox
< RADIO_SIZE
)
153 hCheckbox
= RADIO_SIZE
;
157 wCheckbox
= RADIO_SIZE
;
158 hCheckbox
= RADIO_SIZE
;
161 return wxSize(wCheckbox
, hCheckbox
);
164 void wxCheckBox::SetValue(bool val
)
166 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
170 #define BST_CHECKED 0x0001
173 bool wxCheckBox::GetValue() const
176 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
178 return ((0x003 & SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0)) == 0x003);
182 void wxCheckBox::Command (wxCommandEvent
& event
)
184 SetValue ((event
.GetInt() != 0));
185 ProcessCommand (event
);
188 // ----------------------------------------------------------------------------
190 // ----------------------------------------------------------------------------
192 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*label
,
194 const wxSize
& size
, long style
,
195 const wxValidator
& validator
,
196 const wxString
& name
)
199 SetValidator(validator
);
200 if (parent
) parent
->AddChild(this);
202 SetBackgroundColour(parent
->GetBackgroundColour()) ;
203 SetForegroundColour(parent
->GetForegroundColour()) ;
204 m_windowStyle
= style
;
207 m_windowId
= NewControlId();
218 long msStyle
= CHECK_FLAGS
;
220 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, wxT("toggle"),
222 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
223 wxGetInstance(), NULL
);
226 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
228 Ctl3dSubclassCtl(wx_button
);
233 m_hWnd
= (WXHWND
)wx_button
;
235 // Subclass again for purposes of dialog editing mode
236 SubclassWin((WXHWND
)wx_button
);
238 SetSize(x
, y
, width
, height
);
240 ShowWindow(wx_button
, SW_SHOW
);
245 void wxBitmapCheckBox::SetLabel(const wxBitmap
& bitmap
)
247 wxFAIL_MSG(wxT("not implemented"));