]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/carbon/spinbutt.cpp
added test for Replace(whatever, "")
[wxWidgets.git] / src / osx / carbon / spinbutt.cpp
... / ...
CommitLineData
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/osx/uma.h"
18
19
20IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
21IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
22
23
24wxSpinButton::wxSpinButton()
25 : wxSpinButtonBase()
26{
27}
28
29bool 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
58wxSpinButton::~wxSpinButton()
59{
60}
61
62int wxSpinButton::GetMin() const
63{
64 return m_min;
65}
66
67int wxSpinButton::GetMax() const
68{
69 return m_max;
70}
71
72int 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
84void wxSpinButton::SetValue(int val)
85{
86 m_value = val;
87}
88
89void 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
97void 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 // Do not send an event if the value has not actually changed
128 // (Also works for wxSpinCtrl)
129 if ( m_value == oldValue )
130 return;
131
132 wxSpinEvent event( scrollEvent, m_windowId );
133
134 event.SetPosition( m_value );
135 event.SetEventObject( this );
136 if ((HandleWindowEvent( event )) && !event.IsAllowed())
137 m_value = oldValue;
138
139 m_peer->SetValue( m_value );
140
141 // always send a thumbtrack event
142 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
143 {
144 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
145 wxSpinEvent event2( scrollEvent, GetId() );
146 event2.SetPosition( m_value );
147 event2.SetEventObject( this );
148 HandleWindowEvent( event2 );
149 }
150}
151
152void wxSpinButton::MacHandleControlClick(WXWidget WXUNUSED(control),
153 wxInt16 controlpart,
154 bool WXUNUSED(mouseStillDown))
155{
156 int nScrollInc = 0;
157
158 switch ( controlpart )
159 {
160 case kControlUpButtonPart :
161 nScrollInc = 1;
162 break;
163
164 case kControlDownButtonPart :
165 nScrollInc = -1;
166 break;
167
168 default:
169 break;
170 }
171
172 MacHandleValueChanged( nScrollInc ) ;
173}
174
175wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler),
176 WXEVENTREF WXUNUSED(event))
177{
178#if 0
179 // these have been handled by the live action proc already
180 int nScrollInc = 0;
181 wxMacCarbonEvent cEvent( (EventRef)event );
182
183 switch ( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart, typeControlPartCode) )
184 {
185 case kControlUpButtonPart :
186 nScrollInc = 1;
187 break;
188
189 case kControlDownButtonPart :
190 nScrollInc = -1;
191 break;
192
193 default :
194 break;
195 }
196
197 MacHandleValueChanged( nScrollInc ) ;
198#endif
199
200 return noErr;
201}
202
203wxSize wxSpinButton::DoGetBestSize() const
204{
205 return wxSize( 16, 24 );
206}
207
208#endif // wxUSE_SPINBTN