changeset 19:0f63eae37f35

Added bunch of snippets. Rearranged imports on the text snippet258. Unversioned the opengl_test1, but added a prebuild warning that Derelict must be installed.
author Jesse Phillips <Jesse.K.Phillips+D@gmail.com>
date Sat, 01 Mar 2008 15:03:35 -0800
parents 49188ccea1d1
children bfdfcd1c8f28
files dsss.conf dwtsnippets/combo/Snippet26.d dwtsnippets/composite/Snippet9.d dwtsnippets/coolbar/Snippet20.d dwtsnippets/ctabfolder/Snippet165.d dwtsnippets/directorydialog/Snippet33.d dwtsnippets/expandbar/Snippet223.d dwtsnippets/text/Snippet258.d
diffstat 8 files changed, 458 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/dsss.conf	Thu Feb 28 13:59:12 2008 -0800
+++ b/dsss.conf	Sat Mar 01 15:03:35 2008 -0800
@@ -3,6 +3,7 @@
 debugflags+=-g -gc -debug
 
 #used for dwtsnippets/text/Snippet258
+#dwtsnippets/expandbar/Snippet223
 buildflags+=-Jdwtsnippets/images
 
 version(Windows){
@@ -11,6 +12,8 @@
 }
 
 # The linker error work around
+# This is only needed if Tango was
+# installed with DSSS
 version(linux){
     buildflags+= -L-lDD-tango-util
 }
@@ -24,6 +27,12 @@
 [dwtexamples/helloworld/HelloWorld5.d]
 
 [dwtsnippets/button/Snippet293.d]
+[dwtsnippets/combo/Snippet26.d]
+[dwtsnippets/composite/Snippet9.d]
+[dwtsnippets/coolbar/Snippet20.d]
+[dwtsnippets/ctabfolder/Snippet165.d]
+[dwtsnippets/directorydialog/Snippet33.d]
+[dwtsnippets/expandbar/Snippet223.d]
 [dwtsnippets/styledtext/Snippet163.d]
 [dwtsnippets/styledtext/Snippet189.d]
 [dwtsnippets/text/Snippet258.d]
@@ -32,10 +41,8 @@
 [user/drawingboard/DrawingBoard.d]
 [user/torhu_synctest.d]
 
-#Until linux has the opengl stuff
-version(Windows) {
-    [snippets/opengl_test1.d]
-}
+[snippets/opengl_test1.d]
+prebuild=warn Derelict must be installed
 
 [dwtexamples/addressbook/AddressBook.d]
 buildflags+=-g -gc -debug
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/combo/Snippet26.d	Sat Mar 01 15:03:35 2008 -0800
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.combo.Snippet26;
+
+/*
+ * Combo example snippet: create a combo box (non-editable)
+ *
+ * For a list of all DWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import dwt.DWT;
+import dwt.widgets.Display;
+import dwt.widgets.Shell;
+import dwt.widgets.Combo;
+
+char[][] content = ["A", "B", "C"];
+
+void main () {
+    auto display = new Display ();
+    auto shell = new Shell (display);
+    auto combo = new Combo (shell, DWT.READ_ONLY);
+    combo.setItems (content);
+    combo.setSize (200, 200);
+
+    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/composite/Snippet9.d	Sat Mar 01 15:03:35 2008 -0800
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * 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.composite.Snippit9;
+
+/*
+ * Composite example snippet: scroll a child control automatically
+ *
+ * For a list of all DWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import dwt.DWT;
+import dwt.events.PaintListener;
+import dwt.graphics.Color;
+import dwt.graphics.Point;
+import dwt.graphics.Rectangle;
+import dwt.widgets.Composite;
+import dwt.widgets.Display;
+import dwt.widgets.Event;
+import dwt.widgets.Listener;
+import dwt.widgets.ScrollBar;
+import dwt.widgets.Shell;
+
+void main () {
+    auto display = new Display ();
+    auto shell = new Shell
+       (display, DWT.SHELL_TRIM | DWT.H_SCROLL | DWT.V_SCROLL);
+    auto composite = new Composite (shell, DWT.BORDER);
+    composite.setSize (700, 600);
+    auto red = display.getSystemColor (DWT.COLOR_RED);
+    composite.addPaintListener (new class PaintListener {
+        public void paintControl (PaintEvent e) {
+            e.gc.setBackground (red);
+            e.gc.fillOval (5, 5, 690, 590);
+        }
+    });
+    auto hBar = shell.getHorizontalBar ();
+    hBar.addListener (DWT.Selection, new class Listener {
+        public void handleEvent (Event e) {
+            auto location = composite.getLocation ();
+            location.x = -hBar.getSelection ();
+            composite.setLocation (location);
+        }
+    });
+    ScrollBar vBar = shell.getVerticalBar ();
+    vBar.addListener (DWT.Selection, new class Listener {
+        public void handleEvent (Event e) {
+            Point location = composite.getLocation ();
+            location.y = -vBar.getSelection ();
+            composite.setLocation (location);
+        }
+    });
+    shell.addListener (DWT.Resize,  new class Listener {
+        public void handleEvent (Event e) {
+            Point size = composite.getSize ();
+            Rectangle rect = shell.getClientArea ();
+            hBar.setMaximum (size.x);
+            vBar.setMaximum (size.y);
+            hBar.setThumb (Math.min (size.x, rect.width));
+            vBar.setThumb (Math.min (size.y, rect.height));
+            int hPage = size.x - rect.width;
+            int vPage = size.y - rect.height;
+            int hSelection = hBar.getSelection ();
+            int vSelection = vBar.getSelection ();
+            Point location = composite.getLocation ();
+            if (hSelection >= hPage) {
+                if (hPage <= 0) hSelection = 0;
+                location.x = -hSelection;
+            }
+            if (vSelection >= vPage) {
+                if (vPage <= 0) vSelection = 0;
+                location.y = -vSelection;
+            }
+            composite.setLocation (location);
+        }
+    });
+    shell.open ();
+    while (!shell.isDisposed()) {
+        if (!display.readAndDispatch ()) display.sleep ();
+    }
+    display.dispose ();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/coolbar/Snippet20.d	Sat Mar 01 15:03:35 2008 -0800
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.coolbar.Snippet20;
+
+/*
+ * CoolBar example snippet: create a cool bar
+ *
+ * For a list of all DWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import dwt.DWT;
+import dwt.graphics.Point;
+import dwt.widgets.Button;
+import dwt.widgets.Display;
+import dwt.widgets.CoolBar;
+import dwt.widgets.CoolItem;
+import dwt.widgets.Shell;
+
+import tango.util.Convert;
+
+void main () {
+    auto display = new Display ();
+    auto shell = new Shell (display);
+    auto bar = new CoolBar (shell, DWT.BORDER);
+    for (int i=0; i<2; i++) {
+        auto item = new CoolItem (bar, DWT.NONE);
+        auto button = new Button (bar, DWT.PUSH);
+        button.setText ("Button " ~ to!(char[])(i));
+        Point size = button.computeSize (DWT.DEFAULT, DWT.DEFAULT);
+        item.setPreferredSize (item.computeSize (size.x, size.y));
+        item.setControl (button);
+    }
+    bar.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/ctabfolder/Snippet165.d	Sat Mar 01 15:03:35 2008 -0800
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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.ctabfolder.Snippet165;
+
+/*
+ * Create a CTabFolder with min and max buttons, as well as close button and 
+ * image only on selected tab.
+ *
+ * For a list of all DWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ * 
+ * @since 3.0
+ */
+import dwt.DWT;
+import dwt.custom.CTabFolder;
+import dwt.custom.CTabFolder2Adapter ;
+import dwt.custom.CTabFolderEvent ;
+import dwt.custom.CTabItem;
+import dwt.graphics.GC;
+import dwt.graphics.Image;
+import dwt.layout.GridLayout;
+import dwt.layout.GridData;
+import dwt.widgets.Display;
+import dwt.widgets.Shell;
+import dwt.widgets.Text;
+
+import tango.util.Convert;
+
+void main () {
+    auto display = new Display ();
+    auto image = new Image(display, 16, 16);
+    auto gc = new GC(image);
+    gc.setBackground(display.getSystemColor(DWT.COLOR_BLUE));
+    gc.fillRectangle(0, 0, 16, 16);
+    gc.setBackground(display.getSystemColor(DWT.COLOR_YELLOW));
+    gc.fillRectangle(3, 3, 10, 10);
+    gc.dispose();
+    auto shell = new Shell (display);
+    shell.setLayout(new GridLayout());
+    auto folder = new CTabFolder(shell, DWT.BORDER);
+    folder.setLayoutData(new GridData(DWT.FILL, DWT.FILL, true, false));
+    folder.setSimple(false);
+    folder.setUnselectedImageVisible(false);
+    folder.setUnselectedCloseVisible(false);
+    for (int i = 0; i < 8; i++) {
+        CTabItem item = new CTabItem(folder, DWT.CLOSE);
+        item.setText("Item " ~ to!(char[])(i));
+        item.setImage(image);
+        Text text = new Text(folder, DWT.MULTI | DWT.V_SCROLL | DWT.H_SCROLL);
+        text.setText("Text for item " ~ to!(char[])(i) ~
+                     "\n\none, two, three\n\nabcdefghijklmnop");
+        item.setControl(text);
+    }
+    folder.setMinimizeVisible(true);
+    folder.setMaximizeVisible(true);
+    folder.addCTabFolder2Listener(new class CTabFolder2Adapter {
+        public void minimize(CTabFolderEvent event) {
+            folder.setMinimized(true);
+            shell.layout(true);
+        }
+        public void maximize(CTabFolderEvent event) {
+            folder.setMaximized(true);
+            folder.setLayoutData(new GridData(DWT.FILL, DWT.FILL, true, true));
+            shell.layout(true);
+        }
+        public void restore(CTabFolderEvent event) {
+            folder.setMinimized(false);
+            folder.setMaximized(false);
+            folder.setLayoutData(new GridData(DWT.FILL, DWT.FILL, true, false));
+            shell.layout(true);
+        }
+    });
+    shell.setSize(300, 300);
+    shell.open ();
+    while (!shell.isDisposed ()) {
+        if (!display.readAndDispatch ()) display.sleep ();
+    }
+    image.dispose();
+    display.dispose ();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/directorydialog/Snippet33.d	Sat Mar 01 15:03:35 2008 -0800
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.directorydialog.Snippet33;
+
+/*
+ * DirectoryDialog example snippet: prompt for a directory
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+
+import dwt.widgets.DirectoryDialog;
+import dwt.widgets.Display;
+import dwt.widgets.Shell;
+
+import tango.io.FileSystem;
+import tango.io.Stdout;
+import tango.util.Convert;
+
+void main () {
+    auto display = new Display ();
+    auto shell = new Shell (display);
+    shell.open ();
+    auto dialog = new DirectoryDialog (shell);
+    dialog.setFilterPath (FileSystem.getDirectory());
+    Stdout("RESULT=" ~ to!(char[])(dialog.open())).newline;
+    while (!shell.isDisposed()) {
+        if (!display.readAndDispatch ()) display.sleep ();
+    }
+    display.dispose ();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/expandbar/Snippet223.d	Sat Mar 01 15:03:35 2008 -0800
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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.expandbar.Snippet223;
+/* 
+ * example snippet: ExpandBar example
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ * 
+ * @since 3.2
+ */
+
+import dwt.DWT;
+import dwt.dwthelper.ByteArrayInputStream;
+import dwt.graphics.Image;
+import dwt.graphics.ImageData;
+import dwt.layout.FillLayout;
+import dwt.layout.GridLayout;
+import dwt.widgets.Button;
+import dwt.widgets.Composite;
+import dwt.widgets.Display;
+import dwt.widgets.ExpandBar;
+import dwt.widgets.ExpandItem;
+import dwt.widgets.Label;
+import dwt.widgets.Shell;
+import dwt.widgets.Scale;
+import dwt.widgets.Spinner;
+import dwt.widgets.Slider;
+
+void main () {
+    auto display = new Display ();
+    auto shell = new Shell (display);
+    shell.setLayout(new FillLayout());
+    shell.setText("ExpandBar Example");
+    auto bar = new ExpandBar (shell, DWT.V_SCROLL);
+    auto image = new Image(display, new ImageData(new ByteArrayInputStream( cast(byte[]) import("eclipse.png")))); 
+    
+    // First item
+    Composite composite = new Composite (bar, DWT.NONE);
+    GridLayout layout = new GridLayout ();
+    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
+    layout.verticalSpacing = 10;
+    composite.setLayout(layout);
+    Button button = new Button (composite, DWT.PUSH);
+    button.setText("DWT.PUSH");
+    button = new Button (composite, DWT.RADIO);
+    button.setText("DWT.RADIO");
+    button = new Button (composite, DWT.CHECK);
+    button.setText("DWT.CHECK");
+    button = new Button (composite, DWT.TOGGLE);
+    button.setText("DWT.TOGGLE");
+    ExpandItem item0 = new ExpandItem (bar, DWT.NONE, 0);
+    item0.setText("What is your favorite button");
+    item0.setHeight(composite.computeSize(DWT.DEFAULT, DWT.DEFAULT).y);
+    item0.setControl(composite);
+    item0.setImage(image);
+    
+    // Second item
+    composite = new Composite (bar, DWT.NONE);
+    layout = new GridLayout (2, false);
+    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
+    layout.verticalSpacing = 10;
+    composite.setLayout(layout);    
+    Label label = new Label (composite, DWT.NONE);
+    label.setImage(display.getSystemImage(DWT.ICON_ERROR));
+    label = new Label (composite, DWT.NONE);
+    label.setText("DWT.ICON_ERROR");
+    label = new Label (composite, DWT.NONE);
+    label.setImage(display.getSystemImage(DWT.ICON_INFORMATION));
+    label = new Label (composite, DWT.NONE);
+    label.setText("DWT.ICON_INFORMATION");
+    label = new Label (composite, DWT.NONE);
+    label.setImage(display.getSystemImage(DWT.ICON_WARNING));
+    label = new Label (composite, DWT.NONE);
+    label.setText("DWT.ICON_WARNING");
+    label = new Label (composite, DWT.NONE);
+    label.setImage(display.getSystemImage(DWT.ICON_QUESTION));
+    label = new Label (composite, DWT.NONE);
+    label.setText("DWT.ICON_QUESTION");
+    ExpandItem item1 = new ExpandItem (bar, DWT.NONE, 1);
+    item1.setText("What is your favorite icon");
+    item1.setHeight(composite.computeSize(DWT.DEFAULT, DWT.DEFAULT).y);
+    item1.setControl(composite);
+    item1.setImage(image);
+    
+    // Third item
+    composite = new Composite (bar, DWT.NONE);
+    layout = new GridLayout (2, true);
+    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
+    layout.verticalSpacing = 10;
+    composite.setLayout(layout);
+    label = new Label (composite, DWT.NONE);
+    label.setText("Scale"); 
+    new Scale (composite, DWT.NONE);
+    label = new Label (composite, DWT.NONE);
+    label.setText("Spinner");   
+    new Spinner (composite, DWT.BORDER);
+    label = new Label (composite, DWT.NONE);
+    label.setText("Slider");    
+    new Slider (composite, DWT.NONE);
+    ExpandItem item2 = new ExpandItem (bar, DWT.NONE, 2);
+    item2.setText("What is your favorite range widget");
+    item2.setHeight(composite.computeSize(DWT.DEFAULT, DWT.DEFAULT).y);
+    item2.setControl(composite);
+    item2.setImage(image);
+    
+    item1.setExpanded(true);
+    bar.setSpacing(8);
+    shell.setSize(400, 350);
+    shell.open();
+    while (!shell.isDisposed ()) {
+        if (!display.readAndDispatch ()) {
+            display.sleep ();
+        }
+    }
+    image.dispose();
+    display.dispose();
+}
--- a/dwtsnippets/text/Snippet258.d	Thu Feb 28 13:59:12 2008 -0800
+++ b/dwtsnippets/text/Snippet258.d	Sat Mar 01 15:03:35 2008 -0800
@@ -22,18 +22,19 @@
  * @since 3.3
  */
 import dwt.DWT;
+import dwt.dwthelper.ByteArrayInputStream;
+import dwt.events.SelectionAdapter;
+import dwt.events.SelectionEvent;
 import dwt.graphics.Image;
+import dwt.graphics.ImageData;
+import dwt.layout.GridLayout;
+import dwt.layout.GridData;
 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 dwt.graphics.ImageData;
-import dwt.dwthelper.ByteArrayInputStream;
+
 import tango.io.Stdout;
 
 void main() {