# HG changeset patch # User Frank Benoit # Date 1207488684 -7200 # Node ID 798c6c92c4e289e5e66a2f3dc1870b2640c51a92 # Parent 5a5be20dc12088592a7c61112a1adf1460b04079 fix indention diff -r 5a5be20dc120 -r 798c6c92c4e2 dwtsnippets/coolbar/Snippet140.d --- a/dwtsnippets/coolbar/Snippet140.d Sun Apr 06 15:26:23 2008 +0200 +++ b/dwtsnippets/coolbar/Snippet140.d Sun Apr 06 15:31:24 2008 +0200 @@ -43,76 +43,78 @@ 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 (); + 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; + 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); + /* 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++; - } + /* 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()); - } + /* 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); - } - } - }); + /* 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 (); + shell.pack(); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + display.dispose (); }