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