]> git.saurik.com Git - wxWidgets.git/blame - src/os2/spinbutt.cpp
Wrappers for *ToText
[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 8// Copyright: (c) David Webster
65571936 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
3c299c3a
DW
105 m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent)
106 ,WC_SPINBUTTON
107 ,(PSZ)NULL
108 ,lSstyle
109 ,0L, 0L, 0L, 0L
110 ,GetWinHwnd(pParent)
111 ,HWND_TOP
112 ,(HMENU)vId
8787320b 113 ,NULL
3c299c3a
DW
114 ,NULL
115 );
116 if (m_hWnd == 0)
117 {
118 return FALSE;
119 }
8787320b 120 SetRange(m_min, m_max);
3c299c3a
DW
121 if(pParent)
122 pParent->AddChild((wxSpinButton *)this);
123
d8a3f66c
DW
124 ::WinQueryWindowPos(m_hWnd, &vSwp);
125 SetXComp(vSwp.x);
126 SetYComp(vSwp.y);
b3260bce
DW
127 wxFont* pTextFont = new wxFont( 10
128 ,wxMODERN
129 ,wxNORMAL
130 ,wxNORMAL
131 );
132 SetFont(*pTextFont);
3c299c3a
DW
133 //
134 // For OS/2 we want to hide the text portion so we can substitute an
135 // independent text ctrl in its place. 10 device units does this
136 //
137 SetSize( nX
138 ,nY
139 ,10L
140 ,nHeight
141 );
142 wxAssociateWinWithHandle( m_hWnd
143 ,(wxWindowOS2*)this
144 );
8787320b
SN
145#if 0
146 // FIXME:
147 // Apparently, this does not work, as it crashes in setvalue/setrange calls
148 // What's it supposed to do anyway?
3c299c3a
DW
149 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
150 fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc);
8787320b 151#endif
b3260bce 152 delete pTextFont;
3c299c3a
DW
153 return TRUE;
154} // end of wxSpinButton::Create
0e320a79
DW
155
156wxSpinButton::~wxSpinButton()
157{
3c299c3a 158} // end of wxSpinButton::~wxSpinButton
0e320a79 159
409c9842
DW
160// ----------------------------------------------------------------------------
161// size calculation
162// ----------------------------------------------------------------------------
163
e78c4d50 164wxSize wxSpinButton::DoGetBestSize() const
409c9842 165{
3c299c3a 166 //
8787320b
SN
167 // OS/2 PM does not really have system metrics so we'll just set it to
168 // 24x20 which is the size of the buttons and the borders.
3c299c3a
DW
169 // Also we have no horizontal spin buttons.
170 //
8787320b 171 return (wxSize(24,20));
3c299c3a 172} // end of wxSpinButton::DoGetBestSize
409c9842
DW
173
174// ----------------------------------------------------------------------------
0e320a79 175// Attributes
409c9842 176// ----------------------------------------------------------------------------
0e320a79
DW
177
178int wxSpinButton::GetValue() const
179{
3c299c3a
DW
180 long lVal = 0L;
181 char zVal[10];
182
183 ::WinSendMsg( GetHwnd()
184 ,SPBM_QUERYVALUE
185 ,MPFROMP(zVal)
186 ,MPFROM2SHORT( (USHORT)10
187 ,SPBQ_UPDATEIFVALID
188 )
189 );
190 lVal = atol(zVal);
191 return ((int)lVal);
192} // end of wxSpinButton::GetValue
193
194bool wxSpinButton::OS2OnScroll(
195 int nOrientation
196, WXWORD wParam
197, WXWORD wPos
198, WXHWND hControl
199)
0e320a79 200{
3c299c3a 201 wxCHECK_MSG(hControl, FALSE, wxT("scrolling what?") )
0e320a79 202
3c299c3a
DW
203 wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK
204 ,m_windowId
205 );
206 int nVal = (int)wPos; // cast is important for negative values!
409c9842 207
3c299c3a
DW
208 vEvent.SetPosition(nVal);
209 vEvent.SetEventObject(this);
210 return(GetEventHandler()->ProcessEvent(vEvent));
211} // end of wxSpinButton::OS2OnScroll
409c9842 212
3c299c3a
DW
213bool wxSpinButton::OS2Command(
214 WXUINT uCmd
215, WXWORD wId
216)
409c9842 217{
409c9842 218 return FALSE;
3c299c3a 219} // end of wxSpinButton::OS2Command
409c9842 220
3c299c3a
DW
221void wxSpinButton::SetRange(
222 int nMinVal
223, int nMaxVal
224)
0e320a79 225{
3c299c3a
DW
226 m_min = nMinVal;
227 m_max = nMaxVal;
228
229 ::WinSendMsg( GetHwnd()
230 ,SPBM_SETLIMITS
231 ,MPFROMLONG(nMaxVal)
232 ,MPFROMLONG(nMinVal)
233 );
234} // end of wxSpinButton::SetRange
235
236void wxSpinButton::SetValue(
237 int nValue
238)
239{
240 ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0));
241} // end of wxSpinButton::SetValue
0e320a79 242
7e99520b 243#endif //wxUSE_SPINBTN