Blame SOURCES/0142-LOK-make-getViews-be-a-member-function-of-Document.patch

135360
From da8b89db49d0dfcef0ae0052bb8ab9d77a509dfb Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Wed, 16 Sep 2015 14:14:04 +0200
135360
Subject: [PATCH 142/398] LOK: make getViews() be a member function of Document
135360
135360
Just to be consistent, as all other view-related member functions are
135360
there, too.
135360
135360
No real impact, as only the unit test uses this so far, and it always
135360
works with a single document.
135360
135360
Change-Id: I46f1ed8265ab95017986ab45c1b510e961192241
135360
(cherry picked from commit a04b31c9facb08a8e38b79480b9a73bd2693cb9e)
135360
---
135360
 desktop/qa/desktop_lib/test_desktop_lib.cxx |  6 +++---
135360
 desktop/source/lib/init.cxx                 | 17 +++++++++--------
135360
 include/LibreOfficeKit/LibreOfficeKit.h     |  5 ++---
135360
 include/LibreOfficeKit/LibreOfficeKit.hxx   | 18 ++++++++----------
135360
 include/sfx2/lokhelper.hxx                  |  5 ++---
135360
 sfx2/source/view/lokhelper.cxx              | 13 +++++++++++--
135360
 6 files changed, 35 insertions(+), 29 deletions(-)
135360
135360
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
index 7ad81278d64a..0cd88cefffa0 100644
135360
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
@@ -134,10 +134,10 @@ void DesktopLOKTest::testGetFonts()
135360
 void DesktopLOKTest::testCreateView()
135360
 {
135360
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
135360
-    CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
135360
+    CPPUNIT_ASSERT_EQUAL(1, pDocument->m_pDocumentClass->getViews(pDocument));
135360
 
135360
     int nId = pDocument->m_pDocumentClass->createView(pDocument);
135360
-    CPPUNIT_ASSERT_EQUAL(2, SfxLokHelper::getViews());
135360
+    CPPUNIT_ASSERT_EQUAL(2, pDocument->m_pDocumentClass->getViews(pDocument));
135360
 
135360
     // Make sure the created view is the active one, then switch to the old
135360
     // one.
135360
@@ -146,7 +146,7 @@ void DesktopLOKTest::testCreateView()
135360
     CPPUNIT_ASSERT_EQUAL(0, pDocument->m_pDocumentClass->getView(pDocument));
135360
 
135360
     pDocument->m_pDocumentClass->destroyView(pDocument, nId);
135360
-    CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
135360
+    CPPUNIT_ASSERT_EQUAL(1, pDocument->m_pDocumentClass->getViews(pDocument));
135360
     closeDoc();
135360
 }
135360
 
135360
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
135360
index fa99038860cd..617c94638cde 100644
135360
--- a/desktop/source/lib/init.cxx
135360
+++ b/desktop/source/lib/init.cxx
135360
@@ -254,6 +254,7 @@ static int doc_createView(LibreOfficeKitDocument* pThis);
135360
 static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId);
135360
 static void doc_setView(LibreOfficeKitDocument* pThis, int nId);
135360
 static int doc_getView(LibreOfficeKitDocument* pThis);
135360
+static int doc_getViews(LibreOfficeKitDocument* pThis);
135360
 
135360
 LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) :
135360
     mxComponent( xComponent )
135360
@@ -289,6 +290,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference 
135360
         m_pDocumentClass->destroyView = doc_destroyView;
135360
         m_pDocumentClass->setView = doc_setView;
135360
         m_pDocumentClass->getView = doc_getView;
135360
+        m_pDocumentClass->getViews = doc_getViews;
135360
 
135360
         gDocumentClass = m_pDocumentClass;
135360
     }
135360
@@ -316,8 +318,6 @@ 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
     OUString maLastExceptionMsg;
135360
@@ -340,7 +340,6 @@ 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
@@ -458,11 +457,6 @@ 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
@@ -1077,6 +1071,13 @@ static int doc_getView(LibreOfficeKitDocument* /*pThis*/)
135360
     return SfxLokHelper::getView();
135360
 }
135360
 
135360
+static int doc_getViews(LibreOfficeKitDocument* /*pThis*/)
135360
+{
135360
+    SolarMutexGuard aGuard;
135360
+
135360
+    return SfxLokHelper::getViews();
135360
+}
135360
+
135360
 static char* lo_getError (LibreOfficeKit *pThis)
135360
 {
135360
     LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
135360
index 18f4b3edc624..fc025aed5b15 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
135360
@@ -54,9 +54,6 @@ 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
@@ -174,6 +171,8 @@ struct _LibreOfficeKitDocumentClass
135360
     void (*setView) (LibreOfficeKitDocument* pThis, int nId);
135360
     /// @see lok::Document::getView().
135360
     int (*getView) (LibreOfficeKitDocument* pThis);
135360
+    /// @see lok::Document::getViews().
135360
+    int (*getViews) (LibreOfficeKitDocument* pThis);
135360
 #endif // LOK_USE_UNSTABLE_API
135360
 };
135360
 
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
index f5821b71191a..45ace9dfff04 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
@@ -294,6 +294,14 @@ public:
135360
     {
135360
         return mpDoc->pClass->getView(mpDoc);
135360
     }
135360
+
135360
+    /**
135360
+     * Get number of views of this document.
135360
+     */
135360
+    inline int getViews()
135360
+    {
135360
+        return mpDoc->pClass->getViews(mpDoc);
135360
+    }
135360
 #endif // LOK_USE_UNSTABLE_API
135360
 };
135360
 
135360
@@ -340,16 +348,6 @@ 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 50516227e992..99f2076eeea1 100644
135360
--- a/include/sfx2/lokhelper.hxx
135360
+++ b/include/sfx2/lokhelper.hxx
135360
@@ -25,9 +25,8 @@ public:
135360
     static void setView(size_t nId);
135360
     /// Get the currently active view.
135360
     static size_t getView();
135360
-
135360
-    /// Total number of view shells.
135360
-    static int getViews();
135360
+    /// Get the number of views of the current object shell.
135360
+    static size_t getViews();
135360
 };
135360
 
135360
 #endif
135360
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
135360
index 0beb06ddd956..646715ef226f 100644
135360
--- a/sfx2/source/view/lokhelper.cxx
135360
+++ b/sfx2/source/view/lokhelper.cxx
135360
@@ -62,10 +62,19 @@ size_t SfxLokHelper::getView()
135360
     return 0;
135360
 }
135360
 
135360
-int SfxLokHelper::getViews()
135360
+size_t SfxLokHelper::getViews()
135360
 {
135360
+    size_t nRet = 0;
135360
+
135360
+    SfxObjectShell* pObjectShell = SfxViewFrame::Current()->GetObjectShell();
135360
     SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
135360
-    return rViewArr.size();
135360
+    for (size_t i = 0; i < rViewArr.size(); ++i)
135360
+    {
135360
+        if (rViewArr[i]->GetObjectShell() == pObjectShell)
135360
+            ++nRet;
135360
+    }
135360
+
135360
+    return nRet;
135360
 }
135360
 
135360
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
135360
-- 
135360
2.12.0
135360