wxOS2 with Open Watcom: correct PCH usage, missing headers, warning fixes, source...
[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 wxSize best(24,20);
171 return best;
172 } // end of wxSpinButton::DoGetBestSize
173
174 // ----------------------------------------------------------------------------
175 // Attributes
176 // ----------------------------------------------------------------------------
177
178 int wxSpinButton::GetValue() const
179 {
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
194 bool wxSpinButton::OS2OnScroll( int WXUNUSED(nOrientation),
195 WXWORD WXUNUSED(wParam),
196 WXWORD wPos,
197 WXHWND hControl )
198 {
199 wxCHECK_MSG(hControl, false, wxT("scrolling what?") )
200
201 wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK, m_windowId );
202 int nVal = (int)wPos; // cast is important for negative values!
203
204 vEvent.SetPosition(nVal);
205 vEvent.SetEventObject(this);
206 return(GetEventHandler()->ProcessEvent(vEvent));
207 } // end of wxSpinButton::OS2OnScroll
208
209 bool wxSpinButton::OS2Command( WXUINT WXUNUSED(uCmd),
210 WXWORD WXUNUSED(wId) )
211 {
212 return false;
213 } // end of wxSpinButton::OS2Command
214
215 void wxSpinButton::SetRange(
216 int nMinVal
217 , int nMaxVal
218 )
219 {
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
230 void wxSpinButton::SetValue(
231 int nValue
232 )
233 {
234 ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0));
235 } // end of wxSpinButton::SetValue
236
237 #endif //wxUSE_SPINBTN