]>
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.
9 // Copyright: (c) 2000 Johnny C. Norris II
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 #include "wx/wxprec.h"
29 #include "wx/tglbtn.h"
32 #include "wx/button.h"
34 #include "wx/dcscreen.h"
35 #include "wx/settings.h"
40 #include "wx/msw/private.h"
41 #include "wx/msw/private/button.h"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON
, wxCommandEvent
);
49 // ============================================================================
51 // ============================================================================
53 //-----------------------------------------------------------------------------
54 // wxBitmapToggleButton
55 //-----------------------------------------------------------------------------
57 IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton
, wxToggleButton
)
59 bool wxBitmapToggleButton::Create( wxWindow
*parent
, wxWindowID id
,
60 const wxBitmap
& label
,const wxPoint
& pos
, const wxSize
& size
, long style
,
61 const wxValidator
& validator
, const wxString
& name
)
63 if (!wxToggleButton::Create( parent
, id
, wxEmptyString
, pos
, size
, style
, validator
, name
))
68 if (size
.x
== -1 || size
.y
== -1)
70 wxSize new_size
= GetBestSize();
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
88 void wxToggleButton::Init()
93 // Single check box item
94 bool wxToggleButton::Create(wxWindow
*parent
,
96 const wxString
& label
,
98 const wxSize
& size
, long style
,
99 const wxValidator
& validator
,
100 const wxString
& name
)
104 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
107 // if the label contains several lines we must explicitly tell the button
108 // about it or it wouldn't draw it correctly ("\n"s would just appear as
111 // NB: we do it here and not in MSWGetStyle() because we need the label
112 // value and the label is not set yet when MSWGetStyle() is called
114 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
115 msStyle
|= wxMSWButton::GetMultilineStyle(label
);
117 return MSWCreateControl(wxT("BUTTON"), msStyle
, pos
, size
, label
, exstyle
);
120 WXDWORD
wxToggleButton::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
122 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
124 msStyle
|= BS_AUTOCHECKBOX
| BS_PUSHLIKE
| WS_TABSTOP
;
126 if ( style
& wxBU_LEFT
)
128 if ( style
& wxBU_RIGHT
)
130 if ( style
& wxBU_TOP
)
132 if ( style
& wxBU_BOTTOM
)
133 msStyle
|= BS_BOTTOM
;
138 void wxToggleButton::SetValue(bool val
)
141 if ( IsOwnerDrawn() )
147 ::SendMessage(GetHwnd(), BM_SETCHECK
, val
, 0);
151 bool wxToggleButton::GetValue() const
153 if ( IsOwnerDrawn() )
159 return ::SendMessage(GetHwnd(), BM_GETCHECK
, 0, 0) == BST_CHECKED
;
163 void wxToggleButton::Command(wxCommandEvent
& event
)
165 SetValue(event
.GetInt() != 0);
166 ProcessCommand(event
);
169 bool wxToggleButton::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
171 if ( param
!= BN_CLICKED
&& param
!= BN_DBLCLK
)
174 // first update the value so that user event handler gets the new
175 // toggle button value
177 // ownerdrawn buttons don't manage their state themselves unlike usual
178 // auto checkboxes so do it ourselves in any case
181 wxCommandEvent
event(wxEVT_TOGGLEBUTTON
, m_windowId
);
182 event
.SetInt(GetValue());
183 event
.SetEventObject(this);
184 ProcessCommand(event
);
188 wxAnyButton::State
wxToggleButton::GetNormalState() const
191 return State_Pressed
;
196 #endif // wxUSE_TOGGLEBTN