]> git.saurik.com Git - wxWidgets.git/blame - src/msw/radiobut.cpp
There was no icon file in this example, causing compilation with VC to fail. I just...
[wxWidgets.git] / src / msw / radiobut.cpp
CommitLineData
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"
f6bcfd97 27#include "wx/settings.h"
2432b92d 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
621793f4
JS
36bool 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 );
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
KB
84
85 bool want3D;
86 WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
87
88 // Even with extended styles, need to combine with WS_BORDER
89 // for them to look right.
2faefb26 90/*
c085e333 91 if ( want3D || wxStyleHasBorder(m_windowStyle) )
2bda0e17 92 msStyle |= WS_BORDER;
2faefb26 93*/
2bda0e17 94
837e5743 95 m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label,
2bda0e17
KB
96 msStyle,0,0,0,0,
97 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
c085e333 98
223d09f6 99 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") );
c085e333 100
1f112209 101#if wxUSE_CTL3D
2bda0e17
KB
102 if (want3D)
103 {
104 Ctl3dSubclassCtl((HWND) m_hWnd);
c085e333 105 m_useCtl3D = TRUE;
2bda0e17
KB
106 }
107#endif
108
c0ed460c 109 SetFont(parent->GetFont());
2bda0e17
KB
110
111 // Subclass again for purposes of dialog editing mode
112 SubclassWin((WXHWND)m_hWnd);
113
114// SetValue(value);
115
116 // start GRW fix
223d09f6 117 if (label != wxT(""))
2bda0e17 118 {
debe6624 119 int label_width, label_height;
ce3ed50d 120 GetTextExtent(label, &label_width, &label_height, NULL, NULL, & this->GetFont());
2bda0e17
KB
121 if (width < 0)
122 width = (int)(label_width + RADIO_SIZE);
123 if (height<0)
124 {
125 height = (int)(label_height);
126 if (height < RADIO_SIZE)
127 height = RADIO_SIZE;
128 }
129 }
130 else
131 {
132 if (width < 0)
133 width = RADIO_SIZE;
134 if (height < 0)
135 height = RADIO_SIZE;
136 }
137 // end GRW fix
138
139 SetSize(x, y, width, height);
140
a9c317d2
VZ
141 // for compatibility with wxGTK, the first radio button in a group is
142 // always checked (this makes sense anyhow as you need to ensure that at
143 // least one button in the group is checked and this is the simlpest way to
144 // do it)
145 if ( m_windowStyle & wxRB_GROUP )
146 SetValue(TRUE);
147
2bda0e17
KB
148 return TRUE;
149}
150
151
152void wxRadioButton::SetLabel(const wxString& label)
153{
837e5743 154 SetWindowText((HWND) GetHWND(), (const wxChar *)label);
2bda0e17
KB
155}
156
debe6624 157void wxRadioButton::SetValue(bool value)
2bda0e17
KB
158{
159// Following necessary for Win32s, because Win32s translate BM_SETCHECK
160 SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L);
161}
162
72fd19a1 163// Get single selection
2bda0e17
KB
164bool wxRadioButton::GetValue(void) const
165{
72fd19a1 166 return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L) != 0);
2bda0e17
KB
167}
168
2bda0e17
KB
169void wxRadioButton::Command (wxCommandEvent & event)
170{
171 SetValue ( (event.m_commandInt != 0) );
172 ProcessCommand (event);
173}
174
f6bcfd97
BP
175WXHBRUSH wxRadioButton::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
176 WXUINT message,
177 WXWPARAM wParam,
178 WXLPARAM lParam)
179{
180#if wxUSE_CTL3D
181 if ( m_useCtl3D )
182 {
183 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
184 return (WXHBRUSH) hbrush;
185 }
186#endif // wxUSE_CTL3D
187
188 HDC hdc = (HDC)pDC;
189 if (GetParent()->GetTransparentBackground())
190 SetBkMode(hdc, TRANSPARENT);
191 else
192 SetBkMode(hdc, OPAQUE);
193
194 wxColour colBack = GetBackgroundColour();
195
196 if (!IsEnabled())
197 colBack = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
198
199 ::SetBkColor(hdc, wxColourToRGB(colBack));
200 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
201
202 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
203
204 return (WXHBRUSH)brush->GetResourceHandle();
205}
2bda0e17
KB
206
207// Not implemented
208#if 0
debe6624 209bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id,
c085e333 210 const wxBitmap *bitmap,
2bda0e17 211 const wxPoint& pos,
debe6624 212 const wxSize& size, long style,
2bda0e17
KB
213 const wxValidator& validator,
214 const wxString& name)
215{
216 SetName(name);
217 SetValidator(validator);
218
219 if (parent) parent->AddChild(this);
fd71308f
JS
220 SetBackgroundColour(parent->GetBackgroundColour());
221 SetForegroundColour(parent->GetForegroundColour());
2bda0e17
KB
222
223 if ( id == -1 )
c085e333 224 m_windowId = (int)NewControlId();
2bda0e17 225 else
c085e333 226 m_windowId = id;
2bda0e17
KB
227
228 int x = pos.x;
229 int y = pos.y;
230 int width = size.x;
231 int height = size.y;
232 m_windowStyle = style ;
233
234 long groupStyle = 0;
235 if (m_windowStyle & wxRB_GROUP)
236 groupStyle = WS_GROUP;
237
238// long msStyle = groupStyle | RADIO_FLAGS;
239 long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ;
240
241 m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle",
242 msStyle,0,0,0,0,
243 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
c085e333
VZ
244
245 wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE );
246
1f112209 247#if wxUSE_CTL3D
2bda0e17
KB
248 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
249 {
250 Ctl3dSubclassCtl((HWND) GetHWND());
c085e333 251 m_useCtl3D = TRUE;
2bda0e17
KB
252 }
253#endif
254
255 // Subclass again for purposes of dialog editing mode
256 SubclassWin(GetHWND());
257
258 SetSize(x, y, width, height);
259
260 return TRUE;
261}
262
263void wxBitmapRadioButton::SetLabel(const wxBitmap *bitmap)
264{
265}
266
debe6624 267void wxBitmapRadioButton::SetValue(bool value)
2bda0e17
KB
268{
269// Following necessary for Win32s, because Win32s translate BM_SETCHECK
270 SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L);
271}
272
273// Get single selection, for single choice list items
274bool wxBitmapRadioButton::GetValue(void) const
275{
276 return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L);
277}
278
279#endif