Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 8730 Details for
Bug 55156
[RCP] Need access to view toolbar from presentation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Cumulative patch for 55156, 55155, and 55437
55156_workbench_patch.txt (text/plain), 54.33 KB, created by
Stefan Xenos
on 2004-03-21 05:44:07 EST
(
hide
)
Description:
Cumulative patch for 55156, 55155, and 55437
Filename:
MIME Type:
Creator:
Stefan Xenos
Created:
2004-03-21 05:44:07 EST
Size:
54.33 KB
patch
obsolete
>Index: Eclipse UI/org/eclipse/ui/internal/ColorSchemeService.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ColorSchemeService.java,v >retrieving revision 1.10 >diff -u -r1.10 ColorSchemeService.java >--- Eclipse UI/org/eclipse/ui/internal/ColorSchemeService.java 20 Mar 2004 00:42:47 -0000 1.10 >+++ Eclipse UI/org/eclipse/ui/internal/ColorSchemeService.java 21 Mar 2004 10:27:47 -0000 >@@ -132,9 +132,13 @@ > c[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START); > c[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END); > >+ //percent[0] = presentation.getGradientPercentage(); > percent[0] = theme.getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT); > vertical = theme.getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL); >- >+ >+ //vertical = false; >+ >+ // Note: This is currently being overridden in PartTabFolderPresentation > control.setBackground(c, percent, vertical); > > if (presentation.isActive()) { >Index: Eclipse UI/org/eclipse/ui/internal/PartTabFolder.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PartTabFolder.java,v >retrieving revision 1.50 >diff -u -r1.50 PartTabFolder.java >--- Eclipse UI/org/eclipse/ui/internal/PartTabFolder.java 19 Mar 2004 23:24:36 -0000 1.50 >+++ Eclipse UI/org/eclipse/ui/internal/PartTabFolder.java 21 Mar 2004 10:27:50 -0000 >@@ -40,6 +40,16 @@ > import org.eclipse.ui.presentations.StackDropResult; > import org.eclipse.ui.presentations.StackPresentation; > >+/** >+ * Manages a set of ViewPanes that are docked into the workbench window. The container for a PartTabFolder >+ * is always a PartSashContainer (or null), and its children are always either PartPlaceholders or PartPanes. >+ * >+ * TODO: write a common base class for EditorWorkbook and PartTabFolder. >+ * TODO: remove the LayoutPart superclass. All code can either refer to PartPane, >+ * PartPlaceholder, PartSashContainer, or the common base class for EditorWorkbook and PartTabFolder. >+ * The frequent downcasting is due to the fact that much of the code tries to use LayoutPart >+ * or ILayoutContainer references for many different purposes. >+ */ > public class PartTabFolder extends LayoutPart implements ILayoutContainer { > > private boolean active = false; >@@ -538,20 +548,6 @@ > .performDrag(part, DragUtil.getDisplayBounds(part.getControl())); > } > >- /** >- * Returns the current presentable part, or null if there is no current >- * selection >- * >- * @return the current presentable part, or null if there is no current >- * selection >- */ >- /* >- * not used private IPresentablePart getCurrentPresentablePart() { if >- * (current != null) { return current.getPresentablePart(); } >- * >- * return null; } >- */ >- > private void presentationSelectionChanged(IPresentablePart newSelection) { > setSelection(getLayoutPart(newSelection)); > >@@ -922,4 +918,11 @@ > systemMenuManager.add(paneContribution); > } > } >+ >+ /** >+ * >+ */ >+ public void showSystemMenu() { >+ getPresentation().showSystemMenu(); >+ } > } >Index: Eclipse UI/org/eclipse/ui/internal/PresentableEditorPart.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PresentableEditorPart.java,v >retrieving revision 1.5 >diff -u -r1.5 PresentableEditorPart.java >--- Eclipse UI/org/eclipse/ui/internal/PresentableEditorPart.java 17 Mar 2004 17:37:06 -0000 1.5 >+++ Eclipse UI/org/eclipse/ui/internal/PresentableEditorPart.java 21 Mar 2004 10:27:51 -0000 >@@ -15,8 +15,10 @@ > > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Control; > import org.eclipse.ui.IEditorReference; > import org.eclipse.ui.IPropertyListener; >+import org.eclipse.ui.internal.presentations.IPartMenu; > import org.eclipse.ui.presentations.IPresentablePart; > > public class PresentableEditorPart implements IPresentablePart { >@@ -97,5 +99,20 @@ > public boolean isBusy() { > // editors do not support busy currently > return false; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.presentations.IPresentablePart#getToolBar() >+ */ >+ public Control getToolBar() { >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.presentations.IPresentablePart#getPartMenu() >+ */ >+ public IPartMenu getMenu() { >+ // TODO Auto-generated method stub >+ return null; > } > } >Index: Eclipse UI/org/eclipse/ui/internal/PresentableViewPart.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PresentableViewPart.java,v >retrieving revision 1.7 >diff -u -r1.7 PresentableViewPart.java >--- Eclipse UI/org/eclipse/ui/internal/PresentableViewPart.java 17 Mar 2004 17:37:06 -0000 1.7 >+++ Eclipse UI/org/eclipse/ui/internal/PresentableViewPart.java 21 Mar 2004 10:27:51 -0000 >@@ -16,10 +16,14 @@ > import org.eclipse.jface.util.IPropertyChangeListener; > import org.eclipse.jface.util.PropertyChangeEvent; > import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.ToolBar; > import org.eclipse.ui.IPropertyListener; > import org.eclipse.ui.IViewReference; > import org.eclipse.ui.IWorkbenchPartSite; >+import org.eclipse.ui.internal.presentations.IPartMenu; > import org.eclipse.ui.presentations.IPresentablePart; > import org.eclipse.ui.progress.IWorkbenchSiteProgressService; > >@@ -27,10 +31,15 @@ > > private final List listeners = new ArrayList(); > >- > private ViewPane pane; > > private boolean busy = false; >+ >+ private IPartMenu viewMenu = new IPartMenu() { >+ public void showMenu(Point location) { >+ pane.showViewMenu(location); >+ } >+ }; > > private final IPropertyListener propertyListenerProxy = new IPropertyListener() { > >@@ -52,17 +61,20 @@ > /* (non-Javadoc) > * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) > */ >- public void propertyChange(PropertyChangeEvent event) { >- >+ public void propertyChange(PropertyChangeEvent event) { > Boolean state = (Boolean) event.getNewValue(); > PresentableViewPart.this.busy = state.booleanValue(); >- for (int i = 0; i < listeners.size(); i++) >- ((IPropertyListener) listeners.get(i)).propertyChanged( >- PresentableViewPart.this, IPresentablePart.PROP_BUSY); >+ firePropertyChange(IPresentablePart.PROP_BUSY); > } > }); > } > >+ public void firePropertyChange(int propertyId) { >+ for (int i = 0; i < listeners.size(); i++) >+ ((IPropertyListener) listeners.get(i)).propertyChanged( >+ this, propertyId); >+ } >+ > public void addPropertyListener(final IPropertyListener listener) { > if (listeners.isEmpty()) > getViewReference().addPropertyListener(propertyListenerProxy); >@@ -121,6 +133,32 @@ > */ > public boolean isBusy() { > return busy; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.presentations.IPresentablePart#getToolBar() >+ */ >+ public Control getToolBar() { >+ ToolBar control = pane.getToolBarManager().getControl(); >+ >+ if (control.getItemCount() == 0) { >+ control.setVisible(false); >+ return null; >+ } >+ >+ control.setVisible(true); >+ return control; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.presentations.IPresentablePart#getPartMenu() >+ */ >+ public IPartMenu getMenu() { >+ if (pane.hasViewMenu()) { >+ return viewMenu; >+ } >+ >+ return null; > } > > >Index: Eclipse UI/org/eclipse/ui/internal/ViewPane.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ViewPane.java,v >retrieving revision 1.52 >diff -u -r1.52 ViewPane.java >--- Eclipse UI/org/eclipse/ui/internal/ViewPane.java 19 Mar 2004 06:45:18 -0000 1.52 >+++ Eclipse UI/org/eclipse/ui/internal/ViewPane.java 21 Mar 2004 10:27:51 -0000 >@@ -37,7 +37,6 @@ > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Menu; > import org.eclipse.swt.widgets.MenuItem; >-import org.eclipse.swt.widgets.Sash; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.swt.widgets.Text; > import org.eclipse.swt.widgets.ToolBar; >@@ -95,9 +94,6 @@ > */ > private boolean showMenuButton = false; > >- //Created in o.e.ui.Perspective, disposed there. >- private Sash fastViewSash; >- > /** > * Toolbar manager for the ISV toolbar. > */ >@@ -110,10 +106,10 @@ > toolBarResized(toolBar, newCount); > > toolBar.layout(); >- Composite parent = toolBar.getParent(); >- parent.layout(); >- if (parent.getParent() != null) >- parent.getParent().layout(); >+// Composite parent = toolBar.getParent(); >+// parent.layout(); >+// if (parent.getParent() != null) >+// parent.getParent().layout(); > } > } > >@@ -289,8 +285,8 @@ > // All actions on the System toolbar should be accessible on the pane menu. > if (control.getContent() == null) { > // content can be null if view creation failed >- if (locked) >- control.setTabList(new Control[] { isvToolBar , viewToolBar }); >+// if (locked) >+// control.setTabList(new Control[] { isvToolBar , viewToolBar }); > } else { > if (locked) > control.setTabList(new Control[] { viewToolBar, control.getContent()}); >@@ -439,13 +435,7 @@ > } > > private void toolBarResized(ToolBar toolBar, int newSize) { >- if (locked) { >- if (toolBar == viewToolBar) { >- ((ViewForm)control).setTopRight(newSize == 0 ? null :viewToolBar); >- } else if (toolBar == isvToolBar) { >- ((ViewForm)control).setTopCenter(newSize == 0 ? null : isvToolBar); >- } >- } >+ presentableAdapter.firePropertyChange(IPresentablePart.PROP_TOOLBAR); > } > > /** >@@ -490,7 +480,7 @@ > > // ISV toolbar. > // // 1GD0ISU: ITPUI:ALL - Dbl click on view tool cause zoom >- isvToolBar = new ToolBar(parentControl, barStyle); >+ isvToolBar = new ToolBar(parentControl.getParent(), barStyle); > > > >@@ -503,7 +493,7 @@ > } > }); > } else { >- isvToolBar.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ //isvToolBar.setLayoutData(new GridData(GridData.FILL_BOTH)); > } > IContributionItem[] isvItems = null; > if (isvToolBarMgr != null) { >@@ -521,8 +511,8 @@ > // whenever updating the tab colors > if (viewToolBar != null) > ColorSchemeService.setViewColors(viewToolBar); >- ColorSchemeService.setViewColors(isvToolBar); >- ColorSchemeService.setViewColors(isvToolBar.getParent()); >+ //ColorSchemeService.setViewColors(isvToolBar); >+ ColorSchemeService.setViewColors(parentControl); > } > > /** >@@ -664,9 +654,6 @@ > viewToolBarMgr.update(true); > } > } >- public void setFastViewSash(Sash s) { >- fastViewSash = s; >- } > > /* (non-Javadoc) > * Method declared on PartPane. >@@ -765,14 +752,13 @@ > * Shows the pane menu (system menu) for this pane. > */ > public void showPaneMenu() { >- // If this is a fast view, it may have been minimized. Do nothing in this case. >- if (isFastView() && (page.getActiveFastView() != getViewReference())) >- return; >- // TODO should position menu relative to tab, as is done >- // with editors. Also need to take into account view titlebar if present >- Control ref = control.getContent() != null ? control.getContent() : control; >- Point pos = ref.toDisplay(ref.getLocation()); >- showPaneMenu(ref, pos); >+ ILayoutContainer container = getContainer(); >+ >+ if (container instanceof PartTabFolder) { >+ PartTabFolder folder = (PartTabFolder) container; >+ >+ folder.showSystemMenu(); >+ } > } > /** > * Return true if this view is a fast view. >@@ -797,10 +783,6 @@ > */ > protected Sashes findSashes() { > Sashes result = new Sashes(); >- if (isFastView()) { >- result.right = fastViewSash; >- return result; >- } > > ILayoutContainer container = getContainer(); > >@@ -894,19 +876,27 @@ > * Show the view menu for this window. > */ > public void showViewMenu() { >- >+ Rectangle bounds = pullDownButton.getBounds(); >+ Point topLeft = new Point(bounds.x, bounds.y + bounds.height); >+ topLeft = viewToolBar.toDisplay(topLeft); >+ >+ Rectangle parentBounds = getControl().getBounds(); >+ topLeft.x += parentBounds.x; >+ topLeft.y += parentBounds.y; >+ >+ showViewMenu(topLeft); >+ } >+ >+ public void showViewMenu(Point location) { > if (!hasViewMenu()) > return; >- >+ > // If this is a fast view, it may have been minimized. Do nothing in this case. > if (isFastView() && (page.getActiveFastView() != getViewReference())) > return; >- >- Menu aMenu = isvMenuMgr.createContextMenu(getControl()); >- Rectangle bounds = pullDownButton.getBounds(); >- Point topLeft = new Point(bounds.x, bounds.y + bounds.height); >- topLeft = viewToolBar.toDisplay(topLeft); >- aMenu.setLocation(topLeft.x, topLeft.y); >+ >+ Menu aMenu = isvMenuMgr.createContextMenu(getControl().getParent()); >+ aMenu.setLocation(location.x, location.y); > aMenu.setVisible(true); > } > >@@ -933,7 +923,8 @@ > IViewReference ref = getViewReference(); > > if (status != null && !status.isDisposed()) { >- status.setBackground(status.getParent().getBackground()); >+ ColorSchemeService.setViewColors(status); >+ //status.setBackground(status.getParent().getBackground()); > boolean changed = false; > String text = ref.getTitle(); > >@@ -1085,4 +1076,36 @@ > public IPresentablePart getPresentablePart() { > return presentableAdapter; > } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.LayoutPart#reparent(org.eclipse.swt.widgets.Composite) >+ */ >+ public void reparent(Composite newParent) { >+ super.reparent(newParent); >+ >+ if (isvToolBar != null) { >+ isvToolBar.setParent(newParent); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.LayoutPart#moveAbove(org.eclipse.swt.widgets.Control) >+ */ >+ public void moveAbove(Control refControl) { >+ super.moveAbove(refControl); >+ >+ isvToolBar.moveAbove(control); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.LayoutPart#setVisible(boolean) >+ */ >+ public void setVisible(boolean makeVisible) { >+ super.setVisible(makeVisible); >+ >+ if (isvToolBar != null) { >+ isvToolBar.setVisible(makeVisible); >+ } >+ } >+ > } >Index: Eclipse UI/org/eclipse/ui/internal/presentations/BasicStackPresentation.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/presentations/BasicStackPresentation.java,v >retrieving revision 1.13 >diff -u -r1.13 BasicStackPresentation.java >--- Eclipse UI/org/eclipse/ui/internal/presentations/BasicStackPresentation.java 19 Mar 2004 23:24:51 -0000 1.13 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/BasicStackPresentation.java 21 Mar 2004 10:27:57 -0000 >@@ -10,8 +10,12 @@ > *******************************************************************************/ > package org.eclipse.ui.internal.presentations; > >+import java.util.ArrayList; >+import java.util.List; >+ > import org.eclipse.jface.action.IMenuManager; > import org.eclipse.jface.action.MenuManager; >+import org.eclipse.jface.resource.ColorRegistry; > import org.eclipse.jface.resource.FontRegistry; > import org.eclipse.jface.util.Geometry; > import org.eclipse.swt.SWT; >@@ -24,21 +28,32 @@ > import org.eclipse.swt.events.MouseAdapter; > import org.eclipse.swt.events.MouseEvent; > import org.eclipse.swt.events.MouseListener; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Event; > import org.eclipse.swt.widgets.Listener; > import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.ToolBar; >+import org.eclipse.swt.widgets.ToolItem; > import org.eclipse.ui.IPropertyListener; > import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.internal.IWorkbenchGraphicConstants; > import org.eclipse.ui.internal.IWorkbenchThemeConstants; >+import org.eclipse.ui.internal.WorkbenchImages; >+import org.eclipse.ui.internal.WorkbenchMessages; >+import org.eclipse.ui.internal.dnd.DragUtil; > import org.eclipse.ui.presentations.IPresentablePart; > import org.eclipse.ui.presentations.IStackPresentationSite; > import org.eclipse.ui.presentations.PresentationUtil; > import org.eclipse.ui.presentations.StackDropResult; > import org.eclipse.ui.presentations.StackPresentation; >+import org.eclipse.ui.themes.ITheme; > > /** > * Base class for StackPresentations that display IPresentableParts in a CTabFolder. >@@ -52,6 +67,21 @@ > private boolean activeState = false; > private int tabPosition; > private MenuManager systemMenuManager = new MenuManager(); >+ private TabFolderLayout layout; >+ >+ private Color backgroundGradientStart; >+ private Color backgroundGradientEnd; >+ private Color background; >+ >+ //private ToolBar viewToolBar; >+ //private ToolBarManager viewToolBarMgr; >+ >+ // Controls which will be inserted into the title bar if there is room, or above the client pane >+ // if not >+ private List topControls = new ArrayList(); >+ >+ // Stand-in for the top controls >+ //private Composite toolbarProxy; > > private int mousedownState = -1; > >@@ -128,6 +158,10 @@ > } > }; > >+ public int getTopTrimStart() { >+ return layout.getTrimStart(); >+ } >+ > private Listener resizeListener = new Listener() { > public void handleEvent(Event e) { > setControlSize(); >@@ -166,11 +200,32 @@ > } > } > }; >+ private ToolBar viewToolBar; > > public BasicStackPresentation(CTabFolder control, IStackPresentationSite stackSite) { > super(stackSite); > tabFolder = control; > >+ layout = new TabFolderLayout(tabFolder); >+ >+ viewToolBar = new ToolBar(control.getParent(), SWT.HORIZONTAL >+ | SWT.FLAT | SWT.WRAP); >+ >+ ToolItem pullDownButton = new ToolItem(viewToolBar, SWT.PUSH); >+ // Image img = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU); >+ Image hoverImage = >+ WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU_HOVER); >+ pullDownButton.setDisabledImage(hoverImage); // TODO: comment this out? >+ // PR#1GE56QT - Avoid creation of unnecessary image. >+ pullDownButton.setImage(hoverImage); >+ // pullDownButton.setHotImage(hoverImage); >+ pullDownButton.setToolTipText(WorkbenchMessages.getString("Menu")); //$NON-NLS-1$ >+ pullDownButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ showViewMenu(); >+ } >+ }); >+ > // listener to switch between visible tabItems > tabFolder.addListener(SWT.Selection, selectionListener); > >@@ -204,7 +259,38 @@ > } > } > }); >- >+ >+ viewToolBar.setVisible(true); >+ //viewToolBar.moveAbove(null); >+ >+ // Insert a bogus composite into the top-right of the tab folder. We do this to keep >+ // track of where to draw the toolbars. >+ //toolbarProxy = new Composite(tabFolder, SWT.NONE); >+ >+ //tabFolder.setTopRight(toolbarProxy); >+ >+ //titleLabel = new Label(control.getParent(), SWT.NONE); >+ >+ ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme(); >+ ColorRegistry colorRegistry = currentTheme.getColorRegistry(); >+ Color endCol = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END); >+ >+ setBackgroundColors(colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START), >+ endCol, endCol); >+ >+ tabFolder.setTabHeight(24); >+ } >+ >+ /** >+ * >+ */ >+ protected void showViewMenu() { >+ IPartMenu menu = getPartMenu(); >+ >+ if (menu != null) { >+ Rectangle bounds = DragUtil.getDisplayBounds(viewToolBar); >+ menu.showMenu(new Point(bounds.x, bounds.y + bounds.height)); >+ } > } > > /** >@@ -268,7 +354,8 @@ > > CTabItem tab = getTab(part); > initTab(tab, part); >- if(property == IPresentablePart.PROP_BUSY){ >+ switch (property) { >+ case IPresentablePart.PROP_BUSY: > FontRegistry registry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry(); > if(part.isBusy()) > tab.setFont(registry.getItalic(IWorkbenchThemeConstants.TAB_TEXT_FONT)); >@@ -277,8 +364,11 @@ > tab.setFont(registry.get(IWorkbenchThemeConstants.TAB_TEXT_FONT)); > else > tab.setFont(registry.getBold(IWorkbenchThemeConstants.TAB_TEXT_FONT)); >- } >- >+ } >+ break; >+ case IPresentablePart.PROP_TOOLBAR: >+ setControlSize(); >+ break; > } > } > >@@ -306,8 +396,20 @@ > } > > public void drawGradient(Color fgColor, Color [] bgColors, int [] percentages, boolean vertical) { >+ Display display = tabFolder.getDisplay(); >+ //Color c = display.getSystemColor(SWT.COLOR_BLUE); >+ >+ //fgColor = c; >+// tabFolder.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), >+// display.getSystemColor(SWT.COLOR_BLUE), >+// display.getSystemColor(SWT.COLOR_WHITE), >+// display.getSystemColor(SWT.COLOR_WHITE)}, >+// new int[] {25, 50, 100}); >+ >+ //tabFolder.setBackground(display.getSystemColor(SWT.COLOR_DARK_BLUE)); >+ > tabFolder.setSelectionForeground(fgColor); >- tabFolder.setSelectionBackground(bgColors, percentages, vertical); >+ tabFolder.setSelectionBackground(bgColors, percentages, vertical); > } > > public boolean isActive() { >@@ -317,31 +419,78 @@ > /** > * Set the size of a page in the folder. > */ >- private void setControlSize() { >+ protected void setControlSize() { >+ // Set up the top-right controls >+ List topRight = new ArrayList(2); >+ >+ Control toolbar = getCurrentToolbar(); >+ >+ if (toolbar != null) { >+ topRight.add(toolbar); >+ } >+ >+ IPartMenu partMenu = getPartMenu(); >+ >+ if (partMenu != null) { >+ viewToolBar.moveAbove(null); >+ topRight.add(viewToolBar); >+ viewToolBar.setVisible(true); >+ } else { >+ viewToolBar.setVisible(false); >+ } >+ >+ Control[] controls = (Control[])topRight.toArray(new Control[topRight.size()]); >+ >+ layout.setTopRight(controls); >+ > if (current == null || tabFolder == null) > return; >-// Rectangle bounds; >- // @issue as above, the mere presence of a theme should not change the behaviour >-// if ((mapTabToPart.size() > 1) >-// || ((tabThemeDescriptor != null) && (mapTabToPart.size() >= 1))) >-// bounds = calculatePageBounds(tabFolder); >-// else >-// bounds = tabFolder.getBounds(); >- current.setBounds(calculatePageBounds(tabFolder)); >- //current.moveAbove(tabFolder); >- } >- >- public static Rectangle calculatePageBounds(CTabFolder folder) { >- if (folder == null) >- return new Rectangle(0, 0, 0, 0); >- Rectangle bounds = folder.getBounds(); >- Rectangle offset = folder.getClientArea(); >- bounds.x += offset.x; >- bounds.y += offset.y; >- bounds.width = offset.width; >- bounds.height = offset.height; >- return bounds; >- } >+ >+ layout.layout(); >+ >+ current.setBounds(layout.getClientBounds()); >+ >+ updateTrimColours(); >+ } >+ >+ protected IPartMenu getPartMenu() { >+ IPresentablePart part = getCurrentPart(); >+ if (part == null) { >+ return null; >+ } >+ >+ return part.getMenu(); >+ } >+ >+ /** >+ * Update the colours of the trim widgets based on whether they are >+ * currently in the title bar or below it. >+ */ >+ protected void updateTrimColours() { >+ Color background = isTrimOnTop() ? backgroundGradientEnd : this.background ; >+ >+ Control[] trim = layout.getTopRight(); >+ >+ for (int idx = 0; idx < trim.length; idx++) { >+ Control next = trim[idx]; >+ >+ Color nextCol = next.getBackground(); >+ >+ if (nextCol != background) { >+ next.setBackground(background); >+ } >+ } >+ >+ updateBackgroundColors(); >+ } >+ >+ protected boolean isTrimOnTop() { >+ return layout.isTrimOnTop(); >+ } >+ >+// protected Control[] getTopRight() { >+// return layout.getTopRight(); >+// } > > /* (non-Javadoc) > * @see org.eclipse.ui.internal.skins.Presentation#dispose() >@@ -355,6 +504,8 @@ > > tabFolder.dispose(); > tabFolder = null; >+ >+ viewToolBar.dispose(); > } > > /* (non-Javadoc) >@@ -446,12 +597,22 @@ > } > } > >+ public IPresentablePart getCurrentPart() { >+ return current; >+ } >+ >+// protected void setTopRight(List topRight) { >+// layout.setTopRight(topRight); >+// setControlSize(); >+// } >+ > /* (non-Javadoc) > * @see org.eclipse.ui.internal.skins.Presentation#setBounds(org.eclipse.swt.graphics.Rectangle) > */ > public void setBounds(Rectangle bounds) { > tabFolder.setBounds(bounds); > setControlSize(); >+ viewToolBar.moveAbove(getControl()); > } > > /* (non-Javadoc) >@@ -469,6 +630,7 @@ > current.setVisible(isVisible); > } > tabFolder.setVisible(isVisible); >+ viewToolBar.setVisible(isVisible); > } > > /* (non-Javadoc) >@@ -508,7 +670,6 @@ > * @see org.eclipse.ui.internal.skins.StackPresentation#dragOver(org.eclipse.swt.widgets.Control, org.eclipse.swt.graphics.Point) > */ > public StackDropResult dragOver(Control currentControl, Point location) { >- > // Determine which tab we're currently dragging over > Point localPos = tabFolder.toControl(location); > final CTabItem tabUnderPointer = tabFolder.getItem(localPos); >@@ -521,5 +682,70 @@ > > return new StackDropResult(Geometry.toDisplay(tabFolder, tabUnderPointer.getBounds()), > tabFolder.indexOf(tabUnderPointer)); >+ } >+ >+ public int getGradientPercentage() { >+ Rectangle clientBounds = getTabFolder().getBounds(); >+ >+ int percentage = clientBounds.width == 0 ? 100 : Math.min(100, >+ 100 * getTopTrimStart() / clientBounds.width); >+ >+ if (percentage < 0) { >+ percentage = 0; >+ } >+ >+ return percentage; >+ } >+ >+ protected Control getCurrentToolbar() { >+ IPresentablePart part = getCurrentPart(); >+ if (part == null) { >+ return null; >+ } >+ >+ return part.getToolBar(); >+ } >+ >+ protected void setBackgroundColors(Color gradientStart, Color gradientEnd, Color background) { >+ backgroundGradientStart = gradientStart; >+ backgroundGradientEnd = gradientEnd; >+ this.background = background; >+ updateBackgroundColors(); >+ >+ updateTrimColours(); >+ } >+ >+ protected void updateBackgroundColors() { >+ Color [] c = new Color[3]; >+ c[0] = backgroundGradientStart; >+ c[1] = backgroundGradientEnd; >+ c[2] = c[1]; >+ >+ int[] percents = new int[] {getGradientPercentage(), 100}; >+ >+ getTabFolder().setBackground(c, percents, false); >+ getTabFolder().setBackground(background); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.presentations.StackPresentation#showSystemMenu() >+ */ >+ public void showSystemMenu() { >+ IPresentablePart part = getCurrentPart(); >+ if (part != null) { >+ Rectangle bounds = DragUtil.getDisplayBounds(tabFolder); >+ >+ int idx = tabFolder.getSelectionIndex(); >+ if (idx > -1) { >+ CTabItem item = tabFolder.getItem(idx); >+ Rectangle itemBounds = item.getBounds(); >+ >+ bounds.x += itemBounds.x; >+ bounds.y += itemBounds.y; >+ } >+ >+ Point location = new Point(bounds.x, bounds.y + tabFolder.getTabHeight()); >+ showPaneMenu(part, location); >+ } > } > } >Index: Eclipse UI/org/eclipse/ui/internal/presentations/EditorPresentation.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/presentations/EditorPresentation.java,v >retrieving revision 1.9 >diff -u -r1.9 EditorPresentation.java >--- Eclipse UI/org/eclipse/ui/internal/presentations/EditorPresentation.java 19 Mar 2004 23:25:12 -0000 1.9 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/EditorPresentation.java 21 Mar 2004 10:27:57 -0000 >@@ -269,8 +269,8 @@ > .get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR); > bgColors[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START); > bgColors[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END); >- percent[0] = currentTheme.getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT); >- vertical = currentTheme.getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL); >+ percent[0] = getGradientPercentage(); >+ vertical = false; > } > > getTabFolder() >Index: Eclipse UI/org/eclipse/ui/internal/presentations/NativeStackPresentation.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/presentations/NativeStackPresentation.java,v >retrieving revision 1.5 >diff -u -r1.5 NativeStackPresentation.java >--- Eclipse UI/org/eclipse/ui/internal/presentations/NativeStackPresentation.java 16 Mar 2004 15:24:14 -0000 1.5 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/NativeStackPresentation.java 21 Mar 2004 10:27:57 -0000 >@@ -425,4 +425,12 @@ > // tabFolder.indexOf(tabUnderPointer)); > return null; > } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.presentations.StackPresentation#showSystemMenu() >+ */ >+ public void showSystemMenu() { >+ // TODO Auto-generated method stub >+ >+ } > } >Index: Eclipse UI/org/eclipse/ui/internal/presentations/PartTabFolderPresentation.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/presentations/PartTabFolderPresentation.java,v >retrieving revision 1.8 >diff -u -r1.8 PartTabFolderPresentation.java >--- Eclipse UI/org/eclipse/ui/internal/presentations/PartTabFolderPresentation.java 18 Mar 2004 01:30:05 -0000 1.8 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/PartTabFolderPresentation.java 21 Mar 2004 10:27:57 -0000 >@@ -36,8 +36,8 @@ > */ > public class PartTabFolderPresentation extends BasicStackPresentation { > >- private IPreferenceStore preferenceStore = WorkbenchPlugin.getDefault().getPreferenceStore(); >- >+ private IPreferenceStore preferenceStore = WorkbenchPlugin.getDefault().getPreferenceStore(); >+ > private final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { > public void propertyChange(PropertyChangeEvent propertyChangeEvent) { > if (IPreferenceConstants.VIEW_TAB_POSITION.equals(propertyChangeEvent.getProperty()) && !isDisposed()) { >@@ -53,8 +53,11 @@ > public PartTabFolderPresentation(Composite parent, IStackPresentationSite newSite, int flags) { > > super(new CTabFolder(parent, SWT.BORDER), newSite); >+ > CTabFolder tabFolder = getTabFolder(); > >+ tabFolder.setBackground(parent.getBackground()); >+ > preferenceStore.addPropertyChangeListener(propertyChangeListener); > int tabLocation = preferenceStore.getInt(IPreferenceConstants.VIEW_TAB_POSITION); > >@@ -75,6 +78,7 @@ > > tabFolder.setMinimizeVisible((flags & SWT.MIN) != 0); > tabFolder.setMaximizeVisible((flags & SWT.MAX) != 0); >+ > } > > /** >@@ -117,9 +121,12 @@ > fgColor = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR); > bgColors[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START); > bgColors[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END); >+ //percent[0] = getGradientPercentage(); >+ //vertical = false; > percent[0] = currentTheme.getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT); > vertical = currentTheme.getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL); > } >+ > drawGradient(fgColor, bgColors, percent, vertical); > } > >@@ -131,6 +138,7 @@ > > updateGradient(); > } >+ > /* (non-Javadoc) > * @see org.eclipse.ui.presentations.StackPresentation#dispose() > */ >@@ -138,4 +146,35 @@ > preferenceStore.removePropertyChangeListener(propertyChangeListener); > super.dispose(); > } >+ >+// /* (non-Javadoc) >+// * @see org.eclipse.ui.internal.presentations.BasicStackPresentation#setControlSize() >+// */ >+// protected void setControlSize() { >+// super.setControlSize(); >+// >+// updateTitleGradient(); >+// } >+// >+// /* (non-Javadoc) >+// * @see org.eclipse.ui.presentations.StackPresentation#selectPart(org.eclipse.ui.presentations.IPresentablePart) >+// */ >+// public void selectPart(IPresentablePart toSelect) { >+// super.selectPart(toSelect); >+// >+// updateTitleGradient(); >+// } >+// >+// /** >+// * Updates the title's gradient based on the current size and position of >+// * the toolbar. >+// */ >+// protected void updateTitleGradient() { >+// ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme(); >+// ColorRegistry colorRegistry = currentTheme.getColorRegistry(); >+// Color endCol = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END); >+// >+// setBackgroundColors(colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START), >+// endCol, endCol); >+// } > } >Index: Eclipse UI/org/eclipse/ui/internal/themes/WorkbenchPreview.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes/WorkbenchPreview.java,v >retrieving revision 1.6 >diff -u -r1.6 WorkbenchPreview.java >--- Eclipse UI/org/eclipse/ui/internal/themes/WorkbenchPreview.java 18 Mar 2004 00:10:38 -0000 1.6 >+++ Eclipse UI/org/eclipse/ui/internal/themes/WorkbenchPreview.java 21 Mar 2004 10:28:00 -0000 >@@ -148,7 +148,7 @@ > Color [] colors = new Color[2]; > colors[0] = theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START); > colors[1] = theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END); >- folder.setBackground(colors, new int [] {theme.getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT)}, theme.getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL)); >+ folder.setBackground(colors, new int [] {100}, false); > toolBar.setBackground(colors[1]); > viewMessage.setBackground(colors[1]); > viewForm.setBackground(colors[1]); >Index: Eclipse UI/org/eclipse/ui/presentations/IPresentablePart.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/presentations/IPresentablePart.java,v >retrieving revision 1.6 >diff -u -r1.6 IPresentablePart.java >--- Eclipse UI/org/eclipse/ui/presentations/IPresentablePart.java 18 Mar 2004 00:53:46 -0000 1.6 >+++ Eclipse UI/org/eclipse/ui/presentations/IPresentablePart.java 21 Mar 2004 10:28:00 -0000 >@@ -12,7 +12,11 @@ > > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.ui.IEditorPart; > import org.eclipse.ui.IPropertyListener; >+import org.eclipse.ui.IWorkbenchPart; >+import org.eclipse.ui.internal.presentations.IPartMenu; > > /** > * This is a skin's interface to the contents of a view or editor. Note that this >@@ -26,11 +30,31 @@ > public interface IPresentablePart { > > /** >+ * The property id for <code>isDirty</code>. >+ */ >+ public static final int PROP_DIRTY = IEditorPart.PROP_DIRTY; >+ >+ /** >+ * The property id for <code>getEditorInput</code>. >+ */ >+ public static final int PROP_INPUT = IEditorPart.PROP_INPUT; >+ >+ /** >+ * The property id for <code>getTitle</code>, <code>getTitleImage</code> >+ * and <code>getTitleToolTip</code>. >+ */ >+ public static final int PROP_TITLE = IWorkbenchPart.PROP_TITLE; >+ >+ /** > * The property id for <code>isBusy</code>. > */ > public static final int PROP_BUSY = 0x92; > > /** >+ * The property id for toolbar changes >+ */ >+ public static final int PROP_TOOLBAR = 0x93; >+ /** > * Sets the bounds of this part. > * > * @param bounds >@@ -58,9 +82,10 @@ > * <p> > * The properties ids are as follows: > * <ul> >- * <li><code>IWorkbenchPart.PROP_TITLE</code> </li> >- * <li><code>IEditorPart.PROP_INPUT</code> </li> >- * <li><code>IEditorPart.PROP_DIRTY</code> </li> >+ * <li><code>PROP_TITLE</code> </li> >+ * <li><code>PROP_INPUT</code> </li> >+ * <li><code>PROP_DIRTY</code> </li> >+ * <li><code>PROP_TOOLBAR</code> </li> > * </ul> > * </p> > * >@@ -138,5 +163,20 @@ > * @return boolean true if busy > */ > public boolean isBusy(); >+ >+ /** >+ * Returns the local toolbar for this part, or null if this part does not >+ * have a local toolbar. Callers must not dispose or downcast the return value. >+ * >+ * @return the local toolbar for the part, or null if none >+ */ >+ public Control getToolBar(); >+ >+ /** >+ * Returns the menu for this part or null if none >+ * >+ * @return the menu for this part or null if none >+ */ >+ public IPartMenu getMenu(); > > } >Index: Eclipse UI/org/eclipse/ui/presentations/PresentationUtil.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/presentations/PresentationUtil.java,v >retrieving revision 1.4 >diff -u -r1.4 PresentationUtil.java >--- Eclipse UI/org/eclipse/ui/presentations/PresentationUtil.java 18 Mar 2004 13:30:45 -0000 1.4 >+++ Eclipse UI/org/eclipse/ui/presentations/PresentationUtil.java 21 Mar 2004 10:28:00 -0000 >@@ -83,11 +83,7 @@ > Event de = dragEvent; > cancelDrag(); > if (l != null) { >- c.setCapture(true); > l.handleEvent(de); >- if (!c.isDisposed()) { >- c.setCapture(false); >- } > } > } > } >Index: Eclipse UI/org/eclipse/ui/presentations/StackPresentation.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/presentations/StackPresentation.java,v >retrieving revision 1.4 >diff -u -r1.4 StackPresentation.java >--- Eclipse UI/org/eclipse/ui/presentations/StackPresentation.java 18 Mar 2004 00:53:46 -0000 1.4 >+++ Eclipse UI/org/eclipse/ui/presentations/StackPresentation.java 21 Mar 2004 10:28:00 -0000 >@@ -162,4 +162,10 @@ > * a drop target in this location. > */ > public abstract StackDropResult dragOver(Control currentControl, Point location); >+ >+ /** >+ * Instructs the presentation to display the system menu >+ * >+ */ >+ public abstract void showSystemMenu(); > } >Index: Eclipse UI/org/eclipse/ui/internal/presentations/IPartMenu.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/presentations/IPartMenu.java >diff -N Eclipse UI/org/eclipse/ui/internal/presentations/IPartMenu.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/IPartMenu.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,25 @@ >+/******************************************************************************* >+ * Copyright (c) 2004 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.internal.presentations; >+ >+import org.eclipse.swt.graphics.Point; >+ >+/** >+ * @since 3.0 >+ */ >+public interface IPartMenu { >+ /** >+ * Displays the local menu for this part as a popup at the given location. >+ * >+ * @param location position to display the menu at (display coordinates, not null) >+ */ >+ public void showMenu(Point location); >+} >Index: Eclipse UI/org/eclipse/ui/internal/presentations/LayoutCache.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/presentations/LayoutCache.java >diff -N Eclipse UI/org/eclipse/ui/internal/presentations/LayoutCache.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/LayoutCache.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,56 @@ >+/******************************************************************************* >+ * Copyright (c) 2004 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.internal.presentations; >+ >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * Caches the preferred sizes of an array of controls >+ * >+ * @since 3.0 >+ */ >+public class LayoutCache { >+ private SizeCache[] caches; >+ >+ /** >+ * Creates a cache for the given array of controls >+ * >+ * @param controls >+ */ >+ public LayoutCache(Control[] controls) { >+ caches = new SizeCache[controls.length]; >+ for (int idx = 0; idx < controls.length; idx++) { >+ caches[idx] = new SizeCache(controls[idx]); >+ } >+ } >+ >+ /** >+ * Computes the preferred size of the nth control >+ * >+ * @param controlIndex index of the control whose size will be computed >+ * @param widthHint width of the control (or SWT.DEFAULT if unknown) >+ * @param heightHint height of the control (or SWT.DEFAULT if unknown) >+ * @return the preferred size of the control >+ */ >+ public Point computeSize(int controlIndex, int widthHint, int heightHint) { >+ return caches[controlIndex].computeSize(widthHint, heightHint); >+ } >+ >+ /** >+ * Flushes the cache >+ */ >+ public void flush() { >+ for (int idx = 0; idx < caches.length; idx++) { >+ caches[idx].flush(); >+ } >+ } >+} >Index: Eclipse UI/org/eclipse/ui/internal/presentations/SizeCache.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/presentations/SizeCache.java >diff -N Eclipse UI/org/eclipse/ui/internal/presentations/SizeCache.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/SizeCache.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,119 @@ >+/******************************************************************************* >+ * Copyright (c) 2004 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.internal.presentations; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * Caches the preferred size of an SWT control >+ * >+ * @since 3.0 >+ */ >+public class SizeCache { >+ private Control control; >+ >+ private Point preferredSize; >+ private Point cachedWidth; >+ private Point cachedHeight; >+ >+ /** >+ * Creates a cache for size computations on the given control >+ * >+ * @param control the control for which >+ */ >+ public SizeCache(Control control) { >+ this.control = control; >+ } >+ >+ /** >+ * Flush the cache (should be called if the control's contents may have changed since the >+ * last query) >+ */ >+ public void flush() { >+ preferredSize = null; >+ cachedWidth = null; >+ cachedHeight = null; >+ } >+ >+ /** >+ * Computes the preferred size of the control. >+ * >+ * @param widthHint the known width of the control (pixels) or SWT.DEFAULT if unknown >+ * @param heightHint the known height of the control (pixels) or SWT.DEFAULT if unknown >+ * @return the preferred size of the control >+ */ >+ public Point computeSize(int widthHint, int heightHint) { >+ // No hints given -- find the preferred size >+ if (widthHint == SWT.DEFAULT && heightHint == SWT.DEFAULT) { >+ if (preferredSize == null) { >+ preferredSize = computeSize(control, widthHint, heightHint); >+ } >+ >+ return preferredSize; >+ } >+ >+ // Computing a width >+ if (widthHint == SWT.DEFAULT) { >+ if (preferredSize != null && heightHint == preferredSize.y) { >+ return preferredSize; >+ } >+ >+ if (cachedWidth == null || cachedWidth.y != heightHint) { >+ cachedWidth = computeSize(control, widthHint, heightHint); >+ } >+ >+ return cachedWidth; >+ } >+ >+ // Computing a height >+ if (heightHint == SWT.DEFAULT) { >+ // Check if we're asking about the preferred width >+ if (preferredSize != null && widthHint == preferredSize.x) { >+ return preferredSize; >+ } >+ >+ if (cachedHeight == null || cachedHeight.x != widthHint) { >+ cachedHeight = computeSize(control, widthHint, heightHint); >+ } >+ >+ return cachedHeight; >+ } >+ >+ return computeSize(control, widthHint, heightHint); >+ } >+ >+ /** >+ * Compute the control's size, and ensure that non-default hints are returned verbatim >+ * (this tries to compensate for SWT's hints, which aren't really the outer width of the >+ * control). >+ * >+ * @param control >+ * @param widthHint >+ * @param heightHint >+ * @return >+ */ >+ private static Point computeSize(Control control, int widthHint, int heightHint) { >+ Point result = control.computeSize(widthHint, heightHint); >+ >+ if (widthHint != SWT.DEFAULT) { >+ result.x = widthHint; >+ } >+ >+ if (heightHint != SWT.DEFAULT) { >+ result.y = heightHint; >+ } >+ >+ return result; >+ } >+ >+} >Index: Eclipse UI/org/eclipse/ui/internal/presentations/TabFolderLayout.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/presentations/TabFolderLayout.java >diff -N Eclipse UI/org/eclipse/ui/internal/presentations/TabFolderLayout.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/TabFolderLayout.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,283 @@ >+/******************************************************************************* >+ * Copyright (c) 2004 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.internal.presentations; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.CTabFolder; >+import org.eclipse.swt.custom.CTabItem; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * Arranges the contents of a CTabFolder >+ * >+ * @since 3.0 >+ */ >+public class TabFolderLayout { >+ private CTabFolder tabFolder; >+ private Control[] topControls; >+ //private Control upperRightProxy; >+ private LayoutCache cache; >+ private Rectangle centerArea = new Rectangle(0,0,0,0); >+ private int trimStart; >+ private boolean trimOnTop = false; >+ >+ public TabFolderLayout(CTabFolder folder) { >+ this.tabFolder = folder; >+ >+// Composite cmp = new Composite(folder, SWT.DEFAULT); >+// upperRightProxy = cmp; >+// upperRightProxy.setVisible(false); >+// >+// cmp.setLayout(new Layout() { >+// >+// protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { >+// return new Point(10,10); >+// } >+// >+// protected void layout(Composite composite, boolean flushCache) { >+// >+// } >+// }); >+ >+ //tabFolder.setTopRight(upperRightProxy); >+ setTopRight(new Control[0]); >+ } >+ >+ public void dispose() { >+ //tabFolder.setTopRight(null); >+ //upperRightProxy.dispose(); >+ } >+ >+ public Control[] getTopRight() { >+ return topControls; >+ } >+ >+ public Rectangle getClientBounds() { >+ return centerArea; >+ } >+ >+ public int getTrimStart() { >+ return trimStart; >+ } >+ >+ public boolean isTrimOnTop() { >+ return trimOnTop; >+ } >+ >+ /** >+ * Sets the list of controls to be placed at the top-right of the CTabFolder >+ * >+ * @param topRight a list of Control >+ */ >+ public void setTopRight(Control[] upperRight) { >+ topControls = upperRight; >+ >+ cache = new LayoutCache(upperRight); >+ layout(); >+ } >+ >+ /** >+ * Arranges all the controls in this layout >+ */ >+ public void layout() { >+ cache.flush(); >+ >+ Rectangle trimRegion = getTitleTrimRegion(); >+ >+ Point trimSize = computeTrimSize(); >+ >+ Rectangle bounds = tabFolder.getBounds(); >+ >+ trimStart = bounds.width; >+ >+ Rectangle clientBounds = calculatePageBounds(tabFolder); >+ >+ trimOnTop = trimSize.x < trimRegion.width && trimSize.y < trimRegion.height; >+ // Check if we have room for all our topRight controls on the top border >+ if (trimOnTop) { >+ >+ trimStart -= trimSize.x; >+ >+ align(0, topControls.length, trimRegion); >+ >+ centerArea = clientBounds; >+ >+ return; >+ } >+ >+ // Else we need to place the controls below the title >+ >+ Rectangle currentRect = new Rectangle(clientBounds.x, clientBounds.y, clientBounds.width, 0); >+ >+ int idx = 0; >+ while (idx < topControls.length) { >+ int startOfRow = idx; >+ currentRect.height = 0; >+ int rowWidth = 0; >+ >+ int rowCount = 0; >+ while (idx + rowCount < topControls.length) { >+ Point nextSize = cache.computeSize(idx + rowCount, SWT.DEFAULT, SWT.DEFAULT); >+ >+ rowWidth += nextSize.x; >+ >+ if (rowWidth > clientBounds.width) { >+ break; >+ } >+ >+ currentRect.height = Math.max(currentRect.height, nextSize.y); >+ >+ rowCount++; >+ } >+ >+ if (rowCount > 0) { >+ align(idx, rowCount, currentRect); >+ idx += rowCount; >+ } else { >+ Point size = cache.computeSize(idx, clientBounds.width, SWT.DEFAULT); >+ >+ currentRect.height = size.y; >+ topControls[idx].setBounds(currentRect); >+ >+ idx++; >+ } >+ >+ currentRect.y += currentRect.height; >+ } >+ >+ centerArea = new Rectangle(clientBounds.x, currentRect.y, clientBounds.width, >+ clientBounds.height + clientBounds.y - currentRect.y); >+ } >+ >+ /** >+ * Right-alignes a subset of the top controls in the given region. >+ * >+ * @param firstControl the index of the leftmost control to arrange >+ * @param numControls number of controls to arrange >+ * @param region region in which to arrange the controls >+ */ >+ private void align(int firstControl, int numControls, Rectangle region) { >+ int last = firstControl + numControls; >+ int currentPos = region.x + region.width; >+ >+ // Arrange controls from right to left >+ for (int idx = firstControl + numControls - 1; idx >= firstControl; idx--) { >+ Point size = cache.computeSize(idx, SWT.DEFAULT, SWT.DEFAULT); >+ >+ topControls[idx].setBounds(currentPos - size.x, region.y, size.x, size.y); >+ >+ currentPos -= size.x; >+ } >+ } >+ >+ >+ /** >+ * Returns the region in the title where a toolbar could be rendered in coordinates >+ * relative to the tab folder's parent. >+ * >+ * @return >+ */ >+ protected Rectangle getTitleTrimRegion() { >+ Rectangle result = new Rectangle(0,0,0,0); >+ >+ int itemCount = tabFolder.getItemCount(); >+ if (itemCount > 0) { >+ CTabItem item = tabFolder.getItem(itemCount - 1); >+ >+ Rectangle itemBounds = item.getBounds(); >+ >+ result.x = itemBounds.x + itemBounds.width; >+ result.height = itemBounds.height; >+ result.y = itemBounds.y; >+ result.width = getAvailableSpace(tabFolder); >+ } >+ >+ Rectangle bounds = tabFolder.getBounds(); >+ >+ result.x += bounds.x; >+ result.y += bounds.y; >+ >+ int borderSize = 1; >+ result.y += borderSize; >+ result.height -= borderSize; >+ >+ // Amount to shift to avoid stomping on the curve >+ int xShift = 3; >+ result.x += xShift; >+ result.width -= xShift; >+ >+ return result; >+ } >+ >+ /** >+ * Computes the maximium size available for the trim controls without causing >+ * tabs to disappear. >+ * >+ * @param folder >+ * @return the amount of empty space to the right of the tabs >+ */ >+ protected static int getAvailableSpace(CTabFolder folder) { >+ int available = folder.getBounds().width; >+ >+ available -= 2 * folder.getBorderWidth(); >+ available -= folder.getChevronBounds().width; >+ available -= folder.getMaximizeBounds().width; >+ available -= folder.getMinimizeBounds().width; >+ >+ // Add a safety margin to avoid stomping on the curve >+ available -= 10; >+ >+ CTabItem[] tabs = folder.getItems(); >+ for (int idx = 0; idx < tabs.length; idx++) { >+ CTabItem item = tabs[idx]; >+ >+ if (!item.isShowing()) { >+ return 0; >+ } >+ >+ available -= item.getBounds().width; >+ } >+ >+ return Math.max(0, available); >+ } >+ >+ /** >+ * Returns the total preferred width of the top controls >+ * >+ * @return the total preferred width of the top controls >+ */ >+ protected Point computeTrimSize() { >+ int width = 0; >+ int height = 0; >+ for (int idx = 0; idx < topControls.length; idx++) { >+ Point next = cache.computeSize(idx, SWT.DEFAULT, SWT.DEFAULT); >+ width += next.x; >+ height = Math.max(height, next.y); >+ } >+ >+ return new Point(width, height); >+ } >+ >+ private static Rectangle calculatePageBounds(CTabFolder folder) { >+ if (folder == null) >+ return new Rectangle(0, 0, 0, 0); >+ Rectangle bounds = folder.getBounds(); >+ Rectangle offset = folder.getClientArea(); >+ bounds.x += offset.x; >+ bounds.y += offset.y; >+ bounds.width = offset.width; >+ bounds.height = offset.height; >+ return bounds; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 55156
:
8649
|
8650
|
8652
|
8722
| 8730 |
8731
|
8732
|
8733