Blob Blame History Raw
From 7da9e9d07f129c274f1d29db92be237a3e6f2e7f Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.co.uk>
Date: Tue, 15 Sep 2015 09:31:49 +0200
Subject: [PATCH 123/398] lok::Document: add destroyView()

Change-Id: Id9e92593217541b4123e95279019cec3c958056c
(cherry picked from commit 10a0cad9d6990abac507899a34fbcdeb466187f7)
---
 desktop/qa/desktop_lib/test_desktop_lib.cxx |  5 ++++-
 desktop/source/lib/init.cxx                 |  9 +++++++++
 include/LibreOfficeKit/LibreOfficeKit.h     |  2 ++
 include/LibreOfficeKit/LibreOfficeKit.hxx   |  9 +++++++++
 include/sfx2/lokhelper.hxx                  |  2 ++
 sfx2/source/view/lokhelper.cxx              | 12 ++++++++++++
 6 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 8642f4491f9f..6baaa32239c9 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -136,8 +136,11 @@ void DesktopLOKTest::testCreateView()
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
     CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
 
-    pDocument->m_pDocumentClass->createView(pDocument);
+    int nId = pDocument->m_pDocumentClass->createView(pDocument);
     CPPUNIT_ASSERT_EQUAL(2, SfxLokHelper::getViews());
+
+    pDocument->m_pDocumentClass->destroyView(pDocument, nId);
+    CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
     closeDoc();
 }
 
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 3554d46573bf..3b1286e5944d 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -251,6 +251,7 @@ static void doc_resetSelection (LibreOfficeKitDocument* pThis);
 static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand);
 
 static int doc_createView(LibreOfficeKitDocument* pThis);
+static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId);
 
 LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) :
     mxComponent( xComponent )
@@ -283,6 +284,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
         m_pDocumentClass->getCommandValues = doc_getCommandValues;
 
         m_pDocumentClass->createView = doc_createView;
+        m_pDocumentClass->destroyView = doc_destroyView;
 
         gDocumentClass = m_pDocumentClass;
     }
@@ -1058,6 +1060,13 @@ static int doc_createView(LibreOfficeKitDocument* pThis)
     return SfxLokHelper::createView(pViewShell);
 }
 
+static void doc_destroyView(LibreOfficeKitDocument* /*pThis*/, int nId)
+{
+    SolarMutexGuard aGuard;
+
+    SfxLokHelper::destroyView(nId);
+}
+
 static char* lo_getError (LibreOfficeKit *pThis)
 {
     LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index b59d3f8c9f5d..7f41d13ff393 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -168,6 +168,8 @@ struct _LibreOfficeKitDocumentClass
 
     /// @see lok::Document::createView().
     int (*createView) (LibreOfficeKitDocument* pThis);
+    /// @see lok::Document::destroyView().
+    void (*destroyView) (LibreOfficeKitDocument* pThis, int nId);
 #endif // LOK_USE_UNSTABLE_API
 };
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 32f190227719..3e1a0ac20b07 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -267,6 +267,15 @@ public:
     {
         return mpDoc->pClass->createView(mpDoc);
     }
+
+    /**
+     * Destroy a view of an existring document.
+     * @param nId a view ID, returned by createView().
+     */
+    void destroyView(int nId)
+    {
+        mpDoc->pClass->destroyView(mpDoc, nId);
+    }
 #endif // LOK_USE_UNSTABLE_API
 };
 
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index bc3f43010c41..9430cd5665d8 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -16,6 +16,8 @@ class SFX2_DLLPUBLIC SfxLokHelper
 public:
     /// Create a new view shell for pViewShell's object shell.
     static int createView(SfxViewShell* pViewShell);
+    /// Destroy a view shell from the global shell list.
+    static void destroyView(size_t nId);
 
     /// Total number of view shells.
     static int getViews();
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 1bb43d0ea02f..557478a78ae6 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -26,6 +26,18 @@ int SfxLokHelper::createView(SfxViewShell* pViewShell)
     return rViewArr.size() - 1;
 }
 
+void SfxLokHelper::destroyView(size_t nId)
+{
+    SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
+    if (nId > rViewArr.size() - 1)
+        return;
+
+    SfxViewShell* pViewShell = rViewArr[nId];
+    SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
+    SfxRequest aRequest(pViewFrame, SID_CLOSEWIN);
+    pViewFrame->Exec_Impl(aRequest);
+}
+
 int SfxLokHelper::getViews()
 {
     SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
-- 
2.12.0