]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/spinbutt.cpp
fixed bug due to missing break in GetColourFromGTKWidget() (part of patch 1160117)
[wxWidgets.git] / src / mac / classic / 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 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 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 ;
56 Str255 title ;
57
58 MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
59
60 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100,
61 kControlLittleArrowsProc , (long) this ) ;
62
63 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
64
65 MacPostControlCreate() ;
66
67 return true;
68 }
69
70 wxSpinButton::~wxSpinButton()
71 {
72 }
73
74 // Attributes
75 ////////////////////////////////////////////////////////////////////////////
76
77 int wxSpinButton::GetMin() const
78 {
79 return m_min;
80 }
81
82 int wxSpinButton::GetMax() const
83 {
84 return m_max;
85 }
86
87 int wxSpinButton::GetValue() const
88 {
89 int n = m_value;
90
91 if (n < m_min) n = m_min;
92 if (n > m_max) n = m_max;
93
94 return n;
95 }
96
97 void wxSpinButton::SetValue(int val)
98 {
99 m_value = val ;
100 }
101
102 void wxSpinButton::SetRange(int minVal, int maxVal)
103 {
104 m_min = minVal;
105 m_max = maxVal;
106 SetControl32BitMaximum( (ControlHandle) m_macControl , maxVal ) ;
107 SetControl32BitMinimum((ControlHandle) m_macControl , minVal ) ;
108 }
109
110 void wxSpinButton::MacHandleValueChanged( int inc )
111 {
112
113 wxEventType scrollEvent = wxEVT_NULL;
114 int oldValue = m_value ;
115
116 m_value = oldValue + inc;
117
118 if (m_value < m_min)
119 {
120 if ( m_windowStyle & wxSP_WRAP )
121 m_value = m_max;
122 else
123 m_value = m_min;
124 }
125
126 if (m_value > m_max)
127 {
128 if ( m_windowStyle & wxSP_WRAP )
129 m_value = m_min;
130 else
131 m_value = m_max;
132 }
133
134 if ( m_value - oldValue == -1 )
135 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
136 else if ( m_value - oldValue == 1 )
137 scrollEvent = wxEVT_SCROLL_LINEUP ;
138 else
139 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
140
141 wxSpinEvent event(scrollEvent, m_windowId);
142
143 event.SetPosition(m_value);
144 event.SetEventObject( this );
145 if ((GetEventHandler()->ProcessEvent( event )) &&
146 !event.IsAllowed() )
147 {
148 m_value = oldValue ;
149 }
150 SetControl32BitValue( (ControlHandle) m_macControl , m_value ) ;
151
152 /* always send a thumbtrack event */
153 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
154 {
155 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
156 wxSpinEvent event2( scrollEvent, GetId());
157 event2.SetPosition( m_value );
158 event2.SetEventObject( this );
159 GetEventHandler()->ProcessEvent( event2 );
160 }
161 }
162
163 void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
164 {
165 if ( (ControlHandle) m_macControl == NULL )
166 return ;
167
168 int nScrollInc = 0;
169
170 switch( controlpart )
171 {
172 case kControlUpButtonPart :
173 nScrollInc = 1;
174 break ;
175 case kControlDownButtonPart :
176 nScrollInc = -1;
177 break ;
178 }
179 MacHandleValueChanged( nScrollInc ) ;
180
181 }
182
183 // ----------------------------------------------------------------------------
184 // size calculation
185 // ----------------------------------------------------------------------------
186
187 wxSize wxSpinButton::DoGetBestSize() const
188 {
189 return wxSize(16,24);
190 }
191
192 #endif // wxUSE_SPINBTN