]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/spinbutt.cpp
revamping classic MLTE implementation
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "spinbutt.h"
14 #pragma implementation "spinbuttbase.h"
15 #endif
16
17 #include "wx/wxprec.h"
18
19 #if wxUSE_SPINBTN
20
21 #include "wx/spinbutt.h"
22 #include "wx/mac/uma.h"
23
24 // ============================================================================
25 // implementation
26 // ============================================================================
27
28 // ----------------------------------------------------------------------------
29 // wxWin macros
30 // ----------------------------------------------------------------------------
31
32 #if !USE_SHARED_LIBRARY
33 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
34 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
35 #endif
36
37 extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
38
39 wxSpinButton::wxSpinButton()
40 : wxSpinButtonBase()
41 {
42 }
43
44 bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
45 long style, const wxString& name)
46 {
47 m_macIsUserPane = false ;
48
49 if ( !wxSpinButtonBase::Create(parent, id, pos, size,
50 style, wxDefaultValidator, name) )
51 return false;
52
53 m_min = 0;
54 m_max = 100;
55
56 if (!parent)
57 return false;
58
59 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
60
61 m_peer = new wxMacControl(this) ;
62 verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , 0 , m_min , m_max , 1 ,
63 m_peer->GetControlRefAddr() ) );
64
65 m_peer->SetActionProc( wxMacLiveScrollbarActionUPP ) ;
66 MacPostControlCreate(pos,size) ;
67
68 return true;
69 }
70
71 wxSpinButton::~wxSpinButton()
72 {
73 }
74
75 // Attributes
76 ////////////////////////////////////////////////////////////////////////////
77
78 int wxSpinButton::GetMin() const
79 {
80 return m_min;
81 }
82
83 int wxSpinButton::GetMax() const
84 {
85 return m_max;
86 }
87
88 int wxSpinButton::GetValue() const
89 {
90 int n = m_value;
91
92 if (n < m_min) n = m_min;
93 if (n > m_max) n = m_max;
94
95 return n;
96 }
97
98 void wxSpinButton::SetValue(int val)
99 {
100 m_value = val ;
101 }
102
103 void wxSpinButton::SetRange(int minVal, int maxVal)
104 {
105 m_min = minVal;
106 m_max = maxVal;
107 m_peer->SetMaximum( maxVal ) ;
108 m_peer->SetMinimum( minVal ) ;
109 }
110
111 void wxSpinButton::MacHandleValueChanged( int inc )
112 {
113
114 wxEventType scrollEvent = wxEVT_NULL;
115 int oldValue = m_value ;
116
117 m_value = oldValue + inc;
118
119 if (m_value < m_min)
120 {
121 if ( m_windowStyle & wxSP_WRAP )
122 m_value = m_max;
123 else
124 m_value = m_min;
125 }
126
127 if (m_value > m_max)
128 {
129 if ( m_windowStyle & wxSP_WRAP )
130 m_value = m_min;
131 else
132 m_value = m_max;
133 }
134
135 if ( m_value - oldValue == -1 )
136 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
137 else if ( m_value - oldValue == 1 )
138 scrollEvent = wxEVT_SCROLL_LINEUP ;
139 else
140 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
141
142 wxSpinEvent event(scrollEvent, m_windowId);
143
144 event.SetPosition(m_value);
145 event.SetEventObject( this );
146 if ((GetEventHandler()->ProcessEvent( event )) &&
147 !event.IsAllowed() )
148 {
149 m_value = oldValue ;
150 }
151 m_peer->SetValue( m_value ) ;
152
153 /* always send a thumbtrack event */
154 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
155 {
156 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
157 wxSpinEvent event2( scrollEvent, GetId());
158 event2.SetPosition( m_value );
159 event2.SetEventObject( this );
160 GetEventHandler()->ProcessEvent( event2 );
161 }
162 }
163
164 void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
165 {
166 int nScrollInc = 0;
167
168 switch( controlpart )
169 {
170 case kControlUpButtonPart :
171 nScrollInc = 1;
172 break ;
173 case kControlDownButtonPart :
174 nScrollInc = -1;
175 break ;
176 }
177 MacHandleValueChanged( nScrollInc ) ;
178 }
179
180 wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event )
181 {
182 /*
183 // these have been handled by the live action proc already
184 int nScrollInc = 0;
185 wxMacCarbonEvent cEvent( (EventRef) event ) ;
186
187 switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) )
188 {
189 case kControlUpButtonPart :
190 nScrollInc = 1;
191 break ;
192 case kControlDownButtonPart :
193 nScrollInc = -1;
194 break ;
195 }
196 MacHandleValueChanged( nScrollInc ) ;
197 */
198 return noErr ;
199 }
200
201 // ----------------------------------------------------------------------------
202 // size calculation
203 // ----------------------------------------------------------------------------
204
205 wxSize wxSpinButton::DoGetBestSize() const
206 {
207 return wxSize(16,24);
208 }
209
210 #endif // wxUSE_SPINBTN