]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: spinbutt.cpp | |
3 | // Purpose: wxSpinButton | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
e40298d5 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "spinbutt.h" | |
03e11df5 | 14 | #pragma implementation "spinbuttbase.h" |
e9576ca5 SC |
15 | #endif |
16 | ||
17 | #include "wx/spinbutt.h" | |
519cb848 | 18 | #include "wx/mac/uma.h" |
e9576ca5 | 19 | |
e7549107 SC |
20 | // ============================================================================ |
21 | // implementation | |
22 | // ============================================================================ | |
23 | ||
24 | // ---------------------------------------------------------------------------- | |
25 | // wxWin macros | |
26 | // ---------------------------------------------------------------------------- | |
27 | ||
2f1ae414 | 28 | #if !USE_SHARED_LIBRARY |
e7549107 | 29 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) |
d84afea9 | 30 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent) |
2f1ae414 | 31 | #endif |
e9576ca5 | 32 | |
03e11df5 GD |
33 | wxSpinButton::wxSpinButton() |
34 | : wxSpinButtonBase() | |
35 | { | |
36 | } | |
37 | ||
e9576ca5 | 38 | bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, |
e40298d5 | 39 | long style, const wxString& name) |
e9576ca5 | 40 | { |
facd6764 SC |
41 | m_macIsUserPane = FALSE ; |
42 | ||
b45ed7a2 VZ |
43 | if ( !wxSpinButtonBase::Create(parent, id, pos, size, |
44 | style, wxDefaultValidator, name) ) | |
45 | return false; | |
46 | ||
e9576ca5 SC |
47 | m_min = 0; |
48 | m_max = 100; | |
519cb848 | 49 | |
e40298d5 JS |
50 | if (!parent) |
51 | return FALSE; | |
52 | ||
facd6764 | 53 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; |
e40298d5 | 54 | |
facd6764 | 55 | m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 100, |
e40298d5 JS |
56 | kControlLittleArrowsProc , (long) this ) ; |
57 | ||
facd6764 | 58 | wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; |
e40298d5 | 59 | |
facd6764 | 60 | MacPostControlCreate(pos,size) ; |
e40298d5 JS |
61 | |
62 | return TRUE; | |
e9576ca5 | 63 | } |
e40298d5 | 64 | |
e9576ca5 SC |
65 | wxSpinButton::~wxSpinButton() |
66 | { | |
67 | } | |
68 | ||
69 | // Attributes | |
70 | //////////////////////////////////////////////////////////////////////////// | |
71 | ||
03e11df5 GD |
72 | int wxSpinButton::GetMin() const |
73 | { | |
e40298d5 | 74 | return m_min; |
03e11df5 GD |
75 | } |
76 | ||
77 | int wxSpinButton::GetMax() const | |
78 | { | |
e40298d5 | 79 | return m_max; |
03e11df5 GD |
80 | } |
81 | ||
e9576ca5 SC |
82 | int wxSpinButton::GetValue() const |
83 | { | |
519cb848 | 84 | return m_value; |
e9576ca5 SC |
85 | } |
86 | ||
87 | void wxSpinButton::SetValue(int val) | |
88 | { | |
e40298d5 | 89 | m_value = val ; |
e9576ca5 SC |
90 | } |
91 | ||
92 | void wxSpinButton::SetRange(int minVal, int maxVal) | |
93 | { | |
e40298d5 JS |
94 | m_min = minVal; |
95 | m_max = maxVal; | |
facd6764 SC |
96 | SetControl32BitMaximum( (ControlRef) m_macControl , maxVal ) ; |
97 | SetControl32BitMinimum((ControlRef) m_macControl , minVal ) ; | |
e9576ca5 SC |
98 | } |
99 | ||
a54b0880 | 100 | void wxSpinButton::MacHandleValueChanged( int inc ) |
519cb848 | 101 | { |
e40298d5 | 102 | |
a54b0880 | 103 | wxEventType scrollEvent = wxEVT_NULL; |
e40298d5 JS |
104 | int oldValue = m_value ; |
105 | ||
a54b0880 | 106 | m_value = oldValue + inc; |
e40298d5 | 107 | |
a54b0880 SC |
108 | if (m_value < m_min) |
109 | { | |
e40298d5 JS |
110 | if ( m_windowStyle & wxSP_WRAP ) |
111 | m_value = m_max; | |
112 | else | |
113 | m_value = m_min; | |
a54b0880 | 114 | } |
e40298d5 | 115 | |
a54b0880 SC |
116 | if (m_value > m_max) |
117 | { | |
e40298d5 JS |
118 | if ( m_windowStyle & wxSP_WRAP ) |
119 | m_value = m_min; | |
120 | else | |
121 | m_value = m_max; | |
a54b0880 | 122 | } |
e40298d5 | 123 | |
92432aa1 | 124 | if ( m_value - oldValue == -1 ) |
a54b0880 | 125 | scrollEvent = wxEVT_SCROLL_LINEDOWN ; |
92432aa1 | 126 | else if ( m_value - oldValue == 1 ) |
a54b0880 SC |
127 | scrollEvent = wxEVT_SCROLL_LINEUP ; |
128 | else | |
129 | scrollEvent = wxEVT_SCROLL_THUMBTRACK ; | |
e40298d5 | 130 | |
a54b0880 | 131 | wxSpinEvent event(scrollEvent, m_windowId); |
e40298d5 | 132 | |
a54b0880 SC |
133 | event.SetPosition(m_value); |
134 | event.SetEventObject( this ); | |
135 | if ((GetEventHandler()->ProcessEvent( event )) && | |
72d750d4 | 136 | !event.IsAllowed() ) |
a54b0880 SC |
137 | { |
138 | m_value = oldValue ; | |
139 | } | |
facd6764 | 140 | SetControl32BitValue( (ControlRef) m_macControl , m_value ) ; |
e40298d5 | 141 | |
72d750d4 SC |
142 | /* always send a thumbtrack event */ |
143 | if (scrollEvent != wxEVT_SCROLL_THUMBTRACK) | |
144 | { | |
145 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; | |
146 | wxSpinEvent event2( scrollEvent, GetId()); | |
147 | event2.SetPosition( m_value ); | |
148 | event2.SetEventObject( this ); | |
149 | GetEventHandler()->ProcessEvent( event2 ); | |
150 | } | |
519cb848 SC |
151 | } |
152 | ||
4b26b60f | 153 | void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) |
a54b0880 | 154 | { |
facd6764 | 155 | if ( (ControlRef) m_macControl == NULL ) |
e40298d5 JS |
156 | return ; |
157 | ||
158 | int nScrollInc = 0; | |
159 | ||
160 | switch( controlpart ) | |
161 | { | |
162 | case kControlUpButtonPart : | |
163 | nScrollInc = 1; | |
164 | break ; | |
165 | case kControlDownButtonPart : | |
166 | nScrollInc = -1; | |
167 | break ; | |
168 | } | |
169 | MacHandleValueChanged( nScrollInc ) ; | |
170 | ||
a54b0880 SC |
171 | } |
172 | ||
51abe921 SC |
173 | // ---------------------------------------------------------------------------- |
174 | // size calculation | |
175 | // ---------------------------------------------------------------------------- | |
176 | ||
37e2cb08 | 177 | wxSize wxSpinButton::DoGetBestSize() const |
51abe921 | 178 | { |
e40298d5 | 179 | return wxSize(16,24); |
51abe921 | 180 | } |
519cb848 | 181 |