]> git.saurik.com Git - wxWidgets.git/blame - src/os2/tglbtn.cpp
Blind fix for bug #1209944, wxFileConfig constructor corrupts the stack
[wxWidgets.git] / src / os2 / tglbtn.cpp
CommitLineData
322d45dd
DW
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.
7// Modified by:
8// Created: 08.02.01
9// RCS-ID: $Id$
10// Copyright: (c) 2000 Johnny C. Norris II
11// License: wxWindows licence
12/////////////////////////////////////////////////////////////////////////////
13
14// ============================================================================
15// declatations
16// ============================================================================
17
18// ----------------------------------------------------------------------------
19// headers
20// ----------------------------------------------------------------------------
21
22#include "wx/wxprec.h"
23
24#ifdef __BORLANDC__
25 #pragma hdrstop
26#endif
27
28#include "wx/tglbtn.h"
29
30#if wxUSE_TOGGLEBTN
31
32#ifndef WX_PRECOMP
33 #include "wx/button.h"
34 #include "wx/brush.h"
35 #include "wx/dcscreen.h"
36 #include "wx/settings.h"
37
38 #include "wx/log.h"
39#endif // WX_PRECOMP
40
322d45dd
DW
41// ----------------------------------------------------------------------------
42// macros
43// ----------------------------------------------------------------------------
44
45IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
46DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
47
48#define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
49
50// ============================================================================
51// implementation
52// ============================================================================
53
54// ----------------------------------------------------------------------------
55// wxToggleButton
56// ----------------------------------------------------------------------------
57
58bool wxToggleButton::OS2Command(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
59{
60 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
61 event.SetInt(GetValue());
62 event.SetEventObject(this);
63 ProcessCommand(event);
64 return true;
65}
66
67// Single check box item
68bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
69 const wxString& label,
70 const wxPoint& pos,
71 const wxSize& size, long style,
72 const wxValidator& validator,
73 const wxString& name)
74{
75 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
76 return false;
77
78 if ( !OS2CreateControl(wxT("BUTTON"), label, pos, size, 0) )
79 return false;
80
81 return true;
82}
83
84wxBorder wxToggleButton::GetDefaultBorder() const
85{
86 return wxBORDER_NONE;
87}
88
89WXDWORD wxToggleButton::OS2GetStyle(long style, WXDWORD *exstyle) const
90{
91 WXDWORD msStyle = wxControl::OS2GetStyle(style, exstyle);
92
93#ifndef BS_PUSHLIKE
94#define BS_PUSHLIKE 0x00001000L
95#endif
96
97 msStyle |= BS_AUTOCHECKBOX | BS_PUSHLIKE | WS_TABSTOP;
98
99 return msStyle;
100}
101
102wxSize wxToggleButton::DoGetBestSize() const
103{
104 wxString label = wxGetWindowText(GetHWND());
105 int wBtn;
106 wxFont vFont = GetFont();
107 int wChar;
108 int hChar;
109
110 GetTextExtent(label, &wBtn, NULL);
111
112
113 wxGetCharSize(GetHWND(), &wChar, &hChar, &vFont);
114
115 // add a margin - the button is wider than just its label
116 wBtn += 3*wChar;
117
118 // the button height is proportional to the height of the font used
119 int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
120
121#if wxUSE_BUTTON
122 wxSize sz = wxButton::GetDefaultSize();
123 if (wBtn > sz.x)
124 sz.x = wBtn;
125 if (hBtn > sz.y)
126 sz.y = hBtn;
127#else
128 wxSize sz(wBtn, hBtn);
129#endif
130
131 return sz;
132}
133
134void wxToggleButton::SetValue(bool val)
135{
136 ::WinSendMsg(GetHwnd(), BM_SETCHECK, MPFROMSHORT(val), (MPARAM)0);
137}
138
139#ifndef BST_CHECKED
140#define BST_CHECKED 0x0001
141#endif
142
143bool wxToggleButton::GetValue() const
144{
145 return (::WinSendMsg(GetHwnd(), BM_QUERYCHECK, 0, 0) == (MRESULT)BST_CHECKED);
146}
147
148void wxToggleButton::Command(wxCommandEvent & event)
149{
150 SetValue((event.GetInt() != 0));
151 ProcessCommand(event);
152}
153
154#endif // wxUSE_TOGGLEBTN
155