]>
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" | |
2432b92d | 27 | #include "wx/brush.h" |
2bda0e17 KB |
28 | #endif |
29 | ||
30 | #include "wx/msw/private.h" | |
31 | ||
2bda0e17 KB |
32 | IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) |
33 | // IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton) | |
2bda0e17 | 34 | |
621793f4 JS |
35 | bool wxRadioButton::MSWCommand(WXUINT param, WXWORD id) |
36 | { | |
37 | if (param == BN_CLICKED) | |
38 | { | |
39 | wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId); | |
40 | event.SetEventObject( this ); | |
41 | ProcessCommand(event); | |
42 | return TRUE; | |
43 | } | |
44 | else return FALSE; | |
45 | } | |
46 | ||
debe6624 | 47 | bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, |
c085e333 | 48 | const wxString& label, |
2bda0e17 | 49 | const wxPoint& pos, |
debe6624 | 50 | const wxSize& size, long style, |
2bda0e17 KB |
51 | const wxValidator& validator, |
52 | const wxString& name) | |
53 | { | |
54 | SetName(name); | |
55 | SetValidator(validator); | |
56 | ||
57 | if (parent) parent->AddChild(this); | |
58 | ||
fd71308f JS |
59 | SetBackgroundColour(parent->GetBackgroundColour()); |
60 | SetForegroundColour(parent->GetForegroundColour()); | |
2bda0e17 KB |
61 | |
62 | if ( id == -1 ) | |
c085e333 | 63 | m_windowId = (int)NewControlId(); |
2bda0e17 | 64 | else |
c085e333 | 65 | m_windowId = id; |
2bda0e17 KB |
66 | |
67 | int x = pos.x; | |
68 | int y = pos.y; | |
69 | int width = size.x; | |
70 | int height = size.y; | |
71 | ||
72 | m_windowStyle = style ; | |
73 | ||
74 | long groupStyle = 0; | |
75 | if (m_windowStyle & wxRB_GROUP) | |
76 | groupStyle = WS_GROUP; | |
77 | ||
78 | // long msStyle = groupStyle | RADIO_FLAGS; | |
cd2df130 | 79 | long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE ; |
2bda0e17 KB |
80 | |
81 | bool want3D; | |
82 | WXDWORD exStyle = Determine3DEffects(0, &want3D) ; | |
83 | ||
84 | // Even with extended styles, need to combine with WS_BORDER | |
85 | // for them to look right. | |
2faefb26 | 86 | /* |
c085e333 | 87 | if ( want3D || wxStyleHasBorder(m_windowStyle) ) |
2bda0e17 | 88 | msStyle |= WS_BORDER; |
2faefb26 | 89 | */ |
2bda0e17 | 90 | |
837e5743 | 91 | m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label, |
2bda0e17 KB |
92 | msStyle,0,0,0,0, |
93 | (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); | |
c085e333 | 94 | |
223d09f6 | 95 | wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") ); |
c085e333 | 96 | |
1f112209 | 97 | #if wxUSE_CTL3D |
2bda0e17 KB |
98 | if (want3D) |
99 | { | |
100 | Ctl3dSubclassCtl((HWND) m_hWnd); | |
c085e333 | 101 | m_useCtl3D = TRUE; |
2bda0e17 KB |
102 | } |
103 | #endif | |
104 | ||
c0ed460c | 105 | SetFont(parent->GetFont()); |
2bda0e17 KB |
106 | |
107 | // Subclass again for purposes of dialog editing mode | |
108 | SubclassWin((WXHWND)m_hWnd); | |
109 | ||
110 | // SetValue(value); | |
111 | ||
112 | // start GRW fix | |
223d09f6 | 113 | if (label != wxT("")) |
2bda0e17 | 114 | { |
debe6624 | 115 | int label_width, label_height; |
ce3ed50d | 116 | GetTextExtent(label, &label_width, &label_height, NULL, NULL, & this->GetFont()); |
2bda0e17 KB |
117 | if (width < 0) |
118 | width = (int)(label_width + RADIO_SIZE); | |
119 | if (height<0) | |
120 | { | |
121 | height = (int)(label_height); | |
122 | if (height < RADIO_SIZE) | |
123 | height = RADIO_SIZE; | |
124 | } | |
125 | } | |
126 | else | |
127 | { | |
128 | if (width < 0) | |
129 | width = RADIO_SIZE; | |
130 | if (height < 0) | |
131 | height = RADIO_SIZE; | |
132 | } | |
133 | // end GRW fix | |
134 | ||
135 | SetSize(x, y, width, height); | |
136 | ||
137 | return TRUE; | |
138 | } | |
139 | ||
140 | ||
141 | void wxRadioButton::SetLabel(const wxString& label) | |
142 | { | |
837e5743 | 143 | SetWindowText((HWND) GetHWND(), (const wxChar *)label); |
2bda0e17 KB |
144 | } |
145 | ||
debe6624 | 146 | void wxRadioButton::SetValue(bool value) |
2bda0e17 KB |
147 | { |
148 | // Following necessary for Win32s, because Win32s translate BM_SETCHECK | |
149 | SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L); | |
150 | } | |
151 | ||
72fd19a1 | 152 | // Get single selection |
2bda0e17 KB |
153 | bool wxRadioButton::GetValue(void) const |
154 | { | |
72fd19a1 | 155 | return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L) != 0); |
2bda0e17 KB |
156 | } |
157 | ||
2bda0e17 KB |
158 | void wxRadioButton::Command (wxCommandEvent & event) |
159 | { | |
160 | SetValue ( (event.m_commandInt != 0) ); | |
161 | ProcessCommand (event); | |
162 | } | |
163 | ||
164 | ||
165 | // Not implemented | |
166 | #if 0 | |
debe6624 | 167 | bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id, |
c085e333 | 168 | const wxBitmap *bitmap, |
2bda0e17 | 169 | const wxPoint& pos, |
debe6624 | 170 | const wxSize& size, long style, |
2bda0e17 KB |
171 | const wxValidator& validator, |
172 | const wxString& name) | |
173 | { | |
174 | SetName(name); | |
175 | SetValidator(validator); | |
176 | ||
177 | if (parent) parent->AddChild(this); | |
fd71308f JS |
178 | SetBackgroundColour(parent->GetBackgroundColour()); |
179 | SetForegroundColour(parent->GetForegroundColour()); | |
2bda0e17 KB |
180 | |
181 | if ( id == -1 ) | |
c085e333 | 182 | m_windowId = (int)NewControlId(); |
2bda0e17 | 183 | else |
c085e333 | 184 | m_windowId = id; |
2bda0e17 KB |
185 | |
186 | int x = pos.x; | |
187 | int y = pos.y; | |
188 | int width = size.x; | |
189 | int height = size.y; | |
190 | m_windowStyle = style ; | |
191 | ||
192 | long groupStyle = 0; | |
193 | if (m_windowStyle & wxRB_GROUP) | |
194 | groupStyle = WS_GROUP; | |
195 | ||
196 | // long msStyle = groupStyle | RADIO_FLAGS; | |
197 | long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ; | |
198 | ||
199 | m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle", | |
200 | msStyle,0,0,0,0, | |
201 | (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); | |
c085e333 VZ |
202 | |
203 | wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE ); | |
204 | ||
1f112209 | 205 | #if wxUSE_CTL3D |
2bda0e17 KB |
206 | if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS)) |
207 | { | |
208 | Ctl3dSubclassCtl((HWND) GetHWND()); | |
c085e333 | 209 | m_useCtl3D = TRUE; |
2bda0e17 KB |
210 | } |
211 | #endif | |
212 | ||
213 | // Subclass again for purposes of dialog editing mode | |
214 | SubclassWin(GetHWND()); | |
215 | ||
216 | SetSize(x, y, width, height); | |
217 | ||
218 | return TRUE; | |
219 | } | |
220 | ||
221 | void wxBitmapRadioButton::SetLabel(const wxBitmap *bitmap) | |
222 | { | |
223 | } | |
224 | ||
debe6624 | 225 | void wxBitmapRadioButton::SetValue(bool value) |
2bda0e17 KB |
226 | { |
227 | // Following necessary for Win32s, because Win32s translate BM_SETCHECK | |
228 | SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L); | |
229 | } | |
230 | ||
231 | // Get single selection, for single choice list items | |
232 | bool wxBitmapRadioButton::GetValue(void) const | |
233 | { | |
234 | return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L); | |
235 | } | |
236 | ||
237 | #endif |