]>
Commit | Line | Data |
---|---|---|
2646f485 SC |
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 | |
65571936 | 9 | // Licence: wxWindows licence |
2646f485 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "spinbutt.h" | |
14 | #pragma implementation "spinbuttbase.h" | |
15 | #endif | |
16 | ||
312ebad4 WS |
17 | #include "wx/defs.h" |
18 | ||
19 | #if wxUSE_SPINBTN | |
20 | ||
2646f485 SC |
21 | #include "wx/spinbutt.h" |
22 | #include "wx/mac/uma.h" | |
23 | ||
24 | // ============================================================================ | |
25 | // implementation | |
26 | // ============================================================================ | |
27 | ||
28 | // ---------------------------------------------------------------------------- | |
29 | // wxWin macros | |
30 | // ---------------------------------------------------------------------------- | |
31 | ||
62f864c3 VZ |
32 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) |
33 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent) | |
2646f485 SC |
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; | |
312ebad4 | 49 | |
2646f485 | 50 | if (!parent) |
312ebad4 WS |
51 | return false; |
52 | ||
2646f485 SC |
53 | Rect bounds ; |
54 | Str255 title ; | |
312ebad4 | 55 | |
2646f485 | 56 | MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ; |
312ebad4 WS |
57 | |
58 | m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100, | |
2646f485 | 59 | kControlLittleArrowsProc , (long) this ) ; |
312ebad4 | 60 | |
2646f485 | 61 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; |
312ebad4 | 62 | |
2646f485 | 63 | MacPostControlCreate() ; |
312ebad4 WS |
64 | |
65 | return true; | |
2646f485 | 66 | } |
312ebad4 | 67 | |
2646f485 SC |
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 | { | |
6511d307 RR |
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; | |
2646f485 SC |
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 | { | |
312ebad4 | 110 | |
2646f485 SC |
111 | wxEventType scrollEvent = wxEVT_NULL; |
112 | int oldValue = m_value ; | |
312ebad4 | 113 | |
2646f485 | 114 | m_value = oldValue + inc; |
312ebad4 | 115 | |
2646f485 SC |
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 | } | |
312ebad4 | 123 | |
2646f485 SC |
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 | } | |
312ebad4 | 131 | |
2646f485 SC |
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 ; | |
312ebad4 | 138 | |
2646f485 | 139 | wxSpinEvent event(scrollEvent, m_windowId); |
312ebad4 | 140 | |
2646f485 SC |
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 ) ; | |
312ebad4 | 149 | |
2646f485 SC |
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 | ||
312ebad4 | 161 | void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) |
2646f485 SC |
162 | { |
163 | if ( (ControlHandle) m_macControl == NULL ) | |
164 | return ; | |
312ebad4 | 165 | |
2646f485 | 166 | int nScrollInc = 0; |
312ebad4 | 167 | |
2646f485 SC |
168 | switch( controlpart ) |
169 | { | |
170 | case kControlUpButtonPart : | |
171 | nScrollInc = 1; | |
172 | break ; | |
173 | case kControlDownButtonPart : | |
174 | nScrollInc = -1; | |
175 | break ; | |
176 | } | |
177 | MacHandleValueChanged( nScrollInc ) ; | |
312ebad4 | 178 | |
2646f485 SC |
179 | } |
180 | ||
181 | // ---------------------------------------------------------------------------- | |
182 | // size calculation | |
183 | // ---------------------------------------------------------------------------- | |
184 | ||
185 | wxSize wxSpinButton::DoGetBestSize() const | |
186 | { | |
187 | return wxSize(16,24); | |
188 | } | |
189 | ||
312ebad4 | 190 | #endif // wxUSE_SPINBTN |