]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/spinbutt.cpp
[ 1509599 ] 'Split pickers page in widgets sample' with more icons and rebaking.
[wxWidgets.git] / src / mac / carbon / spinbutt.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$
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/mac/uma.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 Rect bounds = wxMacGetBoundsForControl( this , pos , size );
45
46 m_peer = new wxMacControl( this );
47 OSStatus err = CreateLittleArrowsControl(
48 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, 0, m_min, m_max, 1,
49 m_peer->GetControlRefAddr() );
50 verify_noerr( err );
51
52 m_peer->SetActionProc( GetwxMacLiveScrollbarActionProc() );
53 MacPostControlCreate( pos, size );
54
55 return true;
56 }
57
58 wxSpinButton::~wxSpinButton()
59 {
60 }
61
62 int wxSpinButton::GetMin() const
63 {
64 return m_min;
65 }
66
67 int wxSpinButton::GetMax() const
68 {
69 return m_max;
70 }
71
72 int wxSpinButton::GetValue() const
73 {
74 int n = m_value;
75
76 if (n < m_min)
77 n = m_min;
78 else if (n > m_max)
79 n = m_max;
80
81 return n;
82 }
83
84 void wxSpinButton::SetValue(int val)
85 {
86 m_value = val;
87 }
88
89 void wxSpinButton::SetRange(int minVal, int maxVal)
90 {
91 m_min = minVal;
92 m_max = maxVal;
93 m_peer->SetMaximum( maxVal );
94 m_peer->SetMinimum( minVal );
95 }
96
97 void wxSpinButton::MacHandleValueChanged( int inc )
98 {
99 wxEventType scrollEvent = wxEVT_NULL;
100 int oldValue = m_value;
101
102 m_value = oldValue + inc;
103
104 if (m_value < m_min)
105 {
106 if ( m_windowStyle & wxSP_WRAP )
107 m_value = m_max;
108 else
109 m_value = m_min;
110 }
111
112 if (m_value > m_max)
113 {
114 if ( m_windowStyle & wxSP_WRAP )
115 m_value = m_min;
116 else
117 m_value = m_max;
118 }
119
120 if ( m_value - oldValue == -1 )
121 scrollEvent = wxEVT_SCROLL_LINEDOWN;
122 else if ( m_value - oldValue == 1 )
123 scrollEvent = wxEVT_SCROLL_LINEUP;
124 else
125 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
126
127 wxSpinEvent event( scrollEvent, m_windowId );
128
129 event.SetPosition( m_value );
130 event.SetEventObject( this );
131 if ((GetEventHandler()->ProcessEvent( event )) && !event.IsAllowed())
132 m_value = oldValue;
133
134 m_peer->SetValue( m_value );
135
136 // always send a thumbtrack event
137 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
138 {
139 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
140 wxSpinEvent event2( scrollEvent, GetId() );
141 event2.SetPosition( m_value );
142 event2.SetEventObject( this );
143 GetEventHandler()->ProcessEvent( event2 );
144 }
145 }
146
147 void wxSpinButton::MacHandleControlClick( WXWidget control, wxInt16 controlpart, bool mouseStillDown )
148 {
149 int nScrollInc = 0;
150
151 switch ( controlpart )
152 {
153 case kControlUpButtonPart :
154 nScrollInc = 1;
155 break;
156
157 case kControlDownButtonPart :
158 nScrollInc = -1;
159 break;
160
161 default:
162 break;
163 }
164
165 MacHandleValueChanged( nScrollInc ) ;
166 }
167
168 wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event )
169 {
170 #if 0
171 // these have been handled by the live action proc already
172 int nScrollInc = 0;
173 wxMacCarbonEvent cEvent( (EventRef)event );
174
175 switch ( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart, typeControlPartCode) )
176 {
177 case kControlUpButtonPart :
178 nScrollInc = 1;
179 break;
180
181 case kControlDownButtonPart :
182 nScrollInc = -1;
183 break;
184
185 default :
186 break;
187 }
188
189 MacHandleValueChanged( nScrollInc ) ;
190 #endif
191
192 return noErr;
193 }
194
195 wxSize wxSpinButton::DoGetBestSize() const
196 {
197 return wxSize( 16, 24 );
198 }
199
200 #endif // wxUSE_SPINBTN