sd/inc/sdpage.hxx | 3 +++ sd/source/core/sdpage.cxx | 34 ++++++++++++++++++++++++++++++++++ sd/source/ui/unoidl/unomodel.cxx | 33 +++++++++++++++++++-------------- 3 files changed, 56 insertions(+), 14 deletions(-)
New commits: commit 37edf62981acf8b73a70d645755e8cdbc9bbcd3f Author: Gökay Şatır <gokaysa...@collabora.com> AuthorDate: Thu Oct 3 17:31:09 2024 +0300 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Dec 17 11:44:57 2024 +0100 cool#7406: Refactor Impress->getPartInfo & use JsonWriter. We need to add more information to getPartInfo function for getting grid properties. While doing this, i refactored current function to use JsonWriter. We also need to inform client side when a page border, size or margin change happens. This commit also adds a shared function for these events. Change-Id: I9dad094545c7cf0e072a7831f300dd0401ebf4a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178639 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx index 69c7e422af0d..def50b4fe043 100644 --- a/sd/inc/sdpage.hxx +++ b/sd/inc/sdpage.hxx @@ -36,6 +36,7 @@ #include "shapelist.hxx" #include "misc/scopelock.hxx" #include "sddllapi.h" +#include <tools/json_writer.hxx> namespace com::sun::star::animations { class XAnimationNode; @@ -171,6 +172,8 @@ public: OUString GetPresObjText(PresObjKind eObjKind) const; SfxStyleSheet* GetStyleSheetForMasterPageBackground() const; SfxStyleSheet* GetStyleSheetForPresObj(PresObjKind eObjKind) const; + void GetPageInfo(::tools::JsonWriter& jsonWriter); + void NotifyPagePropertyChanges(); bool RestoreDefaultText( SdrObject* pObj ); /** @return true if the given SdrObject is inside the presentation object list */ diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx index fcfa8a10ed54..611b867c6c1a 100644 --- a/sd/source/core/sdpage.cxx +++ b/sd/source/core/sdpage.cxx @@ -22,6 +22,8 @@ #include <comphelper/classids.hxx> #include <comphelper/embeddedobjectcontainer.hxx> +#include <comphelper/lok.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <sfx2/viewsh.hxx> #include <vcl/svapp.hxx> @@ -1749,6 +1751,32 @@ void SdPage::onRemoveObject( SdrObject* pObject ) } } +void SdPage::GetPageInfo(::tools::JsonWriter& jsonWriter) +{ + jsonWriter.put("visible", static_cast<unsigned int>(!this->IsExcluded())); + jsonWriter.put("selected", static_cast<unsigned int>(this->IsSelected())); + jsonWriter.put("width", GetWidth()); + jsonWriter.put("height", GetHeight()); + jsonWriter.put("leftBorder", GetLeftBorder()); + jsonWriter.put("rightBorder", GetRightBorder()); + jsonWriter.put("upperBorder", GetUpperBorder()); + jsonWriter.put("lowerBorder", GetLowerBorder()); + jsonWriter.put("name", GetName()); + jsonWriter.put("hash", GetUniqueID()); +} + +void SdPage::NotifyPagePropertyChanges() +{ + // Send the new size info to views, snapping to grid feature uses this info (maybe some others in the future). + ::tools::JsonWriter jsonWriter; + jsonWriter.put("commandName", ".uno:PageSetup"); + GetPageInfo(jsonWriter); + + OString out = jsonWriter.finishAndGetAsOString(); + SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, out); + SfxViewShell::Current()->NotifyOtherViews(LOK_CALLBACK_STATE_CHANGED, ".uno:PageSetup"_ostr, out); +} + void SdPage::SetSize(const Size& aSize) { Size aOldSize = GetSize(); @@ -1756,6 +1784,9 @@ void SdPage::SetSize(const Size& aSize) if (aSize != aOldSize) { FmFormPage::SetSize(aSize); + + if (comphelper::LibreOfficeKit::isActive() && SfxViewShell::Current()) + NotifyPagePropertyChanges(); } } @@ -1765,6 +1796,9 @@ void SdPage::SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 nRgt != GetRightBorder() || nLwr != GetLowerBorder() ) { FmFormPage::SetBorder(nLft, nUpp, nRgt, nLwr); + + if (comphelper::LibreOfficeKit::isActive() && SfxViewShell::Current()) + NotifyPagePropertyChanges(); } } diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index af23f62fddfd..a0930d8617d8 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -3697,22 +3697,27 @@ OUString SdXImpressDocument::getPartInfo(int nPart) if (!pViewSh) return OUString(); - const SdPage* pSdPage = mpDoc->GetSdPage(nPart, pViewSh->GetPageKind()); - const bool bIsVisible = pSdPage && !pSdPage->IsExcluded(); - const bool bIsSelected = pViewSh->IsSelected(nPart); + SdPage* pSdPage = mpDoc->GetSdPage(nPart, pViewSh->GetPageKind()); const sal_Int16 nMasterPageCount= pViewSh->GetDoc()->GetMasterSdPageCount(pViewSh->GetPageKind()); - OUString aPartInfo = "{ \"visible\": \"" + - OUString::number(static_cast<unsigned int>(bIsVisible)) + - "\", \"selected\": \"" + - OUString::number(static_cast<unsigned int>(bIsSelected)) + - "\", \"masterPageCount\": \"" + - OUString::number(nMasterPageCount) + - "\", \"mode\": \"" + - OUString::number(getEditMode()) + - "\" }"; - - return aPartInfo; + ::tools::JsonWriter jsonWriter; + + jsonWriter.put("masterPageCount", nMasterPageCount); + jsonWriter.put("mode", getEditMode()); + jsonWriter.put("gridSnapEnabled", pViewSh->GetDrawView()->IsGridSnap()); + jsonWriter.put("gridVisible", pViewSh->GetDrawView()->IsGridVisible()); + + // Below information is useful when grid snapping is enabled. It let's to calculate the points we can snap to. + const Size gridCoarse = pViewSh->GetDrawView()->GetGridCoarse(); + const Size innerDots = pViewSh->GetDrawView()->GetGridFine(); + jsonWriter.put("gridCoarseWidth", gridCoarse.getWidth()); + jsonWriter.put("gridCoarseHeight", gridCoarse.getHeight()); + jsonWriter.put("innerSpacesX", innerDots.getWidth() ? gridCoarse.getWidth() / innerDots.getWidth() : 0); + jsonWriter.put("innerSpacesY", innerDots.getHeight() ? gridCoarse.getHeight() / innerDots.getHeight() : 0); + + pSdPage->GetPageInfo(jsonWriter); + + return OStringToOUString(jsonWriter.finishAndGetAsOString(), RTL_TEXTENCODING_UTF8); } void SdXImpressDocument::setPart( int nPart, bool bAllowChangeFocus )