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