sw/source/uibase/ribbar/drawbase.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
New commits: commit 3db6a93c558c55eed085b4386228f9951bb08936 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Wed Sep 21 10:36:28 2022 +0200 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Thu Sep 22 08:03:18 2022 +0200 Compute a better GetDefaultCenterPos ...as 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: https://gerrit.libreoffice.org/c/core/+/140334 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/sw/source/uibase/ribbar/drawbase.cxx b/sw/source/uibase/ribbar/drawbase.cxx index 36a00853da90..f59a27dc07d0 100644 --- a/sw/source/uibase/ribbar/drawbase.cxx +++ b/sw/source/uibase/ribbar/drawbase.cxx @@ -555,7 +555,11 @@ Point SwDrawBase::GetDefaultCenterPos() const } Point aCenter = aVisArea.Center(); - if (aVisArea.Width() > aDocSz.Width()) + // To increase the chance that aCenter actually falls somewhere on a page (rather than on the + // background between pages), keep it centered horizontally for the "Single-page view" + // (GetViewLayoutColumns() == 1) and "Book view" (GetViewLayoutColumns() == 2) cases that + // display the pages centered on the background: + if (aVisArea.Width() > aDocSz.Width() && m_pSh->GetViewOptions()->GetViewLayoutColumns() == 0) aCenter.setX(aDocSz.Width() / 2 + aVisArea.Left()); if (aVisArea.Height() > aDocSz.Height()) aCenter.setY(aDocSz.Height() / 2 + aVisArea.Top());