]>
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 | ||
19 | //----------------------------------------------------------------------------- | |
20 | // wxSlider | |
21 | //----------------------------------------------------------------------------- | |
22 | ||
23 | void 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 | ||
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 ); | |
60 | }; | |
61 | ||
62 | IMPLEMENT_DYNAMIC_CLASS(wxSlider,wxControl) | |
63 | ||
64 | wxSlider::wxSlider(void) | |
65 | { | |
66 | }; | |
67 | ||
debe6624 JS |
68 | wxSlider::wxSlider( wxWindow *parent, wxWindowID id, |
69 | int value, int minValue, int maxValue, | |
c801d85f | 70 | const wxPoint& pos, const wxSize& size, |
debe6624 | 71 | long style, |
c801d85f KB |
72 | /* const wxValidator& validator = wxDefaultValidator, */ |
73 | const wxString& name ) | |
74 | { | |
75 | Create( parent, id, value, minValue, maxValue, | |
76 | pos, size, style, name ); | |
77 | }; | |
78 | ||
79 | wxSlider::~wxSlider(void) | |
80 | { | |
81 | }; | |
82 | ||
debe6624 JS |
83 | bool wxSlider::Create(wxWindow *parent, wxWindowID id, |
84 | int value, int minValue, int maxValue, | |
c801d85f | 85 | const wxPoint& pos, const wxSize& size, |
debe6624 | 86 | long style, |
c801d85f KB |
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 | ||
115 | int wxSlider::GetValue(void) const | |
116 | { | |
117 | return (int)(m_adjust->value+0.5); | |
118 | }; | |
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" ); | |
128 | }; | |
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" ); | |
143 | }; | |
144 | ||
145 | int wxSlider::GetMin(void) const | |
146 | { | |
147 | return (int)(m_adjust->lower+0.5); | |
148 | }; | |
149 | ||
150 | int wxSlider::GetMax(void) const | |
151 | { | |
152 | return (int)(m_adjust->upper+0.5); | |
153 | }; | |
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" ); | |
164 | }; | |
165 | ||
166 | int wxSlider::GetPageSize(void) const | |
167 | { | |
168 | return (int)(m_adjust->page_increment+0.5); | |
169 | }; | |
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" ); | |
180 | }; | |
181 | ||
182 | int wxSlider::GetThumbLength(void) const | |
183 | { | |
184 | return (int)(m_adjust->page_size+0.5); | |
185 | }; | |
186 | ||
debe6624 | 187 | void wxSlider::SetLineSize( int WXUNUSED(lineSize) ) |
c801d85f KB |
188 | { |
189 | }; | |
190 | ||
191 | int wxSlider::GetLineSize(void) const | |
192 | { | |
193 | return 0; | |
194 | }; | |
195 | ||
196 | // not supported in wxGTK (and GTK) | |
197 | ||
198 | void wxSlider::GetSize( int *x, int *y ) const | |
199 | { | |
200 | wxWindow::GetSize( x, y ); | |
201 | }; | |
202 | ||
debe6624 | 203 | void wxSlider::SetSize( int x, int y, int width, int height, int sizeFlags ) |
c801d85f KB |
204 | { |
205 | wxWindow::SetSize( x, y, width, height, sizeFlags ); | |
206 | }; | |
207 | ||
208 | void wxSlider::GetPosition( int *x, int *y ) const | |
209 | { | |
210 | wxWindow::GetPosition( x, y ); | |
211 | }; | |
212 | ||
debe6624 | 213 | void wxSlider::SetTick( int WXUNUSED(tickPos) ) |
c801d85f KB |
214 | { |
215 | }; | |
216 | ||
debe6624 | 217 | void wxSlider::SetTickFreq( int WXUNUSED(n), int WXUNUSED(pos) ) |
c801d85f KB |
218 | { |
219 | }; | |
220 | ||
221 | int wxSlider::GetTickFreq(void) const | |
222 | { | |
223 | return 0; | |
224 | }; | |
225 | ||
226 | void wxSlider::ClearTicks(void) | |
227 | { | |
228 | }; | |
229 | ||
debe6624 | 230 | void wxSlider::SetSelection( int WXUNUSED(minPos), int WXUNUSED(maxPos) ) |
c801d85f KB |
231 | { |
232 | }; | |
233 | ||
234 | int wxSlider::GetSelEnd(void) const | |
235 | { | |
236 | return 0; | |
237 | }; | |
238 | ||
239 | int wxSlider::GetSelStart(void) const | |
240 | { | |
241 | return 0; | |
242 | }; | |
243 | ||
244 | void wxSlider::ClearSel(void) | |
245 | { | |
246 | }; | |
247 |