Mercurial > projects > dwt-linux
annotate dwt/widgets/Scale.d @ 364:2bcb17ebe0be default tip
fix: thx torhu
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 08 Nov 2009 20:57:46 +0100 |
parents | c0d810de7093 |
children |
rev | line source |
---|---|
72 | 1 /******************************************************************************* |
259 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
61 | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
72 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
61 | 12 *******************************************************************************/ |
13 module dwt.widgets.Scale; | |
14 | |
15 | |
16 import dwt.widgets.Control; | |
17 import dwt.widgets.Composite; | |
18 import dwt.widgets.TypedListener; | |
71 | 19 import dwt.DWT; |
61 | 20 import dwt.internal.gtk.OS; |
21 import dwt.graphics.Point; | |
22 import dwt.events.SelectionListener; | |
23 | |
24 /** | |
25 * Instances of the receiver represent a selectable user | |
26 * interface object that present a range of continuous | |
27 * numeric values. | |
28 * <dl> | |
29 * <dt><b>Styles:</b></dt> | |
30 * <dd>HORIZONTAL, VERTICAL</dd> | |
31 * <dt><b>Events:</b></dt> | |
32 * <dd>Selection</dd> | |
33 * </dl> | |
34 * <p> | |
35 * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. | |
36 * </p><p> | |
37 * <p> | |
38 * IMPORTANT: This class is intended to be subclassed <em>only</em> | |
71 | 39 * within the DWT implementation. |
61 | 40 * </p> |
259 | 41 * |
42 * @see <a href="http://www.eclipse.org/swt/snippets/#scale">Scale snippets</a> | |
43 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> | |
44 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
61 | 45 */ |
46 public class Scale : Control { | |
47 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
48 alias Control.computeSize computeSize; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
49 |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
50 |
61 | 51 /** |
52 * Constructs a new instance of this class given its parent | |
53 * and a style value describing its behavior and appearance. | |
54 * <p> | |
55 * The style value is either one of the style constants defined in | |
71 | 56 * class <code>DWT</code> which is applicable to instances of this |
61 | 57 * class, or must be built by <em>bitwise OR</em>'ing together |
58 * (that is, using the <code>int</code> "|" operator) two or more | |
71 | 59 * of those <code>DWT</code> style constants. The class description |
61 | 60 * lists the style constants that are applicable to the class. |
61 * Style bits are also inherited from superclasses. | |
62 * </p> | |
63 * | |
64 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
65 * @param style the style of control to construct | |
66 * | |
67 * @exception IllegalArgumentException <ul> | |
68 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
69 * </ul> | |
71 | 70 * @exception DWTException <ul> |
61 | 71 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
72 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
73 * </ul> | |
74 * | |
71 | 75 * @see DWT#HORIZONTAL |
76 * @see DWT#VERTICAL | |
61 | 77 * @see Widget#checkSubclass |
78 * @see Widget#getStyle | |
79 */ | |
80 public this (Composite parent, int style) { | |
81 super (parent, checkStyle (style)); | |
82 } | |
83 | |
84 /** | |
85 * Adds the listener to the collection of listeners who will | |
86 * be notified when the user changes the receiver's value, by sending | |
87 * it one of the messages defined in the <code>SelectionListener</code> | |
88 * interface. | |
89 * <p> | |
90 * <code>widgetSelected</code> is called when the user changes the receiver's value. | |
91 * <code>widgetDefaultSelected</code> is not called. | |
92 * </p> | |
93 * | |
94 * @param listener the listener which should be notified | |
95 * | |
96 * @exception IllegalArgumentException <ul> | |
97 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
98 * </ul> | |
71 | 99 * @exception DWTException <ul> |
61 | 100 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
101 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
102 * </ul> | |
103 * | |
104 * @see SelectionListener | |
105 * @see #removeSelectionListener | |
106 */ | |
107 public void addSelectionListener (SelectionListener listener) { | |
108 checkWidget (); | |
71 | 109 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); |
61 | 110 TypedListener typedListener = new TypedListener (listener); |
71 | 111 addListener (DWT.Selection,typedListener); |
112 addListener (DWT.DefaultSelection,typedListener); | |
61 | 113 } |
114 | |
115 static int checkStyle (int style) { | |
71 | 116 return checkBits (style, DWT.HORIZONTAL, DWT.VERTICAL, 0, 0, 0, 0); |
61 | 117 } |
118 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
119 public override Point computeSize (int wHint, int hHint, bool changed) { |
61 | 120 checkWidget(); |
71 | 121 if (wHint !is DWT.DEFAULT && wHint < 0) wHint = 0; |
122 if (hHint !is DWT.DEFAULT && hHint < 0) hHint = 0; | |
61 | 123 Point size = computeNativeSize(handle, wHint, hHint, changed); |
71 | 124 if ((style & DWT.HORIZONTAL) !is 0) { |
125 if (wHint is DWT.DEFAULT) size.x = 2 * size.x; | |
61 | 126 } else { |
71 | 127 if (hHint is DWT.DEFAULT) size.y = 2 * size.y; |
61 | 128 } |
129 return size; | |
130 } | |
131 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
132 override void createHandle (int index) { |
61 | 133 state |= HANDLE | THEME_BACKGROUND; |
134 fixedHandle = cast(GtkWidget*)OS.g_object_new (display.gtk_fixed_get_type (), null); | |
71 | 135 if (fixedHandle is null) error (DWT.ERROR_NO_HANDLES); |
61 | 136 OS.gtk_fixed_set_has_window (cast(GtkFixed*)fixedHandle, true); |
137 auto hAdjustment = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 0); | |
71 | 138 if (hAdjustment is null) error (DWT.ERROR_NO_HANDLES); |
139 if ((style & DWT.HORIZONTAL) !is 0) { | |
61 | 140 handle = cast(GtkWidget*)OS.gtk_hscale_new (cast(GtkAdjustment*)hAdjustment); |
141 } else { | |
142 handle = cast(GtkWidget*)OS.gtk_vscale_new (cast(GtkAdjustment*)hAdjustment); | |
143 } | |
71 | 144 if (handle is null) error (DWT.ERROR_NO_HANDLES); |
61 | 145 OS.gtk_container_add (cast(GtkContainer*)fixedHandle, handle); |
146 OS.gtk_scale_set_digits (cast(GtkScale*)handle, 0); | |
147 OS.gtk_scale_set_draw_value (cast(GtkScale*)handle, false); | |
148 } | |
149 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
150 override void hookEvents () { |
61 | 151 super.hookEvents (); |
152 OS.g_signal_connect_closure (handle, OS.value_changed.ptr, display.closures [VALUE_CHANGED], false); | |
153 } | |
154 | |
155 /** | |
156 * Returns the amount that the receiver's value will be | |
157 * modified by when the up/down (or right/left) arrows | |
158 * are pressed. | |
159 * | |
160 * @return the increment | |
161 * | |
71 | 162 * @exception DWTException <ul> |
61 | 163 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
164 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
165 * </ul> | |
166 */ | |
167 public int getIncrement () { | |
168 checkWidget (); | |
169 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
170 return cast(int) hAdjustment.step_increment; | |
171 } | |
172 | |
173 /** | |
174 * Returns the maximum value which the receiver will allow. | |
175 * | |
176 * @return the maximum | |
177 * | |
71 | 178 * @exception DWTException <ul> |
61 | 179 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
180 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
181 * </ul> | |
182 */ | |
183 public int getMaximum () { | |
184 checkWidget (); | |
185 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
186 return cast(int) hAdjustment.upper; | |
187 } | |
188 | |
189 /** | |
190 * Returns the minimum value which the receiver will allow. | |
191 * | |
192 * @return the minimum | |
193 * | |
71 | 194 * @exception DWTException <ul> |
61 | 195 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
196 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
197 * </ul> | |
198 */ | |
199 public int getMinimum () { | |
200 checkWidget (); | |
201 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
202 return cast(int) hAdjustment.lower; | |
203 } | |
204 | |
205 /** | |
206 * Returns the amount that the receiver's value will be | |
207 * modified by when the page increment/decrement areas | |
208 * are selected. | |
209 * | |
210 * @return the page increment | |
211 * | |
71 | 212 * @exception DWTException <ul> |
61 | 213 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
214 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
215 * </ul> | |
216 */ | |
217 public int getPageIncrement () { | |
218 checkWidget (); | |
219 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
220 return cast(int) hAdjustment.page_increment; | |
221 } | |
222 | |
223 /** | |
224 * Returns the 'selection', which is the receiver's position. | |
225 * | |
226 * @return the selection | |
227 * | |
71 | 228 * @exception DWTException <ul> |
61 | 229 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
230 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
231 * </ul> | |
232 */ | |
233 public int getSelection () { | |
234 checkWidget (); | |
235 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
236 return cast(int) hAdjustment.value; | |
237 } | |
238 | |
239 int /*long*/ gtk_value_changed (int /*long*/ adjustment) { | |
71 | 240 postEvent (DWT.Selection); |
61 | 241 return 0; |
242 } | |
243 | |
244 /** | |
245 * Removes the listener from the collection of listeners who will | |
246 * be notified when the user changes the receiver's value. | |
247 * | |
248 * @param listener the listener which should no longer be notified | |
249 * | |
250 * @exception IllegalArgumentException <ul> | |
251 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
252 * </ul> | |
71 | 253 * @exception DWTException <ul> |
61 | 254 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
255 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
256 * </ul> | |
257 * | |
258 * @see SelectionListener | |
259 * @see #addSelectionListener | |
260 */ | |
261 public void removeSelectionListener (SelectionListener listener) { | |
262 checkWidget (); | |
71 | 263 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); |
61 | 264 if (eventTable is null) return; |
71 | 265 eventTable.unhook (DWT.Selection, listener); |
266 eventTable.unhook (DWT.DefaultSelection,listener); | |
61 | 267 } |
268 | |
269 /** | |
270 * Sets the amount that the receiver's value will be | |
271 * modified by when the up/down (or right/left) arrows | |
272 * are pressed to the argument, which must be at least | |
273 * one. | |
274 * | |
275 * @param increment the new increment (must be greater than zero) | |
276 * | |
71 | 277 * @exception DWTException <ul> |
61 | 278 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
279 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
280 * </ul> | |
281 */ | |
282 public void setIncrement (int value) { | |
283 checkWidget (); | |
284 if (value < 1) return; | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
285 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
61 | 286 OS.gtk_range_set_increments (cast(GtkRange*)handle, value, getPageIncrement ()); |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
287 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
61 | 288 } |
289 | |
290 /** | |
291 * Sets the maximum value that the receiver will allow. This new | |
292 * value will be ignored if it is not greater than the receiver's current | |
293 * minimum value. If the new maximum is applied then the receiver's | |
294 * selection value will be adjusted if necessary to fall within its new range. | |
295 * | |
296 * @param value the new maximum, which must be greater than the current minimum | |
297 * | |
71 | 298 * @exception DWTException <ul> |
61 | 299 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
300 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
301 * </ul> | |
302 */ | |
303 public void setMaximum (int value) { | |
304 checkWidget (); | |
305 int minimum = getMinimum(); | |
306 if (value <= minimum) return; | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
307 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
61 | 308 OS.gtk_range_set_range (cast(GtkRange*)handle, minimum, value); |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
309 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
61 | 310 } |
311 | |
312 /** | |
313 * Sets the minimum value that the receiver will allow. This new | |
314 * value will be ignored if it is negative or is not less than the receiver's | |
315 * current maximum value. If the new minimum is applied then the receiver's | |
316 * selection value will be adjusted if necessary to fall within its new range. | |
317 * | |
318 * @param value the new minimum, which must be nonnegative and less than the current maximum | |
319 * | |
71 | 320 * @exception DWTException <ul> |
61 | 321 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
322 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
323 * </ul> | |
324 */ | |
325 public void setMinimum (int value) { | |
326 checkWidget (); | |
327 if (value < 0) return; | |
328 int maximum = getMaximum (); | |
329 if (value >= maximum) return; | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
330 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
61 | 331 OS.gtk_range_set_range (cast(GtkRange*)handle, value, maximum); |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
332 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
61 | 333 } |
334 | |
335 /** | |
336 * Sets the amount that the receiver's value will be | |
337 * modified by when the page increment/decrement areas | |
338 * are selected to the argument, which must be at least | |
339 * one. | |
340 * | |
341 * @param pageIncrement the page increment (must be greater than zero) | |
342 * | |
71 | 343 * @exception DWTException <ul> |
61 | 344 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
345 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
346 * </ul> | |
347 */ | |
348 public void setPageIncrement (int value) { | |
349 checkWidget (); | |
350 if (value < 1) return; | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
351 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
61 | 352 OS.gtk_range_set_increments (cast(GtkRange*)handle, getIncrement (), value); |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
353 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
61 | 354 } |
355 | |
356 /** | |
357 * Sets the 'selection', which is the receiver's value, | |
358 * to the argument which must be greater than or equal to zero. | |
359 * | |
360 * @param value the new selection (must be zero or greater) | |
361 * | |
71 | 362 * @exception DWTException <ul> |
61 | 363 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
364 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
365 * </ul> | |
366 */ | |
367 public void setSelection (int value) { | |
368 checkWidget (); | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
369 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
61 | 370 OS.gtk_range_set_value (cast(GtkRange*)handle, value); |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
371 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
61 | 372 } |
373 | |
374 } |