diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2017-11-05 14:01:42 +0530 |
---|---|---|
committer | pranavk <pranavk@collabora.co.uk> | 2017-11-09 04:12:50 +0100 |
commit | 446a37ece35dbe4c442f0679dd1cb4df79ed87a7 (patch) | |
tree | 092daeb0e04964719b9862debd1d3b5aae67fde2 /libreofficekit | |
parent | ee57d2f8a57ac851c1250f2962ecd1fa987ee3d9 (diff) |
lokdialog: Support painting parts of the dialog
Pass the dimensions of the region to the paintDialog call to paint only
that much of the region in the dialog.
The DIALOG_INVALIDATE callback also returns a 'rectangle' field now in
the payload that tells the region of the dialog invalidated. It can be
used in combination with the new paintDialog call then to paint only the
invalidated region in the dialog.
Change-Id: Iebb228865c71684e0f75dd01271b71ae41a0f906
Reviewed-on: https://gerrit.libreoffice.org/44472
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: pranavk <pranavk@collabora.co.uk>
Diffstat (limited to 'libreofficekit')
5 files changed, 56 insertions, 10 deletions
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx index 5dca746d5f25..9dee02a0ac45 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx @@ -148,4 +148,23 @@ const std::string GtvHelpers::getDirPath(const std::string& filePath) return dirPath; } +const std::vector<int> GtvHelpers::splitIntoIntegers(const std::string& aPayload, const std::string& aDelim, const int nItems) +{ + std::vector<int> aRet; + + if (!aPayload.empty()) + { + gchar** ppCoordinates = g_strsplit(aPayload.c_str(), aDelim.c_str(), nItems); + gchar** ppCoordinate = ppCoordinates; + while (*ppCoordinate) + { + aRet.push_back(atoi(*ppCoordinate)); + ++ppCoordinate; + } + g_strfreev(ppCoordinates); + } + + return aRet; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx b/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx index e0a2defa72d9..9e984846f0ab 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx @@ -38,6 +38,8 @@ namespace GtvHelpers GtkWidget* createCommentBox(const boost::property_tree::ptree& aComment); const std::string getDirPath(const std::string& filePath); + + const std::vector<int> splitIntoIntegers(const std::string& aPayload, const std::string& aDelim, const int nItems); } #endif diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx index 2a3d1a9d9cd9..1614c157ae7c 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx @@ -87,14 +87,22 @@ gtv_lok_dialog_draw(GtkWidget* pDialogDrawingArea, cairo_t* pCairo, gpointer) GtvLokDialog* pDialog = GTV_LOK_DIALOG(gtk_widget_get_toplevel(pDialogDrawingArea)); GtvLokDialogPrivate* priv = getPrivate(pDialog); - g_info("painting dialog"); + GdkRectangle aRect; + gdk_cairo_get_clip_rectangle(pCairo, &aRect); + g_info("Painting dialog region: %d, %d, %d, %d", aRect.x, aRect.y, aRect.width, aRect.height); int nWidth = 1024; int nHeight = 768; + if (aRect.width != 0 && aRect.height != 0) + { + nWidth = aRect.width; + nHeight = aRect.height; + } + cairo_surface_t* pSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, nWidth, nHeight); unsigned char* pBuffer = cairo_image_surface_get_data(pSurface); LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(priv->lokdocview)); char* pDialogTitle = nullptr; - pDocument->pClass->paintDialog(pDocument, priv->dialogid, pBuffer, &pDialogTitle, &nWidth, &nHeight); + pDocument->pClass->paintDialog(pDocument, priv->dialogid, aRect.x, aRect.y, pBuffer, &pDialogTitle, &nWidth, &nHeight); if (pDialogTitle) { gtk_window_set_title(GTK_WINDOW(pDialog), pDialogTitle); @@ -106,7 +114,7 @@ gtv_lok_dialog_draw(GtkWidget* pDialogDrawingArea, cairo_t* pCairo, gpointer) cairo_surface_flush(pSurface); cairo_surface_mark_dirty(pSurface); - cairo_set_source_surface(pCairo, pSurface, 0, 0); + cairo_set_source_surface(pCairo, pSurface, aRect.x, aRect.y); cairo_paint(pCairo); } @@ -474,11 +482,13 @@ gtv_lok_dialog_floating_win_draw(GtkWidget* pDrawingArea, cairo_t* pCairo, gpoin } void -gtv_lok_dialog_invalidate(GtvLokDialog* dialog) +gtv_lok_dialog_invalidate(GtvLokDialog* dialog, const GdkRectangle& aRectangle) { GtvLokDialogPrivate* priv = getPrivate(dialog); - - gtk_widget_queue_draw(priv->pDialogDrawingArea); + if (aRectangle.width != 0 && aRectangle.height != 0) + gtk_widget_queue_draw_area(priv->pDialogDrawingArea, aRectangle.x, aRectangle.y, aRectangle.width, aRectangle.height); + else + gtk_widget_queue_draw(priv->pDialogDrawingArea); } static gboolean diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx index ba565b4cebb0..619005635b60 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx @@ -37,7 +37,7 @@ GType gtv_lok_dialog_get_type (void) G_GNUC_CONST; GtkWidget* gtv_lok_dialog_new(LOKDocView* pDocView, const gchar* dialogId); -void gtv_lok_dialog_invalidate(GtvLokDialog* dialog); +void gtv_lok_dialog_invalidate(GtvLokDialog* dialog, const GdkRectangle& aRectangle); void gtv_lok_dialog_child_invalidate(GtvLokDialog* dialog, int nX, int nY); diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx index 415c3d6526c4..dfdbc3bc6ca6 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx @@ -20,6 +20,8 @@ #include <boost/property_tree/json_parser.hpp> #include <boost/optional.hpp> +#include <iostream> + void LOKDocViewSigHandlers::editChanged(LOKDocView* pDocView, gboolean bWasEdit, gpointer) { GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); @@ -288,8 +290,8 @@ void LOKDocViewSigHandlers::dialog(LOKDocView* pDocView, gchar* pPayload, gpoint std::stringstream aStream(pPayload); boost::property_tree::ptree aRoot; boost::property_tree::read_json(aStream, aRoot); - std::string aDialogId = aRoot.get<std::string>("dialogId"); - std::string aAction = aRoot.get<std::string>("action"); + const std::string aDialogId = aRoot.get<std::string>("dialogId"); + const std::string aAction = aRoot.get<std::string>("action"); // we only understand 'invalidate' and 'close' as of now if (aAction != "invalidate" && aAction != "close") @@ -306,7 +308,20 @@ void LOKDocViewSigHandlers::dialog(LOKDocView* pDocView, gchar* pPayload, gpoint if (aAction == "close") gtk_widget_destroy(GTK_WIDGET(pIt->data)); else if (aAction == "invalidate") - gtv_lok_dialog_invalidate(GTV_LOK_DIALOG(pIt->data)); + { + GdkRectangle aGdkRectangle = {0, 0, 0, 0}; + try + { + const std::string aRectangle = aRoot.get<std::string>("rectangle"); + std::vector<int> aRectPoints = GtvHelpers::splitIntoIntegers(aRectangle, ", ", 4); + if (aRectPoints.size() == 4) + aGdkRectangle = {aRectPoints[0], aRectPoints[1], aRectPoints[2], aRectPoints[3]}; + } + catch(const std::exception& e) + {} + + gtv_lok_dialog_invalidate(GTV_LOK_DIALOG(pIt->data), aGdkRectangle); + } } g_free(pChildDialogId); } |