summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-09-16 09:30:41 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-10-06 16:24:11 +0200
commit470db78ef09351db67fc22c70c5dd4b98bc43a14 (patch)
tree4846ceb384427d7acc2fda4fe74f5ed89eb42477
parenta0b7695a88ee54595880582dd0a17a0a38bb9a78 (diff)
lok::Document: add get/setView()
Change-Id: Ic3bce8f01d7e048e853c063c4bce1255845c60d0 (cherry picked from commit 46588c42a546d4517b773853856b9c8f8c2e5ece)
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx6
-rw-r--r--desktop/source/lib/init.cxx18
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h4
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx20
-rw-r--r--include/sfx2/lokhelper.hxx4
-rw-r--r--sfx2/source/view/lokhelper.cxx24
6 files changed, 75 insertions, 1 deletions
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 75fbafaf69fc..c56e8d0fde96 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 <css::lang::XComponent> &xComponent) :
mxComponent( xComponent )
@@ -285,6 +287,8 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->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<LibLibreOffice_Impl*>(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();