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