changeset 11:b61e7baf0574

Reworked the DrawingBoard for better organization. And also removed the linker fixes in the source files and moved it to dsss.conf by adding buildflags+=-L-lDD-tango-util.
author Jesse Phillips <Jesse.K.Phillips+D@gmail.com>
date Thu, 14 Feb 2008 13:04:14 -0800
parents ab50be5df9a0
children 47a66440dddd
files dsss.conf dwtexamples/addressbook/AddressBook.d dwtexamples/controlexample/ControlExample.d dwtexamples/controlexample/CustomControlExample.d dwtexamples/helloworld/HelloWorld1.d dwtexamples/helloworld/HelloWorld2.d dwtexamples/helloworld/HelloWorld3.d dwtexamples/helloworld/HelloWorld4.d dwtexamples/helloworld/HelloWorld5.d dwtexamples/simple.d dwtexamples/test.d dwtsnippets/images/cancel.gif dwtsnippets/images/eclipse.png dwtsnippets/styledtext/Snippet163.d dwtsnippets/styledtext/Snippet189.d dwtsnippets/text/Snippet258.d dwtsnippets/tooltips/Snippet41.d user/doob_test1/MouseHandler.d user/doob_test1/PaintHandler.d user/doob_test1/draw.d user/drawingboard/DrawingBoard.d user/drawingboard/MouseHandler.d user/drawingboard/PaintHandler.d user/nascent_test1.d user/nascent_test2.d
diffstat 25 files changed, 539 insertions(+), 303 deletions(-) [+]
line wrap: on
line diff
--- a/dsss.conf	Tue Feb 12 20:02:08 2008 -0800
+++ b/dsss.conf	Thu Feb 14 13:04:14 2008 -0800
@@ -5,6 +5,8 @@
     #buildflags+= -L/SUBSYSTEM:windows:5
     buildflags+= -L/SUBSYSTEM:console:5
 }
+# The linker error work around
+buildflags+= -L-lDD-tango-util
 
 [dwtexamples/simple.d]
 [dwtexamples/helloworld/HelloWorld1.d]
@@ -13,9 +15,12 @@
 [dwtexamples/helloworld/HelloWorld4.d]
 [dwtexamples/helloworld/HelloWorld5.d]
 
-[user/doob_test1/draw.d]
-[user/nascent_test1.d]
-[user/nascent_test2.d]
+[dwtsnippets/styledtext/Snippet163.d]
+[dwtsnippets/styledtext/Snippet189.d]
+[dwtsnippets/text/Snippet258.d]
+[dwtsnippets/tooltips/Snippet41.d]
+
+[user/drawingboard/DrawingBoard.d]
 [user/torhu_synctest.d]
 
 [snippets/opengl_test1.d]
--- a/dwtexamples/addressbook/AddressBook.d	Tue Feb 12 20:02:08 2008 -0800
+++ b/dwtexamples/addressbook/AddressBook.d	Thu Feb 14 13:04:14 2008 -0800
@@ -29,10 +29,6 @@
 import dwt.widgets.TableColumn;
 import dwt.widgets.TableItem;
 
-import dwtexamples.addressbook.SearchDialog;
-import dwtexamples.addressbook.DataEntryDialog;
-import dwtexamples.addressbook.FindListener;
-
 import dwt.dwthelper.ResourceBundle;
 
 import tango.core.Exception;
@@ -43,13 +39,9 @@
 import TextUtil = tango.text.Util;
 import Unicode = tango.text.Unicode;
 
-/*** Linker workaround start ***/
-import tango.io.Stdout;
-import tango.math.Math;
-import tango.text.convert.Format;
-import tango.util.Convert;
-import tango.util.PathUtil;
-/*** Linker workaround end ***/
+import dwtexamples.addressbook.SearchDialog;
+import dwtexamples.addressbook.DataEntryDialog;
+import dwtexamples.addressbook.FindListener;
 
 void main() {
     Display display = new Display();
--- a/dwtexamples/controlexample/ControlExample.d	Tue Feb 12 20:02:08 2008 -0800
+++ b/dwtexamples/controlexample/ControlExample.d	Thu Feb 14 13:04:14 2008 -0800
@@ -60,15 +60,6 @@
 import tango.io.Stdout;
 import Math = tango.math.Math;
 
-
-/*** Linker workaround start ***/
-import tango.io.Stdout;
-import tango.math.Math;
-import tango.text.convert.Format;
-import tango.util.Convert;
-import tango.util.PathUtil;
-/*** Linker workaround end ***/
-
 version(JIVE){
     import jive.stacktrace;
 }
--- a/dwtexamples/controlexample/CustomControlExample.d	Tue Feb 12 20:02:08 2008 -0800
+++ b/dwtexamples/controlexample/CustomControlExample.d	Thu Feb 14 13:04:14 2008 -0800
@@ -12,21 +12,20 @@
  *******************************************************************************/
 module dwtexamples.controlexample.CustomControlExample;
 
-
 import dwt.layout.FillLayout;
 import dwt.widgets.Composite;
 import dwt.widgets.Display;
 import dwt.widgets.Shell;
 
+import tango.io.Stdout;
+
 import dwtexamples.controlexample.ControlExample;
 import dwtexamples.controlexample.CComboTab;
 import dwtexamples.controlexample.CLabelTab;
 import dwtexamples.controlexample.CTabFolderTab;
 import dwtexamples.controlexample.SashFormTab;
 import dwtexamples.controlexample.StyledTextTab;
-
 import dwtexamples.controlexample.Tab;
-import tango.io.Stdout;
 
 version( CUSTOM_CONTROL_EXAMPLE_MAIN ){
     void main(){
--- a/dwtexamples/helloworld/HelloWorld1.d	Tue Feb 12 20:02:08 2008 -0800
+++ b/dwtexamples/helloworld/HelloWorld1.d	Thu Feb 14 13:04:14 2008 -0800
@@ -28,10 +28,3 @@
     display.dispose ();
 }
 
-// for unknown reason, there are linker errors. These imports are the workaround
-import tango.io.Stdout;
-import tango.math.Math;
-import tango.text.convert.Format;
-import tango.util.Convert;
-import tango.util.PathUtil;
-
--- a/dwtexamples/helloworld/HelloWorld2.d	Tue Feb 12 20:02:08 2008 -0800
+++ b/dwtexamples/helloworld/HelloWorld2.d	Thu Feb 14 13:04:14 2008 -0800
@@ -32,10 +32,3 @@
     }
     display.dispose ();
 }
-
-// for unknown reason, there are linker errors. These imports are the workaround
-import tango.io.Stdout;
-import tango.math.Math;
-import tango.text.convert.Format;
-import tango.util.Convert;
-import tango.util.PathUtil;
--- a/dwtexamples/helloworld/HelloWorld3.d	Tue Feb 12 20:02:08 2008 -0800
+++ b/dwtexamples/helloworld/HelloWorld3.d	Thu Feb 14 13:04:14 2008 -0800
@@ -40,10 +40,3 @@
     }
     display.dispose ();
 }
-
-// for unknown reason, there are linker errors. These imports are the workaround
-import tango.io.Stdout;
-import tango.math.Math;
-import tango.text.convert.Format;
-import tango.util.Convert;
-import tango.util.PathUtil;
--- a/dwtexamples/helloworld/HelloWorld4.d	Tue Feb 12 20:02:08 2008 -0800
+++ b/dwtexamples/helloworld/HelloWorld4.d	Thu Feb 14 13:04:14 2008 -0800
@@ -33,11 +33,3 @@
     }
     display.dispose ();
 }
-
-
-// for unknown reason, there are linker errors. These imports are the workaround
-import tango.io.Stdout;
-import tango.math.Math;
-import tango.text.convert.Format;
-import tango.util.Convert;
-import tango.util.PathUtil;
--- a/dwtexamples/helloworld/HelloWorld5.d	Tue Feb 12 20:02:08 2008 -0800
+++ b/dwtexamples/helloworld/HelloWorld5.d	Thu Feb 14 13:04:14 2008 -0800
@@ -50,10 +50,3 @@
     }
     display.dispose ();
 }
-
-// for unknown reason, there are linker errors. These imports are the workaround
-import tango.io.Stdout;
-import tango.math.Math;
-import tango.text.convert.Format;
-import tango.util.Convert;
-import tango.util.PathUtil;
--- a/dwtexamples/simple.d	Tue Feb 12 20:02:08 2008 -0800
+++ b/dwtexamples/simple.d	Thu Feb 14 13:04:14 2008 -0800
@@ -1,22 +1,14 @@
 module dwtexample.simple;
 
 import dwt.DWT;
+import dwt.events.SelectionEvent;
+import dwt.events.SelectionListener;
+import dwt.widgets.Button;
 import dwt.widgets.Display;
 import dwt.widgets.Shell;
-import dwt.widgets.Button;
 import dwt.widgets.Text;
 
 import tango.io.Stdout;
-import tango.math.Math;
-import tango.text.convert.Format;
-import tango.util.Convert;
-import tango.util.PathUtil;
-import dwt.events.SelectionListener;
-import dwt.events.SelectionEvent;
-
-
-import dwt.DWT;
-import dwt.widgets.Display;
 
 void main(){
 
--- a/dwtexamples/test.d	Tue Feb 12 20:02:08 2008 -0800
+++ b/dwtexamples/test.d	Thu Feb 14 13:04:14 2008 -0800
@@ -1,9 +1,9 @@
 module test;
 
-private import dwt.internal.gtk.c.cairo;
-private import tango.core.Traits;
-private import tango.io.Stdout;
-private import tango.stdc.stdio;
+import dwt.internal.gtk.c.cairo;
+import tango.core.Traits;
+import tango.io.Stdout;
+import tango.stdc.stdio;
 
 struct lock {
 static void lock() { printf("lock\n");}
@@ -41,4 +41,4 @@
     int i = cairo_version();
     Stdout.formatln("OS.cairo_version() returns: {}    cairo_version() returns: {}", p, i ).newline;
     printf("OS.cairo_version_string returns: %s\n",  cairo_version_string() );
-}
\ No newline at end of file
+}
Binary file dwtsnippets/images/cancel.gif has changed
Binary file dwtsnippets/images/eclipse.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/styledtext/Snippet163.d	Thu Feb 14 13:04:14 2008 -0800
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ * D Port:
+ *     Jesse Phillips <Jesse.K.Phillips+D> gmail.com
+ *******************************************************************************/
+
+module dwtsnippets.styledtext.Snippet163;
+
+/*
+ * Setting the font style, foreground and background colors of StyledText
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import dwt.DWT;
+import dwt.custom.StyledText;
+import dwt.custom.StyleRange;
+import dwt.layout.FillLayout;
+import dwt.widgets.Display;
+import dwt.widgets.Shell;
+
+void main() {
+    Display display = new Display();
+    Shell shell = new Shell(display);
+    shell.setLayout(new FillLayout());
+    StyledText text = new StyledText (shell, DWT.BORDER);
+    text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");
+    // make 0123456789 appear bold
+    StyleRange style1 = new StyleRange();
+    style1.start = 0;
+    style1.length = 10;
+    style1.fontStyle = DWT.BOLD;
+    text.setStyleRange(style1);
+    // make ABCDEFGHIJKLM have a red font
+    StyleRange style2 = new StyleRange();
+    style2.start = 11;
+    style2.length = 13;
+    style2.foreground = display.getSystemColor(DWT.COLOR_RED);
+    text.setStyleRange(style2);
+    // make NOPQRSTUVWXYZ have a blue background
+    StyleRange style3 = new StyleRange();
+    style3.start = 25;
+    style3.length = 13;
+    style3.background = display.getSystemColor(DWT.COLOR_BLUE);
+    text.setStyleRange(style3);
+    
+    shell.pack();
+    shell.open();
+    while (!shell.isDisposed()) {
+        if (!display.readAndDispatch())
+            display.sleep();
+    }
+    display.dispose();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/styledtext/Snippet189.d	Thu Feb 14 13:04:14 2008 -0800
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ * D Port:
+ *     Jesse Phillips <Jesse.K.Phillips+D> gmail.com
+ *******************************************************************************/
+
+module dwtsnippets.styledtext.Snippet189;
+
+/*
+ * Text with underline and strike through
+ * 
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ * 
+ * @since 3.1
+ */
+
+import dwt.DWT;
+import dwt.custom.StyledText;
+import dwt.custom.StyleRange;
+import dwt.layout.FillLayout;
+import dwt.widgets.Display;
+import dwt.widgets.Shell;
+
+void main () {
+    Display display = new Display ();
+    Shell shell = new Shell (display);
+    shell.setText("StyledText with underline and strike through");
+    shell.setLayout(new FillLayout());
+    StyledText text = new StyledText (shell, DWT.BORDER);
+    text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");
+    // make 0123456789 appear underlined
+    StyleRange style1 = new StyleRange();
+    style1.start = 0;
+    style1.length = 10;
+    style1.underline = true;
+    text.setStyleRange(style1);
+    // make ABCDEFGHIJKLM have a strike through
+    StyleRange style2 = new StyleRange();
+    style2.start = 11;
+    style2.length = 13;
+    style2.strikeout = true;
+    text.setStyleRange(style2);
+    // make NOPQRSTUVWXYZ appear underlined and have a strike through
+    StyleRange style3 = new StyleRange();
+    style3.start = 25;
+    style3.length = 13;
+    style3.underline = true;
+    style3.strikeout = true;
+    text.setStyleRange(style3);
+    shell.pack();
+    shell.open();
+    while (!shell.isDisposed ()) {
+        if (!display.readAndDispatch ()) display.sleep ();
+    }
+    display.dispose ();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/text/Snippet258.d	Thu Feb 14 13:04:14 2008 -0800
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ * D port:
+ *     Jesse Phillips <Jesse.K.Phillips+D> gmail.com
+ *******************************************************************************/
+
+module dwtsnippets.text.Snippet258;
+
+/*
+ * Create a search text control
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ * 
+ * @since 3.3
+ */ 
+import dwt.DWT;
+import dwt.graphics.Image;
+import dwt.widgets.Display;
+import dwt.widgets.Shell;
+import dwt.widgets.Text;
+import dwt.widgets.ToolBar;
+import dwt.widgets.ToolItem;
+import dwt.layout.GridLayout;
+import dwt.layout.GridData;
+import dwt.events.SelectionAdapter;
+import dwt.events.SelectionEvent;
+
+import tango.io.Stdout;
+
+void main() {
+    Display display = new Display();
+    Shell shell = new Shell(display);
+    shell.setLayout(new GridLayout(2, false));
+    
+    final Text text = new Text(shell, DWT.SEARCH | DWT.CANCEL);
+    Image image = null;
+    if ((text.getStyle() & DWT.CANCEL) == 0) {
+        image = new Image (display, "../images/cancel.gif");
+        ToolBar toolBar = new ToolBar (shell, DWT.FLAT);
+        ToolItem item = new ToolItem (toolBar, DWT.PUSH);
+        item.setImage (image);
+        item.addSelectionListener(new class SelectionAdapter {
+            public void widgetSelected(SelectionEvent e) {
+                text.setText("");
+                Stdout("Search cancelled").newline;
+            }
+        });
+    }
+    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+    text.setText("Search text");
+    text.addSelectionListener(new class SelectionAdapter {
+        public void widgetDefaultSelected(SelectionEvent e) {
+            if (e.detail == DWT.CANCEL) {
+                Stdout("Search cancelled").newline;
+            } else {
+                Stdout("Searching for: ")(text.getText())("...").newline;
+            }
+        }
+    });
+
+    shell.pack();
+    shell.open();
+    while (!shell.isDisposed()) {
+        if (!display.readAndDispatch()) display.sleep();
+    }
+    if (image != null) image.dispose();
+    display.dispose();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/tooltips/Snippet41.d	Thu Feb 14 13:04:14 2008 -0800
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ * D Port:
+ *     Jesse Phillips <Jesse.K.Phillips+D> gmail.com
+ *******************************************************************************/
+
+module dwtsnippets.tooltips.Snippet41;
+
+/*
+ * Tool Tips example snippet: create tool tips for a tab item, tool item, and shell
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import dwt.DWT;
+import dwt.widgets.Display;
+import dwt.widgets.Shell;
+import dwt.widgets.TabFolder;
+import dwt.widgets.TabItem;
+import dwt.widgets.ToolBar;
+import dwt.widgets.ToolItem;
+
+void main () {
+    char[] string = "This is a string\nwith a new line.";
+    Display display = new Display ();
+    Shell shell = new Shell (display);
+    TabFolder folder = new TabFolder (shell, DWT.BORDER);
+
+    folder.setSize (200, 200);
+    TabItem item0 = new TabItem (folder, 0);
+    item0.setToolTipText ("TabItem toolTip: " ~ string);
+
+    ToolBar bar = new ToolBar (shell, DWT.BORDER);
+    bar.setBounds (0, 200, 200, 64);
+    ToolItem item1 = new ToolItem (bar, 0);
+    item1.setToolTipText ("ToolItem toolTip: " ~ string);
+    shell.setToolTipText ("Shell toolTip: " ~ string);
+
+    shell.open ();
+    while (!shell.isDisposed ()) {
+        if (!display.readAndDispatch ()) display.sleep ();
+    }
+    display.dispose ();
+}
--- a/user/doob_test1/MouseHandler.d	Tue Feb 12 20:02:08 2008 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-module user.doob_test1.MouseHandler;
-
-private import dwt.events.MouseListener;
-private import dwt.events.MouseMoveListener;
-private import dwt.events.MouseEvent;
-
-private import tango.io.Stdout;
-
-private import user.doob_test1.PaintHandler;
-
-class MouseHandler : MouseListener, MouseMoveListener {
-    PaintHandler hPaint;
-    bool pressed = false;
-
-    this(PaintHandler ph) {
-        hPaint = ph;
-    }
-
-    void mouseDoubleClick(MouseEvent e) {
-    }
-
-    void mouseDown(MouseEvent e) {
-        hPaint.x = e.x;
-        hPaint.y = e.y;
-        pressed = true;
-    }
-
-    void mouseUp(MouseEvent e) {
-        hPaint.xDiff = e.x-hPaint.x;
-        hPaint.yDiff = e.y-hPaint.y;
-        hPaint.reDraw();
-        pressed = false;
-    }
-
-    void mouseMove(MouseEvent e) {
-        if(pressed) {
-            hPaint.xDiff = e.x-hPaint.x;
-            hPaint.yDiff = e.y-hPaint.y;
-            hPaint.reDraw();
-        }
-    }
-}
\ No newline at end of file
--- a/user/doob_test1/PaintHandler.d	Tue Feb 12 20:02:08 2008 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-module user.doob_test1.PaintHandler;
-
-private import dwt.DWT;
-private import dwt.events.PaintListener;
-private import dwt.widgets.Canvas;
-private import dwt.widgets.Display;
-
-private import dwt.graphics.GC;
-private import dwt.graphics.Rectangle;
-
-private import tango.io.Stdout;
-
-class PaintHandler : PaintListener {
-    public int x, y, xDiff, yDiff;
-    Canvas canvas;
-    Display display;
-
-    this(Canvas c, Display d) {
-        canvas = c;
-        display = d;
-    }
-
-    public void paintControl(PaintEvent e) {
-         Rectangle clientArea = canvas.getClientArea();
-         e.gc.setBackground(display.getSystemColor(DWT.COLOR_CYAN));
-            e.gc.fillRoundRectangle(x,y,xDiff,yDiff,50,50);
-   }
-
-    public void reDraw() {
-        canvas.redraw();
-    }
-}
\ No newline at end of file
--- a/user/doob_test1/draw.d	Tue Feb 12 20:02:08 2008 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-module user.doob_test1.draw;
-
-private import dwt.DWT;
-private import dwt.events.SelectionListener;
-private import dwt.events.SelectionEvent;
-private import dwt.layout.FillLayout;
-private import dwt.widgets.Canvas;
-private import dwt.widgets.Control;
-private import dwt.widgets.Display;
-private import dwt.widgets.Shell;
-private import dwt.events.PaintListener;
-private import dwt.events.MouseListener;
-private import dwt.events.MouseMoveListener;
-
-private import tango.io.Stdout;
-
-private import user.doob_test1.MouseHandler;
-private import user.doob_test1.PaintHandler;
-
-
-import tango.io.Stdout;
-import tango.math.Math;
-import tango.text.convert.Format;
-import tango.util.Convert;
-import tango.util.PathUtil;
-import dwt.events.SelectionListener;
-import dwt.events.SelectionEvent;
-
-void main(){
-    try{
-        auto display = new Display();
-        auto shell = new Shell(display);
-
-        auto canvas = new Canvas(shell,DWT.NO_REDRAW_RESIZE);
-        auto hPaint= new PaintHandler(canvas, display);
-        auto hMouse = new MouseHandler(hPaint);
-
-        shell.setText("Draw window");
-        shell.setSize(500, 500);
-        shell.setLayout(new FillLayout());
-
-        canvas.addPaintListener(hPaint);
-        canvas.addMouseListener(hMouse);
-        canvas.addMouseMoveListener(hMouse);
-        shell.layout();
-        shell.open();
-        while (!shell.isDisposed()) {
-            if (!display.readAndDispatch()) {
-                display.sleep();
-            }
-        }
-        Stdout("Stop").newline.flush;
-    } catch (Exception e) {
-        Stdout.formatln (e.toString);
-    }
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/drawingboard/DrawingBoard.d	Thu Feb 14 13:04:14 2008 -0800
@@ -0,0 +1,93 @@
+/*
+ * This example is meant to let the user have a area to draw simple shapes.
+ * It uses the FillLayout layout manager.
+ * For information on layout managers an excellent read is:
+ * http://www.eclipse.org/articles/Article-Understanding-Layouts/Understanding-Layouts.htm
+ *
+ * Written by Jesse Phillips <Jesse.K.Phillips+D> gmail.com
+ * All code is free with no restrictions
+ */
+
+module user.drawingboard.DrawingBoard;
+
+import dwt.DWT;
+import dwt.events.MouseListener;
+import dwt.events.MouseMoveListener;
+import dwt.events.PaintListener;
+import dwt.events.SelectionListener;
+import dwt.events.SelectionEvent;
+import dwt.layout.FillLayout;
+import dwt.widgets.Button;
+import dwt.widgets.Canvas;
+import dwt.widgets.Control;
+import dwt.widgets.Display;
+import dwt.widgets.Group;
+import dwt.widgets.Menu;
+import dwt.widgets.MenuItem;
+import dwt.widgets.Shell;
+
+import tango.io.Stdout;
+
+import user.drawingboard.MouseHandler;
+import user.drawingboard.PaintHandler;
+
+void main(){
+    try{
+        auto display = new Display();
+        auto shell = new Shell(display);
+        auto layout = new FillLayout();
+        shell.setSize(500, 500);
+        shell.setText("Draw window");
+        shell.setLayout(layout);
+
+        auto menu = new Menu(shell, DWT.BAR);
+        auto colorMenuHeader = new MenuItem(menu, DWT.CASCADE);
+        colorMenuHeader.setText("&Color");
+        auto colorMenu = new Menu(shell, DWT.DROP_DOWN);
+        colorMenuHeader.setMenu(colorMenu);
+
+        MenuItem[3] colors; 
+        colors[0] = new MenuItem(colorMenu, DWT.RADIO);
+        colors[0].setText("&Red");
+        colors[1] = new MenuItem(colorMenu, DWT.RADIO);
+        colors[1].setText("&Green");
+        colors[2] = new MenuItem(colorMenu, DWT.RADIO);
+        colors[2].setText("&Blue");
+
+        auto shapeMenuHeader = new MenuItem(menu, DWT.CASCADE);
+        shapeMenuHeader.setText("&Shape");
+        auto shapeMenu = new Menu(shell, DWT.DROP_DOWN);
+        shapeMenuHeader.setMenu(shapeMenu);
+
+        MenuItem[3] shapes;
+        shapes[0] = new MenuItem(shapeMenu, DWT.RADIO);
+        shapes[0].setText("&Rectangle");
+        shapes[0].setSelection(true);
+        shapes[1] = new MenuItem(shapeMenu, DWT.RADIO);
+        shapes[1].setText("&Oval");
+        shapes[2] = new MenuItem(shapeMenu, DWT.RADIO);
+        shapes[2].setText("S&quare");
+
+        MenuItem fill = new MenuItem(shapeMenu, DWT.CHECK);
+        fill.setText("&Fill");
+
+        auto canvas = new Canvas(shell,DWT.NO_REDRAW_RESIZE);
+        auto hPaint= new PaintHandler(canvas, display, colors, shapes, fill);
+        auto hMouse = new MouseHandler(hPaint);
+
+        canvas.addPaintListener(hPaint);
+        canvas.addMouseListener(hMouse);
+        canvas.addMouseMoveListener(hMouse);
+
+        shell.setMenuBar(menu);
+
+        shell.open();
+        while (!shell.isDisposed()) {
+            if (!display.readAndDispatch()) {
+                display.sleep();
+            }
+        }
+    } catch (Exception e) {
+        Stdout.formatln (e.toString);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/drawingboard/MouseHandler.d	Thu Feb 14 13:04:14 2008 -0800
@@ -0,0 +1,74 @@
+/*
+ * This class handles events created by the mouse. It will
+ * define the area that PaintHandler will use to draw the shape,
+ * based on where the mouse was pressed and released.
+ *
+ * Written by Jesse Phillips <Jesse.K.Phillips+D> gmail.com
+ * All code is free with no restrictions
+ */
+module user.drawingboard.MouseHandler;
+
+import dwt.events.MouseListener;
+import dwt.events.MouseMoveListener;
+import dwt.events.MouseEvent;
+
+import tango.io.Stdout;
+
+import user.drawingboard.PaintHandler;
+
+/**
+ * This class extends the MouseListener and MouseMoveListener.
+ * MouseListener requires functions:
+ *  mouseDoubleClick(MouseEvent e);
+ *  mouseDown(MouseEvent e);
+ *  mousePush(MouseEvent e);
+ * MouseMoveListener requires function:
+ *  mouseMove(MouseEvent e);
+ */
+class MouseHandler : MouseListener, MouseMoveListener {
+    PaintHandler hPaint;
+    bool pressed = false;
+
+    /**
+     * MouseHandler takes a PaintHandler, which is the class
+     * that will handle draw to the screen when needed.
+     */
+    this(PaintHandler ph) {
+        hPaint = ph;
+    }
+
+    /**
+     * Unused but required by MouseListener interface.
+     */
+    void mouseDoubleClick(MouseEvent e) {
+    }
+
+    /**
+     * Sets the start location for where to draw from.
+     * Sets pressed to true so it can be known that
+     * the mouse is being dragged.
+     */
+    void mouseDown(MouseEvent e) {
+        hPaint.x = e.x;
+        hPaint.y = e.y;
+        pressed = true;
+    }
+
+    /**
+     * Sets pressed to fales to turn of dragging.
+     */
+    void mouseUp(MouseEvent e) {
+        pressed = false;
+    }
+
+    /**
+     * Sets the end location for for the drawing.
+     */
+    void mouseMove(MouseEvent e) {
+        if(pressed) {
+            hPaint.xDiff = e.x-hPaint.x;
+            hPaint.yDiff = e.y-hPaint.y;
+            hPaint.reDraw();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/drawingboard/PaintHandler.d	Thu Feb 14 13:04:14 2008 -0800
@@ -0,0 +1,99 @@
+/*
+ * This class handles draw requests. When the event fires
+ * it will use the GC (graphics context) to draw the shape
+ * defined by the events handled in MouseHandler.
+ * For more on the GC visit:
+ * http://www.eclipse.org/articles/Article-SWT-graphics/SWT_graphics.html
+ *
+ * Written by Jesse Phillips <Jesse.K.Phillips+D> gmail.com
+ * All code is free with no restrictions
+ */
+module user.drawingboard.PaintHandler;
+
+import dwt.DWT;
+import dwt.events.PaintListener;
+import dwt.widgets.Button;
+import dwt.widgets.Canvas;
+import dwt.widgets.Display;
+import dwt.widgets.MenuItem;
+
+import dwt.graphics.GC;
+import dwt.graphics.Rectangle;
+
+import tango.io.Stdout;
+
+/**
+ * This class extends the PaintListener interface.
+ * PaintListener requires one function:
+ *  paintControl(PaintEvent e)
+ */
+class PaintHandler : PaintListener {
+    public int x, y, xDiff, yDiff;
+    Canvas canvas;
+    Display display;
+    MenuItem[] colors, shapes;
+    MenuItem fill;
+
+    this(Canvas can, Display d, MenuItem[] co, MenuItem[] s, MenuItem f) {
+        canvas = can;
+        display = d;
+        colors = co;
+        shapes = s;
+        fill = f;
+    }
+
+    /**
+     * Used to draw the defined shape to a canvas.
+     * It will change the color and shape based on the
+     * options set by the other widgets.
+     */
+    public void paintControl(PaintEvent e) {
+         Rectangle clientArea = canvas.getClientArea();
+
+            /*
+             * Decide what the color will be
+             */
+            auto color = display.getSystemColor(DWT.COLOR_CYAN);
+            if(colors[0].getSelection()) {
+                color = display.getSystemColor(DWT.COLOR_RED);
+            } else if(colors[1].getSelection()) {
+                color = display.getSystemColor(DWT.COLOR_GREEN);
+            } else if(colors[2].getSelection())
+                color = display.getSystemColor(DWT.COLOR_BLUE);
+                
+         e.gc.setBackground(color);
+         e.gc.setForeground(color);
+
+            /*
+             * Decide what is to be drawn
+             */
+            if(fill.getSelection()) {
+                mixin(buildShape!("fill"));
+            } else
+                mixin(buildShape!("draw"));
+
+                
+   }
+
+    public void reDraw() {
+        canvas.redraw();
+    }
+
+    private static int abs(int val) {
+        return val < 0 ? -val : val;
+    }
+
+    template buildShape(char[] pre) {
+        const char[] buildShape = "
+            if(shapes[0].getSelection()) {
+                e.gc." ~ pre ~ "RoundRectangle(x,y,xDiff,yDiff,50,50);
+            } else if(shapes[1].getSelection()) {
+                e.gc." ~ pre ~ "Oval(x,y,xDiff,yDiff);
+            } else if(shapes[2].getSelection())
+                e.gc." ~ pre ~
+                      "Rectangle(x,y,abs(xDiff)>abs(yDiff)?xDiff:yDiff,
+                                     abs(xDiff)>abs(yDiff)?xDiff:yDiff);";
+    }
+        
+
+}
--- a/user/nascent_test1.d	Tue Feb 12 20:02:08 2008 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-//[18:32] <nascent> setting text to a menu Item seems to do it.
-module user.nascent_test1;
-
-import dwt.DWT;
-import dwt.widgets.Display;
-import dwt.widgets.Shell;
-import dwt.widgets.Menu;
-import dwt.widgets.MenuItem;
-
-import tango.io.Stdout;
-import tango.math.Math;
-import tango.text.convert.Format;
-import tango.util.Convert;
-import tango.util.PathUtil;
-import dwt.events.SelectionListener;
-import dwt.events.SelectionEvent;
-
-void main() {
-    Display display = new Display();
-    Shell shell = new Shell(display);
-
-    Menu bar = new Menu(shell, DWT.BAR);
-    shell.setMenuBar(bar);
-    MenuItem fileItem = new MenuItem(bar, DWT.CASCADE);
-
-    fileItem.setText("&File");
-    Menu submenu = new Menu(shell, DWT.DROP_DOWN);
-    fileItem.setMenu(submenu);
-    MenuItem item = new MenuItem(submenu, DWT.PUSH);
-
-    item.setText("Select &All\tCtrl+A");
-    item.setAccelerator(DWT.MOD1 + 'A');
-
-    shell.setSize(200, 200);
-    shell.open();
-    while (!shell.isDisposed()) {
-        if (!display.readAndDispatch())
-            display.sleep();
-    }
-//    display.dispose();
-}
--- a/user/nascent_test2.d	Tue Feb 12 20:02:08 2008 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-
-/*
-[00:11] <nascent> if you select one item from the menu., then another it will segfault.
-*/
-module user.nascent_test2;
-import dwt.DWT;
-import dwt.layout.GridLayout;
-import dwt.widgets.Canvas;
-import dwt.widgets.Display;
-import dwt.widgets.Menu;
-import dwt.widgets.MenuItem;
-import dwt.widgets.Shell;
-
-import tango.io.Stdout;
-import tango.math.Math;
-import tango.text.convert.Format;
-import tango.util.Convert;
-import tango.util.PathUtil;
-import dwt.events.SelectionListener;
-import dwt.events.SelectionEvent;
-
-void main(){
-    auto display = new Display();
-    auto shell = new Shell(display);
-    auto layout = new GridLayout();
-    layout.numColumns = 3;
-    shell.setSize(500, 500);
-    shell.setText("Draw window");
-    shell.setLayout(layout);
-
-    auto menu = new Menu(shell, DWT.BAR);
-    auto shapeMenuHeader = new MenuItem(menu, DWT.CASCADE);
-    shapeMenuHeader.setText("&Shape");
-    auto shapeMenu = new Menu(shell, DWT.DROP_DOWN);
-    shapeMenuHeader.setMenu(shapeMenu);
-
-    MenuItem[3] colors; 
-    colors[0] = new MenuItem(shapeMenu, DWT.RADIO);
-    colors[0].setText("&Red");
-    colors[1] = new MenuItem(shapeMenu, DWT.RADIO);
-    colors[1].setText("&Green");
-    colors[2] = new MenuItem(shapeMenu, DWT.RADIO);
-    colors[2].setText("&Blue");
-
-    shell.setMenuBar(menu);
-
-    shell.open();
-    while (!shell.isDisposed()) {
-        if (!display.readAndDispatch()) {
-            display.sleep();
-        }
-    }
-
-}