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