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