]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/spinbutt.cpp
wx/wxprec.h already includes wx/defs.h (with other minor cleaning).
[wxWidgets.git] / src / mac / classic / spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/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 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_SPINBTN
19
20 #include "wx/spinbutt.h"
21 #include "wx/mac/uma.h"
22
23 // ============================================================================
24 // implementation
25 // ============================================================================
26
27 // ----------------------------------------------------------------------------
28 // wxWin macros
29 // ----------------------------------------------------------------------------
30
31 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
32 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
33
34 wxSpinButton::wxSpinButton()
35 : wxSpinButtonBase()
36 {
37 }
38
39 bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
40 long style, const wxString& name)
41 {
42 if ( !wxSpinButtonBase::Create(parent, id, pos, size,
43 style, wxDefaultValidator, name) )
44 return false;
45
46 m_min = 0;
47 m_max = 100;
48
49 if (!parent)
50 return false;
51
52 Rect bounds ;
53 Str255 title ;
54
55 MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
56
57 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100,
58 kControlLittleArrowsProc , (long) this ) ;
59
60 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
61
62 MacPostControlCreate() ;
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 int n = m_value;
87
88 if (n < m_min) n = m_min;
89 if (n > m_max) n = m_max;
90
91 return n;
92 }
93
94 void wxSpinButton::SetValue(int val)
95 {
96 m_value = val ;
97 }
98
99 void wxSpinButton::SetRange(int minVal, int maxVal)
100 {
101 m_min = minVal;
102 m_max = maxVal;
103 SetControl32BitMaximum( (ControlHandle) m_macControl , maxVal ) ;
104 SetControl32BitMinimum((ControlHandle) m_macControl , minVal ) ;
105 }
106
107 void wxSpinButton::MacHandleValueChanged( int inc )
108 {
109
110 wxEventType scrollEvent = wxEVT_NULL;
111 int oldValue = m_value ;
112
113 m_value = oldValue + inc;
114
115 if (m_value < m_min)
116 {
117 if ( m_windowStyle & wxSP_WRAP )
118 m_value = m_max;
119 else
120 m_value = m_min;
121 }
122
123 if (m_value > m_max)
124 {
125 if ( m_windowStyle & wxSP_WRAP )
126 m_value = m_min;
127 else
128 m_value = m_max;
129 }
130
131 if ( m_value - oldValue == -1 )
132 scrollEvent = wxEVT_SCROLL_LINEDOWN ;
133 else if ( m_value - oldValue == 1 )
134 scrollEvent = wxEVT_SCROLL_LINEUP ;
135 else
136 scrollEvent = wxEVT_SCROLL_THUMBTRACK ;
137
138 wxSpinEvent event(scrollEvent, m_windowId);
139
140 event.SetPosition(m_value);
141 event.SetEventObject( this );
142 if ((GetEventHandler()->ProcessEvent( event )) &&
143 !event.IsAllowed() )
144 {
145 m_value = oldValue ;
146 }
147 SetControl32BitValue( (ControlHandle) m_macControl , m_value ) ;
148
149 /* always send a thumbtrack event */
150 if (scrollEvent != wxEVT_SCROLL_THUMBTRACK)
151 {
152 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
153 wxSpinEvent event2( scrollEvent, GetId());
154 event2.SetPosition( m_value );
155 event2.SetEventObject( this );
156 GetEventHandler()->ProcessEvent( event2 );
157 }
158 }
159
160 void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
161 {
162 if ( (ControlHandle) m_macControl == NULL )
163 return ;
164
165 int nScrollInc = 0;
166
167 switch( controlpart )
168 {
169 case kControlUpButtonPart :
170 nScrollInc = 1;
171 break ;
172 case kControlDownButtonPart :
173 nScrollInc = -1;
174 break ;
175 }
176 MacHandleValueChanged( nScrollInc ) ;
177
178 }
179
180 // ----------------------------------------------------------------------------
181 // size calculation
182 // ----------------------------------------------------------------------------
183
184 wxSize wxSpinButton::DoGetBestSize() const
185 {
186 return wxSize(16,24);
187 }
188
189 #endif // wxUSE_SPINBTN