]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/spinbutt.cpp
corrected preproc condition
[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
e40298d5 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
03e11df5
GD
33wxSpinButton::wxSpinButton()
34 : wxSpinButtonBase()
35{
36}
37
e9576ca5 38bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
e40298d5 39 long style, const wxString& name)
e9576ca5 40{
facd6764
SC
41 m_macIsUserPane = FALSE ;
42
b45ed7a2
VZ
43 if ( !wxSpinButtonBase::Create(parent, id, pos, size,
44 style, wxDefaultValidator, name) )
45 return false;
46
e9576ca5
SC
47 m_min = 0;
48 m_max = 100;
519cb848 49
e40298d5
JS
50 if (!parent)
51 return FALSE;
52
facd6764 53 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
4c37f124
SC
54
55 verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , 0 , m_min , m_max , 1 ,
56 (ControlRef*) &m_macControl ) ) ;
e40298d5 57
facd6764 58 MacPostControlCreate(pos,size) ;
e40298d5
JS
59
60 return TRUE;
e9576ca5 61}
e40298d5 62
e9576ca5
SC
63wxSpinButton::~wxSpinButton()
64{
65}
66
67// Attributes
68////////////////////////////////////////////////////////////////////////////
69
03e11df5
GD
70int wxSpinButton::GetMin() const
71{
e40298d5 72 return m_min;
03e11df5
GD
73}
74
75int wxSpinButton::GetMax() const
76{
e40298d5 77 return m_max;
03e11df5
GD
78}
79
e9576ca5
SC
80int wxSpinButton::GetValue() const
81{
519cb848 82 return m_value;
e9576ca5
SC
83}
84
85void wxSpinButton::SetValue(int val)
86{
e40298d5 87 m_value = val ;
e9576ca5
SC
88}
89
90void wxSpinButton::SetRange(int minVal, int maxVal)
91{
e40298d5
JS
92 m_min = minVal;
93 m_max = maxVal;
facd6764
SC
94 SetControl32BitMaximum( (ControlRef) m_macControl , maxVal ) ;
95 SetControl32BitMinimum((ControlRef) m_macControl , minVal ) ;
e9576ca5
SC
96}
97
a54b0880 98void wxSpinButton::MacHandleValueChanged( int inc )
519cb848 99{
e40298d5 100
a54b0880 101 wxEventType scrollEvent = wxEVT_NULL;
e40298d5
JS
102 int oldValue = m_value ;
103
a54b0880 104 m_value = oldValue + inc;
e40298d5 105
a54b0880
SC
106 if (m_value < m_min)
107 {
e40298d5
JS
108 if ( m_windowStyle & wxSP_WRAP )
109 m_value = m_max;
110 else
111 m_value = m_min;
a54b0880 112 }
e40298d5 113
a54b0880
SC
114 if (m_value > m_max)
115 {
e40298d5
JS
116 if ( m_windowStyle & wxSP_WRAP )
117 m_value = m_min;
118 else
119 m_value = m_max;
a54b0880 120 }
e40298d5 121
92432aa1 122 if ( m_value - oldValue == -1 )
a54b0880 123 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
92432aa1 124 else if ( m_value - oldValue == 1 )
a54b0880
SC
125 scrollEvent = wxEVT_SCROLL_LINEUP ;
126 else
127 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
e40298d5 128
a54b0880 129 wxSpinEvent event(scrollEvent, m_windowId);
e40298d5 130
a54b0880
SC
131 event.SetPosition(m_value);
132 event.SetEventObject( this );
133 if ((GetEventHandler()->ProcessEvent( event )) &&
72d750d4 134 !event.IsAllowed() )
a54b0880
SC
135 {
136 m_value = oldValue ;
137 }
facd6764 138 SetControl32BitValue( (ControlRef) m_macControl , m_value ) ;
e40298d5 139
72d750d4
SC
140 /* always send a thumbtrack event */
141 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
142 {
143 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
144 wxSpinEvent event2( scrollEvent, GetId());
145 event2.SetPosition( m_value );
146 event2.SetEventObject( this );
147 GetEventHandler()->ProcessEvent( event2 );
148 }
519cb848
SC
149}
150
4c37f124 151wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event )
a54b0880 152{
e40298d5 153 int nScrollInc = 0;
4c37f124 154 wxMacCarbonEvent cEvent( (EventRef) event ) ;
e40298d5 155
4c37f124 156 switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) )
e40298d5
JS
157 {
158 case kControlUpButtonPart :
159 nScrollInc = 1;
160 break ;
161 case kControlDownButtonPart :
162 nScrollInc = -1;
163 break ;
164 }
165 MacHandleValueChanged( nScrollInc ) ;
4c37f124 166 return noErr ;
a54b0880
SC
167}
168
51abe921
SC
169// ----------------------------------------------------------------------------
170// size calculation
171// ----------------------------------------------------------------------------
172
37e2cb08 173wxSize wxSpinButton::DoGetBestSize() const
51abe921 174{
e40298d5 175 return wxSize(16,24);
51abe921 176}
519cb848 177