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 extern bool g_blockEventsOnDrag
;
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 static void gtk_slider_callback( GtkWidget
*WXUNUSED(widget
), wxSlider
*win
)
31 if (!win
->HasVMT()) return;
32 if (g_blockEventsOnDrag
) return;
34 float diff
= win
->m_adjust
->value
- win
->m_oldPos
;
35 if (fabs(diff
) < 0.2) return;
37 wxEventType command
= wxEVT_NULL
;
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(void)
72 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
73 int value
, int minValue
, int maxValue
,
74 const wxPoint
& pos
, const wxSize
& size
,
75 long style
, const wxValidator
& validator
, const wxString
& name
)
79 PreCreation( parent
, id
, pos
, size
, style
, name
);
81 SetValidator( validator
);
85 if (style
& wxSL_VERTICAL
== wxSL_VERTICAL
)
86 m_widget
= gtk_hscale_new( (GtkAdjustment
*) NULL
);
88 m_widget
= gtk_vscale_new( (GtkAdjustment
*) NULL
);
90 m_adjust
= gtk_range_get_adjustment( GTK_RANGE(m_widget
) );
92 gtk_signal_connect (GTK_OBJECT (m_adjust
), "value_changed",
93 (GtkSignalFunc
) gtk_slider_callback
, (gpointer
) this );
94 SetRange( minValue
, maxValue
);
104 int wxSlider::GetValue(void) const
106 return (int)(m_adjust
->value
+0.5);
109 void wxSlider::SetValue( int value
)
111 float fpos
= (float)value
;
113 if (fabs(fpos
-m_adjust
->value
) < 0.2) return;
114 m_adjust
->value
= fpos
;
116 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "value_changed" );
119 void wxSlider::SetRange( int minValue
, int maxValue
)
121 float fmin
= (float)minValue
;
122 float fmax
= (float)maxValue
;
124 if ((fabs(fmin
-m_adjust
->lower
) < 0.2) &&
125 (fabs(fmax
-m_adjust
->upper
) < 0.2))
128 m_adjust
->lower
= fmin
;
129 m_adjust
->upper
= fmax
;
131 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "changed" );
134 int wxSlider::GetMin(void) const
136 return (int)(m_adjust
->lower
+0.5);
139 int wxSlider::GetMax(void) const
141 return (int)(m_adjust
->upper
+0.5);
144 void wxSlider::SetPageSize( int pageSize
)
146 float fpage
= (float)pageSize
;
148 if (fabs(fpage
-m_adjust
->page_increment
) < 0.2) return;
150 m_adjust
->page_increment
= fpage
;
152 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "changed" );
155 int wxSlider::GetPageSize(void) const
157 return (int)(m_adjust
->page_increment
+0.5);
160 void wxSlider::SetThumbLength( int len
)
162 float flen
= (float)len
;
164 if (fabs(flen
-m_adjust
->page_size
) < 0.2) return;
166 m_adjust
->page_size
= flen
;
168 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "changed" );
171 int wxSlider::GetThumbLength(void) const
173 return (int)(m_adjust
->page_size
+0.5);
176 void wxSlider::SetLineSize( int WXUNUSED(lineSize
) )
180 int wxSlider::GetLineSize(void) const
185 // not supported in wxGTK (and GTK)
187 void wxSlider::GetSize( int *x
, int *y
) const
189 wxWindow::GetSize( x
, y
);
192 void wxSlider::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
194 wxWindow::SetSize( x
, y
, width
, height
, sizeFlags
);
197 void wxSlider::GetPosition( int *x
, int *y
) const
199 wxWindow::GetPosition( x
, y
);
202 void wxSlider::SetTick( int WXUNUSED(tickPos
) )
206 void wxSlider::SetTickFreq( int WXUNUSED(n
), int WXUNUSED(pos
) )
210 int wxSlider::GetTickFreq(void) const
215 void wxSlider::ClearTicks(void)
219 void wxSlider::SetSelection( int WXUNUSED(minPos
), int WXUNUSED(maxPos
) )
223 int wxSlider::GetSelEnd(void) const
228 int wxSlider::GetSelStart(void) const
233 void wxSlider::ClearSel(void)