]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/spinbutt.cpp
security fix to wxSingleInstanceChecker: check if the lock file was really created...
[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
12#ifdef __GNUG__
13#pragma implementation "spinbutt.h"
03e11df5 14#pragma implementation "spinbuttbase.h"
e9576ca5
SC
15#endif
16
17#include "wx/spinbutt.h"
519cb848 18#include "wx/mac/uma.h"
e9576ca5 19
e7549107
SC
20// ============================================================================
21// implementation
22// ============================================================================
23
24// ----------------------------------------------------------------------------
25// wxWin macros
26// ----------------------------------------------------------------------------
27
2f1ae414 28#if !USE_SHARED_LIBRARY
e7549107 29 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
d84afea9 30 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
2f1ae414 31#endif
e9576ca5 32
64be92e2
SC
33extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
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{
facd6764
SC
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;
519cb848 51
e40298d5
JS
52 if (!parent)
53 return FALSE;
54
facd6764 55 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
4c37f124
SC
56
57 verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , 0 , m_min , m_max , 1 ,
58 (ControlRef*) &m_macControl ) ) ;
64be92e2 59 SetControlAction( (ControlRef) m_macControl , wxMacLiveScrollbarActionUPP ) ;
facd6764 60 MacPostControlCreate(pos,size) ;
e40298d5
JS
61
62 return TRUE;
e9576ca5 63}
e40298d5 64
e9576ca5
SC
65wxSpinButton::~wxSpinButton()
66{
67}
68
69// Attributes
70////////////////////////////////////////////////////////////////////////////
71
03e11df5
GD
72int wxSpinButton::GetMin() const
73{
e40298d5 74 return m_min;
03e11df5
GD
75}
76
77int wxSpinButton::GetMax() const
78{
e40298d5 79 return m_max;
03e11df5
GD
80}
81
e9576ca5
SC
82int wxSpinButton::GetValue() const
83{
519cb848 84 return m_value;
e9576ca5
SC
85}
86
87void wxSpinButton::SetValue(int val)
88{
e40298d5 89 m_value = val ;
e9576ca5
SC
90}
91
92void wxSpinButton::SetRange(int minVal, int maxVal)
93{
e40298d5
JS
94 m_min = minVal;
95 m_max = maxVal;
facd6764
SC
96 SetControl32BitMaximum( (ControlRef) m_macControl , maxVal ) ;
97 SetControl32BitMinimum((ControlRef) m_macControl , minVal ) ;
e9576ca5
SC
98}
99
a54b0880 100void wxSpinButton::MacHandleValueChanged( int inc )
519cb848 101{
e40298d5 102
a54b0880 103 wxEventType scrollEvent = wxEVT_NULL;
e40298d5
JS
104 int oldValue = m_value ;
105
a54b0880 106 m_value = oldValue + inc;
e40298d5 107
a54b0880
SC
108 if (m_value < m_min)
109 {
e40298d5
JS
110 if ( m_windowStyle & wxSP_WRAP )
111 m_value = m_max;
112 else
113 m_value = m_min;
a54b0880 114 }
e40298d5 115
a54b0880
SC
116 if (m_value > m_max)
117 {
e40298d5
JS
118 if ( m_windowStyle & wxSP_WRAP )
119 m_value = m_min;
120 else
121 m_value = m_max;
a54b0880 122 }
e40298d5 123
92432aa1 124 if ( m_value - oldValue == -1 )
a54b0880 125 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
92432aa1 126 else if ( m_value - oldValue == 1 )
a54b0880
SC
127 scrollEvent = wxEVT_SCROLL_LINEUP ;
128 else
129 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
e40298d5 130
a54b0880 131 wxSpinEvent event(scrollEvent, m_windowId);
e40298d5 132
a54b0880
SC
133 event.SetPosition(m_value);
134 event.SetEventObject( this );
135 if ((GetEventHandler()->ProcessEvent( event )) &&
72d750d4 136 !event.IsAllowed() )
a54b0880
SC
137 {
138 m_value = oldValue ;
139 }
facd6764 140 SetControl32BitValue( (ControlRef) m_macControl , m_value ) ;
e40298d5 141
72d750d4
SC
142 /* always send a thumbtrack event */
143 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
144 {
145 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
146 wxSpinEvent event2( scrollEvent, GetId());
147 event2.SetPosition( m_value );
148 event2.SetEventObject( this );
149 GetEventHandler()->ProcessEvent( event2 );
150 }
519cb848
SC
151}
152
64be92e2
SC
153void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
154{
155 int nScrollInc = 0;
156
157 switch( controlpart )
158 {
159 case kControlUpButtonPart :
160 nScrollInc = 1;
161 break ;
162 case kControlDownButtonPart :
163 nScrollInc = -1;
164 break ;
165 }
166 MacHandleValueChanged( nScrollInc ) ;
167}
168
4c37f124 169wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event )
a54b0880 170{
64be92e2
SC
171 /*
172 // these have been handled by the live action proc already
e40298d5 173 int nScrollInc = 0;
4c37f124 174 wxMacCarbonEvent cEvent( (EventRef) event ) ;
e40298d5 175
4c37f124 176 switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) )
e40298d5
JS
177 {
178 case kControlUpButtonPart :
179 nScrollInc = 1;
180 break ;
181 case kControlDownButtonPart :
182 nScrollInc = -1;
183 break ;
184 }
185 MacHandleValueChanged( nScrollInc ) ;
64be92e2 186 */
4c37f124 187 return noErr ;
a54b0880
SC
188}
189
51abe921
SC
190// ----------------------------------------------------------------------------
191// size calculation
192// ----------------------------------------------------------------------------
193
37e2cb08 194wxSize wxSpinButton::DoGetBestSize() const
51abe921 195{
e40298d5 196 return wxSize(16,24);
51abe921 197}
519cb848 198