Mercurial > projects > dwt-mac
comparison dwt/widgets/ScrollBar.d @ 26:74a3be48bba8
Ported dwt.widgets.ScrollBar
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Mon, 08 Sep 2008 17:55:37 +0200 |
parents | e831403a80a9 |
children | 642f460a0908 |
comparison
equal
deleted
inserted
replaced
25:060cdd4457aa | 26:74a3be48bba8 |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | |
10 *******************************************************************************/ | 13 *******************************************************************************/ |
11 module dwt.widgets.ScrollBar; | 14 module dwt.widgets.ScrollBar; |
12 | |
13 import dwt.dwthelper.utils; | |
14 | 15 |
15 | 16 |
16 import dwt.DWT; | 17 import dwt.DWT; |
17 import dwt.DWTException; | 18 import dwt.DWTException; |
18 import dwt.events.SelectionEvent; | 19 import dwt.events.SelectionEvent; |
19 import dwt.events.SelectionListener; | 20 import dwt.events.SelectionListener; |
20 import dwt.graphics.Point; | 21 import dwt.graphics.Point; |
21 import dwt.internal.cocoa.NSScroller; | 22 import dwt.internal.cocoa.NSScroller; |
22 import dwt.internal.cocoa.OS; | 23 import dwt.internal.cocoa.OS; |
23 import dwt.internal.cocoa.id; | 24 import dwt.internal.cocoa.id; |
25 | |
26 import dwt.dwthelper.utils; | |
27 import dwt.internal.cocoa.CGFloat; | |
28 import dwt.widgets.Event; | |
29 import dwt.widgets.Scrollable; | |
30 import dwt.widgets.TypedListener; | |
31 import dwt.widgets.Widget; | |
24 | 32 |
25 /** | 33 /** |
26 * Instances of this class are selectable user interface | 34 * Instances of this class are selectable user interface |
27 * objects that represent a range of positive, numeric values. | 35 * objects that represent a range of positive, numeric values. |
28 * <p> | 36 * <p> |
410 view.sendAction(actionSelector, target); | 418 view.sendAction(actionSelector, target); |
411 } else { | 419 } else { |
412 value = getSelection (); | 420 value = getSelection (); |
413 } | 421 } |
414 Event event = new Event(); | 422 Event event = new Event(); |
415 int hitPart = (cast(NSScroller)view).hitPart(); | 423 NSScrollerPart hitPart = (cast(NSScroller)view).hitPart(); |
416 switch (hitPart) { | 424 switch (hitPart) { |
417 case OS.NSScrollerDecrementLine: | 425 case OS.NSScrollerDecrementLine: |
418 value -= increment; | 426 value -= increment; |
419 event.detail = DWT.ARROW_UP; | 427 event.detail = DWT.ARROW_UP; |
420 break; | 428 break; |
654 void updateBar(int selection, int minimum, int maximum, int thumb) { | 662 void updateBar(int selection, int minimum, int maximum, int thumb) { |
655 NSScroller widget = cast(NSScroller)view; | 663 NSScroller widget = cast(NSScroller)view; |
656 selection = Math.max(minimum, Math.min(maximum - thumb, selection)); | 664 selection = Math.max(minimum, Math.min(maximum - thumb, selection)); |
657 int range = maximum - thumb - minimum; | 665 int range = maximum - thumb - minimum; |
658 float fraction = range < 0 ? 1 : cast(float)(selection - minimum) / range; | 666 float fraction = range < 0 ? 1 : cast(float)(selection - minimum) / range; |
659 float knob = minimum is maximum ? 1 : cast(float)(thumb - minimum) / maximum - minimum; | 667 CGFloat knob = minimum is maximum ? 1 : cast(CGFloat)(thumb - minimum) / maximum - minimum; |
660 widget.setFloatValue(fraction, knob); | 668 widget.setFloatValue(fraction, knob); |
661 widget.setEnabled(range > 0); | 669 widget.setEnabled(range > 0); |
662 } | 670 } |
663 | 671 |
664 } | 672 } |