desktop/source/lib/init.cxx | 18 ++++++++++++++++++ include/sfx2/lokhelper.hxx | 2 ++ include/vcl/ITiledRenderable.hxx | 17 +++++++++++++++++ sd/inc/unomodel.hxx | 2 ++ sd/source/core/drawdoc.cxx | 27 +++++++++++++++++++++++++++ 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 ec9eb71e7936be55be42515256946af5fa69c29c Author: Mohit Marathe <[email protected]> AuthorDate: Wed Oct 8 12:12:39 2025 +0530 Commit: Mohit Marathe <[email protected]> CommitDate: Wed Jan 7 11:47:38 2026 +0100 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]> (cherry picked from commit ce9b71b6aaf387566ca1e02d0f5eecd30c97d741) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196653 Tested-by: Jenkins diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 2d47385bc4c7..7ee2c87a9521 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 a3a79d64591f..eff86ff412b8 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; } @@ -516,6 +521,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( @@ -651,6 +667,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 37de19ba1638..a7474d63cd30 100644 --- a/sd/source/ui/sidebar/SlideBackground.cxx +++ b/sd/source/ui/sidebar/SlideBackground.cxx @@ -1104,21 +1104,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 d96a8812a092..603331236c85 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -793,6 +793,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 7d08f386814e6cd16be348577dc20246723e6330 Author: Mohit Marathe <[email protected]> AuthorDate: Tue Oct 7 12:20:38 2025 +0530 Commit: Mohit Marathe <[email protected]> CommitDate: Wed Jan 7 11:47:27 2026 +0100 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]> (cherry picked from commit e83fcef89185531487d9c3b8356ce91252d2f642) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196649 Tested-by: Jenkins diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 4d8207751382..5a7c94afe24c 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -4828,6 +4828,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"); @@ -6879,6 +6893,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 32e4925f0940..09208199552e 100644 --- a/include/vcl/ITiledRenderable.hxx +++ b/include/vcl/ITiledRenderable.hxx @@ -69,6 +69,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/inc/unomodel.hxx b/sd/inc/unomodel.hxx index c23aeddd8cd3..00ef8841cbda 100644 --- a/sd/inc/unomodel.hxx +++ b/sd/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 da79918751bc..4e9254177cb9 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -4182,6 +4182,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 4a23b76cad18..81f4765272e6 100644 --- a/sd/source/ui/view/drviews1.cxx +++ b/sd/source/ui/view/drviews1.cxx @@ -1064,8 +1064,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); } } }
