]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
670f9935 | 2 | // Name: src/msw/spinbutt.cpp |
2bda0e17 KB |
3 | // Purpose: wxSpinButton |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
b782f2e0 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
a23fd0e1 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
27 | #ifndef WX_PRECOMP | |
57bd4c60 | 28 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" |
670f9935 | 29 | #include "wx/app.h" |
2bda0e17 KB |
30 | #endif |
31 | ||
0e528b99 JS |
32 | #if wxUSE_SPINBTN |
33 | ||
c3cb82e1 JS |
34 | #include "wx/spinbutt.h" |
35 | ||
2fa7c206 JS |
36 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent) |
37 | ||
2bda0e17 | 38 | #include "wx/msw/private.h" |
2bda0e17 | 39 | |
0aed4008 VZ |
40 | #ifndef UDM_SETRANGE32 |
41 | #define UDM_SETRANGE32 (WM_USER+111) | |
42 | #endif | |
43 | ||
44 | #ifndef UDM_SETPOS32 | |
45 | #define UDM_SETPOS32 (WM_USER+113) | |
46 | #define UDM_GETPOS32 (WM_USER+114) | |
47 | #endif | |
48 | ||
b782f2e0 VZ |
49 | // ============================================================================ |
50 | // implementation | |
51 | // ============================================================================ | |
52 | ||
53 | // ---------------------------------------------------------------------------- | |
54 | // wxWin macros | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
2bda0e17 | 57 | |
51741307 | 58 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
59 | WX_DEFINE_FLAGS( wxSpinButtonStyle ) |
60 | ||
3ff066a4 | 61 | wxBEGIN_FLAGS( wxSpinButtonStyle ) |
bc9fb572 JS |
62 | // new style border flags, we put them first to |
63 | // use them for streaming out | |
3ff066a4 SC |
64 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
65 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
66 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
67 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
68 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
69 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
57f4f925 | 70 | |
bc9fb572 | 71 | // old style border flags |
3ff066a4 SC |
72 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
73 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
74 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
75 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
76 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 77 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
78 | |
79 | // standard window styles | |
3ff066a4 SC |
80 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
81 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
82 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
83 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 84 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
85 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
86 | wxFLAGS_MEMBER(wxVSCROLL) | |
87 | wxFLAGS_MEMBER(wxHSCROLL) | |
88 | ||
89 | wxFLAGS_MEMBER(wxSP_HORIZONTAL) | |
90 | wxFLAGS_MEMBER(wxSP_VERTICAL) | |
91 | wxFLAGS_MEMBER(wxSP_ARROW_KEYS) | |
92 | wxFLAGS_MEMBER(wxSP_WRAP) | |
93 | ||
94 | wxEND_FLAGS( wxSpinButtonStyle ) | |
bc9fb572 | 95 | |
51741307 SC |
96 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton, wxControl,"wx/spinbut.h") |
97 | ||
3ff066a4 | 98 | wxBEGIN_PROPERTIES_TABLE(wxSpinButton) |
ed3d6ace | 99 | wxEVENT_RANGE_PROPERTY( Spin , wxEVT_SCROLL_TOP , wxEVT_SCROLL_CHANGED , wxSpinEvent ) |
c5ca409b | 100 | |
d95de154 WS |
101 | wxPROPERTY( Value , int , SetValue, GetValue, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
102 | wxPROPERTY( Min , int , SetMin, GetMin, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
103 | wxPROPERTY( Max , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
af498247 | 104 | wxPROPERTY_FLAGS( WindowStyle , wxSpinButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 105 | wxEND_PROPERTIES_TABLE() |
51741307 | 106 | |
3ff066a4 SC |
107 | wxBEGIN_HANDLERS_TABLE(wxSpinButton) |
108 | wxEND_HANDLERS_TABLE() | |
51741307 | 109 | |
57f4f925 | 110 | wxCONSTRUCTOR_5( wxSpinButton , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
51741307 SC |
111 | #else |
112 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) | |
113 | #endif | |
114 | ||
115 | ||
066f1b7a | 116 | |
b782f2e0 VZ |
117 | // ---------------------------------------------------------------------------- |
118 | // wxSpinButton | |
119 | // ---------------------------------------------------------------------------- | |
120 | ||
31528cd3 VZ |
121 | bool wxSpinButton::Create(wxWindow *parent, |
122 | wxWindowID id, | |
123 | const wxPoint& pos, | |
124 | const wxSize& size, | |
125 | long style, | |
126 | const wxString& name) | |
2bda0e17 | 127 | { |
b782f2e0 | 128 | // basic initialization |
d95de154 | 129 | m_windowId = (id == wxID_ANY) ? NewControlId() : id; |
2bda0e17 | 130 | |
b782f2e0 | 131 | SetName(name); |
2bda0e17 | 132 | |
b782f2e0 VZ |
133 | int x = pos.x; |
134 | int y = pos.y; | |
135 | int width = size.x; | |
136 | int height = size.y; | |
2bda0e17 | 137 | |
b782f2e0 | 138 | m_windowStyle = style; |
2bda0e17 | 139 | |
b782f2e0 | 140 | SetParent(parent); |
2bda0e17 | 141 | |
b782f2e0 VZ |
142 | // get the right size for the control |
143 | if ( width <= 0 || height <= 0 ) | |
144 | { | |
145 | wxSize size = DoGetBestSize(); | |
146 | if ( width <= 0 ) | |
147 | width = size.x; | |
148 | if ( height <= 0 ) | |
149 | height = size.y; | |
150 | } | |
2bda0e17 | 151 | |
b782f2e0 VZ |
152 | if ( x < 0 ) |
153 | x = 0; | |
154 | if ( y < 0 ) | |
155 | y = 0; | |
156 | ||
157 | // translate the styles | |
f6bcfd97 | 158 | DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | /* WS_CLIPSIBLINGS | */ |
882a8f40 VZ |
159 | UDS_NOTHOUSANDS | // never useful, sometimes harmful |
160 | UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy | |
b782f2e0 | 161 | |
b0766406 JS |
162 | if ( m_windowStyle & wxCLIP_SIBLINGS ) |
163 | wstyle |= WS_CLIPSIBLINGS; | |
b782f2e0 VZ |
164 | if ( m_windowStyle & wxSP_HORIZONTAL ) |
165 | wstyle |= UDS_HORZ; | |
166 | if ( m_windowStyle & wxSP_ARROW_KEYS ) | |
167 | wstyle |= UDS_ARROWKEYS; | |
168 | if ( m_windowStyle & wxSP_WRAP ) | |
169 | wstyle |= UDS_WRAP; | |
170 | ||
171 | // create the UpDown control. | |
172 | m_hWnd = (WXHWND)CreateUpDownControl | |
173 | ( | |
174 | wstyle, | |
175 | x, y, width, height, | |
176 | GetHwndOf(parent), | |
177 | m_windowId, | |
178 | wxGetInstance(), | |
179 | NULL, // no buddy | |
180 | m_max, m_min, | |
181 | m_min // initial position | |
182 | ); | |
183 | ||
184 | if ( !m_hWnd ) | |
185 | { | |
f6bcfd97 | 186 | wxLogLastError(wxT("CreateUpDownControl")); |
2bda0e17 | 187 | |
d95de154 | 188 | return false; |
b782f2e0 | 189 | } |
2bda0e17 | 190 | |
b782f2e0 VZ |
191 | if ( parent ) |
192 | { | |
193 | parent->AddChild(this); | |
194 | } | |
31528cd3 | 195 | |
b782f2e0 | 196 | SubclassWin(m_hWnd); |
2bda0e17 | 197 | |
170acdc9 | 198 | SetInitialSize(size); |
8d2e831b | 199 | |
d95de154 | 200 | return true; |
2bda0e17 KB |
201 | } |
202 | ||
a23fd0e1 | 203 | wxSpinButton::~wxSpinButton() |
2bda0e17 KB |
204 | { |
205 | } | |
206 | ||
b782f2e0 VZ |
207 | // ---------------------------------------------------------------------------- |
208 | // size calculation | |
209 | // ---------------------------------------------------------------------------- | |
210 | ||
f68586e5 | 211 | wxSize wxSpinButton::DoGetBestSize() const |
b782f2e0 | 212 | { |
5aaabb37 | 213 | return GetBestSpinnerSize( (GetWindowStyle() & wxSP_VERTICAL) != 0 ); |
b782f2e0 VZ |
214 | } |
215 | ||
216 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 217 | // Attributes |
b782f2e0 | 218 | // ---------------------------------------------------------------------------- |
2bda0e17 | 219 | |
a23fd0e1 | 220 | int wxSpinButton::GetValue() const |
2bda0e17 | 221 | { |
ad8ddd13 | 222 | int n; |
3d9fe7b2 | 223 | #ifdef UDM_GETPOS32 |
5625d0d4 | 224 | if ( wxApp::GetComCtl32Version() >= 580 ) |
3d9fe7b2 VZ |
225 | { |
226 | // use the full 32 bit range if available | |
ad8ddd13 | 227 | n = ::SendMessage(GetHwnd(), UDM_GETPOS32, 0, 0); |
3d9fe7b2 | 228 | } |
419c6f40 | 229 | else |
3d9fe7b2 | 230 | #endif // UDM_GETPOS32 |
419c6f40 WS |
231 | { |
232 | // we're limited to 16 bit | |
233 | n = (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0)); | |
234 | } | |
3d9fe7b2 | 235 | |
ad8ddd13 RR |
236 | if (n < m_min) n = m_min; |
237 | if (n > m_max) n = m_max; | |
419c6f40 | 238 | |
ad8ddd13 | 239 | return n; |
2bda0e17 KB |
240 | } |
241 | ||
debe6624 | 242 | void wxSpinButton::SetValue(int val) |
2bda0e17 | 243 | { |
3d9fe7b2 VZ |
244 | // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual |
245 | ||
246 | #ifdef UDM_SETPOS32 | |
5625d0d4 | 247 | if ( wxApp::GetComCtl32Version() >= 580 ) |
3d9fe7b2 VZ |
248 | { |
249 | // use the full 32 bit range if available | |
250 | ::SendMessage(GetHwnd(), UDM_SETPOS32, 0, val); | |
251 | } | |
252 | else // we're limited to 16 bit | |
253 | #endif // UDM_SETPOS32 | |
254 | { | |
255 | ::SendMessage(GetHwnd(), UDM_SETPOS, 0, MAKELONG((short) val, 0)); | |
256 | } | |
2bda0e17 KB |
257 | } |
258 | ||
1e8dba5e | 259 | void wxSpinButton::NormalizeValue() |
f4322df6 | 260 | { |
1e8dba5e RR |
261 | SetValue( GetValue() ); |
262 | } | |
263 | ||
debe6624 | 264 | void wxSpinButton::SetRange(int minVal, int maxVal) |
2bda0e17 | 265 | { |
93232499 VZ |
266 | const bool hadRange = m_min < m_max; |
267 | ||
31528cd3 | 268 | wxSpinButtonBase::SetRange(minVal, maxVal); |
3d9fe7b2 VZ |
269 | |
270 | #ifdef UDM_SETRANGE32 | |
2a1f999f | 271 | if ( wxApp::GetComCtl32Version() >= 471 ) |
3d9fe7b2 VZ |
272 | { |
273 | // use the full 32 bit range if available | |
274 | ::SendMessage(GetHwnd(), UDM_SETRANGE32, minVal, maxVal); | |
275 | } | |
276 | else // we're limited to 16 bit | |
277 | #endif // UDM_SETRANGE32 | |
278 | { | |
279 | ::SendMessage(GetHwnd(), UDM_SETRANGE, 0, | |
280 | (LPARAM) MAKELONG((short)maxVal, (short)minVal)); | |
281 | } | |
93232499 VZ |
282 | |
283 | // the current value might be out of the new range, force it to be in it | |
284 | NormalizeValue(); | |
285 | ||
286 | // if range was valid but becomes degenerated (min == max) now or vice | |
287 | // versa then the spin buttons are automatically disabled/enabled back | |
288 | // but don't update themselves for some reason, so do it manually | |
289 | if ( hadRange != (m_min < m_max) ) | |
290 | { | |
291 | // update the visual state of the button | |
292 | Refresh(); | |
293 | } | |
2bda0e17 KB |
294 | } |
295 | ||
33ac7e6f | 296 | bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, |
a23fd0e1 | 297 | WXWORD pos, WXHWND control) |
2bda0e17 | 298 | { |
637b7e4f | 299 | wxCHECK_MSG( control, false, wxT("scrolling what?") ); |
2bda0e17 | 300 | |
0655ad29 | 301 | if ( wParam != SB_THUMBPOSITION ) |
a23fd0e1 | 302 | { |
0655ad29 | 303 | // probable SB_ENDSCROLL - we don't react to it |
d95de154 | 304 | return false; |
0655ad29 | 305 | } |
2bda0e17 | 306 | |
0655ad29 VZ |
307 | wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId); |
308 | event.SetPosition((short)pos); // cast is important for negative values! | |
309 | event.SetEventObject(this); | |
2bda0e17 | 310 | |
0655ad29 VZ |
311 | return GetEventHandler()->ProcessEvent(event); |
312 | } | |
2bda0e17 | 313 | |
33ac7e6f | 314 | bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result) |
0655ad29 | 315 | { |
be519ffb | 316 | NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam; |
2bda0e17 | 317 | |
f6bcfd97 | 318 | if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control |
d95de154 | 319 | return false; |
f6bcfd97 | 320 | |
0655ad29 VZ |
321 | wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP |
322 | : wxEVT_SCROLL_LINEDOWN, | |
323 | m_windowId); | |
324 | event.SetPosition(lpnmud->iPos + lpnmud->iDelta); | |
325 | event.SetEventObject(this); | |
2bda0e17 | 326 | |
0655ad29 | 327 | bool processed = GetEventHandler()->ProcessEvent(event); |
2bda0e17 | 328 | |
0655ad29 | 329 | *result = event.IsAllowed() ? 0 : 1; |
2bda0e17 | 330 | |
0655ad29 | 331 | return processed; |
2bda0e17 KB |
332 | } |
333 | ||
33ac7e6f | 334 | bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id)) |
2bda0e17 | 335 | { |
a23fd0e1 | 336 | // No command messages |
d95de154 | 337 | return false; |
2bda0e17 KB |
338 | } |
339 | ||
d95de154 | 340 | #endif // wxUSE_SPINBTN |