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