]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/spinbutt.cpp
Include wx/bitmap.h according to precompiled headers of wx/wx.h (with other minor...
[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
43524b15 127 wxSpinEvent event( scrollEvent, m_windowId );
312ebad4 128
43524b15 129 event.SetPosition( m_value );
a54b0880 130 event.SetEventObject( this );
43524b15
DS
131 if ((GetEventHandler()->ProcessEvent( event )) && !event.IsAllowed())
132 m_value = oldValue;
133
134 m_peer->SetValue( m_value );
312ebad4 135
43524b15 136 // always send a thumbtrack event
72d750d4
SC
137 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
138 {
139 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
43524b15 140 wxSpinEvent event2( scrollEvent, GetId() );
72d750d4
SC
141 event2.SetPosition( m_value );
142 event2.SetEventObject( this );
143 GetEventHandler()->ProcessEvent( event2 );
144 }
519cb848
SC
145}
146
43524b15 147void wxSpinButton::MacHandleControlClick( WXWidget control, wxInt16 controlpart, bool mouseStillDown )
64be92e2
SC
148{
149 int nScrollInc = 0;
312ebad4 150
43524b15 151 switch ( controlpart )
64be92e2
SC
152 {
153 case kControlUpButtonPart :
154 nScrollInc = 1;
43524b15
DS
155 break;
156
64be92e2
SC
157 case kControlDownButtonPart :
158 nScrollInc = -1;
43524b15
DS
159 break;
160
161 default:
162 break;
64be92e2 163 }
43524b15 164
64be92e2
SC
165 MacHandleValueChanged( nScrollInc ) ;
166}
167
312ebad4 168wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event )
a54b0880 169{
43524b15 170#if 0
64be92e2 171 // these have been handled by the live action proc already
e40298d5 172 int nScrollInc = 0;
43524b15 173 wxMacCarbonEvent cEvent( (EventRef)event );
312ebad4 174
43524b15 175 switch ( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart, typeControlPartCode) )
e40298d5
JS
176 {
177 case kControlUpButtonPart :
178 nScrollInc = 1;
43524b15
DS
179 break;
180
e40298d5
JS
181 case kControlDownButtonPart :
182 nScrollInc = -1;
43524b15
DS
183 break;
184
185 default :
186 break;
e40298d5 187 }
43524b15 188
e40298d5 189 MacHandleValueChanged( nScrollInc ) ;
43524b15 190#endif
a54b0880 191
43524b15
DS
192 return noErr;
193}
51abe921 194
37e2cb08 195wxSize wxSpinButton::DoGetBestSize() const
51abe921 196{
43524b15 197 return wxSize( 16, 24 );
51abe921 198}
519cb848 199
312ebad4 200#endif // wxUSE_SPINBTN