[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sw/source

Muhammet Kara (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 30 19:51:24 UTC 2019


 sw/source/uibase/app/docst.cxx |   86 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 85 insertions(+), 1 deletion(-)

New commits:
commit 5a76cbb3570437f2eea4549b97dc6e08068d7a59
Author:     Muhammet Kara <muhammet.kara at collabora.com>
AuthorDate: Mon Jun 24 01:46:42 2019 +0300
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Sep 30 21:50:39 2019 +0200

    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 <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index 806c38b64bf2..59dfb6bbbfd5 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -86,6 +86,7 @@
 #include <paratr.hxx>
 #include <tblafmt.hxx>
 #include <sfx2/watermarkitem.hxx>
+#include <strings.hrc>
 
 using namespace ::com::sun::star;
 
@@ -641,6 +642,71 @@ 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(), uno::UNO_QUERY);
+
+    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,
@@ -830,7 +896,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();
 
@@ -865,6 +936,19 @@ void SwDocShell::Edit(
 
             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


More information about the Libreoffice-commits mailing list