135360
From f0e5649a3d463f89903ad337a5f33f3a33e27478 Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Mon, 14 Sep 2015 15:43:17 +0200
135360
Subject: [PATCH 121/398] lok::Office: add getViews()
135360
135360
Change-Id: Iabfb0f2a19106dc4a6bdae45f9e85d76c68a973e
135360
(cherry picked from commit 2e523afe61f76d9b065a771e558683afb701b93b)
135360
---
135360
 desktop/qa/desktop_lib/test_desktop_lib.cxx | 13 +++++++++++++
135360
 desktop/source/lib/init.cxx                 |  7 +++++++
135360
 include/LibreOfficeKit/LibreOfficeKit.h     |  3 +++
135360
 include/LibreOfficeKit/LibreOfficeKit.hxx   | 10 ++++++++++
135360
 include/sfx2/lokhelper.hxx                  |  3 +++
135360
 sfx2/source/view/lokhelper.cxx              |  6 ++++++
135360
 6 files changed, 42 insertions(+)
135360
135360
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
index a08961403aac..d5616d566f6a 100644
135360
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
@@ -14,6 +14,7 @@
135360
 #include <boost/property_tree/json_parser.hpp>
135360
 #include <comphelper/processfactory.hxx>
135360
 #include <sfx2/objsh.hxx>
135360
+#include <sfx2/lokhelper.hxx>
135360
 #include <test/unoapi_test.hxx>
135360
 
135360
 #include "../../inc/lib/init.hxx"
135360
@@ -50,6 +51,7 @@ public:
135360
     void runAllTests();
135360
     void testGetStyles();
135360
     void testGetFonts();
135360
+    void testCreateView();
135360
 
135360
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
135360
     CPPUNIT_TEST(runAllTests);
135360
@@ -83,6 +85,7 @@ void DesktopLOKTest::runAllTests()
135360
 {
135360
     testGetStyles();
135360
     testGetFonts();
135360
+    testCreateView();
135360
 }
135360
 
135360
 void DesktopLOKTest::testGetStyles()
135360
@@ -134,6 +137,16 @@ void DesktopLOKTest::testGetFonts()
135360
     closeDoc();
135360
 }
135360
 
135360
+void DesktopLOKTest::testCreateView()
135360
+{
135360
+    LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
135360
+    CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
135360
+
135360
+    pDocument->m_pDocumentClass->createView(pDocument);
135360
+    CPPUNIT_ASSERT_EQUAL(2, SfxLokHelper::getViews());
135360
+    closeDoc();
135360
+}
135360
+
135360
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
135360
 
135360
 CPPUNIT_PLUGIN_IMPLEMENT();
135360
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
135360
index ea5de4df1a5c..3554d46573bf 100644
135360
--- a/desktop/source/lib/init.cxx
135360
+++ b/desktop/source/lib/init.cxx
135360
@@ -310,6 +310,7 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions  (LibreOfficeKit* pThi
135360
 static void                    lo_registerCallback (LibreOfficeKit* pThis,
135360
                                                     LibreOfficeKitCallback pCallback,
135360
                                                     void* pData);
135360
+static int lo_getViews(LibreOfficeKit* pThis);
135360
 
135360
 struct LibLibreOffice_Impl : public _LibreOfficeKit
135360
 {
135360
@@ -333,6 +334,7 @@ struct LibLibreOffice_Impl : public _LibreOfficeKit
135360
             m_pOfficeClass->getError = lo_getError;
135360
             m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
135360
             m_pOfficeClass->registerCallback = lo_registerCallback;
135360
+            m_pOfficeClass->getViews = lo_getViews;
135360
 
135360
             gOfficeClass = m_pOfficeClass;
135360
         }
135360
@@ -450,6 +452,11 @@ static void lo_registerCallback (LibreOfficeKit* pThis,
135360
     pLib->mpCallbackData = pData;
135360
 }
135360
 
135360
+static int lo_getViews(LibreOfficeKit* /*pThis*/)
135360
+{
135360
+    return SfxLokHelper::getViews();
135360
+}
135360
+
135360
 static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const char* pFormat, const char* pFilterOptions)
135360
 {
135360
     LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
135360
index eae35374e032..b59d3f8c9f5d 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
135360
@@ -54,6 +54,9 @@ struct _LibreOfficeKitClass
135360
     void (*registerCallback) (LibreOfficeKit* pThis,
135360
                               LibreOfficeKitCallback pCallback,
135360
                               void* pData);
135360
+
135360
+    /// @see lok::Office::getViews().
135360
+    int (*getViews) (LibreOfficeKit* pThis);
135360
 #endif
135360
 };
135360
 
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
index 1a8b002ecba6..32f190227719 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
@@ -313,6 +313,16 @@ public:
135360
     {
135360
         return mpThis->pClass->getError(mpThis);
135360
     }
135360
+
135360
+#ifdef LOK_USE_UNSTABLE_API
135360
+    /**
135360
+     * Get number of total views.
135360
+     */
135360
+    inline int getViews()
135360
+    {
135360
+        return mpThis->pClass->getViews(mpThis);
135360
+    }
135360
+#endif
135360
 };
135360
 
135360
 /// Factory method to create a lok::Office instance.
135360
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
135360
index d439bcedce19..bc3f43010c41 100644
135360
--- a/include/sfx2/lokhelper.hxx
135360
+++ b/include/sfx2/lokhelper.hxx
135360
@@ -16,6 +16,9 @@ class SFX2_DLLPUBLIC SfxLokHelper
135360
 public:
135360
     /// Create a new view shell for pViewShell's object shell.
135360
     static int createView(SfxViewShell* pViewShell);
135360
+
135360
+    /// Total number of view shells.
135360
+    static int getViews();
135360
 };
135360
 
135360
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
135360
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
135360
index 4f500e0388ef..1bb43d0ea02f 100644
135360
--- a/sfx2/source/view/lokhelper.cxx
135360
+++ b/sfx2/source/view/lokhelper.cxx
135360
@@ -26,4 +26,10 @@ int SfxLokHelper::createView(SfxViewShell* pViewShell)
135360
     return rViewArr.size() - 1;
135360
 }
135360
 
135360
+int SfxLokHelper::getViews()
135360
+{
135360
+    SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
135360
+    return rViewArr.size();
135360
+}
135360
+
135360
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
135360
-- 
135360
2.12.0
135360