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