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