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