]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
2ab30ebf | 2 | // Name: 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 | |
3181cff4 | 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 | |
b782f2e0 VZ |
40 | // ============================================================================ |
41 | // implementation | |
42 | // ============================================================================ | |
43 | ||
44 | // ---------------------------------------------------------------------------- | |
45 | // wxWin macros | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
2bda0e17 | 48 | |
51741307 | 49 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
50 | WX_DEFINE_FLAGS( wxSpinButtonStyle ) |
51 | ||
3ff066a4 | 52 | wxBEGIN_FLAGS( wxSpinButtonStyle ) |
bc9fb572 JS |
53 | // new style border flags, we put them first to |
54 | // use them for streaming out | |
3ff066a4 SC |
55 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
56 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
57 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
58 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
59 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
60 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
57f4f925 | 61 | |
bc9fb572 | 62 | // old style border flags |
3ff066a4 SC |
63 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
64 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
65 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
66 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
67 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 68 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
69 | |
70 | // standard window styles | |
3ff066a4 SC |
71 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
72 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
73 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
74 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 75 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
76 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
77 | wxFLAGS_MEMBER(wxVSCROLL) | |
78 | wxFLAGS_MEMBER(wxHSCROLL) | |
79 | ||
80 | wxFLAGS_MEMBER(wxSP_HORIZONTAL) | |
81 | wxFLAGS_MEMBER(wxSP_VERTICAL) | |
82 | wxFLAGS_MEMBER(wxSP_ARROW_KEYS) | |
83 | wxFLAGS_MEMBER(wxSP_WRAP) | |
84 | ||
85 | wxEND_FLAGS( wxSpinButtonStyle ) | |
bc9fb572 | 86 | |
51741307 SC |
87 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton, wxControl,"wx/spinbut.h") |
88 | ||
3ff066a4 SC |
89 | wxBEGIN_PROPERTIES_TABLE(wxSpinButton) |
90 | wxEVENT_RANGE_PROPERTY( Spin , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxSpinEvent ) | |
c5ca409b | 91 | |
d95de154 WS |
92 | wxPROPERTY( Value , int , SetValue, GetValue, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
93 | wxPROPERTY( Min , int , SetMin, GetMin, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
94 | wxPROPERTY( Max , int , SetMax, GetMax, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
af498247 | 95 | wxPROPERTY_FLAGS( WindowStyle , wxSpinButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 96 | wxEND_PROPERTIES_TABLE() |
51741307 | 97 | |
3ff066a4 SC |
98 | wxBEGIN_HANDLERS_TABLE(wxSpinButton) |
99 | wxEND_HANDLERS_TABLE() | |
51741307 | 100 | |
57f4f925 | 101 | wxCONSTRUCTOR_5( wxSpinButton , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
51741307 SC |
102 | #else |
103 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) | |
104 | #endif | |
105 | ||
106 | ||
066f1b7a | 107 | |
b782f2e0 VZ |
108 | // ---------------------------------------------------------------------------- |
109 | // wxSpinButton | |
110 | // ---------------------------------------------------------------------------- | |
111 | ||
31528cd3 VZ |
112 | bool wxSpinButton::Create(wxWindow *parent, |
113 | wxWindowID id, | |
114 | const wxPoint& pos, | |
115 | const wxSize& size, | |
116 | long style, | |
117 | const wxString& name) | |
2bda0e17 | 118 | { |
b782f2e0 | 119 | // basic initialization |
d95de154 | 120 | m_windowId = (id == wxID_ANY) ? NewControlId() : id; |
2bda0e17 | 121 | |
b782f2e0 | 122 | SetName(name); |
2bda0e17 | 123 | |
b782f2e0 VZ |
124 | int x = pos.x; |
125 | int y = pos.y; | |
126 | int width = size.x; | |
127 | int height = size.y; | |
2bda0e17 | 128 | |
b782f2e0 | 129 | m_windowStyle = style; |
2bda0e17 | 130 | |
b782f2e0 | 131 | SetParent(parent); |
2bda0e17 | 132 | |
b782f2e0 VZ |
133 | // get the right size for the control |
134 | if ( width <= 0 || height <= 0 ) | |
135 | { | |
136 | wxSize size = DoGetBestSize(); | |
137 | if ( width <= 0 ) | |
138 | width = size.x; | |
139 | if ( height <= 0 ) | |
140 | height = size.y; | |
141 | } | |
2bda0e17 | 142 | |
b782f2e0 VZ |
143 | if ( x < 0 ) |
144 | x = 0; | |
145 | if ( y < 0 ) | |
146 | y = 0; | |
147 | ||
148 | // translate the styles | |
f6bcfd97 | 149 | DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | /* WS_CLIPSIBLINGS | */ |
882a8f40 VZ |
150 | UDS_NOTHOUSANDS | // never useful, sometimes harmful |
151 | UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy | |
b782f2e0 | 152 | |
b0766406 JS |
153 | if ( m_windowStyle & wxCLIP_SIBLINGS ) |
154 | wstyle |= WS_CLIPSIBLINGS; | |
b782f2e0 VZ |
155 | if ( m_windowStyle & wxSP_HORIZONTAL ) |
156 | wstyle |= UDS_HORZ; | |
157 | if ( m_windowStyle & wxSP_ARROW_KEYS ) | |
158 | wstyle |= UDS_ARROWKEYS; | |
159 | if ( m_windowStyle & wxSP_WRAP ) | |
160 | wstyle |= UDS_WRAP; | |
161 | ||
162 | // create the UpDown control. | |
163 | m_hWnd = (WXHWND)CreateUpDownControl | |
164 | ( | |
165 | wstyle, | |
166 | x, y, width, height, | |
167 | GetHwndOf(parent), | |
168 | m_windowId, | |
169 | wxGetInstance(), | |
170 | NULL, // no buddy | |
171 | m_max, m_min, | |
172 | m_min // initial position | |
173 | ); | |
174 | ||
175 | if ( !m_hWnd ) | |
176 | { | |
f6bcfd97 | 177 | wxLogLastError(wxT("CreateUpDownControl")); |
2bda0e17 | 178 | |
d95de154 | 179 | return false; |
b782f2e0 | 180 | } |
2bda0e17 | 181 | |
b782f2e0 VZ |
182 | if ( parent ) |
183 | { | |
184 | parent->AddChild(this); | |
185 | } | |
31528cd3 | 186 | |
b782f2e0 | 187 | SubclassWin(m_hWnd); |
2bda0e17 | 188 | |
8d2e831b RD |
189 | SetBestSize(size); |
190 | ||
d95de154 | 191 | return true; |
2bda0e17 KB |
192 | } |
193 | ||
a23fd0e1 | 194 | wxSpinButton::~wxSpinButton() |
2bda0e17 KB |
195 | { |
196 | } | |
197 | ||
b782f2e0 VZ |
198 | // ---------------------------------------------------------------------------- |
199 | // size calculation | |
200 | // ---------------------------------------------------------------------------- | |
201 | ||
f68586e5 | 202 | wxSize wxSpinButton::DoGetBestSize() const |
b782f2e0 | 203 | { |
5aaabb37 | 204 | return GetBestSpinnerSize( (GetWindowStyle() & wxSP_VERTICAL) != 0 ); |
b782f2e0 VZ |
205 | } |
206 | ||
207 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 208 | // Attributes |
b782f2e0 | 209 | // ---------------------------------------------------------------------------- |
2bda0e17 | 210 | |
a23fd0e1 | 211 | int wxSpinButton::GetValue() const |
2bda0e17 | 212 | { |
ad8ddd13 | 213 | int n; |
3d9fe7b2 VZ |
214 | #ifdef UDM_GETPOS32 |
215 | if ( wxTheApp->GetComCtl32Version() >= 580 ) | |
216 | { | |
217 | // use the full 32 bit range if available | |
ad8ddd13 | 218 | n = ::SendMessage(GetHwnd(), UDM_GETPOS32, 0, 0); |
3d9fe7b2 | 219 | } |
419c6f40 | 220 | else |
3d9fe7b2 | 221 | #endif // UDM_GETPOS32 |
419c6f40 WS |
222 | { |
223 | // we're limited to 16 bit | |
224 | n = (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0)); | |
225 | } | |
3d9fe7b2 | 226 | |
ad8ddd13 RR |
227 | if (n < m_min) n = m_min; |
228 | if (n > m_max) n = m_max; | |
419c6f40 | 229 | |
ad8ddd13 | 230 | return n; |
2bda0e17 KB |
231 | } |
232 | ||
debe6624 | 233 | void wxSpinButton::SetValue(int val) |
2bda0e17 | 234 | { |
3d9fe7b2 VZ |
235 | // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual |
236 | ||
237 | #ifdef UDM_SETPOS32 | |
238 | if ( wxTheApp->GetComCtl32Version() >= 580 ) | |
239 | { | |
240 | // use the full 32 bit range if available | |
241 | ::SendMessage(GetHwnd(), UDM_SETPOS32, 0, val); | |
242 | } | |
243 | else // we're limited to 16 bit | |
244 | #endif // UDM_SETPOS32 | |
245 | { | |
246 | ::SendMessage(GetHwnd(), UDM_SETPOS, 0, MAKELONG((short) val, 0)); | |
247 | } | |
2bda0e17 KB |
248 | } |
249 | ||
debe6624 | 250 | void wxSpinButton::SetRange(int minVal, int maxVal) |
2bda0e17 | 251 | { |
31528cd3 | 252 | wxSpinButtonBase::SetRange(minVal, maxVal); |
3d9fe7b2 VZ |
253 | |
254 | #ifdef UDM_SETRANGE32 | |
2a1f999f | 255 | if ( wxApp::GetComCtl32Version() >= 471 ) |
3d9fe7b2 VZ |
256 | { |
257 | // use the full 32 bit range if available | |
258 | ::SendMessage(GetHwnd(), UDM_SETRANGE32, minVal, maxVal); | |
259 | } | |
260 | else // we're limited to 16 bit | |
261 | #endif // UDM_SETRANGE32 | |
262 | { | |
263 | ::SendMessage(GetHwnd(), UDM_SETRANGE, 0, | |
264 | (LPARAM) MAKELONG((short)maxVal, (short)minVal)); | |
265 | } | |
2bda0e17 KB |
266 | } |
267 | ||
33ac7e6f | 268 | bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, |
a23fd0e1 | 269 | WXWORD pos, WXHWND control) |
2bda0e17 | 270 | { |
57f4f925 | 271 | wxCHECK_MSG( control, false, wxT("scrolling what?") ) |
2bda0e17 | 272 | |
0655ad29 | 273 | if ( wParam != SB_THUMBPOSITION ) |
a23fd0e1 | 274 | { |
0655ad29 | 275 | // probable SB_ENDSCROLL - we don't react to it |
d95de154 | 276 | return false; |
0655ad29 | 277 | } |
2bda0e17 | 278 | |
0655ad29 VZ |
279 | wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId); |
280 | event.SetPosition((short)pos); // cast is important for negative values! | |
281 | event.SetEventObject(this); | |
2bda0e17 | 282 | |
0655ad29 VZ |
283 | return GetEventHandler()->ProcessEvent(event); |
284 | } | |
2bda0e17 | 285 | |
33ac7e6f | 286 | bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result) |
0655ad29 | 287 | { |
be519ffb | 288 | NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam; |
2bda0e17 | 289 | |
f6bcfd97 | 290 | if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control |
d95de154 | 291 | return false; |
f6bcfd97 | 292 | |
0655ad29 VZ |
293 | wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP |
294 | : wxEVT_SCROLL_LINEDOWN, | |
295 | m_windowId); | |
296 | event.SetPosition(lpnmud->iPos + lpnmud->iDelta); | |
297 | event.SetEventObject(this); | |
2bda0e17 | 298 | |
0655ad29 | 299 | bool processed = GetEventHandler()->ProcessEvent(event); |
2bda0e17 | 300 | |
0655ad29 | 301 | *result = event.IsAllowed() ? 0 : 1; |
2bda0e17 | 302 | |
0655ad29 | 303 | return processed; |
2bda0e17 KB |
304 | } |
305 | ||
33ac7e6f | 306 | bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id)) |
2bda0e17 | 307 | { |
a23fd0e1 | 308 | // No command messages |
d95de154 | 309 | return false; |
2bda0e17 KB |
310 | } |
311 | ||
d95de154 | 312 | #endif // wxUSE_SPINBTN |