]>
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 | |
1b086de1 DW |
32 | void wxRadioButton::Init() |
33 | { | |
34 | m_bFocusJustSet = FALSE; | |
35 | } // end of wxRadioButton::Init | |
36 | ||
3c299c3a DW |
37 | void wxRadioButton::Command ( |
38 | wxCommandEvent& rEvent | |
39 | ) | |
cdf1e714 | 40 | { |
3c299c3a DW |
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 | |
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 | |
1b086de1 DW |
88 | SetFont(*wxSMALL_FONT); |
89 | SetSize( rPos.x | |
90 | ,rPos.y | |
91 | ,rSize.x | |
92 | ,rSize.y | |
93 | ); | |
94 | return TRUE; | |
95 | } // end of wxRadioButton::Create | |
0e320a79 | 96 | |
1b086de1 DW |
97 | wxSize wxRadioButton::DoGetBestSize() const |
98 | { | |
99 | static int snRadioSize = 0; | |
cdf1e714 | 100 | |
1b086de1 DW |
101 | if (!snRadioSize) |
102 | { | |
103 | wxScreenDC vDC; | |
cdf1e714 | 104 | |
1b086de1 DW |
105 | vDC.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); |
106 | snRadioSize = vDC.GetCharHeight(); | |
107 | } | |
108 | ||
109 | wxString sStr = GetLabel(); | |
110 | int nRadioWidth; | |
111 | int nRadioHeight; | |
112 | ||
113 | if (!sStr.empty()) | |
cdf1e714 | 114 | { |
1b086de1 DW |
115 | GetTextExtent( sStr |
116 | ,&nRadioWidth | |
117 | ,&nRadioHeight | |
3c299c3a | 118 | ); |
1b086de1 DW |
119 | nRadioWidth += snRadioSize + GetCharWidth(); |
120 | if (nRadioHeight < snRadioSize) | |
121 | nRadioHeight = snRadioSize; | |
3c299c3a DW |
122 | } |
123 | else | |
124 | { | |
1b086de1 DW |
125 | nRadioWidth = snRadioSize; |
126 | nRadioHeight = snRadioSize; | |
cdf1e714 | 127 | } |
1b086de1 DW |
128 | return wxSize( nRadioWidth |
129 | ,nRadioHeight | |
130 | ); | |
131 | } // end of wxRadioButton::DoGetBestSize | |
0e320a79 | 132 | |
3c299c3a | 133 | // |
0e320a79 | 134 | // Get single selection, for single choice list items |
3c299c3a | 135 | // |
0e320a79 DW |
136 | bool wxRadioButton::GetValue() const |
137 | { | |
3c299c3a DW |
138 | return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0)); |
139 | } // end of wxRadioButton::GetValue | |
0e320a79 | 140 | |
3c299c3a DW |
141 | bool wxRadioButton::OS2Command( |
142 | WXUINT wParam | |
143 | , WXWORD wId | |
144 | ) | |
cdf1e714 | 145 | { |
3c299c3a DW |
146 | if (wParam == BN_CLICKED) |
147 | { | |
148 | wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED | |
149 | ,m_windowId | |
150 | ); | |
cdf1e714 | 151 | |
3c299c3a DW |
152 | rEvent.SetEventObject(this); |
153 | ProcessCommand(rEvent); | |
154 | return TRUE; | |
155 | } | |
156 | else | |
157 | return FALSE; | |
158 | } // end of wxRadioButton::OS2Command | |
cdf1e714 | 159 | |
1b086de1 DW |
160 | void wxRadioButton::SetFocus() |
161 | { | |
162 | // when the radio button receives a WM_SETFOCUS message it generates a | |
163 | // BN_CLICKED which is totally unexpected and leads to catastrophic results | |
164 | // if you pop up a dialog from the radio button event handler as, when the | |
165 | // dialog is dismissed, the focus is returned to the radio button which | |
166 | // generates BN_CLICKED which leads to showing another dialog and so on | |
167 | // without end! | |
168 | // | |
169 | // to aviod this, we drop the pseudo BN_CLICKED events generated when the | |
170 | // button gains focus | |
171 | m_bFocusJustSet = TRUE; | |
172 | ||
173 | wxControl::SetFocus(); | |
174 | } | |
175 | ||
3c299c3a DW |
176 | void wxRadioButton::SetLabel( |
177 | const wxString& rsLabel | |
178 | ) | |
cdf1e714 | 179 | { |
3c299c3a DW |
180 | ::WinSetWindowText((HWND)GetHWND(), (const char *)rsLabel.c_str()); |
181 | } // end of wxRadioButton::SetLabel | |
cdf1e714 | 182 | |
3c299c3a DW |
183 | void wxRadioButton::SetValue( |
184 | bool bValue | |
185 | ) | |
cdf1e714 | 186 | { |
3c299c3a DW |
187 | ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0); |
188 | } // end of wxRadioButton::SetValue | |
0e320a79 | 189 |