]> git.saurik.com Git - wxWidgets.git/blob - src/os2/spinbutt.cpp
Fixed duplicate symbol link error
[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 #ifdef __GNUG__
13 #pragma implementation "spinbutt.h"
14 #pragma implementation "spinbutbase.h"
15 #endif
16
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"
23 #endif
24 #if wxUSE_SPINBTN
25
26 // Can't resolve reference to CreateUpDownControl in
27 // TWIN32, but could probably use normal CreateWindow instead.
28
29
30 #include "wx/spinbutt.h"
31
32 extern void wxAssociateWinWithHandle( HWND hWnd
33 ,wxWindowOS2* pWin
34 );
35
36 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
37
38 #include "wx/os2/private.h"
39
40 // ============================================================================
41 // implementation
42 // ============================================================================
43
44 // ----------------------------------------------------------------------------
45 // wxWin macros
46 // ----------------------------------------------------------------------------
47
48 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
49
50 bool wxSpinButton::Create(
51 wxWindow* pParent
52 , wxWindowID vId
53 , const wxPoint& rPos
54 , const wxSize& rSize
55 , long lStyle
56 , const wxString& rsName
57 )
58 {
59 int nX = rPos.x;
60 int nY = rPos.y;
61 int nWidth = rSize.x;
62 int nHeight = rSize.y;
63 SWP vSwp;
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();
83
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
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
112 ,NULL
113 ,NULL
114 );
115 if (m_hWnd == 0)
116 {
117 return FALSE;
118 }
119 SetRange(m_min, m_max);
120 if(pParent)
121 pParent->AddChild((wxSpinButton *)this);
122
123 ::WinQueryWindowPos(m_hWnd, &vSwp);
124 SetXComp(vSwp.x);
125 SetYComp(vSwp.y);
126 wxFont* pTextFont = new wxFont( 10
127 ,wxMODERN
128 ,wxNORMAL
129 ,wxNORMAL
130 );
131 SetFont(*pTextFont);
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 );
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?
148 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
149 fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc);
150 #endif
151 delete pTextFont;
152 return TRUE;
153 } // end of wxSpinButton::Create
154
155 wxSpinButton::~wxSpinButton()
156 {
157 } // end of wxSpinButton::~wxSpinButton
158
159 // ----------------------------------------------------------------------------
160 // size calculation
161 // ----------------------------------------------------------------------------
162
163 wxSize wxSpinButton::DoGetBestSize() const
164 {
165 //
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.
168 // Also we have no horizontal spin buttons.
169 //
170 return (wxSize(24,20));
171 } // end of wxSpinButton::DoGetBestSize
172
173 // ----------------------------------------------------------------------------
174 // Attributes
175 // ----------------------------------------------------------------------------
176
177 int wxSpinButton::GetValue() const
178 {
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
193 bool wxSpinButton::OS2OnScroll(
194 int nOrientation
195 , WXWORD wParam
196 , WXWORD wPos
197 , WXHWND hControl
198 )
199 {
200 wxCHECK_MSG(hControl, FALSE, wxT("scrolling what?") )
201
202 wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK
203 ,m_windowId
204 );
205 int nVal = (int)wPos; // cast is important for negative values!
206
207 vEvent.SetPosition(nVal);
208 vEvent.SetEventObject(this);
209 return(GetEventHandler()->ProcessEvent(vEvent));
210 } // end of wxSpinButton::OS2OnScroll
211
212 bool wxSpinButton::OS2Command(
213 WXUINT uCmd
214 , WXWORD wId
215 )
216 {
217 return FALSE;
218 } // end of wxSpinButton::OS2Command
219
220 void wxSpinButton::SetRange(
221 int nMinVal
222 , int nMaxVal
223 )
224 {
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
235 void wxSpinButton::SetValue(
236 int nValue
237 )
238 {
239 ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0));
240 } // end of wxSpinButton::SetValue
241
242 #endif //wxUSE_SPINBTN