summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-09-16 12:38:31 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-09-16 14:48:23 +0200
commitdcc92a7cb5aa1faa711c8da7f7d8ecee0a192c25 (patch)
treef6ed2e55dd7dad168af83e266dc53acbe2926af9
parent9035f00ede7925eb699864d17baf7c897a8c7e53 (diff)
sfx2: add SfxLokHelper::getViewIds
and also expose it in the LOK API. This way clients don't have to keep track of what views they created / destroyed, they can also get an up to date list with this method. Change-Id: Ibaee42c545803e04a31e7c13ab6ec370b99465c4
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx6
-rw-r--r--desktop/source/lib/init.cxx8
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h5
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx16
-rw-r--r--include/sfx2/lokhelper.hxx2
-rw-r--r--sfx2/source/view/lokhelper.cxx14
6 files changed, 51 insertions, 0 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 8f3807ee79d5..a7e24fcd7255 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -316,6 +316,12 @@ void DesktopLOKTest::testCreateView()
int nId1 = pDocument->m_pDocumentClass->createView(pDocument);
CPPUNIT_ASSERT_EQUAL(2, pDocument->m_pDocumentClass->getViewsCount(pDocument));
+ // Test getViewIds().
+ std::vector<int> aViewIds(2);
+ CPPUNIT_ASSERT(pDocument->m_pDocumentClass->getViewIds(pDocument, aViewIds.data(), aViewIds.size()));
+ CPPUNIT_ASSERT_EQUAL(nId0, aViewIds[0]);
+ CPPUNIT_ASSERT_EQUAL(nId1, aViewIds[1]);
+
// Make sure the created view is the active one, then switch to the old
// one.
CPPUNIT_ASSERT_EQUAL(nId1, pDocument->m_pDocumentClass->getView(pDocument));
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 967d73073e07..39e6c6599690 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -438,6 +438,7 @@ 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_getViewsCount(LibreOfficeKitDocument* pThis);
+static bool doc_getViewIds(LibreOfficeKitDocument* pThis, int* pArray, size_t nSize);
static unsigned char* doc_renderFont(LibreOfficeKitDocument* pThis,
const char *pFontName,
int* pFontWidth,
@@ -485,6 +486,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->setView = doc_setView;
m_pDocumentClass->getView = doc_getView;
m_pDocumentClass->getViewsCount = doc_getViewsCount;
+ m_pDocumentClass->getViewIds = doc_getViewIds;
m_pDocumentClass->renderFont = doc_renderFont;
m_pDocumentClass->getPartHash = doc_getPartHash;
@@ -2313,6 +2315,12 @@ static int doc_getViewsCount(LibreOfficeKitDocument* /*pThis*/)
return SfxLokHelper::getViewsCount();
}
+static bool doc_getViewIds(LibreOfficeKitDocument* /*pThis*/, int* pArray, size_t nSize)
+{
+ SolarMutexGuard aGuard;
+ return SfxLokHelper::getViewIds(pArray, nSize);
+}
+
unsigned char* doc_renderFont(LibreOfficeKitDocument* /*pThis*/,
const char* pFontName,
int* pFontWidth,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index a0ed81947280..c97655f94f8e 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -244,6 +244,11 @@ struct _LibreOfficeKitDocumentClass
const int nTileWidth,
const int nTileHeight);
+ /// @see lok::Document::getViewIds().
+ bool (*getViewIds) (LibreOfficeKitDocument* pThis,
+ int* pArray,
+ size_t nSize);
+
#endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
};
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index cd3488505673..7c90df53c2f2 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -435,6 +435,22 @@ public:
nTileWidth, nTileHeight);
}
+ /**
+ * Returns the viewID for each existing view. Since viewIDs are not reused,
+ * viewIDs are not the same as the index of the view in the view array over
+ * time. Use getViewsCount() to know the minimal nSize that's large enough.
+ *
+ * @param pArray the array to write the viewIDs into
+ * @param nSize the size of pArray
+ * @returns true if pArray was large enough and result is written, false
+ * otherwise.
+ */
+ inline bool getViewIds(int* pArray,
+ size_t nSize)
+ {
+ return mpDoc->pClass->getViewIds(mpDoc, pArray, nSize);
+ }
+
#endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
};
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 7460377fd3ba..3179ee203c0f 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -29,6 +29,8 @@ public:
static int getView(SfxViewShell* pViewShell = nullptr);
/// Get the number of views of the current object shell.
static std::size_t getViewsCount();
+ /// Get viewIds of all existing views.
+ static bool getViewIds(int* pArray, size_t nSize);
/// Invoke the LOK callback of all views except pThisView, with a payload of rKey-rPayload.
static void notifyOtherViews(SfxViewShell* pThisView, int nType, const OString& rKey, const OString& rPayload);
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 5769127c299d..619e48e61d22 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -94,6 +94,20 @@ std::size_t SfxLokHelper::getViewsCount()
return rViewArr.size();
}
+bool SfxLokHelper::getViewIds(int* pArray, size_t nSize)
+{
+ SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
+ if (rViewArr.size() > nSize)
+ return false;
+
+ for (std::size_t i = 0; i < rViewArr.size(); ++i)
+ {
+ SfxViewShell* pViewShell = rViewArr[i];
+ pArray[i] = pViewShell->GetViewShellId();
+ }
+ return true;
+}
+
void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell* pOtherView, int nType, const OString& rKey, const OString& rPayload)
{
boost::property_tree::ptree aTree;