Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » [Forms] Section's client right margin computation bug ?
[Forms] Section's client right margin computation bug ? [message #313579] Mon, 19 March 2007 20:02 Go to next message
Eclipse UserFriend
This is a multi-part message in MIME format.
--------------000300000004000001060208
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi!

I noticed there was (marginWidth + thmargin) less to what should be the
section's client width. I compared what i get to the screen shots in "UI
Forms enhancements in release 3.3" (yes i did that! :)) and found that i
add a two big margin on the right.

I debugged the private layout of ExpandableComposite and i found that at
line 332 (in release 3.3M5)

int areaWidth = clientArea.width - marginWidth - marginWidth
- thmargin - thmargin;
int cx = marginWidth + thmargin;
if ((expansionStyle & CLIENT_INDENT) != 0) {
cx = x;
areaWidth -= x;
}

But when that is called x equals to (marginWidth + thmargin) so after
that areaWidth equals to clientArea.width - 3*marginWidth - 3*thmargin.

Is that a bug or a feature ? If it is a bug then i propose the following:

int areaWidth = clientArea.width - marginWidth - thmargin;
int cx = marginWidth + thmargin;
if ((expansionStyle & CLIENT_INDENT) != 0) {
cx = x;
}
areaWidth -= cx;

I joined a patch. Should I open a bug request ?

Didier.

--------------000300000004000001060208
Content-Type: text/plain;
name="expandable-composite-right-margin-patch.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="expandable-composite-right-margin-patch.txt"

Index: src/org/eclipse/ui/forms/widgets/ExpandableComposite.java
============================================================ =======
RCS file: /cvsroot/eclipse/org.eclipse.ui.forms/src/org/eclipse/ui/for ms/widgets/ExpandableComposite.java,v
retrieving revision 1.56
diff -u -r1.56 ExpandableComposite.java
--- src/org/eclipse/ui/forms/widgets/ExpandableComposite.java 16 Mar 2007 20:24:01 -0000 1.56
+++ src/org/eclipse/ui/forms/widgets/ExpandableComposite.java 19 Mar 2007 23:53:53 -0000
@@ -1,13 +1,10 @@
/*********************************************************** ********************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- ************************************************************ *******************/
+ * Copyright (c) 2000, 2007 IBM Corporation and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html Contributors:
+ * IBM Corporation - initial API and implementation
+ ************************************************************ ******************/
package org.eclipse.ui.forms.widgets;

import org.eclipse.core.runtime.Assert;
@@ -56,7 +53,6 @@
* If several expandable composites are created in the same parent, up/down
* arrow keys can be used to traverse between them. Expandable text accepts
* mnemonics and mnemonic activation will toggle the expansion state.
- *
* <p>
* While expandable composite recognize that different styles can be used to
* render the title bar, and even defines the constants for these styles (<code>TITLE_BAR</code>
@@ -207,21 +203,21 @@

private Control client;

- private ListenerList listeners = new ListenerList();
+ private final ListenerList listeners = new ListenerList();

private Color titleBarForeground;

private class ExpandableLayout extends Layout implements ILayoutExtension {

- private SizeCache toggleCache = new SizeCache();
+ private final SizeCache toggleCache = new SizeCache();

- private SizeCache textClientCache = new SizeCache();
+ private final SizeCache textClientCache = new SizeCache();

- private SizeCache textLabelCache = new SizeCache();
+ private final SizeCache textLabelCache = new SizeCache();

- private SizeCache descriptionCache = new SizeCache();
+ private final SizeCache descriptionCache = new SizeCache();

- private SizeCache clientCache = new SizeCache();
+ private final SizeCache clientCache = new SizeCache();

private void initCache(boolean shouldFlush) {
toggleCache.setControl(toggle);
@@ -254,22 +250,27 @@
int y = marginHeight + tvmargin;
Point tsize = NULL_SIZE;
Point tcsize = NULL_SIZE;
- if (toggle != null)
+ if (toggle != null) {
tsize = toggleCache.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ }
int twidth = clientArea.width - marginWidth - marginWidth
- thmargin - thmargin;
- if (tsize.x > 0)
+ if (tsize.x > 0) {
twidth -= tsize.x + IGAP;
- if (textClient != null)
+ }
+ if (textClient != null) {
tcsize = textClientCache.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- if (tcsize.x > 0)
+ }
+ if (tcsize.x > 0) {
twidth -= tcsize.x + IGAP;
+ }
Point size = NULL_SIZE;
- if (textLabel != null)
+ if (textLabel != null) {
size = textLabelCache.computeSize(twidth, SWT.DEFAULT);
+ }
if (textLabel instanceof Label) {
- Point defSize = textLabelCache.computeSize(SWT.DEFAULT,
- SWT.DEFAULT);
+ Point defSize = textLabelCache.computeSize(
+ SWT.DEFAULT, SWT.DEFAULT);
if (defSize.y == size.y) {
// One line - pick the smaller of the two widths
size.x = Math.min(defSize.x, size.x);
@@ -296,9 +297,10 @@
int ty = y;
if (textClient != null
&& (expansionStyle & LEFT_TEXT_CLIENT_ALIGNMENT) != 0) {
- if (size.y < tcsize.y)
+ if (size.y < tcsize.y) {
ty = tcsize.y / 2 - size.y / 2 + marginHeight
+ tvmargin;
+ }
}
textLabelCache.setBounds(x, ty, size.x, size.y);
}
@@ -312,43 +314,48 @@
textClientCache.setBounds(tcx, y, tcsize.x, tcsize.y);
}
int tbarHeight = 0;
- if (size.y > 0)
+ if (size.y > 0) {
tbarHeight = size.y;
- if (tcsize.y > 0)
+ }
+ if (tcsize.y > 0) {
tbarHeight = Math.max(tbarHeight, tcsize.y);
+ }
y += tbarHeight;
- if (hasTitleBar())
+ if (hasTitleBar()) {
y += tvmargin;
+ }
if (getSeparatorControl() != null) {
y += VSPACE;
- getSeparatorControl().setBounds(marginWidth, y,
+ getSeparatorControl().setBounds(
+ marginWidth, y,
clientArea.width - marginWidth - marginWidth,
SEPARATOR_HEIGHT);
y += SEPARATOR_HEIGHT;
- if (expanded)
+ if (expanded) {
y += VSPACE;
+ }
}
if (expanded) {
- int areaWidth = clientArea.width - marginWidth - marginWidth
- - thmargin - thmargin;
+ int areaWidth = clientArea.width - marginWidth - thmargin;
int cx = marginWidth + thmargin;
if ((expansionStyle & CLIENT_INDENT) != 0) {
cx = x;
- areaWidth -= x;
}
+ areaWidth -= cx;
if (client != null) {
Point dsize = null;
Control desc = getDescriptionControl();
if (desc != null) {
- dsize = descriptionCache.computeSize(areaWidth,
- SWT.DEFAULT);
+ dsize = descriptionCache.computeSize(
+ areaWidth, SWT.DEFAULT);
y += descriptionVerticalSpacing;
descriptionCache.setBounds(cx, y, areaWidth, dsize.y);
y += dsize.y + clientVerticalSpacing;
} else {
y += clientVerticalSpacing;
- if (getSeparatorControl() != null)
+ if (getSeparatorControl() != null) {
y -= VSPACE;
+ }
}
int cwidth = areaWidth;
int cheight = clientArea.height - marginHeight
@@ -377,39 +384,45 @@
tvmargin = IVGAP;
}
int innerwHint = wHint;
- if (innerwHint != SWT.DEFAULT)
+ if (innerwHint != SWT.DEFAULT) {
innerwHint -= twidth + marginWidth + marginWidth + thmargin
+ thmargin;
+ }

int innertHint = innerwHint;

Point tcsize = NULL_SIZE;
if (textClient != null) {
tcsize = textClientCache.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- if (innertHint != SWT.DEFAULT)
+ if (innertHint != SWT.DEFAULT) {
innertHint -= IGAP + tcsize.x;
+ }
}
Point size = NULL_SIZE;

- if (textLabel != null)
+ if (textLabel != null) {
size = textLabelCache.computeSize(innertHint, SWT.DEFAULT);
+ }
if (textLabel instanceof Label) {
- Point defSize = textLabelCache.computeSize(SWT.DEFAULT,
- SWT.DEFAULT);
+ Point defSize = textLabelCache.computeSize(
+ SWT.DEFAULT, SWT.DEFAULT);
if (defSize.y == size.y) {
// One line - pick the smaller of the two widths
size.x = Math.min(defSize.x, size.x);
}
}
- if (size.x > 0)
+ if (size.x > 0) {
width = size.x;
- if (tcsize.x > 0)
+ }
+ if (tcsize.x > 0) {
width += IGAP + tcsize.x;
+ }
height = tcsize.y > 0 ? Math.max(tcsize.y, size.y) : size.y;
if (getSeparatorControl() != null) {
height += VSPACE + SEPARATOR_HEIGHT;
- if (expanded && client != null)
+ if (expanded && client != null) {
height += VSPACE;
+ }
}
// if (hasTitleBar())
// height += VSPACE;
@@ -418,9 +431,11 @@

if (cwHint != SWT.DEFAULT) {
cwHint -= marginWidth + marginWidth + thmargin + thmargin;
- if ((expansionStyle & CLIENT_INDENT) != 0)
- if (tcsize.x > 0)
+ if ((expansionStyle & CLIENT_INDENT) != 0) {
+ if (tcsize.x > 0) {
cwHint -= twidth;
+ }
+ }
}
Point dsize = null;
Point csize = clientCache.computeSize(FormUtil.getWidthHint(
@@ -429,24 +444,28 @@
int dwHint = cwHint;
if (dwHint == SWT.DEFAULT) {
dwHint = csize.x;
- if ((expansionStyle & CLIENT_INDENT) != 0)
+ if ((expansionStyle & CLIENT_INDENT) != 0) {
dwHint -= twidth;
+ }
}
dsize = descriptionCache.computeSize(dwHint, SWT.DEFAULT);
}
if (dsize != null) {
width = Math.max(width, dsize.x);
- if (expanded)
+ if (expanded) {
height += descriptionVerticalSpacing + dsize.y
+ clientVerticalSpacing;
+ }
} else {
height += clientVerticalSpacing;
- if (getSeparatorControl() != null)
+ if (getSeparatorControl() != null) {
height -= VSPACE;
+ }
}
width = Math.max(width, csize.x);
- if (expanded)
+ if (expanded) {
height += csize.y;
+ }
}
if (toggle != null) {
height = height - size.y + Math.max(size.y, tsize.y);
@@ -501,24 +520,27 @@
public ExpandableComposite(Composite parent, int style, int expansionStyle) {
super(parent, style);
this.expansionStyle = expansionStyle;
- if ((expansionStyle & TITLE_BAR) != 0)
+ if ((expansionStyle & TITLE_BAR) != 0) {
setBackgroundMode(SWT.INHERIT_DEFAULT);
+ }
super.setLayout(new ExpandableLayout());
if (hasTitleBar()) {
- this.addPaintListener(new PaintListener() {
+ addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
onPaint(e);
}
});
}
- if ((expansionStyle & TWISTIE) != 0)
+ if ((expansionStyle & TWISTIE) != 0) {
toggle = new Twistie(this, SWT.NULL);
- else if ((expansionStyle & TREE_NODE) != 0)
+ } else if ((expansionStyle & TREE_NODE) != 0) {
toggle = new TreeNode(this, SWT.NULL);
- else
+ } else {
expanded = true;
- if ((expansionStyle & EXPANDED) != 0)
+ }
+ if ((expansionStyle & EXPANDED) != 0) {
expanded = true;
+ }
if (toggle != null) {
toggle.setExpanded(expanded);
toggle.addHyperlinkListener(new HyperlinkAdapter() {
@@ -528,10 +550,11 @@
});
toggle.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
- if (textLabel instanceof Label && !isFixedStyle())
+ if (textLabel instanceof Label && !isFixedStyle()) {
textLabel.setForeground(toggle.hover ? toggle
.getHoverDecorationColor()
: getTitleBarForeground());
+ }
}
});
toggle.addKeyListener(new KeyAdapter() {
@@ -545,8 +568,8 @@
}
}
});
- if ((getExpansionStyle()&FOCUS_TITLE)==0) {
- toggle.paintFocus=false;
+ if ((getExpansionStyle() & FOCUS_TITLE) == 0) {
+ toggle.paintFocus = false;
toggle.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
textLabel.redraw();
@@ -574,8 +597,9 @@
public void handleEvent(Event e) {
switch (e.type) {
case SWT.MouseDown:
- if (toggle != null)
+ if (toggle != null) {
toggle.setFocus();
+ }
break;
case SWT.MouseUp:
label.setCursor(FormsResources.getBusyCursor());
@@ -619,8 +643,9 @@
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_MNEMONIC) {
// steal the mnemonic
- if (!isVisible() || !isEnabled())
+ if (!isVisible() || !isEnabled()) {
return;
+ }
if (FormUtil.mnemonicMatch(getText(), e.character)) {
e.doit = false;
programmaticToggleState();
@@ -632,7 +657,9 @@
}
}

- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.swt.widgets.Control#forceFocus()
*/
public boolean forceFocus() {
@@ -647,8 +674,9 @@
*/

public void setMenu(Menu menu) {
- if (textLabel != null)
+ if (textLabel != null) {
textLabel.setMenu(menu);
+ }
super.setMenu(menu);
}

@@ -665,10 +693,12 @@
public void setBackground(Color bg) {
super.setBackground(bg);
if ((getExpansionStyle() & TITLE_BAR) == 0) {
- if (textLabel != null)
+ if (textLabel != null) {
textLabel.setBackground(bg);
- if (toggle != null)
+ }
+ if (toggle != null) {
toggle.setBackground(bg);
+ }
}
}

@@ -677,10 +707,12 @@
*/
public void setForeground(Color fg) {
super.setForeground(fg);
- if (textLabel != null)
+ if (textLabel != null) {
textLabel.setForeground(fg);
- if (toggle != null)
+ }
+ if (toggle != null) {
toggle.setForeground(fg);
+ }
}

/**
@@ -690,8 +722,9 @@
* the color object
*/
public void setToggleColor(Color c) {
- if (toggle != null)
+ if (toggle != null) {
toggle.setDecorationColor(c);
+ }
}

/**
@@ -702,8 +735,9 @@
* the active color object
*/
public void setActiveToggleColor(Color c) {
- if (toggle != null)
+ if (toggle != null) {
toggle.setHoverDecorationColor(c);
+ }
}

/**
@@ -711,10 +745,12 @@
*/
public void setFont(Font font) {
super.setFont(font);
- if (textLabel != null)
+ if (textLabel != null) {
textLabel.setFont(font);
- if (toggle != null)
+ }
+ if (toggle != null) {
toggle.setFont(font);
+ }
}

/*
@@ -724,10 +760,12 @@
*/

public void setEnabled(boolean enabled) {
- if (textLabel != null)
+ if (textLabel != null) {
textLabel.setEnabled(enabled);
- if (toggle != null)
+ }
+ if (toggle != null) {
toggle.setEnabled(enabled);
+ }
super.setEnabled(enabled);
}

@@ -762,10 +800,11 @@
* @see #getText()
*/
public void setText(String title) {
- if (textLabel instanceof Label)
+ if (textLabel instanceof Label) {
((Label) textLabel).setText(title);
- else if (textLabel instanceof Hyperlink)
+ } else if (textLabel instanceof Hyperlink) {
((Hyperlink) textLabel).setText(title);
+ }
}

/**
@@ -775,12 +814,13 @@
* @see #setText(String)
*/
public String getText() {
- if (textLabel instanceof Label)
+ if (textLabel instanceof Label) {
return ((Label) textLabel).getText();
- else if (textLabel instanceof Hyperlink)
+ } else if (textLabel instanceof Hyperlink) {
return ((Hyperlink) textLabel).getText();
- else
+ } else {
return ""; //$NON-NLS-1$
+ }
}

/**
@@ -809,8 +849,9 @@
*/
public void setExpanded(boolean expanded) {
internalSetExpanded(expanded);
- if (toggle != null)
+ if (toggle != null) {
toggle.setExpanded(expanded);
+ }
}

/**
@@ -822,10 +863,12 @@
protected void internalSetExpanded(boolean expanded) {
if (this.expanded != expanded) {
this.expanded = expanded;
- if (getDescriptionControl() != null)
+ if (getDescriptionControl() != null) {
getDescriptionControl().setVisible(expanded);
- if (client != null)
+ }
+ if (client != null) {
client.setVisible(expanded);
+ }
layout();
}
}
@@ -936,8 +979,9 @@
* more.
*/
public void setTextClient(Control textClient) {
- if (this.textClient != null)
+ if (this.textClient != null) {
this.textClient.dispose();
+ }
this.textClient = textClient;
}

@@ -955,8 +999,9 @@
* @since 3.3
*/
public int getTextClientHeightDifference() {
- if (textClient == null || textLabel == null)
+ if (textClient == null || textLabel == null) {
return 0;
+ }
int theight = textLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
int tcheight = textClient.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
return Math.max(tcheight - theight, 0);
@@ -1001,22 +1046,25 @@
fireExpanding(newState, true);
internalSetExpanded(newState);
fireExpanding(newState, false);
- if (newState)
+ if (newState) {
FormUtil.ensureVisible(this);
+ }
}

private void fireExpanding(boolean state, boolean before) {
int size = listeners.size();
- if (size == 0)
+ if (size == 0) {
return;
+ }
ExpansionEvent e = new ExpansionEvent(this, state);
- Object [] listenerList = listeners.getListeners();
+ Object[] listenerList = listeners.getListeners();
for (int i = 0; i < size; i++) {
IExpansionListener listener = (IExpansionListener) listenerList[i];
- if (before)
+ if (before) {
listener.expansionStateChanging(e);
- else
+ } else {
listener.expansionStateChanged(e);
+ }
}
}

@@ -1040,24 +1088,27 @@
int loc = down ? index + 1 : index - 1;
while (loc >= 0 && loc < children.length) {
Control c = children[loc];
- if (c instanceof ExpandableComposite && c.isVisible())
+ if (c instanceof ExpandableComposite && c.isVisible()) {
return (ExpandableComposite) c;
+ }
loc = down ? loc + 1 : loc - 1;
}
return null;
}

private void programmaticToggleState() {
- if (toggle != null)
+ if (toggle != null) {
toggle.setExpanded(!toggle.isExpanded());
+ }
toggleState();
}
-
+
private void paintTitleFocus(GC gc) {
Point size = textLabel.getSize();
gc.setBackground(textLabel.getBackground());
gc.setForeground(textLabel.getForeground());
- if (toggle.isFocusControl())
+ if (toggle.isFocusControl()) {
gc.drawFocus(0, 0, size.x, size.y);
+ }
}
}

--------------000300000004000001060208--
Re: [Forms] Section's client right margin computation bug ? [message #313580 is a reply to message #313579] Mon, 19 March 2007 21:05 Go to previous message
Eclipse UserFriend
This is a multi-part message in MIME format.
--------------000100070907080502020503
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Sorry! I did not disable my save actions for that project...

The patch without gargabe...

Ptitjes a
Previous Topic:[DataBinding] Where to call out to a service/database to re-query based on a selection changes.
Next Topic:Additional Validation check on filename in Refactor->Rename dialog
Goto Forum:
  


Current Time: Mon Nov 10 12:47:51 EST 2025

Powered by FUDForum. Page generated in 0.03898 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top