]> git.saurik.com Git - wxWidgets.git/blob - src/os2/spinctrl.cpp
Restored sane way of using BC++ linker
[wxWidgets.git] / src / os2 / spinctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/spinctrl.cpp
3 // Purpose: wxSpinCtrl class implementation for Win32
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16
17 #ifdef __GNUG__
18 #pragma implementation "spinctrlbase.h"
19 #pragma implementation "spinctrl.h"
20 #endif
21
22 // ----------------------------------------------------------------------------
23 // headers
24 // ----------------------------------------------------------------------------
25
26 // for compilers that support precompilation, includes "wx.h".
27 #include "wx/wxprec.h"
28
29
30 #ifndef WX_PRECOMP
31 #include "wx/wx.h"
32 #endif
33
34 #include "wx/spinctrl.h"
35 #include "wx/os2/private.h"
36
37 // ----------------------------------------------------------------------------
38 // macros
39 // ----------------------------------------------------------------------------
40
41 IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl, wxControl)
42
43 BEGIN_EVENT_TABLE(wxSpinCtrl, wxSpinButton)
44 EVT_SPIN(-1, wxSpinCtrl::OnSpinChange)
45 END_EVENT_TABLE()
46 // ----------------------------------------------------------------------------
47 // constants
48 // ----------------------------------------------------------------------------
49
50 // the margin between the up-down control and its buddy
51 static const int MARGIN_BETWEEN = 5;
52
53 // ============================================================================
54 // implementation
55 // ============================================================================
56
57 // ----------------------------------------------------------------------------
58 // construction
59 // ----------------------------------------------------------------------------
60
61 bool wxSpinCtrl::Create(wxWindow *parent,
62 wxWindowID id,
63 const wxString& value,
64 const wxPoint& pos,
65 const wxSize& size,
66 long style,
67 int min, int max, int initial,
68 const wxString& name)
69 {
70 // TODO:
71 /*
72 // before using DoGetBestSize(), have to set style to let the base class
73 // know whether this is a horizontal or vertical control (we're always
74 // vertical)
75 style |= wxSP_VERTICAL;
76 SetWindowStyle(style);
77
78 // calculate the sizes: the size given is the toal size for both controls
79 // and we need to fit them both in the given width (height is the same)
80 wxSize sizeText(size), sizeBtn(size);
81 sizeBtn.x = wxSpinButton::DoGetBestSize().x;
82 if ( sizeText.x <= 0 )
83 {
84 // DEFAULT_ITEM_WIDTH is the default width for the text control
85 sizeText.x = DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN + sizeBtn.x;
86 }
87
88 sizeText.x -= sizeBtn.x + MARGIN_BETWEEN;
89 if ( sizeText.x <= 0 )
90 {
91 wxLogDebug(_T("not enough space for wxSpinCtrl!"));
92 }
93
94 wxPoint posBtn(pos);
95 posBtn.x += sizeText.x + MARGIN_BETWEEN;
96
97 // create the spin button
98 if ( !wxSpinButton::Create(parent, id, posBtn, sizeBtn, style, name) )
99 {
100 return FALSE;
101 }
102
103 SetRange(min, max);
104 SetValue(initial);
105
106 // create the text window
107 m_hwndBuddy = (WXHWND)::CreateWindowEx
108 (
109 WS_EX_CLIENTEDGE, // sunken border
110 _T("EDIT"), // window class
111 NULL, // no window title
112 WS_CHILD | WS_BORDER, // style (will be shown later)
113 pos.x, pos.y, // position
114 0, 0, // size (will be set later)
115 GetHwndOf(parent), // parent
116 (HMENU)-1, // control id
117 wxGetInstance(), // app instance
118 NULL // unused client data
119 );
120
121 if ( !m_hwndBuddy )
122 {
123 wxLogLastError("CreateWindow(buddy text window)");
124
125 return FALSE;
126 }
127
128 // should have the same font as the other controls
129 SetFont(GetParent()->GetFont());
130
131 // set the size of the text window - can do it only now, because we
132 // couldn't call DoGetBestSize() before as font wasn't set
133 if ( sizeText.y <= 0 )
134 {
135 int cx, cy;
136 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
137
138 sizeText.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
139 }
140
141 DoMoveWindow(pos.x, pos.y,
142 sizeText.x + sizeBtn.x + MARGIN_BETWEEN, sizeText.y);
143
144 (void)::ShowWindow((HWND)m_hwndBuddy, SW_SHOW);
145
146 // associate the text window with the spin button
147 (void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0);
148
149 if ( !value.IsEmpty() )
150 {
151 SetValue(value);
152 }
153 */
154 return FALSE;
155 }
156
157 // ----------------------------------------------------------------------------
158 // wxTextCtrl-like methods
159 // ----------------------------------------------------------------------------
160
161 void wxSpinCtrl::SetValue(const wxString& text)
162 {
163 // TODO:
164 /*
165 if ( !::SetWindowText((HWND)m_hwndBuddy, text.c_str()) )
166 {
167 wxLogLastError("SetWindowText(buddy)");
168 }
169 */
170 }
171
172 int wxSpinCtrl::GetValue() const
173 {
174 wxString val = wxGetWindowText(m_hwndBuddy);
175
176 long n;
177 if ( (wxSscanf(val, wxT("%lu"), &n) != 1) )
178 n = INT_MIN;
179
180 return n;
181 }
182
183 // ----------------------------------------------------------------------------
184 // forward some methods to subcontrols
185 // ----------------------------------------------------------------------------
186
187 bool wxSpinCtrl::SetFont(const wxFont& font)
188 {
189 if ( !wxWindowBase::SetFont(font) )
190 {
191 // nothing to do
192 return FALSE;
193 }
194
195 WXHANDLE hFont = GetFont().GetResourceHandle();
196 // TODO:
197 /*
198 (void)::SendMessage((HWND)m_hwndBuddy, WM_SETFONT, (WPARAM)hFont, TRUE);
199 */
200 return TRUE;
201 }
202
203 bool wxSpinCtrl::Show(bool show)
204 {
205 if ( !wxControl::Show(show) )
206 {
207 return FALSE;
208 }
209
210 // TODO:
211 /*
212 ::ShowWindow((HWND)m_hwndBuddy, show ? SW_SHOW : SW_HIDE);
213 */
214 return TRUE;
215 }
216
217 bool wxSpinCtrl::Enable(bool enable)
218 {
219 if ( !wxControl::Enable(enable) )
220 {
221 return FALSE;
222 }
223
224 // TODO:
225 /*
226 ::EnableWindow((HWND)m_hwndBuddy, enable);
227 */
228 return TRUE;
229 }
230
231 // ----------------------------------------------------------------------------
232 // event processing
233 // ----------------------------------------------------------------------------
234
235 void wxSpinCtrl::OnSpinChange(wxSpinEvent& eventSpin)
236 {
237 wxCommandEvent event(wxEVT_COMMAND_SPINCTRL_UPDATED, GetId());
238 event.SetEventObject(this);
239 event.SetInt(eventSpin.GetPosition());
240
241 (void)GetEventHandler()->ProcessEvent(event);
242
243 if ( eventSpin.GetSkipped() )
244 {
245 event.Skip();
246 }
247 }
248
249 // ----------------------------------------------------------------------------
250 // size calculations
251 // ----------------------------------------------------------------------------
252
253 wxSize wxSpinCtrl::DoGetBestSize() const
254 {
255 wxSize sizeBtn = wxSpinButton::DoGetBestSize();
256 // TODO:
257 /*
258 sizeBtn.x += DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN;
259
260 int y;
261 wxGetCharSize(GetHWND(), NULL, &y, &GetFont());
262 y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(y);
263
264 if ( sizeBtn.y < y )
265 {
266 // make the text tall enough
267 sizeBtn.y = y;
268 }
269 */
270 return sizeBtn;
271 }
272
273 void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height)
274 {
275 int widthBtn = DoGetBestSize().x;
276 int widthText = width - widthBtn - MARGIN_BETWEEN;
277 if ( widthText <= 0 )
278 {
279 wxLogDebug(_T("not enough space for wxSpinCtrl!"));
280 }
281 // TODO:
282 /*
283 if ( !::MoveWindow((HWND)m_hwndBuddy, x, y, widthText, height, TRUE) )
284 {
285 wxLogLastError("MoveWindow(buddy)");
286 }
287
288 x += widthText + MARGIN_BETWEEN;
289 if ( !::MoveWindow(GetHwnd(), x, y, widthBtn, height, TRUE) )
290 {
291 wxLogLastError("MoveWindow");
292 }
293 */
294 }