]> git.saurik.com Git - wxWidgets.git/blob - src/msw/radiobut.cpp
Modified mouse ENTER/LEAVE events so that they also
[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 #include "wx/settings.h"
28 #include "wx/brush.h"
29 #endif
30
31 #include "wx/msw/private.h"
32
33 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
34 // IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton)
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 #if wxUSE_VALIDATORS
57 SetValidator(validator);
58 #endif // wxUSE_VALIDATORS
59
60 if (parent) parent->AddChild(this);
61
62 SetBackgroundColour(parent->GetBackgroundColour());
63 SetForegroundColour(parent->GetForegroundColour());
64
65 if ( id == -1 )
66 m_windowId = (int)NewControlId();
67 else
68 m_windowId = id;
69
70 int x = pos.x;
71 int y = pos.y;
72 int width = size.x;
73 int height = size.y;
74
75 m_windowStyle = style ;
76
77 long groupStyle = 0;
78 if (m_windowStyle & wxRB_GROUP)
79 groupStyle = WS_GROUP;
80
81 // long msStyle = groupStyle | RADIO_FLAGS;
82 long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE /* | WS_CLIPSIBLINGS */;
83
84 bool want3D;
85 WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
86
87 // Even with extended styles, need to combine with WS_BORDER
88 // for them to look right.
89 /*
90 if ( want3D || wxStyleHasBorder(m_windowStyle) )
91 msStyle |= WS_BORDER;
92 */
93
94 m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label,
95 msStyle,0,0,0,0,
96 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
97
98 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") );
99
100 #if wxUSE_CTL3D
101 if (want3D)
102 {
103 Ctl3dSubclassCtl((HWND) m_hWnd);
104 m_useCtl3D = TRUE;
105 }
106 #endif
107
108 SetFont(parent->GetFont());
109
110 // Subclass again for purposes of dialog editing mode
111 SubclassWin((WXHWND)m_hWnd);
112
113 // SetValue(value);
114
115 // start GRW fix
116 if (label != wxT(""))
117 {
118 int label_width, label_height;
119 GetTextExtent(label, &label_width, &label_height, NULL, NULL, & this->GetFont());
120 if (width < 0)
121 width = (int)(label_width + RADIO_SIZE);
122 if (height<0)
123 {
124 height = (int)(label_height);
125 if (height < RADIO_SIZE)
126 height = RADIO_SIZE;
127 }
128 }
129 else
130 {
131 if (width < 0)
132 width = RADIO_SIZE;
133 if (height < 0)
134 height = RADIO_SIZE;
135 }
136 // end GRW fix
137
138 SetSize(x, y, width, height);
139
140 return TRUE;
141 }
142
143
144 void wxRadioButton::SetLabel(const wxString& label)
145 {
146 SetWindowText((HWND) GetHWND(), (const wxChar *)label);
147 }
148
149 void wxRadioButton::SetValue(bool value)
150 {
151 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
152 SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L);
153 }
154
155 // Get single selection
156 bool wxRadioButton::GetValue(void) const
157 {
158 return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L) != 0);
159 }
160
161 void wxRadioButton::Command (wxCommandEvent & event)
162 {
163 SetValue ( (event.m_commandInt != 0) );
164 ProcessCommand (event);
165 }
166
167 WXHBRUSH wxRadioButton::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
168 WXUINT message,
169 WXWPARAM wParam,
170 WXLPARAM lParam)
171 {
172 #if wxUSE_CTL3D
173 if ( m_useCtl3D )
174 {
175 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
176 return (WXHBRUSH) hbrush;
177 }
178 #endif // wxUSE_CTL3D
179
180 HDC hdc = (HDC)pDC;
181 if (GetParent()->GetTransparentBackground())
182 SetBkMode(hdc, TRANSPARENT);
183 else
184 SetBkMode(hdc, OPAQUE);
185
186 wxColour colBack = GetBackgroundColour();
187
188 if (!IsEnabled())
189 colBack = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
190
191 ::SetBkColor(hdc, wxColourToRGB(colBack));
192 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
193
194 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
195
196 return (WXHBRUSH)brush->GetResourceHandle();
197 }
198
199 // Not implemented
200 #if 0
201 bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id,
202 const wxBitmap *bitmap,
203 const wxPoint& pos,
204 const wxSize& size, long style,
205 const wxValidator& validator,
206 const wxString& name)
207 {
208 SetName(name);
209 SetValidator(validator);
210
211 if (parent) parent->AddChild(this);
212 SetBackgroundColour(parent->GetBackgroundColour());
213 SetForegroundColour(parent->GetForegroundColour());
214
215 if ( id == -1 )
216 m_windowId = (int)NewControlId();
217 else
218 m_windowId = id;
219
220 int x = pos.x;
221 int y = pos.y;
222 int width = size.x;
223 int height = size.y;
224 m_windowStyle = style ;
225
226 long groupStyle = 0;
227 if (m_windowStyle & wxRB_GROUP)
228 groupStyle = WS_GROUP;
229
230 // long msStyle = groupStyle | RADIO_FLAGS;
231 long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ;
232
233 m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle",
234 msStyle,0,0,0,0,
235 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
236
237 wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE );
238
239 #if wxUSE_CTL3D
240 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
241 {
242 Ctl3dSubclassCtl((HWND) GetHWND());
243 m_useCtl3D = TRUE;
244 }
245 #endif
246
247 // Subclass again for purposes of dialog editing mode
248 SubclassWin(GetHWND());
249
250 SetSize(x, y, width, height);
251
252 return TRUE;
253 }
254
255 void wxBitmapRadioButton::SetLabel(const wxBitmap *bitmap)
256 {
257 }
258
259 void wxBitmapRadioButton::SetValue(bool value)
260 {
261 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
262 SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L);
263 }
264
265 // Get single selection, for single choice list items
266 bool wxBitmapRadioButton::GetValue(void) const
267 {
268 return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L);
269 }
270
271 #endif