]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: msw/spinbutt.cpp | |
3 | // Purpose: wxSpinButton | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
21 | #pragma implementation "spinbutt.h" | |
22 | #pragma implementation "spinbutbase.h" | |
23 | #endif | |
24 | ||
25 | // For compilers that support precompilation, includes "wx.h". | |
26 | #include "wx/wxprec.h" | |
27 | ||
28 | #ifdef __BORLANDC__ | |
29 | #pragma hdrstop | |
30 | #endif | |
31 | ||
32 | #ifndef WX_PRECOMP | |
33 | #include "wx/app.h" | |
34 | #endif | |
35 | ||
36 | #if wxUSE_SPINBTN | |
37 | ||
38 | #include "wx/spinbutt.h" | |
39 | ||
40 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent) | |
41 | ||
42 | #if defined(__WIN95__) | |
43 | ||
44 | #include "wx/msw/private.h" | |
45 | ||
46 | #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)) | |
47 | #include <commctrl.h> | |
48 | #endif | |
49 | ||
50 | // ============================================================================ | |
51 | // implementation | |
52 | // ============================================================================ | |
53 | ||
54 | // ---------------------------------------------------------------------------- | |
55 | // wxWin macros | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
58 | ||
59 | #if wxUSE_EXTENDED_RTTI | |
60 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton, wxControl,"wx/spinbut.h") | |
61 | ||
62 | WX_BEGIN_PROPERTIES_TABLE(wxSpinButton) | |
63 | WX_PROPERTY( Value , int , SetValue, GetValue, 0 ) | |
64 | WX_PROPERTY( Min , int , SetMin, GetMin, 0 ) | |
65 | WX_PROPERTY( Max , int , SetMax, GetMax, 0 ) | |
66 | /* | |
67 | TODO PROPERTIES | |
68 | style wxSP_VERTICAL | wxSP_ARROW_KEYS | |
69 | */ | |
70 | WX_END_PROPERTIES_TABLE() | |
71 | ||
72 | WX_BEGIN_HANDLERS_TABLE(wxSpinButton) | |
73 | WX_END_HANDLERS_TABLE() | |
74 | ||
75 | WX_CONSTRUCTOR_5( wxSpinButton , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) | |
76 | #else | |
77 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) | |
78 | #endif | |
79 | ||
80 | ||
81 | ||
82 | // ---------------------------------------------------------------------------- | |
83 | // wxSpinButton | |
84 | // ---------------------------------------------------------------------------- | |
85 | ||
86 | bool wxSpinButton::Create(wxWindow *parent, | |
87 | wxWindowID id, | |
88 | const wxPoint& pos, | |
89 | const wxSize& size, | |
90 | long style, | |
91 | const wxString& name) | |
92 | { | |
93 | // basic initialization | |
94 | InitBase(); | |
95 | ||
96 | m_windowId = (id == -1) ? NewControlId() : id; | |
97 | ||
98 | m_backgroundColour = parent->GetBackgroundColour() ; | |
99 | m_foregroundColour = parent->GetForegroundColour() ; | |
100 | ||
101 | SetName(name); | |
102 | ||
103 | int x = pos.x; | |
104 | int y = pos.y; | |
105 | int width = size.x; | |
106 | int height = size.y; | |
107 | ||
108 | m_windowStyle = style; | |
109 | ||
110 | SetParent(parent); | |
111 | ||
112 | // get the right size for the control | |
113 | if ( width <= 0 || height <= 0 ) | |
114 | { | |
115 | wxSize size = DoGetBestSize(); | |
116 | if ( width <= 0 ) | |
117 | width = size.x; | |
118 | if ( height <= 0 ) | |
119 | height = size.y; | |
120 | } | |
121 | ||
122 | if ( x < 0 ) | |
123 | x = 0; | |
124 | if ( y < 0 ) | |
125 | y = 0; | |
126 | ||
127 | // translate the styles | |
128 | DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | /* WS_CLIPSIBLINGS | */ | |
129 | UDS_NOTHOUSANDS | // never useful, sometimes harmful | |
130 | UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy | |
131 | ||
132 | if ( m_windowStyle & wxCLIP_SIBLINGS ) | |
133 | wstyle |= WS_CLIPSIBLINGS; | |
134 | if ( m_windowStyle & wxSP_HORIZONTAL ) | |
135 | wstyle |= UDS_HORZ; | |
136 | if ( m_windowStyle & wxSP_ARROW_KEYS ) | |
137 | wstyle |= UDS_ARROWKEYS; | |
138 | if ( m_windowStyle & wxSP_WRAP ) | |
139 | wstyle |= UDS_WRAP; | |
140 | ||
141 | // create the UpDown control. | |
142 | m_hWnd = (WXHWND)CreateUpDownControl | |
143 | ( | |
144 | wstyle, | |
145 | x, y, width, height, | |
146 | GetHwndOf(parent), | |
147 | m_windowId, | |
148 | wxGetInstance(), | |
149 | NULL, // no buddy | |
150 | m_max, m_min, | |
151 | m_min // initial position | |
152 | ); | |
153 | ||
154 | if ( !m_hWnd ) | |
155 | { | |
156 | wxLogLastError(wxT("CreateUpDownControl")); | |
157 | ||
158 | return FALSE; | |
159 | } | |
160 | ||
161 | if ( parent ) | |
162 | { | |
163 | parent->AddChild(this); | |
164 | } | |
165 | ||
166 | SubclassWin(m_hWnd); | |
167 | ||
168 | return TRUE; | |
169 | } | |
170 | ||
171 | wxSpinButton::~wxSpinButton() | |
172 | { | |
173 | } | |
174 | ||
175 | // ---------------------------------------------------------------------------- | |
176 | // size calculation | |
177 | // ---------------------------------------------------------------------------- | |
178 | ||
179 | wxSize wxSpinButton::DoGetBestSize() const | |
180 | { | |
181 | if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 ) | |
182 | { | |
183 | // vertical control | |
184 | return wxSize(GetSystemMetrics(SM_CXVSCROLL), | |
185 | 2*GetSystemMetrics(SM_CYVSCROLL)); | |
186 | } | |
187 | else | |
188 | { | |
189 | // horizontal control | |
190 | return wxSize(2*GetSystemMetrics(SM_CXHSCROLL), | |
191 | GetSystemMetrics(SM_CYHSCROLL)); | |
192 | } | |
193 | } | |
194 | ||
195 | // ---------------------------------------------------------------------------- | |
196 | // Attributes | |
197 | // ---------------------------------------------------------------------------- | |
198 | ||
199 | int wxSpinButton::GetValue() const | |
200 | { | |
201 | #ifdef UDM_GETPOS32 | |
202 | if ( wxTheApp->GetComCtl32Version() >= 580 ) | |
203 | { | |
204 | // use the full 32 bit range if available | |
205 | return ::SendMessage(GetHwnd(), UDM_GETPOS32, 0, 0); | |
206 | } | |
207 | #endif // UDM_GETPOS32 | |
208 | ||
209 | // we're limited to 16 bit | |
210 | return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0)); | |
211 | } | |
212 | ||
213 | void wxSpinButton::SetValue(int val) | |
214 | { | |
215 | // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual | |
216 | ||
217 | #ifdef UDM_SETPOS32 | |
218 | if ( wxTheApp->GetComCtl32Version() >= 580 ) | |
219 | { | |
220 | // use the full 32 bit range if available | |
221 | ::SendMessage(GetHwnd(), UDM_SETPOS32, 0, val); | |
222 | } | |
223 | else // we're limited to 16 bit | |
224 | #endif // UDM_SETPOS32 | |
225 | { | |
226 | ::SendMessage(GetHwnd(), UDM_SETPOS, 0, MAKELONG((short) val, 0)); | |
227 | } | |
228 | } | |
229 | ||
230 | void wxSpinButton::SetRange(int minVal, int maxVal) | |
231 | { | |
232 | wxSpinButtonBase::SetRange(minVal, maxVal); | |
233 | ||
234 | #ifdef UDM_SETRANGE32 | |
235 | if ( wxTheApp->GetComCtl32Version() >= 471 ) | |
236 | { | |
237 | // use the full 32 bit range if available | |
238 | ::SendMessage(GetHwnd(), UDM_SETRANGE32, minVal, maxVal); | |
239 | } | |
240 | else // we're limited to 16 bit | |
241 | #endif // UDM_SETRANGE32 | |
242 | { | |
243 | ::SendMessage(GetHwnd(), UDM_SETRANGE, 0, | |
244 | (LPARAM) MAKELONG((short)maxVal, (short)minVal)); | |
245 | } | |
246 | } | |
247 | ||
248 | bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, | |
249 | WXWORD pos, WXHWND control) | |
250 | { | |
251 | wxCHECK_MSG( control, FALSE, wxT("scrolling what?") ) | |
252 | ||
253 | if ( wParam != SB_THUMBPOSITION ) | |
254 | { | |
255 | // probable SB_ENDSCROLL - we don't react to it | |
256 | return FALSE; | |
257 | } | |
258 | ||
259 | wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId); | |
260 | event.SetPosition((short)pos); // cast is important for negative values! | |
261 | event.SetEventObject(this); | |
262 | ||
263 | return GetEventHandler()->ProcessEvent(event); | |
264 | } | |
265 | ||
266 | bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result) | |
267 | { | |
268 | NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam; | |
269 | ||
270 | if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control | |
271 | return FALSE; | |
272 | ||
273 | wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP | |
274 | : wxEVT_SCROLL_LINEDOWN, | |
275 | m_windowId); | |
276 | event.SetPosition(lpnmud->iPos + lpnmud->iDelta); | |
277 | event.SetEventObject(this); | |
278 | ||
279 | bool processed = GetEventHandler()->ProcessEvent(event); | |
280 | ||
281 | *result = event.IsAllowed() ? 0 : 1; | |
282 | ||
283 | return processed; | |
284 | } | |
285 | ||
286 | bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id)) | |
287 | { | |
288 | // No command messages | |
289 | return FALSE; | |
290 | } | |
291 | ||
292 | #endif // __WIN95__ | |
293 | ||
294 | #endif | |
295 | // wxUSE_SPINCTN | |
296 |