]>
Commit | Line | Data |
---|---|---|
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 | 30 | IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) |
0e320a79 | 31 | |
f289196b DW |
32 | extern void wxAssociateWinWithHandle( HWND hWnd |
33 | ,wxWindowOS2* pWin | |
34 | ); | |
35 | ||
1b086de1 DW |
36 | void wxRadioButton::Init() |
37 | { | |
38 | m_bFocusJustSet = FALSE; | |
39 | } // end of wxRadioButton::Init | |
40 | ||
3c299c3a DW |
41 | void wxRadioButton::Command ( |
42 | wxCommandEvent& rEvent | |
43 | ) | |
cdf1e714 | 44 | { |
3c299c3a DW |
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 | |
5d4b632b | 56 | #if wxUSE_VALIDATORS |
3c299c3a | 57 | , const wxValidator& rValidator |
5d4b632b | 58 | #endif |
3c299c3a DW |
59 | , const wxString& rsName |
60 | ) | |
0e320a79 | 61 | { |
1b086de1 DW |
62 | if ( !CreateControl( pParent |
63 | ,vId | |
64 | ,rPos | |
65 | ,rSize | |
66 | ,lStyle | |
5d4b632b | 67 | #if wxUSE_VALIDATORS |
1b086de1 | 68 | ,rValidator |
5d4b632b | 69 | #endif |
1b086de1 DW |
70 | ,rsName)) |
71 | return FALSE; | |
0e320a79 | 72 | |
1b086de1 | 73 | long lSstyle = HasFlag(wxRB_GROUP) ? WS_GROUP : 0; |
0e320a79 | 74 | |
1b086de1 | 75 | lSstyle |= BS_AUTORADIOBUTTON; |
cdf1e714 | 76 | |
1b086de1 DW |
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; | |
cdf1e714 | 88 | |
f289196b | 89 | wxAssociateWinWithHandle(m_hWnd, this); |
1b086de1 DW |
90 | if (HasFlag(wxRB_GROUP)) |
91 | SetValue(TRUE); | |
0e320a79 | 92 | |
f289196b | 93 | SetFont(*wxSMALL_FONT); |
1b086de1 DW |
94 | SetSize( rPos.x |
95 | ,rPos.y | |
96 | ,rSize.x | |
97 | ,rSize.y | |
98 | ); | |
99 | return TRUE; | |
100 | } // end of wxRadioButton::Create | |
0e320a79 | 101 | |
1b086de1 DW |
102 | wxSize wxRadioButton::DoGetBestSize() const |
103 | { | |
104 | static int snRadioSize = 0; | |
cdf1e714 | 105 | |
1b086de1 DW |
106 | if (!snRadioSize) |
107 | { | |
108 | wxScreenDC vDC; | |
cdf1e714 | 109 | |
1b086de1 DW |
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()) | |
cdf1e714 | 119 | { |
1b086de1 DW |
120 | GetTextExtent( sStr |
121 | ,&nRadioWidth | |
122 | ,&nRadioHeight | |
3c299c3a | 123 | ); |
1b086de1 DW |
124 | nRadioWidth += snRadioSize + GetCharWidth(); |
125 | if (nRadioHeight < snRadioSize) | |
126 | nRadioHeight = snRadioSize; | |
3c299c3a DW |
127 | } |
128 | else | |
129 | { | |
1b086de1 DW |
130 | nRadioWidth = snRadioSize; |
131 | nRadioHeight = snRadioSize; | |
cdf1e714 | 132 | } |
1b086de1 DW |
133 | return wxSize( nRadioWidth |
134 | ,nRadioHeight | |
135 | ); | |
136 | } // end of wxRadioButton::DoGetBestSize | |
0e320a79 | 137 | |
3c299c3a | 138 | // |
0e320a79 | 139 | // Get single selection, for single choice list items |
3c299c3a | 140 | // |
0e320a79 DW |
141 | bool wxRadioButton::GetValue() const |
142 | { | |
3c299c3a DW |
143 | return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0)); |
144 | } // end of wxRadioButton::GetValue | |
0e320a79 | 145 | |
3c299c3a DW |
146 | bool wxRadioButton::OS2Command( |
147 | WXUINT wParam | |
148 | , WXWORD wId | |
149 | ) | |
cdf1e714 | 150 | { |
3c299c3a DW |
151 | if (wParam == BN_CLICKED) |
152 | { | |
153 | wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED | |
154 | ,m_windowId | |
155 | ); | |
cdf1e714 | 156 | |
3c299c3a DW |
157 | rEvent.SetEventObject(this); |
158 | ProcessCommand(rEvent); | |
159 | return TRUE; | |
160 | } | |
161 | else | |
162 | return FALSE; | |
163 | } // end of wxRadioButton::OS2Command | |
cdf1e714 | 164 | |
1b086de1 DW |
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 | ||
3c299c3a DW |
181 | void wxRadioButton::SetLabel( |
182 | const wxString& rsLabel | |
183 | ) | |
cdf1e714 | 184 | { |
3c299c3a DW |
185 | ::WinSetWindowText((HWND)GetHWND(), (const char *)rsLabel.c_str()); |
186 | } // end of wxRadioButton::SetLabel | |
cdf1e714 | 187 | |
3c299c3a DW |
188 | void wxRadioButton::SetValue( |
189 | bool bValue | |
190 | ) | |
cdf1e714 | 191 | { |
3c299c3a DW |
192 | ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0); |
193 | } // end of wxRadioButton::SetValue | |
0e320a79 | 194 | |
97d74dd2 DW |
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 |