]> git.saurik.com Git - wxWidgets.git/blame - src/os2/radiobut.cpp
Add wxFS_SEEKABLE to wxFileSystem::OpenFile calls for images.
[wxWidgets.git] / src / os2 / radiobut.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
521bf4ff 2// Name: src/os2/radiobut.cpp
0e320a79 3// Purpose: wxRadioButton
cdf1e714 4// Author: David Webster
0e320a79 5// Modified by:
cdf1e714 6// Created: 10/12/99
0e320a79 7// RCS-ID: $Id$
cdf1e714 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
cdf1e714
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
b0b5881a 16 #pragma hdrstop
0e320a79
DW
17#endif
18
b0b5881a
WS
19#include "wx/radiobut.h"
20
cdf1e714 21#ifndef WX_PRECOMP
521bf4ff 22 #include <stdio.h>
521bf4ff
WS
23 #include "wx/brush.h"
24 #include "wx/dcscreen.h"
25 #include "wx/settings.h"
cdf1e714
DW
26#endif
27
11e59d47 28#include "wx/os2/private.h"
0e320a79 29
0e320a79 30IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
0e320a79 31
f289196b
DW
32extern void wxAssociateWinWithHandle( HWND hWnd
33 ,wxWindowOS2* pWin
34 );
35
1b086de1
DW
36void wxRadioButton::Init()
37{
b0b5881a 38 m_bFocusJustSet = false;
1b086de1
DW
39} // end of wxRadioButton::Init
40
b0b5881a 41void wxRadioButton::Command ( wxCommandEvent& rEvent )
cdf1e714 42{
3c299c3a
DW
43 SetValue ((rEvent.GetInt() != 0) );
44 ProcessCommand (rEvent);
45} // end of wxRadioButton::Command
46
b0b5881a
WS
47bool wxRadioButton::Create( wxWindow* pParent,
48 wxWindowID vId,
49 const wxString& rsLabel,
50 const wxPoint& rPos,
51 const wxSize& rSize,
52 long lStyle,
53 const wxValidator& rValidator,
54 const wxString& rsName )
0e320a79 55{
1b086de1
DW
56 if ( !CreateControl( pParent
57 ,vId
58 ,rPos
59 ,rSize
60 ,lStyle
1b086de1 61 ,rValidator
1b086de1 62 ,rsName))
b0b5881a 63 return false;
0e320a79 64
2b5f62a0 65 long lSstyle = WS_TABSTOP;
0e320a79 66
2b5f62a0
VZ
67 if (HasFlag(wxRB_GROUP))
68 lSstyle |= WS_GROUP;
69
70 //
71 // wxRB_SINGLE is a temporary workaround for the following problem: if you
72 // have 2 radiobuttons in the same group but which are not consecutive in
73 // the dialog, Windows can enter an infinite loop! The simplest way to
74 // reproduce it is to create radio button, then a panel and then another
75 // radio button: then checking the last button hangs the app.
76 //
77 // Ideally, we'd detect (and avoid) such situation automatically but for
78 // now, as I don't know how to do it, just allow the user to create
79 // BS_RADIOBUTTON buttons for such situations.
80 //
81 lSstyle |= HasFlag(wxRB_SINGLE) ? BS_RADIOBUTTON : BS_AUTORADIOBUTTON;
cdf1e714 82
1b086de1
DW
83 if (HasFlag(wxCLIP_SIBLINGS))
84 lSstyle |= WS_CLIPSIBLINGS;
85
86 if (!OS2CreateControl( _T("BUTTON")
87 ,lSstyle
88 ,rPos
89 ,rSize
90 ,rsLabel
91 ,0
92 ))
b0b5881a 93 return false;
cdf1e714 94
f289196b 95 wxAssociateWinWithHandle(m_hWnd, this);
1b086de1 96 if (HasFlag(wxRB_GROUP))
b0b5881a 97 SetValue(true);
0e320a79 98
f289196b 99 SetFont(*wxSMALL_FONT);
b0b5881a
WS
100 SetSize( rPos.x, rPos.y, rSize.x, rSize.y );
101 return true;
1b086de1 102} // end of wxRadioButton::Create
0e320a79 103
1b086de1
DW
104wxSize wxRadioButton::DoGetBestSize() const
105{
c5f975dd
SN
106 // We should probably compute snRadioSize but it seems to be a constant
107 // independent of its label's font size and not made available by OS/2.
108 static int snRadioSize = RADIO_SIZE;
cdf1e714 109
c5f975dd 110 wxString sStr = wxGetWindowText(GetHwnd());
1b086de1
DW
111 int nRadioWidth;
112 int nRadioHeight;
113
114 if (!sStr.empty())
cdf1e714 115 {
1b086de1
DW
116 GetTextExtent( sStr
117 ,&nRadioWidth
118 ,&nRadioHeight
3c299c3a 119 );
c5f975dd 120 nRadioWidth += snRadioSize;
1b086de1
DW
121 if (nRadioHeight < snRadioSize)
122 nRadioHeight = snRadioSize;
3c299c3a
DW
123 }
124 else
125 {
1b086de1
DW
126 nRadioWidth = snRadioSize;
127 nRadioHeight = snRadioSize;
cdf1e714 128 }
1b086de1
DW
129 return wxSize( nRadioWidth
130 ,nRadioHeight
131 );
132} // end of wxRadioButton::DoGetBestSize
0e320a79 133
3c299c3a 134//
0e320a79 135// Get single selection, for single choice list items
3c299c3a 136//
0e320a79
DW
137bool wxRadioButton::GetValue() const
138{
3c299c3a
DW
139 return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0));
140} // end of wxRadioButton::GetValue
0e320a79 141
6670f564 142bool wxRadioButton::OS2Command( WXUINT wParam, WXWORD WXUNUSED(wId) )
cdf1e714 143{
2b5f62a0 144 if (wParam != BN_CLICKED)
6670f564 145 return false;
2b5f62a0
VZ
146
147 if (m_bFocusJustSet)
148 {
149 //
150 // See above: we want to ignore this event
151 //
6670f564 152 m_bFocusJustSet = false;
2b5f62a0
VZ
153 }
154 else
3c299c3a 155 {
6670f564 156 bool bIsChecked = GetValue();
2b5f62a0
VZ
157
158 if (HasFlag(wxRB_SINGLE))
159 {
160 //
161 // When we use a "manual" radio button, we have to check the button
162 // ourselves -- but it's reset to unchecked state by the user code
163 // (presumably when another button is pressed)
164 //
165 if (!bIsChecked )
b0b5881a 166 SetValue(true);
2b5f62a0 167 }
6670f564 168 wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
3c299c3a
DW
169 rEvent.SetEventObject(this);
170 ProcessCommand(rEvent);
3c299c3a 171 }
6670f564 172 return true;
3c299c3a 173} // end of wxRadioButton::OS2Command
cdf1e714 174
1b086de1
DW
175void wxRadioButton::SetFocus()
176{
177 // when the radio button receives a WM_SETFOCUS message it generates a
178 // BN_CLICKED which is totally unexpected and leads to catastrophic results
179 // if you pop up a dialog from the radio button event handler as, when the
180 // dialog is dismissed, the focus is returned to the radio button which
181 // generates BN_CLICKED which leads to showing another dialog and so on
182 // without end!
183 //
e94d504d 184 // to avoid this, we drop the pseudo BN_CLICKED events generated when the
1b086de1 185 // button gains focus
6670f564 186 m_bFocusJustSet = true;
1b086de1
DW
187
188 wxControl::SetFocus();
189}
190
b0b5881a 191void wxRadioButton::SetLabel( const wxString& rsLabel )
cdf1e714 192{
e94d504d
SN
193 wxString sLabel = ::wxPMTextToLabel(rsLabel);
194 ::WinSetWindowText((HWND)GetHWND(), (const char *)sLabel.c_str());
3c299c3a 195} // end of wxRadioButton::SetLabel
cdf1e714 196
b0b5881a 197void wxRadioButton::SetValue( bool bValue )
cdf1e714 198{
3c299c3a 199 ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0);
2b5f62a0
VZ
200 if (bValue)
201 {
202 const wxWindowList& rSiblings = GetParent()->GetChildren();
2461cfa0 203 wxWindowList::compatibility_iterator nodeThis = rSiblings.Find(this);
2b5f62a0 204
2461cfa0 205 wxCHECK_RET(nodeThis, _T("radio button not a child of its parent?"));
2b5f62a0 206
2b5f62a0 207 //
6e348b12
DW
208 // If it's not the first item of the group ...
209 //
210 if ( !HasFlag(wxRB_GROUP) )
2b5f62a0 211 {
6e348b12
DW
212 //
213 // ...turn off all radio buttons before this one
214 //
2461cfa0
SN
215 for ( wxWindowList::compatibility_iterator nodeBefore = nodeThis->GetPrevious();
216 nodeBefore;
217 nodeBefore = nodeBefore->GetPrevious() )
6e348b12 218 {
2461cfa0 219 wxRadioButton* pBtn = wxDynamicCast( nodeBefore->GetData()
2b5f62a0
VZ
220 ,wxRadioButton
221 );
6e348b12
DW
222 if (!pBtn)
223 {
224 //
225 // The radio buttons in a group must be consecutive, so there
226 // are no more of them
227 //
228 break;
229 }
b0b5881a 230 pBtn->SetValue(false);
6e348b12
DW
231 if (pBtn->HasFlag(wxRB_GROUP))
232 {
233 //
234 // Even if there are other radio buttons before this one,
235 // they're not in the same group with us
236 //
237 break;
238 }
2b5f62a0
VZ
239 }
240 }
241
6e348b12 242 //
2b5f62a0
VZ
243 // ... and all after this one
244 //
2461cfa0
SN
245 for (wxWindowList::compatibility_iterator nodeAfter = nodeThis->GetNext();
246 nodeAfter;
247 nodeAfter = nodeAfter->GetNext())
2b5f62a0 248 {
2461cfa0 249 wxRadioButton* pBtn = wxDynamicCast( nodeAfter->GetData()
2b5f62a0
VZ
250 ,wxRadioButton
251 );
252
253 if (!pBtn || pBtn->HasFlag(wxRB_GROUP) )
254 {
6e348b12 255 //
2b5f62a0
VZ
256 // No more buttons or the first button of the next group
257 //
258 break;
259 }
b0b5881a 260 pBtn->SetValue(false);
2b5f62a0
VZ
261 }
262 }
3c299c3a 263} // end of wxRadioButton::SetValue
0e320a79 264
97d74dd2
DW
265MRESULT wxRadioButton::OS2WindowProc(
266 WXUINT uMsg
267, WXWPARAM wParam
268, WXLPARAM lParam
269)
270{
271 if (uMsg == WM_SETFOCUS)
272 {
b0b5881a 273 m_bFocusJustSet = true;
97d74dd2
DW
274
275 MRESULT mRc = wxControl::OS2WindowProc( uMsg
276 ,wParam
277 ,lParam
278 );
279
b0b5881a 280 m_bFocusJustSet = false;
97d74dd2
DW
281 return mRc;
282 }
283 return wxControl::OS2WindowProc( uMsg
284 ,wParam
285 ,lParam
286 );
287} // end of wxRadioButton::OS2WindowProc