]>
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 | |
670f9935 | 28 | #include "wx/app.h" |
2bda0e17 KB |
29 | #endif |
30 | ||
0e528b99 JS |
31 | #if wxUSE_SPINBTN |
32 | ||
c3cb82e1 JS |
33 | #include "wx/spinbutt.h" |
34 | ||
2fa7c206 JS |
35 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent) |
36 | ||
2bda0e17 | 37 | #include "wx/msw/private.h" |
543ad898 | 38 | #include "wx/msw/wrapcctl.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 SC |
98 | wxBEGIN_PROPERTIES_TABLE(wxSpinButton) |
99 | wxEVENT_RANGE_PROPERTY( Spin , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , 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 | |
8d2e831b RD |
198 | SetBestSize(size); |
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 VZ |
223 | #ifdef UDM_GETPOS32 |
224 | if ( wxTheApp->GetComCtl32Version() >= 580 ) | |
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 | |
247 | if ( wxTheApp->GetComCtl32Version() >= 580 ) | |
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 | ||
debe6624 | 259 | void wxSpinButton::SetRange(int minVal, int maxVal) |
2bda0e17 | 260 | { |
31528cd3 | 261 | wxSpinButtonBase::SetRange(minVal, maxVal); |
3d9fe7b2 VZ |
262 | |
263 | #ifdef UDM_SETRANGE32 | |
2a1f999f | 264 | if ( wxApp::GetComCtl32Version() >= 471 ) |
3d9fe7b2 VZ |
265 | { |
266 | // use the full 32 bit range if available | |
267 | ::SendMessage(GetHwnd(), UDM_SETRANGE32, minVal, maxVal); | |
268 | } | |
269 | else // we're limited to 16 bit | |
270 | #endif // UDM_SETRANGE32 | |
271 | { | |
272 | ::SendMessage(GetHwnd(), UDM_SETRANGE, 0, | |
273 | (LPARAM) MAKELONG((short)maxVal, (short)minVal)); | |
274 | } | |
2bda0e17 KB |
275 | } |
276 | ||
33ac7e6f | 277 | bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, |
a23fd0e1 | 278 | WXWORD pos, WXHWND control) |
2bda0e17 | 279 | { |
637b7e4f | 280 | wxCHECK_MSG( control, false, wxT("scrolling what?") ); |
2bda0e17 | 281 | |
0655ad29 | 282 | if ( wParam != SB_THUMBPOSITION ) |
a23fd0e1 | 283 | { |
0655ad29 | 284 | // probable SB_ENDSCROLL - we don't react to it |
d95de154 | 285 | return false; |
0655ad29 | 286 | } |
2bda0e17 | 287 | |
0655ad29 VZ |
288 | wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId); |
289 | event.SetPosition((short)pos); // cast is important for negative values! | |
290 | event.SetEventObject(this); | |
2bda0e17 | 291 | |
0655ad29 VZ |
292 | return GetEventHandler()->ProcessEvent(event); |
293 | } | |
2bda0e17 | 294 | |
33ac7e6f | 295 | bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result) |
0655ad29 | 296 | { |
be519ffb | 297 | NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam; |
2bda0e17 | 298 | |
f6bcfd97 | 299 | if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control |
d95de154 | 300 | return false; |
f6bcfd97 | 301 | |
0655ad29 VZ |
302 | wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP |
303 | : wxEVT_SCROLL_LINEDOWN, | |
304 | m_windowId); | |
305 | event.SetPosition(lpnmud->iPos + lpnmud->iDelta); | |
306 | event.SetEventObject(this); | |
2bda0e17 | 307 | |
0655ad29 | 308 | bool processed = GetEventHandler()->ProcessEvent(event); |
2bda0e17 | 309 | |
0655ad29 | 310 | *result = event.IsAllowed() ? 0 : 1; |
2bda0e17 | 311 | |
0655ad29 | 312 | return processed; |
2bda0e17 KB |
313 | } |
314 | ||
33ac7e6f | 315 | bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id)) |
2bda0e17 | 316 | { |
a23fd0e1 | 317 | // No command messages |
d95de154 | 318 | return false; |
2bda0e17 KB |
319 | } |
320 | ||
d95de154 | 321 | #endif // wxUSE_SPINBTN |