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