summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-03-10 10:12:02 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-03-16 09:38:03 +0100
commitd440dd241249efbd3f7357e38b1da5b2dd69d242 (patch)
tree012f4c30cb0bb0f8e56cff0f12f9bf3173aef362 /libreofficekit
parent65726aae458d5af0e438dd8494a9812770c06186 (diff)
lokdocview: use lok::Document::setGraphicSelection()
With this, it's now possible to resize images in Writer. Change-Id: I2f557d6a64efda54959627d21406aef85160e470
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/source/gtk/lokdocview.c56
1 files changed, 53 insertions, 3 deletions
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index 08c383134d70..0d62a5f8c0c4 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -26,6 +26,8 @@
// Cursor bitmaps from the Android app.
#define CURSOR_HANDLE_DIR "android/experimental/LOAndroid3/res/drawable/"
+// Number of handles around a graphic selection.
+#define GRAPHIC_HANDLE_COUNT 8
static void lok_docview_class_init( LOKDocViewClass* pClass );
static void lok_docview_init( LOKDocView* pDocView );
@@ -94,6 +96,16 @@ gboolean lcl_signalMotion(GtkWidget* pEventBox, GdkEventButton* pEvent, LOKDocVi
pDocView->pDocument, LOK_SETTEXTSELECTION_END,
pixelToTwip(aPoint.x) / pDocView->fZoom, pixelToTwip(aPoint.y) / pDocView->fZoom);
}
+ else
+ {
+ int i;
+
+ for (i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
+ {
+ if (pDocView->m_bInDragGraphicHandles[i])
+ g_info("lcl_signalButton: dragging the graphic handle #%d", i);
+ }
+ }
return FALSE;
}
@@ -105,6 +117,8 @@ gboolean lcl_signalButton(GtkWidget* pEventBox, GdkEventButton* pEvent, LOKDocVi
if (pEvent->type == GDK_BUTTON_RELEASE)
{
+ int i;
+
if (pDocView->m_bInDragStartHandle)
{
g_info("lcl_signalButton: end of drag start handle");
@@ -123,6 +137,19 @@ gboolean lcl_signalButton(GtkWidget* pEventBox, GdkEventButton* pEvent, LOKDocVi
pDocView->m_bInDragEndHandle = FALSE;
return FALSE;
}
+
+ for (i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
+ {
+ if (pDocView->m_bInDragGraphicHandles[i])
+ {
+ g_info("lcl_signalButton: end of drag graphic handle #%d", i);
+ pDocView->m_bInDragGraphicHandles[i] = FALSE;
+ pDocView->pDocument->pClass->setGraphicSelection(
+ pDocView->pDocument, LOK_SETGRAPHICSELECTION_END,
+ pixelToTwip(pEvent->x) / pDocView->fZoom, pixelToTwip(pEvent->y) / pDocView->fZoom);
+ return FALSE;
+ }
+ }
}
if (pDocView->m_bEdit)
@@ -134,6 +161,8 @@ gboolean lcl_signalButton(GtkWidget* pEventBox, GdkEventButton* pEvent, LOKDocVi
aClick.height = 1;
if (pEvent->type == GDK_BUTTON_PRESS)
{
+ int i;
+
if (gdk_rectangle_intersect(&aClick, &pDocView->m_aHandleStartRect, NULL))
{
g_info("lcl_signalButton: start of drag start handle");
@@ -152,6 +181,20 @@ gboolean lcl_signalButton(GtkWidget* pEventBox, GdkEventButton* pEvent, LOKDocVi
pDocView->m_bInDragEndHandle = TRUE;
return FALSE;
}
+
+ for (i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
+ {
+ if (gdk_rectangle_intersect(&aClick, &pDocView->m_aGraphicHandleRects[i], NULL))
+ {
+ g_info("lcl_signalButton: start of drag graphic handle #%d", i);
+ pDocView->m_bInDragGraphicHandles[i] = TRUE;
+ pDocView->pDocument->pClass->setGraphicSelection(
+ pDocView->pDocument, LOK_SETGRAPHICSELECTION_START,
+ pixelToTwip(pDocView->m_aGraphicHandleRects[i].x + pDocView->m_aGraphicHandleRects[i].width / 2) / pDocView->fZoom,
+ pixelToTwip(pDocView->m_aGraphicHandleRects[i].y + pDocView->m_aGraphicHandleRects[i].height / 2) / pDocView->fZoom);
+ return FALSE;
+ }
+ }
}
}
@@ -267,6 +310,8 @@ static void lok_docview_init( LOKDocView* pDocView )
pDocView->m_bInDragEndHandle = FALSE;
pDocView->m_pGraphicHandle = NULL;
+ memset(&pDocView->m_aGraphicHandleRects, 0, sizeof(pDocView->m_aGraphicHandleRects));
+ memset(&pDocView->m_bInDragGraphicHandles, 0, sizeof(pDocView->m_bInDragGraphicHandles));
gtk_signal_connect( GTK_OBJECT(pDocView), "destroy",
GTK_SIGNAL_FUNC(lcl_onDestroy), NULL );
@@ -351,7 +396,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, float fZoom)
+static void lcl_renderGraphicHandle(cairo_t* pCairo, GdkRectangle* pSelection, cairo_surface_t* pHandle, GdkRectangle* pGraphicHandleRects, float fZoom)
{
int nHandleWidth, nHandleHeight;
GdkRectangle aSelection;
@@ -365,7 +410,7 @@ static void lcl_renderGraphicHandle(cairo_t* pCairo, GdkRectangle* pSelection, c
aSelection.width = twipToPixel(pSelection->width) * fZoom;
aSelection.height = twipToPixel(pSelection->height) * fZoom;
- for (i = 0; i < 8; ++i)
+ for (i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
{
int x = aSelection.x, y = aSelection.y;
cairo_save(pCairo);
@@ -404,6 +449,11 @@ static void lcl_renderGraphicHandle(cairo_t* pCairo, GdkRectangle* pSelection, c
x -= nHandleWidth / 2;
y -= nHandleHeight / 2;
+ pGraphicHandleRects[i].x = x;
+ pGraphicHandleRects[i].y = y;
+ pGraphicHandleRects[i].width = nHandleWidth;
+ pGraphicHandleRects[i].height = nHandleHeight;
+
cairo_translate(pCairo, x, y);
cairo_set_source_surface(pCairo, pHandle, 0, 0);
cairo_paint(pCairo);
@@ -488,7 +538,7 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpoint
{
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);
+ lcl_renderGraphicHandle(pCairo, &pDocView->m_aGraphicSelection, pDocView->m_pGraphicHandle, pDocView->m_aGraphicHandleRects, pDocView->fZoom);
}
cairo_destroy(pCairo);