]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/spinbutt.cpp
switching to CreateXXX methods for Controls and to Hit Event Processing, thus 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 wxSpinButton::wxSpinButton()
34 : wxSpinButtonBase()
35 {
36 }
37
38 bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
39 long style, const wxString& name)
40 {
41 m_macIsUserPane = FALSE ;
42
43 if ( !wxSpinButtonBase::Create(parent, id, pos, size,
44 style, wxDefaultValidator, name) )
45 return false;
46
47 m_min = 0;
48 m_max = 100;
49
50 if (!parent)
51 return FALSE;
52
53 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
54
55 verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , 0 , m_min , m_max , 1 ,
56 (ControlRef*) &m_macControl ) ) ;
57
58 MacPostControlCreate(pos,size) ;
59
60 return TRUE;
61 }
62
63 wxSpinButton::~wxSpinButton()
64 {
65 }
66
67 // Attributes
68 ////////////////////////////////////////////////////////////////////////////
69
70 int wxSpinButton::GetMin() const
71 {
72 return m_min;
73 }
74
75 int wxSpinButton::GetMax() const
76 {
77 return m_max;
78 }
79
80 int wxSpinButton::GetValue() const
81 {
82 return m_value;
83 }
84
85 void wxSpinButton::SetValue(int val)
86 {
87 m_value = val ;
88 }
89
90 void wxSpinButton::SetRange(int minVal, int maxVal)
91 {
92 m_min = minVal;
93 m_max = maxVal;
94 SetControl32BitMaximum( (ControlRef) m_macControl , maxVal ) ;
95 SetControl32BitMinimum((ControlRef) m_macControl , minVal ) ;
96 }
97
98 void wxSpinButton::MacHandleValueChanged( int inc )
99 {
100
101 wxEventType scrollEvent = wxEVT_NULL;
102 int oldValue = m_value ;
103
104 m_value = oldValue + inc;
105
106 if (m_value < m_min)
107 {
108 if ( m_windowStyle & wxSP_WRAP )
109 m_value = m_max;
110 else
111 m_value = m_min;
112 }
113
114 if (m_value > m_max)
115 {
116 if ( m_windowStyle & wxSP_WRAP )
117 m_value = m_min;
118 else
119 m_value = m_max;
120 }
121
122 if ( m_value - oldValue == -1 )
123 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
124 else if ( m_value - oldValue == 1 )
125 scrollEvent = wxEVT_SCROLL_LINEUP ;
126 else
127 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
128
129 wxSpinEvent event(scrollEvent, m_windowId);
130
131 event.SetPosition(m_value);
132 event.SetEventObject( this );
133 if ((GetEventHandler()->ProcessEvent( event )) &&
134 !event.IsAllowed() )
135 {
136 m_value = oldValue ;
137 }
138 SetControl32BitValue( (ControlRef) m_macControl , m_value ) ;
139
140 /* always send a thumbtrack event */
141 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
142 {
143 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
144 wxSpinEvent event2( scrollEvent, GetId());
145 event2.SetPosition( m_value );
146 event2.SetEventObject( this );
147 GetEventHandler()->ProcessEvent( event2 );
148 }
149 }
150
151 wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event )
152 {
153 int nScrollInc = 0;
154 wxMacCarbonEvent cEvent( (EventRef) event ) ;
155
156 switch( cEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) )
157 {
158 case kControlUpButtonPart :
159 nScrollInc = 1;
160 break ;
161 case kControlDownButtonPart :
162 nScrollInc = -1;
163 break ;
164 }
165 MacHandleValueChanged( nScrollInc ) ;
166 return noErr ;
167 }
168
169 // ----------------------------------------------------------------------------
170 // size calculation
171 // ----------------------------------------------------------------------------
172
173 wxSize wxSpinButton::DoGetBestSize() const
174 {
175 return wxSize(16,24);
176 }
177