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