Bug 330566 - Once a Sash is moved to certain limit, it cannot be moved anymore
Summary: Once a Sash is moved to certain limit, it cannot be moved anymore
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.1   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2010-11-18 08:49 EST by Albert CLA
Modified: 2020-01-17 05:24 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Albert CLA 2010-11-18 08:49:03 EST
Build Identifier: 3.5.2

I have encountered a strange behavior when setting minimum composite width when moving sash. I have two composites inside a SWT.HORIZONTAL style SashForm. When I want to set a limit how far to the right Sash can be moved, I'm using a code, which works on Windows and GTK, but when running this code on Mac OS X (10.6), once the sash is moved to this limit, "West-East" cursor won't appear anymore when hovering with a mouse over it, and Sash cannot be no longer moved. If I resize the shell, cursor reappears and Sash can be moved again.

I opened a topic on Eclipse newsgroups (http://www.eclipse.org/forums/index.php?t=msg&th=198780&start=0&S=dc4988e7f16e0cde24de91b976be6e48) and moving the sashForm.layout(); to asyncExec() somehow bypasses this behavior.

This code works fine on Linux and Windows.


Best regards,

Albert


Reproducible: Always

Steps to Reproduce:
Please run the following snippet:

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;

public class SashFormTest
{
    // Mimumum width of right composite
    final static int MIN_WIDTH = 200;
    
    public static void main (String [] args)
    {
        Display display = new Display ();
        
        final Shell shell = new Shell(display);        
        shell.setLayout(new FormLayout());        
        shell.setText("SashFormTest");
        
        final SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL);
        
        sashForm.setLayout(new FormLayout());
        {
            FormData formData = new FormData();
            formData.top = new FormAttachment(0, 0);            
            formData.bottom = new FormAttachment(100, 0);
            formData.left = new FormAttachment(0, 0);            
            formData.right = new FormAttachment(100, 0);
            sashForm.setLayoutData(formData);
        }
        
        Composite leftComposite = new Composite(sashForm, SWT.NONE);
        leftComposite.setLayout(new FormLayout());
        {
            FormData formData = new FormData();
            formData.top = new FormAttachment(0, 0);            
            formData.bottom = new FormAttachment(100, 0);
            formData.left = new FormAttachment(0, 0);            
            formData.right = new FormAttachment(100, 0);
            leftComposite.setLayoutData(formData);
        }
        leftComposite.setBackground(new Color(shell.getDisplay(), 255, 0, 0));
                
        Composite rightComposite = new Composite(sashForm, SWT.NONE);        
        rightComposite.setLayout(new FormLayout());
        {
            FormData formData = new FormData();
            formData.top = new FormAttachment(0, 0);            
            formData.bottom = new FormAttachment(100, 0);
            formData.left = new FormAttachment(0, 0);            
            formData.right = new FormAttachment(100, 0);
            rightComposite.setLayoutData(formData);
        }
        rightComposite.setBackground(new Color(shell.getDisplay(), 0, 255, 0));
        
        sashForm.setWeights(new int[] {30, 70});
        
        shell.setSize(500, 200);
        
        // Get Sash
        Sash sash = getSashes(sashForm);
        
        // Composite on the right side of the sash
        // is always at least 200 px wide, when sash is moved
        sash.addSelectionListener(new SelectionAdapter ()
        {                     
            public void widgetSelected(SelectionEvent event)
            {   
                if (event.x >= shell.getBounds().width - MIN_WIDTH)
                {   
                    int shellWidth = shell.getBounds().width;
                    
                    // Calculate new ratio for sashes weights                    
                    double ratio = (double)shellWidth / Math.abs(shell.getBounds().width - MIN_WIDTH);                                            
                    double percent = 100 / ratio;                  
                    
                    int percentRounded = (int) Math.floor(percent);
                    
                    sashForm.setWeights(new int[]{percentRounded, 100 - percentRounded});                                      
                    sashForm.layout();                      
                }
            }
        });
        
        shell.open ();
        
        while (!shell.isDisposed ())
        {
            if (!display.readAndDispatch())
            {
                display.sleep ();
            }   
        }
        display.dispose ();
    }
    
    private static Sash getSashes(SashForm sf)
    {
        Control control[] = sf.getChildren();
        for (int i = 0; i < control.length; ++i)
        {            
            if (control[i] instanceof Sash)
            {   
                return (Sash)control[i];
            }
        }
        return null;
    }
}
Comment 1 Scott Kovatch CLA 2010-11-18 12:15:01 EST
Is this Cocoa or Carbon? If it's Cocoa we'll have a look -- Carbon is not being updated for 3.7.
Comment 2 Albert CLA 2010-11-23 02:39:11 EST
This issue affects SWT cocoa 3.6.
Comment 3 Scott Kovatch CLA 2010-11-30 13:55:59 EST
The problem seems to be that the sash's NSView is getting buried behind the other Composites in the SashForm. When the Sash is resized the relayout is putting the Composites above the Sash. I'll hold on to this and see what I can do; there's a comment in Sash that we should use sendMouseEvent, which makes sense because we're relying on mouseDragged, and that won't be called unless the view is top-most.
Comment 4 Lakshmi P Shanmugam CLA 2017-07-03 02:40:47 EDT
Bug triaged, visit https://wiki.eclipse.org/SWT/Devel/Triage for more
information.
Comment 5 Eclipse Genie CLA 2020-01-17 05:24:47 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.