]> git.saurik.com Git - wxWidgets.git/blob - src/os2/radiobut.cpp
force making stats
[wxWidgets.git] / src / os2 / radiobut.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: radiobut.cpp
3 // Purpose: wxRadioButton
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/12/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include <stdio.h>
21 #include "wx/setup.h"
22 #include "wx/radiobut.h"
23 #include "wx/brush.h"
24 #include "wx/dcscreen.h"
25 #include "wx/settings.h"
26 #endif
27
28 #include "wx/os2/private.h"
29
30 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
31
32 void wxRadioButton::Init()
33 {
34 m_bFocusJustSet = FALSE;
35 } // end of wxRadioButton::Init
36
37 void wxRadioButton::Command (
38 wxCommandEvent& rEvent
39 )
40 {
41 SetValue ((rEvent.GetInt() != 0) );
42 ProcessCommand (rEvent);
43 } // end of wxRadioButton::Command
44
45 bool wxRadioButton::Create(
46 wxWindow* pParent
47 , wxWindowID vId
48 , const wxString& rsLabel
49 , const wxPoint& rPos
50 , const wxSize& rSize
51 , long lStyle
52 #if wxUSE_VALIDATORS
53 , const wxValidator& rValidator
54 #endif
55 , const wxString& rsName
56 )
57 {
58 if ( !CreateControl( pParent
59 ,vId
60 ,rPos
61 ,rSize
62 ,lStyle
63 #if wxUSE_VALIDATORS
64 ,rValidator
65 #endif
66 ,rsName))
67 return FALSE;
68
69 long lSstyle = HasFlag(wxRB_GROUP) ? WS_GROUP : 0;
70
71 lSstyle |= BS_AUTORADIOBUTTON;
72
73 if (HasFlag(wxCLIP_SIBLINGS))
74 lSstyle |= WS_CLIPSIBLINGS;
75
76 if (!OS2CreateControl( _T("BUTTON")
77 ,lSstyle
78 ,rPos
79 ,rSize
80 ,rsLabel
81 ,0
82 ))
83 return FALSE;
84
85 if (HasFlag(wxRB_GROUP))
86 SetValue(TRUE);
87
88 wxFont* pTextFont = new wxFont( 10
89 ,wxMODERN
90 ,wxNORMAL
91 ,wxNORMAL
92 );
93 SetFont(*pTextFont);
94 SetSize( rPos.x
95 ,rPos.y
96 ,rSize.x
97 ,rSize.y
98 );
99 delete pTextFont;
100 return TRUE;
101 } // end of wxRadioButton::Create
102
103 wxSize wxRadioButton::DoGetBestSize() const
104 {
105 static int snRadioSize = 0;
106
107 if (!snRadioSize)
108 {
109 wxScreenDC vDC;
110
111 vDC.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
112 snRadioSize = vDC.GetCharHeight();
113 }
114
115 wxString sStr = GetLabel();
116 int nRadioWidth;
117 int nRadioHeight;
118
119 if (!sStr.empty())
120 {
121 GetTextExtent( sStr
122 ,&nRadioWidth
123 ,&nRadioHeight
124 );
125 nRadioWidth += snRadioSize + GetCharWidth();
126 if (nRadioHeight < snRadioSize)
127 nRadioHeight = snRadioSize;
128 }
129 else
130 {
131 nRadioWidth = snRadioSize;
132 nRadioHeight = snRadioSize;
133 }
134 return wxSize( nRadioWidth
135 ,nRadioHeight
136 );
137 } // end of wxRadioButton::DoGetBestSize
138
139 //
140 // Get single selection, for single choice list items
141 //
142 bool wxRadioButton::GetValue() const
143 {
144 return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0));
145 } // end of wxRadioButton::GetValue
146
147 bool wxRadioButton::OS2Command(
148 WXUINT wParam
149 , WXWORD wId
150 )
151 {
152 if (wParam == BN_CLICKED)
153 {
154 wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED
155 ,m_windowId
156 );
157
158 rEvent.SetEventObject(this);
159 ProcessCommand(rEvent);
160 return TRUE;
161 }
162 else
163 return FALSE;
164 } // end of wxRadioButton::OS2Command
165
166 void wxRadioButton::SetFocus()
167 {
168 // when the radio button receives a WM_SETFOCUS message it generates a
169 // BN_CLICKED which is totally unexpected and leads to catastrophic results
170 // if you pop up a dialog from the radio button event handler as, when the
171 // dialog is dismissed, the focus is returned to the radio button which
172 // generates BN_CLICKED which leads to showing another dialog and so on
173 // without end!
174 //
175 // to aviod this, we drop the pseudo BN_CLICKED events generated when the
176 // button gains focus
177 m_bFocusJustSet = TRUE;
178
179 wxControl::SetFocus();
180 }
181
182 void wxRadioButton::SetLabel(
183 const wxString& rsLabel
184 )
185 {
186 ::WinSetWindowText((HWND)GetHWND(), (const char *)rsLabel.c_str());
187 } // end of wxRadioButton::SetLabel
188
189 void wxRadioButton::SetValue(
190 bool bValue
191 )
192 {
193 ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0);
194 } // end of wxRadioButton::SetValue
195
196 MRESULT wxRadioButton::OS2WindowProc(
197 WXUINT uMsg
198 , WXWPARAM wParam
199 , WXLPARAM lParam
200 )
201 {
202 if (uMsg == WM_SETFOCUS)
203 {
204 m_bFocusJustSet = TRUE;
205
206 MRESULT mRc = wxControl::OS2WindowProc( uMsg
207 ,wParam
208 ,lParam
209 );
210
211 m_bFocusJustSet = FALSE;
212 return mRc;
213 }
214 return wxControl::OS2WindowProc( uMsg
215 ,wParam
216 ,lParam
217 );
218 } // end of wxRadioButton::OS2WindowProc