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