From f0e5649a3d463f89903ad337a5f33f3a33e27478 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 14 Sep 2015 15:43:17 +0200 Subject: [PATCH 121/398] lok::Office: add getViews() Change-Id: Iabfb0f2a19106dc4a6bdae45f9e85d76c68a973e (cherry picked from commit 2e523afe61f76d9b065a771e558683afb701b93b) --- desktop/qa/desktop_lib/test_desktop_lib.cxx | 13 +++++++++++++ desktop/source/lib/init.cxx | 7 +++++++ include/LibreOfficeKit/LibreOfficeKit.h | 3 +++ include/LibreOfficeKit/LibreOfficeKit.hxx | 10 ++++++++++ include/sfx2/lokhelper.hxx | 3 +++ sfx2/source/view/lokhelper.cxx | 6 ++++++ 6 files changed, 42 insertions(+) diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index a08961403aac..d5616d566f6a 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "../../inc/lib/init.hxx" @@ -50,6 +51,7 @@ public: void runAllTests(); void testGetStyles(); void testGetFonts(); + void testCreateView(); CPPUNIT_TEST_SUITE(DesktopLOKTest); CPPUNIT_TEST(runAllTests); @@ -83,6 +85,7 @@ void DesktopLOKTest::runAllTests() { testGetStyles(); testGetFonts(); + testCreateView(); } void DesktopLOKTest::testGetStyles() @@ -134,6 +137,16 @@ void DesktopLOKTest::testGetFonts() closeDoc(); } +void DesktopLOKTest::testCreateView() +{ + LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); + CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews()); + + pDocument->m_pDocumentClass->createView(pDocument); + CPPUNIT_ASSERT_EQUAL(2, SfxLokHelper::getViews()); + closeDoc(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index ea5de4df1a5c..3554d46573bf 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -310,6 +310,7 @@ 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 { @@ -333,6 +334,7 @@ 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; } @@ -450,6 +452,11 @@ 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); diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index eae35374e032..b59d3f8c9f5d 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -54,6 +54,9 @@ struct _LibreOfficeKitClass void (*registerCallback) (LibreOfficeKit* pThis, LibreOfficeKitCallback pCallback, void* pData); + + /// @see lok::Office::getViews(). + int (*getViews) (LibreOfficeKit* pThis); #endif }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 1a8b002ecba6..32f190227719 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -313,6 +313,16 @@ 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 d439bcedce19..bc3f43010c41 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -16,6 +16,9 @@ class SFX2_DLLPUBLIC SfxLokHelper public: /// Create a new view shell for pViewShell's object shell. static int createView(SfxViewShell* pViewShell); + + /// Total number of view shells. + static int getViews(); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 4f500e0388ef..1bb43d0ea02f 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -26,4 +26,10 @@ int SfxLokHelper::createView(SfxViewShell* pViewShell) return rViewArr.size() - 1; } +int SfxLokHelper::getViews() +{ + SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); + return rViewArr.size(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- 2.12.0