[Libreoffice-commits] core.git: 5 commits - include/LibreOfficeKit libreofficekit/qa libreofficekit/source

Pranav Kant pranavk at gnome.org
Mon Jun 29 04:34:03 PDT 2015


 include/LibreOfficeKit/LibreOfficeKitGtk.h          |    4 -
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |   38 +++++++-------
 libreofficekit/source/gtk/lokdocview.cxx            |   54 +++++++++-----------
 libreofficekit/source/gtk/tilebuffer.cxx            |    5 +
 4 files changed, 49 insertions(+), 52 deletions(-)

New commits:
commit a482d3289fa7e3789a306970ea76d074527c3579
Author: Pranav Kant <pranavk at gnome.org>
Date:   Mon Jun 29 13:34:24 2015 +0530

    gtktiledviewer: Don't continue on widget init failure
    
    Change-Id: I5916357903fad5878d29bc31f21af45816a45ec5

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index db465cb..f7b065c 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -520,8 +520,8 @@ int main( int argc, char* argv[] )
 
     // Docview
     pDocView = lok_doc_view_new (argv[1], NULL, NULL);
-    if (pDocView == NULL)
-        g_error ("Error while creating LOKDocView widget");
+    g_assert_nonnull(pDocView);
+
     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);
commit e2c73bf76a35ee8ce18e4499587de849c92eef1c
Author: Pranav Kant <pranavk at gnome.org>
Date:   Wed Jun 24 02:02:39 2015 +0530

    lokdocview: Handle DELETE key
    
    Change-Id: I58d0c36decf81c812c108458b449402416ebcc2d

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index ca7167b..62f1e61 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -245,6 +245,9 @@ signalKey (GtkWidget* pWidget, GdkEventKey* pEvent)
     case GDK_KEY_BackSpace:
         nKeyCode = com::sun::star::awt::Key::BACKSPACE;
         break;
+    case GDK_KEY_Delete:
+        nKeyCode = com::sun::star::awt::Key::DELETE;
+        break;
     case GDK_KEY_Return:
         nKeyCode = com::sun::star::awt::Key::RETURN;
         break;
commit 580c70883ca8c9bc73ea42cb05983b9df57f55ff
Author: Pranav Kant <pranavk at gnome.org>
Date:   Tue Jun 23 14:37:09 2015 +0530

    tilebuffer: Add timer to measure paintTile() call
    
    Change-Id: I2645863c7445e17d77e2c4e2dc24e22f8685034e

diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
index 3f22f98..60aa16f 100644
--- a/libreofficekit/source/gtk/tilebuffer.cxx
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
@@ -91,7 +91,7 @@ Tile& TileBuffer::getTile(int x, int y, float aZoom)
         aTileRectangle.x = pixelToTwip(nTileSizePixels, aZoom) * y;
         aTileRectangle.y = pixelToTwip(nTileSizePixels, aZoom) * x;
 
-        g_info ("Rendering (%d, %d)", x, y);
+        g_test_timer_start();
         m_pLOKDocument->pClass->paintTile(m_pLOKDocument,
                                           pBuffer,
                                           nTileSizePixels, nTileSizePixels,
@@ -99,6 +99,9 @@ Tile& TileBuffer::getTile(int x, int y, float aZoom)
                                           pixelToTwip(nTileSizePixels, aZoom),
                                           pixelToTwip(nTileSizePixels, aZoom));
 
+        double elapsedTime = g_test_timer_elapsed();
+        g_info ("Rendered (%d, %d) in %f seconds", x, y, elapsedTime);
+
         //create a mapping for it
         m_mTiles[index].setPixbuf(pPixBuf);
         m_mTiles[index].valid = true;
commit da49b8339828c0ee27d999ac4201e0eb12a1a47f
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 1ca9454..db465cb 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
commit 9d2fa921470152647cc3b54355f70a1365f752ff
Author: Pranav Kant <pranavk at gnome.org>
Date:   Tue Jun 23 01:52:44 2015 +0530

    lokdocview: Don't handle hyperlink clicks
    
    Instead emit the signal 'hyperlink-clicked', and let the
    application decide how it wants to handle the hyperlink clicks.
    
    Change-Id: Ief72bbd16727e140cacf28b852ad43952c02f7ae

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 917b294..1ca9454 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -312,6 +312,17 @@ static void signalPart(LOKDocView* /*pLOKDocView*/, int nPart, gpointer /*pData*
 }
 
 /// User clicked on a command button -> inform LOKDocView.
+static void signalHyperlink(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer /*pData*/)
+{
+    GError* pError = NULL;
+    gtk_show_uri(NULL, pPayload, GDK_CURRENT_TIME, &pError);
+    if (pError != NULL)
+    {
+        g_warning("Unable to show URI %s : %s", pPayload, pError->message);
+        g_error_free(pError);
+    }
+}
+
 static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
 {
     if (g_bToolItemBroadcast)
@@ -528,6 +539,7 @@ int main( int argc, char* argv[] )
     g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL);
     g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL);
     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);
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index cff02ea..988397a 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -324,6 +324,12 @@ setPart(LOKDocView* pDocView, const std::string& rString)
     g_signal_emit(pDocView, doc_view_signals[PART_CHANGED], 0, std::stoi(rString));
 }
 
+static void
+hyperlinkClicked(LOKDocView* pDocView, const std::string& rString)
+{
+    g_signal_emit(pDocView, doc_view_signals[HYPERLINK_CLICKED], 0, rString.c_str());
+}
+
 /// Implementation of the global callback handler, invoked by globalCallback();
 static gboolean
 globalCallback (gpointer pData)
@@ -507,8 +513,7 @@ callback (gpointer pData)
     break;
     case LOK_CALLBACK_HYPERLINK_CLICKED:
     {
-        GError* pError = NULL;
-        gtk_show_uri(NULL, pCallback->m_aPayload.c_str(), GDK_CURRENT_TIME, &pError);
+        hyperlinkClicked(pDocView, pCallback->m_aPayload);
     }
     break;
     case LOK_CALLBACK_STATE_CHANGED:
@@ -1353,7 +1358,7 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
      * @aHyperlink: the URI which the application should handle
      */
     doc_view_signals[HYPERLINK_CLICKED] =
-        g_signal_new("hyperlinked-clicked",
+        g_signal_new("hyperlink-clicked",
                      G_TYPE_FROM_CLASS(pGObjectClass),
                      G_SIGNAL_RUN_FIRST,
                      0,


More information about the Libreoffice-commits mailing list