diff dwt/widgets/Scale.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/Scale.d	Tue Oct 21 15:20:04 2008 +0200
+++ b/dwt/widgets/Scale.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
@@ -17,7 +17,9 @@
 import dwt.DWTException;
 import dwt.events.SelectionListener;
 import dwt.graphics.Point;
+import dwt.internal.cocoa.NSControl;
 import dwt.internal.cocoa.NSRect;
+import dwt.internal.cocoa.NSSize;
 import dwt.internal.cocoa.NSSlider;
 import dwt.internal.cocoa.SWTSlider;
 
@@ -38,6 +40,10 @@
  * IMPORTANT: This class is intended to be subclassed <em>only</em>
  * within the DWT implementation.
  * </p>
+ *
+ * @see <a href="http://www.eclipse.org/swt/snippets/#scale">Scale 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 Scale : Control {
     int increment = 1;
@@ -114,16 +120,13 @@
 public Point computeSize (int wHint, int hHint, bool changed) {
     checkWidget();
     NSSlider widget = cast(NSSlider)view;
-    NSRect oldRect = widget.frame();
-    widget.sizeToFit();
-    NSRect newRect = widget.frame();
-    widget.setFrame (oldRect);
-    int width = 0, height = 0;
-    if ((style & DWT.HORIZONTAL) !is 0) {        
-        height = cast(int)newRect.width;
+    NSSize size = widget.cell().cellSizeForBounds(widget.bounds());
+    int width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT;
+    if ((style & DWT.HORIZONTAL) !is 0) {       
+        height = cast(int)Math.ceil(size.height);
         width = height * 10;
     } else {
-        width = cast(int)newRect.width;
+        width = cast(int)Math.ceil(size.width);
         height = width * 10;
     }
     if (wHint !is DWT.DEFAULT) width = wHint;
@@ -134,18 +137,19 @@
 void createHandle () {
     NSSlider widget = cast(NSSlider)new SWTSlider().alloc();
     NSRect rect = new NSRect();
-    if ((style & DWT.HORIZONTAL) !is 0) {
         rect.width = 1;
-    } else {
         rect.height = 1;
-    }
     widget.initWithFrame(rect);
     widget.setMaxValue(100);
-    widget.setTag(jniRef);
     view = widget;
-    parent.contentView().addSubview_(widget);
 }
 
+void deregister() {
+    super.deregister();
+    display.removeWidget(((NSControl)view).cell());
+}
+
+
 /**
  * Returns the amount that the receiver's value will be
  * modified by when the up/down (or right/left) arrows
@@ -231,6 +235,11 @@
     return cast(int)(cast(NSSlider)view).doubleValue();
 }
 
+void register() {
+    super.register();
+    display.addWidget(((NSControl)view).cell(), this);
+}
+
 /**
  * Removes the listener from the collection of listeners who will
  * be notified when the user changes the receiver's value.
@@ -290,8 +299,8 @@
  */
 public void setMaximum (int value) {
     checkWidget();
-    if (value < 0) return;
-    (cast(NSSlider)view).setMaxValue(value);
+    int minimum = (int)((NSSlider)view).minValue();
+    if (value <= minimum) return;
 }
 
 /**
@@ -309,8 +318,8 @@
  */
 public void setMinimum (int value) {
     checkWidget();
-    if (value < 0) return;
-    (cast(NSSlider)view).setMinValue(value);
+    int maximum = (int)((NSSlider)view).maxValue();
+    if (!(0 <= value && value < maximum)) return;
 }
 
 /**