]> git.saurik.com Git - wxWidgets.git/blob - src/os2/spinbutt.cpp
Inital fill in background, removed tabs, -1->wxID_ANY, TRUE->true, FALSE->false
[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 static WXFARPROC fnWndProcSpinCtrl = (WXFARPROC)NULL;
36
37 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
38
39 #include "wx/os2/private.h"
40
41 // ============================================================================
42 // implementation
43 // ============================================================================
44
45 // ----------------------------------------------------------------------------
46 // wxWin macros
47 // ----------------------------------------------------------------------------
48
49 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
50
51 bool wxSpinButton::Create(
52 wxWindow* pParent
53 , wxWindowID vId
54 , const wxPoint& rPos
55 , const wxSize& rSize
56 , long lStyle
57 , const wxString& rsName
58 )
59 {
60 int nX = rPos.x;
61 int nY = rPos.y;
62 int nWidth = rSize.x;
63 int nHeight = rSize.y;
64 SWP vSwp;
65
66 m_min = 0;
67 m_max = 100;
68 if (vId == -1)
69 m_windowId = NewControlId();
70 else
71 m_windowId = vId;
72 m_backgroundColour = pParent->GetBackgroundColour();
73 m_foregroundColour = pParent->GetForegroundColour();
74 SetName(rsName);
75 SetParent(pParent);
76 m_windowStyle = lStyle;
77
78 //
79 // Get the right size for the control
80 //
81 if (nWidth <= 0 || nHeight <= 0 )
82 {
83 wxSize vSize = DoGetBestSize();
84
85 if (nWidth <= 0 )
86 nWidth = vSize.x;
87 if (nHeight <= 0 )
88 nHeight = vSize.y;
89 }
90 if (nX < 0 )
91 nX = 0;
92 if (nY < 0 )
93 nY = 0;
94
95 long lSstyle = 0L;
96
97 lSstyle = WS_VISIBLE |
98 WS_TABSTOP |
99 SPBS_MASTER | // We use only single field spin buttons
100 SPBS_NUMERICONLY; // We default to numeric data
101
102 if (m_windowStyle & wxCLIP_SIBLINGS )
103 lSstyle |= WS_CLIPSIBLINGS;
104
105 m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent)
106 ,WC_SPINBUTTON
107 ,(PSZ)NULL
108 ,lSstyle
109 ,0L, 0L, 0L, 0L
110 ,GetWinHwnd(pParent)
111 ,HWND_TOP
112 ,(HMENU)vId
113 ,NULL
114 ,NULL
115 );
116 if (m_hWnd == 0)
117 {
118 return FALSE;
119 }
120 SetRange(m_min, m_max);
121 if(pParent)
122 pParent->AddChild((wxSpinButton *)this);
123
124 ::WinQueryWindowPos(m_hWnd, &vSwp);
125 SetXComp(vSwp.x);
126 SetYComp(vSwp.y);
127 wxFont* pTextFont = new wxFont( 10
128 ,wxMODERN
129 ,wxNORMAL
130 ,wxNORMAL
131 );
132 SetFont(*pTextFont);
133 //
134 // For OS/2 we want to hide the text portion so we can substitute an
135 // independent text ctrl in its place. 10 device units does this
136 //
137 SetSize( nX
138 ,nY
139 ,10L
140 ,nHeight
141 );
142 wxAssociateWinWithHandle( m_hWnd
143 ,(wxWindowOS2*)this
144 );
145 #if 0
146 // FIXME:
147 // Apparently, this does not work, as it crashes in setvalue/setrange calls
148 // What's it supposed to do anyway?
149 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
150 fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc);
151 #endif
152 delete pTextFont;
153 return TRUE;
154 } // end of wxSpinButton::Create
155
156 wxSpinButton::~wxSpinButton()
157 {
158 } // end of wxSpinButton::~wxSpinButton
159
160 // ----------------------------------------------------------------------------
161 // size calculation
162 // ----------------------------------------------------------------------------
163
164 wxSize wxSpinButton::DoGetBestSize() const
165 {
166 //
167 // OS/2 PM does not really have system metrics so we'll just set it to
168 // 24x20 which is the size of the buttons and the borders.
169 // Also we have no horizontal spin buttons.
170 //
171 return (wxSize(24,20));
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(
195 int nOrientation
196 , WXWORD wParam
197 , WXWORD wPos
198 , WXHWND hControl
199 )
200 {
201 wxCHECK_MSG(hControl, FALSE, wxT("scrolling what?") )
202
203 wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK
204 ,m_windowId
205 );
206 int nVal = (int)wPos; // cast is important for negative values!
207
208 vEvent.SetPosition(nVal);
209 vEvent.SetEventObject(this);
210 return(GetEventHandler()->ProcessEvent(vEvent));
211 } // end of wxSpinButton::OS2OnScroll
212
213 bool wxSpinButton::OS2Command(
214 WXUINT uCmd
215 , WXWORD wId
216 )
217 {
218 return FALSE;
219 } // end of wxSpinButton::OS2Command
220
221 void wxSpinButton::SetRange(
222 int nMinVal
223 , int nMaxVal
224 )
225 {
226 m_min = nMinVal;
227 m_max = nMaxVal;
228
229 ::WinSendMsg( GetHwnd()
230 ,SPBM_SETLIMITS
231 ,MPFROMLONG(nMaxVal)
232 ,MPFROMLONG(nMinVal)
233 );
234 } // end of wxSpinButton::SetRange
235
236 void wxSpinButton::SetValue(
237 int nValue
238 )
239 {
240 ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0));
241 } // end of wxSpinButton::SetValue
242
243 #endif //wxUSE_SPINBTN