]>
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 | IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) | |
33 | // IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton) | |
34 | ||
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 | ||
47 | bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, | |
48 | const wxString& label, | |
49 | const wxPoint& pos, | |
50 | const wxSize& size, long style, | |
51 | const wxValidator& validator, | |
52 | const wxString& name) | |
53 | { | |
54 | SetName(name); | |
55 | SetValidator(validator); | |
56 | ||
57 | if (parent) parent->AddChild(this); | |
58 | ||
59 | SetBackgroundColour(parent->GetBackgroundColour()); | |
60 | SetForegroundColour(parent->GetForegroundColour()); | |
61 | ||
62 | if ( id == -1 ) | |
63 | m_windowId = (int)NewControlId(); | |
64 | else | |
65 | m_windowId = id; | |
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; | |
79 | long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE ; | |
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. | |
86 | /* | |
87 | if ( want3D || wxStyleHasBorder(m_windowStyle) ) | |
88 | msStyle |= WS_BORDER; | |
89 | */ | |
90 | ||
91 | m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label, | |
92 | msStyle,0,0,0,0, | |
93 | (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); | |
94 | ||
95 | wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") ); | |
96 | ||
97 | #if wxUSE_CTL3D | |
98 | if (want3D) | |
99 | { | |
100 | Ctl3dSubclassCtl((HWND) m_hWnd); | |
101 | m_useCtl3D = TRUE; | |
102 | } | |
103 | #endif | |
104 | ||
105 | SetFont(parent->GetFont()); | |
106 | ||
107 | // Subclass again for purposes of dialog editing mode | |
108 | SubclassWin((WXHWND)m_hWnd); | |
109 | ||
110 | // SetValue(value); | |
111 | ||
112 | // start GRW fix | |
113 | if (label != wxT("")) | |
114 | { | |
115 | int label_width, label_height; | |
116 | GetTextExtent(label, &label_width, &label_height, NULL, NULL, & this->GetFont()); | |
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 | { | |
143 | SetWindowText((HWND) GetHWND(), (const wxChar *)label); | |
144 | } | |
145 | ||
146 | void wxRadioButton::SetValue(bool value) | |
147 | { | |
148 | // Following necessary for Win32s, because Win32s translate BM_SETCHECK | |
149 | SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L); | |
150 | } | |
151 | ||
152 | // Get single selection | |
153 | bool wxRadioButton::GetValue(void) const | |
154 | { | |
155 | return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L) != 0); | |
156 | } | |
157 | ||
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 | |
167 | bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id, | |
168 | const wxBitmap *bitmap, | |
169 | const wxPoint& pos, | |
170 | const wxSize& size, long style, | |
171 | const wxValidator& validator, | |
172 | const wxString& name) | |
173 | { | |
174 | SetName(name); | |
175 | SetValidator(validator); | |
176 | ||
177 | if (parent) parent->AddChild(this); | |
178 | SetBackgroundColour(parent->GetBackgroundColour()); | |
179 | SetForegroundColour(parent->GetForegroundColour()); | |
180 | ||
181 | if ( id == -1 ) | |
182 | m_windowId = (int)NewControlId(); | |
183 | else | |
184 | m_windowId = id; | |
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); | |
202 | ||
203 | wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE ); | |
204 | ||
205 | #if wxUSE_CTL3D | |
206 | if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS)) | |
207 | { | |
208 | Ctl3dSubclassCtl((HWND) GetHWND()); | |
209 | m_useCtl3D = TRUE; | |
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 | ||
225 | void wxBitmapRadioButton::SetValue(bool value) | |
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 |