]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/slider.cpp
* Corrected #include "thread.h" => #include "wx/thread.h"
[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
19//-----------------------------------------------------------------------------
20// wxSlider
21//-----------------------------------------------------------------------------
22
23void gtk_slider_callback( GtkWidget *WXUNUSED(widget), wxSlider *win )
24{
25/*
26 printf( "OnScroll from " );
27 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
28 printf( win->GetClassInfo()->GetClassName() );
29 printf( ".\n" );
30*/
31
32 if (!win->HasVMT()) return;
33
34 float diff = win->m_adjust->value - win->m_oldPos;
35 if (fabs(diff) < 0.2) return;
36
37 int command = 0;
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;
51 if (win->GetWindowStyleFlag() & wxSB_VERTICAL == wxSB_VERTICAL) orient = wxHORIZONTAL;
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 );
60};
61
62IMPLEMENT_DYNAMIC_CLASS(wxSlider,wxControl)
63
64wxSlider::wxSlider(void)
65{
66};
67
68wxSlider::wxSlider( wxWindow *parent, const wxWindowID id,
69 const int value, const int minValue, const int maxValue,
70 const wxPoint& pos, const wxSize& size,
71 const long style,
72/* const wxValidator& validator = wxDefaultValidator, */
73 const wxString& name )
74{
75 Create( parent, id, value, minValue, maxValue,
76 pos, size, style, name );
77};
78
79wxSlider::~wxSlider(void)
80{
81};
82
83bool wxSlider::Create(wxWindow *parent, const wxWindowID id,
84 const int value, const int minValue, const int maxValue,
85 const wxPoint& pos, const wxSize& size,
86 const long style,
87/* const wxValidator& validator = wxDefaultValidator, */
88 const wxString& name )
89{
90 m_needParent = TRUE;
91
92 PreCreation( parent, id, pos, size, style, name );
93
94 m_oldPos = 0.0;
95
96 if (style & wxSL_VERTICAL == wxSL_VERTICAL)
97 m_widget = gtk_hscale_new( NULL );
98 else
99 m_widget = gtk_vscale_new( NULL );
100
101 m_adjust = gtk_range_get_adjustment( GTK_RANGE(m_widget) );
102
103 gtk_signal_connect (GTK_OBJECT (m_adjust), "value_changed",
104 (GtkSignalFunc) gtk_slider_callback, (gpointer) this );
105 SetRange( minValue, maxValue );
106 SetValue( value );
107
108 PostCreation();
109
110 Show( TRUE );
111
112 return TRUE;
113};
114
115int wxSlider::GetValue(void) const
116{
117 return (int)(m_adjust->value+0.5);
118};
119
120void wxSlider::SetValue( const int value )
121{
122 float fpos = (float)value;
123 m_oldPos = fpos;
124 if (fabs(fpos-m_adjust->value) < 0.2) return;
125 m_adjust->value = fpos;
126
127 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "value_changed" );
128};
129
130void wxSlider::SetRange( const int minValue, const int maxValue )
131{
132 float fmin = (float)minValue;
133 float fmax = (float)maxValue;
134
135 if ((fabs(fmin-m_adjust->lower) < 0.2) &&
136 (fabs(fmax-m_adjust->upper) < 0.2))
137 return;
138
139 m_adjust->lower = fmin;
140 m_adjust->upper = fmax;
141
142 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
143};
144
145int wxSlider::GetMin(void) const
146{
147 return (int)(m_adjust->lower+0.5);
148};
149
150int wxSlider::GetMax(void) const
151{
152 return (int)(m_adjust->upper+0.5);
153};
154
155void wxSlider::SetPageSize( const int pageSize )
156{
157 float fpage = (float)pageSize;
158
159 if (fabs(fpage-m_adjust->page_increment) < 0.2) return;
160
161 m_adjust->page_increment = fpage;
162
163 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
164};
165
166int wxSlider::GetPageSize(void) const
167{
168 return (int)(m_adjust->page_increment+0.5);
169};
170
171void wxSlider::SetThumbLength( const int len )
172{
173 float flen = (float)len;
174
175 if (fabs(flen-m_adjust->page_size) < 0.2) return;
176
177 m_adjust->page_size = flen;
178
179 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
180};
181
182int wxSlider::GetThumbLength(void) const
183{
184 return (int)(m_adjust->page_size+0.5);
185};
186
187void wxSlider::SetLineSize( const int WXUNUSED(lineSize) )
188{
189};
190
191int wxSlider::GetLineSize(void) const
192{
193 return 0;
194};
195
196// not supported in wxGTK (and GTK)
197
198void wxSlider::GetSize( int *x, int *y ) const
199{
200 wxWindow::GetSize( x, y );
201};
202
203void wxSlider::SetSize( const int x, const int y, const int width, const int height, const int sizeFlags )
204{
205 wxWindow::SetSize( x, y, width, height, sizeFlags );
206};
207
208void wxSlider::GetPosition( int *x, int *y ) const
209{
210 wxWindow::GetPosition( x, y );
211};
212
213void wxSlider::SetTick( const int WXUNUSED(tickPos) )
214{
215};
216
217void wxSlider::SetTickFreq( const int WXUNUSED(n), const int WXUNUSED(pos) )
218{
219};
220
221int wxSlider::GetTickFreq(void) const
222{
223 return 0;
224};
225
226void wxSlider::ClearTicks(void)
227{
228};
229
230void wxSlider::SetSelection( const int WXUNUSED(minPos), const int WXUNUSED(maxPos) )
231{
232};
233
234int wxSlider::GetSelEnd(void) const
235{
236 return 0;
237};
238
239int wxSlider::GetSelStart(void) const
240{
241 return 0;
242};
243
244void wxSlider::ClearSel(void)
245{
246};
247