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