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 278195 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/swt/internal/widgets/displaykit/DisplayLCA.java (-8 / +4 lines)
Lines 311-317 Link Here
311
  }
311
  }
312
312
313
  public void readData( final Display display ) {
313
  public void readData( final Display display ) {
314
    Rectangle oldBounds = display.getBounds();
315
    readBounds( display );
314
    readBounds( display );
316
    readFocusControl( display );
315
    readFocusControl( display );
317
    WidgetTreeVisitor visitor = new AllWidgetTreeVisitor() {
316
    WidgetTreeVisitor visitor = new AllWidgetTreeVisitor() {
Lines 326-339 Link Here
326
      Composite shell = shells[ i ];
325
      Composite shell = shells[ i ];
327
      WidgetTreeVisitor.accept( shell, visitor );
326
      WidgetTreeVisitor.accept( shell, visitor );
328
    }
327
    }
329
330
    // TODO: [fappel] since there is no possibility yet to determine whether
331
    //                a shell is maximized, we use this hack to adjust
332
    //                the bounds of a maximized shell in case of a document
333
    //                resize event
334
    for( int i = 0; i < shells.length; i++ ) {
328
    for( int i = 0; i < shells.length; i++ ) {
335
      if( shells[ i ].getBounds().equals( oldBounds ) ) {
329
      if( shells[ i ].getMaximized() ) {
336
        shells[ i ].setBounds( display.getBounds() );
330
        Object adapter = shells[ i ].getAdapter( IShellAdapter.class );
331
        IShellAdapter shellAdapter = ( IShellAdapter )adapter;
332
        shellAdapter.setBounds( display.getBounds() );
337
      }
333
      }
338
    }
334
    }
339
  }
335
  }
(-)src/org/eclipse/swt/internal/widgets/shellkit/ShellLCA.java (-1 / +8 lines)
Lines 63-69 Link Here
63
    Shell shell = ( Shell )widget;
63
    Shell shell = ( Shell )widget;
64
    // [if] Preserve the menu bounds before setting the new shell bounds.
64
    // [if] Preserve the menu bounds before setting the new shell bounds.
65
    preserveMenuBounds( shell );
65
    preserveMenuBounds( shell );
66
    ControlLCAUtil.readBounds( shell );
66
    readBounds( shell );
67
    readMode( shell );
67
    readMode( shell );
68
    if( WidgetLCAUtil.wasEventSent( shell, JSConst.EVENT_SHELL_CLOSED ) ) {
68
    if( WidgetLCAUtil.wasEventSent( shell, JSConst.EVENT_SHELL_CLOSED ) ) {
69
      shell.close();
69
      shell.close();
Lines 290-295 Link Here
290
  //////////////////
290
  //////////////////
291
  // Helping methods
291
  // Helping methods
292
292
293
  private static void readBounds( final Shell shell ) {
294
    Rectangle bounds = WidgetLCAUtil.readBounds( shell, shell.getBounds() );
295
    Object adapter = shell.getAdapter( IShellAdapter.class );
296
    IShellAdapter shellAdapter = ( IShellAdapter )adapter;
297
    shellAdapter.setBounds( bounds );
298
  }
299
293
  private static void readMode( final Shell shell ) {
300
  private static void readMode( final Shell shell ) {
294
    final String value = WidgetLCAUtil.readPropertyValue( shell, "mode" );
301
    final String value = WidgetLCAUtil.readPropertyValue( shell, "mode" );
295
    if( value != null ) {
302
    if( value != null ) {
(-)src/org/eclipse/swt/internal/widgets/IShellAdapter.java (-1 / +2 lines)
Lines 18-25 Link Here
18
public interface IShellAdapter {
18
public interface IShellAdapter {
19
  
19
  
20
  Control getActiveControl();
20
  Control getActiveControl();
21
  
22
  void setActiveControl( Control control );
21
  void setActiveControl( Control control );
23
  
22
  
24
  Rectangle getMenuBounds();
23
  Rectangle getMenuBounds();
24
  
25
  void setBounds( Rectangle bounds );
25
}
26
}
(-)src/org/eclipse/swt/widgets/Shell.java (-4 / +15 lines)
Lines 127-139 Link Here
127
127
128
  private Control lastActive;
128
  private Control lastActive;
129
  private IShellAdapter shellAdapter;
129
  private IShellAdapter shellAdapter;
130
  private String text = "";
130
  private String text;
131
  private Image image;
131
  private Image image;
132
  private int alpha = 0xFF;
132
  private int alpha;
133
  private Button defaultButton;
133
  private Button defaultButton;
134
  private Button saveDefault;
134
  private Button saveDefault;
135
  private Control savedFocus;  // TODO [rh] move to Decorations when exist
135
  private Control savedFocus;  // TODO [rh] move to Decorations when exist
136
  private int mode = MODE_NONE;
136
  private int mode;
137
137
138
  private Shell( final Display display,
138
  private Shell( final Display display,
139
                 final Shell parent,
139
                 final Shell parent,
Lines 146-151 Link Here
146
    } else {
146
    } else {
147
      this.display = Display.getCurrent();
147
      this.display = Display.getCurrent();
148
    }
148
    }
149
    text = "";
150
    alpha = 0xFF;
151
    mode = MODE_NONE;
149
    this.style = checkStyle( style );
152
    this.style = checkStyle( style );
150
    state |= HIDDEN;
153
    state |= HIDDEN;
151
    this.display.addShell( this );
154
    this.display.addShell( this );
Lines 526-531 Link Here
526
  Composite findDeferredControl() {
529
  Composite findDeferredControl() {
527
    return layoutCount > 0 ? this : null;
530
    return layoutCount > 0 ? this : null;
528
  }
531
  }
532
  
533
  void updateMode() {
534
    mode &= ~MODE_MAXIMIZED;
535
    mode &= ~MODE_MINIMIZED;
536
  }
529
537
530
  /////////////////////
538
  /////////////////////
531
  // Adaptable override
539
  // Adaptable override
Lines 544-549 Link Here
544
          public Rectangle getMenuBounds() {
552
          public Rectangle getMenuBounds() {
545
            return Shell.this.getMenuBounds();
553
            return Shell.this.getMenuBounds();
546
          }
554
          }
555
          public void setBounds( final Rectangle bounds ) {
556
            Shell.this.setBounds( bounds, false );
557
          }
547
        };
558
        };
548
      }
559
      }
549
      result = shellAdapter;
560
      result = shellAdapter;
Lines 1157-1163 Link Here
1157
   * @see #setMaximized
1168
   * @see #setMaximized
1158
   */
1169
   */
1159
  public boolean getMaximized() {
1170
  public boolean getMaximized() {
1160
    return this.mode == MODE_MAXIMIZED;
1171
    return mode == MODE_MAXIMIZED;
1161
  }
1172
  }
1162
1173
1163
  ///////////////////
1174
  ///////////////////
(-)src/org/eclipse/swt/widgets/Control.java (-10 / +21 lines)
Lines 798-811 Link Here
798
    if( bounds == null ) {
798
    if( bounds == null ) {
799
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
799
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
800
    }
800
    }
801
    Point oldLocation = getLocation();
801
    setBounds( bounds, true );
802
    Point oldSize = getSize();
803
    this.bounds
804
      = new Rectangle( bounds.x, bounds.y, bounds.width, bounds.height );
805
    this.bounds.width = Math.max( 0, this.bounds.width );
806
    this.bounds.height = Math.max( 0, this.bounds.height );
807
    notifyMove( oldLocation );
808
    notifyResize( oldSize );
809
  }
802
  }
810
803
811
  /**
804
  /**
Lines 1784-1791 Link Here
1784
    return result;
1777
    return result;
1785
  }
1778
  }
1786
1779
1787
  //////////////////////////////////////////////////////
1780
  ////////////////////////////////
1788
  // Helping methods that throw move- and resize-events
1781
  // Helping methods for setBounds
1782
1783
  void setBounds( final Rectangle bounds, boolean updateMode ) {
1784
    Point oldLocation = getLocation();
1785
    Point oldSize = getSize();
1786
    this.bounds
1787
      = new Rectangle( bounds.x, bounds.y, bounds.width, bounds.height );
1788
    this.bounds.width = Math.max( 0, this.bounds.width );
1789
    this.bounds.height = Math.max( 0, this.bounds.height );
1790
    if( updateMode ) {
1791
      updateMode();
1792
    }
1793
    notifyMove( oldLocation );
1794
    notifyResize( oldSize );
1795
  }
1796
1797
  void updateMode() {
1798
    // subclasses may override
1799
  }
1789
1800
1790
  void notifyResize( final Point oldSize ) {
1801
  void notifyResize( final Point oldSize ) {
1791
    if( !oldSize.equals( getSize() ) ) {
1802
    if( !oldSize.equals( getSize() ) ) {
(-)src/org/eclipse/swt/widgets/Shell_Test.java (+78 lines)
Lines 11-21 Link Here
11
11
12
package org.eclipse.swt.widgets;
12
package org.eclipse.swt.widgets;
13
13
14
import java.util.ArrayList;
15
14
import junit.framework.TestCase;
16
import junit.framework.TestCase;
15
17
16
import org.eclipse.rwt.lifecycle.PhaseId;
18
import org.eclipse.rwt.lifecycle.PhaseId;
17
import org.eclipse.swt.RWTFixture;
19
import org.eclipse.swt.RWTFixture;
18
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.events.ControlAdapter;
22
import org.eclipse.swt.events.ControlEvent;
19
import org.eclipse.swt.graphics.Point;
23
import org.eclipse.swt.graphics.Point;
20
import org.eclipse.swt.graphics.Rectangle;
24
import org.eclipse.swt.graphics.Rectangle;
21
import org.eclipse.swt.internal.widgets.IShellAdapter;
25
import org.eclipse.swt.internal.widgets.IShellAdapter;
Lines 316-321 Link Here
316
    assertEquals( shell.getBounds(), display.getBounds() );
320
    assertEquals( shell.getBounds(), display.getBounds() );
317
  }
321
  }
318
  
322
  
323
  public void testSetBoundsResetMaximized() {
324
    Display display = new Display();
325
    Shell shell = new Shell( display );
326
    shell.setBounds( 1, 2, 3, 4 );
327
    shell.setMaximized( true );
328
    Rectangle bounds = new Rectangle( 10, 10, 10, 10 );
329
    shell.setBounds( bounds );
330
    assertFalse( shell.getMaximized() );
331
    assertEquals( bounds, shell.getBounds() );
332
  }
333
  
334
  public void testSetLocationResetMaximized() {
335
    Display display = new Display();
336
    Shell shell = new Shell( display );
337
    shell.setBounds( 1, 2, 3, 4 );
338
    shell.setMaximized( true );
339
    shell.setLocation( 10, 10 );
340
    assertFalse( shell.getMaximized() );
341
  }
342
  
343
  public void testSetSizeResetMaximized() {
344
    Display display = new Display();
345
    Shell shell = new Shell( display );
346
    shell.setBounds( 1, 2, 3, 4 );
347
    shell.setMaximized( true );
348
    shell.setSize( 6, 6 );
349
    assertFalse( shell.getMaximized() );
350
  }
351
  
352
  public void testSetBoundsResetMaximizedEventOrder() {
353
    final boolean[] maximized = { true };
354
    Display display = new Display();
355
    final Shell shell = new Shell( display );
356
    shell.setBounds( 1, 2, 3, 4 );
357
    shell.addControlListener( new ControlAdapter() {
358
      public void controlResized( final ControlEvent event ) {
359
        maximized[ 0 ] = shell.getMaximized();
360
      }
361
    } );
362
    shell.setMaximized( true );
363
    shell.setSize( 6, 6 );
364
    assertFalse( maximized[ 0 ] );
365
  }
366
  
367
  public void testShellAdapterSetBounds() {
368
    final java.util.List log = new ArrayList();
369
    Display display = new Display();
370
    Shell shell = new Shell( display );
371
    shell.setBounds( 1, 2, 3, 4 );
372
    shell.setMaximized( true );
373
    shell.addControlListener( new ControlAdapter() {
374
      public void controlResized( final ControlEvent event ) {
375
        log.add( event );
376
      }
377
    } );
378
    Object adapter = shell.getAdapter( IShellAdapter.class );
379
    IShellAdapter shellAdapter = ( IShellAdapter )adapter;
380
    shellAdapter.setBounds( new Rectangle( 5,6, 7, 8 ) );
381
    assertEquals( new Rectangle( 5,6, 7, 8 ), shell.getBounds() );
382
    assertTrue( shell.getMaximized() );
383
    assertEquals( 1, log.size() );
384
  }
385
  
386
  public void testSetBoundsResetMinimized() {
387
    Display display = new Display();
388
    Shell shell = new Shell( display );
389
    shell.setBounds( 1, 2, 3, 4 );
390
    shell.setMinimized( true );
391
    Rectangle bounds = new Rectangle( 10, 10, 10, 10 );
392
    shell.setBounds( bounds );
393
    assertFalse( shell.getMinimized() );
394
    assertEquals( bounds, shell.getBounds() );
395
  }
396
  
319
  protected void setUp() throws Exception {
397
  protected void setUp() throws Exception {
320
    RWTFixture.setUp();
398
    RWTFixture.setUp();
321
    RWTFixture.fakePhase( PhaseId.PROCESS_ACTION );
399
    RWTFixture.fakePhase( PhaseId.PROCESS_ACTION );

Return to bug 278195