1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "slider.h"
16 #include "wx/slider.h"
17 #include "wx/mac/uma.h"
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
22 BEGIN_EVENT_TABLE(wxSlider
, wxControl
)
38 extern ControlActionUPP wxMacLiveScrollbarActionUPP
;
40 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
41 int value
, int minValue
, int maxValue
,
43 const wxSize
& size
, long style
,
44 const wxValidator
& validator
,
50 int maxtextwidth
, textheight
;
52 // Is control horizontal or vertical (Can be ambigous if user selects
53 // another style without also specifying horz or vert
54 if (!(style
& wxSL_HORIZONTAL
) && !(style
& wxSL_VERTICAL
)) {
55 // Default is horizontal so make it so
56 style
|= wxSL_HORIZONTAL
;
59 // Check that size corresponds with users selection of vertical or
60 // horizontal slider and insert suitable default values
61 if (style
& wxSL_HORIZONTAL
)
63 slsize
.y
= 15; // Slider width
65 slsize
.x
= 150; // Slider default length
70 slsize
.x
= 15; // Slider width
72 slsize
.y
= 150; // Slider default length
75 /* Set the height and width for the slider control region. The actual
76 * slider is set at 10 pixels across. If the slider has labels then the
77 * control region must be large enough to contain these labels
79 if (style
& wxSL_LABELS
)
84 // Get maximum text label width and height
85 text
.Printf("%d", minValue
);
86 parent
->GetTextExtent(text
, &maxtextwidth
, &textheight
);
87 text
.Printf("%d", maxValue
);
88 parent
->GetTextExtent(text
, &wd
, &ht
);
92 if (wd
> maxtextwidth
) {
96 if (style
& wxSL_VERTICAL
) {
97 slsize
.x
= (15 + maxtextwidth
+ 2); // Slider wd plus mac text width
99 if (style
& wxSL_HORIZONTAL
) {
100 slsize
.y
= (15 + textheight
); // Slider ht plus text ht.
104 MacPreControlCreate( parent
, id
, "" , pos
, slsize
, style
,
105 validator
, name
, &bounds
, title
) ;
107 m_macMinimumStatic
= NULL
;
108 m_macMaximumStatic
= NULL
;
109 m_macValueStatic
= NULL
;
114 m_rangeMax
= maxValue
;
115 m_rangeMin
= minValue
;
117 m_pageSize
= (int)((maxValue
-minValue
)/10);
119 // Must modify bounds to that of the slider dimensions from slider
120 // dimensions plus text labels.
121 if (style
& wxSL_LABELS
)
123 if ( style
& wxSL_HORIZONTAL
)
125 bounds
.bottom
= bounds
.top
+ 15;
126 bounds
.right
-= (5 + maxtextwidth
);
128 else // Vertical slider
130 bounds
.right
= bounds
.left
+ 15;
131 bounds
.bottom
-= (5 + textheight
);
135 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
,
136 title
, false , value
, minValue
, maxValue
,
137 kControlSliderProc
+ kControlSliderLiveFeedback
+ ( ( style
& wxSL_AUTOTICKS
) ? kControlSliderHasTickMarks
: 0 ) , (long) this ) ;
139 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
141 ::SetControlAction( m_macControl
, wxMacLiveScrollbarActionUPP
) ;
143 MacPostControlCreate() ;
145 if ( style
& wxSL_LABELS
)
147 if ( style
& wxSL_HORIZONTAL
)
149 wxPoint
leftpos( 0 , 15 ) ;
150 wxPoint
rightpos( m_width
- (maxtextwidth
+ 20) , 15 ) ;
151 wxPoint
valuepos( m_width
- maxtextwidth
, 0 ) ;
152 wxString valuestring
;
154 valuestring
.Printf( "%d" , minValue
) ;
155 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, leftpos
) ;
157 valuestring
.Printf( "%d" , maxValue
) ;
158 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, rightpos
) ;
160 valuestring
.Printf( "%d" , value
) ;
161 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, valuepos
) ;
163 else // Vertical slider
165 wxPoint
toppos( 17 , 0 ) ;
166 wxPoint
bottompos( 17 , m_height
- (textheight
+ 15) ) ;
167 wxPoint
valuepos( 0 , m_height
- textheight
) ;
168 wxString valuestring
;
170 valuestring
.Printf( "%d" , minValue
) ;
171 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, bottompos
) ;
173 valuestring
.Printf( "%d" , maxValue
) ;
174 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, toppos
) ;
176 valuestring
.Printf( "%d" , value
) ;
177 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, valuepos
) ;
184 wxSlider::~wxSlider()
188 int wxSlider::GetValue() const
190 return GetControlValue( m_macControl
) ;
193 void wxSlider::SetValue(int value
)
195 wxString valuestring
;
196 valuestring
.Printf( "%d" , value
) ;
197 if ( m_macMinimumStatic
)
198 m_macMinimumStatic
->SetLabel( valuestring
) ;
199 SetControlValue( m_macControl
, value
) ;
202 void wxSlider::SetRange(int minValue
, int maxValue
)
206 m_rangeMin
= minValue
;
207 m_rangeMax
= maxValue
;
210 SetControlMinimum(m_macControl
, m_rangeMin
);
211 SetControlMaximum(m_macControl
, m_rangeMax
);
213 if(m_macMinimumStatic
) {
214 value
.Printf("%d", m_rangeMin
);
215 m_macMinimumStatic
->SetLabel(value
);
217 if(m_macMaximumStatic
) {
218 value
.Printf("%d", m_rangeMax
);
219 m_macMaximumStatic
->SetLabel(value
);
221 SetValue(m_rangeMin
);
224 // For trackbars only
225 void wxSlider::SetTickFreq(int n
, int pos
)
231 void wxSlider::SetPageSize(int pageSize
)
234 m_pageSize
= pageSize
;
237 int wxSlider::GetPageSize() const
242 void wxSlider::ClearSel()
247 void wxSlider::ClearTicks()
252 void wxSlider::SetLineSize(int lineSize
)
254 m_lineSize
= lineSize
;
258 int wxSlider::GetLineSize() const
264 int wxSlider::GetSelEnd() const
270 int wxSlider::GetSelStart() const
276 void wxSlider::SetSelection(int minPos
, int maxPos
)
281 void wxSlider::SetThumbLength(int len
)
286 int wxSlider::GetThumbLength() const
292 void wxSlider::SetTick(int tickPos
)
297 void wxSlider::Command (wxCommandEvent
& event
)
299 SetValue (event
.GetInt());
300 ProcessCommand (event
);
303 bool wxSlider::Show( bool show
)
305 return wxWindow::Show( show
) ;
308 void wxSlider::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
310 SInt16 value
= ::GetControlValue( m_macControl
) ;
314 wxScrollEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
315 event
.SetPosition(value
);
316 event
.SetEventObject( this );
317 GetEventHandler()->ProcessEvent(event
);
319 wxCommandEvent
cevent( wxEVT_COMMAND_SLIDER_UPDATED
, m_windowId
);
320 cevent
.SetInt( value
);
321 cevent
.SetEventObject( this );
323 GetEventHandler()->ProcessEvent( cevent
);