]> git.saurik.com Git - wxWidgets.git/blob - src/msw/radiobut.cpp
32bd65e9b82185328a727016e6e69ede5feb7f22
[wxWidgets.git] / src / msw / radiobut.cpp
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 #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
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
48 bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
49 const wxString& label,
50 const wxPoint& pos,
51 const wxSize& size, long style,
52 const wxValidator& validator,
53 const wxString& name)
54 {
55 SetName(name);
56 SetValidator(validator);
57
58 if (parent) parent->AddChild(this);
59
60 SetBackgroundColour(parent->GetBackgroundColour());
61 SetForegroundColour(parent->GetForegroundColour());
62
63 if ( id == -1 )
64 m_windowId = (int)NewControlId();
65 else
66 m_windowId = id;
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;
80 long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ;
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.
87 /*
88 if ( want3D || wxStyleHasBorder(m_windowStyle) )
89 msStyle |= WS_BORDER;
90 */
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);
95
96 wxCHECK_MSG( m_hWnd, FALSE, "Failed to create radiobutton" );
97
98 #if CTL3D
99 if (want3D)
100 {
101 Ctl3dSubclassCtl((HWND) m_hWnd);
102 m_useCtl3D = TRUE;
103 }
104 #endif
105
106 SetFont(parent->GetFont());
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 {
116 int label_width, label_height;
117 GetTextExtent(label, &label_width, &label_height, NULL, NULL, & GetFont());
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
147 void wxRadioButton::SetValue(bool value)
148 {
149 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
150 SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L);
151 }
152
153 // Get single selection, for single choice list items
154 bool wxRadioButton::GetValue(void) const
155 {
156 return (SendMessage((HWND) GetHWND(), BM_SETCHECK, 0, 0L) != 0);
157 }
158
159 WXHBRUSH wxRadioButton::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
160 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
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
195 bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id,
196 const wxBitmap *bitmap,
197 const wxPoint& pos,
198 const wxSize& size, long style,
199 const wxValidator& validator,
200 const wxString& name)
201 {
202 SetName(name);
203 SetValidator(validator);
204
205 if (parent) parent->AddChild(this);
206 SetBackgroundColour(parent->GetBackgroundColour());
207 SetForegroundColour(parent->GetForegroundColour());
208
209 if ( id == -1 )
210 m_windowId = (int)NewControlId();
211 else
212 m_windowId = id;
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);
230
231 wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE );
232
233 #if CTL3D
234 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
235 {
236 Ctl3dSubclassCtl((HWND) GetHWND());
237 m_useCtl3D = TRUE;
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
253 void wxBitmapRadioButton::SetValue(bool value)
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