]> git.saurik.com Git - wxWidgets.git/blame - src/os2/spinbutt.cpp
added IsSizeDeferred() (part of patch 1199639)
[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 //
6670f564
WS
170 wxSize best(24,20);
171 return best;
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
6670f564
WS
194bool wxSpinButton::OS2OnScroll( int WXUNUSED(nOrientation),
195 WXWORD WXUNUSED(wParam),
196 WXWORD wPos,
197 WXHWND hControl )
0e320a79 198{
6670f564 199 wxCHECK_MSG(hControl, false, wxT("scrolling what?") )
0e320a79 200
6670f564
WS
201 wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK, m_windowId );
202 int nVal = (int)wPos; // cast is important for negative values!
409c9842 203
3c299c3a
DW
204 vEvent.SetPosition(nVal);
205 vEvent.SetEventObject(this);
206 return(GetEventHandler()->ProcessEvent(vEvent));
207} // end of wxSpinButton::OS2OnScroll
409c9842 208
6670f564
WS
209bool wxSpinButton::OS2Command( WXUINT WXUNUSED(uCmd),
210 WXWORD WXUNUSED(wId) )
409c9842 211{
6670f564 212 return false;
3c299c3a 213} // end of wxSpinButton::OS2Command
409c9842 214
3c299c3a
DW
215void wxSpinButton::SetRange(
216 int nMinVal
217, int nMaxVal
218)
0e320a79 219{
3c299c3a
DW
220 m_min = nMinVal;
221 m_max = nMaxVal;
222
223 ::WinSendMsg( GetHwnd()
224 ,SPBM_SETLIMITS
225 ,MPFROMLONG(nMaxVal)
226 ,MPFROMLONG(nMinVal)
227 );
228} // end of wxSpinButton::SetRange
229
230void wxSpinButton::SetValue(
231 int nValue
232)
233{
234 ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0));
235} // end of wxSpinButton::SetValue
0e320a79 236
7e99520b 237#endif //wxUSE_SPINBTN