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