diff options
author | Pranav Kant <pranavk@gnome.org> | 2015-06-06 03:10:31 +0530 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-09 10:44:23 +0200 |
commit | c5f1f7ad2710914fdd6645dd8ce958c70d1d8381 (patch) | |
tree | 534668cd82421bcc16fadf717b71c9fc43a98fc9 /libreofficekit | |
parent | c8caa803b43d7091318f1129b7b4cc7ee417c336 (diff) |
lokdocview: Modernise LOKDocView as GObject
Change-Id: I3bbd07ce8163890f9b88567966622dd4fbe9d94d
Diffstat (limited to 'libreofficekit')
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 97 |
1 files changed, 41 insertions, 56 deletions
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 4de4c710be3c..b6c529f41a03 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -37,26 +37,6 @@ // Number of handles around a graphic selection. #define GRAPHIC_HANDLE_COUNT 8 -namespace { - -/// Sets rWidth and rHeight from a "width, height" string. -void payloadToSize(const char* pPayload, long& rWidth, long& rHeight) -{ - rWidth = rHeight = 0; - gchar** ppCoordinates = g_strsplit(pPayload, ", ", 2); - gchar** ppCoordinate = ppCoordinates; - if (!*ppCoordinate) - return; - rWidth = atoi(*ppCoordinate); - ++ppCoordinate; - if (!*ppCoordinate) - return; - rHeight = atoi(*ppCoordinate); - g_strfreev(ppCoordinates); -} - -} - /// Holds data used by LOKDocView only. struct LOKDocView_Impl { @@ -216,6 +196,44 @@ struct LOKDocView_Impl void setTilesInvalid(const GdkRectangle& rRectangle); }; +enum +{ + EDIT_CHANGED, + COMMAND_CHANGED, + SEARCH_NOT_FOUND, + PART_CHANGED, + LAST_SIGNAL +}; + + +static guint doc_view_signals[LAST_SIGNAL] = { 0 }; + + +G_DEFINE_TYPE(LOKDocView, lok_doc_view, GTK_TYPE_SCROLLED_WINDOW) + + +namespace { + +/// Sets rWidth and rHeight from a "width, height" string. +void payloadToSize(const char* pPayload, long& rWidth, long& rHeight) +{ + rWidth = rHeight = 0; + gchar** ppCoordinates = g_strsplit(pPayload, ", ", 2); + gchar** ppCoordinate = ppCoordinates; + if (!*ppCoordinate) + return; + rWidth = atoi(*ppCoordinate); + ++ppCoordinate; + if (!*ppCoordinate) + return; + rHeight = atoi(*ppCoordinate); + g_strfreev(ppCoordinates); +} + +} + + + namespace { /// Implementation of the global callback handler, invoked by globalCallback(); @@ -1073,16 +1091,7 @@ void LOKDocView_Impl::globalCallbackWorkerImpl(int nType, const char* pPayload) #endif } -enum -{ - EDIT_CHANGED, - COMMAND_CHANGED, - SEARCH_NOT_FOUND, - PART_CHANGED, - LAST_SIGNAL -}; -static guint doc_view_signals[LAST_SIGNAL] = { 0 }; void LOKDocView_Impl::commandChanged(const std::string& rString) { @@ -1100,9 +1109,8 @@ void LOKDocView_Impl::setPart(const std::string& rString) renderDocument(0); } -static void lok_doc_view_class_init( gpointer ptr ) +static void lok_doc_view_class_init (LOKDocViewClass* pClass) { - LOKDocViewClass* pClass = static_cast<LOKDocViewClass *>(ptr); GObjectClass *gobject_class = G_OBJECT_CLASS(pClass); pClass->edit_changed = NULL; doc_view_signals[EDIT_CHANGED] = @@ -1146,9 +1154,8 @@ static void lok_doc_view_class_init( gpointer ptr ) G_TYPE_INT); } -static void lok_doc_view_init( GTypeInstance* pInstance, gpointer ) +static void lok_doc_view_init (LOKDocView* pDocView) { - LOKDocView* pDocView = reinterpret_cast<LOKDocView *>(pInstance); // Gtk ScrolledWindow is apparently not fully initialised yet, we specifically // have to set the [hv]adjustment to prevent GTK assertions from firing, see // https://bugzilla.gnome.org/show_bug.cgi?id=438114 for more info. @@ -1183,29 +1190,7 @@ static void lok_doc_view_init( GTypeInstance* pInstance, gpointer ) g_signal_connect(G_OBJECT(pDocView), "destroy", G_CALLBACK(LOKDocView_Impl::destroy), 0); } -SAL_DLLPUBLIC_EXPORT guint lok_doc_view_get_type() -{ - static guint lok_doc_view_type = 0; - - if (!lok_doc_view_type) - { - char pName[] = "LokDocView"; - GtkTypeInfo lok_doc_view_info = - { - pName, - sizeof( LOKDocView ), - sizeof( LOKDocViewClass ), - lok_doc_view_class_init, - lok_doc_view_init, - NULL, - NULL, - nullptr - }; - - lok_doc_view_type = gtk_type_unique( gtk_scrolled_window_get_type(), &lok_doc_view_info ); - } - return lok_doc_view_type; -} +SAL_DLLPUBLIC_EXPORT GType lok_doc_view_get_type(); SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new( LibreOfficeKit* pOffice ) { |