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 2e003f7e6d23dd3768244828322022033f96f9a7 Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Wed Jul 23 20:58:29 2025 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Jul 29 15:21:23 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/+/188352 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 8d27eae32b82..b466e07532b6 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -4156,10 +4156,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 20bfe3d50e88..af7dd155bba8 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -2752,6 +2752,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) @@ -2788,6 +2790,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; } @@ -7843,6 +7846,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 c242d00e0bde..7860adf3c66b 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 c4dac79c412c..b6cdd929cb95 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -1308,6 +1308,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 af536717bcbb..08b481d4d60b 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 b3ce57f63f61..9e127571191b 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 674f8e724efa..0c8dc2ef992e 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -301,6 +301,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");