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(const WXUINT
WXUNUSED(param
), const 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
, const wxWindowID id
, const wxString
& label
,
46 const wxSize
& size
, const 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(const int x
, const int y
, const int width
, const int height
, const 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
))
139 HWND button
= (HWND
) GetHWND();
141 GetWindowText(button
, buf
, 300);
144 GetTextExtent(buf
, ¤t_width
, &cyf
, NULL
, NULL
, GetFont());
146 w1
= (int)(current_width
+ RADIO_SIZE
);
162 MoveWindow(button
, x1
, y1
, w1
, h1
, TRUE
);
165 #if WXWIN_COMPATIBILITY
166 GetEventHandler()->OldOnSize(width, height);
168 wxSizeEvent event(wxSize(width, height), m_windowId);
169 event.eventObject = this;
170 GetEventHandler()->ProcessEvent(event);
176 void wxCheckBox::SetValue(const bool val
)
178 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, val
, 0);
181 bool wxCheckBox::GetValue(void) const
184 return (SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
186 return ((0x003 & SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0)) == 0x003);
190 WXHBRUSH
wxCheckBox::OnCtlColor(const WXHDC pDC
, const WXHWND pWnd
, const WXUINT nCtlColor
,
191 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
196 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
198 return (WXHBRUSH
) hbrush
;
202 if (GetParent()->GetTransparentBackground())
203 SetBkMode((HDC
) pDC
, TRANSPARENT
);
205 SetBkMode((HDC
) pDC
, OPAQUE
);
207 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
208 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
210 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
212 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
213 // has a zero usage count.
214 // backgroundBrush->RealizeResource();
215 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
218 void wxCheckBox::Command (wxCommandEvent
& event
)
220 SetValue ((event
.GetInt() != 0));
221 ProcessCommand (event
);
224 bool wxBitmapCheckBox::Create(wxWindow
*parent
, const wxWindowID id
, const wxBitmap
*label
,
226 const wxSize
& size
, const long style
,
227 const wxValidator
& validator
,
228 const wxString
& name
)
231 SetValidator(validator
);
232 if (parent
) parent
->AddChild(this);
234 SetBackgroundColour(parent
->GetDefaultBackgroundColour()) ;
235 SetForegroundColour(parent
->GetDefaultForegroundColour()) ;
236 m_windowStyle
= style
;
239 m_windowId
= NewControlId();
250 long msStyle
= CHECK_FLAGS
;
252 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, "toggle",
254 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
255 wxGetInstance(), NULL
);
258 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
260 Ctl3dSubclassCtl(wx_button
);
265 m_hWnd
= (WXHWND
)wx_button
;
267 // Subclass again for purposes of dialog editing mode
268 SubclassWin((WXHWND
)wx_button
);
270 // SetFont(parent->GetFont());
272 SetSize(x
, y
, width
, height
);
274 ShowWindow(wx_button
, SW_SHOW
);
278 void wxBitmapCheckBox::SetLabel(const wxBitmap
*bitmap
)
282 void wxBitmapCheckBox::SetSize(const int x
, const int y
, const int width
, const int height
, const int sizeFlags
)
284 int currentX
, currentY
;
285 GetPosition(¤tX
, ¤tY
);
292 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
294 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
297 HWND button
= (HWND
) GetHWND();
300 w1 = checkWidth + FB_MARGIN ;
302 h1 = checkHeight + FB_MARGIN ;
304 MoveWindow(button
, x1
, y1
, w1
, h1
, TRUE
);
306 #if WXWIN_COMPATIBILITY
307 GetEventHandler()->OldOnSize(width
, height
);
309 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
310 event
.eventObject
= this;
311 GetEventHandler()->ProcessEvent(event
);
315 void wxBitmapCheckBox::SetValue(const bool val
)
317 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, val
, 0);
320 bool wxBitmapCheckBox::GetValue(void) const
322 return ((0x003 & SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0)) == 0x003);