]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: spinbutt.cpp | |
3 | // Purpose: wxSpinButton | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
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 SC |
29 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) |
30 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent); | |
2f1ae414 | 31 | #endif |
e9576ca5 | 32 | |
03e11df5 GD |
33 | wxSpinButton::wxSpinButton() |
34 | : wxSpinButtonBase() | |
35 | { | |
36 | } | |
37 | ||
e9576ca5 SC |
38 | bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, |
39 | long style, const wxString& name) | |
40 | { | |
e9576ca5 SC |
41 | m_min = 0; |
42 | m_max = 100; | |
43 | ||
519cb848 SC |
44 | if (!parent) |
45 | return FALSE; | |
46 | ||
47 | Rect bounds ; | |
48 | Str255 title ; | |
49 | ||
50 | MacPreControlCreate( parent , id , "" , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ; | |
51 | ||
72055702 | 52 | m_macControl = ::NewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , 0 , 100, |
519cb848 SC |
53 | kControlLittleArrowsProc , (long) this ) ; |
54 | ||
55 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
56 | ||
57 | MacPostControlCreate() ; | |
e9576ca5 | 58 | |
519cb848 | 59 | return TRUE; |
e9576ca5 SC |
60 | } |
61 | ||
62 | wxSpinButton::~wxSpinButton() | |
63 | { | |
64 | } | |
65 | ||
66 | // Attributes | |
67 | //////////////////////////////////////////////////////////////////////////// | |
68 | ||
03e11df5 GD |
69 | int wxSpinButton::GetMin() const |
70 | { | |
71 | return m_min; | |
72 | } | |
73 | ||
74 | int wxSpinButton::GetMax() const | |
75 | { | |
76 | return m_max; | |
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 | { | |
519cb848 | 86 | m_value = val ; |
e9576ca5 SC |
87 | } |
88 | ||
89 | void wxSpinButton::SetRange(int minVal, int maxVal) | |
90 | { | |
91 | m_min = minVal; | |
92 | m_max = maxVal; | |
72d750d4 SC |
93 | SetControlMaximum( m_macControl , maxVal ) ; |
94 | SetControlMinimum( m_macControl , minVal ) ; | |
e9576ca5 SC |
95 | } |
96 | ||
519cb848 SC |
97 | void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) |
98 | { | |
99 | if ( m_macControl == NULL ) | |
100 | return ; | |
101 | ||
72d750d4 | 102 | int oldValue = m_value ; |
519cb848 | 103 | wxEventType scrollEvent = wxEVT_NULL; |
03e11df5 | 104 | int nScrollInc = 0; |
519cb848 SC |
105 | |
106 | switch( controlpart ) | |
107 | { | |
108 | case kControlUpButtonPart : | |
109 | nScrollInc = 1; | |
110 | scrollEvent = wxEVT_SCROLL_LINEUP; | |
111 | break ; | |
112 | case kControlDownButtonPart : | |
113 | nScrollInc = -1; | |
114 | scrollEvent = wxEVT_SCROLL_LINEDOWN; | |
115 | break ; | |
116 | } | |
117 | ||
118 | m_value = m_value + nScrollInc; | |
119 | ||
120 | if (m_value < m_min) | |
121 | { | |
122 | if ( m_windowStyle & wxSP_WRAP ) | |
123 | m_value = m_max; | |
124 | else | |
125 | m_value = m_min; | |
126 | } | |
127 | ||
128 | if (m_value > m_max) | |
129 | { | |
130 | if ( m_windowStyle & wxSP_WRAP ) | |
131 | m_value = m_min; | |
132 | else | |
133 | m_value = m_max; | |
134 | } | |
135 | ||
72d750d4 | 136 | wxSpinEvent event(scrollEvent, m_windowId); |
519cb848 SC |
137 | |
138 | event.SetPosition(m_value); | |
139 | event.SetEventObject( this ); | |
72d750d4 SC |
140 | if ((GetEventHandler()->ProcessEvent( event )) && |
141 | !event.IsAllowed() ) | |
142 | { | |
143 | m_value = oldValue ; | |
144 | } | |
145 | SetControlValue( m_macControl , m_value ) ; | |
146 | ||
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 | } | |
519cb848 SC |
156 | } |
157 | ||
51abe921 SC |
158 | // ---------------------------------------------------------------------------- |
159 | // size calculation | |
160 | // ---------------------------------------------------------------------------- | |
161 | ||
37e2cb08 | 162 | wxSize wxSpinButton::DoGetBestSize() const |
51abe921 | 163 | { |
0d9e4757 | 164 | if ( (GetWindowStyle() & wxSP_HORIZONTAL) == 0 ) |
51abe921 SC |
165 | { |
166 | // vertical control | |
167 | return wxSize(16, | |
168 | 2*16); | |
169 | } | |
170 | else | |
171 | { | |
172 | // horizontal control | |
173 | return wxSize(2*16, | |
174 | 16); | |
175 | } | |
176 | } | |
519cb848 | 177 |