[Libreoffice-commits] core.git: Branch 'feature/gsoc-tiled-rendering' - include/LibreOfficeKit libreofficekit/qa libreofficekit/source

Pranav Kant pranavk at gnome.org
Mon Jun 22 14:30:13 PDT 2015


 include/LibreOfficeKit/LibreOfficeKitGtk.h          |    4 --
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |   22 ++---------
 libreofficekit/source/gtk/lokdocview.cxx            |   40 +++++++-------------
 3 files changed, 20 insertions(+), 46 deletions(-)

New commits:
commit d7cdd69e7a2e4388d524eafaa6016e9d0403a277
Author: Pranav Kant <pranavk at gnome.org>
Date:   Tue Jun 23 02:58:38 2015 +0530

    lokdocview: Remove superfluous *_post_key()
    
    Instead directly let LOKDocView handle the input.
    
    Change-Id: I260a460df23c3e2e5c78d8b363bb864ae5c63dab

diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 3a1628b..962f9d9 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -74,10 +74,6 @@ void                           lok_doc_view_post_command           (LOKDocView*
                                                                     const char* pCommand,
                                                                     const char* pArguments);
 
-/// Posts a keyboard event to LibreOfficeKit.
-void                           lok_doc_view_post_key               (LOKDocView* pDocView,
-                                                                    GdkEvent* pEvent);
-
 float                          lok_doc_view_pixel_to_twip          (LOKDocView* pDocView,
                                                                     float fInput);
 
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index c854288..18815d6 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -191,19 +191,6 @@ static void getVisibleAreaTwips(GdkRectangle* pArea)
 #endif
 }
 
-
-/// Handles the key-press-event of the window.
-static gboolean signalKey(GtkWidget* /*pWidget*/, GdkEvent* pEvent, gpointer/* pData*/)
-{
-    LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
-    if (!gtk_widget_get_visible(pFindbar) && bool(lok_doc_view_get_edit(pLOKDocView)))
-        {
-            lok_doc_view_post_key(pLOKDocView, pEvent);
-            return TRUE;
-        }
-    return FALSE;
-}
-
 /// Searches for the next or previous text of pFindbarEntry.
 static void doSearch(bool bBackwards)
 {
@@ -541,10 +528,6 @@ int main( int argc, char* argv[] )
     g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL);
     g_signal_connect(pDocView, "hyperlink-clicked", G_CALLBACK(signalHyperlink), NULL);
 
-    // Input handling.
-    g_signal_connect(pWindow, "key-press-event", G_CALLBACK(signalKey), pDocView);
-    g_signal_connect(pWindow, "key-release-event", G_CALLBACK(signalKey), pDocView);
-
     // Scrolled window for DocView
     pScrolledWindow = gtk_scrolled_window_new(0, 0);
     gtk_widget_set_hexpand (pScrolledWindow, TRUE);
@@ -568,6 +551,11 @@ int main( int argc, char* argv[] )
     g_signal_connect(G_OBJECT(pPartModeComboBox), "changed", G_CALLBACK(changePartMode), 0);
     g_signal_connect(G_OBJECT(pPartSelector), "changed", G_CALLBACK(changePart), 0);
 
+    // Make only LOKDocView widget as focussable
+    GList *focusChain = NULL;
+    focusChain = g_list_append( focusChain, pDocView );
+    gtk_container_set_focus_chain ( GTK_CONTAINER (pVBox), focusChain );
+
     gtk_main();
 
     return 0;
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 988397a..ca7167b 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -226,24 +226,21 @@ isEmptyRectangle(const GdkRectangle& rRectangle)
     return rRectangle.x == 0 && rRectangle.y == 0 && rRectangle.width == 0 && rRectangle.height == 0;
 }
 
-static void
-signalKey (LOKDocView* pDocView, const GdkEvent* pEvent)
+static gboolean
+signalKey (GtkWidget* pWidget, GdkEventKey* pEvent)
 {
+    LOKDocView* pDocView = LOK_DOC_VIEW(pWidget);
     LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
     int nCharCode = 0;
     int nKeyCode = 0;
-    guint keyval;
-    GdkModifierType state;
-    gdk_event_get_keyval (pEvent, &keyval);
-    gdk_event_get_state (pEvent, &state);
 
     if (!priv->m_bEdit)
     {
         g_info("signalKey: not in edit mode, ignore");
-        return;
+        return FALSE;
     }
 
-    switch (keyval)
+    switch (pEvent->keyval)
     {
     case GDK_KEY_BackSpace:
         nKeyCode = com::sun::star::awt::Key::BACKSPACE;
@@ -270,22 +267,24 @@ signalKey (LOKDocView* pDocView, const GdkEvent* pEvent)
         nKeyCode = com::sun::star::awt::Key::RIGHT;
         break;
     default:
-        if (keyval >= GDK_KEY_F1 && keyval <= GDK_KEY_F26)
-            nKeyCode = com::sun::star::awt::Key::F1 + (keyval - GDK_KEY_F1);
+        if (pEvent->keyval >= GDK_KEY_F1 && pEvent->keyval <= GDK_KEY_F26)
+            nKeyCode = com::sun::star::awt::Key::F1 + (pEvent->keyval - GDK_KEY_F1);
         else
-            nCharCode = gdk_keyval_to_unicode(keyval);
+            nCharCode = gdk_keyval_to_unicode(pEvent->keyval);
     }
 
     // rsc is not public API, but should be good enough for debugging purposes.
     // If this is needed for real, then probably a new param of type
     // css::awt::KeyModifier is needed in postKeyEvent().
-    if (state & GDK_SHIFT_MASK)
+    if (pEvent->state & GDK_SHIFT_MASK)
         nKeyCode |= KEY_SHIFT;
 
     if (pEvent->type == GDK_KEY_RELEASE)
         priv->m_pDocument->pClass->postKeyEvent(priv->m_pDocument, LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode);
     else
         priv->m_pDocument->pClass->postKeyEvent(priv->m_pDocument, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode);
+
+    return FALSE;
 }
 
 static gboolean
@@ -1151,6 +1150,8 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
     pWidgetClass->draw = lok_doc_view_draw;
     pWidgetClass->button_press_event = lok_doc_view_signal_button;
     pWidgetClass->button_release_event = lok_doc_view_signal_button;
+    pWidgetClass->key_press_event = signalKey;
+    pWidgetClass->key_release_event = signalKey;
     pWidgetClass->motion_notify_event = lok_doc_view_signal_motion;
 
     /**
@@ -1431,6 +1432,8 @@ lok_doc_view_open_document (LOKDocView* pDocView, const gchar* pPath)
         gtk_widget_set_size_request(GTK_WIDGET(pDocView),
                                     nDocumentWidthPixels,
                                     nDocumentHeightPixels);
+        gtk_widget_set_can_focus(GTK_WIDGET(pDocView), TRUE);
+        gtk_widget_grab_focus(GTK_WIDGET(pDocView));
     }
     return TRUE;
 }
@@ -1579,19 +1582,6 @@ lok_doc_view_post_command (LOKDocView* pDocView,
 }
 
 /**
- * lok_doc_view_post_key:
- * @pDocView: the #LOKDocView instance
- * @pEvent: the #GdkEventKey containing information about the event
- *
- * This methods forwards your key events to the LO core.
-*/
-SAL_DLLPUBLIC_EXPORT void
-lok_doc_view_post_key (LOKDocView* pDocView, GdkEvent* pEvent)
-{
-    signalKey(pDocView, pEvent);
-}
-
-/**
  * lok_doc_view_pixel_to_twip:
  * @pDocView: The #LOKDocView instance
  * @fInput: The value in pixels to convert to twips


More information about the Libreoffice-commits mailing list