]> git.saurik.com Git - wxWidgets.git/blob - src/msw/radiobut.cpp
Removed rogue AIAI icon; removed PostScript files from Cygwin makefile
[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 /*
76 if ( want3D || wxStyleHasBorder(m_windowStyle) )
77 msStyle |= WS_BORDER;
78 */
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);
83
84 wxCHECK_MSG( m_hWnd, FALSE, "Failed to create radiobutton" );
85
86 #if CTL3D
87 if (want3D)
88 {
89 Ctl3dSubclassCtl((HWND) m_hWnd);
90 m_useCtl3D = TRUE;
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 {
104 int label_width, label_height;
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
130 void wxRadioButton::SetLabel(const wxString& label)
131 {
132 SetWindowText((HWND) GetHWND(), (const char *)label);
133 }
134
135 void wxRadioButton::SetValue(bool value)
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
142 bool wxRadioButton::GetValue(void) const
143 {
144 return (SendMessage((HWND) GetHWND(), BM_SETCHECK, 0, 0L) != 0);
145 }
146
147 WXHBRUSH wxRadioButton::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
148 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
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
174 void wxRadioButton::Command (wxCommandEvent & event)
175 {
176 SetValue ( (event.m_commandInt != 0) );
177 ProcessCommand (event);
178 }
179
180
181 // Not implemented
182 #if 0
183 bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id,
184 const wxBitmap *bitmap,
185 const wxPoint& pos,
186 const wxSize& size, long style,
187 const wxValidator& validator,
188 const wxString& name)
189 {
190 SetName(name);
191 SetValidator(validator);
192
193 if (parent) parent->AddChild(this);
194 SetBackgroundColour(parent->GetBackgroundColour());
195 SetForegroundColour(parent->GetForegroundColour());
196
197 if ( id == -1 )
198 m_windowId = (int)NewControlId();
199 else
200 m_windowId = id;
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);
218
219 wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE );
220
221 #if CTL3D
222 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
223 {
224 Ctl3dSubclassCtl((HWND) GetHWND());
225 m_useCtl3D = TRUE;
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
237 void wxBitmapRadioButton::SetLabel(const wxBitmap *bitmap)
238 {
239 }
240
241 void wxBitmapRadioButton::SetValue(bool value)
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
248 bool wxBitmapRadioButton::GetValue(void) const
249 {
250 return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L);
251 }
252
253 #endif