]> git.saurik.com Git - wxWidgets.git/blame - src/os2/spinctrl.cpp
Rework IE virtual file system support to use new syntax. Remove now unused code for...
[wxWidgets.git] / src / os2 / spinctrl.cpp
CommitLineData
409c9842 1/////////////////////////////////////////////////////////////////////////////
9de10271 2// Name: src/os2/spinctrl.cpp
42782237 3// Purpose: wxSpinCtrl class implementation for OS/2
409c9842
DW
4// Author: David Webster
5// Modified by:
6// Created: 10/15/99
7// RCS-ID: $Id$
8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
409c9842
DW
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
409c9842
DW
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23
24#ifndef WX_PRECOMP
25 #include "wx/wx.h"
26#endif
27
312ebad4 28#if wxUSE_SPINCTRL
7e99520b 29
409c9842
DW
30#include "wx/spinctrl.h"
31#include "wx/os2/private.h"
32
33// ----------------------------------------------------------------------------
34// macros
35// ----------------------------------------------------------------------------
36
3c299c3a
DW
37extern void wxAssociateWinWithHandle( HWND hWnd
38 ,wxWindowOS2* pWin
39 );
40static WXFARPROC fnWndProcSpinCtrl = (WXFARPROC)NULL;
32334453 41wxArraySpins wxSpinCtrl::m_svAllSpins;
3c299c3a 42
3d62dcb6 43BEGIN_EVENT_TABLE(wxSpinCtrl, wxSpinButton)
6e348b12 44 EVT_CHAR(wxSpinCtrl::OnChar)
312ebad4 45 EVT_SPIN(wxID_ANY, wxSpinCtrl::OnSpinChange)
6e348b12 46 EVT_SET_FOCUS(wxSpinCtrl::OnSetFocus)
3d62dcb6 47END_EVENT_TABLE()
409c9842
DW
48// ----------------------------------------------------------------------------
49// constants
50// ----------------------------------------------------------------------------
51
52// the margin between the up-down control and its buddy
53static const int MARGIN_BETWEEN = 5;
54
55// ============================================================================
56// implementation
57// ============================================================================
3c299c3a
DW
58MRESULT EXPENTRY wxSpinCtrlWndProc(
59 HWND hWnd
60, UINT uMessage
61, MPARAM wParam
62, MPARAM lParam
63)
409c9842 64{
3c299c3a
DW
65 wxSpinCtrl* pSpin = (wxSpinCtrl *)::WinQueryWindowULong( hWnd
66 ,QWL_USER
67 );
9923c37d 68
3c299c3a
DW
69 //
70 // Forward some messages (the key ones only so far) to the spin ctrl
71 //
72 switch (uMessage )
3d62dcb6 73 {
3c299c3a
DW
74 case WM_CHAR:
75 pSpin->OS2WindowProc( uMessage
76 ,wParam
77 ,lParam
78 );
79
80 //
81 // The control may have been deleted at this point, so check.
82 //
83 if (!(::WinIsWindow(vHabmain, hWnd) && ((wxSpinCtrl *)::WinQueryWindowULong( hWnd
84 ,QWL_USER
85 )
86 ) == pSpin))
87 return 0;
88 break;
3d62dcb6 89
409c9842 90 }
3c299c3a
DW
91 return (fnWndProcSpinCtrl( hWnd
92 ,(ULONG)uMessage
93 ,(MPARAM)wParam
94 ,(MPARAM)lParam
95 )
96 );
97} // end of wxSpinCtrlWndProc
98
99wxSpinCtrl::~wxSpinCtrl()
100{
101 m_svAllSpins.Remove(this);
409c9842 102
3c299c3a
DW
103 // This removes spurious memory leak reporting
104 if (m_svAllSpins.GetCount() == 0)
105 m_svAllSpins.Clear();
106} // end of wxSpinCtrl::~wxSpinCtrl
409c9842 107
3c299c3a
DW
108// ----------------------------------------------------------------------------
109// construction
110// ----------------------------------------------------------------------------
111
6670f564
WS
112bool wxSpinCtrl::Create( wxWindow* pParent,
113 wxWindowID vId,
114 const wxString& WXUNUSED(rsValue),
115 const wxPoint& rPos,
116 const wxSize& rSize,
117 long lStyle,
118 int nMin,
119 int nMax,
120 int nInitial,
121 const wxString& rsName )
3c299c3a 122{
312ebad4 123 if (vId == wxID_ANY)
3c299c3a
DW
124 m_windowId = NewControlId();
125 else
126 m_windowId = vId;
adfe3164
SN
127 if (pParent)
128 {
129 m_backgroundColour = pParent->GetBackgroundColour();
130 m_foregroundColour = pParent->GetForegroundColour();
131 }
3c299c3a
DW
132 SetName(rsName);
133 SetParent(pParent);
134 m_windowStyle = lStyle;
135
9de10271 136 int lSstyle = 0L;
3c299c3a
DW
137
138 lSstyle = WS_VISIBLE |
139 WS_TABSTOP |
140 SPBS_MASTER | // We use only single field spin buttons
141 SPBS_NUMERICONLY; // We default to numeric data
142
143 if (m_windowStyle & wxCLIP_SIBLINGS )
144 lSstyle |= WS_CLIPSIBLINGS;
145
146 SPBCDATA vCtrlData;
147
148 vCtrlData.cbSize = sizeof(SPBCDATA);
149 vCtrlData.ulTextLimit = 10L;
150 vCtrlData.lLowerLimit = 0L;
151 vCtrlData.lUpperLimit = 100L;
152 vCtrlData.idMasterSpb = vId;
153 vCtrlData.pHWXCtlData = NULL;
154
155 m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent)
156 ,WC_SPINBUTTON
157 ,(PSZ)NULL
158 ,lSstyle
159 ,0L, 0L, 0L, 0L
160 ,GetWinHwnd(pParent)
161 ,HWND_TOP
162 ,(HMENU)vId
163 ,(PVOID)&vCtrlData
164 ,NULL
165 );
166 if (m_hWnd == 0)
409c9842 167 {
312ebad4 168 return false;
409c9842 169 }
3c299c3a
DW
170 m_hWndBuddy = m_hWnd; // One in the same for OS/2
171 if(pParent)
172 pParent->AddChild((wxSpinButton *)this);
61a028dc
SN
173
174 SetFont(*wxSMALL_FONT);
175 SetXComp(0);
176 SetYComp(0);
9de10271 177 SetSize( rPos.x, rPos.y, rSize.x, rSize.y );
3c299c3a
DW
178
179 SetRange(nMin, nMax);
180 SetValue(nInitial);
181
182 //
183 // For OS/2 we'll just set our handle into our long data
184 //
185 wxAssociateWinWithHandle( m_hWnd
186 ,(wxWindowOS2*)this
187 );
188 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
189 fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc);
190 m_svAllSpins.Add(this);
312ebad4 191 return true;
3c299c3a 192} // end of wxSpinCtrl::Create
409c9842 193
3c299c3a
DW
194wxSize wxSpinCtrl::DoGetBestSize() const
195{
196 wxSize vSizeBtn = wxSpinButton::DoGetBestSize();
197 int nHeight;
0d598bae 198 wxFont vFont = (wxFont)GetFont();
409c9842 199
3c299c3a 200 vSizeBtn.x += DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN;
409c9842 201
3c299c3a
DW
202 wxGetCharSize( GetHWND()
203 ,NULL
204 ,&nHeight
0d598bae 205 ,&vFont
3c299c3a 206 );
61a028dc 207 nHeight = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nHeight)+4;
3d62dcb6 208
3c299c3a 209 if (vSizeBtn.y < nHeight)
3d62dcb6 210 {
3c299c3a
DW
211 //
212 // Make the text tall enough
213 //
214 vSizeBtn.y = nHeight;
3d62dcb6 215 }
3c299c3a
DW
216 return vSizeBtn;
217} // end of wxSpinCtrl::DoGetBestSize
3d62dcb6 218
3c299c3a
DW
219void wxSpinCtrl::DoGetPosition(
220 int* pnX
221, int* pnY
222) const
223{
61a028dc 224 wxSpinButton::DoGetPosition( pnX,pnY );
3c299c3a
DW
225} // end of wxpinCtrl::DoGetPosition
226
227void wxSpinCtrl::DoGetSize(
228 int* pnWidth
229, int* pnHeight
230) const
231{
232 RECTL vSpinrect;
233
234 ::WinQueryWindowRect(GetHwnd(), &vSpinrect);
235
236 if (pnWidth)
237 *pnWidth = vSpinrect.xRight - vSpinrect.xLeft;
238 if (pnHeight)
239 *pnHeight = vSpinrect.yTop - vSpinrect.yBottom;
240} // end of wxSpinCtrl::DoGetSize
241
242void wxSpinCtrl::DoMoveWindow(
243 int nX
244, int nY
245, int nWidth
246, int nHeight
247)
248{
249 wxWindowOS2* pParent = (wxWindowOS2*)GetParent();
3d62dcb6 250
3c299c3a 251 if (pParent)
3d62dcb6 252 {
d8a3f66c
DW
253 int nOS2Height = GetOS2ParentHeight(pParent);
254
255 nY = nOS2Height - (nY + nHeight);
3d62dcb6 256 }
3c299c3a
DW
257 else
258 {
259 RECTL vRect;
3d62dcb6 260
3c299c3a
DW
261 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
262 nY = vRect.yTop - (nY + nHeight);
263 }
264 ::WinSetWindowPos( GetHwnd()
265 ,HWND_TOP
266 ,nX
267 ,nY
268 ,nWidth
269 ,nHeight
270 ,SWP_SIZE | SWP_MOVE | SWP_ZORDER | SWP_SHOW
271 );
272} // end of wxSpinCtrl::DoMoveWindow
273
274bool wxSpinCtrl::Enable(
275 bool bEnable
276)
3d62dcb6 277{
3c299c3a 278 if (!wxControl::Enable(bEnable))
3d62dcb6 279 {
312ebad4 280 return false;
3d62dcb6 281 }
3c299c3a 282 ::WinEnableWindow(GetHwnd(), bEnable);
312ebad4 283 return true;
3c299c3a 284} // end of wxSpinCtrl::Enable
3d62dcb6 285
3c299c3a
DW
286wxSpinCtrl* wxSpinCtrl::GetSpinForTextCtrl(
287 WXHWND hWndBuddy
288)
3d62dcb6 289{
3c299c3a
DW
290 wxSpinCtrl* pSpin = (wxSpinCtrl *)::WinQueryWindowULong( (HWND)hWndBuddy
291 ,QWL_USER
292 );
293 int i = m_svAllSpins.Index(pSpin);
3d62dcb6 294
3c299c3a
DW
295 if (i == wxNOT_FOUND)
296 return NULL;
3d62dcb6 297
3c299c3a
DW
298 // sanity check
299 wxASSERT_MSG( pSpin->m_hWndBuddy == hWndBuddy,
9a83f860 300 wxT("wxSpinCtrl has incorrect buddy HWND!") );
3d62dcb6 301
3c299c3a
DW
302 return pSpin;
303} // end of wxSpinCtrl::GetSpinForTextCtrl
3d62dcb6 304
3c299c3a 305int wxSpinCtrl::GetValue() const
3d62dcb6 306{
3c299c3a
DW
307 long lVal = 0L;
308 char zVal[10];
309
310 ::WinSendMsg( GetHwnd()
311 ,SPBM_QUERYVALUE
312 ,MPFROMP(zVal)
313 ,MPFROM2SHORT( (USHORT)10
314 ,SPBQ_UPDATEIFVALID
315 )
316 );
70a2c656
DW
317 lVal = atol(zVal);
318 return (int)lVal;
3c299c3a
DW
319} // end of wxSpinCtrl::GetValue
320
321void wxSpinCtrl::OnChar (
322 wxKeyEvent& rEvent
323)
324{
9923c37d 325 switch (rEvent.GetKeyCode())
3d62dcb6 326 {
3c299c3a
DW
327 case WXK_RETURN:
328 {
329 wxCommandEvent vEvent( wxEVT_COMMAND_TEXT_ENTER
330 ,m_windowId
331 );
332 wxString sVal = wxGetWindowText(m_hWndBuddy);
333
334 InitCommandEvent(vEvent);
0fba44b4 335 vEvent.SetString(sVal);
3c299c3a 336 vEvent.SetInt(GetValue());
937013e0 337 if (HandleWindowEvent(vEvent))
3c299c3a
DW
338 return;
339 break;
340 }
341
342 case WXK_TAB:
343 //
344 // Always produce navigation event - even if we process TAB
345 // ourselves the fact that we got here means that the user code
346 // decided to skip processing of this TAB - probably to let it
347 // do its default job.
348 //
349 {
350 wxNavigationKeyEvent vEventNav;
351
352 vEventNav.SetDirection(!rEvent.ShiftDown());
353 vEventNav.SetWindowChange(rEvent.ControlDown());
354 vEventNav.SetEventObject(this);
937013e0 355 if (GetParent()->HandleWindowEvent(vEventNav))
3c299c3a
DW
356 return;
357 }
358 break;
3d62dcb6
DW
359 }
360
3c299c3a
DW
361 //
362 // No, we didn't process it
363 //
364 rEvent.Skip();
365} // end of wxSpinCtrl::OnChar
3d62dcb6 366
3c299c3a
DW
367void wxSpinCtrl::OnSpinChange(
368 wxSpinEvent& rEventSpin
369)
3d62dcb6 370{
3c299c3a
DW
371 wxCommandEvent vEvent( wxEVT_COMMAND_SPINCTRL_UPDATED
372 ,GetId()
373 );
374
375 vEvent.SetEventObject(this);
376 vEvent.SetInt(rEventSpin.GetPosition());
937013e0 377 (void)HandleWindowEvent(vEvent);
3c299c3a 378 if (rEventSpin.GetSkipped())
3d62dcb6 379 {
3c299c3a 380 vEvent.Skip();
3d62dcb6 381 }
3c299c3a 382} // end of wxSpinCtrl::OnSpinChange
3d62dcb6 383
6e348b12
DW
384void wxSpinCtrl::OnSetFocus (
385 wxFocusEvent& rEvent
386)
387{
388 //
389 // When we get focus, give it to our buddy window as it needs it more than
390 // we do
391 //
392 ::WinSetFocus(HWND_DESKTOP, (HWND)m_hWndBuddy);
393 rEvent.Skip();
394} // end of wxSpinCtrl::OnSetFocus
395
6670f564
WS
396bool wxSpinCtrl::ProcessTextCommand( WXWORD wCmd,
397 WXWORD WXUNUSED(wId) )
3d62dcb6 398{
3c299c3a 399 switch (wCmd)
3d62dcb6 400 {
3c299c3a
DW
401 case SPBN_CHANGE:
402 {
6670f564 403 wxCommandEvent vEvent( wxEVT_COMMAND_TEXT_UPDATED, GetId() );
3c299c3a
DW
404 vEvent.SetEventObject(this);
405
6670f564 406 wxString sVal = wxGetWindowText(m_hWndBuddy);
3c299c3a 407
0fba44b4 408 vEvent.SetString(sVal);
3c299c3a 409 vEvent.SetInt(GetValue());
937013e0 410 return (HandleWindowEvent(vEvent));
3c299c3a
DW
411 }
412
413 case SPBN_SETFOCUS:
414 case SPBN_KILLFOCUS:
415 {
6670f564
WS
416 wxFocusEvent vEvent( wCmd == EN_KILLFOCUS ? wxEVT_KILL_FOCUS : wxEVT_SET_FOCUS
417 ,m_windowId
418 );
3c299c3a
DW
419
420 vEvent.SetEventObject(this);
937013e0 421 return(HandleWindowEvent(vEvent));
3c299c3a
DW
422 }
423 default:
424 break;
3d62dcb6
DW
425 }
426
3c299c3a
DW
427 //
428 // Not processed
429 //
312ebad4 430 return false;
3c299c3a 431} // end of wxSpinCtrl::ProcessTextCommand
3d62dcb6 432
3c299c3a 433void wxSpinCtrl::SetFocus()
3d62dcb6 434{
3c299c3a
DW
435 ::WinSetFocus(HWND_DESKTOP, GetHwnd());
436} // end of wxSpinCtrl::SetFocus
3d62dcb6 437
3c299c3a
DW
438bool wxSpinCtrl::SetFont(
439 const wxFont& rFont
440)
441{
442 if (!wxWindowBase::SetFont(rFont))
3d62dcb6 443 {
3c299c3a 444 // nothing to do
312ebad4 445 return false;
3d62dcb6 446 }
3d62dcb6 447
3c299c3a
DW
448 wxOS2SetFont( m_hWnd
449 ,rFont
450 );
312ebad4 451 return true;
3c299c3a 452} // end of wxSpinCtrl::SetFont
409c9842 453
3c299c3a
DW
454void wxSpinCtrl::SetValue(
455 const wxString& rsText
456)
3d62dcb6 457{
3c299c3a 458 long lVal;
3d62dcb6 459
a8988cb3 460 lVal = atol(rsText.c_str());
3c299c3a
DW
461 wxSpinButton::SetValue(lVal);
462} // end of wxSpinCtrl::SetValue
3d62dcb6 463
3c299c3a
DW
464bool wxSpinCtrl::Show(
465 bool bShow
466)
409c9842 467{
3c299c3a 468 if (!wxControl::Show(bShow))
409c9842 469 {
312ebad4 470 return false;
409c9842 471 }
312ebad4 472 return true;
3c299c3a 473} // end of wxSpinCtrl::Show
7e99520b 474
cfcebdb1
DW
475void wxSpinCtrl::SetSelection (
476 long lFrom
477, long lTo
478)
479{
480 //
77ffb593 481 // If from and to are both -1, it means (in wxWidgets) that all text should
cfcebdb1
DW
482 // be selected - translate into Windows convention
483 //
484 if ((lFrom == -1) && (lTo == -1))
485 {
486 lFrom = 0;
487 }
488 ::WinSendMsg(m_hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), (MPARAM)0);
489} // end of wxSpinCtrl::SetSelection
490
312ebad4 491#endif //wxUSE_SPINCTRL