]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: spinbutt.cpp | |
3 | // Purpose: wxSpinButton | |
409c9842 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
409c9842 | 6 | // Created: 10/15/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
409c9842 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
1c85008f SN |
12 | #ifdef __GNUG__ |
13 | #pragma implementation "spinbutt.h" | |
14 | #pragma implementation "spinbutbase.h" | |
15 | #endif | |
16 | ||
409c9842 DW |
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" | |
0e320a79 | 23 | #endif |
7e99520b | 24 | #if wxUSE_SPINBTN |
0e320a79 | 25 | |
409c9842 DW |
26 | // Can't resolve reference to CreateUpDownControl in |
27 | // TWIN32, but could probably use normal CreateWindow instead. | |
28 | ||
29 | ||
0e320a79 | 30 | #include "wx/spinbutt.h" |
3bfbab1e | 31 | |
3c299c3a DW |
32 | extern void wxAssociateWinWithHandle( HWND hWnd |
33 | ,wxWindowOS2* pWin | |
34 | ); | |
35 | static WXFARPROC fnWndProcSpinCtrl = (WXFARPROC)NULL; | |
36 | ||
3bfbab1e SN |
37 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent) |
38 | ||
409c9842 DW |
39 | #include "wx/os2/private.h" |
40 | ||
41 | // ============================================================================ | |
42 | // implementation | |
43 | // ============================================================================ | |
44 | ||
45 | // ---------------------------------------------------------------------------- | |
46 | // wxWin macros | |
47 | // ---------------------------------------------------------------------------- | |
0e320a79 | 48 | |
0e320a79 | 49 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) |
0e320a79 | 50 | |
409c9842 | 51 | bool wxSpinButton::Create( |
3c299c3a DW |
52 | wxWindow* pParent |
53 | , wxWindowID vId | |
54 | , const wxPoint& rPos | |
55 | , const wxSize& rSize | |
56 | , long lStyle | |
57 | , const wxString& rsName | |
409c9842 | 58 | ) |
0e320a79 | 59 | { |
3c299c3a DW |
60 | int nX = rPos.x; |
61 | int nY = rPos.y; | |
62 | int nWidth = rSize.x; | |
63 | int nHeight = rSize.y; | |
d8a3f66c | 64 | SWP vSwp; |
3c299c3a DW |
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(); | |
0e320a79 | 84 | |
3c299c3a DW |
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 | ||
5d44b24e DW |
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 | ||
3c299c3a DW |
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 | ||
d8a3f66c DW |
141 | ::WinQueryWindowPos(m_hWnd, &vSwp); |
142 | SetXComp(vSwp.x); | |
143 | SetYComp(vSwp.y); | |
e58dab20 | 144 | SetFont(*wxSMALL_FONT); |
3c299c3a DW |
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 | |
0e320a79 DW |
161 | |
162 | wxSpinButton::~wxSpinButton() | |
163 | { | |
3c299c3a | 164 | } // end of wxSpinButton::~wxSpinButton |
0e320a79 | 165 | |
409c9842 DW |
166 | // ---------------------------------------------------------------------------- |
167 | // size calculation | |
168 | // ---------------------------------------------------------------------------- | |
169 | ||
e78c4d50 | 170 | wxSize wxSpinButton::DoGetBestSize() const |
409c9842 | 171 | { |
3c299c3a DW |
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 | |
409c9842 DW |
178 | |
179 | // ---------------------------------------------------------------------------- | |
0e320a79 | 180 | // Attributes |
409c9842 | 181 | // ---------------------------------------------------------------------------- |
0e320a79 DW |
182 | |
183 | int wxSpinButton::GetValue() const | |
184 | { | |
3c299c3a DW |
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 | ) | |
0e320a79 | 206 | { |
3c299c3a | 207 | wxCHECK_MSG(hControl, FALSE, wxT("scrolling what?") ) |
0e320a79 | 208 | |
3c299c3a DW |
209 | wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK |
210 | ,m_windowId | |
211 | ); | |
212 | int nVal = (int)wPos; // cast is important for negative values! | |
409c9842 | 213 | |
3c299c3a DW |
214 | vEvent.SetPosition(nVal); |
215 | vEvent.SetEventObject(this); | |
216 | return(GetEventHandler()->ProcessEvent(vEvent)); | |
217 | } // end of wxSpinButton::OS2OnScroll | |
409c9842 | 218 | |
3c299c3a DW |
219 | bool wxSpinButton::OS2Command( |
220 | WXUINT uCmd | |
221 | , WXWORD wId | |
222 | ) | |
409c9842 | 223 | { |
409c9842 | 224 | return FALSE; |
3c299c3a | 225 | } // end of wxSpinButton::OS2Command |
409c9842 | 226 | |
3c299c3a DW |
227 | void wxSpinButton::SetRange( |
228 | int nMinVal | |
229 | , int nMaxVal | |
230 | ) | |
0e320a79 | 231 | { |
3c299c3a DW |
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 | |
0e320a79 | 248 | |
7e99520b | 249 | #endif //wxUSE_SPINBTN |