diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2017-11-05 14:01:42 +0530 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2017-11-15 17:07:17 +0100 |
commit | f13dfb4c018080e94d8ed247984bf2f37e0653b8 (patch) | |
tree | 0307994500d53238cfd8a97954f1153dfd034b91 /libreofficekit | |
parent | dd2c566b29b74d025761df77f5744c5b21e97625 (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 eb3aebf97675..5122ad2c2c02 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 033b974f0fbd..a9c94d09a083 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 677245512821..2c9ae8b71003 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("panting 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 c177e6bf5e41..1ce1d3afbcb3 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); } |