]> git.saurik.com Git - wxWidgets.git/blame - src/msw/radiobut.cpp
Changed wxGridCellAttr::HasAlignment to treat values of -1 as no
[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 );
42 ProcessCommand(event);
43 return TRUE;
44 }
45 else return FALSE;
46}
47
debe6624 48bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
c085e333 49 const wxString& label,
2bda0e17 50 const wxPoint& pos,
debe6624 51 const wxSize& size, long style,
2bda0e17
KB
52 const wxValidator& validator,
53 const wxString& name)
54{
55 SetName(name);
11b6a93b 56#if wxUSE_VALIDATORS
2bda0e17 57 SetValidator(validator);
11b6a93b 58#endif // wxUSE_VALIDATORS
2bda0e17
KB
59
60 if (parent) parent->AddChild(this);
61
fd71308f
JS
62 SetBackgroundColour(parent->GetBackgroundColour());
63 SetForegroundColour(parent->GetForegroundColour());
2bda0e17
KB
64
65 if ( id == -1 )
c085e333 66 m_windowId = (int)NewControlId();
2bda0e17 67 else
c085e333 68 m_windowId = id;
2bda0e17
KB
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;
f6bcfd97 82 long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE /* | WS_CLIPSIBLINGS */;
2bda0e17
KB
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.
2faefb26 89/*
c085e333 90 if ( want3D || wxStyleHasBorder(m_windowStyle) )
2bda0e17 91 msStyle |= WS_BORDER;
2faefb26 92*/
2bda0e17 93
837e5743 94 m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label,
2bda0e17
KB
95 msStyle,0,0,0,0,
96 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
c085e333 97
223d09f6 98 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") );
c085e333 99
1f112209 100#if wxUSE_CTL3D
2bda0e17
KB
101 if (want3D)
102 {
103 Ctl3dSubclassCtl((HWND) m_hWnd);
c085e333 104 m_useCtl3D = TRUE;
2bda0e17
KB
105 }
106#endif
107
c0ed460c 108 SetFont(parent->GetFont());
2bda0e17
KB
109
110 // Subclass again for purposes of dialog editing mode
111 SubclassWin((WXHWND)m_hWnd);
112
113// SetValue(value);
114
115 // start GRW fix
223d09f6 116 if (label != wxT(""))
2bda0e17 117 {
debe6624 118 int label_width, label_height;
ce3ed50d 119 GetTextExtent(label, &label_width, &label_height, NULL, NULL, & this->GetFont());
2bda0e17
KB
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
144void wxRadioButton::SetLabel(const wxString& label)
145{
837e5743 146 SetWindowText((HWND) GetHWND(), (const wxChar *)label);
2bda0e17
KB
147}
148
debe6624 149void wxRadioButton::SetValue(bool value)
2bda0e17
KB
150{
151// Following necessary for Win32s, because Win32s translate BM_SETCHECK
152 SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L);
153}
154
72fd19a1 155// Get single selection
2bda0e17
KB
156bool wxRadioButton::GetValue(void) const
157{
72fd19a1 158 return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L) != 0);
2bda0e17
KB
159}
160
2bda0e17
KB
161void wxRadioButton::Command (wxCommandEvent & event)
162{
163 SetValue ( (event.m_commandInt != 0) );
164 ProcessCommand (event);
165}
166
f6bcfd97
BP
167WXHBRUSH 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}
2bda0e17
KB
198
199// Not implemented
200#if 0
debe6624 201bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id,
c085e333 202 const wxBitmap *bitmap,
2bda0e17 203 const wxPoint& pos,
debe6624 204 const wxSize& size, long style,
2bda0e17
KB
205 const wxValidator& validator,
206 const wxString& name)
207{
208 SetName(name);
209 SetValidator(validator);
210
211 if (parent) parent->AddChild(this);
fd71308f
JS
212 SetBackgroundColour(parent->GetBackgroundColour());
213 SetForegroundColour(parent->GetForegroundColour());
2bda0e17
KB
214
215 if ( id == -1 )
c085e333 216 m_windowId = (int)NewControlId();
2bda0e17 217 else
c085e333 218 m_windowId = id;
2bda0e17
KB
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);
c085e333
VZ
236
237 wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE );
238
1f112209 239#if wxUSE_CTL3D
2bda0e17
KB
240 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
241 {
242 Ctl3dSubclassCtl((HWND) GetHWND());
c085e333 243 m_useCtl3D = TRUE;
2bda0e17
KB
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
255void wxBitmapRadioButton::SetLabel(const wxBitmap *bitmap)
256{
257}
258
debe6624 259void wxBitmapRadioButton::SetValue(bool value)
2bda0e17
KB
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
266bool wxBitmapRadioButton::GetValue(void) const
267{
268 return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L);
269}
270
271#endif