# HG changeset patch # User Frank Benoit # Date 1216560366 -7200 # Node ID 9a1be6ff19a2cff3affe1253d59556b3649c40b7 # Parent 7b1c122b4128581ec26a97f642bdb8a3191246e5 More snippets, thanks to Tom D. diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/combo/Snippet147.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/combo/Snippet147.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module combo.Snippet147; +/* + * Combo example snippet: stop CR from going to the default button + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.TraverseListener; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Combo; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.dwthelper.utils; + +import tango.io.Stdout; + +void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new GridLayout()); + Combo combo = new Combo(shell, DWT.NONE); + combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + combo.setText("Here is some text"); + combo.addSelectionListener(new class() SelectionAdapter{ + public void widgetDefaultSelected(SelectionEvent e) { + Stdout("Combo default selected (overrides default button)\n"); + } + }); + combo.addTraverseListener(new class() TraverseListener{ + public void keyTraversed(TraverseEvent e) { + if (e.detail == DWT.TRAVERSE_RETURN) { + e.doit = false; + e.detail = DWT.TRAVERSE_NONE; + } + } + }); + Button button = new Button(shell, DWT.PUSH); + button.setText("Ok"); + button.addSelectionListener(new class() SelectionAdapter{ + public void widgetSelected(SelectionEvent e) { + Stdout("Button selected\n"); + } + }); + shell.setDefaultButton(button); + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); +} + diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/combo/Snippet24.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/combo/Snippet24.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,57 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module combo.Snippet24; + +/* + * example snippet: detect CR in a text or combo control (default selection) + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.widgets.Combo; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Shell; +import dwt.widgets.Text; +import dwt.layout.RowLayout; + +import dwt.dwthelper.utils; +import tango.io.Stdout; + +void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setLayout (new RowLayout ()); + Combo combo = new Combo (shell, DWT.NONE); + combo.setItems (["A-1", "B-1", "C-1"]); + Text text = new Text (shell, DWT.SINGLE | DWT.BORDER); + text.setText ("some text"); + combo.addListener (DWT.DefaultSelection, new class() Listener{ + public void handleEvent (Event e) { + Stdout(e.widget.toString() ~ " - Default Selection\n"); + } + }); + text.addListener (DWT.DefaultSelection, new class() Listener{ + public void handleEvent (Event e) { + Stdout(e.widget.toString() ~ " - Default Selection\n"); + } + }); + shell.pack (); + shell.open (); + while (!shell.isDisposed()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/combo/Snippet269.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/combo/Snippet269.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.html37 + * + * Contributors: + * IBM Corporation - initial API and implementation + * D Port: + * Thomas Demmer + *******************************************************************************/ +module combo.Snippet269; + +/* + * Combo example snippet: set the caret position within a Combo's text + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.widgets.Combo; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.graphics.Point; +import dwt.layout.FillLayout; + +import dwt.dwthelper.utils; + +void main(String[] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setLayout (new FillLayout ()); + Combo combo = new Combo (shell, DWT.NONE); + combo.add ("item"); + combo.select (0); + shell.pack (); + shell.open (); + int stringLength = combo.getText().length; + combo.setSelection (new Point (stringLength, stringLength)); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/combo/Snippet289.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/combo/Snippet289.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module combo.Snippet289; + +/* + * Combo example snippet: add an item to a combo box + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.events.TraverseListener; +import dwt.events.VerifyListener; +import dwt.graphics.Point; +import dwt.layout.FillLayout; +import dwt.widgets.Combo; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.dwthelper.utils; + +void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + Combo combo = new Combo(shell, DWT.NONE); + combo.setItems(["1111", "2222", "3333", "4444"]); + combo.setText(combo.getItem(0)); + combo.addVerifyListener(new class() VerifyListener{ + public void verifyText(VerifyEvent e) { + String newText = e.text; + try { + Integer.parseInt(newText); + } catch (NumberFormatException ex) { + e.doit = false; + } + } + }); + combo.addTraverseListener(new class() TraverseListener { + public void keyTraversed(TraverseEvent e) { + if (e.detail == DWT.TRAVERSE_RETURN) { + e.doit = false; + e.detail = DWT.TRAVERSE_NONE; + String newText = combo.getText(); + try { + Integer.parseInt(newText); + combo.add(newText); + combo.setSelection(new Point(0, newText.length)); + } catch (NumberFormatException ex) { + } + } + } + }); + + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); +} diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/composite/Snippet115.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/composite/Snippet115.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,76 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module composite.Snippet115; + +/* + * Composite example snippet: force radio behavior on two different composites + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.widgets.Button; +import dwt.widgets.Composite; +import dwt.widgets.Control; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Shell; +import dwt.layout.RowLayout; + +import dwt.dwthelper.utils; +import tango.util.Convert; + +void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setLayout (new RowLayout (DWT.VERTICAL)); + Composite c1 = new Composite (shell, DWT.BORDER | DWT.NO_RADIO_GROUP); + c1.setLayout (new RowLayout ()); + Composite c2 = new Composite (shell, DWT.BORDER | DWT.NO_RADIO_GROUP); + c2.setLayout (new RowLayout ()); + Composite [] composites = [c1, c2]; + Listener radioGroup = new class() Listener{ + public void handleEvent (Event event) { + for (int i=0; i + *******************************************************************************/ +module composite.Snippet237; +/* + * Composite Snippet: inherit a background color or image + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.2 + */ + +import dwt.DWT; +import dwt.graphics.Color; +import dwt.layout.RowLayout; +import dwt.widgets.Display; +import dwt.widgets.Button; +import dwt.widgets.Composite; +import dwt.widgets.Group; +import dwt.widgets.Label; +import dwt.widgets.List; +import dwt.widgets.Shell; +import dwt.widgets.Text; + +import dwt.dwthelper.utils; + +void main(String[] args){ + Snippet237.main(args); +} +public class Snippet237 { + + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setText("Composite.setBackgroundMode()"); + shell.setLayout(new RowLayout(DWT.VERTICAL)); + + Color color = display.getSystemColor(DWT.COLOR_CYAN); + + Group group = new Group(shell, DWT.NONE); + group.setText("DWT.INHERIT_NONE"); + group.setBackground(color); + group.setBackgroundMode(DWT.INHERIT_NONE); + createChildren(group); + + group = new Group(shell, DWT.NONE); + group.setBackground(color); + group.setText("DWT.INHERIT_DEFAULT"); + group.setBackgroundMode(DWT.INHERIT_DEFAULT); + createChildren(group); + + group = new Group(shell, DWT.NONE); + group.setBackground(color); + group.setText("DWT.INHERIT_FORCE"); + group.setBackgroundMode(DWT.INHERIT_FORCE); + createChildren(group); + + shell.pack(); + shell.open(); + while(!shell.isDisposed()) { + if(!display.readAndDispatch()) display.sleep(); + } + display.dispose(); + } + static void createChildren(Composite parent) { + parent.setLayout(new RowLayout()); + List list = new List(parent, DWT.BORDER | DWT.MULTI); + list.add("List item 1"); + list.add("List item 2"); + Label label = new Label(parent, DWT.NONE); + label.setText("Label"); + Button button = new Button(parent, DWT.RADIO); + button.setText("Radio Button"); + button = new Button(parent, DWT.CHECK); + button.setText("Check box Button"); + button = new Button(parent, DWT.PUSH); + button.setText("Push Button"); + Text text = new Text(parent, DWT.BORDER); + text.setText("Text"); + } +} diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/composite/Snippet46.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/composite/Snippet46.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,78 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module composite.Snippet46; + +/* + * Composite example snippet: intercept mouse events (drag a button with the mouse) + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +import dwt.widgets.Button; +import dwt.widgets.Composite; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Shell; +import dwt.layout.FillLayout; + +import dwt.dwthelper.utils; + +void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + Composite composite = new Composite (shell, DWT.NONE); + composite.setEnabled (false); + composite.setLayout (new FillLayout ()); + Button button = new Button (composite, DWT.PUSH); + button.setText ("Button"); + composite.pack (); + composite.setLocation (10, 10); + Point [] offset = new Point [1]; + Listener listener = new class() Listener{ + public void handleEvent (Event event) { + switch (event.type) { + case DWT.MouseDown: + Rectangle rect = composite.getBounds (); + if (rect.contains (event.x, event.y)) { + Point pt1 = composite.toDisplay (0, 0); + Point pt2 = shell.toDisplay (event.x, event.y); + offset [0] = new Point (pt2.x - pt1.x, pt2.y - pt1.y); + } + break; + case DWT.MouseMove: + if (offset [0] !is null) { + Point pt = offset [0]; + composite.setLocation (event.x - pt.x, event.y - pt.y); + } + break; + case DWT.MouseUp: + offset [0] = null; + break; + } + } + }; + shell.addListener (DWT.MouseDown, listener); + shell.addListener (DWT.MouseUp, listener); + shell.addListener (DWT.MouseMove, listener); + shell.setSize (300, 300); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/composite/Snippet75.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/composite/Snippet75.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,112 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module composite.Snippet75; + +/* + * Composite example snippet: set the tab traversal order of children + * In this example, composite1 (i.e. c1) tab order is set to: B2, B1, B3, and + * shell tab order is set to: c1, B7, toolBar1, (c4: no focusable children), c2, L2 + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.widgets.Button; +import dwt.widgets.Combo; +import dwt.widgets.Composite; +import dwt.widgets.Control; +import dwt.widgets.Display; +import dwt.widgets.Label; +import dwt.widgets.List; +import dwt.widgets.Shell; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; +import dwt.layout.FillLayout; +import dwt.layout.RowLayout; + +import dwt.dwthelper.utils; + + +void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setLayout (new RowLayout ()); + + Composite c1 = new Composite (shell, DWT.BORDER); + c1.setLayout (new RowLayout ()); + Button b1 = new Button (c1, DWT.PUSH); + b1.setText ("B&1"); + Button r1 = new Button (c1, DWT.RADIO); + r1.setText ("R1"); + Button r2 = new Button (c1, DWT.RADIO); + r2.setText ("R&2"); + Button r3 = new Button (c1, DWT.RADIO); + r3.setText ("R3"); + Button b2 = new Button (c1, DWT.PUSH); + b2.setText ("B2"); + List l1 = new List (c1, DWT.SINGLE | DWT.BORDER); + l1.setItems (["L1"]); + Button b3 = new Button (c1, DWT.PUSH); + b3.setText ("B&3"); + Button b4 = new Button (c1, DWT.PUSH); + b4.setText ("B&4"); + + Composite c2 = new Composite (shell, DWT.BORDER); + c2.setLayout (new RowLayout ()); + Button b5 = new Button (c2, DWT.PUSH); + b5.setText ("B&5"); + Button b6 = new Button (c2, DWT.PUSH); + b6.setText ("B&6"); + + List l2 = new List (shell, DWT.SINGLE | DWT.BORDER); + l2.setItems ( ["L2"] ); + + ToolBar tb1 = new ToolBar (shell, DWT.FLAT | DWT.BORDER); + ToolItem i1 = new ToolItem (tb1, DWT.RADIO); + i1.setText ("I1"); + ToolItem i2 = new ToolItem (tb1, DWT.RADIO); + i2.setText ("I2"); + Combo combo1 = new Combo (tb1, DWT.READ_ONLY | DWT.BORDER); + combo1.setItems (["C1"]); + combo1.setText ("C1"); + combo1.pack (); + ToolItem i3 = new ToolItem (tb1, DWT.SEPARATOR); + i3.setWidth (combo1.getSize ().x); + i3.setControl (combo1); + ToolItem i4 = new ToolItem (tb1, DWT.PUSH); + i4.setText ("I&4"); + ToolItem i5 = new ToolItem (tb1, DWT.CHECK); + i5.setText ("I5"); + + Button b7 = new Button (shell, DWT.PUSH); + b7.setText ("B&7"); + + Composite c4 = new Composite (shell, DWT.BORDER); + Composite c5 = new Composite (c4, DWT.BORDER); + c5.setLayout(new FillLayout()); + (new Label(c5, DWT.NONE)).setText("No"); + c5.pack(); + + + Control [] tabList1 = [cast(Control)b2, b1, b3]; + c1.setTabList (tabList1); + Control [] tabList2 = [cast(Control)c1, b7, tb1, c4, c2, l2]; + shell.setTabList (tabList2); + shell.pack (); + shell.open (); + + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/composite/Snippet98.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/composite/Snippet98.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module composite.Snippet98; + +/* + * Composite example snippet: create and dispose children of a composite + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Composite; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Shell; +import dwt.widgets.Table; +import dwt.widgets.TableItem; + +import dwt.dwthelper.utils; + +import tango.util.Convert; + +static int pageNum = 0; +static Composite pageComposite; + +void main(String args[]) { + Display display = new Display(); + final Shell shell = new Shell(display); + shell.setLayout(new GridLayout()); + Button button = new Button(shell, DWT.PUSH); + button.setText("Push"); + pageComposite = new Composite(shell, DWT.NONE); + pageComposite.setLayout(new GridLayout()); + pageComposite.setLayoutData(new GridData()); + + button.addListener(DWT.Selection, new class() Listener{ + public void handleEvent(Event event) { + if ((pageComposite !is null) && (!pageComposite.isDisposed())) { + pageComposite.dispose(); + } + pageComposite = new Composite(shell, DWT.NONE); + pageComposite.setLayout(new GridLayout()); + pageComposite.setLayoutData(new GridData()); + if (pageNum++ % 2 == 0) { + Table table = new Table(pageComposite, DWT.BORDER); + table.setLayoutData(new GridData()); + for (int i = 0; i < 5; i++) { + (new TableItem(table, DWT.NONE)).setText("table item " ~ to!(char[])(i)); + } + } else { + (new Button(pageComposite, DWT.RADIO)).setText("radio"); + } + shell.layout(true); + } + }); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); +} diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/control/Snippet127.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/control/Snippet127.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module control.Snippet127; + +/* + * Control example snippet: prevent Tab from traversing out of a control + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.events.TraverseEvent; +import dwt.events.TraverseListener; +import dwt.widgets.Button; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Shell; +import dwt.layout.RowLayout; + +import dwt.dwthelper.utils; + +void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setLayout(new RowLayout ()); + Button button1 = new Button(shell, DWT.PUSH); + button1.setText("Can't Traverse"); + button1.addTraverseListener(new class() TraverseListener{ + public void keyTraversed(TraverseEvent e) { + switch (e.detail) { + case DWT.TRAVERSE_TAB_NEXT: + case DWT.TRAVERSE_TAB_PREVIOUS: { + e.doit = false; + } + } + } + }); + Button button2 = new Button (shell, DWT.PUSH); + button2.setText("Can Traverse"); + shell.pack (); + shell.open(); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/control/Snippet14.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/control/Snippet14.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module control.Snippet14; + +/* + * Control example snippet: detect mouse enter, exit and hover events + * + * 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.Event; +import dwt.widgets.Listener; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; + +import tango.io.Stdout; + +void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setSize (100, 100); + shell.addListener (DWT.MouseEnter, new class() Listener{ + public void handleEvent (Event e) { + Stdout("ENTER\n"); + Stdout.flush(); + } + }); + shell.addListener (DWT.MouseExit, new class() Listener{ + public void handleEvent (Event e) { + Stdout("EXIT\n"); + Stdout.flush(); + } + }); + shell.addListener (DWT.MouseHover, new class() Listener{ + public void handleEvent (Event e) { + Stdout("HOVER\n"); + Stdout.flush(); + } + }); + shell.open (); + while (!shell.isDisposed()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/control/Snippet214.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/control/Snippet214.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,81 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module control.Snippet214; + +/* + * Control example snippet: set a background image (a dynamic gradient) + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.2 + */ +import dwt.DWT; + +import dwt.graphics.GC; +import dwt.graphics.Image; +import dwt.graphics.Rectangle; +import dwt.layout.FillLayout; +import dwt.layout.RowLayout; +import dwt.widgets.Button; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Group; +import dwt.widgets.Listener; +import dwt.widgets.Shell; +import dwt.layout.RowLayout; + +import dwt.dwthelper.utils; + +import tango.util.Convert; + +static Image oldImage; +void main(String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setBackgroundMode (DWT.INHERIT_DEFAULT); + FillLayout layout1 = new FillLayout (DWT.VERTICAL); + layout1.marginWidth = layout1.marginHeight = 10; + shell.setLayout (layout1); + Group group = new Group (shell, DWT.NONE); + group.setText ("Group "); + RowLayout layout2 = new RowLayout (DWT.VERTICAL); + layout2.marginWidth = layout2.marginHeight = layout2.spacing = 10; + group.setLayout (layout2); + for (int i=0; i<8; i++) { + Button button = new Button (group, DWT.RADIO); + button.setText ("Button " ~ to!(char[])(i)); + } + shell.addListener (DWT.Resize, new class() Listener { + public void handleEvent (Event event) { + Rectangle rect = shell.getClientArea (); + Image newImage = new Image (display, Math.max (1, rect.width), 1); + GC gc = new GC (newImage); + gc.setForeground (display.getSystemColor (DWT.COLOR_WHITE)); + gc.setBackground (display.getSystemColor (DWT.COLOR_BLUE)); + gc.fillGradientRectangle (rect.x, rect.y, rect.width, 1, false); + gc.dispose (); + shell.setBackgroundImage (newImage); + if (oldImage !is null) oldImage.dispose (); + oldImage = newImage; + } + }); + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + if (oldImage !is null) oldImage.dispose (); + display.dispose (); +} + diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/control/Snippet247.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/control/Snippet247.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module control.Snippet247; + +/* + * Control example snippet: allow a multi-line text to process the default button + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.SelectionListener; +import dwt.events.TraverseEvent; +import dwt.events.TraverseListener; +import dwt.widgets.Button; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Text; +import dwt.layout.RowLayout; + +import dwt.dwthelper.utils; + +import tango.io.Stdout; + +void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setLayout(new RowLayout()); + Text text = new Text(shell, DWT.MULTI | DWT.BORDER); + String modifier = DWT.MOD1 == DWT.CTRL ? "Ctrl" : "Command"; + text.setText("Hit " ~ modifier ~ "+Return\nto see\nthe default button\nrun"); + text.addTraverseListener(new class() TraverseListener{ + public void keyTraversed(TraverseEvent e) { + switch (e.detail) { + case DWT.TRAVERSE_RETURN: + if ((e.stateMask & DWT.MOD1) != 0) e.doit = true; + default: + } + } + }); + Button button = new Button (shell, DWT.PUSH); + button.pack(); + button.setText("OK"); + button.addSelectionListener(new class() SelectionAdapter{ + public void widgetSelected(SelectionEvent e) { + Stdout("OK selected\n"); + Stdout.flush(); + } + }); + shell.setDefaultButton(button); + shell.pack (); + shell.open(); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/ctabfolder/Snippet82.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/ctabfolder/Snippet82.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,80 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module ctabfolder.Snippet82; + +/* + * CTabFolder example snippet: prevent an item from closing + * + * For a list of all SWT 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.layout.FillLayout; +import dwt.widgets.Button; +import dwt.widgets.Display; +import dwt.widgets.Item; +import dwt.widgets.Shell; +import dwt.widgets.Text; + +import dwt.dwthelper.utils; + +import tango.util.Convert; + +void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + CTabFolder folder = new CTabFolder(shell, DWT.BORDER); + for (int i = 0; i < 4; i++) { + CTabItem item = new CTabItem(folder, DWT.CLOSE); + item.setText("Item " ~ to!(String)(i) ); + Text text = new Text(folder, DWT.MULTI); + text.setText("Content for Item "~ to!(String)(i)); + item.setControl(text); + } + + CTabItem specialItem = new CTabItem(folder, DWT.CLOSE); + specialItem.setText("Don't Close Me"); + Text text = new Text(folder, DWT.MULTI); + text.setText("This tab can never be closed"); + specialItem.setControl(text); + + folder.addCTabFolder2Listener(new class() CTabFolder2Adapter { + public void close(CTabFolderEvent event) { + if (event.item == specialItem) { + event.doit = false; + } + } + }); + + CTabItem noCloseItem = new CTabItem(folder, DWT.NONE); + noCloseItem.setText("No Close Button"); + Text text2 = new Text(folder, DWT.MULTI); + text2.setText("This tab does not have a close button"); + noCloseItem.setControl(text2); + + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); +} + diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/cursor/Snippet118.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/cursor/Snippet118.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,66 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module cursor.Snippet118; + +/* + * Cursor example snippet: create a color cursor from an image file + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ +import dwt.DWT; +import dwt.graphics.Cursor; +import dwt.graphics.ImageData; +import dwt.graphics.Point; +import dwt.widgets.Button; +import dwt.widgets.Display; +import dwt.widgets.FileDialog; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; + +void main (String [] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setSize(150, 150); + Cursor[] cursor = new Cursor[1]; + Button button = new Button(shell, DWT.PUSH); + button.setText("Change cursor"); + Point size = button.computeSize(DWT.DEFAULT, DWT.DEFAULT); + button.setSize(size); + button.addListener(DWT.Selection, new class() Listener{ + public void handleEvent(Event e) { + FileDialog dialog = new FileDialog(shell); + dialog.setFilterExtensions(["*.ico", "*.gif", "*.*"]); + String name = dialog.open(); + if (name is null) return; + ImageData image = new ImageData(name); + Cursor oldCursor = cursor[0]; + cursor[0] = new Cursor(display, image, 0, 0); + shell.setCursor(cursor[0]); + if (oldCursor !is null) oldCursor.dispose(); + } + }); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + if (cursor[0] !is null) cursor[0].dispose(); + display.dispose(); +} + diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/cursor/Snippet119.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/cursor/Snippet119.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,133 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module cursor.Snippet119; + +/* + * Cursor example snippet: create a color cursor from a source and a mask + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ +import dwt.DWT; +import dwt.events.PaintListener; +import dwt.graphics.Color; +import dwt.graphics.Cursor; +import dwt.graphics.GC; +import dwt.graphics.Image; +import dwt.graphics.ImageData; +import dwt.graphics.PaletteData; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; + + + +static byte[] srcData = [ + cast(byte)0x11, cast(byte)0x11, cast(byte)0x11, cast(byte)0x00, cast(byte)0x00, cast(byte)0x11, cast(byte)0x11, cast(byte)0x11, + cast(byte)0x11, cast(byte)0x10, cast(byte)0x00, cast(byte)0x01, cast(byte)0x10, cast(byte)0x00, cast(byte)0x01, cast(byte)0x11, + cast(byte)0x11, cast(byte)0x00, cast(byte)0x22, cast(byte)0x01, cast(byte)0x10, cast(byte)0x33, cast(byte)0x00, cast(byte)0x11, + cast(byte)0x10, cast(byte)0x02, cast(byte)0x22, cast(byte)0x01, cast(byte)0x10, cast(byte)0x33, cast(byte)0x30, cast(byte)0x01, + cast(byte)0x10, cast(byte)0x22, cast(byte)0x22, cast(byte)0x01, cast(byte)0x10, cast(byte)0x33, cast(byte)0x33, cast(byte)0x01, + cast(byte)0x10, cast(byte)0x22, cast(byte)0x22, cast(byte)0x01, cast(byte)0x10, cast(byte)0x33, cast(byte)0x33, cast(byte)0x01, + cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, + cast(byte)0x01, cast(byte)0x11, cast(byte)0x11, cast(byte)0x01, cast(byte)0x10, cast(byte)0x11, cast(byte)0x11, cast(byte)0x10, + cast(byte)0x01, cast(byte)0x11, cast(byte)0x11, cast(byte)0x01, cast(byte)0x10, cast(byte)0x11, cast(byte)0x11, cast(byte)0x10, + cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, cast(byte)0x00, + cast(byte)0x10, cast(byte)0x44, cast(byte)0x44, cast(byte)0x01, cast(byte)0x10, cast(byte)0x55, cast(byte)0x55, cast(byte)0x01, + cast(byte)0x10, cast(byte)0x44, cast(byte)0x44, cast(byte)0x01, cast(byte)0x10, cast(byte)0x55, cast(byte)0x55, cast(byte)0x01, + cast(byte)0x10, cast(byte)0x04, cast(byte)0x44, cast(byte)0x01, cast(byte)0x10, cast(byte)0x55, cast(byte)0x50, cast(byte)0x01, + cast(byte)0x11, cast(byte)0x00, cast(byte)0x44, cast(byte)0x01, cast(byte)0x10, cast(byte)0x55, cast(byte)0x00, cast(byte)0x11, + cast(byte)0x11, cast(byte)0x10, cast(byte)0x00, cast(byte)0x01, cast(byte)0x10, cast(byte)0x00, cast(byte)0x01, cast(byte)0x11, + cast(byte)0x11, cast(byte)0x11, cast(byte)0x11, cast(byte)0x00, cast(byte)0x00, cast(byte)0x11, cast(byte)0x11, cast(byte)0x11, +]; + +static byte[] mskData = [ + cast(byte)0x03, cast(byte)0xc0, + cast(byte)0x1f, cast(byte)0xf8, + cast(byte)0x3f, cast(byte)0xfc, + cast(byte)0x7f, cast(byte)0xfe, + cast(byte)0x7f, cast(byte)0xfe, + cast(byte)0x7f, cast(byte)0xfe, + cast(byte)0xff, cast(byte)0xff, + cast(byte)0xfe, cast(byte)0x7f, + cast(byte)0xfe, cast(byte)0x7f, + cast(byte)0xff, cast(byte)0xff, + cast(byte)0x7f, cast(byte)0xfe, + cast(byte)0x7f, cast(byte)0xfe, + cast(byte)0x7f, cast(byte)0xfe, + cast(byte)0x3f, cast(byte)0xfc, + cast(byte)0x1f, cast(byte)0xf8, + cast(byte)0x03, cast(byte)0xc0 +]; + +void main (String [] args) { + Display display = new Display(); + Color white = display.getSystemColor (DWT.COLOR_WHITE); + Color black = display.getSystemColor (DWT.COLOR_BLACK); + Color yellow = display.getSystemColor (DWT.COLOR_YELLOW); + Color red = display.getSystemColor (DWT.COLOR_RED); + Color green = display.getSystemColor (DWT.COLOR_GREEN); + Color blue = display.getSystemColor (DWT.COLOR_BLUE); + + //Create a source ImageData of depth 4 + PaletteData palette = new PaletteData ([black.getRGB(), white.getRGB(), yellow.getRGB(), + red.getRGB(), blue.getRGB(), green.getRGB()]); + ImageData sourceData = new ImageData (16, 16, 4, palette, 1, srcData); + + //Create a mask ImageData of depth 1 (monochrome) + palette = new PaletteData ([black.getRGB(), white.getRGB()]); + ImageData maskData = new ImageData (16, 16, 1, palette, 1, mskData); + + //Set mask + sourceData.maskData = maskData.data; + sourceData.maskPad = maskData.scanlinePad; + + //Create cursor + Cursor cursor = new Cursor(display, sourceData, 10, 10); + + //Remove mask to draw them separately just to show what they look like + sourceData.maskData = null; + sourceData.maskPad = -1; + + Shell shell = new Shell(display); + Image source = new Image (display,sourceData); + Image mask = new Image (display, maskData); + shell.addPaintListener(new class() PaintListener{ + public void paintControl(PaintEvent e) { + GC gc = e.gc; + int x = 10, y = 10; + String stringSource = "source: "; + String stringMask = "mask: "; + gc.drawString(stringSource, x, y); + gc.drawString(stringMask, x, y + 30); + x += Math.max(gc.stringExtent(stringSource).x, gc.stringExtent(stringMask).x); + gc.drawImage(source, x, y); + gc.drawImage(mask, x, y + 30); + } + }); + shell.setSize(150, 150); + shell.open(); + shell.setCursor(cursor); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + cursor.dispose(); + source.dispose(); + mask.dispose(); + display.dispose(); +} diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/cursor/Snippet242.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/cursor/Snippet242.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module cursor.Snippet242; + +/* + * Cursor snippet: Hide the Cursor over a control. + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ + +import dwt.DWT; +import dwt.events.PaintEvent; +import dwt.events.PaintListener; +import dwt.graphics.Color; +import dwt.graphics.Cursor; +import dwt.graphics.ImageData; +import dwt.graphics.PaletteData; +import dwt.widgets.Canvas; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; + +void main(String [] args) { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setBounds(10, 10, 200, 200); + Canvas canvas = new Canvas(shell, DWT.BORDER); + canvas.setBounds(10,50,150,100); + canvas.addPaintListener(new class() PaintListener{ + public void paintControl(PaintEvent e) { + e.gc.drawString("hide Cursor here", 10, 10); + } + }); + + // create a cursor with a transparent image + Color white = display.getSystemColor (DWT.COLOR_WHITE); + Color black = display.getSystemColor (DWT.COLOR_BLACK); + PaletteData palette = new PaletteData ([white.getRGB(), black.getRGB()]); + ImageData sourceData = new ImageData (16, 16, 1, palette); + sourceData.transparentPixel = 0; + Cursor cursor = new Cursor(display, sourceData, 0, 0); + + shell.open(); + canvas.setCursor(cursor); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + cursor.dispose(); + display.dispose(); +} + diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/cursor/Snippet44.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/cursor/Snippet44.d Sun Jul 20 15:26:06 2008 +0200 @@ -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: + * Thomas Demmer + *******************************************************************************/ +module cursor.Snippet44; + +/* + * Cursor example snippet: set the hand cursor into a control + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.graphics.Cursor; +import dwt.widgets.Button; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; + +void main (String [] args) { + Display display = new Display (); + Cursor cursor = new Cursor (display, DWT.CURSOR_HAND); + Shell shell = new Shell (display); + shell.open (); + Button b = new Button (shell, 0); + b.setBounds (10, 10, 200, 200); + b.addListener (DWT.Selection, new class() Listener{ + public void handleEvent (Event e) { + b.setCursor (cursor); + } + }); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + cursor.dispose (); + display.dispose (); +} + diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/cursor/Snippet92.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/cursor/Snippet92.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,87 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module cursor.Snippet92; + +/* + * Cursor example snippet: create a cursor from a source and a mask + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.events.PaintEvent; +import dwt.events.PaintListener; +import dwt.graphics.Color; +import dwt.graphics.Cursor; +import dwt.graphics.GC; +import dwt.graphics.Image; +import dwt.graphics.ImageData; +import dwt.graphics.PaletteData; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; + + +void main (String [] args) { + Display display = new Display(); + Color white = display.getSystemColor (DWT.COLOR_WHITE); + Color black = display.getSystemColor (DWT.COLOR_BLACK); + + //Create a source ImageData of depth 1 (monochrome) + PaletteData palette = new PaletteData ([white.getRGB(), black.getRGB()]); + ImageData sourceData = new ImageData (20, 20, 1, palette); + for (int i = 0; i < 10; i ++) { + for (int j = 0; j < 20; j++) { + sourceData.setPixel(i, j, 1); + } + } + + //Create a mask ImageData of depth 1 (monochrome) + palette = new PaletteData ([white.getRGB(), black.getRGB()]); + ImageData maskData = new ImageData (20, 20, 1, palette); + for (int i = 0; i < 20; i ++) { + for (int j = 0; j < 10; j++) { + maskData.setPixel(i, j, 1); + } + } + //Create cursor + Cursor cursor = new Cursor(display, sourceData, maskData, 10, 10); + + Shell shell = new Shell(display); + Image source = new Image (display,sourceData); + Image mask = new Image (display, maskData); + //Draw source and mask just to show what they look like + shell.addPaintListener(new class() PaintListener{ + void paintControl(PaintEvent e) { + GC gc = e.gc; + gc.drawString("source: ", 10, 10); + gc.drawImage(source, 0, 0, 20, 20, 60, 10, 20, 20); + gc.drawString("mask: ",10, 40); + gc.drawImage(mask, 0, 0, 20, 20, 60, 40, 20, 20); + } + }); + shell.setSize(150, 150); + shell.open(); + shell.setCursor(cursor); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + cursor.dispose(); + source.dispose(); + mask.dispose(); + display.dispose(); +} + diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/datetime/Snippet250.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/datetime/Snippet250.d Sun Jul 20 15:26:06 2008 +0200 @@ -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: + * Thomas Demmer + *******************************************************************************/ +module datetime.Snippet250; + +/* + * DateTime example snippet: create a DateTime calendar and a DateTime time. + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.layout.RowLayout; +import dwt.widgets.DateTime; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; + +import tango.io.Stdout; + +void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setLayout (new RowLayout ()); + + DateTime calendar = new DateTime (shell, DWT.CALENDAR); + calendar.addSelectionListener (new class() SelectionAdapter{ + void widgetSelected (SelectionEvent e) { + Stdout("calendar date changed\n"); + Stdout.flush(); + } + }); + + DateTime time = new DateTime (shell, DWT.TIME); + time.addSelectionListener (new class() SelectionAdapter{ + void widgetSelected (SelectionEvent e) { + Stdout("time changed\n"); + Stdout.flush(); + } + }); + + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/datetime/Snippet251.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/datetime/Snippet251.d Sun Jul 20 15:26:06 2008 +0200 @@ -0,0 +1,92 @@ +/******************************************************************************* + * 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: + * Thomas Demmer + *******************************************************************************/ +module datetime.Snippet251; + +/* + * DateTime example snippet: create a DateTime calendar, date, and time in a dialog. + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.layout.FillLayout; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.DateTime; +import dwt.widgets.Dialog; +import dwt.widgets.Display; +import dwt.widgets.Label; +import dwt.widgets.Shell; + +import dwt.dwthelper.utils; + +import tango.io.Stdout; + +void main (String [] args) { + /* These cannot be local in the + * listener, hence we put it here and not at the + * constructor. (THD) + * (dmd.1.028) + */ + DateTime calendar, date, time; + Shell dialog; + + Display display = new Display (); + Shell shell = new Shell (display); + shell.setLayout(new FillLayout()); + + Button open = new Button (shell, DWT.PUSH); + open.setText ("Open Dialog"); + open.addSelectionListener (new class() SelectionAdapter{ + public void widgetSelected (SelectionEvent e) { + dialog = new Shell (shell, DWT.DIALOG_TRIM); + dialog.setLayout (new GridLayout (3, false)); + + calendar = new DateTime (dialog, DWT.CALENDAR | DWT.BORDER); + date = new DateTime (dialog, DWT.DATE | DWT.SHORT); + time = new DateTime (dialog, DWT.TIME | DWT.SHORT); + + new Label (dialog, DWT.NONE); + new Label (dialog, DWT.NONE); + Button ok = new Button (dialog, DWT.PUSH); + ok.setText ("OK"); + ok.setLayoutData(new GridData (DWT.FILL, DWT.CENTER, false, false)); + ok.addSelectionListener (new class() SelectionAdapter{ + void widgetSelected (SelectionEvent e) { + Stdout.formatln("Calendar date selected (MM/DD/YYYY) = {:d02}/{:d02}/{:d04}", + (calendar.getMonth () + 1),calendar.getDay (),calendar.getYear ()); + Stdout.formatln("Date selected (MM/YYYY)= {:d02}/{:d04}", + (date.getMonth () + 1), date.getYear ()); + Stdout.formatln("Time selected (HH:MM) = {:d02}:{:d02}", + time.getHours(), time.getMinutes()); + Stdout.flush(); + dialog.close (); + } + }); + dialog.setDefaultButton (ok); + dialog.pack (); + dialog.open (); + } + }); + shell.pack (); + shell.open (); + + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 7b1c122b4128 -r 9a1be6ff19a2 snippets/dsss.conf --- a/snippets/dsss.conf Sun Jul 13 00:51:55 2008 +0200 +++ b/snippets/dsss.conf Sun Jul 20 15:26:06 2008 +0200 @@ -15,7 +15,6 @@ } - [busyindicator/Snippet130.d] [busyindicator/Snippet130a.d] [button/Snippet108.d] @@ -26,36 +25,57 @@ [button/Snippet293.d] [button/Snippet294.d] [canvas/Snippet21.d] -[canvas/Snippet48.d] [canvas/Snippet245.d] [canvas/Snippet275.d] [canvas/Snippet290.d] +[canvas/Snippet48.d] [caret/Snippet43.d] [caret/Snippet74.d] [ccombo/Snippet39.d] -[clipboard/Snippet94.d] [clipboard/Snippet122.d] [clipboard/Snippet282.d] +[clipboard/Snippet94.d] [color/Snippet208.d] +[combo/Snippet147.d] +[combo/Snippet24.d] +[combo/Snippet26.d] +[combo/Snippet269.d] +[combo/Snippet289.d] +[composite/Snippet115.d] +[composite/Snippet237.d] +[composite/Snippet46.d] +[composite/Snippet75.d] +[composite/Snippet9.d] +[composite/Snippet98.d] +[control/Snippet127.d] +[control/Snippet14.d] +[control/Snippet214.d] +[control/Snippet247.d] [control/Snippet25.d] [control/Snippet62.d] -[combo/Snippet26.d] -[composite/Snippet9.d] -[coolbar/Snippet20.d] [coolbar/Snippet140.d] [coolbar/Snippet150.d] +[coolbar/Snippet20.d] [ctabfolder/Snippet165.d] +[ctabfolder/Snippet82.d] +[cursor/Snippet118.d] +[cursor/Snippet119.d] +[cursor/Snippet242.d] +[cursor/Snippet44.d] +[cursor/Snippet92.d] +[datetime/Snippet250.d] +[datetime/Snippet251.d] [directorydialog/Snippet33.d] [expandbar/Snippet223.d] [filedialog/Snippet72.d] [gc/Snippet10.d] -[gc/Snippet66.d] [gc/Snippet207.d] [gc/Snippet215.d] +[gc/Snippet66.d] +[menu/Snippet152.d] +[menu/Snippet286.d] [menu/Snippet29.d] [menu/Snippet97.d] -[menu/Snippet152.d] -[menu/Snippet286.d] [program/Snippet32.d] [sash/Snippet107.d] [sashform/Snippet109.d] @@ -67,24 +87,24 @@ [styledtext/Snippet163.d] [styledtext/Snippet189.d] [tabfolder/Snippet76.d] +[table/Snippet144.d] [table/Snippet38.d] [table/Snippet96.d] -[table/Snippet144.d] [text/Snippet258.d] +[toolbar/Snippet153.d] +[toolbar/Snippet288.d] [toolbar/Snippet47.d] [toolbar/Snippet49.d] [toolbar/Snippet58.d] [toolbar/Snippet67.d] -[toolbar/Snippet153.d] -[toolbar/Snippet288.d] [tooltips/Snippet41.d] [tray/Snippet143.d] -[tree/Snippet8.d] [tree/Snippet15.d] [tree/Snippet170.d] [tree/Snippet193.d] [tree/Snippet220.d] [tree/Snippet226.d] +[tree/Snippet8.d] [treeeditor/Snippet111.d] version(Derelict){