]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/tglbtn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/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 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
45 wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON
, wxCommandEvent
);
47 #define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
49 // ============================================================================
51 // ============================================================================
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 bool wxToggleButton::OS2Command(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
59 wxCommandEvent
event(wxEVT_TOGGLEBUTTON
, m_windowId
);
60 event
.SetInt(GetValue());
61 event
.SetEventObject(this);
62 ProcessCommand(event
);
66 // Single check box item
67 bool wxToggleButton::Create(wxWindow
*parent
, wxWindowID id
,
68 const wxString
& label
,
70 const wxSize
& size
, long style
,
71 const wxValidator
& validator
,
74 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
77 if ( !OS2CreateControl(wxT("BUTTON"), label
, pos
, size
, 0) )
83 wxBorder
wxToggleButton::GetDefaultBorder() const
88 WXDWORD
wxToggleButton::OS2GetStyle(long style
, WXDWORD
*exstyle
) const
90 WXDWORD msStyle
= wxControl::OS2GetStyle(style
, exstyle
);
93 #define BS_PUSHLIKE 0x00001000L
96 msStyle
|= BS_AUTOCHECKBOX
| BS_PUSHLIKE
| WS_TABSTOP
;
101 wxSize
wxToggleButton::DoGetBestSize() const
103 wxString label
= wxGetWindowText(GetHWND());
105 wxFont vFont
= GetFont();
109 GetTextExtent(label
, &wBtn
, NULL
);
112 wxGetCharSize(GetHWND(), &wChar
, &hChar
, &vFont
);
114 // add a margin - the button is wider than just its label
117 // the button height is proportional to the height of the font used
118 int hBtn
= BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar
);
121 wxSize sz
= wxButton::GetDefaultSize();
127 wxSize
sz(wBtn
, hBtn
);
133 void wxToggleButton::SetValue(bool val
)
135 ::WinSendMsg(GetHwnd(), BM_SETCHECK
, MPFROMSHORT(val
), (MPARAM
)0);
139 #define BST_CHECKED 0x0001
142 bool wxToggleButton::GetValue() const
144 return (::WinSendMsg(GetHwnd(), BM_QUERYCHECK
, 0, 0) == (MRESULT
)BST_CHECKED
);
147 void wxToggleButton::Command(wxCommandEvent
& event
)
149 SetValue((event
.GetInt() != 0));
150 ProcessCommand(event
);
153 #endif // wxUSE_TOGGLEBTN