]> git.saurik.com Git - wxWidgets.git/blame - src/os2/spinbutt.cpp
PyCrust updates
[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;
d8a3f66c 64 SWP vSwp;
3c299c3a
DW
65
66 m_min = 0;
67 m_max = 100;
68 if (vId == -1)
69 m_windowId = NewControlId();
70 else
71 m_windowId = vId;
72 m_backgroundColour = pParent->GetBackgroundColour();
73 m_foregroundColour = pParent->GetForegroundColour();
74 SetName(rsName);
75 SetParent(pParent);
76 m_windowStyle = lStyle;
77
78 //
79 // Get the right size for the control
80 //
81 if (nWidth <= 0 || nHeight <= 0 )
82 {
83 wxSize vSize = DoGetBestSize();
0e320a79 84
3c299c3a
DW
85 if (nWidth <= 0 )
86 nWidth = vSize.x;
87 if (nHeight <= 0 )
88 nHeight = vSize.y;
89 }
90 if (nX < 0 )
91 nX = 0;
92 if (nY < 0 )
93 nY = 0;
94
95 long lSstyle = 0L;
96
97 lSstyle = WS_VISIBLE |
98 WS_TABSTOP |
99 SPBS_MASTER | // We use only single field spin buttons
100 SPBS_NUMERICONLY; // We default to numeric data
101
102 if (m_windowStyle & wxCLIP_SIBLINGS )
103 lSstyle |= WS_CLIPSIBLINGS;
104
105 SPBCDATA vCtrlData;
106
107 vCtrlData.cbSize = sizeof(SPBCDATA);
108 vCtrlData.ulTextLimit = 10L;
109 vCtrlData.lLowerLimit = 0L;
110 vCtrlData.lUpperLimit = 100L;
111 vCtrlData.idMasterSpb = vId;
112 vCtrlData.pHWXCtlData = NULL;
113
114 m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent)
115 ,WC_SPINBUTTON
116 ,(PSZ)NULL
117 ,lSstyle
118 ,0L, 0L, 0L, 0L
119 ,GetWinHwnd(pParent)
120 ,HWND_TOP
121 ,(HMENU)vId
122 ,(PVOID)&vCtrlData
123 ,NULL
124 );
125 if (m_hWnd == 0)
126 {
127 return FALSE;
128 }
129 if(pParent)
130 pParent->AddChild((wxSpinButton *)this);
131
d8a3f66c
DW
132 ::WinQueryWindowPos(m_hWnd, &vSwp);
133 SetXComp(vSwp.x);
134 SetYComp(vSwp.y);
3c299c3a
DW
135 SetFont(pParent->GetFont());
136 //
137 // For OS/2 we want to hide the text portion so we can substitute an
138 // independent text ctrl in its place. 10 device units does this
139 //
140 SetSize( nX
141 ,nY
142 ,10L
143 ,nHeight
144 );
145 wxAssociateWinWithHandle( m_hWnd
146 ,(wxWindowOS2*)this
147 );
148 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
149 fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc);
150 return TRUE;
151} // end of wxSpinButton::Create
0e320a79
DW
152
153wxSpinButton::~wxSpinButton()
154{
3c299c3a 155} // end of wxSpinButton::~wxSpinButton
0e320a79 156
409c9842
DW
157// ----------------------------------------------------------------------------
158// size calculation
159// ----------------------------------------------------------------------------
160
e78c4d50 161wxSize wxSpinButton::DoGetBestSize() const
409c9842 162{
3c299c3a
DW
163 //
164 // OS/2 PM does not really have system metrics so we'll just set our best guess
165 // Also we have no horizontal spin buttons.
166 //
167 return (wxSize(10,20));
168} // end of wxSpinButton::DoGetBestSize
409c9842
DW
169
170// ----------------------------------------------------------------------------
0e320a79 171// Attributes
409c9842 172// ----------------------------------------------------------------------------
0e320a79
DW
173
174int wxSpinButton::GetValue() const
175{
3c299c3a
DW
176 int nVal = 0;
177 long lVal = 0L;
178 char zVal[10];
179
180 ::WinSendMsg( GetHwnd()
181 ,SPBM_QUERYVALUE
182 ,MPFROMP(zVal)
183 ,MPFROM2SHORT( (USHORT)10
184 ,SPBQ_UPDATEIFVALID
185 )
186 );
187 lVal = atol(zVal);
188 return ((int)lVal);
189} // end of wxSpinButton::GetValue
190
191bool wxSpinButton::OS2OnScroll(
192 int nOrientation
193, WXWORD wParam
194, WXWORD wPos
195, WXHWND hControl
196)
0e320a79 197{
3c299c3a 198 wxCHECK_MSG(hControl, FALSE, wxT("scrolling what?") )
0e320a79 199
3c299c3a
DW
200 wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK
201 ,m_windowId
202 );
203 int nVal = (int)wPos; // cast is important for negative values!
409c9842 204
3c299c3a
DW
205 vEvent.SetPosition(nVal);
206 vEvent.SetEventObject(this);
207 return(GetEventHandler()->ProcessEvent(vEvent));
208} // end of wxSpinButton::OS2OnScroll
409c9842 209
3c299c3a
DW
210bool wxSpinButton::OS2Command(
211 WXUINT uCmd
212, WXWORD wId
213)
409c9842 214{
409c9842 215 return FALSE;
3c299c3a 216} // end of wxSpinButton::OS2Command
409c9842 217
3c299c3a
DW
218void wxSpinButton::SetRange(
219 int nMinVal
220, int nMaxVal
221)
0e320a79 222{
3c299c3a
DW
223 m_min = nMinVal;
224 m_max = nMaxVal;
225
226 ::WinSendMsg( GetHwnd()
227 ,SPBM_SETLIMITS
228 ,MPFROMLONG(nMaxVal)
229 ,MPFROMLONG(nMinVal)
230 );
231} // end of wxSpinButton::SetRange
232
233void wxSpinButton::SetValue(
234 int nValue
235)
236{
237 ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0));
238} // end of wxSpinButton::SetValue
0e320a79 239
7e99520b 240#endif //wxUSE_SPINBTN