]> git.saurik.com Git - wxWidgets.git/blame - src/msw/radiobut.cpp
fix for red to blue mapping in toolbar buttons
[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
2bda0e17
KB
32IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
33// IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton)
2bda0e17 34
621793f4
JS
35bool wxRadioButton::MSWCommand(WXUINT param, WXWORD id)
36{
37 if (param == BN_CLICKED)
38 {
39 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId);
40 event.SetEventObject( this );
41 ProcessCommand(event);
42 return TRUE;
43 }
44 else return FALSE;
45}
46
debe6624 47bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
c085e333 48 const wxString& label,
2bda0e17 49 const wxPoint& pos,
debe6624 50 const wxSize& size, long style,
2bda0e17
KB
51 const wxValidator& validator,
52 const wxString& name)
53{
54 SetName(name);
11b6a93b 55#if wxUSE_VALIDATORS
2bda0e17 56 SetValidator(validator);
11b6a93b 57#endif // wxUSE_VALIDATORS
2bda0e17
KB
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 92
837e5743 93 m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label,
2bda0e17
KB
94 msStyle,0,0,0,0,
95 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
c085e333 96
223d09f6 97 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") );
c085e333 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
223d09f6 115 if (label != wxT(""))
2bda0e17 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{
837e5743 145 SetWindowText((HWND) GetHWND(), (const wxChar *)label);
2bda0e17
KB
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
2bda0e17
KB
160void wxRadioButton::Command (wxCommandEvent & event)
161{
162 SetValue ( (event.m_commandInt != 0) );
163 ProcessCommand (event);
164}
165
166
167// Not implemented
168#if 0
debe6624 169bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id,
c085e333 170 const wxBitmap *bitmap,
2bda0e17 171 const wxPoint& pos,
debe6624 172 const wxSize& size, long style,
2bda0e17
KB
173 const wxValidator& validator,
174 const wxString& name)
175{
176 SetName(name);
177 SetValidator(validator);
178
179 if (parent) parent->AddChild(this);
fd71308f
JS
180 SetBackgroundColour(parent->GetBackgroundColour());
181 SetForegroundColour(parent->GetForegroundColour());
2bda0e17
KB
182
183 if ( id == -1 )
c085e333 184 m_windowId = (int)NewControlId();
2bda0e17 185 else
c085e333 186 m_windowId = id;
2bda0e17
KB
187
188 int x = pos.x;
189 int y = pos.y;
190 int width = size.x;
191 int height = size.y;
192 m_windowStyle = style ;
193
194 long groupStyle = 0;
195 if (m_windowStyle & wxRB_GROUP)
196 groupStyle = WS_GROUP;
197
198// long msStyle = groupStyle | RADIO_FLAGS;
199 long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ;
200
201 m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle",
202 msStyle,0,0,0,0,
203 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
c085e333
VZ
204
205 wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE );
206
1f112209 207#if wxUSE_CTL3D
2bda0e17
KB
208 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
209 {
210 Ctl3dSubclassCtl((HWND) GetHWND());
c085e333 211 m_useCtl3D = TRUE;
2bda0e17
KB
212 }
213#endif
214
215 // Subclass again for purposes of dialog editing mode
216 SubclassWin(GetHWND());
217
218 SetSize(x, y, width, height);
219
220 return TRUE;
221}
222
223void wxBitmapRadioButton::SetLabel(const wxBitmap *bitmap)
224{
225}
226
debe6624 227void wxBitmapRadioButton::SetValue(bool value)
2bda0e17
KB
228{
229// Following necessary for Win32s, because Win32s translate BM_SETCHECK
230 SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L);
231}
232
233// Get single selection, for single choice list items
234bool wxBitmapRadioButton::GetValue(void) const
235{
236 return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L);
237}
238
239#endif