Mercurial > projects > dwt-mac
diff dwt/widgets/ScrollBar.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | 642f460a0908 |
children | 34237ae5156a |
line wrap: on
line diff
--- a/dwt/widgets/ScrollBar.d Tue Oct 21 15:20:04 2008 +0200 +++ b/dwt/widgets/ScrollBar.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 @@ -9,7 +9,7 @@ * IBM Corporation - initial API and implementation * * Port to the D programming language: - * Jacob Carlborg <jacob.carlborg@gmail.com> + * Jacob Carlborg <doob@me.com> *******************************************************************************/ module dwt.widgets.ScrollBar; @@ -19,6 +19,7 @@ import dwt.events.SelectionEvent; import dwt.events.SelectionListener; import dwt.graphics.Point; +import dwt.internal.cocoa.NSRect; import dwt.internal.cocoa.NSScroller; import dwt.internal.cocoa.OS; import dwt.internal.cocoa.id; @@ -92,11 +93,13 @@ * @see Scrollable * @see Scrollable#getHorizontalBar * @see Scrollable#getVerticalBar + * @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 ScrollBar : Widget { NSScroller view; Scrollable parent; - int minimum, maximum, thumb; + int minimum, maximum = 100, thumb = 10; int increment = 1; int pageIncrement = 10; id target; @@ -150,10 +153,9 @@ return checkBits (style, DWT.HORIZONTAL, DWT.VERTICAL, 0, 0, 0, 0); } -void createWidget () { - maximum = 100; - thumb = 10; - super.createWidget(); +void deregister () { + super.deregister (); + display.removeWidget (view); } /** @@ -268,7 +270,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); } @@ -287,8 +289,8 @@ */ public Point getSize () { checkWidget(); -// return getControlSize (handle); - return new Point(0, 0); + NSRect rect = ((NSScroller)view).frame(); + return new Point((int)rect.width, (int)rect.height); } /** @@ -395,8 +397,14 @@ eventTable.unhook(DWT.DefaultSelection,listener); } +void register () { + super.register (); + display.addWidget (view, this); +} + void releaseHandle () { super.releaseHandle (); + if (view !is null) view.release(); view = null; } @@ -404,7 +412,6 @@ super.releaseParent (); if (parent.horizontalBar is this) parent.horizontalBar = null; if (parent.verticalBar is this) parent.verticalBar = null; - parent.resizeClientArea (); } void releaseWidget () { @@ -484,15 +491,14 @@ */ public void setEnabled (bool enabled) { checkWidget(); -// if (enabled) { -// if ((state & DISABLED) is 0) return; -// state &= ~DISABLED; -// OS.EnableControl (handle); -// } else { -// if ((state & DISABLED) !is 0) return; -// state |= DISABLED; -// OS.DisableControl (handle); -// } + if (enabled) { + if ((state & DISABLED) is 0) return; + state &= ~DISABLED; + } else { + if ((state & DISABLED) !is 0) return; + state |= DISABLED; + } + view.setEnabled(enabled); } /** @@ -631,10 +637,12 @@ if (thumb < 1) return; if (increment < 1) return; if (pageIncrement < 1) return; - thumb = Math.min (thumb, maximum - minimum); + this.thumb = thumb = Math.min (thumb, maximum - minimum); + this.maximum = maximum; + this.minimum = minimum; this.increment = increment; this.pageIncrement = pageIncrement; - updateBar(selection, minimum, maximum, thumb); + updateBar (selection, minimum, maximum, thumb); } /** @@ -655,18 +663,17 @@ */ public void setVisible (bool visible) { checkWidget(); - //TODO visibility parent.setScrollBarVisible (this, visible); } -void updateBar(int selection, int minimum, int maximum, int thumb) { - NSScroller widget = cast(NSScroller)view; - selection = Math.max(minimum, Math.min(maximum - thumb, selection)); +void updateBar (int selection, int minimum, int maximum, int thumb) { + NSScroller widget = cast(NSScroller) view; + 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 = minimum is maximum ? 1 : cast(CGFloat)(thumb - minimum) / maximum - minimum; - widget.setFloatValue(fraction, knob); - widget.setEnabled(range > 0); + float fraction = range <= 0 ? 1 : cast(float) (selection - minimum) / range; + CGFloat knob = range <= 0 ? 1 : cast(CGFloat) thumb / (maximum - minimum); + widget.setFloatValue (fraction, knob); + widget.setEnabled (range > 0); } }