135360
From 7da9e9d07f129c274f1d29db92be237a3e6f2e7f Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Tue, 15 Sep 2015 09:31:49 +0200
135360
Subject: [PATCH 123/398] lok::Document: add destroyView()
135360
135360
Change-Id: Id9e92593217541b4123e95279019cec3c958056c
135360
(cherry picked from commit 10a0cad9d6990abac507899a34fbcdeb466187f7)
135360
---
135360
 desktop/qa/desktop_lib/test_desktop_lib.cxx |  5 ++++-
135360
 desktop/source/lib/init.cxx                 |  9 +++++++++
135360
 include/LibreOfficeKit/LibreOfficeKit.h     |  2 ++
135360
 include/LibreOfficeKit/LibreOfficeKit.hxx   |  9 +++++++++
135360
 include/sfx2/lokhelper.hxx                  |  2 ++
135360
 sfx2/source/view/lokhelper.cxx              | 12 ++++++++++++
135360
 6 files changed, 38 insertions(+), 1 deletion(-)
135360
135360
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
index 8642f4491f9f..6baaa32239c9 100644
135360
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
@@ -136,8 +136,11 @@ void DesktopLOKTest::testCreateView()
135360
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
135360
     CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
135360
 
135360
-    pDocument->m_pDocumentClass->createView(pDocument);
135360
+    int nId = pDocument->m_pDocumentClass->createView(pDocument);
135360
     CPPUNIT_ASSERT_EQUAL(2, SfxLokHelper::getViews());
135360
+
135360
+    pDocument->m_pDocumentClass->destroyView(pDocument, nId);
135360
+    CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
135360
     closeDoc();
135360
 }
135360
 
135360
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
135360
index 3554d46573bf..3b1286e5944d 100644
135360
--- a/desktop/source/lib/init.cxx
135360
+++ b/desktop/source/lib/init.cxx
135360
@@ -251,6 +251,7 @@ static void doc_resetSelection (LibreOfficeKitDocument* pThis);
135360
 static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand);
135360
 
135360
 static int doc_createView(LibreOfficeKitDocument* pThis);
135360
+static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId);
135360
 
135360
 LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) :
135360
     mxComponent( xComponent )
135360
@@ -283,6 +284,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference 
135360
         m_pDocumentClass->getCommandValues = doc_getCommandValues;
135360
 
135360
         m_pDocumentClass->createView = doc_createView;
135360
+        m_pDocumentClass->destroyView = doc_destroyView;
135360
 
135360
         gDocumentClass = m_pDocumentClass;
135360
     }
135360
@@ -1058,6 +1060,13 @@ static int doc_createView(LibreOfficeKitDocument* pThis)
135360
     return SfxLokHelper::createView(pViewShell);
135360
 }
135360
 
135360
+static void doc_destroyView(LibreOfficeKitDocument* /*pThis*/, int nId)
135360
+{
135360
+    SolarMutexGuard aGuard;
135360
+
135360
+    SfxLokHelper::destroyView(nId);
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 b59d3f8c9f5d..7f41d13ff393 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
135360
@@ -168,6 +168,8 @@ struct _LibreOfficeKitDocumentClass
135360
 
135360
     /// @see lok::Document::createView().
135360
     int (*createView) (LibreOfficeKitDocument* pThis);
135360
+    /// @see lok::Document::destroyView().
135360
+    void (*destroyView) (LibreOfficeKitDocument* pThis, int nId);
135360
 #endif // LOK_USE_UNSTABLE_API
135360
 };
135360
 
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
index 32f190227719..3e1a0ac20b07 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
@@ -267,6 +267,15 @@ public:
135360
     {
135360
         return mpDoc->pClass->createView(mpDoc);
135360
     }
135360
+
135360
+    /**
135360
+     * Destroy a view of an existring document.
135360
+     * @param nId a view ID, returned by createView().
135360
+     */
135360
+    void destroyView(int nId)
135360
+    {
135360
+        mpDoc->pClass->destroyView(mpDoc, nId);
135360
+    }
135360
 #endif // LOK_USE_UNSTABLE_API
135360
 };
135360
 
135360
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
135360
index bc3f43010c41..9430cd5665d8 100644
135360
--- a/include/sfx2/lokhelper.hxx
135360
+++ b/include/sfx2/lokhelper.hxx
135360
@@ -16,6 +16,8 @@ class SFX2_DLLPUBLIC SfxLokHelper
135360
 public:
135360
     /// Create a new view shell for pViewShell's object shell.
135360
     static int createView(SfxViewShell* pViewShell);
135360
+    /// Destroy a view shell from the global shell list.
135360
+    static void destroyView(size_t nId);
135360
 
135360
     /// Total number of view shells.
135360
     static int getViews();
135360
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
135360
index 1bb43d0ea02f..557478a78ae6 100644
135360
--- a/sfx2/source/view/lokhelper.cxx
135360
+++ b/sfx2/source/view/lokhelper.cxx
135360
@@ -26,6 +26,18 @@ int SfxLokHelper::createView(SfxViewShell* pViewShell)
135360
     return rViewArr.size() - 1;
135360
 }
135360
 
135360
+void SfxLokHelper::destroyView(size_t nId)
135360
+{
135360
+    SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
135360
+    if (nId > rViewArr.size() - 1)
135360
+        return;
135360
+
135360
+    SfxViewShell* pViewShell = rViewArr[nId];
135360
+    SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
135360
+    SfxRequest aRequest(pViewFrame, SID_CLOSEWIN);
135360
+    pViewFrame->Exec_Impl(aRequest);
135360
+}
135360
+
135360
 int SfxLokHelper::getViews()
135360
 {
135360
     SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
135360
-- 
135360
2.12.0
135360