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