]> git.saurik.com Git - wxWidgets.git/blame - src/os2/radiobut.cpp
reenabled WS_EX_CONTROLPARENT style together with a check that the focus window is...
[wxWidgets.git] / src / os2 / radiobut.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobut.cpp
3// Purpose: wxRadioButton
cdf1e714 4// Author: David Webster
0e320a79 5// Modified by:
cdf1e714 6// Created: 10/12/99
0e320a79 7// RCS-ID: $Id$
cdf1e714
DW
8// Copyright: (c) David Webster
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__
16#pragma hdrstop
0e320a79
DW
17#endif
18
cdf1e714
DW
19#ifndef WX_PRECOMP
20#include <stdio.h>
21#include "wx/setup.h"
0e320a79 22#include "wx/radiobut.h"
cdf1e714 23#include "wx/brush.h"
a4a16252
SN
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
1b086de1
DW
32void wxRadioButton::Init()
33{
34 m_bFocusJustSet = FALSE;
35} // end of wxRadioButton::Init
36
3c299c3a
DW
37void wxRadioButton::Command (
38 wxCommandEvent& rEvent
39)
cdf1e714 40{
3c299c3a
DW
41 SetValue ((rEvent.GetInt() != 0) );
42 ProcessCommand (rEvent);
43} // end of wxRadioButton::Command
44
45bool wxRadioButton::Create(
46 wxWindow* pParent
47, wxWindowID vId
48, const wxString& rsLabel
49, const wxPoint& rPos
50, const wxSize& rSize
51, long lStyle
5d4b632b 52#if wxUSE_VALIDATORS
3c299c3a 53, const wxValidator& rValidator
5d4b632b 54#endif
3c299c3a
DW
55, const wxString& rsName
56)
0e320a79 57{
1b086de1
DW
58 if ( !CreateControl( pParent
59 ,vId
60 ,rPos
61 ,rSize
62 ,lStyle
5d4b632b 63#if wxUSE_VALIDATORS
1b086de1 64 ,rValidator
5d4b632b 65#endif
1b086de1
DW
66 ,rsName))
67 return FALSE;
0e320a79 68
1b086de1 69 long lSstyle = HasFlag(wxRB_GROUP) ? WS_GROUP : 0;
0e320a79 70
1b086de1 71 lSstyle |= BS_AUTORADIOBUTTON;
cdf1e714 72
1b086de1
DW
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;
cdf1e714 84
1b086de1
DW
85 if (HasFlag(wxRB_GROUP))
86 SetValue(TRUE);
0e320a79 87
b3260bce
DW
88 wxFont* pTextFont = new wxFont( 10
89 ,wxMODERN
90 ,wxNORMAL
91 ,wxNORMAL
92 );
93 SetFont(*pTextFont);
1b086de1
DW
94 SetSize( rPos.x
95 ,rPos.y
96 ,rSize.x
97 ,rSize.y
98 );
b3260bce 99 delete pTextFont;
1b086de1
DW
100 return TRUE;
101} // end of wxRadioButton::Create
0e320a79 102
1b086de1
DW
103wxSize wxRadioButton::DoGetBestSize() const
104{
105 static int snRadioSize = 0;
cdf1e714 106
1b086de1
DW
107 if (!snRadioSize)
108 {
109 wxScreenDC vDC;
cdf1e714 110
1b086de1
DW
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())
cdf1e714 120 {
1b086de1
DW
121 GetTextExtent( sStr
122 ,&nRadioWidth
123 ,&nRadioHeight
3c299c3a 124 );
1b086de1
DW
125 nRadioWidth += snRadioSize + GetCharWidth();
126 if (nRadioHeight < snRadioSize)
127 nRadioHeight = snRadioSize;
3c299c3a
DW
128 }
129 else
130 {
1b086de1
DW
131 nRadioWidth = snRadioSize;
132 nRadioHeight = snRadioSize;
cdf1e714 133 }
1b086de1
DW
134 return wxSize( nRadioWidth
135 ,nRadioHeight
136 );
137} // end of wxRadioButton::DoGetBestSize
0e320a79 138
3c299c3a 139//
0e320a79 140// Get single selection, for single choice list items
3c299c3a 141//
0e320a79
DW
142bool wxRadioButton::GetValue() const
143{
3c299c3a
DW
144 return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0));
145} // end of wxRadioButton::GetValue
0e320a79 146
3c299c3a
DW
147bool wxRadioButton::OS2Command(
148 WXUINT wParam
149, WXWORD wId
150)
cdf1e714 151{
3c299c3a
DW
152 if (wParam == BN_CLICKED)
153 {
154 wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED
155 ,m_windowId
156 );
cdf1e714 157
3c299c3a
DW
158 rEvent.SetEventObject(this);
159 ProcessCommand(rEvent);
160 return TRUE;
161 }
162 else
163 return FALSE;
164} // end of wxRadioButton::OS2Command
cdf1e714 165
1b086de1
DW
166void 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
3c299c3a
DW
182void wxRadioButton::SetLabel(
183 const wxString& rsLabel
184)
cdf1e714 185{
3c299c3a
DW
186 ::WinSetWindowText((HWND)GetHWND(), (const char *)rsLabel.c_str());
187} // end of wxRadioButton::SetLabel
cdf1e714 188
3c299c3a
DW
189void wxRadioButton::SetValue(
190 bool bValue
191)
cdf1e714 192{
3c299c3a
DW
193 ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0);
194} // end of wxRadioButton::SetValue
0e320a79 195