Bug 132832 - XLayoutConstrains.calcAdjustedSize doesn't return proper size for multiline checkbox and hyperlink
Summary: XLayoutConstrains.calcAdjustedSize doesn't return proper size for multiline c...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
6.4.0.0.alpha0+
Hardware: All All
: medium normal
Assignee: Michael Weghorn
URL:
Whiteboard: target:7.0.0 target:6.4.5
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-08 06:25 UTC by Michael Weghorn
Modified: 2020-05-13 20:04 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Sample Java extension to reproduce the issue (17.74 KB, application/vnd.openofficeorg.extension)
2020-05-08 06:25 UTC, Michael Weghorn
Details
Source code of sample extension (11.19 KB, application/gzip)
2020-05-08 06:26 UTC, Michael Weghorn
Details
Screenshot after resizing (20.13 KB, image/png)
2020-05-08 06:27 UTC, Michael Weghorn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Weghorn 2020-05-08 06:25:09 UTC
Created attachment 160517 [details]
Sample Java extension to reproduce the issue

The method calcAdjustedSize() of the UNO interface does not return proper height/width for mutline checkboxes and hyperlinks.

A sample extension is attached.

# Steps to reproduce:

1) install the attached sample extension "StarterProject.oxt"
2) start LO Writer
3) in the menu, select "Test Extension" -> "Show Dialog" to show the sample dialog
4) press the "Resize" button, which calls the 'calcAdjustedSize' method (with value 500 for width and 50 for the height) to calculate the proper size for the form controls, then resizes to the returned size using 'setPosSize'
5) check the text shown next to the checkbox (second last control) and the hyperlink (last control)

# Result:

* The text to the checkbox is much wider than the expected width of 500, and still cut off, since it does not fit into one line.
* The text for the hyperlink control is incomplete, since it is just one line, but cut off at width 500.

A screenshot will be attached.

# Expected result:

Both, the text for the checkbox and that for the hyperlink control should be complete, split over multiple lines, and not exceed the width of 500.

# Version used

Version: 7.0.0.0.alpha0+
Build ID: 934fd1c617d1f7fba90f922bf2d526ea3f35f9b7
CPU threads: 4; OS: Linux 5.6; UI render: default; VCL: gtk3; 
Locale: en-GB (en_GB.UTF-8); UI-Language: en-US
Calc: threaded

and the result is similar when using the gen/x11 VCL plugin instead.

# More information/notes

The relevant Java method from the extension to do the resizing looks as follows (whole extension source code will be attached):

public ActionOneDialog(XComponentContext xContext)
        {
          this.dialog = DialogHelper.createDialog("ActionOneDialog.xdl", xContext, this);
          
          XButton button = DialogHelper.getButton(dialog, "Resize");
          button.addActionListener(new XActionListener()
          {

            @Override
            public void disposing(EventObject arg0)
            {
            }

            @Override
            public void actionPerformed(ActionEvent arg0)
            {
              String output = "Control: %s, calculated Width %d, maximum Width %d, calculated Height %d";
              Size max = new Size(500, 50);
              Size size;
              XLayoutConstrains lc;
              XWindow window;
              Rectangle r = null;

              XFixedText label = DialogHelper.getLabel(dialog, "Label1");
              lc = UnoRuntime.queryInterface(XLayoutConstrains.class, label);
              size = lc.calcAdjustedSize(max);
              System.out.println(String.format(output, "Label1", size.Width, max.Width, size.Height));
              window = UnoRuntime.queryInterface(XWindow.class, label);
              r = window.getPosSize();
              window.setPosSize(r.X, r.Y, size.Width, size.Height, PosSize.POSSIZE);

              XTextComponent text = DialogHelper.getEditField(dialog, "TextField1");
              lc = UnoRuntime.queryInterface(XLayoutConstrains.class, text);
              size = lc.calcAdjustedSize(max);
              System.out.println(String.format(output, "TextField1", size.Width, max.Width, size.Height));
              window = UnoRuntime.queryInterface(XWindow.class, text);
              r = window.getPosSize();
              window.setPosSize(r.X, r.Y, size.Width, size.Height, PosSize.POSSIZE);

              XListBox list = DialogHelper.getListBox(dialog, "ListBox1");
              lc = UnoRuntime.queryInterface(XLayoutConstrains.class, list);
              size = lc.calcAdjustedSize(max);
              System.out.println(String.format(output, "ListBox1", size.Width, max.Width, size.Height));
              window = UnoRuntime.queryInterface(XWindow.class, list);
              r = window.getPosSize();
              window.setPosSize(r.X, r.Y, size.Width, size.Height, PosSize.POSSIZE);

              XComboBox combo = DialogHelper.getCombobox(dialog, "ComboBox1");
              lc = UnoRuntime.queryInterface(XLayoutConstrains.class, combo);
              size = lc.calcAdjustedSize(max);
              System.out.println(String.format(output, "ComboBox1", size.Width, max.Width, size.Height));
              window = UnoRuntime.queryInterface(XWindow.class, combo);
              r = window.getPosSize();
              window.setPosSize(r.X, r.Y, size.Width, size.Height, PosSize.POSSIZE);

              XCheckBox check = DialogHelper.getCheckBox(dialog, "CheckBox1");
              lc = UnoRuntime.queryInterface(XLayoutConstrains.class, check);
              size = lc.calcAdjustedSize(max);
              System.out.println(String.format(output, "CheckBox1", size.Width, max.Width, size.Height));
              window = UnoRuntime.queryInterface(XWindow.class, check);
              r = window.getPosSize();
              window.setPosSize(r.X, r.Y, size.Width, size.Height, PosSize.POSSIZE);

              XFixedHyperlink link = DialogHelper.getLink(dialog, "Hyper1");
              lc = UnoRuntime.queryInterface(XLayoutConstrains.class, link);
              size = lc.calcAdjustedSize(max);
              System.out.println(String.format(output, "Hyper1", size.Width, max.Width, size.Height));
              window = UnoRuntime.queryInterface(XWindow.class, link);
              r = window.getPosSize();
              window.setPosSize(r.X, r.Y, size.Width, size.Height, PosSize.POSSIZE);
            }
          });
          
	}
Comment 1 Michael Weghorn 2020-05-08 06:26:46 UTC
Created attachment 160518 [details]
Source code of sample extension
Comment 2 Michael Weghorn 2020-05-08 06:27:48 UTC
Created attachment 160519 [details]
Screenshot after resizing

This bug was initially reported to me by another person inside our organization. I'm currently taking a look.
Comment 3 Commit Notification 2020-05-11 08:30:05 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/2539f1d142e0077dfeec36ef349a1f5443f1c94b

tdf#132832 calcAdjustedSize: Take max width into account

It will be available in 7.0.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Michael Weghorn 2020-05-11 08:31:26 UTC
Fixed on master, backport for 6.4 pending at https://gerrit.libreoffice.org/c/core/+/93798
Comment 5 Commit Notification 2020-05-13 20:04:09 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "libreoffice-6-4":

https://git.libreoffice.org/core/commit/ae6d48c94da8d29fa0f34f801f99131fe6206f83

tdf#132832 calcAdjustedSize: Take max width into account

It will be available in 6.4.5.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.