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