]>
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 | ||
312ebad4 WS |
12 | #include "wx/defs.h" |
13 | ||
14 | #if wxUSE_SPINBTN | |
15 | ||
2646f485 SC |
16 | #include "wx/spinbutt.h" |
17 | #include "wx/mac/uma.h" | |
18 | ||
19 | // ============================================================================ | |
20 | // implementation | |
21 | // ============================================================================ | |
22 | ||
23 | // ---------------------------------------------------------------------------- | |
24 | // wxWin macros | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
62f864c3 VZ |
27 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) |
28 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent) | |
2646f485 SC |
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; | |
312ebad4 | 44 | |
2646f485 | 45 | if (!parent) |
312ebad4 WS |
46 | return false; |
47 | ||
2646f485 SC |
48 | Rect bounds ; |
49 | Str255 title ; | |
312ebad4 | 50 | |
2646f485 | 51 | MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ; |
312ebad4 WS |
52 | |
53 | m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100, | |
2646f485 | 54 | kControlLittleArrowsProc , (long) this ) ; |
312ebad4 | 55 | |
2646f485 | 56 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; |
312ebad4 | 57 | |
2646f485 | 58 | MacPostControlCreate() ; |
312ebad4 WS |
59 | |
60 | return true; | |
2646f485 | 61 | } |
312ebad4 | 62 | |
2646f485 SC |
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 | { | |
6511d307 RR |
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; | |
2646f485 SC |
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 | { | |
312ebad4 | 105 | |
2646f485 SC |
106 | wxEventType scrollEvent = wxEVT_NULL; |
107 | int oldValue = m_value ; | |
312ebad4 | 108 | |
2646f485 | 109 | m_value = oldValue + inc; |
312ebad4 | 110 | |
2646f485 SC |
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 | } | |
312ebad4 | 118 | |
2646f485 SC |
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 | } | |
312ebad4 | 126 | |
2646f485 SC |
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 ; | |
312ebad4 | 133 | |
2646f485 | 134 | wxSpinEvent event(scrollEvent, m_windowId); |
312ebad4 | 135 | |
2646f485 SC |
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 ) ; | |
312ebad4 | 144 | |
2646f485 SC |
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 | ||
312ebad4 | 156 | void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) |
2646f485 SC |
157 | { |
158 | if ( (ControlHandle) m_macControl == NULL ) | |
159 | return ; | |
312ebad4 | 160 | |
2646f485 | 161 | int nScrollInc = 0; |
312ebad4 | 162 | |
2646f485 SC |
163 | switch( controlpart ) |
164 | { | |
165 | case kControlUpButtonPart : | |
166 | nScrollInc = 1; | |
167 | break ; | |
168 | case kControlDownButtonPart : | |
169 | nScrollInc = -1; | |
170 | break ; | |
171 | } | |
172 | MacHandleValueChanged( nScrollInc ) ; | |
312ebad4 | 173 | |
2646f485 SC |
174 | } |
175 | ||
176 | // ---------------------------------------------------------------------------- | |
177 | // size calculation | |
178 | // ---------------------------------------------------------------------------- | |
179 | ||
180 | wxSize wxSpinButton::DoGetBestSize() const | |
181 | { | |
182 | return wxSize(16,24); | |
183 | } | |
184 | ||
312ebad4 | 185 | #endif // wxUSE_SPINBTN |