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"
34 #include "wx/checkbox.h"
36 #include "wx/dcscreen.h"
37 #include "wx/settings.h"
40 #include "wx/msw/private.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
47 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
49 // ============================================================================
51 // ============================================================================
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 bool wxCheckBox::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
59 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, m_windowId
);
60 event
.SetInt(GetValue());
61 event
.SetEventObject(this);
62 ProcessCommand(event
);
66 bool wxCheckBox::Create(wxWindow
*parent
,
68 const wxString
& label
,
70 const wxSize
& size
, long style
,
71 const wxValidator
& validator
,
74 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
77 long msStyle
= BS_AUTOCHECKBOX
| WS_TABSTOP
;
78 if ( style
& wxALIGN_RIGHT
)
79 msStyle
|= BS_LEFTTEXT
;
81 return MSWCreateControl(wxT("BUTTON"), msStyle
, pos
, size
, label
, 0);
84 void wxCheckBox::SetLabel(const wxString
& label
)
86 SetWindowText(GetHwnd(), label
);
89 wxSize
wxCheckBox::DoGetBestSize() const
91 static int s_checkSize
= 0;
96 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
98 s_checkSize
= dc
.GetCharHeight();
101 wxString str
= wxGetWindowText(GetHWND());
103 int wCheckbox
, hCheckbox
;
104 if ( !str
.IsEmpty() )
106 GetTextExtent(str
, &wCheckbox
, &hCheckbox
);
107 wCheckbox
+= s_checkSize
+ GetCharWidth();
109 if ( hCheckbox
< s_checkSize
)
110 hCheckbox
= s_checkSize
;
114 wCheckbox
= s_checkSize
;
115 hCheckbox
= s_checkSize
;
118 return wxSize(wCheckbox
, hCheckbox
);
121 void wxCheckBox::SetValue(bool val
)
123 SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
127 #define BST_CHECKED 0x0001
130 bool wxCheckBox::GetValue() const
133 return (SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
135 return ((0x001 & SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0)) == 0x001);
139 void wxCheckBox::Command (wxCommandEvent
& event
)
141 SetValue ((event
.GetInt() != 0));
142 ProcessCommand (event
);
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*WXUNUSED(label
),
151 const wxSize
& size
, long style
,
152 const wxValidator
& validator
,
153 const wxString
& name
)
157 SetValidator(validator
);
158 #endif // wxUSE_VALIDATORS
159 if (parent
) parent
->AddChild(this);
161 SetBackgroundColour(parent
->GetBackgroundColour()) ;
162 SetForegroundColour(parent
->GetForegroundColour()) ;
163 m_windowStyle
= style
;
166 m_windowId
= NewControlId();
177 long msStyle
= CHECK_FLAGS
;
179 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, wxT("toggle"),
181 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
182 wxGetInstance(), NULL
);
185 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
187 Ctl3dSubclassCtl(wx_button
);
192 m_hWnd
= (WXHWND
)wx_button
;
194 // Subclass again for purposes of dialog editing mode
195 SubclassWin((WXHWND
)wx_button
);
197 SetSize(x
, y
, width
, height
);
199 ShowWindow(wx_button
, SW_SHOW
);
204 void wxBitmapCheckBox::SetLabel(const wxBitmap
& WXUNUSED(bitmap
))
206 wxFAIL_MSG(wxT("not implemented"));
209 #endif // wxUSE_CHECKBOX