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
, wxWindowID id
, const wxString
& label
,
65 const wxSize
& size
, long style
,
66 const wxValidator
& validator
,
70 SetValidator(validator
);
71 if (parent
) parent
->AddChild(this);
73 SetBackgroundColour(parent
->GetBackgroundColour()) ;
74 SetForegroundColour(parent
->GetForegroundColour()) ;
76 m_windowStyle
= style
;
78 wxString Label
= label
;
80 Label
= wxT(" "); // Apparently needed or checkbox won't show
83 m_windowId
= NewControlId();
92 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
93 if ( style
& wxALIGN_RIGHT
)
94 msStyle
|= BS_LEFTTEXT
;
96 // We perhaps have different concepts of 3D here - a 3D border,
97 // versus a 3D button.
98 // So we only wish to give a border if this is specified
101 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
103 // Even with extended styles, need to combine with WS_BORDER
104 // for them to look right.
106 if ( want3D || wxStyleHasBorder(m_windowStyle) )
107 msStyle |= WS_BORDER;
110 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
, wxT("BUTTON"), Label
,
113 (HWND
)parent
->GetHWND(), (HMENU
)m_windowId
,
114 wxGetInstance(), NULL
);
119 Ctl3dSubclassCtl(GetHwnd());
124 // Subclass again for purposes of dialog editing mode
127 SetFont(parent
->GetFont());
129 SetSize(x
, y
, width
, height
);
134 void wxCheckBox::SetLabel(const wxString
& label
)
136 SetWindowText(GetHwnd(), label
);
139 wxSize
wxCheckBox::DoGetBestSize() const
141 int wCheckbox
, hCheckbox
;
143 wxString str
= wxGetWindowText(GetHWND());
145 if ( !str
.IsEmpty() )
147 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
148 wCheckbox
+= RADIO_SIZE
;
150 if ( hCheckbox
< RADIO_SIZE
)
151 hCheckbox
= RADIO_SIZE
;
155 wCheckbox
= RADIO_SIZE
;
156 hCheckbox
= RADIO_SIZE
;
159 return wxSize(wCheckbox
, hCheckbox
);
162 void wxCheckBox::SetValue(bool val
)
164 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
168 #define BST_CHECKED 0x0001
171 bool wxCheckBox::GetValue() const
174 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
176 return ((0x003 & SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0)) == 0x003);
180 void wxCheckBox::Command (wxCommandEvent
& event
)
182 SetValue ((event
.GetInt() != 0));
183 ProcessCommand (event
);
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*label
,
192 const wxSize
& size
, long style
,
193 const wxValidator
& validator
,
194 const wxString
& name
)
197 SetValidator(validator
);
198 if (parent
) parent
->AddChild(this);
200 SetBackgroundColour(parent
->GetBackgroundColour()) ;
201 SetForegroundColour(parent
->GetForegroundColour()) ;
202 m_windowStyle
= style
;
205 m_windowId
= NewControlId();
216 long msStyle
= CHECK_FLAGS
;
218 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, wxT("toggle"),
220 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
221 wxGetInstance(), NULL
);
224 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
226 Ctl3dSubclassCtl(wx_button
);
231 m_hWnd
= (WXHWND
)wx_button
;
233 // Subclass again for purposes of dialog editing mode
234 SubclassWin((WXHWND
)wx_button
);
236 SetSize(x
, y
, width
, height
);
238 ShowWindow(wx_button
, SW_SHOW
);
243 void wxBitmapCheckBox::SetLabel(const wxBitmap
& bitmap
)
245 wxFAIL_MSG(wxT("not implemented"));