sw/source/uibase/app/docst.cxx | 85 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-)
New commits: commit c927ea4c5d8a9ede979e17c09c2303854ccdebec Author: Muhammet Kara <muhammet.k...@collabora.com> AuthorDate: Mon Jun 24 01:46:42 2019 +0300 Commit: Muhammet Kara <muhammet.k...@collabora.com> CommitDate: Sat Nov 9 20:02:37 2019 +0100 Sync page orientation of Endnote page Description: When changing the default page style to have a different orientation, end-notes are placed on a page with a custom ‘Endnote’ page style. This style does not inherit its orientation from the default style. Repro: Create a blank document, insert→End Note, Format→Page in the first page, select the Page tab, and alter the Orientation to Landscape, ‘Ok’. The End-note page should update its orientation too. NB. If the Endnote page style is manually set to a different value in a document template it will remain in the selected orientation. After this patch, Default style and the Endnote style have their orientations synced after each run of the Format > Page dialog. Ideally, this should be solved by resolving tdf#41316 on master: Page styles should support hierarchical parent-child relationships (like paragraph or character styles) Change-Id: I255b470d1aebb897f50a4a74b8678b771ffbab28 Reviewed-on: https://gerrit.libreoffice.org/79869 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Andras Timar <andras.ti...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/82173 Tested-by: Jenkins Reviewed-by: Muhammet Kara <muhammet.k...@collabora.com> diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx index d413e4fe8e4c..cb580785e8a8 100644 --- a/sw/source/uibase/app/docst.cxx +++ b/sw/source/uibase/app/docst.cxx @@ -89,6 +89,7 @@ #include <tblafmt.hxx> #include <sfx2/watermarkitem.hxx> #include <SwUndoFmt.hxx> +#include <strings.hrc> using namespace ::com::sun::star; @@ -646,6 +647,70 @@ IMPL_LINK_NOARG(ApplyStyle, ApplyHdl, LinkParamNone*, void) pWrtShell->EndAllAction(); } +namespace +{ +/// Checks if there is an Endnote page style in use, and makes sure it has the same orientation +/// with the Default (Standard) page style. +void syncEndnoteOrientation(const uno::Reference< style::XStyleFamiliesSupplier >& xStyleFamSupp) +{ + if (!xStyleFamSupp.is()) + { + SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null."); + return; + } + uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamSupp->getStyleFamilies(); + + if (!xStyleFamilies.is()) + return; + + uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName("PageStyles"), + uno::UNO_QUERY); + + if (!xPageStyles.is()) + return; + + uno::Reference<css::style::XStyle> xEndnotePageStyle(xPageStyles->getByName("Endnote"), + uno::UNO_QUERY); + + if (!xEndnotePageStyle.is()) + return; + + // Language-independent name of the "Default Style" is "Standard" + uno::Reference<css::style::XStyle> xDefaultPageStyle(xPageStyles->getByName("Standard"), + uno::UNO_QUERY); + if (!xDefaultPageStyle.is()) + return; + + if (xEndnotePageStyle->isUserDefined() || !xEndnotePageStyle->isInUse()) + return; + + uno::Reference<beans::XPropertySet> xEndnotePagePropSet(xPageStyles->getByName("Endnote"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xDefaultPagePropSet(xPageStyles->getByName("Standard"), uno::UNO_QUERY); + + if (!xEndnotePagePropSet.is() || !xDefaultPagePropSet.is()) + { + SAL_WARN("sw.ui", "xEndnotePagePropSet or xDefaultPagePropSet is null."); + return; + } + + sal_Int32 nWidth, nHeight; + bool bIsDefLandScape, bIsEndLandScape; + + xDefaultPagePropSet->getPropertyValue("IsLandscape") >>= bIsDefLandScape; + xEndnotePagePropSet->getPropertyValue("IsLandscape") >>= bIsEndLandScape; + + if (bIsDefLandScape == bIsEndLandScape) + return; + + xEndnotePagePropSet->getPropertyValue("Width") >>= nWidth; + xEndnotePagePropSet->getPropertyValue("Height") >>= nHeight; + + xEndnotePagePropSet->setPropertyValue("IsLandscape", css::uno::toAny(bIsDefLandScape)); + xEndnotePagePropSet->setPropertyValue("Width", css::uno::toAny(nHeight)); + xEndnotePagePropSet->setPropertyValue("Height", css::uno::toAny(nWidth)); +} +} + void SwDocShell::Edit( const OUString &rName, const OUString &rParent, @@ -845,7 +910,12 @@ void SwDocShell::Edit( pReq->Ignore(); // the 'old' request is not relevant any more } - pDlg->StartExecuteAsync([bModified, bNew, nFamily, nSlot, nNewStyleUndoId, pApplyStyleHelper, pRequest, xTmp, this](sal_Int32 nResult){ + bool bIsDefaultPage = nFamily == SfxStyleFamily::Page + && rName == SwResId(STR_POOLPAGE_STANDARD) + && pStyle->IsUsed() + && !pStyle->IsUserDefined(); + + pDlg->StartExecuteAsync([bIsDefaultPage, bModified, bNew, nFamily, nSlot, nNewStyleUndoId, pApplyStyleHelper, pRequest, xTmp, this](sal_Int32 nResult){ if (RET_OK == nResult) pApplyStyleHelper->apply(); @@ -925,6 +995,19 @@ void SwDocShell::Edit( pApplyStyleHelper->m_pDlg.disposeAndClear(); if (pRequest) pRequest->Done(); + + if (bIsDefaultPage && bModified) + { + uno::Reference< style::XStyleFamiliesSupplier > xStyleFamSupp(GetModel(), uno::UNO_QUERY); + + if (!xStyleFamSupp.is()) + { + SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null."); + return; + } + + syncEndnoteOrientation(xStyleFamSupp); + } }); } else _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits