# HG changeset patch # User Frank Benoit # Date 1205448818 -3600 # Node ID 8ee0dfe6f6851f8deab5dac0d885b113cc84ca3b # Parent 3dc632b3f71b0fde8ade4338c1eb0a7d36c7d9a3 Snippet134 with non rectangular shell. Some more minor fixes. diff -r 3dc632b3f71b -r 8ee0dfe6f685 dsss.conf --- a/dsss.conf Mon Mar 10 04:59:18 2008 +0100 +++ b/dsss.conf Thu Mar 13 23:53:38 2008 +0100 @@ -37,6 +37,7 @@ [dwtsnippets/menu/Snippet29.d] [dwtsnippets/menu/Snippet97.d] [dwtsnippets/sash/Snippet107.d] +[dwtsnippets/shell/Snippet134.d] [dwtsnippets/styledtext/Snippet163.d] [dwtsnippets/styledtext/Snippet189.d] [dwtsnippets/table/Snippet38.d] diff -r 3dc632b3f71b -r 8ee0dfe6f685 dwtsnippets/composite/Snippet9.d --- a/dwtsnippets/composite/Snippet9.d Mon Mar 10 04:59:18 2008 +0100 +++ b/dwtsnippets/composite/Snippet9.d Thu Mar 13 23:53:38 2008 +0100 @@ -1,4 +1,4 @@ -/******************************************************************************* +/******************************************************************************* * 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 @@ -29,6 +29,7 @@ import dwt.widgets.Listener; import dwt.widgets.ScrollBar; import dwt.widgets.Shell; +import dwt.dwthelper.utils; void main () { auto display = new Display (); diff -r 3dc632b3f71b -r 8ee0dfe6f685 dwtsnippets/shell/Snippet134.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtsnippets/shell/Snippet134.d Thu Mar 13 23:53:38 2008 +0100 @@ -0,0 +1,111 @@ +/******************************************************************************* + * 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 + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ +module dwtsnippets.shell.Snippet134; + +/* + * Shell example snippet: create a non-rectangular window + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ +import dwt.DWT; +import dwt.graphics.Region; +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Button; +import dwt.widgets.Listener; +import dwt.widgets.Event; + +import dwt.dwthelper.utils; + +version(JIVE){ + import jive.stacktrace; +} + +int[] circle(int r, int offsetX, int offsetY) { + int[] polygon = new int[8 * r + 4]; + //x^2 + y^2 = r^2 + for (int i = 0; i < 2 * r + 1; i++) { + int x = i - r; + int y = cast(int)Math.sqrt( cast(float)(r*r - x*x)); + polygon[2*i] = offsetX + x; + polygon[2*i+1] = offsetY + y; + polygon[8*r - 2*i - 2] = offsetX + x; + polygon[8*r - 2*i - 1] = offsetY - y; + } + return polygon; +} + +Display display; +Shell shell; + +void main(char[][] args) { + display = new Display(); + //Shell must be created with style SWT.NO_TRIM + shell = new Shell(display, DWT.NO_TRIM | DWT.ON_TOP); + shell.setBackground(display.getSystemColor(DWT.COLOR_RED)); + //define a region that looks like a key hole + Region region = new Region(); + region.add(circle(67, 67, 67)); + region.subtract(circle(20, 67, 50)); + region.subtract([67, 50, 55, 105, 79, 105]); + //define the shape of the shell using setRegion + shell.setRegion(region); + Rectangle size = region.getBounds(); + shell.setSize(size.width, size.height); + //add ability to move shell around + Listener l = new class Listener { + Point origin; + public void handleEvent(Event e) { + switch (e.type) { + case DWT.MouseDown: + origin = new Point(e.x, e.y); + break; + case DWT.MouseUp: + origin = null; + break; + case DWT.MouseMove: + if (origin !is null) { + Point p = display.map(shell, null, e.x, e.y); + shell.setLocation(p.x - origin.x, p.y - origin.y); + } + break; + } + } + }; + shell.addListener(DWT.MouseDown, l); + shell.addListener(DWT.MouseUp, l); + shell.addListener(DWT.MouseMove, l); + //add ability to close shell + Button b = new Button(shell, DWT.PUSH); + b.setBackground(shell.getBackground()); + b.setText("close"); + b.pack(); + b.setLocation(10, 68); + b.addListener(DWT.Selection, new class Listener { + public void handleEvent(Event e) { + shell.close(); + } + }); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + region.dispose(); + display.dispose(); +} diff -r 3dc632b3f71b -r 8ee0dfe6f685 dwtsnippets/table/Snippet144.d --- a/dwtsnippets/table/Snippet144.d Mon Mar 10 04:59:18 2008 +0100 +++ b/dwtsnippets/table/Snippet144.d Thu Mar 13 23:53:38 2008 +0100 @@ -1,4 +1,4 @@ -/******************************************************************************* +/******************************************************************************* * 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 @@ -17,7 +17,7 @@ * * For a list of all SWT example snippets see * http://www.eclipse.org/swt/snippets/ - * + * * @since 3.0 */ import dwt.DWT; @@ -61,8 +61,8 @@ elapsed.start; table.setItemCount (COUNT); auto t = elapsed.stop; - label.setText ("Items: " ~ to!(char[])(COUNT) ~ - ", Time: " ~ to!(char[])(t) ~ " (ms)"); + label.setText ("Items: " ~ to!(char[])(COUNT) ~ + ", Time: " ~ to!(char[])(t) ~ " (sec)"); shell.layout (); } }); diff -r 3dc632b3f71b -r 8ee0dfe6f685 dwtsnippets/tree/Snippet8.d --- a/dwtsnippets/tree/Snippet8.d Mon Mar 10 04:59:18 2008 +0100 +++ b/dwtsnippets/tree/Snippet8.d Thu Mar 13 23:53:38 2008 +0100 @@ -1,4 +1,4 @@ -/******************************************************************************* +/******************************************************************************* * 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 @@ -11,7 +11,7 @@ * Jesse Phillips gmail.com *******************************************************************************/ module dwtsnippets.tree.Snippet8; - + /* * Tree example snippet: create a tree (lazy) * @@ -29,7 +29,7 @@ import dwt.widgets.Tree; import dwt.widgets.TreeItem; -import tango.math.Math; +import dwt.dwthelper.utils; import tango.io.FilePath; import tango.io.FileRoots; diff -r 3dc632b3f71b -r 8ee0dfe6f685 user/dragdrop/texttolabel.d --- a/user/dragdrop/texttolabel.d Mon Mar 10 04:59:18 2008 +0100 +++ b/user/dragdrop/texttolabel.d Thu Mar 13 23:53:38 2008 +0100 @@ -5,7 +5,7 @@ * http://www.java2s.com/Tutorial/Java/0280__SWT/DragselectedtextinTexttoLabel.htm * * Drag sellected text to a label. - * + * * Port to the D programming language: * Jesse Phillips gmail.com * @@ -26,13 +26,14 @@ import dwt.widgets.Label; import dwt.widgets.Shell; import dwt.widgets.Text; +import dwt.dwthelper.utils; import tango.io.Stdout; void main() { auto display = new Display(); auto shell = new Shell(display); - + auto text = new Text(shell, DWT.BORDER|DWT.SINGLE); int i = 0; @@ -41,7 +42,7 @@ types[0] = TextTransfer.getInstance(); auto source = new DragSource(text, DND.DROP_MOVE | DND.DROP_COPY); source.setTransfer(types); - + source.addDragListener(new class DragSourceAdapter { public void dragSetData(DragSourceEvent event) { // Get the selected items in the drag source