1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "slider.h"
16 #include "wx/slider.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 void gtk_slider_callback( GtkWidget
*WXUNUSED(widget
), wxSlider
*win
)
26 printf( "OnScroll from " );
27 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
28 printf( win->GetClassInfo()->GetClassName() );
32 if (!win
->HasVMT()) return;
34 float diff
= win
->m_adjust
->value
- win
->m_oldPos
;
35 if (fabs(diff
) < 0.2) return;
39 float line_step
= win
->m_adjust
->step_increment
;
40 float page_step
= win
->m_adjust
->page_increment
;
42 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
43 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
44 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
45 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
46 else command
= wxEVT_SCROLL_THUMBTRACK
;
48 int value
= (int)(win
->m_adjust
->value
+0.5);
50 int orient
= wxHORIZONTAL
;
51 if (win
->GetWindowStyleFlag() & wxSB_VERTICAL
== wxSB_VERTICAL
) orient
= wxHORIZONTAL
;
53 wxScrollEvent
event( command
, win
->GetId(), value
, orient
);
54 event
.SetEventObject( win
);
55 win
->ProcessEvent( event
);
57 wxCommandEvent
cevent( wxEVT_COMMAND_SLIDER_UPDATED
, win
->GetId() );
58 cevent
.SetEventObject( win
);
59 win
->ProcessEvent( cevent
);
62 IMPLEMENT_DYNAMIC_CLASS(wxSlider
,wxControl
)
64 wxSlider::wxSlider(void)
68 wxSlider::wxSlider( wxWindow
*parent
, const wxWindowID id
,
69 const int value
, const int minValue
, const int maxValue
,
70 const wxPoint
& pos
, const wxSize
& size
,
72 /* const wxValidator& validator = wxDefaultValidator, */
73 const wxString
& name
)
75 Create( parent
, id
, value
, minValue
, maxValue
,
76 pos
, size
, style
, name
);
79 wxSlider::~wxSlider(void)
83 bool wxSlider::Create(wxWindow
*parent
, const wxWindowID id
,
84 const int value
, const int minValue
, const int maxValue
,
85 const wxPoint
& pos
, const wxSize
& size
,
87 /* const wxValidator& validator = wxDefaultValidator, */
88 const wxString
& name
)
92 PreCreation( parent
, id
, pos
, size
, style
, name
);
96 if (style
& wxSL_VERTICAL
== wxSL_VERTICAL
)
97 m_widget
= gtk_hscale_new( NULL
);
99 m_widget
= gtk_vscale_new( NULL
);
101 m_adjust
= gtk_range_get_adjustment( GTK_RANGE(m_widget
) );
103 gtk_signal_connect (GTK_OBJECT (m_adjust
), "value_changed",
104 (GtkSignalFunc
) gtk_slider_callback
, (gpointer
) this );
105 SetRange( minValue
, maxValue
);
115 int wxSlider::GetValue(void) const
117 return (int)(m_adjust
->value
+0.5);
120 void wxSlider::SetValue( const int value
)
122 float fpos
= (float)value
;
124 if (fabs(fpos
-m_adjust
->value
) < 0.2) return;
125 m_adjust
->value
= fpos
;
127 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "value_changed" );
130 void wxSlider::SetRange( const int minValue
, const int maxValue
)
132 float fmin
= (float)minValue
;
133 float fmax
= (float)maxValue
;
135 if ((fabs(fmin
-m_adjust
->lower
) < 0.2) &&
136 (fabs(fmax
-m_adjust
->upper
) < 0.2))
139 m_adjust
->lower
= fmin
;
140 m_adjust
->upper
= fmax
;
142 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "changed" );
145 int wxSlider::GetMin(void) const
147 return (int)(m_adjust
->lower
+0.5);
150 int wxSlider::GetMax(void) const
152 return (int)(m_adjust
->upper
+0.5);
155 void wxSlider::SetPageSize( const int pageSize
)
157 float fpage
= (float)pageSize
;
159 if (fabs(fpage
-m_adjust
->page_increment
) < 0.2) return;
161 m_adjust
->page_increment
= fpage
;
163 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "changed" );
166 int wxSlider::GetPageSize(void) const
168 return (int)(m_adjust
->page_increment
+0.5);
171 void wxSlider::SetThumbLength( const int len
)
173 float flen
= (float)len
;
175 if (fabs(flen
-m_adjust
->page_size
) < 0.2) return;
177 m_adjust
->page_size
= flen
;
179 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "changed" );
182 int wxSlider::GetThumbLength(void) const
184 return (int)(m_adjust
->page_size
+0.5);
187 void wxSlider::SetLineSize( const int WXUNUSED(lineSize
) )
191 int wxSlider::GetLineSize(void) const
196 // not supported in wxGTK (and GTK)
198 void wxSlider::GetSize( int *x
, int *y
) const
200 wxWindow::GetSize( x
, y
);
203 void wxSlider::SetSize( const int x
, const int y
, const int width
, const int height
, const int sizeFlags
)
205 wxWindow::SetSize( x
, y
, width
, height
, sizeFlags
);
208 void wxSlider::GetPosition( int *x
, int *y
) const
210 wxWindow::GetPosition( x
, y
);
213 void wxSlider::SetTick( const int WXUNUSED(tickPos
) )
217 void wxSlider::SetTickFreq( const int WXUNUSED(n
), const int WXUNUSED(pos
) )
221 int wxSlider::GetTickFreq(void) const
226 void wxSlider::ClearTicks(void)
230 void wxSlider::SetSelection( const int WXUNUSED(minPos
), const int WXUNUSED(maxPos
) )
234 int wxSlider::GetSelEnd(void) const
239 int wxSlider::GetSelStart(void) const
244 void wxSlider::ClearSel(void)