diff dwt/custom/ScrolledComposite.d @ 41:6337764516f1

Sync dwt/custom with dwt-linux (took copy of complete folder)
author Frank Benoit <benoit@tionex.de>
date Tue, 07 Oct 2008 16:29:55 +0200
parents a9ab4c738ed8
children 05e03d23ca3a
line wrap: on
line diff
--- a/dwt/custom/ScrolledComposite.d	Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/ScrolledComposite.d	Tue Oct 07 16:29:55 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 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
@@ -7,13 +7,29 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
-module dwt.custom;
+module dwt.custom.ScrolledComposite;
+
+import dwt.dwthelper.utils;
+
 
-import dwt.*;
-import dwt.events.*;
-import dwt.graphics.*;
-import dwt.widgets.*;
+import dwt.DWT;
+import dwt.DWTException;
+import dwt.events.DisposeEvent;
+import dwt.events.DisposeListener;
+import dwt.graphics.Point;
+import dwt.graphics.Rectangle;
+import dwt.widgets.Composite;
+import dwt.widgets.Control;
+import dwt.widgets.Display;
+import dwt.widgets.Event;
+import dwt.widgets.Layout;
+import dwt.widgets.Listener;
+import dwt.widgets.ScrollBar;
+import dwt.widgets.Shell;
+import dwt.custom.ScrolledCompositeLayout;
 
 /**
  * A ScrolledComposite provides scrollbars and will scroll its content when the user
@@ -21,17 +37,17 @@
  *
  *
  * <p>There are two ways to use the ScrolledComposite:
- * 
+ *
  * <p>
- * 1) Set the size of the control that is being scrolled and the ScrolledComposite 
+ * 1) Set the size of the control that is being scrolled and the ScrolledComposite
  * will show scrollbars when the contained control can not be fully seen.
- * 
+ *
  * 2) The second way imitates the way a browser would work.  Set the minimum size of
- * the control and the ScrolledComposite will show scroll bars if the visible area is 
- * less than the minimum size of the control and it will expand the size of the control 
- * if the visible area is greater than the minimum size.  This requires invoking 
+ * the control and the ScrolledComposite will show scroll bars if the visible area is
+ * less than the minimum size of the control and it will expand the size of the control
+ * if the visible area is greater than the minimum size.  This requires invoking
  * both setMinWidth(), setMinHeight() and setExpandHorizontal(), setExpandVertical().
- * 
+ *
  * <code><pre>
  * public static void main (String [] args) {
  *      Display display = new Display ();
@@ -39,7 +55,7 @@
  *      Color blue = display.getSystemColor(DWT.COLOR_BLUE);
  *      Shell shell = new Shell (display);
  *      shell.setLayout(new FillLayout());
- *  
+ *
  *      // set the size of the scrolled content - method 1
  *      final ScrolledComposite sc1 = new ScrolledComposite(shell, DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER);
  *      final Composite c1 = new Composite(sc1, DWT.NONE);
@@ -51,7 +67,7 @@
  *      Button b1 = new Button (c1, DWT.PUSH);
  *      b1.setText("first button");
  *      c1.setSize(c1.computeSize(DWT.DEFAULT, DWT.DEFAULT));
- *      
+ *
  *      // set the minimum width and height of the scrolled content - method 2
  *      final ScrolledComposite sc2 = new ScrolledComposite(shell, DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER);
  *      sc2.setExpandHorizontal(true);
@@ -65,7 +81,7 @@
  *      Button b2 = new Button (c2, DWT.PUSH);
  *      b2.setText("first button");
  *      sc2.setMinSize(c2.computeSize(DWT.DEFAULT, DWT.DEFAULT));
- *      
+ *
  *      Button add = new Button (shell, DWT.PUSH);
  *      add.setText("add children");
  *      final int[] index = new int[]{0};
@@ -77,7 +93,7 @@
  *              // reset size of content so children can be seen - method 1
  *              c1.setSize(c1.computeSize(DWT.DEFAULT, DWT.DEFAULT));
  *              c1.layout();
- *              
+ *
  *              button = new Button(c2, DWT.PUSH);
  *              button.setText("button "+index[0]);
  *              // reset the minimum width and height so children can be seen - method 2
@@ -85,7 +101,7 @@
  *              c2.layout();
  *          }
  *      });
- * 
+ *
  *      shell.open ();
  *      while (!shell.isDisposed ()) {
  *          if (!display.readAndDispatch ()) display.sleep ();
@@ -97,13 +113,16 @@
  * <dl>
  * <dt><b>Styles:</b><dd>H_SCROLL, V_SCROLL
  * </dl>
+ *
+ * @see <a href="http://www.eclipse.org/swt/snippets/#scrolledcomposite">ScrolledComposite snippets</a>
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public class ScrolledComposite : Composite {
 
     Control content;
     Listener contentListener;
     Listener filter;
-    
+
     int minHeight = 0;
     int minWidth = 0;
     bool expandHorizontal = false;
@@ -117,7 +136,7 @@
  * <p>
  * The style value is either one of the style constants defined in
  * class <code>DWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together 
+ * class, or must be built by <em>bitwise OR</em>'ing together
  * (that is, using the <code>int</code> "|" operator) two or more
  * of those <code>DWT</code> style constants. The class description
  * lists the style constants that are applicable to the class.
@@ -137,47 +156,46 @@
  * @see DWT#H_SCROLL
  * @see DWT#V_SCROLL
  * @see #getStyle()
- */ 
+ */
 public this(Composite parent, int style) {
     super(parent, checkStyle(style));
     super.setLayout(new ScrolledCompositeLayout());
     ScrollBar hBar = getHorizontalBar ();
     if (hBar !is null) {
         hBar.setVisible(false);
-        hBar.addListener (DWT.Selection, new Listener () {
+        hBar.addListener (DWT.Selection, new class() Listener  {
             public void handleEvent (Event e) {
                 hScroll();
             }
         });
     }
-    
+
     ScrollBar vBar = getVerticalBar ();
     if (vBar !is null) {
         vBar.setVisible(false);
-        vBar.addListener (DWT.Selection, new Listener () {
+        vBar.addListener (DWT.Selection, new class() Listener {
             public void handleEvent (Event e) {
                 vScroll();
             }
         });
     }
-    
-    contentListener = new Listener() {
+
+    contentListener = new class() Listener {
         public void handleEvent(Event e) {
             if (e.type !is DWT.Resize) return;
             layout(false);
         }
     };
-    
-    filter = new Listener() {
+
+    filter = new class() Listener {
         public void handleEvent(Event event) {
-            if ( null !is cast(Control)event.widget ) {
-                Control control = cast(Control) event.widget;
+            if (auto control = cast(Control)event.widget ) {
                 if (contains(control)) showControl(control);
             }
         }
     };
-    
-    addDisposeListener(new DisposeListener() {
+
+    addDisposeListener(new class() DisposeListener {
         public void widgetDisposed(DisposeEvent e) {
             getDisplay().removeFilter(DWT.FocusIn, filter);
         }
@@ -201,12 +219,12 @@
 }
 
 /**
- * Returns the Always Show Scrollbars flag.  True if the scrollbars are 
- * always shown even if they are not required.  False if the scrollbars are only 
+ * Returns the Always Show Scrollbars flag.  True if the scrollbars are
+ * always shown even if they are not required.  False if the scrollbars are only
  * visible when some part of the composite needs to be scrolled to be seen.
- * The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the 
+ * The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the
  * horizontal and vertical directions.
- * 
+ *
  * @return the Always Show Scrollbars flag value
  */
 public bool getAlwaysShowScrollBars() {
@@ -215,7 +233,7 @@
 }
 
 /**
- * Returns <code>true</code> if the content control 
+ * Returns <code>true</code> if the content control
  * will be expanded to fill available horizontal space.
  *
  * @return the receiver's horizontal expansion state
@@ -224,7 +242,7 @@
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 3.2
  */
 public bool getExpandHorizontal() {
@@ -233,7 +251,7 @@
 }
 
 /**
- * Returns <code>true</code> if the content control 
+ * Returns <code>true</code> if the content control
  * will be expanded to fill available vertical space.
  *
  * @return the receiver's vertical expansion state
@@ -242,7 +260,7 @@
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 3.2
  */
 public bool getExpandVertical() {
@@ -259,7 +277,7 @@
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 3.2
  */
 public int getMinWidth() {
@@ -276,7 +294,7 @@
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 3.2
  */
 public int getMinHeight() {
@@ -286,7 +304,7 @@
 
 /**
  * Get the content that is being scrolled.
- * 
+ *
  * @return the control displayed in the content area
  */
 public Control getContent() {
@@ -295,14 +313,16 @@
 }
 
 /**
- * Returns <code>true</code> if the receiver automatically scrolls to a focused child control 
+ * Returns <code>true</code> if the receiver automatically scrolls to a focused child control
  * to make it visible. Otherwise, returns <code>false</code>.
- * 
+ *
+ * @return a bool indicating whether focused child controls are automatically scrolled into the viewport
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 3.4
  */
 public bool getShowFocusedControl() {
@@ -320,13 +340,13 @@
 bool needHScroll(Rectangle contentRect, bool vVisible) {
     ScrollBar hBar = getHorizontalBar();
     if (hBar is null) return false;
-    
+
     Rectangle hostRect = getBounds();
     int border = getBorderWidth();
     hostRect.width -= 2*border;
     ScrollBar vBar = getVerticalBar();
     if (vVisible && vBar !is null) hostRect.width -= vBar.getSize().x;
-    
+
     if (!expandHorizontal && contentRect.width > hostRect.width) return true;
     if (expandHorizontal && minWidth > hostRect.width) return true;
     return false;
@@ -335,31 +355,31 @@
 bool needVScroll(Rectangle contentRect, bool hVisible) {
     ScrollBar vBar = getVerticalBar();
     if (vBar is null) return false;
-    
+
     Rectangle hostRect = getBounds();
     int border = getBorderWidth();
     hostRect.height -= 2*border;
     ScrollBar hBar = getHorizontalBar();
     if (hVisible && hBar !is null) hostRect.height -= hBar.getSize().y;
-    
+
     if (!expandVertical && contentRect.height > hostRect.height) return true;
     if (expandVertical && minHeight > hostRect.height) return true;
     return false;
 }
 
 /**
- * Return the point in the content that currently appears in the top left 
+ * Return the point in the content that currently appears in the top left
  * corner of the scrolled composite.
- * 
- * @return the point in the content that currently appears in the top left 
+ *
+ * @return the point in the content that currently appears in the top left
  * corner of the scrolled composite.  If no content has been set, this returns
  * (0, 0).
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 2.0
  */
 public Point getOrigin() {
@@ -369,14 +389,14 @@
     return new Point(-location.x, -location.y);
 }
 /**
- * Scrolls the content so that the specified point in the content is in the top 
- * left corner.  If no content has been set, nothing will occur.  
- * 
- * Negative values will be ignored.  Values greater than the maximum scroll 
+ * Scrolls the content so that the specified point in the content is in the top
+ * left corner.  If no content has been set, nothing will occur.
+ *
+ * Negative values will be ignored.  Values greater than the maximum scroll
  * distance will result in scrolling to the end of the scrollbar.
  *
- * @param origin the point on the content to appear in the top left corner 
- * 
+ * @param origin the point on the content to appear in the top left corner
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -388,21 +408,21 @@
     setOrigin(origin.x, origin.y);
 }
 /**
- * Scrolls the content so that the specified point in the content is in the top 
- * left corner.  If no content has been set, nothing will occur.  
- * 
- * Negative values will be ignored.  Values greater than the maximum scroll 
+ * Scrolls the content so that the specified point in the content is in the top
+ * left corner.  If no content has been set, nothing will occur.
+ *
+ * Negative values will be ignored.  Values greater than the maximum scroll
  * distance will result in scrolling to the end of the scrollbar.
  *
- * @param x the x coordinate of the content to appear in the top left corner 
- * 
- * @param y the y coordinate of the content to appear in the top left corner 
- * 
+ * @param x the x coordinate of the content to appear in the top left corner
+ *
+ * @param y the y coordinate of the content to appear in the top left corner
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
+ *
  * @since 2.0
  */
 public void setOrigin(int x, int y) {
@@ -425,14 +445,14 @@
     content.setLocation(x, y);
 }
 /**
- * Set the Always Show Scrollbars flag.  True if the scrollbars are 
- * always shown even if they are not required.  False if the scrollbars are only 
+ * Set the Always Show Scrollbars flag.  True if the scrollbars are
+ * always shown even if they are not required.  False if the scrollbars are only
  * visible when some part of the composite needs to be scrolled to be seen.
- * The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the 
+ * The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the
  * horizontal and vertical directions.
- * 
+ *
  * @param show true to show the scrollbars even when not required, false to show scrollbars only when required
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -451,9 +471,9 @@
 
 /**
  * Set the content that will be scrolled.
- * 
+ *
  * @param content the control to be displayed in the content area
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -463,9 +483,9 @@
     checkWidget();
     if (this.content !is null && !this.content.isDisposed()) {
         this.content.removeListener(DWT.Resize, contentListener);
-        this.content.setBounds(new Rectangle(-200, -200, 0, 0));    
+        this.content.setBounds(new Rectangle(-200, -200, 0, 0));
     }
-    
+
     this.content = content;
     ScrollBar vBar = getVerticalBar ();
     ScrollBar hBar = getHorizontalBar ();
@@ -489,15 +509,15 @@
     }
 }
 /**
- * Configure the ScrolledComposite to resize the content object to be as wide as the 
+ * Configure the ScrolledComposite to resize the content object to be as wide as the
  * ScrolledComposite when the width of the ScrolledComposite is greater than the
  * minimum width specified in setMinWidth.  If the ScrolledComposite is less than the
  * minimum width, the content will not be resized and instead the horizontal scroll bar will be
  * used to view the entire width.
  * If expand is false, this behaviour is turned off.  By default, this behaviour is turned off.
- * 
+ *
  * @param expand true to expand the content control to fill available horizontal space
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -510,15 +530,15 @@
     layout(false);
 }
 /**
- * Configure the ScrolledComposite to resize the content object to be as tall as the 
+ * Configure the ScrolledComposite to resize the content object to be as tall as the
  * ScrolledComposite when the height of the ScrolledComposite is greater than the
  * minimum height specified in setMinHeight.  If the ScrolledComposite is less than the
  * minimum height, the content will not be resized and instead the vertical scroll bar will be
  * used to view the entire height.
  * If expand is false, this behaviour is turned off.  By default, this behaviour is turned off.
- * 
+ *
  * @param expand true to expand the content control to fill available vertical space
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -545,17 +565,17 @@
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
  */
-public void setLayout (Layout layout) {
+public override void setLayout (Layout layout) {
     checkWidget();
     return;
 }
 /**
  * Specify the minimum height at which the ScrolledComposite will begin scrolling the
- * content with the vertical scroll bar.  This value is only relevant if  
+ * content with the vertical scroll bar.  This value is only relevant if
  * setExpandVertical(true) has been set.
- * 
+ *
  * @param height the minimum height or 0 for default height
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -566,11 +586,11 @@
 }
 /**
  * Specify the minimum width and height at which the ScrolledComposite will begin scrolling the
- * content with the horizontal scroll bar.  This value is only relevant if  
+ * content with the horizontal scroll bar.  This value is only relevant if
  * setExpandHorizontal(true) and setExpandVertical(true) have been set.
- * 
+ *
  * @param size the minimum size or null for the default size
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -585,12 +605,12 @@
 }
 /**
  * Specify the minimum width and height at which the ScrolledComposite will begin scrolling the
- * content with the horizontal scroll bar.  This value is only relevant if  
+ * content with the horizontal scroll bar.  This value is only relevant if
  * setExpandHorizontal(true) and setExpandVertical(true) have been set.
- * 
+ *
  * @param width the minimum width or 0 for default width
  * @param height the minimum height or 0 for default height
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -605,11 +625,11 @@
 }
 /**
  * Specify the minimum width at which the ScrolledComposite will begin scrolling the
- * content with the horizontal scroll bar.  This value is only relevant if  
+ * content with the horizontal scroll bar.  This value is only relevant if
  * setExpandHorizontal(true) has been set.
- * 
+ *
  * @param width the minimum width or 0 for default width
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -622,18 +642,18 @@
 /**
  * Configure the receiver to automatically scroll to a focused child control
  * to make it visible.
- * 
- * If show is <code>false</code>, show a focused control is off.  
+ *
+ * If show is <code>false</code>, show a focused control is off.
  * By default, show a focused control is off.
- * 
+ *
  * @param show <code>true</code> to show a focused control.
- * 
+ *
  * @exception DWTException <ul>
  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
- * 
- *  @since 3.4
+ *
+ * @since 3.4
  */
 public void setShowFocusedControl(bool show) {
     checkWidget();
@@ -668,7 +688,7 @@
     if (control is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (control.isDisposed ()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     if (!contains(control)) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    
+
     Rectangle itemRect = getDisplay().map(control.getParent(), this, control.getBounds());
     Rectangle area = getClientArea();
     Point origin = getOrigin();