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