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

Miklos Vajna vmiklos at collabora.co.uk
Mon Feb 9 05:58:19 PST 2015


 libreofficekit/source/gtk/lokdocview.c |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

New commits:
commit ff7920181f0c3466a2a417818ab9c9a5affc7651
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Feb 9 14:22:01 2015 +0100

    lokdocview: when have a cursor but no selection, show the middle handle
    
    Change-Id: I1497bd73303a0445f06f3302aa5b8a537243bfeb

diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index a7cf3ec..351c7cc 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -24,6 +24,9 @@
 #define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
 #endif
 
+// Cursor bitmaps from the Android app.
+#define CURSOR_HANDLE_DIR "android/experimental/LOAndroid3/res/drawable/"
+
 static void lok_docview_class_init( LOKDocViewClass* pClass );
 static void lok_docview_init( LOKDocView* pDocView );
 static float pixelToTwip(float nInput);
@@ -204,6 +207,32 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpoint
                         twipToPixel(pDocView->m_aVisibleCursor.width),
                         twipToPixel(pDocView->m_aVisibleCursor.height));
         cairo_fill(pCairo);
+
+    }
+
+    if (!lcl_isEmptyRectangle(&pDocView->m_aVisibleCursor) && !pDocView->m_pTextSelectionRectangles)
+    {
+        // Have a cursor, but no selection: we need the middle handle.
+        GdkPoint aCursorBottom;
+        cairo_surface_t* pSurface;
+        int nHandleWidth, nHandleHeight;
+        double fHandleScale;
+
+        pSurface = cairo_image_surface_create_from_png(CURSOR_HANDLE_DIR "handle_middle.png");
+        nHandleWidth = cairo_image_surface_get_width(pSurface);
+        nHandleHeight = cairo_image_surface_get_height(pSurface);
+        // We want to scale down the handle, so that its height is the same as the cursor caret.
+        fHandleScale = twipToPixel(pDocView->m_aVisibleCursor.height) / nHandleHeight;
+        // We want the top center of the handle bitmap to be at the bottom center of the cursor rectangle.
+        aCursorBottom.x = twipToPixel(pDocView->m_aVisibleCursor.x) + twipToPixel(pDocView->m_aVisibleCursor.width) / 2 - (nHandleWidth * fHandleScale) / 2;
+        aCursorBottom.y = twipToPixel(pDocView->m_aVisibleCursor.y) + twipToPixel(pDocView->m_aVisibleCursor.height);
+        cairo_save(pCairo);
+        cairo_translate(pCairo, aCursorBottom.x, aCursorBottom.y);
+        cairo_scale(pCairo, fHandleScale, fHandleScale);
+        cairo_set_source_surface(pCairo, pSurface, 0, 0);
+        cairo_paint(pCairo);
+        cairo_surface_destroy(pSurface);
+        cairo_restore(pCairo);
     }
 
     if (pDocView->m_pTextSelectionRectangles)


More information about the Libreoffice-commits mailing list