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