]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/slider.cpp
Version 0.4 of wxPython for MSW.
[wxWidgets.git] / src / gtk1 / slider.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: slider.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifdef __GNUG__
13#pragma implementation "slider.h"
14#endif
15
16#include "wx/slider.h"
17#include "wx/utils.h"
18
66bd6b93
RR
19//-----------------------------------------------------------------------------
20// data
21//-----------------------------------------------------------------------------
22
23extern bool g_blockEventsOnDrag;
24
c801d85f 25//-----------------------------------------------------------------------------
97b3455a 26// "value_changed"
c801d85f
KB
27//-----------------------------------------------------------------------------
28
66bd6b93 29static void gtk_slider_callback( GtkWidget *WXUNUSED(widget), wxSlider *win )
c801d85f 30{
c801d85f 31 if (!win->HasVMT()) return;
66bd6b93 32 if (g_blockEventsOnDrag) return;
c801d85f
KB
33
34 float diff = win->m_adjust->value - win->m_oldPos;
35 if (fabs(diff) < 0.2) return;
36
7798a18e 37 wxEventType command = wxEVT_NULL;
c801d85f
KB
38
39 float line_step = win->m_adjust->step_increment;
40 float page_step = win->m_adjust->page_increment;
41
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;
47
48 int value = (int)(win->m_adjust->value+0.5);
49
50 int orient = wxHORIZONTAL;
84efdbf1 51 if (win->GetWindowStyleFlag() & wxSB_VERTICAL == wxSB_VERTICAL) orient = wxVERTICAL;
c801d85f
KB
52
53 wxScrollEvent event( command, win->GetId(), value, orient );
54 event.SetEventObject( win );
55 win->ProcessEvent( event );
56
57 wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, win->GetId() );
58 cevent.SetEventObject( win );
59 win->ProcessEvent( cevent );
6de97a3b 60}
c801d85f 61
97b3455a
RR
62//-----------------------------------------------------------------------------
63// wxSlider
64//-----------------------------------------------------------------------------
65
c801d85f
KB
66IMPLEMENT_DYNAMIC_CLASS(wxSlider,wxControl)
67
68wxSlider::wxSlider(void)
69{
6de97a3b 70}
c801d85f
KB
71
72wxSlider::~wxSlider(void)
73{
6de97a3b 74}
c801d85f 75
debe6624
JS
76bool wxSlider::Create(wxWindow *parent, wxWindowID id,
77 int value, int minValue, int maxValue,
c801d85f 78 const wxPoint& pos, const wxSize& size,
6de97a3b 79 long style, const wxValidator& validator, const wxString& name )
c801d85f
KB
80{
81 m_needParent = TRUE;
82
83 PreCreation( parent, id, pos, size, style, name );
84
6de97a3b
RR
85 SetValidator( validator );
86
c801d85f
KB
87 m_oldPos = 0.0;
88
89 if (style & wxSL_VERTICAL == wxSL_VERTICAL)
c67daf87 90 m_widget = gtk_hscale_new( (GtkAdjustment *) NULL );
c801d85f 91 else
c67daf87 92 m_widget = gtk_vscale_new( (GtkAdjustment *) NULL );
c801d85f
KB
93
94 m_adjust = gtk_range_get_adjustment( GTK_RANGE(m_widget) );
95
96 gtk_signal_connect (GTK_OBJECT (m_adjust), "value_changed",
97 (GtkSignalFunc) gtk_slider_callback, (gpointer) this );
98 SetRange( minValue, maxValue );
99 SetValue( value );
100
101 PostCreation();
102
103 Show( TRUE );
104
105 return TRUE;
6de97a3b 106}
c801d85f
KB
107
108int wxSlider::GetValue(void) const
109{
110 return (int)(m_adjust->value+0.5);
6de97a3b 111}
c801d85f 112
debe6624 113void wxSlider::SetValue( int value )
c801d85f
KB
114{
115 float fpos = (float)value;
116 m_oldPos = fpos;
117 if (fabs(fpos-m_adjust->value) < 0.2) return;
118 m_adjust->value = fpos;
119
120 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "value_changed" );
6de97a3b 121}
c801d85f 122
debe6624 123void wxSlider::SetRange( int minValue, int maxValue )
c801d85f
KB
124{
125 float fmin = (float)minValue;
126 float fmax = (float)maxValue;
127
128 if ((fabs(fmin-m_adjust->lower) < 0.2) &&
129 (fabs(fmax-m_adjust->upper) < 0.2))
130 return;
131
132 m_adjust->lower = fmin;
133 m_adjust->upper = fmax;
134
135 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
6de97a3b 136}
c801d85f
KB
137
138int wxSlider::GetMin(void) const
139{
140 return (int)(m_adjust->lower+0.5);
6de97a3b 141}
c801d85f
KB
142
143int wxSlider::GetMax(void) const
144{
145 return (int)(m_adjust->upper+0.5);
6de97a3b 146}
c801d85f 147
debe6624 148void wxSlider::SetPageSize( int pageSize )
c801d85f
KB
149{
150 float fpage = (float)pageSize;
151
152 if (fabs(fpage-m_adjust->page_increment) < 0.2) return;
153
154 m_adjust->page_increment = fpage;
155
156 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
6de97a3b 157}
c801d85f
KB
158
159int wxSlider::GetPageSize(void) const
160{
161 return (int)(m_adjust->page_increment+0.5);
6de97a3b 162}
c801d85f 163
debe6624 164void wxSlider::SetThumbLength( int len )
c801d85f
KB
165{
166 float flen = (float)len;
167
168 if (fabs(flen-m_adjust->page_size) < 0.2) return;
169
170 m_adjust->page_size = flen;
171
172 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
6de97a3b 173}
c801d85f
KB
174
175int wxSlider::GetThumbLength(void) const
176{
177 return (int)(m_adjust->page_size+0.5);
6de97a3b 178}
c801d85f 179
debe6624 180void wxSlider::SetLineSize( int WXUNUSED(lineSize) )
c801d85f 181{
6de97a3b 182}
c801d85f
KB
183
184int wxSlider::GetLineSize(void) const
185{
186 return 0;
6de97a3b 187}
c801d85f
KB
188
189// not supported in wxGTK (and GTK)
190
191void wxSlider::GetSize( int *x, int *y ) const
192{
193 wxWindow::GetSize( x, y );
6de97a3b 194}
c801d85f 195
debe6624 196void wxSlider::SetSize( int x, int y, int width, int height, int sizeFlags )
c801d85f
KB
197{
198 wxWindow::SetSize( x, y, width, height, sizeFlags );
6de97a3b 199}
c801d85f
KB
200
201void wxSlider::GetPosition( int *x, int *y ) const
202{
203 wxWindow::GetPosition( x, y );
6de97a3b 204}
c801d85f 205
debe6624 206void wxSlider::SetTick( int WXUNUSED(tickPos) )
c801d85f 207{
6de97a3b 208}
c801d85f 209
debe6624 210void wxSlider::SetTickFreq( int WXUNUSED(n), int WXUNUSED(pos) )
c801d85f 211{
6de97a3b 212}
c801d85f
KB
213
214int wxSlider::GetTickFreq(void) const
215{
216 return 0;
6de97a3b 217}
c801d85f
KB
218
219void wxSlider::ClearTicks(void)
220{
6de97a3b 221}
c801d85f 222
debe6624 223void wxSlider::SetSelection( int WXUNUSED(minPos), int WXUNUSED(maxPos) )
c801d85f 224{
6de97a3b 225}
c801d85f
KB
226
227int wxSlider::GetSelEnd(void) const
228{
229 return 0;
6de97a3b 230}
c801d85f
KB
231
232int wxSlider::GetSelStart(void) const
233{
234 return 0;
6de97a3b 235}
c801d85f
KB
236
237void wxSlider::ClearSel(void)
238{
6de97a3b 239}
c801d85f 240
b4071e91
RR
241bool wxSlider::IsOwnGtkWindow( GdkWindow *window )
242{
243 GtkRange *range = GTK_RANGE(m_widget);
244 return ( (window == GTK_WIDGET(range)->window) ||
245 (window == range->trough) ||
246 (window == range->slider) ||
247 (window == range->step_forw) ||
248 (window == range->step_back) );
249}
250
251