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