]>
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 | ||
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "slider.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/slider.h" | |
16 | #include "wx/utils.h" | |
17 | ||
66bd6b93 RR |
18 | //----------------------------------------------------------------------------- |
19 | // data | |
20 | //----------------------------------------------------------------------------- | |
21 | ||
22 | extern bool g_blockEventsOnDrag; | |
23 | ||
c801d85f | 24 | //----------------------------------------------------------------------------- |
97b3455a | 25 | // "value_changed" |
c801d85f KB |
26 | //----------------------------------------------------------------------------- |
27 | ||
66bd6b93 | 28 | static 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 | ||
41 | if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN; | |
42 | else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP; | |
43 | else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN; | |
44 | else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP; | |
45 | else command = wxEVT_SCROLL_THUMBTRACK; | |
46 | ||
47 | int value = (int)(win->m_adjust->value+0.5); | |
48 | ||
49 | int orient = wxHORIZONTAL; | |
84efdbf1 | 50 | if (win->GetWindowStyleFlag() & wxSB_VERTICAL == wxSB_VERTICAL) orient = wxVERTICAL; |
c801d85f KB |
51 | |
52 | wxScrollEvent event( command, win->GetId(), value, orient ); | |
53 | event.SetEventObject( win ); | |
54 | win->ProcessEvent( event ); | |
55 | ||
56 | wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, win->GetId() ); | |
57 | cevent.SetEventObject( win ); | |
58 | win->ProcessEvent( cevent ); | |
6de97a3b | 59 | } |
c801d85f | 60 | |
97b3455a RR |
61 | //----------------------------------------------------------------------------- |
62 | // wxSlider | |
63 | //----------------------------------------------------------------------------- | |
64 | ||
c801d85f KB |
65 | IMPLEMENT_DYNAMIC_CLASS(wxSlider,wxControl) |
66 | ||
67 | wxSlider::wxSlider(void) | |
68 | { | |
6de97a3b | 69 | } |
c801d85f KB |
70 | |
71 | wxSlider::~wxSlider(void) | |
72 | { | |
6de97a3b | 73 | } |
c801d85f | 74 | |
debe6624 JS |
75 | bool wxSlider::Create(wxWindow *parent, wxWindowID id, |
76 | int value, int minValue, int maxValue, | |
c801d85f | 77 | const wxPoint& pos, const wxSize& size, |
6de97a3b | 78 | long style, const wxValidator& validator, const wxString& name ) |
c801d85f KB |
79 | { |
80 | m_needParent = TRUE; | |
81 | ||
82 | PreCreation( parent, id, pos, size, style, name ); | |
83 | ||
6de97a3b RR |
84 | SetValidator( validator ); |
85 | ||
c801d85f KB |
86 | m_oldPos = 0.0; |
87 | ||
88 | if (style & wxSL_VERTICAL == wxSL_VERTICAL) | |
c67daf87 | 89 | m_widget = gtk_hscale_new( (GtkAdjustment *) NULL ); |
c801d85f | 90 | else |
c67daf87 | 91 | m_widget = gtk_vscale_new( (GtkAdjustment *) NULL ); |
c801d85f | 92 | |
58614078 RR |
93 | gtk_scale_set_draw_value( GTK_SCALE( m_widget ), FALSE ); |
94 | ||
c801d85f KB |
95 | m_adjust = gtk_range_get_adjustment( GTK_RANGE(m_widget) ); |
96 | ||
97 | gtk_signal_connect (GTK_OBJECT (m_adjust), "value_changed", | |
98 | (GtkSignalFunc) gtk_slider_callback, (gpointer) this ); | |
99 | SetRange( minValue, maxValue ); | |
100 | SetValue( value ); | |
101 | ||
6ca41e57 RR |
102 | m_parent->AddChild( this ); |
103 | ||
104 | (m_parent->m_insertCallback)( m_parent, this ); | |
105 | ||
c801d85f KB |
106 | PostCreation(); |
107 | ||
f96aa4d9 RR |
108 | SetBackgroundColour( parent->GetBackgroundColour() ); |
109 | ||
c801d85f KB |
110 | Show( TRUE ); |
111 | ||
112 | return TRUE; | |
6de97a3b | 113 | } |
c801d85f KB |
114 | |
115 | int wxSlider::GetValue(void) const | |
116 | { | |
117 | return (int)(m_adjust->value+0.5); | |
6de97a3b | 118 | } |
c801d85f | 119 | |
debe6624 | 120 | void wxSlider::SetValue( int value ) |
c801d85f KB |
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" ); | |
6de97a3b | 128 | } |
c801d85f | 129 | |
debe6624 | 130 | void wxSlider::SetRange( int minValue, int maxValue ) |
c801d85f KB |
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" ); | |
6de97a3b | 143 | } |
c801d85f KB |
144 | |
145 | int wxSlider::GetMin(void) const | |
146 | { | |
147 | return (int)(m_adjust->lower+0.5); | |
6de97a3b | 148 | } |
c801d85f KB |
149 | |
150 | int wxSlider::GetMax(void) const | |
151 | { | |
152 | return (int)(m_adjust->upper+0.5); | |
6de97a3b | 153 | } |
c801d85f | 154 | |
debe6624 | 155 | void wxSlider::SetPageSize( int pageSize ) |
c801d85f KB |
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" ); | |
6de97a3b | 164 | } |
c801d85f KB |
165 | |
166 | int wxSlider::GetPageSize(void) const | |
167 | { | |
168 | return (int)(m_adjust->page_increment+0.5); | |
6de97a3b | 169 | } |
c801d85f | 170 | |
debe6624 | 171 | void wxSlider::SetThumbLength( int len ) |
c801d85f KB |
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" ); | |
6de97a3b | 180 | } |
c801d85f KB |
181 | |
182 | int wxSlider::GetThumbLength(void) const | |
183 | { | |
184 | return (int)(m_adjust->page_size+0.5); | |
6de97a3b | 185 | } |
c801d85f | 186 | |
debe6624 | 187 | void wxSlider::SetLineSize( int WXUNUSED(lineSize) ) |
c801d85f | 188 | { |
6de97a3b | 189 | } |
c801d85f KB |
190 | |
191 | int wxSlider::GetLineSize(void) const | |
192 | { | |
193 | return 0; | |
6de97a3b | 194 | } |
c801d85f | 195 | |
debe6624 | 196 | void wxSlider::SetTick( int WXUNUSED(tickPos) ) |
c801d85f | 197 | { |
6de97a3b | 198 | } |
c801d85f | 199 | |
debe6624 | 200 | void wxSlider::SetTickFreq( int WXUNUSED(n), int WXUNUSED(pos) ) |
c801d85f | 201 | { |
6de97a3b | 202 | } |
c801d85f KB |
203 | |
204 | int wxSlider::GetTickFreq(void) const | |
205 | { | |
206 | return 0; | |
6de97a3b | 207 | } |
c801d85f KB |
208 | |
209 | void wxSlider::ClearTicks(void) | |
210 | { | |
6de97a3b | 211 | } |
c801d85f | 212 | |
debe6624 | 213 | void wxSlider::SetSelection( int WXUNUSED(minPos), int WXUNUSED(maxPos) ) |
c801d85f | 214 | { |
6de97a3b | 215 | } |
c801d85f KB |
216 | |
217 | int wxSlider::GetSelEnd(void) const | |
218 | { | |
219 | return 0; | |
6de97a3b | 220 | } |
c801d85f KB |
221 | |
222 | int wxSlider::GetSelStart(void) const | |
223 | { | |
224 | return 0; | |
6de97a3b | 225 | } |
c801d85f KB |
226 | |
227 | void wxSlider::ClearSel(void) | |
228 | { | |
6de97a3b | 229 | } |
c801d85f | 230 | |
b4071e91 RR |
231 | bool wxSlider::IsOwnGtkWindow( GdkWindow *window ) |
232 | { | |
233 | GtkRange *range = GTK_RANGE(m_widget); | |
234 | return ( (window == GTK_WIDGET(range)->window) || | |
235 | (window == range->trough) || | |
236 | (window == range->slider) || | |
237 | (window == range->step_forw) || | |
238 | (window == range->step_back) ); | |
239 | } | |
240 | ||
58614078 RR |
241 | void wxSlider::ApplyWidgetStyle() |
242 | { | |
243 | SetWidgetStyle(); | |
244 | gtk_widget_set_style( m_widget, m_widgetStyle ); | |
245 | } |