summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-01-27 09:34:04 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-02-09 08:09:22 +0100
commit31ce5f4b1961258a88f4cc5fa9c0a88d02c14b47 (patch)
treef944a67029ce8ea1591f76158f3949f85bb83177 /libreofficekit
parentec170c92c61fbe043b5a8848402f5ded33b81c21 (diff)
lokdocview: initial overlay on top of the tiles
It currently contains a non-blinking cursor caret in case at least one character is typed. Change-Id: I476bb1e8434a5df8c97054d670d68bc79721914e
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/source/gtk/lokdocview.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index 8f80d20ad902..92140b36f379 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -26,6 +26,7 @@
static void lok_docview_class_init( LOKDocViewClass* pClass );
static void lok_docview_init( LOKDocView* pDocView );
static float pixelToTwip(float nInput);
+static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpointer pData);
// We specifically need to destroy the document when closing in order to ensure
// that lock files etc. are cleaned up.
@@ -112,9 +113,12 @@ static void lok_docview_init( LOKDocView* pDocView )
pDocView->fZoom = 1;
pDocView->m_bEdit = FALSE;
+ memset(&pDocView->m_aVisibleCursor, 0, sizeof(pDocView->m_aVisibleCursor));
gtk_signal_connect( GTK_OBJECT(pDocView), "destroy",
GTK_SIGNAL_FUNC(lcl_onDestroy), NULL );
+ g_signal_connect_after(pDocView->pEventBox, "expose-event",
+ G_CALLBACK(renderOverlay), pDocView);
}
SAL_DLLPUBLIC_EXPORT GtkWidget* lok_docview_new( LibreOfficeKit* pOffice )
@@ -139,6 +143,38 @@ 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;
+}
+
+static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpointer pData)
+{
+ LOKDocView* pDocView = pData;
+ cairo_t* pCairo;
+
+ (void)pEvent;
+ pCairo = gdk_cairo_create(gtk_widget_get_window(pWidget));
+
+ if (!lcl_isEmptyRectangle(&pDocView->m_aVisibleCursor))
+ {
+ if (pDocView->m_aVisibleCursor.width == 0)
+ // Set a minimal width if it would be 0.
+ pDocView->m_aVisibleCursor.width = 30;
+
+ cairo_set_source_rgb(pCairo, 0, 0, 0);
+ cairo_rectangle(pCairo,
+ twipToPixel(pDocView->m_aVisibleCursor.x),
+ twipToPixel(pDocView->m_aVisibleCursor.y),
+ twipToPixel(pDocView->m_aVisibleCursor.width),
+ twipToPixel(pDocView->m_aVisibleCursor.height));
+ cairo_fill(pCairo);
+ }
+
+ cairo_destroy(pCairo);
+ return FALSE;
+}
+
void renderDocument(LOKDocView* pDocView, GdkRectangle* pPartial)
{
long nDocumentWidthTwips, nDocumentHeightTwips, nDocumentWidthPixels, nDocumentHeightPixels;
@@ -300,6 +336,12 @@ static gboolean lok_docview_callback(gpointer pData)
renderDocument(pCallback->m_pDocView, NULL);
}
break;
+ case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
+ {
+ pCallback->m_pDocView->m_aVisibleCursor = lcl_payloadToRectangle(pCallback->m_pPayload);
+ gtk_widget_queue_draw(GTK_WIDGET(pCallback->m_pDocView->pEventBox));
+ }
+ break;
default:
break;
}