Blame SOURCES/0060-lokdocview-Remove-superfluous-_post_key.patch

135360
From 061935437f10f6e35d0b0561a5465f4872a8c909 Mon Sep 17 00:00:00 2001
135360
From: Pranav Kant <pranavk@gnome.org>
135360
Date: Tue, 23 Jun 2015 02:58:38 +0530
135360
Subject: [PATCH 060/398] lokdocview: Remove superfluous *_post_key()
135360
135360
Instead directly let LOKDocView handle the input.
135360
135360
Change-Id: I260a460df23c3e2e5c78d8b363bb864ae5c63dab
135360
(cherry picked from commit da49b8339828c0ee27d999ac4201e0eb12a1a47f)
135360
---
135360
 include/LibreOfficeKit/LibreOfficeKitGtk.h         |  4 ---
135360
 .../qa/gtktiledviewer/gtktiledviewer.cxx           | 22 +++---------
135360
 libreofficekit/source/gtk/lokdocview.cxx           | 40 ++++++++--------------
135360
 3 files changed, 20 insertions(+), 46 deletions(-)
135360
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
135360
index 3a1628b60e86..962f9d9265bb 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
135360
@@ -74,10 +74,6 @@ void                           lok_doc_view_post_command           (LOKDocView*
135360
                                                                     const char* pCommand,
135360
                                                                     const char* pArguments);
135360
 
135360
-/// Posts a keyboard event to LibreOfficeKit.
135360
-void                           lok_doc_view_post_key               (LOKDocView* pDocView,
135360
-                                                                    GdkEvent* pEvent);
135360
-
135360
 float                          lok_doc_view_pixel_to_twip          (LOKDocView* pDocView,
135360
                                                                     float fInput);
135360
 
135360
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
index 61f016dffab8..7510ca53a928 100644
135360
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
@@ -190,19 +190,6 @@ static void getVisibleAreaTwips(GdkRectangle* pArea)
135360
 #endif
135360
 }
135360
 
135360
-
135360
-/// Handles the key-press-event of the window.
135360
-static gboolean signalKey(GtkWidget* /*pWidget*/, GdkEvent* pEvent, gpointer/* pData*/)
135360
-{
135360
-    LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
135360
-    if (!gtk_widget_get_visible(pFindbar) && bool(lok_doc_view_get_edit(pLOKDocView)))
135360
-        {
135360
-            lok_doc_view_post_key(pLOKDocView, pEvent);
135360
-            return TRUE;
135360
-        }
135360
-    return FALSE;
135360
-}
135360
-
135360
 /// Searches for the next or previous text of pFindbarEntry.
135360
 static void doSearch(bool bBackwards)
135360
 {
135360
@@ -540,10 +527,6 @@ int main( int argc, char* argv[] )
135360
     g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL);
135360
     g_signal_connect(pDocView, "hyperlink-clicked", G_CALLBACK(signalHyperlink), NULL);
135360
 
135360
-    // Input handling.
135360
-    g_signal_connect(pWindow, "key-press-event", G_CALLBACK(signalKey), pDocView);
135360
-    g_signal_connect(pWindow, "key-release-event", G_CALLBACK(signalKey), pDocView);
135360
-
135360
     // Scrolled window for DocView
135360
     pScrolledWindow = gtk_scrolled_window_new(0, 0);
135360
     gtk_widget_set_hexpand (pScrolledWindow, TRUE);
135360
@@ -567,6 +550,11 @@ int main( int argc, char* argv[] )
135360
     g_signal_connect(G_OBJECT(pPartModeComboBox), "changed", G_CALLBACK(changePartMode), 0);
135360
     g_signal_connect(G_OBJECT(pPartSelector), "changed", G_CALLBACK(changePart), 0);
135360
 
135360
+    // Make only LOKDocView widget as focussable
135360
+    GList *focusChain = NULL;
135360
+    focusChain = g_list_append( focusChain, pDocView );
135360
+    gtk_container_set_focus_chain ( GTK_CONTAINER (pVBox), focusChain );
135360
+
135360
     gtk_main();
135360
 
135360
     return 0;
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index 19da4b2da691..368a8d536887 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -226,24 +226,21 @@ isEmptyRectangle(const GdkRectangle& rRectangle)
135360
     return rRectangle.x == 0 && rRectangle.y == 0 && rRectangle.width == 0 && rRectangle.height == 0;
135360
 }
135360
 
135360
-static void
135360
-signalKey (LOKDocView* pDocView, const GdkEvent* pEvent)
135360
+static gboolean
135360
+signalKey (GtkWidget* pWidget, GdkEventKey* pEvent)
135360
 {
135360
+    LOKDocView* pDocView = LOK_DOC_VIEW(pWidget);
135360
     LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
135360
     int nCharCode = 0;
135360
     int nKeyCode = 0;
135360
-    guint keyval;
135360
-    GdkModifierType state;
135360
-    gdk_event_get_keyval (pEvent, &keyval);
135360
-    gdk_event_get_state (pEvent, &state);
135360
 
135360
     if (!priv->m_bEdit)
135360
     {
135360
         g_info("signalKey: not in edit mode, ignore");
135360
-        return;
135360
+        return FALSE;
135360
     }
135360
 
135360
-    switch (keyval)
135360
+    switch (pEvent->keyval)
135360
     {
135360
     case GDK_KEY_BackSpace:
135360
         nKeyCode = com::sun::star::awt::Key::BACKSPACE;
135360
@@ -270,22 +267,24 @@ signalKey (LOKDocView* pDocView, const GdkEvent* pEvent)
135360
         nKeyCode = com::sun::star::awt::Key::RIGHT;
135360
         break;
135360
     default:
135360
-        if (keyval >= GDK_KEY_F1 && keyval <= GDK_KEY_F26)
135360
-            nKeyCode = com::sun::star::awt::Key::F1 + (keyval - GDK_KEY_F1);
135360
+        if (pEvent->keyval >= GDK_KEY_F1 && pEvent->keyval <= GDK_KEY_F26)
135360
+            nKeyCode = com::sun::star::awt::Key::F1 + (pEvent->keyval - GDK_KEY_F1);
135360
         else
135360
-            nCharCode = gdk_keyval_to_unicode(keyval);
135360
+            nCharCode = gdk_keyval_to_unicode(pEvent->keyval);
135360
     }
135360
 
135360
     // rsc is not public API, but should be good enough for debugging purposes.
135360
     // If this is needed for real, then probably a new param of type
135360
     // css::awt::KeyModifier is needed in postKeyEvent().
135360
-    if (state & GDK_SHIFT_MASK)
135360
+    if (pEvent->state & GDK_SHIFT_MASK)
135360
         nKeyCode |= KEY_SHIFT;
135360
 
135360
     if (pEvent->type == GDK_KEY_RELEASE)
135360
         priv->m_pDocument->pClass->postKeyEvent(priv->m_pDocument, LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode);
135360
     else
135360
         priv->m_pDocument->pClass->postKeyEvent(priv->m_pDocument, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode);
135360
+
135360
+    return FALSE;
135360
 }
135360
 
135360
 static gboolean
135360
@@ -1151,6 +1150,8 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
135360
     pWidgetClass->draw = lok_doc_view_draw;
135360
     pWidgetClass->button_press_event = lok_doc_view_signal_button;
135360
     pWidgetClass->button_release_event = lok_doc_view_signal_button;
135360
+    pWidgetClass->key_press_event = signalKey;
135360
+    pWidgetClass->key_release_event = signalKey;
135360
     pWidgetClass->motion_notify_event = lok_doc_view_signal_motion;
135360
 
135360
     /**
135360
@@ -1431,6 +1432,8 @@ lok_doc_view_open_document (LOKDocView* pDocView, const gchar* pPath)
135360
         gtk_widget_set_size_request(GTK_WIDGET(pDocView),
135360
                                     nDocumentWidthPixels,
135360
                                     nDocumentHeightPixels);
135360
+        gtk_widget_set_can_focus(GTK_WIDGET(pDocView), TRUE);
135360
+        gtk_widget_grab_focus(GTK_WIDGET(pDocView));
135360
     }
135360
     return TRUE;
135360
 }
135360
@@ -1579,19 +1582,6 @@ lok_doc_view_post_command (LOKDocView* pDocView,
135360
 }
135360
 
135360
 /**
135360
- * lok_doc_view_post_key:
135360
- * @pDocView: the #LOKDocView instance
135360
- * @pEvent: the #GdkEventKey containing information about the event
135360
- *
135360
- * This methods forwards your key events to the LO core.
135360
-*/
135360
-SAL_DLLPUBLIC_EXPORT void
135360
-lok_doc_view_post_key (LOKDocView* pDocView, GdkEvent* pEvent)
135360
-{
135360
-    signalKey(pDocView, pEvent);
135360
-}
135360
-
135360
-/**
135360
  * lok_doc_view_pixel_to_twip:
135360
  * @pDocView: The #LOKDocView instance
135360
  * @fInput: The value in pixels to convert to twips
135360
-- 
135360
2.12.0
135360