]>
Commit | Line | Data |
---|---|---|
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" | |
14 | #pragma implementation "spinbuttbase.h" | |
15 | #endif | |
16 | ||
17 | #include "wx/spinbutt.h" | |
18 | #include "wx/mac/uma.h" | |
19 | ||
20 | // ============================================================================ | |
21 | // implementation | |
22 | // ============================================================================ | |
23 | ||
24 | // ---------------------------------------------------------------------------- | |
25 | // wxWin macros | |
26 | // ---------------------------------------------------------------------------- | |
27 | ||
28 | #if !USE_SHARED_LIBRARY | |
29 | IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) | |
30 | IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent); | |
31 | #endif | |
32 | ||
33 | wxSpinButton::wxSpinButton() | |
34 | : wxSpinButtonBase() | |
35 | { | |
36 | } | |
37 | ||
38 | bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, | |
39 | long style, const wxString& name) | |
40 | { | |
41 | m_min = 0; | |
42 | m_max = 100; | |
43 | ||
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 | ||
52 | m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 100, | |
53 | kControlLittleArrowsProc , (long) this ) ; | |
54 | ||
55 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
56 | ||
57 | MacPostControlCreate() ; | |
58 | ||
59 | return TRUE; | |
60 | } | |
61 | ||
62 | wxSpinButton::~wxSpinButton() | |
63 | { | |
64 | } | |
65 | ||
66 | // Attributes | |
67 | //////////////////////////////////////////////////////////////////////////// | |
68 | ||
69 | int wxSpinButton::GetMin() const | |
70 | { | |
71 | return m_min; | |
72 | } | |
73 | ||
74 | int wxSpinButton::GetMax() const | |
75 | { | |
76 | return m_max; | |
77 | } | |
78 | ||
79 | int wxSpinButton::GetValue() const | |
80 | { | |
81 | return m_value; | |
82 | } | |
83 | ||
84 | void wxSpinButton::SetValue(int val) | |
85 | { | |
86 | m_value = val ; | |
87 | wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId); | |
88 | ||
89 | event.SetPosition(m_value); | |
90 | event.SetEventObject( this ); | |
91 | GetEventHandler()->ProcessEvent(event); | |
92 | } | |
93 | ||
94 | void wxSpinButton::SetRange(int minVal, int maxVal) | |
95 | { | |
96 | m_min = minVal; | |
97 | m_max = maxVal; | |
98 | SetControlMaximum( m_macControl , maxVal ) ; | |
99 | SetControlMinimum( m_macControl , minVal ) ; | |
100 | } | |
101 | ||
102 | void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) | |
103 | { | |
104 | if ( m_macControl == NULL ) | |
105 | return ; | |
106 | ||
107 | int oldValue = m_value ; | |
108 | wxEventType scrollEvent = wxEVT_NULL; | |
109 | int nScrollInc = 0; | |
110 | ||
111 | switch( controlpart ) | |
112 | { | |
113 | case kControlUpButtonPart : | |
114 | nScrollInc = 1; | |
115 | scrollEvent = wxEVT_SCROLL_LINEUP; | |
116 | break ; | |
117 | case kControlDownButtonPart : | |
118 | nScrollInc = -1; | |
119 | scrollEvent = wxEVT_SCROLL_LINEDOWN; | |
120 | break ; | |
121 | } | |
122 | ||
123 | m_value = m_value + nScrollInc; | |
124 | ||
125 | if (m_value < m_min) | |
126 | { | |
127 | if ( m_windowStyle & wxSP_WRAP ) | |
128 | m_value = m_max; | |
129 | else | |
130 | m_value = m_min; | |
131 | } | |
132 | ||
133 | if (m_value > m_max) | |
134 | { | |
135 | if ( m_windowStyle & wxSP_WRAP ) | |
136 | m_value = m_min; | |
137 | else | |
138 | m_value = m_max; | |
139 | } | |
140 | ||
141 | wxSpinEvent event(scrollEvent, m_windowId); | |
142 | ||
143 | event.SetPosition(m_value); | |
144 | event.SetEventObject( this ); | |
145 | if ((GetEventHandler()->ProcessEvent( event )) && | |
146 | !event.IsAllowed() ) | |
147 | { | |
148 | m_value = oldValue ; | |
149 | } | |
150 | SetControlValue( m_macControl , m_value ) ; | |
151 | ||
152 | /* always send a thumbtrack event */ | |
153 | if (scrollEvent != wxEVT_SCROLL_THUMBTRACK) | |
154 | { | |
155 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; | |
156 | wxSpinEvent event2( scrollEvent, GetId()); | |
157 | event2.SetPosition( m_value ); | |
158 | event2.SetEventObject( this ); | |
159 | GetEventHandler()->ProcessEvent( event2 ); | |
160 | } | |
161 | } | |
162 | ||
163 | // ---------------------------------------------------------------------------- | |
164 | // size calculation | |
165 | // ---------------------------------------------------------------------------- | |
166 | ||
167 | wxSize wxSpinButton::DoGetBestSize() const | |
168 | { | |
169 | if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 ) | |
170 | { | |
171 | // vertical control | |
172 | return wxSize(16, | |
173 | 2*16); | |
174 | } | |
175 | else | |
176 | { | |
177 | // horizontal control | |
178 | return wxSize(2*16, | |
179 | 16); | |
180 | } | |
181 | } | |
182 |