Blame SOURCES/0024-lokdocview-Modernise-LOKDocView-as-GObject.patch

135360
From 9d8fd399aa92d5bcfc11399f296ed2ffdd741286 Mon Sep 17 00:00:00 2001
135360
From: Pranav Kant <pranavk@gnome.org>
135360
Date: Sat, 6 Jun 2015 03:10:31 +0530
135360
Subject: [PATCH 024/398] lokdocview: Modernise LOKDocView as GObject
135360
135360
Change-Id: I3bbd07ce8163890f9b88567966622dd4fbe9d94d
135360
(cherry picked from commit c5f1f7ad2710914fdd6645dd8ce958c70d1d8381)
135360
---
135360
 include/LibreOfficeKit/LibreOfficeKitGtk.h | 63 ++++++++++---------
135360
 libreofficekit/source/gtk/lokdocview.cxx   | 97 +++++++++++++-----------------
135360
 2 files changed, 77 insertions(+), 83 deletions(-)
135360
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
135360
index 069c565435bb..747e45e531f9 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
135360
@@ -18,9 +18,13 @@
135360
 
135360
 G_BEGIN_DECLS
135360
 
135360
-#define LOK_DOC_VIEW(obj)          GTK_CHECK_CAST (obj, lok_doc_view_get_type(), LOKDocView)
135360
-#define LOK_DOC_VIEW_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, lok_doc_view_get_type(), LOKDocViewClass)
135360
-#define IS_LOK_DOC_VIEW(obj)       GTK_CHECK_TYPE (obj, lok_doc_view_get_type())
135360
+#define LOK_TYPE_DOC_VIEW            (lok_doc_view_get_type())
135360
+#define LOK_DOC_VIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), LOK_TYPE_DOC_VIEW, LOKDocView))
135360
+#define LOK_IS_DOC_VIEW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), LOK_TYPE_DOC_VIEW))
135360
+#define LOK_DOC_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  LOK_TYPE_DOC_VIEW, LOKDocViewClass))
135360
+#define LOK_IS_DOC_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  LOK_TYPE_DOC_VIEW))
135360
+#define LOK_DOC_VIEW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  LOK_TYPE_DOC_VIEW, LOKDocViewClass))
135360
+
135360
 
135360
 typedef struct _LOKDocView       LOKDocView;
135360
 typedef struct _LOKDocViewClass  LOKDocViewClass;
135360
@@ -40,40 +44,45 @@ struct _LOKDocViewClass
135360
   void (* part_changed) (LOKDocView* pView, int new_part);
135360
 };
135360
 
135360
-guint           lok_doc_view_get_type        (void);
135360
-GtkWidget*      lok_doc_view_new             ( LibreOfficeKit* pOffice );
135360
-gboolean        lok_doc_view_open_document   (LOKDocView* pDocView,
135360
-                                             char* pPath);
135360
+GType                          lok_doc_view_get_type               (void);
135360
+GtkWidget*                     lok_doc_view_new                    (LibreOfficeKit* pOffice );
135360
+gboolean                       lok_doc_view_open_document          (LOKDocView* pDocView,
135360
+                                                                    char* pPath);
135360
 
135360
 /// Gets the document the viewer displays.
135360
-LibreOfficeKitDocument* lok_doc_view_get_document(LOKDocView* pDocView);
135360
-
135360
-void            lok_doc_view_set_zoom        (LOKDocView* pDocView,
135360
-                                             float fZoom);
135360
-float           lok_doc_view_get_zoom        (LOKDocView* pDocView);
135360
-
135360
-int             lok_doc_view_get_parts       (LOKDocView* pDocView);
135360
-int             lok_doc_view_get_part        (LOKDocView* pDocView);
135360
-void            lok_doc_view_set_part        (LOKDocView* pDocView,
135360
-                                             int nPart);
135360
-char*           lok_doc_view_get_part_name   (LOKDocView* pDocView,
135360
-                                             int nPart);
135360
-void            lok_doc_view_set_partmode    (LOKDocView* pDocView,
135360
-                                             int nPartMode);
135360
+LibreOfficeKitDocument*        lok_doc_view_get_document           (LOKDocView* pDocView);
135360
+
135360
+void                           lok_doc_view_set_zoom               (LOKDocView* pDocView,
135360
+                                                                    float fZoom);
135360
+float                          lok_doc_view_get_zoom               (LOKDocView* pDocView);
135360
+
135360
+int                            lok_doc_view_get_parts              (LOKDocView* pDocView);
135360
+int                            lok_doc_view_get_part               (LOKDocView* pDocView);
135360
+void                           lok_doc_view_set_part               (LOKDocView* pDocView,
135360
+                                                                    int nPart);
135360
+char*                          lok_doc_view_get_part_name          (LOKDocView* pDocView,
135360
+                                                                    int nPart);
135360
+void                           lok_doc_view_set_partmode           (LOKDocView* pDocView,
135360
+                                                                    int nPartMode);
135360
 /// Sets if the viewer is actually an editor or not.
135360
-void            lok_doc_view_set_edit        (LOKDocView* pDocView,
135360
-                                             gboolean bEdit);
135360
+void                           lok_doc_view_set_edit               (LOKDocView* pDocView,
135360
+                                                                    gboolean bEdit);
135360
 /// Gets if the viewer is actually an editor or not.
135360
-gboolean        lok_doc_view_get_edit        (LOKDocView* pDocView);
135360
+gboolean                       lok_doc_view_get_edit               (LOKDocView* pDocView);
135360
 
135360
 /// Posts the .uno: command to the LibreOfficeKit.
135360
-void            lok_doc_view_post_command    (LOKDocView* pDocView, const char* pCommand, const char* pArguments);
135360
+void                           lok_doc_view_post_command           (LOKDocView* pDocView,
135360
+                                                                    const char* pCommand,
135360
+                                                                    const char* pArguments);
135360
 
135360
 /// Posts a keyboard event to LibreOfficeKit.
135360
-void            lok_doc_view_post_key    (GtkWidget* pWidget, GdkEventKey* pEvent, gpointer pData);
135360
+void                           lok_doc_view_post_key               (GtkWidget* pWidget,
135360
+                                                                    GdkEventKey* pEvent,
135360
+                                                                    gpointer pData);
135360
 
135360
 /// Get the visible area of the document (in twips).
135360
-void lok_doc_view_get_visarea(LOKDocView* pThis, GdkRectangle* pArea);
135360
+void                           lok_doc_view_get_visarea            (LOKDocView* pThis,
135360
+                                                                    GdkRectangle* pArea);
135360
 
135360
 G_END_DECLS
135360
 
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index b1e31887599d..9b09ef6452bb 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -37,26 +37,6 @@
135360
 // Number of handles around a graphic selection.
135360
 #define GRAPHIC_HANDLE_COUNT 8
135360
 
135360
-namespace {
135360
-
135360
-/// Sets rWidth and rHeight from a "width, height" string.
135360
-void payloadToSize(const char* pPayload, long& rWidth, long& rHeight)
135360
-{
135360
-    rWidth = rHeight = 0;
135360
-    gchar** ppCoordinates = g_strsplit(pPayload, ", ", 2);
135360
-    gchar** ppCoordinate = ppCoordinates;
135360
-    if (!*ppCoordinate)
135360
-        return;
135360
-    rWidth = atoi(*ppCoordinate);
135360
-    ++ppCoordinate;
135360
-    if (!*ppCoordinate)
135360
-        return;
135360
-    rHeight = atoi(*ppCoordinate);
135360
-    g_strfreev(ppCoordinates);
135360
-}
135360
-
135360
-}
135360
-
135360
 /// Holds data used by LOKDocView only.
135360
 struct LOKDocView_Impl
135360
 {
135360
@@ -216,6 +196,44 @@ struct LOKDocView_Impl
135360
     void setTilesInvalid(const GdkRectangle& rRectangle);
135360
 };
135360
 
135360
+enum
135360
+{
135360
+    EDIT_CHANGED,
135360
+    COMMAND_CHANGED,
135360
+    SEARCH_NOT_FOUND,
135360
+    PART_CHANGED,
135360
+    LAST_SIGNAL
135360
+};
135360
+
135360
+
135360
+static guint doc_view_signals[LAST_SIGNAL] = { 0 };
135360
+
135360
+
135360
+G_DEFINE_TYPE(LOKDocView, lok_doc_view, GTK_TYPE_SCROLLED_WINDOW)
135360
+
135360
+
135360
+namespace {
135360
+
135360
+/// Sets rWidth and rHeight from a "width, height" string.
135360
+void payloadToSize(const char* pPayload, long& rWidth, long& rHeight)
135360
+{
135360
+    rWidth = rHeight = 0;
135360
+    gchar** ppCoordinates = g_strsplit(pPayload, ", ", 2);
135360
+    gchar** ppCoordinate = ppCoordinates;
135360
+    if (!*ppCoordinate)
135360
+        return;
135360
+    rWidth = atoi(*ppCoordinate);
135360
+    ++ppCoordinate;
135360
+    if (!*ppCoordinate)
135360
+        return;
135360
+    rHeight = atoi(*ppCoordinate);
135360
+    g_strfreev(ppCoordinates);
135360
+}
135360
+
135360
+}
135360
+
135360
+
135360
+
135360
 namespace {
135360
 
135360
 /// Implementation of the global callback handler, invoked by globalCallback();
135360
@@ -1073,16 +1091,7 @@ void LOKDocView_Impl::globalCallbackWorkerImpl(int nType, const char* pPayload)
135360
 #endif
135360
 }
135360
 
135360
-enum
135360
-{
135360
-    EDIT_CHANGED,
135360
-    COMMAND_CHANGED,
135360
-    SEARCH_NOT_FOUND,
135360
-    PART_CHANGED,
135360
-    LAST_SIGNAL
135360
-};
135360
 
135360
-static guint doc_view_signals[LAST_SIGNAL] = { 0 };
135360
 
135360
 void LOKDocView_Impl::commandChanged(const std::string& rString)
135360
 {
135360
@@ -1100,9 +1109,8 @@ void LOKDocView_Impl::setPart(const std::string& rString)
135360
     renderDocument(0);
135360
 }
135360
 
135360
-static void lok_doc_view_class_init( gpointer ptr )
135360
+static void lok_doc_view_class_init (LOKDocViewClass* pClass)
135360
 {
135360
-    LOKDocViewClass* pClass = static_cast<LOKDocViewClass *>(ptr);
135360
     GObjectClass *gobject_class = G_OBJECT_CLASS(pClass);
135360
     pClass->edit_changed = NULL;
135360
     doc_view_signals[EDIT_CHANGED] =
135360
@@ -1146,9 +1154,8 @@ static void lok_doc_view_class_init( gpointer ptr )
135360
                      G_TYPE_INT);
135360
 }
135360
 
135360
-static void lok_doc_view_init( GTypeInstance* pInstance, gpointer )
135360
+static void lok_doc_view_init (LOKDocView* pDocView)
135360
 {
135360
-    LOKDocView* pDocView = reinterpret_cast<LOKDocView *>(pInstance);
135360
     // Gtk ScrolledWindow is apparently not fully initialised yet, we specifically
135360
     // have to set the [hv]adjustment to prevent GTK assertions from firing, see
135360
     // https://bugzilla.gnome.org/show_bug.cgi?id=438114 for more info.
135360
@@ -1183,29 +1190,7 @@ static void lok_doc_view_init( GTypeInstance* pInstance, gpointer )
135360
     g_signal_connect(G_OBJECT(pDocView), "destroy", G_CALLBACK(LOKDocView_Impl::destroy), 0);
135360
 }
135360
 
135360
-SAL_DLLPUBLIC_EXPORT guint lok_doc_view_get_type()
135360
-{
135360
-    static guint lok_doc_view_type = 0;
135360
-
135360
-    if (!lok_doc_view_type)
135360
-    {
135360
-        char pName[] = "LokDocView";
135360
-        GtkTypeInfo lok_doc_view_info =
135360
-        {
135360
-            pName,
135360
-            sizeof( LOKDocView ),
135360
-            sizeof( LOKDocViewClass ),
135360
-            lok_doc_view_class_init,
135360
-            lok_doc_view_init,
135360
-            NULL,
135360
-            NULL,
135360
-            nullptr
135360
-        };
135360
-
135360
-        lok_doc_view_type = gtk_type_unique( gtk_scrolled_window_get_type(), &lok_doc_view_info );
135360
-    }
135360
-    return lok_doc_view_type;
135360
-}
135360
+SAL_DLLPUBLIC_EXPORT GType lok_doc_view_get_type();
135360
 
135360
 SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new( LibreOfficeKit* pOffice )
135360
 {
135360
-- 
135360
2.12.0
135360