]>
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 DW |
23 | #include "wx/brush.h" |
24 | #endif | |
25 | ||
11e59d47 | 26 | #include "wx/os2/private.h" |
0e320a79 | 27 | |
0e320a79 | 28 | IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) |
0e320a79 | 29 | |
1b086de1 DW |
30 | void wxRadioButton::Init() |
31 | { | |
32 | m_bFocusJustSet = FALSE; | |
33 | } // end of wxRadioButton::Init | |
34 | ||
3c299c3a DW |
35 | void wxRadioButton::Command ( |
36 | wxCommandEvent& rEvent | |
37 | ) | |
cdf1e714 | 38 | { |
3c299c3a DW |
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 | |
5d4b632b | 50 | #if wxUSE_VALIDATORS |
3c299c3a | 51 | , const wxValidator& rValidator |
5d4b632b | 52 | #endif |
3c299c3a DW |
53 | , const wxString& rsName |
54 | ) | |
0e320a79 | 55 | { |
1b086de1 DW |
56 | if ( !CreateControl( pParent |
57 | ,vId | |
58 | ,rPos | |
59 | ,rSize | |
60 | ,lStyle | |
5d4b632b | 61 | #if wxUSE_VALIDATORS |
1b086de1 | 62 | ,rValidator |
5d4b632b | 63 | #endif |
1b086de1 DW |
64 | ,rsName)) |
65 | return FALSE; | |
0e320a79 | 66 | |
1b086de1 | 67 | long lSstyle = HasFlag(wxRB_GROUP) ? WS_GROUP : 0; |
0e320a79 | 68 | |
1b086de1 | 69 | lSstyle |= BS_AUTORADIOBUTTON; |
cdf1e714 | 70 | |
1b086de1 DW |
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; | |
cdf1e714 | 82 | |
1b086de1 DW |
83 | if (HasFlag(wxRB_GROUP)) |
84 | SetValue(TRUE); | |
0e320a79 | 85 | |
1b086de1 DW |
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 | |
0e320a79 | 94 | |
1b086de1 DW |
95 | wxSize wxRadioButton::DoGetBestSize() const |
96 | { | |
97 | static int snRadioSize = 0; | |
cdf1e714 | 98 | |
1b086de1 DW |
99 | if (!snRadioSize) |
100 | { | |
101 | wxScreenDC vDC; | |
cdf1e714 | 102 | |
1b086de1 DW |
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()) | |
cdf1e714 | 112 | { |
1b086de1 DW |
113 | GetTextExtent( sStr |
114 | ,&nRadioWidth | |
115 | ,&nRadioHeight | |
3c299c3a | 116 | ); |
1b086de1 DW |
117 | nRadioWidth += snRadioSize + GetCharWidth(); |
118 | if (nRadioHeight < snRadioSize) | |
119 | nRadioHeight = snRadioSize; | |
3c299c3a DW |
120 | } |
121 | else | |
122 | { | |
1b086de1 DW |
123 | nRadioWidth = snRadioSize; |
124 | nRadioHeight = snRadioSize; | |
cdf1e714 | 125 | } |
1b086de1 DW |
126 | return wxSize( nRadioWidth |
127 | ,nRadioHeight | |
128 | ); | |
129 | } // end of wxRadioButton::DoGetBestSize | |
0e320a79 | 130 | |
3c299c3a | 131 | // |
0e320a79 | 132 | // Get single selection, for single choice list items |
3c299c3a | 133 | // |
0e320a79 DW |
134 | bool wxRadioButton::GetValue() const |
135 | { | |
3c299c3a DW |
136 | return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0)); |
137 | } // end of wxRadioButton::GetValue | |
0e320a79 | 138 | |
3c299c3a DW |
139 | bool wxRadioButton::OS2Command( |
140 | WXUINT wParam | |
141 | , WXWORD wId | |
142 | ) | |
cdf1e714 | 143 | { |
3c299c3a DW |
144 | if (wParam == BN_CLICKED) |
145 | { | |
146 | wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED | |
147 | ,m_windowId | |
148 | ); | |
cdf1e714 | 149 | |
3c299c3a DW |
150 | rEvent.SetEventObject(this); |
151 | ProcessCommand(rEvent); | |
152 | return TRUE; | |
153 | } | |
154 | else | |
155 | return FALSE; | |
156 | } // end of wxRadioButton::OS2Command | |
cdf1e714 | 157 | |
1b086de1 DW |
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 | ||
3c299c3a DW |
174 | void wxRadioButton::SetLabel( |
175 | const wxString& rsLabel | |
176 | ) | |
cdf1e714 | 177 | { |
3c299c3a DW |
178 | ::WinSetWindowText((HWND)GetHWND(), (const char *)rsLabel.c_str()); |
179 | } // end of wxRadioButton::SetLabel | |
cdf1e714 | 180 | |
3c299c3a DW |
181 | void wxRadioButton::SetValue( |
182 | bool bValue | |
183 | ) | |
cdf1e714 | 184 | { |
3c299c3a DW |
185 | ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0); |
186 | } // end of wxRadioButton::SetValue | |
0e320a79 | 187 |