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 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
52 m_macMinimumStatic
= NULL
;
57 m_rangeMax
= maxValue
;
58 m_rangeMin
= minValue
;
60 m_pageSize
= (int)((maxValue
-minValue
)/10);
64 if ( style
& wxSL_LABELS
&& style
& wxSL_VERTICAL
)
66 bounds
.right
= bounds
.left
+ m_width
;
71 if ( style
& wxSL_LABELS
&& style
& wxSL_HORIZONTAL
)
73 bounds
.bottom
= bounds
.top
+ m_height
;
76 if ( style
& wxSL_LABELS
&& style
& wxSL_HORIZONTAL
)
82 if ( style
& wxSL_LABELS
&& style
& wxSL_VERTICAL
)
88 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , value
, minValue
, maxValue
,
89 kControlSliderProc
+ kControlSliderLiveFeedback
+ ( ( style
& wxSL_AUTOTICKS
) ? kControlSliderHasTickMarks
: 0 ) , (long) this ) ;
91 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
93 ::SetControlAction( m_macControl
, wxMacLiveScrollbarActionUPP
) ;
95 MacPostControlCreate() ;
97 if ( style
& wxSL_LABELS
)
99 if ( style
& wxSL_HORIZONTAL
)
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
;
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
) ;
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
;
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
) ;
135 wxSlider::~wxSlider()
139 int wxSlider::GetValue() const
141 return GetControlValue( m_macControl
) ;
144 void wxSlider::SetValue(int value
)
146 wxString valuestring
;
147 valuestring
.Printf( "%d" , value
) ;
148 if ( m_macMinimumStatic
)
149 m_macMinimumStatic
->SetLabel( valuestring
) ;
150 SetControlValue( m_macControl
, value
) ;
153 void wxSlider::SetRange(int minValue
, int maxValue
)
155 m_rangeMin
= minValue
;
156 m_rangeMax
= maxValue
;
161 // For trackbars only
162 void wxSlider::SetTickFreq(int n
, int pos
)
168 void wxSlider::SetPageSize(int pageSize
)
171 m_pageSize
= pageSize
;
174 int wxSlider::GetPageSize() const
179 void wxSlider::ClearSel()
184 void wxSlider::ClearTicks()
189 void wxSlider::SetLineSize(int lineSize
)
191 m_lineSize
= lineSize
;
195 int wxSlider::GetLineSize() const
201 int wxSlider::GetSelEnd() const
207 int wxSlider::GetSelStart() const
213 void wxSlider::SetSelection(int minPos
, int maxPos
)
218 void wxSlider::SetThumbLength(int len
)
223 int wxSlider::GetThumbLength() const
229 void wxSlider::SetTick(int tickPos
)
234 void wxSlider::Command (wxCommandEvent
& event
)
236 SetValue (event
.GetInt());
237 ProcessCommand (event
);
240 bool wxSlider::Show( bool show
)
242 return wxWindow::Show( show
) ;
245 void wxSlider::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
247 SInt16 value
= ::GetControlValue( m_macControl
) ;
251 wxScrollEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
252 event
.SetPosition(GetControlValue( m_macControl
) );
253 event
.SetEventObject( this );
255 #if WXWIN_COMPATIBILITY
257 wxEventType oldEvent
= event
.GetEventType();
258 event
.SetEventType( wxEVT_COMMAND_SLIDER_UPDATED
);
259 if ( !GetEventHandler()->ProcessEvent(event
) )
261 event
.SetEventType( oldEvent
);
262 if (!GetParent()->GetEventHandler()->ProcessEvent(event
))
266 GetEventHandler()->ProcessEvent(event
);