Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 355709
Collapse All | Expand All

(-)src/org/eclipse/rwt/internal/textsize/MarkLayoutNeededVisitor.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 EclipseSource and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    EclipseSource - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.rwt.internal.textsize;
12
13
import org.eclipse.swt.internal.widgets.ICompositeAdapter;
14
import org.eclipse.swt.internal.widgets.WidgetTreeVisitor.AllWidgetTreeVisitor;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Widget;
17
18
19
class MarkLayoutNeededVisitor extends AllWidgetTreeVisitor {
20
21
  public boolean doVisit( Widget widget ) {
22
    if( widget instanceof Composite ) {
23
      Composite composite = ( Composite )widget;
24
      getAdapter( composite ).markLayoutNeeded();
25
    }
26
    return true;
27
  }
28
29
  private static ICompositeAdapter getAdapter( Composite composite ) {
30
    Object adapter = composite.getAdapter( ICompositeAdapter.class );
31
    return ( ICompositeAdapter )adapter;
32
  }
33
}
(-)src/org/eclipse/rwt/internal/textsize/TextSizeRecalculation.java (-2 / +7 lines)
Lines 33-38 Link Here
33
    Rectangle boundsBuffer = shell.getBounds();
33
    Rectangle boundsBuffer = shell.getBounds();
34
    bufferScrolledCompositeOrigins( shell );
34
    bufferScrolledCompositeOrigins( shell );
35
    clearLayoutBuffers( shell );
35
    clearLayoutBuffers( shell );
36
    markLayoutNeeded( shell );
36
    enlargeShell( shell );
37
    enlargeShell( shell );
37
    rePackControls( shell );
38
    rePackControls( shell );
38
    enlargeScrolledCompositeContent( shell );
39
    enlargeScrolledCompositeContent( shell );
Lines 49-54 Link Here
49
    WidgetTreeVisitor.accept( shell, new ClearLayoutBuffersVisitor() );
50
    WidgetTreeVisitor.accept( shell, new ClearLayoutBuffersVisitor() );
50
  }
51
  }
51
52
53
  private void markLayoutNeeded( Shell shell ) {
54
    WidgetTreeVisitor.accept( shell, new MarkLayoutNeededVisitor() );
55
  }
56
52
  private void bufferScrolledCompositeOrigins( Shell shell ) {
57
  private void bufferScrolledCompositeOrigins( Shell shell ) {
53
    WidgetTreeVisitor.accept( shell, new BufferScrolledCompositeOriginsVisitor() );
58
    WidgetTreeVisitor.accept( shell, new BufferScrolledCompositeOriginsVisitor() );
54
  }
59
  }
Lines 60-66 Link Here
60
  private void restoreScrolledCompositeOrigins( Shell shell ) {
65
  private void restoreScrolledCompositeOrigins( Shell shell ) {
61
    WidgetTreeVisitor.accept( shell, new RestoreScrolledCompositeOriginsVisitor() );
66
    WidgetTreeVisitor.accept( shell, new RestoreScrolledCompositeOriginsVisitor() );
62
  }
67
  }
63
  
68
64
  private void restoreShellSize( Shell shell, Rectangle bufferedBounds ) {
69
  private void restoreShellSize( Shell shell, Rectangle bufferedBounds ) {
65
    setShellSize( shell, bufferedBounds );
70
    setShellSize( shell, bufferedBounds );
66
  }
71
  }
Lines 87-93 Link Here
87
    IDisplayAdapter displayAdapter = ( IDisplayAdapter )adapter;
92
    IDisplayAdapter displayAdapter = ( IDisplayAdapter )adapter;
88
    return displayAdapter.getShells();
93
    return displayAdapter.getShells();
89
  }
94
  }
90
  
95
91
  private void setShellSize( Shell shell, Rectangle bounds ) {
96
  private void setShellSize( Shell shell, Rectangle bounds ) {
92
    getShellAdapter( shell ).setBounds( bounds );
97
    getShellAdapter( shell ).setBounds( bounds );
93
  }
98
  }
(-)src/org/eclipse/swt/internal/widgets/ICompositeAdapter.java (+18 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 EclipseSource and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    EclipseSource - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.swt.internal.widgets;
12
13
14
public interface ICompositeAdapter {
15
16
  void markLayoutNeeded();
17
18
}
(-)src/org/eclipse/swt/widgets/Composite.java (-1 / +23 lines)
Lines 15-20 Link Here
15
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.graphics.Point;
16
import org.eclipse.swt.graphics.Point;
17
import org.eclipse.swt.graphics.Rectangle;
17
import org.eclipse.swt.graphics.Rectangle;
18
import org.eclipse.swt.internal.SerializableCompatibility;
19
import org.eclipse.swt.internal.widgets.ICompositeAdapter;
18
import org.eclipse.swt.widgets.ControlHolder.IControlHolderAdapter;
20
import org.eclipse.swt.widgets.ControlHolder.IControlHolderAdapter;
19
21
20
/**
22
/**
Lines 34-39 Link Here
34
 */
36
 */
35
public class Composite extends Scrollable {
37
public class Composite extends Scrollable {
36
38
39
  private final ICompositeAdapter compositeAdapter;
37
  private Layout layout;
40
  private Layout layout;
38
  int layoutCount;
41
  int layoutCount;
39
  private final ControlHolder controlHolder;
42
  private final ControlHolder controlHolder;
Lines 44-49 Link Here
44
    // prevent instantiation from outside this package
47
    // prevent instantiation from outside this package
45
    super( parent );
48
    super( parent );
46
    controlHolder = new ControlHolder();
49
    controlHolder = new ControlHolder();
50
    compositeAdapter = new CompositeAdapter();
47
  }
51
  }
48
52
49
  /**
53
  /**
Lines 76-81 Link Here
76
  public Composite( Composite parent, int style ) {
80
  public Composite( Composite parent, int style ) {
77
    super( parent, style );
81
    super( parent, style );
78
    controlHolder = new ControlHolder();
82
    controlHolder = new ControlHolder();
83
    compositeAdapter = new CompositeAdapter();
79
  }
84
  }
80
85
81
  void initState() {
86
  void initState() {
Lines 114-119 Link Here
114
    Object result;
119
    Object result;
115
    if( adapter == IControlHolderAdapter.class ) {
120
    if( adapter == IControlHolderAdapter.class ) {
116
      result = controlHolder;
121
      result = controlHolder;
122
    } else if( adapter == ICompositeAdapter.class ) {
123
      result = compositeAdapter;
117
    } else {
124
    } else {
118
      result = super.getAdapter( adapter );
125
      result = super.getAdapter( adapter );
119
    }
126
    }
Lines 832-838 Link Here
832
  void notifyResize( Point oldSize ) {
839
  void notifyResize( Point oldSize ) {
833
    // TODO [rh] revise this: the SWT code (method sendResize) first calls
840
    // TODO [rh] revise this: the SWT code (method sendResize) first calls
834
    //      'super' (fires resize events) and *then* does the layouting
841
    //      'super' (fires resize events) and *then* does the layouting
835
    if( !oldSize.equals( getSize() ) ) {
842
    if( !oldSize.equals( getSize() ) || isLayoutNeeded() ) {
836
      ProcessActionRunner.add( new Runnable() {
843
      ProcessActionRunner.add( new Runnable() {
837
        public void run() {
844
        public void run() {
838
          if( !isDisposed() && layout != null ) {
845
          if( !isDisposed() && layout != null ) {
Lines 845-850 Link Here
845
    super.notifyResize( oldSize );
852
    super.notifyResize( oldSize );
846
  }
853
  }
847
854
855
  private boolean isLayoutNeeded() {
856
    return ( state & LAYOUT_NEEDED ) != 0;
857
  }
858
848
  ///////////////////
859
  ///////////////////
849
  // Skinning support
860
  // Skinning support
850
861
Lines 858-861 Link Here
858
      }
869
      }
859
    }
870
    }
860
  }
871
  }
872
873
  ////////////////
874
  // Inner classes
875
876
  private final class CompositeAdapter implements ICompositeAdapter, SerializableCompatibility {
877
878
    public void markLayoutNeeded() {
879
      Composite.this.markLayout( false, false );
880
    }
881
882
  }
861
}
883
}
(-)src/org/eclipse/rwt/internal/textsize/TextSizeRecalculation_Test.java (-35 / +60 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Frank Appel - initial API and implementation
9
 *    Frank Appel - initial API and implementation
10
 *    EclipseSource - ongoing development
10
 ******************************************************************************/
11
 ******************************************************************************/
11
package org.eclipse.rwt.internal.textsize;
12
package org.eclipse.rwt.internal.textsize;
12
13
Lines 21-27 Link Here
21
import org.eclipse.swt.events.ControlListener;
22
import org.eclipse.swt.events.ControlListener;
22
import org.eclipse.swt.graphics.*;
23
import org.eclipse.swt.graphics.*;
23
import org.eclipse.swt.internal.widgets.ControlUtil;
24
import org.eclipse.swt.internal.widgets.ControlUtil;
24
import org.eclipse.swt.layout.FillLayout;
25
import org.eclipse.swt.layout.*;
25
import org.eclipse.swt.widgets.*;
26
import org.eclipse.swt.widgets.*;
26
27
27
28
Lines 29-88 Link Here
29
  private static final FontData FONT_DATA = new FontData( "arial", 23, SWT.BOLD );
30
  private static final FontData FONT_DATA = new FontData( "arial", 23, SWT.BOLD );
30
  private static final String TEXT_TO_MEASURE = "textToMeasure";
31
  private static final String TEXT_TO_MEASURE = "textToMeasure";
31
32
33
  private Display display;
32
  private Shell shell;
34
  private Shell shell;
33
  private Composite scrolledCompositeContent;
35
  private Composite scrolledCompositeContent;
34
  private ResizeListener shellResizeListener;
36
  private ResizeListener shellResizeListener;
35
  private ResizeListener scrolledCompositeContentResizeListener;
37
  private ResizeListener scrolledCompositeContentResizeListener;
36
  private Label packedControl;
38
  private Label packedControl;
37
  
38
  
39
  private final class ResizeListener implements ControlListener {
40
    private int resizeCount;
41
    
42
    public void controlResized( ControlEvent e ) {
43
      resizeCount++;
44
    }
45
39
46
    public void controlMoved( ControlEvent e ) {
40
  protected void setUp() throws Exception {
47
    }
41
    Fixture.setUp();
42
    display = new Display();
43
    shell = new Shell( display );
44
  }
48
45
49
    public int resizeCount() {
46
  protected void tearDown() throws Exception {
50
      return resizeCount;
47
    Fixture.tearDown();
51
    }
52
  }
48
  }
53
  
49
54
 
55
  public void testExecute() {
50
  public void testExecute() {
56
    createWidgetTree();
51
    createWidgetTree();
57
    registerResizeListeners();
52
    registerResizeListeners();
58
    turnOnImmediateResizeEventHandling();
53
    turnOnImmediateResizeEventHandling();
59
    fakeMeasurementResults();
54
    fakeMeasurementResults();
60
    TextSizeRecalculation recalculation = new TextSizeRecalculation();
55
    TextSizeRecalculation recalculation = new TextSizeRecalculation();
61
    
56
62
    recalculation.execute();
57
    recalculation.execute();
63
  
58
64
    checkResizeTookPlace();
59
    checkResizeTookPlace();
65
    checkRePackTookPlace();
60
    checkRePackTookPlace();
66
  }
61
  }
67
  
62
68
  public void testIControlAdapterIsPacked() {
63
  public void testIControlAdapterIsPacked() {
69
    Display display = new Display();
70
    Shell control = new Shell( display );
64
    Shell control = new Shell( display );
71
    assertFalse( ControlUtil.getControlAdapter( control ).isPacked() );
65
    assertFalse( ControlUtil.getControlAdapter( control ).isPacked() );
72
    
66
73
    control.pack();
67
    control.pack();
74
    assertTrue( ControlUtil.getControlAdapter( control ).isPacked() );
68
    assertTrue( ControlUtil.getControlAdapter( control ).isPacked() );
75
    
69
76
    control.setBounds( new Rectangle( 1, 1, 2, 2 ) );
70
    control.setBounds( new Rectangle( 1, 1, 2, 2 ) );
77
    assertFalse( ControlUtil.getControlAdapter( control ).isPacked() );
71
    assertFalse( ControlUtil.getControlAdapter( control ).isPacked() );
78
  }
72
  }
79
73
80
  protected void setUp() throws Exception {
74
  public void testLayoutOfCompositeWithFixedSize() {
81
    Fixture.setUp();
75
    turnOnImmediateResizeEventHandling();
82
  }
76
    createShellWithLayout();
83
  
77
    Composite fixedSizeComposite = createFixedSizeComposite();
84
  protected void tearDown() throws Exception {
78
    Label label = new Label( fixedSizeComposite, SWT.NONE );
85
    Fixture.tearDown();
79
    label.setText( "text" );
80
    shell.pack();
81
    // simulate smaller size because of text estimation
82
    label.setSize( 5, 5 );
83
    ResizeListener resizeListener = new ResizeListener();
84
    label.addControlListener( resizeListener );
85
86
    TextSizeRecalculation recalculation = new TextSizeRecalculation();
87
    recalculation.execute();
88
89
    assertEquals( 1, resizeListener.resizeCount() );
86
  }
90
  }
87
91
88
  private void checkResizeTookPlace() {
92
  private void checkResizeTookPlace() {
Lines 91-97 Link Here
91
    assertEquals( 2, shellResizeListener.resizeCount() );
95
    assertEquals( 2, shellResizeListener.resizeCount() );
92
    assertEquals( 2, scrolledCompositeContentResizeListener.resizeCount() );
96
    assertEquals( 2, scrolledCompositeContentResizeListener.resizeCount() );
93
  }
97
  }
94
  
98
95
  private void checkRePackTookPlace() {
99
  private void checkRePackTookPlace() {
96
    assertEquals( new Point( 100, 22 ), packedControl.getSize() );
100
    assertEquals( new Point( 100, 22 ), packedControl.getSize() );
97
  }
101
  }
Lines 105-112 Link Here
105
  }
109
  }
106
110
107
  private void createWidgetTree() {
111
  private void createWidgetTree() {
108
    Display display = new Display();
112
    createShellWithLayout();
109
    createShellWithLayout( display );
110
    createScrolledCompositeWithContent();
113
    createScrolledCompositeWithContent();
111
    createPackedControl();
114
    createPackedControl();
112
  }
115
  }
Lines 124-132 Link Here
124
    scrolledComposite.setContent( scrolledCompositeContent );
127
    scrolledComposite.setContent( scrolledCompositeContent );
125
  }
128
  }
126
129
127
  private void createShellWithLayout( Display display ) {
130
  private void createShellWithLayout() {
128
    shell = new Shell( display );
131
    shell.setLayout( new GridLayout() );
129
    shell.setLayout( new FillLayout() );
132
  }
133
134
  private Composite createFixedSizeComposite() {
135
    Composite result = new Composite( shell, SWT.NONE );
136
    result.setLayout( new GridLayout() );
137
    result.setLayoutData( new GridData( 200, SWT.DEFAULT ) );
138
    return result;
130
  }
139
  }
131
140
132
  private void registerResizeListeners() {
141
  private void registerResizeListeners() {
Lines 135-141 Link Here
135
    shell.addControlListener( shellResizeListener );
144
    shell.addControlListener( shellResizeListener );
136
    scrolledCompositeContent.addControlListener( scrolledCompositeContentResizeListener );
145
    scrolledCompositeContent.addControlListener( scrolledCompositeContentResizeListener );
137
  }
146
  }
138
  
147
139
  private void turnOnImmediateResizeEventHandling() {
148
  private void turnOnImmediateResizeEventHandling() {
140
    Fixture.fakePhase( PhaseId.PROCESS_ACTION );
149
    Fixture.fakePhase( PhaseId.PROCESS_ACTION );
141
  }
150
  }
Lines 145-148 Link Here
145
    RWTFactory.getTextSizeStorage().storeFont( FONT_DATA );
154
    RWTFactory.getTextSizeStorage().storeFont( FONT_DATA );
146
    TextSizeStorageUtil.store( FONT_DATA, TEXT_TO_MEASURE, 0, new Point( 100, 20 ) );
155
    TextSizeStorageUtil.store( FONT_DATA, TEXT_TO_MEASURE, 0, new Point( 100, 20 ) );
147
  }
156
  }
157
158
  private final class ResizeListener implements ControlListener {
159
    private int resizeCount;
160
161
    public void controlResized( ControlEvent e ) {
162
      resizeCount++;
163
    }
164
165
    public void controlMoved( ControlEvent e ) {
166
    }
167
168
    public int resizeCount() {
169
      return resizeCount;
170
    }
171
  }
172
148
}
173
}

Return to bug 355709