Blob Blame History Raw
From cb4dc8447179758aa6e8330fdff7c67b72c9b2da Mon Sep 17 00:00:00 2001
From: Pranav Kant <pranavk@gnome.org>
Date: Wed, 10 Jun 2015 16:10:19 +0530
Subject: [PATCH 041/398] lokdocview: Create LOK context inside of
 lok_doc_view_new

Change-Id: I675192d6bd6d10e6c7974a5de6f488f9a087ac32
(cherry picked from commit 7a9dc7fd35168e1f44fb0aa23c984f90163db621)
---
 include/LibreOfficeKit/LibreOfficeKitGtk.h          |  2 +-
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 15 ++++-----------
 libreofficekit/source/gtk/lokdocview.cxx            | 14 ++++++++++----
 3 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 24c577e6e003..bdd2e9ab90e3 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -46,7 +46,7 @@ struct _LOKDocViewClass
 
 GType                          lok_doc_view_get_type               (void) G_GNUC_CONST;
 
-GtkWidget*                     lok_doc_view_new                    (LibreOfficeKit* pOffice );
+GtkWidget*                     lok_doc_view_new                    (const char* pPath);
 
 gboolean                       lok_doc_view_open_document          (LOKDocView* pDocView,
                                                                     char* pPath);
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index c8b47f7c7142..4f74583f52b3 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -19,7 +19,6 @@
 #include <gtk/gtk.h>
 
 #include <LibreOfficeKit/LibreOfficeKitGtk.h>
-#include <LibreOfficeKit/LibreOfficeKitInit.h>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
 #ifndef g_info
@@ -53,8 +52,6 @@ GtkWidget* pFindbar;
 GtkWidget* pFindbarEntry;
 GtkWidget* pFindbarLabel;
 
-static LibreOfficeKit* pOffice;
-
 static void lcl_registerToolItem(GtkToolItem* pItem, const std::string& rName)
 {
     g_aToolItemCommandNames[pItem] = rName;
@@ -361,10 +358,6 @@ int main( int argc, char* argv[] )
         return 1;
     }
 
-    pOffice = lok_init( argv[1] );
-    if ( pOffice == NULL )
-        return 1;
-
     gtk_init( &argc, &argv );
 
     GtkWidget *pWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL );
@@ -469,7 +462,9 @@ int main( int argc, char* argv[] )
     gtk_box_pack_end(GTK_BOX(pVBox), pFindbar, FALSE, FALSE, 0);
 
     // Docview
-    pDocView = lok_doc_view_new( pOffice );
+    pDocView = lok_doc_view_new(argv[1]);
+    if (pDocView == NULL)
+        g_error ("Error while creating LOKDocView widget");
     g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
     g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL);
     g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL);
@@ -492,7 +487,7 @@ int main( int argc, char* argv[] )
 
     int bOpened = lok_doc_view_open_document( LOK_DOC_VIEW(pDocView), argv[2] );
     if (!bOpened)
-        g_error("main: lok_doc_view_open_document() failed with '%s'", pOffice->pClass->getError(pOffice));
+        g_error("main: lok_doc_view_open_document() failed");
     assert(lok_doc_view_get_document(LOK_DOC_VIEW(pDocView)));
 
     // GtkComboBox requires gtk 2.24 or later
@@ -507,8 +502,6 @@ int main( int argc, char* argv[] )
 
     gtk_main();
 
-    pOffice->pClass->destroy( pOffice );
-
     return 0;
 }
 
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index c035d0dcad55..d45ab2db4be5 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -18,6 +18,7 @@
 #include <com/sun/star/awt/Key.hpp>
 #define LOK_USE_UNSTABLE_API
 #include <LibreOfficeKit/LibreOfficeKit.h>
+#include <LibreOfficeKit/LibreOfficeKitInit.h>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <LibreOfficeKit/LibreOfficeKitGtk.h>
 #include <rsc/rsc-vcl-shared-types.hxx>
@@ -308,7 +309,10 @@ LOKDocView_Impl::~LOKDocView_Impl()
 {
     if (m_pDocument)
         m_pDocument->pClass->destroy(m_pDocument);
+    if (m_pOffice)
+        m_pOffice->pClass->destroy(m_pOffice);
     m_pDocument = 0;
+    m_pOffice = 0;
 }
 
 void LOKDocView_Impl::destroy(LOKDocView* pDocView, gpointer /*pData*/)
@@ -1177,14 +1181,16 @@ static void lok_doc_view_init (LOKDocView* pDocView)
 
 /**
  * lok_doc_view_new:
- * @pOffice: The LibreOfficeKit context.
+ * @pPath: LibreOffice install path.
  *
  * Returns: The #LOKDocView widget instance.
  */
-SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new( LibreOfficeKit* pOffice )
+SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new(const char* pPath)
 {
-    LOKDocView* pDocView = LOK_DOC_VIEW(gtk_type_new(lok_doc_view_get_type()));
-    pDocView->m_pImpl->m_pOffice = pOffice;
+    LOKDocView* pDocView = LOK_DOC_VIEW(g_object_new(LOK_TYPE_DOC_VIEW, NULL));
+    pDocView->m_pImpl->m_pOffice = lok_init (pPath);
+    if (pDocView->m_pImpl->m_pOffice == NULL)
+        return NULL;
     return GTK_WIDGET( pDocView );
 }
 
-- 
2.12.0