desktop/source/lib/init.cxx | 18 ++++++++++++++++++ include/sfx2/lokhelper.hxx | 2 ++ include/vcl/ITiledRenderable.hxx | 17 +++++++++++++++++ sd/source/core/drawdoc.cxx | 27 +++++++++++++++++++++++++++ sd/source/ui/inc/unomodel.hxx | 2 ++ sd/source/ui/sidebar/SlideBackground.cxx | 15 --------------- sd/source/ui/unoidl/unomodel.cxx | 28 ++++++++++++++++++++++++++++ sd/source/ui/view/drviews1.cxx | 5 +++-- sfx2/source/view/lokhelper.cxx | 18 ++++++++++++++++++ 9 files changed, 115 insertions(+), 17 deletions(-)
New commits: commit ce9b71b6aaf387566ca1e02d0f5eecd30c97d741 Author: Mohit Marathe <[email protected]> AuthorDate: Wed Oct 8 12:12:39 2025 +0530 Commit: Michael Stahl <[email protected]> CommitDate: Tue Oct 14 15:28:02 2025 +0200 lok: notify all views about page or document resize event Signed-off-by: Mohit Marathe <[email protected]> Change-Id: I1df92e32cf56d940bc3da98c69a555e6423b8c53 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192058 Reviewed-by: Michael Stahl <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index ab8dc309afa1..148303d0bda3 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -187,6 +187,8 @@ public: static void notifyDocumentSizeChanged(SfxViewShell const* pThisView, const OString& rPayload, vcl::ITiledRenderable* pDoc, bool bInvalidateAll = true); /// Emits a LOK_CALLBACK_DOCUMENT_SIZE_CHANGED for all views of the same document - if @bInvalidateAll - first invalidates all parts static void notifyDocumentSizeChangedAllViews(vcl::ITiledRenderable* pDoc, bool bInvalidateAll = true); + /// Emits a LOK_CALLBACK_STATE_CHANGED for all views of the same document - with payload ".uno:CurrentPageResize" + static void notifyCurrentPageSizeChangedAllViews(vcl::ITiledRenderable* pDoc); /// Emits a LOK_CALLBACK_DOCUMENT_SIZE_CHANGED for all views of the same document with the same part static void notifyPartSizeChangedAllViews(vcl::ITiledRenderable* pDoc, int nPart); /// Emits a LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx index 56b4202da639..c569cd4d2f69 100644 --- a/sd/source/core/drawdoc.cxx +++ b/sd/source/core/drawdoc.cxx @@ -20,6 +20,7 @@ #include <libxml/xmlwriter.h> #include "PageListWatcher.hxx" +#include <ViewShellBase.hxx> #include <com/sun/star/document/PrinterIndependentLayout.hpp> #include <com/sun/star/i18n/ScriptType.hpp> #include <com/sun/star/beans/XPropertyContainer.hpp> @@ -39,6 +40,7 @@ #include <officecfg/Office/Draw.hxx> #include <sfx2/linkmgr.hxx> +#include <sfx2/lokhelper.hxx> #include <Outliner.hxx> #include <sdmod.hxx> #include <editeng/editstat.hxx> @@ -53,6 +55,8 @@ #include <i18nlangtag/languagetag.hxx> #include <unotools/charclass.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/lok.hxx> +#include <comphelper/servicehelper.hxx> #include <unotools/lingucfg.hxx> #include <unotools/localedatawrapper.hxx> #include <unotools/syslocale.hxx> @@ -83,6 +87,7 @@ #include <vcl/settings.hxx> #include <vcl/svapp.hxx> #include <unokywds.hxx> +#include <unomodel.hxx> namespace com::sun::star::linguistic2 { class XHyphenator; } namespace com::sun::star::linguistic2 { class XSpellChecker1; } @@ -512,6 +517,17 @@ void SdDrawDocument::ResizeCurrentPage( // SdPage* pNotesPage = GetSdPage(i, PageKind::Notes); // pNotesPage->SetAutoLayout( pNotesPage->GetAutoLayout() ); // } + + // Notify LOK clients of the current page size change. + if (!comphelper::LibreOfficeKit::isActive()) + return; + + SfxViewShell* pViewShell = SfxViewShell::Current(); + if (pViewShell) + { + SdXImpressDocument* pDoc = comphelper::getFromUnoTunnel<SdXImpressDocument>(pViewShell->GetCurrentDocument()); + SfxLokHelper::notifyCurrentPageSizeChangedAllViews(pDoc); + } } void SdDrawDocument::AdaptPageSize( @@ -647,6 +663,17 @@ void SdDrawDocument::AdaptPageSizeForAllPages( pNotesPage->SetAutoLayout( pNotesPage->GetAutoLayout() ); } } + + // Notify LOK clients of the document size change. + if (!comphelper::LibreOfficeKit::isActive()) + return; + + SfxViewShell* pViewShell = SfxViewShell::Current(); + if (pViewShell) + { + SdXImpressDocument* pDoc = comphelper::getFromUnoTunnel<SdXImpressDocument>(pViewShell->GetCurrentDocument()); + SfxLokHelper::notifyDocumentSizeChangedAllViews(pDoc); + } } SdrModel* SdDrawDocument::AllocModel() const diff --git a/sd/source/ui/sidebar/SlideBackground.cxx b/sd/source/ui/sidebar/SlideBackground.cxx index d44b6502c6a1..fc0e032e1a79 100644 --- a/sd/source/ui/sidebar/SlideBackground.cxx +++ b/sd/source/ui/sidebar/SlideBackground.cxx @@ -1103,21 +1103,6 @@ IMPL_LINK_NOARG(SlideBackground, PaperSizeModifyHdl, weld::ComboBox&, void) GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, SfxCallMode::RECORD, { &aSizeItem, mpPageItem.get(), &aFitObjs }); - - // Notify LOK clients of the page size change. - if (!comphelper::LibreOfficeKit::isActive()) - return; - - SfxViewShell* pViewShell = SfxViewShell::GetFirst(); - while (pViewShell) - { - if (pViewShell->GetDocId() == mrBase.GetDocId()) - { - SdXImpressDocument* pDoc = comphelper::getFromUnoTunnel<SdXImpressDocument>(pViewShell->GetCurrentDocument()); - SfxLokHelper::notifyDocumentSizeChangedAllViews(pDoc); - } - pViewShell = SfxViewShell::GetNext(*pViewShell); - } } IMPL_LINK_NOARG(SlideBackground, FillColorHdl, ColorListBox&, void) diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 4512b0ad4a57..31303a95a781 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -814,6 +814,24 @@ void SfxLokHelper::notifyDocumentSizeChangedAllViews(vcl::ITiledRenderable* pDoc } } +void SfxLokHelper::notifyCurrentPageSizeChangedAllViews(vcl::ITiledRenderable *pDoc) +{ + if (!pDoc || pDoc->isDisposed() || DisableCallbacks::disabled()) + return; + + const SfxViewShell* const pCurrentViewShell = SfxViewShell::Current(); + SfxViewShell* pViewShell = SfxViewShell::GetFirst(); + while (pViewShell) + { + if (pCurrentViewShell == nullptr || pViewShell->GetDocId() == pCurrentViewShell->GetDocId()) + { + OString aPayload = ".uno:CurrentPageResize"_ostr; + pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, aPayload); + } + pViewShell = SfxViewShell::GetNext(*pViewShell); + } +} + void SfxLokHelper::notifyPartSizeChangedAllViews(vcl::ITiledRenderable* pDoc, int nPart) { if (DisableCallbacks::disabled()) commit e83fcef89185531487d9c3b8356ce91252d2f642 Author: Mohit Marathe <[email protected]> AuthorDate: Tue Oct 7 12:20:38 2025 +0530 Commit: Michael Stahl <[email protected]> CommitDate: Tue Oct 14 15:27:59 2025 +0200 lok: handle switching to page having different size by sending a lok callback such that client can handle it by retrieving individual part sizes, and set the view size accordingly Signed-off-by: Mohit Marathe <[email protected]> Change-Id: I2d707c38aa39d38a7be09176957bbbcfbf7d2dd8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192004 Reviewed-by: Michael Stahl <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index ef5ad972b266..c093efa36060 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -4822,6 +4822,20 @@ static char* getRulerState(LibreOfficeKitDocument* pThis) return convertOString(aJsonWriter.finishAndGetAsOString()); } +static char* getAllPartSize(LibreOfficeKitDocument* pThis) +{ + SetLastExceptionMsg(); + ITiledRenderable* pDoc = getTiledRenderable(pThis); + if (!pDoc) + { + SetLastExceptionMsg(u"Document doesn't support tiled rendering"_ustr); + return nullptr; + } + tools::JsonWriter aJsonWriter; + pDoc->getAllPartSize(aJsonWriter); + return convertOString(aJsonWriter.finishAndGetAsOString()); +} + static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nCharCode, int nKeyCode) { comphelper::ProfileZone aZone("doc_postKeyEvent"); @@ -6840,6 +6854,10 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo { return convertOString(pDoc->getViewRenderState()); } + else if (aCommand == ".uno:AllPageSize") + { + return getAllPartSize(pThis); + } else if (aCommand.starts_with(aViewRowColumnHeaders)) { tools::Rectangle aRectangle; diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx index bffa919f2137..1e3502a781af 100644 --- a/include/vcl/ITiledRenderable.hxx +++ b/include/vcl/ITiledRenderable.hxx @@ -70,6 +70,23 @@ public: */ virtual Size getDocumentSize() = 0; + /** + * Gets the part size in TWIPs. + * + * nPart is the part number in 0-based indexing. + */ + virtual Size getPartSize(int /*nPart*/) + { + return Size(1,1); + } + + /** + * Gets all parts' size in TWIPs. + */ + virtual void getAllPartSize(::tools::JsonWriter& /*rJsonWriter*/) + { + } + /** * Get the data area size (in Calc last column and row). */ diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx index b5b53ca335cf..6a2a01ce99f7 100644 --- a/sd/source/ui/inc/unomodel.hxx +++ b/sd/source/ui/inc/unomodel.hxx @@ -244,6 +244,8 @@ public: tools::Long nTileWidth, tools::Long nTileHeight ) override; virtual Size getDocumentSize() override; + virtual Size getPartSize(int part) override; + virtual void getAllPartSize(::tools::JsonWriter& rJsonWriter) override; SD_DLLPUBLIC virtual void setPart( int nPart, bool bAllowChangeFocus = true ) override; SD_DLLPUBLIC virtual int getPart() override; SD_DLLPUBLIC virtual int getParts() override; diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index e5d508183504..a5ec6e19c064 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -4199,6 +4199,34 @@ Size SdXImpressDocument::getDocumentSize() return o3tl::convert(aSize, o3tl::Length::mm100, o3tl::Length::twip); } +Size SdXImpressDocument::getPartSize(int part) +{ + if (part < 0 || part > 0xFFFF) + return Size(0,0); + + const sal_uInt16 nSlideIndex = static_cast<sal_uInt16>(part); + SdPage* pPage = mpDoc ? mpDoc->GetSdPage(nSlideIndex, PageKind::Standard) : nullptr; + + if (pPage == nullptr) + return Size(0,0); + + Size aRectSize(pPage->GetWidth() + 1, pPage->GetHeight() + 1); + return o3tl::convert(aRectSize, o3tl::Length::mm100, o3tl::Length::twip); +} + +void SdXImpressDocument::getAllPartSize(::tools::JsonWriter& rJsonWriter) +{ + auto aArray = rJsonWriter.startArray("parts"); + const int nParts = getParts(); + for (int i = 0; i < nParts; ++i) + { + const Size aSize = getPartSize(i); + auto aItem = rJsonWriter.startStruct(); + rJsonWriter.put("width", aSize.getWidth()); + rJsonWriter.put("height", aSize.getHeight()); + } +} + void SdXImpressDocument::getPostIts(::tools::JsonWriter& rJsonWriter) { auto commentsNode = rJsonWriter.startNode("comments"); diff --git a/sd/source/ui/view/drviews1.cxx b/sd/source/ui/view/drviews1.cxx index 2e6109d2e1a0..21dec5ad5204 100644 --- a/sd/source/ui/view/drviews1.cxx +++ b/sd/source/ui/view/drviews1.cxx @@ -1060,8 +1060,9 @@ bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage, bool bAllowChangeFocus) if (comphelper::LibreOfficeKit::isActive()) { - SdXImpressDocument* pDoc = GetDoc()->getUnoModel(); - SfxLokHelper::notifyDocumentSizeChangedAllViews(pDoc); + OString aPayload = ".uno:CurrentPageResize"_ostr; + SfxViewShell* pViewShell = GetViewShell(); + pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, aPayload); } } }
