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 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
21 BEGIN_EVENT_TABLE(wxSlider
, wxControl
)
36 extern ControlActionUPP wxMacLiveScrollbarActionUPP
;
38 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
39 int value
, int minValue
, int maxValue
,
41 const wxSize
& size
, long style
,
42 const wxValidator
& validator
,
48 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
50 m_macMinimumStatic
= NULL
;
55 m_rangeMax
= maxValue
;
56 m_rangeMin
= minValue
;
58 m_pageSize
= (int)((maxValue
-minValue
)/10);
62 if ( style
& wxSL_LABELS
&& style
& wxSL_VERTICAL
)
64 bounds
.right
= bounds
.left
+ m_width
;
69 if ( style
& wxSL_LABELS
&& style
& wxSL_HORIZONTAL
)
71 bounds
.bottom
= bounds
.top
+ m_height
;
74 if ( style
& wxSL_LABELS
&& style
& wxSL_HORIZONTAL
)
80 if ( style
& wxSL_LABELS
&& style
& wxSL_VERTICAL
)
86 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , value
, minValue
, maxValue
,
87 kControlSliderProc
+ kControlSliderLiveFeedback
+ ( ( style
& wxSL_AUTOTICKS
) ? kControlSliderHasTickMarks
: 0 ) , (long) this ) ;
89 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
91 ::SetControlAction( m_macControl
, wxMacLiveScrollbarActionUPP
) ;
93 MacPostControlCreate() ;
95 if ( style
& wxSL_LABELS
)
97 if ( style
& wxSL_HORIZONTAL
)
99 wxSize
size( 24 , 12 ) ;
100 wxPoint
leftpos( 0 , 0 ) ;
101 wxPoint
rightpos( m_width
- 2 * 12 , 0 ) ;
102 wxPoint
valuepos( m_width
- 12 , 20 ) ;
103 wxString valuestring
;
105 valuestring
.Printf( "%d" , minValue
) ;
106 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, leftpos
, size
) ;
107 valuestring
.Printf( "%d" , maxValue
) ;
108 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, rightpos
, size
) ;
109 valuestring
.Printf( "%d" , value
) ;
110 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, valuepos
, size
) ;
114 wxSize
size( 24 , 12 ) ;
115 wxPoint
toppos( 0 , 12 ) ;
116 wxPoint
bottompos( 0 , m_height
- 12 ) ;
117 wxPoint
valuepos( 20 , 0 ) ;
118 wxString valuestring
;
120 valuestring
.Printf( "%d" , minValue
) ;
121 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, bottompos
, size
) ;
122 valuestring
.Printf( "%d" , maxValue
) ;
123 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, toppos
, size
) ;
124 valuestring
.Printf( "%d" , value
) ;
125 m_macMinimumStatic
= new wxStaticText( this , -1 , valuestring
, valuepos
, size
) ;
133 wxSlider::~wxSlider()
137 int wxSlider::GetValue() const
139 return GetControlValue( m_macControl
) ;
142 void wxSlider::SetValue(int value
)
144 wxString valuestring
;
145 valuestring
.Printf( "%d" , value
) ;
146 if ( m_macMinimumStatic
)
147 m_macMinimumStatic
->SetLabel( valuestring
) ;
148 SetControlValue( m_macControl
, value
) ;
151 void wxSlider::SetRange(int minValue
, int maxValue
)
153 m_rangeMin
= minValue
;
154 m_rangeMax
= maxValue
;
159 // For trackbars only
160 void wxSlider::SetTickFreq(int n
, int pos
)
166 void wxSlider::SetPageSize(int pageSize
)
169 m_pageSize
= pageSize
;
172 int wxSlider::GetPageSize() const
177 void wxSlider::ClearSel()
182 void wxSlider::ClearTicks()
187 void wxSlider::SetLineSize(int lineSize
)
189 m_lineSize
= lineSize
;
193 int wxSlider::GetLineSize() const
199 int wxSlider::GetSelEnd() const
205 int wxSlider::GetSelStart() const
211 void wxSlider::SetSelection(int minPos
, int maxPos
)
216 void wxSlider::SetThumbLength(int len
)
221 int wxSlider::GetThumbLength() const
227 void wxSlider::SetTick(int tickPos
)
232 void wxSlider::Command (wxCommandEvent
& event
)
234 SetValue (event
.GetInt());
235 ProcessCommand (event
);
238 bool wxSlider::Show( bool show
)
240 return wxWindow::Show( show
) ;
243 void wxSlider::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
245 SInt16 value
= ::GetControlValue( m_macControl
) ;
249 wxScrollEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
250 event
.SetPosition(GetControlValue( m_macControl
) );
251 event
.SetEventObject( this );
253 #if WXWIN_COMPATIBILITY
255 wxEventType oldEvent
= event
.GetEventType();
256 event
.SetEventType( wxEVT_COMMAND_SLIDER_UPDATED
);
257 if ( !GetEventHandler()->ProcessEvent(event
) )
259 event
.SetEventType( oldEvent
);
260 if (!GetParent()->GetEventHandler()->ProcessEvent(event
))
264 GetEventHandler()->ProcessEvent(event
);