Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 344392 - Bidi 3.7: Images in disabled ToolBar disappear when orientation changed (setOrientation) used.
Summary: Bidi 3.7: Images in disabled ToolBar disappear when orientation changed (setO...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 RC1   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-01 04:57 EDT by mariavin CLA
Modified: 2011-05-11 15:14 EDT (History)
10 users (show)

See Also:
Silenio_Quarti: review+


Attachments
picture of the problem. (21.76 KB, image/gif)
2011-05-01 04:58 EDT, mariavin CLA
no flags Details
patch - changes in ToolBar and ToolItem (8.07 KB, patch)
2011-05-10 08:42 EDT, Helena Halperin CLA
no flags Details | Diff
patch (4.80 KB, patch)
2011-05-11 13:39 EDT, Felipe Heidrich CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mariavin CLA 2011-05-01 04:57:26 EDT
Build Identifier: Build id: 20100617-1415

When ToolBar is disabled, use (couple of times) of setOrientation makes the images in ToolBar to disappear in original orientation. 
Let say we run in LTR GUI (ControlExamle - in org.eclipse.swt.examples.mirroringTest package.), if we disable the toolbar then click couple of times on the "set orientation SWT.LEFT_TO_RIGHT" the images begin to disappear (see steps to Reproduce).

Reproducible: Always

Steps to Reproduce:
attachment 194265 [details]
Steps to Reproduce:
1. Apply the attached patch on the "org.eclipse.swt.examples" project (project
level).
2. Go to org.eclipse.swt.examples.mirroringTest package.
3. Run the ControlExamle.
4. Go to the "Toolbar" Tab.
5. In "Others..." group the "Enabled..." option should be unchecked.
6. In "Orientation..." group choose "set orientation SWT.LEFT_TO_RIGHT".
resulrt - some of the icons disappeare. 
Notes: 
1. if you'll keep toggle between   "set orientation SWT.LEFT_TO_RIGHT" to " group choose "SWT.LEFT_TO_RIGHT" the icons eventually will all disapeare in the SWT.LEFT_TO_RIGHT view.
2. same happens (but oppositely) in the mirrored GUI you can use the ControlExamleRTL to reproduce.
Comment 1 mariavin CLA 2011-05-01 04:58:30 EDT
Created attachment 194436 [details]
picture of the problem.
Comment 2 Felipe Heidrich CLA 2011-05-02 10:24:53 EDT
This problem was spotted by Helena last week:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=341282#c13

Helena, do you have a fix ?

Note that your code in original patch is also wrong.
As long as we remove the image from one image list (by disposing it), and add to some other image list. The disabledImageList and the imageList will be out of sync.
Using ImageList#indexOf/ImageList#put is not correct. You fix the case for toolbar that is changing, but is possible some other toolbar has some other image at the same index that you are forcing the new image with ImageList#put, thus breaking another user.

Steps:
Run control example
Go to ToolBar tab
change (dynamically) the orientation to RTL
change back (dynamically) the orientation to LTR
uncheck the enable button
Go to CoolBar tab
(the images in the toolbar inside of the coolbar are wrong).
Comment 3 Felipe Heidrich CLA 2011-05-06 11:39:58 EDT
Helena, RC1 is next week. It would be good if we could get a fix by Mon or Tue. Thank you.
Comment 4 Helena Halperin CLA 2011-05-10 08:42:21 EDT
Created attachment 195203 [details]
patch - changes in ToolBar and ToolItem

To TooItem added indexes to store indexes of image in ImageList-ltr and ImageList-rtl. Also added disabledImage2Rtl to store disabled image, that is used in disabledImageList-rtl. When the item should be released, and function releaseImages is called, the images are removed from ltr and rtl image lists.
Comment 5 Felipe Heidrich CLA 2011-05-10 15:02:09 EDT
The code is still wrong.
Toolbars share image lists, but they never share the images in the image list.
You can't use ImageList#indexOf basically. It is possible that someother ToolBar has the same image as the toolbar that is changing, but you can never use the same image index cause one toolbar can disabled and other enabled...

Here is a test case, run it and press F1:
public static void main(String[] args) {
    Display display= new Display();
    Shell shell= new Shell(display);
    Image image0 = new Image (display, "build_exec.gif");
    Image image1 = new Image (display, "debug_exc.gif");
    
    final ToolBar bar = new ToolBar (shell, SWT.FLAT);
    ToolItem item0 = new ToolItem (bar, SWT.CHECK);
    item0.setText("1.");
    item0.setImage(image0);
    bar.setOrientation(SWT.RIGHT_TO_LEFT);
    bar.setOrientation(SWT.LEFT_TO_RIGHT);
    
    
    final ToolBar bar2 = new ToolBar (shell, SWT.FLAT | SWT.RIGHT_TO_LEFT );
	ToolItem item1 = new ToolItem (bar2, SWT.CHECK);
    item1.setText("2.");
    item1.setImage(image0);
    bar2.setEnabled(false);
    
    display.addFilter(SWT.KeyDown, new Listener() {
    	public void handleEvent(Event event) {
    		bar.setOrientation(bar.getOrientation() == SWT.RIGHT_TO_LEFT ? SWT.LEFT_TO_RIGHT : SWT.RIGHT_TO_LEFT);
    		bar2.redraw();
    	}
    });
    
    shell.setLayout(new GridLayout());
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}


----
Comment 6 Felipe Heidrich CLA 2011-05-10 15:43:39 EDT
Helena, what about this ?
I just wrote it up, can you break it ? does it leak or something ? pls help test.


void updateOrientation () {
	super.updateOrientation ();
	if (imageList != null) {
		Point size = imageList.getImageSize ();
		ImageList newImageList = display.getImageListToolBar (style & SWT.RIGHT_TO_LEFT, size.x, size.y);
		ImageList newHotImageList = display.getImageListToolBarHot (style & SWT.RIGHT_TO_LEFT, size.x, size.y);
		ImageList newDisabledImageList = display.getImageListToolBarDisabled (style & SWT.RIGHT_TO_LEFT, size.x, size.y);	
		TBBUTTONINFO info = new TBBUTTONINFO ();
		info.cbSize = TBBUTTONINFO.sizeof;
		info.dwMask = OS.TBIF_IMAGE;
		int count = (int)/*64*/OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
		for (int i=0; i<count; i++) {
			ToolItem item = items [i];
			if ((item.getStyle() & SWT.SEPARATOR) != 0) continue;
			if (item.image == null) continue;
			OS.SendMessage (handle, OS.TB_GETBUTTONINFO, item.id, info);
			if (info.iImage != OS.I_IMAGENONE) {
				Image image = imageList.get(info.iImage);
				Image hot = hotImageList.get(info.iImage);
				Image disabled = disabledImageList.get(info.iImage);
				imageList.put(info.iImage, null);
				hotImageList.put(info.iImage, null);
				disabledImageList.put(info.iImage, null);
				info.iImage = newImageList.add(image);
				newHotImageList.add(hot);
				newDisabledImageList.add(disabled);
				OS.SendMessage (handle, OS.TB_SETBUTTONINFO, item.id, info);
			}
		}
		display.releaseToolImageList (imageList);
		display.releaseToolHotImageList (hotImageList);
		display.releaseToolDisabledImageList (disabledImageList);
		OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, newImageList.getHandle ());
		OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, newHotImageList.getHandle ());
		OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, newDisabledImageList.getHandle ());
		imageList = newImageList;
		hotImageList = newHotImageList;
		disabledImageList = newDisabledImageList;
	}
}
Comment 7 Helena Halperin CLA 2011-05-11 07:41:43 EDT
(In reply to comment #6)
> Helena, what about this ?
> I just wrote it up, can you break it ? does it leak or something ? pls help
> test.
> 
I tested it.
A  part of enabled images  disappeared, a part of disabled images are shown enabled,   but if to add redraw() in the end of updateOrientation, all works fine.
Comment 8 Felipe Heidrich CLA 2011-05-11 09:54:07 EDT
(In reply to comment #7)
> (In reply to comment #6)
> > Helena, what about this ?
> > I just wrote it up, can you break it ? does it leak or something ? pls help
> > test.
> > 
> I tested it.
> A  part of enabled images  disappeared, a part of disabled images are shown
> enabled,   but if to add redraw() in the end of updateOrientation, all works
> fine.

not sure I understood, can you provide steps (or a testcase) so I can reproduce the problem here ?
Comment 9 Helena Halperin CLA 2011-05-11 10:40:04 EDT
(In reply to comment #8)
> not sure I understood, can you provide steps (or a testcase) so I can reproduce
> the problem here ?

Run ControlExample. Click on F1 2 tmes. Several images disappered. Minimize window, maximize. All images restored. 
Disable toolbar. F1. Several images now enabled. Minimize, maximize the window. All images disabled.
Comment 10 Felipe Heidrich CLA 2011-05-11 10:51:02 EDT
(In reply to comment #9)
> (In reply to comment #8)
> > not sure I understood, can you provide steps (or a testcase) so I can reproduce
> > the problem here ?
> Run ControlExample. Click on F1 2 tmes. Several images disappered. Minimize
> window, maximize. All images restored. 
> Disable toolbar. F1. Several images now enabled. Minimize, maximize the window.
> All images disabled.

with my patch ? it works fine for me on windows 7
what are you testing ? xp ?
Comment 11 Helena Halperin CLA 2011-05-11 11:04:56 EDT
(In reply to comment #10)
> with my patch ? it works fine for me on windows 7
> what are you testing ? xp ?

Your patch, 
XP
Comment 12 Felipe Heidrich CLA 2011-05-11 11:17:40 EDT
(In reply to comment #11)
> (In reply to comment #10)
> > with my patch ? it works fine for me on windows 7
> > what are you testing ? xp ?
> Your patch, 
> XP

and adding OS.InvalidateRect (handle, null, true); to end of the method solves the problem ?
Comment 13 Helena Halperin CLA 2011-05-11 11:25:07 EDT
(In reply to comment #12)
> and adding OS.InvalidateRect (handle, null, true); to end of the method solves
> the problem ?

yes
Comment 14 Felipe Heidrich CLA 2011-05-11 13:39:14 EDT
Created attachment 195397 [details]
patch
Comment 15 Felipe Heidrich CLA 2011-05-11 13:41:44 EDT
Silenio, I rewrote updateOrientation() for Toolbar.
-We tested the code on Windows 7 and XP
-This only affects people calling the new API
-I tested with Sleak
Comment 16 Felipe Heidrich CLA 2011-05-11 15:14:53 EDT
fixed in head