]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
get rid of duplicate comment :)
[wxWidgets.git] / src / msw / spinbutt.cpp
CommitLineData
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
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
40IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
41
2bda0e17 42#include "wx/msw/private.h"
543ad898 43#include "wx/msw/wrapcctl.h"
2bda0e17 44
b782f2e0
VZ
45// ============================================================================
46// implementation
47// ============================================================================
48
49// ----------------------------------------------------------------------------
50// wxWin macros
51// ----------------------------------------------------------------------------
52
2bda0e17 53
51741307 54#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
55WX_DEFINE_FLAGS( wxSpinButtonStyle )
56
3ff066a4 57wxBEGIN_FLAGS( wxSpinButtonStyle )
bc9fb572
JS
58 // new style border flags, we put them first to
59 // use them for streaming out
3ff066a4
SC
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)
57f4f925 66
bc9fb572 67 // old style border flags
3ff066a4
SC
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)
cb0afb26 73 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
74
75 // standard window styles
3ff066a4
SC
76 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
77 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
78 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
79 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 80 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
3ff066a4
SC
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 )
bc9fb572 91
51741307
SC
92IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton, wxControl,"wx/spinbut.h")
93
3ff066a4
SC
94wxBEGIN_PROPERTIES_TABLE(wxSpinButton)
95 wxEVENT_RANGE_PROPERTY( Spin , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxSpinEvent )
c5ca409b 96
d95de154
WS
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"))
af498247 100 wxPROPERTY_FLAGS( WindowStyle , wxSpinButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
3ff066a4 101wxEND_PROPERTIES_TABLE()
51741307 102
3ff066a4
SC
103wxBEGIN_HANDLERS_TABLE(wxSpinButton)
104wxEND_HANDLERS_TABLE()
51741307 105
57f4f925 106wxCONSTRUCTOR_5( wxSpinButton , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
51741307
SC
107#else
108IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
109#endif
110
111
066f1b7a 112
b782f2e0
VZ
113// ----------------------------------------------------------------------------
114// wxSpinButton
115// ----------------------------------------------------------------------------
116
31528cd3
VZ
117bool wxSpinButton::Create(wxWindow *parent,
118 wxWindowID id,
119 const wxPoint& pos,
120 const wxSize& size,
121 long style,
122 const wxString& name)
2bda0e17 123{
b782f2e0 124 // basic initialization
d95de154 125 m_windowId = (id == wxID_ANY) ? NewControlId() : id;
2bda0e17 126
b782f2e0 127 SetName(name);
2bda0e17 128
b782f2e0
VZ
129 int x = pos.x;
130 int y = pos.y;
131 int width = size.x;
132 int height = size.y;
2bda0e17 133
b782f2e0 134 m_windowStyle = style;
2bda0e17 135
b782f2e0 136 SetParent(parent);
2bda0e17 137
b782f2e0
VZ
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 }
2bda0e17 147
b782f2e0
VZ
148 if ( x < 0 )
149 x = 0;
150 if ( y < 0 )
151 y = 0;
152
153 // translate the styles
f6bcfd97 154 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | /* WS_CLIPSIBLINGS | */
882a8f40
VZ
155 UDS_NOTHOUSANDS | // never useful, sometimes harmful
156 UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy
b782f2e0 157
b0766406
JS
158 if ( m_windowStyle & wxCLIP_SIBLINGS )
159 wstyle |= WS_CLIPSIBLINGS;
b782f2e0
VZ
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 {
f6bcfd97 182 wxLogLastError(wxT("CreateUpDownControl"));
2bda0e17 183
d95de154 184 return false;
b782f2e0 185 }
2bda0e17 186
b782f2e0
VZ
187 if ( parent )
188 {
189 parent->AddChild(this);
190 }
31528cd3 191
b782f2e0 192 SubclassWin(m_hWnd);
2bda0e17 193
8d2e831b
RD
194 SetBestSize(size);
195
d95de154 196 return true;
2bda0e17
KB
197}
198
a23fd0e1 199wxSpinButton::~wxSpinButton()
2bda0e17
KB
200{
201}
202
b782f2e0
VZ
203// ----------------------------------------------------------------------------
204// size calculation
205// ----------------------------------------------------------------------------
206
f68586e5 207wxSize wxSpinButton::DoGetBestSize() const
b782f2e0 208{
5aaabb37 209 return GetBestSpinnerSize( (GetWindowStyle() & wxSP_VERTICAL) != 0 );
b782f2e0
VZ
210}
211
212// ----------------------------------------------------------------------------
2bda0e17 213// Attributes
b782f2e0 214// ----------------------------------------------------------------------------
2bda0e17 215
a23fd0e1 216int wxSpinButton::GetValue() const
2bda0e17 217{
ad8ddd13 218 int n;
3d9fe7b2
VZ
219#ifdef UDM_GETPOS32
220 if ( wxTheApp->GetComCtl32Version() >= 580 )
221 {
222 // use the full 32 bit range if available
ad8ddd13 223 n = ::SendMessage(GetHwnd(), UDM_GETPOS32, 0, 0);
3d9fe7b2 224 }
419c6f40 225 else
3d9fe7b2 226#endif // UDM_GETPOS32
419c6f40
WS
227 {
228 // we're limited to 16 bit
229 n = (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
230 }
3d9fe7b2 231
ad8ddd13
RR
232 if (n < m_min) n = m_min;
233 if (n > m_max) n = m_max;
419c6f40 234
ad8ddd13 235 return n;
2bda0e17
KB
236}
237
debe6624 238void wxSpinButton::SetValue(int val)
2bda0e17 239{
3d9fe7b2
VZ
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 }
2bda0e17
KB
253}
254
debe6624 255void wxSpinButton::SetRange(int minVal, int maxVal)
2bda0e17 256{
31528cd3 257 wxSpinButtonBase::SetRange(minVal, maxVal);
3d9fe7b2
VZ
258
259#ifdef UDM_SETRANGE32
260 if ( wxTheApp->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 }
2bda0e17
KB
271}
272
33ac7e6f 273bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
a23fd0e1 274 WXWORD pos, WXHWND control)
2bda0e17 275{
57f4f925 276 wxCHECK_MSG( control, false, wxT("scrolling what?") )
2bda0e17 277
0655ad29 278 if ( wParam != SB_THUMBPOSITION )
a23fd0e1 279 {
0655ad29 280 // probable SB_ENDSCROLL - we don't react to it
d95de154 281 return false;
0655ad29 282 }
2bda0e17 283
0655ad29
VZ
284 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
285 event.SetPosition((short)pos); // cast is important for negative values!
286 event.SetEventObject(this);
2bda0e17 287
0655ad29
VZ
288 return GetEventHandler()->ProcessEvent(event);
289}
2bda0e17 290
33ac7e6f 291bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result)
0655ad29 292{
be519ffb 293 NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam;
2bda0e17 294
f6bcfd97 295 if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control
d95de154 296 return false;
f6bcfd97 297
0655ad29
VZ
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);
2bda0e17 303
0655ad29 304 bool processed = GetEventHandler()->ProcessEvent(event);
2bda0e17 305
0655ad29 306 *result = event.IsAllowed() ? 0 : 1;
2bda0e17 307
0655ad29 308 return processed;
2bda0e17
KB
309}
310
33ac7e6f 311bool wxSpinButton::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD WXUNUSED(id))
2bda0e17 312{
a23fd0e1 313 // No command messages
d95de154 314 return false;
2bda0e17
KB
315}
316
d95de154 317#endif // wxUSE_SPINBTN