# HG changeset patch # User John Reimer # Date 1210451565 25200 # Node ID 4a04b6759f989473f858d903e1e22aab6770b097 # Parent 04f122e90b0a986552d697da6d92399f5ef5caf4 Clean up directory names diff -r 04f122e90b0a -r 4a04b6759f98 dsss.conf --- a/dsss.conf Sat Apr 26 10:11:28 2008 +0200 +++ b/dsss.conf Sat May 10 13:32:45 2008 -0700 @@ -14,10 +14,10 @@ buildflags+= -L/rc:dwt } -[dwtexamples] +[examples] type=subdir -[dwtsnippets] +[snippets] type=subdir [user] diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/addressbook/AddressBook.d --- a/dwtexamples/addressbook/AddressBook.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,902 +0,0 @@ -/******************************************************************************* - * 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 - * Port to the D programming language: - * Frank Benoit - *******************************************************************************/ -module dwtexamples.addressbook.AddressBook; - -import dwt.DWT; -import dwt.events.MenuAdapter; -import dwt.events.MenuEvent; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.events.ShellAdapter; -import dwt.events.ShellEvent; -import dwt.graphics.Cursor; -import dwt.layout.FillLayout; -import dwt.widgets.Display; -import dwt.widgets.FileDialog; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.MessageBox; -import dwt.widgets.Shell; -import dwt.widgets.Table; -import dwt.widgets.TableColumn; -import dwt.widgets.TableItem; - -import dwt.dwthelper.ResourceBundle; - -import tango.core.Exception; -import tango.io.FilePath; -import tango.io.File; -import tango.io.FileConduit; -import tango.io.stream.FileStream; -import TextUtil = tango.text.Util; -import Unicode = tango.text.Unicode; - -import dwtexamples.addressbook.SearchDialog; -import dwtexamples.addressbook.DataEntryDialog; -import dwtexamples.addressbook.FindListener; - -void main() { - Display display = new Display(); - auto application = new AddressBook(); - Shell shell = application.open(display); - while(!shell.isDisposed()){ - if(!display.readAndDispatch()){ - display.sleep(); - } - } - display.dispose(); -} - -/** - * AddressBookExample is an example that uses org.eclipse.swt - * libraries to implement a simple address book. This application has - * save, load, sorting, and searching functions common - * to basic address books. - */ -public class AddressBook { - - private static ResourceBundle resAddressBook; - private static const char[] resAddressBookData = cast(char[]) import( "dwtexamples.addressbook.addressbook.properties" ); - private Shell shell; - - private Table table; - private SearchDialog searchDialog; - - private FilePath file; - private bool isModified; - - private char[][] copyBuffer; - - private int lastSortColumn= -1; - - private static const char[] DELIMITER = "\t"; - private static char[][] columnNames; - -public this(){ - if( resAddressBook is null ){ - resAddressBook = ResourceBundle.getBundleFromData(resAddressBookData); - columnNames = [ - resAddressBook.getString("Last_name"), - resAddressBook.getString("First_name"), - resAddressBook.getString("Business_phone"), - resAddressBook.getString("Home_phone"), - resAddressBook.getString("Email"), - resAddressBook.getString("Fax") ]; - } -} - - -public Shell open(Display display) { - shell = new Shell(display); - shell.setLayout(new FillLayout()); - - shell.addShellListener( new class() ShellAdapter { - public void shellClosed(ShellEvent e) { - e.doit = closeAddressBook(); - } - }); - - createMenuBar(); - - searchDialog = new SearchDialog(shell); - searchDialog.setSearchAreaNames(columnNames); - searchDialog.setSearchAreaLabel(resAddressBook.getString("Column")); - searchDialog.addFindListener(new class() FindListener { - public bool find() { - return findEntry(); - } - }); - - table = new Table(shell, DWT.SINGLE | DWT.BORDER | DWT.FULL_SELECTION); - table.setHeaderVisible(true); - table.setMenu(createPopUpMenu()); - table.addSelectionListener(new class() SelectionAdapter { - public void widgetDefaultSelected(SelectionEvent e) { - TableItem[] items = table.getSelection(); - if (items.length > 0) editEntry(items[0]); - } - }); - for(int i = 0; i < columnNames.length; i++) { - TableColumn column = new TableColumn(table, DWT.NONE); - column.setText(columnNames[i]); - column.setWidth(150); - int columnIndex = i; - column.addSelectionListener(new class(columnIndex) SelectionAdapter { - int c; - this( int c ){ this.c = c; } - public void widgetSelected(SelectionEvent e) { - sort(c); - } - }); - } - - newAddressBook(); - - shell.setSize(table.computeSize(DWT.DEFAULT, DWT.DEFAULT).x, 300); - shell.open(); - return shell; -} - -private bool closeAddressBook() { - if(isModified) { - //ask user if they want to save current address book - MessageBox box = new MessageBox(shell, DWT.ICON_WARNING | DWT.YES | DWT.NO | DWT.CANCEL); - box.setText(shell.getText()); - box.setMessage(resAddressBook.getString("Close_save")); - - int choice = box.open(); - if(choice is DWT.CANCEL) { - return false; - } else if(choice is DWT.YES) { - if (!save()) return false; - } - } - - TableItem[] items = table.getItems(); - for (int i = 0; i < items.length; i ++) { - items[i].dispose(); - } - - return true; -} -/** - * Creates the menu at the top of the shell where most - * of the programs functionality is accessed. - * - * @return The Menu widget that was created - */ -private Menu createMenuBar() { - Menu menuBar = new Menu(shell, DWT.BAR); - shell.setMenuBar(menuBar); - - //create each header and subMenu for the menuBar - createFileMenu(menuBar); - createEditMenu(menuBar); - createSearchMenu(menuBar); - createHelpMenu(menuBar); - - return menuBar; -} - -/** - * Converts an encoded char[] to a char[] array representing a table entry. - */ -private char[][] decodeLine(char[] line) { - char[][] toks = TextUtil.split( line, DELIMITER ); - while( toks.length < table.getColumnCount() ){ - toks ~= ""; - } - return toks[ 0 .. table.getColumnCount() ]; -} -private void displayError(char[] msg) { - MessageBox box = new MessageBox(shell, DWT.ICON_ERROR); - box.setMessage(msg); - box.open(); -} -private void editEntry(TableItem item) { - DataEntryDialog dialog = new DataEntryDialog(shell); - dialog.setLabels(columnNames); - char[][] values = new char[][table.getColumnCount()]; - for (int i = 0; i < values.length; i++) { - values[i] = item.getText(i); - } - dialog.setValues(values); - values = dialog.open(); - if (values !is null) { - item.setText(values); - isModified = true; - } -} -private char[] encodeLine(char[][] tableItems) { - char[] line = ""; - for (int i = 0; i < tableItems.length - 1; i++) { - line ~= tableItems[i] ~ DELIMITER; - } - line ~= tableItems[tableItems.length - 1] ~ "\n"; - - return line; -} -private bool findEntry() { - Cursor waitCursor = new Cursor(shell.getDisplay(), DWT.CURSOR_WAIT); - shell.setCursor(waitCursor); - - bool matchCase = searchDialog.getMatchCase(); - bool matchWord = searchDialog.getMatchWord(); - char[] searchString = searchDialog.getSearchString(); - int column = searchDialog.getSelectedSearchArea(); - - searchString = matchCase ? searchString : Unicode.toLower( searchString ); - - bool found = false; - if (searchDialog.getSearchDown()) { - for(int i = table.getSelectionIndex() + 1; i < table.getItemCount(); i++) { - found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase); - if ( found ){ - table.setSelection(i); - break; - } - } - } else { - for(int i = table.getSelectionIndex() - 1; i > -1; i--) { - found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase); - if ( found ){ - table.setSelection(i); - break; - } - } - } - - shell.setCursor(cast(Cursor)null); - waitCursor.dispose(); - - return found; -} -private bool findMatch(char[] searchString, TableItem item, int column, bool matchWord, bool matchCase) { - - char[] tableText = matchCase ? item.getText(column) : Unicode.toLower( item.getText(column)); - if (matchWord) { - if (tableText !is null && tableText==searchString) { - return true; - } - - } else { - if(tableText!is null && TextUtil.containsPattern( tableText, searchString)) { - return true; - } - } - return false; -} -private void newAddressBook() { - shell.setText(resAddressBook.getString("Title_bar") ~ resAddressBook.getString("New_title")); - *(cast(Object*)&file) = null; - ///cast(Object)file = null; - isModified = false; -} -private void newEntry() { - DataEntryDialog dialog = new DataEntryDialog(shell); - dialog.setLabels(columnNames); - char[][] data = dialog.open(); - if (data !is null) { - TableItem item = new TableItem(table, DWT.NONE); - item.setText(data); - isModified = true; - } -} - -private void openAddressBook() { - FileDialog fileDialog = new FileDialog(shell, DWT.OPEN); - - fileDialog.setFilterExtensions(["*.adr;", "*.*"]); - fileDialog.setFilterNames([ - resAddressBook.getString("Book_filter_name") ~ " (*.adr)", - resAddressBook.getString("All_filter_name") ~ " (*.*)"]); - char[] name = fileDialog.open(); - - if(name is null) return; - FilePath file = new FilePath(name); - if (!file.exists()) { - displayError(resAddressBook.getString("File")~file.toString()~" "~resAddressBook.getString("Does_not_exist")); - return; - } - - Cursor waitCursor = new Cursor(shell.getDisplay(), DWT.CURSOR_WAIT); - shell.setCursor(waitCursor); - - char[][] data; - try { - scope ioFile = new File (file); - data = TextUtil.splitLines (cast(char[]) ioFile.read); - } catch (IOException e ) { - displayError(resAddressBook.getString("IO_error_read") ~ "\n" ~ file.toString()); - return; - } finally { - - shell.setCursor(cast(Cursor)null); - waitCursor.dispose(); - } - - char[][][] tableInfo = new char[][][](data.length,table.getColumnCount()); - foreach( idx, line; data ){ - char[][] linetoks = decodeLine(line); - tableInfo[ idx ] = linetoks; - } - /+ - int writeIndex = 0; - for (int i = 0; i < data.length; i++) { - char[][] line = decodeLine(data[i]); - if (line !is null) tableInfo[writeIndex++] = line; - } - if (writeIndex !is data.length) { - char[][][] result = new char[][writeIndex][table.getColumnCount()]; - System.arraycopy(tableInfo, 0, result, 0, writeIndex); - tableInfo = result; - } - +/ - tango.core.Array.sort( tableInfo, new RowComparator(0)); - - for (int i = 0; i < tableInfo.length; i++) { - TableItem item = new TableItem(table, DWT.NONE); - item.setText(tableInfo[i]); - } - shell.setText(resAddressBook.getString("Title_bar")~fileDialog.getFileName()); - isModified = false; - this.file = file; -} -private bool save() { - if(file is null) return saveAs(); - - Cursor waitCursor = new Cursor(shell.getDisplay(), DWT.CURSOR_WAIT); - shell.setCursor(waitCursor); - - TableItem[] items = table.getItems(); - char[][] lines = new char[][items.length]; - for(int i = 0; i < items.length; i++) { - char[][] itemText = new char[][table.getColumnCount()]; - for (int j = 0; j < itemText.length; j++) { - itemText[j] = items[i].getText(j); - } - lines[i] = encodeLine(itemText); - } - - FileOutput fileOutput; - bool result = true; - try { - fileOutput = new FileOutput( file.toString ); - for (int i = 0; i < lines.length; i++) { - fileOutput.write(lines[i]); - } - } catch(IOException e ) { - displayError(resAddressBook.getString("IO_error_write") ~ "\n" ~ file.toString()); - result = false; - } catch(Exception e2 ) { - displayError(resAddressBook.getString("error_write") ~ "\n" ~ e2.toString()); - result = false; - } finally { - shell.setCursor(null); - waitCursor.dispose(); - - } - - if(fileOutput !is null) { - try { - fileOutput.close(); - } catch(IOException e) { - displayError(resAddressBook.getString("IO_error_close") ~ "\n" ~ file.toString()); - return false; - } - } - if( !result ){ - return false; - } - - shell.setText(resAddressBook.getString("Title_bar")~file.toString()); - isModified = false; - return true; -} -private bool saveAs() { - - FileDialog saveDialog = new FileDialog(shell, DWT.SAVE); - saveDialog.setFilterExtensions(["*.adr;", "*.*"]); - saveDialog.setFilterNames(["Address Books (*.adr)", "All Files "]); - - saveDialog.open(); - char[] name = saveDialog.getFileName(); - if(!name) return false; - - if( TextUtil.locatePatternPrior( name, ".adr" ) !is name.length - 4) { - name ~= ".adr"; - } - - FilePath file = new FilePath(saveDialog.getFilterPath() ); - file.append( name ); - if(file.exists()) { - MessageBox box = new MessageBox(shell, DWT.ICON_WARNING | DWT.YES | DWT.NO); - box.setText(resAddressBook.getString("Save_as_title")); - box.setMessage(resAddressBook.getString("File") ~ file.toString()~" "~resAddressBook.getString("Query_overwrite")); - if(box.open() !is DWT.YES) { - return false; - } - } - this.file = file; - return save(); -} -private void sort(int column) { - if(table.getItemCount() <= 1) return; - - TableItem[] items = table.getItems(); - char[][][] data = new char[][][](items.length, table.getColumnCount()); - for(int i = 0; i < items.length; i++) { - for(int j = 0; j < table.getColumnCount(); j++) { - data[i][j] = items[i].getText(j); - } - } - - tango.core.Array.sort(data, new RowComparator(column)); - - if (lastSortColumn !is column) { - table.setSortColumn(table.getColumn(column)); - table.setSortDirection(DWT.DOWN); - for (int i = 0; i < data.length; i++) { - items[i].setText(data[i]); - } - lastSortColumn = column; - } else { - // reverse order if the current column is selected again - table.setSortDirection(DWT.UP); - int j = data.length -1; - for (int i = 0; i < data.length; i++) { - items[i].setText(data[j--]); - } - lastSortColumn = -1; - } - -} -/** - * Creates all the items located in the File submenu and - * associate all the menu items with their appropriate - * functions. - * - * @param menuBar Menu - * the Menu that file contain - * the File submenu. - */ -private void createFileMenu(Menu menuBar) { - //File menu. - MenuItem item = new MenuItem(menuBar, DWT.CASCADE); - item.setText(resAddressBook.getString("File_menu_title")); - Menu menu = new Menu(shell, DWT.DROP_DOWN); - item.setMenu(menu); - /** - * Adds a listener to handle enabling and disabling - * some items in the Edit submenu. - */ - menu.addMenuListener(new class() MenuAdapter { - public void menuShown(MenuEvent e) { - Menu menu = cast(Menu)e.widget; - MenuItem[] items = menu.getItems(); - items[1].setEnabled(table.getSelectionCount() !is 0); // edit contact - items[5].setEnabled((file !is null) && isModified); // save - items[6].setEnabled(table.getItemCount() !is 0); // save as - } - }); - - - //File -> New Contact - MenuItem subItem = new MenuItem(menu, DWT.NONE); - subItem.setText(resAddressBook.getString("New_contact")); - subItem.setAccelerator(DWT.MOD1 + 'N'); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - newEntry(); - } - }); - subItem = new MenuItem(menu, DWT.NONE); - subItem.setText(resAddressBook.getString("Edit_contact")); - subItem.setAccelerator(DWT.MOD1 + 'E'); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - TableItem[] items = table.getSelection(); - if (items.length is 0) return; - editEntry(items[0]); - } - }); - - - new MenuItem(menu, DWT.SEPARATOR); - - //File -> New Address Book - subItem = new MenuItem(menu, DWT.NONE); - subItem.setText(resAddressBook.getString("New_address_book")); - subItem.setAccelerator(DWT.MOD1 + 'B'); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - if (closeAddressBook()) { - newAddressBook(); - } - } - }); - - //File -> Open - subItem = new MenuItem(menu, DWT.NONE); - subItem.setText(resAddressBook.getString("Open_address_book")); - subItem.setAccelerator(DWT.MOD1 + 'O'); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - if (closeAddressBook()) { - openAddressBook(); - } - } - }); - - //File -> Save. - subItem = new MenuItem(menu, DWT.NONE); - subItem.setText(resAddressBook.getString("Save_address_book")); - subItem.setAccelerator(DWT.MOD1 + 'S'); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - save(); - } - }); - - //File -> Save As. - subItem = new MenuItem(menu, DWT.NONE); - subItem.setText(resAddressBook.getString("Save_book_as")); - subItem.setAccelerator(DWT.MOD1 + 'A'); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - saveAs(); - } - }); - - - new MenuItem(menu, DWT.SEPARATOR); - - //File -> Exit. - subItem = new MenuItem(menu, DWT.NONE); - subItem.setText(resAddressBook.getString("Exit")); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - shell.close(); - } - }); -} - -/** - * Creates all the items located in the Edit submenu and - * associate all the menu items with their appropriate - * functions. - * - * @param menuBar Menu - * the Menu that file contain - * the Edit submenu. - * - * @see #createSortMenu() - */ -private MenuItem createEditMenu(Menu menuBar) { - //Edit menu. - MenuItem item = new MenuItem(menuBar, DWT.CASCADE); - item.setText(resAddressBook.getString("Edit_menu_title")); - Menu menu = new Menu(shell, DWT.DROP_DOWN); - item.setMenu(menu); - - /** - * Add a listener to handle enabling and disabling - * some items in the Edit submenu. - */ - menu.addMenuListener(new class() MenuAdapter { - public void menuShown(MenuEvent e) { - Menu menu = cast(Menu)e.widget; - MenuItem[] items = menu.getItems(); - int count = table.getSelectionCount(); - items[0].setEnabled(count !is 0); // edit - items[1].setEnabled(count !is 0); // copy - items[2].setEnabled(copyBuffer !is null); // paste - items[3].setEnabled(count !is 0); // delete - items[5].setEnabled(table.getItemCount() !is 0); // sort - } - }); - - //Edit -> Edit - MenuItem subItem = new MenuItem(menu, DWT.PUSH); - subItem.setText(resAddressBook.getString("Edit")); - subItem.setAccelerator(DWT.MOD1 + 'E'); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - TableItem[] items = table.getSelection(); - if (items.length is 0) return; - editEntry(items[0]); - } - }); - - //Edit -> Copy - subItem = new MenuItem(menu, DWT.NONE); - subItem.setText(resAddressBook.getString("Copy")); - subItem.setAccelerator(DWT.MOD1 + 'C'); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - TableItem[] items = table.getSelection(); - if (items.length is 0) return; - copyBuffer = new char[][table.getColumnCount()]; - for (int i = 0; i < copyBuffer.length; i++) { - copyBuffer[i] = items[0].getText(i); - } - } - }); - - //Edit -> Paste - subItem = new MenuItem(menu, DWT.NONE); - subItem.setText(resAddressBook.getString("Paste")); - subItem.setAccelerator(DWT.MOD1 + 'V'); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - if (copyBuffer is null) return; - TableItem item = new TableItem(table, DWT.NONE); - item.setText(copyBuffer); - isModified = true; - } - }); - - //Edit -> Delete - subItem = new MenuItem(menu, DWT.NONE); - subItem.setText(resAddressBook.getString("Delete")); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - TableItem[] items = table.getSelection(); - if (items.length is 0) return; - items[0].dispose(); - isModified = true; } - }); - - new MenuItem(menu, DWT.SEPARATOR); - - //Edit -> Sort(Cascade) - subItem = new MenuItem(menu, DWT.CASCADE); - subItem.setText(resAddressBook.getString("Sort")); - Menu submenu = createSortMenu(); - subItem.setMenu(submenu); - - return item; - -} - -/** - * Creates all the items located in the Sort cascading submenu and - * associate all the menu items with their appropriate - * functions. - * - * @return Menu - * The cascading menu with all the sort menu items on it. - */ -private Menu createSortMenu() { - Menu submenu = new Menu(shell, DWT.DROP_DOWN); - MenuItem subitem; - for(int i = 0; i < columnNames.length; i++) { - subitem = new MenuItem (submenu, DWT.NONE); - subitem.setText(columnNames [i]); - int column = i; - subitem.addSelectionListener(new class(column) SelectionAdapter { - int c; - this(int c){ this.c = c; } - public void widgetSelected(SelectionEvent e) { - sort(c); - } - }); - } - - return submenu; -} - -/** - * Creates all the items located in the Search submenu and - * associate all the menu items with their appropriate - * functions. - * - * @param menuBar Menu - * the Menu that file contain - * the Search submenu. - */ -private void createSearchMenu(Menu menuBar) { - //Search menu. - MenuItem item = new MenuItem(menuBar, DWT.CASCADE); - item.setText(resAddressBook.getString("Search_menu_title")); - Menu searchMenu = new Menu(shell, DWT.DROP_DOWN); - item.setMenu(searchMenu); - - //Search -> Find... - item = new MenuItem(searchMenu, DWT.NONE); - item.setText(resAddressBook.getString("Find")); - item.setAccelerator(DWT.MOD1 + 'F'); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - searchDialog.setMatchCase(false); - searchDialog.setMatchWord(false); - searchDialog.setSearchDown(true); - searchDialog.setSearchString(""); - searchDialog.setSelectedSearchArea(0); - searchDialog.open(); - } - }); - - //Search -> Find Next - item = new MenuItem(searchMenu, DWT.NONE); - item.setText(resAddressBook.getString("Find_next")); - item.setAccelerator(DWT.F3); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - searchDialog.open(); - } - }); -} - -/** - * Creates all items located in the popup menu and associates - * all the menu items with their appropriate functions. - * - * @return Menu - * The created popup menu. - */ -private Menu createPopUpMenu() { - Menu popUpMenu = new Menu(shell, DWT.POP_UP); - - /** - * Adds a listener to handle enabling and disabling - * some items in the Edit submenu. - */ - popUpMenu.addMenuListener(new class() MenuAdapter { - public void menuShown(MenuEvent e) { - Menu menu = cast(Menu)e.widget; - MenuItem[] items = menu.getItems(); - int count = table.getSelectionCount(); - items[2].setEnabled(count !is 0); // edit - items[3].setEnabled(count !is 0); // copy - items[4].setEnabled(copyBuffer !is null); // paste - items[5].setEnabled(count !is 0); // delete - items[7].setEnabled(table.getItemCount() !is 0); // find - } - }); - - //New - MenuItem item = new MenuItem(popUpMenu, DWT.PUSH); - item.setText(resAddressBook.getString("Pop_up_new")); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - newEntry(); - } - }); - - new MenuItem(popUpMenu, DWT.SEPARATOR); - - //Edit - item = new MenuItem(popUpMenu, DWT.PUSH); - item.setText(resAddressBook.getString("Pop_up_edit")); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - TableItem[] items = table.getSelection(); - if (items.length is 0) return; - editEntry(items[0]); - } - }); - - //Copy - item = new MenuItem(popUpMenu, DWT.PUSH); - item.setText(resAddressBook.getString("Pop_up_copy")); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - TableItem[] items = table.getSelection(); - if (items.length is 0) return; - copyBuffer = new char[][table.getColumnCount()]; - for (int i = 0; i < copyBuffer.length; i++) { - copyBuffer[i] = items[0].getText(i); - } - } - }); - - //Paste - item = new MenuItem(popUpMenu, DWT.PUSH); - item.setText(resAddressBook.getString("Pop_up_paste")); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - if (copyBuffer is null) return; - TableItem item = new TableItem(table, DWT.NONE); - item.setText(copyBuffer); - isModified = true; - } - }); - - //Delete - item = new MenuItem(popUpMenu, DWT.PUSH); - item.setText(resAddressBook.getString("Pop_up_delete")); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - TableItem[] items = table.getSelection(); - if (items.length is 0) return; - items[0].dispose(); - isModified = true; - } - }); - - new MenuItem(popUpMenu, DWT.SEPARATOR); - - //Find... - item = new MenuItem(popUpMenu, DWT.PUSH); - item.setText(resAddressBook.getString("Pop_up_find")); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - searchDialog.open(); - } - }); - - return popUpMenu; -} - -/** - * Creates all the items located in the Help submenu and - * associate all the menu items with their appropriate - * functions. - * - * @param menuBar Menu - * the Menu that file contain - * the Help submenu. - */ -private void createHelpMenu(Menu menuBar) { - - //Help Menu - MenuItem item = new MenuItem(menuBar, DWT.CASCADE); - item.setText(resAddressBook.getString("Help_menu_title")); - Menu menu = new Menu(shell, DWT.DROP_DOWN); - item.setMenu(menu); - - //Help -> About Text Editor - MenuItem subItem = new MenuItem(menu, DWT.NONE); - subItem.setText(resAddressBook.getString("About")); - subItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - MessageBox box = new MessageBox(shell, DWT.NONE); - box.setText(resAddressBook.getString("About_1") ~ shell.getText()); - box.setMessage(shell.getText() ~ resAddressBook.getString("About_2")); - box.open(); - } - }); -} - - -/** - * To compare entries (rows) by the given column - */ -private class RowComparator /*: Comparator*/ { - private int column; - - /** - * Constructs a RowComparator given the column index - * @param col The index (starting at zero) of the column - */ - public this(int col) { - column = col; - } - - /** - * Compares two rows (type char[][]) using the specified - * column entry. - * @param obj1 First row to compare - * @param obj2 Second row to compare - * @return negative if obj1 less than obj2, positive if - * obj1 greater than obj2, and zero if equal. - */ - public bool compare(char[][] row1, char[][] row2) { - return row1[column] < row2[column]; - } - - alias compare opCall; -} - -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/addressbook/DataEntryDialog.d --- a/dwtexamples/addressbook/DataEntryDialog.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,177 +0,0 @@ -/******************************************************************************* - * 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 - *******************************************************************************/ -module dwtexamples.addressbook.DataEntryDialog; - -import dwt.DWT; -import dwt.events.ModifyEvent; -import dwt.events.ModifyListener; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Composite; -import dwt.widgets.Display; -import dwt.widgets.Label; -import dwt.widgets.Shell; -import dwt.widgets.Text; - -import dwt.dwthelper.ResourceBundle; -import dwt.dwthelper.utils; - -/** - * DataEntryDialog class uses org.eclipse.swt - * libraries to implement a dialog that accepts basic personal information that - * is added to a Table widget or edits a TableItem entry - * to represent the entered data. - */ -public class DataEntryDialog { - - private static ResourceBundle resAddressBook; - - Shell shell; - char[][] values; - char[][] labels; - -public this(Shell parent) { - if( resAddressBook is null ){ - resAddressBook = ResourceBundle.getBundle("examples_addressbook"); - } - shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.PRIMARY_MODAL); - shell.setLayout(new GridLayout()); -} - -private void addTextListener(Text text) { - text.addModifyListener(new class(text) ModifyListener { - Text text; - this( Text text ){ this.text = text; } - public void modifyText(ModifyEvent e){ - Integer index = cast(Integer)(this.text.getData("index")); - values[index.intValue()] = this.text.getText(); - } - }); -} -private void createControlButtons() { - Composite composite = new Composite(shell, DWT.NONE); - composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - composite.setLayout(layout); - - Button okButton = new Button(composite, DWT.PUSH); - okButton.setText(resAddressBook.getString("OK")); - okButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - shell.close(); - } - }); - - Button cancelButton = new Button(composite, DWT.PUSH); - cancelButton.setText(resAddressBook.getString("Cancel")); - cancelButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - values = null; - shell.close(); - } - }); - - shell.setDefaultButton(okButton); -} - -private void createTextWidgets() { - if (labels is null) return; - - Composite composite = new Composite(shell, DWT.NONE); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - GridLayout layout= new GridLayout(); - layout.numColumns = 2; - composite.setLayout(layout); - - if (values is null) - values = new char[][labels.length]; - - for (int i = 0; i < labels.length; i++) { - Label label = new Label(composite, DWT.RIGHT); - label.setText(labels[i]); - Text text = new Text(composite, DWT.BORDER); - GridData gridData = new GridData(); - gridData.widthHint = 400; - text.setLayoutData(gridData); - if (values[i] !is null) { - text.setText(values[i]); - } - text.setData("index", new Integer(i)); - addTextListener(text); - } -} - -public char[][] getLabels() { - return labels; -} -public char[] getTitle() { - return shell.getText(); -} -/** - * Returns the contents of the Text widgets in the dialog in a - * char[] array. - * - * @return char[][] - * The contents of the text widgets of the dialog. - * May return null if all text widgets are empty. - */ -public char[][] getValues() { - return values; -} -/** - * Opens the dialog in the given state. Sets Text widget contents - * and dialog behaviour accordingly. - * - * @param dialogState int - * The state the dialog should be opened in. - */ -public char[][] open() { - createTextWidgets(); - createControlButtons(); - shell.pack(); - shell.open(); - Display display = shell.getDisplay(); - while(!shell.isDisposed()){ - if(!display.readAndDispatch()) - display.sleep(); - } - - return getValues(); -} -public void setLabels(char[][] labels) { - this.labels = labels; -} -public void setTitle(char[] title) { - shell.setText(title); -} -/** - * Sets the values of the Text widgets of the dialog to - * the values supplied in the parameter array. - * - * @param itemInfo char[][] - * The values to which the dialog contents will be set. - */ -public void setValues(char[][] itemInfo) { - if (labels is null) return; - - if (values is null) - values = new char[][labels.length]; - - int numItems = Math.min(values.length, itemInfo.length); - for(int i = 0; i < numItems; i++) { - values[i] = itemInfo[i]; - } -} -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/addressbook/FindListener.d --- a/dwtexamples/addressbook/FindListener.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 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 - *******************************************************************************/ -module dwtexamples.addressbook.FindListener; - - -public interface FindListener { - -public bool find(); - -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/addressbook/SearchDialog.d --- a/dwtexamples/addressbook/SearchDialog.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 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 - *******************************************************************************/ -module dwtexamples.addressbook.SearchDialog; - - -import dwt.DWT; -import dwt.events.ModifyEvent; -import dwt.events.ModifyListener; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.events.ShellAdapter; -import dwt.events.ShellEvent; -import dwt.layout.FillLayout; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Combo; -import dwt.widgets.Composite; -import dwt.widgets.Group; -import dwt.widgets.Label; -import dwt.widgets.MessageBox; -import dwt.widgets.Shell; -import dwt.widgets.Text; - -import dwtexamples.addressbook.FindListener; - -import dwt.dwthelper.ResourceBundle; - -/** - * SearchDialog is a simple class that uses org.eclipse.swt - * libraries to implement a basic search dialog. - */ -public class SearchDialog { - - private static ResourceBundle resAddressBook; - - Shell shell; - Text searchText; - Combo searchArea; - Label searchAreaLabel; - Button matchCase; - Button matchWord; - Button findButton; - Button down; - FindListener findHandler; - -/** - * Class constructor that sets the parent shell and the table widget that - * the dialog will search. - * - * @param parent Shell - * The shell that is the parent of the dialog. - */ -public this(Shell parent) { - if( resAddressBook is null ){ - resAddressBook = ResourceBundle.getBundle("examples_addressbook"); - } - shell = new Shell(parent, DWT.CLOSE | DWT.BORDER | DWT.TITLE); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - shell.setLayout(layout); - shell.setText(resAddressBook.getString("Search_dialog_title")); - shell.addShellListener(new class() ShellAdapter{ - public void shellClosed(ShellEvent e) { - // don't dispose of the shell, just hide it for later use - e.doit = false; - shell.setVisible(false); - } - }); - - Label label = new Label(shell, DWT.LEFT); - label.setText(resAddressBook.getString("Dialog_find_what")); - searchText = new Text(shell, DWT.BORDER); - GridData gridData = new GridData(GridData.FILL_HORIZONTAL); - gridData.widthHint = 200; - searchText.setLayoutData(gridData); - searchText.addModifyListener(new class() ModifyListener { - public void modifyText(ModifyEvent e) { - bool enableFind = (searchText.getCharCount() !is 0); - findButton.setEnabled(enableFind); - } - }); - - searchAreaLabel = new Label(shell, DWT.LEFT); - searchArea = new Combo(shell, DWT.DROP_DOWN | DWT.READ_ONLY); - gridData = new GridData(GridData.FILL_HORIZONTAL); - gridData.widthHint = 200; - searchArea.setLayoutData(gridData); - - matchCase = new Button(shell, DWT.CHECK); - matchCase.setText(resAddressBook.getString("Dialog_match_case")); - gridData = new GridData(); - gridData.horizontalSpan = 2; - matchCase.setLayoutData(gridData); - - matchWord = new Button(shell, DWT.CHECK); - matchWord.setText(resAddressBook.getString("Dialog_match_word")); - gridData = new GridData(); - gridData.horizontalSpan = 2; - matchWord.setLayoutData(gridData); - - Group direction = new Group(shell, DWT.NONE); - gridData = new GridData(); - gridData.horizontalSpan = 2; - direction.setLayoutData(gridData); - direction.setLayout (new FillLayout ()); - direction.setText(resAddressBook.getString("Dialog_direction")); - - Button up = new Button(direction, DWT.RADIO); - up.setText(resAddressBook.getString("Dialog_dir_up")); - up.setSelection(false); - - down = new Button(direction, DWT.RADIO); - down.setText(resAddressBook.getString("Dialog_dir_down")); - down.setSelection(true); - - Composite composite = new Composite(shell, DWT.NONE); - gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - gridData.horizontalSpan = 2; - composite.setLayoutData(gridData); - layout = new GridLayout(); - layout.numColumns = 2; - layout.makeColumnsEqualWidth = true; - composite.setLayout(layout); - - findButton = new Button(composite, DWT.PUSH); - findButton.setText(resAddressBook.getString("Dialog_find")); - findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - findButton.setEnabled(false); - findButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - if (!findHandler.find()){ - MessageBox box = new MessageBox(shell, DWT.ICON_INFORMATION | DWT.OK | DWT.PRIMARY_MODAL); - box.setText(shell.getText()); - box.setMessage(resAddressBook.getString("Cannot_find") ~ "\"" ~ searchText.getText() ~ "\""); - box.open(); - } - } - }); - - Button cancelButton = new Button(composite, DWT.PUSH); - cancelButton.setText(resAddressBook.getString("Cancel")); - cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); - cancelButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - shell.setVisible(false); - } - }); - - shell.pack(); -} -public char[] getSearchAreaLabel(char[] label) { - return searchAreaLabel.getText(); -} - -public char[][] getsearchAreaNames() { - return searchArea.getItems(); -} -public bool getMatchCase() { - return matchCase.getSelection(); -} -public bool getMatchWord() { - return matchWord.getSelection(); -} -public char[] getSearchString() { - return searchText.getText(); -} -public bool getSearchDown(){ - return down.getSelection(); -} -public int getSelectedSearchArea() { - return searchArea.getSelectionIndex(); -} -public void open() { - if (shell.isVisible()) { - shell.setFocus(); - } else { - shell.open(); - } - searchText.setFocus(); -} -public void setSearchAreaNames(char[][] names) { - for (int i = 0; i < names.length; i++) { - searchArea.add(names[i]); - } - searchArea.select(0); -} -public void setSearchAreaLabel(char[] label) { - searchAreaLabel.setText(label); -} -public void setMatchCase(bool match) { - matchCase.setSelection(match); -} -public void setMatchWord(bool match) { - matchWord.setSelection(match); -} -public void setSearchDown(bool searchDown){ - down.setSelection(searchDown); -} -public void setSearchString(char[] searchString) { - searchText.setText(searchString); -} - -public void setSelectedSearchArea(int index) { - searchArea.select(index); -} -public void addFindListener(FindListener listener) { - this.findHandler = listener; -} -public void removeFindListener(FindListener listener) { - this.findHandler = null; -} -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/clipboard/ClipboardExample.d --- a/dwtexamples/clipboard/ClipboardExample.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,495 +0,0 @@ -/******************************************************************************* - * 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 gmail.com - *******************************************************************************/ -module dwtexamples.clipboard; - -import dwt.DWT; -import dwt.custom.ScrolledComposite; -import dwt.custom.StyledText; -import dwt.dnd.Clipboard; -import dwt.dnd.FileTransfer; -import dwt.dnd.HTMLTransfer; -import dwt.dnd.RTFTransfer; -import dwt.dnd.TextTransfer; -import dwt.dnd.Transfer; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.graphics.Point; -import dwt.graphics.Rectangle; -import dwt.layout.FillLayout; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Combo; -import dwt.widgets.Composite; -import dwt.widgets.DirectoryDialog; -import dwt.widgets.Display; -import dwt.widgets.FileDialog; -import dwt.widgets.Group; -import dwt.widgets.Label; -import dwt.widgets.List; -import dwt.widgets.Shell; -import dwt.widgets.Table; -import dwt.widgets.TableItem; -import dwt.widgets.Text; -import dwt.dwthelper.utils; - -import tango.io.Stdout; - -class ClipboardExample { - static const int SIZE = 60; - Clipboard clipboard; - Shell shell; - Text copyText; - Text pasteText; - Text copyRtfText; - Text pasteRtfText; - Text copyHtmlText; - Text pasteHtmlText; - Table copyFileTable; - Table pasteFileTable; - Text text; - Combo combo; - StyledText styledText; - Label status; - - public void open(Display display) { - clipboard = new Clipboard(display); - shell = new Shell (display); - shell.setText("DWT Clipboard"); - shell.setLayout(new FillLayout()); - - ScrolledComposite sc = new ScrolledComposite(shell, DWT.H_SCROLL | DWT.V_SCROLL); - Composite parent = new Composite(sc, DWT.NONE); - sc.setContent(parent); - parent.setLayout(new GridLayout(2, true)); - - Group copyGroup = new Group(parent, DWT.NONE); - copyGroup.setText("Copy From:"); - GridData data = new GridData(GridData.FILL_BOTH); - copyGroup.setLayoutData(data); - copyGroup.setLayout(new GridLayout(3, false)); - - Group pasteGroup = new Group(parent, DWT.NONE); - pasteGroup.setText("Paste To:"); - data = new GridData(GridData.FILL_BOTH); - pasteGroup.setLayoutData(data); - pasteGroup.setLayout(new GridLayout(3, false)); - - Group controlGroup = new Group(parent, DWT.NONE); - controlGroup.setText("Control API:"); - data = new GridData(GridData.FILL_BOTH); - data.horizontalSpan = 2; - controlGroup.setLayoutData(data); - controlGroup.setLayout(new GridLayout(5, false)); - - /* Enable with Available Types * - Group typesGroup = new Group(parent, DWT.NONE); - typesGroup.setText("Available Types"); - data = new GridData(GridData.FILL_BOTH); - data.horizontalSpan = 2; - typesGroup.setLayoutData(data); - typesGroup.setLayout(new GridLayout(2, false)); - /**/ - - status = new Label(parent, DWT.BORDER); - data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 2; - data.heightHint = 60; - status.setLayoutData(data); - - createTextTransfer(copyGroup, pasteGroup); - //TODO: Doesn't work -// createRTFTransfer(copyGroup, pasteGroup); - createHTMLTransfer(copyGroup, pasteGroup); - //TODO: Doesn't work -// createFileTransfer(copyGroup, pasteGroup); - createMyTransfer(copyGroup, pasteGroup); - createControlTransfer(controlGroup); - //TODO: Causes Segfault -// createAvailableTypes(typesGroup); - - sc.setMinSize(parent.computeSize(DWT.DEFAULT, DWT.DEFAULT)); - sc.setExpandHorizontal(true); - sc.setExpandVertical(true); - - Point size = shell.computeSize(DWT.DEFAULT, DWT.DEFAULT); - Rectangle monitorArea = shell.getMonitor().getClientArea(); - shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20)); - shell.open(); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - clipboard.dispose(); - } - void createTextTransfer(Composite copyParent, Composite pasteParent) { - - // TextTransfer - Label l = new Label(copyParent, DWT.NONE); - l.setText("TextTransfer:"); //$NON-NLS-1$ - copyText = new Text(copyParent, DWT.MULTI | DWT.BORDER | DWT.V_SCROLL | DWT.H_SCROLL); - copyText.setText("some\nplain\ntext"); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.heightHint = data.widthHint = SIZE; - copyText.setLayoutData(data); - Button b = new Button(copyParent, DWT.PUSH); - b.setText("Copy"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - auto data = copyText.getText(); - if (data.length > 0) { - status.setText(""); - auto obj = new Object[1]; - auto trans = new TextTransfer[1]; - obj[0] = cast(Object) new ArrayWrapperString(data); - trans[0] = TextTransfer.getInstance(); - clipboard.setContents(obj, trans); - } else { - status.setText("nothing to copy"); - } - } - }); - - l = new Label(pasteParent, DWT.NONE); - l.setText("TextTransfer:"); //$NON-NLS-1$ - pasteText = new Text(pasteParent, DWT.READ_ONLY | DWT.MULTI | DWT.BORDER | DWT.V_SCROLL | DWT.H_SCROLL); - data = new GridData(GridData.FILL_HORIZONTAL); - data.heightHint = data.widthHint = SIZE; - pasteText.setLayoutData(data); - b = new Button(pasteParent, DWT.PUSH); - b.setText("Paste"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - auto data = cast(ArrayWrapperString) clipboard.getContents(TextTransfer.getInstance()); - if (data !is null) { - status.setText(""); - pasteText.setText("begin paste>"~data.array~" 0) { - status.setText(""); - data = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i " ~ data ~ "}"; - auto obj = new Object[1]; - auto trans = new Transfer[1]; - obj[0] = cast(Object) new ArrayWrapperString(data); - trans[0] = RTFTransfer.getInstance(); - clipboard.setContents(obj, trans); - } else { - status.setText("nothing to copy"); - } - } - }); - - l = new Label(pasteParent, DWT.NONE); - l.setText("RTFTransfer:"); //$NON-NLS-1$ - pasteRtfText = new Text(pasteParent, DWT.READ_ONLY | DWT.MULTI | DWT.BORDER | DWT.V_SCROLL | DWT.H_SCROLL); - data = new GridData(GridData.FILL_HORIZONTAL); - data.heightHint = data.widthHint = SIZE; - pasteRtfText.setLayoutData(data); - b = new Button(pasteParent, DWT.PUSH); - b.setText("Paste"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - auto data = cast(ArrayWrapperString) clipboard.getContents(RTFTransfer.getInstance()); - if (data !is null) { - status.setText(""); - pasteRtfText.setText("begin paste>"~data.array~"Hello World"); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.heightHint = data.widthHint = SIZE; - copyHtmlText.setLayoutData(data); - Button b = new Button(copyParent, DWT.PUSH); - b.setText("Copy"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - auto data = copyHtmlText.getText(); - if (data.length > 0) { - status.setText(""); - auto obj = new Object[1]; - auto trans = new Transfer[1]; - obj[0] = cast(Object) new ArrayWrapperString(data); - trans[0] = HTMLTransfer.getInstance(); - clipboard.setContents(obj, trans); - } else { - status.setText("nothing to copy"); - } - } - }); - - l = new Label(pasteParent, DWT.NONE); - l.setText("HTMLTransfer:"); //$NON-NLS-1$ - pasteHtmlText = new Text(pasteParent, DWT.READ_ONLY | DWT.MULTI | DWT.BORDER | DWT.V_SCROLL | DWT.H_SCROLL); - data = new GridData(GridData.FILL_HORIZONTAL); - data.heightHint = data.widthHint = SIZE; - pasteHtmlText.setLayoutData(data); - b = new Button(pasteParent, DWT.PUSH); - b.setText("Paste"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - auto data = cast(ArrayWrapperString) clipboard.getContents(HTMLTransfer.getInstance()); - if (data !is null) { - status.setText(""); - pasteHtmlText.setText("begin paste>"~data.array~" 0){ - //copyFileTable.removeAll(); - //This cannot be used - //auto separator = System.getProperty("file.separator"); - version(linux) { - auto separator = "/"; - } - version(Windows) { - auto separator = "\\"; - } - auto path = dialog.getFilterPath(); - auto names = dialog.getFileNames(); - for (int i = 0; i < names.length; i++) { - TableItem item = new TableItem(copyFileTable, DWT.NONE); - item.setText(path~separator~names[i]); - } - } - } - }); - b = new Button(c, DWT.PUSH); - b.setText("Select directory"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - DirectoryDialog dialog = new DirectoryDialog(shell, DWT.OPEN); - auto result = dialog.open(); - if (result !is null && result.length > 0){ - //copyFileTable.removeAll(); - TableItem item = new TableItem(copyFileTable, DWT.NONE); - item.setText(result); - } - } - }); - - b = new Button(copyParent, DWT.PUSH); - b.setText("Copy"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - TableItem[] items = copyFileTable.getItems(); - if (items.length > 0){ - status.setText(""); - auto data = new char[][items.length]; - for (int i = 0; i < data.length; i++) { - data[i] = items[i].getText(); - } - auto obj = new Object[1]; - auto trans = new Transfer[1]; - obj[0] = cast(Object) new ArrayWrapperString2(data); - trans[0] = FileTransfer.getInstance(); - clipboard.setContents(obj, trans); - } else { - status.setText("nothing to copy"); - } - } - }); - - l = new Label(pasteParent, DWT.NONE); - l.setText("FileTransfer:"); //$NON-NLS-1$ - pasteFileTable = new Table(pasteParent, DWT.MULTI | DWT.BORDER); - data = new GridData(GridData.FILL_HORIZONTAL); - data.heightHint = data.widthHint = SIZE; - pasteFileTable.setLayoutData(data); - b = new Button(pasteParent, DWT.PUSH); - b.setText("Paste"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - auto data = cast(ArrayWrapperString2) clipboard.getContents(FileTransfer.getInstance()); - if (data !is null && data.array.length > 0) { - status.setText(""); - pasteFileTable.removeAll(); - foreach (s; data.array) { - TableItem item = new TableItem(pasteFileTable, DWT.NONE); - item.setText(s); - } - } else { - status.setText("nothing to paste"); - } - } - }); - } - void createMyTransfer(Composite copyParent, Composite pasteParent){ - // MyType Transfer - // TODO - } - void createControlTransfer(Composite parent){ - Label l = new Label(parent, DWT.NONE); - l.setText("Text:"); - Button b = new Button(parent, DWT.PUSH); - b.setText("Cut"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - text.cut(); - } - }); - b = new Button(parent, DWT.PUSH); - b.setText("Copy"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - text.copy(); - } - }); - b = new Button(parent, DWT.PUSH); - b.setText("Paste"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - text.paste(); - } - }); - text = new Text(parent, DWT.BORDER | DWT.MULTI | DWT.H_SCROLL | DWT.V_SCROLL); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.heightHint = data.widthHint = SIZE; - text.setLayoutData(data); - - l = new Label(parent, DWT.NONE); - l.setText("Combo:"); - b = new Button(parent, DWT.PUSH); - b.setText("Cut"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - combo.cut(); - } - }); - b = new Button(parent, DWT.PUSH); - b.setText("Copy"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - combo.copy(); - } - }); - b = new Button(parent, DWT.PUSH); - b.setText("Paste"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - combo.paste(); - } - }); - combo = new Combo(parent, DWT.NONE); - char[][] str = new char[][4]; - str[0] = "Item 1"; - str[1] = "Item 2"; - str[2] = "Item 3"; - str[3] = "A longer Item"; - combo.setItems(str); - - l = new Label(parent, DWT.NONE); - l.setText("StyledText:"); - l = new Label(parent, DWT.NONE); - l.setVisible(false); - b = new Button(parent, DWT.PUSH); - b.setText("Copy"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - styledText.copy(); - } - }); - b = new Button(parent, DWT.PUSH); - b.setText("Paste"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - styledText.paste(); - } - }); - styledText = new StyledText(parent, DWT.BORDER | DWT.MULTI | DWT.H_SCROLL | DWT.V_SCROLL); - data = new GridData(GridData.FILL_HORIZONTAL); - data.heightHint = data.widthHint = SIZE; - styledText.setLayoutData(data); - } - void createAvailableTypes(Composite parent){ - final List list = new List(parent, DWT.BORDER | DWT.H_SCROLL | DWT.V_SCROLL); - GridData data = new GridData(GridData.FILL_BOTH); - data.heightHint = 100; - list.setLayoutData(data); - Button b = new Button(parent, DWT.PUSH); - b.setText("Get Available Types"); - b.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - list.removeAll(); - auto names = clipboard.getAvailableTypeNames(); - for (int i = 0; i < names.length; i++) { - list.add(names[i]); - } - } - }); - } -} -void main() { - Stdout.formatln( "The ClipboardExample: still work left" ); - Stdout.formatln( "todo: RTF, File Transfer, Available types"); - Stdout.formatln( "line 300, there might be a better way to do" ); - Stdout.formatln( "system independent path seperators in tango" ); - Stdout.formatln( "" ); - - - Display display = new Display(); - (new ClipboardExample()).open(display); - display.dispose(); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/AlignableTab.d --- a/dwtexamples/controlexample/AlignableTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.AlignableTab; - - - -import dwt.DWT; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.events.SelectionListener; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -/** - * AlignableTab is the abstract - * superclass of example controls that can be - * aligned. - */ -abstract class AlignableTab : Tab { - - /* Alignment Controls */ - Button leftButton, rightButton, centerButton; - - /* Alignment Group */ - Group alignmentGroup; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Other" group. - */ - void createOtherGroup () { - super.createOtherGroup (); - - /* Create the group */ - alignmentGroup = new Group (otherGroup, DWT.NONE); - alignmentGroup.setLayout (new GridLayout ()); - alignmentGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | - GridData.VERTICAL_ALIGN_FILL)); - alignmentGroup.setText (ControlExample.getResourceString("Alignment")); - - /* Create the controls */ - leftButton = new Button (alignmentGroup, DWT.RADIO); - leftButton.setText (ControlExample.getResourceString("Left")); - centerButton = new Button (alignmentGroup, DWT.RADIO); - centerButton.setText(ControlExample.getResourceString("Center")); - rightButton = new Button (alignmentGroup, DWT.RADIO); - rightButton.setText (ControlExample.getResourceString("Right")); - - /* Add the listeners */ - SelectionListener selectionListener = new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - if (!(cast(Button) event.widget).getSelection ()) return; - setExampleWidgetAlignment (); - } - }; - leftButton.addSelectionListener (selectionListener); - centerButton.addSelectionListener (selectionListener); - rightButton.addSelectionListener (selectionListener); - } - - /** - * Sets the alignment of the "Example" widgets. - */ - abstract void setExampleWidgetAlignment (); - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - Widget [] widgets = getExampleWidgets (); - if (widgets.length !is 0) { - leftButton.setSelection ((widgets [0].getStyle () & DWT.LEFT) !is 0); - centerButton.setSelection ((widgets [0].getStyle () & DWT.CENTER) !is 0); - rightButton.setSelection ((widgets [0].getStyle () & DWT.RIGHT) !is 0); - } - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/ButtonTab.d --- a/dwtexamples/controlexample/ButtonTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,244 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.ButtonTab; - - - -import dwt.DWT; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.events.SelectionListener; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.AlignableTab; -import dwtexamples.controlexample.ControlExample; - -/** - * ButtonTab is the class that - * demonstrates DWT buttons. - */ -class ButtonTab : AlignableTab { - - /* Example widgets and groups that contain them */ - Button button1, button2, button3, button4, button5, button6, button7, button8, button9; - Group textButtonGroup, imageButtonGroup, imagetextButtonGroup; - - /* Alignment widgets added to the "Control" group */ - Button upButton, downButton; - - /* Style widgets added to the "Style" group */ - Button pushButton, checkButton, radioButton, toggleButton, arrowButton, flatButton; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Control" group. - */ - void createControlGroup () { - super.createControlGroup (); - - /* Create the controls */ - upButton = new Button (alignmentGroup, DWT.RADIO); - upButton.setText (ControlExample.getResourceString("Up")); - downButton = new Button (alignmentGroup, DWT.RADIO); - downButton.setText (ControlExample.getResourceString("Down")); - - /* Add the listeners */ - SelectionListener selectionListener = new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - if (!(cast(Button) event.widget).getSelection()) return; - setExampleWidgetAlignment (); - } - }; - upButton.addSelectionListener(selectionListener); - downButton.addSelectionListener(selectionListener); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for text buttons */ - textButtonGroup = new Group(exampleGroup, DWT.NONE); - GridLayout gridLayout = new GridLayout (); - textButtonGroup.setLayout(gridLayout); - gridLayout.numColumns = 3; - textButtonGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - textButtonGroup.setText (ControlExample.getResourceString("Text_Buttons")); - - /* Create a group for the image buttons */ - imageButtonGroup = new Group(exampleGroup, DWT.NONE); - gridLayout = new GridLayout(); - imageButtonGroup.setLayout(gridLayout); - gridLayout.numColumns = 3; - imageButtonGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - imageButtonGroup.setText (ControlExample.getResourceString("Image_Buttons")); - - /* Create a group for the image and text buttons */ - imagetextButtonGroup = new Group(exampleGroup, DWT.NONE); - gridLayout = new GridLayout(); - imagetextButtonGroup.setLayout(gridLayout); - gridLayout.numColumns = 3; - imagetextButtonGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - imagetextButtonGroup.setText (ControlExample.getResourceString("Image_Text_Buttons")); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (pushButton.getSelection()) style |= DWT.PUSH; - if (checkButton.getSelection()) style |= DWT.CHECK; - if (radioButton.getSelection()) style |= DWT.RADIO; - if (toggleButton.getSelection()) style |= DWT.TOGGLE; - if (flatButton.getSelection()) style |= DWT.FLAT; - if (borderButton.getSelection()) style |= DWT.BORDER; - if (leftButton.getSelection()) style |= DWT.LEFT; - if (rightButton.getSelection()) style |= DWT.RIGHT; - if (arrowButton.getSelection()) { - style |= DWT.ARROW; - if (upButton.getSelection()) style |= DWT.UP; - if (downButton.getSelection()) style |= DWT.DOWN; - } else { - if (centerButton.getSelection()) style |= DWT.CENTER; - } - - /* Create the example widgets */ - button1 = new Button(textButtonGroup, style); - button1.setText(ControlExample.getResourceString("One")); - button2 = new Button(textButtonGroup, style); - button2.setText(ControlExample.getResourceString("Two")); - button3 = new Button(textButtonGroup, style); - button3.setText(ControlExample.getResourceString("Three")); - button4 = new Button(imageButtonGroup, style); - button4.setImage(instance.images[ControlExample.ciClosedFolder]); - button5 = new Button(imageButtonGroup, style); - button5.setImage(instance.images[ControlExample.ciOpenFolder]); - button6 = new Button(imageButtonGroup, style); - button6.setImage(instance.images[ControlExample.ciTarget]); - button7 = new Button(imagetextButtonGroup, style); - button7.setText(ControlExample.getResourceString("One")); - button7.setImage(instance.images[ControlExample.ciClosedFolder]); - button8 = new Button(imagetextButtonGroup, style); - button8.setText(ControlExample.getResourceString("Two")); - button8.setImage(instance.images[ControlExample.ciOpenFolder]); - button9 = new Button(imagetextButtonGroup, style); - button9.setText(ControlExample.getResourceString("Three")); - button9.setImage(instance.images[ControlExample.ciTarget]); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup (); - - /* Create the extra widgets */ - pushButton = new Button (styleGroup, DWT.RADIO); - pushButton.setText("DWT.PUSH"); - checkButton = new Button (styleGroup, DWT.RADIO); - checkButton.setText ("DWT.CHECK"); - radioButton = new Button (styleGroup, DWT.RADIO); - radioButton.setText ("DWT.RADIO"); - toggleButton = new Button (styleGroup, DWT.RADIO); - toggleButton.setText ("DWT.TOGGLE"); - arrowButton = new Button (styleGroup, DWT.RADIO); - arrowButton.setText ("DWT.ARROW"); - flatButton = new Button (styleGroup, DWT.CHECK); - flatButton.setText ("DWT.FLAT"); - borderButton = new Button (styleGroup, DWT.CHECK); - borderButton.setText ("DWT.BORDER"); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) button1, button2, button3, button4, button5, button6, button7, button8, button9 ]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return [ cast(char[])"Selection", "Text", "ToolTipText" ]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Button"; - } - - /** - * Sets the alignment of the "Example" widgets. - */ - void setExampleWidgetAlignment () { - int alignment = 0; - if (leftButton.getSelection ()) alignment = DWT.LEFT; - if (centerButton.getSelection ()) alignment = DWT.CENTER; - if (rightButton.getSelection ()) alignment = DWT.RIGHT; - if (upButton.getSelection ()) alignment = DWT.UP; - if (downButton.getSelection ()) alignment = DWT.DOWN; - button1.setAlignment (alignment); - button2.setAlignment (alignment); - button3.setAlignment (alignment); - button4.setAlignment (alignment); - button5.setAlignment (alignment); - button6.setAlignment (alignment); - button7.setAlignment (alignment); - button8.setAlignment (alignment); - button9.setAlignment (alignment); - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - if (arrowButton.getSelection ()) { - upButton.setEnabled (true); - centerButton.setEnabled (false); - downButton.setEnabled (true); - } else { - upButton.setEnabled (false); - centerButton.setEnabled (true); - downButton.setEnabled (false); - } - upButton.setSelection ((button1.getStyle () & DWT.UP) !is 0); - downButton.setSelection ((button1.getStyle () & DWT.DOWN) !is 0); - pushButton.setSelection ((button1.getStyle () & DWT.PUSH) !is 0); - checkButton.setSelection ((button1.getStyle () & DWT.CHECK) !is 0); - radioButton.setSelection ((button1.getStyle () & DWT.RADIO) !is 0); - toggleButton.setSelection ((button1.getStyle () & DWT.TOGGLE) !is 0); - arrowButton.setSelection ((button1.getStyle () & DWT.ARROW) !is 0); - flatButton.setSelection ((button1.getStyle () & DWT.FLAT) !is 0); - borderButton.setSelection ((button1.getStyle () & DWT.BORDER) !is 0); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/CComboTab.d --- a/dwtexamples/controlexample/CComboTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.CComboTab; - - - -import dwt.DWT; -import dwt.custom.CCombo; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -class CComboTab : Tab { - - /* Example widgets and groups that contain them */ - CCombo combo1; - Group comboGroup; - - /* Style widgets added to the "Style" group */ - Button flatButton, readOnlyButton; - - static char[] [] ListData; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - if( ListData is null ){ - ListData = [ - ControlExample.getResourceString("ListData1_0"), - ControlExample.getResourceString("ListData1_1"), - ControlExample.getResourceString("ListData1_2"), - ControlExample.getResourceString("ListData1_3"), - ControlExample.getResourceString("ListData1_4"), - ControlExample.getResourceString("ListData1_5"), - ControlExample.getResourceString("ListData1_6"), - ControlExample.getResourceString("ListData1_7"), - ControlExample.getResourceString("ListData1_8")]; - } - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the combo box */ - comboGroup = new Group (exampleGroup, DWT.NONE); - comboGroup.setLayout (new GridLayout ()); - comboGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - comboGroup.setText (ControlExample.getResourceString("Custom_Combo")); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (flatButton.getSelection ()) style |= DWT.FLAT; - if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY; - if (borderButton.getSelection ()) style |= DWT.BORDER; - - /* Create the example widgets */ - combo1 = new CCombo (comboGroup, style); - combo1.setItems (ListData); - if (ListData.length >= 3) { - combo1.setText(ListData [2]); - } - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup () { - super.createStyleGroup (); - - /* Create the extra widgets */ - readOnlyButton = new Button (styleGroup, DWT.CHECK); - readOnlyButton.setText ("DWT.READ_ONLY"); - borderButton = new Button (styleGroup, DWT.CHECK); - borderButton.setText ("DWT.BORDER"); - flatButton = new Button (styleGroup, DWT.CHECK); - flatButton.setText ("DWT.FLAT"); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [cast(Widget) combo1]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Editable", "Items", "Selection", "Text", "TextLimit", "ToolTipText", "VisibleItemCount"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "CCombo"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - flatButton.setSelection ((combo1.getStyle () & DWT.FLAT) !is 0); - readOnlyButton.setSelection ((combo1.getStyle () & DWT.READ_ONLY) !is 0); - borderButton.setSelection ((combo1.getStyle () & DWT.BORDER) !is 0); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/CLabelTab.d --- a/dwtexamples/controlexample/CLabelTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.CLabelTab; - - - -import dwt.DWT; -import dwt.custom.CLabel; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.Widget; - - -import dwtexamples.controlexample.AlignableTab; -import dwtexamples.controlexample.ControlExample; - -import tango.text.convert.Format; - -class CLabelTab : AlignableTab { - /* Example widgets and groups that contain them */ - CLabel label1, label2, label3; - Group textLabelGroup; - - /* Style widgets added to the "Style" group */ - Button shadowInButton, shadowOutButton, shadowNoneButton; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the text labels */ - textLabelGroup = new Group(exampleGroup, DWT.NONE); - GridLayout gridLayout = new GridLayout (); - textLabelGroup.setLayout (gridLayout); - gridLayout.numColumns = 3; - textLabelGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - textLabelGroup.setText (ControlExample.getResourceString("Custom_Labels")); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (shadowInButton.getSelection ()) style |= DWT.SHADOW_IN; - if (shadowNoneButton.getSelection ()) style |= DWT.SHADOW_NONE; - if (shadowOutButton.getSelection ()) style |= DWT.SHADOW_OUT; - if (leftButton.getSelection ()) style |= DWT.LEFT; - if (centerButton.getSelection ()) style |= DWT.CENTER; - if (rightButton.getSelection ()) style |= DWT.RIGHT; - - /* Create the example widgets */ - label1 = new CLabel (textLabelGroup, style); - label1.setText(ControlExample.getResourceString("One")); - label1.setImage (instance.images[ControlExample.ciClosedFolder]); - label2 = new CLabel (textLabelGroup, style); - label2.setImage (instance.images[ControlExample.ciTarget]); - label3 = new CLabel (textLabelGroup, style); - label3.setText(Format( "{}\n{}", ControlExample.getResourceString("Example_string"), ControlExample.getResourceString("One_Two_Three"))); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup (); - - /* Create the extra widgets */ - shadowNoneButton = new Button (styleGroup, DWT.RADIO); - shadowNoneButton.setText ("DWT.SHADOW_NONE"); - shadowInButton = new Button (styleGroup, DWT.RADIO); - shadowInButton.setText ("DWT.SHADOW_IN"); - shadowOutButton = new Button (styleGroup, DWT.RADIO); - shadowOutButton.setText ("DWT.SHADOW_OUT"); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) label1, label2, label3]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Text", "ToolTipText"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "CLabel"; - } - - /** - * Sets the alignment of the "Example" widgets. - */ - void setExampleWidgetAlignment () { - int alignment = 0; - if (leftButton.getSelection ()) alignment = DWT.LEFT; - if (centerButton.getSelection ()) alignment = DWT.CENTER; - if (rightButton.getSelection ()) alignment = DWT.RIGHT; - label1.setAlignment (alignment); - label2.setAlignment (alignment); - label3.setAlignment (alignment); - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - leftButton.setSelection ((label1.getStyle () & DWT.LEFT) !is 0); - centerButton.setSelection ((label1.getStyle () & DWT.CENTER) !is 0); - rightButton.setSelection ((label1.getStyle () & DWT.RIGHT) !is 0); - shadowInButton.setSelection ((label1.getStyle () & DWT.SHADOW_IN) !is 0); - shadowOutButton.setSelection ((label1.getStyle () & DWT.SHADOW_OUT) !is 0); - shadowNoneButton.setSelection ((label1.getStyle () & (DWT.SHADOW_IN | DWT.SHADOW_OUT)) is 0); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/CTabFolderTab.d --- a/dwtexamples/controlexample/CTabFolderTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,478 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.CTabFolderTab; - - - -import dwt.DWT; -import dwt.custom.CTabFolder; -import dwt.custom.CTabFolder2Adapter; -import dwt.custom.CTabFolderEvent; -import dwt.custom.CTabItem; -import dwt.events.DisposeEvent; -import dwt.events.DisposeListener; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.graphics.Color; -import dwt.graphics.Font; -import dwt.graphics.FontData; -import dwt.graphics.Image; -import dwt.graphics.RGB; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Event; -import dwt.widgets.Group; -import dwt.widgets.Item; -import dwt.widgets.Listener; -import dwt.widgets.TableItem; -import dwt.widgets.Text; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -import tango.text.convert.Format; - -class CTabFolderTab : Tab { - int lastSelectedTab = 0; - - /* Example widgets and groups that contain them */ - CTabFolder tabFolder1; - Group tabFolderGroup, itemGroup; - - /* Style widgets added to the "Style" group */ - Button topButton, bottomButton, flatButton, closeButton; - - static char[] [] CTabItems1; - - /* Controls and resources added to the "Fonts" group */ - static const int SELECTION_FOREGROUND_COLOR = 3; - static const int SELECTION_BACKGROUND_COLOR = 4; - static const int ITEM_FONT = 5; - Color selectionForegroundColor, selectionBackgroundColor; - Font itemFont; - - /* Other widgets added to the "Other" group */ - Button simpleTabButton, singleTabButton, imageButton, showMinButton, showMaxButton, unselectedCloseButton, unselectedImageButton; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - if( CTabItems1 is null ){ - CTabItems1 = [ - ControlExample.getResourceString("CTabItem1_0"), - ControlExample.getResourceString("CTabItem1_1"), - ControlExample.getResourceString("CTabItem1_2")]; - } - } - - /** - * Creates the "Colors and Fonts" group. - */ - void createColorAndFontGroup () { - super.createColorAndFontGroup(); - - TableItem item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Selection_Foreground_Color")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Selection_Background_Color")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Item_Font")); - - shell.addDisposeListener(new class() DisposeListener { - public void widgetDisposed(DisposeEvent event) { - if (selectionBackgroundColor !is null) selectionBackgroundColor.dispose(); - if (selectionForegroundColor !is null) selectionForegroundColor.dispose(); - if (itemFont !is null) itemFont.dispose(); - selectionBackgroundColor = null; - selectionForegroundColor = null; - itemFont = null; - } - }); - } - - void changeFontOrColor(int index) { - switch (index) { - case SELECTION_FOREGROUND_COLOR: { - Color oldColor = selectionForegroundColor; - if (oldColor is null) oldColor = tabFolder1.getSelectionForeground(); - colorDialog.setRGB(oldColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = selectionForegroundColor; - selectionForegroundColor = new Color (display, rgb); - setSelectionForeground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case SELECTION_BACKGROUND_COLOR: { - Color oldColor = selectionBackgroundColor; - if (oldColor is null) oldColor = tabFolder1.getSelectionBackground(); - colorDialog.setRGB(oldColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = selectionBackgroundColor; - selectionBackgroundColor = new Color (display, rgb); - setSelectionBackground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case ITEM_FONT: { - Font oldFont = itemFont; - if (oldFont is null) oldFont = tabFolder1.getItem (0).getFont (); - fontDialog.setFontList(oldFont.getFontData()); - FontData fontData = fontDialog.open (); - if (fontData is null) return; - oldFont = itemFont; - itemFont = new Font (display, fontData); - setItemFont (); - setExampleWidgetSize (); - if (oldFont !is null) oldFont.dispose (); - } - break; - default: - super.changeFontOrColor(index); - } - } - - /** - * Creates the "Other" group. - */ - void createOtherGroup () { - super.createOtherGroup (); - - /* Create display controls specific to this example */ - simpleTabButton = new Button (otherGroup, DWT.CHECK); - simpleTabButton.setText (ControlExample.getResourceString("Set_Simple_Tabs")); - simpleTabButton.setSelection(true); - simpleTabButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setSimpleTabs(); - } - }); - - singleTabButton = new Button (otherGroup, DWT.CHECK); - singleTabButton.setText (ControlExample.getResourceString("Set_Single_Tabs")); - singleTabButton.setSelection(false); - singleTabButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setSingleTabs(); - } - }); - - showMinButton = new Button (otherGroup, DWT.CHECK); - showMinButton.setText (ControlExample.getResourceString("Set_Min_Visible")); - showMinButton.setSelection(false); - showMinButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setMinimizeVisible(); - } - }); - - showMaxButton = new Button (otherGroup, DWT.CHECK); - showMaxButton.setText (ControlExample.getResourceString("Set_Max_Visible")); - showMaxButton.setSelection(false); - showMaxButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setMaximizeVisible(); - } - }); - - imageButton = new Button (otherGroup, DWT.CHECK); - imageButton.setText (ControlExample.getResourceString("Set_Image")); - imageButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setImages(); - } - }); - - unselectedImageButton = new Button (otherGroup, DWT.CHECK); - unselectedImageButton.setText (ControlExample.getResourceString("Set_Unselected_Image_Visible")); - unselectedImageButton.setSelection(true); - unselectedImageButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setUnselectedImageVisible(); - } - }); - unselectedCloseButton = new Button (otherGroup, DWT.CHECK); - unselectedCloseButton.setText (ControlExample.getResourceString("Set_Unselected_Close_Visible")); - unselectedCloseButton.setSelection(true); - unselectedCloseButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setUnselectedCloseVisible(); - } - }); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the CTabFolder */ - tabFolderGroup = new Group (exampleGroup, DWT.NONE); - tabFolderGroup.setLayout (new GridLayout ()); - tabFolderGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - tabFolderGroup.setText ("CTabFolder"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (topButton.getSelection ()) style |= DWT.TOP; - if (bottomButton.getSelection ()) style |= DWT.BOTTOM; - if (borderButton.getSelection ()) style |= DWT.BORDER; - if (flatButton.getSelection ()) style |= DWT.FLAT; - if (closeButton.getSelection ()) style |= DWT.CLOSE; - - /* Create the example widgets */ - tabFolder1 = new CTabFolder (tabFolderGroup, style); - for (int i = 0; i < CTabItems1.length; i++) { - CTabItem item = new CTabItem(tabFolder1, DWT.NONE); - item.setText(CTabItems1[i]); - Text text = new Text(tabFolder1, DWT.READ_ONLY); - text.setText(Format( "{}: {}", ControlExample.getResourceString("CTabItem_content"), i)); - item.setControl(text); - } - tabFolder1.addListener(DWT.Selection, new class() Listener { - public void handleEvent(Event event) { - lastSelectedTab = tabFolder1.getSelectionIndex(); - } - }); - tabFolder1.setSelection(lastSelectedTab); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup (); - - /* Create the extra widgets */ - topButton = new Button (styleGroup, DWT.RADIO); - topButton.setText ("DWT.TOP"); - topButton.setSelection(true); - bottomButton = new Button (styleGroup, DWT.RADIO); - bottomButton.setText ("DWT.BOTTOM"); - borderButton = new Button (styleGroup, DWT.CHECK); - borderButton.setText ("DWT.BORDER"); - flatButton = new Button (styleGroup, DWT.CHECK); - flatButton.setText ("DWT.FLAT"); - closeButton = new Button (styleGroup, DWT.CHECK); - closeButton.setText ("DWT.CLOSE"); - } - - /** - * Gets the list of custom event names. - * - * @return an array containing custom event names - */ - char[] [] getCustomEventNames () { - return ["CTabFolderEvent"]; - } - - /** - * Gets the "Example" widget children's items, if any. - * - * @return an array containing the example widget children's items - */ - Item [] getExampleWidgetItems () { - return tabFolder1.getItems(); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) tabFolder1]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "CTabFolder"; - } - - /** - * Hooks the custom listener specified by eventName. - */ - void hookCustomListener (char[] eventName) { - if (eventName is "CTabFolderEvent") { - tabFolder1.addCTabFolder2Listener (new class(eventName) CTabFolder2Adapter { - char[] name; - this( char[] name ){ this.name = name; } - public void close (CTabFolderEvent event) { - log (name, event); - } - }); - } - } - - /** - * Sets the foreground color, background color, and font - * of the "Example" widgets to their default settings. - * Also sets foreground and background color of the Node 1 - * TreeItems to default settings. - */ - void resetColorsAndFonts () { - super.resetColorsAndFonts (); - Color oldColor = selectionForegroundColor; - selectionForegroundColor = null; - setSelectionForeground (); - if (oldColor !is null) oldColor.dispose(); - oldColor = selectionBackgroundColor; - selectionBackgroundColor = null; - setSelectionBackground (); - if (oldColor !is null) oldColor.dispose(); - Font oldFont = itemFont; - itemFont = null; - setItemFont (); - if (oldFont !is null) oldFont.dispose(); - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState(); - setSimpleTabs(); - setSingleTabs(); - setImages(); - setMinimizeVisible(); - setMaximizeVisible(); - setUnselectedCloseVisible(); - setUnselectedImageVisible(); - setSelectionBackground (); - setSelectionForeground (); - setItemFont (); - setExampleWidgetSize(); - } - - /** - * Sets the shape that the CTabFolder will use to render itself. - */ - void setSimpleTabs () { - tabFolder1.setSimple (simpleTabButton.getSelection ()); - setExampleWidgetSize(); - } - - /** - * Sets the number of tabs that the CTabFolder should display. - */ - void setSingleTabs () { - tabFolder1.setSingle (singleTabButton.getSelection ()); - setExampleWidgetSize(); - } - /** - * Sets an image into each item of the "Example" widgets. - */ - void setImages () { - bool setImage = imageButton.getSelection (); - CTabItem items[] = tabFolder1.getItems (); - for (int i = 0; i < items.length; i++) { - if (setImage) { - items[i].setImage (instance.images[ControlExample.ciClosedFolder]); - } else { - items[i].setImage (null); - } - } - setExampleWidgetSize (); - } - /** - * Sets the visibility of the minimize button - */ - void setMinimizeVisible () { - tabFolder1.setMinimizeVisible(showMinButton.getSelection ()); - setExampleWidgetSize(); - } - /** - * Sets the visibility of the maximize button - */ - void setMaximizeVisible () { - tabFolder1.setMaximizeVisible(showMaxButton.getSelection ()); - setExampleWidgetSize(); - } - /** - * Sets the visibility of the close button on unselected tabs - */ - void setUnselectedCloseVisible () { - tabFolder1.setUnselectedCloseVisible(unselectedCloseButton.getSelection ()); - setExampleWidgetSize(); - } - /** - * Sets the visibility of the image on unselected tabs - */ - void setUnselectedImageVisible () { - tabFolder1.setUnselectedImageVisible(unselectedImageButton.getSelection ()); - setExampleWidgetSize(); - } - /** - * Sets the background color of CTabItem 0. - */ - void setSelectionBackground () { - if (!instance.startup) { - tabFolder1.setSelectionBackground(selectionBackgroundColor); - } - // Set the selection background item's image to match the background color of the selection. - Color color = selectionBackgroundColor; - if (color is null) color = tabFolder1.getSelectionBackground (); - TableItem item = colorAndFontTable.getItem(SELECTION_BACKGROUND_COLOR); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (colorImage(color)); - } - - /** - * Sets the foreground color of CTabItem 0. - */ - void setSelectionForeground () { - if (!instance.startup) { - tabFolder1.setSelectionForeground(selectionForegroundColor); - } - // Set the selection foreground item's image to match the foreground color of the selection. - Color color = selectionForegroundColor; - if (color is null) color = tabFolder1.getSelectionForeground (); - TableItem item = colorAndFontTable.getItem(SELECTION_FOREGROUND_COLOR); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (colorImage(color)); - } - - /** - * Sets the font of CTabItem 0. - */ - void setItemFont () { - if (!instance.startup) { - tabFolder1.getItem (0).setFont (itemFont); - setExampleWidgetSize(); - } - /* Set the font item's image to match the font of the item. */ - Font ft = itemFont; - if (ft is null) ft = tabFolder1.getItem (0).getFont (); - TableItem item = colorAndFontTable.getItem(ITEM_FONT); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (fontImage(ft)); - item.setFont(ft); - colorAndFontTable.layout (); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/CanvasTab.d --- a/dwtexamples/controlexample/CanvasTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,335 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.CanvasTab; - - - -import dwt.DWT; -import dwt.events.ControlAdapter; -import dwt.events.ControlEvent; -import dwt.events.PaintEvent; -import dwt.events.PaintListener; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.graphics.Color; -import dwt.graphics.Font; -import dwt.graphics.GC; -import dwt.graphics.Point; -import dwt.graphics.Rectangle; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Canvas; -import dwt.widgets.Caret; -import dwt.widgets.Composite; -import dwt.widgets.Group; -import dwt.widgets.ScrollBar; -import dwt.widgets.TabFolder; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -class CanvasTab : Tab { - static const int colors [] = [ - DWT.COLOR_RED, - DWT.COLOR_GREEN, - DWT.COLOR_BLUE, - DWT.COLOR_MAGENTA, - DWT.COLOR_YELLOW, - DWT.COLOR_CYAN, - DWT.COLOR_DARK_RED, - DWT.COLOR_DARK_GREEN, - DWT.COLOR_DARK_BLUE, - DWT.COLOR_DARK_MAGENTA, - DWT.COLOR_DARK_YELLOW, - DWT.COLOR_DARK_CYAN - ]; - static final char[] canvasString = "Canvas"; //$NON-NLS-1$ - - /* Example widgets and groups that contain them */ - Canvas canvas; - Group canvasGroup; - - /* Style widgets added to the "Style" group */ - Button horizontalButton, verticalButton, noBackgroundButton, noFocusButton, - noMergePaintsButton, noRedrawResizeButton, doubleBufferedButton; - - /* Other widgets added to the "Other" group */ - Button caretButton, fillDamageButton; - - int paintCount; - int cx, cy; - int maxX, maxY; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Other" group. - */ - void createOtherGroup () { - super.createOtherGroup (); - - /* Create display controls specific to this example */ - caretButton = new Button (otherGroup, DWT.CHECK); - caretButton.setText (ControlExample.getResourceString("Caret")); - fillDamageButton = new Button (otherGroup, DWT.CHECK); - fillDamageButton.setText (ControlExample.getResourceString("FillDamage")); - - /* Add the listeners */ - caretButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setCaret (); - } - }); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the canvas widget */ - canvasGroup = new Group (exampleGroup, DWT.NONE); - canvasGroup.setLayout (new GridLayout ()); - canvasGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - canvasGroup.setText ("Canvas"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; - if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; - if (borderButton.getSelection ()) style |= DWT.BORDER; - if (noBackgroundButton.getSelection ()) style |= DWT.NO_BACKGROUND; - if (noFocusButton.getSelection ()) style |= DWT.NO_FOCUS; - if (noMergePaintsButton.getSelection ()) style |= DWT.NO_MERGE_PAINTS; - if (noRedrawResizeButton.getSelection ()) style |= DWT.NO_REDRAW_RESIZE; - if (doubleBufferedButton.getSelection ()) style |= DWT.DOUBLE_BUFFERED; - - /* Create the example widgets */ - paintCount = 0; cx = 0; cy = 0; - canvas = new Canvas (canvasGroup, style); - canvas.addPaintListener(new class() PaintListener { - public void paintControl(PaintEvent e) { - paintCount++; - GC gc = e.gc; - if (fillDamageButton.getSelection ()) { - Color color = e.display.getSystemColor (colors [paintCount % colors.length]); - gc.setBackground(color); - gc.fillRectangle(e.x, e.y, e.width, e.height); - } - Point size = canvas.getSize (); - gc.drawArc(cx + 1, cy + 1, size.x - 2, size.y - 2, 0, 360); - gc.drawRectangle(cx + (size.x - 10) / 2, cy + (size.y - 10) / 2, 10, 10); - Point extent = gc.textExtent(canvasString); - gc.drawString(canvasString, cx + (size.x - extent.x) / 2, cy - extent.y + (size.y - 10) / 2, true); - } - }); - canvas.addControlListener(new class() ControlAdapter { - public void controlResized(ControlEvent event) { - Point size = canvas.getSize (); - maxX = size.x * 3 / 2; maxY = size.y * 3 / 2; - resizeScrollBars (); - } - }); - ScrollBar bar = canvas.getHorizontalBar(); - if (bar !is null) { - hookListeners (bar); - bar.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - scrollHorizontal (cast(ScrollBar)event.widget); - } - }); - } - bar = canvas.getVerticalBar(); - if (bar !is null) { - hookListeners (bar); - bar.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - scrollVertical (cast(ScrollBar)event.widget); - } - }); - } - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup(); - - /* Create the extra widgets */ - horizontalButton = new Button (styleGroup, DWT.CHECK); - horizontalButton.setText ("DWT.H_SCROLL"); - horizontalButton.setSelection(true); - verticalButton = new Button (styleGroup, DWT.CHECK); - verticalButton.setText ("DWT.V_SCROLL"); - verticalButton.setSelection(true); - borderButton = new Button (styleGroup, DWT.CHECK); - borderButton.setText ("DWT.BORDER"); - noBackgroundButton = new Button (styleGroup, DWT.CHECK); - noBackgroundButton.setText ("DWT.NO_BACKGROUND"); - noFocusButton = new Button (styleGroup, DWT.CHECK); - noFocusButton.setText ("DWT.NO_FOCUS"); - noMergePaintsButton = new Button (styleGroup, DWT.CHECK); - noMergePaintsButton.setText ("DWT.NO_MERGE_PAINTS"); - noRedrawResizeButton = new Button (styleGroup, DWT.CHECK); - noRedrawResizeButton.setText ("DWT.NO_REDRAW_RESIZE"); - doubleBufferedButton = new Button (styleGroup, DWT.CHECK); - doubleBufferedButton.setText ("DWT.DOUBLE_BUFFERED"); - } - - /** - * Creates the tab folder page. - * - * @param tabFolder org.eclipse.swt.widgets.TabFolder - * @return the new page for the tab folder - */ - Composite createTabFolderPage (TabFolder tabFolder) { - super.createTabFolderPage (tabFolder); - - /* - * Add a resize listener to the tabFolderPage so that - * if the user types into the example widget to change - * its preferred size, and then resizes the shell, we - * recalculate the preferred size correctly. - */ - tabFolderPage.addControlListener(new class() ControlAdapter { - public void controlResized(ControlEvent e) { - setExampleWidgetSize (); - } - }); - - return tabFolderPage; - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) canvas ]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["ToolTipText"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Canvas"; - } - - /** - * Resizes the maximum and thumb of both scrollbars. - */ - void resizeScrollBars () { - Rectangle clientArea = canvas.getClientArea(); - ScrollBar bar = canvas.getHorizontalBar(); - if (bar !is null) { - bar.setMaximum(maxX); - bar.setThumb(clientArea.width); - bar.setPageIncrement(clientArea.width); - } - bar = canvas.getVerticalBar(); - if (bar !is null) { - bar.setMaximum(maxY); - bar.setThumb(clientArea.height); - bar.setPageIncrement(clientArea.height); - } - } - - /** - * Scrolls the canvas horizontally. - * - * @param scrollBar - */ - void scrollHorizontal (ScrollBar scrollBar) { - Rectangle bounds = canvas.getClientArea(); - int x = -scrollBar.getSelection(); - if (x + maxX < bounds.width) { - x = bounds.width - maxX; - } - canvas.scroll(x, cy, cx, cy, maxX, maxY, false); - cx = x; - } - - /** - * Scrolls the canvas vertically. - * - * @param scrollBar - */ - void scrollVertical (ScrollBar scrollBar) { - Rectangle bounds = canvas.getClientArea(); - int y = -scrollBar.getSelection(); - if (y + maxY < bounds.height) { - y = bounds.height - maxY; - } - canvas.scroll(cx, y, cx, cy, maxX, maxY, false); - cy = y; - } - - /** - * Sets or clears the caret in the "Example" widget. - */ - void setCaret () { - Caret oldCaret = canvas.getCaret (); - if (caretButton.getSelection ()) { - Caret newCaret = new Caret(canvas, DWT.NONE); - Font font = canvas.getFont(); - newCaret.setFont(font); - GC gc = new GC(canvas); - gc.setFont(font); - newCaret.setBounds(1, 1, 1, gc.getFontMetrics().getHeight()); - gc.dispose(); - canvas.setCaret (newCaret); - canvas.setFocus(); - } else { - canvas.setCaret (null); - } - if (oldCaret !is null) oldCaret.dispose (); - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - horizontalButton.setSelection ((canvas.getStyle () & DWT.H_SCROLL) !is 0); - verticalButton.setSelection ((canvas.getStyle () & DWT.V_SCROLL) !is 0); - borderButton.setSelection ((canvas.getStyle () & DWT.BORDER) !is 0); - noBackgroundButton.setSelection ((canvas.getStyle () & DWT.NO_BACKGROUND) !is 0); - noFocusButton.setSelection ((canvas.getStyle () & DWT.NO_FOCUS) !is 0); - noMergePaintsButton.setSelection ((canvas.getStyle () & DWT.NO_MERGE_PAINTS) !is 0); - noRedrawResizeButton.setSelection ((canvas.getStyle () & DWT.NO_REDRAW_RESIZE) !is 0); - doubleBufferedButton.setSelection ((canvas.getStyle () & DWT.DOUBLE_BUFFERED) !is 0); - if (!instance.startup) setCaret (); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/ComboTab.d --- a/dwtexamples/controlexample/ComboTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.ComboTab; - - - -import dwt.DWT; -import dwt.events.ControlAdapter; -import dwt.events.ControlEvent; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Combo; -import dwt.widgets.Composite; -import dwt.widgets.Group; -import dwt.widgets.TabFolder; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -class ComboTab : Tab { - - /* Example widgets and groups that contain them */ - Combo combo1; - Group comboGroup; - - /* Style widgets added to the "Style" group */ - Button dropDownButton, readOnlyButton, simpleButton; - - static char[] [] ListData; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - if( ListData.length is 0 ){ - ListData = [ControlExample.getResourceString("ListData0_0"), - ControlExample.getResourceString("ListData0_1"), - ControlExample.getResourceString("ListData0_2"), - ControlExample.getResourceString("ListData0_3"), - ControlExample.getResourceString("ListData0_4"), - ControlExample.getResourceString("ListData0_5"), - ControlExample.getResourceString("ListData0_6"), - ControlExample.getResourceString("ListData0_7"), - ControlExample.getResourceString("ListData0_8")]; - } - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the combo box */ - comboGroup = new Group (exampleGroup, DWT.NONE); - comboGroup.setLayout (new GridLayout ()); - comboGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - comboGroup.setText ("Combo"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (dropDownButton.getSelection ()) style |= DWT.DROP_DOWN; - if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY; - if (simpleButton.getSelection ()) style |= DWT.SIMPLE; - - /* Create the example widgets */ - combo1 = new Combo (comboGroup, style); - combo1.setItems (ListData); - if (ListData.length >= 3) { - combo1.setText(ListData [2]); - } - } - - /** - * Creates the tab folder page. - * - * @param tabFolder org.eclipse.swt.widgets.TabFolder - * @return the new page for the tab folder - */ - Composite createTabFolderPage (TabFolder tabFolder) { - super.createTabFolderPage (tabFolder); - - /* - * Add a resize listener to the tabFolderPage so that - * if the user types into the example widget to change - * its preferred size, and then resizes the shell, we - * recalculate the preferred size correctly. - */ - tabFolderPage.addControlListener(new class() ControlAdapter { - public void controlResized(ControlEvent e) { - setExampleWidgetSize (); - } - }); - - return tabFolderPage; - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup () { - super.createStyleGroup (); - - /* Create the extra widgets */ - dropDownButton = new Button (styleGroup, DWT.RADIO); - dropDownButton.setText ("DWT.DROP_DOWN"); - simpleButton = new Button (styleGroup, DWT.RADIO); - simpleButton.setText("DWT.SIMPLE"); - readOnlyButton = new Button (styleGroup, DWT.CHECK); - readOnlyButton.setText ("DWT.READ_ONLY"); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) combo1]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Items", "Orientation", "Selection", "Text", "TextLimit", "ToolTipText", "VisibleItemCount"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Combo"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - dropDownButton.setSelection ((combo1.getStyle () & DWT.DROP_DOWN) !is 0); - simpleButton.setSelection ((combo1.getStyle () & DWT.SIMPLE) !is 0); - readOnlyButton.setSelection ((combo1.getStyle () & DWT.READ_ONLY) !is 0); - readOnlyButton.setEnabled(!simpleButton.getSelection()); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/ControlExample.d --- a/dwtexamples/controlexample/ControlExample.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,345 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.ControlExample; - -import dwt.DWT; -import dwt.graphics.Image; -import dwt.graphics.ImageData; -import dwt.graphics.Point; -import dwt.graphics.Rectangle; -import dwt.layout.FillLayout; -import dwt.widgets.Composite; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.TabFolder; -import dwt.widgets.TabItem; -import dwt.dwthelper.ResourceBundle; -import dwt.dwthelper.ByteArrayInputStream; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ButtonTab; -import dwtexamples.controlexample.CanvasTab; -import dwtexamples.controlexample.ComboTab; -import dwtexamples.controlexample.CoolBarTab; -import dwtexamples.controlexample.DateTimeTab; -import dwtexamples.controlexample.DialogTab; -import dwtexamples.controlexample.ExpandBarTab; -import dwtexamples.controlexample.GroupTab; -import dwtexamples.controlexample.LabelTab; -import dwtexamples.controlexample.LinkTab; -import dwtexamples.controlexample.ListTab; -import dwtexamples.controlexample.MenuTab; -import dwtexamples.controlexample.ProgressBarTab; -import dwtexamples.controlexample.SashTab; -import dwtexamples.controlexample.ScaleTab; -import dwtexamples.controlexample.ShellTab; -import dwtexamples.controlexample.SliderTab; -import dwtexamples.controlexample.SpinnerTab; -import dwtexamples.controlexample.TabFolderTab; -import dwtexamples.controlexample.TableTab; -import dwtexamples.controlexample.TextTab; -import dwtexamples.controlexample.ToolBarTab; -import dwtexamples.controlexample.ToolTipTab; -import dwtexamples.controlexample.TreeTab; - - -import tango.core.Exception; -import tango.text.convert.Format; -import tango.io.Stdout; -import Math = tango.math.Math; -import dwt.dwthelper.utils; - -version(JIVE){ - import jive.stacktrace; -} - -interface IControlExampleFactory{ - ControlExample create(Shell shell, char[] title); -} - -void main(){ - Display display = new Display(); - Shell shell = new Shell(display, DWT.SHELL_TRIM); - shell.setLayout(new FillLayout()); - - IControlExampleFactory ifactory; - char[] key; - if( auto factory = ClassInfo.find( "dwtexamples.controlexample.CustomControlExample.CustomControlExampleFactory" )){ - ifactory = cast(IControlExampleFactory) factory.create; - key = "custom.window.title"; - } - else{ - ifactory = new ControlExampleFactory(); - key = "window.title"; - } - auto instance = ifactory.create( shell, key ); - ControlExample.setShellSize(instance, shell); - shell.open(); - while (! shell.isDisposed()) { - if (! display.readAndDispatch()) display.sleep(); - } - instance.dispose(); - display.dispose(); -} - -public class ControlExampleFactory : IControlExampleFactory { - ControlExample create(Shell shell, char[] title){ - Stdout.formatln( "The ControlExample: still work left" ); - Stdout.formatln( "todo: Implement Get/Set API reflection" ); - Stdout.formatln( "" ); - version(Windows){ - Stdout.formatln( "On Win2K:" ); - Stdout.formatln( "note: Buttons text+image do show only the image" ); - Stdout.formatln( " in java it behaves the same" ); - Stdout.formatln( " it is not supported on all plattforms" ); - Stdout.formatln( "" ); - } - version(linux){ - Stdout.formatln( "todo: ExpandBarTab looks strange" ); - Stdout.formatln( "On linux GTK:" ); - Stdout.formatln( "todo: DateTimeTab not implemented" ); - Stdout.formatln( "bug: ProgressBarTab crash on vertical" ); - Stdout.formatln( " in java it behaves the same" ); - Stdout.formatln( "bug: SliderTab horizontal arrow buttons are too high." ); - Stdout.formatln( " in java it behaves the same" ); - Stdout.formatln( " Known bug:" ); - Stdout.formatln( " https://bugs.eclipse.org/bugs/show_bug.cgi?id=197402" ); - Stdout.formatln( " http://bugzilla.gnome.org/show_bug.cgi?id=475909" ); - Stdout.formatln( "" ); - } - Stdout.formatln( "please report problems" ); - auto res = new ControlExample( shell ); - shell.setText(ControlExample.getResourceString("window.title")); - return res; - } -} - -public class ControlExample { - private static ResourceBundle resourceBundle; - private static const char[] resourceData = import( "dwtexamples.controlexample.controlexample.properties" ); - - private ShellTab shellTab; - private TabFolder tabFolder; - private Tab [] tabs; - Image images[]; - - static const int ciClosedFolder = 0, ciOpenFolder = 1, ciTarget = 2, ciBackground = 3, ciParentBackground = 4; - - static const byte[][] imageData = [ - cast(byte[]) import( "dwtexamples.controlexample.closedFolder.gif" ), - cast(byte[]) import( "dwtexamples.controlexample.openFolder.gif" ), - cast(byte[]) import( "dwtexamples.controlexample.target.gif" ), - cast(byte[]) import( "dwtexamples.controlexample.backgroundImage.png" ), - cast(byte[]) import( "dwtexamples.controlexample.parentBackgroundImage.png" ) - ]; - static const int[] imageTypes = [ - DWT.ICON, - DWT.ICON, - DWT.ICON, - DWT.BITMAP, - DWT.BITMAP]; - - bool startup = true; - - static this(){ - resourceBundle = ResourceBundle.getBundleFromData( resourceData ); //$NON-NLS-1$ - } - - /** - * Creates an instance of a ControlExample embedded inside - * the supplied parent Composite. - * - * @param parent the container of the example - */ - public this(Composite parent) { - initResources(); - tabFolder = new TabFolder (parent, DWT.NONE); - tabs = createTabs(); - for (int i=0; i monitorArea.width && DWT.getPlatform()=="carbon") { - TabItem [] tabItems = instance.tabFolder.getItems(); - for (int i=0; i - *******************************************************************************/ -module dwtexamples.controlexample.CoolBarTab; - - - -import dwt.DWT; -import dwt.events.MenuAdapter; -import dwt.events.MenuEvent; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.graphics.Image; -import dwt.graphics.Point; -import dwt.graphics.Rectangle; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Control; -import dwt.widgets.CoolBar; -import dwt.widgets.CoolItem; -import dwt.widgets.Event; -import dwt.widgets.Group; -import dwt.widgets.Item; -import dwt.widgets.Listener; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.Text; -import dwt.widgets.ToolBar; -import dwt.widgets.ToolItem; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import tango.util.Convert; - -class CoolBarTab : Tab { - /* Example widgets and group that contains them */ - CoolBar coolBar; - CoolItem pushItem, dropDownItem, radioItem, checkItem, textItem; - Group coolBarGroup; - - /* Style widgets added to the "Style" group */ - Button horizontalButton, verticalButton; - Button dropDownButton, flatButton; - - /* Other widgets added to the "Other" group */ - Button lockedButton; - - Point[] sizes; - int[] wrapIndices; - int[] order; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Other" group. - */ - void createOtherGroup () { - super.createOtherGroup (); - - /* Create display controls specific to this example */ - lockedButton = new Button (otherGroup, DWT.CHECK); - lockedButton.setText (ControlExample.getResourceString("Locked")); - - /* Add the listeners */ - lockedButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetLocked (); - } - }); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - coolBarGroup = new Group (exampleGroup, DWT.NONE); - coolBarGroup.setLayout (new GridLayout ()); - coolBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - coolBarGroup.setText ("CoolBar"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - int style = getDefaultStyle(), itemStyle = 0; - - /* Compute the widget, item, and item toolBar styles */ - int toolBarStyle = DWT.FLAT; - bool vertical = false; - if (horizontalButton.getSelection ()) { - style |= DWT.HORIZONTAL; - toolBarStyle |= DWT.HORIZONTAL; - } - if (verticalButton.getSelection ()) { - style |= DWT.VERTICAL; - toolBarStyle |= DWT.VERTICAL; - vertical = true; - } - if (borderButton.getSelection()) style |= DWT.BORDER; - if (flatButton.getSelection()) style |= DWT.FLAT; - if (dropDownButton.getSelection()) itemStyle |= DWT.DROP_DOWN; - - /* - * Create the example widgets. - */ - coolBar = new CoolBar (coolBarGroup, style); - - /* Create the push button toolbar cool item */ - ToolBar toolBar = new ToolBar (coolBar, toolBarStyle); - ToolItem item = new ToolItem (toolBar, DWT.PUSH); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setToolTipText ("DWT.PUSH"); - item = new ToolItem (toolBar, DWT.PUSH); - item.setImage (instance.images[ControlExample.ciOpenFolder]); - item.setToolTipText ("DWT.PUSH"); - item = new ToolItem (toolBar, DWT.PUSH); - item.setImage (instance.images[ControlExample.ciTarget]); - item.setToolTipText ("DWT.PUSH"); - item = new ToolItem (toolBar, DWT.SEPARATOR); - item = new ToolItem (toolBar, DWT.PUSH); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setToolTipText ("DWT.PUSH"); - item = new ToolItem (toolBar, DWT.PUSH); - item.setImage (instance.images[ControlExample.ciOpenFolder]); - item.setToolTipText ("DWT.PUSH"); - pushItem = new CoolItem (coolBar, itemStyle); - pushItem.setControl (toolBar); - pushItem.addSelectionListener (new CoolItemSelectionListener()); - - /* Create the dropdown toolbar cool item */ - toolBar = new ToolBar (coolBar, toolBarStyle); - item = new ToolItem (toolBar, DWT.DROP_DOWN); - item.setImage (instance.images[ControlExample.ciOpenFolder]); - item.setToolTipText ("DWT.DROP_DOWN"); - item.addSelectionListener (new DropDownSelectionListener()); - item = new ToolItem (toolBar, DWT.DROP_DOWN); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setToolTipText ("DWT.DROP_DOWN"); - item.addSelectionListener (new DropDownSelectionListener()); - dropDownItem = new CoolItem (coolBar, itemStyle); - dropDownItem.setControl (toolBar); - dropDownItem.addSelectionListener (new CoolItemSelectionListener()); - - /* Create the radio button toolbar cool item */ - toolBar = new ToolBar (coolBar, toolBarStyle); - item = new ToolItem (toolBar, DWT.RADIO); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setToolTipText ("DWT.RADIO"); - item = new ToolItem (toolBar, DWT.RADIO); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setToolTipText ("DWT.RADIO"); - item = new ToolItem (toolBar, DWT.RADIO); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setToolTipText ("DWT.RADIO"); - radioItem = new CoolItem (coolBar, itemStyle); - radioItem.setControl (toolBar); - radioItem.addSelectionListener (new CoolItemSelectionListener()); - - /* Create the check button toolbar cool item */ - toolBar = new ToolBar (coolBar, toolBarStyle); - item = new ToolItem (toolBar, DWT.CHECK); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setToolTipText ("DWT.CHECK"); - item = new ToolItem (toolBar, DWT.CHECK); - item.setImage (instance.images[ControlExample.ciTarget]); - item.setToolTipText ("DWT.CHECK"); - item = new ToolItem (toolBar, DWT.CHECK); - item.setImage (instance.images[ControlExample.ciOpenFolder]); - item.setToolTipText ("DWT.CHECK"); - item = new ToolItem (toolBar, DWT.CHECK); - item.setImage (instance.images[ControlExample.ciTarget]); - item.setToolTipText ("DWT.CHECK"); - checkItem = new CoolItem (coolBar, itemStyle); - checkItem.setControl (toolBar); - checkItem.addSelectionListener (new CoolItemSelectionListener()); - - /* Create the text cool item */ - if (!vertical) { - Text text = new Text (coolBar, DWT.BORDER | DWT.SINGLE); - textItem = new CoolItem (coolBar, itemStyle); - textItem.setControl (text); - textItem.addSelectionListener (new CoolItemSelectionListener()); - Point textSize = text.computeSize(DWT.DEFAULT, DWT.DEFAULT); - textSize = textItem.computeSize(textSize.x, textSize.y); - textItem.setMinimumSize(textSize); - textItem.setPreferredSize(textSize); - textItem.setSize(textSize); - } - - /* Set the sizes after adding all cool items */ - CoolItem[] coolItems = coolBar.getItems(); - for (int i = 0; i < coolItems.length; i++) { - CoolItem coolItem = coolItems[i]; - Control control = coolItem.getControl(); - Point size = control.computeSize(DWT.DEFAULT, DWT.DEFAULT); - Point coolSize = coolItem.computeSize(size.x, size.y); - if ( auto bar = cast(ToolBar)control ) { - if (bar.getItemCount() > 0) { - if (vertical) { - size.y = bar.getItem(0).getBounds().height; - } else { - size.x = bar.getItem(0).getWidth(); - } - } - } - coolItem.setMinimumSize(size); - coolItem.setPreferredSize(coolSize); - coolItem.setSize(coolSize); - } - - /* If we have saved state, restore it */ - if (order !is null && order.length is coolBar.getItemCount()) { - coolBar.setItemLayout(order, wrapIndices, sizes); - } else { - coolBar.setWrapIndices([1, 3]); - } - - /* Add a listener to resize the group box to match the coolbar */ - coolBar.addListener(DWT.Resize, new class() Listener { - public void handleEvent(Event event) { - exampleGroup.layout(); - } - }); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup(); - - /* Create the extra widgets */ - horizontalButton = new Button (styleGroup, DWT.RADIO); - horizontalButton.setText ("DWT.HORIZONTAL"); - verticalButton = new Button (styleGroup, DWT.RADIO); - verticalButton.setText ("DWT.VERTICAL"); - borderButton = new Button (styleGroup, DWT.CHECK); - borderButton.setText ("DWT.BORDER"); - flatButton = new Button (styleGroup, DWT.CHECK); - flatButton.setText ("DWT.FLAT"); - Group itemGroup = new Group(styleGroup, DWT.NONE); - itemGroup.setLayout (new GridLayout ()); - itemGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); - itemGroup.setText(ControlExample.getResourceString("Item_Styles")); - dropDownButton = new Button (itemGroup, DWT.CHECK); - dropDownButton.setText ("DWT.DROP_DOWN"); - } - - /** - * Disposes the "Example" widgets. - */ - void disposeExampleWidgets () { - /* store the state of the toolbar if applicable */ - if (coolBar !is null) { - sizes = coolBar.getItemSizes(); - wrapIndices = coolBar.getWrapIndices(); - order = coolBar.getItemOrder(); - } - super.disposeExampleWidgets(); - } - - /** - * Gets the "Example" widget children's items, if any. - * - * @return an array containing the example widget children's items - */ - Item [] getExampleWidgetItems () { - return coolBar.getItems(); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) coolBar]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["ToolTipText"]; - } - - /** - * Gets the short text for the tab folder item. - */ - public char[] getShortTabText() { - return "CB"; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "CoolBar"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - horizontalButton.setSelection ((coolBar.getStyle () & DWT.HORIZONTAL) !is 0); - verticalButton.setSelection ((coolBar.getStyle () & DWT.VERTICAL) !is 0); - borderButton.setSelection ((coolBar.getStyle () & DWT.BORDER) !is 0); - flatButton.setSelection ((coolBar.getStyle () & DWT.FLAT) !is 0); - dropDownButton.setSelection ((coolBar.getItem(0).getStyle () & DWT.DROP_DOWN) !is 0); - lockedButton.setSelection(coolBar.getLocked()); - if (!instance.startup) setWidgetLocked (); - } - - /** - * Sets the header visible state of the "Example" widgets. - */ - void setWidgetLocked () { - coolBar.setLocked (lockedButton.getSelection ()); - } - - /** - * Listens to widgetSelected() events on DWT.DROP_DOWN type ToolItems - * and opens/closes a menu when appropriate. - */ - class DropDownSelectionListener : SelectionAdapter { - private Menu menu = null; - private bool visible = false; - - public void widgetSelected(SelectionEvent event) { - // Create the menu if it has not already been created - if (menu is null) { - // Lazy create the menu. - menu = new Menu(shell); - menu.addMenuListener(new class() MenuAdapter { - public void menuHidden(MenuEvent e) { - visible = false; - } - }); - for (int i = 0; i < 9; ++i) { - final char[] text = ControlExample.getResourceString("DropDownData_" ~ to!(char[])(i)); - if (text.length !is 0) { - MenuItem menuItem = new MenuItem(menu, DWT.NONE); - menuItem.setText(text); - /* - * Add a menu selection listener so that the menu is hidden - * when the user selects an item from the drop down menu. - */ - menuItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - setMenuVisible(false); - } - }); - } else { - new MenuItem(menu, DWT.SEPARATOR); - } - } - } - - /** - * A selection event will be fired when a drop down tool - * item is selected in the main area and in the drop - * down arrow. Examine the event detail to determine - * where the widget was selected. - */ - if (event.detail is DWT.ARROW) { - /* - * The drop down arrow was selected. - */ - if (visible) { - // Hide the menu to give the Arrow the appearance of being a toggle button. - setMenuVisible(false); - } else { - // Position the menu below and vertically aligned with the the drop down tool button. - ToolItem toolItem = cast(ToolItem) event.widget; - ToolBar toolBar = toolItem.getParent(); - - Rectangle toolItemBounds = toolItem.getBounds(); - Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); - menu.setLocation(point.x, point.y + toolItemBounds.height); - setMenuVisible(true); - } - } else { - /* - * Main area of drop down tool item selected. - * An application would invoke the code to perform the action for the tool item. - */ - } - } - private void setMenuVisible(bool visible) { - menu.setVisible(visible); - this.visible = visible; - } - } - - /** - * Listens to widgetSelected() events on DWT.DROP_DOWN type CoolItems - * and opens/closes a menu when appropriate. - */ - class CoolItemSelectionListener : SelectionAdapter { - private Menu menu = null; - - public void widgetSelected(SelectionEvent event) { - /** - * A selection event will be fired when the cool item - * is selected by its gripper or if the drop down arrow - * (or 'chevron') is selected. Examine the event detail - * to determine where the widget was selected. - */ - if (event.detail is DWT.ARROW) { - /* If the popup menu is already up (i.e. user pressed arrow twice), - * then dispose it. - */ - if (menu !is null) { - menu.dispose(); - menu = null; - return; - } - - /* Get the cool item and convert its bounds to display coordinates. */ - CoolItem coolItem = cast(CoolItem) event.widget; - Rectangle itemBounds = coolItem.getBounds (); - itemBounds.width = event.x - itemBounds.x; - Point pt = coolBar.toDisplay(new Point (itemBounds.x, itemBounds.y)); - itemBounds.x = pt.x; - itemBounds.y = pt.y; - - /* Get the toolbar from the cool item. */ - ToolBar toolBar = cast(ToolBar) coolItem.getControl (); - ToolItem[] tools = toolBar.getItems (); - int toolCount = tools.length; - - /* Convert the bounds of each tool item to display coordinates, - * and determine which ones are past the bounds of the cool item. - */ - int i = 0; - while (i < toolCount) { - Rectangle toolBounds = tools[i].getBounds (); - pt = toolBar.toDisplay(new Point(toolBounds.x, toolBounds.y)); - toolBounds.x = pt.x; - toolBounds.y = pt.y; - Rectangle intersection = itemBounds.intersection (toolBounds); - if (intersection!=toolBounds) break; - i++; - } - - /* Create a pop-up menu with items for each of the hidden buttons. */ - menu = new Menu (coolBar); - for (int j = i; j < toolCount; j++) { - ToolItem tool = tools[j]; - Image image = tool.getImage(); - if (image is null) { - new MenuItem (menu, DWT.SEPARATOR); - } else { - if ((tool.getStyle() & DWT.DROP_DOWN) !is 0) { - MenuItem menuItem = new MenuItem (menu, DWT.CASCADE); - menuItem.setImage(image); - char[] text = tool.getToolTipText(); - if (text !is null) menuItem.setText(text); - Menu m = new Menu(menu); - menuItem.setMenu(m); - for (int k = 0; k < 9; ++k) { - text = ControlExample.getResourceString("DropDownData_" ~ to!(char[])(k)); - if (text.length !is 0) { - MenuItem mi = new MenuItem(m, DWT.NONE); - mi.setText(text); - /* Application code to perform the action for the submenu item would go here. */ - } else { - new MenuItem(m, DWT.SEPARATOR); - } - } - } else { - MenuItem menuItem = new MenuItem (menu, DWT.NONE); - menuItem.setImage(image); - char[] text = tool.getToolTipText(); - if (text !is null) menuItem.setText(text); - } - /* Application code to perform the action for the menu item would go here. */ - } - } - - /* Display the pop-up menu at the lower left corner of the arrow button. - * Dispose the menu when the user is done with it. - */ - pt = coolBar.toDisplay(new Point(event.x, event.y)); - menu.setLocation (pt.x, pt.y); - menu.setVisible (true); - while (menu !is null && !menu.isDisposed() && menu.isVisible ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - if (menu !is null) { - menu.dispose (); - menu = null; - } - } - } - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/CustomControlExample.d --- a/dwtexamples/controlexample/CustomControlExample.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/******************************************************************************* - * 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 - * Port to the D programming language: - * Frank Benoit - *******************************************************************************/ -module dwtexamples.controlexample.CustomControlExample; - -import dwt.layout.FillLayout; -import dwt.widgets.Composite; -import dwt.widgets.Display; -import dwt.widgets.Shell; - -import tango.io.Stdout; - -import dwtexamples.controlexample.ControlExample; -import dwtexamples.controlexample.CComboTab; -import dwtexamples.controlexample.CLabelTab; -import dwtexamples.controlexample.CTabFolderTab; -import dwtexamples.controlexample.SashFormTab; -import dwtexamples.controlexample.StyledTextTab; -import dwtexamples.controlexample.Tab; - -public class CustomControlExampleFactory : IControlExampleFactory { - CustomControlExample create(Shell shell, char[] title) { - - Stdout.formatln( "The CustomControlExample: still work left" ); - Stdout.formatln( "warning in Control:setBounds() line=695 gtk_widget_size_allocate()" ); - Stdout.formatln( "Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -5 and height 15" ); - Stdout.formatln( "for the CTabFolder widget. Params are OK. Further bugtracking needed." ); - Stdout.formatln( "please report problems" ); - - auto res = new CustomControlExample( shell ); - shell.setText(ControlExample.getResourceString("custom.window.title")); - return res; - } -} - - -public class CustomControlExample : ControlExample { - - /** - * Creates an instance of a CustomControlExample embedded - * inside the supplied parent Composite. - * - * @param parent the container of the example - */ - public this(Composite parent) { - super (parent); - } - - /** - * Answers the set of example Tabs - */ - Tab[] createTabs() { - return [ cast(Tab) - new CComboTab (this), - new CLabelTab (this), - new CTabFolderTab (this), - new SashFormTab (this), - new StyledTextTab (this) - ]; - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/DateTimeTab.d --- a/dwtexamples/controlexample/DateTimeTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.DateTimeTab; - - - -import dwt.DWT; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.DateTime; -import dwt.widgets.Group; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -class DateTimeTab : Tab { - /* Example widgets and groups that contain them */ - DateTime dateTime1; - Group dateTimeGroup; - - /* Style widgets added to the "Style" group */ - Button dateButton, timeButton, calendarButton, shortButton, mediumButton, longButton; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the list */ - dateTimeGroup = new Group (exampleGroup, DWT.NONE); - dateTimeGroup.setLayout (new GridLayout ()); - dateTimeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - dateTimeGroup.setText ("DateTime"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (dateButton.getSelection ()) style |= DWT.DATE; - if (timeButton.getSelection ()) style |= DWT.TIME; - if (calendarButton.getSelection ()) style |= DWT.CALENDAR; - if (shortButton.getSelection ()) style |= DWT.SHORT; - if (mediumButton.getSelection ()) style |= DWT.MEDIUM; - if (longButton.getSelection ()) style |= DWT.LONG; - if (borderButton.getSelection ()) style |= DWT.BORDER; - - /* Create the example widgets */ - dateTime1 = new DateTime (dateTimeGroup, style); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup (); - - /* Create the extra widgets */ - dateButton = new Button(styleGroup, DWT.RADIO); - dateButton.setText("DWT.DATE"); - timeButton = new Button(styleGroup, DWT.RADIO); - timeButton.setText("DWT.TIME"); - calendarButton = new Button(styleGroup, DWT.RADIO); - calendarButton.setText("DWT.CALENDAR"); - Group formatGroup = new Group(styleGroup, DWT.NONE); - formatGroup.setLayout(new GridLayout()); - shortButton = new Button(formatGroup, DWT.RADIO); - shortButton.setText("DWT.SHORT"); - mediumButton = new Button(formatGroup, DWT.RADIO); - mediumButton.setText("DWT.MEDIUM"); - longButton = new Button(formatGroup, DWT.RADIO); - longButton.setText("DWT.LONG"); - borderButton = new Button(styleGroup, DWT.CHECK); - borderButton.setText("DWT.BORDER"); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [dateTime1]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Day", "Hours", "Minutes", "Month", "Seconds", "Year"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "DateTime"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - dateButton.setSelection ((dateTime1.getStyle () & DWT.DATE) !is 0); - timeButton.setSelection ((dateTime1.getStyle () & DWT.TIME) !is 0); - calendarButton.setSelection ((dateTime1.getStyle () & DWT.CALENDAR) !is 0); - shortButton.setSelection ((dateTime1.getStyle () & DWT.SHORT) !is 0); - mediumButton.setSelection ((dateTime1.getStyle () & DWT.MEDIUM) !is 0); - longButton.setSelection ((dateTime1.getStyle () & DWT.LONG) !is 0); - borderButton.setSelection ((dateTime1.getStyle () & DWT.BORDER) !is 0); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/DialogTab.d --- a/dwtexamples/controlexample/DialogTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,512 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.DialogTab; - - - -import dwt.DWT; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.events.SelectionListener; -import dwt.graphics.FontData; -import dwt.graphics.RGB; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.printing.PrintDialog; -import dwt.printing.PrinterData; -import dwt.widgets.Button; -import dwt.widgets.ColorDialog; -import dwt.widgets.Combo; -import dwt.widgets.DirectoryDialog; -import dwt.widgets.FileDialog; -import dwt.widgets.FontDialog; -import dwt.widgets.Group; -import dwt.widgets.MessageBox; -import dwt.widgets.Text; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import tango.text.convert.Format; - -class DialogTab : Tab { - /* Example widgets and groups that contain them */ - Group dialogStyleGroup, resultGroup; - Text textWidget; - - /* Style widgets added to the "Style" group */ - Combo dialogCombo; - Button createButton; - Button okButton, cancelButton; - Button yesButton, noButton; - Button retryButton; - Button abortButton, ignoreButton; - Button iconErrorButton, iconInformationButton, iconQuestionButton; - Button iconWarningButton, iconWorkingButton, noIconButton; - Button primaryModalButton, applicationModalButton, systemModalButton; - Button saveButton, openButton, multiButton; - - static const char[] [] FilterExtensions = ["*.txt", "*.bat", "*.doc", "*"]; - static char[] [] FilterNames; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - if( FilterNames.length is 0 ){ - FilterNames = [ ControlExample.getResourceString("FilterName_0"), - ControlExample.getResourceString("FilterName_1"), - ControlExample.getResourceString("FilterName_2"), - ControlExample.getResourceString("FilterName_3")]; - } - } - - /** - * Handle a button style selection event. - * - * @param event the selection event - */ - void buttonStyleSelected(SelectionEvent event) { - /* - * Only certain combinations of button styles are - * supported for various dialogs. Make sure the - * control widget reflects only valid combinations. - */ - bool ok = okButton.getSelection (); - bool cancel = cancelButton.getSelection (); - bool yes = yesButton.getSelection (); - bool no = noButton.getSelection (); - bool abort = abortButton.getSelection (); - bool retry = retryButton.getSelection (); - bool ignore = ignoreButton.getSelection (); - - okButton.setEnabled (!(yes || no || retry || abort || ignore)); - cancelButton.setEnabled (!(abort || ignore || (yes !is no))); - yesButton.setEnabled (!(ok || retry || abort || ignore || (cancel && !yes && !no))); - noButton.setEnabled (!(ok || retry || abort || ignore || (cancel && !yes && !no))); - retryButton.setEnabled (!(ok || yes || no)); - abortButton.setEnabled (!(ok || cancel || yes || no)); - ignoreButton.setEnabled (!(ok || cancel || yes || no)); - - createButton.setEnabled ( - !(ok || cancel || yes || no || retry || abort || ignore) || - ok || - (ok && cancel) || - (yes && no) || - (yes && no && cancel) || - (retry && cancel) || - (abort && retry && ignore)); - - - } - - /** - * Handle the create button selection event. - * - * @param event org.eclipse.swt.events.SelectionEvent - */ - void createButtonSelected(SelectionEvent event) { - - /* Compute the appropriate dialog style */ - int style = getDefaultStyle(); - if (okButton.getEnabled () && okButton.getSelection ()) style |= DWT.OK; - if (cancelButton.getEnabled () && cancelButton.getSelection ()) style |= DWT.CANCEL; - if (yesButton.getEnabled () && yesButton.getSelection ()) style |= DWT.YES; - if (noButton.getEnabled () && noButton.getSelection ()) style |= DWT.NO; - if (retryButton.getEnabled () && retryButton.getSelection ()) style |= DWT.RETRY; - if (abortButton.getEnabled () && abortButton.getSelection ()) style |= DWT.ABORT; - if (ignoreButton.getEnabled () && ignoreButton.getSelection ()) style |= DWT.IGNORE; - if (iconErrorButton.getEnabled () && iconErrorButton.getSelection ()) style |= DWT.ICON_ERROR; - if (iconInformationButton.getEnabled () && iconInformationButton.getSelection ()) style |= DWT.ICON_INFORMATION; - if (iconQuestionButton.getEnabled () && iconQuestionButton.getSelection ()) style |= DWT.ICON_QUESTION; - if (iconWarningButton.getEnabled () && iconWarningButton.getSelection ()) style |= DWT.ICON_WARNING; - if (iconWorkingButton.getEnabled () && iconWorkingButton.getSelection ()) style |= DWT.ICON_WORKING; - if (primaryModalButton.getEnabled () && primaryModalButton.getSelection ()) style |= DWT.PRIMARY_MODAL; - if (applicationModalButton.getEnabled () && applicationModalButton.getSelection ()) style |= DWT.APPLICATION_MODAL; - if (systemModalButton.getEnabled () && systemModalButton.getSelection ()) style |= DWT.SYSTEM_MODAL; - if (saveButton.getEnabled () && saveButton.getSelection ()) style |= DWT.SAVE; - if (openButton.getEnabled () && openButton.getSelection ()) style |= DWT.OPEN; - if (multiButton.getEnabled () && multiButton.getSelection ()) style |= DWT.MULTI; - - /* Open the appropriate dialog type */ - char[] name = dialogCombo.getText (); - - if (name == ControlExample.getResourceString("ColorDialog")) { - ColorDialog dialog = new ColorDialog (shell ,style); - dialog.setRGB (new RGB (100, 100, 100)); - dialog.setText (ControlExample.getResourceString("Title")); - RGB result = dialog.open (); - textWidget.append (Format( ControlExample.getResourceString("ColorDialog")~"{}", Text.DELIMITER)); - textWidget.append (Format( ControlExample.getResourceString("Result")~"{}{}", result, Text.DELIMITER, Text.DELIMITER)); - return; - } - - if (name == ControlExample.getResourceString("DirectoryDialog")) { - DirectoryDialog dialog = new DirectoryDialog (shell, style); - dialog.setMessage (ControlExample.getResourceString("Example_string")); - dialog.setText (ControlExample.getResourceString("Title")); - char[] result = dialog.open (); - textWidget.append (ControlExample.getResourceString("DirectoryDialog") ~ Text.DELIMITER); - textWidget.append (Format( ControlExample.getResourceString("Result"), result ) ~ Text.DELIMITER ~ Text.DELIMITER); - return; - } - - if (name== ControlExample.getResourceString("FileDialog")) { - FileDialog dialog = new FileDialog (shell, style); - dialog.setFileName (ControlExample.getResourceString("readme_txt")); - dialog.setFilterNames (FilterNames); - dialog.setFilterExtensions (FilterExtensions); - dialog.setText (ControlExample.getResourceString("Title")); - char[] result = dialog.open(); - textWidget.append (ControlExample.getResourceString("FileDialog") ~ Text.DELIMITER); - textWidget.append (Format( ControlExample.getResourceString("Result"), result ) ~ Text.DELIMITER); - if ((dialog.getStyle () & DWT.MULTI) !is 0) { - char[] [] files = dialog.getFileNames (); - for (int i=0; i - *******************************************************************************/ -module dwtexamples.controlexample.ExpandBarTab; - - - -import dwt.DWT; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Composite; -import dwt.widgets.ExpandBar; -import dwt.widgets.ExpandItem; -import dwt.widgets.Group; -import dwt.widgets.Label; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -class ExpandBarTab : Tab { - /* Example widgets and groups that contain them */ - ExpandBar expandBar1; - Group expandBarGroup; - - /* Style widgets added to the "Style" group */ - Button verticalButton; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the list */ - expandBarGroup = new Group (exampleGroup, DWT.NONE); - expandBarGroup.setLayout (new GridLayout ()); - expandBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - expandBarGroup.setText ("ExpandBar"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (borderButton.getSelection ()) style |= DWT.BORDER; - if (verticalButton.getSelection()) style |= DWT.V_SCROLL; - - /* Create the example widgets */ - expandBar1 = new ExpandBar (expandBarGroup, style); - - // First item - Composite composite = new Composite (expandBar1, DWT.NONE); - composite.setLayout(new GridLayout ()); - (new Button (composite, DWT.PUSH)).setText("DWT.PUSH"); - (new Button (composite, DWT.RADIO)).setText("DWT.RADIO"); - (new Button (composite, DWT.CHECK)).setText("DWT.CHECK"); - (new Button (composite, DWT.TOGGLE)).setText("DWT.TOGGLE"); - ExpandItem item = new ExpandItem (expandBar1, DWT.NONE, 0); - item.setText(ControlExample.getResourceString("Item1_Text")); - item.setHeight(composite.computeSize(DWT.DEFAULT, DWT.DEFAULT).y); - item.setControl(composite); - item.setImage(instance.images[ControlExample.ciClosedFolder]); - - // Second item - composite = new Composite (expandBar1, DWT.NONE); - composite.setLayout(new GridLayout (2, false)); - (new Label (composite, DWT.NONE)).setImage(display.getSystemImage(DWT.ICON_ERROR)); - (new Label (composite, DWT.NONE)).setText("DWT.ICON_ERROR"); - (new Label (composite, DWT.NONE)).setImage(display.getSystemImage(DWT.ICON_INFORMATION)); - (new Label (composite, DWT.NONE)).setText("DWT.ICON_INFORMATION"); - (new Label (composite, DWT.NONE)).setImage(display.getSystemImage(DWT.ICON_WARNING)); - (new Label (composite, DWT.NONE)).setText("DWT.ICON_WARNING"); - (new Label (composite, DWT.NONE)).setImage(display.getSystemImage(DWT.ICON_QUESTION)); - (new Label (composite, DWT.NONE)).setText("DWT.ICON_QUESTION"); - item = new ExpandItem (expandBar1, DWT.NONE, 1); - item.setText(ControlExample.getResourceString("Item2_Text")); - item.setHeight(composite.computeSize(DWT.DEFAULT, DWT.DEFAULT).y); - item.setControl(composite); - item.setImage(instance.images[ControlExample.ciOpenFolder]); - item.setExpanded(true); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup (); - - /* Create the extra widgets */ - verticalButton = new Button (styleGroup, DWT.CHECK); - verticalButton.setText ("DWT.V_SCROLL"); - verticalButton.setSelection(true); - borderButton = new Button(styleGroup, DWT.CHECK); - borderButton.setText("DWT.BORDER"); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) expandBar1]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Spacing"]; - } - - /** - * Gets the short text for the tab folder item. - */ - public char[] getShortTabText() { - return "EB"; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "ExpandBar"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - Widget [] widgets = getExampleWidgets (); - if (widgets.length !is 0){ - verticalButton.setSelection ((widgets [0].getStyle () & DWT.V_SCROLL) !is 0); - borderButton.setSelection ((widgets [0].getStyle () & DWT.BORDER) !is 0); - } - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/GroupTab.d --- a/dwtexamples/controlexample/GroupTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.GroupTab; - - - -import dwt.DWT; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -class GroupTab : Tab { - Button titleButton; - - /* Example widgets and groups that contain them */ - Group group1; - Group groupGroup; - - /* Style widgets added to the "Style" group */ - Button shadowEtchedInButton, shadowEtchedOutButton, shadowInButton, shadowOutButton, shadowNoneButton; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Other" group. - */ - void createOtherGroup () { - super.createOtherGroup (); - - /* Create display controls specific to this example */ - titleButton = new Button (otherGroup, DWT.CHECK); - titleButton.setText (ControlExample.getResourceString("Title_Text")); - - /* Add the listeners */ - titleButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setTitleText (); - } - }); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the Group */ - groupGroup = new Group (exampleGroup, DWT.NONE); - groupGroup.setLayout (new GridLayout ()); - groupGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - groupGroup.setText ("Group"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (shadowEtchedInButton.getSelection ()) style |= DWT.SHADOW_ETCHED_IN; - if (shadowEtchedOutButton.getSelection ()) style |= DWT.SHADOW_ETCHED_OUT; - if (shadowInButton.getSelection ()) style |= DWT.SHADOW_IN; - if (shadowOutButton.getSelection ()) style |= DWT.SHADOW_OUT; - if (shadowNoneButton.getSelection ()) style |= DWT.SHADOW_NONE; - if (borderButton.getSelection ()) style |= DWT.BORDER; - - /* Create the example widgets */ - group1 = new Group (groupGroup, style); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup (); - - /* Create the extra widgets */ - shadowEtchedInButton = new Button (styleGroup, DWT.RADIO); - shadowEtchedInButton.setText ("DWT.SHADOW_ETCHED_IN"); - shadowEtchedInButton.setSelection(true); - shadowEtchedOutButton = new Button (styleGroup, DWT.RADIO); - shadowEtchedOutButton.setText ("DWT.SHADOW_ETCHED_OUT"); - shadowInButton = new Button (styleGroup, DWT.RADIO); - shadowInButton.setText ("DWT.SHADOW_IN"); - shadowOutButton = new Button (styleGroup, DWT.RADIO); - shadowOutButton.setText ("DWT.SHADOW_OUT"); - shadowNoneButton = new Button (styleGroup, DWT.RADIO); - shadowNoneButton.setText ("DWT.SHADOW_NONE"); - borderButton = new Button (styleGroup, DWT.CHECK); - borderButton.setText ("DWT.BORDER"); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) group1]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["ToolTipText"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Group"; - } - - /** - * Sets the title text of the "Example" widgets. - */ - void setTitleText () { - if (titleButton.getSelection ()) { - group1.setText (ControlExample.getResourceString("Title_Text")); - } else { - group1.setText (""); - } - setExampleWidgetSize (); - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - shadowEtchedInButton.setSelection ((group1.getStyle () & DWT.SHADOW_ETCHED_IN) !is 0); - shadowEtchedOutButton.setSelection ((group1.getStyle () & DWT.SHADOW_ETCHED_OUT) !is 0); - shadowInButton.setSelection ((group1.getStyle () & DWT.SHADOW_IN) !is 0); - shadowOutButton.setSelection ((group1.getStyle () & DWT.SHADOW_OUT) !is 0); - shadowNoneButton.setSelection ((group1.getStyle () & DWT.SHADOW_NONE) !is 0); - borderButton.setSelection ((group1.getStyle () & DWT.BORDER) !is 0); - if (!instance.startup) setTitleText (); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/LabelTab.d --- a/dwtexamples/controlexample/LabelTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.LabelTab; - - - -import dwt.DWT; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.Label; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import dwtexamples.controlexample.AlignableTab; - -class LabelTab : AlignableTab { - /* Example widgets and groups that contain them */ - Label label1, label2, label3, label4, label5, label6; - Group textLabelGroup, imageLabelGroup; - - /* Style widgets added to the "Style" group */ - Button wrapButton, separatorButton, horizontalButton, verticalButton, shadowInButton, shadowOutButton, shadowNoneButton; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the text labels */ - textLabelGroup = new Group(exampleGroup, DWT.NONE); - GridLayout gridLayout = new GridLayout (); - textLabelGroup.setLayout (gridLayout); - gridLayout.numColumns = 3; - textLabelGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - textLabelGroup.setText (ControlExample.getResourceString("Text_Labels")); - - /* Create a group for the image labels */ - imageLabelGroup = new Group (exampleGroup, DWT.SHADOW_NONE); - gridLayout = new GridLayout (); - imageLabelGroup.setLayout (gridLayout); - gridLayout.numColumns = 3; - imageLabelGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - imageLabelGroup.setText (ControlExample.getResourceString("Image_Labels")); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (wrapButton.getSelection ()) style |= DWT.WRAP; - if (separatorButton.getSelection ()) style |= DWT.SEPARATOR; - if (horizontalButton.getSelection ()) style |= DWT.HORIZONTAL; - if (verticalButton.getSelection ()) style |= DWT.VERTICAL; - if (shadowInButton.getSelection ()) style |= DWT.SHADOW_IN; - if (shadowOutButton.getSelection ()) style |= DWT.SHADOW_OUT; - if (shadowNoneButton.getSelection ()) style |= DWT.SHADOW_NONE; - if (borderButton.getSelection ()) style |= DWT.BORDER; - if (leftButton.getSelection ()) style |= DWT.LEFT; - if (centerButton.getSelection ()) style |= DWT.CENTER; - if (rightButton.getSelection ()) style |= DWT.RIGHT; - - /* Create the example widgets */ - label1 = new Label (textLabelGroup, style); - label1.setText(ControlExample.getResourceString("One")); - label2 = new Label (textLabelGroup, style); - label2.setText(ControlExample.getResourceString("Two")); - label3 = new Label (textLabelGroup, style); - if (wrapButton.getSelection ()) { - label3.setText (ControlExample.getResourceString("Wrap_Text")); - } else { - label3.setText (ControlExample.getResourceString("Three")); - } - label4 = new Label (imageLabelGroup, style); - label4.setImage (instance.images[ControlExample.ciClosedFolder]); - label5 = new Label (imageLabelGroup, style); - label5.setImage (instance.images[ControlExample.ciOpenFolder]); - label6 = new Label(imageLabelGroup, style); - label6.setImage (instance.images[ControlExample.ciTarget]); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup (); - - /* Create the extra widgets */ - wrapButton = new Button (styleGroup, DWT.CHECK); - wrapButton.setText ("DWT.WRAP"); - separatorButton = new Button (styleGroup, DWT.CHECK); - separatorButton.setText ("DWT.SEPARATOR"); - horizontalButton = new Button (styleGroup, DWT.RADIO); - horizontalButton.setText ("DWT.HORIZONTAL"); - verticalButton = new Button (styleGroup, DWT.RADIO); - verticalButton.setText ("DWT.VERTICAL"); - Group styleSubGroup = new Group (styleGroup, DWT.NONE); - styleSubGroup.setLayout (new GridLayout ()); - shadowInButton = new Button (styleSubGroup, DWT.RADIO); - shadowInButton.setText ("DWT.SHADOW_IN"); - shadowOutButton = new Button (styleSubGroup, DWT.RADIO); - shadowOutButton.setText ("DWT.SHADOW_OUT"); - shadowNoneButton = new Button (styleSubGroup, DWT.RADIO); - shadowNoneButton.setText ("DWT.SHADOW_NONE"); - borderButton = new Button(styleGroup, DWT.CHECK); - borderButton.setText("DWT.BORDER"); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) label1, label2, label3, label4, label5, label6 ]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Text", "ToolTipText"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Label"; - } - - /** - * Sets the alignment of the "Example" widgets. - */ - void setExampleWidgetAlignment () { - int alignment = 0; - if (leftButton.getSelection ()) alignment = DWT.LEFT; - if (centerButton.getSelection ()) alignment = DWT.CENTER; - if (rightButton.getSelection ()) alignment = DWT.RIGHT; - label1.setAlignment (alignment); - label2.setAlignment (alignment); - label3.setAlignment (alignment); - label4.setAlignment (alignment); - label5.setAlignment (alignment); - label6.setAlignment (alignment); - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - bool isSeparator = (label1.getStyle () & DWT.SEPARATOR) !is 0; - wrapButton.setSelection (!isSeparator && (label1.getStyle () & DWT.WRAP) !is 0); - leftButton.setSelection (!isSeparator && (label1.getStyle () & DWT.LEFT) !is 0); - centerButton.setSelection (!isSeparator && (label1.getStyle () & DWT.CENTER) !is 0); - rightButton.setSelection (!isSeparator && (label1.getStyle () & DWT.RIGHT) !is 0); - shadowInButton.setSelection (isSeparator && (label1.getStyle () & DWT.SHADOW_IN) !is 0); - shadowOutButton.setSelection (isSeparator && (label1.getStyle () & DWT.SHADOW_OUT) !is 0); - shadowNoneButton.setSelection (isSeparator && (label1.getStyle () & DWT.SHADOW_NONE) !is 0); - horizontalButton.setSelection (isSeparator && (label1.getStyle () & DWT.HORIZONTAL) !is 0); - verticalButton.setSelection (isSeparator && (label1.getStyle () & DWT.VERTICAL) !is 0); - wrapButton.setEnabled (!isSeparator); - leftButton.setEnabled (!isSeparator); - centerButton.setEnabled (!isSeparator); - rightButton.setEnabled (!isSeparator); - shadowInButton.setEnabled (isSeparator); - shadowOutButton.setEnabled (isSeparator); - shadowNoneButton.setEnabled (isSeparator); - horizontalButton.setEnabled (isSeparator); - verticalButton.setEnabled (isSeparator); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/LinkTab.d --- a/dwtexamples/controlexample/LinkTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.LinkTab; - - - -import dwt.DWT; -import dwt.DWTError; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.Label; -import dwt.widgets.Link; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -class LinkTab : Tab { - /* Example widgets and groups that contain them */ - Link link1; - Group linkGroup; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Example" group. - */ - override void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the list */ - linkGroup = new Group (exampleGroup, DWT.NONE); - linkGroup.setLayout (new GridLayout ()); - linkGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - linkGroup.setText ("Link"); - } - - /** - * Creates the "Example" widgets. - */ - override void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (borderButton.getSelection ()) style |= DWT.BORDER; - - /* Create the example widgets */ - try { - link1 = new Link (linkGroup, style); - link1.setText (ControlExample.getResourceString("LinkText")); - } catch (DWTError e) { - // temporary code for photon - Label label = new Label (linkGroup, DWT.CENTER | DWT.WRAP); - label.setText ("Link widget not suported"); - } - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup (); - - /* Create the extra widgets */ - borderButton = new Button(styleGroup, DWT.CHECK); - borderButton.setText("DWT.BORDER"); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { -// temporary code for photon - if (link1 !is null) return [ cast(Widget) link1 ]; - return null; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Text", "ToolTipText"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Link"; - } - -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/ListTab.d --- a/dwtexamples/controlexample/ListTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.ListTab; - - - -import dwt.DWT; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Group; -import dwt.widgets.List; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import dwtexamples.controlexample.ScrollableTab; - -class ListTab : ScrollableTab { - - /* Example widgets and groups that contain them */ - List list1; - Group listGroup; - - static char[] [] ListData1; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - if( ListData1.length is 0 ){ - ListData1 = [ - ControlExample.getResourceString("ListData1_0"), - ControlExample.getResourceString("ListData1_1"), - ControlExample.getResourceString("ListData1_2"), - ControlExample.getResourceString("ListData1_3"), - ControlExample.getResourceString("ListData1_4"), - ControlExample.getResourceString("ListData1_5"), - ControlExample.getResourceString("ListData1_6"), - ControlExample.getResourceString("ListData1_7"), - ControlExample.getResourceString("ListData1_8")]; - } - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the list */ - listGroup = new Group (exampleGroup, DWT.NONE); - listGroup.setLayout (new GridLayout ()); - listGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - listGroup.setText ("List"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (singleButton.getSelection ()) style |= DWT.SINGLE; - if (multiButton.getSelection ()) style |= DWT.MULTI; - if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; - if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; - if (borderButton.getSelection ()) style |= DWT.BORDER; - - /* Create the example widgets */ - list1 = new List (listGroup, style); - list1.setItems (ListData1); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [cast(Widget) list1]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Items", "Selection", "ToolTipText", "TopIndex" ]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "List"; - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/MenuTab.d --- a/dwtexamples/controlexample/MenuTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,329 +0,0 @@ -/******************************************************************************* - * 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 - * Port to the D programming language: - * Frank Benoit - *******************************************************************************/ -module dwtexamples.controlexample.MenuTab; - - - -import dwt.DWT; -import dwt.events.PaintEvent; -import dwt.events.PaintListener; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.Label; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.Shell; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -import dwt.dwthelper.utils; - -import tango.util.Convert; - -class MenuTab : Tab { - /* Widgets added to the "Menu Style", "MenuItem Style" and "Other" groups */ - Button barButton, dropDownButton, popUpButton, noRadioGroupButton, leftToRightButton, rightToLeftButton; - Button checkButton, cascadeButton, pushButton, radioButton, separatorButton; - Button imagesButton, acceleratorsButton, mnemonicsButton, subMenuButton, subSubMenuButton; - Button createButton, closeAllButton; - Group menuItemStyleGroup; - - /* Variables used to track the open shells */ - int shellCount = 0; - Shell [] shells; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - shells = new Shell [4]; - } - - /** - * Close all the example shells. - */ - void closeAllShells() { - for (int i = 0; i= shells.length) { - Shell [] newShells = new Shell [shells.length + 4]; - System.arraycopy (shells, 0, newShells, 0, shells.length); - shells = newShells; - } - - int orientation = 0; - if (leftToRightButton.getSelection()) orientation |= DWT.LEFT_TO_RIGHT; - if (rightToLeftButton.getSelection()) orientation |= DWT.RIGHT_TO_LEFT; - int radioBehavior = 0; - if (noRadioGroupButton.getSelection()) radioBehavior |= DWT.NO_RADIO_GROUP; - - /* Create the shell and menu(s) */ - Shell shell = new Shell (DWT.SHELL_TRIM | orientation); - shells [shellCount] = shell; - if (barButton.getSelection ()) { - /* Create menu bar. */ - Menu menuBar = new Menu(shell, DWT.BAR | radioBehavior); - shell.setMenuBar(menuBar); - hookListeners(menuBar); - - if (dropDownButton.getSelection() && cascadeButton.getSelection()) { - /* Create cascade button and drop-down menu in menu bar. */ - MenuItem item = new MenuItem(menuBar, DWT.CASCADE); - item.setText(getMenuItemText("Cascade")); - if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciOpenFolder]); - hookListeners(item); - Menu dropDownMenu = new Menu(shell, DWT.DROP_DOWN | radioBehavior); - item.setMenu(dropDownMenu); - hookListeners(dropDownMenu); - - /* Create various menu items, depending on selections. */ - createMenuItems(dropDownMenu, subMenuButton.getSelection(), subSubMenuButton.getSelection()); - } - } - - if (popUpButton.getSelection()) { - /* Create pop-up menu. */ - Menu popUpMenu = new Menu(shell, DWT.POP_UP | radioBehavior); - shell.setMenu(popUpMenu); - hookListeners(popUpMenu); - - /* Create various menu items, depending on selections. */ - createMenuItems(popUpMenu, subMenuButton.getSelection(), subSubMenuButton.getSelection()); - } - - /* Set the size, title and open the shell. */ - shell.setSize (300, 100); - shell.setText (ControlExample.getResourceString("Title") ~ to!(char[])(shellCount)); - shell.addPaintListener(new class() PaintListener { - public void paintControl(PaintEvent e) { - e.gc.drawString(ControlExample.getResourceString("PopupMenuHere"), 20, 20); - } - }); - shell.open (); - shellCount++; - } - - /** - * Creates the "Control" group. - */ - void createControlGroup () { - /* - * Create the "Control" group. This is the group on the - * right half of each example tab. For MenuTab, it consists of - * the Menu style group, the MenuItem style group and the 'other' group. - */ - controlGroup = new Group (tabFolderPage, DWT.NONE); - controlGroup.setLayout (new GridLayout (2, true)); - controlGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); - controlGroup.setText (ControlExample.getResourceString("Parameters")); - - /* Create a group for the menu style controls */ - styleGroup = new Group (controlGroup, DWT.NONE); - styleGroup.setLayout (new GridLayout ()); - styleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); - styleGroup.setText (ControlExample.getResourceString("Menu_Styles")); - - /* Create a group for the menu item style controls */ - menuItemStyleGroup = new Group (controlGroup, DWT.NONE); - menuItemStyleGroup.setLayout (new GridLayout ()); - menuItemStyleGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); - menuItemStyleGroup.setText (ControlExample.getResourceString("MenuItem_Styles")); - - /* Create a group for the 'other' controls */ - otherGroup = new Group (controlGroup, DWT.NONE); - otherGroup.setLayout (new GridLayout ()); - otherGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); - otherGroup.setText (ControlExample.getResourceString("Other")); - } - - /** - * Creates the "Control" widget children. - */ - void createControlWidgets () { - - /* Create the menu style buttons */ - barButton = new Button (styleGroup, DWT.CHECK); - barButton.setText ("DWT.BAR"); - dropDownButton = new Button (styleGroup, DWT.CHECK); - dropDownButton.setText ("DWT.DROP_DOWN"); - popUpButton = new Button (styleGroup, DWT.CHECK); - popUpButton.setText ("DWT.POP_UP"); - noRadioGroupButton = new Button (styleGroup, DWT.CHECK); - noRadioGroupButton.setText ("DWT.NO_RADIO_GROUP"); - leftToRightButton = new Button (styleGroup, DWT.RADIO); - leftToRightButton.setText ("DWT.LEFT_TO_RIGHT"); - leftToRightButton.setSelection(true); - rightToLeftButton = new Button (styleGroup, DWT.RADIO); - rightToLeftButton.setText ("DWT.RIGHT_TO_LEFT"); - - /* Create the menu item style buttons */ - cascadeButton = new Button (menuItemStyleGroup, DWT.CHECK); - cascadeButton.setText ("DWT.CASCADE"); - checkButton = new Button (menuItemStyleGroup, DWT.CHECK); - checkButton.setText ("DWT.CHECK"); - pushButton = new Button (menuItemStyleGroup, DWT.CHECK); - pushButton.setText ("DWT.PUSH"); - radioButton = new Button (menuItemStyleGroup, DWT.CHECK); - radioButton.setText ("DWT.RADIO"); - separatorButton = new Button (menuItemStyleGroup, DWT.CHECK); - separatorButton.setText ("DWT.SEPARATOR"); - - /* Create the 'other' buttons */ - imagesButton = new Button (otherGroup, DWT.CHECK); - imagesButton.setText (ControlExample.getResourceString("Images")); - acceleratorsButton = new Button (otherGroup, DWT.CHECK); - acceleratorsButton.setText (ControlExample.getResourceString("Accelerators")); - mnemonicsButton = new Button (otherGroup, DWT.CHECK); - mnemonicsButton.setText (ControlExample.getResourceString("Mnemonics")); - subMenuButton = new Button (otherGroup, DWT.CHECK); - subMenuButton.setText (ControlExample.getResourceString("SubMenu")); - subSubMenuButton = new Button (otherGroup, DWT.CHECK); - subSubMenuButton.setText (ControlExample.getResourceString("SubSubMenu")); - - /* Create the "create" and "closeAll" buttons (and a 'filler' label to place them) */ - new Label(controlGroup, DWT.NONE); - createButton = new Button (controlGroup, DWT.NONE); - createButton.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_END)); - createButton.setText (ControlExample.getResourceString("Create_Shell")); - closeAllButton = new Button (controlGroup, DWT.NONE); - closeAllButton.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING)); - closeAllButton.setText (ControlExample.getResourceString("Close_All_Shells")); - - /* Add the listeners */ - createButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - createButtonSelected(e); - } - }); - closeAllButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - closeAllShells (); - } - }); - subMenuButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - subSubMenuButton.setEnabled (subMenuButton.getSelection ()); - } - }); - - /* Set the default state */ - barButton.setSelection (true); - dropDownButton.setSelection (true); - popUpButton.setSelection (true); - cascadeButton.setSelection (true); - checkButton.setSelection (true); - pushButton.setSelection (true); - radioButton.setSelection (true); - separatorButton.setSelection (true); - subSubMenuButton.setEnabled (subMenuButton.getSelection ()); - } - - /* Create various menu items, depending on selections. */ - void createMenuItems(Menu menu, bool createSubMenu, bool createSubSubMenu) { - MenuItem item; - if (pushButton.getSelection()) { - item = new MenuItem(menu, DWT.PUSH); - item.setText(getMenuItemText("Push")); - if (acceleratorsButton.getSelection()) item.setAccelerator(DWT.MOD1 + DWT.MOD2 + 'P'); - if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciClosedFolder]); - hookListeners(item); - } - - if (separatorButton.getSelection()) { - new MenuItem(menu, DWT.SEPARATOR); - } - - if (checkButton.getSelection()) { - item = new MenuItem(menu, DWT.CHECK); - item.setText(getMenuItemText("Check")); - if (acceleratorsButton.getSelection()) item.setAccelerator(DWT.MOD1 + DWT.MOD2 + 'C'); - if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciOpenFolder]); - hookListeners(item); - } - - if (radioButton.getSelection()) { - item = new MenuItem(menu, DWT.RADIO); - item.setText(getMenuItemText("1Radio")); - if (acceleratorsButton.getSelection()) item.setAccelerator(DWT.MOD1 + DWT.MOD2 + '1'); - if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciTarget]); - item.setSelection(true); - hookListeners(item); - - item = new MenuItem(menu, DWT.RADIO); - item.setText(getMenuItemText("2Radio")); - if (acceleratorsButton.getSelection()) item.setAccelerator(DWT.MOD1 + DWT.MOD2 + '2'); - if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciTarget]); - hookListeners(item); - } - - if (createSubMenu && cascadeButton.getSelection()) { - /* Create cascade button and drop-down menu for the sub-menu. */ - item = new MenuItem(menu, DWT.CASCADE); - item.setText(getMenuItemText("Cascade")); - if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciOpenFolder]); - hookListeners(item); - Menu subMenu = new Menu(menu.getShell(), DWT.DROP_DOWN); - item.setMenu(subMenu); - hookListeners(subMenu); - - createMenuItems(subMenu, createSubSubMenu, false); - } - } - - char[] getMenuItemText(char[] item) { - bool cascade = ( item == "Cascade"); - bool mnemonic = mnemonicsButton.getSelection(); - bool accelerator = acceleratorsButton.getSelection(); - char acceleratorKey = item[0]; - if (mnemonic && accelerator && !cascade) { - return ControlExample.getResourceString(item ~ "WithMnemonic") ~ "\tCtrl+Shift+" ~ acceleratorKey; - } - if (accelerator && !cascade) { - return ControlExample.getResourceString(item) ~ "\tCtrl+Shift+" ~ acceleratorKey; - } - if (mnemonic) { - return ControlExample.getResourceString(item ~ "WithMnemonic"); - } - return ControlExample.getResourceString(item); - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Menu"; - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/ProgressBarTab.d --- a/dwtexamples/controlexample/ProgressBarTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.ProgressBarTab; - - - -import dwt.DWT; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.ProgressBar; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import dwtexamples.controlexample.RangeTab; - -class ProgressBarTab : RangeTab { - /* Example widgets and groups that contain them */ - ProgressBar progressBar1; - Group progressBarGroup; - - /* Style widgets added to the "Style" group */ - Button smoothButton; - Button indeterminateButton; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup() { - super.createExampleGroup (); - - /* Create a group for the progress bar */ - progressBarGroup = new Group (exampleGroup, DWT.NONE); - progressBarGroup.setLayout (new GridLayout ()); - progressBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - progressBarGroup.setText ("ProgressBar"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (horizontalButton.getSelection ()) style |= DWT.HORIZONTAL; - if (verticalButton.getSelection ()) style |= DWT.VERTICAL; - if (smoothButton.getSelection ()) style |= DWT.SMOOTH; - if (borderButton.getSelection ()) style |= DWT.BORDER; - if (indeterminateButton.getSelection ()) style |= DWT.INDETERMINATE; - - /* Create the example widgets */ - progressBar1 = new ProgressBar (progressBarGroup, style); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup () { - super.createStyleGroup (); - - /* Create the extra widgets */ - smoothButton = new Button (styleGroup, DWT.CHECK); - smoothButton.setText ("DWT.SMOOTH"); - indeterminateButton = new Button (styleGroup, DWT.CHECK); - indeterminateButton.setText ("DWT.INDETERMINATE"); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) progressBar1]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Selection", "ToolTipText"]; - } - - /** - * Gets the short text for the tab folder item. - */ - public char[] getShortTabText() { - return "PB"; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "ProgressBar"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - if (indeterminateButton.getSelection ()) { - selectionSpinner.setEnabled (false); - minimumSpinner.setEnabled (false); - maximumSpinner.setEnabled (false); - } else { - selectionSpinner.setEnabled (true); - minimumSpinner.setEnabled (true); - maximumSpinner.setEnabled (true); - } - smoothButton.setSelection ((progressBar1.getStyle () & DWT.SMOOTH) !is 0); - indeterminateButton.setSelection ((progressBar1.getStyle () & DWT.INDETERMINATE) !is 0); - } - - /** - * Gets the default maximum of the "Example" widgets. - */ - int getDefaultMaximum () { - return progressBar1.getMaximum(); - } - - /** - * Gets the default minimim of the "Example" widgets. - */ - int getDefaultMinimum () { - return progressBar1.getMinimum(); - } - - /** - * Gets the default selection of the "Example" widgets. - */ - int getDefaultSelection () { - return progressBar1.getSelection(); - } - - /** - * Sets the maximum of the "Example" widgets. - */ - void setWidgetMaximum () { - progressBar1.setMaximum (maximumSpinner.getSelection ()); - updateSpinners (); - } - - /** - * Sets the minimim of the "Example" widgets. - */ - void setWidgetMinimum () { - progressBar1.setMinimum (minimumSpinner.getSelection ()); - updateSpinners (); - } - - /** - * Sets the selection of the "Example" widgets. - */ - void setWidgetSelection () { - progressBar1.setSelection (selectionSpinner.getSelection ()); - updateSpinners (); - } - - /** - * Update the Spinner widgets to reflect the actual value set - * on the "Example" widget. - */ - void updateSpinners () { - minimumSpinner.setSelection (progressBar1.getMinimum ()); - selectionSpinner.setSelection (progressBar1.getSelection ()); - maximumSpinner.setSelection (progressBar1.getMaximum ()); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/RangeTab.d --- a/dwtexamples/controlexample/RangeTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.RangeTab; - - - -import dwt.DWT; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.Spinner; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -abstract class RangeTab : Tab { - /* Style widgets added to the "Style" group */ - Button horizontalButton, verticalButton; - bool orientationButtons = true; - - /* Scale widgets added to the "Control" group */ - Spinner minimumSpinner, selectionSpinner, maximumSpinner; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Control" widget children. - */ - void createControlWidgets () { - /* Create controls specific to this example */ - createMinimumGroup (); - createMaximumGroup (); - createSelectionGroup (); - } - - /** - * Create a group of widgets to control the maximum - * attribute of the example widget. - */ - void createMaximumGroup() { - - /* Create the group */ - Group maximumGroup = new Group (controlGroup, DWT.NONE); - maximumGroup.setLayout (new GridLayout ()); - maximumGroup.setText (ControlExample.getResourceString("Maximum")); - maximumGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); - - /* Create a Spinner widget */ - maximumSpinner = new Spinner (maximumGroup, DWT.BORDER); - maximumSpinner.setMaximum (100000); - maximumSpinner.setSelection (getDefaultMaximum()); - maximumSpinner.setPageIncrement (100); - maximumSpinner.setIncrement (1); - maximumSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); - - /* Add the listeners */ - maximumSpinner.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetMaximum (); - } - }); - } - - /** - * Create a group of widgets to control the minimum - * attribute of the example widget. - */ - void createMinimumGroup() { - - /* Create the group */ - Group minimumGroup = new Group (controlGroup, DWT.NONE); - minimumGroup.setLayout (new GridLayout ()); - minimumGroup.setText (ControlExample.getResourceString("Minimum")); - minimumGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); - - /* Create a Spinner widget */ - minimumSpinner = new Spinner (minimumGroup, DWT.BORDER); - minimumSpinner.setMaximum (100000); - minimumSpinner.setSelection(getDefaultMinimum()); - minimumSpinner.setPageIncrement (100); - minimumSpinner.setIncrement (1); - minimumSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); - - /* Add the listeners */ - minimumSpinner.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetMinimum (); - } - }); - - } - - /** - * Create a group of widgets to control the selection - * attribute of the example widget. - */ - void createSelectionGroup() { - - /* Create the group */ - Group selectionGroup = new Group(controlGroup, DWT.NONE); - selectionGroup.setLayout(new GridLayout()); - GridData gridData = new GridData(DWT.FILL, DWT.BEGINNING, false, false); - selectionGroup.setLayoutData(gridData); - selectionGroup.setText(ControlExample.getResourceString("Selection")); - - /* Create a Spinner widget */ - selectionSpinner = new Spinner (selectionGroup, DWT.BORDER); - selectionSpinner.setMaximum (100000); - selectionSpinner.setSelection (getDefaultSelection()); - selectionSpinner.setPageIncrement (100); - selectionSpinner.setIncrement (1); - selectionSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); - - /* Add the listeners */ - selectionSpinner.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - setWidgetSelection (); - } - }); - - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup () { - super.createStyleGroup (); - - /* Create the extra widgets */ - if (orientationButtons) { - horizontalButton = new Button (styleGroup, DWT.RADIO); - horizontalButton.setText ("DWT.HORIZONTAL"); - verticalButton = new Button (styleGroup, DWT.RADIO); - verticalButton.setText ("DWT.VERTICAL"); - } - borderButton = new Button (styleGroup, DWT.CHECK); - borderButton.setText ("DWT.BORDER"); - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - if (!instance.startup) { - setWidgetMinimum (); - setWidgetMaximum (); - setWidgetSelection (); - } - Widget [] widgets = getExampleWidgets (); - if (widgets.length !is 0) { - if (orientationButtons) { - horizontalButton.setSelection ((widgets [0].getStyle () & DWT.HORIZONTAL) !is 0); - verticalButton.setSelection ((widgets [0].getStyle () & DWT.VERTICAL) !is 0); - } - borderButton.setSelection ((widgets [0].getStyle () & DWT.BORDER) !is 0); - } - } - - /** - * Gets the default maximum of the "Example" widgets. - */ - abstract int getDefaultMaximum (); - - /** - * Gets the default minimim of the "Example" widgets. - */ - abstract int getDefaultMinimum (); - - /** - * Gets the default selection of the "Example" widgets. - */ - abstract int getDefaultSelection (); - - /** - * Sets the maximum of the "Example" widgets. - */ - abstract void setWidgetMaximum (); - - /** - * Sets the minimim of the "Example" widgets. - */ - abstract void setWidgetMinimum (); - - /** - * Sets the selection of the "Example" widgets. - */ - abstract void setWidgetSelection (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/SashFormTab.d --- a/dwtexamples/controlexample/SashFormTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.SashFormTab; - - - -import dwt.DWT; -import dwt.custom.SashForm; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.List; -import dwt.widgets.Text; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - - -class SashFormTab : Tab { - /* Example widgets and groups that contain them */ - Group sashFormGroup; - SashForm form; - List list1, list2; - Text text; - - /* Style widgets added to the "Style" group */ - Button horizontalButton, verticalButton, smoothButton; - - static char[] [] ListData0; - static char[] [] ListData1; - - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - if( ListData0 is null ){ - ListData0 = [ - ControlExample.getResourceString("ListData0_0"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData0_1"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData0_2"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData0_3"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData0_4"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData0_5"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData0_6"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData0_7")]; //$NON-NLS-1$ - - } - if( ListData1 is null ){ - ListData1 = [ - ControlExample.getResourceString("ListData1_0"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData1_1"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData1_2"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData1_3"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData1_4"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData1_5"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData1_6"), //$NON-NLS-1$ - ControlExample.getResourceString("ListData1_7")]; //$NON-NLS-1$ - } - } - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the sashform widget */ - sashFormGroup = new Group (exampleGroup, DWT.NONE); - sashFormGroup.setLayout (new GridLayout ()); - sashFormGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - sashFormGroup.setText ("SashForm"); - } - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; - if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; - if (smoothButton.getSelection ()) style |= DWT.SMOOTH; - - /* Create the example widgets */ - form = new SashForm (sashFormGroup, style); - list1 = new List (form, DWT.V_SCROLL | DWT.H_SCROLL | DWT.BORDER); - list1.setItems (ListData0); - list2 = new List (form, DWT.V_SCROLL | DWT.H_SCROLL | DWT.BORDER); - list2.setItems (ListData1); - text = new Text (form, DWT.MULTI | DWT.BORDER); - text.setText (ControlExample.getResourceString("Multi_line")); //$NON-NLS-1$ - form.setWeights([1, 1, 1]); - } - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup(); - - /* Create the extra widgets */ - horizontalButton = new Button (styleGroup, DWT.RADIO); - horizontalButton.setText ("DWT.HORIZONTAL"); - horizontalButton.setSelection(true); - verticalButton = new Button (styleGroup, DWT.RADIO); - verticalButton.setText ("DWT.VERTICAL"); - verticalButton.setSelection(false); - smoothButton = new Button (styleGroup, DWT.CHECK); - smoothButton.setText ("DWT.SMOOTH"); - smoothButton.setSelection(false); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) form]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "SashForm"; //$NON-NLS-1$ - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - horizontalButton.setSelection ((form.getStyle () & DWT.H_SCROLL) !is 0); - verticalButton.setSelection ((form.getStyle () & DWT.V_SCROLL) !is 0); - smoothButton.setSelection ((form.getStyle () & DWT.SMOOTH) !is 0); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/SashTab.d --- a/dwtexamples/controlexample/SashTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,264 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.SashTab; - - - -import dwt.DWT; -import dwt.events.ControlAdapter; -import dwt.events.ControlEvent; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.graphics.Rectangle; -import dwt.layout.FillLayout; -import dwt.layout.GridData; -import dwt.widgets.Button; -import dwt.widgets.Composite; -import dwt.widgets.Group; -import dwt.widgets.List; -import dwt.widgets.Sash; -import dwt.widgets.Text; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -class SashTab : Tab { - /* Example widgets and groups that contain them */ - Sash hSash, vSash; - Composite sashComp; - Group sashGroup; - List list1, list2, list3; - Text text; - Button smoothButton; - - static char[] [] ListData0; - static char[] [] ListData1; - - /* Constants */ - static final int SASH_WIDTH = 3; - static final int SASH_LIMIT = 20; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - if( ListData0.length is 0 ){ - ListData0 = [ - ControlExample.getResourceString("ListData0_0"), - ControlExample.getResourceString("ListData0_1"), - ControlExample.getResourceString("ListData0_2"), - ControlExample.getResourceString("ListData0_3"), - ControlExample.getResourceString("ListData0_4"), - ControlExample.getResourceString("ListData0_5"), - ControlExample.getResourceString("ListData0_6"), - ControlExample.getResourceString("ListData0_7"), - ControlExample.getResourceString("ListData0_8")]; - } - if( ListData1.length is 0 ){ - ListData1 = [ - ControlExample.getResourceString("ListData1_0"), - ControlExample.getResourceString("ListData1_1"), - ControlExample.getResourceString("ListData1_2"), - ControlExample.getResourceString("ListData1_3"), - ControlExample.getResourceString("ListData1_4"), - ControlExample.getResourceString("ListData1_5"), - ControlExample.getResourceString("ListData1_6"), - ControlExample.getResourceString("ListData1_7"), - ControlExample.getResourceString("ListData1_8")]; - } - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - exampleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - exampleGroup.setLayout(new FillLayout()); - - /* Create a group for the sash widgets */ - sashGroup = new Group (exampleGroup, DWT.NONE); - FillLayout layout = new FillLayout(); - layout.marginHeight = layout.marginWidth = 5; - sashGroup.setLayout(layout); - sashGroup.setText ("Sash"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - /* - * Create the page. This example does not use layouts. - */ - sashComp = new Composite(sashGroup, DWT.BORDER); - - /* Create the list and text widgets */ - list1 = new List (sashComp, DWT.V_SCROLL | DWT.H_SCROLL | DWT.BORDER); - list1.setItems (ListData0); - list2 = new List (sashComp, DWT.V_SCROLL | DWT.H_SCROLL | DWT.BORDER); - list2.setItems (ListData1); - text = new Text (sashComp, DWT.MULTI | DWT.BORDER); - text.setText (ControlExample.getResourceString("Multi_line")); - - /* Create the sashes */ - int style = getDefaultStyle(); - if (smoothButton.getSelection()) style |= DWT.SMOOTH; - vSash = new Sash (sashComp, DWT.VERTICAL | style); - hSash = new Sash (sashComp, DWT.HORIZONTAL | style); - - /* Add the listeners */ - hSash.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - Rectangle rect = vSash.getParent().getClientArea(); - event.y = Math.min (Math.max (event.y, SASH_LIMIT), rect.height - SASH_LIMIT); - if (event.detail !is DWT.DRAG) { - hSash.setBounds (event.x, event.y, event.width, event.height); - layout (); - } - } - }); - vSash.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - Rectangle rect = vSash.getParent().getClientArea(); - event.x = Math.min (Math.max (event.x, SASH_LIMIT), rect.width - SASH_LIMIT); - if (event.detail !is DWT.DRAG) { - vSash.setBounds (event.x, event.y, event.width, event.height); - layout (); - } - } - }); - sashComp.addControlListener (new class() ControlAdapter { - public void controlResized (ControlEvent event) { - resized (); - } - }); - } - - /** - * Creates the "Size" group. The "Size" group contains - * controls that allow the user to change the size of - * the example widgets. - */ - void createSizeGroup () { - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup (); - - /* Create the extra widgets */ - smoothButton = new Button (styleGroup, DWT.CHECK); - smoothButton.setText("DWT.SMOOTH"); - } - - void disposeExampleWidgets () { - sashComp.dispose(); - sashComp = null; - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) hSash, vSash ]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["ToolTipText"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Sash"; - } - - /** - * Layout the list and text widgets according to the new - * positions of the sashes..events.SelectionEvent - */ - void layout () { - - Rectangle clientArea = sashComp.getClientArea (); - Rectangle hSashBounds = hSash.getBounds (); - Rectangle vSashBounds = vSash.getBounds (); - - list1.setBounds (0, 0, vSashBounds.x, hSashBounds.y); - list2.setBounds (vSashBounds.x + vSashBounds.width, 0, clientArea.width - (vSashBounds.x + vSashBounds.width), hSashBounds.y); - text.setBounds (0, hSashBounds.y + hSashBounds.height, clientArea.width, clientArea.height - (hSashBounds.y + hSashBounds.height)); - - /** - * If the horizontal sash has been moved then the vertical - * sash is either too long or too short and its size must - * be adjusted. - */ - vSashBounds.height = hSashBounds.y; - vSash.setBounds (vSashBounds); - } - /** - * Sets the size of the "Example" widgets. - */ - void setExampleWidgetSize () { - sashGroup.layout (true); - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - smoothButton.setSelection ((hSash.getStyle () & DWT.SMOOTH) !is 0); - } - - /** - * Handle the shell resized event. - */ - void resized () { - - /* Get the client area for the shell */ - Rectangle clientArea = sashComp.getClientArea (); - - /* - * Make list 1 half the width and half the height of the tab leaving room for the sash. - * Place list 1 in the top left quadrant of the tab. - */ - Rectangle list1Bounds = new Rectangle (0, 0, (clientArea.width - SASH_WIDTH) / 2, (clientArea.height - SASH_WIDTH) / 2); - list1.setBounds (list1Bounds); - - /* - * Make list 2 half the width and half the height of the tab leaving room for the sash. - * Place list 2 in the top right quadrant of the tab. - */ - list2.setBounds (list1Bounds.width + SASH_WIDTH, 0, clientArea.width - (list1Bounds.width + SASH_WIDTH), list1Bounds.height); - - /* - * Make the text area the full width and half the height of the tab leaving room for the sash. - * Place the text area in the bottom half of the tab. - */ - text.setBounds (0, list1Bounds.height + SASH_WIDTH, clientArea.width, clientArea.height - (list1Bounds.height + SASH_WIDTH)); - - /* Position the sashes */ - vSash.setBounds (list1Bounds.width, 0, SASH_WIDTH, list1Bounds.height); - hSash.setBounds (0, list1Bounds.height, clientArea.width, SASH_WIDTH); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/ScaleTab.d --- a/dwtexamples/controlexample/ScaleTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,243 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.ScaleTab; - - - -import dwt.DWT; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Group; -import dwt.widgets.Scale; -import dwt.widgets.Spinner; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import dwtexamples.controlexample.RangeTab; - - -class ScaleTab : RangeTab { - /* Example widgets and groups that contain them */ - Scale scale1; - Group scaleGroup; - - /* Spinner widgets added to the "Control" group */ - Spinner incrementSpinner, pageIncrementSpinner; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Control" widget children. - */ - void createControlWidgets () { - super.createControlWidgets (); - createIncrementGroup (); - createPageIncrementGroup (); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the scale */ - scaleGroup = new Group (exampleGroup, DWT.NONE); - scaleGroup.setLayout (new GridLayout ()); - scaleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - scaleGroup.setText ("Scale"); - - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (horizontalButton.getSelection ()) style |= DWT.HORIZONTAL; - if (verticalButton.getSelection ()) style |= DWT.VERTICAL; - if (borderButton.getSelection ()) style |= DWT.BORDER; - - /* Create the example widgets */ - scale1 = new Scale (scaleGroup, style); - } - - /** - * Create a group of widgets to control the increment - * attribute of the example widget. - */ - void createIncrementGroup() { - - /* Create the group */ - Group incrementGroup = new Group (controlGroup, DWT.NONE); - incrementGroup.setLayout (new GridLayout ()); - incrementGroup.setText (ControlExample.getResourceString("Increment")); - incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); - - /* Create the Spinner widget */ - incrementSpinner = new Spinner (incrementGroup, DWT.BORDER); - incrementSpinner.setMaximum (100000); - incrementSpinner.setSelection (getDefaultIncrement()); - incrementSpinner.setPageIncrement (100); - incrementSpinner.setIncrement (1); - incrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); - - /* Add the listeners */ - incrementSpinner.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent e) { - setWidgetIncrement (); - } - }); - } - - /** - * Create a group of widgets to control the page increment - * attribute of the example widget. - */ - void createPageIncrementGroup() { - - /* Create the group */ - Group pageIncrementGroup = new Group (controlGroup, DWT.NONE); - pageIncrementGroup.setLayout (new GridLayout ()); - pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment")); - pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); - - /* Create the Spinner widget */ - pageIncrementSpinner = new Spinner (pageIncrementGroup, DWT.BORDER); - pageIncrementSpinner.setMaximum (100000); - pageIncrementSpinner.setSelection (getDefaultPageIncrement()); - pageIncrementSpinner.setPageIncrement (100); - pageIncrementSpinner.setIncrement (1); - pageIncrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); - - /* Add the listeners */ - pageIncrementSpinner.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetPageIncrement (); - } - }); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) scale1]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Selection", "ToolTipText"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Scale"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - if (!instance.startup) { - setWidgetIncrement (); - setWidgetPageIncrement (); - } - } - - /** - * Gets the default maximum of the "Example" widgets. - */ - int getDefaultMaximum () { - return scale1.getMaximum(); - } - - /** - * Gets the default minimim of the "Example" widgets. - */ - int getDefaultMinimum () { - return scale1.getMinimum(); - } - - /** - * Gets the default selection of the "Example" widgets. - */ - int getDefaultSelection () { - return scale1.getSelection(); - } - - /** - * Gets the default increment of the "Example" widgets. - */ - int getDefaultIncrement () { - return scale1.getIncrement(); - } - - /** - * Gets the default page increment of the "Example" widgets. - */ - int getDefaultPageIncrement () { - return scale1.getPageIncrement(); - } - - /** - * Sets the increment of the "Example" widgets. - */ - void setWidgetIncrement () { - scale1.setIncrement (incrementSpinner.getSelection ()); - } - - /** - * Sets the minimim of the "Example" widgets. - */ - void setWidgetMaximum () { - scale1.setMaximum (maximumSpinner.getSelection ()); - } - - /** - * Sets the minimim of the "Example" widgets. - */ - void setWidgetMinimum () { - scale1.setMinimum (minimumSpinner.getSelection ()); - } - - /** - * Sets the page increment of the "Example" widgets. - */ - void setWidgetPageIncrement () { - scale1.setPageIncrement (pageIncrementSpinner.getSelection ()); - } - - /** - * Sets the selection of the "Example" widgets. - */ - void setWidgetSelection () { - scale1.setSelection (selectionSpinner.getSelection ()); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/ScrollableTab.d --- a/dwtexamples/controlexample/ScrollableTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.ScrollableTab; - - - -import dwt.DWT; -import dwt.widgets.Button; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -abstract class ScrollableTab : Tab { - /* Style widgets added to the "Style" group */ - Button singleButton, multiButton, horizontalButton, verticalButton; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup () { - super.createStyleGroup (); - - /* Create the extra widgets */ - singleButton = new Button (styleGroup, DWT.RADIO); - singleButton.setText ("DWT.SINGLE"); - multiButton = new Button (styleGroup, DWT.RADIO); - multiButton.setText ("DWT.MULTI"); - horizontalButton = new Button (styleGroup, DWT.CHECK); - horizontalButton.setText ("DWT.H_SCROLL"); - horizontalButton.setSelection(true); - verticalButton = new Button (styleGroup, DWT.CHECK); - verticalButton.setText ("DWT.V_SCROLL"); - verticalButton.setSelection(true); - borderButton = new Button (styleGroup, DWT.CHECK); - borderButton.setText ("DWT.BORDER"); - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - Widget [] widgets = getExampleWidgets (); - if (widgets.length !is 0){ - singleButton.setSelection ((widgets [0].getStyle () & DWT.SINGLE) !is 0); - multiButton.setSelection ((widgets [0].getStyle () & DWT.MULTI) !is 0); - horizontalButton.setSelection ((widgets [0].getStyle () & DWT.H_SCROLL) !is 0); - verticalButton.setSelection ((widgets [0].getStyle () & DWT.V_SCROLL) !is 0); - borderButton.setSelection ((widgets [0].getStyle () & DWT.BORDER) !is 0); - } - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/ShellTab.d --- a/dwtexamples/controlexample/ShellTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,313 +0,0 @@ -/******************************************************************************* - * 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 - * Port to the D programming language: - * Frank Benoit -*******************************************************************************/ -module dwtexamples.controlexample.ShellTab; - - - -import dwt.DWT; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.events.SelectionListener; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Event; -import dwt.widgets.Group; -import dwt.widgets.Listener; -import dwt.widgets.Shell; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -import dwt.dwthelper.utils; - -import tango.util.Convert; - -class ShellTab : Tab { - /* Style widgets added to the "Style" groups, and "Other" group */ - Button noParentButton, parentButton; - Button noTrimButton, closeButton, titleButton, minButton, maxButton, borderButton, resizeButton, onTopButton, toolButton; - Button createButton, closeAllButton; - Button modelessButton, primaryModalButton, applicationModalButton, systemModalButton; - Button imageButton; - Group parentStyleGroup, modalStyleGroup; - - /* Variables used to track the open shells */ - int shellCount = 0; - Shell [] shells; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Close all the example shells. - */ - void closeAllShells() { - for (int i = 0; i= shells.length) { - Shell [] newShells = new Shell [shells.length + 4]; - System.arraycopy (shells, 0, newShells, 0, shells.length); - shells = newShells; - } - - /* Compute the shell style */ - int style = DWT.NONE; - if (noTrimButton.getSelection()) style |= DWT.NO_TRIM; - if (closeButton.getSelection()) style |= DWT.CLOSE; - if (titleButton.getSelection()) style |= DWT.TITLE; - if (minButton.getSelection()) style |= DWT.MIN; - if (maxButton.getSelection()) style |= DWT.MAX; - if (borderButton.getSelection()) style |= DWT.BORDER; - if (resizeButton.getSelection()) style |= DWT.RESIZE; - if (onTopButton.getSelection()) style |= DWT.ON_TOP; - if (toolButton.getSelection()) style |= DWT.TOOL; - if (modelessButton.getSelection()) style |= DWT.MODELESS; - if (primaryModalButton.getSelection()) style |= DWT.PRIMARY_MODAL; - if (applicationModalButton.getSelection()) style |= DWT.APPLICATION_MODAL; - if (systemModalButton.getSelection()) style |= DWT.SYSTEM_MODAL; - - /* Create the shell with or without a parent */ - if (noParentButton.getSelection ()) { - shells [shellCount] = new Shell (style); - } else { - shells [shellCount] = new Shell (shell, style); - } - Shell currentShell = shells [shellCount]; - Button button = new Button(currentShell, DWT.PUSH); - button.setBounds(20, 20, 120, 30); - Button closeButton = new Button(currentShell, DWT.PUSH); - closeButton.setBounds(160, 20, 120, 30); - closeButton.setText(ControlExample.getResourceString("Close")); - closeButton.addListener(DWT.Selection, new class(currentShell) Listener { - Shell s; - this( Shell s ){ this.s = s; } - public void handleEvent(Event event) { - s.dispose(); - } - }); - - /* Set the size, title, and image, and open the shell */ - currentShell.setSize (300, 100); - currentShell.setText (ControlExample.getResourceString("Title") ~ to!(char[])(shellCount)); - if (imageButton.getSelection()) currentShell.setImage(instance.images[ControlExample.ciTarget]); - if (backgroundImageButton.getSelection()) currentShell.setBackgroundImage(instance.images[ControlExample.ciBackground]); - hookListeners (currentShell); - currentShell.open (); - shellCount++; - } - - /** - * Creates the "Control" group. - */ - void createControlGroup () { - /* - * Create the "Control" group. This is the group on the - * right half of each example tab. It consists of the - * style group, the 'other' group and the size group. - */ - controlGroup = new Group (tabFolderPage, DWT.NONE); - controlGroup.setLayout (new GridLayout (2, true)); - controlGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); - controlGroup.setText (ControlExample.getResourceString("Parameters")); - - /* Create a group for the decoration style controls */ - styleGroup = new Group (controlGroup, DWT.NONE); - styleGroup.setLayout (new GridLayout ()); - styleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false, 1, 3)); - styleGroup.setText (ControlExample.getResourceString("Decoration_Styles")); - - /* Create a group for the modal style controls */ - modalStyleGroup = new Group (controlGroup, DWT.NONE); - modalStyleGroup.setLayout (new GridLayout ()); - modalStyleGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); - modalStyleGroup.setText (ControlExample.getResourceString("Modal_Styles")); - - /* Create a group for the 'other' controls */ - otherGroup = new Group (controlGroup, DWT.NONE); - otherGroup.setLayout (new GridLayout ()); - otherGroup.setLayoutData (new GridData(DWT.FILL, DWT.FILL, false, false)); - otherGroup.setText (ControlExample.getResourceString("Other")); - - /* Create a group for the parent style controls */ - parentStyleGroup = new Group (controlGroup, DWT.NONE); - parentStyleGroup.setLayout (new GridLayout ()); - GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - parentStyleGroup.setLayoutData (gridData); - parentStyleGroup.setText (ControlExample.getResourceString("Parent")); - } - - /** - * Creates the "Control" widget children. - */ - void createControlWidgets () { - - /* Create the parent style buttons */ - noParentButton = new Button (parentStyleGroup, DWT.RADIO); - noParentButton.setText (ControlExample.getResourceString("No_Parent")); - parentButton = new Button (parentStyleGroup, DWT.RADIO); - parentButton.setText (ControlExample.getResourceString("Parent")); - - /* Create the decoration style buttons */ - noTrimButton = new Button (styleGroup, DWT.CHECK); - noTrimButton.setText ("DWT.NO_TRIM"); - closeButton = new Button (styleGroup, DWT.CHECK); - closeButton.setText ("DWT.CLOSE"); - titleButton = new Button (styleGroup, DWT.CHECK); - titleButton.setText ("DWT.TITLE"); - minButton = new Button (styleGroup, DWT.CHECK); - minButton.setText ("DWT.MIN"); - maxButton = new Button (styleGroup, DWT.CHECK); - maxButton.setText ("DWT.MAX"); - borderButton = new Button (styleGroup, DWT.CHECK); - borderButton.setText ("DWT.BORDER"); - resizeButton = new Button (styleGroup, DWT.CHECK); - resizeButton.setText ("DWT.RESIZE"); - onTopButton = new Button (styleGroup, DWT.CHECK); - onTopButton.setText ("DWT.ON_TOP"); - toolButton = new Button (styleGroup, DWT.CHECK); - toolButton.setText ("DWT.TOOL"); - - /* Create the modal style buttons */ - modelessButton = new Button (modalStyleGroup, DWT.RADIO); - modelessButton.setText ("DWT.MODELESS"); - primaryModalButton = new Button (modalStyleGroup, DWT.RADIO); - primaryModalButton.setText ("DWT.PRIMARY_MODAL"); - applicationModalButton = new Button (modalStyleGroup, DWT.RADIO); - applicationModalButton.setText ("DWT.APPLICATION_MODAL"); - systemModalButton = new Button (modalStyleGroup, DWT.RADIO); - systemModalButton.setText ("DWT.SYSTEM_MODAL"); - - /* Create the 'other' buttons */ - imageButton = new Button (otherGroup, DWT.CHECK); - imageButton.setText (ControlExample.getResourceString("Image")); - backgroundImageButton = new Button(otherGroup, DWT.CHECK); - backgroundImageButton.setText(ControlExample.getResourceString("BackgroundImage")); - - /* Create the "create" and "closeAll" buttons */ - createButton = new Button (controlGroup, DWT.NONE); - GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_END); - createButton.setLayoutData (gridData); - createButton.setText (ControlExample.getResourceString("Create_Shell")); - closeAllButton = new Button (controlGroup, DWT.NONE); - gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING); - closeAllButton.setText (ControlExample.getResourceString("Close_All_Shells")); - closeAllButton.setLayoutData (gridData); - - /* Add the listeners */ - createButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - createButtonSelected(e); - } - }); - closeAllButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - closeAllShells (); - } - }); - SelectionListener decorationButtonListener = new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - decorationButtonSelected(event); - } - }; - noTrimButton.addSelectionListener (decorationButtonListener); - closeButton.addSelectionListener (decorationButtonListener); - titleButton.addSelectionListener (decorationButtonListener); - minButton.addSelectionListener (decorationButtonListener); - maxButton.addSelectionListener (decorationButtonListener); - borderButton.addSelectionListener (decorationButtonListener); - resizeButton.addSelectionListener (decorationButtonListener); - applicationModalButton.addSelectionListener (decorationButtonListener); - systemModalButton.addSelectionListener (decorationButtonListener); - - /* Set the default state */ - noParentButton.setSelection (true); - modelessButton.setSelection (true); - backgroundImageButton.setSelection(false); - } - - /** - * Handle a decoration button selection event. - * - * @param event org.eclipse.swt.events.SelectionEvent - */ - public void decorationButtonSelected(SelectionEvent event) { - - /* Make sure if the modal style is DWT.APPLICATION_MODAL or - * DWT.SYSTEM_MODAL the style DWT.CLOSE is also selected. - * This is to make sure the user can close the shell. - */ - Button widget = cast(Button) event.widget; - if (widget is applicationModalButton || widget is systemModalButton) { - if (widget.getSelection()) { - closeButton.setSelection (true); - noTrimButton.setSelection (false); - } - return; - } - if (widget is closeButton) { - if (applicationModalButton.getSelection() || systemModalButton.getSelection()) { - closeButton.setSelection (true); - } - } - /* - * Make sure if the No Trim button is selected then - * all other decoration buttons are deselected. - */ - if (widget.getSelection() && widget !is noTrimButton) { - noTrimButton.setSelection (false); - return; - } - if (widget.getSelection() && widget is noTrimButton) { - if (applicationModalButton.getSelection() || systemModalButton.getSelection()) { - noTrimButton.setSelection (false); - return; - } - closeButton.setSelection (false); - titleButton.setSelection (false); - minButton.setSelection (false); - maxButton.setSelection (false); - borderButton.setSelection (false); - resizeButton.setSelection (false); - return; - } - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Shell"; - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/SliderTab.d --- a/dwtexamples/controlexample/SliderTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,285 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.SliderTab; - - - -import dwt.DWT; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Group; -import dwt.widgets.Slider; -import dwt.widgets.Spinner; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import dwtexamples.controlexample.RangeTab; - -class SliderTab : RangeTab { - /* Example widgets and groups that contain them */ - Slider slider1; - Group sliderGroup; - - /* Spinner widgets added to the "Control" group */ - Spinner incrementSpinner, pageIncrementSpinner, thumbSpinner; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Control" widget children. - */ - void createControlWidgets () { - super.createControlWidgets (); - createThumbGroup (); - createIncrementGroup (); - createPageIncrementGroup (); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the slider */ - sliderGroup = new Group (exampleGroup, DWT.NONE); - sliderGroup.setLayout (new GridLayout ()); - sliderGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - sliderGroup.setText ("Slider"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (horizontalButton.getSelection ()) style |= DWT.HORIZONTAL; - if (verticalButton.getSelection ()) style |= DWT.VERTICAL; - if (borderButton.getSelection ()) style |= DWT.BORDER; - - /* Create the example widgets */ - slider1 = new Slider(sliderGroup, style); - } - - /** - * Create a group of widgets to control the increment - * attribute of the example widget. - */ - void createIncrementGroup() { - - /* Create the group */ - Group incrementGroup = new Group (controlGroup, DWT.NONE); - incrementGroup.setLayout (new GridLayout ()); - incrementGroup.setText (ControlExample.getResourceString("Increment")); - incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); - - /* Create the Spinner widget */ - incrementSpinner = new Spinner (incrementGroup, DWT.BORDER); - incrementSpinner.setMaximum (100000); - incrementSpinner.setSelection (getDefaultIncrement()); - incrementSpinner.setPageIncrement (100); - incrementSpinner.setIncrement (1); - incrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); - - /* Add the listeners */ - incrementSpinner.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent e) { - setWidgetIncrement (); - } - }); - } - - /** - * Create a group of widgets to control the page increment - * attribute of the example widget. - */ - void createPageIncrementGroup() { - - /* Create the group */ - Group pageIncrementGroup = new Group (controlGroup, DWT.NONE); - pageIncrementGroup.setLayout (new GridLayout ()); - pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment")); - pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); - - /* Create the Spinner widget */ - pageIncrementSpinner = new Spinner (pageIncrementGroup, DWT.BORDER); - pageIncrementSpinner.setMaximum (100000); - pageIncrementSpinner.setSelection (getDefaultPageIncrement()); - pageIncrementSpinner.setPageIncrement (100); - pageIncrementSpinner.setIncrement (1); - pageIncrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); - - /* Add the listeners */ - pageIncrementSpinner.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetPageIncrement (); - } - }); - } - - /** - * Create a group of widgets to control the thumb - * attribute of the example widget. - */ - void createThumbGroup() { - - /* Create the group */ - Group thumbGroup = new Group (controlGroup, DWT.NONE); - thumbGroup.setLayout (new GridLayout ()); - thumbGroup.setText (ControlExample.getResourceString("Thumb")); - thumbGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); - - /* Create the Spinner widget */ - thumbSpinner = new Spinner (thumbGroup, DWT.BORDER); - thumbSpinner.setMaximum (100000); - thumbSpinner.setSelection (getDefaultThumb()); - thumbSpinner.setPageIncrement (100); - thumbSpinner.setIncrement (1); - thumbSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); - - /* Add the listeners */ - thumbSpinner.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetThumb (); - } - }); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) slider1 ]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Selection", "ToolTipText"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Slider"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - if (!instance.startup) { - setWidgetIncrement (); - setWidgetPageIncrement (); - setWidgetThumb (); - } - } - - /** - * Gets the default maximum of the "Example" widgets. - */ - int getDefaultMaximum () { - return slider1.getMaximum(); - } - - /** - * Gets the default minimim of the "Example" widgets. - */ - int getDefaultMinimum () { - return slider1.getMinimum(); - } - - /** - * Gets the default selection of the "Example" widgets. - */ - int getDefaultSelection () { - return slider1.getSelection(); - } - - /** - * Gets the default increment of the "Example" widgets. - */ - int getDefaultIncrement () { - return slider1.getIncrement(); - } - - /** - * Gets the default page increment of the "Example" widgets. - */ - int getDefaultPageIncrement () { - return slider1.getPageIncrement(); - } - - /** - * Gets the default thumb of the "Example" widgets. - */ - int getDefaultThumb () { - return slider1.getThumb(); - } - - /** - * Sets the increment of the "Example" widgets. - */ - void setWidgetIncrement () { - slider1.setIncrement (incrementSpinner.getSelection ()); - } - - /** - * Sets the minimim of the "Example" widgets. - */ - void setWidgetMaximum () { - slider1.setMaximum (maximumSpinner.getSelection ()); - } - - /** - * Sets the minimim of the "Example" widgets. - */ - void setWidgetMinimum () { - slider1.setMinimum (minimumSpinner.getSelection ()); - } - - /** - * Sets the page increment of the "Example" widgets. - */ - void setWidgetPageIncrement () { - slider1.setPageIncrement (pageIncrementSpinner.getSelection ()); - } - - /** - * Sets the selection of the "Example" widgets. - */ - void setWidgetSelection () { - slider1.setSelection (selectionSpinner.getSelection ()); - } - - /** - * Sets the thumb of the "Example" widgets. - */ - void setWidgetThumb () { - slider1.setThumb (thumbSpinner.getSelection ()); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/SpinnerTab.d --- a/dwtexamples/controlexample/SpinnerTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,333 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.SpinnerTab; - - - -import dwt.DWT; -import dwt.events.ControlAdapter; -import dwt.events.ControlEvent; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Composite; -import dwt.widgets.Group; -import dwt.widgets.Spinner; -import dwt.widgets.TabFolder; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import dwtexamples.controlexample.RangeTab; - -class SpinnerTab : RangeTab { - - /* Example widgets and groups that contain them */ - Spinner spinner1; - Group spinnerGroup; - - /* Style widgets added to the "Style" group */ - Button readOnlyButton, wrapButton; - - /* Spinner widgets added to the "Control" group */ - Spinner incrementSpinner, pageIncrementSpinner, digitsSpinner; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Control" widget children. - */ - void createControlWidgets () { - super.createControlWidgets (); - createIncrementGroup (); - createPageIncrementGroup (); - createDigitsGroup (); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the spinner */ - spinnerGroup = new Group (exampleGroup, DWT.NONE); - spinnerGroup.setLayout (new GridLayout ()); - spinnerGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - spinnerGroup.setText ("Spinner"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY; - if (borderButton.getSelection ()) style |= DWT.BORDER; - if (wrapButton.getSelection ()) style |= DWT.WRAP; - - /* Create the example widgets */ - spinner1 = new Spinner (spinnerGroup, style); - } - - /** - * Create a group of widgets to control the increment - * attribute of the example widget. - */ - void createIncrementGroup() { - - /* Create the group */ - Group incrementGroup = new Group (controlGroup, DWT.NONE); - incrementGroup.setLayout (new GridLayout ()); - incrementGroup.setText (ControlExample.getResourceString("Increment")); - incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); - - /* Create the Spinner widget */ - incrementSpinner = new Spinner (incrementGroup, DWT.BORDER); - incrementSpinner.setMaximum (100000); - incrementSpinner.setSelection (getDefaultIncrement()); - incrementSpinner.setPageIncrement (100); - incrementSpinner.setIncrement (1); - incrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); - - /* Add the listeners */ - incrementSpinner.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent e) { - setWidgetIncrement (); - } - }); - } - - /** - * Create a group of widgets to control the page increment - * attribute of the example widget. - */ - void createPageIncrementGroup() { - - /* Create the group */ - Group pageIncrementGroup = new Group (controlGroup, DWT.NONE); - pageIncrementGroup.setLayout (new GridLayout ()); - pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment")); - pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); - - /* Create the Spinner widget */ - pageIncrementSpinner = new Spinner (pageIncrementGroup, DWT.BORDER); - pageIncrementSpinner.setMaximum (100000); - pageIncrementSpinner.setSelection (getDefaultPageIncrement()); - pageIncrementSpinner.setPageIncrement (100); - pageIncrementSpinner.setIncrement (1); - pageIncrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); - - /* Add the listeners */ - pageIncrementSpinner.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetPageIncrement (); - } - }); - } - - /** - * Create a group of widgets to control the digits - * attribute of the example widget. - */ - void createDigitsGroup() { - - /* Create the group */ - Group digitsGroup = new Group (controlGroup, DWT.NONE); - digitsGroup.setLayout (new GridLayout ()); - digitsGroup.setText (ControlExample.getResourceString("Digits")); - digitsGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); - - /* Create the Spinner widget */ - digitsSpinner = new Spinner (digitsGroup, DWT.BORDER); - digitsSpinner.setMaximum (100000); - digitsSpinner.setSelection (getDefaultDigits()); - digitsSpinner.setPageIncrement (100); - digitsSpinner.setIncrement (1); - digitsSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); - - /* Add the listeners */ - digitsSpinner.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent e) { - setWidgetDigits (); - } - }); - } - - /** - * Creates the tab folder page. - * - * @param tabFolder org.eclipse.swt.widgets.TabFolder - * @return the new page for the tab folder - */ - Composite createTabFolderPage (TabFolder tabFolder) { - super.createTabFolderPage (tabFolder); - - /* - * Add a resize listener to the tabFolderPage so that - * if the user types into the example widget to change - * its preferred size, and then resizes the shell, we - * recalculate the preferred size correctly. - */ - tabFolderPage.addControlListener(new class() ControlAdapter { - public void controlResized(ControlEvent e) { - setExampleWidgetSize (); - } - }); - - return tabFolderPage; - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup () { - orientationButtons = false; - super.createStyleGroup (); - - /* Create the extra widgets */ - readOnlyButton = new Button (styleGroup, DWT.CHECK); - readOnlyButton.setText ("DWT.READ_ONLY"); - wrapButton = new Button (styleGroup, DWT.CHECK); - wrapButton.setText ("DWT.WRAP"); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) spinner1 ]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Selection", "ToolTipText"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Spinner"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - readOnlyButton.setSelection ((spinner1.getStyle () & DWT.READ_ONLY) !is 0); - wrapButton.setSelection ((spinner1.getStyle () & DWT.WRAP) !is 0); - if (!instance.startup) { - setWidgetIncrement (); - setWidgetPageIncrement (); - setWidgetDigits (); - } - } - - /** - * Gets the default maximum of the "Example" widgets. - */ - int getDefaultMaximum () { - return spinner1.getMaximum(); - } - - /** - * Gets the default minimim of the "Example" widgets. - */ - int getDefaultMinimum () { - return spinner1.getMinimum(); - } - - /** - * Gets the default selection of the "Example" widgets. - */ - int getDefaultSelection () { - return spinner1.getSelection(); - } - - /** - * Gets the default increment of the "Example" widgets. - */ - int getDefaultIncrement () { - return spinner1.getIncrement(); - } - - /** - * Gets the default page increment of the "Example" widgets. - */ - int getDefaultPageIncrement () { - return spinner1.getPageIncrement(); - } - - /** - * Gets the default digits of the "Example" widgets. - */ - int getDefaultDigits () { - return spinner1.getDigits(); - } - - /** - * Sets the increment of the "Example" widgets. - */ - void setWidgetIncrement () { - spinner1.setIncrement (incrementSpinner.getSelection ()); - } - - /** - * Sets the minimim of the "Example" widgets. - */ - void setWidgetMaximum () { - spinner1.setMaximum (maximumSpinner.getSelection ()); - } - - /** - * Sets the minimim of the "Example" widgets. - */ - void setWidgetMinimum () { - spinner1.setMinimum (minimumSpinner.getSelection ()); - } - - /** - * Sets the page increment of the "Example" widgets. - */ - void setWidgetPageIncrement () { - spinner1.setPageIncrement (pageIncrementSpinner.getSelection ()); - } - - /** - * Sets the digits of the "Example" widgets. - */ - void setWidgetDigits () { - spinner1.setDigits (digitsSpinner.getSelection ()); - } - - /** - * Sets the selection of the "Example" widgets. - */ - void setWidgetSelection () { - spinner1.setSelection (selectionSpinner.getSelection ()); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/StyledTextTab.d --- a/dwtexamples/controlexample/StyledTextTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,356 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.StyledTextTab; - - -import dwt.dwthelper.ByteArrayInputStream; - - -import dwt.DWT; -import dwt.custom.StyleRange; -import dwt.custom.StyledText; -import dwt.events.ControlAdapter; -import dwt.events.ControlEvent; -import dwt.events.DisposeEvent; -import dwt.events.DisposeListener; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.events.SelectionListener; -import dwt.graphics.Color; -import dwt.graphics.Image; -import dwt.graphics.ImageData; -import dwt.graphics.Point; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Composite; -import dwt.widgets.Display; -import dwt.widgets.Group; -import dwt.widgets.Label; -import dwt.widgets.TabFolder; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.ScrollableTab; -import dwtexamples.controlexample.ControlExample; -import tango.core.Exception; -import tango.io.Stdout; - -class StyledTextTab : ScrollableTab { - /* Example widgets and groups that contain them */ - StyledText styledText; - Group styledTextGroup, styledTextStyleGroup; - - /* Style widgets added to the "Style" group */ - Button wrapButton, readOnlyButton, fullSelectionButton; - - /* Buttons for adding StyleRanges to StyledText */ - Button boldButton, italicButton, redButton, yellowButton, underlineButton, strikeoutButton; - Image boldImage, italicImage, redImage, yellowImage, underlineImage, strikeoutImage; - - /* Variables for saving state. */ - char[] text; - StyleRange[] styleRanges; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates a bitmap image. - */ - Image createBitmapImage (Display display, void[] sourceData, void[] maskData ) { - InputStream sourceStream = new ByteArrayInputStream ( cast(byte[])sourceData ); - InputStream maskStream = new ByteArrayInputStream ( cast(byte[])maskData ); - ImageData source = new ImageData (sourceStream); - ImageData mask = new ImageData (maskStream); - Image result = new Image (display, source, mask); - try { - sourceStream.close (); - maskStream.close (); - } catch (IOException e) { - Stderr.formatln( "Stacktrace: {}", e ); - } - return result; - } - - /** - * Creates the "Control" widget children. - */ - void createControlWidgets () { - super.createControlWidgets (); - - /* Add a group for modifying the StyledText widget */ - createStyledTextStyleGroup (); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the styled text widget */ - styledTextGroup = new Group (exampleGroup, DWT.NONE); - styledTextGroup.setLayout (new GridLayout ()); - styledTextGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - styledTextGroup.setText ("StyledText"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (singleButton.getSelection ()) style |= DWT.SINGLE; - if (multiButton.getSelection ()) style |= DWT.MULTI; - if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; - if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; - if (wrapButton.getSelection ()) style |= DWT.WRAP; - if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY; - if (borderButton.getSelection ()) style |= DWT.BORDER; - if (fullSelectionButton.getSelection ()) style |= DWT.FULL_SELECTION; - - /* Create the example widgets */ - styledText = new StyledText (styledTextGroup, style); - styledText.setText (ControlExample.getResourceString("Example_string")); - styledText.append ("\n"); - styledText.append (ControlExample.getResourceString("One_Two_Three")); - - if (text !is null) { - styledText.setText(text); - text = null; - } - if (styleRanges !is null) { - styledText.setStyleRanges(styleRanges); - styleRanges = null; - } - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup(); - - /* Create the extra widgets */ - wrapButton = new Button (styleGroup, DWT.CHECK); - wrapButton.setText ("DWT.WRAP"); - readOnlyButton = new Button (styleGroup, DWT.CHECK); - readOnlyButton.setText ("DWT.READ_ONLY"); - fullSelectionButton = new Button (styleGroup, DWT.CHECK); - fullSelectionButton.setText ("DWT.FULL_SELECTION"); - } - - /** - * Creates the "StyledText Style" group. - */ - void createStyledTextStyleGroup () { - styledTextStyleGroup = new Group (controlGroup, DWT.NONE); - styledTextStyleGroup.setText (ControlExample.getResourceString ("StyledText_Styles")); - styledTextStyleGroup.setLayout (new GridLayout(6, false)); - GridData data = new GridData (GridData.HORIZONTAL_ALIGN_FILL); - data.horizontalSpan = 2; - styledTextStyleGroup.setLayoutData (data); - - /* Get images */ - boldImage = createBitmapImage (display, import("dwtexamples.controlexample.bold.bmp"), import("dwtexamples.controlexample.bold_mask.bmp")); - italicImage = createBitmapImage (display, import("dwtexamples.controlexample.italic.bmp"), import("dwtexamples.controlexample.italic_mask.bmp")); - redImage = createBitmapImage (display, import("dwtexamples.controlexample.red.bmp"), import("dwtexamples.controlexample.red_mask.bmp")); - yellowImage = createBitmapImage (display, import("dwtexamples.controlexample.yellow.bmp"), import("dwtexamples.controlexample.yellow_mask.bmp")); - underlineImage = createBitmapImage (display, import("dwtexamples.controlexample.underline.bmp"), import("dwtexamples.controlexample.underline_mask.bmp")); - strikeoutImage = createBitmapImage (display, import("dwtexamples.controlexample.strikeout.bmp"), import("dwtexamples.controlexample.strikeout_mask.bmp")); - - /* Create controls to modify the StyledText */ - Label label = new Label (styledTextStyleGroup, DWT.NONE); - label.setText (ControlExample.getResourceString ("StyledText_Style_Instructions")); - label.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, false, false, 6, 1)); - label = new Label (styledTextStyleGroup, DWT.NONE); - label.setText (ControlExample.getResourceString ("Bold")); - label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); - boldButton = new Button (styledTextStyleGroup, DWT.PUSH); - boldButton.setImage (boldImage); - label = new Label (styledTextStyleGroup, DWT.NONE); - label.setText (ControlExample.getResourceString ("Underline")); - label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); - underlineButton = new Button (styledTextStyleGroup, DWT.PUSH); - underlineButton.setImage (underlineImage); - label = new Label (styledTextStyleGroup, DWT.NONE); - label.setText (ControlExample.getResourceString ("Foreground_Style")); - label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); - redButton = new Button (styledTextStyleGroup, DWT.PUSH); - redButton.setImage (redImage); - label = new Label (styledTextStyleGroup, DWT.NONE); - label.setText (ControlExample.getResourceString ("Italic")); - label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); - italicButton = new Button (styledTextStyleGroup, DWT.PUSH); - italicButton.setImage (italicImage); - label = new Label (styledTextStyleGroup, DWT.NONE); - label.setText (ControlExample.getResourceString ("Strikeout")); - label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); - strikeoutButton = new Button (styledTextStyleGroup, DWT.PUSH); - strikeoutButton.setImage (strikeoutImage); - label = new Label (styledTextStyleGroup, DWT.NONE); - label.setText (ControlExample.getResourceString ("Background_Style")); - label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); - yellowButton = new Button (styledTextStyleGroup, DWT.PUSH); - yellowButton.setImage (yellowImage); - SelectionListener styleListener = new class() SelectionAdapter { - public void widgetSelected (SelectionEvent e) { - Point sel = styledText.getSelectionRange(); - if ((sel is null) || (sel.y is 0)) return; - StyleRange style; - for (int i = sel.x; i - *******************************************************************************/ -module dwtexamples.controlexample.Tab; - - - -import dwt.DWT; -import dwt.events.ArmEvent; -import dwt.events.ControlEvent; -import dwt.events.DisposeEvent; -import dwt.events.DisposeListener; -import dwt.events.FocusEvent; -import dwt.events.HelpEvent; -import dwt.events.KeyAdapter; -import dwt.events.KeyEvent; -import dwt.events.MenuEvent; -import dwt.events.ModifyEvent; -import dwt.events.MouseEvent; -import dwt.events.PaintEvent; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.events.SelectionListener; -import dwt.events.ShellEvent; -import dwt.events.TraverseEvent; -import dwt.events.TreeEvent; -import dwt.events.TypedEvent; -import dwt.events.VerifyEvent; -import dwt.graphics.Color; -import dwt.graphics.Font; -import dwt.graphics.FontData; -import dwt.graphics.GC; -import dwt.graphics.Image; -import dwt.graphics.Point; -import dwt.graphics.RGB; -import dwt.graphics.Rectangle; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.ColorDialog; -import dwt.widgets.Combo; -import dwt.widgets.Composite; -import dwt.widgets.Control; -import dwt.widgets.Display; -import dwt.widgets.Event; -import dwt.widgets.FontDialog; -import dwt.widgets.Group; -import dwt.widgets.Item; -import dwt.widgets.Label; -import dwt.widgets.Link; -import dwt.widgets.List; -import dwt.widgets.Listener; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.ProgressBar; -import dwt.widgets.Sash; -import dwt.widgets.Scale; -import dwt.widgets.Shell; -import dwt.widgets.Slider; -import dwt.widgets.Spinner; -import dwt.widgets.TabFolder; -import dwt.widgets.Table; -import dwt.widgets.TableItem; -import dwt.widgets.Text; -import dwt.widgets.Tree; -import dwt.widgets.TreeItem; -import dwt.widgets.ToolTip; -import dwt.widgets.Widget; -import dwt.widgets.Canvas; -import dwt.widgets.CoolBar; -import dwt.widgets.ExpandBar; - -import dwt.dwthelper.utils; - -import dwtexamples.controlexample.ControlExample; -import tango.text.convert.Format; - -import tango.io.Stdout; - -/** - * Tab is the abstract superclass of every page - * in the example's tab folder. Each page in the tab folder - * describes a control. - * - * A Tab itself is not a control but instead provides a - * hierarchy with which to share code that is common to - * every page in the folder. - * - * A typical page in a Tab contains a two column composite. - * The left column contains the "Example" group. The right - * column contains "Control" group. The "Control" group - * contains controls that allow the user to interact with - * the example control. The "Control" group typically - * contains a "Style", "Other" and "Size" group. Subclasses - * can override these defaults to augment a group or stop - * a group from being created. - */ - struct EventName { - char[] name; - int id; - } -abstract class Tab { - Shell shell; - Display display; - - /* Common control buttons */ - Button borderButton, enabledButton, visibleButton, backgroundImageButton, popupMenuButton; - Button preferredButton, tooSmallButton, smallButton, largeButton, fillHButton, fillVButton; - - /* Common groups and composites */ - Composite tabFolderPage; - Group exampleGroup, controlGroup, listenersGroup, otherGroup, sizeGroup, styleGroup, colorGroup, backgroundModeGroup; - - /* Controlling instance */ - const ControlExample instance; - - /* Sizing constants for the "Size" group */ - static const int TOO_SMALL_SIZE = 10; - static const int SMALL_SIZE = 50; - static const int LARGE_SIZE = 100; - - /* Right-to-left support */ - static const bool RTL_SUPPORT_ENABLE = false; - Group orientationGroup; - Button rtlButton, ltrButton, defaultOrietationButton; - - /* Controls and resources for the "Colors & Fonts" group */ - static const int IMAGE_SIZE = 12; - static const int FOREGROUND_COLOR = 0; - static const int BACKGROUND_COLOR = 1; - static const int FONT = 2; - Table colorAndFontTable; - ColorDialog colorDialog; - FontDialog fontDialog; - Color foregroundColor, backgroundColor; - Font font; - - /* Controls and resources for the "Background Mode" group */ - Combo backgroundModeCombo; - Button backgroundModeImageButton, backgroundModeColorButton; - - /* Event logging variables and controls */ - Text eventConsole; - bool logging = false; - bool [] eventsFilter; - - /* Set/Get API controls */ - Combo nameCombo; - Label returnTypeLabel; - Button getButton, setButton; - Text setText, getText; - - static EventName[] EVENT_NAMES = [ - {"Activate"[], DWT.Activate}, - {"Arm", DWT.Arm}, - {"Close", DWT.Close}, - {"Collapse", DWT.Collapse}, - {"Deactivate", DWT.Deactivate}, - {"DefaultSelection", DWT.DefaultSelection}, - {"Deiconify", DWT.Deiconify}, - {"Dispose", DWT.Dispose}, - {"DragDetect", DWT.DragDetect}, - {"EraseItem", DWT.EraseItem}, - {"Expand", DWT.Expand}, - {"FocusIn", DWT.FocusIn}, - {"FocusOut", DWT.FocusOut}, - {"HardKeyDown", DWT.HardKeyDown}, - {"HardKeyUp", DWT.HardKeyUp}, - {"Help", DWT.Help}, - {"Hide", DWT.Hide}, - {"Iconify", DWT.Iconify}, - {"KeyDown", DWT.KeyDown}, - {"KeyUp", DWT.KeyUp}, - {"MeasureItem", DWT.MeasureItem}, - {"MenuDetect", DWT.MenuDetect}, - {"Modify", DWT.Modify}, - {"MouseDoubleClick", DWT.MouseDoubleClick}, - {"MouseDown", DWT.MouseDown}, - {"MouseEnter", DWT.MouseEnter}, - {"MouseExit", DWT.MouseExit}, - {"MouseHover", DWT.MouseHover}, - {"MouseMove", DWT.MouseMove}, - {"MouseUp", DWT.MouseUp}, - {"MouseWheel", DWT.MouseWheel}, - {"Move", DWT.Move}, - {"Paint", DWT.Paint}, - {"PaintItem", DWT.PaintItem}, - {"Resize", DWT.Resize}, - {"Selection", DWT.Selection}, - {"SetData", DWT.SetData}, -// {"Settings", DWT.Settings}, // note: this event only goes to Display - {"Show", DWT.Show}, - {"Traverse", DWT.Traverse}, - {"Verify", DWT.Verify} - ]; - - bool samplePopup = false; - - - struct ReflectTypeInfo{ - ReflectMethodInfo[ char[] ] methods; - } - struct ReflectMethodInfo{ - TypeInfo returnType; - TypeInfo[] argumentTypes; - } - static ReflectTypeInfo[ ClassInfo ] reflectTypeInfos; - - static ReflectMethodInfo createMethodInfo( TypeInfo ret, TypeInfo[] args ... ){ - ReflectMethodInfo res; - res.returnType = ret; - foreach( arg; args ){ - res.argumentTypes ~= arg; - } - return res; - } - static void createSetterGetter( ref ReflectTypeInfo ti, char[] name, TypeInfo type ){ - ti.methods[ "get" ~ name ] = createMethodInfo( type ); - ti.methods[ "set" ~ name ] = createMethodInfo( typeid(void), type ); - } - - static void registerTypes(){ - if( reflectTypeInfos.length > 0 ){ - return; - } - - { - ReflectTypeInfo ti; - createSetterGetter( ti, "Selection", typeid(bool) ); - createSetterGetter( ti, "Text", typeid(char[]) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ Button.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ Canvas.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "Orientation", typeid(int) ); - createSetterGetter( ti, "Items", typeid(char[]) ); - createSetterGetter( ti, "Selection", typeid(Point) ); - createSetterGetter( ti, "Text", typeid(char[]) ); - createSetterGetter( ti, "TextLimit", typeid(int) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - createSetterGetter( ti, "VisibleItemCount", typeid(int) ); - reflectTypeInfos[ Combo.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ CoolBar.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "Spacing", typeid(int) ); - reflectTypeInfos[ ExpandBar.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ Group.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "Text", typeid(char[]) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ Label.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "Text", typeid(char[]) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ Link.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "Items", typeid(char[][]) ); - createSetterGetter( ti, "Selection", typeid(char[]) ); - createSetterGetter( ti, "TopIndex", typeid(int) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ List.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "Selection", typeid(char[]) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ ProgressBar.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ Sash.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "Selection", typeid(int) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ Scale.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "Selection", typeid(int) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ Slider.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "Selection", typeid(int) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - reflectTypeInfos[ Spinner.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "DoubleClickEnabled", typeid(bool) ); - createSetterGetter( ti, "EchoChar", typeid(wchar) ); - createSetterGetter( ti, "Editable", typeid(bool) ); - createSetterGetter( ti, "Orientation", typeid(int) ); - createSetterGetter( ti, "Selection", typeid(Point) ); - createSetterGetter( ti, "Tabs", typeid(int) ); - createSetterGetter( ti, "Text", typeid(char[]) ); - createSetterGetter( ti, "TextLimit", typeid(int) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - createSetterGetter( ti, "TopIndex", typeid(int) ); - reflectTypeInfos[ Text.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "Message", typeid(int) ); - createSetterGetter( ti, "Text", typeid(char[]) ); - reflectTypeInfos[ ToolTip.classinfo ] = ti; - } - { - ReflectTypeInfo ti; - createSetterGetter( ti, "ColumnOrder", typeid(int[]) ); - createSetterGetter( ti, "Selection", typeid(TreeItem[]) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - createSetterGetter( ti, "TopItem", typeid(int) ); - reflectTypeInfos[ Tree.classinfo ] = ti; - } - - /+{ - ReflectTypeInfo ti; - createSetterGetter( ti, "Editable", typeid(bool) ); - createSetterGetter( ti, "Items", typeid(char[]) ); - createSetterGetter( ti, "Selection", typeid(Point) ); - createSetterGetter( ti, "Text", typeid(char[]) ); - createSetterGetter( ti, "TextLimit", typeid(int) ); - createSetterGetter( ti, "ToolTipText", typeid(char[]) ); - createSetterGetter( ti, "VisibleItemCount", typeid(int) ); - reflectTypeInfos[ CCombo.classinfo ] = ti; - }+/ - } - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - this.instance = instance; - registerTypes(); - } - - /** - * Creates the "Control" group. The "Control" group - * is typically the right hand column in the tab. - */ - void createControlGroup () { - - /* - * Create the "Control" group. This is the group on the - * right half of each example tab. It consists of the - * "Style" group, the "Other" group and the "Size" group. - */ - controlGroup = new Group (tabFolderPage, DWT.NONE); - controlGroup.setLayout (new GridLayout (2, true)); - controlGroup.setLayoutData (new GridData(DWT.FILL, DWT.FILL, false, false)); - controlGroup.setText (ControlExample.getResourceString("Parameters")); - - /* Create individual groups inside the "Control" group */ - createStyleGroup (); - createOtherGroup (); - createSetGetGroup(); - createSizeGroup (); - createColorAndFontGroup (); - if (RTL_SUPPORT_ENABLE) { - createOrientationGroup (); - } - - /* - * For each Button child in the style group, add a selection - * listener that will recreate the example controls. If the - * style group button is a RADIO button, ensure that the radio - * button is selected before recreating the example controls. - * When the user selects a RADIO button, the current RADIO - * button in the group is deselected and the new RADIO button - * is selected automatically. The listeners are notified for - * both these operations but typically only do work when a RADIO - * button is selected. - */ - SelectionListener selectionListener = new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - if ((event.widget.getStyle () & DWT.RADIO) !is 0) { - if (!(cast(Button) event.widget).getSelection ()) return; - } - recreateExampleWidgets (); - } - }; - Control [] children = styleGroup.getChildren (); - for (int i=0; i 0) oldColor = controls [0].getForeground (); - } - if (oldColor !is null) colorDialog.setRGB(oldColor.getRGB()); // seed dialog with current color - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = foregroundColor; // save old foreground color to dispose when done - foregroundColor = new Color (display, rgb); - setExampleWidgetForeground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case BACKGROUND_COLOR: { - Color oldColor = backgroundColor; - if (oldColor is null) { - Control [] controls = getExampleControls (); - if (controls.length > 0) oldColor = controls [0].getBackground (); // seed dialog with current color - } - if (oldColor !is null) colorDialog.setRGB(oldColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = backgroundColor; // save old background color to dispose when done - backgroundColor = new Color (display, rgb); - setExampleWidgetBackground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case FONT: { - Font oldFont = font; - if (oldFont is null) { - Control [] controls = getExampleControls (); - if (controls.length > 0) oldFont = controls [0].getFont (); - } - if (oldFont !is null) fontDialog.setFontList(oldFont.getFontData()); // seed dialog with current font - FontData fontData = fontDialog.open (); - if (fontData is null) return; - oldFont = font; // dispose old font when done - font = new Font (display, fontData); - setExampleWidgetFont (); - setExampleWidgetSize (); - if (oldFont !is null) oldFont.dispose (); - } - break; - default: - } - } - - /** - * Creates the "Other" group. This is typically - * a child of the "Control" group. - */ - void createOtherGroup () { - /* Create the group */ - otherGroup = new Group (controlGroup, DWT.NONE); - otherGroup.setLayout (new GridLayout ()); - otherGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); - otherGroup.setText (ControlExample.getResourceString("Other")); - - /* Create the controls */ - enabledButton = new Button(otherGroup, DWT.CHECK); - enabledButton.setText(ControlExample.getResourceString("Enabled")); - visibleButton = new Button(otherGroup, DWT.CHECK); - visibleButton.setText(ControlExample.getResourceString("Visible")); - backgroundImageButton = new Button(otherGroup, DWT.CHECK); - backgroundImageButton.setText(ControlExample.getResourceString("BackgroundImage")); - popupMenuButton = new Button(otherGroup, DWT.CHECK); - popupMenuButton.setText(ControlExample.getResourceString("Popup_Menu")); - - /* Add the listeners */ - enabledButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setExampleWidgetEnabled (); - } - }); - visibleButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setExampleWidgetVisibility (); - } - }); - backgroundImageButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setExampleWidgetBackgroundImage (); - } - }); - popupMenuButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setExampleWidgetPopupMenu (); - } - }); - - /* Set the default state */ - enabledButton.setSelection(true); - visibleButton.setSelection(true); - backgroundImageButton.setSelection(false); - popupMenuButton.setSelection(false); - } - - /** - * Creates the "Background Mode" group. - */ - void createBackgroundModeGroup () { - // note that this method must be called after createExampleWidgets - if (getExampleControls ().length is 0) return; - - /* Create the group */ - backgroundModeGroup = new Group (controlGroup, DWT.NONE); - backgroundModeGroup.setLayout (new GridLayout ()); - backgroundModeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); - backgroundModeGroup.setText (ControlExample.getResourceString("Background_Mode")); - - /* Create the controls */ - backgroundModeCombo = new Combo(backgroundModeGroup, DWT.READ_ONLY); - backgroundModeCombo.setItems(["DWT.INHERIT_NONE", "DWT.INHERIT_DEFAULT", "DWT.INHERIT_FORCE"]); - backgroundModeImageButton = new Button(backgroundModeGroup, DWT.CHECK); - backgroundModeImageButton.setText(ControlExample.getResourceString("BackgroundImage")); - backgroundModeColorButton = new Button(backgroundModeGroup, DWT.CHECK); - backgroundModeColorButton.setText(ControlExample.getResourceString("Background_Color")); - - /* Add the listeners */ - backgroundModeCombo.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setExampleGroupBackgroundMode (); - } - }); - backgroundModeImageButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setExampleGroupBackgroundImage (); - } - }); - backgroundModeColorButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setExampleGroupBackgroundColor (); - } - }); - - /* Set the default state */ - backgroundModeCombo.setText(backgroundModeCombo.getItem(0)); - backgroundModeImageButton.setSelection(false); - backgroundModeColorButton.setSelection(false); - } - - /** - * Create the event console popup menu. - */ - void createEventConsolePopup () { - Menu popup = new Menu (shell, DWT.POP_UP); - eventConsole.setMenu (popup); - - MenuItem cut = new MenuItem (popup, DWT.PUSH); - cut.setText (ControlExample.getResourceString("MenuItem_Cut")); - cut.addListener (DWT.Selection, new class() Listener { - public void handleEvent (Event event) { - eventConsole.cut (); - } - }); - MenuItem copy = new MenuItem (popup, DWT.PUSH); - copy.setText (ControlExample.getResourceString("MenuItem_Copy")); - copy.addListener (DWT.Selection, new class() Listener { - public void handleEvent (Event event) { - eventConsole.copy (); - } - }); - MenuItem paste = new MenuItem (popup, DWT.PUSH); - paste.setText (ControlExample.getResourceString("MenuItem_Paste")); - paste.addListener (DWT.Selection, new class() Listener { - public void handleEvent (Event event) { - eventConsole.paste (); - } - }); - new MenuItem (popup, DWT.SEPARATOR); - MenuItem selectAll = new MenuItem (popup, DWT.PUSH); - selectAll.setText(ControlExample.getResourceString("MenuItem_SelectAll")); - selectAll.addListener (DWT.Selection, new class() Listener { - public void handleEvent (Event event) { - eventConsole.selectAll (); - } - }); - } - - /** - * Creates the "Example" group. The "Example" group - * is typically the left hand column in the tab. - */ - void createExampleGroup () { - exampleGroup = new Group (tabFolderPage, DWT.NONE); - exampleGroup.setLayout (new GridLayout ()); - exampleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - } - - /** - * Creates the "Example" widget children of the "Example" group. - * Subclasses override this method to create the particular - * example control. - */ - void createExampleWidgets () { - /* Do nothing */ - } - - /** - * Creates and opens the "Listener selection" dialog. - */ - void createListenerSelectionDialog () { - Shell dialog = new Shell (shell, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); - dialog.setText (ControlExample.getResourceString ("Select_Listeners")); - dialog.setLayout (new GridLayout (2, false)); - Table table = new Table (dialog, DWT.BORDER | DWT.V_SCROLL | DWT.CHECK); - GridData data = new GridData(GridData.FILL_BOTH); - data.verticalSpan = 2; - table.setLayoutData(data); - for (int i = 0; i < EVENT_NAMES.length; i++) { - TableItem item = new TableItem (table, DWT.NONE); - item.setText( EVENT_NAMES[i].name ); - item.setChecked (eventsFilter[i]); - } - char[] [] customNames = getCustomEventNames (); - for (int i = 0; i < customNames.length; i++) { - TableItem item = new TableItem (table, DWT.NONE); - item.setText (customNames[i]); - item.setChecked (eventsFilter[EVENT_NAMES.length + i]); - } - Button selectAll = new Button (dialog, DWT.PUSH); - selectAll.setText(ControlExample.getResourceString ("Select_All")); - selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); - selectAll.addSelectionListener (new class(table, customNames) SelectionAdapter { - Table tbl; - char[][] cn; - this( Table tbl, char[][] cn ){ this.tbl = tbl; this.cn = cn; } - public void widgetSelected(SelectionEvent e) { - TableItem [] items = tbl.getItems(); - for (int i = 0; i < EVENT_NAMES.length; i++) { - items[i].setChecked(true); - } - for (int i = 0; i < cn.length; i++) { - items[EVENT_NAMES.length + i].setChecked(true); - } - } - }); - Button deselectAll = new Button (dialog, DWT.PUSH); - deselectAll.setText(ControlExample.getResourceString ("Deselect_All")); - deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING)); - deselectAll.addSelectionListener (new class(table, customNames) SelectionAdapter { - Table tbl; - char[][] cn; - this( Table tbl, char[][] cn ){ this.tbl = tbl; this.cn = cn; } - public void widgetSelected(SelectionEvent e) { - TableItem [] items = tbl.getItems(); - for (int i = 0; i < EVENT_NAMES.length; i++) { - items[i].setChecked(false); - } - for (int i = 0; i < cn.length; i++) { - items[EVENT_NAMES.length + i].setChecked(false); - } - } - }); - new Label(dialog, DWT.NONE); /* Filler */ - Button ok = new Button (dialog, DWT.PUSH); - ok.setText(ControlExample.getResourceString ("OK")); - dialog.setDefaultButton(ok); - ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); - ok.addSelectionListener (new class(dialog, table, customNames ) SelectionAdapter { - Shell dlg; - Table tbl; - char[][] cn; - this( Shell dlg, Table tbl, char[][] cn ){ this.tbl = tbl; this.dlg = dlg; this.cn = cn; } - public void widgetSelected(SelectionEvent e) { - TableItem [] items = tbl.getItems(); - for (int i = 0; i < EVENT_NAMES.length; i++) { - eventsFilter[i] = items[i].getChecked(); - } - for (int i = 0; i < cn.length; i++) { - eventsFilter[EVENT_NAMES.length + i] = items[EVENT_NAMES.length + i].getChecked(); - } - dlg.dispose(); - } - }); - dialog.pack (); - dialog.open (); - while (! dialog.isDisposed()) { - if (! display.readAndDispatch()) display.sleep(); - } - } - - /** - * Creates the "Listeners" group. The "Listeners" group - * goes below the "Example" and "Control" groups. - */ - void createListenersGroup () { - listenersGroup = new Group (tabFolderPage, DWT.NONE); - listenersGroup.setLayout (new GridLayout (3, false)); - listenersGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true, 2, 1)); - listenersGroup.setText (ControlExample.getResourceString ("Listeners")); - - /* - * Create the button to access the 'Listeners' dialog. - */ - Button listenersButton = new Button (listenersGroup, DWT.PUSH); - listenersButton.setText (ControlExample.getResourceString ("Select_Listeners")); - listenersButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent e) { - createListenerSelectionDialog (); - recreateExampleWidgets (); - } - }); - - /* - * Create the checkbox to add/remove listeners to/from the example widgets. - */ - Button listenCheckbox = new Button (listenersGroup, DWT.CHECK); - listenCheckbox.setText (ControlExample.getResourceString ("Listen")); - listenCheckbox.addSelectionListener (new class(listenCheckbox) SelectionAdapter { - Button lcb; - this( Button lcb ){ this.lcb = lcb; } - public void widgetSelected(SelectionEvent e) { - logging = lcb.getSelection (); - recreateExampleWidgets (); - } - }); - - /* - * Create the button to clear the text. - */ - Button clearButton = new Button (listenersGroup, DWT.PUSH); - clearButton.setText (ControlExample.getResourceString ("Clear")); - clearButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - clearButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent e) { - eventConsole.setText (""); - } - }); - - /* Initialize the eventsFilter to log all events. */ - int customEventCount = getCustomEventNames ().length; - eventsFilter = new bool [EVENT_NAMES.length + customEventCount]; - for (int i = 0; i < EVENT_NAMES.length + customEventCount; i++) { - eventsFilter [i] = true; - } - - /* Create the event console Text. */ - eventConsole = new Text (listenersGroup, DWT.BORDER | DWT.MULTI | DWT.V_SCROLL | DWT.H_SCROLL); - GridData data = new GridData (GridData.FILL_BOTH); - data.horizontalSpan = 3; - data.heightHint = 80; - eventConsole.setLayoutData (data); - createEventConsolePopup (); - eventConsole.addKeyListener (new class() KeyAdapter { - public void keyPressed (KeyEvent e) { - if ((e.keyCode is 'A' || e.keyCode is 'a') && (e.stateMask & DWT.MOD1) !is 0) { - eventConsole.selectAll (); - e.doit = false; - } - } - }); - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return null; - } - - void createSetGetDialog(int x, int y, char[][] methodNames) { - Shell dialog = new Shell(shell, DWT.DIALOG_TRIM | DWT.RESIZE | DWT.MODELESS); - dialog.setLayout(new GridLayout(2, false)); - dialog.setText(getTabText() ~ " " ~ ControlExample.getResourceString ("Set_Get")); - nameCombo = new Combo(dialog, DWT.READ_ONLY); - nameCombo.setItems(methodNames); - nameCombo.setText(methodNames[0]); - nameCombo.setVisibleItemCount(methodNames.length); - nameCombo.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, false, false)); - nameCombo.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - resetLabels(); - } - }); - returnTypeLabel = new Label(dialog, DWT.NONE); - returnTypeLabel.setLayoutData(new GridData(DWT.FILL, DWT.BEGINNING, false, false)); - setButton = new Button(dialog, DWT.PUSH); - setButton.setLayoutData(new GridData(DWT.FILL, DWT.BEGINNING, false, false)); - setButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - setValue(); - setText.selectAll(); - setText.setFocus(); - } - }); - setText = new Text(dialog, DWT.SINGLE | DWT.BORDER); - setText.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, false, false)); - getButton = new Button(dialog, DWT.PUSH); - getButton.setLayoutData(new GridData(DWT.FILL, DWT.BEGINNING, false, false)); - getButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - getValue(); - } - }); - getText = new Text(dialog, DWT.MULTI | DWT.BORDER | DWT.READ_ONLY | DWT.H_SCROLL | DWT.V_SCROLL); - GridData data = new GridData(DWT.FILL, DWT.FILL, true, true); - data.widthHint = 240; - data.heightHint = 200; - getText.setLayoutData(data); - resetLabels(); - dialog.setDefaultButton(setButton); - dialog.pack(); - dialog.setLocation(x, y); - dialog.open(); - } - - void resetLabels() { - char[] methodRoot = nameCombo.getText(); - returnTypeLabel.setText(parameterInfo(methodRoot)); - setButton.setText(setMethodName(methodRoot)); - getButton.setText("get" ~ methodRoot); - setText.setText(""); - getText.setText(""); - getValue(); - setText.setFocus(); - } - - char[] setMethodName(char[] methodRoot) { - return "set" ~ methodRoot; - } - - char[] parameterInfo(char[] methodRoot) { - char[] methodName = "get" ~ methodRoot; - auto mthi = getMethodInfo( methodName ); - char[] typeNameString = mthi.returnType.toString; -//PORTING_LEFT - -// char[] typeName = null; -// ClassInfo returnType = getReturnType(methodRoot); - bool isArray = false; - TypeInfo ti = mthi.returnType; - - if ( auto tia = cast(TypeInfo_Array) mthi.returnType ) { - ti = tia.value; - isArray = true; - } - if ( auto tia = cast(TypeInfo_Class ) ti ) { - } else if ( auto tia = cast(TypeInfo_Interface ) ti ) { - } else { - } - //char[] typeNameString = typeName; - char[] info; -// int index = typeName.lastIndexOf('.'); -// if (index !is -1 && index+1 < typeName.length()) typeNameString = typeName.substring(index+1); -// char[] info = ControlExample.getResourceString("Info_" + typeNameString + (isArray ? "A" : "")); -// if (isArray) { -// typeNameString += "[]"; -// } -// return ControlExample.getResourceString("Parameter_Info", [typeNameString, info]); - - return Format( ControlExample.getResourceString("Parameter_Info"), typeNameString, info ); - } - - void getValue() { -//PORTING_LEFT -/+ - char[] methodName = "get" + nameCombo.getText(); - getText.setText(""); - Widget[] widgets = getExampleWidgets(); - for (int i = 0; i < widgets.length; i++) { - try { - java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, null); - Object result = method.invoke(widgets[i], null); - if (result is null) { - getText.append("null"); - } else if (result.getClass().isArray()) { - int length = java.lang.reflect.Array.getLength(result); - if (length is 0) { - getText.append(result.getClass().getComponentType() + "[0]"); - } - for (int j = 0; j < length; j++) { - getText.append(java.lang.reflect.Array.get(result,j).toString() + "\n"); - } - } else { - getText.append(result.toString()); - } - } catch (Exception e) { - getText.append(e.toString()); - } - if (i + 1 < widgets.length) { - getText.append("\n\n"); - } - } -+/ - } - - private ReflectMethodInfo getMethodInfo( char[] methodName ){ - Widget[] widgets = getExampleWidgets(); - if( widgets.length is 0 ){ - Stdout.formatln( "getWidgets returns null in {}", this.classinfo.name ); - } - if( auto rti = widgets[0].classinfo in reflectTypeInfos ){ - if( auto mthi = methodName in rti.methods ){ - return *mthi; - } - else{ - Stdout.formatln( "method unknown {} in type {} in {}", methodName, widgets[0].classinfo.name, this.classinfo.name ); - } - } - else{ - Stdout.formatln( "type unknown {} in {}", widgets[0].classinfo.name, this.classinfo.name ); - } - } - - TypeInfo getReturnType(char[] methodRoot) { - char[] methodName = "get" ~ methodRoot; - auto mthi = getMethodInfo( methodName ); - return mthi.returnType; - } - - void setValue() { -//PORTING_LEFT -/+ - /* The parameter type must be the same as the get method's return type */ - char[] methodRoot = nameCombo.getText(); - Class returnType = getReturnType(methodRoot); - char[] methodName = setMethodName(methodRoot); - char[] value = setText.getText(); - Widget[] widgets = getExampleWidgets(); - for (int i = 0; i < widgets.length; i++) { - try { - java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, [returnType]); - char[] typeName = returnType.getName(); - Object[] parameter = null; - if (typeName.equals("int")) { - parameter = [new Integer(value)]; - } else if (typeName.equals("long")) { - parameter = [new Long(value)]; - } else if (typeName.equals("char")) { - parameter = [value.length() is 1 ? new Character(value.charAt(0)) : new Character('\0')]; - } else if (typeName.equals("bool")) { - parameter = [new bool(value)]; - } else if (typeName.equals("java.lang.char[]")) { - parameter = [value]; - } else if (typeName.equals("org.eclipse.swt.graphics.Point")) { - char[] xy[] = split(value, ','); - parameter = [new Point((new Integer(xy[0])).intValue(),(new Integer(xy[1])).intValue())]; - } else if (typeName.equals("[I")) { - char[] strings[] = split(value, ','); - int[] ints = new int[strings.length]; - for (int j = 0; j < strings.length; j++) { - ints[j] = (new Integer(strings[j])).intValue(); - } - parameter = [ints]; - } else if (typeName.equals("[Ljava.lang.char[];")) { - parameter = [split(value, ',')]; - } else { - parameter = parameterForType(typeName, value, widgets[i]); - } - method.invoke(widgets[i], parameter); - } catch (Exception e) { - getText.setText(e.toString()); - } - } -+/ -return null; - } - - Object[] parameterForType(char[] typeName, char[] value, Widget widget) { -//PORTING_LEFT -return null; - //return [value]; - } - - void createOrientationGroup () { - /* Create Orientation group*/ - orientationGroup = new Group (controlGroup, DWT.NONE); - orientationGroup.setLayout (new GridLayout()); - orientationGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); - orientationGroup.setText (ControlExample.getResourceString("Orientation")); - defaultOrietationButton = new Button (orientationGroup, DWT.RADIO); - defaultOrietationButton.setText (ControlExample.getResourceString("Default")); - defaultOrietationButton.setSelection (true); - ltrButton = new Button (orientationGroup, DWT.RADIO); - ltrButton.setText ("DWT.LEFT_TO_RIGHT"); - rtlButton = new Button (orientationGroup, DWT.RADIO); - rtlButton.setText ("DWT.RIGHT_TO_LEFT"); - } - - /** - * Creates the "Size" group. The "Size" group contains - * controls that allow the user to change the size of - * the example widgets. - */ - void createSizeGroup () { - /* Create the group */ - sizeGroup = new Group (controlGroup, DWT.NONE); - sizeGroup.setLayout (new GridLayout()); - sizeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); - sizeGroup.setText (ControlExample.getResourceString("Size")); - - /* Create the controls */ - - /* - * The preferred size of a widget is the size returned - * by widget.computeSize (DWT.DEFAULT, DWT.DEFAULT). - * This size is defined on a widget by widget basis. - * Many widgets will attempt to display their contents. - */ - preferredButton = new Button (sizeGroup, DWT.RADIO); - preferredButton.setText (ControlExample.getResourceString("Preferred")); - tooSmallButton = new Button (sizeGroup, DWT.RADIO); - tooSmallButton.setText ( Format( "{} X {}", TOO_SMALL_SIZE, TOO_SMALL_SIZE)); - smallButton = new Button(sizeGroup, DWT.RADIO); - smallButton.setText (Format( "{} X {}", SMALL_SIZE, SMALL_SIZE)); - largeButton = new Button (sizeGroup, DWT.RADIO); - largeButton.setText (Format( "{} X {}", LARGE_SIZE, LARGE_SIZE)); - fillHButton = new Button (sizeGroup, DWT.CHECK); - fillHButton.setText (ControlExample.getResourceString("Fill_X")); - fillVButton = new Button (sizeGroup, DWT.CHECK); - fillVButton.setText (ControlExample.getResourceString("Fill_Y")); - - /* Add the listeners */ - SelectionAdapter selectionListener = new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setExampleWidgetSize (); - } - }; - preferredButton.addSelectionListener(selectionListener); - tooSmallButton.addSelectionListener(selectionListener); - smallButton.addSelectionListener(selectionListener); - largeButton.addSelectionListener(selectionListener); - fillHButton.addSelectionListener(selectionListener); - fillVButton.addSelectionListener(selectionListener); - - /* Set the default state */ - preferredButton.setSelection (true); - } - - /** - * Creates the "Style" group. The "Style" group contains - * controls that allow the user to change the style of - * the example widgets. Changing a widget "Style" causes - * the widget to be destroyed and recreated. - */ - void createStyleGroup () { - styleGroup = new Group (controlGroup, DWT.NONE); - styleGroup.setLayout (new GridLayout ()); - styleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); - styleGroup.setText (ControlExample.getResourceString("Styles")); - } - - /** - * Creates the tab folder page. - * - * @param tabFolder org.eclipse.swt.widgets.TabFolder - * @return the new page for the tab folder - */ - Composite createTabFolderPage (TabFolder tabFolder) { - /* Cache the shell and display. */ - shell = tabFolder.getShell (); - display = shell.getDisplay (); - - /* Create a two column page. */ - tabFolderPage = new Composite (tabFolder, DWT.NONE); - tabFolderPage.setLayout (new GridLayout (2, false)); - - /* Create the "Example" and "Control" groups. */ - createExampleGroup (); - createControlGroup (); - - /* Create the "Listeners" group under the "Control" group. */ - createListenersGroup (); - - /* Create and initialize the example and control widgets. */ - createExampleWidgets (); - hookExampleWidgetListeners (); - createControlWidgets (); - createBackgroundModeGroup (); - setExampleWidgetState (); - - return tabFolderPage; - } - - void setExampleWidgetPopupMenu() { - Control[] controls = getExampleControls(); - for (int i = 0; i < controls.length; i++) { - Control control = controls [i]; - control.addListener(DWT.MenuDetect, new class(control) Listener { - Control ctrl; - this( Control ctrl ){ this.ctrl = ctrl; } - public void handleEvent(Event event) { - Menu menu = ctrl.getMenu(); - if (menu !is null && samplePopup) { - menu.dispose(); - menu = null; - } - if (menu is null && popupMenuButton.getSelection()) { - menu = new Menu(shell, DWT.POP_UP); - MenuItem item = new MenuItem(menu, DWT.PUSH); - item.setText("Sample popup menu item"); - specialPopupMenuItems(menu, event); - ctrl.setMenu(menu); - samplePopup = true; - } - } - }); - } - } - - protected void specialPopupMenuItems(Menu menu, Event event) { - } - - /** - * Disposes the "Example" widgets. - */ - void disposeExampleWidgets () { - Widget [] widgets = getExampleWidgets (); - for (int i=0; i - *******************************************************************************/ -module dwtexamples.controlexample.TabFolderTab; - - - -import dwt.DWT; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Group; -import dwt.widgets.Item; -import dwt.widgets.TabFolder; -import dwt.widgets.TabItem; -import dwt.widgets.Text; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import tango.text.convert.Format; - -class TabFolderTab : Tab { - /* Example widgets and groups that contain them */ - TabFolder tabFolder1; - Group tabFolderGroup; - - /* Style widgets added to the "Style" group */ - Button topButton, bottomButton; - - static char[] [] TabItems1; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - if( TabItems1.length is 0 ){ - TabItems1 = [ - ControlExample.getResourceString("TabItem1_0"), - ControlExample.getResourceString("TabItem1_1"), - ControlExample.getResourceString("TabItem1_2")]; - } - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the TabFolder */ - tabFolderGroup = new Group (exampleGroup, DWT.NONE); - tabFolderGroup.setLayout (new GridLayout ()); - tabFolderGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - tabFolderGroup.setText ("TabFolder"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (topButton.getSelection ()) style |= DWT.TOP; - if (bottomButton.getSelection ()) style |= DWT.BOTTOM; - if (borderButton.getSelection ()) style |= DWT.BORDER; - - /* Create the example widgets */ - tabFolder1 = new TabFolder (tabFolderGroup, style); - for (int i = 0; i < TabItems1.length; i++) { - TabItem item = new TabItem(tabFolder1, DWT.NONE); - item.setText(TabItems1[i]); - item.setToolTipText(Format( ControlExample.getResourceString("Tooltip"), TabItems1[i] )); - Text content = new Text(tabFolder1, DWT.WRAP | DWT.MULTI); - content.setText(Format( "{}: {}", ControlExample.getResourceString("TabItem_content"), i)); - item.setControl(content); - } - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup (); - - /* Create the extra widgets */ - topButton = new Button (styleGroup, DWT.RADIO); - topButton.setText ("DWT.TOP"); - topButton.setSelection(true); - bottomButton = new Button (styleGroup, DWT.RADIO); - bottomButton.setText ("DWT.BOTTOM"); - borderButton = new Button (styleGroup, DWT.CHECK); - borderButton.setText ("DWT.BORDER"); - } - - /** - * Gets the "Example" widget children's items, if any. - * - * @return an array containing the example widget children's items - */ - Item [] getExampleWidgetItems () { - return tabFolder1.getItems(); - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [cast(Widget) tabFolder1 ]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Selection", "SelectionIndex"]; - } - - char[] setMethodName(char[] methodRoot) { - /* Override to handle special case of int getSelectionIndex()/setSelection(int) */ - return (methodRoot == "SelectionIndex") ? "setSelection" : "set" ~ methodRoot; - } - -//PROTING_LEFT -/+ - Object[] parameterForType(char[] typeName, char[] value, Widget widget) { - if (value.length is 0 ) return new Object[] {new TabItem[0]}; - if (typeName.equals("org.eclipse.swt.widgets.TabItem")) { - TabItem item = findItem(value, ((TabFolder) widget).getItems()); - if (item !is null) return new Object[] {item}; - } - if (typeName.equals("[Lorg.eclipse.swt.widgets.TabItem;")) { - char[][] values = split(value, ','); - TabItem[] items = new TabItem[values.length]; - for (int i = 0; i < values.length; i++) { - items[i] = findItem(values[i], ((TabFolder) widget).getItems()); - } - return new Object[] {items}; - } - return super.parameterForType(typeName, value, widget); - } -+/ - TabItem findItem(char[] value, TabItem[] items) { - for (int i = 0; i < items.length; i++) { - TabItem item = items[i]; - if (item.getText() ==/*eq*/ value) return item; - } - return null; - } - - /** - * Gets the short text for the tab folder item. - */ - public char[] getShortTabText() { - return "TF"; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "TabFolder"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - topButton.setSelection ((tabFolder1.getStyle () & DWT.TOP) !is 0); - bottomButton.setSelection ((tabFolder1.getStyle () & DWT.BOTTOM) !is 0); - borderButton.setSelection ((tabFolder1.getStyle () & DWT.BORDER) !is 0); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/TableTab.d --- a/dwtexamples/controlexample/TableTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,721 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.TableTab; - - - -import dwt.DWT; -import dwt.events.DisposeEvent; -import dwt.events.DisposeListener; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.events.SelectionListener; -import dwt.graphics.Color; -import dwt.graphics.Font; -import dwt.graphics.FontData; -import dwt.graphics.Image; -import dwt.graphics.Point; -import dwt.graphics.RGB; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Event; -import dwt.widgets.Group; -import dwt.widgets.Item; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.Table; -import dwt.widgets.TableColumn; -import dwt.widgets.TableItem; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import dwtexamples.controlexample.ScrollableTab; - -import dwt.dwthelper.utils; - -import tango.text.convert.Format; -import tango.util.Convert; -import tango.core.Exception; - -class TableTab : ScrollableTab { - /* Example widgets and groups that contain them */ - Table table1; - Group tableGroup; - - /* Size widgets added to the "Size" group */ - Button packColumnsButton; - - /* Style widgets added to the "Style" group */ - Button checkButton, fullSelectionButton, hideSelectionButton; - - /* Other widgets added to the "Other" group */ - Button multipleColumns, moveableColumns, resizableColumns, headerVisibleButton, sortIndicatorButton, headerImagesButton, linesVisibleButton, subImagesButton; - - /* Controls and resources added to the "Colors and Fonts" group */ - static const int ITEM_FOREGROUND_COLOR = 3; - static const int ITEM_BACKGROUND_COLOR = 4; - static const int ITEM_FONT = 5; - static const int CELL_FOREGROUND_COLOR = 6; - static const int CELL_BACKGROUND_COLOR = 7; - static const int CELL_FONT = 8; - Color itemForegroundColor, itemBackgroundColor, cellForegroundColor, cellBackgroundColor; - Font itemFont, cellFont; - - static char[] [] columnTitles; - static char[][][] tableData; - - Point menuMouseCoords; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - if( columnTitles.length is 0 ){ - columnTitles = [ - ControlExample.getResourceString("TableTitle_0"), - ControlExample.getResourceString("TableTitle_1"), - ControlExample.getResourceString("TableTitle_2"), - ControlExample.getResourceString("TableTitle_3")]; - } - if( tableData.length is 0 ){ - tableData = [ - [ ControlExample.getResourceString("TableLine0_0"), - ControlExample.getResourceString("TableLine0_1"), - ControlExample.getResourceString("TableLine0_2"), - ControlExample.getResourceString("TableLine0_3") ], - [ ControlExample.getResourceString("TableLine1_0"), - ControlExample.getResourceString("TableLine1_1"), - ControlExample.getResourceString("TableLine1_2"), - ControlExample.getResourceString("TableLine1_3") ], - [ ControlExample.getResourceString("TableLine2_0"), - ControlExample.getResourceString("TableLine2_1"), - ControlExample.getResourceString("TableLine2_2"), - ControlExample.getResourceString("TableLine2_3") ]]; - } - } - - /** - * Creates the "Colors and Fonts" group. - */ - void createColorAndFontGroup () { - super.createColorAndFontGroup(); - - TableItem item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Item_Foreground_Color")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Item_Background_Color")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Item_Font")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Cell_Foreground_Color")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Cell_Background_Color")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Cell_Font")); - - shell.addDisposeListener(new class() DisposeListener { - public void widgetDisposed(DisposeEvent event) { - if (itemBackgroundColor !is null) itemBackgroundColor.dispose(); - if (itemForegroundColor !is null) itemForegroundColor.dispose(); - if (itemFont !is null) itemFont.dispose(); - if (cellBackgroundColor !is null) cellBackgroundColor.dispose(); - if (cellForegroundColor !is null) cellForegroundColor.dispose(); - if (cellFont !is null) cellFont.dispose(); - itemBackgroundColor = null; - itemForegroundColor = null; - itemFont = null; - cellBackgroundColor = null; - cellForegroundColor = null; - cellFont = null; - } - }); - } - - void changeFontOrColor(int index) { - switch (index) { - case ITEM_FOREGROUND_COLOR: { - Color oldColor = itemForegroundColor; - if (oldColor is null) oldColor = table1.getItem (0).getForeground (); - colorDialog.setRGB(oldColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = itemForegroundColor; - itemForegroundColor = new Color (display, rgb); - setItemForeground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case ITEM_BACKGROUND_COLOR: { - Color oldColor = itemBackgroundColor; - if (oldColor is null) oldColor = table1.getItem (0).getBackground (); - colorDialog.setRGB(oldColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = itemBackgroundColor; - itemBackgroundColor = new Color (display, rgb); - setItemBackground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case ITEM_FONT: { - Font oldFont = itemFont; - if (oldFont is null) oldFont = table1.getItem (0).getFont (); - fontDialog.setFontList(oldFont.getFontData()); - FontData fontData = fontDialog.open (); - if (fontData is null) return; - oldFont = itemFont; - itemFont = new Font (display, fontData); - setItemFont (); - setExampleWidgetSize (); - if (oldFont !is null) oldFont.dispose (); - } - break; - case CELL_FOREGROUND_COLOR: { - Color oldColor = cellForegroundColor; - if (oldColor is null) oldColor = table1.getItem (0).getForeground (1); - colorDialog.setRGB(oldColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = cellForegroundColor; - cellForegroundColor = new Color (display, rgb); - setCellForeground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case CELL_BACKGROUND_COLOR: { - Color oldColor = cellBackgroundColor; - if (oldColor is null) oldColor = table1.getItem (0).getBackground (1); - colorDialog.setRGB(oldColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = cellBackgroundColor; - cellBackgroundColor = new Color (display, rgb); - setCellBackground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case CELL_FONT: { - Font oldFont = cellFont; - if (oldFont is null) oldFont = table1.getItem (0).getFont (1); - fontDialog.setFontList(oldFont.getFontData()); - FontData fontData = fontDialog.open (); - if (fontData is null) return; - oldFont = cellFont; - cellFont = new Font (display, fontData); - setCellFont (); - setExampleWidgetSize (); - if (oldFont !is null) oldFont.dispose (); - } - break; - default: - super.changeFontOrColor(index); - } - } - - /** - * Creates the "Other" group. - */ - void createOtherGroup () { - super.createOtherGroup (); - - /* Create display controls specific to this example */ - linesVisibleButton = new Button (otherGroup, DWT.CHECK); - linesVisibleButton.setText (ControlExample.getResourceString("Lines_Visible")); - multipleColumns = new Button (otherGroup, DWT.CHECK); - multipleColumns.setText (ControlExample.getResourceString("Multiple_Columns")); - multipleColumns.setSelection(true); - headerVisibleButton = new Button (otherGroup, DWT.CHECK); - headerVisibleButton.setText (ControlExample.getResourceString("Header_Visible")); - sortIndicatorButton = new Button (otherGroup, DWT.CHECK); - sortIndicatorButton.setText (ControlExample.getResourceString("Sort_Indicator")); - moveableColumns = new Button (otherGroup, DWT.CHECK); - moveableColumns.setText (ControlExample.getResourceString("Moveable_Columns")); - resizableColumns = new Button (otherGroup, DWT.CHECK); - resizableColumns.setText (ControlExample.getResourceString("Resizable_Columns")); - headerImagesButton = new Button (otherGroup, DWT.CHECK); - headerImagesButton.setText (ControlExample.getResourceString("Header_Images")); - subImagesButton = new Button (otherGroup, DWT.CHECK); - subImagesButton.setText (ControlExample.getResourceString("Sub_Images")); - - /* Add the listeners */ - linesVisibleButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetLinesVisible (); - } - }); - multipleColumns.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - recreateExampleWidgets (); - } - }); - headerVisibleButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetHeaderVisible (); - } - }); - sortIndicatorButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetSortIndicator (); - } - }); - moveableColumns.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setColumnsMoveable (); - } - }); - resizableColumns.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setColumnsResizable (); - } - }); - headerImagesButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - recreateExampleWidgets (); - } - }); - subImagesButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - recreateExampleWidgets (); - } - }); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the table */ - tableGroup = new Group (exampleGroup, DWT.NONE); - tableGroup.setLayout (new GridLayout ()); - tableGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - tableGroup.setText ("Table"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - /* Compute the widget style */ - int style = getDefaultStyle(); - if (singleButton.getSelection ()) style |= DWT.SINGLE; - if (multiButton.getSelection ()) style |= DWT.MULTI; - if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; - if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; - if (checkButton.getSelection ()) style |= DWT.CHECK; - if (fullSelectionButton.getSelection ()) style |= DWT.FULL_SELECTION; - if (hideSelectionButton.getSelection ()) style |= DWT.HIDE_SELECTION; - if (borderButton.getSelection ()) style |= DWT.BORDER; - - /* Create the table widget */ - table1 = new Table (tableGroup, style); - - /* Fill the table with data */ - bool multiColumn = multipleColumns.getSelection(); - if (multiColumn) { - for (int i = 0; i < columnTitles.length; i++) { - TableColumn tableColumn = new TableColumn(table1, DWT.NONE); - tableColumn.setText(columnTitles[i]); - tableColumn.setToolTipText( Format( ControlExample.getResourceString("Tooltip"), columnTitles[i] )); - if (headerImagesButton.getSelection()) tableColumn.setImage(instance.images [i % 3]); - } - table1.setSortColumn(table1.getColumn(0)); - } - for (int i=0; i<16; i++) { - TableItem item = new TableItem (table1, DWT.NONE); - if (multiColumn && subImagesButton.getSelection()) { - for (int j = 0; j < columnTitles.length; j++) { - item.setImage(j, instance.images [i % 3]); - } - } else { - item.setImage(instance.images [i % 3]); - } - setItemText (item, i, ControlExample.getResourceString("Index") ~ to!(char[])(i)); - } - packColumns(); - } - - void setItemText(TableItem item, int i, char[] node) { - int index = i % 3; - if (multipleColumns.getSelection()) { - tableData [index][0] = node; - item.setText (tableData [index]); - } else { - item.setText (node); - } - } - - /** - * Creates the "Size" group. The "Size" group contains - * controls that allow the user to change the size of - * the example widgets. - */ - void createSizeGroup () { - super.createSizeGroup(); - - packColumnsButton = new Button (sizeGroup, DWT.PUSH); - packColumnsButton.setText (ControlExample.getResourceString("Pack_Columns")); - packColumnsButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - packColumns (); - setExampleWidgetSize (); - } - }); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup () { - super.createStyleGroup (); - - /* Create the extra widgets */ - checkButton = new Button (styleGroup, DWT.CHECK); - checkButton.setText ("DWT.CHECK"); - fullSelectionButton = new Button (styleGroup, DWT.CHECK); - fullSelectionButton.setText ("DWT.FULL_SELECTION"); - hideSelectionButton = new Button (styleGroup, DWT.CHECK); - hideSelectionButton.setText ("DWT.HIDE_SELECTION"); - } - - /** - * Gets the "Example" widget children's items, if any. - * - * @return an array containing the example widget children's items - */ - Item [] getExampleWidgetItems () { - Item [] columns = table1.getColumns(); - Item [] items = table1.getItems(); - Item [] allItems = new Item [columns.length + items.length]; - System.arraycopy(columns, 0, allItems, 0, columns.length); - System.arraycopy(items, 0, allItems, columns.length, items.length); - return allItems; - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) table1 ]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["ColumnOrder", "ItemCount", "Selection", "SelectionIndex", "ToolTipText", "TopIndex"]; - } - - char[] setMethodName(char[] methodRoot) { - /* Override to handle special case of int getSelectionIndex()/setSelection(int) */ - return (methodRoot == "SelectionIndex" ) ? "setSelection" : "set" ~ methodRoot; - } - - void packColumns () { - int columnCount = table1.getColumnCount(); - for (int i = 0; i < columnCount; i++) { - TableColumn tableColumn = table1.getColumn(i); - tableColumn.pack(); - } - } - -//PORTING_LEFT -/+ - Object[] parameterForType(char[] typeName, char[] value, Widget widget) { - if (value.length is 0 ) return [new TableItem[0]]; // bug in Table? - if (typeName.equals("org.eclipse.swt.widgets.TableItem")) { - TableItem item = findItem(value, ((Table) widget).getItems()); - if (item !is null) return new Object[] {item}; - } - if (typeName.equals("[Lorg.eclipse.swt.widgets.TableItem;")) { - char[][] values = split(value, ','); - TableItem[] items = new TableItem[values.length]; - for (int i = 0; i < values.length; i++) { - items[i] = findItem(values[i], ((Table) widget).getItems()); - } - return new Object[] {items}; - } - return super.parameterForType(typeName, value, widget); - } -+/ - TableItem findItem(char[] value, TableItem[] items) { - for (int i = 0; i < items.length; i++) { - TableItem item = items[i]; - if (item.getText() == value ) return item; - } - return null; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Table"; - } - - /** - * Sets the foreground color, background color, and font - * of the "Example" widgets to their default settings. - * Also sets foreground and background color of TableItem [0] - * to default settings. - */ - void resetColorsAndFonts () { - super.resetColorsAndFonts (); - Color oldColor = itemForegroundColor; - itemForegroundColor = null; - setItemForeground (); - if (oldColor !is null) oldColor.dispose(); - oldColor = itemBackgroundColor; - itemBackgroundColor = null; - setItemBackground (); - if (oldColor !is null) oldColor.dispose(); - Font oldFont = font; - itemFont = null; - setItemFont (); - if (oldFont !is null) oldFont.dispose(); - oldColor = cellForegroundColor; - cellForegroundColor = null; - setCellForeground (); - if (oldColor !is null) oldColor.dispose(); - oldColor = cellBackgroundColor; - cellBackgroundColor = null; - setCellBackground (); - if (oldColor !is null) oldColor.dispose(); - oldFont = font; - cellFont = null; - setCellFont (); - if (oldFont !is null) oldFont.dispose(); - } - - /** - * Sets the background color of the Row 0 TableItem in column 1. - */ - void setCellBackground () { - if (!instance.startup) { - table1.getItem (0).setBackground (1, cellBackgroundColor); - } - /* Set the background color item's image to match the background color of the cell. */ - Color color = cellBackgroundColor; - if (color is null) color = table1.getItem (0).getBackground (1); - TableItem item = colorAndFontTable.getItem(CELL_BACKGROUND_COLOR); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (colorImage(color)); - } - - /** - * Sets the foreground color of the Row 0 TableItem in column 1. - */ - void setCellForeground () { - if (!instance.startup) { - table1.getItem (0).setForeground (1, cellForegroundColor); - } - /* Set the foreground color item's image to match the foreground color of the cell. */ - Color color = cellForegroundColor; - if (color is null) color = table1.getItem (0).getForeground (1); - TableItem item = colorAndFontTable.getItem(CELL_FOREGROUND_COLOR); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (colorImage(color)); - } - - /** - * Sets the font of the Row 0 TableItem in column 1. - */ - void setCellFont () { - if (!instance.startup) { - table1.getItem (0).setFont (1, cellFont); - } - /* Set the font item's image to match the font of the item. */ - Font ft = cellFont; - if (ft is null) ft = table1.getItem (0).getFont (1); - TableItem item = colorAndFontTable.getItem(CELL_FONT); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (fontImage(ft)); - item.setFont(ft); - colorAndFontTable.layout (); - } - - /** - * Sets the background color of TableItem [0]. - */ - void setItemBackground () { - if (!instance.startup) { - table1.getItem (0).setBackground (itemBackgroundColor); - } - /* Set the background color item's image to match the background color of the item. */ - Color color = itemBackgroundColor; - if (color is null) color = table1.getItem (0).getBackground (); - TableItem item = colorAndFontTable.getItem(ITEM_BACKGROUND_COLOR); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (colorImage(color)); - } - - /** - * Sets the foreground color of TableItem [0]. - */ - void setItemForeground () { - if (!instance.startup) { - table1.getItem (0).setForeground (itemForegroundColor); - } - /* Set the foreground color item's image to match the foreground color of the item. */ - Color color = itemForegroundColor; - if (color is null) color = table1.getItem (0).getForeground (); - TableItem item = colorAndFontTable.getItem(ITEM_FOREGROUND_COLOR); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (colorImage(color)); - } - - /** - * Sets the font of TableItem 0. - */ - void setItemFont () { - if (!instance.startup) { - table1.getItem (0).setFont (itemFont); - } - /* Set the font item's image to match the font of the item. */ - Font ft = itemFont; - if (ft is null) ft = table1.getItem (0).getFont (); - TableItem item = colorAndFontTable.getItem(ITEM_FONT); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (fontImage(ft)); - item.setFont(ft); - colorAndFontTable.layout (); - } - - /** - * Sets the moveable columns state of the "Example" widgets. - */ - void setColumnsMoveable () { - bool selection = moveableColumns.getSelection(); - TableColumn[] columns = table1.getColumns(); - for (int i = 0; i < columns.length; i++) { - columns[i].setMoveable(selection); - } - } - - /** - * Sets the resizable columns state of the "Example" widgets. - */ - void setColumnsResizable () { - bool selection = resizableColumns.getSelection(); - TableColumn[] columns = table1.getColumns(); - for (int i = 0; i < columns.length; i++) { - columns[i].setResizable(selection); - } - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - setItemBackground (); - setItemForeground (); - setItemFont (); - setCellBackground (); - setCellForeground (); - setCellFont (); - if (!instance.startup) { - setColumnsMoveable (); - setColumnsResizable (); - setWidgetHeaderVisible (); - setWidgetSortIndicator (); - setWidgetLinesVisible (); - } - super.setExampleWidgetState (); - checkButton.setSelection ((table1.getStyle () & DWT.CHECK) !is 0); - fullSelectionButton.setSelection ((table1.getStyle () & DWT.FULL_SELECTION) !is 0); - hideSelectionButton.setSelection ((table1.getStyle () & DWT.HIDE_SELECTION) !is 0); - try { - TableColumn column = table1.getColumn(0); - moveableColumns.setSelection (column.getMoveable()); - resizableColumns.setSelection (column.getResizable()); - } catch (IllegalArgumentException ex) {} - headerVisibleButton.setSelection (table1.getHeaderVisible()); - linesVisibleButton.setSelection (table1.getLinesVisible()); - } - - /** - * Sets the header visible state of the "Example" widgets. - */ - void setWidgetHeaderVisible () { - table1.setHeaderVisible (headerVisibleButton.getSelection ()); - } - - /** - * Sets the sort indicator state of the "Example" widgets. - */ - void setWidgetSortIndicator () { - if (sortIndicatorButton.getSelection ()) { - /* Reset to known state: 'down' on column 0. */ - table1.setSortDirection (DWT.DOWN); - TableColumn [] columns = table1.getColumns(); - for (int i = 0; i < columns.length; i++) { - TableColumn column = columns[i]; - if (i is 0) table1.setSortColumn(column); - SelectionListener listener = new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - int sortDirection = DWT.DOWN; - if (e.widget is table1.getSortColumn()) { - /* If the sort column hasn't changed, cycle down -> up -> none. */ - switch (table1.getSortDirection ()) { - case DWT.DOWN: sortDirection = DWT.UP; break; - case DWT.UP: sortDirection = DWT.NONE; break; - } - } else { - table1.setSortColumn(cast(TableColumn)e.widget); - } - table1.setSortDirection (sortDirection); - } - }; - column.addSelectionListener(listener); - column.setData("SortListener", cast(Object)listener); //$NON-NLS-1$ - } - } else { - table1.setSortDirection (DWT.NONE); - TableColumn [] columns = table1.getColumns(); - for (int i = 0; i < columns.length; i++) { - SelectionListener listener = cast(SelectionListener)columns[i].getData("SortListener"); //$NON-NLS-1$ - if (listener !is null) columns[i].removeSelectionListener(listener); - } - } - } - - /** - * Sets the lines visible state of the "Example" widgets. - */ - void setWidgetLinesVisible () { - table1.setLinesVisible (linesVisibleButton.getSelection ()); - } - - protected void specialPopupMenuItems(Menu menu, Event event) { - MenuItem item = new MenuItem(menu, DWT.PUSH); - item.setText("getItem(Point) on mouse coordinates"); - menuMouseCoords = table1.toControl(new Point(event.x, event.y)); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - eventConsole.append ("getItem(Point(" ~ menuMouseCoords.toString() ~ ")) returned: " ~ ((table1.getItem(menuMouseCoords))).toString); - eventConsole.append ("\n"); - }; - }); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/TextTab.d --- a/dwtexamples/controlexample/TextTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.TextTab; - - - -import dwt.DWT; -import dwt.events.ControlAdapter; -import dwt.events.ControlEvent; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Composite; -import dwt.widgets.Group; -import dwt.widgets.TabFolder; -import dwt.widgets.Text; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import dwtexamples.controlexample.ScrollableTab; - -class TextTab : ScrollableTab { - /* Example widgets and groups that contain them */ - Text text; - Group textGroup; - - /* Style widgets added to the "Style" group */ - Button wrapButton, readOnlyButton, passwordButton, searchButton, cancelButton; - Button leftButton, centerButton, rightButton; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the text widget */ - textGroup = new Group (exampleGroup, DWT.NONE); - textGroup.setLayout (new GridLayout ()); - textGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - textGroup.setText ("Text"); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (singleButton.getSelection ()) style |= DWT.SINGLE; - if (multiButton.getSelection ()) style |= DWT.MULTI; - if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; - if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; - if (wrapButton.getSelection ()) style |= DWT.WRAP; - if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY; - if (passwordButton.getSelection ()) style |= DWT.PASSWORD; - if (searchButton.getSelection ()) style |= DWT.SEARCH; - if (cancelButton.getSelection ()) style |= DWT.CANCEL; - if (borderButton.getSelection ()) style |= DWT.BORDER; - if (leftButton.getSelection ()) style |= DWT.LEFT; - if (centerButton.getSelection ()) style |= DWT.CENTER; - if (rightButton.getSelection ()) style |= DWT.RIGHT; - - /* Create the example widgets */ - text = new Text (textGroup, style); - text.setText (ControlExample.getResourceString("Example_string") ~ Text.DELIMITER ~ ControlExample.getResourceString("One_Two_Three")); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup(); - - /* Create the extra widgets */ - wrapButton = new Button (styleGroup, DWT.CHECK); - wrapButton.setText ("DWT.WRAP"); - readOnlyButton = new Button (styleGroup, DWT.CHECK); - readOnlyButton.setText ("DWT.READ_ONLY"); - passwordButton = new Button (styleGroup, DWT.CHECK); - passwordButton.setText ("DWT.PASSWORD"); - searchButton = new Button (styleGroup, DWT.CHECK); - searchButton.setText ("DWT.SEARCH"); - cancelButton = new Button (styleGroup, DWT.CHECK); - cancelButton.setText ("DWT.CANCEL"); - - Composite alignmentGroup = new Composite (styleGroup, DWT.NONE); - GridLayout layout = new GridLayout (); - layout.marginWidth = layout.marginHeight = 0; - alignmentGroup.setLayout (layout); - alignmentGroup.setLayoutData (new GridData (GridData.FILL_BOTH)); - leftButton = new Button (alignmentGroup, DWT.RADIO); - leftButton.setText ("DWT.LEFT"); - centerButton = new Button (alignmentGroup, DWT.RADIO); - centerButton.setText ("DWT.CENTER"); - rightButton = new Button (alignmentGroup, DWT.RADIO); - rightButton.setText ("DWT.RIGHT"); - } - - /** - * Creates the tab folder page. - * - * @param tabFolder org.eclipse.swt.widgets.TabFolder - * @return the new page for the tab folder - */ - Composite createTabFolderPage (TabFolder tabFolder) { - super.createTabFolderPage (tabFolder); - - /* - * Add a resize listener to the tabFolderPage so that - * if the user types into the example widget to change - * its preferred size, and then resizes the shell, we - * recalculate the preferred size correctly. - */ - tabFolderPage.addControlListener(new class() ControlAdapter { - public void controlResized(ControlEvent e) { - setExampleWidgetSize (); - } - }); - - return tabFolderPage; - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) text]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["DoubleClickEnabled", "EchoChar", "Editable", "Orientation", "Selection", "Tabs", "Text", "TextLimit", "ToolTipText", "TopIndex"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Text"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - wrapButton.setSelection ((text.getStyle () & DWT.WRAP) !is 0); - readOnlyButton.setSelection ((text.getStyle () & DWT.READ_ONLY) !is 0); - passwordButton.setSelection ((text.getStyle () & DWT.PASSWORD) !is 0); - searchButton.setSelection ((text.getStyle () & DWT.SEARCH) !is 0); - leftButton.setSelection ((text.getStyle () & DWT.LEFT) !is 0); - centerButton.setSelection ((text.getStyle () & DWT.CENTER) !is 0); - rightButton.setSelection ((text.getStyle () & DWT.RIGHT) !is 0); - - /* Special case: CANCEL and H_SCROLL have the same value, - * so to avoid confusion, only set CANCEL if SEARCH is set. */ - if ((text.getStyle () & DWT.SEARCH) !is 0) { - cancelButton.setSelection ((text.getStyle () & DWT.CANCEL) !is 0); - horizontalButton.setSelection (false); - } else { - cancelButton.setSelection (false); - horizontalButton.setSelection ((text.getStyle () & DWT.H_SCROLL) !is 0); - } - - passwordButton.setEnabled ((text.getStyle () & DWT.SINGLE) !is 0); - searchButton.setEnabled ((text.getStyle () & DWT.SINGLE) !is 0); - cancelButton.setEnabled ((text.getStyle () & DWT.SEARCH) !is 0); - wrapButton.setEnabled ((text.getStyle () & DWT.MULTI) !is 0); - horizontalButton.setEnabled ((text.getStyle () & DWT.MULTI) !is 0); - verticalButton.setEnabled ((text.getStyle () & DWT.MULTI) !is 0); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/ToolBarTab.d --- a/dwtexamples/controlexample/ToolBarTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,400 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.ToolBarTab; - - - -import dwt.DWT; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.graphics.Point; -import dwt.graphics.Rectangle; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Combo; -import dwt.widgets.Group; -import dwt.widgets.Item; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.ToolBar; -import dwt.widgets.ToolItem; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -import dwt.dwthelper.utils; - -import tango.util.Convert; - -class ToolBarTab : Tab { - /* Example widgets and groups that contain them */ - ToolBar imageToolBar, textToolBar, imageTextToolBar; - Group imageToolBarGroup, textToolBarGroup, imageTextToolBarGroup; - - /* Style widgets added to the "Style" group */ - Button horizontalButton, verticalButton, flatButton, shadowOutButton, wrapButton, rightButton; - - /* Other widgets added to the "Other" group */ - Button comboChildButton; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the image tool bar */ - imageToolBarGroup = new Group (exampleGroup, DWT.NONE); - imageToolBarGroup.setLayout (new GridLayout ()); - imageToolBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - imageToolBarGroup.setText (ControlExample.getResourceString("Image_ToolBar")); - - /* Create a group for the text tool bar */ - textToolBarGroup = new Group (exampleGroup, DWT.NONE); - textToolBarGroup.setLayout (new GridLayout ()); - textToolBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - textToolBarGroup.setText (ControlExample.getResourceString("Text_ToolBar")); - - /* Create a group for the image and text tool bar */ - imageTextToolBarGroup = new Group (exampleGroup, DWT.NONE); - imageTextToolBarGroup.setLayout (new GridLayout ()); - imageTextToolBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - imageTextToolBarGroup.setText (ControlExample.getResourceString("ImageText_ToolBar")); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (horizontalButton.getSelection()) style |= DWT.HORIZONTAL; - if (verticalButton.getSelection()) style |= DWT.VERTICAL; - if (flatButton.getSelection()) style |= DWT.FLAT; - if (wrapButton.getSelection()) style |= DWT.WRAP; - if (borderButton.getSelection()) style |= DWT.BORDER; - if (shadowOutButton.getSelection()) style |= DWT.SHADOW_OUT; - if (rightButton.getSelection()) style |= DWT.RIGHT; - - /* - * Create the example widgets. - * - * A tool bar must consist of all image tool - * items or all text tool items but not both. - */ - - /* Create the image tool bar */ - imageToolBar = new ToolBar (imageToolBarGroup, style); - ToolItem item = new ToolItem (imageToolBar, DWT.PUSH); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setToolTipText("DWT.PUSH"); - item = new ToolItem (imageToolBar, DWT.PUSH); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setToolTipText ("DWT.PUSH"); - item = new ToolItem (imageToolBar, DWT.RADIO); - item.setImage (instance.images[ControlExample.ciOpenFolder]); - item.setToolTipText ("DWT.RADIO"); - item = new ToolItem (imageToolBar, DWT.RADIO); - item.setImage (instance.images[ControlExample.ciOpenFolder]); - item.setToolTipText ("DWT.RADIO"); - item = new ToolItem (imageToolBar, DWT.CHECK); - item.setImage (instance.images[ControlExample.ciTarget]); - item.setToolTipText ("DWT.CHECK"); - item = new ToolItem (imageToolBar, DWT.RADIO); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setToolTipText ("DWT.RADIO"); - item = new ToolItem (imageToolBar, DWT.RADIO); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setToolTipText ("DWT.RADIO"); - item = new ToolItem (imageToolBar, DWT.SEPARATOR); - item.setToolTipText("DWT.SEPARATOR"); - if (comboChildButton.getSelection ()) { - Combo combo = new Combo (imageToolBar, DWT.NONE); - combo.setItems (["250", "500", "750"]); - combo.setText (combo.getItem (0)); - combo.pack (); - item.setWidth (combo.getSize ().x); - item.setControl (combo); - } - item = new ToolItem (imageToolBar, DWT.DROP_DOWN); - item.setImage (instance.images[ControlExample.ciTarget]); - item.setToolTipText ("DWT.DROP_DOWN"); - item.addSelectionListener(new DropDownSelectionListener()); - - /* Create the text tool bar */ - textToolBar = new ToolBar (textToolBarGroup, style); - item = new ToolItem (textToolBar, DWT.PUSH); - item.setText (ControlExample.getResourceString("Push")); - item.setToolTipText("DWT.PUSH"); - item = new ToolItem (textToolBar, DWT.PUSH); - item.setText (ControlExample.getResourceString("Push")); - item.setToolTipText("DWT.PUSH"); - item = new ToolItem (textToolBar, DWT.RADIO); - item.setText (ControlExample.getResourceString("Radio")); - item.setToolTipText("DWT.RADIO"); - item = new ToolItem (textToolBar, DWT.RADIO); - item.setText (ControlExample.getResourceString("Radio")); - item.setToolTipText("DWT.RADIO"); - item = new ToolItem (textToolBar, DWT.CHECK); - item.setText (ControlExample.getResourceString("Check")); - item.setToolTipText("DWT.CHECK"); - item = new ToolItem (textToolBar, DWT.RADIO); - item.setText (ControlExample.getResourceString("Radio")); - item.setToolTipText("DWT.RADIO"); - item = new ToolItem (textToolBar, DWT.RADIO); - item.setText (ControlExample.getResourceString("Radio")); - item.setToolTipText("DWT.RADIO"); - item = new ToolItem (textToolBar, DWT.SEPARATOR); - item.setToolTipText("DWT.SEPARATOR"); - if (comboChildButton.getSelection ()) { - Combo combo = new Combo (textToolBar, DWT.NONE); - combo.setItems (["250", "500", "750"]); - combo.setText (combo.getItem (0)); - combo.pack (); - item.setWidth (combo.getSize ().x); - item.setControl (combo); - } - item = new ToolItem (textToolBar, DWT.DROP_DOWN); - item.setText (ControlExample.getResourceString("Drop_Down")); - item.setToolTipText("DWT.DROP_DOWN"); - item.addSelectionListener(new DropDownSelectionListener()); - - /* Create the image and text tool bar */ - imageTextToolBar = new ToolBar (imageTextToolBarGroup, style); - item = new ToolItem (imageTextToolBar, DWT.PUSH); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setText (ControlExample.getResourceString("Push")); - item.setToolTipText("DWT.PUSH"); - item = new ToolItem (imageTextToolBar, DWT.PUSH); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setText (ControlExample.getResourceString("Push")); - item.setToolTipText("DWT.PUSH"); - item = new ToolItem (imageTextToolBar, DWT.RADIO); - item.setImage (instance.images[ControlExample.ciOpenFolder]); - item.setText (ControlExample.getResourceString("Radio")); - item.setToolTipText("DWT.RADIO"); - item = new ToolItem (imageTextToolBar, DWT.RADIO); - item.setImage (instance.images[ControlExample.ciOpenFolder]); - item.setText (ControlExample.getResourceString("Radio")); - item.setToolTipText("DWT.RADIO"); - item = new ToolItem (imageTextToolBar, DWT.CHECK); - item.setImage (instance.images[ControlExample.ciTarget]); - item.setText (ControlExample.getResourceString("Check")); - item.setToolTipText("DWT.CHECK"); - item = new ToolItem (imageTextToolBar, DWT.RADIO); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setText (ControlExample.getResourceString("Radio")); - item.setToolTipText("DWT.RADIO"); - item = new ToolItem (imageTextToolBar, DWT.RADIO); - item.setImage (instance.images[ControlExample.ciClosedFolder]); - item.setText (ControlExample.getResourceString("Radio")); - item.setToolTipText("DWT.RADIO"); - item = new ToolItem (imageTextToolBar, DWT.SEPARATOR); - item.setToolTipText("DWT.SEPARATOR"); - if (comboChildButton.getSelection ()) { - Combo combo = new Combo (imageTextToolBar, DWT.NONE); - combo.setItems (["250", "500", "750"]); - combo.setText (combo.getItem (0)); - combo.pack (); - item.setWidth (combo.getSize ().x); - item.setControl (combo); - } - item = new ToolItem (imageTextToolBar, DWT.DROP_DOWN); - item.setImage (instance.images[ControlExample.ciTarget]); - item.setText (ControlExample.getResourceString("Drop_Down")); - item.setToolTipText("DWT.DROP_DOWN"); - item.addSelectionListener(new DropDownSelectionListener()); - - /* - * Do not add the selection event for this drop down - * tool item. Without hooking the event, the drop down - * widget does nothing special when the drop down area - * is selected. - */ - } - - /** - * Creates the "Other" group. - */ - void createOtherGroup () { - super.createOtherGroup (); - - /* Create display controls specific to this example */ - comboChildButton = new Button (otherGroup, DWT.CHECK); - comboChildButton.setText (ControlExample.getResourceString("Combo_child")); - - /* Add the listeners */ - comboChildButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - recreateExampleWidgets (); - } - }); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup(); - - /* Create the extra widgets */ - horizontalButton = new Button (styleGroup, DWT.RADIO); - horizontalButton.setText ("DWT.HORIZONTAL"); - verticalButton = new Button (styleGroup, DWT.RADIO); - verticalButton.setText ("DWT.VERTICAL"); - flatButton = new Button (styleGroup, DWT.CHECK); - flatButton.setText ("DWT.FLAT"); - shadowOutButton = new Button (styleGroup, DWT.CHECK); - shadowOutButton.setText ("DWT.SHADOW_OUT"); - wrapButton = new Button (styleGroup, DWT.CHECK); - wrapButton.setText ("DWT.WRAP"); - rightButton = new Button (styleGroup, DWT.CHECK); - rightButton.setText ("DWT.RIGHT"); - borderButton = new Button (styleGroup, DWT.CHECK); - borderButton.setText ("DWT.BORDER"); - } - - void disposeExampleWidgets () { - super.disposeExampleWidgets (); - } - - /** - * Gets the "Example" widget children's items, if any. - * - * @return an array containing the example widget children's items - */ - Item [] getExampleWidgetItems () { - Item [] imageToolBarItems = imageToolBar.getItems(); - Item [] textToolBarItems = textToolBar.getItems(); - Item [] imageTextToolBarItems = imageTextToolBar.getItems(); - Item [] allItems = new Item [imageToolBarItems.length + textToolBarItems.length + imageTextToolBarItems.length]; - System.arraycopy(imageToolBarItems, 0, allItems, 0, imageToolBarItems.length); - System.arraycopy(textToolBarItems, 0, allItems, imageToolBarItems.length, textToolBarItems.length); - System.arraycopy(imageTextToolBarItems, 0, allItems, imageToolBarItems.length + textToolBarItems.length, imageTextToolBarItems.length); - return allItems; - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) imageToolBar, textToolBar, imageTextToolBar ]; - } - - /** - * Gets the short text for the tab folder item. - */ - public char[] getShortTabText() { - return "TB"; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "ToolBar"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - super.setExampleWidgetState (); - horizontalButton.setSelection ((imageToolBar.getStyle () & DWT.HORIZONTAL) !is 0); - verticalButton.setSelection ((imageToolBar.getStyle () & DWT.VERTICAL) !is 0); - flatButton.setSelection ((imageToolBar.getStyle () & DWT.FLAT) !is 0); - wrapButton.setSelection ((imageToolBar.getStyle () & DWT.WRAP) !is 0); - shadowOutButton.setSelection ((imageToolBar.getStyle () & DWT.SHADOW_OUT) !is 0); - borderButton.setSelection ((imageToolBar.getStyle () & DWT.BORDER) !is 0); - rightButton.setSelection ((imageToolBar.getStyle () & DWT.RIGHT) !is 0); - } - - /** - * Listens to widgetSelected() events on DWT.DROP_DOWN type ToolItems - * and opens/closes a menu when appropriate. - */ - class DropDownSelectionListener : SelectionAdapter { - private Menu menu = null; - private bool visible = false; - - public void widgetSelected(SelectionEvent event) { - // Create the menu if it has not already been created - if (menu is null) { - // Lazy create the menu. - menu = new Menu(shell); - for (int i = 0; i < 9; ++i) { - final char[] text = ControlExample.getResourceString("DropDownData_" ~ to!(char[])(i)); - if (text.length !is 0) { - MenuItem menuItem = new MenuItem(menu, DWT.NONE); - menuItem.setText(text); - /* - * Add a menu selection listener so that the menu is hidden - * when the user selects an item from the drop down menu. - */ - menuItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - setMenuVisible(false); - } - }); - } else { - new MenuItem(menu, DWT.SEPARATOR); - } - } - } - - /** - * A selection event will be fired when a drop down tool - * item is selected in the main area and in the drop - * down arrow. Examine the event detail to determine - * where the widget was selected. - */ - if (event.detail is DWT.ARROW) { - /* - * The drop down arrow was selected. - */ - if (visible) { - // Hide the menu to give the Arrow the appearance of being a toggle button. - setMenuVisible(false); - } else { - // Position the menu below and vertically aligned with the the drop down tool button. - final ToolItem toolItem = cast(ToolItem) event.widget; - final ToolBar toolBar = toolItem.getParent(); - - Rectangle toolItemBounds = toolItem.getBounds(); - Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); - menu.setLocation(point.x, point.y + toolItemBounds.height); - setMenuVisible(true); - } - } else { - /* - * Main area of drop down tool item selected. - * An application would invoke the code to perform the action for the tool item. - */ - } - } - private void setMenuVisible(bool visible) { - menu.setVisible(visible); - this.visible = visible; - } - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/ToolTipTab.d --- a/dwtexamples/controlexample/ToolTipTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,268 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.ToolTipTab; - - - -import dwt.DWT; -import dwt.events.ControlAdapter; -import dwt.events.ControlEvent; -import dwt.events.DisposeEvent; -import dwt.events.DisposeListener; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Composite; -import dwt.widgets.Group; -import dwt.widgets.TabFolder; -import dwt.widgets.ToolTip; -import dwt.widgets.Tray; -import dwt.widgets.TrayItem; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; - -class ToolTipTab : Tab { - - /* Example widgets and groups that contain them */ - ToolTip toolTip1; - Group toolTipGroup; - - /* Style widgets added to the "Style" group */ - Button balloonButton, iconErrorButton, iconInformationButton, iconWarningButton, noIconButton; - - /* Other widgets added to the "Other" group */ - Button autoHideButton, showInTrayButton; - - Tray tray; - TrayItem trayItem; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the tooltip visibility check box */ - toolTipGroup = new Group (exampleGroup, DWT.NONE); - toolTipGroup.setLayout (new GridLayout ()); - toolTipGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - toolTipGroup.setText ("ToolTip"); - visibleButton = new Button(toolTipGroup, DWT.CHECK); - visibleButton.setText(ControlExample.getResourceString("Visible")); - visibleButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setExampleWidgetVisibility (); - } - }); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - - /* Compute the widget style */ - int style = getDefaultStyle(); - if (balloonButton.getSelection ()) style |= DWT.BALLOON; - if (iconErrorButton.getSelection ()) style |= DWT.ICON_ERROR; - if (iconInformationButton.getSelection ()) style |= DWT.ICON_INFORMATION; - if (iconWarningButton.getSelection ()) style |= DWT.ICON_WARNING; - - /* Create the example widgets */ - toolTip1 = new ToolTip (shell, style); - toolTip1.setText(ControlExample.getResourceString("ToolTip_Title")); - toolTip1.setMessage(ControlExample.getResourceString("Example_string")); - } - - /** - * Creates the tab folder page. - * - * @param tabFolder org.eclipse.swt.widgets.TabFolder - * @return the new page for the tab folder - */ - Composite createTabFolderPage (TabFolder tabFolder) { - super.createTabFolderPage (tabFolder); - - /* - * Add a resize listener to the tabFolderPage so that - * if the user types into the example widget to change - * its preferred size, and then resizes the shell, we - * recalculate the preferred size correctly. - */ - tabFolderPage.addControlListener(new class() ControlAdapter { - public void controlResized(ControlEvent e) { - setExampleWidgetSize (); - } - }); - - return tabFolderPage; - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup () { - super.createStyleGroup (); - - /* Create the extra widgets */ - balloonButton = new Button (styleGroup, DWT.CHECK); - balloonButton.setText ("DWT.BALLOON"); - iconErrorButton = new Button (styleGroup, DWT.RADIO); - iconErrorButton.setText("DWT.ICON_ERROR"); - iconInformationButton = new Button (styleGroup, DWT.RADIO); - iconInformationButton.setText("DWT.ICON_INFORMATION"); - iconWarningButton = new Button (styleGroup, DWT.RADIO); - iconWarningButton.setText("DWT.ICON_WARNING"); - noIconButton = new Button (styleGroup, DWT.RADIO); - noIconButton.setText(ControlExample.getResourceString("No_Icon")); - } - - void createColorAndFontGroup () { - // ToolTip does not need a color and font group. - } - - void createOtherGroup () { - /* Create the group */ - otherGroup = new Group (controlGroup, DWT.NONE); - otherGroup.setLayout (new GridLayout ()); - otherGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); - otherGroup.setText (ControlExample.getResourceString("Other")); - - /* Create the controls */ - autoHideButton = new Button(otherGroup, DWT.CHECK); - autoHideButton.setText(ControlExample.getResourceString("AutoHide")); - showInTrayButton = new Button(otherGroup, DWT.CHECK); - showInTrayButton.setText(ControlExample.getResourceString("Show_In_Tray")); - tray = display.getSystemTray(); - showInTrayButton.setEnabled(tray !is null); - - /* Add the listeners */ - autoHideButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setExampleWidgetAutoHide (); - } - }); - showInTrayButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - showExampleWidgetInTray (); - } - }); - shell.addDisposeListener(new class() DisposeListener { - public void widgetDisposed(DisposeEvent event) { - disposeTrayItem(); - } - }); - - /* Set the default state */ - autoHideButton.setSelection(true); - } - - void createSizeGroup () { - // ToolTip does not need a size group. - } - - /** - * Disposes the "Example" widgets. - */ - void disposeExampleWidgets () { - disposeTrayItem(); - super.disposeExampleWidgets(); - } - - /** - * Gets the "Example" widget children. - */ - // Tab uses this for many things - widgets would only get set/get, listeners, and dispose. - Widget[] getExampleWidgets () { - return [ cast(Widget) toolTip1 ]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["Message", "Text"]; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "ToolTip"; - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - showExampleWidgetInTray (); - setExampleWidgetAutoHide (); - super.setExampleWidgetState (); - balloonButton.setSelection ((toolTip1.getStyle () & DWT.BALLOON) !is 0); - iconErrorButton.setSelection ((toolTip1.getStyle () & DWT.ICON_ERROR) !is 0); - iconInformationButton.setSelection ((toolTip1.getStyle () & DWT.ICON_INFORMATION) !is 0); - iconWarningButton.setSelection ((toolTip1.getStyle () & DWT.ICON_WARNING) !is 0); - noIconButton.setSelection ((toolTip1.getStyle () & (DWT.ICON_ERROR | DWT.ICON_INFORMATION | DWT.ICON_WARNING)) is 0); - autoHideButton.setSelection(toolTip1.getAutoHide()); - } - - /** - * Sets the visibility of the "Example" widgets. - */ - void setExampleWidgetVisibility () { - toolTip1.setVisible (visibleButton.getSelection ()); - } - - /** - * Sets the autoHide state of the "Example" widgets. - */ - void setExampleWidgetAutoHide () { - toolTip1.setAutoHide(autoHideButton.getSelection ()); - } - - void showExampleWidgetInTray () { - if (showInTrayButton.getSelection ()) { - createTrayItem(); - trayItem.setToolTip(toolTip1); - } else { - disposeTrayItem(); - } - } - - void createTrayItem() { - if (trayItem is null) { - trayItem = new TrayItem(tray, DWT.NONE); - trayItem.setImage(instance.images[ControlExample.ciTarget]); - } - } - - void disposeTrayItem() { - if (trayItem !is null) { - trayItem.setToolTip(null); - trayItem.dispose(); - trayItem = null; - } - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/controlexample/TreeTab.d --- a/dwtexamples/controlexample/TreeTab.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,826 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.TreeTab; - - - -import dwt.DWT; -import dwt.events.DisposeEvent; -import dwt.events.DisposeListener; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.events.SelectionListener; -import dwt.graphics.Color; -import dwt.graphics.Font; -import dwt.graphics.FontData; -import dwt.graphics.Image; -import dwt.graphics.Point; -import dwt.graphics.RGB; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Button; -import dwt.widgets.Event; -import dwt.widgets.Group; -import dwt.widgets.Item; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.TableItem; -import dwt.widgets.Tree; -import dwt.widgets.TreeColumn; -import dwt.widgets.TreeItem; -import dwt.widgets.Widget; - -import dwtexamples.controlexample.Tab; -import dwtexamples.controlexample.ControlExample; -import dwtexamples.controlexample.ScrollableTab; - -import dwt.dwthelper.utils; - -import tango.text.convert.Format; -import tango.util.Convert; -import tango.core.Exception; - -class TreeTab : ScrollableTab { - /* Example widgets and groups that contain them */ - Tree tree1, tree2; - TreeItem textNode1, imageNode1; - Group treeGroup, imageTreeGroup, itemGroup; - - /* Size widgets added to the "Size" group */ - Button packColumnsButton; - - /* Style widgets added to the "Style" group */ - Button checkButton, fullSelectionButton; - - /* Other widgets added to the "Other" group */ - Button multipleColumns, moveableColumns, resizableColumns, headerVisibleButton, sortIndicatorButton, headerImagesButton, subImagesButton, linesVisibleButton; - - /* Controls and resources added to the "Colors and Fonts" group */ - static const int ITEM_FOREGROUND_COLOR = 3; - static const int ITEM_BACKGROUND_COLOR = 4; - static const int ITEM_FONT = 5; - static const int CELL_FOREGROUND_COLOR = 6; - static const int CELL_BACKGROUND_COLOR = 7; - static const int CELL_FONT = 8; - Color itemForegroundColor, itemBackgroundColor, cellForegroundColor, cellBackgroundColor; - Font itemFont, cellFont; - - static char[] [] columnTitles; - - static char[][][] tableData; - - Point menuMouseCoords; - - /** - * Creates the Tab within a given instance of ControlExample. - */ - this(ControlExample instance) { - super(instance); - if( columnTitles.length is 0 ){ - columnTitles = [ - ControlExample.getResourceString("TableTitle_0"), - ControlExample.getResourceString("TableTitle_1"), - ControlExample.getResourceString("TableTitle_2"), - ControlExample.getResourceString("TableTitle_3")]; - } - if( tableData.length is 0 ){ - tableData = [ - [ ControlExample.getResourceString("TableLine0_0"), - ControlExample.getResourceString("TableLine0_1"), - ControlExample.getResourceString("TableLine0_2"), - ControlExample.getResourceString("TableLine0_3") ], - [ ControlExample.getResourceString("TableLine1_0"), - ControlExample.getResourceString("TableLine1_1"), - ControlExample.getResourceString("TableLine1_2"), - ControlExample.getResourceString("TableLine1_3") ], - [ ControlExample.getResourceString("TableLine2_0"), - ControlExample.getResourceString("TableLine2_1"), - ControlExample.getResourceString("TableLine2_2"), - ControlExample.getResourceString("TableLine2_3") ] ]; - } - } - - /** - * Creates the "Colors and Fonts" group. - */ - void createColorAndFontGroup () { - super.createColorAndFontGroup(); - - TableItem item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Item_Foreground_Color")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Item_Background_Color")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Item_Font")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Cell_Foreground_Color")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Cell_Background_Color")); - item = new TableItem(colorAndFontTable, DWT.None); - item.setText(ControlExample.getResourceString ("Cell_Font")); - - shell.addDisposeListener(new class() DisposeListener { - public void widgetDisposed(DisposeEvent event) { - if (itemBackgroundColor !is null) itemBackgroundColor.dispose(); - if (itemForegroundColor !is null) itemForegroundColor.dispose(); - if (itemFont !is null) itemFont.dispose(); - if (cellBackgroundColor !is null) cellBackgroundColor.dispose(); - if (cellForegroundColor !is null) cellForegroundColor.dispose(); - if (cellFont !is null) cellFont.dispose(); - itemBackgroundColor = null; - itemForegroundColor = null; - itemFont = null; - cellBackgroundColor = null; - cellForegroundColor = null; - cellFont = null; - } - }); - } - - void changeFontOrColor(int index) { - switch (index) { - case ITEM_FOREGROUND_COLOR: { - Color oldColor = itemForegroundColor; - if (oldColor is null) oldColor = textNode1.getForeground (); - colorDialog.setRGB(oldColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = itemForegroundColor; - itemForegroundColor = new Color (display, rgb); - setItemForeground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case ITEM_BACKGROUND_COLOR: { - Color oldColor = itemBackgroundColor; - if (oldColor is null) oldColor = textNode1.getBackground (); - colorDialog.setRGB(oldColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = itemBackgroundColor; - itemBackgroundColor = new Color (display, rgb); - setItemBackground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case ITEM_FONT: { - Font oldFont = itemFont; - if (oldFont is null) oldFont = textNode1.getFont (); - fontDialog.setFontList(oldFont.getFontData()); - FontData fontData = fontDialog.open (); - if (fontData is null) return; - oldFont = itemFont; - itemFont = new Font (display, fontData); - setItemFont (); - setExampleWidgetSize (); - if (oldFont !is null) oldFont.dispose (); - } - break; - case CELL_FOREGROUND_COLOR: { - Color oldColor = cellForegroundColor; - if (oldColor is null) oldColor = textNode1.getForeground (1); - colorDialog.setRGB(oldColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = cellForegroundColor; - cellForegroundColor = new Color (display, rgb); - setCellForeground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case CELL_BACKGROUND_COLOR: { - Color oldColor = cellBackgroundColor; - if (oldColor is null) oldColor = textNode1.getBackground (1); - colorDialog.setRGB(oldColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb is null) return; - oldColor = cellBackgroundColor; - cellBackgroundColor = new Color (display, rgb); - setCellBackground (); - if (oldColor !is null) oldColor.dispose (); - } - break; - case CELL_FONT: { - Font oldFont = cellFont; - if (oldFont is null) oldFont = textNode1.getFont (1); - fontDialog.setFontList(oldFont.getFontData()); - FontData fontData = fontDialog.open (); - if (fontData is null) return; - oldFont = cellFont; - cellFont = new Font (display, fontData); - setCellFont (); - setExampleWidgetSize (); - if (oldFont !is null) oldFont.dispose (); - } - break; - default: - super.changeFontOrColor(index); - } - } - - /** - * Creates the "Other" group. - */ - void createOtherGroup () { - super.createOtherGroup (); - - /* Create display controls specific to this example */ - linesVisibleButton = new Button (otherGroup, DWT.CHECK); - linesVisibleButton.setText (ControlExample.getResourceString("Lines_Visible")); - multipleColumns = new Button (otherGroup, DWT.CHECK); - multipleColumns.setText (ControlExample.getResourceString("Multiple_Columns")); - headerVisibleButton = new Button (otherGroup, DWT.CHECK); - headerVisibleButton.setText (ControlExample.getResourceString("Header_Visible")); - sortIndicatorButton = new Button (otherGroup, DWT.CHECK); - sortIndicatorButton.setText (ControlExample.getResourceString("Sort_Indicator")); - moveableColumns = new Button (otherGroup, DWT.CHECK); - moveableColumns.setText (ControlExample.getResourceString("Moveable_Columns")); - resizableColumns = new Button (otherGroup, DWT.CHECK); - resizableColumns.setText (ControlExample.getResourceString("Resizable_Columns")); - headerImagesButton = new Button (otherGroup, DWT.CHECK); - headerImagesButton.setText (ControlExample.getResourceString("Header_Images")); - subImagesButton = new Button (otherGroup, DWT.CHECK); - subImagesButton.setText (ControlExample.getResourceString("Sub_Images")); - - /* Add the listeners */ - linesVisibleButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetLinesVisible (); - } - }); - multipleColumns.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - recreateExampleWidgets (); - } - }); - headerVisibleButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetHeaderVisible (); - } - }); - sortIndicatorButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setWidgetSortIndicator (); - } - }); - moveableColumns.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setColumnsMoveable (); - } - }); - resizableColumns.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - setColumnsResizable (); - } - }); - headerImagesButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - recreateExampleWidgets (); - } - }); - subImagesButton.addSelectionListener (new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - recreateExampleWidgets (); - } - }); - } - - /** - * Creates the "Example" group. - */ - void createExampleGroup () { - super.createExampleGroup (); - - /* Create a group for the text tree */ - treeGroup = new Group (exampleGroup, DWT.NONE); - treeGroup.setLayout (new GridLayout ()); - treeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - treeGroup.setText ("Tree"); - - /* Create a group for the image tree */ - imageTreeGroup = new Group (exampleGroup, DWT.NONE); - imageTreeGroup.setLayout (new GridLayout ()); - imageTreeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); - imageTreeGroup.setText (ControlExample.getResourceString("Tree_With_Images")); - } - - /** - * Creates the "Example" widgets. - */ - void createExampleWidgets () { - /* Compute the widget style */ - int style = getDefaultStyle(); - if (singleButton.getSelection()) style |= DWT.SINGLE; - if (multiButton.getSelection()) style |= DWT.MULTI; - if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; - if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; - if (checkButton.getSelection()) style |= DWT.CHECK; - if (fullSelectionButton.getSelection ()) style |= DWT.FULL_SELECTION; - if (borderButton.getSelection()) style |= DWT.BORDER; - - /* Create the text tree */ - tree1 = new Tree (treeGroup, style); - bool multiColumn = multipleColumns.getSelection(); - if (multiColumn) { - for (int i = 0; i < columnTitles.length; i++) { - TreeColumn treeColumn = new TreeColumn(tree1, DWT.NONE); - treeColumn.setText(columnTitles[i]); - treeColumn.setToolTipText(Format( ControlExample.getResourceString("Tooltip") , columnTitles[i])); - } - tree1.setSortColumn(tree1.getColumn(0)); - } - for (int i = 0; i < 4; i++) { - TreeItem item = new TreeItem (tree1, DWT.NONE); - setItemText(item, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1))); - if (i < 3) { - TreeItem subitem = new TreeItem (item, DWT.NONE); - setItemText(subitem, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1) ~ "_1")); - } - } - TreeItem treeRoots[] = tree1.getItems (); - TreeItem item = new TreeItem (treeRoots[1], DWT.NONE); - setItemText(item, 1, ControlExample.getResourceString("Node_2_2")); - item = new TreeItem (item, DWT.NONE); - setItemText(item, 1, ControlExample.getResourceString("Node_2_2_1")); - textNode1 = treeRoots[0]; - packColumns(tree1); - try { - TreeColumn column = tree1.getColumn(0); - resizableColumns.setSelection (column.getResizable()); - } catch (IllegalArgumentException ex) {} - - /* Create the image tree */ - tree2 = new Tree (imageTreeGroup, style); - Image image = instance.images[ControlExample.ciClosedFolder]; - if (multiColumn) { - for (int i = 0; i < columnTitles.length; i++) { - TreeColumn treeColumn = new TreeColumn(tree2, DWT.NONE); - treeColumn.setText(columnTitles[i]); - treeColumn.setToolTipText(Format( ControlExample.getResourceString("Tooltip"), columnTitles[i])); - if (headerImagesButton.getSelection()) treeColumn.setImage(image); - } - } - for (int i = 0; i < 4; i++) { - item = new TreeItem (tree2, DWT.NONE); - setItemText(item, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1))); - if (multiColumn && subImagesButton.getSelection()) { - for (int j = 0; j < columnTitles.length; j++) { - item.setImage(j, image); - } - } else { - item.setImage(image); - } - if (i < 3) { - TreeItem subitem = new TreeItem (item, DWT.NONE); - setItemText(subitem, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1) ~ "_1")); - if (multiColumn && subImagesButton.getSelection()) { - for (int j = 0; j < columnTitles.length; j++) { - subitem.setImage(j, image); - } - } else { - subitem.setImage(image); - } - } - } - treeRoots = tree2.getItems (); - item = new TreeItem (treeRoots[1], DWT.NONE); - setItemText(item, 1, ControlExample.getResourceString("Node_2_2")); - if (multiColumn && subImagesButton.getSelection()) { - for (int j = 0; j < columnTitles.length; j++) { - item.setImage(j, image); - } - } else { - item.setImage(image); - } - item = new TreeItem (item, DWT.NONE); - setItemText(item, 1, ControlExample.getResourceString("Node_2_2_1")); - if (multiColumn && subImagesButton.getSelection()) { - for (int j = 0; j < columnTitles.length; j++) { - item.setImage(j, image); - } - } else { - item.setImage(image); - } - imageNode1 = treeRoots[0]; - packColumns(tree2); - } - - void setItemText(TreeItem item, int i, char[] node) { - int index = i % 3; - if (multipleColumns.getSelection()) { - tableData [index][0] = node; - item.setText (tableData [index]); - } else { - item.setText (node); - } - } - - /** - * Creates the "Size" group. The "Size" group contains - * controls that allow the user to change the size of - * the example widgets. - */ - void createSizeGroup () { - super.createSizeGroup(); - - packColumnsButton = new Button (sizeGroup, DWT.PUSH); - packColumnsButton.setText (ControlExample.getResourceString("Pack_Columns")); - packColumnsButton.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected (SelectionEvent event) { - packColumns (tree1); - packColumns (tree2); - setExampleWidgetSize (); - } - }); - } - - /** - * Creates the "Style" group. - */ - void createStyleGroup() { - super.createStyleGroup(); - - /* Create the extra widgets */ - checkButton = new Button (styleGroup, DWT.CHECK); - checkButton.setText ("DWT.CHECK"); - fullSelectionButton = new Button (styleGroup, DWT.CHECK); - fullSelectionButton.setText ("DWT.FULL_SELECTION"); - } - - /** - * Gets the "Example" widget children's items, if any. - * - * @return an array containing the example widget children's items - */ - Item [] getExampleWidgetItems () { - /* Note: We do not bother collecting the tree items - * because tree items don't have any events. If events - * are ever added to TreeItem, then this needs to change. - */ - Item [] columns1 = tree1.getColumns(); - Item [] columns2 = tree2.getColumns(); - Item [] allItems = new Item [columns1.length + columns2.length]; - System.arraycopy(columns1, 0, allItems, 0, columns1.length); - System.arraycopy(columns2, 0, allItems, columns1.length, columns2.length); - return allItems; - } - - /** - * Gets the "Example" widget children. - */ - Widget [] getExampleWidgets () { - return [ cast(Widget) tree1, tree2 ]; - } - - /** - * Returns a list of set/get API method names (without the set/get prefix) - * that can be used to set/get values in the example control(s). - */ - char[][] getMethodNames() { - return ["ColumnOrder", "Selection", "ToolTipText", "TopItem"]; - } - -//PORTING_LEFT -/+ - Object[] parameterForType(char[] typeName, char[] value, Widget widget) { - if (typeName.equals("org.eclipse.swt.widgets.TreeItem")) { - TreeItem item = findItem(value, ((Tree) widget).getItems()); - if (item !is null) return new Object[] {item}; - } - if (typeName.equals("[Lorg.eclipse.swt.widgets.TreeItem;")) { - char[][] values = split(value, ','); - TreeItem[] items = new TreeItem[values.length]; - for (int i = 0; i < values.length; i++) { - TreeItem item = findItem(values[i], ((Tree) widget).getItems()); - if (item is null) break; - items[i] = item; - } - return new Object[] {items}; - } - return super.parameterForType(typeName, value, widget); - } -+/ - TreeItem findItem(char[] value, TreeItem[] items) { - for (int i = 0; i < items.length; i++) { - TreeItem item = items[i]; - if (item.getText() == value ) return item; - item = findItem(value, item.getItems()); - if (item !is null) return item; - } - return null; - } - - /** - * Gets the text for the tab folder item. - */ - char[] getTabText () { - return "Tree"; - } - - void packColumns (Tree tree) { - if (multipleColumns.getSelection()) { - int columnCount = tree.getColumnCount(); - for (int i = 0; i < columnCount; i++) { - TreeColumn treeColumn = tree.getColumn(i); - treeColumn.pack(); - } - } - } - - /** - * Sets the moveable columns state of the "Example" widgets. - */ - void setColumnsMoveable () { - bool selection = moveableColumns.getSelection(); - TreeColumn[] columns1 = tree1.getColumns(); - for (int i = 0; i < columns1.length; i++) { - columns1[i].setMoveable(selection); - } - TreeColumn[] columns2 = tree2.getColumns(); - for (int i = 0; i < columns2.length; i++) { - columns2[i].setMoveable(selection); - } - } - - /** - * Sets the resizable columns state of the "Example" widgets. - */ - void setColumnsResizable () { - bool selection = resizableColumns.getSelection(); - TreeColumn[] columns1 = tree1.getColumns(); - for (int i = 0; i < columns1.length; i++) { - columns1[i].setResizable(selection); - } - TreeColumn[] columns2 = tree2.getColumns(); - for (int i = 0; i < columns2.length; i++) { - columns2[i].setResizable(selection); - } - } - - /** - * Sets the foreground color, background color, and font - * of the "Example" widgets to their default settings. - * Also sets foreground and background color of the Node 1 - * TreeItems to default settings. - */ - void resetColorsAndFonts () { - super.resetColorsAndFonts (); - Color oldColor = itemForegroundColor; - itemForegroundColor = null; - setItemForeground (); - if (oldColor !is null) oldColor.dispose(); - oldColor = itemBackgroundColor; - itemBackgroundColor = null; - setItemBackground (); - if (oldColor !is null) oldColor.dispose(); - Font oldFont = font; - itemFont = null; - setItemFont (); - if (oldFont !is null) oldFont.dispose(); - oldColor = cellForegroundColor; - cellForegroundColor = null; - setCellForeground (); - if (oldColor !is null) oldColor.dispose(); - oldColor = cellBackgroundColor; - cellBackgroundColor = null; - setCellBackground (); - if (oldColor !is null) oldColor.dispose(); - oldFont = font; - cellFont = null; - setCellFont (); - if (oldFont !is null) oldFont.dispose(); - } - - /** - * Sets the state of the "Example" widgets. - */ - void setExampleWidgetState () { - setItemBackground (); - setItemForeground (); - setItemFont (); - setCellBackground (); - setCellForeground (); - setCellFont (); - if (!instance.startup) { - setColumnsMoveable (); - setColumnsResizable (); - setWidgetHeaderVisible (); - setWidgetSortIndicator (); - setWidgetLinesVisible (); - } - super.setExampleWidgetState (); - checkButton.setSelection ((tree1.getStyle () & DWT.CHECK) !is 0); - checkButton.setSelection ((tree2.getStyle () & DWT.CHECK) !is 0); - fullSelectionButton.setSelection ((tree1.getStyle () & DWT.FULL_SELECTION) !is 0); - fullSelectionButton.setSelection ((tree2.getStyle () & DWT.FULL_SELECTION) !is 0); - try { - TreeColumn column = tree1.getColumn(0); - moveableColumns.setSelection (column.getMoveable()); - resizableColumns.setSelection (column.getResizable()); - } catch (IllegalArgumentException ex) {} - headerVisibleButton.setSelection (tree1.getHeaderVisible()); - linesVisibleButton.setSelection (tree1.getLinesVisible()); - } - - /** - * Sets the background color of the Node 1 TreeItems in column 1. - */ - void setCellBackground () { - if (!instance.startup) { - textNode1.setBackground (1, cellBackgroundColor); - imageNode1.setBackground (1, cellBackgroundColor); - } - /* Set the background color item's image to match the background color of the cell. */ - Color color = cellBackgroundColor; - if (color is null) color = textNode1.getBackground (1); - TableItem item = colorAndFontTable.getItem(CELL_BACKGROUND_COLOR); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (colorImage(color)); - } - - /** - * Sets the foreground color of the Node 1 TreeItems in column 1. - */ - void setCellForeground () { - if (!instance.startup) { - textNode1.setForeground (1, cellForegroundColor); - imageNode1.setForeground (1, cellForegroundColor); - } - /* Set the foreground color item's image to match the foreground color of the cell. */ - Color color = cellForegroundColor; - if (color is null) color = textNode1.getForeground (1); - TableItem item = colorAndFontTable.getItem(CELL_FOREGROUND_COLOR); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (colorImage(color)); - } - - /** - * Sets the font of the Node 1 TreeItems in column 1. - */ - void setCellFont () { - if (!instance.startup) { - textNode1.setFont (1, cellFont); - imageNode1.setFont (1, cellFont); - } - /* Set the font item's image to match the font of the item. */ - Font ft = cellFont; - if (ft is null) ft = textNode1.getFont (1); - TableItem item = colorAndFontTable.getItem(CELL_FONT); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (fontImage(ft)); - item.setFont(ft); - colorAndFontTable.layout (); - } - - /** - * Sets the background color of the Node 1 TreeItems. - */ - void setItemBackground () { - if (!instance.startup) { - textNode1.setBackground (itemBackgroundColor); - imageNode1.setBackground (itemBackgroundColor); - } - /* Set the background button's color to match the background color of the item. */ - Color color = itemBackgroundColor; - if (color is null) color = textNode1.getBackground (); - TableItem item = colorAndFontTable.getItem(ITEM_BACKGROUND_COLOR); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (colorImage(color)); - } - - /** - * Sets the foreground color of the Node 1 TreeItems. - */ - void setItemForeground () { - if (!instance.startup) { - textNode1.setForeground (itemForegroundColor); - imageNode1.setForeground (itemForegroundColor); - } - /* Set the foreground button's color to match the foreground color of the item. */ - Color color = itemForegroundColor; - if (color is null) color = textNode1.getForeground (); - TableItem item = colorAndFontTable.getItem(ITEM_FOREGROUND_COLOR); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (colorImage(color)); - } - - /** - * Sets the font of the Node 1 TreeItems. - */ - void setItemFont () { - if (!instance.startup) { - textNode1.setFont (itemFont); - imageNode1.setFont (itemFont); - } - /* Set the font item's image to match the font of the item. */ - Font ft = itemFont; - if (ft is null) ft = textNode1.getFont (); - TableItem item = colorAndFontTable.getItem(ITEM_FONT); - Image oldImage = item.getImage(); - if (oldImage !is null) oldImage.dispose(); - item.setImage (fontImage(ft)); - item.setFont(ft); - colorAndFontTable.layout (); - } - - /** - * Sets the header visible state of the "Example" widgets. - */ - void setWidgetHeaderVisible () { - tree1.setHeaderVisible (headerVisibleButton.getSelection ()); - tree2.setHeaderVisible (headerVisibleButton.getSelection ()); - } - - /** - * Sets the sort indicator state of the "Example" widgets. - */ - void setWidgetSortIndicator () { - if (sortIndicatorButton.getSelection ()) { - initializeSortState (tree1); - initializeSortState (tree2); - } else { - resetSortState (tree1); - resetSortState (tree2); - } - } - - /** - * Sets the initial sort indicator state and adds a listener - * to cycle through sort states and columns. - */ - void initializeSortState (Tree tree) { - /* Reset to known state: 'down' on column 0. */ - tree.setSortDirection (DWT.DOWN); - TreeColumn [] columns = tree.getColumns(); - for (int i = 0; i < columns.length; i++) { - TreeColumn column = columns[i]; - if (i is 0) tree.setSortColumn(column); - SelectionListener listener = new class(tree) SelectionAdapter { - Tree t; - this( Tree t ){ this.t = t; } - public void widgetSelected(SelectionEvent e) { - int sortDirection = DWT.DOWN; - if (e.widget is t.getSortColumn()) { - /* If the sort column hasn't changed, cycle down -> up -> none. */ - switch (t.getSortDirection ()) { - case DWT.DOWN: sortDirection = DWT.UP; break; - case DWT.UP: sortDirection = DWT.NONE; break; - } - } else { - t.setSortColumn(cast(TreeColumn)e.widget); - } - t.setSortDirection (sortDirection); - } - }; - column.addSelectionListener(listener); - column.setData("SortListener", cast(Object)listener); //$NON-NLS-1$ - } - } - - void resetSortState (Tree tree) { - tree.setSortDirection (DWT.NONE); - TreeColumn [] columns = tree.getColumns(); - for (int i = 0; i < columns.length; i++) { - SelectionListener listener = cast(SelectionListener)columns[i].getData("SortListener"); //$NON-NLS-1$ - if (listener !is null) columns[i].removeSelectionListener(listener); - } - } - - /** - * Sets the lines visible state of the "Example" widgets. - */ - void setWidgetLinesVisible () { - tree1.setLinesVisible (linesVisibleButton.getSelection ()); - tree2.setLinesVisible (linesVisibleButton.getSelection ()); - } - - protected void specialPopupMenuItems(Menu menu, Event event) { - MenuItem item = new MenuItem(menu, DWT.PUSH); - item.setText("getItem(Point) on mouse coordinates"); - Tree t = cast(Tree) event.widget; - menuMouseCoords = t.toControl(new Point(event.x, event.y)); - item.addSelectionListener(new class(t) SelectionAdapter { - Tree t; - this( Tree t ){ this.t = t; } - public void widgetSelected(SelectionEvent e) { - eventConsole.append ("getItem(Point(" ~ menuMouseCoords.toString ~ ")) returned: " ~ (this.t.getItem(menuMouseCoords)).toString); - eventConsole.append ("\n"); - }; - }); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/dsss.conf --- a/dwtexamples/dsss.conf Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -[*] -buildflags+=-g -gc -buildflags+=-J$LIB_PREFIX/res -J../res -I.. - -version(Windows) { - # if no console window is wanted/needed use -version=gui - version(gui) { - buildflags+= -L/SUBSYSTEM:windows:5 - } else { - buildflags+= -L/SUBSYSTEM:console:5 - } - buildflags+= -L/rc:dwt -} - -[simple.d] - -[addressbook/AddressBook.d] -[clipboard/ClipboardExample.d] -[controlexample/ControlExample.d] -[controlexample/CustomControlExample.d] -[helloworld/HelloWorld1.d] -[helloworld/HelloWorld2.d] -[helloworld/HelloWorld3.d] -[helloworld/HelloWorld4.d] -[helloworld/HelloWorld5.d] -[texteditor/TextEditor.d] - diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/helloworld/HelloWorld1.d --- a/dwtexamples/helloworld/HelloWorld1.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 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 - *******************************************************************************/ -module dwtexamples.helloworld.HelloWorld1; - - -import dwt.widgets.Display; -import dwt.widgets.Shell; - -/* - * This example demonstrates the minimum amount of code required - * to open an DWT Shell and process the events. - */ -void main(){ - Display display = new Display (); - Shell shell = new Shell (display); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/helloworld/HelloWorld2.d --- a/dwtexamples/helloworld/HelloWorld2.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 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 - *******************************************************************************/ -module dwtexamples.helloworld.HelloWorld2; - -import dwt.DWT; -import dwt.widgets.Display; -import dwt.widgets.Label; -import dwt.widgets.Shell; - -/* - * This example builds on HelloWorld1 and demonstrates the minimum amount - * of code required to open an DWT Shell with a Label and process the events. - */ - -void main(){ - Display display = new Display (); - Shell shell = new Shell (display); - Label label = new Label (shell, DWT.CENTER); - label.setText ("Hello_world"); - label.setBounds (shell.getClientArea ()); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/helloworld/HelloWorld3.d --- a/dwtexamples/helloworld/HelloWorld3.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 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 - *******************************************************************************/ -module dwtexamples.helloworld.HelloWorld3; - -import dwt.DWT; -import dwt.events.ControlAdapter; -import dwt.events.ControlEvent; -import dwt.widgets.Display; -import dwt.widgets.Label; -import dwt.widgets.Shell; - -/* - * This example builds on HelloWorld2 and demonstrates how to resize the - * Label when the Shell resizes using a Listener mechanism. - */ - -void main () { - Display display = new Display (); - final Shell shell = new Shell (display); - final Label label = new Label (shell, DWT.CENTER); - label.setText ("Hello_world"); - label.pack(); - shell.addControlListener(new class() ControlAdapter { - public void controlResized(ControlEvent e) { - label.setBounds (shell.getClientArea ()); - } - }); - shell.pack(); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/helloworld/HelloWorld4.d --- a/dwtexamples/helloworld/HelloWorld4.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 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 - *******************************************************************************/ -module dwtexamples.helloworld.HelloWorld4; - -import dwt.DWT; -import dwt.layout.FillLayout; -import dwt.widgets.Display; -import dwt.widgets.Label; -import dwt.widgets.Shell; - -/* - * This example builds on HelloWorld2 and demonstrates how to resize the - * Label when the Shell resizes using a Layout. - */ -void main () { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout(new FillLayout()); - Label label = new Label (shell, DWT.CENTER); - label.setText ("Hello_world"); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/helloworld/HelloWorld5.d --- a/dwtexamples/helloworld/HelloWorld5.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 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 - *******************************************************************************/ -module dwtexamples.helloworld.HelloWorld5; - - -import dwt.events.DisposeEvent; -import dwt.events.DisposeListener; -import dwt.events.PaintEvent; -import dwt.events.PaintListener; -import dwt.graphics.Color; -import dwt.graphics.GC; -import dwt.graphics.Rectangle; -import dwt.widgets.Display; -import dwt.widgets.Shell; - -/* - * This example builds on HelloWorld1 and demonstrates how to draw directly - * on an DWT Control. - */ - -void main () { - Display display = new Display (); - final Color red = new Color(display, 0xFF, 0, 0); - final Shell shell = new Shell (display); - shell.addPaintListener(new class() PaintListener { - public void paintControl(PaintEvent event){ - GC gc = event.gc; - gc.setForeground(red); - Rectangle rect = shell.getClientArea(); - gc.drawRectangle(rect.x + 10, rect.y + 10, rect.width - 20, rect.height - 20); - gc.drawString("Hello_world", rect.x + 20, rect.y + 20); - } - }); - shell.addDisposeListener (new class() DisposeListener { - public void widgetDisposed (DisposeEvent e) { - red.dispose(); - } - }); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/simple.d --- a/dwtexamples/simple.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -module dwtexample.simple; - -import dwt.DWT; -import dwt.events.SelectionEvent; -import dwt.events.SelectionListener; -import dwt.widgets.Button; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Text; - -import tango.io.Stdout; - -void main(){ - - try{ - - Display display = new Display(); - Shell shell = new Shell(display); - shell.setSize(300, 200); - shell.setText("Simple DWT Sample"); - auto btn = new Button( shell, DWT.PUSH ); - btn.setBounds(40, 50, 100, 50); - btn.setText( "hey" ); - - auto txt = new Text(shell, DWT.BORDER); - txt.setBounds(170, 50, 100, 40); - - btn.addSelectionListener(new class () SelectionListener { - public void widgetSelected(SelectionEvent event) { - txt.setText("No problem"); - } - public void widgetDefaultSelected(SelectionEvent event) { - txt.setText("No worries!"); - } - }); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - catch (Exception e) { - Stdout.formatln (e.toString); - } -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/sleak/SleakExample.d --- a/dwtexamples/sleak/SleakExample.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Port to the D programming language - * Frank Benoit - */ -module dwtexamples.sleak.SleakExample; - -import dwt.DWT; -import dwt.graphics.DeviceData; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Canvas; -import dwt.widgets.List; -import dwt.program.Program; -import dwt.graphics.ImageData; -import dwt.graphics.Image; -import dwt.layout.FillLayout; -import dwt.events.PaintListener; -import dwt.events.PaintEvent; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; - -import dwtx.sleak.Sleak; - -import tango.io.Stdout; -version(JIVE){ - import jive.stacktrace; -} - -void main() { - Display display; - Shell shell; - List list; - Canvas canvas; - Image image; - - version( all ){ - DeviceData data = new DeviceData(); - data.tracking = true; - display = new Display(data); - Sleak sleak = new Sleak(); - sleak.open(); - } - else{ - display = new Display(); - } - - shell = new Shell(display); - shell.setLayout(new FillLayout()); - list = new List(shell, DWT.BORDER | DWT.SINGLE | DWT.V_SCROLL | DWT.H_SCROLL); - list.setItems(Program.getExtensions()); - canvas = new Canvas(shell, DWT.BORDER); - canvas.addPaintListener(new class() PaintListener { - public void paintControl(PaintEvent e) { - if (image !is null) { - e.gc.drawImage(image, 0, 0); - } - } - }); - list.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - image = null; // potentially leak one image - char[][] selection = list.getSelection(); - if (selection.length !is 0) { - Program program = Program.findProgram(selection[0]); - if (program !is null) { - ImageData imageData = program.getImageData(); - if (imageData !is null) { - if (image !is null) image.dispose(); - image = new Image(display, imageData); - } - } - } - canvas.redraw(); - } - }); - shell.setSize(shell.computeSize(DWT.DEFAULT, 200)); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/test.d --- a/dwtexamples/test.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -module test; - -import dwt.internal.gtk.c.cairo; -import tango.core.Traits; -import tango.io.Stdout; -import tango.stdc.stdio; - -struct lock { -static void lock() { printf("lock\n");} -static void unlock() { printf("unlock\n");} -} - -const static char[] mm = "Inside outer cairo_version"; - -template NameOfFunc(alias f) { - // Note: highly dependent on the .stringof formatting - // the value begins with "& " which is why the first two chars are cut off - const char[] NameOfFunc = (&f).stringof[2 .. $]; -} - -template ForwardGtkOsCFunc( alias cFunc ) { - alias ParameterTupleOf!(cFunc) P; - alias ReturnTypeOf!(cFunc) R; - mixin("public static R " ~ NameOfFunc!(cFunc) ~ "( P p ){ - lock.lock(); - scope(exit) lock.unlock(); - Stdout (mm).newline; - return cFunc(p); - }"); -} - -public class OS { - mixin ForwardGtkOsCFunc!(cairo_version); - mixin ForwardGtkOsCFunc!(cairo_version_string); -} - -void main() -{ - Stdout ("calling cairo_version...").newline; - int p = OS.cairo_version(); - int i = cairo_version(); - Stdout.formatln("OS.cairo_version() returns: {} cairo_version() returns: {}", p, i ).newline; - printf("OS.cairo_version_string returns: %s\n", cairo_version_string() ); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtexamples/texteditor/Images.d --- a/dwtexamples/texteditor/Images.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/******************************************************************************* - * 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 - * Port to the D programming language: - * Thomas Graber - *******************************************************************************/ -module dwtexamples.texteditor.Images; - -import dwt.dwthelper.InputStream; - -import dwt.graphics.Image; -import dwt.graphics.ImageData; -import dwt.widgets.Display; -import dwt.dwthelper.ByteArrayInputStream; - -import tango.core.Exception; -import tango.io.Stdout; - -public class Images { - - // Bitmap Images - public Image Bold; - public Image Italic; - public Image Underline; - public Image Strikeout; - public Image Red; - public Image Green; - public Image Blue; - public Image Erase; - - Image[] AllBitmaps; - - this () { - } - - public void freeAll () { - for (int i=0; i - *******************************************************************************/ -module dwtexamples.texteditor.TextEditor; - -import dwt.DWT; -import dwt.custom.ExtendedModifyEvent; -import dwt.custom.ExtendedModifyListener; -import dwt.custom.StyleRange; -import dwt.custom.StyledText; -import dwt.events.DisposeEvent; -import dwt.events.DisposeListener; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.graphics.Color; -import dwt.graphics.Font; -import dwt.graphics.FontData; -import dwt.graphics.Point; -import dwt.graphics.RGB; -import dwt.layout.GridData; -import dwt.layout.GridLayout; -import dwt.widgets.Display; -import dwt.widgets.FontDialog; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.Shell; -import dwt.widgets.ToolBar; -import dwt.widgets.ToolItem; -import dwt.widgets.Widget; -import dwt.dwthelper.ResourceBundle; -import dwt.dwthelper.utils; - -import tango.util.collection.ArraySeq; - -import dwtexamples.texteditor.Images; - -version( JIVE ){ - import jive.stacktrace; -} - -/** - */ -public class TextEditor { - Shell shell; - ToolBar toolBar; - StyledText text; - Images images; - alias ArraySeq!(StyleRange) StyleCache; - StyleCache cachedStyles; - - Color RED = null; - Color BLUE = null; - Color GREEN = null; - Font font = null; - ToolItem boldButton, italicButton, underlineButton, strikeoutButton; - - //string resources - static ResourceBundle resources; - private static const char[] resourceData = import( "dwtexamples.texteditor.examples_texteditor.properties" ); - - /* - * static ctor - */ - static this() - { - resources = ResourceBundle.getBundleFromData( resourceData ); - } - - /* - * ctor - */ - this() { - images = new Images(); - } - - /* - * creates edit menu - */ - Menu createEditMenu() { - Menu bar = shell.getMenuBar (); - Menu menu = new Menu (bar); - - MenuItem item = new MenuItem (menu, DWT.PUSH); - item.setText (resources.getString("Cut_menuitem")); - item.setAccelerator(DWT.MOD1 + 'X'); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - handleCutCopy(); - text.cut(); - } - }); - item = new MenuItem (menu, DWT.PUSH); - item.setText (resources.getString("Copy_menuitem")); - item.setAccelerator(DWT.MOD1 + 'C'); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - handleCutCopy(); - text.copy(); - } - }); - item = new MenuItem (menu, DWT.PUSH); - item.setText (resources.getString("Paste_menuitem")); - item.setAccelerator(DWT.MOD1 + 'V'); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - text.paste(); - } - }); - new MenuItem (menu, DWT.SEPARATOR); - item = new MenuItem (menu, DWT.PUSH); - item.setText (resources.getString("Font_menuitem")); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - setFont(); - } - }); - return menu; - } - - /* - * creates file menu - */ - Menu createFileMenu() { - Menu bar = shell.getMenuBar (); - Menu menu = new Menu (bar); - - MenuItem item = new MenuItem (menu, DWT.PUSH); - item.setText (resources.getString("Exit_menuitem")); - item.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - shell.close (); - } - }); - - return menu; - } - - /* - * Set a style - */ - void setStyle(Widget widget) { - Point sel = text.getSelectionRange(); - if ((sel is null) || (sel.y is 0)) return; - StyleRange style; - for (int i = sel.x; i 0) { - StyleRange lastStyle = cachedStyles.tail(); - if (lastStyle.similarTo(style) && lastStyle.start + lastStyle.length is style.start) { - lastStyle.length++; - } else { - cachedStyles.append(style); - } - } else { - cachedStyles.append(style); - } - } - } - } - - /* - * handle modify - */ - void handleExtendedModify(ExtendedModifyEvent event) { - if (event.length is 0) return; - StyleRange style; - //PORTING event.length is char count, but it needs to decide on codepoint count - auto cont = text.getTextRange(event.start, event.length); - if ( codepointCount(cont) is 1 || cont == text.getLineDelimiter()) { - // Have the new text take on the style of the text to its right (during - // typing) if no style information is active. - int caretOffset = text.getCaretOffset(); - style = null; - if (caretOffset < text.getCharCount()) style = text.getStyleRangeAtOffset(caretOffset); - if (style !is null) { - style = cast(StyleRange) style.clone (); - style.start = event.start; - style.length = event.length; - } else { - style = new StyleRange(event.start, event.length, null, null, DWT.NORMAL); - } - if (boldButton.getSelection()) style.fontStyle |= DWT.BOLD; - if (italicButton.getSelection()) style.fontStyle |= DWT.ITALIC; - style.underline = underlineButton.getSelection(); - style.strikeout = strikeoutButton.getSelection(); - if (!style.isUnstyled()) text.setStyleRange(style); - } else { - // paste occurring, have text take on the styles it had when it was - // cut/copied - foreach (style; cachedStyles) { - StyleRange newStyle = cast(StyleRange)style.clone(); - newStyle.start = style.start + event.start; - text.setStyleRange(newStyle); - } - } - } - - /* - * opens the shell - */ - public Shell open (Display display) { - createShell (display); - createMenuBar (); - createToolBar (); - createStyledText (); - shell.setSize(500, 300); - shell.open (); - return shell; - } - - /* - * set the font for styled text widget - */ - void setFont() { - FontDialog fontDialog = new FontDialog(shell); - fontDialog.setFontList((text.getFont()).getFontData()); - FontData fontData = fontDialog.open(); - if (fontData !is null) { - Font newFont = new Font(shell.getDisplay(), fontData); - text.setFont(newFont); - if (font !is null) font.dispose(); - font = newFont; - } - } - - /* - * initialize the colors - */ - void initializeColors() { - Display display = Display.getDefault(); - RED = new Color (display, new RGB(255,0,0)); - BLUE = new Color (display, new RGB(0,0,255)); - GREEN = new Color (display, new RGB(0,255,0)); - } -} - -/* - * main function - */ -public void main (char[][] args) { - Display display = new Display (); - TextEditor example = new TextEditor (); - Shell shell = example.open (display); - while (!shell.isDisposed ()) - if (!display.readAndDispatch ()) display.sleep (); - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/button/Snippet293.d --- a/dwtsnippets/button/Snippet293.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 gmail.com - *******************************************************************************/ -module dwt.snippets; - -/* - * create a tri-state button. - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.layout.GridLayout; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Button; - -void main() { - auto display = new Display(); - auto shell = new Shell(display); - shell.setLayout(new GridLayout()); - - auto b1 = new Button (shell, DWT.CHECK); - b1.setText("State 1"); - b1.setSelection(true); - - auto b2 = new Button (shell, DWT.CHECK); - b2.setText("State 2"); - b2.setSelection(false); - - auto b3 = new Button (shell, DWT.CHECK); - b3.setText("State 3"); - b3.setSelection(true); - - // This function does not appear in the api for swt 3.3 - // b3.setGrayed(true); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/combo/Snippet26.d --- a/dwtsnippets/combo/Snippet26.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/******************************************************************************* - * 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 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 (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/composite/Snippet9.d --- a/dwtsnippets/composite/Snippet9.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -/******************************************************************************* - * 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 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; -import dwt.dwthelper.utils; - -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 (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/control/Snippet25.d --- a/dwtsnippets/control/Snippet25.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,154 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.control.Snippet25; - -/* - * Control example snippet: print key state, code and character - * - * For a list of all DWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @since 3.0 - */ -import dwt.DWT; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Listener; -import dwt.widgets.Event; - -import tango.io.Stdout; -import tango.text.convert.Format; - -static char[] stateMask (int stateMask) { - char[] string = ""; - if ((stateMask & DWT.CTRL) != 0) string ~= " CTRL"; - if ((stateMask & DWT.ALT) != 0) string ~= " ALT"; - if ((stateMask & DWT.SHIFT) != 0) string ~= " SHIFT"; - if ((stateMask & DWT.COMMAND) != 0) string ~= " COMMAND"; - return string; -} - -static char[] character (char character) { - switch (character) { - case 0: return "'\\0'"; - case DWT.BS: return "'\\b'"; - case DWT.CR: return "'\\r'"; - case DWT.DEL: return "DEL"; - case DWT.ESC: return "ESC"; - case DWT.LF: return "'\\n'"; - case DWT.TAB: return "'\\t'"; - default: - return "'" ~ character ~"'"; - } -} - -static char[] keyCode (int keyCode) { - switch (keyCode) { - - /* Keyboard and Mouse Masks */ - case DWT.ALT: return "ALT"; - case DWT.SHIFT: return "SHIFT"; - case DWT.CONTROL: return "CONTROL"; - case DWT.COMMAND: return "COMMAND"; - - /* Non-Numeric Keypad Keys */ - case DWT.ARROW_UP: return "ARROW_UP"; - case DWT.ARROW_DOWN: return "ARROW_DOWN"; - case DWT.ARROW_LEFT: return "ARROW_LEFT"; - case DWT.ARROW_RIGHT: return "ARROW_RIGHT"; - case DWT.PAGE_UP: return "PAGE_UP"; - case DWT.PAGE_DOWN: return "PAGE_DOWN"; - case DWT.HOME: return "HOME"; - case DWT.END: return "END"; - case DWT.INSERT: return "INSERT"; - - /* Virtual and Ascii Keys */ - case DWT.BS: return "BS"; - case DWT.CR: return "CR"; - case DWT.DEL: return "DEL"; - case DWT.ESC: return "ESC"; - case DWT.LF: return "LF"; - case DWT.TAB: return "TAB"; - - /* Functions Keys */ - case DWT.F1: return "F1"; - case DWT.F2: return "F2"; - case DWT.F3: return "F3"; - case DWT.F4: return "F4"; - case DWT.F5: return "F5"; - case DWT.F6: return "F6"; - case DWT.F7: return "F7"; - case DWT.F8: return "F8"; - case DWT.F9: return "F9"; - case DWT.F10: return "F10"; - case DWT.F11: return "F11"; - case DWT.F12: return "F12"; - case DWT.F13: return "F13"; - case DWT.F14: return "F14"; - case DWT.F15: return "F15"; - - /* Numeric Keypad Keys */ - case DWT.KEYPAD_ADD: return "KEYPAD_ADD"; - case DWT.KEYPAD_SUBTRACT: return "KEYPAD_SUBTRACT"; - case DWT.KEYPAD_MULTIPLY: return "KEYPAD_MULTIPLY"; - case DWT.KEYPAD_DIVIDE: return "KEYPAD_DIVIDE"; - case DWT.KEYPAD_DECIMAL: return "KEYPAD_DECIMAL"; - case DWT.KEYPAD_CR: return "KEYPAD_CR"; - case DWT.KEYPAD_0: return "KEYPAD_0"; - case DWT.KEYPAD_1: return "KEYPAD_1"; - case DWT.KEYPAD_2: return "KEYPAD_2"; - case DWT.KEYPAD_3: return "KEYPAD_3"; - case DWT.KEYPAD_4: return "KEYPAD_4"; - case DWT.KEYPAD_5: return "KEYPAD_5"; - case DWT.KEYPAD_6: return "KEYPAD_6"; - case DWT.KEYPAD_7: return "KEYPAD_7"; - case DWT.KEYPAD_8: return "KEYPAD_8"; - case DWT.KEYPAD_9: return "KEYPAD_9"; - case DWT.KEYPAD_EQUAL: return "KEYPAD_EQUAL"; - - /* Other keys */ - case DWT.CAPS_LOCK: return "CAPS_LOCK"; - case DWT.NUM_LOCK: return "NUM_LOCK"; - case DWT.SCROLL_LOCK: return "SCROLL_LOCK"; - case DWT.PAUSE: return "PAUSE"; - case DWT.BREAK: return "BREAK"; - case DWT.PRINT_SCREEN: return "PRINT_SCREEN"; - case DWT.HELP: return "HELP"; - - default: - return character (cast(char) keyCode); - } - -} - -void main () { - Display display = new Display (); - Shell shell = new Shell (display); - Listener listener = new class Listener { - public void handleEvent (Event e) { - char[] string = e.type == DWT.KeyDown ? "DOWN:" : "UP :"; - string ~= Format("stateMask=0x{:x}{},", e.stateMask, stateMask (e.stateMask)); - string ~= Format(" keyCode=0x{:x} {},", e.keyCode, keyCode (e.keyCode)); - string ~= Format(" character=0x{:x} {}", e.character, character (e.character)); - Stdout.formatln (string); - } - }; - shell.addListener (DWT.KeyDown, listener); - shell.addListener (DWT.KeyUp, listener); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/control/Snippet62.d --- a/dwtsnippets/control/Snippet62.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ - module dwtsnippets.control.Snippet62; - - /* - * Control example snippet: print mouse state and button (down, move, up) - * - * 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.Listener; -import dwt.widgets.Event; - -import tango.io.Stdout; -import tango.util.Convert; - -static char[] stateMask (int stateMask) { - char[] str = ""; - if ((stateMask & DWT.CTRL) != 0) str ~= " CTRL"; - if ((stateMask & DWT.ALT) != 0) str ~= " ALT"; - if ((stateMask & DWT.SHIFT) != 0) str ~= " SHIFT"; - if ((stateMask & DWT.COMMAND) != 0) str ~= " COMMAND"; - return str; -} - -void main () { - Display display = new Display (); - final Shell shell = new Shell (display); - Listener listener = new class Listener { - public void handleEvent (Event e) { - char[] str = "Unknown"; - switch (e.type) { - case DWT.MouseDown: str = "DOWN"; break; - case DWT.MouseMove: str = "MOVE"; break; - case DWT.MouseUp: str = "UP"; break; - } - str ~=": button: " ~ to!(char[])(e.button) ~ ", "; - str ~= "stateMask=0x" ~ to!(char[])(e.stateMask) - ~ stateMask (e.stateMask) - ~ ", x=" ~ to!(char[])(e.x) ~ ", y=" ~ to!(char[])(e.y); - if ((e.stateMask & DWT.BUTTON1) != 0) str ~= " BUTTON1"; - if ((e.stateMask & DWT.BUTTON2) != 0) str ~= " BUTTON2"; - if ((e.stateMask & DWT.BUTTON3) != 0) str ~= " BUTTON3"; - if ((e.stateMask & DWT.BUTTON4) != 0) str ~= " BUTTON4"; - if ((e.stateMask & DWT.BUTTON5) != 0) str ~= " BUTTON5"; - Stdout.formatln (str); - } - }; - shell.addListener (DWT.MouseDown, listener); - shell.addListener (DWT.MouseMove, listener); - shell.addListener (DWT.MouseUp, listener); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/coolbar/Snippet140.d --- a/dwtsnippets/coolbar/Snippet140.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.coolbar.Snippet140; - -/* - * CoolBar example snippet: drop-down a chevron menu containing hidden tool items - * - * 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.Display; -import dwt.widgets.Shell; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.ToolBar; -import dwt.widgets.ToolItem; -import dwt.widgets.CoolBar; -import dwt.widgets.CoolItem; -import dwt.events.SelectionEvent; -import dwt.events.SelectionAdapter; -import dwt.layout.GridLayout; -import dwt.layout.GridData; - -import tango.util.Convert; - -static Display display; -static Shell shell; -static CoolBar coolBar; -static Menu chevronMenu = null; - - -void main () { - display = new Display (); - shell = new Shell (display); - shell.setLayout(new GridLayout()); - coolBar = new CoolBar(shell, DWT.FLAT | DWT.BORDER); - coolBar.setLayoutData(new GridData(GridData.FILL_BOTH)); - ToolBar toolBar = new ToolBar(coolBar, DWT.FLAT | DWT.WRAP); - int minWidth = 0; - for (int j = 0; j < 5; j++) { - int width = 0; - ToolItem item = new ToolItem(toolBar, DWT.PUSH); - item.setText("B" ~ to!(char[])(j)); - width = item.getWidth(); - /* find the width of the widest tool */ - if (width > minWidth) minWidth = width; - } - CoolItem coolItem = new CoolItem(coolBar, DWT.DROP_DOWN); - coolItem.setControl(toolBar); - Point size = toolBar.computeSize(DWT.DEFAULT, DWT.DEFAULT); - Point coolSize = coolItem.computeSize (size.x, size.y); - coolItem.setMinimumSize(minWidth, coolSize.y); - coolItem.setPreferredSize(coolSize); - coolItem.setSize(coolSize); - coolItem.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - if (event.detail == DWT.ARROW) { - CoolItem item = cast(CoolItem) event.widget; - Rectangle itemBounds = item.getBounds (); - Point pt = coolBar.toDisplay(new Point(itemBounds.x, itemBounds.y)); - itemBounds.x = pt.x; - itemBounds.y = pt.y; - ToolBar bar = cast(ToolBar) item.getControl (); - ToolItem[] tools = bar.getItems (); - - int i = 0; - while (i < tools.length) { - Rectangle toolBounds = tools[i].getBounds (); - pt = bar.toDisplay(new Point(toolBounds.x, toolBounds.y)); - toolBounds.x = pt.x; - toolBounds.y = pt.y; - - /* Figure out the visible portion of the tool by looking at the - * intersection of the tool bounds with the cool item bounds. - */ - Rectangle intersection = itemBounds.intersection (toolBounds); - - /* If the tool is not completely within the cool item bounds, then it - * is partially hidden, and all remaining tools are completely hidden. - */ - if (intersection != toolBounds) break; - i++; - } - - /* Create a menu with items for each of the completely hidden buttons. */ - if (chevronMenu !is null) chevronMenu.dispose(); - chevronMenu = new Menu (coolBar); - for (int j = i; j < tools.length; j++) { - MenuItem menuItem = new MenuItem (chevronMenu, DWT.PUSH); - menuItem.setText (tools[j].getText()); - } - - /* Drop down the menu below the chevron, with the left edges aligned. */ - pt = coolBar.toDisplay(new Point(event.x, event.y)); - chevronMenu.setLocation (pt.x, pt.y); - chevronMenu.setVisible (true); - } - } - }); - - shell.pack(); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/coolbar/Snippet150.d --- a/dwtsnippets/coolbar/Snippet150.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.coolbar.Snippet150; - -/* - * CoolBar example snippet: create a coolbar (relayout when resized) - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @since 3.0 - */ -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.ToolBar; -import dwt.widgets.ToolItem; -import dwt.widgets.Shell; -import dwt.widgets.Text; -import dwt.widgets.Event; -import dwt.widgets.Listener; -import dwt.layout.FormLayout; -import dwt.layout.FormData; -import dwt.layout.FormAttachment; - -import tango.util.Convert; - -int itemCount; -CoolItem createItem(CoolBar coolBar, int count) { - ToolBar toolBar = new ToolBar(coolBar, DWT.FLAT); - for (int i = 0; i < count; i++) { - ToolItem item = new ToolItem(toolBar, DWT.PUSH); - item.setText(to!(char[])(itemCount++) ~""); - } - toolBar.pack(); - Point size = toolBar.getSize(); - CoolItem item = new CoolItem(coolBar, DWT.NONE); - item.setControl(toolBar); - Point preferred = item.computeSize(size.x, size.y); - item.setPreferredSize(preferred); - return item; -} - -void main () { - - Display display = new Display(); - final Shell shell = new Shell(display); - CoolBar coolBar = new CoolBar(shell, DWT.NONE); - createItem(coolBar, 3); - createItem(coolBar, 2); - createItem(coolBar, 3); - createItem(coolBar, 4); - int style = DWT.BORDER | DWT.H_SCROLL | DWT.V_SCROLL; - Text text = new Text(shell, style); - FormLayout layout = new FormLayout(); - shell.setLayout(layout); - FormData coolData = new FormData(); - coolData.left = new FormAttachment(0); - coolData.right = new FormAttachment(100); - coolData.top = new FormAttachment(0); - coolBar.setLayoutData(coolData); - coolBar.addListener(DWT.Resize, new class() Listener { - void handleEvent(Event event) { - shell.layout(); - } - }); - FormData textData = new FormData(); - textData.left = new FormAttachment(0); - textData.right = new FormAttachment(100); - textData.top = new FormAttachment(coolBar); - textData.bottom = new FormAttachment(100); - text.setLayoutData(textData); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); - -} \ No newline at end of file diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/coolbar/Snippet20.d --- a/dwtsnippets/coolbar/Snippet20.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/******************************************************************************* - * 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 gmail.com - *******************************************************************************/ -module dwtsnippets.coolbar.Snippet20; - -/* - * CoolBar example snippet: create a cool bar - * - * For a list of all SWT 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)); - auto size = button.computeSize (DWT.DEFAULT, DWT.DEFAULT); - item.setPreferredSize (item.computeSize (size.x, size.y)); - item.setControl (button); - } - bar.pack (); - shell.setSize(300, 100); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/ctabfolder/Snippet165.d --- a/dwtsnippets/ctabfolder/Snippet165.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/******************************************************************************* - * 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 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 (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/directorydialog/Snippet33.d --- a/dwtsnippets/directorydialog/Snippet33.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/******************************************************************************* - * 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 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 (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/dsss.conf --- a/dwtsnippets/dsss.conf Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -# DWT dwt-samples/dwtsnippets directory - -[*] -buildflags+=-g -gc -buildflags+=-J$LIB_PREFIX/res -J../res -I.. - -version(Windows) { - # if no console window is wanted/needed use -version=gui - version(gui) { - buildflags+= -L/SUBSYSTEM:windows:5 - } else { - buildflags+= -L/SUBSYSTEM:console:5 - } - buildflags+= -L/rc:dwt -} - - - -[button/Snippet293.d] -[control/Snippet25.d] -[control/Snippet62.d] -[combo/Snippet26.d] -[composite/Snippet9.d] -[coolbar/Snippet20.d] -[coolbar/Snippet140.d] -[coolbar/Snippet150.d] -[ctabfolder/Snippet165.d] -[directorydialog/Snippet33.d] -[expandbar/Snippet223.d] -[filedialog/Snippet72.d] -[gc/Snippet10.d] -[gc/Snippet66.d] -[gc/Snippet207.d] -[gc/Snippet215.d] -[menu/Snippet29.d] -[menu/Snippet97.d] -[menu/Snippet152.d] -[menu/Snippet286.d] -[program/Snippet32.d] -[sash/Snippet107.d] -[sashform/Snippet109.d] -[shell/Snippet134.d] -[shell/Snippet138.d] -[spinner/Snippet184.d] -[spinner/Snippet190.d] -[styledtext/Snippet163.d] -[styledtext/Snippet189.d] -[table/Snippet38.d] -[table/Snippet144.d] -[text/Snippet258.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] - -version(Derelict){ - [opengl] - type=subdir -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/expandbar/Snippet223.d --- a/dwtsnippets/expandbar/Snippet223.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -/******************************************************************************* - * 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 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(); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/filedialog/Snippet72.d --- a/dwtsnippets/filedialog/Snippet72.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.filedialog.Snippet72; - -/* - * FileDialog example snippet: prompt for a file name (to save) - * - * 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.Shell; -import dwt.widgets.FileDialog; - -import tango.io.Stdout; - -void main () { - Display display = new Display (); - Shell shell = new Shell (display); - shell.open (); - FileDialog dialog = new FileDialog (shell, DWT.SAVE); - dialog.setFilterNames (["Batch Files", "All Files (*.*)"]); - dialog.setFilterExtensions (["*.bat", "*.*"]); //Windows wild cards - dialog.setFilterPath ("c:\\"); //Windows path - dialog.setFileName ("fred.bat"); - Stdout.formatln ("Save to: {}", dialog.open ()); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/gc/Snippet10.d --- a/dwtsnippets/gc/Snippet10.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/******************************************************************************* - * 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 - * Port to the D programming language: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.gc.Snippet10; - -/* - * Draw using transformations, paths and alpha blending - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @since 3.1 - */ -import dwt.DWT; -import dwt.graphics.GC; -import dwt.graphics.Path; -import dwt.graphics.Transform; -import dwt.graphics.Font; -import dwt.graphics.FontData; -import dwt.graphics.Image; -import dwt.graphics.Rectangle; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Listener; -import dwt.widgets.Event; - - -void main() { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setText("Advanced Graphics"); - FontData fd = shell.getFont().getFontData()[0]; - Font font = new Font(display, fd.getName(), 60., DWT.BOLD | DWT.ITALIC); - Image image = new Image(display, 640, 480); - Rectangle rect = image.getBounds(); - GC gc = new GC(image); - gc.setBackground(display.getSystemColor(DWT.COLOR_RED)); - gc.fillOval(rect.x, rect.y, rect.width, rect.height); - gc.dispose(); - shell.addListener(DWT.Paint, new class() Listener { - public void handleEvent(Event event) { - GC gc = event.gc; - Transform tr = new Transform(display); - tr.translate(50, 120); - tr.rotate(-30); - gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2); - gc.setAlpha(100); - gc.setTransform(tr); - Path path = new Path(display); - path.addString("DWT", 0, 0, font); - gc.setBackground(display.getSystemColor(DWT.COLOR_GREEN)); - gc.setForeground(display.getSystemColor(DWT.COLOR_BLUE)); - gc.fillPath(path); - gc.drawPath(path); - tr.dispose(); - path.dispose(); - } - }); - shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2)); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - image.dispose(); - font.dispose(); - display.dispose(); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/gc/Snippet207.d --- a/dwtsnippets/gc/Snippet207.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -/******************************************************************************* - * 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 - * Port to the D programming language: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.gc.Snippet207; - -/* - * Use transformation matrices to reflect, rotate and shear images - * - * 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.GC; -import dwt.graphics.Transform; -import dwt.graphics.Font; -import dwt.graphics.Rectangle; -import dwt.graphics.Image; -import dwt.layout.FillLayout; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Canvas; - -import Math=tango.math.Math; - -void main() { - Display display = new Display(); - - Image image = new Image(display, 110, 60); - GC gc = new GC(image); - Font font = new Font(display, "Times", 30., DWT.BOLD); - gc.setFont(font); - gc.setBackground(display.getSystemColor(DWT.COLOR_RED)); - gc.fillRectangle(0, 0, 110, 60); - gc.setForeground(display.getSystemColor(DWT.COLOR_WHITE)); - gc.drawText("DWT", 10, 10, true); - font.dispose(); - gc.dispose(); - - Rectangle rect = image.getBounds(); - Shell shell = new Shell(display); - shell.setText("Matrix Tranformations"); - shell.setLayout(new FillLayout()); - Canvas canvas = new Canvas(shell, DWT.DOUBLE_BUFFERED); - canvas.addPaintListener(new class() PaintListener { - public void paintControl(PaintEvent e) { - GC gc = e.gc; - gc.setAdvanced(true); - if (!gc.getAdvanced()){ - gc.drawText("Advanced graphics not supported", 30, 30, true); - return; - } - - // Original image - int x = 30, y = 30; - gc.drawImage(image, x, y); - x += rect.width + 30; - - Transform transform = new Transform(display); - - // Note that the tranform is applied to the whole GC therefore - // the coordinates need to be adjusted too. - - // Reflect around the y axis. - transform.setElements(-1, 0, 0, 1, 0 ,0); - gc.setTransform(transform); - gc.drawImage(image, -1*x-rect.width, y); - - x = 30; y += rect.height + 30; - - // Reflect around the x axis. - transform.setElements(1, 0, 0, -1, 0, 0); - gc.setTransform(transform); - gc.drawImage(image, x, -1*y-rect.height); - - x += rect.width + 30; - - // Reflect around the x and y axes - transform.setElements(-1, 0, 0, -1, 0, 0); - gc.setTransform(transform); - gc.drawImage(image, -1*x-rect.width, -1*y-rect.height); - - x = 30; y += rect.height + 30; - - // Shear in the x-direction - transform.setElements(1, 0, -1, 1, 0, 0); - gc.setTransform(transform); - gc.drawImage(image, 300, y); - - // Shear in y-direction - transform.setElements(1, -1, 0, 1, 0, 0); - gc.setTransform(transform); - gc.drawImage(image, 150, 475); - - // Rotate by 45 degrees - float cos45 = Math.cos(45); - float sin45 = Math.sin(45); - transform.setElements(cos45, sin45, -sin45, cos45, 0, 0); - gc.setTransform(transform); - gc.drawImage(image, 350, 100); - - transform.dispose(); - } - }); - - shell.setSize(350, 550); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - image.dispose(); - display.dispose(); -} - - - - - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/gc/Snippet215.d --- a/dwtsnippets/gc/Snippet215.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.gc.Snippet215; - -/* - * GC example snippet: take a screen shot with a GC - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.graphics.GC; -import dwt.graphics.Image; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Listener; -import dwt.widgets.Event; -import dwt.widgets.Button; -import dwt.widgets.Canvas; -import dwt.custom.ScrolledComposite; -import dwt.layout.FillLayout; -import dwt.events.PaintListener; - -Image image; - -void main() { - final Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - Button button = new Button(shell, DWT.PUSH); - button.setText("Capture"); - button.addListener(DWT.Selection, new class() Listener { - public void handleEvent(Event event) { - - /* Take the screen shot */ - GC gc = new GC(display); - image = new Image(display, display.getBounds()); - gc.copyArea(image, 0, 0); - gc.dispose(); - - Shell popup = new Shell(shell, DWT.SHELL_TRIM); - popup.setLayout(new FillLayout()); - popup.setText("Image"); - popup.setBounds(50, 50, 200, 200); - popup.addListener(DWT.Close, new class() Listener { - public void handleEvent(Event e) { - image.dispose(); - } - }); - - ScrolledComposite sc = new ScrolledComposite (popup, DWT.V_SCROLL | DWT.H_SCROLL); - Canvas canvas = new Canvas(sc, DWT.NONE); - sc.setContent(canvas); - canvas.setBounds(display.getBounds ()); - canvas.addPaintListener(new class() PaintListener { - public void paintControl(PaintEvent e) { - e.gc.drawImage(image, 0, 0); - } - }); - popup.open(); - } - }); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/gc/Snippet66.d --- a/dwtsnippets/gc/Snippet66.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.gc.Snippet66; - -/* - * GC example snippet: implement a simple scribble program - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.graphics.GC; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Listener; -import dwt.widgets.Event; - -void main () { - Display display = new Display (); - final Shell shell = new Shell (display); - Listener listener = new class() Listener { - int lastX = 0, lastY = 0; - public void handleEvent (Event event) { - switch (event.type) { - case DWT.MouseMove: - if ((event.stateMask & DWT.BUTTON1) == 0) break; - GC gc = new GC (shell); - gc.drawLine (lastX, lastY, event.x, event.y); - gc.dispose (); - //FALL THROUGH - case DWT.MouseDown: - lastX = event.x; - lastY = event.y; - break; - } - } - }; - shell.addListener (DWT.MouseDown, listener); - shell.addListener (DWT.MouseMove, listener); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/menu/Snippet152.d --- a/dwtsnippets/menu/Snippet152.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.menu.Snippet152; - -/* - * Control example snippet: update a status line when an item is armed - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @since 3.0 - */ - -import dwt.DWT; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Event; -import dwt.widgets.Listener; -import dwt.widgets.Label; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.layout.FormLayout; -import dwt.layout.FormData; -import dwt.layout.FormAttachment; - -void main() { - Display display = new Display(); - Shell shell = new Shell(display); - FormLayout layout = new FormLayout(); - shell.setLayout(layout); - Label label = new Label(shell, DWT.BORDER); - Listener armListener = new class Listener { - public void handleEvent(Event event) { - MenuItem item = cast(MenuItem) event.widget; - label.setText(item.getText()); - label.update(); - } - }; - Listener showListener = new class Listener { - public void handleEvent(Event event) { - Menu menu = cast(Menu) event.widget; - MenuItem item = menu.getParentItem(); - if (item !is null) { - label.setText(item.getText()); - label.update(); - } - } - }; - Listener hideListener = new class Listener { - public void handleEvent(Event event) { - label.setText(""); - label.update(); - } - }; - FormData labelData = new FormData(); - labelData.left = new FormAttachment(0); - labelData.right = new FormAttachment(100); - labelData.bottom = new FormAttachment(100); - label.setLayoutData(labelData); - Menu menuBar = new Menu(shell, DWT.BAR); - shell.setMenuBar(menuBar); - MenuItem fileItem = new MenuItem(menuBar, DWT.CASCADE); - fileItem.setText("File"); - fileItem.addListener(DWT.Arm, armListener); - MenuItem editItem = new MenuItem(menuBar, DWT.CASCADE); - editItem.setText("Edit"); - editItem.addListener(DWT.Arm, armListener); - Menu fileMenu = new Menu(shell, DWT.DROP_DOWN); - fileMenu.addListener(DWT.Hide, hideListener); - fileMenu.addListener(DWT.Show, showListener); - fileItem.setMenu(fileMenu); - char[][] fileStrings = [ "New", "Close", "Exit" ]; - for (int i = 0; i < fileStrings.length; i++) { - MenuItem item = new MenuItem(fileMenu, DWT.PUSH); - item.setText(fileStrings[i]); - item.addListener(DWT.Arm, armListener); - } - Menu editMenu = new Menu(shell, DWT.DROP_DOWN); - editMenu.addListener(DWT.Hide, hideListener); - editMenu.addListener(DWT.Show, showListener); - char[][] editStrings = [ "Cut", "Copy", "Paste" ]; - editItem.setMenu(editMenu); - for (int i = 0; i < editStrings.length; i++) { - MenuItem item = new MenuItem(editMenu, DWT.PUSH); - item.setText(editStrings[i]); - item.addListener(DWT.Arm, armListener); - } - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/menu/Snippet286.d --- a/dwtsnippets/menu/Snippet286.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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 - *******************************************************************************/ -module dwtsnippets.menu.Snippet286; - -/* - * use a menu item's armListener to update a status line. - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.events.ArmEvent; -import dwt.events.ArmListener; -import dwt.layout.GridLayout; -import dwt.layout.GridData; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Canvas; -import dwt.widgets.Label; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; - -import tango.util.Convert; - - -void main() { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new GridLayout()); - - Canvas blankCanvas = new Canvas(shell, DWT.BORDER); - blankCanvas.setLayoutData(new GridData(200, 200)); - Label statusLine = new Label(shell, DWT.NONE); - statusLine.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, true, false)); - - Menu bar = new Menu (shell, DWT.BAR); - shell.setMenuBar (bar); - - MenuItem menuItem = new MenuItem (bar, DWT.CASCADE); - menuItem.setText ("Test"); - Menu menu = new Menu(bar); - menuItem.setMenu (menu); - - for (int i = 0; i < 5; i++) { - MenuItem item = new MenuItem (menu, DWT.PUSH); - item.setText ("Item " ~ to!(char[])(i)); - item.addArmListener(new class ArmListener { - public void widgetArmed(ArmEvent e) { - statusLine.setText((cast(MenuItem)e.getSource()).getText()); - } - }); - } - - shell.pack(); - shell.open(); - - while(!shell.isDisposed()) { - if(!display.readAndDispatch()) display.sleep(); - } -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/menu/Snippet29.d --- a/dwtsnippets/menu/Snippet29.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/******************************************************************************* - * 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 gmail.com - *******************************************************************************/ -module dwtsnippets.menu.Snippet29; - -/* - * Menu example snippet: create a bar and pull down menu (accelerators, mnemonics) - * - * 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.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.Shell; - -import tango.io.Stdout; - -void main () { - auto display = new Display (); - auto shell = new Shell (display); - auto bar = new Menu (shell, DWT.BAR); - shell.setMenuBar (bar); - auto fileItem = new MenuItem (bar, DWT.CASCADE); - fileItem.setText ("&File"); - auto submenu = new Menu (shell, DWT.DROP_DOWN); - fileItem.setMenu (submenu); - auto item = new MenuItem (submenu, DWT.PUSH); - item.addListener (DWT.Selection, new class Listener { - public void handleEvent (Event e) { - Stdout("Select All").newline; - } - }); - item.setText ("Select &All\tCtrl+A"); - item.setAccelerator (DWT.CTRL + 'A'); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/menu/Snippet97.d --- a/dwtsnippets/menu/Snippet97.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/******************************************************************************* - * 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 gmail.com - *******************************************************************************/ -module dwtsnippets.menu.Snippet97; - -/* - * Menu example snippet: fill a menu dynamically (when menu shown) - * Select items then right click to show menu. - * - * 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.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.Shell; -import dwt.widgets.Tree; -import dwt.widgets.TreeItem; - -import tango.util.Convert; - -void main () { - auto display = new Display (); - auto shell = new Shell (display); - auto tree = new Tree (shell, DWT.BORDER | DWT.MULTI); - auto menu = new Menu (shell, DWT.POP_UP); - tree.setMenu (menu); - for (int i=0; i<12; i++) { - auto item = new TreeItem (tree, DWT.NONE); - item.setText ("Item " ~ to!(char[])(i)); - } - menu.addListener (DWT.Show, new class Listener { - public void handleEvent (Event event) { - auto menuItems = menu.getItems (); - foreach (item; menuItems) { - item.dispose (); - } - auto treeItems = tree.getSelection (); - foreach (item; treeItems) { - auto menuItem = new MenuItem (menu, DWT.PUSH); - menuItem.setText (item.getText ()); - } - } - }); - tree.setSize (200, 200); - shell.setSize (300, 300); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/opengl/Readme.txt --- a/dwtsnippets/opengl/Readme.txt Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -opengl_test.d -- based on snippet195.java - -Build dependencies: - -* DerelictGL and DerelictGLU -- Install both of these with dsss OR have the derelict source in your include path using the "-I" command line flag. You may also have to add DerelictUtil to your include path. - -* Import libraries provided via dwt-win projects wiki (www.dsource.org/project/dwt-win): -These will include glu32.lib and opengl32.lib (win32 version). Place these in your library path, ie usually in \dmd\lib - -* Make sure that dwt library is either built and installed with dsss or that you have dwt source in your include path using the "-I" command line flag. - ------------------------------------- - -If you have installed all required libraries with dsss, then you should be able to just do a "dsss build snippets\opengl_test1.d" - - - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/opengl/Snippet174.d --- a/dwtsnippets/opengl/Snippet174.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/******************************************************************************* - * 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: - * Sebastian Davids - initial implementation - * IBM Corporation - * Port to the D programming language: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.opengl.Snippet174; - -/* - * SWT OpenGL snippet: draw a square - * - * This snippet requires the experimental org.eclipse.swt.opengl plugin, which - * is not included in SWT by default and should only be used with versions of - * SWT prior to 3.2. For information on using OpenGL in SWT see - * http://www.eclipse.org/swt/opengl/ . - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @since 3.2 - */ -import dwt.DWT; -import dwt.dwthelper.Runnable; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.graphics.Rectangle; -import dwt.events.ControlEvent; -import dwt.events.ControlAdapter; -import dwt.layout.FillLayout; -import dwt.opengl.GLCanvas; -import dwt.opengl.GLData; - -import derelict.opengl.gl; -import derelict.opengl.glu; - -import Math = tango.math.Math; - -public static void main() -{ - DerelictGL.load(); - DerelictGLU.load(); - - Display display = new Display(); - Shell shell = new Shell(display); - shell.setText("OpenGL in DWT"); - shell.setLayout(new FillLayout()); - GLData data = new GLData(); - data.doubleBuffer = true; - final GLCanvas canvas = new GLCanvas(shell, DWT.NO_BACKGROUND, data); - canvas.addControlListener(new class ControlAdapter { - public void controlResized(ControlEvent e) { - resize(canvas); - } - }); - init(canvas); - (new class Runnable { - public void run() { - if (canvas.isDisposed()) return; - render(); - canvas.swapBuffers(); - canvas.getDisplay().timerExec(15, this); - } - }).run(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} - -static void init(GLCanvas canvas) { - canvas.setCurrent(); - resize(canvas); - glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - glColor3f(0.0f, 0.0f, 0.0f); - glClearDepth(1.0f); - glEnable(GL_DEPTH_TEST); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); -} - -static void render() { - static int rot = 0; - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glLoadIdentity(); - glTranslatef(0.0f, 0.0f, -6.0f); - glRotatef(rot++, 0,0,1); - rot %= 360; - glBegin(GL_QUADS); - glVertex3f(-1.0f, 1.0f, 0.0f); - glVertex3f(1.0f, 1.0f, 0.0f); - glVertex3f(1.0f, -1.0f, 0.0f); - glVertex3f(-1.0f, -1.0f, 0.0f); - glEnd(); -} - -static void resize(GLCanvas canvas) { - canvas.setCurrent(); - Rectangle rect = canvas.getClientArea(); - int width = rect.width; - int height = Math.max(rect.height, 1); - glViewport(0, 0, width, height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - float aspect = cast(float) width / cast(float) height; - gluPerspective(45.0f, aspect, 0.5f, 400.0f); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/opengl/Snippet195.d --- a/dwtsnippets/opengl/Snippet195.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,141 +0,0 @@ -/******************************************************************************* - * 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 - * Port to the D Programming Language: - * John Reimer - *******************************************************************************/ - -module dwtsnippets.opengl.Snippet195; - -/* - * SWT OpenGL snippet: based on snippet195.java - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @since 3.2 - */ - -import dwt.DWT; -import dwt.dwthelper.Runnable; - -import dwt.layout.FillLayout; -import dwt.widgets.Shell; -import dwt.widgets.Display; -import dwt.widgets.Event; -import dwt.widgets.Composite; -import dwt.widgets.Listener; -import dwt.graphics.Rectangle; -import dwt.opengl.GLCanvas; -import dwt.opengl.GLData; - -import derelict.opengl.gl; -import derelict.opengl.glu; - -import Math = tango.math.Math; - -void drawTorus(float r, float R, int nsides, int rings) -{ - float ringDelta = 2.0f * cast(float) Math.PI / rings; - float sideDelta = 2.0f * cast(float) Math.PI / nsides; - float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f; - for (int i = rings - 1; i >= 0; i--) { - float theta1 = theta + ringDelta; - float cosTheta1 = cast(float) Math.cos(theta1); - float sinTheta1 = cast(float) Math.sin(theta1); - glBegin(GL_QUAD_STRIP); - float phi = 0.0f; - for (int j = nsides; j >= 0; j--) { - phi += sideDelta; - float cosPhi = cast(float) Math.cos(phi); - float sinPhi = cast(float) Math.sin(phi); - float dist = R + r * cosPhi; - glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); - glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); - glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); - glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi); - } - glEnd(); - theta = theta1; - cosTheta = cosTheta1; - sinTheta = sinTheta1; - } -} - -void main() -{ - DerelictGL.load(); - DerelictGLU.load(); - - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - Composite comp = new Composite(shell, DWT.NONE); - comp.setLayout(new FillLayout()); - GLData data = new GLData (); - data.doubleBuffer = true; - GLCanvas canvas = new GLCanvas(comp, DWT.NONE, data); - - canvas.setCurrent(); - - canvas.addListener(DWT.Resize, new class() Listener { - public void handleEvent(Event event) { - Rectangle bounds = canvas.getBounds(); - float fAspect = cast(float) bounds.width / cast(float) bounds.height; - - glViewport(0, 0, bounds.width, bounds.height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(45.0f, fAspect, 0.5f, 400.0f); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - } - }); - - glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - glColor3f(1.0f, 0.0f, 0.0f); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glClearDepth(1.0); - glLineWidth(2); - glEnable(GL_DEPTH_TEST); - - shell.setText("DWT/DerelictGL Example"); - shell.setSize(640, 480); - shell.open(); - - display.asyncExec(new class() Runnable { - int rot = 0; - public void run() { - if (!canvas.isDisposed()) { - canvas.setCurrent(); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glClearColor(.3f, .5f, .8f, 1.0f); - glLoadIdentity(); - glTranslatef(0.0f, 0.0f, -10.0f); - float frot = rot; - glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f); - glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f); - rot++; - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glColor3f(0.9f, 0.9f, 0.9f); - drawTorus(1, 1.9f + (cast(float) Math.sin((0.004f * frot))), 15, 15); - canvas.swapBuffers(); - display.asyncExec(this); - } - } - }); - - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/opengl/dsss.conf --- a/dwtsnippets/opengl/dsss.conf Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -[*] -buildflags+=-g -gc -buildflags+=-J$LIB_PREFIX/res -J../../res -I../.. - -version(Windows){ - # if no console window is wanted/needed use -version=gui - version(gui) { - buildflags+= -L/SUBSYSTEM:windows:5 - } else { - buildflags+= -L/SUBSYSTEM:console:5 - } - buildflags+= -L/rc:dwt -} - - -[Snippet174.d] -[Snippet195.d] diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/program/Snippet32.d --- a/dwtsnippets/program/Snippet32.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/******************************************************************************* - * 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.program.Snippet32; - -/* - * Program example snippet: find the icon of the program that edits .bmp files - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.graphics.ImageData; -import dwt.graphics.Image; -import dwt.widgets.Shell; -import dwt.widgets.Display; -import dwt.widgets.Label; -import dwt.program.Program; - -void main () { - Display display = new Display (); - Shell shell = new Shell (display); - Label label = new Label (shell, DWT.NONE); - label.setText ("Can't find icon for .bmp"); - Image image = null; - Program p = Program.findProgram (".bmp"); - if (p !is null) { - ImageData data = p.getImageData (); - if (data !is null) { - image = new Image (display, data); - label.setImage (image); - } - } - label.pack (); - shell.pack (); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - if (image !is null) image.dispose (); - display.dispose (); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/sash/Snippet107.d --- a/dwtsnippets/sash/Snippet107.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/******************************************************************************* - * 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 - *******************************************************************************/ -module dwtsnippets.sash.Snippet107; -/* - * Sash example snippet: implement a simple splitter (with a 20 pixel limit) - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.graphics.Rectangle; -import dwt.layout.FormAttachment; -import dwt.layout.FormData; -import dwt.layout.FormLayout; -import dwt.widgets.Button; -import dwt.widgets.Display; -import dwt.widgets.Event; -import dwt.widgets.Listener; -import dwt.widgets.Sash; -import dwt.widgets.Shell; - -import tango.math.Math; - -void main () { - auto display = new Display (); - auto shell = new Shell (display); - auto button1 = new Button (shell, DWT.PUSH); - button1.setText ("Button 1"); - auto sash = new Sash (shell, DWT.VERTICAL); - auto button2 = new Button (shell, DWT.PUSH); - button2.setText ("Button 2"); - - auto form = new FormLayout (); - shell.setLayout (form); - - auto button1Data = new FormData (); - button1Data.left = new FormAttachment (0, 0); - button1Data.right = new FormAttachment (sash, 0); - button1Data.top = new FormAttachment (0, 0); - button1Data.bottom = new FormAttachment (100, 0); - button1.setLayoutData (button1Data); - - int limit = 20, percent = 50; - auto sashData = new FormData (); - sashData.left = new FormAttachment (percent, 0); - sashData.top = new FormAttachment (0, 0); - sashData.bottom = new FormAttachment (100, 0); - sash.setLayoutData (sashData); - sash.addListener (DWT.Selection, new class Listener { - public void handleEvent (Event e) { - auto sashRect = sash.getBounds (); - auto shellRect = shell.getClientArea (); - int right = shellRect.width - sashRect.width - limit; - e.x = Math.max (Math.min (e.x, right), limit); - if (e.x !is sashRect.x) { - sashData.left = new FormAttachment (0, e.x); - shell.layout (); - } - } - }); - - auto button2Data = new FormData (); - button2Data.left = new FormAttachment (sash, 0); - button2Data.right = new FormAttachment (100, 0); - button2Data.top = new FormAttachment (0, 0); - button2Data.bottom = new FormAttachment (100, 0); - button2.setLayoutData (button2Data); - - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/sashform/Snippet109.d --- a/dwtsnippets/sashform/Snippet109.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.sashform.Snippet109; - -/* - * SashForm example snippet: create a sash form with three children - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.custom.SashForm; -import dwt.layout.FillLayout; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Label; -import dwt.widgets.Button; -import dwt.widgets.Composite; - -void main () { - final Display display = new Display (); - Shell shell = new Shell(display); - shell.setLayout (new FillLayout()); - - SashForm form = new SashForm(shell,DWT.HORIZONTAL); - form.setLayout(new FillLayout()); - - Composite child1 = new Composite(form,DWT.NONE); - child1.setLayout(new FillLayout()); - (new Label(child1,DWT.NONE)).setText("Label in pane 1"); - - Composite child2 = new Composite(form,DWT.NONE); - child2.setLayout(new FillLayout()); - (new Button(child2,DWT.PUSH)).setText("Button in pane2"); - - Composite child3 = new Composite(form,DWT.NONE); - child3.setLayout(new FillLayout()); - (new Label(child3,DWT.PUSH)).setText("Label in pane3"); - - form.setWeights([30,40,30]); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/shell/Snippet134.d --- a/dwtsnippets/shell/Snippet134.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -/******************************************************************************* - * 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 04f122e90b0a -r 4a04b6759f98 dwtsnippets/shell/Snippet138.d --- a/dwtsnippets/shell/Snippet138.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.shell.Snippet138; - -/* - * example snippet: set icons with different resolutions - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @since 3.0 - */ -import dwt.DWT; -import dwt.graphics.GC; -import dwt.graphics.Image; -import dwt.widgets.Display; -import dwt.widgets.Shell; - -void main() { - Display display = new Display(); - - Image small = new Image(display, 16, 16); - GC gc = new GC(small); - gc.setBackground(display.getSystemColor(DWT.COLOR_RED)); - gc.fillArc(0, 0, 16, 16, 45, 270); - gc.dispose(); - - Image large = new Image(display, 32, 32); - gc = new GC(large); - gc.setBackground(display.getSystemColor(DWT.COLOR_RED)); - gc.fillArc(0, 0, 32, 32, 45, 270); - gc.dispose(); - - /* Provide different resolutions for icons to get - * high quality rendering wherever the OS needs - * large icons. For example, the ALT+TAB window - * on certain systems uses a larger icon. - */ - Shell shell = new Shell(display); - shell.setText("Small and Large icons"); - shell.setImages([small, large]); - - /* No large icon: the OS will scale up the - * small icon when it needs a large one. - */ - Shell shell2 = new Shell(display); - shell2.setText("Small icon"); - shell2.setImage(small); - - shell.open(); - shell2.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - small.dispose(); - large.dispose(); - display.dispose(); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/spinner/Snippet184.d --- a/dwtsnippets/spinner/Snippet184.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/******************************************************************************* - * 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 - * Port to the D programming language: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.spinner.Snippet184; - -/* - * Spinner example snippet: create and initialize a spinner widget - * - * For a list of all DWT 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.Spinner; - -void main() { - Display display = new Display(); - Shell shell = new Shell(display); - Spinner spinner = new Spinner (shell, DWT.BORDER); - spinner.setMinimum(0); - spinner.setMaximum(1000); - spinner.setSelection(500); - spinner.setIncrement(1); - spinner.setPageIncrement(100); - spinner.pack(); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/spinner/Snippet190.d --- a/dwtsnippets/spinner/Snippet190.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/******************************************************************************* - * 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 - * Port to the D programming language: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.spinner.Snippet190; - -import dwt.DWT; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Spinner; -import dwt.events.SelectionAdapter; -import dwt.events.SelectionEvent; -import dwt.layout.GridLayout; - -import Math = tango.math.Math; -import tango.io.Stdout; - -/* - * Floating point values in Spinner - * - * For a list of all DWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @since 3.1 - */ - -void main () { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setText("Spinner with float values"); - shell.setLayout(new GridLayout()); - final Spinner spinner = new Spinner(shell, DWT.NONE); - // allow 3 decimal places - spinner.setDigits(3); - // set the minimum value to 0.001 - spinner.setMinimum(1); - // set the maximum value to 20 - spinner.setMaximum(20000); - // set the increment value to 0.010 - spinner.setIncrement(10); - // set the seletion to 3.456 - spinner.setSelection(3456); - spinner.addSelectionListener(new class() SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - int selection = spinner.getSelection(); - float digits = spinner.getDigits(); - Stdout.formatln("Selection is {}", selection / Math.pow(10.f, digits)); - } - }); - shell.setSize(200, 200); - shell.open(); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/styledtext/Snippet163.d --- a/dwtsnippets/styledtext/Snippet163.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/******************************************************************************* - * 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: - * Jesse Phillips gmail.com - *******************************************************************************/ - -module dwtsnippets.styledtext.Snippet163; - -/* - * Setting the font style, foreground and background colors of StyledText - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.custom.StyledText; -import dwt.custom.StyleRange; -import dwt.layout.FillLayout; -import dwt.widgets.Display; -import dwt.widgets.Shell; - -version(JIVE){ - import jive.stacktrace; -} - -void main() { - auto display = new Display(); - auto shell = new Shell(display); - shell.setLayout(new FillLayout()); - auto text = new StyledText (shell, DWT.BORDER); - text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ"); - // make 0123456789 appear bold - auto style1 = new StyleRange(); - style1.start = 0; - style1.length = 10; - style1.fontStyle = DWT.BOLD; - text.setStyleRange(style1); - // make ABCDEFGHIJKLM have a red font - auto style2 = new StyleRange(); - style2.start = 11; - style2.length = 13; - style2.foreground = display.getSystemColor(DWT.COLOR_RED); - text.setStyleRange(style2); - // make NOPQRSTUVWXYZ have a blue background - auto style3 = new StyleRange(); - style3.start = 25; - style3.length = 13; - style3.background = display.getSystemColor(DWT.COLOR_BLUE); - text.setStyleRange(style3); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/styledtext/Snippet189.d --- a/dwtsnippets/styledtext/Snippet189.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/******************************************************************************* - * 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: - * Jesse Phillips gmail.com - *******************************************************************************/ - -module dwtsnippets.styledtext.Snippet189; - -/* - * Text with underline and strike through - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @since 3.1 - */ - -import dwt.DWT; -import dwt.custom.StyledText; -import dwt.custom.StyleRange; -import dwt.layout.FillLayout; -import dwt.widgets.Display; -import dwt.widgets.Shell; - -void main () { - auto display = new Display (); - auto shell = new Shell (display); - shell.setText("StyledText with underline and strike through"); - shell.setLayout(new FillLayout()); - auto text = new StyledText (shell, DWT.BORDER); - text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ"); - // make 0123456789 appear underlined - auto style1 = new StyleRange(); - style1.start = 0; - style1.length = 10; - style1.underline = true; - text.setStyleRange(style1); - // make ABCDEFGHIJKLM have a strike through - auto style2 = new StyleRange(); - style2.start = 11; - style2.length = 13; - style2.strikeout = true; - text.setStyleRange(style2); - // make NOPQRSTUVWXYZ appear underlined and have a strike through - auto style3 = new StyleRange(); - style3.start = 25; - style3.length = 13; - style3.underline = true; - style3.strikeout = true; - text.setStyleRange(style3); - shell.pack(); - shell.open(); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/table/Snippet144.d --- a/dwtsnippets/table/Snippet144.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/******************************************************************************* - * 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 gmail.com - *******************************************************************************/ -module dwtsnippets.table.Snippet144; - -/* - * Virtual Table example snippet: create a table with 1,000,000 items (lazy) - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @since 3.0 - */ -import dwt.DWT; -import dwt.widgets.Button; -import dwt.widgets.Display; -import dwt.widgets.Event; -import dwt.widgets.Label; -import dwt.widgets.Listener; -import dwt.widgets.Shell; -import dwt.widgets.Table; -import dwt.widgets.TableItem; -import dwt.layout.RowLayout; -import dwt.layout.RowData; - -import tango.io.Stdout; -import tango.time.StopWatch; -import tango.util.Convert; - -const int COUNT = 1000000; - -void main() { - auto display = new Display (); - auto shell = new Shell (display); - shell.setLayout (new RowLayout (DWT.VERTICAL)); - auto table = new Table (shell, DWT.VIRTUAL | DWT.BORDER); - table.addListener (DWT.SetData, new class Listener { - public void handleEvent (Event event) { - auto item = cast(TableItem) event.item; - auto index = table.indexOf (item); - item.setText ("Item " ~ to!(char[])(index)); - Stdout(item.getText ()).newline; - } - }); - table.setLayoutData (new RowData (200, 200)); - auto button = new Button (shell, DWT.PUSH); - button.setText ("Add Items"); - auto label = new Label(shell, DWT.NONE); - button.addListener (DWT.Selection, new class Listener { - public void handleEvent (Event event) { - StopWatch elapsed; - elapsed.start; - table.setItemCount (COUNT); - auto t = elapsed.stop; - label.setText ("Items: " ~ to!(char[])(COUNT) ~ - ", Time: " ~ to!(char[])(t) ~ " (sec)"); - shell.layout (); - } - }); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/table/Snippet38.d --- a/dwtsnippets/table/Snippet38.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/******************************************************************************* - * 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 gmail.com - *******************************************************************************/ -module dwtsnippets.table.Snippet38; - -/* - * Table example snippet: create a table (columns, headers, lines) - * - * 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.Table; -import dwt.widgets.TableColumn; -import dwt.widgets.TableItem; - -import tango.util.Convert; - -void main () { - auto display = new Display (); - auto shell = new Shell (display); - auto table = new Table (shell, DWT.MULTI | DWT.BORDER | DWT.FULL_SELECTION); - table.setLinesVisible (true); - table.setHeaderVisible (true); - char[][] titles = [" ", "C", "!", "Description", "Resource", "In Folder", "Location"]; - int[] styles = [DWT.NONE, DWT.LEFT, DWT.RIGHT, DWT.CENTER, DWT.NONE, DWT.NONE, DWT.NONE]; - foreach (i,title; titles) { - auto column = new TableColumn (table, styles[i]); - column.setText (title); - } - int count = 128; - for (int i=0; i gmail.com - *******************************************************************************/ - -module dwtsnippets.text.Snippet258; - -/* - * Create a search text control - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @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 tango.io.Stdout; - -void main() { - auto display = new Display(); - auto shell = new Shell(display); - shell.setLayout(new GridLayout(2, false)); - - auto text = new Text(shell, DWT.SEARCH | DWT.CANCEL); - Image image = null; - if ((text.getStyle() & DWT.CANCEL) == 0) { - image = new Image (display, new ImageData(new ByteArrayInputStream( cast(byte[]) import("cancel.gif" )))); - auto toolBar = new ToolBar (shell, DWT.FLAT); - auto item = new ToolItem (toolBar, DWT.PUSH); - item.setImage (image); - item.addSelectionListener(new class SelectionAdapter { - public void widgetSelected(SelectionEvent e) { - text.setText(""); - Stdout("Search cancelled").newline; - } - }); - } - text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - text.setText("Search text"); - text.addSelectionListener(new class SelectionAdapter { - public void widgetDefaultSelected(SelectionEvent e) { - if (e.detail == DWT.CANCEL) { - Stdout("Search cancelled").newline; - } else { - Stdout("Searching for: ")(text.getText())("...").newline; - } - } - }); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - if (image !is null) image.dispose(); - display.dispose(); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/toolbar/Snippet153.d --- a/dwtsnippets/toolbar/Snippet153.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.toolbar.Snippet153; - -/* - * ToolBar example snippet: update a status line when the pointer enters a ToolItem - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.events.MouseEvent; -import dwt.events.MouseMoveListener; -import dwt.graphics.Point; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.ToolBar; -import dwt.widgets.ToolItem; -import dwt.widgets.Label; - -static char[] statusText = ""; -void main() { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setBounds(10, 10, 200, 200); - ToolBar bar = new ToolBar(shell, DWT.BORDER); - bar.setBounds(10, 10, 150, 50); - Label statusLine = new Label(shell, DWT.BORDER); - statusLine.setBounds(10, 90, 150, 30); - (new ToolItem(bar, DWT.NONE)).setText("item 1"); - (new ToolItem(bar, DWT.NONE)).setText("item 2"); - (new ToolItem(bar, DWT.NONE)).setText("item 3"); - bar.addMouseMoveListener(new class MouseMoveListener { - void mouseMove(MouseEvent e) { - ToolItem item = bar.getItem(new Point(e.x, e.y)); - char[] name = ""; - if (item !is null) { - name = item.getText(); - } - if (statusText != name) { - statusLine.setText(name); - statusText = name; - } - } - }); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/toolbar/Snippet288.d --- a/dwtsnippets/toolbar/Snippet288.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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 - *******************************************************************************/ -module dwtsnippets.toolbar.Snippet288; - -/* - * Create a ToolBar containing animated GIFs - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.DWTException; -import dwt.graphics.GC; -import dwt.graphics.Color; -import dwt.graphics.Image; -import dwt.graphics.ImageLoader; -import dwt.graphics.ImageData; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.ToolBar; -import dwt.widgets.ToolItem; -import dwt.widgets.FileDialog; -import dwt.dwthelper.Runnable; - -import tango.io.FilePath; -import tango.io.FileConst; -import tango.core.Thread; -import tango.io.Stdout; -import tango.util.Convert; -import tango.core.Exception; - -static Display display; -static Shell shell; -static GC shellGC; -static Color shellBackground; -static ImageLoader[] loader; -static ImageData[][] imageDataArray; -static Thread[] animateThread; -static Image[][] image; -private static ToolItem[] item; -static final bool useGIFBackground = false; - -void main () { - display = new Display(); - Shell shell = new Shell (display); - shellBackground = shell.getBackground(); - FileDialog dialog = new FileDialog(shell, DWT.OPEN | DWT.MULTI); - dialog.setText("Select Multiple Animated GIFs"); - dialog.setFilterExtensions(["*.gif"]); - char[] filename = dialog.open(); - char[][] filenames = dialog.getFileNames(); - int numToolBarItems = filenames.length; - if (numToolBarItems > 0) { - try { - loadAllImages((new FilePath(filename)).parent, filenames); - } catch (DWTException e) { - Stdout.print("There was an error loading an image.").newline; - e.printStackTrace(); - } - ToolBar toolBar = new ToolBar (shell, DWT.FLAT | DWT.BORDER | DWT.WRAP); - item = new ToolItem[numToolBarItems]; - for (int i = 0; i < numToolBarItems; i++) { - item[i] = new ToolItem (toolBar, DWT.PUSH); - item[i].setImage(image[i][0]); - } - toolBar.pack (); - shell.open (); - - startAnimationThreads(); - - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - - for (int i = 0; i < numToolBarItems; i++) { - for (int j = 0; j < image[i].length; j++) { - image[i][j].dispose(); - } - } - display.dispose (); - } - thread_joinAll(); -} - -private static void loadAllImages(char[] directory, char[][] filenames) { - int numItems = filenames.length; - loader.length = numItems; - imageDataArray.length = numItems; - image.length = numItems; - for (int i = 0; i < numItems; i++) { - loader[i] = new ImageLoader(); - int fullWidth = loader[i].logicalScreenWidth; - int fullHeight = loader[i].logicalScreenHeight; - imageDataArray[i] = loader[i].load(directory ~ FileConst.PathSeparatorChar ~ filenames[i]); - int numFramesOfAnimation = imageDataArray[i].length; - image[i] = new Image[numFramesOfAnimation]; - for (int j = 0; j < numFramesOfAnimation; j++) { - if (j == 0) { - //for the first frame of animation, just draw the first frame - image[i][j] = new Image(display, imageDataArray[i][j]); - fullWidth = imageDataArray[i][j].width; - fullHeight = imageDataArray[i][j].height; - } - else { - //after the first frame of animation, draw the background or previous frame first, then the new image data - image[i][j] = new Image(display, fullWidth, fullHeight); - GC gc = new GC(image[i][j]); - gc.setBackground(shellBackground); - gc.fillRectangle(0, 0, fullWidth, fullHeight); - ImageData imageData = imageDataArray[i][j]; - switch (imageData.disposalMethod) { - case DWT.DM_FILL_BACKGROUND: - /* Fill with the background color before drawing. */ - Color bgColor = null; - if (useGIFBackground && loader[i].backgroundPixel != -1) { - bgColor = new Color(display, imageData.palette.getRGB(loader[i].backgroundPixel)); - } - gc.setBackground(bgColor !is null ? bgColor : shellBackground); - gc.fillRectangle(imageData.x, imageData.y, imageData.width, imageData.height); - if (bgColor !is null) bgColor.dispose(); - break; - default: - /* Restore the previous image before drawing. */ - gc.drawImage( - image[i][j-1], - 0, - 0, - fullWidth, - fullHeight, - 0, - 0, - fullWidth, - fullHeight); - break; - } - Image newFrame = new Image(display, imageData); - gc.drawImage(newFrame, - 0, - 0, - imageData.width, - imageData.height, - imageData.x, - imageData.y, - imageData.width, - imageData.height); - newFrame.dispose(); - gc.dispose(); - } - } - } -} - -private static void startAnimationThreads() { - animateThread = new Thread[image.length]; - for (int ii = 0; ii < image.length; ii++) { - animateThread[ii] = new class(ii) Thread { - int imageDataIndex = 0; - int id = 0; - this(int _id) { - id = _id; - name = "Animation "~to!(char[])(ii); - isDaemon = true; - super(&run); - } - void run() { - try { - int repeatCount = loader[id].repeatCount; - while (loader[id].repeatCount == 0 || repeatCount > 0) { - imageDataIndex = (imageDataIndex + 1) % imageDataArray[id].length; - if (!display.isDisposed()) { - display.asyncExec(new class Runnable { - public void run() { - if (!item[id].isDisposed()) - item[id].setImage(image[id][imageDataIndex]); - } - }); - } - - /* Sleep for the specified delay time (adding commonly-used slow-down fudge factors). */ - try { - int ms = imageDataArray[id][imageDataIndex].delayTime * 10; - if (ms < 20) ms += 30; - if (ms < 30) ms += 10; - Thread.sleep(0.001*ms); - } catch (ThreadException e) { - } - - /* If we have just drawn the last image, decrement the repeat count and start again. */ - if (imageDataIndex == imageDataArray[id].length - 1) repeatCount--; - } - } catch (DWTException ex) { - Stdout.print("There was an error animating the GIF").newline; - ex.printStackTrace(); - } - } - }; - animateThread[ii].start(); - } -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/toolbar/Snippet47.d --- a/dwtsnippets/toolbar/Snippet47.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.toolbar.Snippet47; - -/* - * ToolBar example snippet: create tool bar (normal, hot and disabled images) - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.graphics.GC; -import dwt.graphics.Color; -import dwt.graphics.Image; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.ToolBar; -import dwt.widgets.ToolItem; - -void main () { - Display display = new Display (); - Shell shell = new Shell (display); - - Image image = new Image (display, 20, 20); - Color color = display.getSystemColor (DWT.COLOR_BLUE); - GC gc = new GC (image); - gc.setBackground (color); - gc.fillRectangle (image.getBounds ()); - gc.dispose (); - - Image disabledImage = new Image (display, 20, 20); - color = display.getSystemColor (DWT.COLOR_GREEN); - gc = new GC (disabledImage); - gc.setBackground (color); - gc.fillRectangle (disabledImage.getBounds ()); - gc.dispose (); - - Image hotImage = new Image (display, 20, 20); - color = display.getSystemColor (DWT.COLOR_RED); - gc = new GC (hotImage); - gc.setBackground (color); - gc.fillRectangle (hotImage.getBounds ()); - gc.dispose (); - - ToolBar bar = new ToolBar (shell, DWT.BORDER | DWT.FLAT); - bar.setSize (200, 32); - for (int i=0; i<12; i++) { - ToolItem item = new ToolItem (bar, 0); - item.setImage (image); - item.setDisabledImage (disabledImage); - item.setHotImage (hotImage); - if (i % 3 == 0) item.setEnabled (false); - } - - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - image.dispose (); - disabledImage.dispose (); - hotImage.dispose (); - display.dispose (); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/toolbar/Snippet49.d --- a/dwtsnippets/toolbar/Snippet49.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.toolbar.Snippet49; - -/* - * ToolBar example snippet: create tool bar (wrap on resize) - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.graphics.Rectangle; -import dwt.graphics.Point; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.ToolBar; -import dwt.widgets.ToolItem; -import dwt.widgets.Event; -import dwt.widgets.Listener; - -import tango.util.Convert; - -void main () { - Display display = new Display (); - Shell shell = new Shell (display); - ToolBar toolBar = new ToolBar (shell, DWT.WRAP); - for (int i=0; i<12; i++) { - ToolItem item = new ToolItem (toolBar, DWT.PUSH); - item.setText ("Item " ~ to!(char[])(i)); - } - shell.addListener (DWT.Resize, new class Listener { - void handleEvent (Event e) { - Rectangle rect = shell.getClientArea (); - Point size = toolBar.computeSize (rect.width, DWT.DEFAULT); - toolBar.setSize (size); - } - }); - toolBar.pack (); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/toolbar/Snippet58.d --- a/dwtsnippets/toolbar/Snippet58.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/******************************************************************************* - * 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: - * Bill Baxter - *******************************************************************************/ -module dwtsnippets.toolbar.Snippet58; - -/* - * ToolBar example snippet: place a combo box in a tool bar - * - * 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.Shell; -import dwt.widgets.ToolBar; -import dwt.widgets.ToolItem; -import dwt.widgets.Combo; - -import tango.util.Convert; - -void main () { - Display display = new Display (); - Shell shell = new Shell (display); - ToolBar bar = new ToolBar (shell, DWT.BORDER); - for (int i=0; i<4; i++) { - ToolItem item = new ToolItem (bar, 0); - item.setText ("Item " ~ to!(char[])(i)); - } - ToolItem sep = new ToolItem (bar, DWT.SEPARATOR); - int start = bar.getItemCount (); - for (int i=start; i - *******************************************************************************/ -module dwtsnippets.toolbar.Snippet67; - -/* - * ToolBar example snippet: place a drop down menu in a tool bar - * - * For a list of all SWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.graphics.Rectangle; -import dwt.graphics.Point; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.ToolBar; -import dwt.widgets.ToolItem; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.Listener; -import dwt.widgets.Event; - -import tango.util.Convert; - -void main () { - Display display = new Display (); - Shell shell = new Shell (display); - ToolBar toolBar = new ToolBar (shell, DWT.NONE); - Menu menu = new Menu (shell, DWT.POP_UP); - for (int i=0; i<8; i++) { - MenuItem item = new MenuItem (menu, DWT.PUSH); - item.setText ("Item " ~ to!(char[])(i)); - } - ToolItem item = new ToolItem (toolBar, DWT.DROP_DOWN); - item.addListener (DWT.Selection, new class Listener { - void handleEvent (Event event) { - if (event.detail == DWT.ARROW) { - Rectangle rect = item.getBounds (); - Point pt = new Point (rect.x, rect.y + rect.height); - pt = toolBar.toDisplay (pt); - menu.setLocation (pt.x, pt.y); - menu.setVisible (true); - } - } - }); - toolBar.pack (); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - menu.dispose (); - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/tooltips/Snippet41.d --- a/dwtsnippets/tooltips/Snippet41.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/******************************************************************************* - * 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: - * Jesse Phillips gmail.com - *******************************************************************************/ - -module dwtsnippets.tooltips.Snippet41; - -/* - * Tool Tips example snippet: create tool tips for a tab item, tool item, and shell - * - * 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.Shell; -import dwt.widgets.TabFolder; -import dwt.widgets.TabItem; -import dwt.widgets.ToolBar; -import dwt.widgets.ToolItem; - -void main () { - auto string = "This is a string\nwith a new line."; - auto display = new Display (); - auto shell = new Shell (display); - - TabFolder folder = new TabFolder (shell, DWT.BORDER); - - folder.setSize (200, 200); - auto item0 = new TabItem (folder, 0); - item0.setText( "Text" ); - item0.setToolTipText ("TabItem toolTip: " ~ string); - - auto bar = new ToolBar (shell, DWT.BORDER); - bar.setBounds (0, 200, 200, 64); - - ToolItem item1 = new ToolItem (bar, 0); - item1.setText( "Text" ); - item1.setToolTipText ("ToolItem toolTip: " ~ string); - shell.setToolTipText ("Shell toolTip: " ~ string); - - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/tray/Snippet143.d --- a/dwtsnippets/tray/Snippet143.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/******************************************************************************* - * 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 - * Port to the D programming language - * Frank Benoit - *******************************************************************************/ -module dwt.snippets.tray.Snippet143; - -/* - * Tray example snippet: place an icon with a popup menu on the system tray - * - * For a list of all DWT example snippets see - * http://www.eclipse.org/swt/snippets/ - * - * @since 3.0 - */ -import dwt.DWT; -import dwt.graphics.Image; -import dwt.widgets.Shell; -import dwt.widgets.Display; -import dwt.widgets.Menu; -import dwt.widgets.MenuItem; -import dwt.widgets.Tray; -import dwt.widgets.TrayItem; -import dwt.widgets.Listener; -import dwt.widgets.Event; -import tango.io.Stdout; -import tango.text.convert.Format; - -TrayItem item; -Menu menu; - -public static void main(char[][] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Image image = new Image (display, 16, 16); - final Tray tray = display.getSystemTray (); - if (tray is null) { - Stdout.formatln ("The system tray is not available"); - } else { - item = new TrayItem (tray, DWT.NONE); - item.setToolTipText("DWT TrayItem"); - item.addListener (DWT.Show, new class() Listener { - public void handleEvent (Event event) { - Stdout.formatln("show"); - } - }); - item.addListener (DWT.Hide, new class() Listener { - public void handleEvent (Event event) { - Stdout.formatln("hide"); - } - }); - item.addListener (DWT.Selection, new class() Listener { - public void handleEvent (Event event) { - Stdout.formatln("selection"); - } - }); - item.addListener (DWT.DefaultSelection, new class() Listener { - public void handleEvent (Event event) { - Stdout.formatln("default selection"); - } - }); - menu = new Menu (shell, DWT.POP_UP); - for (int i = 0; i < 8; i++) { - MenuItem mi = new MenuItem (menu, DWT.PUSH); - mi.setText ( Format( "Item{}", i )); - mi.addListener (DWT.Selection, new class() Listener { - public void handleEvent (Event event) { - Stdout.formatln("selection {}", event.widget); - } - }); - if (i == 0) menu.setDefaultItem(mi); - } - item.addListener (DWT.MenuDetect, new class() Listener { - public void handleEvent (Event event) { - menu.setVisible (true); - } - }); - item.setImage (image); - } - shell.setBounds(50, 50, 300, 200); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - image.dispose (); - display.dispose (); -} - diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/tree/Snippet15.d --- a/dwtsnippets/tree/Snippet15.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/******************************************************************************* - * 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 gmail.com - *******************************************************************************/ -module dwtsnippets.tree.Snippet15; - -/* - * Tree example snippet: create a tree - * - * For a list of all DWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ -import dwt.DWT; -import dwt.layout.FillLayout; -import dwt.widgets.Display; -import dwt.widgets.Shell; -import dwt.widgets.Tree; -import dwt.widgets.TreeItem; - -import tango.util.Convert; - -void main () { - auto display = new Display (); - auto shell = new Shell (display); - shell.setLayout(new FillLayout()); - auto tree = new Tree (shell, DWT.BORDER); - for (int i=0; i<4; i++) { - auto iItem = new TreeItem (tree, 0); - iItem.setText ("TreeItem (0) -" ~ to!(char[])(i)); - for (int j=0; j<4; j++) { - TreeItem jItem = new TreeItem (iItem, 0); - jItem.setText ("TreeItem (1) -" ~ to!(char[])(j)); - for (int k=0; k<4; k++) { - TreeItem kItem = new TreeItem (jItem, 0); - kItem.setText ("TreeItem (2) -" ~ to!(char[])(k)); - for (int l=0; l<4; l++) { - TreeItem lItem = new TreeItem (kItem, 0); - lItem.setText ("TreeItem (3) -" ~ to!(char[])(l)); - } - } - } - } - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 dwtsnippets/tree/Snippet8.d --- a/dwtsnippets/tree/Snippet8.d Sat Apr 26 10:11:28 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/******************************************************************************* - * 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 gmail.com - *******************************************************************************/ -module dwtsnippets.tree.Snippet8; - -/* - * Tree example snippet: create a tree (lazy) - * - * For a list of all DWT example snippets see - * http://www.eclipse.org/swt/snippets/ - */ - -import dwt.DWT; -import dwt.layout.FillLayout; -import dwt.graphics.Point; -import dwt.widgets.Display; -import dwt.widgets.Event; -import dwt.widgets.Listener; -import dwt.widgets.Shell; -import dwt.widgets.Tree; -import dwt.widgets.TreeItem; - -import dwt.dwthelper.utils; -import tango.io.FilePath; -import tango.io.FileRoots; - -void main () { - auto display = new Display (); - auto shell = new Shell (display); - shell.setText ("Lazy Tree"); - shell.setLayout (new FillLayout ()); - auto tree = new Tree (shell, DWT.BORDER); - auto roots = FileRoots.list(); - foreach (file; roots) { - auto root = new TreeItem (tree, 0); - root.setText (file); - root.setData (new FilePath(file)); - new TreeItem (root, 0); - } - tree.addListener (DWT.Expand, new class Listener { - public void handleEvent (Event event) { - auto root = cast(TreeItem) event.item; - auto items = root.getItems (); - foreach(item; items) { - if (item.getData () !is null) return; - item.dispose (); - } - auto file = cast(FilePath) root.getData (); - auto files = file.toList(); - if (files is null) return; - foreach (f; files) { - TreeItem item = new TreeItem (root, 0); - item.setText (f.toString()); - item.setData (f); - if (f.isFolder()) { - new TreeItem (item, 0); - } - } - } - }); - auto size = tree.computeSize (300, DWT.DEFAULT); - auto width = Math.max (300, size.x); - auto height = Math.max (300, size.y); - shell.setSize (shell.computeSize (width, height)); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} diff -r 04f122e90b0a -r 4a04b6759f98 examples/addressbook/AddressBook.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/addressbook/AddressBook.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,902 @@ +/******************************************************************************* + * 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 + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ +module examples.addressbook.AddressBook; + +import dwt.DWT; +import dwt.events.MenuAdapter; +import dwt.events.MenuEvent; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.ShellAdapter; +import dwt.events.ShellEvent; +import dwt.graphics.Cursor; +import dwt.layout.FillLayout; +import dwt.widgets.Display; +import dwt.widgets.FileDialog; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.MessageBox; +import dwt.widgets.Shell; +import dwt.widgets.Table; +import dwt.widgets.TableColumn; +import dwt.widgets.TableItem; + +import dwt.dwthelper.ResourceBundle; + +import tango.core.Exception; +import tango.io.FilePath; +import tango.io.File; +import tango.io.FileConduit; +import tango.io.stream.FileStream; +import TextUtil = tango.text.Util; +import Unicode = tango.text.Unicode; + +import examples.addressbook.SearchDialog; +import examples.addressbook.DataEntryDialog; +import examples.addressbook.FindListener; + +void main() { + Display display = new Display(); + auto application = new AddressBook(); + Shell shell = application.open(display); + while(!shell.isDisposed()){ + if(!display.readAndDispatch()){ + display.sleep(); + } + } + display.dispose(); +} + +/** + * AddressBookExample is an example that uses org.eclipse.swt + * libraries to implement a simple address book. This application has + * save, load, sorting, and searching functions common + * to basic address books. + */ +public class AddressBook { + + private static ResourceBundle resAddressBook; + private static const char[] resAddressBookData = cast(char[]) import( "dwtexamples.addressbook.addressbook.properties" ); + private Shell shell; + + private Table table; + private SearchDialog searchDialog; + + private FilePath file; + private bool isModified; + + private char[][] copyBuffer; + + private int lastSortColumn= -1; + + private static const char[] DELIMITER = "\t"; + private static char[][] columnNames; + +public this(){ + if( resAddressBook is null ){ + resAddressBook = ResourceBundle.getBundleFromData(resAddressBookData); + columnNames = [ + resAddressBook.getString("Last_name"), + resAddressBook.getString("First_name"), + resAddressBook.getString("Business_phone"), + resAddressBook.getString("Home_phone"), + resAddressBook.getString("Email"), + resAddressBook.getString("Fax") ]; + } +} + + +public Shell open(Display display) { + shell = new Shell(display); + shell.setLayout(new FillLayout()); + + shell.addShellListener( new class() ShellAdapter { + public void shellClosed(ShellEvent e) { + e.doit = closeAddressBook(); + } + }); + + createMenuBar(); + + searchDialog = new SearchDialog(shell); + searchDialog.setSearchAreaNames(columnNames); + searchDialog.setSearchAreaLabel(resAddressBook.getString("Column")); + searchDialog.addFindListener(new class() FindListener { + public bool find() { + return findEntry(); + } + }); + + table = new Table(shell, DWT.SINGLE | DWT.BORDER | DWT.FULL_SELECTION); + table.setHeaderVisible(true); + table.setMenu(createPopUpMenu()); + table.addSelectionListener(new class() SelectionAdapter { + public void widgetDefaultSelected(SelectionEvent e) { + TableItem[] items = table.getSelection(); + if (items.length > 0) editEntry(items[0]); + } + }); + for(int i = 0; i < columnNames.length; i++) { + TableColumn column = new TableColumn(table, DWT.NONE); + column.setText(columnNames[i]); + column.setWidth(150); + int columnIndex = i; + column.addSelectionListener(new class(columnIndex) SelectionAdapter { + int c; + this( int c ){ this.c = c; } + public void widgetSelected(SelectionEvent e) { + sort(c); + } + }); + } + + newAddressBook(); + + shell.setSize(table.computeSize(DWT.DEFAULT, DWT.DEFAULT).x, 300); + shell.open(); + return shell; +} + +private bool closeAddressBook() { + if(isModified) { + //ask user if they want to save current address book + MessageBox box = new MessageBox(shell, DWT.ICON_WARNING | DWT.YES | DWT.NO | DWT.CANCEL); + box.setText(shell.getText()); + box.setMessage(resAddressBook.getString("Close_save")); + + int choice = box.open(); + if(choice is DWT.CANCEL) { + return false; + } else if(choice is DWT.YES) { + if (!save()) return false; + } + } + + TableItem[] items = table.getItems(); + for (int i = 0; i < items.length; i ++) { + items[i].dispose(); + } + + return true; +} +/** + * Creates the menu at the top of the shell where most + * of the programs functionality is accessed. + * + * @return The Menu widget that was created + */ +private Menu createMenuBar() { + Menu menuBar = new Menu(shell, DWT.BAR); + shell.setMenuBar(menuBar); + + //create each header and subMenu for the menuBar + createFileMenu(menuBar); + createEditMenu(menuBar); + createSearchMenu(menuBar); + createHelpMenu(menuBar); + + return menuBar; +} + +/** + * Converts an encoded char[] to a char[] array representing a table entry. + */ +private char[][] decodeLine(char[] line) { + char[][] toks = TextUtil.split( line, DELIMITER ); + while( toks.length < table.getColumnCount() ){ + toks ~= ""; + } + return toks[ 0 .. table.getColumnCount() ]; +} +private void displayError(char[] msg) { + MessageBox box = new MessageBox(shell, DWT.ICON_ERROR); + box.setMessage(msg); + box.open(); +} +private void editEntry(TableItem item) { + DataEntryDialog dialog = new DataEntryDialog(shell); + dialog.setLabels(columnNames); + char[][] values = new char[][table.getColumnCount()]; + for (int i = 0; i < values.length; i++) { + values[i] = item.getText(i); + } + dialog.setValues(values); + values = dialog.open(); + if (values !is null) { + item.setText(values); + isModified = true; + } +} +private char[] encodeLine(char[][] tableItems) { + char[] line = ""; + for (int i = 0; i < tableItems.length - 1; i++) { + line ~= tableItems[i] ~ DELIMITER; + } + line ~= tableItems[tableItems.length - 1] ~ "\n"; + + return line; +} +private bool findEntry() { + Cursor waitCursor = new Cursor(shell.getDisplay(), DWT.CURSOR_WAIT); + shell.setCursor(waitCursor); + + bool matchCase = searchDialog.getMatchCase(); + bool matchWord = searchDialog.getMatchWord(); + char[] searchString = searchDialog.getSearchString(); + int column = searchDialog.getSelectedSearchArea(); + + searchString = matchCase ? searchString : Unicode.toLower( searchString ); + + bool found = false; + if (searchDialog.getSearchDown()) { + for(int i = table.getSelectionIndex() + 1; i < table.getItemCount(); i++) { + found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase); + if ( found ){ + table.setSelection(i); + break; + } + } + } else { + for(int i = table.getSelectionIndex() - 1; i > -1; i--) { + found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase); + if ( found ){ + table.setSelection(i); + break; + } + } + } + + shell.setCursor(cast(Cursor)null); + waitCursor.dispose(); + + return found; +} +private bool findMatch(char[] searchString, TableItem item, int column, bool matchWord, bool matchCase) { + + char[] tableText = matchCase ? item.getText(column) : Unicode.toLower( item.getText(column)); + if (matchWord) { + if (tableText !is null && tableText==searchString) { + return true; + } + + } else { + if(tableText!is null && TextUtil.containsPattern( tableText, searchString)) { + return true; + } + } + return false; +} +private void newAddressBook() { + shell.setText(resAddressBook.getString("Title_bar") ~ resAddressBook.getString("New_title")); + *(cast(Object*)&file) = null; + ///cast(Object)file = null; + isModified = false; +} +private void newEntry() { + DataEntryDialog dialog = new DataEntryDialog(shell); + dialog.setLabels(columnNames); + char[][] data = dialog.open(); + if (data !is null) { + TableItem item = new TableItem(table, DWT.NONE); + item.setText(data); + isModified = true; + } +} + +private void openAddressBook() { + FileDialog fileDialog = new FileDialog(shell, DWT.OPEN); + + fileDialog.setFilterExtensions(["*.adr;", "*.*"]); + fileDialog.setFilterNames([ + resAddressBook.getString("Book_filter_name") ~ " (*.adr)", + resAddressBook.getString("All_filter_name") ~ " (*.*)"]); + char[] name = fileDialog.open(); + + if(name is null) return; + FilePath file = new FilePath(name); + if (!file.exists()) { + displayError(resAddressBook.getString("File")~file.toString()~" "~resAddressBook.getString("Does_not_exist")); + return; + } + + Cursor waitCursor = new Cursor(shell.getDisplay(), DWT.CURSOR_WAIT); + shell.setCursor(waitCursor); + + char[][] data; + try { + scope ioFile = new File (file); + data = TextUtil.splitLines (cast(char[]) ioFile.read); + } catch (IOException e ) { + displayError(resAddressBook.getString("IO_error_read") ~ "\n" ~ file.toString()); + return; + } finally { + + shell.setCursor(cast(Cursor)null); + waitCursor.dispose(); + } + + char[][][] tableInfo = new char[][][](data.length,table.getColumnCount()); + foreach( idx, line; data ){ + char[][] linetoks = decodeLine(line); + tableInfo[ idx ] = linetoks; + } + /+ + int writeIndex = 0; + for (int i = 0; i < data.length; i++) { + char[][] line = decodeLine(data[i]); + if (line !is null) tableInfo[writeIndex++] = line; + } + if (writeIndex !is data.length) { + char[][][] result = new char[][writeIndex][table.getColumnCount()]; + System.arraycopy(tableInfo, 0, result, 0, writeIndex); + tableInfo = result; + } + +/ + tango.core.Array.sort( tableInfo, new RowComparator(0)); + + for (int i = 0; i < tableInfo.length; i++) { + TableItem item = new TableItem(table, DWT.NONE); + item.setText(tableInfo[i]); + } + shell.setText(resAddressBook.getString("Title_bar")~fileDialog.getFileName()); + isModified = false; + this.file = file; +} +private bool save() { + if(file is null) return saveAs(); + + Cursor waitCursor = new Cursor(shell.getDisplay(), DWT.CURSOR_WAIT); + shell.setCursor(waitCursor); + + TableItem[] items = table.getItems(); + char[][] lines = new char[][items.length]; + for(int i = 0; i < items.length; i++) { + char[][] itemText = new char[][table.getColumnCount()]; + for (int j = 0; j < itemText.length; j++) { + itemText[j] = items[i].getText(j); + } + lines[i] = encodeLine(itemText); + } + + FileOutput fileOutput; + bool result = true; + try { + fileOutput = new FileOutput( file.toString ); + for (int i = 0; i < lines.length; i++) { + fileOutput.write(lines[i]); + } + } catch(IOException e ) { + displayError(resAddressBook.getString("IO_error_write") ~ "\n" ~ file.toString()); + result = false; + } catch(Exception e2 ) { + displayError(resAddressBook.getString("error_write") ~ "\n" ~ e2.toString()); + result = false; + } finally { + shell.setCursor(null); + waitCursor.dispose(); + + } + + if(fileOutput !is null) { + try { + fileOutput.close(); + } catch(IOException e) { + displayError(resAddressBook.getString("IO_error_close") ~ "\n" ~ file.toString()); + return false; + } + } + if( !result ){ + return false; + } + + shell.setText(resAddressBook.getString("Title_bar")~file.toString()); + isModified = false; + return true; +} +private bool saveAs() { + + FileDialog saveDialog = new FileDialog(shell, DWT.SAVE); + saveDialog.setFilterExtensions(["*.adr;", "*.*"]); + saveDialog.setFilterNames(["Address Books (*.adr)", "All Files "]); + + saveDialog.open(); + char[] name = saveDialog.getFileName(); + if(!name) return false; + + if( TextUtil.locatePatternPrior( name, ".adr" ) !is name.length - 4) { + name ~= ".adr"; + } + + FilePath file = new FilePath(saveDialog.getFilterPath() ); + file.append( name ); + if(file.exists()) { + MessageBox box = new MessageBox(shell, DWT.ICON_WARNING | DWT.YES | DWT.NO); + box.setText(resAddressBook.getString("Save_as_title")); + box.setMessage(resAddressBook.getString("File") ~ file.toString()~" "~resAddressBook.getString("Query_overwrite")); + if(box.open() !is DWT.YES) { + return false; + } + } + this.file = file; + return save(); +} +private void sort(int column) { + if(table.getItemCount() <= 1) return; + + TableItem[] items = table.getItems(); + char[][][] data = new char[][][](items.length, table.getColumnCount()); + for(int i = 0; i < items.length; i++) { + for(int j = 0; j < table.getColumnCount(); j++) { + data[i][j] = items[i].getText(j); + } + } + + tango.core.Array.sort(data, new RowComparator(column)); + + if (lastSortColumn !is column) { + table.setSortColumn(table.getColumn(column)); + table.setSortDirection(DWT.DOWN); + for (int i = 0; i < data.length; i++) { + items[i].setText(data[i]); + } + lastSortColumn = column; + } else { + // reverse order if the current column is selected again + table.setSortDirection(DWT.UP); + int j = data.length -1; + for (int i = 0; i < data.length; i++) { + items[i].setText(data[j--]); + } + lastSortColumn = -1; + } + +} +/** + * Creates all the items located in the File submenu and + * associate all the menu items with their appropriate + * functions. + * + * @param menuBar Menu + * the Menu that file contain + * the File submenu. + */ +private void createFileMenu(Menu menuBar) { + //File menu. + MenuItem item = new MenuItem(menuBar, DWT.CASCADE); + item.setText(resAddressBook.getString("File_menu_title")); + Menu menu = new Menu(shell, DWT.DROP_DOWN); + item.setMenu(menu); + /** + * Adds a listener to handle enabling and disabling + * some items in the Edit submenu. + */ + menu.addMenuListener(new class() MenuAdapter { + public void menuShown(MenuEvent e) { + Menu menu = cast(Menu)e.widget; + MenuItem[] items = menu.getItems(); + items[1].setEnabled(table.getSelectionCount() !is 0); // edit contact + items[5].setEnabled((file !is null) && isModified); // save + items[6].setEnabled(table.getItemCount() !is 0); // save as + } + }); + + + //File -> New Contact + MenuItem subItem = new MenuItem(menu, DWT.NONE); + subItem.setText(resAddressBook.getString("New_contact")); + subItem.setAccelerator(DWT.MOD1 + 'N'); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + newEntry(); + } + }); + subItem = new MenuItem(menu, DWT.NONE); + subItem.setText(resAddressBook.getString("Edit_contact")); + subItem.setAccelerator(DWT.MOD1 + 'E'); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + TableItem[] items = table.getSelection(); + if (items.length is 0) return; + editEntry(items[0]); + } + }); + + + new MenuItem(menu, DWT.SEPARATOR); + + //File -> New Address Book + subItem = new MenuItem(menu, DWT.NONE); + subItem.setText(resAddressBook.getString("New_address_book")); + subItem.setAccelerator(DWT.MOD1 + 'B'); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + if (closeAddressBook()) { + newAddressBook(); + } + } + }); + + //File -> Open + subItem = new MenuItem(menu, DWT.NONE); + subItem.setText(resAddressBook.getString("Open_address_book")); + subItem.setAccelerator(DWT.MOD1 + 'O'); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + if (closeAddressBook()) { + openAddressBook(); + } + } + }); + + //File -> Save. + subItem = new MenuItem(menu, DWT.NONE); + subItem.setText(resAddressBook.getString("Save_address_book")); + subItem.setAccelerator(DWT.MOD1 + 'S'); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + save(); + } + }); + + //File -> Save As. + subItem = new MenuItem(menu, DWT.NONE); + subItem.setText(resAddressBook.getString("Save_book_as")); + subItem.setAccelerator(DWT.MOD1 + 'A'); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + saveAs(); + } + }); + + + new MenuItem(menu, DWT.SEPARATOR); + + //File -> Exit. + subItem = new MenuItem(menu, DWT.NONE); + subItem.setText(resAddressBook.getString("Exit")); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + shell.close(); + } + }); +} + +/** + * Creates all the items located in the Edit submenu and + * associate all the menu items with their appropriate + * functions. + * + * @param menuBar Menu + * the Menu that file contain + * the Edit submenu. + * + * @see #createSortMenu() + */ +private MenuItem createEditMenu(Menu menuBar) { + //Edit menu. + MenuItem item = new MenuItem(menuBar, DWT.CASCADE); + item.setText(resAddressBook.getString("Edit_menu_title")); + Menu menu = new Menu(shell, DWT.DROP_DOWN); + item.setMenu(menu); + + /** + * Add a listener to handle enabling and disabling + * some items in the Edit submenu. + */ + menu.addMenuListener(new class() MenuAdapter { + public void menuShown(MenuEvent e) { + Menu menu = cast(Menu)e.widget; + MenuItem[] items = menu.getItems(); + int count = table.getSelectionCount(); + items[0].setEnabled(count !is 0); // edit + items[1].setEnabled(count !is 0); // copy + items[2].setEnabled(copyBuffer !is null); // paste + items[3].setEnabled(count !is 0); // delete + items[5].setEnabled(table.getItemCount() !is 0); // sort + } + }); + + //Edit -> Edit + MenuItem subItem = new MenuItem(menu, DWT.PUSH); + subItem.setText(resAddressBook.getString("Edit")); + subItem.setAccelerator(DWT.MOD1 + 'E'); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + TableItem[] items = table.getSelection(); + if (items.length is 0) return; + editEntry(items[0]); + } + }); + + //Edit -> Copy + subItem = new MenuItem(menu, DWT.NONE); + subItem.setText(resAddressBook.getString("Copy")); + subItem.setAccelerator(DWT.MOD1 + 'C'); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + TableItem[] items = table.getSelection(); + if (items.length is 0) return; + copyBuffer = new char[][table.getColumnCount()]; + for (int i = 0; i < copyBuffer.length; i++) { + copyBuffer[i] = items[0].getText(i); + } + } + }); + + //Edit -> Paste + subItem = new MenuItem(menu, DWT.NONE); + subItem.setText(resAddressBook.getString("Paste")); + subItem.setAccelerator(DWT.MOD1 + 'V'); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + if (copyBuffer is null) return; + TableItem item = new TableItem(table, DWT.NONE); + item.setText(copyBuffer); + isModified = true; + } + }); + + //Edit -> Delete + subItem = new MenuItem(menu, DWT.NONE); + subItem.setText(resAddressBook.getString("Delete")); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + TableItem[] items = table.getSelection(); + if (items.length is 0) return; + items[0].dispose(); + isModified = true; } + }); + + new MenuItem(menu, DWT.SEPARATOR); + + //Edit -> Sort(Cascade) + subItem = new MenuItem(menu, DWT.CASCADE); + subItem.setText(resAddressBook.getString("Sort")); + Menu submenu = createSortMenu(); + subItem.setMenu(submenu); + + return item; + +} + +/** + * Creates all the items located in the Sort cascading submenu and + * associate all the menu items with their appropriate + * functions. + * + * @return Menu + * The cascading menu with all the sort menu items on it. + */ +private Menu createSortMenu() { + Menu submenu = new Menu(shell, DWT.DROP_DOWN); + MenuItem subitem; + for(int i = 0; i < columnNames.length; i++) { + subitem = new MenuItem (submenu, DWT.NONE); + subitem.setText(columnNames [i]); + int column = i; + subitem.addSelectionListener(new class(column) SelectionAdapter { + int c; + this(int c){ this.c = c; } + public void widgetSelected(SelectionEvent e) { + sort(c); + } + }); + } + + return submenu; +} + +/** + * Creates all the items located in the Search submenu and + * associate all the menu items with their appropriate + * functions. + * + * @param menuBar Menu + * the Menu that file contain + * the Search submenu. + */ +private void createSearchMenu(Menu menuBar) { + //Search menu. + MenuItem item = new MenuItem(menuBar, DWT.CASCADE); + item.setText(resAddressBook.getString("Search_menu_title")); + Menu searchMenu = new Menu(shell, DWT.DROP_DOWN); + item.setMenu(searchMenu); + + //Search -> Find... + item = new MenuItem(searchMenu, DWT.NONE); + item.setText(resAddressBook.getString("Find")); + item.setAccelerator(DWT.MOD1 + 'F'); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + searchDialog.setMatchCase(false); + searchDialog.setMatchWord(false); + searchDialog.setSearchDown(true); + searchDialog.setSearchString(""); + searchDialog.setSelectedSearchArea(0); + searchDialog.open(); + } + }); + + //Search -> Find Next + item = new MenuItem(searchMenu, DWT.NONE); + item.setText(resAddressBook.getString("Find_next")); + item.setAccelerator(DWT.F3); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + searchDialog.open(); + } + }); +} + +/** + * Creates all items located in the popup menu and associates + * all the menu items with their appropriate functions. + * + * @return Menu + * The created popup menu. + */ +private Menu createPopUpMenu() { + Menu popUpMenu = new Menu(shell, DWT.POP_UP); + + /** + * Adds a listener to handle enabling and disabling + * some items in the Edit submenu. + */ + popUpMenu.addMenuListener(new class() MenuAdapter { + public void menuShown(MenuEvent e) { + Menu menu = cast(Menu)e.widget; + MenuItem[] items = menu.getItems(); + int count = table.getSelectionCount(); + items[2].setEnabled(count !is 0); // edit + items[3].setEnabled(count !is 0); // copy + items[4].setEnabled(copyBuffer !is null); // paste + items[5].setEnabled(count !is 0); // delete + items[7].setEnabled(table.getItemCount() !is 0); // find + } + }); + + //New + MenuItem item = new MenuItem(popUpMenu, DWT.PUSH); + item.setText(resAddressBook.getString("Pop_up_new")); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + newEntry(); + } + }); + + new MenuItem(popUpMenu, DWT.SEPARATOR); + + //Edit + item = new MenuItem(popUpMenu, DWT.PUSH); + item.setText(resAddressBook.getString("Pop_up_edit")); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + TableItem[] items = table.getSelection(); + if (items.length is 0) return; + editEntry(items[0]); + } + }); + + //Copy + item = new MenuItem(popUpMenu, DWT.PUSH); + item.setText(resAddressBook.getString("Pop_up_copy")); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + TableItem[] items = table.getSelection(); + if (items.length is 0) return; + copyBuffer = new char[][table.getColumnCount()]; + for (int i = 0; i < copyBuffer.length; i++) { + copyBuffer[i] = items[0].getText(i); + } + } + }); + + //Paste + item = new MenuItem(popUpMenu, DWT.PUSH); + item.setText(resAddressBook.getString("Pop_up_paste")); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + if (copyBuffer is null) return; + TableItem item = new TableItem(table, DWT.NONE); + item.setText(copyBuffer); + isModified = true; + } + }); + + //Delete + item = new MenuItem(popUpMenu, DWT.PUSH); + item.setText(resAddressBook.getString("Pop_up_delete")); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + TableItem[] items = table.getSelection(); + if (items.length is 0) return; + items[0].dispose(); + isModified = true; + } + }); + + new MenuItem(popUpMenu, DWT.SEPARATOR); + + //Find... + item = new MenuItem(popUpMenu, DWT.PUSH); + item.setText(resAddressBook.getString("Pop_up_find")); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + searchDialog.open(); + } + }); + + return popUpMenu; +} + +/** + * Creates all the items located in the Help submenu and + * associate all the menu items with their appropriate + * functions. + * + * @param menuBar Menu + * the Menu that file contain + * the Help submenu. + */ +private void createHelpMenu(Menu menuBar) { + + //Help Menu + MenuItem item = new MenuItem(menuBar, DWT.CASCADE); + item.setText(resAddressBook.getString("Help_menu_title")); + Menu menu = new Menu(shell, DWT.DROP_DOWN); + item.setMenu(menu); + + //Help -> About Text Editor + MenuItem subItem = new MenuItem(menu, DWT.NONE); + subItem.setText(resAddressBook.getString("About")); + subItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + MessageBox box = new MessageBox(shell, DWT.NONE); + box.setText(resAddressBook.getString("About_1") ~ shell.getText()); + box.setMessage(shell.getText() ~ resAddressBook.getString("About_2")); + box.open(); + } + }); +} + + +/** + * To compare entries (rows) by the given column + */ +private class RowComparator /*: Comparator*/ { + private int column; + + /** + * Constructs a RowComparator given the column index + * @param col The index (starting at zero) of the column + */ + public this(int col) { + column = col; + } + + /** + * Compares two rows (type char[][]) using the specified + * column entry. + * @param obj1 First row to compare + * @param obj2 Second row to compare + * @return negative if obj1 less than obj2, positive if + * obj1 greater than obj2, and zero if equal. + */ + public bool compare(char[][] row1, char[][] row2) { + return row1[column] < row2[column]; + } + + alias compare opCall; +} + +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/addressbook/DataEntryDialog.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/addressbook/DataEntryDialog.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,177 @@ +/******************************************************************************* + * 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 + *******************************************************************************/ +module examples.addressbook.DataEntryDialog; + +import dwt.DWT; +import dwt.events.ModifyEvent; +import dwt.events.ModifyListener; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Composite; +import dwt.widgets.Display; +import dwt.widgets.Label; +import dwt.widgets.Shell; +import dwt.widgets.Text; + +import dwt.dwthelper.ResourceBundle; +import dwt.dwthelper.utils; + +/** + * DataEntryDialog class uses org.eclipse.swt + * libraries to implement a dialog that accepts basic personal information that + * is added to a Table widget or edits a TableItem entry + * to represent the entered data. + */ +public class DataEntryDialog { + + private static ResourceBundle resAddressBook; + + Shell shell; + char[][] values; + char[][] labels; + +public this(Shell parent) { + if( resAddressBook is null ){ + resAddressBook = ResourceBundle.getBundle("examples_addressbook"); + } + shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.PRIMARY_MODAL); + shell.setLayout(new GridLayout()); +} + +private void addTextListener(Text text) { + text.addModifyListener(new class(text) ModifyListener { + Text text; + this( Text text ){ this.text = text; } + public void modifyText(ModifyEvent e){ + Integer index = cast(Integer)(this.text.getData("index")); + values[index.intValue()] = this.text.getText(); + } + }); +} +private void createControlButtons() { + Composite composite = new Composite(shell, DWT.NONE); + composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + composite.setLayout(layout); + + Button okButton = new Button(composite, DWT.PUSH); + okButton.setText(resAddressBook.getString("OK")); + okButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + shell.close(); + } + }); + + Button cancelButton = new Button(composite, DWT.PUSH); + cancelButton.setText(resAddressBook.getString("Cancel")); + cancelButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + values = null; + shell.close(); + } + }); + + shell.setDefaultButton(okButton); +} + +private void createTextWidgets() { + if (labels is null) return; + + Composite composite = new Composite(shell, DWT.NONE); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + GridLayout layout= new GridLayout(); + layout.numColumns = 2; + composite.setLayout(layout); + + if (values is null) + values = new char[][labels.length]; + + for (int i = 0; i < labels.length; i++) { + Label label = new Label(composite, DWT.RIGHT); + label.setText(labels[i]); + Text text = new Text(composite, DWT.BORDER); + GridData gridData = new GridData(); + gridData.widthHint = 400; + text.setLayoutData(gridData); + if (values[i] !is null) { + text.setText(values[i]); + } + text.setData("index", new Integer(i)); + addTextListener(text); + } +} + +public char[][] getLabels() { + return labels; +} +public char[] getTitle() { + return shell.getText(); +} +/** + * Returns the contents of the Text widgets in the dialog in a + * char[] array. + * + * @return char[][] + * The contents of the text widgets of the dialog. + * May return null if all text widgets are empty. + */ +public char[][] getValues() { + return values; +} +/** + * Opens the dialog in the given state. Sets Text widget contents + * and dialog behaviour accordingly. + * + * @param dialogState int + * The state the dialog should be opened in. + */ +public char[][] open() { + createTextWidgets(); + createControlButtons(); + shell.pack(); + shell.open(); + Display display = shell.getDisplay(); + while(!shell.isDisposed()){ + if(!display.readAndDispatch()) + display.sleep(); + } + + return getValues(); +} +public void setLabels(char[][] labels) { + this.labels = labels; +} +public void setTitle(char[] title) { + shell.setText(title); +} +/** + * Sets the values of the Text widgets of the dialog to + * the values supplied in the parameter array. + * + * @param itemInfo char[][] + * The values to which the dialog contents will be set. + */ +public void setValues(char[][] itemInfo) { + if (labels is null) return; + + if (values is null) + values = new char[][labels.length]; + + int numItems = Math.min(values.length, itemInfo.length); + for(int i = 0; i < numItems; i++) { + values[i] = itemInfo[i]; + } +} +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/addressbook/FindListener.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/addressbook/FindListener.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 + *******************************************************************************/ +module examples.addressbook.FindListener; + + +public interface FindListener { + +public bool find(); + +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/addressbook/SearchDialog.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/addressbook/SearchDialog.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,221 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 + *******************************************************************************/ +module examples.addressbook.SearchDialog; + + +import dwt.DWT; +import dwt.events.ModifyEvent; +import dwt.events.ModifyListener; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.ShellAdapter; +import dwt.events.ShellEvent; +import dwt.layout.FillLayout; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Combo; +import dwt.widgets.Composite; +import dwt.widgets.Group; +import dwt.widgets.Label; +import dwt.widgets.MessageBox; +import dwt.widgets.Shell; +import dwt.widgets.Text; + +import examples.addressbook.FindListener; + +import dwt.dwthelper.ResourceBundle; + +/** + * SearchDialog is a simple class that uses org.eclipse.swt + * libraries to implement a basic search dialog. + */ +public class SearchDialog { + + private static ResourceBundle resAddressBook; + + Shell shell; + Text searchText; + Combo searchArea; + Label searchAreaLabel; + Button matchCase; + Button matchWord; + Button findButton; + Button down; + FindListener findHandler; + +/** + * Class constructor that sets the parent shell and the table widget that + * the dialog will search. + * + * @param parent Shell + * The shell that is the parent of the dialog. + */ +public this(Shell parent) { + if( resAddressBook is null ){ + resAddressBook = ResourceBundle.getBundle("examples_addressbook"); + } + shell = new Shell(parent, DWT.CLOSE | DWT.BORDER | DWT.TITLE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + shell.setLayout(layout); + shell.setText(resAddressBook.getString("Search_dialog_title")); + shell.addShellListener(new class() ShellAdapter{ + public void shellClosed(ShellEvent e) { + // don't dispose of the shell, just hide it for later use + e.doit = false; + shell.setVisible(false); + } + }); + + Label label = new Label(shell, DWT.LEFT); + label.setText(resAddressBook.getString("Dialog_find_what")); + searchText = new Text(shell, DWT.BORDER); + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.widthHint = 200; + searchText.setLayoutData(gridData); + searchText.addModifyListener(new class() ModifyListener { + public void modifyText(ModifyEvent e) { + bool enableFind = (searchText.getCharCount() !is 0); + findButton.setEnabled(enableFind); + } + }); + + searchAreaLabel = new Label(shell, DWT.LEFT); + searchArea = new Combo(shell, DWT.DROP_DOWN | DWT.READ_ONLY); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.widthHint = 200; + searchArea.setLayoutData(gridData); + + matchCase = new Button(shell, DWT.CHECK); + matchCase.setText(resAddressBook.getString("Dialog_match_case")); + gridData = new GridData(); + gridData.horizontalSpan = 2; + matchCase.setLayoutData(gridData); + + matchWord = new Button(shell, DWT.CHECK); + matchWord.setText(resAddressBook.getString("Dialog_match_word")); + gridData = new GridData(); + gridData.horizontalSpan = 2; + matchWord.setLayoutData(gridData); + + Group direction = new Group(shell, DWT.NONE); + gridData = new GridData(); + gridData.horizontalSpan = 2; + direction.setLayoutData(gridData); + direction.setLayout (new FillLayout ()); + direction.setText(resAddressBook.getString("Dialog_direction")); + + Button up = new Button(direction, DWT.RADIO); + up.setText(resAddressBook.getString("Dialog_dir_up")); + up.setSelection(false); + + down = new Button(direction, DWT.RADIO); + down.setText(resAddressBook.getString("Dialog_dir_down")); + down.setSelection(true); + + Composite composite = new Composite(shell, DWT.NONE); + gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gridData.horizontalSpan = 2; + composite.setLayoutData(gridData); + layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = true; + composite.setLayout(layout); + + findButton = new Button(composite, DWT.PUSH); + findButton.setText(resAddressBook.getString("Dialog_find")); + findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + findButton.setEnabled(false); + findButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + if (!findHandler.find()){ + MessageBox box = new MessageBox(shell, DWT.ICON_INFORMATION | DWT.OK | DWT.PRIMARY_MODAL); + box.setText(shell.getText()); + box.setMessage(resAddressBook.getString("Cannot_find") ~ "\"" ~ searchText.getText() ~ "\""); + box.open(); + } + } + }); + + Button cancelButton = new Button(composite, DWT.PUSH); + cancelButton.setText(resAddressBook.getString("Cancel")); + cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); + cancelButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + shell.setVisible(false); + } + }); + + shell.pack(); +} +public char[] getSearchAreaLabel(char[] label) { + return searchAreaLabel.getText(); +} + +public char[][] getsearchAreaNames() { + return searchArea.getItems(); +} +public bool getMatchCase() { + return matchCase.getSelection(); +} +public bool getMatchWord() { + return matchWord.getSelection(); +} +public char[] getSearchString() { + return searchText.getText(); +} +public bool getSearchDown(){ + return down.getSelection(); +} +public int getSelectedSearchArea() { + return searchArea.getSelectionIndex(); +} +public void open() { + if (shell.isVisible()) { + shell.setFocus(); + } else { + shell.open(); + } + searchText.setFocus(); +} +public void setSearchAreaNames(char[][] names) { + for (int i = 0; i < names.length; i++) { + searchArea.add(names[i]); + } + searchArea.select(0); +} +public void setSearchAreaLabel(char[] label) { + searchAreaLabel.setText(label); +} +public void setMatchCase(bool match) { + matchCase.setSelection(match); +} +public void setMatchWord(bool match) { + matchWord.setSelection(match); +} +public void setSearchDown(bool searchDown){ + down.setSelection(searchDown); +} +public void setSearchString(char[] searchString) { + searchText.setText(searchString); +} + +public void setSelectedSearchArea(int index) { + searchArea.select(index); +} +public void addFindListener(FindListener listener) { + this.findHandler = listener; +} +public void removeFindListener(FindListener listener) { + this.findHandler = null; +} +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/clipboard/ClipboardExample.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/clipboard/ClipboardExample.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,495 @@ +/******************************************************************************* + * 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 gmail.com + *******************************************************************************/ +module examples.clipboard.ClipboardExample; + +import dwt.DWT; +import dwt.custom.ScrolledComposite; +import dwt.custom.StyledText; +import dwt.dnd.Clipboard; +import dwt.dnd.FileTransfer; +import dwt.dnd.HTMLTransfer; +import dwt.dnd.RTFTransfer; +import dwt.dnd.TextTransfer; +import dwt.dnd.Transfer; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +import dwt.layout.FillLayout; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Combo; +import dwt.widgets.Composite; +import dwt.widgets.DirectoryDialog; +import dwt.widgets.Display; +import dwt.widgets.FileDialog; +import dwt.widgets.Group; +import dwt.widgets.Label; +import dwt.widgets.List; +import dwt.widgets.Shell; +import dwt.widgets.Table; +import dwt.widgets.TableItem; +import dwt.widgets.Text; +import dwt.dwthelper.utils; + +import tango.io.Stdout; + +class ClipboardExample { + static const int SIZE = 60; + Clipboard clipboard; + Shell shell; + Text copyText; + Text pasteText; + Text copyRtfText; + Text pasteRtfText; + Text copyHtmlText; + Text pasteHtmlText; + Table copyFileTable; + Table pasteFileTable; + Text text; + Combo combo; + StyledText styledText; + Label status; + + public void open(Display display) { + clipboard = new Clipboard(display); + shell = new Shell (display); + shell.setText("DWT Clipboard"); + shell.setLayout(new FillLayout()); + + ScrolledComposite sc = new ScrolledComposite(shell, DWT.H_SCROLL | DWT.V_SCROLL); + Composite parent = new Composite(sc, DWT.NONE); + sc.setContent(parent); + parent.setLayout(new GridLayout(2, true)); + + Group copyGroup = new Group(parent, DWT.NONE); + copyGroup.setText("Copy From:"); + GridData data = new GridData(GridData.FILL_BOTH); + copyGroup.setLayoutData(data); + copyGroup.setLayout(new GridLayout(3, false)); + + Group pasteGroup = new Group(parent, DWT.NONE); + pasteGroup.setText("Paste To:"); + data = new GridData(GridData.FILL_BOTH); + pasteGroup.setLayoutData(data); + pasteGroup.setLayout(new GridLayout(3, false)); + + Group controlGroup = new Group(parent, DWT.NONE); + controlGroup.setText("Control API:"); + data = new GridData(GridData.FILL_BOTH); + data.horizontalSpan = 2; + controlGroup.setLayoutData(data); + controlGroup.setLayout(new GridLayout(5, false)); + + /* Enable with Available Types * + Group typesGroup = new Group(parent, DWT.NONE); + typesGroup.setText("Available Types"); + data = new GridData(GridData.FILL_BOTH); + data.horizontalSpan = 2; + typesGroup.setLayoutData(data); + typesGroup.setLayout(new GridLayout(2, false)); + /**/ + + status = new Label(parent, DWT.BORDER); + data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + data.heightHint = 60; + status.setLayoutData(data); + + createTextTransfer(copyGroup, pasteGroup); + //TODO: Doesn't work +// createRTFTransfer(copyGroup, pasteGroup); + createHTMLTransfer(copyGroup, pasteGroup); + //TODO: Doesn't work +// createFileTransfer(copyGroup, pasteGroup); + createMyTransfer(copyGroup, pasteGroup); + createControlTransfer(controlGroup); + //TODO: Causes Segfault +// createAvailableTypes(typesGroup); + + sc.setMinSize(parent.computeSize(DWT.DEFAULT, DWT.DEFAULT)); + sc.setExpandHorizontal(true); + sc.setExpandVertical(true); + + Point size = shell.computeSize(DWT.DEFAULT, DWT.DEFAULT); + Rectangle monitorArea = shell.getMonitor().getClientArea(); + shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20)); + shell.open(); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + clipboard.dispose(); + } + void createTextTransfer(Composite copyParent, Composite pasteParent) { + + // TextTransfer + Label l = new Label(copyParent, DWT.NONE); + l.setText("TextTransfer:"); //$NON-NLS-1$ + copyText = new Text(copyParent, DWT.MULTI | DWT.BORDER | DWT.V_SCROLL | DWT.H_SCROLL); + copyText.setText("some\nplain\ntext"); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.heightHint = data.widthHint = SIZE; + copyText.setLayoutData(data); + Button b = new Button(copyParent, DWT.PUSH); + b.setText("Copy"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + auto data = copyText.getText(); + if (data.length > 0) { + status.setText(""); + auto obj = new Object[1]; + auto trans = new TextTransfer[1]; + obj[0] = cast(Object) new ArrayWrapperString(data); + trans[0] = TextTransfer.getInstance(); + clipboard.setContents(obj, trans); + } else { + status.setText("nothing to copy"); + } + } + }); + + l = new Label(pasteParent, DWT.NONE); + l.setText("TextTransfer:"); //$NON-NLS-1$ + pasteText = new Text(pasteParent, DWT.READ_ONLY | DWT.MULTI | DWT.BORDER | DWT.V_SCROLL | DWT.H_SCROLL); + data = new GridData(GridData.FILL_HORIZONTAL); + data.heightHint = data.widthHint = SIZE; + pasteText.setLayoutData(data); + b = new Button(pasteParent, DWT.PUSH); + b.setText("Paste"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + auto data = cast(ArrayWrapperString) clipboard.getContents(TextTransfer.getInstance()); + if (data !is null) { + status.setText(""); + pasteText.setText("begin paste>"~data.array~" 0) { + status.setText(""); + data = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i " ~ data ~ "}"; + auto obj = new Object[1]; + auto trans = new Transfer[1]; + obj[0] = cast(Object) new ArrayWrapperString(data); + trans[0] = RTFTransfer.getInstance(); + clipboard.setContents(obj, trans); + } else { + status.setText("nothing to copy"); + } + } + }); + + l = new Label(pasteParent, DWT.NONE); + l.setText("RTFTransfer:"); //$NON-NLS-1$ + pasteRtfText = new Text(pasteParent, DWT.READ_ONLY | DWT.MULTI | DWT.BORDER | DWT.V_SCROLL | DWT.H_SCROLL); + data = new GridData(GridData.FILL_HORIZONTAL); + data.heightHint = data.widthHint = SIZE; + pasteRtfText.setLayoutData(data); + b = new Button(pasteParent, DWT.PUSH); + b.setText("Paste"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + auto data = cast(ArrayWrapperString) clipboard.getContents(RTFTransfer.getInstance()); + if (data !is null) { + status.setText(""); + pasteRtfText.setText("begin paste>"~data.array~"Hello World"); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.heightHint = data.widthHint = SIZE; + copyHtmlText.setLayoutData(data); + Button b = new Button(copyParent, DWT.PUSH); + b.setText("Copy"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + auto data = copyHtmlText.getText(); + if (data.length > 0) { + status.setText(""); + auto obj = new Object[1]; + auto trans = new Transfer[1]; + obj[0] = cast(Object) new ArrayWrapperString(data); + trans[0] = HTMLTransfer.getInstance(); + clipboard.setContents(obj, trans); + } else { + status.setText("nothing to copy"); + } + } + }); + + l = new Label(pasteParent, DWT.NONE); + l.setText("HTMLTransfer:"); //$NON-NLS-1$ + pasteHtmlText = new Text(pasteParent, DWT.READ_ONLY | DWT.MULTI | DWT.BORDER | DWT.V_SCROLL | DWT.H_SCROLL); + data = new GridData(GridData.FILL_HORIZONTAL); + data.heightHint = data.widthHint = SIZE; + pasteHtmlText.setLayoutData(data); + b = new Button(pasteParent, DWT.PUSH); + b.setText("Paste"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + auto data = cast(ArrayWrapperString) clipboard.getContents(HTMLTransfer.getInstance()); + if (data !is null) { + status.setText(""); + pasteHtmlText.setText("begin paste>"~data.array~" 0){ + //copyFileTable.removeAll(); + //This cannot be used + //auto separator = System.getProperty("file.separator"); + version(linux) { + auto separator = "/"; + } + version(Windows) { + auto separator = "\\"; + } + auto path = dialog.getFilterPath(); + auto names = dialog.getFileNames(); + for (int i = 0; i < names.length; i++) { + TableItem item = new TableItem(copyFileTable, DWT.NONE); + item.setText(path~separator~names[i]); + } + } + } + }); + b = new Button(c, DWT.PUSH); + b.setText("Select directory"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + DirectoryDialog dialog = new DirectoryDialog(shell, DWT.OPEN); + auto result = dialog.open(); + if (result !is null && result.length > 0){ + //copyFileTable.removeAll(); + TableItem item = new TableItem(copyFileTable, DWT.NONE); + item.setText(result); + } + } + }); + + b = new Button(copyParent, DWT.PUSH); + b.setText("Copy"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + TableItem[] items = copyFileTable.getItems(); + if (items.length > 0){ + status.setText(""); + auto data = new char[][items.length]; + for (int i = 0; i < data.length; i++) { + data[i] = items[i].getText(); + } + auto obj = new Object[1]; + auto trans = new Transfer[1]; + obj[0] = cast(Object) new ArrayWrapperString2(data); + trans[0] = FileTransfer.getInstance(); + clipboard.setContents(obj, trans); + } else { + status.setText("nothing to copy"); + } + } + }); + + l = new Label(pasteParent, DWT.NONE); + l.setText("FileTransfer:"); //$NON-NLS-1$ + pasteFileTable = new Table(pasteParent, DWT.MULTI | DWT.BORDER); + data = new GridData(GridData.FILL_HORIZONTAL); + data.heightHint = data.widthHint = SIZE; + pasteFileTable.setLayoutData(data); + b = new Button(pasteParent, DWT.PUSH); + b.setText("Paste"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + auto data = cast(ArrayWrapperString2) clipboard.getContents(FileTransfer.getInstance()); + if (data !is null && data.array.length > 0) { + status.setText(""); + pasteFileTable.removeAll(); + foreach (s; data.array) { + TableItem item = new TableItem(pasteFileTable, DWT.NONE); + item.setText(s); + } + } else { + status.setText("nothing to paste"); + } + } + }); + } + void createMyTransfer(Composite copyParent, Composite pasteParent){ + // MyType Transfer + // TODO + } + void createControlTransfer(Composite parent){ + Label l = new Label(parent, DWT.NONE); + l.setText("Text:"); + Button b = new Button(parent, DWT.PUSH); + b.setText("Cut"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + text.cut(); + } + }); + b = new Button(parent, DWT.PUSH); + b.setText("Copy"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + text.copy(); + } + }); + b = new Button(parent, DWT.PUSH); + b.setText("Paste"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + text.paste(); + } + }); + text = new Text(parent, DWT.BORDER | DWT.MULTI | DWT.H_SCROLL | DWT.V_SCROLL); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.heightHint = data.widthHint = SIZE; + text.setLayoutData(data); + + l = new Label(parent, DWT.NONE); + l.setText("Combo:"); + b = new Button(parent, DWT.PUSH); + b.setText("Cut"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + combo.cut(); + } + }); + b = new Button(parent, DWT.PUSH); + b.setText("Copy"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + combo.copy(); + } + }); + b = new Button(parent, DWT.PUSH); + b.setText("Paste"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + combo.paste(); + } + }); + combo = new Combo(parent, DWT.NONE); + char[][] str = new char[][4]; + str[0] = "Item 1"; + str[1] = "Item 2"; + str[2] = "Item 3"; + str[3] = "A longer Item"; + combo.setItems(str); + + l = new Label(parent, DWT.NONE); + l.setText("StyledText:"); + l = new Label(parent, DWT.NONE); + l.setVisible(false); + b = new Button(parent, DWT.PUSH); + b.setText("Copy"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + styledText.copy(); + } + }); + b = new Button(parent, DWT.PUSH); + b.setText("Paste"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + styledText.paste(); + } + }); + styledText = new StyledText(parent, DWT.BORDER | DWT.MULTI | DWT.H_SCROLL | DWT.V_SCROLL); + data = new GridData(GridData.FILL_HORIZONTAL); + data.heightHint = data.widthHint = SIZE; + styledText.setLayoutData(data); + } + void createAvailableTypes(Composite parent){ + final List list = new List(parent, DWT.BORDER | DWT.H_SCROLL | DWT.V_SCROLL); + GridData data = new GridData(GridData.FILL_BOTH); + data.heightHint = 100; + list.setLayoutData(data); + Button b = new Button(parent, DWT.PUSH); + b.setText("Get Available Types"); + b.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + list.removeAll(); + auto names = clipboard.getAvailableTypeNames(); + for (int i = 0; i < names.length; i++) { + list.add(names[i]); + } + } + }); + } +} +void main() { + Stdout.formatln( "The ClipboardExample: still work left" ); + Stdout.formatln( "todo: RTF, File Transfer, Available types"); + Stdout.formatln( "line 300, there might be a better way to do" ); + Stdout.formatln( "system independent path seperators in tango" ); + Stdout.formatln( "" ); + + + Display display = new Display(); + (new ClipboardExample()).open(display); + display.dispose(); +} + diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/AlignableTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/AlignableTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.AlignableTab; + + + +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.SelectionListener; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.Widget; + +import dwtexamples.controlexample.Tab; +import dwtexamples.controlexample.ControlExample; + +/** + * AlignableTab is the abstract + * superclass of example controls that can be + * aligned. + */ +abstract class AlignableTab : Tab { + + /* Alignment Controls */ + Button leftButton, rightButton, centerButton; + + /* Alignment Group */ + Group alignmentGroup; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Other" group. + */ + void createOtherGroup () { + super.createOtherGroup (); + + /* Create the group */ + alignmentGroup = new Group (otherGroup, DWT.NONE); + alignmentGroup.setLayout (new GridLayout ()); + alignmentGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | + GridData.VERTICAL_ALIGN_FILL)); + alignmentGroup.setText (ControlExample.getResourceString("Alignment")); + + /* Create the controls */ + leftButton = new Button (alignmentGroup, DWT.RADIO); + leftButton.setText (ControlExample.getResourceString("Left")); + centerButton = new Button (alignmentGroup, DWT.RADIO); + centerButton.setText(ControlExample.getResourceString("Center")); + rightButton = new Button (alignmentGroup, DWT.RADIO); + rightButton.setText (ControlExample.getResourceString("Right")); + + /* Add the listeners */ + SelectionListener selectionListener = new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + if (!(cast(Button) event.widget).getSelection ()) return; + setExampleWidgetAlignment (); + } + }; + leftButton.addSelectionListener (selectionListener); + centerButton.addSelectionListener (selectionListener); + rightButton.addSelectionListener (selectionListener); + } + + /** + * Sets the alignment of the "Example" widgets. + */ + abstract void setExampleWidgetAlignment (); + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + Widget [] widgets = getExampleWidgets (); + if (widgets.length !is 0) { + leftButton.setSelection ((widgets [0].getStyle () & DWT.LEFT) !is 0); + centerButton.setSelection ((widgets [0].getStyle () & DWT.CENTER) !is 0); + rightButton.setSelection ((widgets [0].getStyle () & DWT.RIGHT) !is 0); + } + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/ButtonTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/ButtonTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,244 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.ButtonTab; + + + +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.SelectionListener; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.Widget; + +import dwtexamples.controlexample.AlignableTab; +import dwtexamples.controlexample.ControlExample; + +/** + * ButtonTab is the class that + * demonstrates DWT buttons. + */ +class ButtonTab : AlignableTab { + + /* Example widgets and groups that contain them */ + Button button1, button2, button3, button4, button5, button6, button7, button8, button9; + Group textButtonGroup, imageButtonGroup, imagetextButtonGroup; + + /* Alignment widgets added to the "Control" group */ + Button upButton, downButton; + + /* Style widgets added to the "Style" group */ + Button pushButton, checkButton, radioButton, toggleButton, arrowButton, flatButton; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Control" group. + */ + void createControlGroup () { + super.createControlGroup (); + + /* Create the controls */ + upButton = new Button (alignmentGroup, DWT.RADIO); + upButton.setText (ControlExample.getResourceString("Up")); + downButton = new Button (alignmentGroup, DWT.RADIO); + downButton.setText (ControlExample.getResourceString("Down")); + + /* Add the listeners */ + SelectionListener selectionListener = new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + if (!(cast(Button) event.widget).getSelection()) return; + setExampleWidgetAlignment (); + } + }; + upButton.addSelectionListener(selectionListener); + downButton.addSelectionListener(selectionListener); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for text buttons */ + textButtonGroup = new Group(exampleGroup, DWT.NONE); + GridLayout gridLayout = new GridLayout (); + textButtonGroup.setLayout(gridLayout); + gridLayout.numColumns = 3; + textButtonGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + textButtonGroup.setText (ControlExample.getResourceString("Text_Buttons")); + + /* Create a group for the image buttons */ + imageButtonGroup = new Group(exampleGroup, DWT.NONE); + gridLayout = new GridLayout(); + imageButtonGroup.setLayout(gridLayout); + gridLayout.numColumns = 3; + imageButtonGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + imageButtonGroup.setText (ControlExample.getResourceString("Image_Buttons")); + + /* Create a group for the image and text buttons */ + imagetextButtonGroup = new Group(exampleGroup, DWT.NONE); + gridLayout = new GridLayout(); + imagetextButtonGroup.setLayout(gridLayout); + gridLayout.numColumns = 3; + imagetextButtonGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + imagetextButtonGroup.setText (ControlExample.getResourceString("Image_Text_Buttons")); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (pushButton.getSelection()) style |= DWT.PUSH; + if (checkButton.getSelection()) style |= DWT.CHECK; + if (radioButton.getSelection()) style |= DWT.RADIO; + if (toggleButton.getSelection()) style |= DWT.TOGGLE; + if (flatButton.getSelection()) style |= DWT.FLAT; + if (borderButton.getSelection()) style |= DWT.BORDER; + if (leftButton.getSelection()) style |= DWT.LEFT; + if (rightButton.getSelection()) style |= DWT.RIGHT; + if (arrowButton.getSelection()) { + style |= DWT.ARROW; + if (upButton.getSelection()) style |= DWT.UP; + if (downButton.getSelection()) style |= DWT.DOWN; + } else { + if (centerButton.getSelection()) style |= DWT.CENTER; + } + + /* Create the example widgets */ + button1 = new Button(textButtonGroup, style); + button1.setText(ControlExample.getResourceString("One")); + button2 = new Button(textButtonGroup, style); + button2.setText(ControlExample.getResourceString("Two")); + button3 = new Button(textButtonGroup, style); + button3.setText(ControlExample.getResourceString("Three")); + button4 = new Button(imageButtonGroup, style); + button4.setImage(instance.images[ControlExample.ciClosedFolder]); + button5 = new Button(imageButtonGroup, style); + button5.setImage(instance.images[ControlExample.ciOpenFolder]); + button6 = new Button(imageButtonGroup, style); + button6.setImage(instance.images[ControlExample.ciTarget]); + button7 = new Button(imagetextButtonGroup, style); + button7.setText(ControlExample.getResourceString("One")); + button7.setImage(instance.images[ControlExample.ciClosedFolder]); + button8 = new Button(imagetextButtonGroup, style); + button8.setText(ControlExample.getResourceString("Two")); + button8.setImage(instance.images[ControlExample.ciOpenFolder]); + button9 = new Button(imagetextButtonGroup, style); + button9.setText(ControlExample.getResourceString("Three")); + button9.setImage(instance.images[ControlExample.ciTarget]); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup (); + + /* Create the extra widgets */ + pushButton = new Button (styleGroup, DWT.RADIO); + pushButton.setText("DWT.PUSH"); + checkButton = new Button (styleGroup, DWT.RADIO); + checkButton.setText ("DWT.CHECK"); + radioButton = new Button (styleGroup, DWT.RADIO); + radioButton.setText ("DWT.RADIO"); + toggleButton = new Button (styleGroup, DWT.RADIO); + toggleButton.setText ("DWT.TOGGLE"); + arrowButton = new Button (styleGroup, DWT.RADIO); + arrowButton.setText ("DWT.ARROW"); + flatButton = new Button (styleGroup, DWT.CHECK); + flatButton.setText ("DWT.FLAT"); + borderButton = new Button (styleGroup, DWT.CHECK); + borderButton.setText ("DWT.BORDER"); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) button1, button2, button3, button4, button5, button6, button7, button8, button9 ]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return [ cast(char[])"Selection", "Text", "ToolTipText" ]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Button"; + } + + /** + * Sets the alignment of the "Example" widgets. + */ + void setExampleWidgetAlignment () { + int alignment = 0; + if (leftButton.getSelection ()) alignment = DWT.LEFT; + if (centerButton.getSelection ()) alignment = DWT.CENTER; + if (rightButton.getSelection ()) alignment = DWT.RIGHT; + if (upButton.getSelection ()) alignment = DWT.UP; + if (downButton.getSelection ()) alignment = DWT.DOWN; + button1.setAlignment (alignment); + button2.setAlignment (alignment); + button3.setAlignment (alignment); + button4.setAlignment (alignment); + button5.setAlignment (alignment); + button6.setAlignment (alignment); + button7.setAlignment (alignment); + button8.setAlignment (alignment); + button9.setAlignment (alignment); + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + if (arrowButton.getSelection ()) { + upButton.setEnabled (true); + centerButton.setEnabled (false); + downButton.setEnabled (true); + } else { + upButton.setEnabled (false); + centerButton.setEnabled (true); + downButton.setEnabled (false); + } + upButton.setSelection ((button1.getStyle () & DWT.UP) !is 0); + downButton.setSelection ((button1.getStyle () & DWT.DOWN) !is 0); + pushButton.setSelection ((button1.getStyle () & DWT.PUSH) !is 0); + checkButton.setSelection ((button1.getStyle () & DWT.CHECK) !is 0); + radioButton.setSelection ((button1.getStyle () & DWT.RADIO) !is 0); + toggleButton.setSelection ((button1.getStyle () & DWT.TOGGLE) !is 0); + arrowButton.setSelection ((button1.getStyle () & DWT.ARROW) !is 0); + flatButton.setSelection ((button1.getStyle () & DWT.FLAT) !is 0); + borderButton.setSelection ((button1.getStyle () & DWT.BORDER) !is 0); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/CComboTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/CComboTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.CComboTab; + + + +import dwt.DWT; +import dwt.custom.CCombo; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.Widget; + +import dwtexamples.controlexample.Tab; +import dwtexamples.controlexample.ControlExample; + +class CComboTab : Tab { + + /* Example widgets and groups that contain them */ + CCombo combo1; + Group comboGroup; + + /* Style widgets added to the "Style" group */ + Button flatButton, readOnlyButton; + + static char[] [] ListData; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + if( ListData is null ){ + ListData = [ + ControlExample.getResourceString("ListData1_0"), + ControlExample.getResourceString("ListData1_1"), + ControlExample.getResourceString("ListData1_2"), + ControlExample.getResourceString("ListData1_3"), + ControlExample.getResourceString("ListData1_4"), + ControlExample.getResourceString("ListData1_5"), + ControlExample.getResourceString("ListData1_6"), + ControlExample.getResourceString("ListData1_7"), + ControlExample.getResourceString("ListData1_8")]; + } + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the combo box */ + comboGroup = new Group (exampleGroup, DWT.NONE); + comboGroup.setLayout (new GridLayout ()); + comboGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + comboGroup.setText (ControlExample.getResourceString("Custom_Combo")); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (flatButton.getSelection ()) style |= DWT.FLAT; + if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY; + if (borderButton.getSelection ()) style |= DWT.BORDER; + + /* Create the example widgets */ + combo1 = new CCombo (comboGroup, style); + combo1.setItems (ListData); + if (ListData.length >= 3) { + combo1.setText(ListData [2]); + } + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup () { + super.createStyleGroup (); + + /* Create the extra widgets */ + readOnlyButton = new Button (styleGroup, DWT.CHECK); + readOnlyButton.setText ("DWT.READ_ONLY"); + borderButton = new Button (styleGroup, DWT.CHECK); + borderButton.setText ("DWT.BORDER"); + flatButton = new Button (styleGroup, DWT.CHECK); + flatButton.setText ("DWT.FLAT"); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [cast(Widget) combo1]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Editable", "Items", "Selection", "Text", "TextLimit", "ToolTipText", "VisibleItemCount"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "CCombo"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + flatButton.setSelection ((combo1.getStyle () & DWT.FLAT) !is 0); + readOnlyButton.setSelection ((combo1.getStyle () & DWT.READ_ONLY) !is 0); + borderButton.setSelection ((combo1.getStyle () & DWT.BORDER) !is 0); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/CLabelTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/CLabelTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.CLabelTab; + + + +import dwt.DWT; +import dwt.custom.CLabel; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.Widget; + + +import dwtexamples.controlexample.AlignableTab; +import dwtexamples.controlexample.ControlExample; + +import tango.text.convert.Format; + +class CLabelTab : AlignableTab { + /* Example widgets and groups that contain them */ + CLabel label1, label2, label3; + Group textLabelGroup; + + /* Style widgets added to the "Style" group */ + Button shadowInButton, shadowOutButton, shadowNoneButton; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the text labels */ + textLabelGroup = new Group(exampleGroup, DWT.NONE); + GridLayout gridLayout = new GridLayout (); + textLabelGroup.setLayout (gridLayout); + gridLayout.numColumns = 3; + textLabelGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + textLabelGroup.setText (ControlExample.getResourceString("Custom_Labels")); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (shadowInButton.getSelection ()) style |= DWT.SHADOW_IN; + if (shadowNoneButton.getSelection ()) style |= DWT.SHADOW_NONE; + if (shadowOutButton.getSelection ()) style |= DWT.SHADOW_OUT; + if (leftButton.getSelection ()) style |= DWT.LEFT; + if (centerButton.getSelection ()) style |= DWT.CENTER; + if (rightButton.getSelection ()) style |= DWT.RIGHT; + + /* Create the example widgets */ + label1 = new CLabel (textLabelGroup, style); + label1.setText(ControlExample.getResourceString("One")); + label1.setImage (instance.images[ControlExample.ciClosedFolder]); + label2 = new CLabel (textLabelGroup, style); + label2.setImage (instance.images[ControlExample.ciTarget]); + label3 = new CLabel (textLabelGroup, style); + label3.setText(Format( "{}\n{}", ControlExample.getResourceString("Example_string"), ControlExample.getResourceString("One_Two_Three"))); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup (); + + /* Create the extra widgets */ + shadowNoneButton = new Button (styleGroup, DWT.RADIO); + shadowNoneButton.setText ("DWT.SHADOW_NONE"); + shadowInButton = new Button (styleGroup, DWT.RADIO); + shadowInButton.setText ("DWT.SHADOW_IN"); + shadowOutButton = new Button (styleGroup, DWT.RADIO); + shadowOutButton.setText ("DWT.SHADOW_OUT"); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) label1, label2, label3]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Text", "ToolTipText"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "CLabel"; + } + + /** + * Sets the alignment of the "Example" widgets. + */ + void setExampleWidgetAlignment () { + int alignment = 0; + if (leftButton.getSelection ()) alignment = DWT.LEFT; + if (centerButton.getSelection ()) alignment = DWT.CENTER; + if (rightButton.getSelection ()) alignment = DWT.RIGHT; + label1.setAlignment (alignment); + label2.setAlignment (alignment); + label3.setAlignment (alignment); + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + leftButton.setSelection ((label1.getStyle () & DWT.LEFT) !is 0); + centerButton.setSelection ((label1.getStyle () & DWT.CENTER) !is 0); + rightButton.setSelection ((label1.getStyle () & DWT.RIGHT) !is 0); + shadowInButton.setSelection ((label1.getStyle () & DWT.SHADOW_IN) !is 0); + shadowOutButton.setSelection ((label1.getStyle () & DWT.SHADOW_OUT) !is 0); + shadowNoneButton.setSelection ((label1.getStyle () & (DWT.SHADOW_IN | DWT.SHADOW_OUT)) is 0); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/CTabFolderTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/CTabFolderTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,478 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.CTabFolderTab; + + + +import dwt.DWT; +import dwt.custom.CTabFolder; +import dwt.custom.CTabFolder2Adapter; +import dwt.custom.CTabFolderEvent; +import dwt.custom.CTabItem; +import dwt.events.DisposeEvent; +import dwt.events.DisposeListener; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.graphics.Color; +import dwt.graphics.Font; +import dwt.graphics.FontData; +import dwt.graphics.Image; +import dwt.graphics.RGB; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Event; +import dwt.widgets.Group; +import dwt.widgets.Item; +import dwt.widgets.Listener; +import dwt.widgets.TableItem; +import dwt.widgets.Text; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +import tango.text.convert.Format; + +class CTabFolderTab : Tab { + int lastSelectedTab = 0; + + /* Example widgets and groups that contain them */ + CTabFolder tabFolder1; + Group tabFolderGroup, itemGroup; + + /* Style widgets added to the "Style" group */ + Button topButton, bottomButton, flatButton, closeButton; + + static char[] [] CTabItems1; + + /* Controls and resources added to the "Fonts" group */ + static const int SELECTION_FOREGROUND_COLOR = 3; + static const int SELECTION_BACKGROUND_COLOR = 4; + static const int ITEM_FONT = 5; + Color selectionForegroundColor, selectionBackgroundColor; + Font itemFont; + + /* Other widgets added to the "Other" group */ + Button simpleTabButton, singleTabButton, imageButton, showMinButton, showMaxButton, unselectedCloseButton, unselectedImageButton; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + if( CTabItems1 is null ){ + CTabItems1 = [ + ControlExample.getResourceString("CTabItem1_0"), + ControlExample.getResourceString("CTabItem1_1"), + ControlExample.getResourceString("CTabItem1_2")]; + } + } + + /** + * Creates the "Colors and Fonts" group. + */ + void createColorAndFontGroup () { + super.createColorAndFontGroup(); + + TableItem item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Selection_Foreground_Color")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Selection_Background_Color")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Item_Font")); + + shell.addDisposeListener(new class() DisposeListener { + public void widgetDisposed(DisposeEvent event) { + if (selectionBackgroundColor !is null) selectionBackgroundColor.dispose(); + if (selectionForegroundColor !is null) selectionForegroundColor.dispose(); + if (itemFont !is null) itemFont.dispose(); + selectionBackgroundColor = null; + selectionForegroundColor = null; + itemFont = null; + } + }); + } + + void changeFontOrColor(int index) { + switch (index) { + case SELECTION_FOREGROUND_COLOR: { + Color oldColor = selectionForegroundColor; + if (oldColor is null) oldColor = tabFolder1.getSelectionForeground(); + colorDialog.setRGB(oldColor.getRGB()); + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = selectionForegroundColor; + selectionForegroundColor = new Color (display, rgb); + setSelectionForeground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case SELECTION_BACKGROUND_COLOR: { + Color oldColor = selectionBackgroundColor; + if (oldColor is null) oldColor = tabFolder1.getSelectionBackground(); + colorDialog.setRGB(oldColor.getRGB()); + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = selectionBackgroundColor; + selectionBackgroundColor = new Color (display, rgb); + setSelectionBackground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case ITEM_FONT: { + Font oldFont = itemFont; + if (oldFont is null) oldFont = tabFolder1.getItem (0).getFont (); + fontDialog.setFontList(oldFont.getFontData()); + FontData fontData = fontDialog.open (); + if (fontData is null) return; + oldFont = itemFont; + itemFont = new Font (display, fontData); + setItemFont (); + setExampleWidgetSize (); + if (oldFont !is null) oldFont.dispose (); + } + break; + default: + super.changeFontOrColor(index); + } + } + + /** + * Creates the "Other" group. + */ + void createOtherGroup () { + super.createOtherGroup (); + + /* Create display controls specific to this example */ + simpleTabButton = new Button (otherGroup, DWT.CHECK); + simpleTabButton.setText (ControlExample.getResourceString("Set_Simple_Tabs")); + simpleTabButton.setSelection(true); + simpleTabButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setSimpleTabs(); + } + }); + + singleTabButton = new Button (otherGroup, DWT.CHECK); + singleTabButton.setText (ControlExample.getResourceString("Set_Single_Tabs")); + singleTabButton.setSelection(false); + singleTabButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setSingleTabs(); + } + }); + + showMinButton = new Button (otherGroup, DWT.CHECK); + showMinButton.setText (ControlExample.getResourceString("Set_Min_Visible")); + showMinButton.setSelection(false); + showMinButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setMinimizeVisible(); + } + }); + + showMaxButton = new Button (otherGroup, DWT.CHECK); + showMaxButton.setText (ControlExample.getResourceString("Set_Max_Visible")); + showMaxButton.setSelection(false); + showMaxButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setMaximizeVisible(); + } + }); + + imageButton = new Button (otherGroup, DWT.CHECK); + imageButton.setText (ControlExample.getResourceString("Set_Image")); + imageButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setImages(); + } + }); + + unselectedImageButton = new Button (otherGroup, DWT.CHECK); + unselectedImageButton.setText (ControlExample.getResourceString("Set_Unselected_Image_Visible")); + unselectedImageButton.setSelection(true); + unselectedImageButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setUnselectedImageVisible(); + } + }); + unselectedCloseButton = new Button (otherGroup, DWT.CHECK); + unselectedCloseButton.setText (ControlExample.getResourceString("Set_Unselected_Close_Visible")); + unselectedCloseButton.setSelection(true); + unselectedCloseButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setUnselectedCloseVisible(); + } + }); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the CTabFolder */ + tabFolderGroup = new Group (exampleGroup, DWT.NONE); + tabFolderGroup.setLayout (new GridLayout ()); + tabFolderGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + tabFolderGroup.setText ("CTabFolder"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (topButton.getSelection ()) style |= DWT.TOP; + if (bottomButton.getSelection ()) style |= DWT.BOTTOM; + if (borderButton.getSelection ()) style |= DWT.BORDER; + if (flatButton.getSelection ()) style |= DWT.FLAT; + if (closeButton.getSelection ()) style |= DWT.CLOSE; + + /* Create the example widgets */ + tabFolder1 = new CTabFolder (tabFolderGroup, style); + for (int i = 0; i < CTabItems1.length; i++) { + CTabItem item = new CTabItem(tabFolder1, DWT.NONE); + item.setText(CTabItems1[i]); + Text text = new Text(tabFolder1, DWT.READ_ONLY); + text.setText(Format( "{}: {}", ControlExample.getResourceString("CTabItem_content"), i)); + item.setControl(text); + } + tabFolder1.addListener(DWT.Selection, new class() Listener { + public void handleEvent(Event event) { + lastSelectedTab = tabFolder1.getSelectionIndex(); + } + }); + tabFolder1.setSelection(lastSelectedTab); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup (); + + /* Create the extra widgets */ + topButton = new Button (styleGroup, DWT.RADIO); + topButton.setText ("DWT.TOP"); + topButton.setSelection(true); + bottomButton = new Button (styleGroup, DWT.RADIO); + bottomButton.setText ("DWT.BOTTOM"); + borderButton = new Button (styleGroup, DWT.CHECK); + borderButton.setText ("DWT.BORDER"); + flatButton = new Button (styleGroup, DWT.CHECK); + flatButton.setText ("DWT.FLAT"); + closeButton = new Button (styleGroup, DWT.CHECK); + closeButton.setText ("DWT.CLOSE"); + } + + /** + * Gets the list of custom event names. + * + * @return an array containing custom event names + */ + char[] [] getCustomEventNames () { + return ["CTabFolderEvent"]; + } + + /** + * Gets the "Example" widget children's items, if any. + * + * @return an array containing the example widget children's items + */ + Item [] getExampleWidgetItems () { + return tabFolder1.getItems(); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) tabFolder1]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "CTabFolder"; + } + + /** + * Hooks the custom listener specified by eventName. + */ + void hookCustomListener (char[] eventName) { + if (eventName is "CTabFolderEvent") { + tabFolder1.addCTabFolder2Listener (new class(eventName) CTabFolder2Adapter { + char[] name; + this( char[] name ){ this.name = name; } + public void close (CTabFolderEvent event) { + log (name, event); + } + }); + } + } + + /** + * Sets the foreground color, background color, and font + * of the "Example" widgets to their default settings. + * Also sets foreground and background color of the Node 1 + * TreeItems to default settings. + */ + void resetColorsAndFonts () { + super.resetColorsAndFonts (); + Color oldColor = selectionForegroundColor; + selectionForegroundColor = null; + setSelectionForeground (); + if (oldColor !is null) oldColor.dispose(); + oldColor = selectionBackgroundColor; + selectionBackgroundColor = null; + setSelectionBackground (); + if (oldColor !is null) oldColor.dispose(); + Font oldFont = itemFont; + itemFont = null; + setItemFont (); + if (oldFont !is null) oldFont.dispose(); + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState(); + setSimpleTabs(); + setSingleTabs(); + setImages(); + setMinimizeVisible(); + setMaximizeVisible(); + setUnselectedCloseVisible(); + setUnselectedImageVisible(); + setSelectionBackground (); + setSelectionForeground (); + setItemFont (); + setExampleWidgetSize(); + } + + /** + * Sets the shape that the CTabFolder will use to render itself. + */ + void setSimpleTabs () { + tabFolder1.setSimple (simpleTabButton.getSelection ()); + setExampleWidgetSize(); + } + + /** + * Sets the number of tabs that the CTabFolder should display. + */ + void setSingleTabs () { + tabFolder1.setSingle (singleTabButton.getSelection ()); + setExampleWidgetSize(); + } + /** + * Sets an image into each item of the "Example" widgets. + */ + void setImages () { + bool setImage = imageButton.getSelection (); + CTabItem items[] = tabFolder1.getItems (); + for (int i = 0; i < items.length; i++) { + if (setImage) { + items[i].setImage (instance.images[ControlExample.ciClosedFolder]); + } else { + items[i].setImage (null); + } + } + setExampleWidgetSize (); + } + /** + * Sets the visibility of the minimize button + */ + void setMinimizeVisible () { + tabFolder1.setMinimizeVisible(showMinButton.getSelection ()); + setExampleWidgetSize(); + } + /** + * Sets the visibility of the maximize button + */ + void setMaximizeVisible () { + tabFolder1.setMaximizeVisible(showMaxButton.getSelection ()); + setExampleWidgetSize(); + } + /** + * Sets the visibility of the close button on unselected tabs + */ + void setUnselectedCloseVisible () { + tabFolder1.setUnselectedCloseVisible(unselectedCloseButton.getSelection ()); + setExampleWidgetSize(); + } + /** + * Sets the visibility of the image on unselected tabs + */ + void setUnselectedImageVisible () { + tabFolder1.setUnselectedImageVisible(unselectedImageButton.getSelection ()); + setExampleWidgetSize(); + } + /** + * Sets the background color of CTabItem 0. + */ + void setSelectionBackground () { + if (!instance.startup) { + tabFolder1.setSelectionBackground(selectionBackgroundColor); + } + // Set the selection background item's image to match the background color of the selection. + Color color = selectionBackgroundColor; + if (color is null) color = tabFolder1.getSelectionBackground (); + TableItem item = colorAndFontTable.getItem(SELECTION_BACKGROUND_COLOR); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (colorImage(color)); + } + + /** + * Sets the foreground color of CTabItem 0. + */ + void setSelectionForeground () { + if (!instance.startup) { + tabFolder1.setSelectionForeground(selectionForegroundColor); + } + // Set the selection foreground item's image to match the foreground color of the selection. + Color color = selectionForegroundColor; + if (color is null) color = tabFolder1.getSelectionForeground (); + TableItem item = colorAndFontTable.getItem(SELECTION_FOREGROUND_COLOR); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (colorImage(color)); + } + + /** + * Sets the font of CTabItem 0. + */ + void setItemFont () { + if (!instance.startup) { + tabFolder1.getItem (0).setFont (itemFont); + setExampleWidgetSize(); + } + /* Set the font item's image to match the font of the item. */ + Font ft = itemFont; + if (ft is null) ft = tabFolder1.getItem (0).getFont (); + TableItem item = colorAndFontTable.getItem(ITEM_FONT); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (fontImage(ft)); + item.setFont(ft); + colorAndFontTable.layout (); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/CanvasTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/CanvasTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,335 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.CanvasTab; + + + +import dwt.DWT; +import dwt.events.ControlAdapter; +import dwt.events.ControlEvent; +import dwt.events.PaintEvent; +import dwt.events.PaintListener; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.graphics.Color; +import dwt.graphics.Font; +import dwt.graphics.GC; +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Canvas; +import dwt.widgets.Caret; +import dwt.widgets.Composite; +import dwt.widgets.Group; +import dwt.widgets.ScrollBar; +import dwt.widgets.TabFolder; +import dwt.widgets.Widget; + +import dwtexamples.controlexample.Tab; +import dwtexamples.controlexample.ControlExample; + +class CanvasTab : Tab { + static const int colors [] = [ + DWT.COLOR_RED, + DWT.COLOR_GREEN, + DWT.COLOR_BLUE, + DWT.COLOR_MAGENTA, + DWT.COLOR_YELLOW, + DWT.COLOR_CYAN, + DWT.COLOR_DARK_RED, + DWT.COLOR_DARK_GREEN, + DWT.COLOR_DARK_BLUE, + DWT.COLOR_DARK_MAGENTA, + DWT.COLOR_DARK_YELLOW, + DWT.COLOR_DARK_CYAN + ]; + static final char[] canvasString = "Canvas"; //$NON-NLS-1$ + + /* Example widgets and groups that contain them */ + Canvas canvas; + Group canvasGroup; + + /* Style widgets added to the "Style" group */ + Button horizontalButton, verticalButton, noBackgroundButton, noFocusButton, + noMergePaintsButton, noRedrawResizeButton, doubleBufferedButton; + + /* Other widgets added to the "Other" group */ + Button caretButton, fillDamageButton; + + int paintCount; + int cx, cy; + int maxX, maxY; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Other" group. + */ + void createOtherGroup () { + super.createOtherGroup (); + + /* Create display controls specific to this example */ + caretButton = new Button (otherGroup, DWT.CHECK); + caretButton.setText (ControlExample.getResourceString("Caret")); + fillDamageButton = new Button (otherGroup, DWT.CHECK); + fillDamageButton.setText (ControlExample.getResourceString("FillDamage")); + + /* Add the listeners */ + caretButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setCaret (); + } + }); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the canvas widget */ + canvasGroup = new Group (exampleGroup, DWT.NONE); + canvasGroup.setLayout (new GridLayout ()); + canvasGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + canvasGroup.setText ("Canvas"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; + if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; + if (borderButton.getSelection ()) style |= DWT.BORDER; + if (noBackgroundButton.getSelection ()) style |= DWT.NO_BACKGROUND; + if (noFocusButton.getSelection ()) style |= DWT.NO_FOCUS; + if (noMergePaintsButton.getSelection ()) style |= DWT.NO_MERGE_PAINTS; + if (noRedrawResizeButton.getSelection ()) style |= DWT.NO_REDRAW_RESIZE; + if (doubleBufferedButton.getSelection ()) style |= DWT.DOUBLE_BUFFERED; + + /* Create the example widgets */ + paintCount = 0; cx = 0; cy = 0; + canvas = new Canvas (canvasGroup, style); + canvas.addPaintListener(new class() PaintListener { + public void paintControl(PaintEvent e) { + paintCount++; + GC gc = e.gc; + if (fillDamageButton.getSelection ()) { + Color color = e.display.getSystemColor (colors [paintCount % colors.length]); + gc.setBackground(color); + gc.fillRectangle(e.x, e.y, e.width, e.height); + } + Point size = canvas.getSize (); + gc.drawArc(cx + 1, cy + 1, size.x - 2, size.y - 2, 0, 360); + gc.drawRectangle(cx + (size.x - 10) / 2, cy + (size.y - 10) / 2, 10, 10); + Point extent = gc.textExtent(canvasString); + gc.drawString(canvasString, cx + (size.x - extent.x) / 2, cy - extent.y + (size.y - 10) / 2, true); + } + }); + canvas.addControlListener(new class() ControlAdapter { + public void controlResized(ControlEvent event) { + Point size = canvas.getSize (); + maxX = size.x * 3 / 2; maxY = size.y * 3 / 2; + resizeScrollBars (); + } + }); + ScrollBar bar = canvas.getHorizontalBar(); + if (bar !is null) { + hookListeners (bar); + bar.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + scrollHorizontal (cast(ScrollBar)event.widget); + } + }); + } + bar = canvas.getVerticalBar(); + if (bar !is null) { + hookListeners (bar); + bar.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + scrollVertical (cast(ScrollBar)event.widget); + } + }); + } + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup(); + + /* Create the extra widgets */ + horizontalButton = new Button (styleGroup, DWT.CHECK); + horizontalButton.setText ("DWT.H_SCROLL"); + horizontalButton.setSelection(true); + verticalButton = new Button (styleGroup, DWT.CHECK); + verticalButton.setText ("DWT.V_SCROLL"); + verticalButton.setSelection(true); + borderButton = new Button (styleGroup, DWT.CHECK); + borderButton.setText ("DWT.BORDER"); + noBackgroundButton = new Button (styleGroup, DWT.CHECK); + noBackgroundButton.setText ("DWT.NO_BACKGROUND"); + noFocusButton = new Button (styleGroup, DWT.CHECK); + noFocusButton.setText ("DWT.NO_FOCUS"); + noMergePaintsButton = new Button (styleGroup, DWT.CHECK); + noMergePaintsButton.setText ("DWT.NO_MERGE_PAINTS"); + noRedrawResizeButton = new Button (styleGroup, DWT.CHECK); + noRedrawResizeButton.setText ("DWT.NO_REDRAW_RESIZE"); + doubleBufferedButton = new Button (styleGroup, DWT.CHECK); + doubleBufferedButton.setText ("DWT.DOUBLE_BUFFERED"); + } + + /** + * Creates the tab folder page. + * + * @param tabFolder org.eclipse.swt.widgets.TabFolder + * @return the new page for the tab folder + */ + Composite createTabFolderPage (TabFolder tabFolder) { + super.createTabFolderPage (tabFolder); + + /* + * Add a resize listener to the tabFolderPage so that + * if the user types into the example widget to change + * its preferred size, and then resizes the shell, we + * recalculate the preferred size correctly. + */ + tabFolderPage.addControlListener(new class() ControlAdapter { + public void controlResized(ControlEvent e) { + setExampleWidgetSize (); + } + }); + + return tabFolderPage; + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) canvas ]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["ToolTipText"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Canvas"; + } + + /** + * Resizes the maximum and thumb of both scrollbars. + */ + void resizeScrollBars () { + Rectangle clientArea = canvas.getClientArea(); + ScrollBar bar = canvas.getHorizontalBar(); + if (bar !is null) { + bar.setMaximum(maxX); + bar.setThumb(clientArea.width); + bar.setPageIncrement(clientArea.width); + } + bar = canvas.getVerticalBar(); + if (bar !is null) { + bar.setMaximum(maxY); + bar.setThumb(clientArea.height); + bar.setPageIncrement(clientArea.height); + } + } + + /** + * Scrolls the canvas horizontally. + * + * @param scrollBar + */ + void scrollHorizontal (ScrollBar scrollBar) { + Rectangle bounds = canvas.getClientArea(); + int x = -scrollBar.getSelection(); + if (x + maxX < bounds.width) { + x = bounds.width - maxX; + } + canvas.scroll(x, cy, cx, cy, maxX, maxY, false); + cx = x; + } + + /** + * Scrolls the canvas vertically. + * + * @param scrollBar + */ + void scrollVertical (ScrollBar scrollBar) { + Rectangle bounds = canvas.getClientArea(); + int y = -scrollBar.getSelection(); + if (y + maxY < bounds.height) { + y = bounds.height - maxY; + } + canvas.scroll(cx, y, cx, cy, maxX, maxY, false); + cy = y; + } + + /** + * Sets or clears the caret in the "Example" widget. + */ + void setCaret () { + Caret oldCaret = canvas.getCaret (); + if (caretButton.getSelection ()) { + Caret newCaret = new Caret(canvas, DWT.NONE); + Font font = canvas.getFont(); + newCaret.setFont(font); + GC gc = new GC(canvas); + gc.setFont(font); + newCaret.setBounds(1, 1, 1, gc.getFontMetrics().getHeight()); + gc.dispose(); + canvas.setCaret (newCaret); + canvas.setFocus(); + } else { + canvas.setCaret (null); + } + if (oldCaret !is null) oldCaret.dispose (); + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + horizontalButton.setSelection ((canvas.getStyle () & DWT.H_SCROLL) !is 0); + verticalButton.setSelection ((canvas.getStyle () & DWT.V_SCROLL) !is 0); + borderButton.setSelection ((canvas.getStyle () & DWT.BORDER) !is 0); + noBackgroundButton.setSelection ((canvas.getStyle () & DWT.NO_BACKGROUND) !is 0); + noFocusButton.setSelection ((canvas.getStyle () & DWT.NO_FOCUS) !is 0); + noMergePaintsButton.setSelection ((canvas.getStyle () & DWT.NO_MERGE_PAINTS) !is 0); + noRedrawResizeButton.setSelection ((canvas.getStyle () & DWT.NO_REDRAW_RESIZE) !is 0); + doubleBufferedButton.setSelection ((canvas.getStyle () & DWT.DOUBLE_BUFFERED) !is 0); + if (!instance.startup) setCaret (); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/ComboTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/ComboTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,164 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 dwtexamples.controlexample.ComboTab; + + + +import dwt.DWT; +import dwt.events.ControlAdapter; +import dwt.events.ControlEvent; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Combo; +import dwt.widgets.Composite; +import dwt.widgets.Group; +import dwt.widgets.TabFolder; +import dwt.widgets.Widget; + +import dwtexamples.controlexample.Tab; +import dwtexamples.controlexample.ControlExample; + +class ComboTab : Tab { + + /* Example widgets and groups that contain them */ + Combo combo1; + Group comboGroup; + + /* Style widgets added to the "Style" group */ + Button dropDownButton, readOnlyButton, simpleButton; + + static char[] [] ListData; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + if( ListData.length is 0 ){ + ListData = [ControlExample.getResourceString("ListData0_0"), + ControlExample.getResourceString("ListData0_1"), + ControlExample.getResourceString("ListData0_2"), + ControlExample.getResourceString("ListData0_3"), + ControlExample.getResourceString("ListData0_4"), + ControlExample.getResourceString("ListData0_5"), + ControlExample.getResourceString("ListData0_6"), + ControlExample.getResourceString("ListData0_7"), + ControlExample.getResourceString("ListData0_8")]; + } + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the combo box */ + comboGroup = new Group (exampleGroup, DWT.NONE); + comboGroup.setLayout (new GridLayout ()); + comboGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + comboGroup.setText ("Combo"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (dropDownButton.getSelection ()) style |= DWT.DROP_DOWN; + if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY; + if (simpleButton.getSelection ()) style |= DWT.SIMPLE; + + /* Create the example widgets */ + combo1 = new Combo (comboGroup, style); + combo1.setItems (ListData); + if (ListData.length >= 3) { + combo1.setText(ListData [2]); + } + } + + /** + * Creates the tab folder page. + * + * @param tabFolder org.eclipse.swt.widgets.TabFolder + * @return the new page for the tab folder + */ + Composite createTabFolderPage (TabFolder tabFolder) { + super.createTabFolderPage (tabFolder); + + /* + * Add a resize listener to the tabFolderPage so that + * if the user types into the example widget to change + * its preferred size, and then resizes the shell, we + * recalculate the preferred size correctly. + */ + tabFolderPage.addControlListener(new class() ControlAdapter { + public void controlResized(ControlEvent e) { + setExampleWidgetSize (); + } + }); + + return tabFolderPage; + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup () { + super.createStyleGroup (); + + /* Create the extra widgets */ + dropDownButton = new Button (styleGroup, DWT.RADIO); + dropDownButton.setText ("DWT.DROP_DOWN"); + simpleButton = new Button (styleGroup, DWT.RADIO); + simpleButton.setText("DWT.SIMPLE"); + readOnlyButton = new Button (styleGroup, DWT.CHECK); + readOnlyButton.setText ("DWT.READ_ONLY"); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) combo1]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Items", "Orientation", "Selection", "Text", "TextLimit", "ToolTipText", "VisibleItemCount"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Combo"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + dropDownButton.setSelection ((combo1.getStyle () & DWT.DROP_DOWN) !is 0); + simpleButton.setSelection ((combo1.getStyle () & DWT.SIMPLE) !is 0); + readOnlyButton.setSelection ((combo1.getStyle () & DWT.READ_ONLY) !is 0); + readOnlyButton.setEnabled(!simpleButton.getSelection()); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/ControlExample.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/ControlExample.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,344 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.ControlExample; + +import dwt.DWT; +import dwt.graphics.Image; +import dwt.graphics.ImageData; +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +import dwt.layout.FillLayout; +import dwt.widgets.Composite; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.TabFolder; +import dwt.widgets.TabItem; +import dwt.dwthelper.ResourceBundle; +import dwt.dwthelper.ByteArrayInputStream; + +import examples.controlexample.Tab; +import examples.controlexample.ButtonTab; +import examples.controlexample.CanvasTab; +import examples.controlexample.ComboTab; +import examples.controlexample.CoolBarTab; +import examples.controlexample.DateTimeTab; +import examples.controlexample.DialogTab; +import examples.controlexample.ExpandBarTab; +import examples.controlexample.GroupTab; +import examples.controlexample.LabelTab; +import examples.controlexample.LinkTab; +import examples.controlexample.ListTab; +import examples.controlexample.MenuTab; +import examples.controlexample.ProgressBarTab; +import examples.controlexample.SashTab; +import examples.controlexample.ScaleTab; +import examples.controlexample.ShellTab; +import examples.controlexample.SliderTab; +import examples.controlexample.SpinnerTab; +import examples.controlexample.TabFolderTab; +import examples.controlexample.TableTab; +import examples.controlexample.TextTab; +import examples.controlexample.ToolBarTab; +import examples.controlexample.ToolTipTab; +import examples.controlexample.TreeTab; + +import tango.core.Exception; +import tango.text.convert.Format; +import tango.io.Stdout; +import Math = tango.math.Math; +import dwt.dwthelper.utils; + +version(JIVE){ + import jive.stacktrace; +} + +interface IControlExampleFactory{ + ControlExample create(Shell shell, char[] title); +} + +void main(){ + Display display = new Display(); + Shell shell = new Shell(display, DWT.SHELL_TRIM); + shell.setLayout(new FillLayout()); + + IControlExampleFactory ifactory; + char[] key; + if( auto factory = ClassInfo.find( "dwtexamples.controlexample.CustomControlExample.CustomControlExampleFactory" )){ + ifactory = cast(IControlExampleFactory) factory.create; + key = "custom.window.title"; + } + else{ + ifactory = new ControlExampleFactory(); + key = "window.title"; + } + auto instance = ifactory.create( shell, key ); + ControlExample.setShellSize(instance, shell); + shell.open(); + while (! shell.isDisposed()) { + if (! display.readAndDispatch()) display.sleep(); + } + instance.dispose(); + display.dispose(); +} + +public class ControlExampleFactory : IControlExampleFactory { + ControlExample create(Shell shell, char[] title){ + Stdout.formatln( "The ControlExample: still work left" ); + Stdout.formatln( "todo: Implement Get/Set API reflection" ); + Stdout.formatln( "" ); + version(Windows){ + Stdout.formatln( "On Win2K:" ); + Stdout.formatln( "note: Buttons text+image do show only the image" ); + Stdout.formatln( " in java it behaves the same" ); + Stdout.formatln( " it is not supported on all plattforms" ); + Stdout.formatln( "" ); + } + version(linux){ + Stdout.formatln( "todo: ExpandBarTab looks strange" ); + Stdout.formatln( "On linux GTK:" ); + Stdout.formatln( "todo: DateTimeTab not implemented" ); + Stdout.formatln( "bug: ProgressBarTab crash on vertical" ); + Stdout.formatln( " in java it behaves the same" ); + Stdout.formatln( "bug: SliderTab horizontal arrow buttons are too high." ); + Stdout.formatln( " in java it behaves the same" ); + Stdout.formatln( " Known bug:" ); + Stdout.formatln( " https://bugs.eclipse.org/bugs/show_bug.cgi?id=197402" ); + Stdout.formatln( " http://bugzilla.gnome.org/show_bug.cgi?id=475909" ); + Stdout.formatln( "" ); + } + Stdout.formatln( "please report problems" ); + auto res = new ControlExample( shell ); + shell.setText(ControlExample.getResourceString("window.title")); + return res; + } +} + +public class ControlExample { + private static ResourceBundle resourceBundle; + private static const char[] resourceData = import( "dwtexamples.controlexample.controlexample.properties" ); + + private ShellTab shellTab; + private TabFolder tabFolder; + private Tab [] tabs; + Image images[]; + + static const int ciClosedFolder = 0, ciOpenFolder = 1, ciTarget = 2, ciBackground = 3, ciParentBackground = 4; + + static const byte[][] imageData = [ + cast(byte[]) import( "dwtexamples.controlexample.closedFolder.gif" ), + cast(byte[]) import( "dwtexamples.controlexample.openFolder.gif" ), + cast(byte[]) import( "dwtexamples.controlexample.target.gif" ), + cast(byte[]) import( "dwtexamples.controlexample.backgroundImage.png" ), + cast(byte[]) import( "dwtexamples.controlexample.parentBackgroundImage.png" ) + ]; + static const int[] imageTypes = [ + DWT.ICON, + DWT.ICON, + DWT.ICON, + DWT.BITMAP, + DWT.BITMAP]; + + bool startup = true; + + static this(){ + resourceBundle = ResourceBundle.getBundleFromData( resourceData ); //$NON-NLS-1$ + } + + /** + * Creates an instance of a ControlExample embedded inside + * the supplied parent Composite. + * + * @param parent the container of the example + */ + public this(Composite parent) { + initResources(); + tabFolder = new TabFolder (parent, DWT.NONE); + tabs = createTabs(); + for (int i=0; i monitorArea.width && DWT.getPlatform()=="carbon") { + TabItem [] tabItems = instance.tabFolder.getItems(); + for (int i=0; i + *******************************************************************************/ +module examples.controlexample.CoolBarTab; + + + +import dwt.DWT; +import dwt.events.MenuAdapter; +import dwt.events.MenuEvent; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.graphics.Image; +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Control; +import dwt.widgets.CoolBar; +import dwt.widgets.CoolItem; +import dwt.widgets.Event; +import dwt.widgets.Group; +import dwt.widgets.Item; +import dwt.widgets.Listener; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.Text; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import tango.util.Convert; + +class CoolBarTab : Tab { + /* Example widgets and group that contains them */ + CoolBar coolBar; + CoolItem pushItem, dropDownItem, radioItem, checkItem, textItem; + Group coolBarGroup; + + /* Style widgets added to the "Style" group */ + Button horizontalButton, verticalButton; + Button dropDownButton, flatButton; + + /* Other widgets added to the "Other" group */ + Button lockedButton; + + Point[] sizes; + int[] wrapIndices; + int[] order; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Other" group. + */ + void createOtherGroup () { + super.createOtherGroup (); + + /* Create display controls specific to this example */ + lockedButton = new Button (otherGroup, DWT.CHECK); + lockedButton.setText (ControlExample.getResourceString("Locked")); + + /* Add the listeners */ + lockedButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetLocked (); + } + }); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + coolBarGroup = new Group (exampleGroup, DWT.NONE); + coolBarGroup.setLayout (new GridLayout ()); + coolBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + coolBarGroup.setText ("CoolBar"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + int style = getDefaultStyle(), itemStyle = 0; + + /* Compute the widget, item, and item toolBar styles */ + int toolBarStyle = DWT.FLAT; + bool vertical = false; + if (horizontalButton.getSelection ()) { + style |= DWT.HORIZONTAL; + toolBarStyle |= DWT.HORIZONTAL; + } + if (verticalButton.getSelection ()) { + style |= DWT.VERTICAL; + toolBarStyle |= DWT.VERTICAL; + vertical = true; + } + if (borderButton.getSelection()) style |= DWT.BORDER; + if (flatButton.getSelection()) style |= DWT.FLAT; + if (dropDownButton.getSelection()) itemStyle |= DWT.DROP_DOWN; + + /* + * Create the example widgets. + */ + coolBar = new CoolBar (coolBarGroup, style); + + /* Create the push button toolbar cool item */ + ToolBar toolBar = new ToolBar (coolBar, toolBarStyle); + ToolItem item = new ToolItem (toolBar, DWT.PUSH); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setToolTipText ("DWT.PUSH"); + item = new ToolItem (toolBar, DWT.PUSH); + item.setImage (instance.images[ControlExample.ciOpenFolder]); + item.setToolTipText ("DWT.PUSH"); + item = new ToolItem (toolBar, DWT.PUSH); + item.setImage (instance.images[ControlExample.ciTarget]); + item.setToolTipText ("DWT.PUSH"); + item = new ToolItem (toolBar, DWT.SEPARATOR); + item = new ToolItem (toolBar, DWT.PUSH); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setToolTipText ("DWT.PUSH"); + item = new ToolItem (toolBar, DWT.PUSH); + item.setImage (instance.images[ControlExample.ciOpenFolder]); + item.setToolTipText ("DWT.PUSH"); + pushItem = new CoolItem (coolBar, itemStyle); + pushItem.setControl (toolBar); + pushItem.addSelectionListener (new CoolItemSelectionListener()); + + /* Create the dropdown toolbar cool item */ + toolBar = new ToolBar (coolBar, toolBarStyle); + item = new ToolItem (toolBar, DWT.DROP_DOWN); + item.setImage (instance.images[ControlExample.ciOpenFolder]); + item.setToolTipText ("DWT.DROP_DOWN"); + item.addSelectionListener (new DropDownSelectionListener()); + item = new ToolItem (toolBar, DWT.DROP_DOWN); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setToolTipText ("DWT.DROP_DOWN"); + item.addSelectionListener (new DropDownSelectionListener()); + dropDownItem = new CoolItem (coolBar, itemStyle); + dropDownItem.setControl (toolBar); + dropDownItem.addSelectionListener (new CoolItemSelectionListener()); + + /* Create the radio button toolbar cool item */ + toolBar = new ToolBar (coolBar, toolBarStyle); + item = new ToolItem (toolBar, DWT.RADIO); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setToolTipText ("DWT.RADIO"); + item = new ToolItem (toolBar, DWT.RADIO); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setToolTipText ("DWT.RADIO"); + item = new ToolItem (toolBar, DWT.RADIO); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setToolTipText ("DWT.RADIO"); + radioItem = new CoolItem (coolBar, itemStyle); + radioItem.setControl (toolBar); + radioItem.addSelectionListener (new CoolItemSelectionListener()); + + /* Create the check button toolbar cool item */ + toolBar = new ToolBar (coolBar, toolBarStyle); + item = new ToolItem (toolBar, DWT.CHECK); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setToolTipText ("DWT.CHECK"); + item = new ToolItem (toolBar, DWT.CHECK); + item.setImage (instance.images[ControlExample.ciTarget]); + item.setToolTipText ("DWT.CHECK"); + item = new ToolItem (toolBar, DWT.CHECK); + item.setImage (instance.images[ControlExample.ciOpenFolder]); + item.setToolTipText ("DWT.CHECK"); + item = new ToolItem (toolBar, DWT.CHECK); + item.setImage (instance.images[ControlExample.ciTarget]); + item.setToolTipText ("DWT.CHECK"); + checkItem = new CoolItem (coolBar, itemStyle); + checkItem.setControl (toolBar); + checkItem.addSelectionListener (new CoolItemSelectionListener()); + + /* Create the text cool item */ + if (!vertical) { + Text text = new Text (coolBar, DWT.BORDER | DWT.SINGLE); + textItem = new CoolItem (coolBar, itemStyle); + textItem.setControl (text); + textItem.addSelectionListener (new CoolItemSelectionListener()); + Point textSize = text.computeSize(DWT.DEFAULT, DWT.DEFAULT); + textSize = textItem.computeSize(textSize.x, textSize.y); + textItem.setMinimumSize(textSize); + textItem.setPreferredSize(textSize); + textItem.setSize(textSize); + } + + /* Set the sizes after adding all cool items */ + CoolItem[] coolItems = coolBar.getItems(); + for (int i = 0; i < coolItems.length; i++) { + CoolItem coolItem = coolItems[i]; + Control control = coolItem.getControl(); + Point size = control.computeSize(DWT.DEFAULT, DWT.DEFAULT); + Point coolSize = coolItem.computeSize(size.x, size.y); + if ( auto bar = cast(ToolBar)control ) { + if (bar.getItemCount() > 0) { + if (vertical) { + size.y = bar.getItem(0).getBounds().height; + } else { + size.x = bar.getItem(0).getWidth(); + } + } + } + coolItem.setMinimumSize(size); + coolItem.setPreferredSize(coolSize); + coolItem.setSize(coolSize); + } + + /* If we have saved state, restore it */ + if (order !is null && order.length is coolBar.getItemCount()) { + coolBar.setItemLayout(order, wrapIndices, sizes); + } else { + coolBar.setWrapIndices([1, 3]); + } + + /* Add a listener to resize the group box to match the coolbar */ + coolBar.addListener(DWT.Resize, new class() Listener { + public void handleEvent(Event event) { + exampleGroup.layout(); + } + }); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup(); + + /* Create the extra widgets */ + horizontalButton = new Button (styleGroup, DWT.RADIO); + horizontalButton.setText ("DWT.HORIZONTAL"); + verticalButton = new Button (styleGroup, DWT.RADIO); + verticalButton.setText ("DWT.VERTICAL"); + borderButton = new Button (styleGroup, DWT.CHECK); + borderButton.setText ("DWT.BORDER"); + flatButton = new Button (styleGroup, DWT.CHECK); + flatButton.setText ("DWT.FLAT"); + Group itemGroup = new Group(styleGroup, DWT.NONE); + itemGroup.setLayout (new GridLayout ()); + itemGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); + itemGroup.setText(ControlExample.getResourceString("Item_Styles")); + dropDownButton = new Button (itemGroup, DWT.CHECK); + dropDownButton.setText ("DWT.DROP_DOWN"); + } + + /** + * Disposes the "Example" widgets. + */ + void disposeExampleWidgets () { + /* store the state of the toolbar if applicable */ + if (coolBar !is null) { + sizes = coolBar.getItemSizes(); + wrapIndices = coolBar.getWrapIndices(); + order = coolBar.getItemOrder(); + } + super.disposeExampleWidgets(); + } + + /** + * Gets the "Example" widget children's items, if any. + * + * @return an array containing the example widget children's items + */ + Item [] getExampleWidgetItems () { + return coolBar.getItems(); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) coolBar]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["ToolTipText"]; + } + + /** + * Gets the short text for the tab folder item. + */ + public char[] getShortTabText() { + return "CB"; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "CoolBar"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + horizontalButton.setSelection ((coolBar.getStyle () & DWT.HORIZONTAL) !is 0); + verticalButton.setSelection ((coolBar.getStyle () & DWT.VERTICAL) !is 0); + borderButton.setSelection ((coolBar.getStyle () & DWT.BORDER) !is 0); + flatButton.setSelection ((coolBar.getStyle () & DWT.FLAT) !is 0); + dropDownButton.setSelection ((coolBar.getItem(0).getStyle () & DWT.DROP_DOWN) !is 0); + lockedButton.setSelection(coolBar.getLocked()); + if (!instance.startup) setWidgetLocked (); + } + + /** + * Sets the header visible state of the "Example" widgets. + */ + void setWidgetLocked () { + coolBar.setLocked (lockedButton.getSelection ()); + } + + /** + * Listens to widgetSelected() events on DWT.DROP_DOWN type ToolItems + * and opens/closes a menu when appropriate. + */ + class DropDownSelectionListener : SelectionAdapter { + private Menu menu = null; + private bool visible = false; + + public void widgetSelected(SelectionEvent event) { + // Create the menu if it has not already been created + if (menu is null) { + // Lazy create the menu. + menu = new Menu(shell); + menu.addMenuListener(new class() MenuAdapter { + public void menuHidden(MenuEvent e) { + visible = false; + } + }); + for (int i = 0; i < 9; ++i) { + final char[] text = ControlExample.getResourceString("DropDownData_" ~ to!(char[])(i)); + if (text.length !is 0) { + MenuItem menuItem = new MenuItem(menu, DWT.NONE); + menuItem.setText(text); + /* + * Add a menu selection listener so that the menu is hidden + * when the user selects an item from the drop down menu. + */ + menuItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + setMenuVisible(false); + } + }); + } else { + new MenuItem(menu, DWT.SEPARATOR); + } + } + } + + /** + * A selection event will be fired when a drop down tool + * item is selected in the main area and in the drop + * down arrow. Examine the event detail to determine + * where the widget was selected. + */ + if (event.detail is DWT.ARROW) { + /* + * The drop down arrow was selected. + */ + if (visible) { + // Hide the menu to give the Arrow the appearance of being a toggle button. + setMenuVisible(false); + } else { + // Position the menu below and vertically aligned with the the drop down tool button. + ToolItem toolItem = cast(ToolItem) event.widget; + ToolBar toolBar = toolItem.getParent(); + + Rectangle toolItemBounds = toolItem.getBounds(); + Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); + menu.setLocation(point.x, point.y + toolItemBounds.height); + setMenuVisible(true); + } + } else { + /* + * Main area of drop down tool item selected. + * An application would invoke the code to perform the action for the tool item. + */ + } + } + private void setMenuVisible(bool visible) { + menu.setVisible(visible); + this.visible = visible; + } + } + + /** + * Listens to widgetSelected() events on DWT.DROP_DOWN type CoolItems + * and opens/closes a menu when appropriate. + */ + class CoolItemSelectionListener : SelectionAdapter { + private Menu menu = null; + + public void widgetSelected(SelectionEvent event) { + /** + * A selection event will be fired when the cool item + * is selected by its gripper or if the drop down arrow + * (or 'chevron') is selected. Examine the event detail + * to determine where the widget was selected. + */ + if (event.detail is DWT.ARROW) { + /* If the popup menu is already up (i.e. user pressed arrow twice), + * then dispose it. + */ + if (menu !is null) { + menu.dispose(); + menu = null; + return; + } + + /* Get the cool item and convert its bounds to display coordinates. */ + CoolItem coolItem = cast(CoolItem) event.widget; + Rectangle itemBounds = coolItem.getBounds (); + itemBounds.width = event.x - itemBounds.x; + Point pt = coolBar.toDisplay(new Point (itemBounds.x, itemBounds.y)); + itemBounds.x = pt.x; + itemBounds.y = pt.y; + + /* Get the toolbar from the cool item. */ + ToolBar toolBar = cast(ToolBar) coolItem.getControl (); + ToolItem[] tools = toolBar.getItems (); + int toolCount = tools.length; + + /* Convert the bounds of each tool item to display coordinates, + * and determine which ones are past the bounds of the cool item. + */ + int i = 0; + while (i < toolCount) { + Rectangle toolBounds = tools[i].getBounds (); + pt = toolBar.toDisplay(new Point(toolBounds.x, toolBounds.y)); + toolBounds.x = pt.x; + toolBounds.y = pt.y; + Rectangle intersection = itemBounds.intersection (toolBounds); + if (intersection!=toolBounds) break; + i++; + } + + /* Create a pop-up menu with items for each of the hidden buttons. */ + menu = new Menu (coolBar); + for (int j = i; j < toolCount; j++) { + ToolItem tool = tools[j]; + Image image = tool.getImage(); + if (image is null) { + new MenuItem (menu, DWT.SEPARATOR); + } else { + if ((tool.getStyle() & DWT.DROP_DOWN) !is 0) { + MenuItem menuItem = new MenuItem (menu, DWT.CASCADE); + menuItem.setImage(image); + char[] text = tool.getToolTipText(); + if (text !is null) menuItem.setText(text); + Menu m = new Menu(menu); + menuItem.setMenu(m); + for (int k = 0; k < 9; ++k) { + text = ControlExample.getResourceString("DropDownData_" ~ to!(char[])(k)); + if (text.length !is 0) { + MenuItem mi = new MenuItem(m, DWT.NONE); + mi.setText(text); + /* Application code to perform the action for the submenu item would go here. */ + } else { + new MenuItem(m, DWT.SEPARATOR); + } + } + } else { + MenuItem menuItem = new MenuItem (menu, DWT.NONE); + menuItem.setImage(image); + char[] text = tool.getToolTipText(); + if (text !is null) menuItem.setText(text); + } + /* Application code to perform the action for the menu item would go here. */ + } + } + + /* Display the pop-up menu at the lower left corner of the arrow button. + * Dispose the menu when the user is done with it. + */ + pt = coolBar.toDisplay(new Point(event.x, event.y)); + menu.setLocation (pt.x, pt.y); + menu.setVisible (true); + while (menu !is null && !menu.isDisposed() && menu.isVisible ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + if (menu !is null) { + menu.dispose (); + menu = null; + } + } + } + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/CustomControlExample.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/CustomControlExample.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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 + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ +module examples.controlexample.CustomControlExample; + +import dwt.layout.FillLayout; +import dwt.widgets.Composite; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +import tango.io.Stdout; + +import examples.controlexample.ControlExample; +import examples.controlexample.CComboTab; +import examples.controlexample.CLabelTab; +import examples.controlexample.CTabFolderTab; +import examples.controlexample.SashFormTab; +import examples.controlexample.StyledTextTab; +import examples.controlexample.Tab; + +public class CustomControlExampleFactory : IControlExampleFactory { + CustomControlExample create(Shell shell, char[] title) { + + Stdout.formatln( "The CustomControlExample: still work left" ); + Stdout.formatln( "warning in Control:setBounds() line=695 gtk_widget_size_allocate()" ); + Stdout.formatln( "Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -5 and height 15" ); + Stdout.formatln( "for the CTabFolder widget. Params are OK. Further bugtracking needed." ); + Stdout.formatln( "please report problems" ); + + auto res = new CustomControlExample( shell ); + shell.setText(ControlExample.getResourceString("custom.window.title")); + return res; + } +} + + +public class CustomControlExample : ControlExample { + + /** + * Creates an instance of a CustomControlExample embedded + * inside the supplied parent Composite. + * + * @param parent the container of the example + */ + public this(Composite parent) { + super (parent); + } + + /** + * Answers the set of example Tabs + */ + Tab[] createTabs() { + return [ cast(Tab) + new CComboTab (this), + new CLabelTab (this), + new CTabFolderTab (this), + new SashFormTab (this), + new StyledTextTab (this) + ]; + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/DateTimeTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/DateTimeTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.DateTimeTab; + + + +import dwt.DWT; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.DateTime; +import dwt.widgets.Group; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +class DateTimeTab : Tab { + /* Example widgets and groups that contain them */ + DateTime dateTime1; + Group dateTimeGroup; + + /* Style widgets added to the "Style" group */ + Button dateButton, timeButton, calendarButton, shortButton, mediumButton, longButton; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the list */ + dateTimeGroup = new Group (exampleGroup, DWT.NONE); + dateTimeGroup.setLayout (new GridLayout ()); + dateTimeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + dateTimeGroup.setText ("DateTime"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (dateButton.getSelection ()) style |= DWT.DATE; + if (timeButton.getSelection ()) style |= DWT.TIME; + if (calendarButton.getSelection ()) style |= DWT.CALENDAR; + if (shortButton.getSelection ()) style |= DWT.SHORT; + if (mediumButton.getSelection ()) style |= DWT.MEDIUM; + if (longButton.getSelection ()) style |= DWT.LONG; + if (borderButton.getSelection ()) style |= DWT.BORDER; + + /* Create the example widgets */ + dateTime1 = new DateTime (dateTimeGroup, style); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup (); + + /* Create the extra widgets */ + dateButton = new Button(styleGroup, DWT.RADIO); + dateButton.setText("DWT.DATE"); + timeButton = new Button(styleGroup, DWT.RADIO); + timeButton.setText("DWT.TIME"); + calendarButton = new Button(styleGroup, DWT.RADIO); + calendarButton.setText("DWT.CALENDAR"); + Group formatGroup = new Group(styleGroup, DWT.NONE); + formatGroup.setLayout(new GridLayout()); + shortButton = new Button(formatGroup, DWT.RADIO); + shortButton.setText("DWT.SHORT"); + mediumButton = new Button(formatGroup, DWT.RADIO); + mediumButton.setText("DWT.MEDIUM"); + longButton = new Button(formatGroup, DWT.RADIO); + longButton.setText("DWT.LONG"); + borderButton = new Button(styleGroup, DWT.CHECK); + borderButton.setText("DWT.BORDER"); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [dateTime1]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Day", "Hours", "Minutes", "Month", "Seconds", "Year"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "DateTime"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + dateButton.setSelection ((dateTime1.getStyle () & DWT.DATE) !is 0); + timeButton.setSelection ((dateTime1.getStyle () & DWT.TIME) !is 0); + calendarButton.setSelection ((dateTime1.getStyle () & DWT.CALENDAR) !is 0); + shortButton.setSelection ((dateTime1.getStyle () & DWT.SHORT) !is 0); + mediumButton.setSelection ((dateTime1.getStyle () & DWT.MEDIUM) !is 0); + longButton.setSelection ((dateTime1.getStyle () & DWT.LONG) !is 0); + borderButton.setSelection ((dateTime1.getStyle () & DWT.BORDER) !is 0); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/DialogTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/DialogTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,512 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.DialogTab; + + + +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.SelectionListener; +import dwt.graphics.FontData; +import dwt.graphics.RGB; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.printing.PrintDialog; +import dwt.printing.PrinterData; +import dwt.widgets.Button; +import dwt.widgets.ColorDialog; +import dwt.widgets.Combo; +import dwt.widgets.DirectoryDialog; +import dwt.widgets.FileDialog; +import dwt.widgets.FontDialog; +import dwt.widgets.Group; +import dwt.widgets.MessageBox; +import dwt.widgets.Text; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import tango.text.convert.Format; + +class DialogTab : Tab { + /* Example widgets and groups that contain them */ + Group dialogStyleGroup, resultGroup; + Text textWidget; + + /* Style widgets added to the "Style" group */ + Combo dialogCombo; + Button createButton; + Button okButton, cancelButton; + Button yesButton, noButton; + Button retryButton; + Button abortButton, ignoreButton; + Button iconErrorButton, iconInformationButton, iconQuestionButton; + Button iconWarningButton, iconWorkingButton, noIconButton; + Button primaryModalButton, applicationModalButton, systemModalButton; + Button saveButton, openButton, multiButton; + + static const char[] [] FilterExtensions = ["*.txt", "*.bat", "*.doc", "*"]; + static char[] [] FilterNames; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + if( FilterNames.length is 0 ){ + FilterNames = [ ControlExample.getResourceString("FilterName_0"), + ControlExample.getResourceString("FilterName_1"), + ControlExample.getResourceString("FilterName_2"), + ControlExample.getResourceString("FilterName_3")]; + } + } + + /** + * Handle a button style selection event. + * + * @param event the selection event + */ + void buttonStyleSelected(SelectionEvent event) { + /* + * Only certain combinations of button styles are + * supported for various dialogs. Make sure the + * control widget reflects only valid combinations. + */ + bool ok = okButton.getSelection (); + bool cancel = cancelButton.getSelection (); + bool yes = yesButton.getSelection (); + bool no = noButton.getSelection (); + bool abort = abortButton.getSelection (); + bool retry = retryButton.getSelection (); + bool ignore = ignoreButton.getSelection (); + + okButton.setEnabled (!(yes || no || retry || abort || ignore)); + cancelButton.setEnabled (!(abort || ignore || (yes !is no))); + yesButton.setEnabled (!(ok || retry || abort || ignore || (cancel && !yes && !no))); + noButton.setEnabled (!(ok || retry || abort || ignore || (cancel && !yes && !no))); + retryButton.setEnabled (!(ok || yes || no)); + abortButton.setEnabled (!(ok || cancel || yes || no)); + ignoreButton.setEnabled (!(ok || cancel || yes || no)); + + createButton.setEnabled ( + !(ok || cancel || yes || no || retry || abort || ignore) || + ok || + (ok && cancel) || + (yes && no) || + (yes && no && cancel) || + (retry && cancel) || + (abort && retry && ignore)); + + + } + + /** + * Handle the create button selection event. + * + * @param event org.eclipse.swt.events.SelectionEvent + */ + void createButtonSelected(SelectionEvent event) { + + /* Compute the appropriate dialog style */ + int style = getDefaultStyle(); + if (okButton.getEnabled () && okButton.getSelection ()) style |= DWT.OK; + if (cancelButton.getEnabled () && cancelButton.getSelection ()) style |= DWT.CANCEL; + if (yesButton.getEnabled () && yesButton.getSelection ()) style |= DWT.YES; + if (noButton.getEnabled () && noButton.getSelection ()) style |= DWT.NO; + if (retryButton.getEnabled () && retryButton.getSelection ()) style |= DWT.RETRY; + if (abortButton.getEnabled () && abortButton.getSelection ()) style |= DWT.ABORT; + if (ignoreButton.getEnabled () && ignoreButton.getSelection ()) style |= DWT.IGNORE; + if (iconErrorButton.getEnabled () && iconErrorButton.getSelection ()) style |= DWT.ICON_ERROR; + if (iconInformationButton.getEnabled () && iconInformationButton.getSelection ()) style |= DWT.ICON_INFORMATION; + if (iconQuestionButton.getEnabled () && iconQuestionButton.getSelection ()) style |= DWT.ICON_QUESTION; + if (iconWarningButton.getEnabled () && iconWarningButton.getSelection ()) style |= DWT.ICON_WARNING; + if (iconWorkingButton.getEnabled () && iconWorkingButton.getSelection ()) style |= DWT.ICON_WORKING; + if (primaryModalButton.getEnabled () && primaryModalButton.getSelection ()) style |= DWT.PRIMARY_MODAL; + if (applicationModalButton.getEnabled () && applicationModalButton.getSelection ()) style |= DWT.APPLICATION_MODAL; + if (systemModalButton.getEnabled () && systemModalButton.getSelection ()) style |= DWT.SYSTEM_MODAL; + if (saveButton.getEnabled () && saveButton.getSelection ()) style |= DWT.SAVE; + if (openButton.getEnabled () && openButton.getSelection ()) style |= DWT.OPEN; + if (multiButton.getEnabled () && multiButton.getSelection ()) style |= DWT.MULTI; + + /* Open the appropriate dialog type */ + char[] name = dialogCombo.getText (); + + if (name == ControlExample.getResourceString("ColorDialog")) { + ColorDialog dialog = new ColorDialog (shell ,style); + dialog.setRGB (new RGB (100, 100, 100)); + dialog.setText (ControlExample.getResourceString("Title")); + RGB result = dialog.open (); + textWidget.append (Format( ControlExample.getResourceString("ColorDialog")~"{}", Text.DELIMITER)); + textWidget.append (Format( ControlExample.getResourceString("Result")~"{}{}", result, Text.DELIMITER, Text.DELIMITER)); + return; + } + + if (name == ControlExample.getResourceString("DirectoryDialog")) { + DirectoryDialog dialog = new DirectoryDialog (shell, style); + dialog.setMessage (ControlExample.getResourceString("Example_string")); + dialog.setText (ControlExample.getResourceString("Title")); + char[] result = dialog.open (); + textWidget.append (ControlExample.getResourceString("DirectoryDialog") ~ Text.DELIMITER); + textWidget.append (Format( ControlExample.getResourceString("Result"), result ) ~ Text.DELIMITER ~ Text.DELIMITER); + return; + } + + if (name== ControlExample.getResourceString("FileDialog")) { + FileDialog dialog = new FileDialog (shell, style); + dialog.setFileName (ControlExample.getResourceString("readme_txt")); + dialog.setFilterNames (FilterNames); + dialog.setFilterExtensions (FilterExtensions); + dialog.setText (ControlExample.getResourceString("Title")); + char[] result = dialog.open(); + textWidget.append (ControlExample.getResourceString("FileDialog") ~ Text.DELIMITER); + textWidget.append (Format( ControlExample.getResourceString("Result"), result ) ~ Text.DELIMITER); + if ((dialog.getStyle () & DWT.MULTI) !is 0) { + char[] [] files = dialog.getFileNames (); + for (int i=0; i + *******************************************************************************/ +module examples.controlexample.ExpandBarTab; + + + +import dwt.DWT; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Composite; +import dwt.widgets.ExpandBar; +import dwt.widgets.ExpandItem; +import dwt.widgets.Group; +import dwt.widgets.Label; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +class ExpandBarTab : Tab { + /* Example widgets and groups that contain them */ + ExpandBar expandBar1; + Group expandBarGroup; + + /* Style widgets added to the "Style" group */ + Button verticalButton; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the list */ + expandBarGroup = new Group (exampleGroup, DWT.NONE); + expandBarGroup.setLayout (new GridLayout ()); + expandBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + expandBarGroup.setText ("ExpandBar"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (borderButton.getSelection ()) style |= DWT.BORDER; + if (verticalButton.getSelection()) style |= DWT.V_SCROLL; + + /* Create the example widgets */ + expandBar1 = new ExpandBar (expandBarGroup, style); + + // First item + Composite composite = new Composite (expandBar1, DWT.NONE); + composite.setLayout(new GridLayout ()); + (new Button (composite, DWT.PUSH)).setText("DWT.PUSH"); + (new Button (composite, DWT.RADIO)).setText("DWT.RADIO"); + (new Button (composite, DWT.CHECK)).setText("DWT.CHECK"); + (new Button (composite, DWT.TOGGLE)).setText("DWT.TOGGLE"); + ExpandItem item = new ExpandItem (expandBar1, DWT.NONE, 0); + item.setText(ControlExample.getResourceString("Item1_Text")); + item.setHeight(composite.computeSize(DWT.DEFAULT, DWT.DEFAULT).y); + item.setControl(composite); + item.setImage(instance.images[ControlExample.ciClosedFolder]); + + // Second item + composite = new Composite (expandBar1, DWT.NONE); + composite.setLayout(new GridLayout (2, false)); + (new Label (composite, DWT.NONE)).setImage(display.getSystemImage(DWT.ICON_ERROR)); + (new Label (composite, DWT.NONE)).setText("DWT.ICON_ERROR"); + (new Label (composite, DWT.NONE)).setImage(display.getSystemImage(DWT.ICON_INFORMATION)); + (new Label (composite, DWT.NONE)).setText("DWT.ICON_INFORMATION"); + (new Label (composite, DWT.NONE)).setImage(display.getSystemImage(DWT.ICON_WARNING)); + (new Label (composite, DWT.NONE)).setText("DWT.ICON_WARNING"); + (new Label (composite, DWT.NONE)).setImage(display.getSystemImage(DWT.ICON_QUESTION)); + (new Label (composite, DWT.NONE)).setText("DWT.ICON_QUESTION"); + item = new ExpandItem (expandBar1, DWT.NONE, 1); + item.setText(ControlExample.getResourceString("Item2_Text")); + item.setHeight(composite.computeSize(DWT.DEFAULT, DWT.DEFAULT).y); + item.setControl(composite); + item.setImage(instance.images[ControlExample.ciOpenFolder]); + item.setExpanded(true); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup (); + + /* Create the extra widgets */ + verticalButton = new Button (styleGroup, DWT.CHECK); + verticalButton.setText ("DWT.V_SCROLL"); + verticalButton.setSelection(true); + borderButton = new Button(styleGroup, DWT.CHECK); + borderButton.setText("DWT.BORDER"); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) expandBar1]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Spacing"]; + } + + /** + * Gets the short text for the tab folder item. + */ + public char[] getShortTabText() { + return "EB"; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "ExpandBar"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + Widget [] widgets = getExampleWidgets (); + if (widgets.length !is 0){ + verticalButton.setSelection ((widgets [0].getStyle () & DWT.V_SCROLL) !is 0); + borderButton.setSelection ((widgets [0].getStyle () & DWT.BORDER) !is 0); + } + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/GroupTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/GroupTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,164 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.GroupTab; + + + +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +class GroupTab : Tab { + Button titleButton; + + /* Example widgets and groups that contain them */ + Group group1; + Group groupGroup; + + /* Style widgets added to the "Style" group */ + Button shadowEtchedInButton, shadowEtchedOutButton, shadowInButton, shadowOutButton, shadowNoneButton; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Other" group. + */ + void createOtherGroup () { + super.createOtherGroup (); + + /* Create display controls specific to this example */ + titleButton = new Button (otherGroup, DWT.CHECK); + titleButton.setText (ControlExample.getResourceString("Title_Text")); + + /* Add the listeners */ + titleButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setTitleText (); + } + }); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the Group */ + groupGroup = new Group (exampleGroup, DWT.NONE); + groupGroup.setLayout (new GridLayout ()); + groupGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + groupGroup.setText ("Group"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (shadowEtchedInButton.getSelection ()) style |= DWT.SHADOW_ETCHED_IN; + if (shadowEtchedOutButton.getSelection ()) style |= DWT.SHADOW_ETCHED_OUT; + if (shadowInButton.getSelection ()) style |= DWT.SHADOW_IN; + if (shadowOutButton.getSelection ()) style |= DWT.SHADOW_OUT; + if (shadowNoneButton.getSelection ()) style |= DWT.SHADOW_NONE; + if (borderButton.getSelection ()) style |= DWT.BORDER; + + /* Create the example widgets */ + group1 = new Group (groupGroup, style); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup (); + + /* Create the extra widgets */ + shadowEtchedInButton = new Button (styleGroup, DWT.RADIO); + shadowEtchedInButton.setText ("DWT.SHADOW_ETCHED_IN"); + shadowEtchedInButton.setSelection(true); + shadowEtchedOutButton = new Button (styleGroup, DWT.RADIO); + shadowEtchedOutButton.setText ("DWT.SHADOW_ETCHED_OUT"); + shadowInButton = new Button (styleGroup, DWT.RADIO); + shadowInButton.setText ("DWT.SHADOW_IN"); + shadowOutButton = new Button (styleGroup, DWT.RADIO); + shadowOutButton.setText ("DWT.SHADOW_OUT"); + shadowNoneButton = new Button (styleGroup, DWT.RADIO); + shadowNoneButton.setText ("DWT.SHADOW_NONE"); + borderButton = new Button (styleGroup, DWT.CHECK); + borderButton.setText ("DWT.BORDER"); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) group1]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["ToolTipText"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Group"; + } + + /** + * Sets the title text of the "Example" widgets. + */ + void setTitleText () { + if (titleButton.getSelection ()) { + group1.setText (ControlExample.getResourceString("Title_Text")); + } else { + group1.setText (""); + } + setExampleWidgetSize (); + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + shadowEtchedInButton.setSelection ((group1.getStyle () & DWT.SHADOW_ETCHED_IN) !is 0); + shadowEtchedOutButton.setSelection ((group1.getStyle () & DWT.SHADOW_ETCHED_OUT) !is 0); + shadowInButton.setSelection ((group1.getStyle () & DWT.SHADOW_IN) !is 0); + shadowOutButton.setSelection ((group1.getStyle () & DWT.SHADOW_OUT) !is 0); + shadowNoneButton.setSelection ((group1.getStyle () & DWT.SHADOW_NONE) !is 0); + borderButton.setSelection ((group1.getStyle () & DWT.BORDER) !is 0); + if (!instance.startup) setTitleText (); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/LabelTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/LabelTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.LabelTab; + + + +import dwt.DWT; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.Label; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import examples.controlexample.AlignableTab; + +class LabelTab : AlignableTab { + /* Example widgets and groups that contain them */ + Label label1, label2, label3, label4, label5, label6; + Group textLabelGroup, imageLabelGroup; + + /* Style widgets added to the "Style" group */ + Button wrapButton, separatorButton, horizontalButton, verticalButton, shadowInButton, shadowOutButton, shadowNoneButton; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the text labels */ + textLabelGroup = new Group(exampleGroup, DWT.NONE); + GridLayout gridLayout = new GridLayout (); + textLabelGroup.setLayout (gridLayout); + gridLayout.numColumns = 3; + textLabelGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + textLabelGroup.setText (ControlExample.getResourceString("Text_Labels")); + + /* Create a group for the image labels */ + imageLabelGroup = new Group (exampleGroup, DWT.SHADOW_NONE); + gridLayout = new GridLayout (); + imageLabelGroup.setLayout (gridLayout); + gridLayout.numColumns = 3; + imageLabelGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + imageLabelGroup.setText (ControlExample.getResourceString("Image_Labels")); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (wrapButton.getSelection ()) style |= DWT.WRAP; + if (separatorButton.getSelection ()) style |= DWT.SEPARATOR; + if (horizontalButton.getSelection ()) style |= DWT.HORIZONTAL; + if (verticalButton.getSelection ()) style |= DWT.VERTICAL; + if (shadowInButton.getSelection ()) style |= DWT.SHADOW_IN; + if (shadowOutButton.getSelection ()) style |= DWT.SHADOW_OUT; + if (shadowNoneButton.getSelection ()) style |= DWT.SHADOW_NONE; + if (borderButton.getSelection ()) style |= DWT.BORDER; + if (leftButton.getSelection ()) style |= DWT.LEFT; + if (centerButton.getSelection ()) style |= DWT.CENTER; + if (rightButton.getSelection ()) style |= DWT.RIGHT; + + /* Create the example widgets */ + label1 = new Label (textLabelGroup, style); + label1.setText(ControlExample.getResourceString("One")); + label2 = new Label (textLabelGroup, style); + label2.setText(ControlExample.getResourceString("Two")); + label3 = new Label (textLabelGroup, style); + if (wrapButton.getSelection ()) { + label3.setText (ControlExample.getResourceString("Wrap_Text")); + } else { + label3.setText (ControlExample.getResourceString("Three")); + } + label4 = new Label (imageLabelGroup, style); + label4.setImage (instance.images[ControlExample.ciClosedFolder]); + label5 = new Label (imageLabelGroup, style); + label5.setImage (instance.images[ControlExample.ciOpenFolder]); + label6 = new Label(imageLabelGroup, style); + label6.setImage (instance.images[ControlExample.ciTarget]); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup (); + + /* Create the extra widgets */ + wrapButton = new Button (styleGroup, DWT.CHECK); + wrapButton.setText ("DWT.WRAP"); + separatorButton = new Button (styleGroup, DWT.CHECK); + separatorButton.setText ("DWT.SEPARATOR"); + horizontalButton = new Button (styleGroup, DWT.RADIO); + horizontalButton.setText ("DWT.HORIZONTAL"); + verticalButton = new Button (styleGroup, DWT.RADIO); + verticalButton.setText ("DWT.VERTICAL"); + Group styleSubGroup = new Group (styleGroup, DWT.NONE); + styleSubGroup.setLayout (new GridLayout ()); + shadowInButton = new Button (styleSubGroup, DWT.RADIO); + shadowInButton.setText ("DWT.SHADOW_IN"); + shadowOutButton = new Button (styleSubGroup, DWT.RADIO); + shadowOutButton.setText ("DWT.SHADOW_OUT"); + shadowNoneButton = new Button (styleSubGroup, DWT.RADIO); + shadowNoneButton.setText ("DWT.SHADOW_NONE"); + borderButton = new Button(styleGroup, DWT.CHECK); + borderButton.setText("DWT.BORDER"); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) label1, label2, label3, label4, label5, label6 ]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Text", "ToolTipText"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Label"; + } + + /** + * Sets the alignment of the "Example" widgets. + */ + void setExampleWidgetAlignment () { + int alignment = 0; + if (leftButton.getSelection ()) alignment = DWT.LEFT; + if (centerButton.getSelection ()) alignment = DWT.CENTER; + if (rightButton.getSelection ()) alignment = DWT.RIGHT; + label1.setAlignment (alignment); + label2.setAlignment (alignment); + label3.setAlignment (alignment); + label4.setAlignment (alignment); + label5.setAlignment (alignment); + label6.setAlignment (alignment); + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + bool isSeparator = (label1.getStyle () & DWT.SEPARATOR) !is 0; + wrapButton.setSelection (!isSeparator && (label1.getStyle () & DWT.WRAP) !is 0); + leftButton.setSelection (!isSeparator && (label1.getStyle () & DWT.LEFT) !is 0); + centerButton.setSelection (!isSeparator && (label1.getStyle () & DWT.CENTER) !is 0); + rightButton.setSelection (!isSeparator && (label1.getStyle () & DWT.RIGHT) !is 0); + shadowInButton.setSelection (isSeparator && (label1.getStyle () & DWT.SHADOW_IN) !is 0); + shadowOutButton.setSelection (isSeparator && (label1.getStyle () & DWT.SHADOW_OUT) !is 0); + shadowNoneButton.setSelection (isSeparator && (label1.getStyle () & DWT.SHADOW_NONE) !is 0); + horizontalButton.setSelection (isSeparator && (label1.getStyle () & DWT.HORIZONTAL) !is 0); + verticalButton.setSelection (isSeparator && (label1.getStyle () & DWT.VERTICAL) !is 0); + wrapButton.setEnabled (!isSeparator); + leftButton.setEnabled (!isSeparator); + centerButton.setEnabled (!isSeparator); + rightButton.setEnabled (!isSeparator); + shadowInButton.setEnabled (isSeparator); + shadowOutButton.setEnabled (isSeparator); + shadowNoneButton.setEnabled (isSeparator); + horizontalButton.setEnabled (isSeparator); + verticalButton.setEnabled (isSeparator); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/LinkTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/LinkTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.LinkTab; + + + +import dwt.DWT; +import dwt.DWTError; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.Label; +import dwt.widgets.Link; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +class LinkTab : Tab { + /* Example widgets and groups that contain them */ + Link link1; + Group linkGroup; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Example" group. + */ + override void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the list */ + linkGroup = new Group (exampleGroup, DWT.NONE); + linkGroup.setLayout (new GridLayout ()); + linkGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + linkGroup.setText ("Link"); + } + + /** + * Creates the "Example" widgets. + */ + override void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (borderButton.getSelection ()) style |= DWT.BORDER; + + /* Create the example widgets */ + try { + link1 = new Link (linkGroup, style); + link1.setText (ControlExample.getResourceString("LinkText")); + } catch (DWTError e) { + // temporary code for photon + Label label = new Label (linkGroup, DWT.CENTER | DWT.WRAP); + label.setText ("Link widget not suported"); + } + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup (); + + /* Create the extra widgets */ + borderButton = new Button(styleGroup, DWT.CHECK); + borderButton.setText("DWT.BORDER"); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { +// temporary code for photon + if (link1 !is null) return [ cast(Widget) link1 ]; + return null; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Text", "ToolTipText"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Link"; + } + +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/ListTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/ListTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.ListTab; + + + +import dwt.DWT; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Group; +import dwt.widgets.List; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import examples.controlexample.ScrollableTab; + +class ListTab : ScrollableTab { + + /* Example widgets and groups that contain them */ + List list1; + Group listGroup; + + static char[] [] ListData1; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + if( ListData1.length is 0 ){ + ListData1 = [ + ControlExample.getResourceString("ListData1_0"), + ControlExample.getResourceString("ListData1_1"), + ControlExample.getResourceString("ListData1_2"), + ControlExample.getResourceString("ListData1_3"), + ControlExample.getResourceString("ListData1_4"), + ControlExample.getResourceString("ListData1_5"), + ControlExample.getResourceString("ListData1_6"), + ControlExample.getResourceString("ListData1_7"), + ControlExample.getResourceString("ListData1_8")]; + } + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the list */ + listGroup = new Group (exampleGroup, DWT.NONE); + listGroup.setLayout (new GridLayout ()); + listGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + listGroup.setText ("List"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (singleButton.getSelection ()) style |= DWT.SINGLE; + if (multiButton.getSelection ()) style |= DWT.MULTI; + if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; + if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; + if (borderButton.getSelection ()) style |= DWT.BORDER; + + /* Create the example widgets */ + list1 = new List (listGroup, style); + list1.setItems (ListData1); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [cast(Widget) list1]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Items", "Selection", "ToolTipText", "TopIndex" ]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "List"; + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/MenuTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/MenuTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,329 @@ +/******************************************************************************* + * 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 + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ +module examples.controlexample.MenuTab; + + + +import dwt.DWT; +import dwt.events.PaintEvent; +import dwt.events.PaintListener; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.Label; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.Shell; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +import dwt.dwthelper.utils; + +import tango.util.Convert; + +class MenuTab : Tab { + /* Widgets added to the "Menu Style", "MenuItem Style" and "Other" groups */ + Button barButton, dropDownButton, popUpButton, noRadioGroupButton, leftToRightButton, rightToLeftButton; + Button checkButton, cascadeButton, pushButton, radioButton, separatorButton; + Button imagesButton, acceleratorsButton, mnemonicsButton, subMenuButton, subSubMenuButton; + Button createButton, closeAllButton; + Group menuItemStyleGroup; + + /* Variables used to track the open shells */ + int shellCount = 0; + Shell [] shells; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + shells = new Shell [4]; + } + + /** + * Close all the example shells. + */ + void closeAllShells() { + for (int i = 0; i= shells.length) { + Shell [] newShells = new Shell [shells.length + 4]; + System.arraycopy (shells, 0, newShells, 0, shells.length); + shells = newShells; + } + + int orientation = 0; + if (leftToRightButton.getSelection()) orientation |= DWT.LEFT_TO_RIGHT; + if (rightToLeftButton.getSelection()) orientation |= DWT.RIGHT_TO_LEFT; + int radioBehavior = 0; + if (noRadioGroupButton.getSelection()) radioBehavior |= DWT.NO_RADIO_GROUP; + + /* Create the shell and menu(s) */ + Shell shell = new Shell (DWT.SHELL_TRIM | orientation); + shells [shellCount] = shell; + if (barButton.getSelection ()) { + /* Create menu bar. */ + Menu menuBar = new Menu(shell, DWT.BAR | radioBehavior); + shell.setMenuBar(menuBar); + hookListeners(menuBar); + + if (dropDownButton.getSelection() && cascadeButton.getSelection()) { + /* Create cascade button and drop-down menu in menu bar. */ + MenuItem item = new MenuItem(menuBar, DWT.CASCADE); + item.setText(getMenuItemText("Cascade")); + if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciOpenFolder]); + hookListeners(item); + Menu dropDownMenu = new Menu(shell, DWT.DROP_DOWN | radioBehavior); + item.setMenu(dropDownMenu); + hookListeners(dropDownMenu); + + /* Create various menu items, depending on selections. */ + createMenuItems(dropDownMenu, subMenuButton.getSelection(), subSubMenuButton.getSelection()); + } + } + + if (popUpButton.getSelection()) { + /* Create pop-up menu. */ + Menu popUpMenu = new Menu(shell, DWT.POP_UP | radioBehavior); + shell.setMenu(popUpMenu); + hookListeners(popUpMenu); + + /* Create various menu items, depending on selections. */ + createMenuItems(popUpMenu, subMenuButton.getSelection(), subSubMenuButton.getSelection()); + } + + /* Set the size, title and open the shell. */ + shell.setSize (300, 100); + shell.setText (ControlExample.getResourceString("Title") ~ to!(char[])(shellCount)); + shell.addPaintListener(new class() PaintListener { + public void paintControl(PaintEvent e) { + e.gc.drawString(ControlExample.getResourceString("PopupMenuHere"), 20, 20); + } + }); + shell.open (); + shellCount++; + } + + /** + * Creates the "Control" group. + */ + void createControlGroup () { + /* + * Create the "Control" group. This is the group on the + * right half of each example tab. For MenuTab, it consists of + * the Menu style group, the MenuItem style group and the 'other' group. + */ + controlGroup = new Group (tabFolderPage, DWT.NONE); + controlGroup.setLayout (new GridLayout (2, true)); + controlGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); + controlGroup.setText (ControlExample.getResourceString("Parameters")); + + /* Create a group for the menu style controls */ + styleGroup = new Group (controlGroup, DWT.NONE); + styleGroup.setLayout (new GridLayout ()); + styleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); + styleGroup.setText (ControlExample.getResourceString("Menu_Styles")); + + /* Create a group for the menu item style controls */ + menuItemStyleGroup = new Group (controlGroup, DWT.NONE); + menuItemStyleGroup.setLayout (new GridLayout ()); + menuItemStyleGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); + menuItemStyleGroup.setText (ControlExample.getResourceString("MenuItem_Styles")); + + /* Create a group for the 'other' controls */ + otherGroup = new Group (controlGroup, DWT.NONE); + otherGroup.setLayout (new GridLayout ()); + otherGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); + otherGroup.setText (ControlExample.getResourceString("Other")); + } + + /** + * Creates the "Control" widget children. + */ + void createControlWidgets () { + + /* Create the menu style buttons */ + barButton = new Button (styleGroup, DWT.CHECK); + barButton.setText ("DWT.BAR"); + dropDownButton = new Button (styleGroup, DWT.CHECK); + dropDownButton.setText ("DWT.DROP_DOWN"); + popUpButton = new Button (styleGroup, DWT.CHECK); + popUpButton.setText ("DWT.POP_UP"); + noRadioGroupButton = new Button (styleGroup, DWT.CHECK); + noRadioGroupButton.setText ("DWT.NO_RADIO_GROUP"); + leftToRightButton = new Button (styleGroup, DWT.RADIO); + leftToRightButton.setText ("DWT.LEFT_TO_RIGHT"); + leftToRightButton.setSelection(true); + rightToLeftButton = new Button (styleGroup, DWT.RADIO); + rightToLeftButton.setText ("DWT.RIGHT_TO_LEFT"); + + /* Create the menu item style buttons */ + cascadeButton = new Button (menuItemStyleGroup, DWT.CHECK); + cascadeButton.setText ("DWT.CASCADE"); + checkButton = new Button (menuItemStyleGroup, DWT.CHECK); + checkButton.setText ("DWT.CHECK"); + pushButton = new Button (menuItemStyleGroup, DWT.CHECK); + pushButton.setText ("DWT.PUSH"); + radioButton = new Button (menuItemStyleGroup, DWT.CHECK); + radioButton.setText ("DWT.RADIO"); + separatorButton = new Button (menuItemStyleGroup, DWT.CHECK); + separatorButton.setText ("DWT.SEPARATOR"); + + /* Create the 'other' buttons */ + imagesButton = new Button (otherGroup, DWT.CHECK); + imagesButton.setText (ControlExample.getResourceString("Images")); + acceleratorsButton = new Button (otherGroup, DWT.CHECK); + acceleratorsButton.setText (ControlExample.getResourceString("Accelerators")); + mnemonicsButton = new Button (otherGroup, DWT.CHECK); + mnemonicsButton.setText (ControlExample.getResourceString("Mnemonics")); + subMenuButton = new Button (otherGroup, DWT.CHECK); + subMenuButton.setText (ControlExample.getResourceString("SubMenu")); + subSubMenuButton = new Button (otherGroup, DWT.CHECK); + subSubMenuButton.setText (ControlExample.getResourceString("SubSubMenu")); + + /* Create the "create" and "closeAll" buttons (and a 'filler' label to place them) */ + new Label(controlGroup, DWT.NONE); + createButton = new Button (controlGroup, DWT.NONE); + createButton.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_END)); + createButton.setText (ControlExample.getResourceString("Create_Shell")); + closeAllButton = new Button (controlGroup, DWT.NONE); + closeAllButton.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING)); + closeAllButton.setText (ControlExample.getResourceString("Close_All_Shells")); + + /* Add the listeners */ + createButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + createButtonSelected(e); + } + }); + closeAllButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + closeAllShells (); + } + }); + subMenuButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + subSubMenuButton.setEnabled (subMenuButton.getSelection ()); + } + }); + + /* Set the default state */ + barButton.setSelection (true); + dropDownButton.setSelection (true); + popUpButton.setSelection (true); + cascadeButton.setSelection (true); + checkButton.setSelection (true); + pushButton.setSelection (true); + radioButton.setSelection (true); + separatorButton.setSelection (true); + subSubMenuButton.setEnabled (subMenuButton.getSelection ()); + } + + /* Create various menu items, depending on selections. */ + void createMenuItems(Menu menu, bool createSubMenu, bool createSubSubMenu) { + MenuItem item; + if (pushButton.getSelection()) { + item = new MenuItem(menu, DWT.PUSH); + item.setText(getMenuItemText("Push")); + if (acceleratorsButton.getSelection()) item.setAccelerator(DWT.MOD1 + DWT.MOD2 + 'P'); + if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciClosedFolder]); + hookListeners(item); + } + + if (separatorButton.getSelection()) { + new MenuItem(menu, DWT.SEPARATOR); + } + + if (checkButton.getSelection()) { + item = new MenuItem(menu, DWT.CHECK); + item.setText(getMenuItemText("Check")); + if (acceleratorsButton.getSelection()) item.setAccelerator(DWT.MOD1 + DWT.MOD2 + 'C'); + if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciOpenFolder]); + hookListeners(item); + } + + if (radioButton.getSelection()) { + item = new MenuItem(menu, DWT.RADIO); + item.setText(getMenuItemText("1Radio")); + if (acceleratorsButton.getSelection()) item.setAccelerator(DWT.MOD1 + DWT.MOD2 + '1'); + if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciTarget]); + item.setSelection(true); + hookListeners(item); + + item = new MenuItem(menu, DWT.RADIO); + item.setText(getMenuItemText("2Radio")); + if (acceleratorsButton.getSelection()) item.setAccelerator(DWT.MOD1 + DWT.MOD2 + '2'); + if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciTarget]); + hookListeners(item); + } + + if (createSubMenu && cascadeButton.getSelection()) { + /* Create cascade button and drop-down menu for the sub-menu. */ + item = new MenuItem(menu, DWT.CASCADE); + item.setText(getMenuItemText("Cascade")); + if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciOpenFolder]); + hookListeners(item); + Menu subMenu = new Menu(menu.getShell(), DWT.DROP_DOWN); + item.setMenu(subMenu); + hookListeners(subMenu); + + createMenuItems(subMenu, createSubSubMenu, false); + } + } + + char[] getMenuItemText(char[] item) { + bool cascade = ( item == "Cascade"); + bool mnemonic = mnemonicsButton.getSelection(); + bool accelerator = acceleratorsButton.getSelection(); + char acceleratorKey = item[0]; + if (mnemonic && accelerator && !cascade) { + return ControlExample.getResourceString(item ~ "WithMnemonic") ~ "\tCtrl+Shift+" ~ acceleratorKey; + } + if (accelerator && !cascade) { + return ControlExample.getResourceString(item) ~ "\tCtrl+Shift+" ~ acceleratorKey; + } + if (mnemonic) { + return ControlExample.getResourceString(item ~ "WithMnemonic"); + } + return ControlExample.getResourceString(item); + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Menu"; + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/ProgressBarTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/ProgressBarTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,189 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.ProgressBarTab; + + + +import dwt.DWT; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.ProgressBar; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import examples.controlexample.RangeTab; + +class ProgressBarTab : RangeTab { + /* Example widgets and groups that contain them */ + ProgressBar progressBar1; + Group progressBarGroup; + + /* Style widgets added to the "Style" group */ + Button smoothButton; + Button indeterminateButton; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup() { + super.createExampleGroup (); + + /* Create a group for the progress bar */ + progressBarGroup = new Group (exampleGroup, DWT.NONE); + progressBarGroup.setLayout (new GridLayout ()); + progressBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + progressBarGroup.setText ("ProgressBar"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (horizontalButton.getSelection ()) style |= DWT.HORIZONTAL; + if (verticalButton.getSelection ()) style |= DWT.VERTICAL; + if (smoothButton.getSelection ()) style |= DWT.SMOOTH; + if (borderButton.getSelection ()) style |= DWT.BORDER; + if (indeterminateButton.getSelection ()) style |= DWT.INDETERMINATE; + + /* Create the example widgets */ + progressBar1 = new ProgressBar (progressBarGroup, style); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup () { + super.createStyleGroup (); + + /* Create the extra widgets */ + smoothButton = new Button (styleGroup, DWT.CHECK); + smoothButton.setText ("DWT.SMOOTH"); + indeterminateButton = new Button (styleGroup, DWT.CHECK); + indeterminateButton.setText ("DWT.INDETERMINATE"); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) progressBar1]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Selection", "ToolTipText"]; + } + + /** + * Gets the short text for the tab folder item. + */ + public char[] getShortTabText() { + return "PB"; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "ProgressBar"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + if (indeterminateButton.getSelection ()) { + selectionSpinner.setEnabled (false); + minimumSpinner.setEnabled (false); + maximumSpinner.setEnabled (false); + } else { + selectionSpinner.setEnabled (true); + minimumSpinner.setEnabled (true); + maximumSpinner.setEnabled (true); + } + smoothButton.setSelection ((progressBar1.getStyle () & DWT.SMOOTH) !is 0); + indeterminateButton.setSelection ((progressBar1.getStyle () & DWT.INDETERMINATE) !is 0); + } + + /** + * Gets the default maximum of the "Example" widgets. + */ + int getDefaultMaximum () { + return progressBar1.getMaximum(); + } + + /** + * Gets the default minimim of the "Example" widgets. + */ + int getDefaultMinimum () { + return progressBar1.getMinimum(); + } + + /** + * Gets the default selection of the "Example" widgets. + */ + int getDefaultSelection () { + return progressBar1.getSelection(); + } + + /** + * Sets the maximum of the "Example" widgets. + */ + void setWidgetMaximum () { + progressBar1.setMaximum (maximumSpinner.getSelection ()); + updateSpinners (); + } + + /** + * Sets the minimim of the "Example" widgets. + */ + void setWidgetMinimum () { + progressBar1.setMinimum (minimumSpinner.getSelection ()); + updateSpinners (); + } + + /** + * Sets the selection of the "Example" widgets. + */ + void setWidgetSelection () { + progressBar1.setSelection (selectionSpinner.getSelection ()); + updateSpinners (); + } + + /** + * Update the Spinner widgets to reflect the actual value set + * on the "Example" widget. + */ + void updateSpinners () { + minimumSpinner.setSelection (progressBar1.getMinimum ()); + selectionSpinner.setSelection (progressBar1.getSelection ()); + maximumSpinner.setSelection (progressBar1.getMaximum ()); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/RangeTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/RangeTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,208 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.RangeTab; + + + +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.Spinner; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +abstract class RangeTab : Tab { + /* Style widgets added to the "Style" group */ + Button horizontalButton, verticalButton; + bool orientationButtons = true; + + /* Scale widgets added to the "Control" group */ + Spinner minimumSpinner, selectionSpinner, maximumSpinner; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Control" widget children. + */ + void createControlWidgets () { + /* Create controls specific to this example */ + createMinimumGroup (); + createMaximumGroup (); + createSelectionGroup (); + } + + /** + * Create a group of widgets to control the maximum + * attribute of the example widget. + */ + void createMaximumGroup() { + + /* Create the group */ + Group maximumGroup = new Group (controlGroup, DWT.NONE); + maximumGroup.setLayout (new GridLayout ()); + maximumGroup.setText (ControlExample.getResourceString("Maximum")); + maximumGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); + + /* Create a Spinner widget */ + maximumSpinner = new Spinner (maximumGroup, DWT.BORDER); + maximumSpinner.setMaximum (100000); + maximumSpinner.setSelection (getDefaultMaximum()); + maximumSpinner.setPageIncrement (100); + maximumSpinner.setIncrement (1); + maximumSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); + + /* Add the listeners */ + maximumSpinner.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetMaximum (); + } + }); + } + + /** + * Create a group of widgets to control the minimum + * attribute of the example widget. + */ + void createMinimumGroup() { + + /* Create the group */ + Group minimumGroup = new Group (controlGroup, DWT.NONE); + minimumGroup.setLayout (new GridLayout ()); + minimumGroup.setText (ControlExample.getResourceString("Minimum")); + minimumGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); + + /* Create a Spinner widget */ + minimumSpinner = new Spinner (minimumGroup, DWT.BORDER); + minimumSpinner.setMaximum (100000); + minimumSpinner.setSelection(getDefaultMinimum()); + minimumSpinner.setPageIncrement (100); + minimumSpinner.setIncrement (1); + minimumSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); + + /* Add the listeners */ + minimumSpinner.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetMinimum (); + } + }); + + } + + /** + * Create a group of widgets to control the selection + * attribute of the example widget. + */ + void createSelectionGroup() { + + /* Create the group */ + Group selectionGroup = new Group(controlGroup, DWT.NONE); + selectionGroup.setLayout(new GridLayout()); + GridData gridData = new GridData(DWT.FILL, DWT.BEGINNING, false, false); + selectionGroup.setLayoutData(gridData); + selectionGroup.setText(ControlExample.getResourceString("Selection")); + + /* Create a Spinner widget */ + selectionSpinner = new Spinner (selectionGroup, DWT.BORDER); + selectionSpinner.setMaximum (100000); + selectionSpinner.setSelection (getDefaultSelection()); + selectionSpinner.setPageIncrement (100); + selectionSpinner.setIncrement (1); + selectionSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); + + /* Add the listeners */ + selectionSpinner.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + setWidgetSelection (); + } + }); + + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup () { + super.createStyleGroup (); + + /* Create the extra widgets */ + if (orientationButtons) { + horizontalButton = new Button (styleGroup, DWT.RADIO); + horizontalButton.setText ("DWT.HORIZONTAL"); + verticalButton = new Button (styleGroup, DWT.RADIO); + verticalButton.setText ("DWT.VERTICAL"); + } + borderButton = new Button (styleGroup, DWT.CHECK); + borderButton.setText ("DWT.BORDER"); + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + if (!instance.startup) { + setWidgetMinimum (); + setWidgetMaximum (); + setWidgetSelection (); + } + Widget [] widgets = getExampleWidgets (); + if (widgets.length !is 0) { + if (orientationButtons) { + horizontalButton.setSelection ((widgets [0].getStyle () & DWT.HORIZONTAL) !is 0); + verticalButton.setSelection ((widgets [0].getStyle () & DWT.VERTICAL) !is 0); + } + borderButton.setSelection ((widgets [0].getStyle () & DWT.BORDER) !is 0); + } + } + + /** + * Gets the default maximum of the "Example" widgets. + */ + abstract int getDefaultMaximum (); + + /** + * Gets the default minimim of the "Example" widgets. + */ + abstract int getDefaultMinimum (); + + /** + * Gets the default selection of the "Example" widgets. + */ + abstract int getDefaultSelection (); + + /** + * Sets the maximum of the "Example" widgets. + */ + abstract void setWidgetMaximum (); + + /** + * Sets the minimim of the "Example" widgets. + */ + abstract void setWidgetMinimum (); + + /** + * Sets the selection of the "Example" widgets. + */ + abstract void setWidgetSelection (); +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/SashFormTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/SashFormTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.SashFormTab; + + + +import dwt.DWT; +import dwt.custom.SashForm; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.List; +import dwt.widgets.Text; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + + +class SashFormTab : Tab { + /* Example widgets and groups that contain them */ + Group sashFormGroup; + SashForm form; + List list1, list2; + Text text; + + /* Style widgets added to the "Style" group */ + Button horizontalButton, verticalButton, smoothButton; + + static char[] [] ListData0; + static char[] [] ListData1; + + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + if( ListData0 is null ){ + ListData0 = [ + ControlExample.getResourceString("ListData0_0"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData0_1"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData0_2"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData0_3"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData0_4"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData0_5"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData0_6"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData0_7")]; //$NON-NLS-1$ + + } + if( ListData1 is null ){ + ListData1 = [ + ControlExample.getResourceString("ListData1_0"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData1_1"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData1_2"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData1_3"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData1_4"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData1_5"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData1_6"), //$NON-NLS-1$ + ControlExample.getResourceString("ListData1_7")]; //$NON-NLS-1$ + } + } + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the sashform widget */ + sashFormGroup = new Group (exampleGroup, DWT.NONE); + sashFormGroup.setLayout (new GridLayout ()); + sashFormGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + sashFormGroup.setText ("SashForm"); + } + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; + if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; + if (smoothButton.getSelection ()) style |= DWT.SMOOTH; + + /* Create the example widgets */ + form = new SashForm (sashFormGroup, style); + list1 = new List (form, DWT.V_SCROLL | DWT.H_SCROLL | DWT.BORDER); + list1.setItems (ListData0); + list2 = new List (form, DWT.V_SCROLL | DWT.H_SCROLL | DWT.BORDER); + list2.setItems (ListData1); + text = new Text (form, DWT.MULTI | DWT.BORDER); + text.setText (ControlExample.getResourceString("Multi_line")); //$NON-NLS-1$ + form.setWeights([1, 1, 1]); + } + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup(); + + /* Create the extra widgets */ + horizontalButton = new Button (styleGroup, DWT.RADIO); + horizontalButton.setText ("DWT.HORIZONTAL"); + horizontalButton.setSelection(true); + verticalButton = new Button (styleGroup, DWT.RADIO); + verticalButton.setText ("DWT.VERTICAL"); + verticalButton.setSelection(false); + smoothButton = new Button (styleGroup, DWT.CHECK); + smoothButton.setText ("DWT.SMOOTH"); + smoothButton.setSelection(false); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) form]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "SashForm"; //$NON-NLS-1$ + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + horizontalButton.setSelection ((form.getStyle () & DWT.H_SCROLL) !is 0); + verticalButton.setSelection ((form.getStyle () & DWT.V_SCROLL) !is 0); + smoothButton.setSelection ((form.getStyle () & DWT.SMOOTH) !is 0); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/SashTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/SashTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,264 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.SashTab; + + + +import dwt.DWT; +import dwt.events.ControlAdapter; +import dwt.events.ControlEvent; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.graphics.Rectangle; +import dwt.layout.FillLayout; +import dwt.layout.GridData; +import dwt.widgets.Button; +import dwt.widgets.Composite; +import dwt.widgets.Group; +import dwt.widgets.List; +import dwt.widgets.Sash; +import dwt.widgets.Text; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +class SashTab : Tab { + /* Example widgets and groups that contain them */ + Sash hSash, vSash; + Composite sashComp; + Group sashGroup; + List list1, list2, list3; + Text text; + Button smoothButton; + + static char[] [] ListData0; + static char[] [] ListData1; + + /* Constants */ + static final int SASH_WIDTH = 3; + static final int SASH_LIMIT = 20; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + if( ListData0.length is 0 ){ + ListData0 = [ + ControlExample.getResourceString("ListData0_0"), + ControlExample.getResourceString("ListData0_1"), + ControlExample.getResourceString("ListData0_2"), + ControlExample.getResourceString("ListData0_3"), + ControlExample.getResourceString("ListData0_4"), + ControlExample.getResourceString("ListData0_5"), + ControlExample.getResourceString("ListData0_6"), + ControlExample.getResourceString("ListData0_7"), + ControlExample.getResourceString("ListData0_8")]; + } + if( ListData1.length is 0 ){ + ListData1 = [ + ControlExample.getResourceString("ListData1_0"), + ControlExample.getResourceString("ListData1_1"), + ControlExample.getResourceString("ListData1_2"), + ControlExample.getResourceString("ListData1_3"), + ControlExample.getResourceString("ListData1_4"), + ControlExample.getResourceString("ListData1_5"), + ControlExample.getResourceString("ListData1_6"), + ControlExample.getResourceString("ListData1_7"), + ControlExample.getResourceString("ListData1_8")]; + } + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + exampleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + exampleGroup.setLayout(new FillLayout()); + + /* Create a group for the sash widgets */ + sashGroup = new Group (exampleGroup, DWT.NONE); + FillLayout layout = new FillLayout(); + layout.marginHeight = layout.marginWidth = 5; + sashGroup.setLayout(layout); + sashGroup.setText ("Sash"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + /* + * Create the page. This example does not use layouts. + */ + sashComp = new Composite(sashGroup, DWT.BORDER); + + /* Create the list and text widgets */ + list1 = new List (sashComp, DWT.V_SCROLL | DWT.H_SCROLL | DWT.BORDER); + list1.setItems (ListData0); + list2 = new List (sashComp, DWT.V_SCROLL | DWT.H_SCROLL | DWT.BORDER); + list2.setItems (ListData1); + text = new Text (sashComp, DWT.MULTI | DWT.BORDER); + text.setText (ControlExample.getResourceString("Multi_line")); + + /* Create the sashes */ + int style = getDefaultStyle(); + if (smoothButton.getSelection()) style |= DWT.SMOOTH; + vSash = new Sash (sashComp, DWT.VERTICAL | style); + hSash = new Sash (sashComp, DWT.HORIZONTAL | style); + + /* Add the listeners */ + hSash.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + Rectangle rect = vSash.getParent().getClientArea(); + event.y = Math.min (Math.max (event.y, SASH_LIMIT), rect.height - SASH_LIMIT); + if (event.detail !is DWT.DRAG) { + hSash.setBounds (event.x, event.y, event.width, event.height); + layout (); + } + } + }); + vSash.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + Rectangle rect = vSash.getParent().getClientArea(); + event.x = Math.min (Math.max (event.x, SASH_LIMIT), rect.width - SASH_LIMIT); + if (event.detail !is DWT.DRAG) { + vSash.setBounds (event.x, event.y, event.width, event.height); + layout (); + } + } + }); + sashComp.addControlListener (new class() ControlAdapter { + public void controlResized (ControlEvent event) { + resized (); + } + }); + } + + /** + * Creates the "Size" group. The "Size" group contains + * controls that allow the user to change the size of + * the example widgets. + */ + void createSizeGroup () { + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup (); + + /* Create the extra widgets */ + smoothButton = new Button (styleGroup, DWT.CHECK); + smoothButton.setText("DWT.SMOOTH"); + } + + void disposeExampleWidgets () { + sashComp.dispose(); + sashComp = null; + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) hSash, vSash ]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["ToolTipText"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Sash"; + } + + /** + * Layout the list and text widgets according to the new + * positions of the sashes..events.SelectionEvent + */ + void layout () { + + Rectangle clientArea = sashComp.getClientArea (); + Rectangle hSashBounds = hSash.getBounds (); + Rectangle vSashBounds = vSash.getBounds (); + + list1.setBounds (0, 0, vSashBounds.x, hSashBounds.y); + list2.setBounds (vSashBounds.x + vSashBounds.width, 0, clientArea.width - (vSashBounds.x + vSashBounds.width), hSashBounds.y); + text.setBounds (0, hSashBounds.y + hSashBounds.height, clientArea.width, clientArea.height - (hSashBounds.y + hSashBounds.height)); + + /** + * If the horizontal sash has been moved then the vertical + * sash is either too long or too short and its size must + * be adjusted. + */ + vSashBounds.height = hSashBounds.y; + vSash.setBounds (vSashBounds); + } + /** + * Sets the size of the "Example" widgets. + */ + void setExampleWidgetSize () { + sashGroup.layout (true); + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + smoothButton.setSelection ((hSash.getStyle () & DWT.SMOOTH) !is 0); + } + + /** + * Handle the shell resized event. + */ + void resized () { + + /* Get the client area for the shell */ + Rectangle clientArea = sashComp.getClientArea (); + + /* + * Make list 1 half the width and half the height of the tab leaving room for the sash. + * Place list 1 in the top left quadrant of the tab. + */ + Rectangle list1Bounds = new Rectangle (0, 0, (clientArea.width - SASH_WIDTH) / 2, (clientArea.height - SASH_WIDTH) / 2); + list1.setBounds (list1Bounds); + + /* + * Make list 2 half the width and half the height of the tab leaving room for the sash. + * Place list 2 in the top right quadrant of the tab. + */ + list2.setBounds (list1Bounds.width + SASH_WIDTH, 0, clientArea.width - (list1Bounds.width + SASH_WIDTH), list1Bounds.height); + + /* + * Make the text area the full width and half the height of the tab leaving room for the sash. + * Place the text area in the bottom half of the tab. + */ + text.setBounds (0, list1Bounds.height + SASH_WIDTH, clientArea.width, clientArea.height - (list1Bounds.height + SASH_WIDTH)); + + /* Position the sashes */ + vSash.setBounds (list1Bounds.width, 0, SASH_WIDTH, list1Bounds.height); + hSash.setBounds (0, list1Bounds.height, clientArea.width, SASH_WIDTH); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/ScaleTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/ScaleTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,243 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.ScaleTab; + + + +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Group; +import dwt.widgets.Scale; +import dwt.widgets.Spinner; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import examples.controlexample.RangeTab; + + +class ScaleTab : RangeTab { + /* Example widgets and groups that contain them */ + Scale scale1; + Group scaleGroup; + + /* Spinner widgets added to the "Control" group */ + Spinner incrementSpinner, pageIncrementSpinner; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Control" widget children. + */ + void createControlWidgets () { + super.createControlWidgets (); + createIncrementGroup (); + createPageIncrementGroup (); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the scale */ + scaleGroup = new Group (exampleGroup, DWT.NONE); + scaleGroup.setLayout (new GridLayout ()); + scaleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + scaleGroup.setText ("Scale"); + + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (horizontalButton.getSelection ()) style |= DWT.HORIZONTAL; + if (verticalButton.getSelection ()) style |= DWT.VERTICAL; + if (borderButton.getSelection ()) style |= DWT.BORDER; + + /* Create the example widgets */ + scale1 = new Scale (scaleGroup, style); + } + + /** + * Create a group of widgets to control the increment + * attribute of the example widget. + */ + void createIncrementGroup() { + + /* Create the group */ + Group incrementGroup = new Group (controlGroup, DWT.NONE); + incrementGroup.setLayout (new GridLayout ()); + incrementGroup.setText (ControlExample.getResourceString("Increment")); + incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); + + /* Create the Spinner widget */ + incrementSpinner = new Spinner (incrementGroup, DWT.BORDER); + incrementSpinner.setMaximum (100000); + incrementSpinner.setSelection (getDefaultIncrement()); + incrementSpinner.setPageIncrement (100); + incrementSpinner.setIncrement (1); + incrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); + + /* Add the listeners */ + incrementSpinner.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent e) { + setWidgetIncrement (); + } + }); + } + + /** + * Create a group of widgets to control the page increment + * attribute of the example widget. + */ + void createPageIncrementGroup() { + + /* Create the group */ + Group pageIncrementGroup = new Group (controlGroup, DWT.NONE); + pageIncrementGroup.setLayout (new GridLayout ()); + pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment")); + pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); + + /* Create the Spinner widget */ + pageIncrementSpinner = new Spinner (pageIncrementGroup, DWT.BORDER); + pageIncrementSpinner.setMaximum (100000); + pageIncrementSpinner.setSelection (getDefaultPageIncrement()); + pageIncrementSpinner.setPageIncrement (100); + pageIncrementSpinner.setIncrement (1); + pageIncrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); + + /* Add the listeners */ + pageIncrementSpinner.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetPageIncrement (); + } + }); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) scale1]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Selection", "ToolTipText"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Scale"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + if (!instance.startup) { + setWidgetIncrement (); + setWidgetPageIncrement (); + } + } + + /** + * Gets the default maximum of the "Example" widgets. + */ + int getDefaultMaximum () { + return scale1.getMaximum(); + } + + /** + * Gets the default minimim of the "Example" widgets. + */ + int getDefaultMinimum () { + return scale1.getMinimum(); + } + + /** + * Gets the default selection of the "Example" widgets. + */ + int getDefaultSelection () { + return scale1.getSelection(); + } + + /** + * Gets the default increment of the "Example" widgets. + */ + int getDefaultIncrement () { + return scale1.getIncrement(); + } + + /** + * Gets the default page increment of the "Example" widgets. + */ + int getDefaultPageIncrement () { + return scale1.getPageIncrement(); + } + + /** + * Sets the increment of the "Example" widgets. + */ + void setWidgetIncrement () { + scale1.setIncrement (incrementSpinner.getSelection ()); + } + + /** + * Sets the minimim of the "Example" widgets. + */ + void setWidgetMaximum () { + scale1.setMaximum (maximumSpinner.getSelection ()); + } + + /** + * Sets the minimim of the "Example" widgets. + */ + void setWidgetMinimum () { + scale1.setMinimum (minimumSpinner.getSelection ()); + } + + /** + * Sets the page increment of the "Example" widgets. + */ + void setWidgetPageIncrement () { + scale1.setPageIncrement (pageIncrementSpinner.getSelection ()); + } + + /** + * Sets the selection of the "Example" widgets. + */ + void setWidgetSelection () { + scale1.setSelection (selectionSpinner.getSelection ()); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/ScrollableTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/ScrollableTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.ScrollableTab; + + + +import dwt.DWT; +import dwt.widgets.Button; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +abstract class ScrollableTab : Tab { + /* Style widgets added to the "Style" group */ + Button singleButton, multiButton, horizontalButton, verticalButton; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup () { + super.createStyleGroup (); + + /* Create the extra widgets */ + singleButton = new Button (styleGroup, DWT.RADIO); + singleButton.setText ("DWT.SINGLE"); + multiButton = new Button (styleGroup, DWT.RADIO); + multiButton.setText ("DWT.MULTI"); + horizontalButton = new Button (styleGroup, DWT.CHECK); + horizontalButton.setText ("DWT.H_SCROLL"); + horizontalButton.setSelection(true); + verticalButton = new Button (styleGroup, DWT.CHECK); + verticalButton.setText ("DWT.V_SCROLL"); + verticalButton.setSelection(true); + borderButton = new Button (styleGroup, DWT.CHECK); + borderButton.setText ("DWT.BORDER"); + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + Widget [] widgets = getExampleWidgets (); + if (widgets.length !is 0){ + singleButton.setSelection ((widgets [0].getStyle () & DWT.SINGLE) !is 0); + multiButton.setSelection ((widgets [0].getStyle () & DWT.MULTI) !is 0); + horizontalButton.setSelection ((widgets [0].getStyle () & DWT.H_SCROLL) !is 0); + verticalButton.setSelection ((widgets [0].getStyle () & DWT.V_SCROLL) !is 0); + borderButton.setSelection ((widgets [0].getStyle () & DWT.BORDER) !is 0); + } + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/ShellTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/ShellTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,313 @@ +/******************************************************************************* + * 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 + * Port to the D programming language: + * Frank Benoit +*******************************************************************************/ +module examples.controlexample.ShellTab; + + + +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.SelectionListener; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Event; +import dwt.widgets.Group; +import dwt.widgets.Listener; +import dwt.widgets.Shell; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +import dwt.dwthelper.utils; + +import tango.util.Convert; + +class ShellTab : Tab { + /* Style widgets added to the "Style" groups, and "Other" group */ + Button noParentButton, parentButton; + Button noTrimButton, closeButton, titleButton, minButton, maxButton, borderButton, resizeButton, onTopButton, toolButton; + Button createButton, closeAllButton; + Button modelessButton, primaryModalButton, applicationModalButton, systemModalButton; + Button imageButton; + Group parentStyleGroup, modalStyleGroup; + + /* Variables used to track the open shells */ + int shellCount = 0; + Shell [] shells; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Close all the example shells. + */ + void closeAllShells() { + for (int i = 0; i= shells.length) { + Shell [] newShells = new Shell [shells.length + 4]; + System.arraycopy (shells, 0, newShells, 0, shells.length); + shells = newShells; + } + + /* Compute the shell style */ + int style = DWT.NONE; + if (noTrimButton.getSelection()) style |= DWT.NO_TRIM; + if (closeButton.getSelection()) style |= DWT.CLOSE; + if (titleButton.getSelection()) style |= DWT.TITLE; + if (minButton.getSelection()) style |= DWT.MIN; + if (maxButton.getSelection()) style |= DWT.MAX; + if (borderButton.getSelection()) style |= DWT.BORDER; + if (resizeButton.getSelection()) style |= DWT.RESIZE; + if (onTopButton.getSelection()) style |= DWT.ON_TOP; + if (toolButton.getSelection()) style |= DWT.TOOL; + if (modelessButton.getSelection()) style |= DWT.MODELESS; + if (primaryModalButton.getSelection()) style |= DWT.PRIMARY_MODAL; + if (applicationModalButton.getSelection()) style |= DWT.APPLICATION_MODAL; + if (systemModalButton.getSelection()) style |= DWT.SYSTEM_MODAL; + + /* Create the shell with or without a parent */ + if (noParentButton.getSelection ()) { + shells [shellCount] = new Shell (style); + } else { + shells [shellCount] = new Shell (shell, style); + } + Shell currentShell = shells [shellCount]; + Button button = new Button(currentShell, DWT.PUSH); + button.setBounds(20, 20, 120, 30); + Button closeButton = new Button(currentShell, DWT.PUSH); + closeButton.setBounds(160, 20, 120, 30); + closeButton.setText(ControlExample.getResourceString("Close")); + closeButton.addListener(DWT.Selection, new class(currentShell) Listener { + Shell s; + this( Shell s ){ this.s = s; } + public void handleEvent(Event event) { + s.dispose(); + } + }); + + /* Set the size, title, and image, and open the shell */ + currentShell.setSize (300, 100); + currentShell.setText (ControlExample.getResourceString("Title") ~ to!(char[])(shellCount)); + if (imageButton.getSelection()) currentShell.setImage(instance.images[ControlExample.ciTarget]); + if (backgroundImageButton.getSelection()) currentShell.setBackgroundImage(instance.images[ControlExample.ciBackground]); + hookListeners (currentShell); + currentShell.open (); + shellCount++; + } + + /** + * Creates the "Control" group. + */ + void createControlGroup () { + /* + * Create the "Control" group. This is the group on the + * right half of each example tab. It consists of the + * style group, the 'other' group and the size group. + */ + controlGroup = new Group (tabFolderPage, DWT.NONE); + controlGroup.setLayout (new GridLayout (2, true)); + controlGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); + controlGroup.setText (ControlExample.getResourceString("Parameters")); + + /* Create a group for the decoration style controls */ + styleGroup = new Group (controlGroup, DWT.NONE); + styleGroup.setLayout (new GridLayout ()); + styleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false, 1, 3)); + styleGroup.setText (ControlExample.getResourceString("Decoration_Styles")); + + /* Create a group for the modal style controls */ + modalStyleGroup = new Group (controlGroup, DWT.NONE); + modalStyleGroup.setLayout (new GridLayout ()); + modalStyleGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); + modalStyleGroup.setText (ControlExample.getResourceString("Modal_Styles")); + + /* Create a group for the 'other' controls */ + otherGroup = new Group (controlGroup, DWT.NONE); + otherGroup.setLayout (new GridLayout ()); + otherGroup.setLayoutData (new GridData(DWT.FILL, DWT.FILL, false, false)); + otherGroup.setText (ControlExample.getResourceString("Other")); + + /* Create a group for the parent style controls */ + parentStyleGroup = new Group (controlGroup, DWT.NONE); + parentStyleGroup.setLayout (new GridLayout ()); + GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + parentStyleGroup.setLayoutData (gridData); + parentStyleGroup.setText (ControlExample.getResourceString("Parent")); + } + + /** + * Creates the "Control" widget children. + */ + void createControlWidgets () { + + /* Create the parent style buttons */ + noParentButton = new Button (parentStyleGroup, DWT.RADIO); + noParentButton.setText (ControlExample.getResourceString("No_Parent")); + parentButton = new Button (parentStyleGroup, DWT.RADIO); + parentButton.setText (ControlExample.getResourceString("Parent")); + + /* Create the decoration style buttons */ + noTrimButton = new Button (styleGroup, DWT.CHECK); + noTrimButton.setText ("DWT.NO_TRIM"); + closeButton = new Button (styleGroup, DWT.CHECK); + closeButton.setText ("DWT.CLOSE"); + titleButton = new Button (styleGroup, DWT.CHECK); + titleButton.setText ("DWT.TITLE"); + minButton = new Button (styleGroup, DWT.CHECK); + minButton.setText ("DWT.MIN"); + maxButton = new Button (styleGroup, DWT.CHECK); + maxButton.setText ("DWT.MAX"); + borderButton = new Button (styleGroup, DWT.CHECK); + borderButton.setText ("DWT.BORDER"); + resizeButton = new Button (styleGroup, DWT.CHECK); + resizeButton.setText ("DWT.RESIZE"); + onTopButton = new Button (styleGroup, DWT.CHECK); + onTopButton.setText ("DWT.ON_TOP"); + toolButton = new Button (styleGroup, DWT.CHECK); + toolButton.setText ("DWT.TOOL"); + + /* Create the modal style buttons */ + modelessButton = new Button (modalStyleGroup, DWT.RADIO); + modelessButton.setText ("DWT.MODELESS"); + primaryModalButton = new Button (modalStyleGroup, DWT.RADIO); + primaryModalButton.setText ("DWT.PRIMARY_MODAL"); + applicationModalButton = new Button (modalStyleGroup, DWT.RADIO); + applicationModalButton.setText ("DWT.APPLICATION_MODAL"); + systemModalButton = new Button (modalStyleGroup, DWT.RADIO); + systemModalButton.setText ("DWT.SYSTEM_MODAL"); + + /* Create the 'other' buttons */ + imageButton = new Button (otherGroup, DWT.CHECK); + imageButton.setText (ControlExample.getResourceString("Image")); + backgroundImageButton = new Button(otherGroup, DWT.CHECK); + backgroundImageButton.setText(ControlExample.getResourceString("BackgroundImage")); + + /* Create the "create" and "closeAll" buttons */ + createButton = new Button (controlGroup, DWT.NONE); + GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_END); + createButton.setLayoutData (gridData); + createButton.setText (ControlExample.getResourceString("Create_Shell")); + closeAllButton = new Button (controlGroup, DWT.NONE); + gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING); + closeAllButton.setText (ControlExample.getResourceString("Close_All_Shells")); + closeAllButton.setLayoutData (gridData); + + /* Add the listeners */ + createButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + createButtonSelected(e); + } + }); + closeAllButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + closeAllShells (); + } + }); + SelectionListener decorationButtonListener = new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + decorationButtonSelected(event); + } + }; + noTrimButton.addSelectionListener (decorationButtonListener); + closeButton.addSelectionListener (decorationButtonListener); + titleButton.addSelectionListener (decorationButtonListener); + minButton.addSelectionListener (decorationButtonListener); + maxButton.addSelectionListener (decorationButtonListener); + borderButton.addSelectionListener (decorationButtonListener); + resizeButton.addSelectionListener (decorationButtonListener); + applicationModalButton.addSelectionListener (decorationButtonListener); + systemModalButton.addSelectionListener (decorationButtonListener); + + /* Set the default state */ + noParentButton.setSelection (true); + modelessButton.setSelection (true); + backgroundImageButton.setSelection(false); + } + + /** + * Handle a decoration button selection event. + * + * @param event org.eclipse.swt.events.SelectionEvent + */ + public void decorationButtonSelected(SelectionEvent event) { + + /* Make sure if the modal style is DWT.APPLICATION_MODAL or + * DWT.SYSTEM_MODAL the style DWT.CLOSE is also selected. + * This is to make sure the user can close the shell. + */ + Button widget = cast(Button) event.widget; + if (widget is applicationModalButton || widget is systemModalButton) { + if (widget.getSelection()) { + closeButton.setSelection (true); + noTrimButton.setSelection (false); + } + return; + } + if (widget is closeButton) { + if (applicationModalButton.getSelection() || systemModalButton.getSelection()) { + closeButton.setSelection (true); + } + } + /* + * Make sure if the No Trim button is selected then + * all other decoration buttons are deselected. + */ + if (widget.getSelection() && widget !is noTrimButton) { + noTrimButton.setSelection (false); + return; + } + if (widget.getSelection() && widget is noTrimButton) { + if (applicationModalButton.getSelection() || systemModalButton.getSelection()) { + noTrimButton.setSelection (false); + return; + } + closeButton.setSelection (false); + titleButton.setSelection (false); + minButton.setSelection (false); + maxButton.setSelection (false); + borderButton.setSelection (false); + resizeButton.setSelection (false); + return; + } + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Shell"; + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/SliderTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/SliderTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,285 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.SliderTab; + + + +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Group; +import dwt.widgets.Slider; +import dwt.widgets.Spinner; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import examples.controlexample.RangeTab; + +class SliderTab : RangeTab { + /* Example widgets and groups that contain them */ + Slider slider1; + Group sliderGroup; + + /* Spinner widgets added to the "Control" group */ + Spinner incrementSpinner, pageIncrementSpinner, thumbSpinner; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Control" widget children. + */ + void createControlWidgets () { + super.createControlWidgets (); + createThumbGroup (); + createIncrementGroup (); + createPageIncrementGroup (); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the slider */ + sliderGroup = new Group (exampleGroup, DWT.NONE); + sliderGroup.setLayout (new GridLayout ()); + sliderGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + sliderGroup.setText ("Slider"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (horizontalButton.getSelection ()) style |= DWT.HORIZONTAL; + if (verticalButton.getSelection ()) style |= DWT.VERTICAL; + if (borderButton.getSelection ()) style |= DWT.BORDER; + + /* Create the example widgets */ + slider1 = new Slider(sliderGroup, style); + } + + /** + * Create a group of widgets to control the increment + * attribute of the example widget. + */ + void createIncrementGroup() { + + /* Create the group */ + Group incrementGroup = new Group (controlGroup, DWT.NONE); + incrementGroup.setLayout (new GridLayout ()); + incrementGroup.setText (ControlExample.getResourceString("Increment")); + incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); + + /* Create the Spinner widget */ + incrementSpinner = new Spinner (incrementGroup, DWT.BORDER); + incrementSpinner.setMaximum (100000); + incrementSpinner.setSelection (getDefaultIncrement()); + incrementSpinner.setPageIncrement (100); + incrementSpinner.setIncrement (1); + incrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); + + /* Add the listeners */ + incrementSpinner.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent e) { + setWidgetIncrement (); + } + }); + } + + /** + * Create a group of widgets to control the page increment + * attribute of the example widget. + */ + void createPageIncrementGroup() { + + /* Create the group */ + Group pageIncrementGroup = new Group (controlGroup, DWT.NONE); + pageIncrementGroup.setLayout (new GridLayout ()); + pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment")); + pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); + + /* Create the Spinner widget */ + pageIncrementSpinner = new Spinner (pageIncrementGroup, DWT.BORDER); + pageIncrementSpinner.setMaximum (100000); + pageIncrementSpinner.setSelection (getDefaultPageIncrement()); + pageIncrementSpinner.setPageIncrement (100); + pageIncrementSpinner.setIncrement (1); + pageIncrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); + + /* Add the listeners */ + pageIncrementSpinner.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetPageIncrement (); + } + }); + } + + /** + * Create a group of widgets to control the thumb + * attribute of the example widget. + */ + void createThumbGroup() { + + /* Create the group */ + Group thumbGroup = new Group (controlGroup, DWT.NONE); + thumbGroup.setLayout (new GridLayout ()); + thumbGroup.setText (ControlExample.getResourceString("Thumb")); + thumbGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); + + /* Create the Spinner widget */ + thumbSpinner = new Spinner (thumbGroup, DWT.BORDER); + thumbSpinner.setMaximum (100000); + thumbSpinner.setSelection (getDefaultThumb()); + thumbSpinner.setPageIncrement (100); + thumbSpinner.setIncrement (1); + thumbSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); + + /* Add the listeners */ + thumbSpinner.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetThumb (); + } + }); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) slider1 ]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Selection", "ToolTipText"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Slider"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + if (!instance.startup) { + setWidgetIncrement (); + setWidgetPageIncrement (); + setWidgetThumb (); + } + } + + /** + * Gets the default maximum of the "Example" widgets. + */ + int getDefaultMaximum () { + return slider1.getMaximum(); + } + + /** + * Gets the default minimim of the "Example" widgets. + */ + int getDefaultMinimum () { + return slider1.getMinimum(); + } + + /** + * Gets the default selection of the "Example" widgets. + */ + int getDefaultSelection () { + return slider1.getSelection(); + } + + /** + * Gets the default increment of the "Example" widgets. + */ + int getDefaultIncrement () { + return slider1.getIncrement(); + } + + /** + * Gets the default page increment of the "Example" widgets. + */ + int getDefaultPageIncrement () { + return slider1.getPageIncrement(); + } + + /** + * Gets the default thumb of the "Example" widgets. + */ + int getDefaultThumb () { + return slider1.getThumb(); + } + + /** + * Sets the increment of the "Example" widgets. + */ + void setWidgetIncrement () { + slider1.setIncrement (incrementSpinner.getSelection ()); + } + + /** + * Sets the minimim of the "Example" widgets. + */ + void setWidgetMaximum () { + slider1.setMaximum (maximumSpinner.getSelection ()); + } + + /** + * Sets the minimim of the "Example" widgets. + */ + void setWidgetMinimum () { + slider1.setMinimum (minimumSpinner.getSelection ()); + } + + /** + * Sets the page increment of the "Example" widgets. + */ + void setWidgetPageIncrement () { + slider1.setPageIncrement (pageIncrementSpinner.getSelection ()); + } + + /** + * Sets the selection of the "Example" widgets. + */ + void setWidgetSelection () { + slider1.setSelection (selectionSpinner.getSelection ()); + } + + /** + * Sets the thumb of the "Example" widgets. + */ + void setWidgetThumb () { + slider1.setThumb (thumbSpinner.getSelection ()); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/SpinnerTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/SpinnerTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,333 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.SpinnerTab; + + + +import dwt.DWT; +import dwt.events.ControlAdapter; +import dwt.events.ControlEvent; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Composite; +import dwt.widgets.Group; +import dwt.widgets.Spinner; +import dwt.widgets.TabFolder; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import examples.controlexample.RangeTab; + +class SpinnerTab : RangeTab { + + /* Example widgets and groups that contain them */ + Spinner spinner1; + Group spinnerGroup; + + /* Style widgets added to the "Style" group */ + Button readOnlyButton, wrapButton; + + /* Spinner widgets added to the "Control" group */ + Spinner incrementSpinner, pageIncrementSpinner, digitsSpinner; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Control" widget children. + */ + void createControlWidgets () { + super.createControlWidgets (); + createIncrementGroup (); + createPageIncrementGroup (); + createDigitsGroup (); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the spinner */ + spinnerGroup = new Group (exampleGroup, DWT.NONE); + spinnerGroup.setLayout (new GridLayout ()); + spinnerGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + spinnerGroup.setText ("Spinner"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY; + if (borderButton.getSelection ()) style |= DWT.BORDER; + if (wrapButton.getSelection ()) style |= DWT.WRAP; + + /* Create the example widgets */ + spinner1 = new Spinner (spinnerGroup, style); + } + + /** + * Create a group of widgets to control the increment + * attribute of the example widget. + */ + void createIncrementGroup() { + + /* Create the group */ + Group incrementGroup = new Group (controlGroup, DWT.NONE); + incrementGroup.setLayout (new GridLayout ()); + incrementGroup.setText (ControlExample.getResourceString("Increment")); + incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); + + /* Create the Spinner widget */ + incrementSpinner = new Spinner (incrementGroup, DWT.BORDER); + incrementSpinner.setMaximum (100000); + incrementSpinner.setSelection (getDefaultIncrement()); + incrementSpinner.setPageIncrement (100); + incrementSpinner.setIncrement (1); + incrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); + + /* Add the listeners */ + incrementSpinner.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent e) { + setWidgetIncrement (); + } + }); + } + + /** + * Create a group of widgets to control the page increment + * attribute of the example widget. + */ + void createPageIncrementGroup() { + + /* Create the group */ + Group pageIncrementGroup = new Group (controlGroup, DWT.NONE); + pageIncrementGroup.setLayout (new GridLayout ()); + pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment")); + pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); + + /* Create the Spinner widget */ + pageIncrementSpinner = new Spinner (pageIncrementGroup, DWT.BORDER); + pageIncrementSpinner.setMaximum (100000); + pageIncrementSpinner.setSelection (getDefaultPageIncrement()); + pageIncrementSpinner.setPageIncrement (100); + pageIncrementSpinner.setIncrement (1); + pageIncrementSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); + + /* Add the listeners */ + pageIncrementSpinner.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetPageIncrement (); + } + }); + } + + /** + * Create a group of widgets to control the digits + * attribute of the example widget. + */ + void createDigitsGroup() { + + /* Create the group */ + Group digitsGroup = new Group (controlGroup, DWT.NONE); + digitsGroup.setLayout (new GridLayout ()); + digitsGroup.setText (ControlExample.getResourceString("Digits")); + digitsGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); + + /* Create the Spinner widget */ + digitsSpinner = new Spinner (digitsGroup, DWT.BORDER); + digitsSpinner.setMaximum (100000); + digitsSpinner.setSelection (getDefaultDigits()); + digitsSpinner.setPageIncrement (100); + digitsSpinner.setIncrement (1); + digitsSpinner.setLayoutData (new GridData (DWT.FILL, DWT.CENTER, true, false)); + + /* Add the listeners */ + digitsSpinner.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent e) { + setWidgetDigits (); + } + }); + } + + /** + * Creates the tab folder page. + * + * @param tabFolder org.eclipse.swt.widgets.TabFolder + * @return the new page for the tab folder + */ + Composite createTabFolderPage (TabFolder tabFolder) { + super.createTabFolderPage (tabFolder); + + /* + * Add a resize listener to the tabFolderPage so that + * if the user types into the example widget to change + * its preferred size, and then resizes the shell, we + * recalculate the preferred size correctly. + */ + tabFolderPage.addControlListener(new class() ControlAdapter { + public void controlResized(ControlEvent e) { + setExampleWidgetSize (); + } + }); + + return tabFolderPage; + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup () { + orientationButtons = false; + super.createStyleGroup (); + + /* Create the extra widgets */ + readOnlyButton = new Button (styleGroup, DWT.CHECK); + readOnlyButton.setText ("DWT.READ_ONLY"); + wrapButton = new Button (styleGroup, DWT.CHECK); + wrapButton.setText ("DWT.WRAP"); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) spinner1 ]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Selection", "ToolTipText"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Spinner"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + readOnlyButton.setSelection ((spinner1.getStyle () & DWT.READ_ONLY) !is 0); + wrapButton.setSelection ((spinner1.getStyle () & DWT.WRAP) !is 0); + if (!instance.startup) { + setWidgetIncrement (); + setWidgetPageIncrement (); + setWidgetDigits (); + } + } + + /** + * Gets the default maximum of the "Example" widgets. + */ + int getDefaultMaximum () { + return spinner1.getMaximum(); + } + + /** + * Gets the default minimim of the "Example" widgets. + */ + int getDefaultMinimum () { + return spinner1.getMinimum(); + } + + /** + * Gets the default selection of the "Example" widgets. + */ + int getDefaultSelection () { + return spinner1.getSelection(); + } + + /** + * Gets the default increment of the "Example" widgets. + */ + int getDefaultIncrement () { + return spinner1.getIncrement(); + } + + /** + * Gets the default page increment of the "Example" widgets. + */ + int getDefaultPageIncrement () { + return spinner1.getPageIncrement(); + } + + /** + * Gets the default digits of the "Example" widgets. + */ + int getDefaultDigits () { + return spinner1.getDigits(); + } + + /** + * Sets the increment of the "Example" widgets. + */ + void setWidgetIncrement () { + spinner1.setIncrement (incrementSpinner.getSelection ()); + } + + /** + * Sets the minimim of the "Example" widgets. + */ + void setWidgetMaximum () { + spinner1.setMaximum (maximumSpinner.getSelection ()); + } + + /** + * Sets the minimim of the "Example" widgets. + */ + void setWidgetMinimum () { + spinner1.setMinimum (minimumSpinner.getSelection ()); + } + + /** + * Sets the page increment of the "Example" widgets. + */ + void setWidgetPageIncrement () { + spinner1.setPageIncrement (pageIncrementSpinner.getSelection ()); + } + + /** + * Sets the digits of the "Example" widgets. + */ + void setWidgetDigits () { + spinner1.setDigits (digitsSpinner.getSelection ()); + } + + /** + * Sets the selection of the "Example" widgets. + */ + void setWidgetSelection () { + spinner1.setSelection (selectionSpinner.getSelection ()); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/StyledTextTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/StyledTextTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,356 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.StyledTextTab; + + +import dwt.dwthelper.ByteArrayInputStream; + + +import dwt.DWT; +import dwt.custom.StyleRange; +import dwt.custom.StyledText; +import dwt.events.ControlAdapter; +import dwt.events.ControlEvent; +import dwt.events.DisposeEvent; +import dwt.events.DisposeListener; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.SelectionListener; +import dwt.graphics.Color; +import dwt.graphics.Image; +import dwt.graphics.ImageData; +import dwt.graphics.Point; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Composite; +import dwt.widgets.Display; +import dwt.widgets.Group; +import dwt.widgets.Label; +import dwt.widgets.TabFolder; +import dwt.widgets.Widget; + +import examples.controlexample.ScrollableTab; +import examples.controlexample.ControlExample; +import tango.core.Exception; +import tango.io.Stdout; + +class StyledTextTab : ScrollableTab { + /* Example widgets and groups that contain them */ + StyledText styledText; + Group styledTextGroup, styledTextStyleGroup; + + /* Style widgets added to the "Style" group */ + Button wrapButton, readOnlyButton, fullSelectionButton; + + /* Buttons for adding StyleRanges to StyledText */ + Button boldButton, italicButton, redButton, yellowButton, underlineButton, strikeoutButton; + Image boldImage, italicImage, redImage, yellowImage, underlineImage, strikeoutImage; + + /* Variables for saving state. */ + char[] text; + StyleRange[] styleRanges; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates a bitmap image. + */ + Image createBitmapImage (Display display, void[] sourceData, void[] maskData ) { + InputStream sourceStream = new ByteArrayInputStream ( cast(byte[])sourceData ); + InputStream maskStream = new ByteArrayInputStream ( cast(byte[])maskData ); + ImageData source = new ImageData (sourceStream); + ImageData mask = new ImageData (maskStream); + Image result = new Image (display, source, mask); + try { + sourceStream.close (); + maskStream.close (); + } catch (IOException e) { + Stderr.formatln( "Stacktrace: {}", e ); + } + return result; + } + + /** + * Creates the "Control" widget children. + */ + void createControlWidgets () { + super.createControlWidgets (); + + /* Add a group for modifying the StyledText widget */ + createStyledTextStyleGroup (); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the styled text widget */ + styledTextGroup = new Group (exampleGroup, DWT.NONE); + styledTextGroup.setLayout (new GridLayout ()); + styledTextGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + styledTextGroup.setText ("StyledText"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (singleButton.getSelection ()) style |= DWT.SINGLE; + if (multiButton.getSelection ()) style |= DWT.MULTI; + if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; + if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; + if (wrapButton.getSelection ()) style |= DWT.WRAP; + if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY; + if (borderButton.getSelection ()) style |= DWT.BORDER; + if (fullSelectionButton.getSelection ()) style |= DWT.FULL_SELECTION; + + /* Create the example widgets */ + styledText = new StyledText (styledTextGroup, style); + styledText.setText (ControlExample.getResourceString("Example_string")); + styledText.append ("\n"); + styledText.append (ControlExample.getResourceString("One_Two_Three")); + + if (text !is null) { + styledText.setText(text); + text = null; + } + if (styleRanges !is null) { + styledText.setStyleRanges(styleRanges); + styleRanges = null; + } + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup(); + + /* Create the extra widgets */ + wrapButton = new Button (styleGroup, DWT.CHECK); + wrapButton.setText ("DWT.WRAP"); + readOnlyButton = new Button (styleGroup, DWT.CHECK); + readOnlyButton.setText ("DWT.READ_ONLY"); + fullSelectionButton = new Button (styleGroup, DWT.CHECK); + fullSelectionButton.setText ("DWT.FULL_SELECTION"); + } + + /** + * Creates the "StyledText Style" group. + */ + void createStyledTextStyleGroup () { + styledTextStyleGroup = new Group (controlGroup, DWT.NONE); + styledTextStyleGroup.setText (ControlExample.getResourceString ("StyledText_Styles")); + styledTextStyleGroup.setLayout (new GridLayout(6, false)); + GridData data = new GridData (GridData.HORIZONTAL_ALIGN_FILL); + data.horizontalSpan = 2; + styledTextStyleGroup.setLayoutData (data); + + /* Get images */ + boldImage = createBitmapImage (display, import("dwtexamples.controlexample.bold.bmp"), import("dwtexamples.controlexample.bold_mask.bmp")); + italicImage = createBitmapImage (display, import("dwtexamples.controlexample.italic.bmp"), import("dwtexamples.controlexample.italic_mask.bmp")); + redImage = createBitmapImage (display, import("dwtexamples.controlexample.red.bmp"), import("dwtexamples.controlexample.red_mask.bmp")); + yellowImage = createBitmapImage (display, import("dwtexamples.controlexample.yellow.bmp"), import("dwtexamples.controlexample.yellow_mask.bmp")); + underlineImage = createBitmapImage (display, import("dwtexamples.controlexample.underline.bmp"), import("dwtexamples.controlexample.underline_mask.bmp")); + strikeoutImage = createBitmapImage (display, import("dwtexamples.controlexample.strikeout.bmp"), import("dwtexamples.controlexample.strikeout_mask.bmp")); + + /* Create controls to modify the StyledText */ + Label label = new Label (styledTextStyleGroup, DWT.NONE); + label.setText (ControlExample.getResourceString ("StyledText_Style_Instructions")); + label.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, false, false, 6, 1)); + label = new Label (styledTextStyleGroup, DWT.NONE); + label.setText (ControlExample.getResourceString ("Bold")); + label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); + boldButton = new Button (styledTextStyleGroup, DWT.PUSH); + boldButton.setImage (boldImage); + label = new Label (styledTextStyleGroup, DWT.NONE); + label.setText (ControlExample.getResourceString ("Underline")); + label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); + underlineButton = new Button (styledTextStyleGroup, DWT.PUSH); + underlineButton.setImage (underlineImage); + label = new Label (styledTextStyleGroup, DWT.NONE); + label.setText (ControlExample.getResourceString ("Foreground_Style")); + label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); + redButton = new Button (styledTextStyleGroup, DWT.PUSH); + redButton.setImage (redImage); + label = new Label (styledTextStyleGroup, DWT.NONE); + label.setText (ControlExample.getResourceString ("Italic")); + label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); + italicButton = new Button (styledTextStyleGroup, DWT.PUSH); + italicButton.setImage (italicImage); + label = new Label (styledTextStyleGroup, DWT.NONE); + label.setText (ControlExample.getResourceString ("Strikeout")); + label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); + strikeoutButton = new Button (styledTextStyleGroup, DWT.PUSH); + strikeoutButton.setImage (strikeoutImage); + label = new Label (styledTextStyleGroup, DWT.NONE); + label.setText (ControlExample.getResourceString ("Background_Style")); + label.setLayoutData(new GridData(DWT.END, DWT.CENTER, true, false)); + yellowButton = new Button (styledTextStyleGroup, DWT.PUSH); + yellowButton.setImage (yellowImage); + SelectionListener styleListener = new class() SelectionAdapter { + public void widgetSelected (SelectionEvent e) { + Point sel = styledText.getSelectionRange(); + if ((sel is null) || (sel.y is 0)) return; + StyleRange style; + for (int i = sel.x; i + *******************************************************************************/ +module examples.controlexample.Tab; + + + +import dwt.DWT; +import dwt.events.ArmEvent; +import dwt.events.ControlEvent; +import dwt.events.DisposeEvent; +import dwt.events.DisposeListener; +import dwt.events.FocusEvent; +import dwt.events.HelpEvent; +import dwt.events.KeyAdapter; +import dwt.events.KeyEvent; +import dwt.events.MenuEvent; +import dwt.events.ModifyEvent; +import dwt.events.MouseEvent; +import dwt.events.PaintEvent; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.SelectionListener; +import dwt.events.ShellEvent; +import dwt.events.TraverseEvent; +import dwt.events.TreeEvent; +import dwt.events.TypedEvent; +import dwt.events.VerifyEvent; +import dwt.graphics.Color; +import dwt.graphics.Font; +import dwt.graphics.FontData; +import dwt.graphics.GC; +import dwt.graphics.Image; +import dwt.graphics.Point; +import dwt.graphics.RGB; +import dwt.graphics.Rectangle; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.ColorDialog; +import dwt.widgets.Combo; +import dwt.widgets.Composite; +import dwt.widgets.Control; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.FontDialog; +import dwt.widgets.Group; +import dwt.widgets.Item; +import dwt.widgets.Label; +import dwt.widgets.Link; +import dwt.widgets.List; +import dwt.widgets.Listener; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.ProgressBar; +import dwt.widgets.Sash; +import dwt.widgets.Scale; +import dwt.widgets.Shell; +import dwt.widgets.Slider; +import dwt.widgets.Spinner; +import dwt.widgets.TabFolder; +import dwt.widgets.Table; +import dwt.widgets.TableItem; +import dwt.widgets.Text; +import dwt.widgets.Tree; +import dwt.widgets.TreeItem; +import dwt.widgets.ToolTip; +import dwt.widgets.Widget; +import dwt.widgets.Canvas; +import dwt.widgets.CoolBar; +import dwt.widgets.ExpandBar; + +import dwt.dwthelper.utils; + +import examples.controlexample.ControlExample; +import tango.text.convert.Format; + +import tango.io.Stdout; + +/** + * Tab is the abstract superclass of every page + * in the example's tab folder. Each page in the tab folder + * describes a control. + * + * A Tab itself is not a control but instead provides a + * hierarchy with which to share code that is common to + * every page in the folder. + * + * A typical page in a Tab contains a two column composite. + * The left column contains the "Example" group. The right + * column contains "Control" group. The "Control" group + * contains controls that allow the user to interact with + * the example control. The "Control" group typically + * contains a "Style", "Other" and "Size" group. Subclasses + * can override these defaults to augment a group or stop + * a group from being created. + */ + struct EventName { + char[] name; + int id; + } +abstract class Tab { + Shell shell; + Display display; + + /* Common control buttons */ + Button borderButton, enabledButton, visibleButton, backgroundImageButton, popupMenuButton; + Button preferredButton, tooSmallButton, smallButton, largeButton, fillHButton, fillVButton; + + /* Common groups and composites */ + Composite tabFolderPage; + Group exampleGroup, controlGroup, listenersGroup, otherGroup, sizeGroup, styleGroup, colorGroup, backgroundModeGroup; + + /* Controlling instance */ + const ControlExample instance; + + /* Sizing constants for the "Size" group */ + static const int TOO_SMALL_SIZE = 10; + static const int SMALL_SIZE = 50; + static const int LARGE_SIZE = 100; + + /* Right-to-left support */ + static const bool RTL_SUPPORT_ENABLE = false; + Group orientationGroup; + Button rtlButton, ltrButton, defaultOrietationButton; + + /* Controls and resources for the "Colors & Fonts" group */ + static const int IMAGE_SIZE = 12; + static const int FOREGROUND_COLOR = 0; + static const int BACKGROUND_COLOR = 1; + static const int FONT = 2; + Table colorAndFontTable; + ColorDialog colorDialog; + FontDialog fontDialog; + Color foregroundColor, backgroundColor; + Font font; + + /* Controls and resources for the "Background Mode" group */ + Combo backgroundModeCombo; + Button backgroundModeImageButton, backgroundModeColorButton; + + /* Event logging variables and controls */ + Text eventConsole; + bool logging = false; + bool [] eventsFilter; + + /* Set/Get API controls */ + Combo nameCombo; + Label returnTypeLabel; + Button getButton, setButton; + Text setText, getText; + + static EventName[] EVENT_NAMES = [ + {"Activate"[], DWT.Activate}, + {"Arm", DWT.Arm}, + {"Close", DWT.Close}, + {"Collapse", DWT.Collapse}, + {"Deactivate", DWT.Deactivate}, + {"DefaultSelection", DWT.DefaultSelection}, + {"Deiconify", DWT.Deiconify}, + {"Dispose", DWT.Dispose}, + {"DragDetect", DWT.DragDetect}, + {"EraseItem", DWT.EraseItem}, + {"Expand", DWT.Expand}, + {"FocusIn", DWT.FocusIn}, + {"FocusOut", DWT.FocusOut}, + {"HardKeyDown", DWT.HardKeyDown}, + {"HardKeyUp", DWT.HardKeyUp}, + {"Help", DWT.Help}, + {"Hide", DWT.Hide}, + {"Iconify", DWT.Iconify}, + {"KeyDown", DWT.KeyDown}, + {"KeyUp", DWT.KeyUp}, + {"MeasureItem", DWT.MeasureItem}, + {"MenuDetect", DWT.MenuDetect}, + {"Modify", DWT.Modify}, + {"MouseDoubleClick", DWT.MouseDoubleClick}, + {"MouseDown", DWT.MouseDown}, + {"MouseEnter", DWT.MouseEnter}, + {"MouseExit", DWT.MouseExit}, + {"MouseHover", DWT.MouseHover}, + {"MouseMove", DWT.MouseMove}, + {"MouseUp", DWT.MouseUp}, + {"MouseWheel", DWT.MouseWheel}, + {"Move", DWT.Move}, + {"Paint", DWT.Paint}, + {"PaintItem", DWT.PaintItem}, + {"Resize", DWT.Resize}, + {"Selection", DWT.Selection}, + {"SetData", DWT.SetData}, +// {"Settings", DWT.Settings}, // note: this event only goes to Display + {"Show", DWT.Show}, + {"Traverse", DWT.Traverse}, + {"Verify", DWT.Verify} + ]; + + bool samplePopup = false; + + + struct ReflectTypeInfo{ + ReflectMethodInfo[ char[] ] methods; + } + struct ReflectMethodInfo{ + TypeInfo returnType; + TypeInfo[] argumentTypes; + } + static ReflectTypeInfo[ ClassInfo ] reflectTypeInfos; + + static ReflectMethodInfo createMethodInfo( TypeInfo ret, TypeInfo[] args ... ){ + ReflectMethodInfo res; + res.returnType = ret; + foreach( arg; args ){ + res.argumentTypes ~= arg; + } + return res; + } + static void createSetterGetter( ref ReflectTypeInfo ti, char[] name, TypeInfo type ){ + ti.methods[ "get" ~ name ] = createMethodInfo( type ); + ti.methods[ "set" ~ name ] = createMethodInfo( typeid(void), type ); + } + + static void registerTypes(){ + if( reflectTypeInfos.length > 0 ){ + return; + } + + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Selection", typeid(bool) ); + createSetterGetter( ti, "Text", typeid(char[]) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ Button.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ Canvas.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Orientation", typeid(int) ); + createSetterGetter( ti, "Items", typeid(char[]) ); + createSetterGetter( ti, "Selection", typeid(Point) ); + createSetterGetter( ti, "Text", typeid(char[]) ); + createSetterGetter( ti, "TextLimit", typeid(int) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + createSetterGetter( ti, "VisibleItemCount", typeid(int) ); + reflectTypeInfos[ Combo.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ CoolBar.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Spacing", typeid(int) ); + reflectTypeInfos[ ExpandBar.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ Group.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Text", typeid(char[]) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ Label.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Text", typeid(char[]) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ Link.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Items", typeid(char[][]) ); + createSetterGetter( ti, "Selection", typeid(char[]) ); + createSetterGetter( ti, "TopIndex", typeid(int) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ List.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Selection", typeid(char[]) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ ProgressBar.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ Sash.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Selection", typeid(int) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ Scale.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Selection", typeid(int) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ Slider.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Selection", typeid(int) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ Spinner.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "DoubleClickEnabled", typeid(bool) ); + createSetterGetter( ti, "EchoChar", typeid(wchar) ); + createSetterGetter( ti, "Editable", typeid(bool) ); + createSetterGetter( ti, "Orientation", typeid(int) ); + createSetterGetter( ti, "Selection", typeid(Point) ); + createSetterGetter( ti, "Tabs", typeid(int) ); + createSetterGetter( ti, "Text", typeid(char[]) ); + createSetterGetter( ti, "TextLimit", typeid(int) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + createSetterGetter( ti, "TopIndex", typeid(int) ); + reflectTypeInfos[ Text.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Message", typeid(int) ); + createSetterGetter( ti, "Text", typeid(char[]) ); + reflectTypeInfos[ ToolTip.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "ColumnOrder", typeid(int[]) ); + createSetterGetter( ti, "Selection", typeid(TreeItem[]) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + createSetterGetter( ti, "TopItem", typeid(int) ); + reflectTypeInfos[ Tree.classinfo ] = ti; + } + + /+{ + ReflectTypeInfo ti; + createSetterGetter( ti, "Editable", typeid(bool) ); + createSetterGetter( ti, "Items", typeid(char[]) ); + createSetterGetter( ti, "Selection", typeid(Point) ); + createSetterGetter( ti, "Text", typeid(char[]) ); + createSetterGetter( ti, "TextLimit", typeid(int) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + createSetterGetter( ti, "VisibleItemCount", typeid(int) ); + reflectTypeInfos[ CCombo.classinfo ] = ti; + }+/ + } + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + this.instance = instance; + registerTypes(); + } + + /** + * Creates the "Control" group. The "Control" group + * is typically the right hand column in the tab. + */ + void createControlGroup () { + + /* + * Create the "Control" group. This is the group on the + * right half of each example tab. It consists of the + * "Style" group, the "Other" group and the "Size" group. + */ + controlGroup = new Group (tabFolderPage, DWT.NONE); + controlGroup.setLayout (new GridLayout (2, true)); + controlGroup.setLayoutData (new GridData(DWT.FILL, DWT.FILL, false, false)); + controlGroup.setText (ControlExample.getResourceString("Parameters")); + + /* Create individual groups inside the "Control" group */ + createStyleGroup (); + createOtherGroup (); + createSetGetGroup(); + createSizeGroup (); + createColorAndFontGroup (); + if (RTL_SUPPORT_ENABLE) { + createOrientationGroup (); + } + + /* + * For each Button child in the style group, add a selection + * listener that will recreate the example controls. If the + * style group button is a RADIO button, ensure that the radio + * button is selected before recreating the example controls. + * When the user selects a RADIO button, the current RADIO + * button in the group is deselected and the new RADIO button + * is selected automatically. The listeners are notified for + * both these operations but typically only do work when a RADIO + * button is selected. + */ + SelectionListener selectionListener = new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + if ((event.widget.getStyle () & DWT.RADIO) !is 0) { + if (!(cast(Button) event.widget).getSelection ()) return; + } + recreateExampleWidgets (); + } + }; + Control [] children = styleGroup.getChildren (); + for (int i=0; i 0) oldColor = controls [0].getForeground (); + } + if (oldColor !is null) colorDialog.setRGB(oldColor.getRGB()); // seed dialog with current color + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = foregroundColor; // save old foreground color to dispose when done + foregroundColor = new Color (display, rgb); + setExampleWidgetForeground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case BACKGROUND_COLOR: { + Color oldColor = backgroundColor; + if (oldColor is null) { + Control [] controls = getExampleControls (); + if (controls.length > 0) oldColor = controls [0].getBackground (); // seed dialog with current color + } + if (oldColor !is null) colorDialog.setRGB(oldColor.getRGB()); + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = backgroundColor; // save old background color to dispose when done + backgroundColor = new Color (display, rgb); + setExampleWidgetBackground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case FONT: { + Font oldFont = font; + if (oldFont is null) { + Control [] controls = getExampleControls (); + if (controls.length > 0) oldFont = controls [0].getFont (); + } + if (oldFont !is null) fontDialog.setFontList(oldFont.getFontData()); // seed dialog with current font + FontData fontData = fontDialog.open (); + if (fontData is null) return; + oldFont = font; // dispose old font when done + font = new Font (display, fontData); + setExampleWidgetFont (); + setExampleWidgetSize (); + if (oldFont !is null) oldFont.dispose (); + } + break; + default: + } + } + + /** + * Creates the "Other" group. This is typically + * a child of the "Control" group. + */ + void createOtherGroup () { + /* Create the group */ + otherGroup = new Group (controlGroup, DWT.NONE); + otherGroup.setLayout (new GridLayout ()); + otherGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); + otherGroup.setText (ControlExample.getResourceString("Other")); + + /* Create the controls */ + enabledButton = new Button(otherGroup, DWT.CHECK); + enabledButton.setText(ControlExample.getResourceString("Enabled")); + visibleButton = new Button(otherGroup, DWT.CHECK); + visibleButton.setText(ControlExample.getResourceString("Visible")); + backgroundImageButton = new Button(otherGroup, DWT.CHECK); + backgroundImageButton.setText(ControlExample.getResourceString("BackgroundImage")); + popupMenuButton = new Button(otherGroup, DWT.CHECK); + popupMenuButton.setText(ControlExample.getResourceString("Popup_Menu")); + + /* Add the listeners */ + enabledButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setExampleWidgetEnabled (); + } + }); + visibleButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setExampleWidgetVisibility (); + } + }); + backgroundImageButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setExampleWidgetBackgroundImage (); + } + }); + popupMenuButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setExampleWidgetPopupMenu (); + } + }); + + /* Set the default state */ + enabledButton.setSelection(true); + visibleButton.setSelection(true); + backgroundImageButton.setSelection(false); + popupMenuButton.setSelection(false); + } + + /** + * Creates the "Background Mode" group. + */ + void createBackgroundModeGroup () { + // note that this method must be called after createExampleWidgets + if (getExampleControls ().length is 0) return; + + /* Create the group */ + backgroundModeGroup = new Group (controlGroup, DWT.NONE); + backgroundModeGroup.setLayout (new GridLayout ()); + backgroundModeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); + backgroundModeGroup.setText (ControlExample.getResourceString("Background_Mode")); + + /* Create the controls */ + backgroundModeCombo = new Combo(backgroundModeGroup, DWT.READ_ONLY); + backgroundModeCombo.setItems(["DWT.INHERIT_NONE", "DWT.INHERIT_DEFAULT", "DWT.INHERIT_FORCE"]); + backgroundModeImageButton = new Button(backgroundModeGroup, DWT.CHECK); + backgroundModeImageButton.setText(ControlExample.getResourceString("BackgroundImage")); + backgroundModeColorButton = new Button(backgroundModeGroup, DWT.CHECK); + backgroundModeColorButton.setText(ControlExample.getResourceString("Background_Color")); + + /* Add the listeners */ + backgroundModeCombo.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setExampleGroupBackgroundMode (); + } + }); + backgroundModeImageButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setExampleGroupBackgroundImage (); + } + }); + backgroundModeColorButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setExampleGroupBackgroundColor (); + } + }); + + /* Set the default state */ + backgroundModeCombo.setText(backgroundModeCombo.getItem(0)); + backgroundModeImageButton.setSelection(false); + backgroundModeColorButton.setSelection(false); + } + + /** + * Create the event console popup menu. + */ + void createEventConsolePopup () { + Menu popup = new Menu (shell, DWT.POP_UP); + eventConsole.setMenu (popup); + + MenuItem cut = new MenuItem (popup, DWT.PUSH); + cut.setText (ControlExample.getResourceString("MenuItem_Cut")); + cut.addListener (DWT.Selection, new class() Listener { + public void handleEvent (Event event) { + eventConsole.cut (); + } + }); + MenuItem copy = new MenuItem (popup, DWT.PUSH); + copy.setText (ControlExample.getResourceString("MenuItem_Copy")); + copy.addListener (DWT.Selection, new class() Listener { + public void handleEvent (Event event) { + eventConsole.copy (); + } + }); + MenuItem paste = new MenuItem (popup, DWT.PUSH); + paste.setText (ControlExample.getResourceString("MenuItem_Paste")); + paste.addListener (DWT.Selection, new class() Listener { + public void handleEvent (Event event) { + eventConsole.paste (); + } + }); + new MenuItem (popup, DWT.SEPARATOR); + MenuItem selectAll = new MenuItem (popup, DWT.PUSH); + selectAll.setText(ControlExample.getResourceString("MenuItem_SelectAll")); + selectAll.addListener (DWT.Selection, new class() Listener { + public void handleEvent (Event event) { + eventConsole.selectAll (); + } + }); + } + + /** + * Creates the "Example" group. The "Example" group + * is typically the left hand column in the tab. + */ + void createExampleGroup () { + exampleGroup = new Group (tabFolderPage, DWT.NONE); + exampleGroup.setLayout (new GridLayout ()); + exampleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + } + + /** + * Creates the "Example" widget children of the "Example" group. + * Subclasses override this method to create the particular + * example control. + */ + void createExampleWidgets () { + /* Do nothing */ + } + + /** + * Creates and opens the "Listener selection" dialog. + */ + void createListenerSelectionDialog () { + Shell dialog = new Shell (shell, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); + dialog.setText (ControlExample.getResourceString ("Select_Listeners")); + dialog.setLayout (new GridLayout (2, false)); + Table table = new Table (dialog, DWT.BORDER | DWT.V_SCROLL | DWT.CHECK); + GridData data = new GridData(GridData.FILL_BOTH); + data.verticalSpan = 2; + table.setLayoutData(data); + for (int i = 0; i < EVENT_NAMES.length; i++) { + TableItem item = new TableItem (table, DWT.NONE); + item.setText( EVENT_NAMES[i].name ); + item.setChecked (eventsFilter[i]); + } + char[] [] customNames = getCustomEventNames (); + for (int i = 0; i < customNames.length; i++) { + TableItem item = new TableItem (table, DWT.NONE); + item.setText (customNames[i]); + item.setChecked (eventsFilter[EVENT_NAMES.length + i]); + } + Button selectAll = new Button (dialog, DWT.PUSH); + selectAll.setText(ControlExample.getResourceString ("Select_All")); + selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); + selectAll.addSelectionListener (new class(table, customNames) SelectionAdapter { + Table tbl; + char[][] cn; + this( Table tbl, char[][] cn ){ this.tbl = tbl; this.cn = cn; } + public void widgetSelected(SelectionEvent e) { + TableItem [] items = tbl.getItems(); + for (int i = 0; i < EVENT_NAMES.length; i++) { + items[i].setChecked(true); + } + for (int i = 0; i < cn.length; i++) { + items[EVENT_NAMES.length + i].setChecked(true); + } + } + }); + Button deselectAll = new Button (dialog, DWT.PUSH); + deselectAll.setText(ControlExample.getResourceString ("Deselect_All")); + deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING)); + deselectAll.addSelectionListener (new class(table, customNames) SelectionAdapter { + Table tbl; + char[][] cn; + this( Table tbl, char[][] cn ){ this.tbl = tbl; this.cn = cn; } + public void widgetSelected(SelectionEvent e) { + TableItem [] items = tbl.getItems(); + for (int i = 0; i < EVENT_NAMES.length; i++) { + items[i].setChecked(false); + } + for (int i = 0; i < cn.length; i++) { + items[EVENT_NAMES.length + i].setChecked(false); + } + } + }); + new Label(dialog, DWT.NONE); /* Filler */ + Button ok = new Button (dialog, DWT.PUSH); + ok.setText(ControlExample.getResourceString ("OK")); + dialog.setDefaultButton(ok); + ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); + ok.addSelectionListener (new class(dialog, table, customNames ) SelectionAdapter { + Shell dlg; + Table tbl; + char[][] cn; + this( Shell dlg, Table tbl, char[][] cn ){ this.tbl = tbl; this.dlg = dlg; this.cn = cn; } + public void widgetSelected(SelectionEvent e) { + TableItem [] items = tbl.getItems(); + for (int i = 0; i < EVENT_NAMES.length; i++) { + eventsFilter[i] = items[i].getChecked(); + } + for (int i = 0; i < cn.length; i++) { + eventsFilter[EVENT_NAMES.length + i] = items[EVENT_NAMES.length + i].getChecked(); + } + dlg.dispose(); + } + }); + dialog.pack (); + dialog.open (); + while (! dialog.isDisposed()) { + if (! display.readAndDispatch()) display.sleep(); + } + } + + /** + * Creates the "Listeners" group. The "Listeners" group + * goes below the "Example" and "Control" groups. + */ + void createListenersGroup () { + listenersGroup = new Group (tabFolderPage, DWT.NONE); + listenersGroup.setLayout (new GridLayout (3, false)); + listenersGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true, 2, 1)); + listenersGroup.setText (ControlExample.getResourceString ("Listeners")); + + /* + * Create the button to access the 'Listeners' dialog. + */ + Button listenersButton = new Button (listenersGroup, DWT.PUSH); + listenersButton.setText (ControlExample.getResourceString ("Select_Listeners")); + listenersButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent e) { + createListenerSelectionDialog (); + recreateExampleWidgets (); + } + }); + + /* + * Create the checkbox to add/remove listeners to/from the example widgets. + */ + Button listenCheckbox = new Button (listenersGroup, DWT.CHECK); + listenCheckbox.setText (ControlExample.getResourceString ("Listen")); + listenCheckbox.addSelectionListener (new class(listenCheckbox) SelectionAdapter { + Button lcb; + this( Button lcb ){ this.lcb = lcb; } + public void widgetSelected(SelectionEvent e) { + logging = lcb.getSelection (); + recreateExampleWidgets (); + } + }); + + /* + * Create the button to clear the text. + */ + Button clearButton = new Button (listenersGroup, DWT.PUSH); + clearButton.setText (ControlExample.getResourceString ("Clear")); + clearButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + clearButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent e) { + eventConsole.setText (""); + } + }); + + /* Initialize the eventsFilter to log all events. */ + int customEventCount = getCustomEventNames ().length; + eventsFilter = new bool [EVENT_NAMES.length + customEventCount]; + for (int i = 0; i < EVENT_NAMES.length + customEventCount; i++) { + eventsFilter [i] = true; + } + + /* Create the event console Text. */ + eventConsole = new Text (listenersGroup, DWT.BORDER | DWT.MULTI | DWT.V_SCROLL | DWT.H_SCROLL); + GridData data = new GridData (GridData.FILL_BOTH); + data.horizontalSpan = 3; + data.heightHint = 80; + eventConsole.setLayoutData (data); + createEventConsolePopup (); + eventConsole.addKeyListener (new class() KeyAdapter { + public void keyPressed (KeyEvent e) { + if ((e.keyCode is 'A' || e.keyCode is 'a') && (e.stateMask & DWT.MOD1) !is 0) { + eventConsole.selectAll (); + e.doit = false; + } + } + }); + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return null; + } + + void createSetGetDialog(int x, int y, char[][] methodNames) { + Shell dialog = new Shell(shell, DWT.DIALOG_TRIM | DWT.RESIZE | DWT.MODELESS); + dialog.setLayout(new GridLayout(2, false)); + dialog.setText(getTabText() ~ " " ~ ControlExample.getResourceString ("Set_Get")); + nameCombo = new Combo(dialog, DWT.READ_ONLY); + nameCombo.setItems(methodNames); + nameCombo.setText(methodNames[0]); + nameCombo.setVisibleItemCount(methodNames.length); + nameCombo.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, false, false)); + nameCombo.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + resetLabels(); + } + }); + returnTypeLabel = new Label(dialog, DWT.NONE); + returnTypeLabel.setLayoutData(new GridData(DWT.FILL, DWT.BEGINNING, false, false)); + setButton = new Button(dialog, DWT.PUSH); + setButton.setLayoutData(new GridData(DWT.FILL, DWT.BEGINNING, false, false)); + setButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + setValue(); + setText.selectAll(); + setText.setFocus(); + } + }); + setText = new Text(dialog, DWT.SINGLE | DWT.BORDER); + setText.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, false, false)); + getButton = new Button(dialog, DWT.PUSH); + getButton.setLayoutData(new GridData(DWT.FILL, DWT.BEGINNING, false, false)); + getButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + getValue(); + } + }); + getText = new Text(dialog, DWT.MULTI | DWT.BORDER | DWT.READ_ONLY | DWT.H_SCROLL | DWT.V_SCROLL); + GridData data = new GridData(DWT.FILL, DWT.FILL, true, true); + data.widthHint = 240; + data.heightHint = 200; + getText.setLayoutData(data); + resetLabels(); + dialog.setDefaultButton(setButton); + dialog.pack(); + dialog.setLocation(x, y); + dialog.open(); + } + + void resetLabels() { + char[] methodRoot = nameCombo.getText(); + returnTypeLabel.setText(parameterInfo(methodRoot)); + setButton.setText(setMethodName(methodRoot)); + getButton.setText("get" ~ methodRoot); + setText.setText(""); + getText.setText(""); + getValue(); + setText.setFocus(); + } + + char[] setMethodName(char[] methodRoot) { + return "set" ~ methodRoot; + } + + char[] parameterInfo(char[] methodRoot) { + char[] methodName = "get" ~ methodRoot; + auto mthi = getMethodInfo( methodName ); + char[] typeNameString = mthi.returnType.toString; +//PORTING_LEFT + +// char[] typeName = null; +// ClassInfo returnType = getReturnType(methodRoot); + bool isArray = false; + TypeInfo ti = mthi.returnType; + + if ( auto tia = cast(TypeInfo_Array) mthi.returnType ) { + ti = tia.value; + isArray = true; + } + if ( auto tia = cast(TypeInfo_Class ) ti ) { + } else if ( auto tia = cast(TypeInfo_Interface ) ti ) { + } else { + } + //char[] typeNameString = typeName; + char[] info; +// int index = typeName.lastIndexOf('.'); +// if (index !is -1 && index+1 < typeName.length()) typeNameString = typeName.substring(index+1); +// char[] info = ControlExample.getResourceString("Info_" + typeNameString + (isArray ? "A" : "")); +// if (isArray) { +// typeNameString += "[]"; +// } +// return ControlExample.getResourceString("Parameter_Info", [typeNameString, info]); + + return Format( ControlExample.getResourceString("Parameter_Info"), typeNameString, info ); + } + + void getValue() { +//PORTING_LEFT +/+ + char[] methodName = "get" + nameCombo.getText(); + getText.setText(""); + Widget[] widgets = getExampleWidgets(); + for (int i = 0; i < widgets.length; i++) { + try { + java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, null); + Object result = method.invoke(widgets[i], null); + if (result is null) { + getText.append("null"); + } else if (result.getClass().isArray()) { + int length = java.lang.reflect.Array.getLength(result); + if (length is 0) { + getText.append(result.getClass().getComponentType() + "[0]"); + } + for (int j = 0; j < length; j++) { + getText.append(java.lang.reflect.Array.get(result,j).toString() + "\n"); + } + } else { + getText.append(result.toString()); + } + } catch (Exception e) { + getText.append(e.toString()); + } + if (i + 1 < widgets.length) { + getText.append("\n\n"); + } + } ++/ + } + + private ReflectMethodInfo getMethodInfo( char[] methodName ){ + Widget[] widgets = getExampleWidgets(); + if( widgets.length is 0 ){ + Stdout.formatln( "getWidgets returns null in {}", this.classinfo.name ); + } + if( auto rti = widgets[0].classinfo in reflectTypeInfos ){ + if( auto mthi = methodName in rti.methods ){ + return *mthi; + } + else{ + Stdout.formatln( "method unknown {} in type {} in {}", methodName, widgets[0].classinfo.name, this.classinfo.name ); + } + } + else{ + Stdout.formatln( "type unknown {} in {}", widgets[0].classinfo.name, this.classinfo.name ); + } + } + + TypeInfo getReturnType(char[] methodRoot) { + char[] methodName = "get" ~ methodRoot; + auto mthi = getMethodInfo( methodName ); + return mthi.returnType; + } + + void setValue() { +//PORTING_LEFT +/+ + /* The parameter type must be the same as the get method's return type */ + char[] methodRoot = nameCombo.getText(); + Class returnType = getReturnType(methodRoot); + char[] methodName = setMethodName(methodRoot); + char[] value = setText.getText(); + Widget[] widgets = getExampleWidgets(); + for (int i = 0; i < widgets.length; i++) { + try { + java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, [returnType]); + char[] typeName = returnType.getName(); + Object[] parameter = null; + if (typeName.equals("int")) { + parameter = [new Integer(value)]; + } else if (typeName.equals("long")) { + parameter = [new Long(value)]; + } else if (typeName.equals("char")) { + parameter = [value.length() is 1 ? new Character(value.charAt(0)) : new Character('\0')]; + } else if (typeName.equals("bool")) { + parameter = [new bool(value)]; + } else if (typeName.equals("java.lang.char[]")) { + parameter = [value]; + } else if (typeName.equals("org.eclipse.swt.graphics.Point")) { + char[] xy[] = split(value, ','); + parameter = [new Point((new Integer(xy[0])).intValue(),(new Integer(xy[1])).intValue())]; + } else if (typeName.equals("[I")) { + char[] strings[] = split(value, ','); + int[] ints = new int[strings.length]; + for (int j = 0; j < strings.length; j++) { + ints[j] = (new Integer(strings[j])).intValue(); + } + parameter = [ints]; + } else if (typeName.equals("[Ljava.lang.char[];")) { + parameter = [split(value, ',')]; + } else { + parameter = parameterForType(typeName, value, widgets[i]); + } + method.invoke(widgets[i], parameter); + } catch (Exception e) { + getText.setText(e.toString()); + } + } ++/ +return null; + } + + Object[] parameterForType(char[] typeName, char[] value, Widget widget) { +//PORTING_LEFT +return null; + //return [value]; + } + + void createOrientationGroup () { + /* Create Orientation group*/ + orientationGroup = new Group (controlGroup, DWT.NONE); + orientationGroup.setLayout (new GridLayout()); + orientationGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); + orientationGroup.setText (ControlExample.getResourceString("Orientation")); + defaultOrietationButton = new Button (orientationGroup, DWT.RADIO); + defaultOrietationButton.setText (ControlExample.getResourceString("Default")); + defaultOrietationButton.setSelection (true); + ltrButton = new Button (orientationGroup, DWT.RADIO); + ltrButton.setText ("DWT.LEFT_TO_RIGHT"); + rtlButton = new Button (orientationGroup, DWT.RADIO); + rtlButton.setText ("DWT.RIGHT_TO_LEFT"); + } + + /** + * Creates the "Size" group. The "Size" group contains + * controls that allow the user to change the size of + * the example widgets. + */ + void createSizeGroup () { + /* Create the group */ + sizeGroup = new Group (controlGroup, DWT.NONE); + sizeGroup.setLayout (new GridLayout()); + sizeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); + sizeGroup.setText (ControlExample.getResourceString("Size")); + + /* Create the controls */ + + /* + * The preferred size of a widget is the size returned + * by widget.computeSize (DWT.DEFAULT, DWT.DEFAULT). + * This size is defined on a widget by widget basis. + * Many widgets will attempt to display their contents. + */ + preferredButton = new Button (sizeGroup, DWT.RADIO); + preferredButton.setText (ControlExample.getResourceString("Preferred")); + tooSmallButton = new Button (sizeGroup, DWT.RADIO); + tooSmallButton.setText ( Format( "{} X {}", TOO_SMALL_SIZE, TOO_SMALL_SIZE)); + smallButton = new Button(sizeGroup, DWT.RADIO); + smallButton.setText (Format( "{} X {}", SMALL_SIZE, SMALL_SIZE)); + largeButton = new Button (sizeGroup, DWT.RADIO); + largeButton.setText (Format( "{} X {}", LARGE_SIZE, LARGE_SIZE)); + fillHButton = new Button (sizeGroup, DWT.CHECK); + fillHButton.setText (ControlExample.getResourceString("Fill_X")); + fillVButton = new Button (sizeGroup, DWT.CHECK); + fillVButton.setText (ControlExample.getResourceString("Fill_Y")); + + /* Add the listeners */ + SelectionAdapter selectionListener = new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setExampleWidgetSize (); + } + }; + preferredButton.addSelectionListener(selectionListener); + tooSmallButton.addSelectionListener(selectionListener); + smallButton.addSelectionListener(selectionListener); + largeButton.addSelectionListener(selectionListener); + fillHButton.addSelectionListener(selectionListener); + fillVButton.addSelectionListener(selectionListener); + + /* Set the default state */ + preferredButton.setSelection (true); + } + + /** + * Creates the "Style" group. The "Style" group contains + * controls that allow the user to change the style of + * the example widgets. Changing a widget "Style" causes + * the widget to be destroyed and recreated. + */ + void createStyleGroup () { + styleGroup = new Group (controlGroup, DWT.NONE); + styleGroup.setLayout (new GridLayout ()); + styleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); + styleGroup.setText (ControlExample.getResourceString("Styles")); + } + + /** + * Creates the tab folder page. + * + * @param tabFolder org.eclipse.swt.widgets.TabFolder + * @return the new page for the tab folder + */ + Composite createTabFolderPage (TabFolder tabFolder) { + /* Cache the shell and display. */ + shell = tabFolder.getShell (); + display = shell.getDisplay (); + + /* Create a two column page. */ + tabFolderPage = new Composite (tabFolder, DWT.NONE); + tabFolderPage.setLayout (new GridLayout (2, false)); + + /* Create the "Example" and "Control" groups. */ + createExampleGroup (); + createControlGroup (); + + /* Create the "Listeners" group under the "Control" group. */ + createListenersGroup (); + + /* Create and initialize the example and control widgets. */ + createExampleWidgets (); + hookExampleWidgetListeners (); + createControlWidgets (); + createBackgroundModeGroup (); + setExampleWidgetState (); + + return tabFolderPage; + } + + void setExampleWidgetPopupMenu() { + Control[] controls = getExampleControls(); + for (int i = 0; i < controls.length; i++) { + Control control = controls [i]; + control.addListener(DWT.MenuDetect, new class(control) Listener { + Control ctrl; + this( Control ctrl ){ this.ctrl = ctrl; } + public void handleEvent(Event event) { + Menu menu = ctrl.getMenu(); + if (menu !is null && samplePopup) { + menu.dispose(); + menu = null; + } + if (menu is null && popupMenuButton.getSelection()) { + menu = new Menu(shell, DWT.POP_UP); + MenuItem item = new MenuItem(menu, DWT.PUSH); + item.setText("Sample popup menu item"); + specialPopupMenuItems(menu, event); + ctrl.setMenu(menu); + samplePopup = true; + } + } + }); + } + } + + protected void specialPopupMenuItems(Menu menu, Event event) { + } + + /** + * Disposes the "Example" widgets. + */ + void disposeExampleWidgets () { + Widget [] widgets = getExampleWidgets (); + for (int i=0; i + *******************************************************************************/ +module examples.controlexample.TabFolderTab; + + + +import dwt.DWT; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Group; +import dwt.widgets.Item; +import dwt.widgets.TabFolder; +import dwt.widgets.TabItem; +import dwt.widgets.Text; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import tango.text.convert.Format; + +class TabFolderTab : Tab { + /* Example widgets and groups that contain them */ + TabFolder tabFolder1; + Group tabFolderGroup; + + /* Style widgets added to the "Style" group */ + Button topButton, bottomButton; + + static char[] [] TabItems1; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + if( TabItems1.length is 0 ){ + TabItems1 = [ + ControlExample.getResourceString("TabItem1_0"), + ControlExample.getResourceString("TabItem1_1"), + ControlExample.getResourceString("TabItem1_2")]; + } + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the TabFolder */ + tabFolderGroup = new Group (exampleGroup, DWT.NONE); + tabFolderGroup.setLayout (new GridLayout ()); + tabFolderGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + tabFolderGroup.setText ("TabFolder"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (topButton.getSelection ()) style |= DWT.TOP; + if (bottomButton.getSelection ()) style |= DWT.BOTTOM; + if (borderButton.getSelection ()) style |= DWT.BORDER; + + /* Create the example widgets */ + tabFolder1 = new TabFolder (tabFolderGroup, style); + for (int i = 0; i < TabItems1.length; i++) { + TabItem item = new TabItem(tabFolder1, DWT.NONE); + item.setText(TabItems1[i]); + item.setToolTipText(Format( ControlExample.getResourceString("Tooltip"), TabItems1[i] )); + Text content = new Text(tabFolder1, DWT.WRAP | DWT.MULTI); + content.setText(Format( "{}: {}", ControlExample.getResourceString("TabItem_content"), i)); + item.setControl(content); + } + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup (); + + /* Create the extra widgets */ + topButton = new Button (styleGroup, DWT.RADIO); + topButton.setText ("DWT.TOP"); + topButton.setSelection(true); + bottomButton = new Button (styleGroup, DWT.RADIO); + bottomButton.setText ("DWT.BOTTOM"); + borderButton = new Button (styleGroup, DWT.CHECK); + borderButton.setText ("DWT.BORDER"); + } + + /** + * Gets the "Example" widget children's items, if any. + * + * @return an array containing the example widget children's items + */ + Item [] getExampleWidgetItems () { + return tabFolder1.getItems(); + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [cast(Widget) tabFolder1 ]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Selection", "SelectionIndex"]; + } + + char[] setMethodName(char[] methodRoot) { + /* Override to handle special case of int getSelectionIndex()/setSelection(int) */ + return (methodRoot == "SelectionIndex") ? "setSelection" : "set" ~ methodRoot; + } + +//PROTING_LEFT +/+ + Object[] parameterForType(char[] typeName, char[] value, Widget widget) { + if (value.length is 0 ) return new Object[] {new TabItem[0]}; + if (typeName.equals("org.eclipse.swt.widgets.TabItem")) { + TabItem item = findItem(value, ((TabFolder) widget).getItems()); + if (item !is null) return new Object[] {item}; + } + if (typeName.equals("[Lorg.eclipse.swt.widgets.TabItem;")) { + char[][] values = split(value, ','); + TabItem[] items = new TabItem[values.length]; + for (int i = 0; i < values.length; i++) { + items[i] = findItem(values[i], ((TabFolder) widget).getItems()); + } + return new Object[] {items}; + } + return super.parameterForType(typeName, value, widget); + } ++/ + TabItem findItem(char[] value, TabItem[] items) { + for (int i = 0; i < items.length; i++) { + TabItem item = items[i]; + if (item.getText() ==/*eq*/ value) return item; + } + return null; + } + + /** + * Gets the short text for the tab folder item. + */ + public char[] getShortTabText() { + return "TF"; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "TabFolder"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + topButton.setSelection ((tabFolder1.getStyle () & DWT.TOP) !is 0); + bottomButton.setSelection ((tabFolder1.getStyle () & DWT.BOTTOM) !is 0); + borderButton.setSelection ((tabFolder1.getStyle () & DWT.BORDER) !is 0); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/TableTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/TableTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,721 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.TableTab; + + + +import dwt.DWT; +import dwt.events.DisposeEvent; +import dwt.events.DisposeListener; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.SelectionListener; +import dwt.graphics.Color; +import dwt.graphics.Font; +import dwt.graphics.FontData; +import dwt.graphics.Image; +import dwt.graphics.Point; +import dwt.graphics.RGB; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Event; +import dwt.widgets.Group; +import dwt.widgets.Item; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.Table; +import dwt.widgets.TableColumn; +import dwt.widgets.TableItem; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import examples.controlexample.ScrollableTab; + +import dwt.dwthelper.utils; + +import tango.text.convert.Format; +import tango.util.Convert; +import tango.core.Exception; + +class TableTab : ScrollableTab { + /* Example widgets and groups that contain them */ + Table table1; + Group tableGroup; + + /* Size widgets added to the "Size" group */ + Button packColumnsButton; + + /* Style widgets added to the "Style" group */ + Button checkButton, fullSelectionButton, hideSelectionButton; + + /* Other widgets added to the "Other" group */ + Button multipleColumns, moveableColumns, resizableColumns, headerVisibleButton, sortIndicatorButton, headerImagesButton, linesVisibleButton, subImagesButton; + + /* Controls and resources added to the "Colors and Fonts" group */ + static const int ITEM_FOREGROUND_COLOR = 3; + static const int ITEM_BACKGROUND_COLOR = 4; + static const int ITEM_FONT = 5; + static const int CELL_FOREGROUND_COLOR = 6; + static const int CELL_BACKGROUND_COLOR = 7; + static const int CELL_FONT = 8; + Color itemForegroundColor, itemBackgroundColor, cellForegroundColor, cellBackgroundColor; + Font itemFont, cellFont; + + static char[] [] columnTitles; + static char[][][] tableData; + + Point menuMouseCoords; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + if( columnTitles.length is 0 ){ + columnTitles = [ + ControlExample.getResourceString("TableTitle_0"), + ControlExample.getResourceString("TableTitle_1"), + ControlExample.getResourceString("TableTitle_2"), + ControlExample.getResourceString("TableTitle_3")]; + } + if( tableData.length is 0 ){ + tableData = [ + [ ControlExample.getResourceString("TableLine0_0"), + ControlExample.getResourceString("TableLine0_1"), + ControlExample.getResourceString("TableLine0_2"), + ControlExample.getResourceString("TableLine0_3") ], + [ ControlExample.getResourceString("TableLine1_0"), + ControlExample.getResourceString("TableLine1_1"), + ControlExample.getResourceString("TableLine1_2"), + ControlExample.getResourceString("TableLine1_3") ], + [ ControlExample.getResourceString("TableLine2_0"), + ControlExample.getResourceString("TableLine2_1"), + ControlExample.getResourceString("TableLine2_2"), + ControlExample.getResourceString("TableLine2_3") ]]; + } + } + + /** + * Creates the "Colors and Fonts" group. + */ + void createColorAndFontGroup () { + super.createColorAndFontGroup(); + + TableItem item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Item_Foreground_Color")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Item_Background_Color")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Item_Font")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Cell_Foreground_Color")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Cell_Background_Color")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Cell_Font")); + + shell.addDisposeListener(new class() DisposeListener { + public void widgetDisposed(DisposeEvent event) { + if (itemBackgroundColor !is null) itemBackgroundColor.dispose(); + if (itemForegroundColor !is null) itemForegroundColor.dispose(); + if (itemFont !is null) itemFont.dispose(); + if (cellBackgroundColor !is null) cellBackgroundColor.dispose(); + if (cellForegroundColor !is null) cellForegroundColor.dispose(); + if (cellFont !is null) cellFont.dispose(); + itemBackgroundColor = null; + itemForegroundColor = null; + itemFont = null; + cellBackgroundColor = null; + cellForegroundColor = null; + cellFont = null; + } + }); + } + + void changeFontOrColor(int index) { + switch (index) { + case ITEM_FOREGROUND_COLOR: { + Color oldColor = itemForegroundColor; + if (oldColor is null) oldColor = table1.getItem (0).getForeground (); + colorDialog.setRGB(oldColor.getRGB()); + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = itemForegroundColor; + itemForegroundColor = new Color (display, rgb); + setItemForeground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case ITEM_BACKGROUND_COLOR: { + Color oldColor = itemBackgroundColor; + if (oldColor is null) oldColor = table1.getItem (0).getBackground (); + colorDialog.setRGB(oldColor.getRGB()); + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = itemBackgroundColor; + itemBackgroundColor = new Color (display, rgb); + setItemBackground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case ITEM_FONT: { + Font oldFont = itemFont; + if (oldFont is null) oldFont = table1.getItem (0).getFont (); + fontDialog.setFontList(oldFont.getFontData()); + FontData fontData = fontDialog.open (); + if (fontData is null) return; + oldFont = itemFont; + itemFont = new Font (display, fontData); + setItemFont (); + setExampleWidgetSize (); + if (oldFont !is null) oldFont.dispose (); + } + break; + case CELL_FOREGROUND_COLOR: { + Color oldColor = cellForegroundColor; + if (oldColor is null) oldColor = table1.getItem (0).getForeground (1); + colorDialog.setRGB(oldColor.getRGB()); + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = cellForegroundColor; + cellForegroundColor = new Color (display, rgb); + setCellForeground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case CELL_BACKGROUND_COLOR: { + Color oldColor = cellBackgroundColor; + if (oldColor is null) oldColor = table1.getItem (0).getBackground (1); + colorDialog.setRGB(oldColor.getRGB()); + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = cellBackgroundColor; + cellBackgroundColor = new Color (display, rgb); + setCellBackground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case CELL_FONT: { + Font oldFont = cellFont; + if (oldFont is null) oldFont = table1.getItem (0).getFont (1); + fontDialog.setFontList(oldFont.getFontData()); + FontData fontData = fontDialog.open (); + if (fontData is null) return; + oldFont = cellFont; + cellFont = new Font (display, fontData); + setCellFont (); + setExampleWidgetSize (); + if (oldFont !is null) oldFont.dispose (); + } + break; + default: + super.changeFontOrColor(index); + } + } + + /** + * Creates the "Other" group. + */ + void createOtherGroup () { + super.createOtherGroup (); + + /* Create display controls specific to this example */ + linesVisibleButton = new Button (otherGroup, DWT.CHECK); + linesVisibleButton.setText (ControlExample.getResourceString("Lines_Visible")); + multipleColumns = new Button (otherGroup, DWT.CHECK); + multipleColumns.setText (ControlExample.getResourceString("Multiple_Columns")); + multipleColumns.setSelection(true); + headerVisibleButton = new Button (otherGroup, DWT.CHECK); + headerVisibleButton.setText (ControlExample.getResourceString("Header_Visible")); + sortIndicatorButton = new Button (otherGroup, DWT.CHECK); + sortIndicatorButton.setText (ControlExample.getResourceString("Sort_Indicator")); + moveableColumns = new Button (otherGroup, DWT.CHECK); + moveableColumns.setText (ControlExample.getResourceString("Moveable_Columns")); + resizableColumns = new Button (otherGroup, DWT.CHECK); + resizableColumns.setText (ControlExample.getResourceString("Resizable_Columns")); + headerImagesButton = new Button (otherGroup, DWT.CHECK); + headerImagesButton.setText (ControlExample.getResourceString("Header_Images")); + subImagesButton = new Button (otherGroup, DWT.CHECK); + subImagesButton.setText (ControlExample.getResourceString("Sub_Images")); + + /* Add the listeners */ + linesVisibleButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetLinesVisible (); + } + }); + multipleColumns.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + recreateExampleWidgets (); + } + }); + headerVisibleButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetHeaderVisible (); + } + }); + sortIndicatorButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetSortIndicator (); + } + }); + moveableColumns.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setColumnsMoveable (); + } + }); + resizableColumns.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setColumnsResizable (); + } + }); + headerImagesButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + recreateExampleWidgets (); + } + }); + subImagesButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + recreateExampleWidgets (); + } + }); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the table */ + tableGroup = new Group (exampleGroup, DWT.NONE); + tableGroup.setLayout (new GridLayout ()); + tableGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + tableGroup.setText ("Table"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + /* Compute the widget style */ + int style = getDefaultStyle(); + if (singleButton.getSelection ()) style |= DWT.SINGLE; + if (multiButton.getSelection ()) style |= DWT.MULTI; + if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; + if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; + if (checkButton.getSelection ()) style |= DWT.CHECK; + if (fullSelectionButton.getSelection ()) style |= DWT.FULL_SELECTION; + if (hideSelectionButton.getSelection ()) style |= DWT.HIDE_SELECTION; + if (borderButton.getSelection ()) style |= DWT.BORDER; + + /* Create the table widget */ + table1 = new Table (tableGroup, style); + + /* Fill the table with data */ + bool multiColumn = multipleColumns.getSelection(); + if (multiColumn) { + for (int i = 0; i < columnTitles.length; i++) { + TableColumn tableColumn = new TableColumn(table1, DWT.NONE); + tableColumn.setText(columnTitles[i]); + tableColumn.setToolTipText( Format( ControlExample.getResourceString("Tooltip"), columnTitles[i] )); + if (headerImagesButton.getSelection()) tableColumn.setImage(instance.images [i % 3]); + } + table1.setSortColumn(table1.getColumn(0)); + } + for (int i=0; i<16; i++) { + TableItem item = new TableItem (table1, DWT.NONE); + if (multiColumn && subImagesButton.getSelection()) { + for (int j = 0; j < columnTitles.length; j++) { + item.setImage(j, instance.images [i % 3]); + } + } else { + item.setImage(instance.images [i % 3]); + } + setItemText (item, i, ControlExample.getResourceString("Index") ~ to!(char[])(i)); + } + packColumns(); + } + + void setItemText(TableItem item, int i, char[] node) { + int index = i % 3; + if (multipleColumns.getSelection()) { + tableData [index][0] = node; + item.setText (tableData [index]); + } else { + item.setText (node); + } + } + + /** + * Creates the "Size" group. The "Size" group contains + * controls that allow the user to change the size of + * the example widgets. + */ + void createSizeGroup () { + super.createSizeGroup(); + + packColumnsButton = new Button (sizeGroup, DWT.PUSH); + packColumnsButton.setText (ControlExample.getResourceString("Pack_Columns")); + packColumnsButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + packColumns (); + setExampleWidgetSize (); + } + }); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup () { + super.createStyleGroup (); + + /* Create the extra widgets */ + checkButton = new Button (styleGroup, DWT.CHECK); + checkButton.setText ("DWT.CHECK"); + fullSelectionButton = new Button (styleGroup, DWT.CHECK); + fullSelectionButton.setText ("DWT.FULL_SELECTION"); + hideSelectionButton = new Button (styleGroup, DWT.CHECK); + hideSelectionButton.setText ("DWT.HIDE_SELECTION"); + } + + /** + * Gets the "Example" widget children's items, if any. + * + * @return an array containing the example widget children's items + */ + Item [] getExampleWidgetItems () { + Item [] columns = table1.getColumns(); + Item [] items = table1.getItems(); + Item [] allItems = new Item [columns.length + items.length]; + System.arraycopy(columns, 0, allItems, 0, columns.length); + System.arraycopy(items, 0, allItems, columns.length, items.length); + return allItems; + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) table1 ]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["ColumnOrder", "ItemCount", "Selection", "SelectionIndex", "ToolTipText", "TopIndex"]; + } + + char[] setMethodName(char[] methodRoot) { + /* Override to handle special case of int getSelectionIndex()/setSelection(int) */ + return (methodRoot == "SelectionIndex" ) ? "setSelection" : "set" ~ methodRoot; + } + + void packColumns () { + int columnCount = table1.getColumnCount(); + for (int i = 0; i < columnCount; i++) { + TableColumn tableColumn = table1.getColumn(i); + tableColumn.pack(); + } + } + +//PORTING_LEFT +/+ + Object[] parameterForType(char[] typeName, char[] value, Widget widget) { + if (value.length is 0 ) return [new TableItem[0]]; // bug in Table? + if (typeName.equals("org.eclipse.swt.widgets.TableItem")) { + TableItem item = findItem(value, ((Table) widget).getItems()); + if (item !is null) return new Object[] {item}; + } + if (typeName.equals("[Lorg.eclipse.swt.widgets.TableItem;")) { + char[][] values = split(value, ','); + TableItem[] items = new TableItem[values.length]; + for (int i = 0; i < values.length; i++) { + items[i] = findItem(values[i], ((Table) widget).getItems()); + } + return new Object[] {items}; + } + return super.parameterForType(typeName, value, widget); + } ++/ + TableItem findItem(char[] value, TableItem[] items) { + for (int i = 0; i < items.length; i++) { + TableItem item = items[i]; + if (item.getText() == value ) return item; + } + return null; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Table"; + } + + /** + * Sets the foreground color, background color, and font + * of the "Example" widgets to their default settings. + * Also sets foreground and background color of TableItem [0] + * to default settings. + */ + void resetColorsAndFonts () { + super.resetColorsAndFonts (); + Color oldColor = itemForegroundColor; + itemForegroundColor = null; + setItemForeground (); + if (oldColor !is null) oldColor.dispose(); + oldColor = itemBackgroundColor; + itemBackgroundColor = null; + setItemBackground (); + if (oldColor !is null) oldColor.dispose(); + Font oldFont = font; + itemFont = null; + setItemFont (); + if (oldFont !is null) oldFont.dispose(); + oldColor = cellForegroundColor; + cellForegroundColor = null; + setCellForeground (); + if (oldColor !is null) oldColor.dispose(); + oldColor = cellBackgroundColor; + cellBackgroundColor = null; + setCellBackground (); + if (oldColor !is null) oldColor.dispose(); + oldFont = font; + cellFont = null; + setCellFont (); + if (oldFont !is null) oldFont.dispose(); + } + + /** + * Sets the background color of the Row 0 TableItem in column 1. + */ + void setCellBackground () { + if (!instance.startup) { + table1.getItem (0).setBackground (1, cellBackgroundColor); + } + /* Set the background color item's image to match the background color of the cell. */ + Color color = cellBackgroundColor; + if (color is null) color = table1.getItem (0).getBackground (1); + TableItem item = colorAndFontTable.getItem(CELL_BACKGROUND_COLOR); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (colorImage(color)); + } + + /** + * Sets the foreground color of the Row 0 TableItem in column 1. + */ + void setCellForeground () { + if (!instance.startup) { + table1.getItem (0).setForeground (1, cellForegroundColor); + } + /* Set the foreground color item's image to match the foreground color of the cell. */ + Color color = cellForegroundColor; + if (color is null) color = table1.getItem (0).getForeground (1); + TableItem item = colorAndFontTable.getItem(CELL_FOREGROUND_COLOR); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (colorImage(color)); + } + + /** + * Sets the font of the Row 0 TableItem in column 1. + */ + void setCellFont () { + if (!instance.startup) { + table1.getItem (0).setFont (1, cellFont); + } + /* Set the font item's image to match the font of the item. */ + Font ft = cellFont; + if (ft is null) ft = table1.getItem (0).getFont (1); + TableItem item = colorAndFontTable.getItem(CELL_FONT); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (fontImage(ft)); + item.setFont(ft); + colorAndFontTable.layout (); + } + + /** + * Sets the background color of TableItem [0]. + */ + void setItemBackground () { + if (!instance.startup) { + table1.getItem (0).setBackground (itemBackgroundColor); + } + /* Set the background color item's image to match the background color of the item. */ + Color color = itemBackgroundColor; + if (color is null) color = table1.getItem (0).getBackground (); + TableItem item = colorAndFontTable.getItem(ITEM_BACKGROUND_COLOR); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (colorImage(color)); + } + + /** + * Sets the foreground color of TableItem [0]. + */ + void setItemForeground () { + if (!instance.startup) { + table1.getItem (0).setForeground (itemForegroundColor); + } + /* Set the foreground color item's image to match the foreground color of the item. */ + Color color = itemForegroundColor; + if (color is null) color = table1.getItem (0).getForeground (); + TableItem item = colorAndFontTable.getItem(ITEM_FOREGROUND_COLOR); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (colorImage(color)); + } + + /** + * Sets the font of TableItem 0. + */ + void setItemFont () { + if (!instance.startup) { + table1.getItem (0).setFont (itemFont); + } + /* Set the font item's image to match the font of the item. */ + Font ft = itemFont; + if (ft is null) ft = table1.getItem (0).getFont (); + TableItem item = colorAndFontTable.getItem(ITEM_FONT); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (fontImage(ft)); + item.setFont(ft); + colorAndFontTable.layout (); + } + + /** + * Sets the moveable columns state of the "Example" widgets. + */ + void setColumnsMoveable () { + bool selection = moveableColumns.getSelection(); + TableColumn[] columns = table1.getColumns(); + for (int i = 0; i < columns.length; i++) { + columns[i].setMoveable(selection); + } + } + + /** + * Sets the resizable columns state of the "Example" widgets. + */ + void setColumnsResizable () { + bool selection = resizableColumns.getSelection(); + TableColumn[] columns = table1.getColumns(); + for (int i = 0; i < columns.length; i++) { + columns[i].setResizable(selection); + } + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + setItemBackground (); + setItemForeground (); + setItemFont (); + setCellBackground (); + setCellForeground (); + setCellFont (); + if (!instance.startup) { + setColumnsMoveable (); + setColumnsResizable (); + setWidgetHeaderVisible (); + setWidgetSortIndicator (); + setWidgetLinesVisible (); + } + super.setExampleWidgetState (); + checkButton.setSelection ((table1.getStyle () & DWT.CHECK) !is 0); + fullSelectionButton.setSelection ((table1.getStyle () & DWT.FULL_SELECTION) !is 0); + hideSelectionButton.setSelection ((table1.getStyle () & DWT.HIDE_SELECTION) !is 0); + try { + TableColumn column = table1.getColumn(0); + moveableColumns.setSelection (column.getMoveable()); + resizableColumns.setSelection (column.getResizable()); + } catch (IllegalArgumentException ex) {} + headerVisibleButton.setSelection (table1.getHeaderVisible()); + linesVisibleButton.setSelection (table1.getLinesVisible()); + } + + /** + * Sets the header visible state of the "Example" widgets. + */ + void setWidgetHeaderVisible () { + table1.setHeaderVisible (headerVisibleButton.getSelection ()); + } + + /** + * Sets the sort indicator state of the "Example" widgets. + */ + void setWidgetSortIndicator () { + if (sortIndicatorButton.getSelection ()) { + /* Reset to known state: 'down' on column 0. */ + table1.setSortDirection (DWT.DOWN); + TableColumn [] columns = table1.getColumns(); + for (int i = 0; i < columns.length; i++) { + TableColumn column = columns[i]; + if (i is 0) table1.setSortColumn(column); + SelectionListener listener = new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + int sortDirection = DWT.DOWN; + if (e.widget is table1.getSortColumn()) { + /* If the sort column hasn't changed, cycle down -> up -> none. */ + switch (table1.getSortDirection ()) { + case DWT.DOWN: sortDirection = DWT.UP; break; + case DWT.UP: sortDirection = DWT.NONE; break; + } + } else { + table1.setSortColumn(cast(TableColumn)e.widget); + } + table1.setSortDirection (sortDirection); + } + }; + column.addSelectionListener(listener); + column.setData("SortListener", cast(Object)listener); //$NON-NLS-1$ + } + } else { + table1.setSortDirection (DWT.NONE); + TableColumn [] columns = table1.getColumns(); + for (int i = 0; i < columns.length; i++) { + SelectionListener listener = cast(SelectionListener)columns[i].getData("SortListener"); //$NON-NLS-1$ + if (listener !is null) columns[i].removeSelectionListener(listener); + } + } + } + + /** + * Sets the lines visible state of the "Example" widgets. + */ + void setWidgetLinesVisible () { + table1.setLinesVisible (linesVisibleButton.getSelection ()); + } + + protected void specialPopupMenuItems(Menu menu, Event event) { + MenuItem item = new MenuItem(menu, DWT.PUSH); + item.setText("getItem(Point) on mouse coordinates"); + menuMouseCoords = table1.toControl(new Point(event.x, event.y)); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + eventConsole.append ("getItem(Point(" ~ menuMouseCoords.toString() ~ ")) returned: " ~ ((table1.getItem(menuMouseCoords))).toString); + eventConsole.append ("\n"); + }; + }); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/TextTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/TextTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.TextTab; + + + +import dwt.DWT; +import dwt.events.ControlAdapter; +import dwt.events.ControlEvent; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Composite; +import dwt.widgets.Group; +import dwt.widgets.TabFolder; +import dwt.widgets.Text; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import examples.controlexample.ScrollableTab; + +class TextTab : ScrollableTab { + /* Example widgets and groups that contain them */ + Text text; + Group textGroup; + + /* Style widgets added to the "Style" group */ + Button wrapButton, readOnlyButton, passwordButton, searchButton, cancelButton; + Button leftButton, centerButton, rightButton; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the text widget */ + textGroup = new Group (exampleGroup, DWT.NONE); + textGroup.setLayout (new GridLayout ()); + textGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + textGroup.setText ("Text"); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (singleButton.getSelection ()) style |= DWT.SINGLE; + if (multiButton.getSelection ()) style |= DWT.MULTI; + if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; + if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; + if (wrapButton.getSelection ()) style |= DWT.WRAP; + if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY; + if (passwordButton.getSelection ()) style |= DWT.PASSWORD; + if (searchButton.getSelection ()) style |= DWT.SEARCH; + if (cancelButton.getSelection ()) style |= DWT.CANCEL; + if (borderButton.getSelection ()) style |= DWT.BORDER; + if (leftButton.getSelection ()) style |= DWT.LEFT; + if (centerButton.getSelection ()) style |= DWT.CENTER; + if (rightButton.getSelection ()) style |= DWT.RIGHT; + + /* Create the example widgets */ + text = new Text (textGroup, style); + text.setText (ControlExample.getResourceString("Example_string") ~ Text.DELIMITER ~ ControlExample.getResourceString("One_Two_Three")); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup(); + + /* Create the extra widgets */ + wrapButton = new Button (styleGroup, DWT.CHECK); + wrapButton.setText ("DWT.WRAP"); + readOnlyButton = new Button (styleGroup, DWT.CHECK); + readOnlyButton.setText ("DWT.READ_ONLY"); + passwordButton = new Button (styleGroup, DWT.CHECK); + passwordButton.setText ("DWT.PASSWORD"); + searchButton = new Button (styleGroup, DWT.CHECK); + searchButton.setText ("DWT.SEARCH"); + cancelButton = new Button (styleGroup, DWT.CHECK); + cancelButton.setText ("DWT.CANCEL"); + + Composite alignmentGroup = new Composite (styleGroup, DWT.NONE); + GridLayout layout = new GridLayout (); + layout.marginWidth = layout.marginHeight = 0; + alignmentGroup.setLayout (layout); + alignmentGroup.setLayoutData (new GridData (GridData.FILL_BOTH)); + leftButton = new Button (alignmentGroup, DWT.RADIO); + leftButton.setText ("DWT.LEFT"); + centerButton = new Button (alignmentGroup, DWT.RADIO); + centerButton.setText ("DWT.CENTER"); + rightButton = new Button (alignmentGroup, DWT.RADIO); + rightButton.setText ("DWT.RIGHT"); + } + + /** + * Creates the tab folder page. + * + * @param tabFolder org.eclipse.swt.widgets.TabFolder + * @return the new page for the tab folder + */ + Composite createTabFolderPage (TabFolder tabFolder) { + super.createTabFolderPage (tabFolder); + + /* + * Add a resize listener to the tabFolderPage so that + * if the user types into the example widget to change + * its preferred size, and then resizes the shell, we + * recalculate the preferred size correctly. + */ + tabFolderPage.addControlListener(new class() ControlAdapter { + public void controlResized(ControlEvent e) { + setExampleWidgetSize (); + } + }); + + return tabFolderPage; + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) text]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["DoubleClickEnabled", "EchoChar", "Editable", "Orientation", "Selection", "Tabs", "Text", "TextLimit", "ToolTipText", "TopIndex"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Text"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + wrapButton.setSelection ((text.getStyle () & DWT.WRAP) !is 0); + readOnlyButton.setSelection ((text.getStyle () & DWT.READ_ONLY) !is 0); + passwordButton.setSelection ((text.getStyle () & DWT.PASSWORD) !is 0); + searchButton.setSelection ((text.getStyle () & DWT.SEARCH) !is 0); + leftButton.setSelection ((text.getStyle () & DWT.LEFT) !is 0); + centerButton.setSelection ((text.getStyle () & DWT.CENTER) !is 0); + rightButton.setSelection ((text.getStyle () & DWT.RIGHT) !is 0); + + /* Special case: CANCEL and H_SCROLL have the same value, + * so to avoid confusion, only set CANCEL if SEARCH is set. */ + if ((text.getStyle () & DWT.SEARCH) !is 0) { + cancelButton.setSelection ((text.getStyle () & DWT.CANCEL) !is 0); + horizontalButton.setSelection (false); + } else { + cancelButton.setSelection (false); + horizontalButton.setSelection ((text.getStyle () & DWT.H_SCROLL) !is 0); + } + + passwordButton.setEnabled ((text.getStyle () & DWT.SINGLE) !is 0); + searchButton.setEnabled ((text.getStyle () & DWT.SINGLE) !is 0); + cancelButton.setEnabled ((text.getStyle () & DWT.SEARCH) !is 0); + wrapButton.setEnabled ((text.getStyle () & DWT.MULTI) !is 0); + horizontalButton.setEnabled ((text.getStyle () & DWT.MULTI) !is 0); + verticalButton.setEnabled ((text.getStyle () & DWT.MULTI) !is 0); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/ToolBarTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/ToolBarTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,400 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.ToolBarTab; + + + +import dwt.DWT; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Combo; +import dwt.widgets.Group; +import dwt.widgets.Item; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +import dwt.dwthelper.utils; + +import tango.util.Convert; + +class ToolBarTab : Tab { + /* Example widgets and groups that contain them */ + ToolBar imageToolBar, textToolBar, imageTextToolBar; + Group imageToolBarGroup, textToolBarGroup, imageTextToolBarGroup; + + /* Style widgets added to the "Style" group */ + Button horizontalButton, verticalButton, flatButton, shadowOutButton, wrapButton, rightButton; + + /* Other widgets added to the "Other" group */ + Button comboChildButton; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the image tool bar */ + imageToolBarGroup = new Group (exampleGroup, DWT.NONE); + imageToolBarGroup.setLayout (new GridLayout ()); + imageToolBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + imageToolBarGroup.setText (ControlExample.getResourceString("Image_ToolBar")); + + /* Create a group for the text tool bar */ + textToolBarGroup = new Group (exampleGroup, DWT.NONE); + textToolBarGroup.setLayout (new GridLayout ()); + textToolBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + textToolBarGroup.setText (ControlExample.getResourceString("Text_ToolBar")); + + /* Create a group for the image and text tool bar */ + imageTextToolBarGroup = new Group (exampleGroup, DWT.NONE); + imageTextToolBarGroup.setLayout (new GridLayout ()); + imageTextToolBarGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + imageTextToolBarGroup.setText (ControlExample.getResourceString("ImageText_ToolBar")); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (horizontalButton.getSelection()) style |= DWT.HORIZONTAL; + if (verticalButton.getSelection()) style |= DWT.VERTICAL; + if (flatButton.getSelection()) style |= DWT.FLAT; + if (wrapButton.getSelection()) style |= DWT.WRAP; + if (borderButton.getSelection()) style |= DWT.BORDER; + if (shadowOutButton.getSelection()) style |= DWT.SHADOW_OUT; + if (rightButton.getSelection()) style |= DWT.RIGHT; + + /* + * Create the example widgets. + * + * A tool bar must consist of all image tool + * items or all text tool items but not both. + */ + + /* Create the image tool bar */ + imageToolBar = new ToolBar (imageToolBarGroup, style); + ToolItem item = new ToolItem (imageToolBar, DWT.PUSH); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setToolTipText("DWT.PUSH"); + item = new ToolItem (imageToolBar, DWT.PUSH); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setToolTipText ("DWT.PUSH"); + item = new ToolItem (imageToolBar, DWT.RADIO); + item.setImage (instance.images[ControlExample.ciOpenFolder]); + item.setToolTipText ("DWT.RADIO"); + item = new ToolItem (imageToolBar, DWT.RADIO); + item.setImage (instance.images[ControlExample.ciOpenFolder]); + item.setToolTipText ("DWT.RADIO"); + item = new ToolItem (imageToolBar, DWT.CHECK); + item.setImage (instance.images[ControlExample.ciTarget]); + item.setToolTipText ("DWT.CHECK"); + item = new ToolItem (imageToolBar, DWT.RADIO); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setToolTipText ("DWT.RADIO"); + item = new ToolItem (imageToolBar, DWT.RADIO); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setToolTipText ("DWT.RADIO"); + item = new ToolItem (imageToolBar, DWT.SEPARATOR); + item.setToolTipText("DWT.SEPARATOR"); + if (comboChildButton.getSelection ()) { + Combo combo = new Combo (imageToolBar, DWT.NONE); + combo.setItems (["250", "500", "750"]); + combo.setText (combo.getItem (0)); + combo.pack (); + item.setWidth (combo.getSize ().x); + item.setControl (combo); + } + item = new ToolItem (imageToolBar, DWT.DROP_DOWN); + item.setImage (instance.images[ControlExample.ciTarget]); + item.setToolTipText ("DWT.DROP_DOWN"); + item.addSelectionListener(new DropDownSelectionListener()); + + /* Create the text tool bar */ + textToolBar = new ToolBar (textToolBarGroup, style); + item = new ToolItem (textToolBar, DWT.PUSH); + item.setText (ControlExample.getResourceString("Push")); + item.setToolTipText("DWT.PUSH"); + item = new ToolItem (textToolBar, DWT.PUSH); + item.setText (ControlExample.getResourceString("Push")); + item.setToolTipText("DWT.PUSH"); + item = new ToolItem (textToolBar, DWT.RADIO); + item.setText (ControlExample.getResourceString("Radio")); + item.setToolTipText("DWT.RADIO"); + item = new ToolItem (textToolBar, DWT.RADIO); + item.setText (ControlExample.getResourceString("Radio")); + item.setToolTipText("DWT.RADIO"); + item = new ToolItem (textToolBar, DWT.CHECK); + item.setText (ControlExample.getResourceString("Check")); + item.setToolTipText("DWT.CHECK"); + item = new ToolItem (textToolBar, DWT.RADIO); + item.setText (ControlExample.getResourceString("Radio")); + item.setToolTipText("DWT.RADIO"); + item = new ToolItem (textToolBar, DWT.RADIO); + item.setText (ControlExample.getResourceString("Radio")); + item.setToolTipText("DWT.RADIO"); + item = new ToolItem (textToolBar, DWT.SEPARATOR); + item.setToolTipText("DWT.SEPARATOR"); + if (comboChildButton.getSelection ()) { + Combo combo = new Combo (textToolBar, DWT.NONE); + combo.setItems (["250", "500", "750"]); + combo.setText (combo.getItem (0)); + combo.pack (); + item.setWidth (combo.getSize ().x); + item.setControl (combo); + } + item = new ToolItem (textToolBar, DWT.DROP_DOWN); + item.setText (ControlExample.getResourceString("Drop_Down")); + item.setToolTipText("DWT.DROP_DOWN"); + item.addSelectionListener(new DropDownSelectionListener()); + + /* Create the image and text tool bar */ + imageTextToolBar = new ToolBar (imageTextToolBarGroup, style); + item = new ToolItem (imageTextToolBar, DWT.PUSH); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setText (ControlExample.getResourceString("Push")); + item.setToolTipText("DWT.PUSH"); + item = new ToolItem (imageTextToolBar, DWT.PUSH); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setText (ControlExample.getResourceString("Push")); + item.setToolTipText("DWT.PUSH"); + item = new ToolItem (imageTextToolBar, DWT.RADIO); + item.setImage (instance.images[ControlExample.ciOpenFolder]); + item.setText (ControlExample.getResourceString("Radio")); + item.setToolTipText("DWT.RADIO"); + item = new ToolItem (imageTextToolBar, DWT.RADIO); + item.setImage (instance.images[ControlExample.ciOpenFolder]); + item.setText (ControlExample.getResourceString("Radio")); + item.setToolTipText("DWT.RADIO"); + item = new ToolItem (imageTextToolBar, DWT.CHECK); + item.setImage (instance.images[ControlExample.ciTarget]); + item.setText (ControlExample.getResourceString("Check")); + item.setToolTipText("DWT.CHECK"); + item = new ToolItem (imageTextToolBar, DWT.RADIO); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setText (ControlExample.getResourceString("Radio")); + item.setToolTipText("DWT.RADIO"); + item = new ToolItem (imageTextToolBar, DWT.RADIO); + item.setImage (instance.images[ControlExample.ciClosedFolder]); + item.setText (ControlExample.getResourceString("Radio")); + item.setToolTipText("DWT.RADIO"); + item = new ToolItem (imageTextToolBar, DWT.SEPARATOR); + item.setToolTipText("DWT.SEPARATOR"); + if (comboChildButton.getSelection ()) { + Combo combo = new Combo (imageTextToolBar, DWT.NONE); + combo.setItems (["250", "500", "750"]); + combo.setText (combo.getItem (0)); + combo.pack (); + item.setWidth (combo.getSize ().x); + item.setControl (combo); + } + item = new ToolItem (imageTextToolBar, DWT.DROP_DOWN); + item.setImage (instance.images[ControlExample.ciTarget]); + item.setText (ControlExample.getResourceString("Drop_Down")); + item.setToolTipText("DWT.DROP_DOWN"); + item.addSelectionListener(new DropDownSelectionListener()); + + /* + * Do not add the selection event for this drop down + * tool item. Without hooking the event, the drop down + * widget does nothing special when the drop down area + * is selected. + */ + } + + /** + * Creates the "Other" group. + */ + void createOtherGroup () { + super.createOtherGroup (); + + /* Create display controls specific to this example */ + comboChildButton = new Button (otherGroup, DWT.CHECK); + comboChildButton.setText (ControlExample.getResourceString("Combo_child")); + + /* Add the listeners */ + comboChildButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + recreateExampleWidgets (); + } + }); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup(); + + /* Create the extra widgets */ + horizontalButton = new Button (styleGroup, DWT.RADIO); + horizontalButton.setText ("DWT.HORIZONTAL"); + verticalButton = new Button (styleGroup, DWT.RADIO); + verticalButton.setText ("DWT.VERTICAL"); + flatButton = new Button (styleGroup, DWT.CHECK); + flatButton.setText ("DWT.FLAT"); + shadowOutButton = new Button (styleGroup, DWT.CHECK); + shadowOutButton.setText ("DWT.SHADOW_OUT"); + wrapButton = new Button (styleGroup, DWT.CHECK); + wrapButton.setText ("DWT.WRAP"); + rightButton = new Button (styleGroup, DWT.CHECK); + rightButton.setText ("DWT.RIGHT"); + borderButton = new Button (styleGroup, DWT.CHECK); + borderButton.setText ("DWT.BORDER"); + } + + void disposeExampleWidgets () { + super.disposeExampleWidgets (); + } + + /** + * Gets the "Example" widget children's items, if any. + * + * @return an array containing the example widget children's items + */ + Item [] getExampleWidgetItems () { + Item [] imageToolBarItems = imageToolBar.getItems(); + Item [] textToolBarItems = textToolBar.getItems(); + Item [] imageTextToolBarItems = imageTextToolBar.getItems(); + Item [] allItems = new Item [imageToolBarItems.length + textToolBarItems.length + imageTextToolBarItems.length]; + System.arraycopy(imageToolBarItems, 0, allItems, 0, imageToolBarItems.length); + System.arraycopy(textToolBarItems, 0, allItems, imageToolBarItems.length, textToolBarItems.length); + System.arraycopy(imageTextToolBarItems, 0, allItems, imageToolBarItems.length + textToolBarItems.length, imageTextToolBarItems.length); + return allItems; + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) imageToolBar, textToolBar, imageTextToolBar ]; + } + + /** + * Gets the short text for the tab folder item. + */ + public char[] getShortTabText() { + return "TB"; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "ToolBar"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + super.setExampleWidgetState (); + horizontalButton.setSelection ((imageToolBar.getStyle () & DWT.HORIZONTAL) !is 0); + verticalButton.setSelection ((imageToolBar.getStyle () & DWT.VERTICAL) !is 0); + flatButton.setSelection ((imageToolBar.getStyle () & DWT.FLAT) !is 0); + wrapButton.setSelection ((imageToolBar.getStyle () & DWT.WRAP) !is 0); + shadowOutButton.setSelection ((imageToolBar.getStyle () & DWT.SHADOW_OUT) !is 0); + borderButton.setSelection ((imageToolBar.getStyle () & DWT.BORDER) !is 0); + rightButton.setSelection ((imageToolBar.getStyle () & DWT.RIGHT) !is 0); + } + + /** + * Listens to widgetSelected() events on DWT.DROP_DOWN type ToolItems + * and opens/closes a menu when appropriate. + */ + class DropDownSelectionListener : SelectionAdapter { + private Menu menu = null; + private bool visible = false; + + public void widgetSelected(SelectionEvent event) { + // Create the menu if it has not already been created + if (menu is null) { + // Lazy create the menu. + menu = new Menu(shell); + for (int i = 0; i < 9; ++i) { + final char[] text = ControlExample.getResourceString("DropDownData_" ~ to!(char[])(i)); + if (text.length !is 0) { + MenuItem menuItem = new MenuItem(menu, DWT.NONE); + menuItem.setText(text); + /* + * Add a menu selection listener so that the menu is hidden + * when the user selects an item from the drop down menu. + */ + menuItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + setMenuVisible(false); + } + }); + } else { + new MenuItem(menu, DWT.SEPARATOR); + } + } + } + + /** + * A selection event will be fired when a drop down tool + * item is selected in the main area and in the drop + * down arrow. Examine the event detail to determine + * where the widget was selected. + */ + if (event.detail is DWT.ARROW) { + /* + * The drop down arrow was selected. + */ + if (visible) { + // Hide the menu to give the Arrow the appearance of being a toggle button. + setMenuVisible(false); + } else { + // Position the menu below and vertically aligned with the the drop down tool button. + final ToolItem toolItem = cast(ToolItem) event.widget; + final ToolBar toolBar = toolItem.getParent(); + + Rectangle toolItemBounds = toolItem.getBounds(); + Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); + menu.setLocation(point.x, point.y + toolItemBounds.height); + setMenuVisible(true); + } + } else { + /* + * Main area of drop down tool item selected. + * An application would invoke the code to perform the action for the tool item. + */ + } + } + private void setMenuVisible(bool visible) { + menu.setVisible(visible); + this.visible = visible; + } + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/ToolTipTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/ToolTipTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,268 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.ToolTipTab; + + + +import dwt.DWT; +import dwt.events.ControlAdapter; +import dwt.events.ControlEvent; +import dwt.events.DisposeEvent; +import dwt.events.DisposeListener; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Composite; +import dwt.widgets.Group; +import dwt.widgets.TabFolder; +import dwt.widgets.ToolTip; +import dwt.widgets.Tray; +import dwt.widgets.TrayItem; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; + +class ToolTipTab : Tab { + + /* Example widgets and groups that contain them */ + ToolTip toolTip1; + Group toolTipGroup; + + /* Style widgets added to the "Style" group */ + Button balloonButton, iconErrorButton, iconInformationButton, iconWarningButton, noIconButton; + + /* Other widgets added to the "Other" group */ + Button autoHideButton, showInTrayButton; + + Tray tray; + TrayItem trayItem; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the tooltip visibility check box */ + toolTipGroup = new Group (exampleGroup, DWT.NONE); + toolTipGroup.setLayout (new GridLayout ()); + toolTipGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + toolTipGroup.setText ("ToolTip"); + visibleButton = new Button(toolTipGroup, DWT.CHECK); + visibleButton.setText(ControlExample.getResourceString("Visible")); + visibleButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setExampleWidgetVisibility (); + } + }); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + + /* Compute the widget style */ + int style = getDefaultStyle(); + if (balloonButton.getSelection ()) style |= DWT.BALLOON; + if (iconErrorButton.getSelection ()) style |= DWT.ICON_ERROR; + if (iconInformationButton.getSelection ()) style |= DWT.ICON_INFORMATION; + if (iconWarningButton.getSelection ()) style |= DWT.ICON_WARNING; + + /* Create the example widgets */ + toolTip1 = new ToolTip (shell, style); + toolTip1.setText(ControlExample.getResourceString("ToolTip_Title")); + toolTip1.setMessage(ControlExample.getResourceString("Example_string")); + } + + /** + * Creates the tab folder page. + * + * @param tabFolder org.eclipse.swt.widgets.TabFolder + * @return the new page for the tab folder + */ + Composite createTabFolderPage (TabFolder tabFolder) { + super.createTabFolderPage (tabFolder); + + /* + * Add a resize listener to the tabFolderPage so that + * if the user types into the example widget to change + * its preferred size, and then resizes the shell, we + * recalculate the preferred size correctly. + */ + tabFolderPage.addControlListener(new class() ControlAdapter { + public void controlResized(ControlEvent e) { + setExampleWidgetSize (); + } + }); + + return tabFolderPage; + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup () { + super.createStyleGroup (); + + /* Create the extra widgets */ + balloonButton = new Button (styleGroup, DWT.CHECK); + balloonButton.setText ("DWT.BALLOON"); + iconErrorButton = new Button (styleGroup, DWT.RADIO); + iconErrorButton.setText("DWT.ICON_ERROR"); + iconInformationButton = new Button (styleGroup, DWT.RADIO); + iconInformationButton.setText("DWT.ICON_INFORMATION"); + iconWarningButton = new Button (styleGroup, DWT.RADIO); + iconWarningButton.setText("DWT.ICON_WARNING"); + noIconButton = new Button (styleGroup, DWT.RADIO); + noIconButton.setText(ControlExample.getResourceString("No_Icon")); + } + + void createColorAndFontGroup () { + // ToolTip does not need a color and font group. + } + + void createOtherGroup () { + /* Create the group */ + otherGroup = new Group (controlGroup, DWT.NONE); + otherGroup.setLayout (new GridLayout ()); + otherGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); + otherGroup.setText (ControlExample.getResourceString("Other")); + + /* Create the controls */ + autoHideButton = new Button(otherGroup, DWT.CHECK); + autoHideButton.setText(ControlExample.getResourceString("AutoHide")); + showInTrayButton = new Button(otherGroup, DWT.CHECK); + showInTrayButton.setText(ControlExample.getResourceString("Show_In_Tray")); + tray = display.getSystemTray(); + showInTrayButton.setEnabled(tray !is null); + + /* Add the listeners */ + autoHideButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setExampleWidgetAutoHide (); + } + }); + showInTrayButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + showExampleWidgetInTray (); + } + }); + shell.addDisposeListener(new class() DisposeListener { + public void widgetDisposed(DisposeEvent event) { + disposeTrayItem(); + } + }); + + /* Set the default state */ + autoHideButton.setSelection(true); + } + + void createSizeGroup () { + // ToolTip does not need a size group. + } + + /** + * Disposes the "Example" widgets. + */ + void disposeExampleWidgets () { + disposeTrayItem(); + super.disposeExampleWidgets(); + } + + /** + * Gets the "Example" widget children. + */ + // Tab uses this for many things - widgets would only get set/get, listeners, and dispose. + Widget[] getExampleWidgets () { + return [ cast(Widget) toolTip1 ]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["Message", "Text"]; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "ToolTip"; + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + showExampleWidgetInTray (); + setExampleWidgetAutoHide (); + super.setExampleWidgetState (); + balloonButton.setSelection ((toolTip1.getStyle () & DWT.BALLOON) !is 0); + iconErrorButton.setSelection ((toolTip1.getStyle () & DWT.ICON_ERROR) !is 0); + iconInformationButton.setSelection ((toolTip1.getStyle () & DWT.ICON_INFORMATION) !is 0); + iconWarningButton.setSelection ((toolTip1.getStyle () & DWT.ICON_WARNING) !is 0); + noIconButton.setSelection ((toolTip1.getStyle () & (DWT.ICON_ERROR | DWT.ICON_INFORMATION | DWT.ICON_WARNING)) is 0); + autoHideButton.setSelection(toolTip1.getAutoHide()); + } + + /** + * Sets the visibility of the "Example" widgets. + */ + void setExampleWidgetVisibility () { + toolTip1.setVisible (visibleButton.getSelection ()); + } + + /** + * Sets the autoHide state of the "Example" widgets. + */ + void setExampleWidgetAutoHide () { + toolTip1.setAutoHide(autoHideButton.getSelection ()); + } + + void showExampleWidgetInTray () { + if (showInTrayButton.getSelection ()) { + createTrayItem(); + trayItem.setToolTip(toolTip1); + } else { + disposeTrayItem(); + } + } + + void createTrayItem() { + if (trayItem is null) { + trayItem = new TrayItem(tray, DWT.NONE); + trayItem.setImage(instance.images[ControlExample.ciTarget]); + } + } + + void disposeTrayItem() { + if (trayItem !is null) { + trayItem.setToolTip(null); + trayItem.dispose(); + trayItem = null; + } + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/controlexample/TreeTab.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/controlexample/TreeTab.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,826 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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 examples.controlexample.TreeTab; + + + +import dwt.DWT; +import dwt.events.DisposeEvent; +import dwt.events.DisposeListener; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.events.SelectionListener; +import dwt.graphics.Color; +import dwt.graphics.Font; +import dwt.graphics.FontData; +import dwt.graphics.Image; +import dwt.graphics.Point; +import dwt.graphics.RGB; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Button; +import dwt.widgets.Event; +import dwt.widgets.Group; +import dwt.widgets.Item; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.TableItem; +import dwt.widgets.Tree; +import dwt.widgets.TreeColumn; +import dwt.widgets.TreeItem; +import dwt.widgets.Widget; + +import examples.controlexample.Tab; +import examples.controlexample.ControlExample; +import examples.controlexample.ScrollableTab; + +import dwt.dwthelper.utils; + +import tango.text.convert.Format; +import tango.util.Convert; +import tango.core.Exception; + +class TreeTab : ScrollableTab { + /* Example widgets and groups that contain them */ + Tree tree1, tree2; + TreeItem textNode1, imageNode1; + Group treeGroup, imageTreeGroup, itemGroup; + + /* Size widgets added to the "Size" group */ + Button packColumnsButton; + + /* Style widgets added to the "Style" group */ + Button checkButton, fullSelectionButton; + + /* Other widgets added to the "Other" group */ + Button multipleColumns, moveableColumns, resizableColumns, headerVisibleButton, sortIndicatorButton, headerImagesButton, subImagesButton, linesVisibleButton; + + /* Controls and resources added to the "Colors and Fonts" group */ + static const int ITEM_FOREGROUND_COLOR = 3; + static const int ITEM_BACKGROUND_COLOR = 4; + static const int ITEM_FONT = 5; + static const int CELL_FOREGROUND_COLOR = 6; + static const int CELL_BACKGROUND_COLOR = 7; + static const int CELL_FONT = 8; + Color itemForegroundColor, itemBackgroundColor, cellForegroundColor, cellBackgroundColor; + Font itemFont, cellFont; + + static char[] [] columnTitles; + + static char[][][] tableData; + + Point menuMouseCoords; + + /** + * Creates the Tab within a given instance of ControlExample. + */ + this(ControlExample instance) { + super(instance); + if( columnTitles.length is 0 ){ + columnTitles = [ + ControlExample.getResourceString("TableTitle_0"), + ControlExample.getResourceString("TableTitle_1"), + ControlExample.getResourceString("TableTitle_2"), + ControlExample.getResourceString("TableTitle_3")]; + } + if( tableData.length is 0 ){ + tableData = [ + [ ControlExample.getResourceString("TableLine0_0"), + ControlExample.getResourceString("TableLine0_1"), + ControlExample.getResourceString("TableLine0_2"), + ControlExample.getResourceString("TableLine0_3") ], + [ ControlExample.getResourceString("TableLine1_0"), + ControlExample.getResourceString("TableLine1_1"), + ControlExample.getResourceString("TableLine1_2"), + ControlExample.getResourceString("TableLine1_3") ], + [ ControlExample.getResourceString("TableLine2_0"), + ControlExample.getResourceString("TableLine2_1"), + ControlExample.getResourceString("TableLine2_2"), + ControlExample.getResourceString("TableLine2_3") ] ]; + } + } + + /** + * Creates the "Colors and Fonts" group. + */ + void createColorAndFontGroup () { + super.createColorAndFontGroup(); + + TableItem item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Item_Foreground_Color")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Item_Background_Color")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Item_Font")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Cell_Foreground_Color")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Cell_Background_Color")); + item = new TableItem(colorAndFontTable, DWT.None); + item.setText(ControlExample.getResourceString ("Cell_Font")); + + shell.addDisposeListener(new class() DisposeListener { + public void widgetDisposed(DisposeEvent event) { + if (itemBackgroundColor !is null) itemBackgroundColor.dispose(); + if (itemForegroundColor !is null) itemForegroundColor.dispose(); + if (itemFont !is null) itemFont.dispose(); + if (cellBackgroundColor !is null) cellBackgroundColor.dispose(); + if (cellForegroundColor !is null) cellForegroundColor.dispose(); + if (cellFont !is null) cellFont.dispose(); + itemBackgroundColor = null; + itemForegroundColor = null; + itemFont = null; + cellBackgroundColor = null; + cellForegroundColor = null; + cellFont = null; + } + }); + } + + void changeFontOrColor(int index) { + switch (index) { + case ITEM_FOREGROUND_COLOR: { + Color oldColor = itemForegroundColor; + if (oldColor is null) oldColor = textNode1.getForeground (); + colorDialog.setRGB(oldColor.getRGB()); + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = itemForegroundColor; + itemForegroundColor = new Color (display, rgb); + setItemForeground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case ITEM_BACKGROUND_COLOR: { + Color oldColor = itemBackgroundColor; + if (oldColor is null) oldColor = textNode1.getBackground (); + colorDialog.setRGB(oldColor.getRGB()); + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = itemBackgroundColor; + itemBackgroundColor = new Color (display, rgb); + setItemBackground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case ITEM_FONT: { + Font oldFont = itemFont; + if (oldFont is null) oldFont = textNode1.getFont (); + fontDialog.setFontList(oldFont.getFontData()); + FontData fontData = fontDialog.open (); + if (fontData is null) return; + oldFont = itemFont; + itemFont = new Font (display, fontData); + setItemFont (); + setExampleWidgetSize (); + if (oldFont !is null) oldFont.dispose (); + } + break; + case CELL_FOREGROUND_COLOR: { + Color oldColor = cellForegroundColor; + if (oldColor is null) oldColor = textNode1.getForeground (1); + colorDialog.setRGB(oldColor.getRGB()); + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = cellForegroundColor; + cellForegroundColor = new Color (display, rgb); + setCellForeground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case CELL_BACKGROUND_COLOR: { + Color oldColor = cellBackgroundColor; + if (oldColor is null) oldColor = textNode1.getBackground (1); + colorDialog.setRGB(oldColor.getRGB()); + RGB rgb = colorDialog.open(); + if (rgb is null) return; + oldColor = cellBackgroundColor; + cellBackgroundColor = new Color (display, rgb); + setCellBackground (); + if (oldColor !is null) oldColor.dispose (); + } + break; + case CELL_FONT: { + Font oldFont = cellFont; + if (oldFont is null) oldFont = textNode1.getFont (1); + fontDialog.setFontList(oldFont.getFontData()); + FontData fontData = fontDialog.open (); + if (fontData is null) return; + oldFont = cellFont; + cellFont = new Font (display, fontData); + setCellFont (); + setExampleWidgetSize (); + if (oldFont !is null) oldFont.dispose (); + } + break; + default: + super.changeFontOrColor(index); + } + } + + /** + * Creates the "Other" group. + */ + void createOtherGroup () { + super.createOtherGroup (); + + /* Create display controls specific to this example */ + linesVisibleButton = new Button (otherGroup, DWT.CHECK); + linesVisibleButton.setText (ControlExample.getResourceString("Lines_Visible")); + multipleColumns = new Button (otherGroup, DWT.CHECK); + multipleColumns.setText (ControlExample.getResourceString("Multiple_Columns")); + headerVisibleButton = new Button (otherGroup, DWT.CHECK); + headerVisibleButton.setText (ControlExample.getResourceString("Header_Visible")); + sortIndicatorButton = new Button (otherGroup, DWT.CHECK); + sortIndicatorButton.setText (ControlExample.getResourceString("Sort_Indicator")); + moveableColumns = new Button (otherGroup, DWT.CHECK); + moveableColumns.setText (ControlExample.getResourceString("Moveable_Columns")); + resizableColumns = new Button (otherGroup, DWT.CHECK); + resizableColumns.setText (ControlExample.getResourceString("Resizable_Columns")); + headerImagesButton = new Button (otherGroup, DWT.CHECK); + headerImagesButton.setText (ControlExample.getResourceString("Header_Images")); + subImagesButton = new Button (otherGroup, DWT.CHECK); + subImagesButton.setText (ControlExample.getResourceString("Sub_Images")); + + /* Add the listeners */ + linesVisibleButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetLinesVisible (); + } + }); + multipleColumns.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + recreateExampleWidgets (); + } + }); + headerVisibleButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetHeaderVisible (); + } + }); + sortIndicatorButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setWidgetSortIndicator (); + } + }); + moveableColumns.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setColumnsMoveable (); + } + }); + resizableColumns.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + setColumnsResizable (); + } + }); + headerImagesButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + recreateExampleWidgets (); + } + }); + subImagesButton.addSelectionListener (new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + recreateExampleWidgets (); + } + }); + } + + /** + * Creates the "Example" group. + */ + void createExampleGroup () { + super.createExampleGroup (); + + /* Create a group for the text tree */ + treeGroup = new Group (exampleGroup, DWT.NONE); + treeGroup.setLayout (new GridLayout ()); + treeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + treeGroup.setText ("Tree"); + + /* Create a group for the image tree */ + imageTreeGroup = new Group (exampleGroup, DWT.NONE); + imageTreeGroup.setLayout (new GridLayout ()); + imageTreeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); + imageTreeGroup.setText (ControlExample.getResourceString("Tree_With_Images")); + } + + /** + * Creates the "Example" widgets. + */ + void createExampleWidgets () { + /* Compute the widget style */ + int style = getDefaultStyle(); + if (singleButton.getSelection()) style |= DWT.SINGLE; + if (multiButton.getSelection()) style |= DWT.MULTI; + if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; + if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; + if (checkButton.getSelection()) style |= DWT.CHECK; + if (fullSelectionButton.getSelection ()) style |= DWT.FULL_SELECTION; + if (borderButton.getSelection()) style |= DWT.BORDER; + + /* Create the text tree */ + tree1 = new Tree (treeGroup, style); + bool multiColumn = multipleColumns.getSelection(); + if (multiColumn) { + for (int i = 0; i < columnTitles.length; i++) { + TreeColumn treeColumn = new TreeColumn(tree1, DWT.NONE); + treeColumn.setText(columnTitles[i]); + treeColumn.setToolTipText(Format( ControlExample.getResourceString("Tooltip") , columnTitles[i])); + } + tree1.setSortColumn(tree1.getColumn(0)); + } + for (int i = 0; i < 4; i++) { + TreeItem item = new TreeItem (tree1, DWT.NONE); + setItemText(item, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1))); + if (i < 3) { + TreeItem subitem = new TreeItem (item, DWT.NONE); + setItemText(subitem, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1) ~ "_1")); + } + } + TreeItem treeRoots[] = tree1.getItems (); + TreeItem item = new TreeItem (treeRoots[1], DWT.NONE); + setItemText(item, 1, ControlExample.getResourceString("Node_2_2")); + item = new TreeItem (item, DWT.NONE); + setItemText(item, 1, ControlExample.getResourceString("Node_2_2_1")); + textNode1 = treeRoots[0]; + packColumns(tree1); + try { + TreeColumn column = tree1.getColumn(0); + resizableColumns.setSelection (column.getResizable()); + } catch (IllegalArgumentException ex) {} + + /* Create the image tree */ + tree2 = new Tree (imageTreeGroup, style); + Image image = instance.images[ControlExample.ciClosedFolder]; + if (multiColumn) { + for (int i = 0; i < columnTitles.length; i++) { + TreeColumn treeColumn = new TreeColumn(tree2, DWT.NONE); + treeColumn.setText(columnTitles[i]); + treeColumn.setToolTipText(Format( ControlExample.getResourceString("Tooltip"), columnTitles[i])); + if (headerImagesButton.getSelection()) treeColumn.setImage(image); + } + } + for (int i = 0; i < 4; i++) { + item = new TreeItem (tree2, DWT.NONE); + setItemText(item, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1))); + if (multiColumn && subImagesButton.getSelection()) { + for (int j = 0; j < columnTitles.length; j++) { + item.setImage(j, image); + } + } else { + item.setImage(image); + } + if (i < 3) { + TreeItem subitem = new TreeItem (item, DWT.NONE); + setItemText(subitem, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1) ~ "_1")); + if (multiColumn && subImagesButton.getSelection()) { + for (int j = 0; j < columnTitles.length; j++) { + subitem.setImage(j, image); + } + } else { + subitem.setImage(image); + } + } + } + treeRoots = tree2.getItems (); + item = new TreeItem (treeRoots[1], DWT.NONE); + setItemText(item, 1, ControlExample.getResourceString("Node_2_2")); + if (multiColumn && subImagesButton.getSelection()) { + for (int j = 0; j < columnTitles.length; j++) { + item.setImage(j, image); + } + } else { + item.setImage(image); + } + item = new TreeItem (item, DWT.NONE); + setItemText(item, 1, ControlExample.getResourceString("Node_2_2_1")); + if (multiColumn && subImagesButton.getSelection()) { + for (int j = 0; j < columnTitles.length; j++) { + item.setImage(j, image); + } + } else { + item.setImage(image); + } + imageNode1 = treeRoots[0]; + packColumns(tree2); + } + + void setItemText(TreeItem item, int i, char[] node) { + int index = i % 3; + if (multipleColumns.getSelection()) { + tableData [index][0] = node; + item.setText (tableData [index]); + } else { + item.setText (node); + } + } + + /** + * Creates the "Size" group. The "Size" group contains + * controls that allow the user to change the size of + * the example widgets. + */ + void createSizeGroup () { + super.createSizeGroup(); + + packColumnsButton = new Button (sizeGroup, DWT.PUSH); + packColumnsButton.setText (ControlExample.getResourceString("Pack_Columns")); + packColumnsButton.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected (SelectionEvent event) { + packColumns (tree1); + packColumns (tree2); + setExampleWidgetSize (); + } + }); + } + + /** + * Creates the "Style" group. + */ + void createStyleGroup() { + super.createStyleGroup(); + + /* Create the extra widgets */ + checkButton = new Button (styleGroup, DWT.CHECK); + checkButton.setText ("DWT.CHECK"); + fullSelectionButton = new Button (styleGroup, DWT.CHECK); + fullSelectionButton.setText ("DWT.FULL_SELECTION"); + } + + /** + * Gets the "Example" widget children's items, if any. + * + * @return an array containing the example widget children's items + */ + Item [] getExampleWidgetItems () { + /* Note: We do not bother collecting the tree items + * because tree items don't have any events. If events + * are ever added to TreeItem, then this needs to change. + */ + Item [] columns1 = tree1.getColumns(); + Item [] columns2 = tree2.getColumns(); + Item [] allItems = new Item [columns1.length + columns2.length]; + System.arraycopy(columns1, 0, allItems, 0, columns1.length); + System.arraycopy(columns2, 0, allItems, columns1.length, columns2.length); + return allItems; + } + + /** + * Gets the "Example" widget children. + */ + Widget [] getExampleWidgets () { + return [ cast(Widget) tree1, tree2 ]; + } + + /** + * Returns a list of set/get API method names (without the set/get prefix) + * that can be used to set/get values in the example control(s). + */ + char[][] getMethodNames() { + return ["ColumnOrder", "Selection", "ToolTipText", "TopItem"]; + } + +//PORTING_LEFT +/+ + Object[] parameterForType(char[] typeName, char[] value, Widget widget) { + if (typeName.equals("org.eclipse.swt.widgets.TreeItem")) { + TreeItem item = findItem(value, ((Tree) widget).getItems()); + if (item !is null) return new Object[] {item}; + } + if (typeName.equals("[Lorg.eclipse.swt.widgets.TreeItem;")) { + char[][] values = split(value, ','); + TreeItem[] items = new TreeItem[values.length]; + for (int i = 0; i < values.length; i++) { + TreeItem item = findItem(values[i], ((Tree) widget).getItems()); + if (item is null) break; + items[i] = item; + } + return new Object[] {items}; + } + return super.parameterForType(typeName, value, widget); + } ++/ + TreeItem findItem(char[] value, TreeItem[] items) { + for (int i = 0; i < items.length; i++) { + TreeItem item = items[i]; + if (item.getText() == value ) return item; + item = findItem(value, item.getItems()); + if (item !is null) return item; + } + return null; + } + + /** + * Gets the text for the tab folder item. + */ + char[] getTabText () { + return "Tree"; + } + + void packColumns (Tree tree) { + if (multipleColumns.getSelection()) { + int columnCount = tree.getColumnCount(); + for (int i = 0; i < columnCount; i++) { + TreeColumn treeColumn = tree.getColumn(i); + treeColumn.pack(); + } + } + } + + /** + * Sets the moveable columns state of the "Example" widgets. + */ + void setColumnsMoveable () { + bool selection = moveableColumns.getSelection(); + TreeColumn[] columns1 = tree1.getColumns(); + for (int i = 0; i < columns1.length; i++) { + columns1[i].setMoveable(selection); + } + TreeColumn[] columns2 = tree2.getColumns(); + for (int i = 0; i < columns2.length; i++) { + columns2[i].setMoveable(selection); + } + } + + /** + * Sets the resizable columns state of the "Example" widgets. + */ + void setColumnsResizable () { + bool selection = resizableColumns.getSelection(); + TreeColumn[] columns1 = tree1.getColumns(); + for (int i = 0; i < columns1.length; i++) { + columns1[i].setResizable(selection); + } + TreeColumn[] columns2 = tree2.getColumns(); + for (int i = 0; i < columns2.length; i++) { + columns2[i].setResizable(selection); + } + } + + /** + * Sets the foreground color, background color, and font + * of the "Example" widgets to their default settings. + * Also sets foreground and background color of the Node 1 + * TreeItems to default settings. + */ + void resetColorsAndFonts () { + super.resetColorsAndFonts (); + Color oldColor = itemForegroundColor; + itemForegroundColor = null; + setItemForeground (); + if (oldColor !is null) oldColor.dispose(); + oldColor = itemBackgroundColor; + itemBackgroundColor = null; + setItemBackground (); + if (oldColor !is null) oldColor.dispose(); + Font oldFont = font; + itemFont = null; + setItemFont (); + if (oldFont !is null) oldFont.dispose(); + oldColor = cellForegroundColor; + cellForegroundColor = null; + setCellForeground (); + if (oldColor !is null) oldColor.dispose(); + oldColor = cellBackgroundColor; + cellBackgroundColor = null; + setCellBackground (); + if (oldColor !is null) oldColor.dispose(); + oldFont = font; + cellFont = null; + setCellFont (); + if (oldFont !is null) oldFont.dispose(); + } + + /** + * Sets the state of the "Example" widgets. + */ + void setExampleWidgetState () { + setItemBackground (); + setItemForeground (); + setItemFont (); + setCellBackground (); + setCellForeground (); + setCellFont (); + if (!instance.startup) { + setColumnsMoveable (); + setColumnsResizable (); + setWidgetHeaderVisible (); + setWidgetSortIndicator (); + setWidgetLinesVisible (); + } + super.setExampleWidgetState (); + checkButton.setSelection ((tree1.getStyle () & DWT.CHECK) !is 0); + checkButton.setSelection ((tree2.getStyle () & DWT.CHECK) !is 0); + fullSelectionButton.setSelection ((tree1.getStyle () & DWT.FULL_SELECTION) !is 0); + fullSelectionButton.setSelection ((tree2.getStyle () & DWT.FULL_SELECTION) !is 0); + try { + TreeColumn column = tree1.getColumn(0); + moveableColumns.setSelection (column.getMoveable()); + resizableColumns.setSelection (column.getResizable()); + } catch (IllegalArgumentException ex) {} + headerVisibleButton.setSelection (tree1.getHeaderVisible()); + linesVisibleButton.setSelection (tree1.getLinesVisible()); + } + + /** + * Sets the background color of the Node 1 TreeItems in column 1. + */ + void setCellBackground () { + if (!instance.startup) { + textNode1.setBackground (1, cellBackgroundColor); + imageNode1.setBackground (1, cellBackgroundColor); + } + /* Set the background color item's image to match the background color of the cell. */ + Color color = cellBackgroundColor; + if (color is null) color = textNode1.getBackground (1); + TableItem item = colorAndFontTable.getItem(CELL_BACKGROUND_COLOR); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (colorImage(color)); + } + + /** + * Sets the foreground color of the Node 1 TreeItems in column 1. + */ + void setCellForeground () { + if (!instance.startup) { + textNode1.setForeground (1, cellForegroundColor); + imageNode1.setForeground (1, cellForegroundColor); + } + /* Set the foreground color item's image to match the foreground color of the cell. */ + Color color = cellForegroundColor; + if (color is null) color = textNode1.getForeground (1); + TableItem item = colorAndFontTable.getItem(CELL_FOREGROUND_COLOR); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (colorImage(color)); + } + + /** + * Sets the font of the Node 1 TreeItems in column 1. + */ + void setCellFont () { + if (!instance.startup) { + textNode1.setFont (1, cellFont); + imageNode1.setFont (1, cellFont); + } + /* Set the font item's image to match the font of the item. */ + Font ft = cellFont; + if (ft is null) ft = textNode1.getFont (1); + TableItem item = colorAndFontTable.getItem(CELL_FONT); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (fontImage(ft)); + item.setFont(ft); + colorAndFontTable.layout (); + } + + /** + * Sets the background color of the Node 1 TreeItems. + */ + void setItemBackground () { + if (!instance.startup) { + textNode1.setBackground (itemBackgroundColor); + imageNode1.setBackground (itemBackgroundColor); + } + /* Set the background button's color to match the background color of the item. */ + Color color = itemBackgroundColor; + if (color is null) color = textNode1.getBackground (); + TableItem item = colorAndFontTable.getItem(ITEM_BACKGROUND_COLOR); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (colorImage(color)); + } + + /** + * Sets the foreground color of the Node 1 TreeItems. + */ + void setItemForeground () { + if (!instance.startup) { + textNode1.setForeground (itemForegroundColor); + imageNode1.setForeground (itemForegroundColor); + } + /* Set the foreground button's color to match the foreground color of the item. */ + Color color = itemForegroundColor; + if (color is null) color = textNode1.getForeground (); + TableItem item = colorAndFontTable.getItem(ITEM_FOREGROUND_COLOR); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (colorImage(color)); + } + + /** + * Sets the font of the Node 1 TreeItems. + */ + void setItemFont () { + if (!instance.startup) { + textNode1.setFont (itemFont); + imageNode1.setFont (itemFont); + } + /* Set the font item's image to match the font of the item. */ + Font ft = itemFont; + if (ft is null) ft = textNode1.getFont (); + TableItem item = colorAndFontTable.getItem(ITEM_FONT); + Image oldImage = item.getImage(); + if (oldImage !is null) oldImage.dispose(); + item.setImage (fontImage(ft)); + item.setFont(ft); + colorAndFontTable.layout (); + } + + /** + * Sets the header visible state of the "Example" widgets. + */ + void setWidgetHeaderVisible () { + tree1.setHeaderVisible (headerVisibleButton.getSelection ()); + tree2.setHeaderVisible (headerVisibleButton.getSelection ()); + } + + /** + * Sets the sort indicator state of the "Example" widgets. + */ + void setWidgetSortIndicator () { + if (sortIndicatorButton.getSelection ()) { + initializeSortState (tree1); + initializeSortState (tree2); + } else { + resetSortState (tree1); + resetSortState (tree2); + } + } + + /** + * Sets the initial sort indicator state and adds a listener + * to cycle through sort states and columns. + */ + void initializeSortState (Tree tree) { + /* Reset to known state: 'down' on column 0. */ + tree.setSortDirection (DWT.DOWN); + TreeColumn [] columns = tree.getColumns(); + for (int i = 0; i < columns.length; i++) { + TreeColumn column = columns[i]; + if (i is 0) tree.setSortColumn(column); + SelectionListener listener = new class(tree) SelectionAdapter { + Tree t; + this( Tree t ){ this.t = t; } + public void widgetSelected(SelectionEvent e) { + int sortDirection = DWT.DOWN; + if (e.widget is t.getSortColumn()) { + /* If the sort column hasn't changed, cycle down -> up -> none. */ + switch (t.getSortDirection ()) { + case DWT.DOWN: sortDirection = DWT.UP; break; + case DWT.UP: sortDirection = DWT.NONE; break; + } + } else { + t.setSortColumn(cast(TreeColumn)e.widget); + } + t.setSortDirection (sortDirection); + } + }; + column.addSelectionListener(listener); + column.setData("SortListener", cast(Object)listener); //$NON-NLS-1$ + } + } + + void resetSortState (Tree tree) { + tree.setSortDirection (DWT.NONE); + TreeColumn [] columns = tree.getColumns(); + for (int i = 0; i < columns.length; i++) { + SelectionListener listener = cast(SelectionListener)columns[i].getData("SortListener"); //$NON-NLS-1$ + if (listener !is null) columns[i].removeSelectionListener(listener); + } + } + + /** + * Sets the lines visible state of the "Example" widgets. + */ + void setWidgetLinesVisible () { + tree1.setLinesVisible (linesVisibleButton.getSelection ()); + tree2.setLinesVisible (linesVisibleButton.getSelection ()); + } + + protected void specialPopupMenuItems(Menu menu, Event event) { + MenuItem item = new MenuItem(menu, DWT.PUSH); + item.setText("getItem(Point) on mouse coordinates"); + Tree t = cast(Tree) event.widget; + menuMouseCoords = t.toControl(new Point(event.x, event.y)); + item.addSelectionListener(new class(t) SelectionAdapter { + Tree t; + this( Tree t ){ this.t = t; } + public void widgetSelected(SelectionEvent e) { + eventConsole.append ("getItem(Point(" ~ menuMouseCoords.toString ~ ")) returned: " ~ (this.t.getItem(menuMouseCoords)).toString); + eventConsole.append ("\n"); + }; + }); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/dsss.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/dsss.conf Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,27 @@ +[*] +buildflags+=-g -gc +buildflags+=-J$LIB_PREFIX/res -J../res -I.. + +version(Windows) { + # if no console window is wanted/needed use -version=gui + version(gui) { + buildflags+= -L/SUBSYSTEM:windows:5 + } else { + buildflags+= -L/SUBSYSTEM:console:5 + } + buildflags+= -L/rc:dwt +} + +[simple.d] + +[addressbook/AddressBook.d] +[clipboard/ClipboardExample.d] +[controlexample/ControlExample.d] +[controlexample/CustomControlExample.d] +[helloworld/HelloWorld1.d] +[helloworld/HelloWorld2.d] +[helloworld/HelloWorld3.d] +[helloworld/HelloWorld4.d] +[helloworld/HelloWorld5.d] +[texteditor/TextEditor.d] + diff -r 04f122e90b0a -r 4a04b6759f98 examples/helloworld/HelloWorld1.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/helloworld/HelloWorld1.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 + *******************************************************************************/ +module examples.helloworld.HelloWorld1; + + +import dwt.widgets.Display; +import dwt.widgets.Shell; + +/* + * This example demonstrates the minimum amount of code required + * to open an DWT Shell and process the events. + */ +void main(){ + Display display = new Display (); + Shell shell = new Shell (display); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 04f122e90b0a -r 4a04b6759f98 examples/helloworld/HelloWorld2.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/helloworld/HelloWorld2.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 + *******************************************************************************/ +module examples.helloworld.HelloWorld2; + +import dwt.DWT; +import dwt.widgets.Display; +import dwt.widgets.Label; +import dwt.widgets.Shell; + +/* + * This example builds on HelloWorld1 and demonstrates the minimum amount + * of code required to open an DWT Shell with a Label and process the events. + */ + +void main(){ + Display display = new Display (); + Shell shell = new Shell (display); + Label label = new Label (shell, DWT.CENTER); + label.setText ("Hello_world"); + label.setBounds (shell.getClientArea ()); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/helloworld/HelloWorld3.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/helloworld/HelloWorld3.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 + *******************************************************************************/ +module examples.helloworld.HelloWorld3; + +import dwt.DWT; +import dwt.events.ControlAdapter; +import dwt.events.ControlEvent; +import dwt.widgets.Display; +import dwt.widgets.Label; +import dwt.widgets.Shell; + +/* + * This example builds on HelloWorld2 and demonstrates how to resize the + * Label when the Shell resizes using a Listener mechanism. + */ + +void main () { + Display display = new Display (); + final Shell shell = new Shell (display); + final Label label = new Label (shell, DWT.CENTER); + label.setText ("Hello_world"); + label.pack(); + shell.addControlListener(new class() ControlAdapter { + public void controlResized(ControlEvent e) { + label.setBounds (shell.getClientArea ()); + } + }); + shell.pack(); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/helloworld/HelloWorld4.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/helloworld/HelloWorld4.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 + *******************************************************************************/ +module examples.helloworld.HelloWorld4; + +import dwt.DWT; +import dwt.layout.FillLayout; +import dwt.widgets.Display; +import dwt.widgets.Label; +import dwt.widgets.Shell; + +/* + * This example builds on HelloWorld2 and demonstrates how to resize the + * Label when the Shell resizes using a Layout. + */ +void main () { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setLayout(new FillLayout()); + Label label = new Label (shell, DWT.CENTER); + label.setText ("Hello_world"); + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/helloworld/HelloWorld5.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/helloworld/HelloWorld5.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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 + *******************************************************************************/ +module examples.helloworld.HelloWorld5; + + +import dwt.events.DisposeEvent; +import dwt.events.DisposeListener; +import dwt.events.PaintEvent; +import dwt.events.PaintListener; +import dwt.graphics.Color; +import dwt.graphics.GC; +import dwt.graphics.Rectangle; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +/* + * This example builds on HelloWorld1 and demonstrates how to draw directly + * on an DWT Control. + */ + +void main () { + Display display = new Display (); + final Color red = new Color(display, 0xFF, 0, 0); + final Shell shell = new Shell (display); + shell.addPaintListener(new class() PaintListener { + public void paintControl(PaintEvent event){ + GC gc = event.gc; + gc.setForeground(red); + Rectangle rect = shell.getClientArea(); + gc.drawRectangle(rect.x + 10, rect.y + 10, rect.width - 20, rect.height - 20); + gc.drawString("Hello_world", rect.x + 20, rect.y + 20); + } + }); + shell.addDisposeListener (new class() DisposeListener { + public void widgetDisposed (DisposeEvent e) { + red.dispose(); + } + }); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/simple.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/simple.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,48 @@ +module example.simple; + +import dwt.DWT; +import dwt.events.SelectionEvent; +import dwt.events.SelectionListener; +import dwt.widgets.Button; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Text; + +import tango.io.Stdout; + +void main(){ + + try{ + + Display display = new Display(); + Shell shell = new Shell(display); + shell.setSize(300, 200); + shell.setText("Simple DWT Sample"); + auto btn = new Button( shell, DWT.PUSH ); + btn.setBounds(40, 50, 100, 50); + btn.setText( "hey" ); + + auto txt = new Text(shell, DWT.BORDER); + txt.setBounds(170, 50, 100, 40); + + btn.addSelectionListener(new class () SelectionListener { + public void widgetSelected(SelectionEvent event) { + txt.setText("No problem"); + } + public void widgetDefaultSelected(SelectionEvent event) { + txt.setText("No worries!"); + } + }); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + catch (Exception e) { + Stdout.formatln (e.toString); + } +} + diff -r 04f122e90b0a -r 4a04b6759f98 examples/sleak/SleakExample.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/sleak/SleakExample.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. + * This file is made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Port to the D programming language + * Frank Benoit + */ +module examples.sleak.SleakExample; + +import dwt.DWT; +import dwt.graphics.DeviceData; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Canvas; +import dwt.widgets.List; +import dwt.program.Program; +import dwt.graphics.ImageData; +import dwt.graphics.Image; +import dwt.layout.FillLayout; +import dwt.events.PaintListener; +import dwt.events.PaintEvent; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; + +import dwtx.sleak.Sleak; + +import tango.io.Stdout; +version(JIVE){ + import jive.stacktrace; +} + +void main() { + Display display; + Shell shell; + List list; + Canvas canvas; + Image image; + + version( all ){ + DeviceData data = new DeviceData(); + data.tracking = true; + display = new Display(data); + Sleak sleak = new Sleak(); + sleak.open(); + } + else{ + display = new Display(); + } + + shell = new Shell(display); + shell.setLayout(new FillLayout()); + list = new List(shell, DWT.BORDER | DWT.SINGLE | DWT.V_SCROLL | DWT.H_SCROLL); + list.setItems(Program.getExtensions()); + canvas = new Canvas(shell, DWT.BORDER); + canvas.addPaintListener(new class() PaintListener { + public void paintControl(PaintEvent e) { + if (image !is null) { + e.gc.drawImage(image, 0, 0); + } + } + }); + list.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + image = null; // potentially leak one image + char[][] selection = list.getSelection(); + if (selection.length !is 0) { + Program program = Program.findProgram(selection[0]); + if (program !is null) { + ImageData imageData = program.getImageData(); + if (imageData !is null) { + if (image !is null) image.dispose(); + image = new Image(display, imageData); + } + } + } + canvas.redraw(); + } + }); + shell.setSize(shell.computeSize(DWT.DEFAULT, 200)); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/test.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/test.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,44 @@ +module test; + +import dwt.internal.gtk.c.cairo; +import tango.core.Traits; +import tango.io.Stdout; +import tango.stdc.stdio; + +struct lock { +static void lock() { printf("lock\n");} +static void unlock() { printf("unlock\n");} +} + +const static char[] mm = "Inside outer cairo_version"; + +template NameOfFunc(alias f) { + // Note: highly dependent on the .stringof formatting + // the value begins with "& " which is why the first two chars are cut off + const char[] NameOfFunc = (&f).stringof[2 .. $]; +} + +template ForwardGtkOsCFunc( alias cFunc ) { + alias ParameterTupleOf!(cFunc) P; + alias ReturnTypeOf!(cFunc) R; + mixin("public static R " ~ NameOfFunc!(cFunc) ~ "( P p ){ + lock.lock(); + scope(exit) lock.unlock(); + Stdout (mm).newline; + return cFunc(p); + }"); +} + +public class OS { + mixin ForwardGtkOsCFunc!(cairo_version); + mixin ForwardGtkOsCFunc!(cairo_version_string); +} + +void main() +{ + Stdout ("calling cairo_version...").newline; + int p = OS.cairo_version(); + int i = cairo_version(); + Stdout.formatln("OS.cairo_version() returns: {} cairo_version() returns: {}", p, i ).newline; + printf("OS.cairo_version_string returns: %s\n", cairo_version_string() ); +} diff -r 04f122e90b0a -r 4a04b6759f98 examples/texteditor/Images.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/texteditor/Images.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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 + * Port to the D programming language: + * Thomas Graber + *******************************************************************************/ +module examples.texteditor.Images; + +import dwt.dwthelper.InputStream; + +import dwt.graphics.Image; +import dwt.graphics.ImageData; +import dwt.widgets.Display; +import dwt.dwthelper.ByteArrayInputStream; + +import tango.core.Exception; +import tango.io.Stdout; + +public class Images { + + // Bitmap Images + public Image Bold; + public Image Italic; + public Image Underline; + public Image Strikeout; + public Image Red; + public Image Green; + public Image Blue; + public Image Erase; + + Image[] AllBitmaps; + + this () { + } + + public void freeAll () { + for (int i=0; i + *******************************************************************************/ +module examples.texteditor.TextEditor; + +import dwt.DWT; +import dwt.custom.ExtendedModifyEvent; +import dwt.custom.ExtendedModifyListener; +import dwt.custom.StyleRange; +import dwt.custom.StyledText; +import dwt.events.DisposeEvent; +import dwt.events.DisposeListener; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.graphics.Color; +import dwt.graphics.Font; +import dwt.graphics.FontData; +import dwt.graphics.Point; +import dwt.graphics.RGB; +import dwt.layout.GridData; +import dwt.layout.GridLayout; +import dwt.widgets.Display; +import dwt.widgets.FontDialog; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.Shell; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; +import dwt.widgets.Widget; +import dwt.dwthelper.ResourceBundle; +import dwt.dwthelper.utils; + +import tango.util.collection.ArraySeq; + +import examples.texteditor.Images; + +version( JIVE ){ + import jive.stacktrace; +} + +/** + */ +public class TextEditor { + Shell shell; + ToolBar toolBar; + StyledText text; + Images images; + alias ArraySeq!(StyleRange) StyleCache; + StyleCache cachedStyles; + + Color RED = null; + Color BLUE = null; + Color GREEN = null; + Font font = null; + ToolItem boldButton, italicButton, underlineButton, strikeoutButton; + + //string resources + static ResourceBundle resources; + private static const char[] resourceData = import( "dwtexamples.texteditor.examples_texteditor.properties" ); + + /* + * static ctor + */ + static this() + { + resources = ResourceBundle.getBundleFromData( resourceData ); + } + + /* + * ctor + */ + this() { + images = new Images(); + } + + /* + * creates edit menu + */ + Menu createEditMenu() { + Menu bar = shell.getMenuBar (); + Menu menu = new Menu (bar); + + MenuItem item = new MenuItem (menu, DWT.PUSH); + item.setText (resources.getString("Cut_menuitem")); + item.setAccelerator(DWT.MOD1 + 'X'); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + handleCutCopy(); + text.cut(); + } + }); + item = new MenuItem (menu, DWT.PUSH); + item.setText (resources.getString("Copy_menuitem")); + item.setAccelerator(DWT.MOD1 + 'C'); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + handleCutCopy(); + text.copy(); + } + }); + item = new MenuItem (menu, DWT.PUSH); + item.setText (resources.getString("Paste_menuitem")); + item.setAccelerator(DWT.MOD1 + 'V'); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + text.paste(); + } + }); + new MenuItem (menu, DWT.SEPARATOR); + item = new MenuItem (menu, DWT.PUSH); + item.setText (resources.getString("Font_menuitem")); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + setFont(); + } + }); + return menu; + } + + /* + * creates file menu + */ + Menu createFileMenu() { + Menu bar = shell.getMenuBar (); + Menu menu = new Menu (bar); + + MenuItem item = new MenuItem (menu, DWT.PUSH); + item.setText (resources.getString("Exit_menuitem")); + item.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + shell.close (); + } + }); + + return menu; + } + + /* + * Set a style + */ + void setStyle(Widget widget) { + Point sel = text.getSelectionRange(); + if ((sel is null) || (sel.y is 0)) return; + StyleRange style; + for (int i = sel.x; i 0) { + StyleRange lastStyle = cachedStyles.tail(); + if (lastStyle.similarTo(style) && lastStyle.start + lastStyle.length is style.start) { + lastStyle.length++; + } else { + cachedStyles.append(style); + } + } else { + cachedStyles.append(style); + } + } + } + } + + /* + * handle modify + */ + void handleExtendedModify(ExtendedModifyEvent event) { + if (event.length is 0) return; + StyleRange style; + //PORTING event.length is char count, but it needs to decide on codepoint count + auto cont = text.getTextRange(event.start, event.length); + if ( codepointCount(cont) is 1 || cont == text.getLineDelimiter()) { + // Have the new text take on the style of the text to its right (during + // typing) if no style information is active. + int caretOffset = text.getCaretOffset(); + style = null; + if (caretOffset < text.getCharCount()) style = text.getStyleRangeAtOffset(caretOffset); + if (style !is null) { + style = cast(StyleRange) style.clone (); + style.start = event.start; + style.length = event.length; + } else { + style = new StyleRange(event.start, event.length, null, null, DWT.NORMAL); + } + if (boldButton.getSelection()) style.fontStyle |= DWT.BOLD; + if (italicButton.getSelection()) style.fontStyle |= DWT.ITALIC; + style.underline = underlineButton.getSelection(); + style.strikeout = strikeoutButton.getSelection(); + if (!style.isUnstyled()) text.setStyleRange(style); + } else { + // paste occurring, have text take on the styles it had when it was + // cut/copied + foreach (style; cachedStyles) { + StyleRange newStyle = cast(StyleRange)style.clone(); + newStyle.start = style.start + event.start; + text.setStyleRange(newStyle); + } + } + } + + /* + * opens the shell + */ + public Shell open (Display display) { + createShell (display); + createMenuBar (); + createToolBar (); + createStyledText (); + shell.setSize(500, 300); + shell.open (); + return shell; + } + + /* + * set the font for styled text widget + */ + void setFont() { + FontDialog fontDialog = new FontDialog(shell); + fontDialog.setFontList((text.getFont()).getFontData()); + FontData fontData = fontDialog.open(); + if (fontData !is null) { + Font newFont = new Font(shell.getDisplay(), fontData); + text.setFont(newFont); + if (font !is null) font.dispose(); + font = newFont; + } + } + + /* + * initialize the colors + */ + void initializeColors() { + Display display = Display.getDefault(); + RED = new Color (display, new RGB(255,0,0)); + BLUE = new Color (display, new RGB(0,0,255)); + GREEN = new Color (display, new RGB(0,255,0)); + } +} + +/* + * main function + */ +public void main (char[][] args) { + Display display = new Display (); + TextEditor example = new TextEditor (); + Shell shell = example.open (display); + while (!shell.isDisposed ()) + if (!display.readAndDispatch ()) display.sleep (); + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/button/Snippet293.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/button/Snippet293.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2000, 2008 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 gmail.com + *******************************************************************************/ +module snippets.button.Snippet293; + +/* + * create a tri-state button. + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.layout.GridLayout; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Button; + +void main() { + auto display = new Display(); + auto shell = new Shell(display); + shell.setLayout(new GridLayout()); + + auto b1 = new Button (shell, DWT.CHECK); + b1.setText("State 1"); + b1.setSelection(true); + + auto b2 = new Button (shell, DWT.CHECK); + b2.setText("State 2"); + b2.setSelection(false); + + auto b3 = new Button (shell, DWT.CHECK); + b3.setText("State 3"); + b3.setSelection(true); + + // This function does not appear in the api for swt 3.3 + // b3.setGrayed(true); + + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/combo/Snippet26.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/combo/Snippet26.d Sat May 10 13:32:45 2008 -0700 @@ -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 gmail.com + *******************************************************************************/ +module snippets.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 (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/composite/Snippet9.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/composite/Snippet9.d Sat May 10 13:32:45 2008 -0700 @@ -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 + * Jesse Phillips gmail.com + *******************************************************************************/ +module snippets.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; +import dwt.dwthelper.utils; + +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 (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/control/Snippet25.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/control/Snippet25.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,154 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.control.Snippet25; + +/* + * Control example snippet: print key state, code and character + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ +import dwt.DWT; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Listener; +import dwt.widgets.Event; + +import tango.io.Stdout; +import tango.text.convert.Format; + +static char[] stateMask (int stateMask) { + char[] string = ""; + if ((stateMask & DWT.CTRL) != 0) string ~= " CTRL"; + if ((stateMask & DWT.ALT) != 0) string ~= " ALT"; + if ((stateMask & DWT.SHIFT) != 0) string ~= " SHIFT"; + if ((stateMask & DWT.COMMAND) != 0) string ~= " COMMAND"; + return string; +} + +static char[] character (char character) { + switch (character) { + case 0: return "'\\0'"; + case DWT.BS: return "'\\b'"; + case DWT.CR: return "'\\r'"; + case DWT.DEL: return "DEL"; + case DWT.ESC: return "ESC"; + case DWT.LF: return "'\\n'"; + case DWT.TAB: return "'\\t'"; + default: + return "'" ~ character ~"'"; + } +} + +static char[] keyCode (int keyCode) { + switch (keyCode) { + + /* Keyboard and Mouse Masks */ + case DWT.ALT: return "ALT"; + case DWT.SHIFT: return "SHIFT"; + case DWT.CONTROL: return "CONTROL"; + case DWT.COMMAND: return "COMMAND"; + + /* Non-Numeric Keypad Keys */ + case DWT.ARROW_UP: return "ARROW_UP"; + case DWT.ARROW_DOWN: return "ARROW_DOWN"; + case DWT.ARROW_LEFT: return "ARROW_LEFT"; + case DWT.ARROW_RIGHT: return "ARROW_RIGHT"; + case DWT.PAGE_UP: return "PAGE_UP"; + case DWT.PAGE_DOWN: return "PAGE_DOWN"; + case DWT.HOME: return "HOME"; + case DWT.END: return "END"; + case DWT.INSERT: return "INSERT"; + + /* Virtual and Ascii Keys */ + case DWT.BS: return "BS"; + case DWT.CR: return "CR"; + case DWT.DEL: return "DEL"; + case DWT.ESC: return "ESC"; + case DWT.LF: return "LF"; + case DWT.TAB: return "TAB"; + + /* Functions Keys */ + case DWT.F1: return "F1"; + case DWT.F2: return "F2"; + case DWT.F3: return "F3"; + case DWT.F4: return "F4"; + case DWT.F5: return "F5"; + case DWT.F6: return "F6"; + case DWT.F7: return "F7"; + case DWT.F8: return "F8"; + case DWT.F9: return "F9"; + case DWT.F10: return "F10"; + case DWT.F11: return "F11"; + case DWT.F12: return "F12"; + case DWT.F13: return "F13"; + case DWT.F14: return "F14"; + case DWT.F15: return "F15"; + + /* Numeric Keypad Keys */ + case DWT.KEYPAD_ADD: return "KEYPAD_ADD"; + case DWT.KEYPAD_SUBTRACT: return "KEYPAD_SUBTRACT"; + case DWT.KEYPAD_MULTIPLY: return "KEYPAD_MULTIPLY"; + case DWT.KEYPAD_DIVIDE: return "KEYPAD_DIVIDE"; + case DWT.KEYPAD_DECIMAL: return "KEYPAD_DECIMAL"; + case DWT.KEYPAD_CR: return "KEYPAD_CR"; + case DWT.KEYPAD_0: return "KEYPAD_0"; + case DWT.KEYPAD_1: return "KEYPAD_1"; + case DWT.KEYPAD_2: return "KEYPAD_2"; + case DWT.KEYPAD_3: return "KEYPAD_3"; + case DWT.KEYPAD_4: return "KEYPAD_4"; + case DWT.KEYPAD_5: return "KEYPAD_5"; + case DWT.KEYPAD_6: return "KEYPAD_6"; + case DWT.KEYPAD_7: return "KEYPAD_7"; + case DWT.KEYPAD_8: return "KEYPAD_8"; + case DWT.KEYPAD_9: return "KEYPAD_9"; + case DWT.KEYPAD_EQUAL: return "KEYPAD_EQUAL"; + + /* Other keys */ + case DWT.CAPS_LOCK: return "CAPS_LOCK"; + case DWT.NUM_LOCK: return "NUM_LOCK"; + case DWT.SCROLL_LOCK: return "SCROLL_LOCK"; + case DWT.PAUSE: return "PAUSE"; + case DWT.BREAK: return "BREAK"; + case DWT.PRINT_SCREEN: return "PRINT_SCREEN"; + case DWT.HELP: return "HELP"; + + default: + return character (cast(char) keyCode); + } + +} + +void main () { + Display display = new Display (); + Shell shell = new Shell (display); + Listener listener = new class Listener { + public void handleEvent (Event e) { + char[] string = e.type == DWT.KeyDown ? "DOWN:" : "UP :"; + string ~= Format("stateMask=0x{:x}{},", e.stateMask, stateMask (e.stateMask)); + string ~= Format(" keyCode=0x{:x} {},", e.keyCode, keyCode (e.keyCode)); + string ~= Format(" character=0x{:x} {}", e.character, character (e.character)); + Stdout.formatln (string); + } + }; + shell.addListener (DWT.KeyDown, listener); + shell.addListener (DWT.KeyUp, listener); + shell.setSize (200, 200); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/control/Snippet62.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/control/Snippet62.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,74 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ + module snippets.control.Snippet62; + + /* + * Control example snippet: print mouse state and button (down, move, up) + * + * 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.Listener; +import dwt.widgets.Event; + +import tango.io.Stdout; +import tango.util.Convert; + +static char[] stateMask (int stateMask) { + char[] str = ""; + if ((stateMask & DWT.CTRL) != 0) str ~= " CTRL"; + if ((stateMask & DWT.ALT) != 0) str ~= " ALT"; + if ((stateMask & DWT.SHIFT) != 0) str ~= " SHIFT"; + if ((stateMask & DWT.COMMAND) != 0) str ~= " COMMAND"; + return str; +} + +void main () { + Display display = new Display (); + final Shell shell = new Shell (display); + Listener listener = new class Listener { + public void handleEvent (Event e) { + char[] str = "Unknown"; + switch (e.type) { + case DWT.MouseDown: str = "DOWN"; break; + case DWT.MouseMove: str = "MOVE"; break; + case DWT.MouseUp: str = "UP"; break; + } + str ~=": button: " ~ to!(char[])(e.button) ~ ", "; + str ~= "stateMask=0x" ~ to!(char[])(e.stateMask) + ~ stateMask (e.stateMask) + ~ ", x=" ~ to!(char[])(e.x) ~ ", y=" ~ to!(char[])(e.y); + if ((e.stateMask & DWT.BUTTON1) != 0) str ~= " BUTTON1"; + if ((e.stateMask & DWT.BUTTON2) != 0) str ~= " BUTTON2"; + if ((e.stateMask & DWT.BUTTON3) != 0) str ~= " BUTTON3"; + if ((e.stateMask & DWT.BUTTON4) != 0) str ~= " BUTTON4"; + if ((e.stateMask & DWT.BUTTON5) != 0) str ~= " BUTTON5"; + Stdout.formatln (str); + } + }; + shell.addListener (DWT.MouseDown, listener); + shell.addListener (DWT.MouseMove, listener); + shell.addListener (DWT.MouseUp, listener); + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/coolbar/Snippet140.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/coolbar/Snippet140.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,120 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.coolbar.Snippet140; + +/* + * CoolBar example snippet: drop-down a chevron menu containing hidden tool items + * + * 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.Display; +import dwt.widgets.Shell; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; +import dwt.widgets.CoolBar; +import dwt.widgets.CoolItem; +import dwt.events.SelectionEvent; +import dwt.events.SelectionAdapter; +import dwt.layout.GridLayout; +import dwt.layout.GridData; + +import tango.util.Convert; + +static Display display; +static Shell shell; +static CoolBar coolBar; +static Menu chevronMenu = null; + + +void main () { + display = new Display (); + shell = new Shell (display); + shell.setLayout(new GridLayout()); + coolBar = new CoolBar(shell, DWT.FLAT | DWT.BORDER); + coolBar.setLayoutData(new GridData(GridData.FILL_BOTH)); + ToolBar toolBar = new ToolBar(coolBar, DWT.FLAT | DWT.WRAP); + int minWidth = 0; + for (int j = 0; j < 5; j++) { + int width = 0; + ToolItem item = new ToolItem(toolBar, DWT.PUSH); + item.setText("B" ~ to!(char[])(j)); + width = item.getWidth(); + /* find the width of the widest tool */ + if (width > minWidth) minWidth = width; + } + CoolItem coolItem = new CoolItem(coolBar, DWT.DROP_DOWN); + coolItem.setControl(toolBar); + Point size = toolBar.computeSize(DWT.DEFAULT, DWT.DEFAULT); + Point coolSize = coolItem.computeSize (size.x, size.y); + coolItem.setMinimumSize(minWidth, coolSize.y); + coolItem.setPreferredSize(coolSize); + coolItem.setSize(coolSize); + coolItem.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent event) { + if (event.detail == DWT.ARROW) { + CoolItem item = cast(CoolItem) event.widget; + Rectangle itemBounds = item.getBounds (); + Point pt = coolBar.toDisplay(new Point(itemBounds.x, itemBounds.y)); + itemBounds.x = pt.x; + itemBounds.y = pt.y; + ToolBar bar = cast(ToolBar) item.getControl (); + ToolItem[] tools = bar.getItems (); + + int i = 0; + while (i < tools.length) { + Rectangle toolBounds = tools[i].getBounds (); + pt = bar.toDisplay(new Point(toolBounds.x, toolBounds.y)); + toolBounds.x = pt.x; + toolBounds.y = pt.y; + + /* Figure out the visible portion of the tool by looking at the + * intersection of the tool bounds with the cool item bounds. + */ + Rectangle intersection = itemBounds.intersection (toolBounds); + + /* If the tool is not completely within the cool item bounds, then it + * is partially hidden, and all remaining tools are completely hidden. + */ + if (intersection != toolBounds) break; + i++; + } + + /* Create a menu with items for each of the completely hidden buttons. */ + if (chevronMenu !is null) chevronMenu.dispose(); + chevronMenu = new Menu (coolBar); + for (int j = i; j < tools.length; j++) { + MenuItem menuItem = new MenuItem (chevronMenu, DWT.PUSH); + menuItem.setText (tools[j].getText()); + } + + /* Drop down the menu below the chevron, with the left edges aligned. */ + pt = coolBar.toDisplay(new Point(event.x, event.y)); + chevronMenu.setLocation (pt.x, pt.y); + chevronMenu.setVisible (true); + } + } + }); + + shell.pack(); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/coolbar/Snippet150.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/coolbar/Snippet150.d Sat May 10 13:32:45 2008 -0700 @@ -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: + * Bill Baxter + *******************************************************************************/ +module snippets.coolbar.Snippet150; + +/* + * CoolBar example snippet: create a coolbar (relayout when resized) + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ +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.ToolBar; +import dwt.widgets.ToolItem; +import dwt.widgets.Shell; +import dwt.widgets.Text; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.layout.FormLayout; +import dwt.layout.FormData; +import dwt.layout.FormAttachment; + +import tango.util.Convert; + +int itemCount; +CoolItem createItem(CoolBar coolBar, int count) { + ToolBar toolBar = new ToolBar(coolBar, DWT.FLAT); + for (int i = 0; i < count; i++) { + ToolItem item = new ToolItem(toolBar, DWT.PUSH); + item.setText(to!(char[])(itemCount++) ~""); + } + toolBar.pack(); + Point size = toolBar.getSize(); + CoolItem item = new CoolItem(coolBar, DWT.NONE); + item.setControl(toolBar); + Point preferred = item.computeSize(size.x, size.y); + item.setPreferredSize(preferred); + return item; +} + +void main () { + + Display display = new Display(); + final Shell shell = new Shell(display); + CoolBar coolBar = new CoolBar(shell, DWT.NONE); + createItem(coolBar, 3); + createItem(coolBar, 2); + createItem(coolBar, 3); + createItem(coolBar, 4); + int style = DWT.BORDER | DWT.H_SCROLL | DWT.V_SCROLL; + Text text = new Text(shell, style); + FormLayout layout = new FormLayout(); + shell.setLayout(layout); + FormData coolData = new FormData(); + coolData.left = new FormAttachment(0); + coolData.right = new FormAttachment(100); + coolData.top = new FormAttachment(0); + coolBar.setLayoutData(coolData); + coolBar.addListener(DWT.Resize, new class() Listener { + void handleEvent(Event event) { + shell.layout(); + } + }); + FormData textData = new FormData(); + textData.left = new FormAttachment(0); + textData.right = new FormAttachment(100); + textData.top = new FormAttachment(coolBar); + textData.bottom = new FormAttachment(100); + text.setLayoutData(textData); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + display.dispose(); + +} \ No newline at end of file diff -r 04f122e90b0a -r 4a04b6759f98 snippets/coolbar/Snippet20.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/coolbar/Snippet20.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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 gmail.com + *******************************************************************************/ +module snippets.coolbar.Snippet20; + +/* + * CoolBar example snippet: create a cool bar + * + * For a list of all SWT 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)); + auto size = button.computeSize (DWT.DEFAULT, DWT.DEFAULT); + item.setPreferredSize (item.computeSize (size.x, size.y)); + item.setControl (button); + } + bar.pack (); + shell.setSize(300, 100); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/ctabfolder/Snippet165.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/ctabfolder/Snippet165.d Sat May 10 13:32:45 2008 -0700 @@ -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 gmail.com + *******************************************************************************/ +module snippets.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 (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/directorydialog/Snippet33.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/directorydialog/Snippet33.d Sat May 10 13:32:45 2008 -0700 @@ -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 gmail.com + *******************************************************************************/ +module snippets.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 (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/dsss.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/dsss.conf Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,66 @@ +# DWT dwt-samples/dwtsnippets directory + +[*] +buildflags+=-g -gc +buildflags+=-J$LIB_PREFIX/res -J../res -I.. + +version(Windows) { + # if no console window is wanted/needed use -version=gui + version(gui) { + buildflags+= -L/SUBSYSTEM:windows:5 + } else { + buildflags+= -L/SUBSYSTEM:console:5 + } + buildflags+= -L/rc:dwt +} + + + +[button/Snippet293.d] +[control/Snippet25.d] +[control/Snippet62.d] +[combo/Snippet26.d] +[composite/Snippet9.d] +[coolbar/Snippet20.d] +[coolbar/Snippet140.d] +[coolbar/Snippet150.d] +[ctabfolder/Snippet165.d] +[directorydialog/Snippet33.d] +[expandbar/Snippet223.d] +[filedialog/Snippet72.d] +[gc/Snippet10.d] +[gc/Snippet66.d] +[gc/Snippet207.d] +[gc/Snippet215.d] +[menu/Snippet29.d] +[menu/Snippet97.d] +[menu/Snippet152.d] +[menu/Snippet286.d] +[program/Snippet32.d] +[sash/Snippet107.d] +[sashform/Snippet109.d] +[shell/Snippet134.d] +[shell/Snippet138.d] +[spinner/Snippet184.d] +[spinner/Snippet190.d] +[styledtext/Snippet163.d] +[styledtext/Snippet189.d] +[table/Snippet38.d] +[table/Snippet144.d] +[text/Snippet258.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] + +version(Derelict){ + [opengl] + type=subdir +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/expandbar/Snippet223.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/expandbar/Snippet223.d Sat May 10 13:32:45 2008 -0700 @@ -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 gmail.com + *******************************************************************************/ +module snippets.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(); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/filedialog/Snippet72.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/filedialog/Snippet72.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.filedialog.Snippet72; + +/* + * FileDialog example snippet: prompt for a file name (to save) + * + * 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.Shell; +import dwt.widgets.FileDialog; + +import tango.io.Stdout; + +void main () { + Display display = new Display (); + Shell shell = new Shell (display); + shell.open (); + FileDialog dialog = new FileDialog (shell, DWT.SAVE); + dialog.setFilterNames (["Batch Files", "All Files (*.*)"]); + dialog.setFilterExtensions (["*.bat", "*.*"]); //Windows wild cards + dialog.setFilterPath ("c:\\"); //Windows path + dialog.setFileName ("fred.bat"); + Stdout.formatln ("Save to: {}", dialog.open ()); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/gc/Snippet10.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/gc/Snippet10.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,78 @@ +/******************************************************************************* + * 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 + * Port to the D programming language: + * Bill Baxter + *******************************************************************************/ +module snippets.gc.Snippet10; + +/* + * Draw using transformations, paths and alpha blending + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.1 + */ +import dwt.DWT; +import dwt.graphics.GC; +import dwt.graphics.Path; +import dwt.graphics.Transform; +import dwt.graphics.Font; +import dwt.graphics.FontData; +import dwt.graphics.Image; +import dwt.graphics.Rectangle; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Listener; +import dwt.widgets.Event; + + +void main() { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setText("Advanced Graphics"); + FontData fd = shell.getFont().getFontData()[0]; + Font font = new Font(display, fd.getName(), 60., DWT.BOLD | DWT.ITALIC); + Image image = new Image(display, 640, 480); + Rectangle rect = image.getBounds(); + GC gc = new GC(image); + gc.setBackground(display.getSystemColor(DWT.COLOR_RED)); + gc.fillOval(rect.x, rect.y, rect.width, rect.height); + gc.dispose(); + shell.addListener(DWT.Paint, new class() Listener { + public void handleEvent(Event event) { + GC gc = event.gc; + Transform tr = new Transform(display); + tr.translate(50, 120); + tr.rotate(-30); + gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2); + gc.setAlpha(100); + gc.setTransform(tr); + Path path = new Path(display); + path.addString("DWT", 0, 0, font); + gc.setBackground(display.getSystemColor(DWT.COLOR_GREEN)); + gc.setForeground(display.getSystemColor(DWT.COLOR_BLUE)); + gc.fillPath(path); + gc.drawPath(path); + tr.dispose(); + path.dispose(); + } + }); + shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2)); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + image.dispose(); + font.dispose(); + display.dispose(); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/gc/Snippet207.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/gc/Snippet207.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,129 @@ +/******************************************************************************* + * 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 + * Port to the D programming language: + * Bill Baxter + *******************************************************************************/ +module snippets.gc.Snippet207; + +/* + * Use transformation matrices to reflect, rotate and shear images + * + * 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.GC; +import dwt.graphics.Transform; +import dwt.graphics.Font; +import dwt.graphics.Rectangle; +import dwt.graphics.Image; +import dwt.layout.FillLayout; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Canvas; + +import Math=tango.math.Math; + +void main() { + Display display = new Display(); + + Image image = new Image(display, 110, 60); + GC gc = new GC(image); + Font font = new Font(display, "Times", 30., DWT.BOLD); + gc.setFont(font); + gc.setBackground(display.getSystemColor(DWT.COLOR_RED)); + gc.fillRectangle(0, 0, 110, 60); + gc.setForeground(display.getSystemColor(DWT.COLOR_WHITE)); + gc.drawText("DWT", 10, 10, true); + font.dispose(); + gc.dispose(); + + Rectangle rect = image.getBounds(); + Shell shell = new Shell(display); + shell.setText("Matrix Tranformations"); + shell.setLayout(new FillLayout()); + Canvas canvas = new Canvas(shell, DWT.DOUBLE_BUFFERED); + canvas.addPaintListener(new class() PaintListener { + public void paintControl(PaintEvent e) { + GC gc = e.gc; + gc.setAdvanced(true); + if (!gc.getAdvanced()){ + gc.drawText("Advanced graphics not supported", 30, 30, true); + return; + } + + // Original image + int x = 30, y = 30; + gc.drawImage(image, x, y); + x += rect.width + 30; + + Transform transform = new Transform(display); + + // Note that the tranform is applied to the whole GC therefore + // the coordinates need to be adjusted too. + + // Reflect around the y axis. + transform.setElements(-1, 0, 0, 1, 0 ,0); + gc.setTransform(transform); + gc.drawImage(image, -1*x-rect.width, y); + + x = 30; y += rect.height + 30; + + // Reflect around the x axis. + transform.setElements(1, 0, 0, -1, 0, 0); + gc.setTransform(transform); + gc.drawImage(image, x, -1*y-rect.height); + + x += rect.width + 30; + + // Reflect around the x and y axes + transform.setElements(-1, 0, 0, -1, 0, 0); + gc.setTransform(transform); + gc.drawImage(image, -1*x-rect.width, -1*y-rect.height); + + x = 30; y += rect.height + 30; + + // Shear in the x-direction + transform.setElements(1, 0, -1, 1, 0, 0); + gc.setTransform(transform); + gc.drawImage(image, 300, y); + + // Shear in y-direction + transform.setElements(1, -1, 0, 1, 0, 0); + gc.setTransform(transform); + gc.drawImage(image, 150, 475); + + // Rotate by 45 degrees + float cos45 = Math.cos(45); + float sin45 = Math.sin(45); + transform.setElements(cos45, sin45, -sin45, cos45, 0, 0); + gc.setTransform(transform); + gc.drawImage(image, 350, 100); + + transform.dispose(); + } + }); + + shell.setSize(350, 550); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + image.dispose(); + display.dispose(); +} + + + + + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/gc/Snippet215.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/gc/Snippet215.d Sat May 10 13:32:45 2008 -0700 @@ -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 + * Port to the D programming language: + * Bill Baxter + *******************************************************************************/ +module snippets.gc.Snippet215; + +/* + * GC example snippet: take a screen shot with a GC + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.graphics.GC; +import dwt.graphics.Image; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Listener; +import dwt.widgets.Event; +import dwt.widgets.Button; +import dwt.widgets.Canvas; +import dwt.custom.ScrolledComposite; +import dwt.layout.FillLayout; +import dwt.events.PaintListener; + +Image image; + +void main() { + final Display display = new Display(); + final Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + Button button = new Button(shell, DWT.PUSH); + button.setText("Capture"); + button.addListener(DWT.Selection, new class() Listener { + public void handleEvent(Event event) { + + /* Take the screen shot */ + GC gc = new GC(display); + image = new Image(display, display.getBounds()); + gc.copyArea(image, 0, 0); + gc.dispose(); + + Shell popup = new Shell(shell, DWT.SHELL_TRIM); + popup.setLayout(new FillLayout()); + popup.setText("Image"); + popup.setBounds(50, 50, 200, 200); + popup.addListener(DWT.Close, new class() Listener { + public void handleEvent(Event e) { + image.dispose(); + } + }); + + ScrolledComposite sc = new ScrolledComposite (popup, DWT.V_SCROLL | DWT.H_SCROLL); + Canvas canvas = new Canvas(sc, DWT.NONE); + sc.setContent(canvas); + canvas.setBounds(display.getBounds ()); + canvas.addPaintListener(new class() PaintListener { + public void paintControl(PaintEvent e) { + e.gc.drawImage(image, 0, 0); + } + }); + popup.open(); + } + }); + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + display.dispose(); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/gc/Snippet66.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/gc/Snippet66.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,56 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.gc.Snippet66; + +/* + * GC example snippet: implement a simple scribble program + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.graphics.GC; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Listener; +import dwt.widgets.Event; + +void main () { + Display display = new Display (); + final Shell shell = new Shell (display); + Listener listener = new class() Listener { + int lastX = 0, lastY = 0; + public void handleEvent (Event event) { + switch (event.type) { + case DWT.MouseMove: + if ((event.stateMask & DWT.BUTTON1) == 0) break; + GC gc = new GC (shell); + gc.drawLine (lastX, lastY, event.x, event.y); + gc.dispose (); + //FALL THROUGH + case DWT.MouseDown: + lastX = event.x; + lastY = event.y; + break; + } + } + }; + shell.addListener (DWT.MouseDown, listener); + shell.addListener (DWT.MouseMove, listener); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/menu/Snippet152.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/menu/Snippet152.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,103 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.menu.Snippet152; + +/* + * Control example snippet: update a status line when an item is armed + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ + +import dwt.DWT; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Label; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.layout.FormLayout; +import dwt.layout.FormData; +import dwt.layout.FormAttachment; + +void main() { + Display display = new Display(); + Shell shell = new Shell(display); + FormLayout layout = new FormLayout(); + shell.setLayout(layout); + Label label = new Label(shell, DWT.BORDER); + Listener armListener = new class Listener { + public void handleEvent(Event event) { + MenuItem item = cast(MenuItem) event.widget; + label.setText(item.getText()); + label.update(); + } + }; + Listener showListener = new class Listener { + public void handleEvent(Event event) { + Menu menu = cast(Menu) event.widget; + MenuItem item = menu.getParentItem(); + if (item !is null) { + label.setText(item.getText()); + label.update(); + } + } + }; + Listener hideListener = new class Listener { + public void handleEvent(Event event) { + label.setText(""); + label.update(); + } + }; + FormData labelData = new FormData(); + labelData.left = new FormAttachment(0); + labelData.right = new FormAttachment(100); + labelData.bottom = new FormAttachment(100); + label.setLayoutData(labelData); + Menu menuBar = new Menu(shell, DWT.BAR); + shell.setMenuBar(menuBar); + MenuItem fileItem = new MenuItem(menuBar, DWT.CASCADE); + fileItem.setText("File"); + fileItem.addListener(DWT.Arm, armListener); + MenuItem editItem = new MenuItem(menuBar, DWT.CASCADE); + editItem.setText("Edit"); + editItem.addListener(DWT.Arm, armListener); + Menu fileMenu = new Menu(shell, DWT.DROP_DOWN); + fileMenu.addListener(DWT.Hide, hideListener); + fileMenu.addListener(DWT.Show, showListener); + fileItem.setMenu(fileMenu); + char[][] fileStrings = [ "New", "Close", "Exit" ]; + for (int i = 0; i < fileStrings.length; i++) { + MenuItem item = new MenuItem(fileMenu, DWT.PUSH); + item.setText(fileStrings[i]); + item.addListener(DWT.Arm, armListener); + } + Menu editMenu = new Menu(shell, DWT.DROP_DOWN); + editMenu.addListener(DWT.Hide, hideListener); + editMenu.addListener(DWT.Show, showListener); + char[][] editStrings = [ "Cut", "Copy", "Paste" ]; + editItem.setMenu(editMenu); + for (int i = 0; i < editStrings.length; i++) { + MenuItem item = new MenuItem(editMenu, DWT.PUSH); + item.setText(editStrings[i]); + item.addListener(DWT.Arm, armListener); + } + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + display.dispose(); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/menu/Snippet286.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/menu/Snippet286.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007 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 + *******************************************************************************/ +module snippets.menu.Snippet286; + +/* + * use a menu item's armListener to update a status line. + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.events.ArmEvent; +import dwt.events.ArmListener; +import dwt.layout.GridLayout; +import dwt.layout.GridData; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Canvas; +import dwt.widgets.Label; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; + +import tango.util.Convert; + + +void main() { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new GridLayout()); + + Canvas blankCanvas = new Canvas(shell, DWT.BORDER); + blankCanvas.setLayoutData(new GridData(200, 200)); + Label statusLine = new Label(shell, DWT.NONE); + statusLine.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, true, false)); + + Menu bar = new Menu (shell, DWT.BAR); + shell.setMenuBar (bar); + + MenuItem menuItem = new MenuItem (bar, DWT.CASCADE); + menuItem.setText ("Test"); + Menu menu = new Menu(bar); + menuItem.setMenu (menu); + + for (int i = 0; i < 5; i++) { + MenuItem item = new MenuItem (menu, DWT.PUSH); + item.setText ("Item " ~ to!(char[])(i)); + item.addArmListener(new class ArmListener { + public void widgetArmed(ArmEvent e) { + statusLine.setText((cast(MenuItem)e.getSource()).getText()); + } + }); + } + + shell.pack(); + shell.open(); + + while(!shell.isDisposed()) { + if(!display.readAndDispatch()) display.sleep(); + } +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/menu/Snippet29.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/menu/Snippet29.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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 gmail.com + *******************************************************************************/ +module snippets.menu.Snippet29; + +/* + * Menu example snippet: create a bar and pull down menu (accelerators, mnemonics) + * + * 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.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.Shell; + +import tango.io.Stdout; + +void main () { + auto display = new Display (); + auto shell = new Shell (display); + auto bar = new Menu (shell, DWT.BAR); + shell.setMenuBar (bar); + auto fileItem = new MenuItem (bar, DWT.CASCADE); + fileItem.setText ("&File"); + auto submenu = new Menu (shell, DWT.DROP_DOWN); + fileItem.setMenu (submenu); + auto item = new MenuItem (submenu, DWT.PUSH); + item.addListener (DWT.Selection, new class Listener { + public void handleEvent (Event e) { + Stdout("Select All").newline; + } + }); + item.setText ("Select &All\tCtrl+A"); + item.setAccelerator (DWT.CTRL + 'A'); + shell.setSize (200, 200); + shell.open (); + while (!shell.isDisposed()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/menu/Snippet97.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/menu/Snippet97.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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 gmail.com + *******************************************************************************/ +module snippets.menu.Snippet97; + +/* + * Menu example snippet: fill a menu dynamically (when menu shown) + * Select items then right click to show menu. + * + * 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.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.Shell; +import dwt.widgets.Tree; +import dwt.widgets.TreeItem; + +import tango.util.Convert; + +void main () { + auto display = new Display (); + auto shell = new Shell (display); + auto tree = new Tree (shell, DWT.BORDER | DWT.MULTI); + auto menu = new Menu (shell, DWT.POP_UP); + tree.setMenu (menu); + for (int i=0; i<12; i++) { + auto item = new TreeItem (tree, DWT.NONE); + item.setText ("Item " ~ to!(char[])(i)); + } + menu.addListener (DWT.Show, new class Listener { + public void handleEvent (Event event) { + auto menuItems = menu.getItems (); + foreach (item; menuItems) { + item.dispose (); + } + auto treeItems = tree.getSelection (); + foreach (item; treeItems) { + auto menuItem = new MenuItem (menu, DWT.PUSH); + menuItem.setText (item.getText ()); + } + } + }); + tree.setSize (200, 200); + shell.setSize (300, 300); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/opengl/Readme.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/opengl/Readme.txt Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,17 @@ +opengl_test.d -- based on snippet195.java + +Build dependencies: + +* DerelictGL and DerelictGLU -- Install both of these with dsss OR have the derelict source in your include path using the "-I" command line flag. You may also have to add DerelictUtil to your include path. + +* Import libraries provided via dwt-win projects wiki (www.dsource.org/project/dwt-win): +These will include glu32.lib and opengl32.lib (win32 version). Place these in your library path, ie usually in \dmd\lib + +* Make sure that dwt library is either built and installed with dsss or that you have dwt source in your include path using the "-I" command line flag. + +------------------------------------ + +If you have installed all required libraries with dsss, then you should be able to just do a "dsss build snippets\opengl_test1.d" + + + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/opengl/Snippet174.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/opengl/Snippet174.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,116 @@ +/******************************************************************************* + * 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: + * Sebastian Davids - initial implementation + * IBM Corporation + * Port to the D programming language: + * Bill Baxter + *******************************************************************************/ +module snippets.opengl.Snippet174; + +/* + * SWT OpenGL snippet: draw a square + * + * This snippet requires the experimental org.eclipse.swt.opengl plugin, which + * is not included in SWT by default and should only be used with versions of + * SWT prior to 3.2. For information on using OpenGL in SWT see + * http://www.eclipse.org/swt/opengl/ . + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.2 + */ +import dwt.DWT; +import dwt.dwthelper.Runnable; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.graphics.Rectangle; +import dwt.events.ControlEvent; +import dwt.events.ControlAdapter; +import dwt.layout.FillLayout; +import dwt.opengl.GLCanvas; +import dwt.opengl.GLData; + +import derelict.opengl.gl; +import derelict.opengl.glu; + +import Math = tango.math.Math; + +public static void main() +{ + DerelictGL.load(); + DerelictGLU.load(); + + Display display = new Display(); + Shell shell = new Shell(display); + shell.setText("OpenGL in DWT"); + shell.setLayout(new FillLayout()); + GLData data = new GLData(); + data.doubleBuffer = true; + final GLCanvas canvas = new GLCanvas(shell, DWT.NO_BACKGROUND, data); + canvas.addControlListener(new class ControlAdapter { + public void controlResized(ControlEvent e) { + resize(canvas); + } + }); + init(canvas); + (new class Runnable { + public void run() { + if (canvas.isDisposed()) return; + render(); + canvas.swapBuffers(); + canvas.getDisplay().timerExec(15, this); + } + }).run(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + display.dispose(); +} + +static void init(GLCanvas canvas) { + canvas.setCurrent(); + resize(canvas); + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + glColor3f(0.0f, 0.0f, 0.0f); + glClearDepth(1.0f); + glEnable(GL_DEPTH_TEST); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); +} + +static void render() { + static int rot = 0; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -6.0f); + glRotatef(rot++, 0,0,1); + rot %= 360; + glBegin(GL_QUADS); + glVertex3f(-1.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 0.0f); + glEnd(); +} + +static void resize(GLCanvas canvas) { + canvas.setCurrent(); + Rectangle rect = canvas.getClientArea(); + int width = rect.width; + int height = Math.max(rect.height, 1); + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + float aspect = cast(float) width / cast(float) height; + gluPerspective(45.0f, aspect, 0.5f, 400.0f); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/opengl/Snippet195.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/opengl/Snippet195.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,141 @@ +/******************************************************************************* + * 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 + * Port to the D Programming Language: + * John Reimer + *******************************************************************************/ + +module snippets.opengl.Snippet195; + +/* + * SWT OpenGL snippet: based on snippet195.java + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.2 + */ + +import dwt.DWT; +import dwt.dwthelper.Runnable; + +import dwt.layout.FillLayout; +import dwt.widgets.Shell; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Composite; +import dwt.widgets.Listener; +import dwt.graphics.Rectangle; +import dwt.opengl.GLCanvas; +import dwt.opengl.GLData; + +import derelict.opengl.gl; +import derelict.opengl.glu; + +import Math = tango.math.Math; + +void drawTorus(float r, float R, int nsides, int rings) +{ + float ringDelta = 2.0f * cast(float) Math.PI / rings; + float sideDelta = 2.0f * cast(float) Math.PI / nsides; + float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f; + for (int i = rings - 1; i >= 0; i--) { + float theta1 = theta + ringDelta; + float cosTheta1 = cast(float) Math.cos(theta1); + float sinTheta1 = cast(float) Math.sin(theta1); + glBegin(GL_QUAD_STRIP); + float phi = 0.0f; + for (int j = nsides; j >= 0; j--) { + phi += sideDelta; + float cosPhi = cast(float) Math.cos(phi); + float sinPhi = cast(float) Math.sin(phi); + float dist = R + r * cosPhi; + glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); + glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); + glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); + glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi); + } + glEnd(); + theta = theta1; + cosTheta = cosTheta1; + sinTheta = sinTheta1; + } +} + +void main() +{ + DerelictGL.load(); + DerelictGLU.load(); + + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + Composite comp = new Composite(shell, DWT.NONE); + comp.setLayout(new FillLayout()); + GLData data = new GLData (); + data.doubleBuffer = true; + GLCanvas canvas = new GLCanvas(comp, DWT.NONE, data); + + canvas.setCurrent(); + + canvas.addListener(DWT.Resize, new class() Listener { + public void handleEvent(Event event) { + Rectangle bounds = canvas.getBounds(); + float fAspect = cast(float) bounds.width / cast(float) bounds.height; + + glViewport(0, 0, bounds.width, bounds.height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0f, fAspect, 0.5f, 400.0f); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + } + }); + + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + glClearDepth(1.0); + glLineWidth(2); + glEnable(GL_DEPTH_TEST); + + shell.setText("DWT/DerelictGL Example"); + shell.setSize(640, 480); + shell.open(); + + display.asyncExec(new class() Runnable { + int rot = 0; + public void run() { + if (!canvas.isDisposed()) { + canvas.setCurrent(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearColor(.3f, .5f, .8f, 1.0f); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -10.0f); + float frot = rot; + glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f); + glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f); + rot++; + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + glColor3f(0.9f, 0.9f, 0.9f); + drawTorus(1, 1.9f + (cast(float) Math.sin((0.004f * frot))), 15, 15); + canvas.swapBuffers(); + display.asyncExec(this); + } + } + }); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/opengl/dsss.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/opengl/dsss.conf Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,17 @@ +[*] +buildflags+=-g -gc +buildflags+=-J$LIB_PREFIX/res -J../../res -I../.. + +version(Windows){ + # if no console window is wanted/needed use -version=gui + version(gui) { + buildflags+= -L/SUBSYSTEM:windows:5 + } else { + buildflags+= -L/SUBSYSTEM:console:5 + } + buildflags+= -L/rc:dwt +} + + +[Snippet174.d] +[Snippet195.d] diff -r 04f122e90b0a -r 4a04b6759f98 snippets/program/Snippet32.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/program/Snippet32.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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 snippets.program.Snippet32; + +/* + * Program example snippet: find the icon of the program that edits .bmp files + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.graphics.ImageData; +import dwt.graphics.Image; +import dwt.widgets.Shell; +import dwt.widgets.Display; +import dwt.widgets.Label; +import dwt.program.Program; + +void main () { + Display display = new Display (); + Shell shell = new Shell (display); + Label label = new Label (shell, DWT.NONE); + label.setText ("Can't find icon for .bmp"); + Image image = null; + Program p = Program.findProgram (".bmp"); + if (p !is null) { + ImageData data = p.getImageData (); + if (data !is null) { + image = new Image (display, data); + label.setImage (image); + } + } + label.pack (); + shell.pack (); + shell.open (); + while (!shell.isDisposed()) { + if (!display.readAndDispatch ()) display.sleep (); + } + if (image !is null) image.dispose (); + display.dispose (); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/sash/Snippet107.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/sash/Snippet107.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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 + *******************************************************************************/ +module snippets.sash.Snippet107; +/* + * Sash example snippet: implement a simple splitter (with a 20 pixel limit) + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.graphics.Rectangle; +import dwt.layout.FormAttachment; +import dwt.layout.FormData; +import dwt.layout.FormLayout; +import dwt.widgets.Button; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Sash; +import dwt.widgets.Shell; + +import tango.math.Math; + +void main () { + auto display = new Display (); + auto shell = new Shell (display); + auto button1 = new Button (shell, DWT.PUSH); + button1.setText ("Button 1"); + auto sash = new Sash (shell, DWT.VERTICAL); + auto button2 = new Button (shell, DWT.PUSH); + button2.setText ("Button 2"); + + auto form = new FormLayout (); + shell.setLayout (form); + + auto button1Data = new FormData (); + button1Data.left = new FormAttachment (0, 0); + button1Data.right = new FormAttachment (sash, 0); + button1Data.top = new FormAttachment (0, 0); + button1Data.bottom = new FormAttachment (100, 0); + button1.setLayoutData (button1Data); + + int limit = 20, percent = 50; + auto sashData = new FormData (); + sashData.left = new FormAttachment (percent, 0); + sashData.top = new FormAttachment (0, 0); + sashData.bottom = new FormAttachment (100, 0); + sash.setLayoutData (sashData); + sash.addListener (DWT.Selection, new class Listener { + public void handleEvent (Event e) { + auto sashRect = sash.getBounds (); + auto shellRect = shell.getClientArea (); + int right = shellRect.width - sashRect.width - limit; + e.x = Math.max (Math.min (e.x, right), limit); + if (e.x !is sashRect.x) { + sashData.left = new FormAttachment (0, e.x); + shell.layout (); + } + } + }); + + auto button2Data = new FormData (); + button2Data.left = new FormAttachment (sash, 0); + button2Data.right = new FormAttachment (100, 0); + button2Data.top = new FormAttachment (0, 0); + button2Data.bottom = new FormAttachment (100, 0); + button2.setLayoutData (button2Data); + + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/sashform/Snippet109.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/sashform/Snippet109.d Sat May 10 13:32:45 2008 -0700 @@ -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 + * Port to the D programming language: + * Bill Baxter + *******************************************************************************/ +module snippets.sashform.Snippet109; + +/* + * SashForm example snippet: create a sash form with three children + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.custom.SashForm; +import dwt.layout.FillLayout; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Label; +import dwt.widgets.Button; +import dwt.widgets.Composite; + +void main () { + final Display display = new Display (); + Shell shell = new Shell(display); + shell.setLayout (new FillLayout()); + + SashForm form = new SashForm(shell,DWT.HORIZONTAL); + form.setLayout(new FillLayout()); + + Composite child1 = new Composite(form,DWT.NONE); + child1.setLayout(new FillLayout()); + (new Label(child1,DWT.NONE)).setText("Label in pane 1"); + + Composite child2 = new Composite(form,DWT.NONE); + child2.setLayout(new FillLayout()); + (new Button(child2,DWT.PUSH)).setText("Button in pane2"); + + Composite child3 = new Composite(form,DWT.NONE); + child3.setLayout(new FillLayout()); + (new Label(child3,DWT.PUSH)).setText("Label in pane3"); + + form.setWeights([30,40,30]); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/shell/Snippet134.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/shell/Snippet134.d Sat May 10 13:32:45 2008 -0700 @@ -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 snippets.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 04f122e90b0a -r 4a04b6759f98 snippets/shell/Snippet138.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/shell/Snippet138.d Sat May 10 13:32:45 2008 -0700 @@ -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 + * Port to the D programming language: + * Bill Baxter + *******************************************************************************/ +module snippets.shell.Snippet138; + +/* + * example snippet: set icons with different resolutions + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ +import dwt.DWT; +import dwt.graphics.GC; +import dwt.graphics.Image; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +void main() { + Display display = new Display(); + + Image small = new Image(display, 16, 16); + GC gc = new GC(small); + gc.setBackground(display.getSystemColor(DWT.COLOR_RED)); + gc.fillArc(0, 0, 16, 16, 45, 270); + gc.dispose(); + + Image large = new Image(display, 32, 32); + gc = new GC(large); + gc.setBackground(display.getSystemColor(DWT.COLOR_RED)); + gc.fillArc(0, 0, 32, 32, 45, 270); + gc.dispose(); + + /* Provide different resolutions for icons to get + * high quality rendering wherever the OS needs + * large icons. For example, the ALT+TAB window + * on certain systems uses a larger icon. + */ + Shell shell = new Shell(display); + shell.setText("Small and Large icons"); + shell.setImages([small, large]); + + /* No large icon: the OS will scale up the + * small icon when it needs a large one. + */ + Shell shell2 = new Shell(display); + shell2.setText("Small icon"); + shell2.setImage(small); + + shell.open(); + shell2.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + small.dispose(); + large.dispose(); + display.dispose(); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/spinner/Snippet184.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/spinner/Snippet184.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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 + * Port to the D programming language: + * Bill Baxter + *******************************************************************************/ +module snippets.spinner.Snippet184; + +/* + * Spinner example snippet: create and initialize a spinner widget + * + * For a list of all DWT 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.Spinner; + +void main() { + Display display = new Display(); + Shell shell = new Shell(display); + Spinner spinner = new Spinner (shell, DWT.BORDER); + spinner.setMinimum(0); + spinner.setMaximum(1000); + spinner.setSelection(500); + spinner.setIncrement(1); + spinner.setPageIncrement(100); + spinner.pack(); + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/spinner/Snippet190.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/spinner/Snippet190.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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 + * Port to the D programming language: + * Bill Baxter + *******************************************************************************/ +module snippets.spinner.Snippet190; + +import dwt.DWT; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Spinner; +import dwt.events.SelectionAdapter; +import dwt.events.SelectionEvent; +import dwt.layout.GridLayout; + +import Math = tango.math.Math; +import tango.io.Stdout; + +/* + * Floating point values in Spinner + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.1 + */ + +void main () { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setText("Spinner with float values"); + shell.setLayout(new GridLayout()); + final Spinner spinner = new Spinner(shell, DWT.NONE); + // allow 3 decimal places + spinner.setDigits(3); + // set the minimum value to 0.001 + spinner.setMinimum(1); + // set the maximum value to 20 + spinner.setMaximum(20000); + // set the increment value to 0.010 + spinner.setIncrement(10); + // set the seletion to 3.456 + spinner.setSelection(3456); + spinner.addSelectionListener(new class() SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + int selection = spinner.getSelection(); + float digits = spinner.getDigits(); + Stdout.formatln("Selection is {}", selection / Math.pow(10.f, digits)); + } + }); + shell.setSize(200, 200); + shell.open(); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/styledtext/Snippet163.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/styledtext/Snippet163.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,65 @@ +/******************************************************************************* + * 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: + * Jesse Phillips gmail.com + *******************************************************************************/ + +module snippets.styledtext.Snippet163; + +/* + * Setting the font style, foreground and background colors of StyledText + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.custom.StyledText; +import dwt.custom.StyleRange; +import dwt.layout.FillLayout; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +version(JIVE){ + import jive.stacktrace; +} + +void main() { + auto display = new Display(); + auto shell = new Shell(display); + shell.setLayout(new FillLayout()); + auto text = new StyledText (shell, DWT.BORDER); + text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ"); + // make 0123456789 appear bold + auto style1 = new StyleRange(); + style1.start = 0; + style1.length = 10; + style1.fontStyle = DWT.BOLD; + text.setStyleRange(style1); + // make ABCDEFGHIJKLM have a red font + auto style2 = new StyleRange(); + style2.start = 11; + style2.length = 13; + style2.foreground = display.getSystemColor(DWT.COLOR_RED); + text.setStyleRange(style2); + // make NOPQRSTUVWXYZ have a blue background + auto style3 = new StyleRange(); + style3.start = 25; + style3.length = 13; + style3.background = display.getSystemColor(DWT.COLOR_BLUE); + text.setStyleRange(style3); + + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/styledtext/Snippet189.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/styledtext/Snippet189.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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: + * Jesse Phillips gmail.com + *******************************************************************************/ + +module snippets.styledtext.Snippet189; + +/* + * Text with underline and strike through + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.1 + */ + +import dwt.DWT; +import dwt.custom.StyledText; +import dwt.custom.StyleRange; +import dwt.layout.FillLayout; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +void main () { + auto display = new Display (); + auto shell = new Shell (display); + shell.setText("StyledText with underline and strike through"); + shell.setLayout(new FillLayout()); + auto text = new StyledText (shell, DWT.BORDER); + text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ"); + // make 0123456789 appear underlined + auto style1 = new StyleRange(); + style1.start = 0; + style1.length = 10; + style1.underline = true; + text.setStyleRange(style1); + // make ABCDEFGHIJKLM have a strike through + auto style2 = new StyleRange(); + style2.start = 11; + style2.length = 13; + style2.strikeout = true; + text.setStyleRange(style2); + // make NOPQRSTUVWXYZ appear underlined and have a strike through + auto style3 = new StyleRange(); + style3.start = 25; + style3.length = 13; + style3.underline = true; + style3.strikeout = true; + text.setStyleRange(style3); + shell.pack(); + shell.open(); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/table/Snippet144.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/table/Snippet144.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,75 @@ +/******************************************************************************* + * 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 gmail.com + *******************************************************************************/ +module snippets.table.Snippet144; + +/* + * Virtual Table example snippet: create a table with 1,000,000 items (lazy) + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ +import dwt.DWT; +import dwt.widgets.Button; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Label; +import dwt.widgets.Listener; +import dwt.widgets.Shell; +import dwt.widgets.Table; +import dwt.widgets.TableItem; +import dwt.layout.RowLayout; +import dwt.layout.RowData; + +import tango.io.Stdout; +import tango.time.StopWatch; +import tango.util.Convert; + +const int COUNT = 1000000; + +void main() { + auto display = new Display (); + auto shell = new Shell (display); + shell.setLayout (new RowLayout (DWT.VERTICAL)); + auto table = new Table (shell, DWT.VIRTUAL | DWT.BORDER); + table.addListener (DWT.SetData, new class Listener { + public void handleEvent (Event event) { + auto item = cast(TableItem) event.item; + auto index = table.indexOf (item); + item.setText ("Item " ~ to!(char[])(index)); + Stdout(item.getText ()).newline; + } + }); + table.setLayoutData (new RowData (200, 200)); + auto button = new Button (shell, DWT.PUSH); + button.setText ("Add Items"); + auto label = new Label(shell, DWT.NONE); + button.addListener (DWT.Selection, new class Listener { + public void handleEvent (Event event) { + StopWatch elapsed; + elapsed.start; + table.setItemCount (COUNT); + auto t = elapsed.stop; + label.setText ("Items: " ~ to!(char[])(COUNT) ~ + ", Time: " ~ to!(char[])(t) ~ " (sec)"); + shell.layout (); + } + }); + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/table/Snippet38.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/table/Snippet38.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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 gmail.com + *******************************************************************************/ +module snippets.table.Snippet38; + +/* + * Table example snippet: create a table (columns, headers, lines) + * + * 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.Table; +import dwt.widgets.TableColumn; +import dwt.widgets.TableItem; + +import tango.util.Convert; + +void main () { + auto display = new Display (); + auto shell = new Shell (display); + auto table = new Table (shell, DWT.MULTI | DWT.BORDER | DWT.FULL_SELECTION); + table.setLinesVisible (true); + table.setHeaderVisible (true); + char[][] titles = [" ", "C", "!", "Description", "Resource", "In Folder", "Location"]; + int[] styles = [DWT.NONE, DWT.LEFT, DWT.RIGHT, DWT.CENTER, DWT.NONE, DWT.NONE, DWT.NONE]; + foreach (i,title; titles) { + auto column = new TableColumn (table, styles[i]); + column.setText (title); + } + int count = 128; + for (int i=0; i gmail.com + *******************************************************************************/ + +module snippets.text.Snippet258; + +/* + * Create a search text control + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @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 tango.io.Stdout; + +void main() { + auto display = new Display(); + auto shell = new Shell(display); + shell.setLayout(new GridLayout(2, false)); + + auto text = new Text(shell, DWT.SEARCH | DWT.CANCEL); + Image image = null; + if ((text.getStyle() & DWT.CANCEL) == 0) { + image = new Image (display, new ImageData(new ByteArrayInputStream( cast(byte[]) import("cancel.gif" )))); + auto toolBar = new ToolBar (shell, DWT.FLAT); + auto item = new ToolItem (toolBar, DWT.PUSH); + item.setImage (image); + item.addSelectionListener(new class SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + text.setText(""); + Stdout("Search cancelled").newline; + } + }); + } + text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + text.setText("Search text"); + text.addSelectionListener(new class SelectionAdapter { + public void widgetDefaultSelected(SelectionEvent e) { + if (e.detail == DWT.CANCEL) { + Stdout("Search cancelled").newline; + } else { + Stdout("Searching for: ")(text.getText())("...").newline; + } + } + }); + + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + if (image !is null) image.dispose(); + display.dispose(); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/toolbar/Snippet153.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/toolbar/Snippet153.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,62 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.toolbar.Snippet153; + +/* + * ToolBar example snippet: update a status line when the pointer enters a ToolItem + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.events.MouseEvent; +import dwt.events.MouseMoveListener; +import dwt.graphics.Point; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; +import dwt.widgets.Label; + +static char[] statusText = ""; +void main() { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setBounds(10, 10, 200, 200); + ToolBar bar = new ToolBar(shell, DWT.BORDER); + bar.setBounds(10, 10, 150, 50); + Label statusLine = new Label(shell, DWT.BORDER); + statusLine.setBounds(10, 90, 150, 30); + (new ToolItem(bar, DWT.NONE)).setText("item 1"); + (new ToolItem(bar, DWT.NONE)).setText("item 2"); + (new ToolItem(bar, DWT.NONE)).setText("item 3"); + bar.addMouseMoveListener(new class MouseMoveListener { + void mouseMove(MouseEvent e) { + ToolItem item = bar.getItem(new Point(e.x, e.y)); + char[] name = ""; + if (item !is null) { + name = item.getText(); + } + if (statusText != name) { + statusLine.setText(name); + statusText = name; + } + } + }); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + display.dispose(); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/toolbar/Snippet288.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/toolbar/Snippet288.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,208 @@ +/******************************************************************************* + * Copyright (c) 2008 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 + *******************************************************************************/ +module snippets.toolbar.Snippet288; + +/* + * Create a ToolBar containing animated GIFs + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.DWTException; +import dwt.graphics.GC; +import dwt.graphics.Color; +import dwt.graphics.Image; +import dwt.graphics.ImageLoader; +import dwt.graphics.ImageData; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; +import dwt.widgets.FileDialog; +import dwt.dwthelper.Runnable; + +import tango.io.FilePath; +import tango.io.FileConst; +import tango.core.Thread; +import tango.io.Stdout; +import tango.util.Convert; +import tango.core.Exception; + +static Display display; +static Shell shell; +static GC shellGC; +static Color shellBackground; +static ImageLoader[] loader; +static ImageData[][] imageDataArray; +static Thread[] animateThread; +static Image[][] image; +private static ToolItem[] item; +static final bool useGIFBackground = false; + +void main () { + display = new Display(); + Shell shell = new Shell (display); + shellBackground = shell.getBackground(); + FileDialog dialog = new FileDialog(shell, DWT.OPEN | DWT.MULTI); + dialog.setText("Select Multiple Animated GIFs"); + dialog.setFilterExtensions(["*.gif"]); + char[] filename = dialog.open(); + char[][] filenames = dialog.getFileNames(); + int numToolBarItems = filenames.length; + if (numToolBarItems > 0) { + try { + loadAllImages((new FilePath(filename)).parent, filenames); + } catch (DWTException e) { + Stdout.print("There was an error loading an image.").newline; + e.printStackTrace(); + } + ToolBar toolBar = new ToolBar (shell, DWT.FLAT | DWT.BORDER | DWT.WRAP); + item = new ToolItem[numToolBarItems]; + for (int i = 0; i < numToolBarItems; i++) { + item[i] = new ToolItem (toolBar, DWT.PUSH); + item[i].setImage(image[i][0]); + } + toolBar.pack (); + shell.open (); + + startAnimationThreads(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch ()) display.sleep (); + } + + for (int i = 0; i < numToolBarItems; i++) { + for (int j = 0; j < image[i].length; j++) { + image[i][j].dispose(); + } + } + display.dispose (); + } + thread_joinAll(); +} + +private static void loadAllImages(char[] directory, char[][] filenames) { + int numItems = filenames.length; + loader.length = numItems; + imageDataArray.length = numItems; + image.length = numItems; + for (int i = 0; i < numItems; i++) { + loader[i] = new ImageLoader(); + int fullWidth = loader[i].logicalScreenWidth; + int fullHeight = loader[i].logicalScreenHeight; + imageDataArray[i] = loader[i].load(directory ~ FileConst.PathSeparatorChar ~ filenames[i]); + int numFramesOfAnimation = imageDataArray[i].length; + image[i] = new Image[numFramesOfAnimation]; + for (int j = 0; j < numFramesOfAnimation; j++) { + if (j == 0) { + //for the first frame of animation, just draw the first frame + image[i][j] = new Image(display, imageDataArray[i][j]); + fullWidth = imageDataArray[i][j].width; + fullHeight = imageDataArray[i][j].height; + } + else { + //after the first frame of animation, draw the background or previous frame first, then the new image data + image[i][j] = new Image(display, fullWidth, fullHeight); + GC gc = new GC(image[i][j]); + gc.setBackground(shellBackground); + gc.fillRectangle(0, 0, fullWidth, fullHeight); + ImageData imageData = imageDataArray[i][j]; + switch (imageData.disposalMethod) { + case DWT.DM_FILL_BACKGROUND: + /* Fill with the background color before drawing. */ + Color bgColor = null; + if (useGIFBackground && loader[i].backgroundPixel != -1) { + bgColor = new Color(display, imageData.palette.getRGB(loader[i].backgroundPixel)); + } + gc.setBackground(bgColor !is null ? bgColor : shellBackground); + gc.fillRectangle(imageData.x, imageData.y, imageData.width, imageData.height); + if (bgColor !is null) bgColor.dispose(); + break; + default: + /* Restore the previous image before drawing. */ + gc.drawImage( + image[i][j-1], + 0, + 0, + fullWidth, + fullHeight, + 0, + 0, + fullWidth, + fullHeight); + break; + } + Image newFrame = new Image(display, imageData); + gc.drawImage(newFrame, + 0, + 0, + imageData.width, + imageData.height, + imageData.x, + imageData.y, + imageData.width, + imageData.height); + newFrame.dispose(); + gc.dispose(); + } + } + } +} + +private static void startAnimationThreads() { + animateThread = new Thread[image.length]; + for (int ii = 0; ii < image.length; ii++) { + animateThread[ii] = new class(ii) Thread { + int imageDataIndex = 0; + int id = 0; + this(int _id) { + id = _id; + name = "Animation "~to!(char[])(ii); + isDaemon = true; + super(&run); + } + void run() { + try { + int repeatCount = loader[id].repeatCount; + while (loader[id].repeatCount == 0 || repeatCount > 0) { + imageDataIndex = (imageDataIndex + 1) % imageDataArray[id].length; + if (!display.isDisposed()) { + display.asyncExec(new class Runnable { + public void run() { + if (!item[id].isDisposed()) + item[id].setImage(image[id][imageDataIndex]); + } + }); + } + + /* Sleep for the specified delay time (adding commonly-used slow-down fudge factors). */ + try { + int ms = imageDataArray[id][imageDataIndex].delayTime * 10; + if (ms < 20) ms += 30; + if (ms < 30) ms += 10; + Thread.sleep(0.001*ms); + } catch (ThreadException e) { + } + + /* If we have just drawn the last image, decrement the repeat count and start again. */ + if (imageDataIndex == imageDataArray[id].length - 1) repeatCount--; + } + } catch (DWTException ex) { + Stdout.print("There was an error animating the GIF").newline; + ex.printStackTrace(); + } + } + }; + animateThread[ii].start(); + } +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/toolbar/Snippet47.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/toolbar/Snippet47.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,74 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.toolbar.Snippet47; + +/* + * ToolBar example snippet: create tool bar (normal, hot and disabled images) + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.graphics.GC; +import dwt.graphics.Color; +import dwt.graphics.Image; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; + +void main () { + Display display = new Display (); + Shell shell = new Shell (display); + + Image image = new Image (display, 20, 20); + Color color = display.getSystemColor (DWT.COLOR_BLUE); + GC gc = new GC (image); + gc.setBackground (color); + gc.fillRectangle (image.getBounds ()); + gc.dispose (); + + Image disabledImage = new Image (display, 20, 20); + color = display.getSystemColor (DWT.COLOR_GREEN); + gc = new GC (disabledImage); + gc.setBackground (color); + gc.fillRectangle (disabledImage.getBounds ()); + gc.dispose (); + + Image hotImage = new Image (display, 20, 20); + color = display.getSystemColor (DWT.COLOR_RED); + gc = new GC (hotImage); + gc.setBackground (color); + gc.fillRectangle (hotImage.getBounds ()); + gc.dispose (); + + ToolBar bar = new ToolBar (shell, DWT.BORDER | DWT.FLAT); + bar.setSize (200, 32); + for (int i=0; i<12; i++) { + ToolItem item = new ToolItem (bar, 0); + item.setImage (image); + item.setDisabledImage (disabledImage); + item.setHotImage (hotImage); + if (i % 3 == 0) item.setEnabled (false); + } + + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + image.dispose (); + disabledImage.dispose (); + hotImage.dispose (); + display.dispose (); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/toolbar/Snippet49.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/toolbar/Snippet49.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,56 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.toolbar.Snippet49; + +/* + * ToolBar example snippet: create tool bar (wrap on resize) + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.graphics.Rectangle; +import dwt.graphics.Point; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; +import dwt.widgets.Event; +import dwt.widgets.Listener; + +import tango.util.Convert; + +void main () { + Display display = new Display (); + Shell shell = new Shell (display); + ToolBar toolBar = new ToolBar (shell, DWT.WRAP); + for (int i=0; i<12; i++) { + ToolItem item = new ToolItem (toolBar, DWT.PUSH); + item.setText ("Item " ~ to!(char[])(i)); + } + shell.addListener (DWT.Resize, new class Listener { + void handleEvent (Event e) { + Rectangle rect = shell.getClientArea (); + Point size = toolBar.computeSize (rect.width, DWT.DEFAULT); + toolBar.setSize (size); + } + }); + toolBar.pack (); + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/toolbar/Snippet58.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/toolbar/Snippet58.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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: + * Bill Baxter + *******************************************************************************/ +module snippets.toolbar.Snippet58; + +/* + * ToolBar example snippet: place a combo box in a tool bar + * + * 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.Shell; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; +import dwt.widgets.Combo; + +import tango.util.Convert; + +void main () { + Display display = new Display (); + Shell shell = new Shell (display); + ToolBar bar = new ToolBar (shell, DWT.BORDER); + for (int i=0; i<4; i++) { + ToolItem item = new ToolItem (bar, 0); + item.setText ("Item " ~ to!(char[])(i)); + } + ToolItem sep = new ToolItem (bar, DWT.SEPARATOR); + int start = bar.getItemCount (); + for (int i=start; i + *******************************************************************************/ +module snippets.toolbar.Snippet67; + +/* + * ToolBar example snippet: place a drop down menu in a tool bar + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.graphics.Rectangle; +import dwt.graphics.Point; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.Listener; +import dwt.widgets.Event; + +import tango.util.Convert; + +void main () { + Display display = new Display (); + Shell shell = new Shell (display); + ToolBar toolBar = new ToolBar (shell, DWT.NONE); + Menu menu = new Menu (shell, DWT.POP_UP); + for (int i=0; i<8; i++) { + MenuItem item = new MenuItem (menu, DWT.PUSH); + item.setText ("Item " ~ to!(char[])(i)); + } + ToolItem item = new ToolItem (toolBar, DWT.DROP_DOWN); + item.addListener (DWT.Selection, new class Listener { + void handleEvent (Event event) { + if (event.detail == DWT.ARROW) { + Rectangle rect = item.getBounds (); + Point pt = new Point (rect.x, rect.y + rect.height); + pt = toolBar.toDisplay (pt); + menu.setLocation (pt.x, pt.y); + menu.setVisible (true); + } + } + }); + toolBar.pack (); + shell.pack (); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + menu.dispose (); + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/tooltips/Snippet41.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/tooltips/Snippet41.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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: + * Jesse Phillips gmail.com + *******************************************************************************/ + +module snippets.tooltips.Snippet41; + +/* + * Tool Tips example snippet: create tool tips for a tab item, tool item, and shell + * + * 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.Shell; +import dwt.widgets.TabFolder; +import dwt.widgets.TabItem; +import dwt.widgets.ToolBar; +import dwt.widgets.ToolItem; + +void main () { + auto string = "This is a string\nwith a new line."; + auto display = new Display (); + auto shell = new Shell (display); + + TabFolder folder = new TabFolder (shell, DWT.BORDER); + + folder.setSize (200, 200); + auto item0 = new TabItem (folder, 0); + item0.setText( "Text" ); + item0.setToolTipText ("TabItem toolTip: " ~ string); + + auto bar = new ToolBar (shell, DWT.BORDER); + bar.setBounds (0, 200, 200, 64); + + ToolItem item1 = new ToolItem (bar, 0); + item1.setText( "Text" ); + item1.setToolTipText ("ToolItem toolTip: " ~ string); + shell.setToolTipText ("Shell toolTip: " ~ string); + + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/tray/Snippet143.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/tray/Snippet143.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,95 @@ +/******************************************************************************* + * 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 + * Port to the D programming language + * Frank Benoit + *******************************************************************************/ +module snippets.tray.Snippet143; + +/* + * Tray example snippet: place an icon with a popup menu on the system tray + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + * + * @since 3.0 + */ +import dwt.DWT; +import dwt.graphics.Image; +import dwt.widgets.Shell; +import dwt.widgets.Display; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; +import dwt.widgets.Tray; +import dwt.widgets.TrayItem; +import dwt.widgets.Listener; +import dwt.widgets.Event; +import tango.io.Stdout; +import tango.text.convert.Format; + +TrayItem item; +Menu menu; + +public static void main(char[][] args) { + Display display = new Display (); + Shell shell = new Shell (display); + Image image = new Image (display, 16, 16); + final Tray tray = display.getSystemTray (); + if (tray is null) { + Stdout.formatln ("The system tray is not available"); + } else { + item = new TrayItem (tray, DWT.NONE); + item.setToolTipText("DWT TrayItem"); + item.addListener (DWT.Show, new class() Listener { + public void handleEvent (Event event) { + Stdout.formatln("show"); + } + }); + item.addListener (DWT.Hide, new class() Listener { + public void handleEvent (Event event) { + Stdout.formatln("hide"); + } + }); + item.addListener (DWT.Selection, new class() Listener { + public void handleEvent (Event event) { + Stdout.formatln("selection"); + } + }); + item.addListener (DWT.DefaultSelection, new class() Listener { + public void handleEvent (Event event) { + Stdout.formatln("default selection"); + } + }); + menu = new Menu (shell, DWT.POP_UP); + for (int i = 0; i < 8; i++) { + MenuItem mi = new MenuItem (menu, DWT.PUSH); + mi.setText ( Format( "Item{}", i )); + mi.addListener (DWT.Selection, new class() Listener { + public void handleEvent (Event event) { + Stdout.formatln("selection {}", event.widget); + } + }); + if (i == 0) menu.setDefaultItem(mi); + } + item.addListener (DWT.MenuDetect, new class() Listener { + public void handleEvent (Event event) { + menu.setVisible (true); + } + }); + item.setImage (image); + } + shell.setBounds(50, 50, 300, 200); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + image.dispose (); + display.dispose (); +} + diff -r 04f122e90b0a -r 4a04b6759f98 snippets/tree/Snippet15.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/tree/Snippet15.d Sat May 10 13:32:45 2008 -0700 @@ -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: + * Jesse Phillips gmail.com + *******************************************************************************/ +module snippets.tree.Snippet15; + +/* + * Tree example snippet: create a tree + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.layout.FillLayout; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Tree; +import dwt.widgets.TreeItem; + +import tango.util.Convert; + +void main () { + auto display = new Display (); + auto shell = new Shell (display); + shell.setLayout(new FillLayout()); + auto tree = new Tree (shell, DWT.BORDER); + for (int i=0; i<4; i++) { + auto iItem = new TreeItem (tree, 0); + iItem.setText ("TreeItem (0) -" ~ to!(char[])(i)); + for (int j=0; j<4; j++) { + TreeItem jItem = new TreeItem (iItem, 0); + jItem.setText ("TreeItem (1) -" ~ to!(char[])(j)); + for (int k=0; k<4; k++) { + TreeItem kItem = new TreeItem (jItem, 0); + kItem.setText ("TreeItem (2) -" ~ to!(char[])(k)); + for (int l=0; l<4; l++) { + TreeItem lItem = new TreeItem (kItem, 0); + lItem.setText ("TreeItem (3) -" ~ to!(char[])(l)); + } + } + } + } + shell.setSize (200, 200); + shell.open (); + while (!shell.isDisposed()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +} diff -r 04f122e90b0a -r 4a04b6759f98 snippets/tree/Snippet8.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snippets/tree/Snippet8.d Sat May 10 13:32:45 2008 -0700 @@ -0,0 +1,79 @@ +/******************************************************************************* + * 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 gmail.com + *******************************************************************************/ +module snippets.tree.Snippet8; + +/* + * Tree example snippet: create a tree (lazy) + * + * For a list of all DWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ + +import dwt.DWT; +import dwt.layout.FillLayout; +import dwt.graphics.Point; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Shell; +import dwt.widgets.Tree; +import dwt.widgets.TreeItem; + +import dwt.dwthelper.utils; +import tango.io.FilePath; +import tango.io.FileRoots; + +void main () { + auto display = new Display (); + auto shell = new Shell (display); + shell.setText ("Lazy Tree"); + shell.setLayout (new FillLayout ()); + auto tree = new Tree (shell, DWT.BORDER); + auto roots = FileRoots.list(); + foreach (file; roots) { + auto root = new TreeItem (tree, 0); + root.setText (file); + root.setData (new FilePath(file)); + new TreeItem (root, 0); + } + tree.addListener (DWT.Expand, new class Listener { + public void handleEvent (Event event) { + auto root = cast(TreeItem) event.item; + auto items = root.getItems (); + foreach(item; items) { + if (item.getData () !is null) return; + item.dispose (); + } + auto file = cast(FilePath) root.getData (); + auto files = file.toList(); + if (files is null) return; + foreach (f; files) { + TreeItem item = new TreeItem (root, 0); + item.setText (f.toString()); + item.setData (f); + if (f.isFolder()) { + new TreeItem (item, 0); + } + } + } + }); + auto size = tree.computeSize (300, DWT.DEFAULT); + auto width = Math.max (300, size.x); + auto height = Math.max (300, size.y); + shell.setSize (shell.computeSize (width, height)); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); +}