Removal of previous wxValidtor code for wxOS2
[wxWidgets.git] / src / os2 / radiobut.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: radiobut.cpp
3 // Purpose: wxRadioButton
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/12/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include <stdio.h>
21 #include "wx/setup.h"
22 #include "wx/radiobut.h"
23 #include "wx/brush.h"
24 #endif
25
26 #include "wx/os2/private.h"
27
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
30 IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton)
31 #endif
32
33 bool wxRadioButton::OS2Command(WXUINT param, WXWORD id)
34 {
35 if (param == BN_CLICKED)
36 {
37 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId);
38 event.SetEventObject( this );
39 ProcessCommand(event);
40 return TRUE;
41 }
42 else return FALSE;
43 }
44
45 bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
46 const wxString& label,
47 const wxPoint& pos,
48 const wxSize& size, long style,
49 #if wxUSE_VALIDATORS
50 const wxValidator& validator,
51 #endif
52 const wxString& name)
53 {
54 SetName(name);
55 #if wxUSE_VALIDATORS
56 SetValidator(validator);
57 #endif
58
59 if (parent) parent->AddChild(this);
60
61 SetBackgroundColour(parent->GetBackgroundColour());
62 SetForegroundColour(parent->GetForegroundColour());
63
64 if ( id == -1 )
65 m_windowId = (int)NewControlId();
66 else
67 m_windowId = id;
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 // TODO create radiobutton
77 /*
78 long groupStyle = 0;
79 if (m_windowStyle & wxRB_GROUP)
80 groupStyle = WS_GROUP;
81
82 // long msStyle = groupStyle | RADIO_FLAGS;
83 long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE ;
84
85 bool want3D;
86 WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
87
88 m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label,
89 msStyle,0,0,0,0,
90 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
91
92 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") );
93
94
95 SetFont(parent->GetFont());
96
97 // Subclass again for purposes of dialog editing mode
98 SubclassWin((WXHWND)m_hWnd);
99
100 // SetValue(value);
101 */
102
103 // start GRW fix
104 if (label != wxT(""))
105 {
106 int label_width, label_height;
107 GetTextExtent(label, &label_width, &label_height, NULL, NULL, & this->GetFont());
108 if (width < 0)
109 width = (int)(label_width + RADIO_SIZE);
110 if (height<0)
111 {
112 height = (int)(label_height);
113 if (height < RADIO_SIZE)
114 height = RADIO_SIZE;
115 }
116 }
117 else
118 {
119 if (width < 0)
120 width = RADIO_SIZE;
121 if (height < 0)
122 height = RADIO_SIZE;
123 }
124 // end GRW fix
125
126 SetSize(x, y, width, height);
127 return FALSE;
128 }
129
130 void wxRadioButton::SetLabel(const wxString& label)
131 {
132 // TODO
133 }
134
135 void wxRadioButton::SetValue(bool value)
136 {
137 // TODO
138 }
139
140 // Get single selection, for single choice list items
141 bool wxRadioButton::GetValue() const
142 {
143 // TODO
144 return FALSE;
145 }
146
147 void wxRadioButton::Command (wxCommandEvent & event)
148 {
149 SetValue ( (event.m_commandInt != 0) );
150 ProcessCommand (event);
151 }
152
153 bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id,
154 const wxBitmap *bitmap,
155 const wxPoint& pos,
156 const wxSize& size, long style,
157 #if wxUSE_VALIDATORS
158 const wxValidator& validator,
159 #endif
160 const wxString& name)
161 {
162 SetName(name);
163 #if wxUSE_VALIDATORS
164 SetValidator(validator);
165 #endif
166
167 if (parent) parent->AddChild(this);
168 SetBackgroundColour(parent->GetBackgroundColour());
169 SetForegroundColour(parent->GetForegroundColour());
170
171 if ( id == -1 )
172 m_windowId = (int)NewControlId();
173 else
174 m_windowId = id;
175
176 int x = pos.x;
177 int y = pos.y;
178 int width = size.x;
179 int height = size.y;
180 m_windowStyle = style ;
181
182 long groupStyle = 0;
183 if (m_windowStyle & wxRB_GROUP)
184 groupStyle = WS_GROUP;
185
186 // TODO:
187 /*
188 // long msStyle = groupStyle | RADIO_FLAGS;
189 // long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ;
190
191 m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle",
192 msStyle,0,0,0,0,
193 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
194
195 wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE );
196
197 */
198 // Subclass again for purposes of dialog editing mode
199 SubclassWin(GetHWND());
200
201 SetSize(x, y, width, height);
202
203 return TRUE;
204 }
205
206 void wxBitmapRadioButton::SetLabel(const wxBitmap *bitmap)
207 {
208 }
209
210 void wxBitmapRadioButton::SetValue(bool value)
211 {
212 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
213 // SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L);
214 }
215
216 // Get single selection, for single choice list items
217 bool wxBitmapRadioButton::GetValue(void) const
218 {
219 // return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L);
220 return FALSE;
221 }
222