summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-02-10 18:19:32 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-02-16 09:20:48 +0100
commitbe77714263eff4a6e60d192bd87dc5309a23fae0 (patch)
tree8ae9b8d7b82a717f97bd5229d346fc5adcbb5095
parent565a9f3fd8333e14497f058f9e4387e511aa36c9 (diff)
lokdocview: allow dragging the selection end handle
Change-Id: I977e93657c52a66f10762293835ead28451b5406
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitGtk.h4
-rw-r--r--libreofficekit/source/gtk/lokdocview.c61
2 files changed, 52 insertions, 13 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 95288cd9557b..40ce630dad72 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -66,6 +66,10 @@ struct _LOKDocView
gboolean m_bInDragMiddleHandle;
/// Bitmap of the text selection end handle.
cairo_surface_t* m_pHandleEnd;
+ /// Rectangle of the text selection end handle, to know if the user clicked on it or not
+ GdkRectangle m_aHandleEndRect;
+ /// If we are in the middle of a drag of the text selection end handle.
+ gboolean m_bInDragEndHandle;
};
struct _LOKDocViewClass
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index 0fa3e11265d9..c18ccc0cf6f5 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -42,28 +42,49 @@ void lcl_onDestroy( LOKDocView* pDocView, gpointer pData )
pDocView->pDocument = NULL;
}
+/**
+ * The user drags the handle, which is below the cursor, but wants to move the
+ * cursor accordingly.
+ *
+ * @param pHandle the rectangle of the handle
+ * @param pEvent the motion event
+ * @param pPoint the computed point (output parameter)
+ */
+void lcl_getDragPoint(GdkRectangle* pHandle, GdkEventButton* pEvent, GdkPoint* pPoint)
+{
+ GdkPoint aCursor, aHandle;
+
+ // Center of the cursor rectangle: we know that it's above the handle.
+ aCursor.x = pHandle->x + pHandle->width / 2;
+ aCursor.y = pHandle->y - pHandle->height / 2;
+ // Center of the handle rectangle.
+ aHandle.x = pHandle->x + pHandle->width / 2;
+ aHandle.y = pHandle->y + pHandle->height / 2;
+ // Our target is the original cursor position + the dragged offset.
+ pPoint->x = aCursor.x + (pEvent->x - aHandle.x);
+ pPoint->y = aCursor.y + (pEvent->y - aHandle.y);
+}
+
gboolean lcl_signalMotion(GtkWidget* pEventBox, GdkEventButton* pEvent, LOKDocView* pDocView)
{
(void)pEventBox;
if (pDocView->m_bInDragMiddleHandle)
{
- // The user drags the handle, which is below the cursor, but wants to move the cursor accordingly.
- GdkPoint aCursor, aHandle, aPoint;
+ GdkPoint aPoint;
g_info("lcl_signalMotion: dragging the middle handle");
- // Center of the cursor rectangle: we know that it's above the handle.
- aCursor.x = pDocView->m_aHandleMiddleRect.x + pDocView->m_aHandleMiddleRect.width / 2;
- aCursor.y = pDocView->m_aHandleMiddleRect.y - pDocView->m_aHandleMiddleRect.height / 2;
- // Center of the handle rectangle.
- aHandle.x = pDocView->m_aHandleMiddleRect.x + pDocView->m_aHandleMiddleRect.width / 2;
- aHandle.y = pDocView->m_aHandleMiddleRect.y + pDocView->m_aHandleMiddleRect.height / 2;
- // Our target is the original cursor position + the dragged offset.
- aPoint.x = aCursor.x + (pEvent->x - aHandle.x);
- aPoint.y = aCursor.y + (pEvent->y - aHandle.y);
-
+ lcl_getDragPoint(&pDocView->m_aHandleMiddleRect, pEvent, &aPoint);
pDocView->pDocument->pClass->postMouseEvent(pDocView->pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, pixelToTwip(aPoint.x), pixelToTwip(aPoint.y), 1);
pDocView->pDocument->pClass->postMouseEvent(pDocView->pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, pixelToTwip(aPoint.x), pixelToTwip(aPoint.y), 1);
}
+ else if (pDocView->m_bInDragEndHandle)
+ {
+ GdkPoint aPoint;
+
+ g_info("lcl_signalMotion: dragging the end handle");
+ lcl_getDragPoint(&pDocView->m_aHandleEndRect, pEvent, &aPoint);
+ pDocView->pDocument->pClass->setTextSelection(pDocView->pDocument, LOK_SETTEXTSELECTION_END, pixelToTwip(aPoint.x), pixelToTwip(aPoint.y));
+ }
return FALSE;
}
@@ -79,6 +100,12 @@ gboolean lcl_signalButton(GtkWidget* pEventBox, GdkEventButton* pEvent, LOKDocVi
pDocView->m_bInDragMiddleHandle = FALSE;
return FALSE;
}
+ else if (pDocView->m_bInDragEndHandle && pEvent->type == GDK_BUTTON_RELEASE)
+ {
+ g_info("lcl_signalButton: end of drag end handle");
+ pDocView->m_bInDragEndHandle = FALSE;
+ return FALSE;
+ }
if (pDocView->m_bEdit)
{
@@ -93,6 +120,12 @@ gboolean lcl_signalButton(GtkWidget* pEventBox, GdkEventButton* pEvent, LOKDocVi
pDocView->m_bInDragMiddleHandle = TRUE;
return FALSE;
}
+ else if (gdk_rectangle_intersect(&aClick, &pDocView->m_aHandleEndRect, NULL) && pEvent->type == GDK_BUTTON_PRESS)
+ {
+ g_info("lcl_signalButton: start of drag end handle");
+ pDocView->m_bInDragEndHandle = TRUE;
+ return FALSE;
+ }
}
lok_docview_set_edit(pDocView, TRUE);
@@ -191,6 +224,8 @@ static void lok_docview_init( LOKDocView* pDocView )
pDocView->m_pHandleEnd = NULL;
memset(&pDocView->m_aHandleMiddleRect, 0, sizeof(pDocView->m_aHandleMiddleRect));
pDocView->m_bInDragMiddleHandle = FALSE;
+ memset(&pDocView->m_aHandleEndRect, 0, sizeof(pDocView->m_aHandleEndRect));
+ pDocView->m_bInDragEndHandle = FALSE;
gtk_signal_connect( GTK_OBJECT(pDocView), "destroy",
GTK_SIGNAL_FUNC(lcl_onDestroy), NULL );
@@ -332,7 +367,7 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpoint
// Have a start position: we need an end handle.
if (!pDocView->m_pHandleEnd)
pDocView->m_pHandleEnd = cairo_image_surface_create_from_png(CURSOR_HANDLE_DIR "handle_end.png");
- lcl_renderHandle(pCairo, &pDocView->m_aTextSelectionEnd, pDocView->m_pHandleEnd, NULL);
+ lcl_renderHandle(pCairo, &pDocView->m_aTextSelectionEnd, pDocView->m_pHandleEnd, &pDocView->m_aHandleEndRect);
}
}