]> git.saurik.com Git - wxWidgets.git/blame - src/msw/radiobut.cpp
better learn the operators...
[wxWidgets.git] / src / msw / radiobut.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
1e6feb95 2// Name: msw/radiobut.cpp
2bda0e17
KB
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__
1e6feb95 13 #pragma implementation "radiobut.h"
2bda0e17
KB
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
1e6feb95 20 #pragma hdrstop
2bda0e17
KB
21#endif
22
1e6feb95
VZ
23#if wxUSE_RADIOBTN
24
2bda0e17 25#ifndef WX_PRECOMP
1e6feb95
VZ
26 #include "wx/radiobut.h"
27 #include "wx/settings.h"
28 #include "wx/brush.h"
2bda0e17
KB
29#endif
30
31#include "wx/msw/private.h"
32
2bda0e17
KB
33IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
34// IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton)
2bda0e17 35
33ac7e6f 36bool wxRadioButton::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
621793f4
JS
37{
38 if (param == BN_CLICKED)
39 {
40 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId);
41 event.SetEventObject( this );
3ca6a5f0 42 event.SetInt( GetValue() );
621793f4
JS
43 ProcessCommand(event);
44 return TRUE;
45 }
46 else return FALSE;
47}
48
debe6624 49bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
c085e333 50 const wxString& label,
2bda0e17 51 const wxPoint& pos,
debe6624 52 const wxSize& size, long style,
2bda0e17
KB
53 const wxValidator& validator,
54 const wxString& name)
55{
56 SetName(name);
11b6a93b 57#if wxUSE_VALIDATORS
2bda0e17 58 SetValidator(validator);
11b6a93b 59#endif // wxUSE_VALIDATORS
2bda0e17
KB
60
61 if (parent) parent->AddChild(this);
62
fd71308f
JS
63 SetBackgroundColour(parent->GetBackgroundColour());
64 SetForegroundColour(parent->GetForegroundColour());
2bda0e17
KB
65
66 if ( id == -1 )
c085e333 67 m_windowId = (int)NewControlId();
2bda0e17 68 else
c085e333 69 m_windowId = id;
2bda0e17
KB
70
71 int x = pos.x;
72 int y = pos.y;
73 int width = size.x;
74 int height = size.y;
75
76 m_windowStyle = style ;
77
78 long groupStyle = 0;
79 if (m_windowStyle & wxRB_GROUP)
80 groupStyle = WS_GROUP;
81
82// long msStyle = groupStyle | RADIO_FLAGS;
f6bcfd97 83 long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE /* | WS_CLIPSIBLINGS */;
2bda0e17 84
b0766406
JS
85 if ( m_windowStyle & wxCLIP_SIBLINGS )
86 msStyle |= WS_CLIPSIBLINGS;
87
88
2bda0e17
KB
89 bool want3D;
90 WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
91
92 // Even with extended styles, need to combine with WS_BORDER
93 // for them to look right.
2faefb26 94/*
c085e333 95 if ( want3D || wxStyleHasBorder(m_windowStyle) )
2bda0e17 96 msStyle |= WS_BORDER;
2faefb26 97*/
2bda0e17 98
837e5743 99 m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label,
2bda0e17
KB
100 msStyle,0,0,0,0,
101 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
c085e333 102
223d09f6 103 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") );
c085e333 104
1f112209 105#if wxUSE_CTL3D
2bda0e17
KB
106 if (want3D)
107 {
108 Ctl3dSubclassCtl((HWND) m_hWnd);
c085e333 109 m_useCtl3D = TRUE;
2bda0e17
KB
110 }
111#endif
112
c0ed460c 113 SetFont(parent->GetFont());
2bda0e17
KB
114
115 // Subclass again for purposes of dialog editing mode
116 SubclassWin((WXHWND)m_hWnd);
117
118// SetValue(value);
119
120 // start GRW fix
223d09f6 121 if (label != wxT(""))
2bda0e17 122 {
debe6624 123 int label_width, label_height;
ce3ed50d 124 GetTextExtent(label, &label_width, &label_height, NULL, NULL, & this->GetFont());
2bda0e17
KB
125 if (width < 0)
126 width = (int)(label_width + RADIO_SIZE);
127 if (height<0)
128 {
129 height = (int)(label_height);
130 if (height < RADIO_SIZE)
131 height = RADIO_SIZE;
132 }
133 }
134 else
135 {
136 if (width < 0)
137 width = RADIO_SIZE;
138 if (height < 0)
139 height = RADIO_SIZE;
140 }
141 // end GRW fix
142
143 SetSize(x, y, width, height);
144
a9c317d2
VZ
145 // for compatibility with wxGTK, the first radio button in a group is
146 // always checked (this makes sense anyhow as you need to ensure that at
147 // least one button in the group is checked and this is the simlpest way to
148 // do it)
149 if ( m_windowStyle & wxRB_GROUP )
150 SetValue(TRUE);
151
2bda0e17
KB
152 return TRUE;
153}
154
155
156void wxRadioButton::SetLabel(const wxString& label)
157{
837e5743 158 SetWindowText((HWND) GetHWND(), (const wxChar *)label);
2bda0e17
KB
159}
160
debe6624 161void wxRadioButton::SetValue(bool value)
2bda0e17
KB
162{
163// Following necessary for Win32s, because Win32s translate BM_SETCHECK
164 SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L);
165}
166
72fd19a1 167// Get single selection
2bda0e17
KB
168bool wxRadioButton::GetValue(void) const
169{
72fd19a1 170 return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L) != 0);
2bda0e17
KB
171}
172
2bda0e17
KB
173void wxRadioButton::Command (wxCommandEvent & event)
174{
175 SetValue ( (event.m_commandInt != 0) );
176 ProcessCommand (event);
177}
178
33ac7e6f 179WXHBRUSH wxRadioButton::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
788722ac
JS
180#if wxUSE_CTL3D
181 WXUINT message,
182 WXWPARAM wParam,
183 WXLPARAM lParam
184#else
33ac7e6f
KB
185 WXUINT WXUNUSED(message),
186 WXWPARAM WXUNUSED(wParam),
788722ac
JS
187 WXLPARAM WXUNUSED(lParam)
188#endif
189 )
f6bcfd97
BP
190{
191#if wxUSE_CTL3D
192 if ( m_useCtl3D )
193 {
194 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
195 return (WXHBRUSH) hbrush;
196 }
197#endif // wxUSE_CTL3D
198
199 HDC hdc = (HDC)pDC;
200 if (GetParent()->GetTransparentBackground())
201 SetBkMode(hdc, TRANSPARENT);
202 else
203 SetBkMode(hdc, OPAQUE);
204
205 wxColour colBack = GetBackgroundColour();
206
207 if (!IsEnabled())
208 colBack = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
209
210 ::SetBkColor(hdc, wxColourToRGB(colBack));
211 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
212
213 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
214
215 return (WXHBRUSH)brush->GetResourceHandle();
216}
2bda0e17
KB
217
218// Not implemented
219#if 0
debe6624 220bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id,
c085e333 221 const wxBitmap *bitmap,
2bda0e17 222 const wxPoint& pos,
debe6624 223 const wxSize& size, long style,
2bda0e17
KB
224 const wxValidator& validator,
225 const wxString& name)
226{
227 SetName(name);
228 SetValidator(validator);
229
230 if (parent) parent->AddChild(this);
fd71308f
JS
231 SetBackgroundColour(parent->GetBackgroundColour());
232 SetForegroundColour(parent->GetForegroundColour());
2bda0e17
KB
233
234 if ( id == -1 )
c085e333 235 m_windowId = (int)NewControlId();
2bda0e17 236 else
c085e333 237 m_windowId = id;
2bda0e17
KB
238
239 int x = pos.x;
240 int y = pos.y;
241 int width = size.x;
242 int height = size.y;
243 m_windowStyle = style ;
244
245 long groupStyle = 0;
246 if (m_windowStyle & wxRB_GROUP)
247 groupStyle = WS_GROUP;
248
249// long msStyle = groupStyle | RADIO_FLAGS;
250 long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ;
251
252 m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle",
253 msStyle,0,0,0,0,
254 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
c085e333
VZ
255
256 wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE );
257
1f112209 258#if wxUSE_CTL3D
2bda0e17
KB
259 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
260 {
261 Ctl3dSubclassCtl((HWND) GetHWND());
c085e333 262 m_useCtl3D = TRUE;
2bda0e17
KB
263 }
264#endif
265
266 // Subclass again for purposes of dialog editing mode
267 SubclassWin(GetHWND());
268
269 SetSize(x, y, width, height);
270
271 return TRUE;
272}
273
274void wxBitmapRadioButton::SetLabel(const wxBitmap *bitmap)
275{
276}
277
debe6624 278void wxBitmapRadioButton::SetValue(bool value)
2bda0e17
KB
279{
280// Following necessary for Win32s, because Win32s translate BM_SETCHECK
281 SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L);
282}
283
284// Get single selection, for single choice list items
285bool wxBitmapRadioButton::GetValue(void) const
286{
287 return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L);
288}
289
290#endif
1e6feb95
VZ
291
292#endif // wxUSE_RADIOBTN