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