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