changeset 4:8d49c4eb4800

Added user examples
author Frank Benoit <benoit@tionex.de>
date Sun, 10 Feb 2008 04:28:56 +0100
parents 6e0b2c96d1fd
children 1de00968e454
files .hgignore dsss.conf dwtexamples/controlexample/ControlExample.d user/doob_test1/MouseHandler.d user/doob_test1/PaintHandler.d user/doob_test1/draw.d user/nascent_test1.d user/nascent_test2.d user/torhu_synctest.d
diffstat 9 files changed, 300 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Thu Feb 07 00:09:21 2008 +0100
+++ b/.hgignore	Sun Feb 10 04:28:56 2008 +0100
@@ -2,6 +2,8 @@
 
 *.a
 *.swp
+*.map
+*.exe
 
 syntax: regexp
 ^build.sh$
@@ -18,6 +20,9 @@
 ^dwtexamples/controlexample/ControlExample$
 ^dwtexamples/controlexample/CustomControlExample$
 
+^user/nascent_test1$
+^user/nascent_test2$
+^user/torhu_synctest$
+^user/doob_test1/draw$
 
 
-
--- a/dsss.conf	Thu Feb 07 00:09:21 2008 +0100
+++ b/dsss.conf	Sun Feb 10 04:28:56 2008 +0100
@@ -13,7 +13,10 @@
 [dwtexamples/helloworld/HelloWorld4.d]
 [dwtexamples/helloworld/HelloWorld5.d]
 
-[test1/draw.d]
+[user/doob_test1/draw.d]
+[user/nascent_test1.d]
+[user/nascent_test2.d]
+[user/torhu_synctest.d]
 
 [dwtexamples/addressbook/AddressBook.d]
 buildflags+=-g -gc -debug
@@ -25,7 +28,8 @@
 [dwtexamples/controlexample/ControlExample.d]
 buildflags+=-g -gc -debug
 version(Windows){
-    buildflags+= -L/SUBSYSTEM:console:5
+    buildflags+= -L/SUBSYSTEM:windows:5
+    buildflags+= -L/RC:sample.res
 }
 buildflags+=-Jdwtexamples/controlexample
 buildflags+=-version=CONTROL_EXAMPLE_MAIN
--- a/dwtexamples/controlexample/ControlExample.d	Thu Feb 07 00:09:21 2008 +0100
+++ b/dwtexamples/controlexample/ControlExample.d	Sun Feb 10 04:28:56 2008 +0100
@@ -7,7 +7,7 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
-  * Port to the D programming language:
+ * Port to the D programming language:
  *     Frank Benoit <benoit@tionex.de>
 *******************************************************************************/
 module dwtexamples.controlexample.ControlExample;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/doob_test1/MouseHandler.d	Sun Feb 10 04:28:56 2008 +0100
@@ -0,0 +1,42 @@
+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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/doob_test1/PaintHandler.d	Sun Feb 10 04:28:56 2008 +0100
@@ -0,0 +1,32 @@
+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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/doob_test1/draw.d	Sun Feb 10 04:28:56 2008 +0100
@@ -0,0 +1,56 @@
+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/nascent_test1.d	Sun Feb 10 04:28:56 2008 +0100
@@ -0,0 +1,41 @@
+//[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();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/nascent_test2.d	Sun Feb 10 04:28:56 2008 +0100
@@ -0,0 +1,54 @@
+
+/*
+[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();
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/torhu_synctest.d	Sun Feb 10 04:28:56 2008 +0100
@@ -0,0 +1,62 @@
+module user.torhu_synctest;
+
+import dwt.DWT;
+import dwt.dwthelper.Runnable;
+import dwt.widgets.Display;
+import dwt.widgets.Shell;
+import dwt.widgets.Button;
+import dwt.widgets.Synchronizer;
+import dwt.widgets.Text;
+
+import tango.core.Thread;
+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{
+
+        Display display = new Display();
+        Shell shell = new Shell(display);
+        shell.setSize(300, 200);
+        shell.setText("Simple DWT Sample");
+        auto btn = new Button( shell, DWT.PUSH );
+        btn.setBounds(40, 50, 100, 50);
+        btn.setText( "test syncExec" );
+
+        auto txt = new Text(shell, DWT.BORDER);
+        txt.setBounds(170, 50, 100, 40);
+
+        auto t = new Thread({Display.getDefault.syncExec(new class Runnable {
+            void run() { txt.setText("inside syncExec"); }
+        });});
+                
+
+        btn.addSelectionListener(new class () SelectionListener {
+            public void widgetSelected(SelectionEvent event) {
+                
+                t.start();
+            }
+            public void widgetDefaultSelected(SelectionEvent event) {
+                //txt.setText("No worries!");
+            }
+        });
+
+        shell.open();
+        while (!shell.isDisposed()) {
+            if (!display.readAndDispatch()) {
+                display.sleep();
+                Stdout( "." ).flush;
+            }
+        }
+    }
+    catch (Exception e) {
+        Stdout.formatln (e.toString);
+    }
+}