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