]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/spinbutt.cpp
carbon cfm fixes
[wxWidgets.git] / src / mac / carbon / spinbutt.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: spinbutt.cpp
3// Purpose: wxSpinButton
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5 13#pragma implementation "spinbutt.h"
03e11df5 14#pragma implementation "spinbuttbase.h"
e9576ca5
SC
15#endif
16
3d1a4878 17#include "wx/wxprec.h"
312ebad4
WS
18
19#if wxUSE_SPINBTN
20
e9576ca5 21#include "wx/spinbutt.h"
519cb848 22#include "wx/mac/uma.h"
e9576ca5 23
e7549107
SC
24// ============================================================================
25// implementation
26// ============================================================================
27
28// ----------------------------------------------------------------------------
29// wxWin macros
30// ----------------------------------------------------------------------------
31
2f1ae414 32#if !USE_SHARED_LIBRARY
e7549107 33 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
d84afea9 34 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
2f1ae414 35#endif
e9576ca5 36
64be92e2
SC
37extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
38
03e11df5
GD
39wxSpinButton::wxSpinButton()
40 : wxSpinButtonBase()
41{
42}
43
e9576ca5 44bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
e40298d5 45 long style, const wxString& name)
e9576ca5 46{
312ebad4
WS
47 m_macIsUserPane = false ;
48
b45ed7a2
VZ
49 if ( !wxSpinButtonBase::Create(parent, id, pos, size,
50 style, wxDefaultValidator, name) )
51 return false;
52
e9576ca5
SC
53 m_min = 0;
54 m_max = 100;
312ebad4 55
e40298d5 56 if (!parent)
312ebad4
WS
57 return false;
58
facd6764 59 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
312ebad4 60
b905d6cc 61 m_peer = new wxMacControl(this) ;
4c37f124 62 verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , 0 , m_min , m_max , 1 ,
5ca0d812 63 m_peer->GetControlRefAddr() ) );
312ebad4 64
5ca0d812 65 m_peer->SetActionProc( wxMacLiveScrollbarActionUPP ) ;
facd6764 66 MacPostControlCreate(pos,size) ;
312ebad4
WS
67
68 return true;
e9576ca5 69}
312ebad4 70
e9576ca5
SC
71wxSpinButton::~wxSpinButton()
72{
73}
74
75// Attributes
76////////////////////////////////////////////////////////////////////////////
77
03e11df5
GD
78int wxSpinButton::GetMin() const
79{
e40298d5 80 return m_min;
03e11df5
GD
81}
82
83int wxSpinButton::GetMax() const
84{
e40298d5 85 return m_max;
03e11df5
GD
86}
87
e9576ca5
SC
88int wxSpinButton::GetValue() const
89{
6511d307
RR
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;
e9576ca5
SC
96}
97
98void wxSpinButton::SetValue(int val)
99{
e40298d5 100 m_value = val ;
e9576ca5
SC
101}
102
103void wxSpinButton::SetRange(int minVal, int maxVal)
104{
e40298d5
JS
105 m_min = minVal;
106 m_max = maxVal;
5ca0d812
SC
107 m_peer->SetMaximum( maxVal ) ;
108 m_peer->SetMinimum( minVal ) ;
e9576ca5
SC
109}
110
a54b0880 111void wxSpinButton::MacHandleValueChanged( int inc )
519cb848 112{
312ebad4 113
a54b0880 114 wxEventType scrollEvent = wxEVT_NULL;
e40298d5 115 int oldValue = m_value ;
312ebad4 116
a54b0880 117 m_value = oldValue + inc;
312ebad4 118
a54b0880
SC
119 if (m_value < m_min)
120 {
e40298d5
JS
121 if ( m_windowStyle & wxSP_WRAP )
122 m_value = m_max;
123 else
124 m_value = m_min;
a54b0880 125 }
312ebad4 126
a54b0880
SC
127 if (m_value > m_max)
128 {
e40298d5
JS
129 if ( m_windowStyle & wxSP_WRAP )
130 m_value = m_min;
131 else
132 m_value = m_max;
a54b0880 133 }
312ebad4 134
92432aa1 135 if ( m_value - oldValue == -1 )
a54b0880 136 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
92432aa1 137 else if ( m_value - oldValue == 1 )
a54b0880
SC
138 scrollEvent = wxEVT_SCROLL_LINEUP ;
139 else
140 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
312ebad4 141
a54b0880 142 wxSpinEvent event(scrollEvent, m_windowId);
312ebad4 143
a54b0880
SC
144 event.SetPosition(m_value);
145 event.SetEventObject( this );
146 if ((GetEventHandler()->ProcessEvent( event )) &&
72d750d4 147 !event.IsAllowed() )
a54b0880
SC
148 {
149 m_value = oldValue ;
150 }
5ca0d812 151 m_peer->SetValue( m_value ) ;
312ebad4 152
72d750d4
SC
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 }
519cb848
SC
162}
163
312ebad4 164void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
64be92e2
SC
165{
166 int nScrollInc = 0;
312ebad4 167
64be92e2
SC
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
312ebad4 180wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event )
a54b0880 181{
64be92e2
SC
182 /*
183 // these have been handled by the live action proc already
e40298d5 184 int nScrollInc = 0;
4c37f124 185 wxMacCarbonEvent cEvent( (EventRef) event ) ;
312ebad4 186
4c37f124 187 switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) )
e40298d5
JS
188 {
189 case kControlUpButtonPart :
190 nScrollInc = 1;
191 break ;
192 case kControlDownButtonPart :
193 nScrollInc = -1;
194 break ;
195 }
196 MacHandleValueChanged( nScrollInc ) ;
64be92e2 197 */
4c37f124 198 return noErr ;
a54b0880
SC
199}
200
51abe921
SC
201// ----------------------------------------------------------------------------
202// size calculation
203// ----------------------------------------------------------------------------
204
37e2cb08 205wxSize wxSpinButton::DoGetBestSize() const
51abe921 206{
e40298d5 207 return wxSize(16,24);
51abe921 208}
519cb848 209
312ebad4 210#endif // wxUSE_SPINBTN