[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 2 commits - include/LibreOfficeKit libreofficekit/source sw/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Jan 27 00:35:49 PST 2015


 include/LibreOfficeKit/LibreOfficeKit.h    |    8 ++++-
 include/LibreOfficeKit/LibreOfficeKitGtk.h |    2 +
 libreofficekit/source/gtk/lokdocview.c     |   42 +++++++++++++++++++++++++++++
 sw/source/core/crsr/viscrs.cxx             |    9 ++++++
 4 files changed, 60 insertions(+), 1 deletion(-)

New commits:
commit 5ba05541e0cbb1dee712781f7d09c2d2038e9f08
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Jan 27 09:34:04 2015 +0100

    lokdocview: initial overlay on top of the tiles
    
    It currently contains a non-blinking cursor caret in case at least one
    character is typed.
    
    Change-Id: I476bb1e8434a5df8c97054d670d68bc79721914e

diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index b3cd304..75278e7 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -43,6 +43,8 @@ struct _LOKDocView
     LibreOfficeKitDocument* pDocument;
     /// View or edit mode.
     gboolean m_bEdit;
+    /// Position and size of the visible cursor.
+    GdkRectangle m_aVisibleCursor;
 };
 
 struct _LOKDocViewClass
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index bb2444c..e9a440e 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -23,6 +23,7 @@
 static void lok_docview_class_init( LOKDocViewClass* pClass );
 static void lok_docview_init( LOKDocView* pDocView );
 static float pixelToTwip(float nInput);
+static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpointer pData);
 
 // We specifically need to destroy the document when closing in order to ensure
 // that lock files etc. are cleaned up.
@@ -109,9 +110,12 @@ static void lok_docview_init( LOKDocView* pDocView )
 
     pDocView->fZoom = 1;
     pDocView->m_bEdit = FALSE;
+    memset(&pDocView->m_aVisibleCursor, 0, sizeof(pDocView->m_aVisibleCursor));
 
     gtk_signal_connect( GTK_OBJECT(pDocView), "destroy",
                         GTK_SIGNAL_FUNC(lcl_onDestroy), NULL );
+    g_signal_connect_after(pDocView->pEventBox, "expose-event",
+                           G_CALLBACK(renderOverlay), pDocView);
 }
 
 SAL_DLLPUBLIC_EXPORT GtkWidget* lok_docview_new( LibreOfficeKit* pOffice )
@@ -136,6 +140,38 @@ static float pixelToTwip(float nInput)
     return (nInput / g_nDPI) * 1440.0f;
 }
 
+static gboolean lcl_isEmptyRectangle(GdkRectangle* pRectangle)
+{
+    return pRectangle->x == 0 && pRectangle->y == 0 && pRectangle->width == 0 && pRectangle->height == 0;
+}
+
+static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpointer pData)
+{
+    LOKDocView* pDocView = pData;
+    cairo_t* pCairo;
+
+    (void)pEvent;
+    pCairo = gdk_cairo_create(gtk_widget_get_window(pWidget));
+
+    if (!lcl_isEmptyRectangle(&pDocView->m_aVisibleCursor))
+    {
+        if (pDocView->m_aVisibleCursor.width == 0)
+            // Set a minimal width if it would be 0.
+            pDocView->m_aVisibleCursor.width = 30;
+
+        cairo_set_source_rgb(pCairo, 0, 0, 0);
+        cairo_rectangle(pCairo,
+                        twipToPixel(pDocView->m_aVisibleCursor.x),
+                        twipToPixel(pDocView->m_aVisibleCursor.y),
+                        twipToPixel(pDocView->m_aVisibleCursor.width),
+                        twipToPixel(pDocView->m_aVisibleCursor.height));
+        cairo_fill(pCairo);
+    }
+
+    cairo_destroy(pCairo);
+    return FALSE;
+}
+
 void renderDocument(LOKDocView* pDocView, GdkRectangle* pPartial)
 {
     long nDocumentWidthTwips, nDocumentHeightTwips, nDocumentWidthPixels, nDocumentHeightPixels;
@@ -292,6 +328,12 @@ static gboolean lok_docview_callback(gpointer pData)
             renderDocument(pCallback->m_pDocView, NULL);
     }
     break;
+    case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
+    {
+        pCallback->m_pDocView->m_aVisibleCursor = lcl_payloadToRectangle(pCallback->m_pPayload);
+        gtk_widget_queue_draw(GTK_WIDGET(pCallback->m_pDocView->pEventBox));
+    }
+    break;
     default:
         break;
     }
commit 06b5aa80eb9cb4b2cbc77f41c83c0b7b0fe64a57
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Jan 27 09:32:43 2015 +0100

    Add LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR
    
    So that clients can draw a blinking cursor at the cursor position if
    they want so.
    
    Change-Id: I662b8d28d7054f89c381c14333a51e1dc222f93d

diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 991fae4..d3b80cd 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -60,7 +60,13 @@ typedef enum
      * Rectangle format: "width,height,x,y", where all numbers are document
      * coordinates, in twips.
      */
-    LOK_CALLBACK_INVALIDATE_TILES
+    LOK_CALLBACK_INVALIDATE_TILES,
+    /**
+     * The size and/or the position of the visible cursor changed.
+     *
+     * Rectangle format is the same as LOK_CALLBACK_INVALIDATE_TILES.
+     */
+    LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR
 }
 LibreOfficeKitCallbackType;
 
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index fadb3e8..d8d0631 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -175,6 +175,15 @@ void SwVisCrsr::_SetPosAndShow()
     m_aTxtCrsr.SetSize( aRect.SSize() );
 
     m_aTxtCrsr.SetPos( aRect.Pos() );
+
+    if (m_pCrsrShell->isTiledRendering())
+    {
+        std::stringstream ss;
+        ss << aRect.Width() << ", " << aRect.Height() << ", " << aRect.Left() << ", " << aRect.Top();
+        OString sRect = ss.str().c_str();
+        m_pCrsrShell->libreOfficeKitCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
+    }
+
     if ( !m_pCrsrShell->IsCrsrReadonly()  || m_pCrsrShell->GetViewOptions()->IsSelectionInReadonly() )
     {
         if ( m_pCrsrShell->GetDrawView() )


More information about the Libreoffice-commits mailing list