diff dwt/widgets/Slider.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents e831403a80a9
children cfa563df4fdd
line wrap: on
line diff
--- a/dwt/widgets/Slider.d	Tue Oct 21 15:20:04 2008 +0200
+++ b/dwt/widgets/Slider.d	Mon Dec 01 17:07:00 2008 +0100
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -70,6 +70,9 @@
  * </p>
  *
  * @see ScrollBar
+ * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a>
+ * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a>
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public class Slider : Control {
     bool dragging;
@@ -181,9 +184,7 @@
     widget.setEnabled(true);
     widget.setTarget(widget);
     widget.setAction(OS.sel_sendSelection);
-    widget.setTag(jniRef);
     view = widget;
-    parent.contentView().addSubview_(widget);
     updateBar(0, minimum, maximum, thumb);
 }
 
@@ -270,7 +271,7 @@
 public int getSelection () {
     checkWidget();
     NSScroller widget = cast(NSScroller)view;
-    float value = widget.floatValue();
+    double value = widget.doubleValue();
     return cast(int)((maximum - thumb - minimum) * value + minimum);
 }
 
@@ -317,7 +318,7 @@
 
 void sendSelection () {
     Event event = new Event();
-    int hitPart = (cast(NSScroller)view).hitPart();
+    int hitPart = cast(int)/*64*/((NSScroller)view).hitPart();
     int value = getSelection ();
     switch (hitPart) {
         case OS.NSScrollerDecrementLine:
@@ -451,12 +452,13 @@
     updateBar(value, minimum, maximum, thumb);
 }
 
-void updateBar(int selection, int minimum, int maximum, int thumb) {
+void updateBar (int selection, int minimum, int maximum, int thumb) {
     NSScroller widget = cast(NSScroller)view;
-    selection = Math.max(minimum, Math.min(maximum - thumb, selection));
-    float fraction = minimum is maximum ? 1 : cast(float)(selection - minimum) / (maximum - thumb - minimum);
-    float knob = minimum is maximum ? 1 : cast(float)(thumb - minimum) / (maximum - minimum);
-    widget.setFloatValue(fraction, knob);
+    selection = Math.max (minimum, Math.min (maximum - thumb, selection));
+    int range = maximum - thumb - minimum;
+    float fraction = range <= 0 ? 1 : cast(float)(selection - minimum) / range;
+    CGFloat knob = range <= 0 ? 1 : cast(CGFloat)thumb / (maximum - minimum);
+    widget.setFloatValue (fraction, knob);
 }
 
 /**