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

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/ColorSchemeService.java (-3 / +4 lines)
Lines 132-140 Link Here
132
        c[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
132
        c[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
133
        c[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
133
        c[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
134
134
135
        percent[0] = theme.getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT);
135
		percent[0] = presentation.getGradientPercentage();
136
        vertical = theme.getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL);
136
        vertical = false;
137
        
137
138
        // Note: This is currently being overridden in PartTabFolderPresentation
138
        control.setBackground(c, percent, vertical);		
139
        control.setBackground(c, percent, vertical);		
139
140
140
        if (presentation.isActive()) {                
141
        if (presentation.isActive()) {                
(-)Eclipse UI/org/eclipse/ui/internal/IWorkbenchThemeConstants.java (-4 / +1 lines)
Lines 30-37 Link Here
30
    public static final String INACTIVE_TAB_BG_END = "org.eclipse.ui.workbench.INACTIVE_TAB_BG_END"; //$NON-NLS-1$
30
    public static final String INACTIVE_TAB_BG_END = "org.eclipse.ui.workbench.INACTIVE_TAB_BG_END"; //$NON-NLS-1$
31
31
32
    public static final String ACTIVE_TAB_PERCENT = "org.eclipse.ui.workbench.ACTIVE_TAB_PERCENT"; //$NON-NLS-1$
32
    public static final String ACTIVE_TAB_PERCENT = "org.eclipse.ui.workbench.ACTIVE_TAB_PERCENT"; //$NON-NLS-1$
33
    public static final String INACTIVE_TAB_PERCENT = "org.eclipse.ui.workbench.INACTIVE_TAB_PERCENT"; //$NON-NLS-1$
33
    public static final String ACTIVE_TAB_VERTICAL = "org.eclipse.ui.workbench.ACTIVE_TAB_VERTICAL"; //$NON-NLS-1$    
34
35
    public static final String ACTIVE_TAB_VERTICAL = "org.eclipse.ui.workbench.ACTIVE_TAB_VERTICAL"; //$NON-NLS-1$
36
    public static final String INACTIVE_TAB_VERTICAL = "org.eclipse.ui.workbench.INACTIVE_TAB_VERTICAL"; //$NON-NLS-1$    
37
}
34
}
(-)Eclipse UI/org/eclipse/ui/internal/PartTabFolder.java (-14 / +10 lines)
Lines 40-45 Link Here
40
import org.eclipse.ui.presentations.StackDropResult;
40
import org.eclipse.ui.presentations.StackDropResult;
41
import org.eclipse.ui.presentations.StackPresentation;
41
import org.eclipse.ui.presentations.StackPresentation;
42
42
43
/**
44
 * Manages a set of ViewPanes that are docked into the workbench window. The container for a PartTabFolder
45
 * is always a PartSashContainer (or null), and its children are always either PartPlaceholders or PartPanes.
46
 * 
47
 * TODO: write a common base class for EditorWorkbook and PartTabFolder.
48
 * TODO: remove the LayoutPart superclass. All code can either refer to PartPane, 
49
 * PartPlaceholder, PartSashContainer, or the common base class for EditorWorkbook and PartTabFolder.
50
 * The frequent downcasting is due to the fact that much of the code tries to use LayoutPart 
51
 * or ILayoutContainer references for many different purposes.
52
 */
43
public class PartTabFolder extends LayoutPart implements ILayoutContainer {
53
public class PartTabFolder extends LayoutPart implements ILayoutContainer {
44
54
45
    private boolean active = false;
55
    private boolean active = false;
Lines 537-556 Link Here
537
        DragUtil
547
        DragUtil
538
                .performDrag(part, DragUtil.getDisplayBounds(part.getControl()));
548
                .performDrag(part, DragUtil.getDisplayBounds(part.getControl()));
539
    }
549
    }
540
541
    /**
542
     * Returns the current presentable part, or null if there is no current
543
     * selection
544
     * 
545
     * @return the current presentable part, or null if there is no current
546
     *         selection
547
     */
548
    /*
549
     * not used private IPresentablePart getCurrentPresentablePart() { if
550
     * (current != null) { return current.getPresentablePart(); }
551
     * 
552
     * return null; }
553
     */
554
550
555
    private void presentationSelectionChanged(IPresentablePart newSelection) {
551
    private void presentationSelectionChanged(IPresentablePart newSelection) {
556
        setSelection(getLayoutPart(newSelection));
552
        setSelection(getLayoutPart(newSelection));
(-)Eclipse UI/org/eclipse/ui/internal/PresentableEditorPart.java (+8 lines)
Lines 15-20 Link Here
15
15
16
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.swt.graphics.Image;
17
import org.eclipse.swt.graphics.Rectangle;
17
import org.eclipse.swt.graphics.Rectangle;
18
import org.eclipse.swt.widgets.Control;
18
import org.eclipse.ui.IEditorReference;
19
import org.eclipse.ui.IEditorReference;
19
import org.eclipse.ui.IPropertyListener;
20
import org.eclipse.ui.IPropertyListener;
20
import org.eclipse.ui.presentations.IPresentablePart;
21
import org.eclipse.ui.presentations.IPresentablePart;
Lines 97-101 Link Here
97
	public boolean isBusy() {
98
	public boolean isBusy() {
98
		// editors do not support busy currently
99
		// editors do not support busy currently
99
		return false;
100
		return false;
101
	}
102
103
	/* (non-Javadoc)
104
	 * @see org.eclipse.ui.presentations.IPresentablePart#getToolBar()
105
	 */
106
	public Control getToolBar() {
107
		return null;
100
	}
108
	}
101
}
109
}
(-)Eclipse UI/org/eclipse/ui/internal/PresentableViewPart.java (-1 / +8 lines)
Lines 17-22 Link Here
17
import org.eclipse.jface.util.PropertyChangeEvent;
17
import org.eclipse.jface.util.PropertyChangeEvent;
18
import org.eclipse.swt.graphics.Image;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Rectangle;
19
import org.eclipse.swt.graphics.Rectangle;
20
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.ui.IPropertyListener;
21
import org.eclipse.ui.IPropertyListener;
21
import org.eclipse.ui.IViewReference;
22
import org.eclipse.ui.IViewReference;
22
import org.eclipse.ui.IWorkbenchPartSite;
23
import org.eclipse.ui.IWorkbenchPartSite;
Lines 27-33 Link Here
27
28
28
    private final List listeners = new ArrayList();
29
    private final List listeners = new ArrayList();
29
 
30
 
30
31
    private ViewPane pane;
31
    private ViewPane pane;
32
    
32
    
33
    private boolean busy = false;
33
    private boolean busy = false;
Lines 121-126 Link Here
121
	 */
121
	 */
122
	public boolean isBusy() {
122
	public boolean isBusy() {
123
		return busy;
123
		return busy;
124
	}
125
126
	/* (non-Javadoc)
127
	 * @see org.eclipse.ui.presentations.IPresentablePart#getToolBar()
128
	 */
129
	public Control getToolBar() {
130
		return pane.getToolBarManager().getControl();
124
	}
131
	}
125
	
132
	
126
	
133
	
(-)Eclipse UI/org/eclipse/ui/internal/ViewPane.java (-22 / +68 lines)
Lines 37-43 Link Here
37
import org.eclipse.swt.widgets.Control;
37
import org.eclipse.swt.widgets.Control;
38
import org.eclipse.swt.widgets.Menu;
38
import org.eclipse.swt.widgets.Menu;
39
import org.eclipse.swt.widgets.MenuItem;
39
import org.eclipse.swt.widgets.MenuItem;
40
import org.eclipse.swt.widgets.Sash;
41
import org.eclipse.swt.widgets.Shell;
40
import org.eclipse.swt.widgets.Shell;
42
import org.eclipse.swt.widgets.Text;
41
import org.eclipse.swt.widgets.Text;
43
import org.eclipse.swt.widgets.ToolBar;
42
import org.eclipse.swt.widgets.ToolBar;
Lines 95-103 Link Here
95
	 */
94
	 */
96
	private boolean showMenuButton = false;
95
	private boolean showMenuButton = false;
97
96
98
	//Created in o.e.ui.Perspective, disposed there.
99
	private Sash fastViewSash;
100
101
	/**
97
	/**
102
	 * Toolbar manager for the ISV toolbar.
98
	 * Toolbar manager for the ISV toolbar.
103
	 */
99
	 */
Lines 289-296 Link Here
289
		// All actions on the System toolbar should be accessible on the pane menu.
285
		// All actions on the System toolbar should be accessible on the pane menu.
290
		if (control.getContent() == null) {
286
		if (control.getContent() == null) {
291
			// content can be null if view creation failed
287
			// content can be null if view creation failed
292
			if (locked)
288
//			if (locked)
293
				control.setTabList(new Control[] { isvToolBar , viewToolBar });
289
//				control.setTabList(new Control[] { isvToolBar , viewToolBar });
294
		} else {
290
		} else {
295
			if (locked)
291
			if (locked)
296
				control.setTabList(new Control[] { viewToolBar, control.getContent()});
292
				control.setTabList(new Control[] { viewToolBar, control.getContent()});
Lines 440-450 Link Here
440
	
436
	
441
	private void toolBarResized(ToolBar toolBar, int newSize) {
437
	private void toolBarResized(ToolBar toolBar, int newSize) {
442
		if (locked) {
438
		if (locked) {
443
			if (toolBar == viewToolBar) {
439
			//if (toolBar == viewToolBar) {
444
				((ViewForm)control).setTopRight(newSize == 0 ? null :viewToolBar);
440
			//	((ViewForm)control).setTopRight(newSize == 0 ? null :viewToolBar);
445
			} else if (toolBar == isvToolBar) {
441
			//} 
446
				((ViewForm)control).setTopCenter(newSize == 0 ? null : isvToolBar);
442
//			else if (toolBar == isvToolBar) {
447
			}
443
				//((ViewForm)control).setTopCenter(newSize == 0 ? null : isvToolBar);
444
			//}
448
		}
445
		}
449
	}
446
	}
450
	
447
	
Lines 490-496 Link Here
490
		
487
		
491
		// ISV toolbar.
488
		// ISV toolbar.
492
		//			// 1GD0ISU: ITPUI:ALL - Dbl click on view tool cause zoom
489
		//			// 1GD0ISU: ITPUI:ALL - Dbl click on view tool cause zoom
493
		isvToolBar = new ToolBar(parentControl, barStyle);
490
		isvToolBar = new ToolBar(parentControl.getParent(), barStyle);
494
		
491
		
495
		
492
		
496
		
493
		
Lines 503-509 Link Here
503
				}
500
				}
504
			});
501
			});
505
		} else {
502
		} else {
506
			isvToolBar.setLayoutData(new GridData(GridData.FILL_BOTH));
503
			//isvToolBar.setLayoutData(new GridData(GridData.FILL_BOTH));
507
		}
504
		}
508
		IContributionItem[] isvItems = null;
505
		IContributionItem[] isvItems = null;
509
		if (isvToolBarMgr != null) {
506
		if (isvToolBarMgr != null) {
Lines 521-528 Link Here
521
		// whenever updating the tab colors
518
		// whenever updating the tab colors
522
		if (viewToolBar != null)
519
		if (viewToolBar != null)
523
		    ColorSchemeService.setViewColors(viewToolBar);
520
		    ColorSchemeService.setViewColors(viewToolBar);
524
		ColorSchemeService.setViewColors(isvToolBar);
521
		//ColorSchemeService.setViewColors(isvToolBar);
525
		ColorSchemeService.setViewColors(isvToolBar.getParent());
522
		//ColorSchemeService.setViewColors(isvToolBar.getParent());
526
	}
523
	}
527
	
524
	
528
	/**
525
	/**
Lines 664-672 Link Here
664
			viewToolBarMgr.update(true);
661
			viewToolBarMgr.update(true);
665
		}
662
		}
666
	}
663
	}
667
	public void setFastViewSash(Sash s) {
668
		fastViewSash = s;
669
	}
670
664
671
	/* (non-Javadoc)
665
	/* (non-Javadoc)
672
	 * Method declared on PartPane.
666
	 * Method declared on PartPane.
Lines 797-806 Link Here
797
	 */
791
	 */
798
	protected Sashes findSashes() {
792
	protected Sashes findSashes() {
799
		Sashes result = new Sashes();
793
		Sashes result = new Sashes();
800
		if (isFastView()) {
801
			result.right = fastViewSash;
802
			return result;
803
		}
804
		
794
		
805
		ILayoutContainer container = getContainer();
795
		ILayoutContainer container = getContainer();
806
		
796
		
Lines 1085-1088 Link Here
1085
	public IPresentablePart getPresentablePart() {
1075
	public IPresentablePart getPresentablePart() {
1086
		return presentableAdapter;
1076
		return presentableAdapter;
1087
	}
1077
	}
1078
	
1079
	/* (non-Javadoc)
1080
	 * @see org.eclipse.ui.internal.LayoutPart#reparent(org.eclipse.swt.widgets.Composite)
1081
	 */
1082
	public void reparent(Composite newParent) {
1083
		super.reparent(newParent);
1084
		
1085
		if (isvToolBar != null) {
1086
			isvToolBar.setParent(newParent);
1087
		}
1088
	}
1089
	
1090
	/* (non-Javadoc)
1091
	 * @see org.eclipse.ui.internal.LayoutPart#moveAbove(org.eclipse.swt.widgets.Control)
1092
	 */
1093
	public void moveAbove(Control refControl) {
1094
		super.moveAbove(refControl);
1095
		
1096
		isvToolBar.moveAbove(control);
1097
	}
1098
	
1099
	/* (non-Javadoc)
1100
	 * @see org.eclipse.ui.internal.LayoutPart#setVisible(boolean)
1101
	 */
1102
	public void setVisible(boolean makeVisible) {
1103
		super.setVisible(makeVisible);
1104
		
1105
		if (isvToolBar != null) {
1106
			isvToolBar.setVisible(makeVisible);
1107
		}
1108
	}
1109
1110
	/**
1111
	 * @param bounds
1112
	 */
1113
	public void setToolbarBounds(Rectangle bounds) {
1114
		if (isvToolBar != null) {
1115
			isvToolBar.update();
1116
			isvToolBar.setBounds(bounds);
1117
		}
1118
	}
1119
1120
	/**
1121
	 * @param hint
1122
	 * @param hint2
1123
	 * @return
1124
	 */
1125
	public Point computePreferredToolbarSize(int hint, int hint2) {
1126
		if (isvToolBar != null) {
1127
			isvToolBar.update();
1128
			return isvToolBar.computeSize(hint, hint2);
1129
		}
1130
		
1131
		return new Point(0,0);
1132
	}
1133
	
1088
}
1134
}
(-)Eclipse UI/org/eclipse/ui/internal/presentations/BasicStackPresentation.java (-26 / +137 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.presentations;
11
package org.eclipse.ui.internal.presentations;
12
12
13
import java.util.ArrayList;
14
import java.util.List;
15
13
import org.eclipse.jface.action.IMenuManager;
16
import org.eclipse.jface.action.IMenuManager;
14
import org.eclipse.jface.action.MenuManager;
17
import org.eclipse.jface.action.MenuManager;
15
import org.eclipse.jface.resource.FontRegistry;
18
import org.eclipse.jface.resource.FontRegistry;
Lines 24-39 Link Here
24
import org.eclipse.swt.events.MouseAdapter;
27
import org.eclipse.swt.events.MouseAdapter;
25
import org.eclipse.swt.events.MouseEvent;
28
import org.eclipse.swt.events.MouseEvent;
26
import org.eclipse.swt.events.MouseListener;
29
import org.eclipse.swt.events.MouseListener;
30
import org.eclipse.swt.events.SelectionAdapter;
31
import org.eclipse.swt.events.SelectionEvent;
27
import org.eclipse.swt.graphics.Color;
32
import org.eclipse.swt.graphics.Color;
33
import org.eclipse.swt.graphics.Image;
28
import org.eclipse.swt.graphics.Point;
34
import org.eclipse.swt.graphics.Point;
29
import org.eclipse.swt.graphics.Rectangle;
35
import org.eclipse.swt.graphics.Rectangle;
30
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.swt.widgets.Control;
37
import org.eclipse.swt.widgets.Display;
31
import org.eclipse.swt.widgets.Event;
38
import org.eclipse.swt.widgets.Event;
32
import org.eclipse.swt.widgets.Listener;
39
import org.eclipse.swt.widgets.Listener;
33
import org.eclipse.swt.widgets.Menu;
40
import org.eclipse.swt.widgets.Menu;
41
import org.eclipse.swt.widgets.ToolBar;
42
import org.eclipse.swt.widgets.ToolItem;
34
import org.eclipse.ui.IPropertyListener;
43
import org.eclipse.ui.IPropertyListener;
35
import org.eclipse.ui.PlatformUI;
44
import org.eclipse.ui.PlatformUI;
45
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
36
import org.eclipse.ui.internal.IWorkbenchThemeConstants;
46
import org.eclipse.ui.internal.IWorkbenchThemeConstants;
47
import org.eclipse.ui.internal.WorkbenchImages;
48
import org.eclipse.ui.internal.WorkbenchMessages;
37
import org.eclipse.ui.presentations.IPresentablePart;
49
import org.eclipse.ui.presentations.IPresentablePart;
38
import org.eclipse.ui.presentations.IStackPresentationSite;
50
import org.eclipse.ui.presentations.IStackPresentationSite;
39
import org.eclipse.ui.presentations.PresentationUtil;
51
import org.eclipse.ui.presentations.PresentationUtil;
Lines 52-57 Link Here
52
	private boolean activeState = false;
64
	private boolean activeState = false;
53
	private int tabPosition;
65
	private int tabPosition;
54
	private MenuManager systemMenuManager = new MenuManager();
66
	private MenuManager systemMenuManager = new MenuManager();
67
	private TabFolderLayout layout;
68
	
69
	//private ToolBar viewToolBar;
70
	//private ToolBarManager viewToolBarMgr;
71
	
72
	// Controls which will be inserted into the title bar if there is room, or above the client pane
73
	// if not
74
	private List topControls = new ArrayList();
75
	
76
	// Stand-in for the top controls
77
	//private Composite toolbarProxy;
55
	
78
	
56
	private int mousedownState = -1;
79
	private int mousedownState = -1;
57
	
80
	
Lines 128-133 Link Here
128
		}
151
		}
129
	};
152
	};
130
	
153
	
154
	public int getTopTrimStart() {
155
		return layout.getTrimStart();
156
	}
157
	
131
	private Listener resizeListener = new Listener() {
158
	private Listener resizeListener = new Listener() {
132
		public void handleEvent(Event e) {
159
		public void handleEvent(Event e) {
133
			setControlSize();
160
			setControlSize();
Lines 166-175 Link Here
166
			}
193
			}
167
		}
194
		}
168
	};
195
	};
196
	private ToolBar viewToolBar;
169
197
170
	public BasicStackPresentation(CTabFolder control, IStackPresentationSite stackSite) {
198
	public BasicStackPresentation(CTabFolder control, IStackPresentationSite stackSite) {
171
	    super(stackSite);
199
	    super(stackSite);
172
		tabFolder = control;
200
		tabFolder = control;
201
		layout = new TabFolderLayout(tabFolder);
173
		
202
		
174
		// listener to switch between visible tabItems
203
		// listener to switch between visible tabItems
175
		tabFolder.addListener(SWT.Selection, selectionListener);
204
		tabFolder.addListener(SWT.Selection, selectionListener);
Lines 204-210 Link Here
204
				}
233
				}
205
			}
234
			}
206
		});
235
		});
207
						
236
		
237
		tabFolder.setTabHeight(24);
238
		
239
		viewToolBar = new ToolBar(control.getParent(), SWT.HORIZONTAL | SWT.FLAT | SWT.WRAP);
240
		
241
		ToolItem pullDownButton = new ToolItem(viewToolBar, SWT.PUSH);
242
		//				Image img = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
243
		Image hoverImage =
244
			WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU_HOVER);
245
		pullDownButton.setDisabledImage(hoverImage); // TODO: comment this out?
246
		// PR#1GE56QT - Avoid creation of unnecessary image.
247
		pullDownButton.setImage(hoverImage);
248
		//				pullDownButton.setHotImage(hoverImage);
249
		pullDownButton.setToolTipText(WorkbenchMessages.getString("Menu")); //$NON-NLS-1$
250
		pullDownButton.addSelectionListener(new SelectionAdapter() {
251
			public void widgetSelected(SelectionEvent e) {
252
				//showViewMenu();
253
			}
254
		});
255
		
256
		viewToolBar.setVisible(true);
257
		//viewToolBar.moveAbove(null);
258
		
259
		// Insert a bogus composite into the top-right of the tab folder. We do this to keep
260
		// track of where to draw the toolbars.
261
		//toolbarProxy = new Composite(tabFolder, SWT.NONE);
262
		
263
		//tabFolder.setTopRight(toolbarProxy);
208
	}
264
	}
209
265
210
	/**
266
	/**
Lines 306-313 Link Here
306
	}
362
	}
307
	
363
	
308
	public void drawGradient(Color fgColor, Color [] bgColors, int [] percentages, boolean vertical) {
364
	public void drawGradient(Color fgColor, Color [] bgColors, int [] percentages, boolean vertical) {
365
		Display display = tabFolder.getDisplay();
366
		Color c = display.getSystemColor(SWT.COLOR_BLUE);
367
368
		//fgColor = c;
369
//		tabFolder.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), 
370
//				 		                           display.getSystemColor(SWT.COLOR_BLUE),
371
//				 		                           display.getSystemColor(SWT.COLOR_WHITE), 
372
//				 		                           display.getSystemColor(SWT.COLOR_WHITE)},
373
//				 		               new int[] {25, 50, 100});
374
		
375
		//tabFolder.setBackground(display.getSystemColor(SWT.COLOR_DARK_BLUE));
376
		
309
		tabFolder.setSelectionForeground(fgColor);
377
		tabFolder.setSelectionForeground(fgColor);
310
		tabFolder.setSelectionBackground(bgColors, percentages, vertical);			    
378
		tabFolder.setSelectionBackground(bgColors, percentages, vertical);	
311
	}
379
	}
312
	
380
	
313
	public boolean isActive() {
381
	public boolean isActive() {
Lines 317-347 Link Here
317
	/**
385
	/**
318
	 * Set the size of a page in the folder.
386
	 * Set the size of a page in the folder.
319
	 */
387
	 */
320
	private void setControlSize() {
388
	protected void setControlSize() {
321
		if (current == null || tabFolder == null)
389
		if (current == null || tabFolder == null)
322
			return;
390
			return;
323
//		Rectangle bounds;
391
324
		// @issue as above, the mere presence of a theme should not change the behaviour
392
		layout.layout();
325
//		if ((mapTabToPart.size() > 1)
393
		
326
//			|| ((tabThemeDescriptor != null) && (mapTabToPart.size() >= 1)))
394
		current.setBounds(layout.getClientBounds());
327
//			bounds = calculatePageBounds(tabFolder);
395
	}
328
//		else
396
	
329
//			bounds = tabFolder.getBounds();
397
	protected boolean isTrimOnTop() {
330
		current.setBounds(calculatePageBounds(tabFolder));
398
		return layout.isTrimOnTop();
331
		//current.moveAbove(tabFolder);
399
	}
332
	}
400
	
333
	
401
//	protected Control[] getTopRight() {
334
	public static Rectangle calculatePageBounds(CTabFolder folder) {
402
//		return layout.getTopRight();
335
		if (folder == null)
403
//	}
336
			return new Rectangle(0, 0, 0, 0);
337
		Rectangle bounds = folder.getBounds();
338
		Rectangle offset = folder.getClientArea();
339
		bounds.x += offset.x;
340
		bounds.y += offset.y;
341
		bounds.width = offset.width;
342
		bounds.height = offset.height;
343
		return bounds;
344
	}	
345
	
404
	
346
	/* (non-Javadoc)
405
	/* (non-Javadoc)
347
	 * @see org.eclipse.ui.internal.skins.Presentation#dispose()
406
	 * @see org.eclipse.ui.internal.skins.Presentation#dispose()
Lines 355-360 Link Here
355
		
414
		
356
		tabFolder.dispose();
415
		tabFolder.dispose();
357
		tabFolder = null;
416
		tabFolder = null;
417
		
418
		viewToolBar.dispose();
358
	}
419
	}
359
	
420
	
360
	/* (non-Javadoc)
421
	/* (non-Javadoc)
Lines 444-457 Link Here
444
			setControlSize();
505
			setControlSize();
445
			current.setVisible(true);			
506
			current.setVisible(true);			
446
		}
507
		}
508
		
509
		// Set up the top-right controls
510
		List topRight = new ArrayList(2);
511
		
512
		Control toolbar = getCurrentToolbar();
513
		
514
		if (toolbar != null) {
515
			topRight.add(toolbar);
516
		} 
517
		
518
		viewToolBar.moveAbove(null);
519
		viewToolBar.setBackground(toolbar.getBackground());
520
		topRight.add(viewToolBar);
521
		
522
		Control[] controls = (Control[])topRight.toArray(new Control[topRight.size()]);
523
		
524
		layout.setTopRight(controls);
447
	}
525
	}
448
	
526
	
527
	
528
	public IPresentablePart getCurrentPart() {
529
		return current;
530
	}
531
	
532
//	protected void setTopRight(List topRight) {
533
//		layout.setTopRight(topRight);
534
//		setControlSize();
535
//	}
536
	
449
	/* (non-Javadoc)
537
	/* (non-Javadoc)
450
	 * @see org.eclipse.ui.internal.skins.Presentation#setBounds(org.eclipse.swt.graphics.Rectangle)
538
	 * @see org.eclipse.ui.internal.skins.Presentation#setBounds(org.eclipse.swt.graphics.Rectangle)
451
	 */
539
	 */
452
	public void setBounds(Rectangle bounds) {
540
	public void setBounds(Rectangle bounds) {
453
		tabFolder.setBounds(bounds);
541
		tabFolder.setBounds(bounds);
454
		setControlSize();
542
		setControlSize();
543
		viewToolBar.moveAbove(getControl());
455
	}
544
	}
456
	
545
	
457
	/* (non-Javadoc)
546
	/* (non-Javadoc)
Lines 508-514 Link Here
508
	 * @see org.eclipse.ui.internal.skins.StackPresentation#dragOver(org.eclipse.swt.widgets.Control, org.eclipse.swt.graphics.Point)
597
	 * @see org.eclipse.ui.internal.skins.StackPresentation#dragOver(org.eclipse.swt.widgets.Control, org.eclipse.swt.graphics.Point)
509
	 */
598
	 */
510
	public StackDropResult dragOver(Control currentControl, Point location) {
599
	public StackDropResult dragOver(Control currentControl, Point location) {
511
		
512
		// Determine which tab we're currently dragging over
600
		// Determine which tab we're currently dragging over
513
		Point localPos = tabFolder.toControl(location);
601
		Point localPos = tabFolder.toControl(location);
514
		final CTabItem tabUnderPointer = tabFolder.getItem(localPos);
602
		final CTabItem tabUnderPointer = tabFolder.getItem(localPos);
Lines 522-525 Link Here
522
		return new StackDropResult(Geometry.toDisplay(tabFolder, tabUnderPointer.getBounds()),
610
		return new StackDropResult(Geometry.toDisplay(tabFolder, tabUnderPointer.getBounds()),
523
			tabFolder.indexOf(tabUnderPointer));
611
			tabFolder.indexOf(tabUnderPointer));
524
	}
612
	}
613
	
614
	public int getGradientPercentage() {
615
		Rectangle clientBounds = getTabFolder().getBounds();
616
		
617
		int percentage = clientBounds.width == 0 ? 100 : Math.min(100, 
618
				100 * getTopTrimStart() / clientBounds.width);
619
		
620
		if (percentage < 0) {
621
			percentage = 0;
622
		}
623
		
624
		return percentage;	    
625
	}
626
	
627
	protected Control getCurrentToolbar() {
628
		IPresentablePart part = getCurrentPart();		
629
		if (part == null) {
630
			return null;
631
		}
632
633
		return part.getToolBar();
634
	}
635
	
525
}
636
}
(-)Eclipse UI/org/eclipse/ui/internal/presentations/EditorPresentation.java (-2 / +2 lines)
Lines 269-276 Link Here
269
            		.get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR);           
269
            		.get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR);           
270
            bgColors[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
270
            bgColors[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
271
            bgColors[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
271
            bgColors[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
272
            percent[0] = currentTheme.getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT);
272
            percent[0] = getGradientPercentage();
273
            vertical = currentTheme.getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL);            
273
            vertical = false;            
274
        }
274
        }
275
275
276
        getTabFolder()
276
        getTabFolder()
(-)Eclipse UI/org/eclipse/ui/internal/presentations/PartTabFolderPresentation.java (-4 / +58 lines)
Lines 21-31 Link Here
21
import org.eclipse.swt.graphics.Color;
21
import org.eclipse.swt.graphics.Color;
22
import org.eclipse.swt.graphics.Font;
22
import org.eclipse.swt.graphics.Font;
23
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.ui.PlatformUI;
25
import org.eclipse.ui.PlatformUI;
25
import org.eclipse.ui.internal.ColorSchemeService;
26
import org.eclipse.ui.internal.ColorSchemeService;
26
import org.eclipse.ui.internal.IPreferenceConstants;
27
import org.eclipse.ui.internal.IPreferenceConstants;
27
import org.eclipse.ui.internal.IWorkbenchThemeConstants;
28
import org.eclipse.ui.internal.IWorkbenchThemeConstants;
28
import org.eclipse.ui.internal.WorkbenchPlugin;
29
import org.eclipse.ui.internal.WorkbenchPlugin;
30
import org.eclipse.ui.presentations.IPresentablePart;
29
import org.eclipse.ui.presentations.IStackPresentationSite;
31
import org.eclipse.ui.presentations.IStackPresentationSite;
30
import org.eclipse.ui.themes.ITheme;
32
import org.eclipse.ui.themes.ITheme;
31
33
Lines 36-43 Link Here
36
 */
38
 */
37
public class PartTabFolderPresentation extends BasicStackPresentation {
39
public class PartTabFolderPresentation extends BasicStackPresentation {
38
	
40
	
39
	private IPreferenceStore preferenceStore = WorkbenchPlugin.getDefault().getPreferenceStore();
41
	private IPreferenceStore preferenceStore = WorkbenchPlugin.getDefault().getPreferenceStore();	
40
		
42
	
41
	private final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
43
	private final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
42
		public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
44
		public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
43
			if (IPreferenceConstants.VIEW_TAB_POSITION.equals(propertyChangeEvent.getProperty()) && !isDisposed()) {
45
			if (IPreferenceConstants.VIEW_TAB_POSITION.equals(propertyChangeEvent.getProperty()) && !isDisposed()) {
Lines 53-60 Link Here
53
	public PartTabFolderPresentation(Composite parent, IStackPresentationSite newSite, int flags) {
55
	public PartTabFolderPresentation(Composite parent, IStackPresentationSite newSite, int flags) {
54
		
56
		
55
		super(new CTabFolder(parent, SWT.BORDER), newSite);
57
		super(new CTabFolder(parent, SWT.BORDER), newSite);
58
		
56
		CTabFolder tabFolder = getTabFolder();
59
		CTabFolder tabFolder = getTabFolder();
57
		
60
		
61
		tabFolder.setBackground(parent.getBackground());
62
		
58
		preferenceStore.addPropertyChangeListener(propertyChangeListener);
63
		preferenceStore.addPropertyChangeListener(propertyChangeListener);
59
		int tabLocation = preferenceStore.getInt(IPreferenceConstants.VIEW_TAB_POSITION); 
64
		int tabLocation = preferenceStore.getInt(IPreferenceConstants.VIEW_TAB_POSITION); 
60
		
65
		
Lines 75-80 Link Here
75
		
80
		
76
		tabFolder.setMinimizeVisible((flags & SWT.MIN) != 0);
81
		tabFolder.setMinimizeVisible((flags & SWT.MIN) != 0);
77
		tabFolder.setMaximizeVisible((flags & SWT.MAX) != 0);
82
		tabFolder.setMaximizeVisible((flags & SWT.MAX) != 0);
83
		
78
	}
84
	}
79
	
85
	
80
	/**
86
	/**
Lines 117-125 Link Here
117
	        fgColor = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR);
123
	        fgColor = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR);
118
            bgColors[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
124
            bgColors[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
119
            bgColors[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
125
            bgColors[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
120
            percent[0] = currentTheme.getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT);
126
            percent[0] = getGradientPercentage();
121
            vertical = currentTheme.getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL);
127
            vertical = false;
122
		}	
128
		}	
129
        
123
		drawGradient(fgColor, bgColors, percent, vertical);	
130
		drawGradient(fgColor, bgColors, percent, vertical);	
124
	}
131
	}
125
	
132
	
Lines 137-141 Link Here
137
	public void dispose() {
144
	public void dispose() {
138
		preferenceStore.removePropertyChangeListener(propertyChangeListener);
145
		preferenceStore.removePropertyChangeListener(propertyChangeListener);
139
		super.dispose();
146
		super.dispose();
147
	}
148
	/* (non-Javadoc)
149
	 * @see org.eclipse.ui.internal.presentations.BasicStackPresentation#setControlSize()
150
	 */
151
	protected void setControlSize() {		
152
		super.setControlSize();
153
		
154
		updateTitleGradient();
155
	}
156
		
157
	/* (non-Javadoc)
158
	 * @see org.eclipse.ui.presentations.StackPresentation#selectPart(org.eclipse.ui.presentations.IPresentablePart)
159
	 */
160
	public void selectPart(IPresentablePart toSelect) {
161
		super.selectPart(toSelect);
162
		
163
		//getTabFolder().redraw();
164
		//updateToolbar();
165
		updateTitleGradient();
166
		
167
		Control toolbar = getCurrentToolbar();
168
		
169
		if (toolbar != null) {
170
			ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();	    
171
			ColorRegistry colorRegistry = currentTheme.getColorRegistry();
172
				
173
		    Color c = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
174
	
175
			toolbar.setBackground(c);
176
		}
177
	}
178
	
179
	/**
180
	 * Updates the title's gradient based on the current size and position of 
181
	 * the toolbar. 
182
	 */
183
	protected void updateTitleGradient() {
184
//		ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();	    
185
//		ColorRegistry colorRegistry = currentTheme.getColorRegistry();
186
//		
187
//		Color [] c = new Color[2];
188
//		c[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
189
//		c[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
190
//
191
//		int[] percents = new int[] {getGradientPercentage()};				
192
//       
193
//		getTabFolder().setBackground(c, percents, false);
140
	}
194
	}
141
}
195
}
(-)Eclipse UI/org/eclipse/ui/internal/themes/WorkbenchPreview.java (-1 / +1 lines)
Lines 148-154 Link Here
148
        Color [] colors = new Color[2];
148
        Color [] colors = new Color[2];
149
        colors[0] = theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
149
        colors[0] = theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
150
        colors[1] = theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
150
        colors[1] = theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
151
        folder.setBackground(colors, new int [] {theme.getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT)}, theme.getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL));
151
        folder.setBackground(colors, new int [] {100}, false);
152
        toolBar.setBackground(colors[1]);
152
        toolBar.setBackground(colors[1]);
153
        viewMessage.setBackground(colors[1]);
153
        viewMessage.setBackground(colors[1]);
154
        viewForm.setBackground(colors[1]);
154
        viewForm.setBackground(colors[1]);
(-)Eclipse UI/org/eclipse/ui/presentations/IPresentablePart.java (+10 lines)
Lines 12-17 Link Here
12
12
13
import org.eclipse.swt.graphics.Image;
13
import org.eclipse.swt.graphics.Image;
14
import org.eclipse.swt.graphics.Rectangle;
14
import org.eclipse.swt.graphics.Rectangle;
15
import org.eclipse.swt.widgets.Control;
15
import org.eclipse.ui.IPropertyListener;
16
import org.eclipse.ui.IPropertyListener;
16
17
17
/**
18
/**
Lines 61-66 Link Here
61
	 *   <li><code>IWorkbenchPart.PROP_TITLE</code> </li>
62
	 *   <li><code>IWorkbenchPart.PROP_TITLE</code> </li>
62
	 *   <li><code>IEditorPart.PROP_INPUT</code> </li>
63
	 *   <li><code>IEditorPart.PROP_INPUT</code> </li>
63
	 *   <li><code>IEditorPart.PROP_DIRTY</code> </li>
64
	 *   <li><code>IEditorPart.PROP_DIRTY</code> </li>
65
	 *   <li><code>IWorkbenchPart.PROP_TOOLBAR</code> </li>
64
	 * </ul>
66
	 * </ul>
65
	 * </p>
67
	 * </p>
66
	 *
68
	 *
Lines 138-142 Link Here
138
	 * @return boolean true if busy
140
	 * @return boolean true if busy
139
	 */
141
	 */
140
	public boolean isBusy();
142
	public boolean isBusy();
143
144
	/**
145
	 * Returns the local toolbar for this part, or null if this part does not
146
	 * have a local toolbar. Callers must not dispose or downcast the return value.
147
	 * 
148
	 * @return the local toolbar for the part, or null if none
149
	 */
150
	public Control getToolBar();
141
	
151
	
142
}
152
}
(-)Eclipse (+90 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal;
12
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.graphics.Point;
15
import org.eclipse.swt.graphics.Rectangle;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Control;
18
import org.eclipse.swt.widgets.Event;
19
import org.eclipse.swt.widgets.Layout;
20
import org.eclipse.swt.widgets.Listener;
21
22
/**
23
 * This class creates an invisible SWT control that can be inserted as a placeholder into
24
 * a layout. This object can be subclassed in order to track sizing events.
25
 * 
26
 * @since 3.0
27
 */
28
public class ProxyControl {
29
	
30
	private Composite proxy;
31
	
32
	/**
33
	 * Creates a proxy control in the given parent.
34
	 *  
35
	 * @param parent the parent of the invisible proxy
36
	 * @param beingDragged a control whose size and position will always match that of the
37
	 * invisible proxy.
38
	 */
39
	public ProxyControl(Composite parent) {
40
		proxy = new Composite(parent, SWT.NONE);
41
		
42
		proxy.setLayout(new Layout() {
43
			protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
44
				return ProxyControl.this.computeSize(wHint, hHint, flushCache);
45
			}
46
47
			protected void layout(Composite composite, boolean flushCache) {
48
				setBounds(composite.getBounds());
49
			}
50
		});
51
		
52
		Listener boundsListener = new Listener() {
53
			public void handleEvent(Event e) {
54
				setBounds(proxy.getBounds());
55
			}
56
		};
57
		
58
		proxy.addListener(SWT.Resize, boundsListener);
59
		proxy.addListener(SWT.Move, boundsListener);
60
	}
61
	
62
	public void dispose() {
63
		proxy.dispose();
64
	}
65
	
66
	public Control getControl() {
67
		return proxy;
68
	}
69
	
70
	/**
71
	 * Subclasses can override to return the preferred size of the proxy
72
	 * 
73
	 * @param composite
74
	 * @param wHint
75
	 * @param hHint
76
	 * @param flushCache
77
	 * @return
78
	 */
79
	public Point computeSize(int wHint, int hHint, boolean flushCache) {
80
		return new Point(0,0);
81
	}
82
83
	/**
84
	 * Subclasses can override to capture resize events.
85
	 * 
86
	 * @param bounds
87
	 */
88
	public void setBounds(Rectangle bounds) {
89
	}
90
}
(-)Eclipse (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.presentations;
12
13
import org.eclipse.swt.graphics.Point;
14
import org.eclipse.swt.widgets.Control;
15
16
/**
17
 * Caches the preferred sizes of an array of controls
18
 * 
19
 * @since 3.0
20
 */
21
public class LayoutCache {
22
	private SizeCache[] caches;
23
	
24
	/**
25
	 * Creates a cache for the given array of controls
26
	 * 
27
	 * @param controls
28
	 */
29
	public LayoutCache(Control[] controls) {
30
		caches = new SizeCache[controls.length];
31
		for (int idx = 0; idx < controls.length; idx++) {
32
			caches[idx] = new SizeCache(controls[idx]);
33
		}
34
	}
35
	
36
	/**
37
	 * Computes the preferred size of the nth control
38
	 * 
39
	 * @param controlIndex index of the control whose size will be computed
40
	 * @param widthHint width of the control (or SWT.DEFAULT if unknown)
41
	 * @param heightHint height of the control (or SWT.DEFAULT if unknown)
42
	 * @return the preferred size of the control
43
	 */
44
	public Point computeSize(int controlIndex, int widthHint, int heightHint) {
45
		return caches[controlIndex].computeSize(widthHint, heightHint);
46
	}
47
	
48
	/**
49
	 * Flushes the cache
50
	 */
51
	public void flush() {
52
		for (int idx = 0; idx < caches.length; idx++) {
53
			caches[idx].flush();
54
		}
55
	}
56
}
(-)Eclipse (+119 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.presentations;
12
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.graphics.Point;
15
import org.eclipse.swt.widgets.Control;
16
17
/**
18
 * Caches the preferred size of an SWT control
19
 * 
20
 * @since 3.0
21
 */
22
public class SizeCache {
23
	private Control control;
24
	
25
	private Point preferredSize;	
26
	private Point cachedWidth;
27
	private Point cachedHeight;
28
29
	/**
30
	 * Creates a cache for size computations on the given control
31
	 * 
32
	 * @param control the control for which 
33
	 */
34
	public SizeCache(Control control) {
35
		this.control = control;		
36
	}
37
	
38
	/**
39
	 * Flush the cache (should be called if the control's contents may have changed since the
40
	 * last query)
41
	 */
42
	public void flush() {
43
		preferredSize = null;
44
		cachedWidth = null;
45
		cachedHeight = null;
46
	}
47
	
48
	/**
49
	 * Computes the preferred size of the control.
50
	 *  
51
	 * @param widthHint the known width of the control (pixels) or SWT.DEFAULT if unknown
52
	 * @param heightHint the known height of the control (pixels) or SWT.DEFAULT if unknown
53
	 * @return the preferred size of the control
54
	 */
55
	public Point computeSize(int widthHint, int heightHint) {
56
		// No hints given -- find the preferred size
57
		if (widthHint == SWT.DEFAULT && heightHint == SWT.DEFAULT) {
58
			if (preferredSize == null) {
59
				preferredSize = computeSize(control, widthHint, heightHint);
60
			}
61
			
62
			return preferredSize;
63
		}
64
		
65
		// Computing a width
66
		if (widthHint == SWT.DEFAULT) {
67
			if (preferredSize != null && heightHint == preferredSize.y) {
68
				return preferredSize;
69
			}
70
71
			if (cachedWidth == null || cachedWidth.y != heightHint) {
72
				cachedWidth = computeSize(control, widthHint, heightHint);
73
			}
74
			
75
			return cachedWidth;
76
		}
77
		
78
		// Computing a height
79
		if (heightHint == SWT.DEFAULT) {
80
			// Check if we're asking about the preferred width
81
			if (preferredSize != null && widthHint == preferredSize.x) {
82
				return preferredSize;
83
			}
84
			
85
			if (cachedHeight == null || cachedHeight.x != widthHint) {
86
				cachedHeight = computeSize(control, widthHint, heightHint);
87
			}
88
			
89
			return cachedHeight;
90
		}
91
		
92
		return computeSize(control, widthHint, heightHint);
93
	}
94
	
95
	/**
96
	 * Compute the control's size, and ensure that non-default hints are returned verbatim
97
	 * (this tries to compensate for SWT's hints, which aren't really the outer width of the
98
	 * control).
99
	 * 
100
	 * @param control
101
	 * @param widthHint
102
	 * @param heightHint
103
	 * @return
104
	 */
105
	private static Point computeSize(Control control, int widthHint, int heightHint) {
106
		Point result = control.computeSize(widthHint, heightHint);
107
		
108
		if (widthHint != SWT.DEFAULT) {
109
			result.x = widthHint;
110
		}
111
		
112
		if (heightHint != SWT.DEFAULT) {
113
			result.y = heightHint;
114
		}
115
		
116
		return result;
117
	}
118
	
119
}
(-)Eclipse (+287 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.presentations;
12
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.custom.CTabFolder;
15
import org.eclipse.swt.custom.CTabItem;
16
import org.eclipse.swt.graphics.Point;
17
import org.eclipse.swt.graphics.Rectangle;
18
import org.eclipse.swt.widgets.Control;
19
20
/**
21
 * Arranges the contents of a CTabFolder
22
 * 
23
 * @since 3.0
24
 */
25
public class TabFolderLayout {
26
	private CTabFolder tabFolder;
27
	private Control[] topControls;
28
	//private Control upperRightProxy;
29
	private LayoutCache cache;
30
	private Rectangle centerArea = new Rectangle(0,0,0,0);
31
	private int trimStart;
32
	private boolean trimOnTop = false;
33
	
34
	public TabFolderLayout(CTabFolder folder) {
35
		this.tabFolder = folder;
36
		
37
//		Composite cmp = new Composite(folder, SWT.DEFAULT);
38
//		upperRightProxy = cmp;
39
//		upperRightProxy.setVisible(false);
40
//		
41
//		cmp.setLayout(new Layout() {
42
//
43
//			protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
44
//				return new Point(10,10);
45
//			}
46
//
47
//			protected void layout(Composite composite, boolean flushCache) {
48
//				
49
//			}
50
//		});
51
52
		//tabFolder.setTopRight(upperRightProxy);
53
		setTopRight(new Control[0]);
54
	}
55
	
56
	public void dispose() {
57
		//tabFolder.setTopRight(null);
58
		//upperRightProxy.dispose();
59
	}
60
	
61
	public Control[] getTopRight() {
62
		return topControls;
63
	}
64
	
65
	public Rectangle getClientBounds() {
66
		return centerArea;
67
	}
68
	
69
	public int getTrimStart() {
70
		return trimStart;
71
	}
72
	
73
	public boolean isTrimOnTop() {
74
		return trimOnTop;
75
	}
76
	
77
	/**
78
	 * Sets the list of controls to be placed at the top-right of the CTabFolder
79
	 * 
80
	 * @param topRight a list of Control
81
	 */
82
	public void setTopRight(Control[] upperRight) {
83
		topControls = upperRight;
84
		
85
		cache = new LayoutCache(upperRight);
86
		layout();
87
	}
88
	
89
		/**
90
		 * Arranges all the controls in this layout
91
		 */
92
		public void layout() {
93
			cache.flush();		
94
	
95
	//		if (topControls.length == 0) {
96
	//			tabFolder.setTopRight(null);
97
	//		}
98
					
99
			Rectangle trimRegion = getTitleTrimRegion();
100
	
101
			Point trimSize = computeTrimSize();
102
			
103
			Rectangle bounds = tabFolder.getBounds();
104
			
105
			trimStart = bounds.width;
106
			
107
			Rectangle clientBounds = calculatePageBounds(tabFolder);
108
			
109
			trimOnTop = trimSize.x < trimRegion.width && trimSize.y < trimRegion.height; 
110
			// Check if we have room for all our topRight controls on the top border
111
			if (trimOnTop) {
112
				
113
				trimStart -= trimSize.x;
114
				
115
				align(0, topControls.length, trimRegion);
116
	
117
				centerArea = clientBounds;
118
				
119
				return;
120
			}
121
			
122
			// Else we need to place the controls below the title
123
			
124
			Rectangle currentRect = new Rectangle(clientBounds.x, clientBounds.y, clientBounds.width, 0);
125
			
126
			int idx = 0;
127
			while (idx < topControls.length) {
128
				int startOfRow = idx;
129
				currentRect.height = 0;
130
				int rowWidth = 0;
131
				
132
				int rowCount = 0;
133
				while (idx + rowCount < topControls.length) {
134
					Point nextSize = cache.computeSize(idx + rowCount, SWT.DEFAULT, SWT.DEFAULT);
135
					
136
					rowWidth += nextSize.x;
137
					
138
					if (rowWidth > clientBounds.width) {
139
						break;
140
					}
141
					
142
					currentRect.height = Math.max(currentRect.height, nextSize.y);
143
					
144
					rowCount++;
145
				}
146
				
147
				if (rowCount > 0) {
148
					align(idx, rowCount, currentRect);
149
					idx += rowCount;
150
				} else {
151
					Point size = cache.computeSize(idx, clientBounds.width, SWT.DEFAULT);
152
153
					currentRect.height = size.y;
154
					topControls[idx].setBounds(currentRect);
155
					
156
					idx++;
157
				}
158
				
159
				currentRect.y += currentRect.height;
160
			}
161
			
162
			centerArea = new Rectangle(clientBounds.x, currentRect.y, clientBounds.width, 
163
						clientBounds.height + clientBounds.y - currentRect.y);
164
		}
165
	
166
	/**
167
	 * Right-alignes a subset of the top controls in the given region.
168
	 * 
169
	 * @param firstControl the index of the leftmost control to arrange
170
	 * @param numControls number of controls to arrange
171
	 * @param region region in which to arrange the controls
172
	 */
173
	private void align(int firstControl, int numControls, Rectangle region) {
174
		int last = firstControl + numControls;
175
		int currentPos = region.x + region.width;
176
		
177
		// Arrange controls from right to left
178
		for (int idx = firstControl + numControls - 1; idx >= firstControl; idx--) {
179
			Point size = cache.computeSize(idx, SWT.DEFAULT, SWT.DEFAULT);
180
			
181
			topControls[idx].setBounds(currentPos - size.x, region.y, size.x, size.y);
182
183
			currentPos -= size.x;
184
		}
185
	}
186
	
187
	
188
	/**
189
	 * Returns the region in the title where a toolbar could be rendered in coordinates
190
	 * relative to the tab folder's parent.
191
	 * 
192
	 * @return
193
	 */
194
	protected Rectangle getTitleTrimRegion() {
195
		Rectangle result = new Rectangle(0,0,0,0); 
196
		
197
		int itemCount = tabFolder.getItemCount(); 
198
		if (itemCount > 0) {
199
			CTabItem item = tabFolder.getItem(itemCount - 1);
200
			
201
			Rectangle itemBounds = item.getBounds();
202
			
203
			result.x = itemBounds.x + itemBounds.width;
204
			result.height = itemBounds.height;
205
			result.y = itemBounds.y;
206
			result.width = getAvailableSpace(tabFolder);
207
		}
208
		
209
		Rectangle bounds = tabFolder.getBounds();
210
		
211
		result.x += bounds.x;
212
		result.y += bounds.y;
213
		
214
		int borderSize = 1;
215
		result.y += borderSize;
216
		result.height -= borderSize;
217
		
218
		// Amount to shift to avoid stomping on the curve
219
		int xShift = 3;
220
		result.x += xShift;
221
		result.width -= xShift;
222
		
223
		return result;
224
	}
225
	
226
	/**
227
	 * Computes the maximium size available for the trim controls without causing
228
	 * tabs to disappear.
229
	 * 
230
	 * @param folder
231
	 * @return the amount of empty space to the right of the tabs
232
	 */
233
	protected static int getAvailableSpace(CTabFolder folder) {
234
		int available = folder.getBounds().width;
235
		
236
		available -= 2 * folder.getBorderWidth();
237
		available -= folder.getChevronBounds().width;
238
		available -= folder.getMaximizeBounds().width;
239
		available -= folder.getMinimizeBounds().width;
240
		
241
		// Add a safety margin to avoid stomping on the curve
242
		available -= 10;
243
		
244
		CTabItem[] tabs = folder.getItems();
245
		for (int idx = 0; idx < tabs.length; idx++) {
246
			CTabItem item = tabs[idx];
247
			
248
			if (!item.isShowing()) {
249
				return 0;
250
			}
251
			
252
			available -= item.getBounds().width;
253
		}
254
		
255
		return Math.max(0, available);
256
	}
257
		
258
	/**
259
	 * Returns the total preferred width of the top controls
260
	 * 
261
	 * @return the total preferred width of the top controls
262
	 */
263
	protected Point computeTrimSize() {
264
		int width = 0;
265
		int height = 0;
266
		for (int idx = 0; idx < topControls.length; idx++) {
267
			Point next = cache.computeSize(idx, SWT.DEFAULT, SWT.DEFAULT);
268
			width += next.x;
269
			height = Math.max(height, next.y);
270
		}
271
		
272
		return new Point(width, height);
273
	}
274
	
275
	private static Rectangle calculatePageBounds(CTabFolder folder) {
276
		if (folder == null)
277
			return new Rectangle(0, 0, 0, 0);
278
		Rectangle bounds = folder.getBounds();
279
		Rectangle offset = folder.getClientArea();
280
		bounds.x += offset.x;
281
		bounds.y += offset.y;
282
		bounds.width = offset.width;
283
		bounds.height = offset.height;
284
		return bounds;
285
	}	
286
287
}

Return to bug 55156