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