]> git.saurik.com Git - wxWidgets.git/blob - src/osx/spinbutt_osx.cpp
Remove some now unused history variables.
[wxWidgets.git] / src / osx / spinbutt_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/spinbutt_osx.cpp
3 // Purpose: wxSpinButton
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_SPINBTN
15
16 #include "wx/spinbutt.h"
17 #include "wx/osx/private.h"
18
19
20 wxSpinButton::wxSpinButton()
21 : wxSpinButtonBase()
22 {
23 }
24
25 bool wxSpinButton::Create( wxWindow *parent,
26 wxWindowID id, const wxPoint& pos, const wxSize& size,
27 long style, const wxString& name )
28 {
29 DontCreatePeer();
30 if ( !wxSpinButtonBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
31 return false;
32
33 m_min = 0;
34 m_max = 100;
35
36 if (!parent)
37 return false;
38
39 SetPeer(wxWidgetImpl::CreateSpinButton( this , parent, id, 0, m_min, m_max, pos, size,
40 style, GetExtraStyle() ));
41
42 MacPostControlCreate( pos, size );
43
44 return true;
45 }
46
47 wxSpinButton::~wxSpinButton()
48 {
49 }
50
51 void wxSpinButton::SetValue( int val )
52 {
53 GetPeer()->SetValue( val );
54 }
55
56 int wxSpinButton::GetValue() const
57 {
58 return GetPeer()->GetValue();
59 }
60
61 void wxSpinButton::SetRange(int minVal, int maxVal)
62 {
63 m_min = minVal;
64 m_max = maxVal;
65 GetPeer()->SetMaximum( maxVal );
66 GetPeer()->SetMinimum( minVal );
67 }
68
69 void wxSpinButton::SendThumbTrackEvent()
70 {
71 wxSpinEvent event( wxEVT_SCROLL_THUMBTRACK, GetId() );
72 event.SetPosition( GetValue() );
73 event.SetEventObject( this );
74 HandleWindowEvent( event );
75 }
76
77 bool wxSpinButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
78 {
79 // all events have already been processed
80 return true;
81 }
82
83 wxSize wxSpinButton::DoGetBestSize() const
84 {
85 return wxSize( 16, 24 );
86 }
87
88 void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent)
89 {
90 int inc = 0;
91
92 if ( scrollEvent == wxEVT_SCROLL_LINEUP )
93 {
94 inc = 1;
95 }
96 else if ( scrollEvent == wxEVT_SCROLL_LINEDOWN )
97 {
98 inc = -1;
99 }
100
101 // trigger scroll events
102
103 int oldValue = GetValue() ;
104
105 int newValue = oldValue + inc;
106
107 if (newValue < m_min)
108 {
109 if ( m_windowStyle & wxSP_WRAP )
110 newValue = m_max;
111 else
112 newValue = m_min;
113 }
114
115 if (newValue > m_max)
116 {
117 if ( m_windowStyle & wxSP_WRAP )
118 newValue = m_min;
119 else
120 newValue = m_max;
121 }
122
123 if ( newValue - oldValue == -1 )
124 scrollEvent = wxEVT_SCROLL_LINEDOWN;
125 else if ( newValue - oldValue == 1 )
126 scrollEvent = wxEVT_SCROLL_LINEUP;
127 else
128 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
129
130 // Do not send an event if the value has not actually changed
131 // (Also works for wxSpinCtrl)
132 if ( newValue == oldValue )
133 return;
134
135 if ( scrollEvent != wxEVT_SCROLL_THUMBTRACK )
136 {
137 wxSpinEvent event( scrollEvent, m_windowId );
138
139 event.SetPosition( newValue );
140 event.SetEventObject( this );
141 if ((HandleWindowEvent( event )) && !event.IsAllowed())
142 newValue = oldValue;
143 }
144
145 GetPeer()->SetValue( newValue );
146
147 // always send a thumbtrack event
148 SendThumbTrackEvent() ;
149 }
150
151 #endif // wxUSE_SPINBTN