1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "checkbox.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/checkbox.h"
27 #include "wx/msw/private.h"
29 #if !USE_SHARED_LIBRARY
30 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
31 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
34 bool wxCheckBox::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
36 wxCommandEvent
event(wxEVENT_TYPE_CHECKBOX_COMMAND
, m_windowId
);
37 event
.SetInt(GetValue());
38 event
.SetEventObject(this);
39 ProcessCommand(event
);
43 // Single check box item
44 bool wxCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
46 const wxSize
& size
, long style
,
47 const wxValidator
& validator
,
51 SetValidator(validator
);
52 if (parent
) parent
->AddChild(this);
54 SetBackgroundColour(parent
->GetDefaultBackgroundColour()) ;
55 SetForegroundColour(parent
->GetDefaultForegroundColour()) ;
57 m_windowStyle
= style
;
59 wxString Label
= label
;
61 Label
= " "; // Apparently needed or checkbox won't show
64 m_windowId
= NewControlId();
73 long msStyle
= BS_AUTOCHECKBOX
|WS_TABSTOP
|WS_CHILD
;
75 // We perhaps have different concepts of 3D here - a 3D border,
76 // versus a 3D button.
77 // So we only wish to give a border if this is specified
80 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
82 // Even with extended styles, need to combine with WS_BORDER
83 // for them to look right.
84 if (want3D
&& ((m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
85 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
)))
88 HWND wx_button
= CreateWindowEx(exStyle
, "BUTTON", (const char *)Label
,
90 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
91 wxGetInstance(), NULL
);
96 Ctl3dSubclassCtl(wx_button
);
101 m_hWnd
= (WXHWND
) wx_button
;
103 // Subclass again for purposes of dialog editing mode
104 SubclassWin((WXHWND
) wx_button
);
106 SetFont(* parent
->GetFont());
108 SetSize(x
, y
, width
, height
);
110 ShowWindow(wx_button
, SW_SHOW
);
114 void wxCheckBox::SetLabel(const wxString
& label
)
116 SetWindowText((HWND
) GetHWND(), (const char *)label
);
119 void wxCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
121 int currentX
, currentY
;
122 GetPosition(¤tX
, ¤tY
);
128 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
130 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
133 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
137 int current_width
, cyf
;
138 HWND button
= (HWND
) GetHWND();
140 GetWindowText(button
, buf
, 300);
143 GetTextExtent(buf
, ¤t_width
, &cyf
, NULL
, NULL
, GetFont());
145 w1
= (int)(current_width
+ RADIO_SIZE
);
161 MoveWindow(button
, x1
, y1
, w1
, h1
, TRUE
);
164 void wxCheckBox::SetValue(bool val
)
166 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, val
, 0);
169 bool wxCheckBox::GetValue(void) const
172 return (SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
174 return ((0x003 & SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0)) == 0x003);
178 WXHBRUSH
wxCheckBox::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
179 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
184 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
186 return (WXHBRUSH
) hbrush
;
190 if (GetParent()->GetTransparentBackground())
191 SetBkMode((HDC
) pDC
, TRANSPARENT
);
193 SetBkMode((HDC
) pDC
, OPAQUE
);
195 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
196 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
198 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
200 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
201 // has a zero usage count.
202 // backgroundBrush->RealizeResource();
203 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
206 void wxCheckBox::Command (wxCommandEvent
& event
)
208 SetValue ((event
.GetInt() != 0));
209 ProcessCommand (event
);
212 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*label
,
214 const wxSize
& size
, long style
,
215 const wxValidator
& validator
,
216 const wxString
& name
)
219 SetValidator(validator
);
220 if (parent
) parent
->AddChild(this);
222 SetBackgroundColour(parent
->GetDefaultBackgroundColour()) ;
223 SetForegroundColour(parent
->GetDefaultForegroundColour()) ;
224 m_windowStyle
= style
;
227 m_windowId
= NewControlId();
238 long msStyle
= CHECK_FLAGS
;
240 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, "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 // SetFont(parent->GetFont());
260 SetSize(x
, y
, width
, height
);
262 ShowWindow(wx_button
, SW_SHOW
);
266 void wxBitmapCheckBox::SetLabel(const wxBitmap
*bitmap
)
270 void wxBitmapCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
272 int currentX
, currentY
;
273 GetPosition(¤tX
, ¤tY
);
280 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
282 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
285 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
287 HWND button
= (HWND
) GetHWND();
290 w1 = checkWidth + FB_MARGIN ;
292 h1 = checkHeight + FB_MARGIN ;
294 MoveWindow(button
, x1
, y1
, w1
, h1
, TRUE
);
297 void wxBitmapCheckBox::SetValue(bool val
)
299 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, val
, 0);
302 bool wxBitmapCheckBox::GetValue(void) const
304 return ((0x003 & SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0)) == 0x003);