]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/spinbutt.cpp
Unwanted semicolon fix [#1212497] + source cleaning.
[wxWidgets.git] / src / mac / carbon / spinbutt.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: spinbutt.cpp
3// Purpose: wxSpinButton
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13#pragma implementation "spinbutt.h"
14#pragma implementation "spinbuttbase.h"
15#endif
16
17#include "wx/wxprec.h"
18
19#if wxUSE_SPINBTN
20
21#include "wx/spinbutt.h"
22#include "wx/mac/uma.h"
23
24// ============================================================================
25// implementation
26// ============================================================================
27
28// ----------------------------------------------------------------------------
29// wxWin macros
30// ----------------------------------------------------------------------------
31
32IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
33IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
34
35wxSpinButton::wxSpinButton()
36 : wxSpinButtonBase()
37{
38}
39
40bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
41 long style, const wxString& name)
42{
43 m_macIsUserPane = false ;
44
45 if ( !wxSpinButtonBase::Create(parent, id, pos, size,
46 style, wxDefaultValidator, name) )
47 return false;
48
49 m_min = 0;
50 m_max = 100;
51
52 if (!parent)
53 return false;
54
55 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
56
57 m_peer = new wxMacControl(this) ;
58 verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , 0 , m_min , m_max , 1 ,
59 m_peer->GetControlRefAddr() ) );
60
61 m_peer->SetActionProc( GetwxMacLiveScrollbarActionProc() ) ;
62 MacPostControlCreate(pos,size) ;
63
64 return true;
65}
66
67wxSpinButton::~wxSpinButton()
68{
69}
70
71// Attributes
72////////////////////////////////////////////////////////////////////////////
73
74int wxSpinButton::GetMin() const
75{
76 return m_min;
77}
78
79int wxSpinButton::GetMax() const
80{
81 return m_max;
82}
83
84int wxSpinButton::GetValue() const
85{
86 int n = m_value;
87
88 if (n < m_min) n = m_min;
89 if (n > m_max) n = m_max;
90
91 return n;
92}
93
94void wxSpinButton::SetValue(int val)
95{
96 m_value = val ;
97}
98
99void wxSpinButton::SetRange(int minVal, int maxVal)
100{
101 m_min = minVal;
102 m_max = maxVal;
103 m_peer->SetMaximum( maxVal ) ;
104 m_peer->SetMinimum( minVal ) ;
105}
106
107void wxSpinButton::MacHandleValueChanged( int inc )
108{
109
110 wxEventType scrollEvent = wxEVT_NULL;
111 int oldValue = m_value ;
112
113 m_value = oldValue + inc;
114
115 if (m_value < m_min)
116 {
117 if ( m_windowStyle & wxSP_WRAP )
118 m_value = m_max;
119 else
120 m_value = m_min;
121 }
122
123 if (m_value > m_max)
124 {
125 if ( m_windowStyle & wxSP_WRAP )
126 m_value = m_min;
127 else
128 m_value = m_max;
129 }
130
131 if ( m_value - oldValue == -1 )
132 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
133 else if ( m_value - oldValue == 1 )
134 scrollEvent = wxEVT_SCROLL_LINEUP ;
135 else
136 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
137
138 wxSpinEvent event(scrollEvent, m_windowId);
139
140 event.SetPosition(m_value);
141 event.SetEventObject( this );
142 if ((GetEventHandler()->ProcessEvent( event )) &&
143 !event.IsAllowed() )
144 {
145 m_value = oldValue ;
146 }
147 m_peer->SetValue( m_value ) ;
148
149 /* always send a thumbtrack event */
150 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
151 {
152 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
153 wxSpinEvent event2( scrollEvent, GetId());
154 event2.SetPosition( m_value );
155 event2.SetEventObject( this );
156 GetEventHandler()->ProcessEvent( event2 );
157 }
158}
159
160void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
161{
162 int nScrollInc = 0;
163
164 switch( controlpart )
165 {
166 case kControlUpButtonPart :
167 nScrollInc = 1;
168 break ;
169 case kControlDownButtonPart :
170 nScrollInc = -1;
171 break ;
172 }
173 MacHandleValueChanged( nScrollInc ) ;
174}
175
176wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event )
177{
178 /*
179 // these have been handled by the live action proc already
180 int nScrollInc = 0;
181 wxMacCarbonEvent cEvent( (EventRef) event ) ;
182
183 switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) )
184 {
185 case kControlUpButtonPart :
186 nScrollInc = 1;
187 break ;
188 case kControlDownButtonPart :
189 nScrollInc = -1;
190 break ;
191 }
192 MacHandleValueChanged( nScrollInc ) ;
193 */
194 return noErr ;
195}
196
197// ----------------------------------------------------------------------------
198// size calculation
199// ----------------------------------------------------------------------------
200
201wxSize wxSpinButton::DoGetBestSize() const
202{
203 return wxSize(16,24);
204}
205
206#endif // wxUSE_SPINBTN