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"
34 #include "wx/dcscreen.h"
35 #include "wx/settings.h"
38 #include "wx/msw/private.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
45 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
,
67 const wxString
& label
,
69 const wxSize
& size
, long style
,
70 const wxValidator
& validator
,
75 SetValidator(validator
);
76 #endif // wxUSE_VALIDATORS
77 if (parent
) parent
->AddChild(this);
79 SetBackgroundColour(parent
->GetBackgroundColour()) ;
80 SetForegroundColour(parent
->GetForegroundColour()) ;
82 m_windowStyle
= style
;
84 // VZ: disabling this ugliness which completely breaks checkboxes in wxGrid
85 // whoever did it, please tell me where and how does the checkbox fail
88 wxString Label
= label
;
90 Label
= wxT(" "); // Apparently needed or checkbox won't show
94 m_windowId
= NewControlId();
103 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
104 if ( style
& wxALIGN_RIGHT
)
105 msStyle
|= BS_LEFTTEXT
;
107 // We perhaps have different concepts of 3D here - a 3D border,
108 // versus a 3D button.
109 // So we only wish to give a border if this is specified
112 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
114 // Even with extended styles, need to combine with WS_BORDER
115 // for them to look right.
117 if ( want3D || wxStyleHasBorder(m_windowStyle) )
118 msStyle |= WS_BORDER;
121 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
, wxT("BUTTON"), label
,
124 (HWND
)parent
->GetHWND(), (HMENU
)m_windowId
,
125 wxGetInstance(), NULL
);
130 Ctl3dSubclassCtl(GetHwnd());
135 // Subclass again for purposes of dialog editing mode
138 SetFont(parent
->GetFont());
140 SetSize(x
, y
, width
, height
);
145 void wxCheckBox::SetLabel(const wxString
& label
)
147 SetWindowText(GetHwnd(), label
);
150 wxSize
wxCheckBox::DoGetBestSize() const
152 static int s_checkSize
= 0;
157 dc
.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
159 s_checkSize
= (3*dc
.GetCharHeight())/2;
162 wxString str
= wxGetWindowText(GetHWND());
164 int wCheckbox
, hCheckbox
;
165 if ( !str
.IsEmpty() )
167 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
168 wCheckbox
+= s_checkSize
+ GetCharWidth();
170 if ( hCheckbox
< s_checkSize
)
171 hCheckbox
= s_checkSize
;
175 wCheckbox
= s_checkSize
;
176 hCheckbox
= s_checkSize
;
179 return wxSize(wCheckbox
, hCheckbox
);
182 void wxCheckBox::SetValue(bool val
)
184 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
188 #define BST_CHECKED 0x0001
191 bool wxCheckBox::GetValue() const
194 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
196 return ((0x001 & SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0)) == 0x001);
200 void wxCheckBox::Command (wxCommandEvent
& event
)
202 SetValue ((event
.GetInt() != 0));
203 ProcessCommand (event
);
206 // ----------------------------------------------------------------------------
208 // ----------------------------------------------------------------------------
210 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*WXUNUSED(label
),
212 const wxSize
& size
, long style
,
213 const wxValidator
& validator
,
214 const wxString
& name
)
218 SetValidator(validator
);
219 #endif // wxUSE_VALIDATORS
220 if (parent
) parent
->AddChild(this);
222 SetBackgroundColour(parent
->GetBackgroundColour()) ;
223 SetForegroundColour(parent
->GetForegroundColour()) ;
224 m_windowStyle
= style
;
227 m_windowId
= NewControlId();
238 long msStyle
= CHECK_FLAGS
;
240 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, wxT("toggle"),
242 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
243 wxGetInstance(), NULL
);
246 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
248 Ctl3dSubclassCtl(wx_button
);
253 m_hWnd
= (WXHWND
)wx_button
;
255 // Subclass again for purposes of dialog editing mode
256 SubclassWin((WXHWND
)wx_button
);
258 SetSize(x
, y
, width
, height
);
260 ShowWindow(wx_button
, SW_SHOW
);
265 void wxBitmapCheckBox::SetLabel(const wxBitmap
& WXUNUSED(bitmap
))
267 wxFAIL_MSG(wxT("not implemented"));