Compute a better GetDefaultCenterPos

Desktop / LibreOffice - Stephan Bergmann [] - 22 September 2022 06:03 UTC is used by e.g. Writer's "View - Toolbars - Form Controls", then Ctrl+click the "Text Box" icon:

After ebd7cc1848ba2010128d09c5db524af2c6f5aa66 "tdf#150845: sw_uiwriter3: Add unittest", my 2560x1600 screen Windows laptop kept failing CppunitTest_sw_uiwriter3 with

> sw/qa/extras/uiwriter/uiwriter3.cxx:962:testTdf150845::TestBody > equality assertion failed > - Expected: 1 > - Actual : 0

As it turned out, SwDrawBase::GetDefaultCenterPos happened to pick a position that didn't fall on the single page horizontally centered in the Writer window, but on the background surrounding it, so in SwFEShell::BeginCreate (sw/source/core/frmedt/feshview.cxx)

> if ( GetPageNumber( rPos ) )

failed and no control was created (and so the number of shapes expected by the test wasn't matched).

The logic to adjust aCenter based on aDocSz is there ever since 39ed6bd497f2fed29c84023aa7d1739b303fd043 "#104503# put inserted control at a central position", but that's hard to understand for me because it's hard to understand for me how SwRootFrame::CheckViewLayout in sw/source/core/layout/pagechg.cxx computes aNewSize (which is what ends up here as aDocSz): At least when the Writer window width is larger than necessary to show the full page, aDocSz.Width() apparently doesn't only measure the page's width, but also (part of?) the width of the surrounding background on its left, so the aCenter.setX(...) adjustment could have come up with an X coordinate that wasn't actually centered on the page as apparently expected by the original code.

Experimentally, I learned that for the three Writer view modes:
- "Single-page view" corresponds to GetViewLayoutColumns() == 1 and displays the page horizontally centered in the window.
- "Multiple-page view" corresponds to GetViewLayoutColumns() == 0 and displays the pages starting flush left in the window.
- "Book view" corresponds to GetViewLayoutColumns() == 2 and displays the two pages horizontally centered in the window.

And at least when the window width is substantially larger than necessary to show the one full page of a one-page document (as when showing a default full-size Writer window on my 2560x1600 screen Windows laptop), the behavior of inserting a default-positioned Ctrl+click "Text Box" icon is:
- For "Single-page view" it now actually inserts the control, horizontally centered on the page (instead of not inserting it at all, or inserting it not horizontally centered).
- For "Multiple-page view" it keeps inserting the control horizontally centered on the page, as before.
- For "Book view" it keeps not inserting the control, as before, as apparently before and after it happens to compute positions (albeit different ones) that fall on the background.

Change-Id: Icf7dd30d4ce81e9d47a3c362f455f721f9e3dd30 Reviewed-on:

3db6a93c558c Compute a better GetDefaultCenterPos
sw/source/uibase/ribbar/drawbase.cxx | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)


  • Share