]> git.saurik.com Git - wxWidgets.git/blob - src/os2/radiobut.cpp
added ctor taking wxFontFlags
[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 extern void wxAssociateWinWithHandle( HWND hWnd
33 ,wxWindowOS2* pWin
34 );
35
36 void wxRadioButton::Init()
37 {
38 m_bFocusJustSet = FALSE;
39 } // end of wxRadioButton::Init
40
41 void wxRadioButton::Command (
42 wxCommandEvent& rEvent
43 )
44 {
45 SetValue ((rEvent.GetInt() != 0) );
46 ProcessCommand (rEvent);
47 } // end of wxRadioButton::Command
48
49 bool wxRadioButton::Create(
50 wxWindow* pParent
51 , wxWindowID vId
52 , const wxString& rsLabel
53 , const wxPoint& rPos
54 , const wxSize& rSize
55 , long lStyle
56 #if wxUSE_VALIDATORS
57 , const wxValidator& rValidator
58 #endif
59 , const wxString& rsName
60 )
61 {
62 if ( !CreateControl( pParent
63 ,vId
64 ,rPos
65 ,rSize
66 ,lStyle
67 #if wxUSE_VALIDATORS
68 ,rValidator
69 #endif
70 ,rsName))
71 return FALSE;
72
73 long lSstyle = HasFlag(wxRB_GROUP) ? WS_GROUP : 0;
74
75 lSstyle |= BS_AUTORADIOBUTTON;
76
77 if (HasFlag(wxCLIP_SIBLINGS))
78 lSstyle |= WS_CLIPSIBLINGS;
79
80 if (!OS2CreateControl( _T("BUTTON")
81 ,lSstyle
82 ,rPos
83 ,rSize
84 ,rsLabel
85 ,0
86 ))
87 return FALSE;
88
89 wxAssociateWinWithHandle(m_hWnd, this);
90 if (HasFlag(wxRB_GROUP))
91 SetValue(TRUE);
92
93 SetFont(*wxSMALL_FONT);
94 SetSize( rPos.x
95 ,rPos.y
96 ,rSize.x
97 ,rSize.y
98 );
99 return TRUE;
100 } // end of wxRadioButton::Create
101
102 wxSize wxRadioButton::DoGetBestSize() const
103 {
104 static int snRadioSize = 0;
105
106 if (!snRadioSize)
107 {
108 wxScreenDC vDC;
109
110 vDC.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
111 snRadioSize = vDC.GetCharHeight();
112 }
113
114 wxString sStr = GetLabel();
115 int nRadioWidth;
116 int nRadioHeight;
117
118 if (!sStr.empty())
119 {
120 GetTextExtent( sStr
121 ,&nRadioWidth
122 ,&nRadioHeight
123 );
124 nRadioWidth += snRadioSize + GetCharWidth();
125 if (nRadioHeight < snRadioSize)
126 nRadioHeight = snRadioSize;
127 }
128 else
129 {
130 nRadioWidth = snRadioSize;
131 nRadioHeight = snRadioSize;
132 }
133 return wxSize( nRadioWidth
134 ,nRadioHeight
135 );
136 } // end of wxRadioButton::DoGetBestSize
137
138 //
139 // Get single selection, for single choice list items
140 //
141 bool wxRadioButton::GetValue() const
142 {
143 return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0));
144 } // end of wxRadioButton::GetValue
145
146 bool wxRadioButton::OS2Command(
147 WXUINT wParam
148 , WXWORD wId
149 )
150 {
151 if (wParam == BN_CLICKED)
152 {
153 wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED
154 ,m_windowId
155 );
156
157 rEvent.SetEventObject(this);
158 ProcessCommand(rEvent);
159 return TRUE;
160 }
161 else
162 return FALSE;
163 } // end of wxRadioButton::OS2Command
164
165 void wxRadioButton::SetFocus()
166 {
167 // when the radio button receives a WM_SETFOCUS message it generates a
168 // BN_CLICKED which is totally unexpected and leads to catastrophic results
169 // if you pop up a dialog from the radio button event handler as, when the
170 // dialog is dismissed, the focus is returned to the radio button which
171 // generates BN_CLICKED which leads to showing another dialog and so on
172 // without end!
173 //
174 // to aviod this, we drop the pseudo BN_CLICKED events generated when the
175 // button gains focus
176 m_bFocusJustSet = TRUE;
177
178 wxControl::SetFocus();
179 }
180
181 void wxRadioButton::SetLabel(
182 const wxString& rsLabel
183 )
184 {
185 ::WinSetWindowText((HWND)GetHWND(), (const char *)rsLabel.c_str());
186 } // end of wxRadioButton::SetLabel
187
188 void wxRadioButton::SetValue(
189 bool bValue
190 )
191 {
192 ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0);
193 } // end of wxRadioButton::SetValue
194
195 MRESULT wxRadioButton::OS2WindowProc(
196 WXUINT uMsg
197 , WXWPARAM wParam
198 , WXLPARAM lParam
199 )
200 {
201 if (uMsg == WM_SETFOCUS)
202 {
203 m_bFocusJustSet = TRUE;
204
205 MRESULT mRc = wxControl::OS2WindowProc( uMsg
206 ,wParam
207 ,lParam
208 );
209
210 m_bFocusJustSet = FALSE;
211 return mRc;
212 }
213 return wxControl::OS2WindowProc( uMsg
214 ,wParam
215 ,lParam
216 );
217 } // end of wxRadioButton::OS2WindowProc