135360
From 4692ad2debc22ba83d79b6c13e22e694f33b5a03 Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Mon, 14 Sep 2015 14:36:56 +0200
135360
Subject: [PATCH 119/398] lok::Document: add createView()
135360
135360
Change-Id: Ic871ec41992b611b10958799b2dc12375a91efe4
135360
(cherry picked from commit 655c7877a0650b7bfd04a3294cdf92bc7ab94055)
135360
---
135360
 desktop/source/lib/init.cxx                         | 19 +++++++++++++++++++
135360
 include/LibreOfficeKit/LibreOfficeKit.h             |  3 +++
135360
 include/LibreOfficeKit/LibreOfficeKit.hxx           | 10 ++++++++++
135360
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 14 ++++++++++++++
135360
 4 files changed, 46 insertions(+)
135360
135360
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
135360
index 87471454b5d2..ea5de4df1a5c 100644
135360
--- a/desktop/source/lib/init.cxx
135360
+++ b/desktop/source/lib/init.cxx
135360
@@ -53,6 +53,7 @@
135360
 #include <sfx2/viewfrm.hxx>
135360
 #include <sfx2/msgpool.hxx>
135360
 #include <sfx2/dispatch.hxx>
135360
+#include <sfx2/lokhelper.hxx>
135360
 #include <svx/svxids.hrc>
135360
 #include <vcl/svapp.hxx>
135360
 #include <vcl/svpforlokit.hxx>
135360
@@ -249,6 +250,7 @@ static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
135360
 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
 
135360
 LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) :
135360
     mxComponent( xComponent )
135360
@@ -280,6 +282,8 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference 
135360
         m_pDocumentClass->resetSelection = doc_resetSelection;
135360
         m_pDocumentClass->getCommandValues = doc_getCommandValues;
135360
 
135360
+        m_pDocumentClass->createView = doc_createView;
135360
+
135360
         gDocumentClass = m_pDocumentClass;
135360
     }
135360
     pClass = m_pDocumentClass.get();
135360
@@ -1032,6 +1036,21 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
135360
     }
135360
 }
135360
 
135360
+static int doc_createView(LibreOfficeKitDocument* pThis)
135360
+{
135360
+    SolarMutexGuard aGuard;
135360
+
135360
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
135360
+    if (!pDoc)
135360
+    {
135360
+        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
135360
+        return -1;
135360
+    }
135360
+
135360
+    SfxViewShell* pViewShell = pDoc->getCurrentViewShell();
135360
+    return SfxLokHelper::createView(pViewShell);
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 8060f0e6ec7c..eae35374e032 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
135360
@@ -162,6 +162,9 @@ struct _LibreOfficeKitDocumentClass
135360
 
135360
     /// @see lok::Document:getStyles
135360
     char* (*getCommandValues) (LibreOfficeKitDocument* pThis, const char* pCommand);
135360
+
135360
+    /// @see lok::Document::createView().
135360
+    int (*createView) (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 44599948e659..1a8b002ecba6 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
@@ -257,6 +257,16 @@ public:
135360
     {
135360
         return mpDoc->pClass->getCommandValues(mpDoc, pCommand);
135360
     }
135360
+
135360
+    /**
135360
+     * Create a new view for an existing document.
135360
+     * By default a loaded document has 1 view.
135360
+     * @return the ID of the new view.
135360
+     */
135360
+    int createView()
135360
+    {
135360
+        return mpDoc->pClass->createView(mpDoc);
135360
+    }
135360
 #endif // LOK_USE_UNSTABLE_API
135360
 };
135360
 
135360
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
index ab33fc703731..60c5281974f4 100644
135360
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
@@ -147,6 +147,14 @@ static void toggleFindbar(GtkWidget* /*pButton*/, gpointer /*pItem*/)
135360
     }
135360
 }
135360
 
135360
+/// Calls lok::Document::createView().
135360
+static void createView(GtkWidget* /*pButton*/, gpointer /*pItem*/)
135360
+{
135360
+    LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
135360
+    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView);
135360
+    pDocument->pClass->createView(pDocument);
135360
+}
135360
+
135360
 /// Our GtkClipboardGetFunc implementation for HTML.
135360
 static void htmlGetFunc(GtkClipboard* /*pClipboard*/, GtkSelectionData* pSelectionData, guint /*info*/, gpointer pUserData)
135360
 {
135360
@@ -554,6 +562,12 @@ int main( int argc, char* argv[] )
135360
     gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pFindButton, -1);
135360
     g_signal_connect(G_OBJECT(pFindButton), "clicked", G_CALLBACK(toggleFindbar), NULL);
135360
 
135360
+    GtkToolItem* pNewViewButton = gtk_tool_button_new( NULL, NULL);
135360
+    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pNewViewButton), "view-continuous-symbolic");
135360
+    gtk_tool_item_set_tooltip_text(pNewViewButton, "New View");
135360
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pNewViewButton, -1);
135360
+    g_signal_connect(G_OBJECT(pNewViewButton), "clicked", G_CALLBACK(createView), NULL);
135360
+
135360
     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
135360
 
135360
     pBold = gtk_toggle_tool_button_new();
135360
-- 
135360
2.12.0
135360