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