Bug 22144 - Coolbar - setSize not being honored after setWrapIndices API used
Summary: Coolbar - setSize not being honored after setWrapIndices API used
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.0   Edit
Hardware: Other other
: P3 normal (vote)
Target Milestone: 2.0.1   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-08-03 15:09 EDT by Lynne Kues CLA
Modified: 2002-08-21 15:09 EDT (History)
0 users

See Also:


Attachments
test case jar file (5.66 KB, application/octet-stream)
2002-08-03 15:10 EDT, Lynne Kues CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lynne Kues CLA 2002-08-03 15:09:51 EDT
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.
Comment 1 Lynne Kues CLA 2002-08-03 15:10:18 EDT
Created attachment 1789 [details]
test case jar file
Comment 2 Felipe Heidrich CLA 2002-08-07 12:14:54 EDT
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[] {});






Comment 3 Felipe Heidrich CLA 2002-08-07 14:24:39 EDT
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


Comment 4 Felipe Heidrich CLA 2002-08-07 14:28:49 EDT
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;
}
}


Comment 5 Steve Northover CLA 2002-08-08 12:07:11 EDT
Fixed in HEAD and R2.0.1.