]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/tglbtn.cpp
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 // Licence: 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 wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON
, wxCommandEvent
);
50 // ============================================================================
52 // ============================================================================
54 //-----------------------------------------------------------------------------
55 // wxBitmapToggleButton
56 //-----------------------------------------------------------------------------
58 IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton
, wxToggleButton
)
60 bool wxBitmapToggleButton::Create( wxWindow
*parent
, wxWindowID id
,
61 const wxBitmap
& label
,const wxPoint
& pos
, const wxSize
& size
, long style
,
62 const wxValidator
& validator
, const wxString
& name
)
64 if (!wxToggleButton::Create( parent
, id
, wxEmptyString
, pos
, size
, style
, validator
, name
))
69 if (size
.x
== -1 || size
.y
== -1)
71 wxSize new_size
= GetBestSize();
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
89 void wxToggleButton::Init()
94 // Single check box item
95 bool wxToggleButton::Create(wxWindow
*parent
,
97 const wxString
& label
,
99 const wxSize
& size
, long style
,
100 const wxValidator
& validator
,
101 const wxString
& name
)
105 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
108 // if the label contains several lines we must explicitly tell the button
109 // about it or it wouldn't draw it correctly ("\n"s would just appear as
112 // NB: we do it here and not in MSWGetStyle() because we need the label
113 // value and the label is not set yet when MSWGetStyle() is called
115 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
116 msStyle
|= wxMSWButton::GetMultilineStyle(label
);
118 return MSWCreateControl(wxT("BUTTON"), msStyle
, pos
, size
, label
, exstyle
);
121 WXDWORD
wxToggleButton::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
123 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
125 msStyle
|= BS_AUTOCHECKBOX
| BS_PUSHLIKE
| WS_TABSTOP
;
127 if ( style
& wxBU_LEFT
)
129 if ( style
& wxBU_RIGHT
)
131 if ( style
& wxBU_TOP
)
133 if ( style
& wxBU_BOTTOM
)
134 msStyle
|= BS_BOTTOM
;
139 void wxToggleButton::SetValue(bool val
)
142 if ( IsOwnerDrawn() )
148 ::SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
152 bool wxToggleButton::GetValue() const
154 if ( IsOwnerDrawn() )
160 return ::SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
;
164 void wxToggleButton::Command(wxCommandEvent
& event
)
166 SetValue(event
.GetInt() != 0);
167 ProcessCommand(event
);
170 bool wxToggleButton::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
172 if ( param
!= BN_CLICKED
&& param
!= BN_DBLCLK
)
175 // first update the value so that user event handler gets the new
176 // toggle button value
178 // ownerdrawn buttons don't manage their state themselves unlike usual
179 // auto checkboxes so do it ourselves in any case
182 wxCommandEvent
event(wxEVT_TOGGLEBUTTON
, m_windowId
);
183 event
.SetInt(GetValue());
184 event
.SetEventObject(this);
185 ProcessCommand(event
);
189 wxAnyButton::State
wxToggleButton::GetNormalState() const
192 return State_Pressed
;
197 #endif // wxUSE_TOGGLEBTN