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