]> git.saurik.com Git - wxWidgets.git/blame - src/os2/spinbutt.cpp
Fixed duplicate symbol link error
[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 );
3c299c3a 35
3bfbab1e
SN
36IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
37
409c9842
DW
38#include "wx/os2/private.h"
39
40// ============================================================================
41// implementation
42// ============================================================================
43
44// ----------------------------------------------------------------------------
45// wxWin macros
46// ----------------------------------------------------------------------------
0e320a79 47
0e320a79 48IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
0e320a79 49
409c9842 50bool wxSpinButton::Create(
3c299c3a
DW
51 wxWindow* pParent
52, wxWindowID vId
53, const wxPoint& rPos
54, const wxSize& rSize
55, long lStyle
56, const wxString& rsName
409c9842 57)
0e320a79 58{
3c299c3a
DW
59 int nX = rPos.x;
60 int nY = rPos.y;
61 int nWidth = rSize.x;
62 int nHeight = rSize.y;
d8a3f66c 63 SWP vSwp;
3c299c3a
DW
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
3c299c3a
DW
104 m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent)
105 ,WC_SPINBUTTON
106 ,(PSZ)NULL
107 ,lSstyle
108 ,0L, 0L, 0L, 0L
109 ,GetWinHwnd(pParent)
110 ,HWND_TOP
111 ,(HMENU)vId
8787320b 112 ,NULL
3c299c3a
DW
113 ,NULL
114 );
115 if (m_hWnd == 0)
116 {
117 return FALSE;
118 }
8787320b 119 SetRange(m_min, m_max);
3c299c3a
DW
120 if(pParent)
121 pParent->AddChild((wxSpinButton *)this);
122
d8a3f66c
DW
123 ::WinQueryWindowPos(m_hWnd, &vSwp);
124 SetXComp(vSwp.x);
125 SetYComp(vSwp.y);
b3260bce
DW
126 wxFont* pTextFont = new wxFont( 10
127 ,wxMODERN
128 ,wxNORMAL
129 ,wxNORMAL
130 );
131 SetFont(*pTextFont);
3c299c3a
DW
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 );
8787320b
SN
144#if 0
145 // FIXME:
146 // Apparently, this does not work, as it crashes in setvalue/setrange calls
147 // What's it supposed to do anyway?
3c299c3a
DW
148 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
149 fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc);
8787320b 150#endif
b3260bce 151 delete pTextFont;
3c299c3a
DW
152 return TRUE;
153} // end of wxSpinButton::Create
0e320a79
DW
154
155wxSpinButton::~wxSpinButton()
156{
3c299c3a 157} // end of wxSpinButton::~wxSpinButton
0e320a79 158
409c9842
DW
159// ----------------------------------------------------------------------------
160// size calculation
161// ----------------------------------------------------------------------------
162
e78c4d50 163wxSize wxSpinButton::DoGetBestSize() const
409c9842 164{
3c299c3a 165 //
8787320b
SN
166 // OS/2 PM does not really have system metrics so we'll just set it to
167 // 24x20 which is the size of the buttons and the borders.
3c299c3a
DW
168 // Also we have no horizontal spin buttons.
169 //
8787320b 170 return (wxSize(24,20));
3c299c3a 171} // end of wxSpinButton::DoGetBestSize
409c9842
DW
172
173// ----------------------------------------------------------------------------
0e320a79 174// Attributes
409c9842 175// ----------------------------------------------------------------------------
0e320a79
DW
176
177int wxSpinButton::GetValue() const
178{
3c299c3a
DW
179 long lVal = 0L;
180 char zVal[10];
181
182 ::WinSendMsg( GetHwnd()
183 ,SPBM_QUERYVALUE
184 ,MPFROMP(zVal)
185 ,MPFROM2SHORT( (USHORT)10
186 ,SPBQ_UPDATEIFVALID
187 )
188 );
189 lVal = atol(zVal);
190 return ((int)lVal);
191} // end of wxSpinButton::GetValue
192
193bool wxSpinButton::OS2OnScroll(
194 int nOrientation
195, WXWORD wParam
196, WXWORD wPos
197, WXHWND hControl
198)
0e320a79 199{
3c299c3a 200 wxCHECK_MSG(hControl, FALSE, wxT("scrolling what?") )
0e320a79 201
3c299c3a
DW
202 wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK
203 ,m_windowId
204 );
205 int nVal = (int)wPos; // cast is important for negative values!
409c9842 206
3c299c3a
DW
207 vEvent.SetPosition(nVal);
208 vEvent.SetEventObject(this);
209 return(GetEventHandler()->ProcessEvent(vEvent));
210} // end of wxSpinButton::OS2OnScroll
409c9842 211
3c299c3a
DW
212bool wxSpinButton::OS2Command(
213 WXUINT uCmd
214, WXWORD wId
215)
409c9842 216{
409c9842 217 return FALSE;
3c299c3a 218} // end of wxSpinButton::OS2Command
409c9842 219
3c299c3a
DW
220void wxSpinButton::SetRange(
221 int nMinVal
222, int nMaxVal
223)
0e320a79 224{
3c299c3a
DW
225 m_min = nMinVal;
226 m_max = nMaxVal;
227
228 ::WinSendMsg( GetHwnd()
229 ,SPBM_SETLIMITS
230 ,MPFROMLONG(nMaxVal)
231 ,MPFROMLONG(nMinVal)
232 );
233} // end of wxSpinButton::SetRange
234
235void wxSpinButton::SetValue(
236 int nValue
237)
238{
239 ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0));
240} // end of wxSpinButton::SetValue
0e320a79 241
7e99520b 242#endif //wxUSE_SPINBTN