comparison dwtsnippets/coolbar/Snippet140.d @ 46:798c6c92c4e2

fix indention
author Frank Benoit <benoit@tionex.de>
date Sun, 06 Apr 2008 15:31:24 +0200
parents 5a5be20dc120
children
comparison
equal deleted inserted replaced
45:5a5be20dc120 46:798c6c92c4e2
41 static CoolBar coolBar; 41 static CoolBar coolBar;
42 static Menu chevronMenu = null; 42 static Menu chevronMenu = null;
43 43
44 44
45 void main () { 45 void main () {
46 display = new Display (); 46 display = new Display ();
47 shell = new Shell (display); 47 shell = new Shell (display);
48 shell.setLayout(new GridLayout()); 48 shell.setLayout(new GridLayout());
49 coolBar = new CoolBar(shell, DWT.FLAT | DWT.BORDER); 49 coolBar = new CoolBar(shell, DWT.FLAT | DWT.BORDER);
50 coolBar.setLayoutData(new GridData(GridData.FILL_BOTH)); 50 coolBar.setLayoutData(new GridData(GridData.FILL_BOTH));
51 ToolBar toolBar = new ToolBar(coolBar, DWT.FLAT | DWT.WRAP); 51 ToolBar toolBar = new ToolBar(coolBar, DWT.FLAT | DWT.WRAP);
52 int minWidth = 0; 52 int minWidth = 0;
53 for (int j = 0; j < 5; j++) { 53 for (int j = 0; j < 5; j++) {
54 int width = 0; 54 int width = 0;
55 ToolItem item = new ToolItem(toolBar, DWT.PUSH); 55 ToolItem item = new ToolItem(toolBar, DWT.PUSH);
56 item.setText("B" ~ to!(char[])(j)); 56 item.setText("B" ~ to!(char[])(j));
57 width = item.getWidth(); 57 width = item.getWidth();
58 /* find the width of the widest tool */ 58 /* find the width of the widest tool */
59 if (width > minWidth) minWidth = width; 59 if (width > minWidth) minWidth = width;
60 }
61 CoolItem coolItem = new CoolItem(coolBar, DWT.DROP_DOWN);
62 coolItem.setControl(toolBar);
63 Point size = toolBar.computeSize(DWT.DEFAULT, DWT.DEFAULT);
64 Point coolSize = coolItem.computeSize (size.x, size.y);
65 coolItem.setMinimumSize(minWidth, coolSize.y);
66 coolItem.setPreferredSize(coolSize);
67 coolItem.setSize(coolSize);
68 coolItem.addSelectionListener(new class() SelectionAdapter {
69 public void widgetSelected(SelectionEvent event) {
70 if (event.detail == DWT.ARROW) {
71 CoolItem item = cast(CoolItem) event.widget;
72 Rectangle itemBounds = item.getBounds ();
73 Point pt = coolBar.toDisplay(new Point(itemBounds.x, itemBounds.y));
74 itemBounds.x = pt.x;
75 itemBounds.y = pt.y;
76 ToolBar bar = cast(ToolBar) item.getControl ();
77 ToolItem[] tools = bar.getItems ();
78
79 int i = 0;
80 while (i < tools.length) {
81 Rectangle toolBounds = tools[i].getBounds ();
82 pt = bar.toDisplay(new Point(toolBounds.x, toolBounds.y));
83 toolBounds.x = pt.x;
84 toolBounds.y = pt.y;
85
86 /* Figure out the visible portion of the tool by looking at the
87 * intersection of the tool bounds with the cool item bounds.
88 */
89 Rectangle intersection = itemBounds.intersection (toolBounds);
90
91 /* If the tool is not completely within the cool item bounds, then it
92 * is partially hidden, and all remaining tools are completely hidden.
93 */
94 if (intersection != toolBounds) break;
95 i++;
96 }
97
98 /* Create a menu with items for each of the completely hidden buttons. */
99 if (chevronMenu !is null) chevronMenu.dispose();
100 chevronMenu = new Menu (coolBar);
101 for (int j = i; j < tools.length; j++) {
102 MenuItem menuItem = new MenuItem (chevronMenu, DWT.PUSH);
103 menuItem.setText (tools[j].getText());
104 }
105
106 /* Drop down the menu below the chevron, with the left edges aligned. */
107 pt = coolBar.toDisplay(new Point(event.x, event.y));
108 chevronMenu.setLocation (pt.x, pt.y);
109 chevronMenu.setVisible (true);
110 }
60 } 111 }
61 CoolItem coolItem = new CoolItem(coolBar, DWT.DROP_DOWN); 112 });
62 coolItem.setControl(toolBar);
63 Point size = toolBar.computeSize(DWT.DEFAULT, DWT.DEFAULT);
64 Point coolSize = coolItem.computeSize (size.x, size.y);
65 coolItem.setMinimumSize(minWidth, coolSize.y);
66 coolItem.setPreferredSize(coolSize);
67 coolItem.setSize(coolSize);
68 coolItem.addSelectionListener(new class() SelectionAdapter {
69 public void widgetSelected(SelectionEvent event) {
70 if (event.detail == DWT.ARROW) {
71 CoolItem item = cast(CoolItem) event.widget;
72 Rectangle itemBounds = item.getBounds ();
73 Point pt = coolBar.toDisplay(new Point(itemBounds.x, itemBounds.y));
74 itemBounds.x = pt.x;
75 itemBounds.y = pt.y;
76 ToolBar bar = cast(ToolBar) item.getControl ();
77 ToolItem[] tools = bar.getItems ();
78 113
79 int i = 0; 114 shell.pack();
80 while (i < tools.length) { 115 shell.open ();
81 Rectangle toolBounds = tools[i].getBounds (); 116 while (!shell.isDisposed ()) {
82 pt = bar.toDisplay(new Point(toolBounds.x, toolBounds.y)); 117 if (!display.readAndDispatch ()) display.sleep ();
83 toolBounds.x = pt.x; 118 }
84 toolBounds.y = pt.y; 119 display.dispose ();
85
86 /* Figure out the visible portion of the tool by looking at the
87 * intersection of the tool bounds with the cool item bounds. */
88 Rectangle intersection = itemBounds.intersection (toolBounds);
89
90 /* If the tool is not completely within the cool item bounds, then it
91 * is partially hidden, and all remaining tools are completely hidden. */
92 if (intersection != toolBounds) break;
93 i++;
94 }
95
96 /* Create a menu with items for each of the completely hidden buttons. */
97 if (chevronMenu !is null) chevronMenu.dispose();
98 chevronMenu = new Menu (coolBar);
99 for (int j = i; j < tools.length; j++) {
100 MenuItem menuItem = new MenuItem (chevronMenu, DWT.PUSH);
101 menuItem.setText (tools[j].getText());
102 }
103
104 /* Drop down the menu below the chevron, with the left edges aligned. */
105 pt = coolBar.toDisplay(new Point(event.x, event.y));
106 chevronMenu.setLocation (pt.x, pt.y);
107 chevronMenu.setVisible (true);
108 }
109 }
110 });
111
112 shell.pack();
113 shell.open ();
114 while (!shell.isDisposed ()) {
115 if (!display.readAndDispatch ()) display.sleep ();
116 }
117 display.dispose ();
118 } 120 }