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

Miklos Vajna vmiklos at collabora.co.uk
Wed Mar 25 02:07:56 PDT 2015


 libreofficekit/source/gtk/lokdocview.cxx |  175 +++++++++++++------------------
 1 file changed, 74 insertions(+), 101 deletions(-)

New commits:
commit ce9581624feecec1ddf0c41964321011fbd535eb
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Mar 25 10:06:28 2015 +0100

    lokdocview: always use zoom factor when doing twips <-> pixel conversion
    
    Change-Id: I81ce20c54bb62bec68152ca228eb222f3fd3c597

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index f0ac06f..fa44b1d 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -29,6 +29,9 @@
 // Number of handles around a graphic selection.
 #define GRAPHIC_HANDLE_COUNT 8
 
+// We know that VirtualDevices use a DPI of 96.
+static const int DPI = 96;
+
 /// Holds data used by LOKDocView only.
 struct LOKDocView_Impl
 {
@@ -97,6 +100,10 @@ struct LOKDocView_Impl
     ~LOKDocView_Impl();
     /// Connected to the destroy signal of LOKDocView, deletes its LOKDocView_Impl.
     static void destroy(LOKDocView* pDocView, gpointer pData);
+    /// Converts from screen pixels to document coordinates.
+    float pixelToTwip(float fInput);
+    /// Converts from document coordinates to screen pixels.
+    float twipToPixel(float fInput);
 };
 
 LOKDocView_Impl::LOKDocView_Impl()
@@ -149,9 +156,18 @@ void LOKDocView_Impl::destroy(LOKDocView* pDocView, gpointer /*pData*/)
     delete pDocView->m_pImpl;
 }
 
+float LOKDocView_Impl::pixelToTwip(float fInput)
+{
+    return (fInput / DPI / m_fZoom) * 1440.0f;
+}
+
+float LOKDocView_Impl::twipToPixel(float fInput)
+{
+    return fInput / 1440.0f * DPI * m_fZoom;
+}
+
 static void lok_docview_class_init( gpointer );
 static void lok_docview_init( GTypeInstance *, gpointer );
-static float pixelToTwip(float nInput);
 static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpointer pData);
 
 /**
@@ -187,7 +203,7 @@ gboolean lcl_signalMotion(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
         lcl_getDragPoint(&pDocView->m_pImpl->m_aHandleMiddleRect, pEvent, &aPoint);
         pDocView->m_pImpl->m_pDocument->pClass->setTextSelection(
                 pDocView->m_pImpl->m_pDocument, LOK_SETTEXTSELECTION_RESET,
-                pixelToTwip(aPoint.x) / pDocView->m_pImpl->m_fZoom, pixelToTwip(aPoint.y) / pDocView->m_pImpl->m_fZoom);
+                pDocView->m_pImpl->pixelToTwip(aPoint.x), pDocView->m_pImpl->pixelToTwip(aPoint.y));
         return FALSE;
     }
     if (pDocView->m_pImpl->m_bInDragStartHandle)
@@ -196,7 +212,7 @@ gboolean lcl_signalMotion(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
         lcl_getDragPoint(&pDocView->m_pImpl->m_aHandleStartRect, pEvent, &aPoint);
         pDocView->m_pImpl->m_pDocument->pClass->setTextSelection(
                 pDocView->m_pImpl->m_pDocument, LOK_SETTEXTSELECTION_START,
-                pixelToTwip(aPoint.x) / pDocView->m_pImpl->m_fZoom, pixelToTwip(aPoint.y) / pDocView->m_pImpl->m_fZoom);
+                pDocView->m_pImpl->pixelToTwip(aPoint.x), pDocView->m_pImpl->pixelToTwip(aPoint.y));
         return FALSE;
     }
     if (pDocView->m_pImpl->m_bInDragEndHandle)
@@ -205,7 +221,7 @@ gboolean lcl_signalMotion(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
         lcl_getDragPoint(&pDocView->m_pImpl->m_aHandleEndRect, pEvent, &aPoint);
         pDocView->m_pImpl->m_pDocument->pClass->setTextSelection(
                 pDocView->m_pImpl->m_pDocument, LOK_SETTEXTSELECTION_END,
-                pixelToTwip(aPoint.x) / pDocView->m_pImpl->m_fZoom, pixelToTwip(aPoint.y) / pDocView->m_pImpl->m_fZoom);
+                pDocView->m_pImpl->pixelToTwip(aPoint.x), pDocView->m_pImpl->pixelToTwip(aPoint.y));
         return FALSE;
     }
     for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
@@ -223,8 +239,8 @@ gboolean lcl_signalMotion(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
     }
 
     GdkRectangle aMotionInTwipsInTwips;
-    aMotionInTwipsInTwips.x = pixelToTwip(pEvent->x) / pDocView->m_pImpl->m_fZoom;
-    aMotionInTwipsInTwips.y = pixelToTwip(pEvent->y) / pDocView->m_pImpl->m_fZoom;
+    aMotionInTwipsInTwips.x = pDocView->m_pImpl->pixelToTwip(pEvent->x);
+    aMotionInTwipsInTwips.y = pDocView->m_pImpl->pixelToTwip(pEvent->y);
     aMotionInTwipsInTwips.width = 1;
     aMotionInTwipsInTwips.height = 1;
     if (gdk_rectangle_intersect(&aMotionInTwipsInTwips, &pDocView->m_pImpl->m_aGraphicSelection, 0))
@@ -233,8 +249,8 @@ gboolean lcl_signalMotion(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
         pDocView->m_pImpl->m_bInDragGraphicSelection = true;
         pDocView->m_pImpl->m_pDocument->pClass->setGraphicSelection(
             pDocView->m_pImpl->m_pDocument, LOK_SETGRAPHICSELECTION_START,
-            pixelToTwip(pEvent->x) / pDocView->m_pImpl->m_fZoom,
-            pixelToTwip(pEvent->y) / pDocView->m_pImpl->m_fZoom);
+            pDocView->m_pImpl->pixelToTwip(pEvent->x),
+            pDocView->m_pImpl->pixelToTwip(pEvent->y));
         return FALSE;
     }
 
@@ -244,7 +260,7 @@ gboolean lcl_signalMotion(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
 /// Receives a button press event.
 gboolean lcl_signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKDocView* pDocView)
 {
-    g_info("lcl_signalButton: %d, %d (in twips: %d, %d)", (int)pEvent->x, (int)pEvent->y, (int)pixelToTwip(pEvent->x), (int)pixelToTwip(pEvent->y));
+    g_info("lcl_signalButton: %d, %d (in twips: %d, %d)", (int)pEvent->x, (int)pEvent->y, (int)pDocView->m_pImpl->pixelToTwip(pEvent->x), (int)pDocView->m_pImpl->pixelToTwip(pEvent->y));
 
     if (pEvent->type == GDK_BUTTON_RELEASE)
     {
@@ -275,7 +291,7 @@ gboolean lcl_signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
                 pDocView->m_pImpl->m_bInDragGraphicHandles[i] = false;
                 pDocView->m_pImpl->m_pDocument->pClass->setGraphicSelection(
                     pDocView->m_pImpl->m_pDocument, LOK_SETGRAPHICSELECTION_END,
-                    pixelToTwip(pEvent->x) / pDocView->m_pImpl->m_fZoom, pixelToTwip(pEvent->y) / pDocView->m_pImpl->m_fZoom);
+                    pDocView->m_pImpl->pixelToTwip(pEvent->x), pDocView->m_pImpl->pixelToTwip(pEvent->y));
                 return FALSE;
             }
         }
@@ -286,8 +302,8 @@ gboolean lcl_signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
             pDocView->m_pImpl->m_bInDragGraphicSelection = false;
             pDocView->m_pImpl->m_pDocument->pClass->setGraphicSelection(
                 pDocView->m_pImpl->m_pDocument, LOK_SETGRAPHICSELECTION_END,
-                pixelToTwip(pEvent->x) / pDocView->m_pImpl->m_fZoom,
-                pixelToTwip(pEvent->y) / pDocView->m_pImpl->m_fZoom);
+                pDocView->m_pImpl->pixelToTwip(pEvent->x),
+                pDocView->m_pImpl->pixelToTwip(pEvent->y));
             return FALSE;
         }
     }
@@ -328,8 +344,8 @@ gboolean lcl_signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
                     pDocView->m_pImpl->m_bInDragGraphicHandles[i] = true;
                     pDocView->m_pImpl->m_pDocument->pClass->setGraphicSelection(
                         pDocView->m_pImpl->m_pDocument, LOK_SETGRAPHICSELECTION_START,
-                        pixelToTwip(pDocView->m_pImpl->m_aGraphicHandleRects[i].x + pDocView->m_pImpl->m_aGraphicHandleRects[i].width / 2) / pDocView->m_pImpl->m_fZoom,
-                        pixelToTwip(pDocView->m_pImpl->m_aGraphicHandleRects[i].y + pDocView->m_pImpl->m_aGraphicHandleRects[i].height / 2) / pDocView->m_pImpl->m_fZoom);
+                        pDocView->m_pImpl->pixelToTwip(pDocView->m_pImpl->m_aGraphicHandleRects[i].x + pDocView->m_pImpl->m_aGraphicHandleRects[i].width / 2),
+                        pDocView->m_pImpl->pixelToTwip(pDocView->m_pImpl->m_aGraphicHandleRects[i].y + pDocView->m_pImpl->m_aGraphicHandleRects[i].height / 2));
                     return FALSE;
                 }
             }
@@ -349,8 +365,8 @@ gboolean lcl_signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
         pDocView->m_pImpl->m_nLastButtonPressTime = pEvent->time;
         pDocView->m_pImpl->m_pDocument->pClass->postMouseEvent(
                 pDocView->m_pImpl->m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN,
-                pixelToTwip(pEvent->x) / pDocView->m_pImpl->m_fZoom,
-                pixelToTwip(pEvent->y) / pDocView->m_pImpl->m_fZoom, nCount);
+                pDocView->m_pImpl->pixelToTwip(pEvent->x),
+                pDocView->m_pImpl->pixelToTwip(pEvent->y), nCount);
         break;
     }
     case GDK_BUTTON_RELEASE:
@@ -361,8 +377,8 @@ gboolean lcl_signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
         pDocView->m_pImpl->m_nLastButtonReleaseTime = pEvent->time;
         pDocView->m_pImpl->m_pDocument->pClass->postMouseEvent(
                 pDocView->m_pImpl->m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP,
-                pixelToTwip(pEvent->x) / pDocView->m_pImpl->m_fZoom,
-                pixelToTwip(pEvent->y) / pDocView->m_pImpl->m_fZoom, nCount);
+                pDocView->m_pImpl->pixelToTwip(pEvent->x),
+                pDocView->m_pImpl->pixelToTwip(pEvent->y), nCount);
         break;
     }
     default:
@@ -451,21 +467,6 @@ SAL_DLLPUBLIC_EXPORT GtkWidget* lok_docview_new( LibreOfficeKit* pOffice )
     return GTK_WIDGET( pDocView );
 }
 
-// We know that VirtualDevices use a DPI of 96.
-static const int g_nDPI = 96;
-
-/// Converts from document coordinates to screen pixels.
-static float twipToPixel(float nInput)
-{
-    return nInput / 1440.0f * g_nDPI;
-}
-
-/// Converts from screen pixels to document coordinates
-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;
@@ -490,7 +491,7 @@ static gboolean lcl_handleTimeout(gpointer pData)
 
 /// Renders pHandle below a pCursor rectangle on pCairo.
 static void lcl_renderHandle(cairo_t* pCairo, GdkRectangle* pCursor, cairo_surface_t* pHandle,
-                             GdkRectangle* pRectangle, float fZoom)
+                             GdkRectangle* pRectangle, LOKDocView* pDocView)
 {
     GdkPoint aCursorBottom;
     int nHandleWidth, nHandleHeight;
@@ -499,10 +500,10 @@ static void lcl_renderHandle(cairo_t* pCairo, GdkRectangle* pCursor, cairo_surfa
     nHandleWidth = cairo_image_surface_get_width(pHandle);
     nHandleHeight = cairo_image_surface_get_height(pHandle);
     // We want to scale down the handle, so that its height is the same as the cursor caret.
-    fHandleScale = twipToPixel(pCursor->height) * fZoom / nHandleHeight;
+    fHandleScale = pDocView->m_pImpl->twipToPixel(pCursor->height) / nHandleHeight;
     // We want the top center of the handle bitmap to be at the bottom center of the cursor rectangle.
-    aCursorBottom.x = twipToPixel(pCursor->x) * fZoom + twipToPixel(pCursor->width) * fZoom / 2 - (nHandleWidth * fHandleScale) / 2;
-    aCursorBottom.y = twipToPixel(pCursor->y) * fZoom + twipToPixel(pCursor->height) * fZoom;
+    aCursorBottom.x = pDocView->m_pImpl->twipToPixel(pCursor->x) + pDocView->m_pImpl->twipToPixel(pCursor->width) / 2 - (nHandleWidth * fHandleScale) / 2;
+    aCursorBottom.y = pDocView->m_pImpl->twipToPixel(pCursor->y) + pDocView->m_pImpl->twipToPixel(pCursor->height);
     cairo_save(pCairo);
     cairo_translate(pCairo, aCursorBottom.x, aCursorBottom.y);
     cairo_scale(pCairo, fHandleScale, fHandleScale);
@@ -521,7 +522,7 @@ 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, GdkRectangle* pGraphicHandleRects, float fZoom)
+static void lcl_renderGraphicHandle(cairo_t* pCairo, GdkRectangle* pSelection, cairo_surface_t* pHandle, GdkRectangle* pGraphicHandleRects, LOKDocView* pDocView)
 {
     int nHandleWidth, nHandleHeight;
     GdkRectangle aSelection;
@@ -529,10 +530,10 @@ static void lcl_renderGraphicHandle(cairo_t* pCairo, GdkRectangle* pSelection, c
     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;
+    aSelection.x = pDocView->m_pImpl->twipToPixel(pSelection->x);
+    aSelection.y = pDocView->m_pImpl->twipToPixel(pSelection->y);
+    aSelection.width = pDocView->m_pImpl->twipToPixel(pSelection->width);
+    aSelection.height = pDocView->m_pImpl->twipToPixel(pSelection->height);
 
     for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
     {
@@ -599,10 +600,10 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* /*pEvent*/, gp
 
         cairo_set_source_rgb(pCairo, 0, 0, 0);
         cairo_rectangle(pCairo,
-                        twipToPixel(pDocView->m_pImpl->m_aVisibleCursor.x) * pDocView->m_pImpl->m_fZoom,
-                        twipToPixel(pDocView->m_pImpl->m_aVisibleCursor.y) * pDocView->m_pImpl->m_fZoom,
-                        twipToPixel(pDocView->m_pImpl->m_aVisibleCursor.width) * pDocView->m_pImpl->m_fZoom,
-                        twipToPixel(pDocView->m_pImpl->m_aVisibleCursor.height) * pDocView->m_pImpl->m_fZoom);
+                        pDocView->m_pImpl->twipToPixel(pDocView->m_pImpl->m_aVisibleCursor.x),
+                        pDocView->m_pImpl->twipToPixel(pDocView->m_pImpl->m_aVisibleCursor.y),
+                        pDocView->m_pImpl->twipToPixel(pDocView->m_pImpl->m_aVisibleCursor.width),
+                        pDocView->m_pImpl->twipToPixel(pDocView->m_pImpl->m_aVisibleCursor.height));
         cairo_fill(pCairo);
     }
 
@@ -613,7 +614,7 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* /*pEvent*/, gp
             pDocView->m_pImpl->m_pHandleMiddle = cairo_image_surface_create_from_png(CURSOR_HANDLE_DIR "handle_middle.png");
         lcl_renderHandle(pCairo, &pDocView->m_pImpl->m_aVisibleCursor,
                          pDocView->m_pImpl->m_pHandleMiddle, &pDocView->m_pImpl->m_aHandleMiddleRect,
-                         pDocView->m_pImpl->m_fZoom);
+                         pDocView);
     }
 
     if (pDocView->m_pImpl->m_pTextSelectionRectangles)
@@ -624,10 +625,10 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* /*pEvent*/, gp
             // Blue with 75% transparency.
             cairo_set_source_rgba(pCairo, ((double)0x43)/255, ((double)0xac)/255, ((double)0xe8)/255, 0.25);
             cairo_rectangle(pCairo,
-                            twipToPixel(pRectangle->x) * pDocView->m_pImpl->m_fZoom,
-                            twipToPixel(pRectangle->y) * pDocView->m_pImpl->m_fZoom,
-                            twipToPixel(pRectangle->width) * pDocView->m_pImpl->m_fZoom,
-                            twipToPixel(pRectangle->height) * pDocView->m_pImpl->m_fZoom);
+                            pDocView->m_pImpl->twipToPixel(pRectangle->x),
+                            pDocView->m_pImpl->twipToPixel(pRectangle->y),
+                            pDocView->m_pImpl->twipToPixel(pRectangle->width),
+                            pDocView->m_pImpl->twipToPixel(pRectangle->height));
             cairo_fill(pCairo);
         }
 
@@ -639,7 +640,7 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* /*pEvent*/, gp
                 pDocView->m_pImpl->m_pHandleStart = cairo_image_surface_create_from_png(CURSOR_HANDLE_DIR "handle_start.png");
             lcl_renderHandle(pCairo, &pDocView->m_pImpl->m_aTextSelectionStart,
                              pDocView->m_pImpl->m_pHandleStart, &pDocView->m_pImpl->m_aHandleStartRect,
-                             pDocView->m_pImpl->m_fZoom);
+                             pDocView);
         }
         if (!lcl_isEmptyRectangle(&pDocView->m_pImpl->m_aTextSelectionEnd))
         {
@@ -648,7 +649,7 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* /*pEvent*/, gp
                 pDocView->m_pImpl->m_pHandleEnd = cairo_image_surface_create_from_png(CURSOR_HANDLE_DIR "handle_end.png");
             lcl_renderHandle(pCairo, &pDocView->m_pImpl->m_aTextSelectionEnd,
                              pDocView->m_pImpl->m_pHandleEnd, &pDocView->m_pImpl->m_aHandleEndRect,
-                             pDocView->m_pImpl->m_fZoom);
+                             pDocView);
         }
     }
 
@@ -656,7 +657,7 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* /*pEvent*/, gp
     {
         if (!pDocView->m_pImpl->m_pGraphicHandle)
             pDocView->m_pImpl->m_pGraphicHandle = cairo_image_surface_create_from_png(CURSOR_HANDLE_DIR "handle_graphic.png");
-        lcl_renderGraphicHandle(pCairo, &pDocView->m_pImpl->m_aGraphicSelection, pDocView->m_pImpl->m_pGraphicHandle, pDocView->m_pImpl->m_aGraphicHandleRects, pDocView->m_pImpl->m_fZoom);
+        lcl_renderGraphicHandle(pCairo, &pDocView->m_pImpl->m_aGraphicSelection, pDocView->m_pImpl->m_pGraphicHandle, pDocView->m_pImpl->m_aGraphicHandleRects, pDocView);
     }
 
     cairo_destroy(pCairo);
@@ -671,8 +672,8 @@ void renderDocument(LOKDocView* pDocView, GdkRectangle* pPartial)
     // Get document size and find out how many rows / columns we need.
     long nDocumentWidthTwips, nDocumentHeightTwips;
     pDocView->m_pImpl->m_pDocument->pClass->getDocumentSize(pDocView->m_pImpl->m_pDocument, &nDocumentWidthTwips, &nDocumentHeightTwips);
-    long nDocumentWidthPixels = twipToPixel(nDocumentWidthTwips) * pDocView->m_pImpl->m_fZoom;
-    long nDocumentHeightPixels = twipToPixel(nDocumentHeightTwips) * pDocView->m_pImpl->m_fZoom;
+    long nDocumentWidthPixels = pDocView->m_pImpl->twipToPixel(nDocumentWidthTwips);
+    long nDocumentHeightPixels = pDocView->m_pImpl->twipToPixel(nDocumentHeightTwips);
     // Total number of rows / columns in this document.
     guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
     guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
@@ -725,10 +726,10 @@ void renderDocument(LOKDocView* pDocView, GdkRectangle* pPartial)
                 aTileRectanglePixels.height = nTileSizePixels;
 
             // Determine size and position of the tile in document coordinates, so we can decide if we can skip painting for partial rendering.
-            aTileRectangleTwips.x = pixelToTwip(nTileSizePixels) / pDocView->m_pImpl->m_fZoom * nColumn;
-            aTileRectangleTwips.y = pixelToTwip(nTileSizePixels) / pDocView->m_pImpl->m_fZoom * nRow;
-            aTileRectangleTwips.width = pixelToTwip(aTileRectanglePixels.width) / pDocView->m_pImpl->m_fZoom;
-            aTileRectangleTwips.height = pixelToTwip(aTileRectanglePixels.height) / pDocView->m_pImpl->m_fZoom;
+            aTileRectangleTwips.x = pDocView->m_pImpl->pixelToTwip(nTileSizePixels) * nColumn;
+            aTileRectangleTwips.y = pDocView->m_pImpl->pixelToTwip(nTileSizePixels) * nRow;
+            aTileRectangleTwips.width = pDocView->m_pImpl->pixelToTwip(aTileRectanglePixels.width);
+            aTileRectangleTwips.height = pDocView->m_pImpl->pixelToTwip(aTileRectanglePixels.height);
             if (pPartial && !gdk_rectangle_intersect(pPartial, &aTileRectangleTwips, 0))
                     bPaint = false;
 
commit 1d9a33e2aed1c8fa1a0aba6e9882098c09b36ecf
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Mar 25 09:14:24 2015 +0100

    lokdocview: sync graphic move behavior with Android
    
    Android behavior is: if there is a graphic selection, then drag inside
    the shape is a move.
    
    lokdocivew behavior was: drag on the border of a graphic selection is a
    move, but inside, it's just a pair of clicks.
    
    Since commit 658534d36f87f9ab03d862e57b04ea268b73ccab (SdrMarkView tiled
    rendering: suppress handles during text edit, 2015-03-19), we can depend
    on the availability of the handles to decide if we want to move the
    shape or do text editing, so do the same in lokdocview as well.
    
    Change-Id: I2b105089e9acbbda75568622d4f2b1adecfe08f1

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 35b23a2..f0ac06f 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -221,38 +221,24 @@ gboolean lcl_signalMotion(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
         g_info("lcl_signalMotion: dragging the graphic selection");
         return FALSE;
     }
-    return FALSE;
-}
 
-/// Is pClick on the border of pDocView->m_aGraphicSelection?
-bool lcl_isOnBorders(LOKDocView* pDocView, GdkPoint* pClick)
-{
-    // Handles are on the corners / edges of the shape:
-    // Let aSelection be the bounding box of all handles (a bit larger than the graphic selection).
-    int nHandleWidth = pixelToTwip(pDocView->m_pImpl->m_aGraphicHandleRects[0].width) / pDocView->m_pImpl->m_fZoom;
-    int nHandleHeight = pixelToTwip(pDocView->m_pImpl->m_aGraphicHandleRects[0].height) / pDocView->m_pImpl->m_fZoom;
-    GdkRectangle aSelection;
-    aSelection.x = pDocView->m_pImpl->m_aGraphicSelection.x - nHandleWidth / 2;
-    aSelection.y = pDocView->m_pImpl->m_aGraphicSelection.y - nHandleHeight / 2;
-    aSelection.width = pDocView->m_pImpl->m_aGraphicSelection.width + nHandleWidth;
-    aSelection.height = pDocView->m_pImpl->m_aGraphicSelection.height + nHandleHeight;
-    GdkRegion* pSelection = gdk_region_rectangle(&aSelection);
-
-    // Let aInsideBorder be the shape without the handles (a bit smaller than the graphic selection).
-    GdkRectangle aInsideBorder;
-    aInsideBorder.x = pDocView->m_pImpl->m_aGraphicSelection.x + nHandleWidth / 2;
-    aInsideBorder.y = pDocView->m_pImpl->m_aGraphicSelection.y + nHandleHeight / 2;
-    aInsideBorder.width = pDocView->m_pImpl->m_aGraphicSelection.width - nHandleWidth;
-    aInsideBorder.height = pDocView->m_pImpl->m_aGraphicSelection.height - nHandleHeight;
-    GdkRegion* pInsideBorder = gdk_region_rectangle(&aInsideBorder);
-
-    // Did we click on the border?
-    gdk_region_subtract(pSelection, pInsideBorder);
-    bool bRet = gdk_region_point_in(pSelection, pClick->x, pClick->y);
-
-    gdk_region_destroy(pInsideBorder);
-    gdk_region_destroy(pSelection);
-    return bRet;
+    GdkRectangle aMotionInTwipsInTwips;
+    aMotionInTwipsInTwips.x = pixelToTwip(pEvent->x) / pDocView->m_pImpl->m_fZoom;
+    aMotionInTwipsInTwips.y = pixelToTwip(pEvent->y) / pDocView->m_pImpl->m_fZoom;
+    aMotionInTwipsInTwips.width = 1;
+    aMotionInTwipsInTwips.height = 1;
+    if (gdk_rectangle_intersect(&aMotionInTwipsInTwips, &pDocView->m_pImpl->m_aGraphicSelection, 0))
+    {
+        g_info("lcl_signalMotion: start of drag graphic selection");
+        pDocView->m_pImpl->m_bInDragGraphicSelection = true;
+        pDocView->m_pImpl->m_pDocument->pClass->setGraphicSelection(
+            pDocView->m_pImpl->m_pDocument, LOK_SETGRAPHICSELECTION_START,
+            pixelToTwip(pEvent->x) / pDocView->m_pImpl->m_fZoom,
+            pixelToTwip(pEvent->y) / pDocView->m_pImpl->m_fZoom);
+        return FALSE;
+    }
+
+    return FALSE;
 }
 
 /// Receives a button press event.
@@ -347,20 +333,6 @@ gboolean lcl_signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD
                     return FALSE;
                 }
             }
-
-            GdkPoint aClickInTwips;
-            aClickInTwips.x = pixelToTwip(pEvent->x) / pDocView->m_pImpl->m_fZoom;
-            aClickInTwips.y = pixelToTwip(pEvent->y) / pDocView->m_pImpl->m_fZoom;
-            if (lcl_isOnBorders(pDocView, &aClickInTwips))
-            {
-                g_info("lcl_signalButton: start of drag graphic selection");
-                pDocView->m_pImpl->m_bInDragGraphicSelection = true;
-                pDocView->m_pImpl->m_pDocument->pClass->setGraphicSelection(
-                    pDocView->m_pImpl->m_pDocument, LOK_SETGRAPHICSELECTION_START,
-                    pixelToTwip(pEvent->x) / pDocView->m_pImpl->m_fZoom,
-                    pixelToTwip(pEvent->y) / pDocView->m_pImpl->m_fZoom);
-                return FALSE;
-            }
         }
     }
 


More information about the Libreoffice-commits mailing list