comparison dwt/widgets/ScrollBar.d @ 31:5c24c1a67fc2

Scrollable
author Frank Benoit <benoit@tionex.de>
date Wed, 09 Jan 2008 06:57:07 +0100
parents
children 27324bbbac70
comparison
equal deleted inserted replaced
30:5e5d1c9cffdb 31:5c24c1a67fc2
1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 IBM Corporation and others.
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
10 *******************************************************************************/
11 module dwt.widgets.ScrollBar;
12
13 import dwt.widgets.Control;
14 import dwt.widgets.Scrollable;
15 import dwt.internal.gtk.c.gtktypes;
16
17 class ScrollBar : Control {
18 GtkAdjustment* adjustmentHandle;
19 Scrollable parent;
20 }
21
22 /+
23 import dwt.SWT;
24 import dwt.internal.gtk.*;
25 import dwt.graphics.*;
26 import dwt.events.*;
27
28 /**
29 * Instances of this class are selectable user interface
30 * objects that represent a range of positive, numeric values.
31 * <p>
32 * At any given moment, a given scroll bar will have a
33 * single 'selection' that is considered to be its
34 * value, which is constrained to be within the range of
35 * values the scroll bar represents (that is, between its
36 * <em>minimum</em> and <em>maximum</em> values).
37 * </p><p>
38 * Typically, scroll bars will be made up of five areas:
39 * <ol>
40 * <li>an arrow button for decrementing the value</li>
41 * <li>a page decrement area for decrementing the value by a larger amount</li>
42 * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
43 * <li>a page increment area for incrementing the value by a larger amount</li>
44 * <li>an arrow button for incrementing the value</li>
45 * </ol>
46 * Based on their style, scroll bars are either <code>HORIZONTAL</code>
47 * (which have a left facing button for decrementing the value and a
48 * right facing button for incrementing it) or <code>VERTICAL</code>
49 * (which have an upward facing button for decrementing the value
50 * and a downward facing buttons for incrementing it).
51 * </p><p>
52 * On some platforms, the size of the scroll bar's thumb can be
53 * varied relative to the magnitude of the range of values it
54 * represents (that is, relative to the difference between its
55 * maximum and minimum values). Typically, this is used to
56 * indicate some proportional value such as the ratio of the
57 * visible area of a document to the total amount of space that
58 * it would take to display it. SWT supports setting the thumb
59 * size even if the underlying platform does not, but in this
60 * case the appearance of the scroll bar will not change.
61 * </p><p>
62 * Scroll bars are created by specifying either <code>H_SCROLL</code>,
63 * <code>V_SCROLL</code> or both when creating a <code>Scrollable</code>.
64 * They are accessed from the <code>Scrollable</code> using
65 * <code>getHorizontalBar</code> and <code>getVerticalBar</code>.
66 * </p><p>
67 * Note: Scroll bars are not Controls. On some platforms, scroll bars
68 * that appear as part of some standard controls such as a text or list
69 * have no operating system resources and are not children of the control.
70 * For this reason, scroll bars are treated specially. To create a control
71 * that looks like a scroll bar but has operating system resources, use
72 * <code>Slider</code>.
73 * </p>
74 * <dl>
75 * <dt><b>Styles:</b></dt>
76 * <dd>HORIZONTAL, VERTICAL</dd>
77 * <dt><b>Events:</b></dt>
78 * <dd>Selection</dd>
79 * </dl>
80 * <p>
81 * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
82 * </p><p>
83 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
84 * </p>
85 *
86 * @see Slider
87 * @see Scrollable
88 * @see Scrollable#getHorizontalBar
89 * @see Scrollable#getVerticalBar
90 */
91 public class ScrollBar extends Widget {
92 Scrollable parent;
93 int /*long*/ adjustmentHandle;
94 int detail;
95 boolean dragSent;
96
97 ScrollBar () {
98 }
99
100 /**
101 * Creates a new instance of the widget.
102 */
103 ScrollBar (Scrollable parent, int style) {
104 super (parent, checkStyle (style));
105 this.parent = parent;
106 createWidget (0);
107 }
108
109 /**
110 * Adds the listener to the collection of listeners who will
111 * be notified when the user changes the receiver's value, by sending
112 * it one of the messages defined in the <code>SelectionListener</code>
113 * interface.
114 * <p>
115 * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
116 * <code>SWT.NONE</code> - for the end of a drag.
117 * <code>SWT.DRAG</code>.
118 * <code>SWT.HOME</code>.
119 * <code>SWT.END</code>.
120 * <code>SWT.ARROW_DOWN</code>.
121 * <code>SWT.ARROW_UP</code>.
122 * <code>SWT.PAGE_DOWN</code>.
123 * <code>SWT.PAGE_UP</code>.
124 * <code>widgetDefaultSelected</code> is not called.
125 * </p>
126 *
127 * @param listener the listener which should be notified when the user changes the receiver's value
128 *
129 * @exception IllegalArgumentException <ul>
130 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
131 * </ul>
132 * @exception SWTException <ul>
133 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
134 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
135 * </ul>
136 *
137 * @see SelectionListener
138 * @see #removeSelectionListener
139 * @see SelectionEvent
140 */
141 public void addSelectionListener (SelectionListener listener) {
142 checkWidget ();
143 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
144 TypedListener typedListener = new TypedListener (listener);
145 addListener (SWT.Selection,typedListener);
146 addListener (SWT.DefaultSelection,typedListener);
147 }
148
149 static int checkStyle (int style) {
150 return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
151 }
152
153 void deregister () {
154 super.deregister ();
155 if (adjustmentHandle != 0) display.removeWidget (adjustmentHandle);
156 }
157
158 /**
159 * Returns <code>true</code> if the receiver is enabled, and
160 * <code>false</code> otherwise. A disabled control is typically
161 * not selectable from the user interface and draws with an
162 * inactive or "grayed" look.
163 *
164 * @return the receiver's enabled state
165 *
166 * @exception SWTException <ul>
167 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
168 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
169 * </ul>
170 *
171 * @see #isEnabled
172 */
173 public boolean getEnabled () {
174 checkWidget ();
175 if (handle != 0) return OS.GTK_WIDGET_SENSITIVE (handle);
176 return true;
177 }
178
179 /**
180 * Returns the amount that the receiver's value will be
181 * modified by when the up/down (or right/left) arrows
182 * are pressed.
183 *
184 * @return the increment
185 *
186 * @exception SWTException <ul>
187 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
188 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
189 * </ul>
190 */
191 public int getIncrement () {
192 checkWidget ();
193 GtkAdjustment adjustment = new GtkAdjustment ();
194 OS.memmove (adjustment, adjustmentHandle);
195 return (int) adjustment.step_increment;
196 }
197
198 /**
199 * Returns the maximum value which the receiver will allow.
200 *
201 * @return the maximum
202 *
203 * @exception SWTException <ul>
204 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
205 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
206 * </ul>
207 */
208 public int getMaximum () {
209 checkWidget ();
210 GtkAdjustment adjustment = new GtkAdjustment ();
211 OS.memmove (adjustment, adjustmentHandle);
212 return (int) adjustment.upper;
213 }
214
215 /**
216 * Returns the minimum value which the receiver will allow.
217 *
218 * @return the minimum
219 *
220 * @exception SWTException <ul>
221 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
222 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
223 * </ul>
224 */
225 public int getMinimum () {
226 checkWidget ();
227 GtkAdjustment adjustment = new GtkAdjustment ();
228 OS.memmove (adjustment, adjustmentHandle);
229 return (int) adjustment.lower;
230 }
231
232 /**
233 * Returns the amount that the receiver's value will be
234 * modified by when the page increment/decrement areas
235 * are selected.
236 *
237 * @return the page increment
238 *
239 * @exception SWTException <ul>
240 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
241 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
242 * </ul>
243 */
244 public int getPageIncrement () {
245 checkWidget ();
246 GtkAdjustment adjustment = new GtkAdjustment ();
247 OS.memmove (adjustment, adjustmentHandle);
248 return (int) adjustment.page_increment;
249 }
250
251 /**
252 * Returns the receiver's parent, which must be a Scrollable.
253 *
254 * @return the receiver's parent
255 *
256 * @exception SWTException <ul>
257 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
258 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
259 * </ul>
260 */
261 public Scrollable getParent () {
262 checkWidget ();
263 return parent;
264 }
265
266 /**
267 * Returns the single 'selection' that is the receiver's value.
268 *
269 * @return the selection
270 *
271 * @exception SWTException <ul>
272 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
273 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
274 * </ul>
275 */
276 public int getSelection () {
277 checkWidget ();
278 GtkAdjustment adjustment = new GtkAdjustment ();
279 OS.memmove (adjustment, adjustmentHandle);
280 return (int) adjustment.value;
281 }
282
283 /**
284 * Returns a point describing the receiver's size. The
285 * x coordinate of the result is the width of the receiver.
286 * The y coordinate of the result is the height of the
287 * receiver.
288 *
289 * @return the receiver's size
290 *
291 * @exception SWTException <ul>
292 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
293 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
294 * </ul>
295 */
296 public Point getSize () {
297 checkWidget ();
298 if (handle == 0) return new Point (0,0);
299 GtkRequisition requisition = new GtkRequisition ();
300 OS.gtk_widget_size_request (handle, requisition);
301 return new Point (requisition.width, requisition.height);
302 }
303
304 /**
305 * Returns the size of the receiver's thumb relative to the
306 * difference between its maximum and minimum values.
307 *
308 * @return the thumb value
309 *
310 * @exception SWTException <ul>
311 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
312 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
313 * </ul>
314 *
315 * @see ScrollBar
316 */
317 public int getThumb () {
318 checkWidget ();
319 GtkAdjustment adjustment = new GtkAdjustment ();
320 OS.memmove (adjustment, adjustmentHandle);
321 return (int) adjustment.page_size;
322 }
323
324 /**
325 * Returns <code>true</code> if the receiver is visible, and
326 * <code>false</code> otherwise.
327 * <p>
328 * If one of the receiver's ancestors is not visible or some
329 * other condition makes the receiver not visible, this method
330 * may still indicate that it is considered visible even though
331 * it may not actually be showing.
332 * </p>
333 *
334 * @return the receiver's visibility state
335 *
336 * @exception SWTException <ul>
337 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
338 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
339 * </ul>
340 */
341 public boolean getVisible () {
342 checkWidget ();
343 int /*long*/ scrolledHandle = parent.scrolledHandle;
344 int [] hsp = new int [1], vsp = new int [1];
345 OS.gtk_scrolled_window_get_policy (scrolledHandle, hsp, vsp);
346 if ((style & SWT.HORIZONTAL) != 0) {
347 return hsp [0] != OS.GTK_POLICY_NEVER;
348 } else {
349 return vsp [0] != OS.GTK_POLICY_NEVER;
350 }
351 }
352
353 int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
354 int /*long*/ result = super.gtk_button_press_event (widget, eventPtr);
355 if (result != 0) return result;
356 detail = OS.GTK_SCROLL_NONE;
357 dragSent = false;
358 return result;
359 }
360
361 int /*long*/ gtk_change_value (int /*long*/ widget, int /*long*/ scroll, int /*long*/ value1, int /*long*/ value2) {
362 detail = (int)/*64*/scroll;
363 return 0;
364 }
365
366 int /*long*/ gtk_value_changed (int /*long*/ adjustment) {
367 Event event = new Event ();
368 dragSent = detail == OS.GTK_SCROLL_JUMP;
369 switch (detail) {
370 case OS.GTK_SCROLL_NONE: event.detail = SWT.NONE; break;
371 case OS.GTK_SCROLL_JUMP: event.detail = SWT.DRAG; break;
372 case OS.GTK_SCROLL_START: event.detail = SWT.HOME; break;
373 case OS.GTK_SCROLL_END: event.detail = SWT.END; break;
374 case OS.GTK_SCROLL_PAGE_DOWN:
375 case OS.GTK_SCROLL_PAGE_RIGHT:
376 case OS.GTK_SCROLL_PAGE_FORWARD: event.detail = SWT.PAGE_DOWN; break;
377 case OS.GTK_SCROLL_PAGE_UP:
378 case OS.GTK_SCROLL_PAGE_LEFT:
379 case OS.GTK_SCROLL_PAGE_BACKWARD: event.detail = SWT.PAGE_UP; break;
380 case OS.GTK_SCROLL_STEP_DOWN:
381 case OS.GTK_SCROLL_STEP_RIGHT:
382 case OS.GTK_SCROLL_STEP_FORWARD: event.detail = SWT.ARROW_DOWN; break;
383 case OS.GTK_SCROLL_STEP_UP:
384 case OS.GTK_SCROLL_STEP_LEFT:
385 case OS.GTK_SCROLL_STEP_BACKWARD: event.detail = SWT.ARROW_UP; break;
386 }
387 detail = OS.GTK_SCROLL_NONE;
388 if (!dragSent) detail = OS.GTK_SCROLL_NONE;
389 postEvent (SWT.Selection, event);
390 parent.updateScrollBarValue (this);
391 return 0;
392 }
393
394 int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
395 GdkEvent gtkEvent = new GdkEvent ();
396 OS.memmove (gtkEvent, gdkEvent, GdkEvent.sizeof);
397 switch (gtkEvent.type) {
398 case OS.GDK_BUTTON_RELEASE: {
399 GdkEventButton gdkEventButton = new GdkEventButton ();
400 OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof);
401 if (gdkEventButton.button == 1 && detail == SWT.DRAG) {
402 if (!dragSent) {
403 Event event = new Event ();
404 event.detail = SWT.DRAG;
405 postEvent (SWT.Selection, event);
406 }
407 postEvent (SWT.Selection);
408 }
409 detail = OS.GTK_SCROLL_NONE;
410 dragSent = false;
411 break;
412 }
413 }
414 return super.gtk_event_after (widget, gdkEvent);
415 }
416
417 void hookEvents () {
418 super.hookEvents ();
419 if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) {
420 OS.g_signal_connect_closure (handle, OS.change_value, display.closures [CHANGE_VALUE], false);
421 }
422 OS.g_signal_connect_closure (adjustmentHandle, OS.value_changed, display.closures [VALUE_CHANGED], false);
423 OS.g_signal_connect_closure_by_id (handle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false);
424 OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
425 }
426
427 /**
428 * Returns <code>true</code> if the receiver is enabled and all
429 * of the receiver's ancestors are enabled, and <code>false</code>
430 * otherwise. A disabled control is typically not selectable from the
431 * user interface and draws with an inactive or "grayed" look.
432 *
433 * @return the receiver's enabled state
434 *
435 * @exception SWTException <ul>
436 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
437 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
438 * </ul>
439 *
440 * @see #getEnabled
441 */
442 public boolean isEnabled () {
443 checkWidget ();
444 return getEnabled () && getParent ().getEnabled ();
445 }
446
447 /**
448 * Returns <code>true</code> if the receiver is visible and all
449 * of the receiver's ancestors are visible and <code>false</code>
450 * otherwise.
451 *
452 * @return the receiver's visibility state
453 *
454 * @exception SWTException <ul>
455 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
456 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
457 * </ul>
458 *
459 * @see #getVisible
460 */
461 public boolean isVisible () {
462 checkWidget ();
463 return getVisible () && getParent ().isVisible ();
464 }
465
466 void register () {
467 super.register ();
468 if (adjustmentHandle != 0) display.addWidget (adjustmentHandle, this);
469 }
470
471 void releaseParent () {
472 super.releaseParent ();
473 if (parent.horizontalBar == this) parent.horizontalBar = null;
474 if (parent.verticalBar == this) parent.verticalBar = null;
475 }
476
477 void releaseWidget () {
478 super.releaseWidget ();
479 parent = null;
480 }
481
482 /**
483 * Removes the listener from the collection of listeners who will
484 * be notified when the user changes the receiver's value.
485 *
486 * @param listener the listener which should no longer be notified
487 *
488 * @exception IllegalArgumentException <ul>
489 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
490 * </ul>
491 * @exception SWTException <ul>
492 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
493 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
494 * </ul>
495 *
496 * @see SelectionListener
497 * @see #addSelectionListener
498 */
499 public void removeSelectionListener (SelectionListener listener) {
500 checkWidget ();
501 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
502 if (eventTable == null) return;
503 eventTable.unhook (SWT.Selection, listener);
504 eventTable.unhook (SWT.DefaultSelection,listener);
505 }
506
507 /**
508 * Enables the receiver if the argument is <code>true</code>,
509 * and disables it otherwise. A disabled control is typically
510 * not selectable from the user interface and draws with an
511 * inactive or "grayed" look.
512 *
513 * @param enabled the new enabled state
514 *
515 * @exception SWTException <ul>
516 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
517 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
518 * </ul>
519 */
520 public void setEnabled (boolean enabled) {
521 checkWidget ();
522 if (handle != 0) OS.gtk_widget_set_sensitive (handle, enabled);
523 }
524
525 /**
526 * Sets the amount that the receiver's value will be
527 * modified by when the up/down (or right/left) arrows
528 * are pressed to the argument, which must be at least
529 * one.
530 *
531 * @param value the new increment (must be greater than zero)
532 *
533 * @exception SWTException <ul>
534 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
535 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
536 * </ul>
537 */
538 public void setIncrement (int value) {
539 checkWidget ();
540 if (value < 1) return;
541 GtkAdjustment adjustment = new GtkAdjustment ();
542 OS.memmove (adjustment, adjustmentHandle);
543 adjustment.step_increment = (float) value;
544 OS.memmove (adjustmentHandle, adjustment);
545 OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
546 OS.gtk_adjustment_changed (adjustmentHandle);
547 OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
548 }
549
550 /**
551 * Sets the maximum. If this value is negative or less than or
552 * equal to the minimum, the value is ignored. If necessary, first
553 * the thumb and then the selection are adjusted to fit within the
554 * new range.
555 *
556 * @param value the new maximum
557 *
558 * @exception SWTException <ul>
559 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
560 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
561 * </ul>
562 */
563 public void setMaximum (int value) {
564 checkWidget ();
565 GtkAdjustment adjustment = new GtkAdjustment ();
566 OS.memmove (adjustment, adjustmentHandle);
567 int minimum = (int) adjustment.lower;
568 if (value <= minimum) return;
569 adjustment.upper = value;
570 adjustment.page_size = Math.min ((int)adjustment.page_size, value - minimum);
571 adjustment.value = Math.min ((int)adjustment.value, (int)(value - adjustment.page_size));
572 OS.memmove (adjustmentHandle, adjustment);
573 OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
574 OS.gtk_adjustment_changed (adjustmentHandle);
575 OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
576 }
577
578 /**
579 * Sets the minimum value. If this value is negative or greater
580 * than or equal to the maximum, the value is ignored. If necessary,
581 * first the thumb and then the selection are adjusted to fit within
582 * the new range.
583 *
584 * @param value the new minimum
585 *
586 * @exception SWTException <ul>
587 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
588 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
589 * </ul>
590 */
591 public void setMinimum (int value) {
592 checkWidget ();
593 if (value < 0) return;
594 GtkAdjustment adjustment = new GtkAdjustment ();
595 OS.memmove (adjustment, adjustmentHandle);
596 int maximum = (int) adjustment.upper;
597 if (value >= maximum) return;
598 adjustment.lower = value;
599 adjustment.page_size = Math.min ((int)adjustment.page_size, maximum - value);
600 adjustment.value = Math.max ((int)adjustment.value, value);
601 OS.memmove (adjustmentHandle, adjustment);
602 OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
603 OS.gtk_adjustment_changed (adjustmentHandle);
604 OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
605 }
606
607 /**
608 * Sets the amount that the receiver's value will be
609 * modified by when the page increment/decrement areas
610 * are selected to the argument, which must be at least
611 * one.
612 *
613 * @param value the page increment (must be greater than zero)
614 *
615 * @exception SWTException <ul>
616 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
617 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
618 * </ul>
619 */
620 public void setPageIncrement (int value) {
621 checkWidget ();
622 if (value < 1) return;
623 GtkAdjustment adjustment = new GtkAdjustment ();
624 OS.memmove (adjustment, adjustmentHandle);
625 adjustment.page_increment = (float) value;
626 OS.memmove (adjustmentHandle, adjustment);
627 OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
628 OS.gtk_adjustment_changed (adjustmentHandle);
629 OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
630 }
631
632 /**
633 * Sets the single <em>selection</em> that is the receiver's
634 * value to the argument which must be greater than or equal
635 * to zero.
636 *
637 * @param selection the new selection (must be zero or greater)
638 *
639 * @exception SWTException <ul>
640 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
641 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
642 * </ul>
643 */
644 public void setSelection (int value) {
645 checkWidget ();
646 value = Math.min (value, getMaximum() - getThumb());
647 OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
648 OS.gtk_adjustment_set_value (adjustmentHandle, value);
649 OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
650 }
651
652 /**
653 * Sets the size of the receiver's thumb relative to the
654 * difference between its maximum and minimum values. This new
655 * value will be ignored if it is less than one, and will be
656 * clamped if it exceeds the receiver's current range.
657 *
658 * @param value the new thumb value, which must be at least one and not
659 * larger than the size of the current range
660 *
661 * @exception SWTException <ul>
662 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
663 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
664 * </ul>
665 */
666 public void setThumb (int value) {
667 checkWidget ();
668 if (value < 1) return;
669 GtkAdjustment adjustment = new GtkAdjustment ();
670 OS.memmove (adjustment, adjustmentHandle);
671 value = (int) Math.min (value, (int)(adjustment.upper - adjustment.lower));
672 adjustment.page_size = (double) value;
673 adjustment.value = Math.min ((int)adjustment.value, (int)(adjustment.upper - value));
674 OS.memmove (adjustmentHandle, adjustment);
675 OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
676 OS.gtk_adjustment_changed (adjustmentHandle);
677 OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
678 }
679
680 /**
681 * Sets the receiver's selection, minimum value, maximum
682 * value, thumb, increment and page increment all at once.
683 * <p>
684 * Note: This is similar to setting the values individually
685 * using the appropriate methods, but may be implemented in a
686 * more efficient fashion on some platforms.
687 * </p>
688 *
689 * @param selection the new selection value
690 * @param minimum the new minimum value
691 * @param maximum the new maximum value
692 * @param thumb the new thumb value
693 * @param increment the new increment value
694 * @param pageIncrement the new pageIncrement value
695 *
696 * @exception SWTException <ul>
697 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
698 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
699 * </ul>
700 */
701 public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
702 checkWidget ();
703 if (minimum < 0) return;
704 if (maximum < 0) return;
705 if (thumb < 1) return;
706 if (increment < 1) return;
707 if (pageIncrement < 1) return;
708 thumb = Math.min (thumb, maximum - minimum);
709 GtkAdjustment adjustment = new GtkAdjustment ();
710 OS.memmove (adjustment, adjustmentHandle);
711 adjustment.lower = minimum;
712 adjustment.upper = maximum;
713 adjustment.step_increment = increment;
714 adjustment.page_increment = pageIncrement;
715 adjustment.page_size = thumb;
716 adjustment.value = Math.min (Math.max (selection, minimum), maximum - thumb);
717 OS.memmove (adjustmentHandle, adjustment);
718 OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
719 OS.gtk_adjustment_changed (adjustmentHandle);
720 OS.gtk_adjustment_value_changed (adjustmentHandle);
721 OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
722 }
723
724 /**
725 * Marks the receiver as visible if the argument is <code>true</code>,
726 * and marks it invisible otherwise.
727 * <p>
728 * If one of the receiver's ancestors is not visible or some
729 * other condition makes the receiver not visible, marking
730 * it visible may not actually cause it to be displayed.
731 * </p>
732 *
733 * @param visible the new visibility state
734 *
735 * @exception SWTException <ul>
736 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
737 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
738 * </ul>
739 */
740 public void setVisible (boolean visible) {
741 checkWidget ();
742 parent.setScrollBarVisible (this, visible);
743 }
744
745 }
746 +/