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