]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: slider.cpp | |
3 | // Purpose: wxSlider | |
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 "slider.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/slider.h" | |
519cb848 | 17 | #include "wx/mac/uma.h" |
e9576ca5 SC |
18 | |
19 | #if !USE_SHARED_LIBRARY | |
20 | IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) | |
21 | ||
22 | BEGIN_EVENT_TABLE(wxSlider, wxControl) | |
23 | END_EVENT_TABLE() | |
24 | #endif | |
25 | ||
26 | ||
27 | ||
28 | // Slider | |
29 | wxSlider::wxSlider() | |
30 | { | |
31 | m_pageSize = 1; | |
32 | m_lineSize = 1; | |
33 | m_rangeMax = 0; | |
34 | m_rangeMin = 0; | |
35 | m_tickFreq = 0; | |
36 | } | |
37 | ||
519cb848 SC |
38 | extern ControlActionUPP wxMacLiveScrollbarActionUPP ; |
39 | ||
e9576ca5 SC |
40 | bool wxSlider::Create(wxWindow *parent, wxWindowID id, |
41 | int value, int minValue, int maxValue, | |
42 | const wxPoint& pos, | |
43 | const wxSize& size, long style, | |
44 | const wxValidator& validator, | |
45 | const wxString& name) | |
46 | { | |
519cb848 SC |
47 | Rect bounds ; |
48 | Str255 title ; | |
49 | ||
50 | MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; | |
e9576ca5 | 51 | |
519cb848 | 52 | m_macMinimumStatic = NULL ; |
e9576ca5 | 53 | |
519cb848 SC |
54 | m_lineSize = 1; |
55 | m_tickFreq = 0; | |
e9576ca5 | 56 | |
519cb848 SC |
57 | m_rangeMax = maxValue; |
58 | m_rangeMin = minValue; | |
59 | ||
60 | m_pageSize = (int)((maxValue-minValue)/10); | |
61 | if ( m_width == -1 ) | |
62 | { | |
63 | m_width = 20 ; | |
64 | if ( style & wxSL_LABELS && style & wxSL_VERTICAL ) | |
65 | m_width += 24 ; | |
66 | bounds.right = bounds.left + m_width ; | |
67 | } | |
68 | if ( m_height == -1 ) | |
69 | { | |
70 | m_height = 20 ; | |
71 | if ( style & wxSL_LABELS && style & wxSL_HORIZONTAL ) | |
72 | m_height += 24 ; | |
73 | bounds.bottom = bounds.top + m_height ; | |
74 | } | |
75 | ||
76 | if ( style & wxSL_LABELS && style & wxSL_HORIZONTAL ) | |
77 | { | |
78 | bounds.top += 12 ; | |
79 | bounds.right -= 24 ; | |
80 | } | |
81 | ||
82 | if ( style & wxSL_LABELS && style & wxSL_VERTICAL ) | |
83 | { | |
84 | bounds.left += 24 ; | |
85 | bounds.top += 12 ; | |
86 | } | |
87 | ||
88 | m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , value , minValue , maxValue, | |
89 | kControlSliderProc + kControlSliderLiveFeedback + ( ( style & wxSL_AUTOTICKS ) ? kControlSliderHasTickMarks : 0 ) , (long) this ) ; | |
90 | ||
91 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
92 | ||
93 | ::SetControlAction( m_macControl , wxMacLiveScrollbarActionUPP ) ; | |
94 | ||
95 | MacPostControlCreate() ; | |
96 | ||
97 | if ( style & wxSL_LABELS ) | |
98 | { | |
99 | if ( style & wxSL_HORIZONTAL ) | |
100 | { | |
101 | wxSize size( 24 , 12 ) ; | |
102 | wxPoint leftpos( 0 , 0 ) ; | |
103 | wxPoint rightpos( m_width - 2 * 12 , 0 ) ; | |
104 | wxPoint valuepos( m_width - 12 , 20 ) ; | |
105 | wxString valuestring ; | |
106 | ||
107 | valuestring.Printf( "%d" , minValue ) ; | |
108 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , leftpos , size ) ; | |
109 | valuestring.Printf( "%d" , maxValue ) ; | |
110 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , rightpos , size ) ; | |
111 | valuestring.Printf( "%d" , value ) ; | |
112 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , valuepos , size ) ; | |
113 | } | |
114 | else | |
115 | { | |
116 | wxSize size( 24 , 12 ) ; | |
117 | wxPoint toppos( 0 , 12 ) ; | |
118 | wxPoint bottompos( 0 , m_height - 12 ) ; | |
119 | wxPoint valuepos( 20 , 0 ) ; | |
120 | wxString valuestring ; | |
121 | ||
122 | valuestring.Printf( "%d" , minValue ) ; | |
123 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , bottompos , size ) ; | |
124 | valuestring.Printf( "%d" , maxValue ) ; | |
125 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , toppos , size ) ; | |
126 | valuestring.Printf( "%d" , value ) ; | |
127 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , valuepos , size ) ; | |
128 | } | |
129 | } | |
130 | ||
131 | return TRUE; | |
e9576ca5 | 132 | |
e9576ca5 SC |
133 | } |
134 | ||
135 | wxSlider::~wxSlider() | |
136 | { | |
137 | } | |
138 | ||
139 | int wxSlider::GetValue() const | |
140 | { | |
519cb848 | 141 | return GetControlValue( m_macControl) ; |
e9576ca5 SC |
142 | } |
143 | ||
144 | void wxSlider::SetValue(int value) | |
145 | { | |
519cb848 SC |
146 | wxString valuestring ; |
147 | valuestring.Printf( "%d" , value ) ; | |
148 | if ( m_macMinimumStatic ) | |
149 | m_macMinimumStatic->SetLabel( valuestring ) ; | |
150 | SetControlValue( m_macControl , value ) ; | |
e9576ca5 SC |
151 | } |
152 | ||
153 | void wxSlider::SetRange(int minValue, int maxValue) | |
154 | { | |
155 | m_rangeMin = minValue; | |
156 | m_rangeMax = maxValue; | |
157 | ||
158 | // TODO | |
159 | } | |
160 | ||
161 | // For trackbars only | |
162 | void wxSlider::SetTickFreq(int n, int pos) | |
163 | { | |
164 | // TODO | |
165 | m_tickFreq = n; | |
166 | } | |
167 | ||
168 | void wxSlider::SetPageSize(int pageSize) | |
169 | { | |
170 | // TODO | |
171 | m_pageSize = pageSize; | |
172 | } | |
173 | ||
174 | int wxSlider::GetPageSize() const | |
175 | { | |
176 | return m_pageSize; | |
177 | } | |
178 | ||
179 | void wxSlider::ClearSel() | |
180 | { | |
181 | // TODO | |
182 | } | |
183 | ||
184 | void wxSlider::ClearTicks() | |
185 | { | |
186 | // TODO | |
187 | } | |
188 | ||
189 | void wxSlider::SetLineSize(int lineSize) | |
190 | { | |
191 | m_lineSize = lineSize; | |
192 | // TODO | |
193 | } | |
194 | ||
195 | int wxSlider::GetLineSize() const | |
196 | { | |
197 | // TODO | |
198 | return 0; | |
199 | } | |
200 | ||
201 | int wxSlider::GetSelEnd() const | |
202 | { | |
203 | // TODO | |
204 | return 0; | |
205 | } | |
206 | ||
207 | int wxSlider::GetSelStart() const | |
208 | { | |
209 | // TODO | |
210 | return 0; | |
211 | } | |
212 | ||
213 | void wxSlider::SetSelection(int minPos, int maxPos) | |
214 | { | |
215 | // TODO | |
216 | } | |
217 | ||
218 | void wxSlider::SetThumbLength(int len) | |
219 | { | |
220 | // TODO | |
221 | } | |
222 | ||
223 | int wxSlider::GetThumbLength() const | |
224 | { | |
225 | // TODO | |
226 | return 0; | |
227 | } | |
228 | ||
229 | void wxSlider::SetTick(int tickPos) | |
230 | { | |
231 | // TODO | |
232 | } | |
233 | ||
234 | void wxSlider::Command (wxCommandEvent & event) | |
235 | { | |
236 | SetValue (event.GetInt()); | |
237 | ProcessCommand (event); | |
238 | } | |
239 | ||
519cb848 | 240 | bool wxSlider::Show( bool show ) |
e9576ca5 | 241 | { |
519cb848 | 242 | return wxWindow::Show( show ) ; |
e9576ca5 SC |
243 | } |
244 | ||
519cb848 SC |
245 | void wxSlider::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) |
246 | { | |
247 | SInt16 value = ::GetControlValue( m_macControl ) ; | |
248 | ||
249 | SetValue( value ) ; | |
250 | ||
251 | wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId); | |
252 | event.SetPosition(GetControlValue( m_macControl) ); | |
253 | event.SetEventObject( this ); | |
254 | ||
255 | #if WXWIN_COMPATIBILITY | |
256 | ||
257 | wxEventType oldEvent = event.GetEventType(); | |
258 | event.SetEventType( wxEVT_COMMAND_SLIDER_UPDATED ); | |
259 | if ( !GetEventHandler()->ProcessEvent(event) ) | |
260 | { | |
261 | event.SetEventType( oldEvent ); | |
262 | if (!GetParent()->GetEventHandler()->ProcessEvent(event)) | |
263 | event.Skip(); | |
264 | } | |
265 | #else | |
266 | GetEventHandler()->ProcessEvent(event); | |
267 | #endif | |
268 | } |