changeset 63:a3f5118c8b37

Ported CoolBar and CoolItem
author Jacob Carlborg <doob@me.com>
date Tue, 23 Dec 2008 22:38:33 +0100
parents 10eaa644646f
children cda53a4e462f
files dwt/widgets/CoolBar.d dwt/widgets/CoolItem.d
diffstat 2 files changed, 33 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/widgets/CoolBar.d	Tue Dec 23 22:21:02 2008 +0100
+++ b/dwt/widgets/CoolBar.d	Tue Dec 23 22:38:33 2008 +0100
@@ -7,6 +7,9 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <doob@me.com>
  *******************************************************************************/
 module dwt.widgets.CoolBar;
 
@@ -21,6 +24,12 @@
 import dwt.graphics.Point;
 import dwt.graphics.Rectangle;
 
+import dwt.widgets.CoolItem;
+import dwt.widgets.Composite;
+import dwt.widgets.Control;
+import dwt.widgets.Event;
+import dwt.widgets.Listener;
+
 /**
  * Instances of this class provide an area for dynamically
  * positioning the items they contain.
@@ -49,17 +58,17 @@
  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public class CoolBar : Composite {
-    CoolItem[][] items = new CoolItem[0][0];
+    CoolItem[][] items;
     CoolItem[] originalItems = new CoolItem[0];
     Cursor hoverCursor, dragCursor, cursor;
     CoolItem dragging = null;
     int mouseXOffset, itemXOffset;
     bool isLocked = false;
     bool inDispose = false;
-    static final int ROW_SPACING = 2;
-    static final int CLICK_DISTANCE = 3;
-    static final int DEFAULT_COOLBAR_WIDTH = 0;
-    static final int DEFAULT_COOLBAR_HEIGHT = 0;
+    static const int ROW_SPACING = 2;
+    static const int CLICK_DISTANCE = 3;
+    static const int DEFAULT_COOLBAR_WIDTH = 0;
+    static const int DEFAULT_COOLBAR_HEIGHT = 0;
     
 /**
  * Constructs a new instance of this class given its parent
@@ -99,7 +108,7 @@
         hoverCursor = new Cursor(display, DWT.CURSOR_SIZEWE);
     }
     dragCursor = new Cursor(display, DWT.CURSOR_SIZEALL);
-    Listener listener = new Listener() {
+    Listener listener = new class () Listener {
         public void handleEvent(Event event) {
             switch (event.type) {
                 case DWT.Dispose:           onDispose(event);           break;
@@ -110,10 +119,11 @@
                 case DWT.MouseDoubleClick:  onMouseDoubleClick(event);  break;
                 case DWT.Paint:             onPaint(event);             break;
                 case DWT.Resize:            onResize();                 break;
+                default:
             }
         }
     };
-    int[] events = new int[] { 
+    int[] events = [
         DWT.Dispose, 
         DWT.MouseDown,
         DWT.MouseExit, 
@@ -122,7 +132,7 @@
         DWT.MouseDoubleClick,
         DWT.Paint,
         DWT.Resize
-    };
+    ];
     for (int i = 0; i < events.length; i++) {
         addListener(events[i], listener);   
     }
@@ -1026,7 +1036,7 @@
  */
 public int[] getWrapIndices () {
     checkWidget();
-    if (items.length <= 1) return new int[]{};
+    if (items.length <= 1) return [];
     int[] wrapIndices = new int[items.length - 1];
     int i = 0, nextWrap = items[0].length;
     for (int row = 1; row < items.length; row++) {
--- a/dwt/widgets/CoolItem.d	Tue Dec 23 22:21:02 2008 +0100
+++ b/dwt/widgets/CoolItem.d	Tue Dec 23 22:38:33 2008 +0100
@@ -7,6 +7,9 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <doob@me.com>
  *******************************************************************************/
 module dwt.widgets.CoolItem;
 
@@ -25,6 +28,14 @@
 import dwt.graphics.Point;
 import dwt.graphics.RGB;
 import dwt.graphics.Rectangle;
+
+import dwt.widgets.Control;
+import dwt.widgets.CoolBar;
+import dwt.widgets.Event;
+import dwt.widgets.Item;
+import dwt.widgets.ToolBar;
+import dwt.widgets.ToolItem;
+import dwt.widgets.TypedListener;
  
 /**
  * Instances of this class are selectable user interface
@@ -261,7 +272,7 @@
     Color black = display.getSystemColor (DWT.COLOR_BLACK);
     Color background = parent.getBackground ();
     
-    PaletteData palette = new PaletteData (new RGB[]{foreground.getRGB(), background.getRGB(), black.getRGB()});
+    PaletteData palette = new PaletteData ([foreground.getRGB(), background.getRGB(), black.getRGB()]);
     ImageData imageData = new ImageData (width, height, 4, palette);
     imageData.transparentPixel = 1;
     Image image = new Image (display, imageData);
@@ -624,9 +635,9 @@
             if (chevron is null) {
                 chevron = new ToolBar (parent, DWT.FLAT | DWT.NO_FOCUS);
                 ToolItem toolItem = new ToolItem (chevron, DWT.PUSH);
-                toolItem.addListener (DWT.Selection, new Listener() {
+                toolItem.addListener (DWT.Selection, new class () Listener {
                     public void handleEvent (Event event) {
-                        CoolItem.this.onSelection (event);
+                        CoolItem.outer.onSelection (event);
                     }
                 });
             }