]>
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 | ||
debe6624 | 36 | bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, |
c085e333 | 37 | const wxString& label, |
2bda0e17 | 38 | const wxPoint& pos, |
debe6624 | 39 | const wxSize& size, long style, |
2bda0e17 KB |
40 | const wxValidator& validator, |
41 | const wxString& name) | |
42 | { | |
43 | SetName(name); | |
44 | SetValidator(validator); | |
45 | ||
46 | if (parent) parent->AddChild(this); | |
47 | ||
fd71308f JS |
48 | SetBackgroundColour(parent->GetBackgroundColour()); |
49 | SetForegroundColour(parent->GetForegroundColour()); | |
2bda0e17 KB |
50 | |
51 | if ( id == -1 ) | |
c085e333 | 52 | m_windowId = (int)NewControlId(); |
2bda0e17 | 53 | else |
c085e333 | 54 | m_windowId = id; |
2bda0e17 KB |
55 | |
56 | int x = pos.x; | |
57 | int y = pos.y; | |
58 | int width = size.x; | |
59 | int height = size.y; | |
60 | ||
61 | m_windowStyle = style ; | |
62 | ||
63 | long groupStyle = 0; | |
64 | if (m_windowStyle & wxRB_GROUP) | |
65 | groupStyle = WS_GROUP; | |
66 | ||
67 | // long msStyle = groupStyle | RADIO_FLAGS; | |
68 | long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ; | |
69 | ||
70 | bool want3D; | |
71 | WXDWORD exStyle = Determine3DEffects(0, &want3D) ; | |
72 | ||
73 | // Even with extended styles, need to combine with WS_BORDER | |
74 | // for them to look right. | |
c085e333 | 75 | if ( want3D || wxStyleHasBorder(m_windowStyle) ) |
2bda0e17 KB |
76 | msStyle |= WS_BORDER; |
77 | ||
78 | m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const char *)label, | |
79 | msStyle,0,0,0,0, | |
80 | (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); | |
c085e333 VZ |
81 | |
82 | wxCHECK_MSG( m_hWnd, FALSE, "Failed to create radiobutton" ); | |
83 | ||
2bda0e17 KB |
84 | #if CTL3D |
85 | if (want3D) | |
86 | { | |
87 | Ctl3dSubclassCtl((HWND) m_hWnd); | |
c085e333 | 88 | m_useCtl3D = TRUE; |
2bda0e17 KB |
89 | } |
90 | #endif | |
91 | ||
92 | SetFont(* parent->GetFont()); | |
93 | ||
94 | // Subclass again for purposes of dialog editing mode | |
95 | SubclassWin((WXHWND)m_hWnd); | |
96 | ||
97 | // SetValue(value); | |
98 | ||
99 | // start GRW fix | |
100 | if (label != "") | |
101 | { | |
debe6624 | 102 | int label_width, label_height; |
2bda0e17 KB |
103 | GetTextExtent(label, &label_width, &label_height, NULL, NULL, GetFont()); |
104 | if (width < 0) | |
105 | width = (int)(label_width + RADIO_SIZE); | |
106 | if (height<0) | |
107 | { | |
108 | height = (int)(label_height); | |
109 | if (height < RADIO_SIZE) | |
110 | height = RADIO_SIZE; | |
111 | } | |
112 | } | |
113 | else | |
114 | { | |
115 | if (width < 0) | |
116 | width = RADIO_SIZE; | |
117 | if (height < 0) | |
118 | height = RADIO_SIZE; | |
119 | } | |
120 | // end GRW fix | |
121 | ||
122 | SetSize(x, y, width, height); | |
123 | ||
124 | return TRUE; | |
125 | } | |
126 | ||
127 | ||
128 | void wxRadioButton::SetLabel(const wxString& label) | |
129 | { | |
130 | SetWindowText((HWND) GetHWND(), (const char *)label); | |
131 | } | |
132 | ||
debe6624 | 133 | void wxRadioButton::SetValue(bool value) |
2bda0e17 KB |
134 | { |
135 | // Following necessary for Win32s, because Win32s translate BM_SETCHECK | |
136 | SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L); | |
137 | } | |
138 | ||
139 | // Get single selection, for single choice list items | |
140 | bool wxRadioButton::GetValue(void) const | |
141 | { | |
142 | return (SendMessage((HWND) GetHWND(), BM_SETCHECK, 0, 0L) != 0); | |
143 | } | |
144 | ||
debe6624 | 145 | WXHBRUSH wxRadioButton::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
c085e333 | 146 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 KB |
147 | { |
148 | #if CTL3D | |
149 | if ( m_useCtl3D ) | |
150 | { | |
151 | HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); | |
152 | return (WXHBRUSH) hbrush; | |
153 | } | |
154 | #endif | |
155 | ||
156 | if (GetParent()->GetTransparentBackground()) | |
157 | SetBkMode((HDC) pDC, TRANSPARENT); | |
158 | else | |
159 | SetBkMode((HDC) pDC, OPAQUE); | |
160 | ||
161 | ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); | |
162 | ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); | |
163 | ||
164 | wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); | |
165 | ||
166 | // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush | |
167 | // has a zero usage count. | |
168 | // backgroundBrush->RealizeResource(); | |
169 | return (WXHBRUSH) backgroundBrush->GetResourceHandle(); | |
170 | } | |
171 | ||
172 | void wxRadioButton::Command (wxCommandEvent & event) | |
173 | { | |
174 | SetValue ( (event.m_commandInt != 0) ); | |
175 | ProcessCommand (event); | |
176 | } | |
177 | ||
178 | ||
179 | // Not implemented | |
180 | #if 0 | |
debe6624 | 181 | bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id, |
c085e333 | 182 | const wxBitmap *bitmap, |
2bda0e17 | 183 | const wxPoint& pos, |
debe6624 | 184 | const wxSize& size, long style, |
2bda0e17 KB |
185 | const wxValidator& validator, |
186 | const wxString& name) | |
187 | { | |
188 | SetName(name); | |
189 | SetValidator(validator); | |
190 | ||
191 | if (parent) parent->AddChild(this); | |
fd71308f JS |
192 | SetBackgroundColour(parent->GetBackgroundColour()); |
193 | SetForegroundColour(parent->GetForegroundColour()); | |
2bda0e17 KB |
194 | |
195 | if ( id == -1 ) | |
c085e333 | 196 | m_windowId = (int)NewControlId(); |
2bda0e17 | 197 | else |
c085e333 | 198 | m_windowId = id; |
2bda0e17 KB |
199 | |
200 | int x = pos.x; | |
201 | int y = pos.y; | |
202 | int width = size.x; | |
203 | int height = size.y; | |
204 | m_windowStyle = style ; | |
205 | ||
206 | long groupStyle = 0; | |
207 | if (m_windowStyle & wxRB_GROUP) | |
208 | groupStyle = WS_GROUP; | |
209 | ||
210 | // long msStyle = groupStyle | RADIO_FLAGS; | |
211 | long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ; | |
212 | ||
213 | m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle", | |
214 | msStyle,0,0,0,0, | |
215 | (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); | |
c085e333 VZ |
216 | |
217 | wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE ); | |
218 | ||
2bda0e17 KB |
219 | #if CTL3D |
220 | if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS)) | |
221 | { | |
222 | Ctl3dSubclassCtl((HWND) GetHWND()); | |
c085e333 | 223 | m_useCtl3D = TRUE; |
2bda0e17 KB |
224 | } |
225 | #endif | |
226 | ||
227 | // Subclass again for purposes of dialog editing mode | |
228 | SubclassWin(GetHWND()); | |
229 | ||
230 | SetSize(x, y, width, height); | |
231 | ||
232 | return TRUE; | |
233 | } | |
234 | ||
235 | void wxBitmapRadioButton::SetLabel(const wxBitmap *bitmap) | |
236 | { | |
237 | } | |
238 | ||
debe6624 | 239 | void wxBitmapRadioButton::SetValue(bool value) |
2bda0e17 KB |
240 | { |
241 | // Following necessary for Win32s, because Win32s translate BM_SETCHECK | |
242 | SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L); | |
243 | } | |
244 | ||
245 | // Get single selection, for single choice list items | |
246 | bool wxBitmapRadioButton::GetValue(void) const | |
247 | { | |
248 | return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L); | |
249 | } | |
250 | ||
251 | #endif |