1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/tglbtn.cpp
3 // Purpose: Definition of the wxToggleButton class, which implements a
4 // toggle button under wxMSW.
5 // Author: John Norris, minor changes by Axel Schlueter
6 // and William Gallafent.
10 // Copyright: (c) 2000 Johnny C. Norris II
11 // License: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 // ============================================================================
16 // ============================================================================
18 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
22 #include "wx/wxprec.h"
30 #include "wx/tglbtn.h"
33 #include "wx/button.h"
35 #include "wx/dcscreen.h"
36 #include "wx/settings.h"
41 #include "wx/msw/private.h"
42 #include "wx/msw/private/button.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
49 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
)
51 // ============================================================================
53 // ============================================================================
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 // Single check box item
60 bool wxToggleButton::Create(wxWindow
*parent
,
62 const wxString
& label
,
64 const wxSize
& size
, long style
,
65 const wxValidator
& validator
,
68 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
71 // if the label contains several lines we must explicitly tell the button
72 // about it or it wouldn't draw it correctly ("\n"s would just appear as
75 // NB: we do it here and not in MSWGetStyle() because we need the label
76 // value and the label is not set yet when MSWGetStyle() is called
78 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
79 msStyle
|= wxMSWButton::GetMultilineStyle(label
);
81 return MSWCreateControl(_T("BUTTON"), msStyle
, pos
, size
, label
, exstyle
);
84 WXDWORD
wxToggleButton::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
86 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
88 msStyle
|= BS_AUTOCHECKBOX
| BS_PUSHLIKE
| WS_TABSTOP
;
90 if ( style
& wxBU_LEFT
)
92 if ( style
& wxBU_RIGHT
)
94 if ( style
& wxBU_TOP
)
96 if ( style
& wxBU_BOTTOM
)
102 wxSize
wxToggleButton::DoGetBestSize() const
104 return wxMSWButton::ComputeBestSize(wx_const_cast(wxToggleButton
*, this));
107 void wxToggleButton::SetLabel(const wxString
& label
)
109 wxMSWButton::UpdateMultilineStyle(GetHwnd(), label
);
111 wxToggleButtonBase::SetLabel(label
);
114 void wxToggleButton::SetValue(bool val
)
116 ::SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
119 bool wxToggleButton::GetValue() const
121 return ::SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
;
124 void wxToggleButton::Command(wxCommandEvent
& event
)
126 SetValue(event
.GetInt() != 0);
127 ProcessCommand(event
);
130 bool wxToggleButton::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
132 wxCommandEvent
event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
, m_windowId
);
133 event
.SetInt(GetValue());
134 event
.SetEventObject(this);
135 ProcessCommand(event
);
139 #endif // wxUSE_TOGGLEBTN