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
))
135 int current_width
, cyf
;
136 HWND button
= (HWND
) GetHWND();
138 GetWindowText(button
, buf
, 300);
141 GetTextExtent(buf
, ¤t_width
, &cyf
, NULL
, NULL
, GetFont());
143 w1
= (int)(current_width
+ RADIO_SIZE
);
159 MoveWindow(button
, x1
, y1
, w1
, h1
, TRUE
);
162 void wxCheckBox::SetValue(bool val
)
164 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, val
, 0);
167 bool wxCheckBox::GetValue(void) const
170 return (SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0) == BST_CHECKED
);
172 return ((0x003 & SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0)) == 0x003);
176 WXHBRUSH
wxCheckBox::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
177 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
182 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
184 return (WXHBRUSH
) hbrush
;
188 if (GetParent()->GetTransparentBackground())
189 SetBkMode((HDC
) pDC
, TRANSPARENT
);
191 SetBkMode((HDC
) pDC
, OPAQUE
);
193 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
194 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
196 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
198 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
199 // has a zero usage count.
200 // backgroundBrush->RealizeResource();
201 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
204 void wxCheckBox::Command (wxCommandEvent
& event
)
206 SetValue ((event
.GetInt() != 0));
207 ProcessCommand (event
);
210 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*label
,
212 const wxSize
& size
, long style
,
213 const wxValidator
& validator
,
214 const wxString
& name
)
217 SetValidator(validator
);
218 if (parent
) parent
->AddChild(this);
220 SetBackgroundColour(parent
->GetDefaultBackgroundColour()) ;
221 SetForegroundColour(parent
->GetDefaultForegroundColour()) ;
222 m_windowStyle
= style
;
225 m_windowId
= NewControlId();
236 long msStyle
= CHECK_FLAGS
;
238 HWND wx_button
= CreateWindowEx(MakeExtendedStyle(m_windowStyle
), CHECK_CLASS
, "toggle",
240 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
241 wxGetInstance(), NULL
);
244 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
246 Ctl3dSubclassCtl(wx_button
);
251 m_hWnd
= (WXHWND
)wx_button
;
253 // Subclass again for purposes of dialog editing mode
254 SubclassWin((WXHWND
)wx_button
);
256 // SetFont(parent->GetFont());
258 SetSize(x
, y
, width
, height
);
260 ShowWindow(wx_button
, SW_SHOW
);
264 void wxBitmapCheckBox::SetLabel(const wxBitmap
*bitmap
)
268 void wxBitmapCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
270 int currentX
, currentY
;
271 GetPosition(¤tX
, ¤tY
);
278 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
280 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
283 HWND button
= (HWND
) GetHWND();
286 w1 = checkWidth + FB_MARGIN ;
288 h1 = checkHeight + FB_MARGIN ;
290 MoveWindow(button
, x1
, y1
, w1
, h1
, TRUE
);
293 void wxBitmapCheckBox::SetValue(bool val
)
295 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, val
, 0);
298 bool wxBitmapCheckBox::GetValue(void) const
300 return ((0x003 & SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0)) == 0x003);