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