[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 2 commits - desktop/source include/LibreOfficeKit include/vcl libreofficekit/source sw/inc sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue Mar 10 02:26:59 PDT 2015
desktop/source/lib/init.cxx | 17 ++++++++
include/LibreOfficeKit/LibreOfficeKit.h | 5 ++
include/LibreOfficeKit/LibreOfficeKit.hxx | 12 +++++
include/LibreOfficeKit/LibreOfficeKitEnums.h | 25 ++++++++++++
include/LibreOfficeKit/LibreOfficeKitGtk.h | 8 +++
include/vcl/ITiledRenderable.hxx | 7 +++
libreofficekit/source/gtk/lokdocview.c | 56 +++++++++++++++++++++++++--
sw/inc/unotxdoc.hxx | 2
sw/source/uibase/docvw/edtwin.cxx | 18 ++++++++
sw/source/uibase/inc/edtwin.hxx | 2
sw/source/uibase/uno/unotxdoc.cxx | 19 +++++++++
11 files changed, 168 insertions(+), 3 deletions(-)
New commits:
commit 2b638ff218970051a970a4170d992d1361db6319
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Mar 10 10:12:02 2015 +0100
lokdocview: use lok::Document::setGraphicSelection()
With this, it's now possible to resize images in Writer.
Change-Id: I2f557d6a64efda54959627d21406aef85160e470
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index ae0aa0e..d83dbd2 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -82,7 +82,15 @@ struct _LOKDocView
gboolean m_bInDragEndHandle;
///@}
+ /// @name Graphic handles.
+ ///@{
+ /// Bitmap of a graphic selection handle.
cairo_surface_t* m_pGraphicHandle;
+ /// Rectangle of a graphic selection handle, to know if the user clicked on it or not.
+ GdkRectangle m_aGraphicHandleRects[8];
+ /// If we are in the middle of a drag of a graphic selection handle.
+ gboolean m_bInDragGraphicHandles[8];
+ ///@}
};
struct _LOKDocViewClass
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index 08c3831..0d62a5f 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);
commit 37f85d81af07f87181cfc3e7e163836414528576
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Mar 10 09:40:38 2015 +0100
LOK: add lok::Document::setGraphicSelection() API and implement it for Writer
Change-Id: I115cf7e7978622d5108c4c792f7de861beb6efb6
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 0c2f4a9..0cc0d79 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -216,6 +216,10 @@ static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
int nType,
int nX,
int nY);
+static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
+ int nType,
+ int nX,
+ int nY);
struct LibLODocument_Impl : public _LibreOfficeKitDocument
{
@@ -246,6 +250,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument
m_pDocumentClass->postKeyEvent = doc_postKeyEvent;
m_pDocumentClass->postMouseEvent = doc_postMouseEvent;
m_pDocumentClass->setTextSelection = doc_setTextSelection;
+ m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
gDocumentClass = m_pDocumentClass;
}
@@ -739,6 +744,18 @@ static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int n
pDoc->setTextSelection(nType, nX, nY);
}
+static void doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY)
+{
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+ return;
+ }
+
+ pDoc->setGraphicSelection(nType, nX, nY);
+}
+
static char* lo_getError (LibreOfficeKit *pThis)
{
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index ea9846a..0b23adf 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -138,6 +138,11 @@ struct _LibreOfficeKitDocumentClass
int nType,
int nX,
int nY);
+ /// @see lok::Document::setGraphicSelection
+ void (*setGraphicSelection)(LibreOfficeKitDocument* pThis,
+ int nType,
+ int nX,
+ int nY);
#endif // LOK_USE_UNSTABLE_API
};
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index a442382..2993193 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -141,6 +141,18 @@ public:
{
mpDoc->pClass->setTextSelection(mpDoc, nType, nX, nY);
}
+
+ /**
+ * Adjusts the graphic selection.
+ *
+ * @param nType @see LibreOfficeKitSetGraphicSelectionType
+ * @param nX horizontal position in document coordinates
+ * @param nY vertical position in document coordinates
+ */
+ inline void setGraphicSelection(int nType, int nX, int nY)
+ {
+ mpDoc->pClass->setGraphicSelection(mpDoc, nType, nX, nY);
+ }
#endif // LOK_USE_UNSTABLE_API
};
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index b8ab5f6..671166e 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -135,6 +135,31 @@ typedef enum
}
LibreOfficeKitSetTextSelectionType;
+typedef enum
+{
+ /**
+ * A move or a resize action starts. It is assumed that there is a valid
+ * graphic selection (see LOK_CALLBACK_GRAPHIC_SELECTION) and the supplied
+ * coordinates are the ones the user tapped on.
+ *
+ * The type of the action is move by default, unless the coordinates are
+ * the position of a handle (see below), in which case it's a resize.
+ *
+ * There are 8 handles for a graphic selection:
+ * - top-left, top-center, top-right
+ * - middle-left, middle-right
+ * - bottom-left, bottom-center, bottom-right
+ */
+ LOK_SETGRAPHICSELECTION_START,
+ /**
+ * A move or resize action stops. It is assumed that this is always used
+ * only after a LOK_SETTEXTSELECTION_START. The supplied coordinates are
+ * the ones where the user released the screen.
+ */
+ LOK_SETGRAPHICSELECTION_END
+}
+LibreOfficeKitSetGraphicSelectionType;
+
#endif // LOK_USE_UNSTABLE_API
#ifdef __cplusplus
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index ee903ad..7f63b1f 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -115,6 +115,13 @@ public:
* @see lok::Document::setTextSelection().
*/
virtual void setTextSelection(int /*nType*/, int /*nX*/, int /*nY*/) { }
+
+ /**
+ * Adjusts the graphic selection.
+ *
+ * @see lok::Document::setGraphicSelection().
+ */
+ virtual void setGraphicSelection(int /*nType*/, int /*nX*/, int /*nY*/) { }
};
} // namespace vcl
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index e528195..b840385 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -417,6 +417,8 @@ public:
virtual void postMouseEvent(int nType, int nX, int nY, int nCount) SAL_OVERRIDE;
/// @see vcl::ITiledRenderable::setTextSelection().
virtual void setTextSelection(int nType, int nX, int nY) SAL_OVERRIDE;
+ /// @see vcl::ITiledRenderable::setGraphicSelection().
+ virtual void setGraphicSelection(int nType, int nX, int nY) SAL_OVERRIDE;
void Invalidate();
void Reactivate(SwDocShell* pNewDocShell);
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 41c4c91..ca6dd8b 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -6283,4 +6283,22 @@ void SwEditWin::SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool
rShell.getShellCrsr(/*bBlock=*/false)->Exchange();
}
+void SwEditWin::SetGraphicLogicPosition(bool bStart, const Point& rPosition)
+{
+ if (bStart)
+ {
+ MouseEvent aClickEvent(rPosition, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
+ MouseButtonDown(aClickEvent);
+ MouseEvent aMoveEvent(Point(rPosition.getX() + MIN_MOVE + 1, rPosition.getY()), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT);
+ MouseMove(aMoveEvent);
+ }
+ else
+ {
+ MouseEvent aMoveEvent(Point(rPosition.getX() - MIN_MOVE - 1, rPosition.getY()), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT);
+ MouseMove(aMoveEvent);
+ MouseEvent aClickEvent(rPosition, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
+ MouseButtonUp(aClickEvent);
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/edtwin.hxx b/sw/source/uibase/inc/edtwin.hxx
index aa6d63b..3aeee19 100644
--- a/sw/source/uibase/inc/edtwin.hxx
+++ b/sw/source/uibase/inc/edtwin.hxx
@@ -308,6 +308,8 @@ public:
void LogicMouseButtonUp(const MouseEvent& rMouseEvent);
/// Allows adjusting the point or mark of the selection to a document coordinate.
void SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark);
+ /// Allows starting or ending a graphic move or resize action.
+ void SetGraphicLogicPosition(bool bStart, const Point& rPosition);
};
#endif
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 7e3e1d8..6c0b893 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3223,6 +3223,25 @@ void SwXTextDocument::setTextSelection(int nType, int nX, int nY)
}
}
+void SwXTextDocument::setGraphicSelection(int nType, int nX, int nY)
+{
+ SolarMutexGuard aGuard;
+
+ SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
+ switch (nType)
+ {
+ case LOK_SETTEXTSELECTION_START:
+ rEditWin.SetGraphicLogicPosition(/*bStart=*/true, Point(nX, nY));
+ break;
+ case LOK_SETTEXTSELECTION_END:
+ rEditWin.SetGraphicLogicPosition(/*bStart=*/false, Point(nX, nY));
+ break;
+ default:
+ assert(false);
+ break;
+ }
+}
+
void * SAL_CALL SwXTextDocument::operator new( size_t t) throw()
{
return SwXTextDocumentBaseClass::operator new(t);
More information about the Libreoffice-commits
mailing list