desktop/qa/desktop_lib/test_desktop_lib.cxx | 3 ++- desktop/source/lib/init.cxx | 10 ++++++++++ include/LibreOfficeKit/LibreOfficeKit.h | 3 +++ include/LibreOfficeKit/LibreOfficeKit.hxx | 8 ++++++++ include/sfx2/lokhelper.hxx | 2 ++ libreofficekit/source/gtk/lokdocview.cxx | 2 +- sfx2/source/view/lokhelper.cxx | 18 ++++++++++++++++++ 7 files changed, 44 insertions(+), 2 deletions(-)
New commits: commit b639097a665852f8f99c06a9421597cf98eec6bb Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Wed Jul 23 20:58:29 2025 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Fri Jul 25 17:55:45 2025 +0200 add a way to get the count of current documents. and don't destroy kit on closing all view of one document in gtktiledviewer. Or maybe gtktiledviewer should keep track of the count of current views itself. Change-Id: I59d61d5c0a8dc2ddce42081e2fd6a52b85f9ae2c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188350 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 7627c5d94480..a5be689942ec 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -4048,10 +4048,11 @@ void DesktopLOKTest::testABI() CPPUNIT_ASSERT_EQUAL(classOffset(22), offsetof(struct _LibreOfficeKitClass, setForkedChild)); CPPUNIT_ASSERT_EQUAL(classOffset(23), offsetof(struct _LibreOfficeKitClass, extractDocumentStructureRequest)); CPPUNIT_ASSERT_EQUAL(classOffset(24), offsetof(struct _LibreOfficeKitClass, registerAnyInputCallback)); + CPPUNIT_ASSERT_EQUAL(classOffset(25), offsetof(struct _LibreOfficeKitClass, getDocsCount)); // When extending LibreOfficeKit with a new function pointer, add new assert for the offsetof the // new function pointer and bump this assert for the size of the class. - CPPUNIT_ASSERT_EQUAL(classOffset(25), sizeof(struct _LibreOfficeKitClass)); + CPPUNIT_ASSERT_EQUAL(classOffset(26), sizeof(struct _LibreOfficeKitClass)); CPPUNIT_ASSERT_EQUAL(documentClassOffset(0), offsetof(struct _LibreOfficeKitDocumentClass, destroy)); CPPUNIT_ASSERT_EQUAL(documentClassOffset(1), offsetof(struct _LibreOfficeKitDocumentClass, saveAs)); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 3b160fae098d..2a1be6c5bcf4 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -2748,6 +2748,8 @@ static void lo_dumpState(LibreOfficeKit* pThis, const char* pOptions, char** pSt static char* lo_extractDocumentStructureRequest(LibreOfficeKit* pThis, const char* pFilePath, const char* pFilter); +static int lo_getDocsCount(LibreOfficeKit* pThis); + LibLibreOffice_Impl::LibLibreOffice_Impl() : m_pOfficeClass( gOfficeClass.lock() ) , maThread(nullptr) @@ -2784,6 +2786,7 @@ LibLibreOffice_Impl::LibLibreOffice_Impl() m_pOfficeClass->setForkedChild = lo_setForkedChild; m_pOfficeClass->extractDocumentStructureRequest = lo_extractDocumentStructureRequest; m_pOfficeClass->registerAnyInputCallback = lo_registerAnyInputCallback; + m_pOfficeClass->getDocsCount = lo_getDocsCount; gOfficeClass = m_pOfficeClass; } @@ -7833,6 +7836,13 @@ static void lo_registerAnyInputCallback(LibreOfficeKit* /*pThis*/, }); } +static int lo_getDocsCount(LibreOfficeKit* /*pThis*/) +{ + SolarMutexGuard aGuard; + return SfxLokHelper::getDocsCount(); + +} + static bool bInitialized = false; static void lo_status_indicator_callback(void *data, comphelper::LibreOfficeKit::statusIndicatorCallbackType type, int percent, const char* pText) diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index af08534cdc0c..502d660229bb 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -162,6 +162,9 @@ struct _LibreOfficeKitClass /// @see lok::Office::registerAnyInputCallback() void (*registerAnyInputCallback)(LibreOfficeKit* pThis, LibreOfficeKitAnyInputCallback pCallback, void* pData); + + /// @see lok::Office::getDocsCount(). + int (*getDocsCount) (LibreOfficeKit* pThis); }; #define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocumentClass,member,(pDoc)->pClass->nSize) diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 51e521680ad4..d53b7f8b97eb 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -1297,6 +1297,14 @@ public: { return mpThis->pClass->registerAnyInputCallback(mpThis, pCallback, pData); } + + /** + * Get number of documents of this LibreOfficeKit. + */ + int getDocsCount() + { + return mpThis->pClass->getDocsCount(mpThis); + } }; /// Factory method to create a lok::Office instance. diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 84c7c8e95538..b9189f585161 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -109,6 +109,8 @@ public: static int getCurrentView(); /// Get the number of views of the current DocId. static std::size_t getViewsCount(int nDocId); + /// Get the number of docs + static std::size_t getDocsCount(); /// Get the most recently active viewId of the DocId. static int getViewId(int nDocId); /// Get viewIds of views of the DocId. diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index f9b4d617dc99..25323b43b7ef 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -2804,7 +2804,7 @@ static void lok_doc_view_destroy (GtkWidget* widget) // Last view(s) gone priv->m_pDocument->pClass->destroy (priv->m_pDocument); priv->m_pDocument = nullptr; - if (priv->m_pOffice) + if (priv->m_pOffice && priv->m_pOffice->pClass->getDocsCount(priv->m_pOffice) == 0) { priv->m_pOffice->pClass->destroy (priv->m_pOffice); priv->m_pOffice = nullptr; diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 8a65d172a1fb..fab94e157562 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -281,6 +281,24 @@ int SfxLokHelper::getViewId(int nDocId) return -1; } +std::size_t SfxLokHelper::getDocsCount() +{ + SfxApplication* pApp = SfxApplication::Get(); + if (!pApp) + return 0; + + std::set<ViewShellDocId> aDocs; + + SfxViewShell* pViewShell = SfxViewShell::GetFirst(); + while (pViewShell) + { + aDocs.insert(pViewShell->GetDocId()); + pViewShell = SfxViewShell::GetNext(*pViewShell); + } + + return aDocs.size(); +} + bool SfxLokHelper::getViewIds(int nDocId, int* pArray, size_t nSize) { assert(nDocId != -1 && "Cannot getViewsIds for invalid DocId -1");