diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Section.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Section.java index 0c88db76a50..b6b1b59a7d3 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Section.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Section.java @@ -24,6 +24,7 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageGcDrawer; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; @@ -314,9 +315,9 @@ private void putTitleBarColor(String key, Color color) { @Override protected void onPaint(PaintEvent e) { - Color bg = null; - Color fg = null; - Color border = null; + Color bg = (titleColors != null) ? titleColors.getOrDefault(COLOR_BG, getBackground()) : getBackground(); + Color fg = (titleColors != null) ? getTitleBarForeground() : getForeground(); + Color border = (titleColors != null) ? titleColors.getOrDefault(COLOR_BORDER, fg) : fg; GC gc = e.gc; Image buffer = null; @@ -325,114 +326,112 @@ protected void onPaint(PaintEvent e) { if (bounds.width == 0 || bounds.height == 0) { return; } + boolean hasTitleBar = (getExpansionStyle() & TITLE_BAR) != 0; + int tvmargin = IGAP; - if ((getExpansionStyle() & TITLE_BAR) != 0) { - buffer = new Image(getDisplay(), bounds.width, bounds.height); + if (hasTitleBar) { + final ImageGcDrawer imageGcDrawer = (iGc, width, height) -> { + // calculate height + int gradientheight = 0; + int theight = 5; + Point tsize = null; + Point tcsize = null; + if (toggle != null) + tsize = toggle.getSize(); + if (getTextClient() != null) + tcsize = getTextClient().getSize(); + Point size = textLabel == null ? new Point(0, 0) : textLabel.getSize(); + if (tsize != null) + theight += Math.max(theight, tsize.y); + gradientheight = theight; + if (tcsize != null) { + theight = Math.max(theight, tcsize.y); + } + theight = Math.max(theight, size.y); + gradientheight = Math.max(gradientheight, size.y); + theight += tvmargin + tvmargin; + gradientheight += tvmargin + tvmargin; + + // Background + if (getBackgroundImage() == null) + updateHeaderImage(bg, bounds, gradientheight, theight); + iGc.setBackground(getBackground()); + iGc.fillRectangle(bounds.x, bounds.y, width, height); + drawBackground(iGc, bounds.x, bounds.y, width, theight - 2); + if (marginWidth > 0) { + // fix up margins + iGc.setBackground(getBackground()); + iGc.fillRectangle(0, 0, marginWidth, theight); + iGc.fillRectangle(bounds.x + width - marginWidth, 0, marginWidth, theight); + } + iGc.setBackground(getBackground()); + FormUtil.setAntialias(iGc, SWT.ON); + // repair the upper left corner + iGc.fillPolygon(new int[] { marginWidth, marginHeight, marginWidth, marginHeight + 2, marginWidth + 2, + marginHeight }); + // repair the upper right corner + iGc.fillPolygon(new int[] { width - marginWidth - 3, marginHeight, width - marginWidth, marginHeight, + width - marginWidth, marginHeight + 3 }); + iGc.setForeground(border); + + // Draw Lines + // top left curve + iGc.drawLine(marginWidth, marginHeight + 2, marginWidth + 2, marginHeight); + // top edge + iGc.drawLine(marginWidth + 2, marginHeight, width - marginWidth - 3, marginHeight); + // top right curve + iGc.drawLine(width - marginWidth - 3, marginHeight, width - marginWidth - 1, + marginHeight + 2); + + // Expand conditions + // left vertical edge gradient + iGc.fillGradientRectangle(marginWidth, marginHeight + 2, 1, theight + 2, true); + // right vertical edge gradient + iGc.fillGradientRectangle(width - marginWidth - 1, marginHeight + 2, 1, theight + 2, true); + + // New in 3.3 - edge treatment + iGc.setForeground(getBackground()); + iGc.drawPolyline(new int[] { marginWidth + 1, marginHeight + gradientheight + 4, marginWidth + 1, + marginHeight + 2, marginWidth + 2, marginHeight + 2, marginWidth + 2, marginHeight + 1, + width - marginWidth - 3, marginHeight + 1, width - marginWidth - 3, marginHeight + 2, + width - marginWidth - 2, marginHeight + 2, width - marginWidth - 2, + marginHeight + gradientheight + 4 }); + }; + + buffer = new Image(getDisplay(), imageGcDrawer, bounds.width, bounds.height); buffer.setBackground(getBackground()); - gc = new GC(buffer); - } - if (titleColors != null) { - bg = titleColors.get(COLOR_BG); - fg = getTitleBarForeground(); - border = titleColors.get(COLOR_BORDER); - } - if (bg == null) - bg = getBackground(); - if (fg == null) - fg = getForeground(); - if (border == null) - border = fg; - int theight = 0; - int gradientheight = 0; - int tvmargin = IGAP; - if ((getExpansionStyle() & TITLE_BAR) != 0) { - Point tsize = null; - Point tcsize = null; - if (toggle != null) - tsize = toggle.getSize(); - if (getTextClient() != null) - tcsize = getTextClient().getSize(); - Point size = textLabel == null ? new Point(0,0) : textLabel.getSize(); - if (tsize != null) - theight += Math.max(theight, tsize.y); - gradientheight = theight; - if (tcsize != null) { - theight = Math.max(theight, tcsize.y); - } - theight = Math.max(theight, size.y); - gradientheight = Math.max(gradientheight, size.y); - theight += tvmargin + tvmargin; - gradientheight += tvmargin + tvmargin; - } else { - theight = 5; - } - if ((getExpansionStyle() & TITLE_BAR) != 0) { - if (getBackgroundImage() == null) - updateHeaderImage(bg, bounds, gradientheight, theight); - gc.setBackground(getBackground()); - gc.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height); - drawBackground(gc, bounds.x, bounds.y, bounds.width, theight - 2); - if (marginWidth > 0) { - // fix up margins - gc.setBackground(getBackground()); - gc.fillRectangle(0, 0, marginWidth, theight); - gc.fillRectangle(bounds.x + bounds.width - marginWidth, 0, - marginWidth, theight); - } } else if (isExpanded()) { + int theight = 5; gc.setForeground(bg); gc.setBackground(getBackground()); gc.fillGradientRectangle(marginWidth, marginHeight, bounds.width - marginWidth - marginWidth, theight, true); - } - gc.setBackground(getBackground()); - FormUtil.setAntialias(gc, SWT.ON); - // repair the upper left corner - gc.fillPolygon(new int[] { marginWidth, marginHeight, marginWidth, - marginHeight + 2, marginWidth + 2, marginHeight }); - // repair the upper right corner - gc.fillPolygon(new int[] { bounds.width - marginWidth - 3, - marginHeight, bounds.width - marginWidth, marginHeight, - bounds.width - marginWidth, marginHeight + 3 }); - gc.setForeground(border); - if (isExpanded() || (getExpansionStyle() & TITLE_BAR) != 0) { - // top left curve - gc.drawLine(marginWidth, marginHeight + 2, marginWidth + 2, - marginHeight); - // top edge - gc.drawLine(marginWidth + 2, marginHeight, bounds.width - - marginWidth - 3, marginHeight); - // top right curve - gc.drawLine(bounds.width - marginWidth - 3, marginHeight, - bounds.width - marginWidth - 1, marginHeight + 2); + // left vertical edge gradient + gc.fillGradientRectangle(marginWidth, marginHeight + 2, 1, theight + 2, true); + // right vertical edge gradient + gc.fillGradientRectangle(bounds.width - marginWidth - 1, marginHeight + 2, 1, theight + 2, true); } else { + gc.setBackground(getBackground()); + FormUtil.setAntialias(gc, SWT.ON); + // repair the upper left corner + gc.fillPolygon(new int[] { marginWidth, marginHeight, marginWidth, + marginHeight + 2, marginWidth + 2, marginHeight }); + // repair the upper right corner + gc.fillPolygon(new int[] { bounds.width - marginWidth - 3, + marginHeight, bounds.width - marginWidth, marginHeight, + bounds.width - marginWidth, marginHeight + 3 }); + gc.setForeground(border); // collapsed short title bar // top edge gc.drawLine(marginWidth, marginHeight, bounds.width - 1, marginHeight); } - if ((getExpansionStyle() & TITLE_BAR) != 0 || isExpanded()) { - // left vertical edge gradient - gc.fillGradientRectangle(marginWidth, marginHeight + 2, 1, theight + 2, true); - // right vertical edge gradient - gc.fillGradientRectangle(bounds.width - marginWidth - 1, marginHeight + 2, 1, theight + 2, true); - } - if ((getExpansionStyle() & TITLE_BAR) != 0) { - // New in 3.3 - edge treatment - gc.setForeground(getBackground()); - gc.drawPolyline(new int[] { marginWidth + 1, marginHeight + gradientheight + 4, marginWidth + 1, - marginHeight + 2, marginWidth + 2, marginHeight + 2, marginWidth + 2, marginHeight + 1, - bounds.width - marginWidth - 3, marginHeight + 1, bounds.width - marginWidth - 3, marginHeight + 2, - bounds.width - marginWidth - 2, marginHeight + 2, bounds.width - marginWidth - 2, - marginHeight + gradientheight + 4 }); - } + if (buffer != null) { - gc.dispose(); e.gc.drawImage(buffer, 0, 0); buffer.dispose(); } } - private void updateHeaderImage(Color bg, Rectangle bounds, int theight, int realtheight) { Color gradient = getTitleBarGradientBackground() != null ? getTitleBarGradientBackground() : getBackground(); Image image = FormImages.getInstance().getSectionGradientImage(gradient, bg, realtheight,