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