]>
Commit | Line | Data |
---|---|---|
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 | // | |
106 | // If the parent is a scrolled window the controls must | |
107 | // have this style or they will overlap the scrollbars | |
108 | // | |
109 | if (pParent) | |
110 | if (pParent->IsKindOf(CLASSINFO(wxScrolledWindow)) || | |
111 | pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow))) | |
112 | lSstyle |= WS_CLIPSIBLINGS; | |
113 | ||
114 | SPBCDATA vCtrlData; | |
115 | ||
116 | vCtrlData.cbSize = sizeof(SPBCDATA); | |
117 | vCtrlData.ulTextLimit = 10L; | |
118 | vCtrlData.lLowerLimit = 0L; | |
119 | vCtrlData.lUpperLimit = 100L; | |
120 | vCtrlData.idMasterSpb = vId; | |
121 | vCtrlData.pHWXCtlData = NULL; | |
122 | ||
123 | m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent) | |
124 | ,WC_SPINBUTTON | |
125 | ,(PSZ)NULL | |
126 | ,lSstyle | |
127 | ,0L, 0L, 0L, 0L | |
128 | ,GetWinHwnd(pParent) | |
129 | ,HWND_TOP | |
130 | ,(HMENU)vId | |
131 | ,(PVOID)&vCtrlData | |
132 | ,NULL | |
133 | ); | |
134 | if (m_hWnd == 0) | |
135 | { | |
136 | return FALSE; | |
137 | } | |
138 | if(pParent) | |
139 | pParent->AddChild((wxSpinButton *)this); | |
140 | ||
141 | ::WinQueryWindowPos(m_hWnd, &vSwp); | |
142 | SetXComp(vSwp.x); | |
143 | SetYComp(vSwp.y); | |
144 | SetFont(*wxSMALL_FONT); | |
145 | // | |
146 | // For OS/2 we want to hide the text portion so we can substitute an | |
147 | // independent text ctrl in its place. 10 device units does this | |
148 | // | |
149 | SetSize( nX | |
150 | ,nY | |
151 | ,10L | |
152 | ,nHeight | |
153 | ); | |
154 | wxAssociateWinWithHandle( m_hWnd | |
155 | ,(wxWindowOS2*)this | |
156 | ); | |
157 | ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this); | |
158 | fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc); | |
159 | return TRUE; | |
160 | } // end of wxSpinButton::Create | |
161 | ||
162 | wxSpinButton::~wxSpinButton() | |
163 | { | |
164 | } // end of wxSpinButton::~wxSpinButton | |
165 | ||
166 | // ---------------------------------------------------------------------------- | |
167 | // size calculation | |
168 | // ---------------------------------------------------------------------------- | |
169 | ||
170 | wxSize wxSpinButton::DoGetBestSize() const | |
171 | { | |
172 | // | |
173 | // OS/2 PM does not really have system metrics so we'll just set our best guess | |
174 | // Also we have no horizontal spin buttons. | |
175 | // | |
176 | return (wxSize(10,20)); | |
177 | } // end of wxSpinButton::DoGetBestSize | |
178 | ||
179 | // ---------------------------------------------------------------------------- | |
180 | // Attributes | |
181 | // ---------------------------------------------------------------------------- | |
182 | ||
183 | int wxSpinButton::GetValue() const | |
184 | { | |
185 | int nVal = 0; | |
186 | long lVal = 0L; | |
187 | char zVal[10]; | |
188 | ||
189 | ::WinSendMsg( GetHwnd() | |
190 | ,SPBM_QUERYVALUE | |
191 | ,MPFROMP(zVal) | |
192 | ,MPFROM2SHORT( (USHORT)10 | |
193 | ,SPBQ_UPDATEIFVALID | |
194 | ) | |
195 | ); | |
196 | lVal = atol(zVal); | |
197 | return ((int)lVal); | |
198 | } // end of wxSpinButton::GetValue | |
199 | ||
200 | bool wxSpinButton::OS2OnScroll( | |
201 | int nOrientation | |
202 | , WXWORD wParam | |
203 | , WXWORD wPos | |
204 | , WXHWND hControl | |
205 | ) | |
206 | { | |
207 | wxCHECK_MSG(hControl, FALSE, wxT("scrolling what?") ) | |
208 | ||
209 | wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK | |
210 | ,m_windowId | |
211 | ); | |
212 | int nVal = (int)wPos; // cast is important for negative values! | |
213 | ||
214 | vEvent.SetPosition(nVal); | |
215 | vEvent.SetEventObject(this); | |
216 | return(GetEventHandler()->ProcessEvent(vEvent)); | |
217 | } // end of wxSpinButton::OS2OnScroll | |
218 | ||
219 | bool wxSpinButton::OS2Command( | |
220 | WXUINT uCmd | |
221 | , WXWORD wId | |
222 | ) | |
223 | { | |
224 | return FALSE; | |
225 | } // end of wxSpinButton::OS2Command | |
226 | ||
227 | void wxSpinButton::SetRange( | |
228 | int nMinVal | |
229 | , int nMaxVal | |
230 | ) | |
231 | { | |
232 | m_min = nMinVal; | |
233 | m_max = nMaxVal; | |
234 | ||
235 | ::WinSendMsg( GetHwnd() | |
236 | ,SPBM_SETLIMITS | |
237 | ,MPFROMLONG(nMaxVal) | |
238 | ,MPFROMLONG(nMinVal) | |
239 | ); | |
240 | } // end of wxSpinButton::SetRange | |
241 | ||
242 | void wxSpinButton::SetValue( | |
243 | int nValue | |
244 | ) | |
245 | { | |
246 | ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0)); | |
247 | } // end of wxSpinButton::SetValue | |
248 | ||
249 | #endif //wxUSE_SPINBTN |