From da8b89db49d0dfcef0ae0052bb8ab9d77a509dfb Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 16 Sep 2015 14:14:04 +0200 Subject: [PATCH 142/398] LOK: make getViews() be a member function of Document Just to be consistent, as all other view-related member functions are there, too. No real impact, as only the unit test uses this so far, and it always works with a single document. Change-Id: I46f1ed8265ab95017986ab45c1b510e961192241 (cherry picked from commit a04b31c9facb08a8e38b79480b9a73bd2693cb9e) --- desktop/qa/desktop_lib/test_desktop_lib.cxx | 6 +++--- desktop/source/lib/init.cxx | 17 +++++++++-------- include/LibreOfficeKit/LibreOfficeKit.h | 5 ++--- include/LibreOfficeKit/LibreOfficeKit.hxx | 18 ++++++++---------- include/sfx2/lokhelper.hxx | 5 ++--- sfx2/source/view/lokhelper.cxx | 13 +++++++++++-- 6 files changed, 35 insertions(+), 29 deletions(-) diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 7ad81278d64a..0cd88cefffa0 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -134,10 +134,10 @@ void DesktopLOKTest::testGetFonts() void DesktopLOKTest::testCreateView() { LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); - CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews()); + CPPUNIT_ASSERT_EQUAL(1, pDocument->m_pDocumentClass->getViews(pDocument)); int nId = pDocument->m_pDocumentClass->createView(pDocument); - CPPUNIT_ASSERT_EQUAL(2, SfxLokHelper::getViews()); + CPPUNIT_ASSERT_EQUAL(2, pDocument->m_pDocumentClass->getViews(pDocument)); // Make sure the created view is the active one, then switch to the old // one. @@ -146,7 +146,7 @@ void DesktopLOKTest::testCreateView() CPPUNIT_ASSERT_EQUAL(0, pDocument->m_pDocumentClass->getView(pDocument)); pDocument->m_pDocumentClass->destroyView(pDocument, nId); - CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews()); + CPPUNIT_ASSERT_EQUAL(1, pDocument->m_pDocumentClass->getViews(pDocument)); closeDoc(); } diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index fa99038860cd..617c94638cde 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -254,6 +254,7 @@ static int doc_createView(LibreOfficeKitDocument* pThis); static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId); static void doc_setView(LibreOfficeKitDocument* pThis, int nId); static int doc_getView(LibreOfficeKitDocument* pThis); +static int doc_getViews(LibreOfficeKitDocument* pThis); LibLODocument_Impl::LibLODocument_Impl(const uno::Reference &xComponent) : mxComponent( xComponent ) @@ -289,6 +290,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference destroyView = doc_destroyView; m_pDocumentClass->setView = doc_setView; m_pDocumentClass->getView = doc_getView; + m_pDocumentClass->getViews = doc_getViews; gDocumentClass = m_pDocumentClass; } @@ -316,8 +318,6 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions (LibreOfficeKit* pThi static void lo_registerCallback (LibreOfficeKit* pThis, LibreOfficeKitCallback pCallback, void* pData); -static int lo_getViews(LibreOfficeKit* pThis); - struct LibLibreOffice_Impl : public _LibreOfficeKit { OUString maLastExceptionMsg; @@ -340,7 +340,6 @@ struct LibLibreOffice_Impl : public _LibreOfficeKit m_pOfficeClass->getError = lo_getError; m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions; m_pOfficeClass->registerCallback = lo_registerCallback; - m_pOfficeClass->getViews = lo_getViews; gOfficeClass = m_pOfficeClass; } @@ -458,11 +457,6 @@ static void lo_registerCallback (LibreOfficeKit* pThis, pLib->mpCallbackData = pData; } -static int lo_getViews(LibreOfficeKit* /*pThis*/) -{ - return SfxLokHelper::getViews(); -} - static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const char* pFormat, const char* pFilterOptions) { LibLODocument_Impl* pDocument = static_cast(pThis); @@ -1077,6 +1071,13 @@ static int doc_getView(LibreOfficeKitDocument* /*pThis*/) return SfxLokHelper::getView(); } +static int doc_getViews(LibreOfficeKitDocument* /*pThis*/) +{ + SolarMutexGuard aGuard; + + return SfxLokHelper::getViews(); +} + static char* lo_getError (LibreOfficeKit *pThis) { LibLibreOffice_Impl* pLib = static_cast(pThis); diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 18f4b3edc624..fc025aed5b15 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -54,9 +54,6 @@ struct _LibreOfficeKitClass void (*registerCallback) (LibreOfficeKit* pThis, LibreOfficeKitCallback pCallback, void* pData); - - /// @see lok::Office::getViews(). - int (*getViews) (LibreOfficeKit* pThis); #endif }; @@ -174,6 +171,8 @@ struct _LibreOfficeKitDocumentClass void (*setView) (LibreOfficeKitDocument* pThis, int nId); /// @see lok::Document::getView(). int (*getView) (LibreOfficeKitDocument* pThis); + /// @see lok::Document::getViews(). + int (*getViews) (LibreOfficeKitDocument* pThis); #endif // LOK_USE_UNSTABLE_API }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index f5821b71191a..45ace9dfff04 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -294,6 +294,14 @@ public: { return mpDoc->pClass->getView(mpDoc); } + + /** + * Get number of views of this document. + */ + inline int getViews() + { + return mpDoc->pClass->getViews(mpDoc); + } #endif // LOK_USE_UNSTABLE_API }; @@ -340,16 +348,6 @@ public: { return mpThis->pClass->getError(mpThis); } - -#ifdef LOK_USE_UNSTABLE_API - /** - * Get number of total views. - */ - inline int getViews() - { - return mpThis->pClass->getViews(mpThis); - } -#endif }; /// Factory method to create a lok::Office instance. diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 50516227e992..99f2076eeea1 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -25,9 +25,8 @@ public: static void setView(size_t nId); /// Get the currently active view. static size_t getView(); - - /// Total number of view shells. - static int getViews(); + /// Get the number of views of the current object shell. + static size_t getViews(); }; #endif diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 0beb06ddd956..646715ef226f 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -62,10 +62,19 @@ size_t SfxLokHelper::getView() return 0; } -int SfxLokHelper::getViews() +size_t SfxLokHelper::getViews() { + size_t nRet = 0; + + SfxObjectShell* pObjectShell = SfxViewFrame::Current()->GetObjectShell(); SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); - return rViewArr.size(); + for (size_t i = 0; i < rViewArr.size(); ++i) + { + if (rViewArr[i]->GetObjectShell() == pObjectShell) + ++nRet; + } + + return nRet; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- 2.12.0