Community
Participate
Working Groups
Build 20020730. 1. Run the attached test case. 2. Move the Search cool item over to the right, so that the first CoolItem's width gets bigger. 3. Press the Delete/Add button, which deletes than adds back the first CoolItem. Notice that the width of the first CoolItem is restored properly. 4. Press the Delete/Add button again, which executes the exact same code. Notice that the width of the first CoolItem is NOT restored properly.
Created attachment 1789 [details] test case jar file
In the step 3, besides remove the first item and add it back the code attempt (I suppose) to force the coolbar to layout in one row. To get this it calls: coolBar.setWrapIndices(new int[] {0}); It should be Ok, although it's unnecessary since the first item of the first row don't need to be marked as a wrap. Anyway it's causing this bug that I going to investigate. In this meantime, to get the same layout on the coolbar the code can use: coolBar.setWrapIndices(new int[] {});
That's the problem: call setWrapIndex (new int [] {0}) item at 0 becomes a BREAK remove Item at 0 new item at 0 becomes a BREAK add item at 0 now item at 1 remains a BREAK (this point coolbar has two rows) call setWrapIndex (new int [] {0}) the BREAK on item 1 is cleared item at 0 is resize to the preferred size (so that the coolbar returns to one row with no free item all way over to the right) Can be fixed: a) do not propagated the BREAK to following item when removing a item with BREAK at index 0 b) do not set BREAK flag for the item at index 0
the following test show a case where we can two rows just removing the first item and then adding it back: package coolbar.prs; import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.layout.*; public class CoolBarIconSizeTest { static Display display; static Shell shell; static CoolBar coolBar; static Menu popup = null; static String[][] toolNames = { {"new_wiz", null, "save", "saveas", "printer"}, {"search"}, {"script_wiz"}, {"debug", "run"}, {"opentype"}, }; public static void main (String [] args) { display = new Display (); shell = new Shell (display); shell.setLayout(new GridLayout()); coolBar = new CoolBar(shell, SWT.FLAT); GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = 600; data.heightHint = 70; coolBar.setLayoutData(data); for (int i = 0; i < toolNames.length; i ++) { ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT); String[] toolFileNames = toolNames[i]; for (int j = 0; j < toolFileNames.length; j++) { int width = 0; String fileName = toolFileNames[j]; if (fileName == null) { new ToolItem(toolBar, SWT.SEPARATOR); } else { ToolItem item = new ToolItem(toolBar, SWT.PUSH); item.setImage(createCoolBarIcon(display, toolFileNames[j])); } } CoolItem coolItem = new CoolItem(coolBar, SWT.DROP_DOWN); coolItem.setControl(toolBar); Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT); Point coolSize = coolItem.computeSize (size.x, size.y); coolItem.setMinimumSize (28,coolSize.y); coolItem.setPreferredSize(coolSize); coolItem.setSize(coolSize); } final Button delAddItem1 = new Button(shell, SWT.PUSH); delAddItem1.setText("Delete/Add Item"); delAddItem1.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { CoolItem cItem = coolBar.getItem(0); int x = coolBar.getItemSizes()[0].x; ToolBar tBar = (ToolBar)cItem.getControl(); cItem.setControl(null); tBar.dispose(); cItem.dispose(); ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT); String[] toolFileNames = toolNames[0]; for (int j = 0; j < toolFileNames.length; j++) { String fileName = toolFileNames[j]; if (fileName == null) { new ToolItem(toolBar, SWT.SEPARATOR); } else { ToolItem item = new ToolItem(toolBar, SWT.PUSH); item.setImage(createCoolBarIcon(display, toolFileNames[j])); } } CoolItem coolItem = new CoolItem(coolBar, SWT.DROP_DOWN, 0); coolItem.setControl(toolBar); Point toolSize = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT); Point coolSize = coolItem.computeSize (toolSize.x, toolSize.y); coolItem.setPreferredSize(coolSize); coolItem.setSize(new Point(x, coolSize.y)); System.out.println("x : " + x); } }); coolBar.setWrapIndices(new int[] {0}); shell.pack(); shell.open (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } static Image createCoolBarIcon(Display display, String fileName) { try { ImageData source = new ImageData (CoolBarIconSizeTest.class.getResourceAsStream(fileName + ".gif")); ImageData mask = source.getTransparencyMask(); return new Image(display, source, mask); } catch (Exception e) { } return null; } }
Fixed in HEAD and R2.0.1.