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 304264810f6475c0f3c12a0f4eba88c61fe1d799 Author: Gökay Şatır <gokaysa...@collabora.com> AuthorDate: Thu Oct 3 17:31:09 2024 +0300 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Oct 4 09:33:07 2024 +0200 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. Signed-off-by: Gökay Şatır <gokaysa...@collabora.com> Change-Id: I9dad094545c7cf0e072a7831f300dd0401ebf4a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174434 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx index 5de35a9fb3a9..c41825024e33 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 07df2efa4b1d..7560c303262b 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> @@ -1744,6 +1746,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(); @@ -1751,6 +1779,9 @@ void SdPage::SetSize(const Size& aSize) if (aSize != aOldSize) { FmFormPage::SetSize(aSize); + + if (comphelper::LibreOfficeKit::isActive() && SfxViewShell::Current()) + NotifyPagePropertyChanges(); } } @@ -1760,6 +1791,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 16e34f3ac0da..597b388eb5de 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -3671,22 +3671,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 )