From 27ebd2b9c14a691889e6c7332024feab7c723d49 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 16 Sep 2015 09:30:41 +0200 Subject: [PATCH 139/398] lok::Document: add get/setView() Change-Id: Ic3bce8f01d7e048e853c063c4bce1255845c60d0 (cherry picked from commit 46588c42a546d4517b773853856b9c8f8c2e5ece) --- desktop/qa/desktop_lib/test_desktop_lib.cxx | 6 ++++++ desktop/source/lib/init.cxx | 18 ++++++++++++++++++ include/LibreOfficeKit/LibreOfficeKit.h | 4 ++++ include/LibreOfficeKit/LibreOfficeKit.hxx | 20 +++++++++++++++++++- include/sfx2/lokhelper.hxx | 4 ++++ sfx2/source/view/lokhelper.cxx | 24 ++++++++++++++++++++++++ 6 files changed, 75 insertions(+), 1 deletion(-) diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 6baaa32239c9..7ad81278d64a 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -139,6 +139,12 @@ void DesktopLOKTest::testCreateView() int nId = pDocument->m_pDocumentClass->createView(pDocument); CPPUNIT_ASSERT_EQUAL(2, SfxLokHelper::getViews()); + // Make sure the created view is the active one, then switch to the old + // one. + CPPUNIT_ASSERT_EQUAL(1, pDocument->m_pDocumentClass->getView(pDocument)); + pDocument->m_pDocumentClass->setView(pDocument, 0); + CPPUNIT_ASSERT_EQUAL(0, pDocument->m_pDocumentClass->getView(pDocument)); + pDocument->m_pDocumentClass->destroyView(pDocument, nId); CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews()); closeDoc(); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 3b1286e5944d..d76de5e5bb3c 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -252,6 +252,8 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo 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); LibLODocument_Impl::LibLODocument_Impl(const uno::Reference &xComponent) : mxComponent( xComponent ) @@ -285,6 +287,8 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference createView = doc_createView; m_pDocumentClass->destroyView = doc_destroyView; + m_pDocumentClass->setView = doc_setView; + m_pDocumentClass->getView = doc_getView; gDocumentClass = m_pDocumentClass; } @@ -1067,6 +1071,20 @@ static void doc_destroyView(LibreOfficeKitDocument* /*pThis*/, int nId) SfxLokHelper::destroyView(nId); } +static void doc_setView(LibreOfficeKitDocument* /*pThis*/, int nId) +{ + SolarMutexGuard aGuard; + + SfxLokHelper::setView(nId); +} + +static int doc_getView(LibreOfficeKitDocument* /*pThis*/) +{ + SolarMutexGuard aGuard; + + return SfxLokHelper::getView(); +} + 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 7f41d13ff393..18f4b3edc624 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -170,6 +170,10 @@ struct _LibreOfficeKitDocumentClass int (*createView) (LibreOfficeKitDocument* pThis); /// @see lok::Document::destroyView(). void (*destroyView) (LibreOfficeKitDocument* pThis, int nId); + /// @see lok::Document::setView(). + void (*setView) (LibreOfficeKitDocument* pThis, int nId); + /// @see lok::Document::getView(). + int (*getView) (LibreOfficeKitDocument* pThis); #endif // LOK_USE_UNSTABLE_API }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 3e1a0ac20b07..f5821b71191a 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -269,13 +269,31 @@ public: } /** - * Destroy a view of an existring document. + * Destroy a view of an existing document. * @param nId a view ID, returned by createView(). */ void destroyView(int nId) { mpDoc->pClass->destroyView(mpDoc, nId); } + + /** + * Set an existing view of an existing document as current. + * @param nId a view ID, returned by createView(). + */ + void setView(int nId) + { + mpDoc->pClass->setView(mpDoc, nId); + } + + /** + * Get the current view. + * @return a view ID, previously returned by createView(). + */ + int getView() + { + return mpDoc->pClass->getView(mpDoc); + } #endif // LOK_USE_UNSTABLE_API }; diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index b57cb7d75b23..a05cd5d4b210 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -21,6 +21,10 @@ public: static int createView(SfxViewShell* pViewShell); /// Destroy a view shell from the global shell list. static void destroyView(size_t nId); + /// Set a view shell as current one. + static void setView(size_t nId); + /// Get the currently active view. + static size_t getView(); /// Total number of view shells. static int getViews(); diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 557478a78ae6..0aea6db9c24e 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -38,6 +38,30 @@ void SfxLokHelper::destroyView(size_t nId) pViewFrame->Exec_Impl(aRequest); } +void SfxLokHelper::setView(size_t nId) +{ + SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); + if (nId > rViewArr.size() - 1) + return; + + SfxViewShell* pViewShell = rViewArr[nId]; + if (SfxViewFrame* pViewFrame = pViewShell->GetViewFrame()) + pViewFrame->GetWindow().GrabFocus(); +} + +size_t SfxLokHelper::getView() +{ + SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); + SfxViewFrame* pViewFrame = SfxViewFrame::Current(); + for (size_t i = 0; i < rViewArr.size(); ++i) + { + if (rViewArr[i]->GetViewFrame() == pViewFrame) + return i; + } + assert(false); + return 0; +} + int SfxLokHelper::getViews() { SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); -- 2.12.0