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