]> git.saurik.com Git - wxWidgets.git/blame - src/os2/spinbutt.cpp
Add virtual ~wxAnyScrollHelperBase() to fix compiler warning.
[wxWidgets.git] / src / os2 / spinbutt.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/os2/spinbutt.cpp
0e320a79 3// Purpose: wxSpinButton
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
409c9842 6// Created: 10/15/99
409c9842 7// Copyright: (c) David Webster
65571936 8// Licence: wxWindows licence
0e320a79
DW
9/////////////////////////////////////////////////////////////////////////////
10
409c9842
DW
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14
15#ifndef WX_PRECOMP
16 #include "wx/wx.h"
0e320a79 17#endif
7e99520b 18#if wxUSE_SPINBTN
0e320a79 19
409c9842
DW
20// Can't resolve reference to CreateUpDownControl in
21// TWIN32, but could probably use normal CreateWindow instead.
22
23
0e320a79 24#include "wx/spinbutt.h"
3bfbab1e 25
3c299c3a
DW
26extern void wxAssociateWinWithHandle( HWND hWnd
27 ,wxWindowOS2* pWin
28 );
3c299c3a 29
409c9842
DW
30#include "wx/os2/private.h"
31
32// ============================================================================
33// implementation
34// ============================================================================
35
36// ----------------------------------------------------------------------------
37// wxWin macros
38// ----------------------------------------------------------------------------
0e320a79 39
409c9842 40bool wxSpinButton::Create(
3c299c3a
DW
41 wxWindow* pParent
42, wxWindowID vId
43, const wxPoint& rPos
44, const wxSize& rSize
45, long lStyle
46, const wxString& rsName
409c9842 47)
0e320a79 48{
3c299c3a
DW
49 int nX = rPos.x;
50 int nY = rPos.y;
51 int nWidth = rSize.x;
52 int nHeight = rSize.y;
d8a3f66c 53 SWP vSwp;
3c299c3a
DW
54
55 m_min = 0;
56 m_max = 100;
57 if (vId == -1)
58 m_windowId = NewControlId();
59 else
60 m_windowId = vId;
adfe3164
SN
61 if (pParent)
62 {
63 m_backgroundColour = pParent->GetBackgroundColour();
64 m_foregroundColour = pParent->GetForegroundColour();
65 }
3c299c3a
DW
66 SetName(rsName);
67 SetParent(pParent);
68 m_windowStyle = lStyle;
69
70 //
71 // Get the right size for the control
72 //
73 if (nWidth <= 0 || nHeight <= 0 )
74 {
75 wxSize vSize = DoGetBestSize();
0e320a79 76
3c299c3a
DW
77 if (nWidth <= 0 )
78 nWidth = vSize.x;
79 if (nHeight <= 0 )
80 nHeight = vSize.y;
81 }
82 if (nX < 0 )
83 nX = 0;
84 if (nY < 0 )
85 nY = 0;
86
bdc43642
VZ
87 long lSstyle = WS_VISIBLE |
88 WS_TABSTOP |
89 SPBS_MASTER | // We use only single field spin buttons
90 SPBS_NUMERICONLY; // We default to numeric data
3c299c3a
DW
91
92 if (m_windowStyle & wxCLIP_SIBLINGS )
93 lSstyle |= WS_CLIPSIBLINGS;
94
3c299c3a
DW
95 m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent)
96 ,WC_SPINBUTTON
97 ,(PSZ)NULL
98 ,lSstyle
99 ,0L, 0L, 0L, 0L
100 ,GetWinHwnd(pParent)
101 ,HWND_TOP
102 ,(HMENU)vId
8787320b 103 ,NULL
3c299c3a
DW
104 ,NULL
105 );
106 if (m_hWnd == 0)
107 {
108 return FALSE;
109 }
8787320b 110 SetRange(m_min, m_max);
3c299c3a
DW
111 if(pParent)
112 pParent->AddChild((wxSpinButton *)this);
113
d8a3f66c
DW
114 ::WinQueryWindowPos(m_hWnd, &vSwp);
115 SetXComp(vSwp.x);
22c68581 116 SetYComp(vSwp.y-5); // compensate for the associated TextControl border
61a028dc
SN
117
118 SetFont(*wxSMALL_FONT);
3c299c3a
DW
119 //
120 // For OS/2 we want to hide the text portion so we can substitute an
22c68581
SN
121 // independent text ctrl in its place.
122 // Therefore we must override any user given width with our best guess.
3c299c3a 123 //
22c68581
SN
124 SetSize( nX - GetXComp()
125 ,nY - GetYComp()
126 ,nWidth
3c299c3a
DW
127 ,nHeight
128 );
129 wxAssociateWinWithHandle( m_hWnd
130 ,(wxWindowOS2*)this
131 );
8787320b
SN
132#if 0
133 // FIXME:
134 // Apparently, this does not work, as it crashes in setvalue/setrange calls
135 // What's it supposed to do anyway?
3c299c3a
DW
136 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
137 fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc);
8787320b 138#endif
3c299c3a
DW
139 return TRUE;
140} // end of wxSpinButton::Create
0e320a79
DW
141
142wxSpinButton::~wxSpinButton()
143{
3c299c3a 144} // end of wxSpinButton::~wxSpinButton
0e320a79 145
409c9842
DW
146// ----------------------------------------------------------------------------
147// size calculation
148// ----------------------------------------------------------------------------
149
e78c4d50 150wxSize wxSpinButton::DoGetBestSize() const
409c9842 151{
3c299c3a 152 //
61a028dc
SN
153 // OS/2 PM does not really have system metrics so we'll just set it to
154 // a square based on its height.
3c299c3a 155 //
61a028dc
SN
156 RECTL vRect;
157 ::WinQueryWindowRect(GetHwnd(),&vRect);
158 return wxSize(vRect.yTop,vRect.yTop);
3c299c3a 159} // end of wxSpinButton::DoGetBestSize
409c9842
DW
160
161// ----------------------------------------------------------------------------
0e320a79 162// Attributes
409c9842 163// ----------------------------------------------------------------------------
0e320a79
DW
164
165int wxSpinButton::GetValue() const
166{
3c299c3a
DW
167 long lVal = 0L;
168 char zVal[10];
169
170 ::WinSendMsg( GetHwnd()
171 ,SPBM_QUERYVALUE
172 ,MPFROMP(zVal)
173 ,MPFROM2SHORT( (USHORT)10
174 ,SPBQ_UPDATEIFVALID
175 )
176 );
177 lVal = atol(zVal);
178 return ((int)lVal);
179} // end of wxSpinButton::GetValue
180
6670f564
WS
181bool wxSpinButton::OS2OnScroll( int WXUNUSED(nOrientation),
182 WXWORD WXUNUSED(wParam),
183 WXWORD wPos,
184 WXHWND hControl )
0e320a79 185{
637b7e4f 186 wxCHECK_MSG(hControl, false, wxT("scrolling what?") );
0e320a79 187
6670f564
WS
188 wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK, m_windowId );
189 int nVal = (int)wPos; // cast is important for negative values!
409c9842 190
3c299c3a
DW
191 vEvent.SetPosition(nVal);
192 vEvent.SetEventObject(this);
937013e0 193 return(HandleWindowEvent(vEvent));
3c299c3a 194} // end of wxSpinButton::OS2OnScroll
409c9842 195
6670f564
WS
196bool wxSpinButton::OS2Command( WXUINT WXUNUSED(uCmd),
197 WXWORD WXUNUSED(wId) )
409c9842 198{
6670f564 199 return false;
3c299c3a 200} // end of wxSpinButton::OS2Command
409c9842 201
3c299c3a
DW
202void wxSpinButton::SetRange(
203 int nMinVal
204, int nMaxVal
205)
0e320a79 206{
3c299c3a
DW
207 m_min = nMinVal;
208 m_max = nMaxVal;
209
210 ::WinSendMsg( GetHwnd()
211 ,SPBM_SETLIMITS
212 ,MPFROMLONG(nMaxVal)
213 ,MPFROMLONG(nMinVal)
214 );
215} // end of wxSpinButton::SetRange
216
217void wxSpinButton::SetValue(
218 int nValue
219)
220{
221 ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0));
222} // end of wxSpinButton::SetValue
0e320a79 223
7e99520b 224#endif //wxUSE_SPINBTN