# HG changeset patch # User Bill Baxter # Date 1211431673 -32400 # Node ID 7990996869555ae5f066c4d002dad14971d23ac8 # Parent 961ca8a76cadbd8bc40a6f67fb8ee8c2674205c5 New tree snippet ports diff -r 961ca8a76cad -r 799099686955 snippets/dsss.conf --- a/snippets/dsss.conf Thu May 22 03:05:49 2008 +0900 +++ b/snippets/dsss.conf Thu May 22 13:47:53 2008 +0900 @@ -64,7 +64,10 @@ [tray/Snippet143.d] [tree/Snippet8.d] [tree/Snippet15.d] +[tree/Snippet170.d] +[tree/Snippet193.d] [tree/Snippet220.d] +[tree/Snippet226.d] [treeeditor/Snippet111.d] version(Derelict){ diff -r 961ca8a76cad -r 799099686955 snippets/tree/Snippet170.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/tree/Snippet170.d Thu May 22 13:47:53 2008 +0900 @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.tree.Snippet170; + +/* + * Tree example snippet: Create a Tree with columns + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.1 + */ + +import dwt.DWT; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Tree; +import dwt.widgets.TreeItem; +import dwt.widgets.TreeColumn; +import dwt.layout.FillLayout; + +import tango.util.Convert; + +import dwt.dwthelper.utils; + +void main() { + Display display = new Display(); + final Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + Tree tree = new Tree(shell, DWT.BORDER | DWT.H_SCROLL | DWT.V_SCROLL); + tree.setHeaderVisible(true); + TreeColumn column1 = new TreeColumn(tree, DWT.LEFT); + column1.setText("Column 1"); + column1.setWidth(200); + TreeColumn column2 = new TreeColumn(tree, DWT.CENTER); + column2.setText("Column 2"); + column2.setWidth(200); + TreeColumn column3 = new TreeColumn(tree, DWT.RIGHT); + column3.setText("Column 3"); + column3.setWidth(200); + for (int i = 0; i < 4; i++) { + TreeItem item = new TreeItem(tree, DWT.NONE); + item.setText([ "item " ~ to!(String)(i), "abc", "defghi" ]); + for (int j = 0; j < 4; j++) { + TreeItem subItem = new TreeItem(item, DWT.NONE); + subItem.setText([ "subitem " ~ to!(String)(j), "jklmnop", "qrs" ]); + for (int k = 0; k < 4; k++) { + TreeItem subsubItem = new TreeItem(subItem, DWT.NONE); + subsubItem.setText([ "subsubitem " ~ to!(String)(k), "tuv", "wxyz" ]); + } + } + } + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + display.dispose(); +} diff -r 961ca8a76cad -r 799099686955 snippets/tree/Snippet193.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/tree/Snippet193.d Thu May 22 13:47:53 2008 +0900 @@ -0,0 +1,119 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.tree.Snippet193; + +/* + * Tree example snippet: allow user to reorder columns by dragging and programmatically. + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.2 + */ +import dwt.DWT; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Tree; +import dwt.widgets.TreeItem; +import dwt.widgets.TreeColumn; +import dwt.widgets.Button; +import dwt.widgets.Listener; +import dwt.widgets.Event; +import dwt.layout.RowLayout; +import dwt.layout.RowData; + +import tango.util.Convert; +import tango.io.Stdout; + +import dwt.dwthelper.utils; + + +void main() { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new RowLayout(DWT.HORIZONTAL)); + final Tree tree = new Tree(shell, DWT.BORDER | DWT.CHECK); + tree.setLayoutData(new RowData(-1, 300)); + tree.setHeaderVisible(true); + TreeColumn column = new TreeColumn(tree, DWT.LEFT); + column.setText("Column 0"); + column = new TreeColumn(tree, DWT.CENTER); + column.setText("Column 1"); + column = new TreeColumn(tree, DWT.LEFT); + column.setText("Column 2"); + column = new TreeColumn(tree, DWT.RIGHT); + column.setText("Column 3"); + column = new TreeColumn(tree, DWT.CENTER); + column.setText("Column 4"); + for (int i = 0; i < 5; i++) { + TreeItem item = new TreeItem(tree, DWT.NONE); + auto istr = to!(String)(i); + String[] text = [istr~":0", + istr~":1", + istr~":2", + istr~":3", + istr~":4"]; + item.setText(text); + for (int j = 0; j < 5; j++) { + auto jstr = to!(String)(j); + TreeItem subItem = new TreeItem(item, DWT.NONE); + text = [istr~","~jstr~":0", + istr~","~jstr~":1", + istr~","~jstr~":2", + istr~","~jstr~":3", + istr~","~jstr~":4"]; + subItem.setText(text); + for (int k = 0; k < 5; k++) { + auto kstr = to!(String)(k); + TreeItem subsubItem = new TreeItem(subItem, DWT.NONE); + text = [istr~","~jstr~","~kstr~":0", + istr~","~jstr~","~kstr~":1", + istr~","~jstr~","~kstr~":2", + istr~","~jstr~","~kstr~":3", + istr~","~jstr~","~kstr~":4"]; + subsubItem.setText(text); + } + } + } + Listener listener = new class Listener { + public void handleEvent(Event e) { + Stdout.print("Move "~e.widget.toString).newline; + } + }; + TreeColumn[] columns = tree.getColumns(); + for (int i = 0; i < columns.length; i++) { + columns[i].setWidth(100); + columns[i].setMoveable(true); + columns[i].addListener(DWT.Move, listener); + } + Button b = new Button(shell, DWT.PUSH); + b.setText("invert column order"); + b.addListener(DWT.Selection, new class Listener { + public void handleEvent(Event e) { + int[] order = tree.getColumnOrder(); + for (int i = 0; i < order.length / 2; i++) { + int temp = order[i]; + order[i] = order[order.length - i - 1]; + order[order.length - i - 1] = temp; + } + tree.setColumnOrder(order); + } + }); + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); +} diff -r 961ca8a76cad -r 799099686955 snippets/tree/Snippet226.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/tree/Snippet226.d Thu May 22 13:47:53 2008 +0900 @@ -0,0 +1,136 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.tree.Snippet226; + +/* + * Tree example snippet: Draw a custom gradient selection + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.3 + */ +import dwt.DWT; +import dwt.graphics.GC; +import dwt.graphics.Rectangle; +import dwt.graphics.Region; +import dwt.graphics.Color; +import dwt.layout.FillLayout; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Tree; +import dwt.widgets.TreeItem; +import dwt.widgets.TreeColumn; +import dwt.widgets.Listener; +import dwt.widgets.Event; + +import tango.util.Convert; + +import dwt.dwthelper.utils; + +void main() +{ + final Display display = new Display(); + Shell shell = new Shell(display); + shell.setText("Custom gradient selection for Tree"); + shell.setLayout(new FillLayout()); + final Tree tree = new Tree(shell, DWT.MULTI | DWT.FULL_SELECTION); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + int columnCount = 4; + for (int i=0; i 0) { + Region region = new Region(); + gc.getClipping(region); + region.add(event.x, event.y, width, event.height); + gc.setClipping(region); + region.dispose(); + } + } + gc.setAdvanced(true); + if (gc.getAdvanced()) gc.setAlpha(127); + Rectangle rect = event.getBounds(); + Color foreground = gc.getForeground(); + Color background = gc.getBackground(); + gc.setForeground(display.getSystemColor(DWT.COLOR_RED)); + gc.setBackground(display.getSystemColor(DWT.COLOR_LIST_BACKGROUND)); + gc.fillGradientRectangle(0, rect.y, 500, rect.height, false); + // restore colors for subsequent drawing + gc.setForeground(foreground); + gc.setBackground(background); + event.detail &= ~DWT.SELECTED; + } + } + }); + for (int i=0; i