]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: radiobut.cpp | |
3 | // Purpose: wxRadioButton | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
c085e333 | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "radiobut.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include <stdio.h> | |
25 | #include "wx/setup.h" | |
26 | #include "wx/radiobut.h" | |
27 | #endif | |
28 | ||
29 | #include "wx/msw/private.h" | |
30 | ||
31 | #if !USE_SHARED_LIBRARY | |
32 | IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) | |
33 | // IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton) | |
34 | #endif | |
35 | ||
621793f4 JS |
36 | bool wxRadioButton::MSWCommand(WXUINT param, WXWORD id) |
37 | { | |
38 | if (param == BN_CLICKED) | |
39 | { | |
40 | wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId); | |
41 | event.SetEventObject( this ); | |
42 | ProcessCommand(event); | |
43 | return TRUE; | |
44 | } | |
45 | else return FALSE; | |
46 | } | |
47 | ||
debe6624 | 48 | bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, |
c085e333 | 49 | const wxString& label, |
2bda0e17 | 50 | const wxPoint& pos, |
debe6624 | 51 | const wxSize& size, long style, |
2bda0e17 KB |
52 | const wxValidator& validator, |
53 | const wxString& name) | |
54 | { | |
55 | SetName(name); | |
56 | SetValidator(validator); | |
57 | ||
58 | if (parent) parent->AddChild(this); | |
59 | ||
fd71308f JS |
60 | SetBackgroundColour(parent->GetBackgroundColour()); |
61 | SetForegroundColour(parent->GetForegroundColour()); | |
2bda0e17 KB |
62 | |
63 | if ( id == -1 ) | |
c085e333 | 64 | m_windowId = (int)NewControlId(); |
2bda0e17 | 65 | else |
c085e333 | 66 | m_windowId = id; |
2bda0e17 KB |
67 | |
68 | int x = pos.x; | |
69 | int y = pos.y; | |
70 | int width = size.x; | |
71 | int height = size.y; | |
72 | ||
73 | m_windowStyle = style ; | |
74 | ||
75 | long groupStyle = 0; | |
76 | if (m_windowStyle & wxRB_GROUP) | |
77 | groupStyle = WS_GROUP; | |
78 | ||
79 | // long msStyle = groupStyle | RADIO_FLAGS; | |
cd2df130 | 80 | long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE ; |
2bda0e17 KB |
81 | |
82 | bool want3D; | |
83 | WXDWORD exStyle = Determine3DEffects(0, &want3D) ; | |
84 | ||
85 | // Even with extended styles, need to combine with WS_BORDER | |
86 | // for them to look right. | |
2faefb26 | 87 | /* |
c085e333 | 88 | if ( want3D || wxStyleHasBorder(m_windowStyle) ) |
2bda0e17 | 89 | msStyle |= WS_BORDER; |
2faefb26 | 90 | */ |
2bda0e17 KB |
91 | |
92 | m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const char *)label, | |
93 | msStyle,0,0,0,0, | |
94 | (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); | |
c085e333 VZ |
95 | |
96 | wxCHECK_MSG( m_hWnd, FALSE, "Failed to create radiobutton" ); | |
97 | ||
2bda0e17 KB |
98 | #if CTL3D |
99 | if (want3D) | |
100 | { | |
101 | Ctl3dSubclassCtl((HWND) m_hWnd); | |
c085e333 | 102 | m_useCtl3D = TRUE; |
2bda0e17 KB |
103 | } |
104 | #endif | |
105 | ||
c0ed460c | 106 | SetFont(parent->GetFont()); |
2bda0e17 KB |
107 | |
108 | // Subclass again for purposes of dialog editing mode | |
109 | SubclassWin((WXHWND)m_hWnd); | |
110 | ||
111 | // SetValue(value); | |
112 | ||
113 | // start GRW fix | |
114 | if (label != "") | |
115 | { | |
debe6624 | 116 | int label_width, label_height; |
c0ed460c | 117 | GetTextExtent(label, &label_width, &label_height, NULL, NULL, & GetFont()); |
2bda0e17 KB |
118 | if (width < 0) |
119 | width = (int)(label_width + RADIO_SIZE); | |
120 | if (height<0) | |
121 | { | |
122 | height = (int)(label_height); | |
123 | if (height < RADIO_SIZE) | |
124 | height = RADIO_SIZE; | |
125 | } | |
126 | } | |
127 | else | |
128 | { | |
129 | if (width < 0) | |
130 | width = RADIO_SIZE; | |
131 | if (height < 0) | |
132 | height = RADIO_SIZE; | |
133 | } | |
134 | // end GRW fix | |
135 | ||
136 | SetSize(x, y, width, height); | |
137 | ||
138 | return TRUE; | |
139 | } | |
140 | ||
141 | ||
142 | void wxRadioButton::SetLabel(const wxString& label) | |
143 | { | |
144 | SetWindowText((HWND) GetHWND(), (const char *)label); | |
145 | } | |
146 | ||
debe6624 | 147 | void wxRadioButton::SetValue(bool value) |
2bda0e17 KB |
148 | { |
149 | // Following necessary for Win32s, because Win32s translate BM_SETCHECK | |
150 | SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L); | |
151 | } | |
152 | ||
72fd19a1 | 153 | // Get single selection |
2bda0e17 KB |
154 | bool wxRadioButton::GetValue(void) const |
155 | { | |
72fd19a1 | 156 | return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L) != 0); |
2bda0e17 KB |
157 | } |
158 | ||
debe6624 | 159 | WXHBRUSH wxRadioButton::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
c085e333 | 160 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 KB |
161 | { |
162 | #if CTL3D | |
163 | if ( m_useCtl3D ) | |
164 | { | |
165 | HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); | |
166 | return (WXHBRUSH) hbrush; | |
167 | } | |
168 | #endif | |
169 | ||
170 | if (GetParent()->GetTransparentBackground()) | |
171 | SetBkMode((HDC) pDC, TRANSPARENT); | |
172 | else | |
173 | SetBkMode((HDC) pDC, OPAQUE); | |
174 | ||
175 | ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); | |
176 | ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); | |
177 | ||
178 | wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); | |
179 | ||
180 | // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush | |
181 | // has a zero usage count. | |
182 | // backgroundBrush->RealizeResource(); | |
183 | return (WXHBRUSH) backgroundBrush->GetResourceHandle(); | |
184 | } | |
185 | ||
186 | void wxRadioButton::Command (wxCommandEvent & event) | |
187 | { | |
188 | SetValue ( (event.m_commandInt != 0) ); | |
189 | ProcessCommand (event); | |
190 | } | |
191 | ||
192 | ||
193 | // Not implemented | |
194 | #if 0 | |
debe6624 | 195 | bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id, |
c085e333 | 196 | const wxBitmap *bitmap, |
2bda0e17 | 197 | const wxPoint& pos, |
debe6624 | 198 | const wxSize& size, long style, |
2bda0e17 KB |
199 | const wxValidator& validator, |
200 | const wxString& name) | |
201 | { | |
202 | SetName(name); | |
203 | SetValidator(validator); | |
204 | ||
205 | if (parent) parent->AddChild(this); | |
fd71308f JS |
206 | SetBackgroundColour(parent->GetBackgroundColour()); |
207 | SetForegroundColour(parent->GetForegroundColour()); | |
2bda0e17 KB |
208 | |
209 | if ( id == -1 ) | |
c085e333 | 210 | m_windowId = (int)NewControlId(); |
2bda0e17 | 211 | else |
c085e333 | 212 | m_windowId = id; |
2bda0e17 KB |
213 | |
214 | int x = pos.x; | |
215 | int y = pos.y; | |
216 | int width = size.x; | |
217 | int height = size.y; | |
218 | m_windowStyle = style ; | |
219 | ||
220 | long groupStyle = 0; | |
221 | if (m_windowStyle & wxRB_GROUP) | |
222 | groupStyle = WS_GROUP; | |
223 | ||
224 | // long msStyle = groupStyle | RADIO_FLAGS; | |
225 | long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ; | |
226 | ||
227 | m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle", | |
228 | msStyle,0,0,0,0, | |
229 | (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); | |
c085e333 VZ |
230 | |
231 | wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE ); | |
232 | ||
2bda0e17 KB |
233 | #if CTL3D |
234 | if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS)) | |
235 | { | |
236 | Ctl3dSubclassCtl((HWND) GetHWND()); | |
c085e333 | 237 | m_useCtl3D = TRUE; |
2bda0e17 KB |
238 | } |
239 | #endif | |
240 | ||
241 | // Subclass again for purposes of dialog editing mode | |
242 | SubclassWin(GetHWND()); | |
243 | ||
244 | SetSize(x, y, width, height); | |
245 | ||
246 | return TRUE; | |
247 | } | |
248 | ||
249 | void wxBitmapRadioButton::SetLabel(const wxBitmap *bitmap) | |
250 | { | |
251 | } | |
252 | ||
debe6624 | 253 | void wxBitmapRadioButton::SetValue(bool value) |
2bda0e17 KB |
254 | { |
255 | // Following necessary for Win32s, because Win32s translate BM_SETCHECK | |
256 | SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L); | |
257 | } | |
258 | ||
259 | // Get single selection, for single choice list items | |
260 | bool wxBitmapRadioButton::GetValue(void) const | |
261 | { | |
262 | return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L); | |
263 | } | |
264 | ||
265 | #endif |