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

Miklos Vajna vmiklos at collabora.co.uk
Thu Mar 5 05:16:30 PST 2015


 android/experimental/LOAndroid3/res/drawable/handle_graphic.png |binary
 include/LibreOfficeKit/LibreOfficeKitGtk.h                      |    2 
 libreofficekit/source/gtk/lokdocview.c                          |   66 ++++++++++
 3 files changed, 68 insertions(+)

New commits:
commit 90468907633c3d5729c42aa294b3e77d0db79206
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Mar 5 14:15:54 2015 +0100

    lokdocview: render graphic selection handles
    
    Change-Id: I8c1331c32baf92b077f45678929df0e4cf185774

diff --git a/android/experimental/LOAndroid3/res/drawable/handle_graphic.png b/android/experimental/LOAndroid3/res/drawable/handle_graphic.png
new file mode 100644
index 0000000..7317eee
Binary files /dev/null and b/android/experimental/LOAndroid3/res/drawable/handle_graphic.png differ
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 595f888..ae0aa0e 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -81,6 +81,8 @@ struct _LOKDocView
     /// If we are in the middle of a drag of the text selection end handle.
     gboolean m_bInDragEndHandle;
     ///@}
+
+    cairo_surface_t* m_pGraphicHandle;
 };
 
 struct _LOKDocViewClass
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index 2ab8577..a6108bd 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -266,6 +266,8 @@ static void lok_docview_init( LOKDocView* pDocView )
     memset(&pDocView->m_aHandleEndRect, 0, sizeof(pDocView->m_aHandleEndRect));
     pDocView->m_bInDragEndHandle = FALSE;
 
+    pDocView->m_pGraphicHandle = NULL;
+
     gtk_signal_connect( GTK_OBJECT(pDocView), "destroy",
                         GTK_SIGNAL_FUNC(lcl_onDestroy), NULL );
     g_signal_connect_after(pDocView->pEventBox, "expose-event",
@@ -348,6 +350,67 @@ static void lcl_renderHandle(cairo_t* pCairo, GdkRectangle* pCursor, cairo_surfa
     }
 }
 
+/// Renders pHandle around a pSelection rectangle on pCairo.
+static void lcl_renderGraphicHandle(cairo_t* pCairo, GdkRectangle* pSelection, cairo_surface_t* pHandle, float fZoom)
+{
+    int nHandleWidth, nHandleHeight;
+    GdkRectangle aSelection;
+    int i;
+
+    nHandleWidth = cairo_image_surface_get_width(pHandle);
+    nHandleHeight = cairo_image_surface_get_height(pHandle);
+
+    aSelection.x = twipToPixel(pSelection->x) * fZoom;
+    aSelection.y = twipToPixel(pSelection->y) * fZoom;
+    aSelection.width = twipToPixel(pSelection->width) * fZoom;
+    aSelection.height = twipToPixel(pSelection->height) * fZoom;
+
+    for (i = 0; i < 8; ++i)
+    {
+        int x = aSelection.x, y = aSelection.y;
+        cairo_save(pCairo);
+
+        switch (i)
+        {
+        case 0: // top-left
+            break;
+        case 1: // top-middle
+            x += aSelection.width / 2;
+            break;
+        case 2: // top-right
+            x += aSelection.width;
+            break;
+        case 3: // middle-left
+            y += aSelection.height / 2;
+            break;
+        case 4: // middle-right
+            x += aSelection.width;
+            y += aSelection.height / 2;
+            break;
+        case 5: // bottom-left
+            y += aSelection.height;
+            break;
+        case 6: // bottom-middle
+            x += aSelection.width / 2;
+            y += aSelection.height;
+            break;
+        case 7: // bottom-right
+            x += aSelection.width;
+            y += aSelection.height;
+            break;
+        }
+
+        // Center the handle.
+        x -= nHandleWidth / 2;
+        y -= nHandleHeight / 2;
+
+        cairo_translate(pCairo, x, y);
+        cairo_set_source_surface(pCairo, pHandle, 0, 0);
+        cairo_paint(pCairo);
+        cairo_restore(pCairo);
+    }
+}
+
 static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpointer pData)
 {
 #if GTK_CHECK_VERSION(2,14,0) // we need gtk_widget_get_window()
@@ -423,6 +486,9 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpoint
 
     if (!lcl_isEmptyRectangle(&pDocView->m_aGraphicSelection))
     {
+        if (!pDocView->m_pGraphicHandle)
+            pDocView->m_pGraphicHandle = cairo_image_surface_create_from_png(CURSOR_HANDLE_DIR "handle_graphic.png");
+        lcl_renderGraphicHandle(pCairo, &pDocView->m_aGraphicSelection, pDocView->m_pGraphicHandle, pDocView->fZoom);
     }
 
     cairo_destroy(pCairo);


More information about the Libreoffice-commits mailing list