Community
Participate
Working Groups
I notice this problem when I put a FormText control on a ScrolledComposite and then call its computeSize() method to set the minimum size for vertical and horizontal scrollbars. The vertical sizing is correct but the horizontal sizing is far too large for a couple of reasons, e.g. doesn't account for new lines in the formtext markup - if the XML contains line breaks then the paragraph width continues to accumulate regardless. I am enclosing some snippet code here which will demonstrate the problem: package org.eclipse.swt.snippets; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.forms.FormColors; import org.eclipse.ui.forms.widgets.FormText; import org.eclipse.ui.forms.widgets.FormToolkit; public class FormTextComputeSize { public static void main (String [] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setBounds(10, 10, 200, 200); // create scrolled composite ScrolledComposite myComposite = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL); myComposite.setExpandHorizontal(true); myComposite.setExpandVertical(true); // add FormText FormToolkit formToolkit = new FormToolkit(display); FormText formText = formToolkit.createFormText(myComposite, true); // add 5 buttons across top for (int i = 0; i < 5; i++) { Button myButton = new Button(formText, SWT.PUSH); myButton.setText("MyButton" + i); formText.setControl("MyButton" + i, myButton); } // add 15 labels vertically for (int i = 0; i < 15; i++) { Label myLabel = new Label(formText, SWT.NONE); myLabel.setText("myLabel" + i); formText.setControl("MyLabel" + i, myLabel); } formText.setColor("header", formToolkit.getColors().getColor(FormColors.TITLE)); formText.setFont("header", JFaceResources.getHeaderFont()); formText.setText(getText(), true, false); myComposite.setContent(formText); Point point = formText.computeSize(SWT.DEFAULT, SWT.DEFAULT); myComposite.setMinSize(point.x, point.y); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep (); } display.dispose (); } static String getText() { StringBuffer buf = new StringBuffer(); buf.append("<form><p>"); for (int i = 0; i < 5; i++) { buf.append("<control fill=\"false\" href=\"" + "MyButton" + i + "\"/>"); } buf.append("<br/>"); for (int i = 0; i < 15; i++) { buf.append("<control fill=\"false\" href=\"" + "MyLabel" + i + "\"/>"); buf.append("<br/>"); } buf.append("</p></form>"); System.out.println(buf.toString()); return buf.toString(); } } This effectively results in the following markup: - <form> - <p> <control fill="false" href="MyButton0" /> <control fill="false" href="MyButton1" /> <control fill="false" href="MyButton2" /> <control fill="false" href="MyButton3" /> <control fill="false" href="MyButton4" /> <br /> <control fill="false" href="MyLabel0" /> <br /> <control fill="false" href="MyLabel1" /> <br /> <control fill="false" href="MyLabel2" /> <br /> <control fill="false" href="MyLabel3" /> <br /> <control fill="false" href="MyLabel4" /> <br /> <control fill="false" href="MyLabel5" /> <br /> <control fill="false" href="MyLabel6" /> <br /> <control fill="false" href="MyLabel7" /> <br /> <control fill="false" href="MyLabel8" /> <br /> <control fill="false" href="MyLabel9" /> <br /> <control fill="false" href="MyLabel10" /> <br /> <control fill="false" href="MyLabel11" /> <br /> <control fill="false" href="MyLabel12" /> <br /> <control fill="false" href="MyLabel13" /> <br /> <control fill="false" href="MyLabel14" /> <br /> </p> </form> I have a patch which addresses the problem shown here which I would like to contribute for evaluation.
Created attachment 43857 [details] Small change to FormText.computeTextSize() method that modifies logic for computing horizontal size This is a change to the computeTextSize() method that I would like to propose in order to better support horizontal scroll bar sizing for FormText controls. The current computation tends to return horizontal dimensions well in excess of the actual size. The amendment is quite small - just a few lines of code with no API changes.
Created attachment 106605 [details] modified patch I reviewed the provided patch. It looks good, though I moved part of the fix out of FormText and into BreakSegment. While testing I discovered that the horizontal margin on FormText was not being interpreted correctly. When computing size, the left margin was being taken into account twice for all paragraphs. When rendering, the right margin was being ignored by any inline controls. Also I discovered an inconsistency with how the Locator.width field was being used by different subclasses of ParagraphSegment. This caused incorrect size calculations for FormText is some very rare cases. This modified patch fixes all listed problems.
Patch applied to HEAD.
*** Bug 234998 has been marked as a duplicate of this bug. ***
*** Bug 264091 has been marked as a duplicate of this bug. ***