]> git.saurik.com Git - wxWidgets.git/blob - src/os2/spinbutt.cpp
fixed problems with sometimes processing the events twice introduced in rev 1.170...
[wxWidgets.git] / src / os2 / spinbutt.cpp
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
27 extern void wxAssociateWinWithHandle( HWND hWnd
28 ,wxWindowOS2* pWin
29 );
30
31 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
32
33 #include "wx/os2/private.h"
34
35 // ============================================================================
36 // implementation
37 // ============================================================================
38
39 // ----------------------------------------------------------------------------
40 // wxWin macros
41 // ----------------------------------------------------------------------------
42
43 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
44
45 bool 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 m_backgroundColour = pParent->GetBackgroundColour();
67 m_foregroundColour = pParent->GetForegroundColour();
68 SetName(rsName);
69 SetParent(pParent);
70 m_windowStyle = lStyle;
71
72 //
73 // Get the right size for the control
74 //
75 if (nWidth <= 0 || nHeight <= 0 )
76 {
77 wxSize vSize = DoGetBestSize();
78
79 if (nWidth <= 0 )
80 nWidth = vSize.x;
81 if (nHeight <= 0 )
82 nHeight = vSize.y;
83 }
84 if (nX < 0 )
85 nX = 0;
86 if (nY < 0 )
87 nY = 0;
88
89 long lSstyle = 0L;
90
91 lSstyle = WS_VISIBLE |
92 WS_TABSTOP |
93 SPBS_MASTER | // We use only single field spin buttons
94 SPBS_NUMERICONLY; // We default to numeric data
95
96 if (m_windowStyle & wxCLIP_SIBLINGS )
97 lSstyle |= WS_CLIPSIBLINGS;
98
99 m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent)
100 ,WC_SPINBUTTON
101 ,(PSZ)NULL
102 ,lSstyle
103 ,0L, 0L, 0L, 0L
104 ,GetWinHwnd(pParent)
105 ,HWND_TOP
106 ,(HMENU)vId
107 ,NULL
108 ,NULL
109 );
110 if (m_hWnd == 0)
111 {
112 return FALSE;
113 }
114 SetRange(m_min, m_max);
115 if(pParent)
116 pParent->AddChild((wxSpinButton *)this);
117
118 ::WinQueryWindowPos(m_hWnd, &vSwp);
119 SetXComp(vSwp.x);
120 SetYComp(vSwp.y);
121 wxFont* pTextFont = new wxFont( 10
122 ,wxMODERN
123 ,wxNORMAL
124 ,wxNORMAL
125 );
126 SetFont(*pTextFont);
127 //
128 // For OS/2 we want to hide the text portion so we can substitute an
129 // independent text ctrl in its place. 10 device units does this
130 //
131 SetSize( nX
132 ,nY
133 ,10L
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 delete pTextFont;
147 return TRUE;
148 } // end of wxSpinButton::Create
149
150 wxSpinButton::~wxSpinButton()
151 {
152 } // end of wxSpinButton::~wxSpinButton
153
154 // ----------------------------------------------------------------------------
155 // size calculation
156 // ----------------------------------------------------------------------------
157
158 wxSize wxSpinButton::DoGetBestSize() const
159 {
160 //
161 // OS/2 PM does not really have system metrics so we'll just set it to
162 // 24x20 which is the size of the buttons and the borders.
163 // Also we have no horizontal spin buttons.
164 //
165 wxSize best(24,20);
166 return best;
167 } // end of wxSpinButton::DoGetBestSize
168
169 // ----------------------------------------------------------------------------
170 // Attributes
171 // ----------------------------------------------------------------------------
172
173 int wxSpinButton::GetValue() const
174 {
175 long lVal = 0L;
176 char zVal[10];
177
178 ::WinSendMsg( GetHwnd()
179 ,SPBM_QUERYVALUE
180 ,MPFROMP(zVal)
181 ,MPFROM2SHORT( (USHORT)10
182 ,SPBQ_UPDATEIFVALID
183 )
184 );
185 lVal = atol(zVal);
186 return ((int)lVal);
187 } // end of wxSpinButton::GetValue
188
189 bool wxSpinButton::OS2OnScroll( int WXUNUSED(nOrientation),
190 WXWORD WXUNUSED(wParam),
191 WXWORD wPos,
192 WXHWND hControl )
193 {
194 wxCHECK_MSG(hControl, false, wxT("scrolling what?") )
195
196 wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK, m_windowId );
197 int nVal = (int)wPos; // cast is important for negative values!
198
199 vEvent.SetPosition(nVal);
200 vEvent.SetEventObject(this);
201 return(GetEventHandler()->ProcessEvent(vEvent));
202 } // end of wxSpinButton::OS2OnScroll
203
204 bool wxSpinButton::OS2Command( WXUINT WXUNUSED(uCmd),
205 WXWORD WXUNUSED(wId) )
206 {
207 return false;
208 } // end of wxSpinButton::OS2Command
209
210 void wxSpinButton::SetRange(
211 int nMinVal
212 , int nMaxVal
213 )
214 {
215 m_min = nMinVal;
216 m_max = nMaxVal;
217
218 ::WinSendMsg( GetHwnd()
219 ,SPBM_SETLIMITS
220 ,MPFROMLONG(nMaxVal)
221 ,MPFROMLONG(nMinVal)
222 );
223 } // end of wxSpinButton::SetRange
224
225 void wxSpinButton::SetValue(
226 int nValue
227 )
228 {
229 ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0));
230 } // end of wxSpinButton::SetValue
231
232 #endif //wxUSE_SPINBTN