diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2017-12-01 13:54:45 +0530 |
---|---|---|
committer | Pranav Kant <pranavk@collabora.co.uk> | 2017-12-04 17:14:02 +0530 |
commit | b5e27fd809845577a90cc1811de062c070110078 (patch) | |
tree | 679cb1c3712b6b0a5b693dfa9990e6de8592cc62 /libreofficekit | |
parent | 3d8154ec427777eadf5719f194662e5ade78fae5 (diff) |
lokdialog: Simplify; make the LOK dialog API more generic
Merge the dialog floating window callbacks and function calls into one.
Unique window ids across vcl::Window is enough to distinguish between
them.
Floating windows don't have a LOK notifier as they are created in the
vcl itself (so we can't access them from sfx2). Use the parent LOK
notifier in that case (which would be a dialog).
This API should also help in autopopup filter tunneling later.
Change-Id: I63a2c97ffdd84695dc967e14c793089a7c50b41b
Diffstat (limited to 'libreofficekit')
7 files changed, 157 insertions, 193 deletions
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx index e5b67d18c57c..f58884c79207 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx @@ -21,6 +21,7 @@ #include "gtv-lokdocview-signal-handlers.hxx" #include "gtv-calc-header-bar.hxx" #include "gtv-comments-sidebar.hxx" +#include "gtv-lok-dialog.hxx" #include <boost/property_tree/json_parser.hpp> #include <boost/optional.hpp> @@ -314,8 +315,7 @@ static void setupDocView(GtvApplicationWindow* window) g_signal_connect(window->lokdocview, "formula-changed", G_CALLBACK(LOKDocViewSigHandlers::formulaChanged), nullptr); g_signal_connect(window->lokdocview, "password-required", G_CALLBACK(LOKDocViewSigHandlers::passwordRequired), nullptr); g_signal_connect(window->lokdocview, "comment", G_CALLBACK(LOKDocViewSigHandlers::comment), nullptr); - g_signal_connect(window->lokdocview, "dialog", G_CALLBACK(LOKDocViewSigHandlers::dialog), nullptr); - g_signal_connect(window->lokdocview, "dialog-child", G_CALLBACK(LOKDocViewSigHandlers::dialogChild), nullptr); + g_signal_connect(window->lokdocview, "window", G_CALLBACK(LOKDocViewSigHandlers::window), nullptr); g_signal_connect(window->lokdocview, "configure-event", G_CALLBACK(LOKDocViewSigHandlers::configureEvent), nullptr); } @@ -422,7 +422,7 @@ gtv_application_window_unregister_child_window(GtvApplicationWindow* window, Gtk } GtkWindow* -gtv_application_window_get_child_window_by_id(GtvApplicationWindow* window, const gchar* pWinId) +gtv_application_window_get_child_window_by_id(GtvApplicationWindow* window, guint nWinId) { GtvApplicationWindowPrivate* priv = getPrivate(window); GList* pIt = nullptr; @@ -430,25 +430,32 @@ gtv_application_window_get_child_window_by_id(GtvApplicationWindow* window, cons // For now, only dialogs are registered as child window for (pIt = priv->m_pChildWindows; pIt != nullptr; pIt = pIt->next) { - gchar* dialogId = nullptr; + guint dialogId = 0; g_object_get(G_OBJECT(pIt->data), "dialogid", &dialogId, nullptr); - // prepend .uno: - gchar* completeWinId = nullptr; - if (pWinId != nullptr) - { - completeWinId = g_strconcat(".uno:", pWinId, nullptr); - } - - if (dialogId != nullptr && g_str_equal(dialogId, completeWinId)) + if (dialogId == nWinId) { ret = GTK_WINDOW(pIt->data); break; } } + return ret; } +GtkWidget* gtv_application_window_get_parent(GtvApplicationWindow* window, guint nWinId) +{ + GtvApplicationWindowPrivate* priv = getPrivate(window); + GList* pIt = nullptr; + for (pIt = priv->m_pChildWindows; pIt != nullptr; pIt = pIt->next) + { + if (gtv_lok_dialog_is_parent_of(GTV_LOK_DIALOG(pIt->data), nWinId)) + return GTK_WIDGET(pIt->data); + } + return nullptr; +} + + // temporary function to invalidate all opened dialogs // because currently the dialog id returned in dialog invalidation payload // doesn't match our hard-coded list of dialog ids (uno commands) for some dialogs diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application-window.hxx b/libreofficekit/qa/gtktiledviewer/gtv-application-window.hxx index f0d5afc0513c..78e9bae3e97f 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-application-window.hxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-application-window.hxx @@ -103,10 +103,12 @@ void gtv_application_window_register_child_window(GtvApplicationWindow* window, void gtv_application_window_unregister_child_window(GtvApplicationWindow* window, GtkWindow* pChildWin); -GtkWindow* gtv_application_window_get_child_window_by_id(GtvApplicationWindow* window, const gchar* pWinId); +GtkWindow* gtv_application_window_get_child_window_by_id(GtvApplicationWindow* window, guint nWinId); GList* gtv_application_window_get_all_child_windows(GtvApplicationWindow* window); +GtkWidget* gtv_application_window_get_parent(GtvApplicationWindow* window, guint nWinId); + G_END_DECLS #endif /* GTV_APPLICATION_WINDOW_H */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx index 546913d5953f..197897c2a185 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx @@ -43,6 +43,9 @@ struct GtvLokDialogPrivate guint32 m_nHeight; // state for child floating windows + guint32 m_nChildId; + guint32 m_nChildWidth; + guint32 m_nChildHeight; guint32 m_nChildLastButtonPressTime; guint32 m_nChildLastButtonReleaseTime; guint32 m_nChildKeyModifier; @@ -132,11 +135,9 @@ gtv_lok_dialog_signal_button(GtkWidget* pDialogDrawingArea, GdkEventButton* pEve else if (pEvent->type == GDK_BUTTON_RELEASE) aEventType = "BUTTON_RELEASE"; - g_info("lok_dialog_signal_button (type: %s): %d, %d (in twips: %d, %d)", + g_info("lok_dialog_signal_button (type: %s): %d, %d", aEventType.c_str(), - (int)pEvent->x, (int)pEvent->y, - (int)pixelToTwip(pEvent->x), - (int)pixelToTwip(pEvent->y)); + (int)pEvent->x, (int)pEvent->y); gtk_widget_grab_focus(pDialogDrawingArea); switch (pEvent->type) @@ -355,6 +356,9 @@ gtv_lok_dialog_init(GtvLokDialog* dialog) GtkWidget* pContentArea = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); priv->pDialogDrawingArea = gtk_drawing_area_new(); priv->pFloatingWin = nullptr; + priv->m_nChildId = 0; + priv->m_nChildWidth = 0; + priv->m_nChildHeight = 0; priv->m_nLastButtonPressTime = 0; priv->m_nLastButtonReleaseTime = 0; @@ -478,17 +482,14 @@ gtv_lok_dialog_floating_win_draw(GtkWidget* pDrawingArea, cairo_t* pCairo, gpoin GtvLokDialogPrivate* priv = getPrivate(pDialog); g_info("gtv_lok_dialog_floating_win_draw triggered"); - int nWidth = 800; - int nHeight = 600; - cairo_surface_t* pSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, nWidth, nHeight); + cairo_surface_t* pSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, priv->m_nChildWidth, priv->m_nChildHeight); unsigned char* pBuffer = cairo_image_surface_get_data(pSurface); LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(priv->lokdocview)); - pDocument->pClass->paintActiveFloatingWindow(pDocument, priv->dialogid, pBuffer, &nWidth, &nHeight); - g_info("Size of floating window: %d x %d", nWidth, nHeight); + pDocument->pClass->paintWindow(pDocument, priv->m_nChildId, pBuffer, 0, 0, priv->m_nChildWidth, priv->m_nChildHeight); - gtk_widget_set_size_request(GTK_WIDGET(pDrawingArea), nWidth, nHeight); - gtk_widget_set_size_request(GTK_WIDGET(pDialog), nWidth, nHeight); - gtk_window_resize(GTK_WINDOW(pDialog), nWidth, nHeight); + gtk_widget_set_size_request(GTK_WIDGET(pDrawingArea), priv->m_nChildWidth, priv->m_nChildHeight); + //gtk_widget_set_size_request(GTK_WIDGET(pDialog), nWidth, nHeight); + //gtk_window_resize(GTK_WINDOW(pDialog), nWidth, nHeight); cairo_surface_flush(pSurface); cairo_surface_mark_dirty(pSurface); @@ -497,16 +498,6 @@ gtv_lok_dialog_floating_win_draw(GtkWidget* pDrawingArea, cairo_t* pCairo, gpoin cairo_paint(pCairo); } -void -gtv_lok_dialog_invalidate(GtvLokDialog* dialog, const GdkRectangle& aRectangle) -{ - GtvLokDialogPrivate* priv = getPrivate(dialog); - 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 gtv_lok_dialog_floating_win_signal_button(GtkWidget* /*pDialogChildDrawingArea*/, GdkEventButton* pEvent, gpointer userdata) { @@ -551,13 +542,13 @@ gtv_lok_dialog_floating_win_signal_button(GtkWidget* /*pDialogChildDrawingArea*/ } priv->m_nChildLastButtonPressed = nEventButton; pDocument->pClass->postDialogChildMouseEvent(pDocument, - priv->dialogid, - LOK_MOUSEEVENT_MOUSEBUTTONDOWN, - (pEvent->x), - (pEvent->y), - nCount, - nEventButton, - priv->m_nChildKeyModifier); + priv->m_nChildId, + LOK_MOUSEEVENT_MOUSEBUTTONDOWN, + (pEvent->x), + (pEvent->y), + nCount, + nEventButton, + priv->m_nChildKeyModifier); break; } @@ -582,7 +573,7 @@ gtv_lok_dialog_floating_win_signal_button(GtkWidget* /*pDialogChildDrawingArea*/ } priv->m_nChildLastButtonPressed = nEventButton; pDocument->pClass->postDialogChildMouseEvent(pDocument, - priv->dialogid, + priv->m_nChildId, LOK_MOUSEEVENT_MOUSEBUTTONUP, (pEvent->x), (pEvent->y), @@ -612,7 +603,7 @@ gtv_lok_dialog_floating_win_signal_motion(GtkWidget* /*pDialogDrawingArea*/, Gdk (int)pixelToTwip(pEvent->y)); pDocument->pClass->postDialogChildMouseEvent(pDocument, - priv->dialogid, + priv->m_nChildId, LOK_MOUSEEVENT_MOUSEMOVE, (pEvent->x), (pEvent->y), @@ -623,40 +614,58 @@ gtv_lok_dialog_floating_win_signal_motion(GtkWidget* /*pDialogDrawingArea*/, Gdk return FALSE; } -void gtv_lok_dialog_child_invalidate(GtvLokDialog* dialog, int nX, int nY) +// Public methods below + +void gtv_lok_dialog_invalidate(GtvLokDialog* dialog, const GdkRectangle& aRectangle) +{ + GtvLokDialogPrivate* priv = getPrivate(dialog); + 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); +} + +// checks if we are the parent of given childId +gboolean gtv_lok_dialog_is_parent_of(GtvLokDialog* dialog, guint childId) { - g_info("Dialog's floating window invalidate"); + GtvLokDialogPrivate* priv = getPrivate(dialog); + + return priv->m_nChildId == childId; +} +void gtv_lok_dialog_child_create(GtvLokDialog* dialog, guint childId, guint nX, guint nY, guint width, guint height) +{ GtvLokDialogPrivate* priv = getPrivate(dialog); - // create new if doesn't exist - if (!priv->pFloatingWin) - { - priv->pFloatingWin = gtk_window_new(GTK_WINDOW_POPUP); - GtkWidget* pDrawingArea = gtk_drawing_area_new(); - gtk_container_add(GTK_CONTAINER(priv->pFloatingWin), pDrawingArea); - - gtk_window_set_transient_for(GTK_WINDOW(priv->pFloatingWin), GTK_WINDOW(dialog)); - gtk_window_set_destroy_with_parent(GTK_WINDOW(priv->pFloatingWin), true); - - gtk_widget_add_events(pDrawingArea, - GDK_BUTTON_PRESS_MASK - |GDK_POINTER_MOTION_MASK - |GDK_BUTTON_RELEASE_MASK - |GDK_BUTTON_MOTION_MASK); - - g_signal_connect(G_OBJECT(pDrawingArea), "draw", G_CALLBACK(gtv_lok_dialog_floating_win_draw), dialog); - g_signal_connect(G_OBJECT(pDrawingArea), "button-press-event", G_CALLBACK(gtv_lok_dialog_floating_win_signal_button), dialog); - g_signal_connect(G_OBJECT(pDrawingArea), "button-release-event", G_CALLBACK(gtv_lok_dialog_floating_win_signal_button), dialog); - g_signal_connect(G_OBJECT(pDrawingArea), "motion-notify-event", G_CALLBACK(gtv_lok_dialog_floating_win_signal_motion), dialog); - - gtk_widget_set_size_request(priv->pFloatingWin, 1, 1); - gtk_window_set_type_hint(GTK_WINDOW(priv->pFloatingWin), GDK_WINDOW_TYPE_HINT_POPUP_MENU); - gtk_window_set_screen(GTK_WINDOW(priv->pFloatingWin), gtk_window_get_screen(GTK_WINDOW(dialog))); - - gtk_widget_show_all(priv->pFloatingWin); - gtk_window_present(GTK_WINDOW(priv->pFloatingWin)); - gtk_widget_grab_focus(pDrawingArea); - } + + g_debug("Dialog [ %d ] child window [ %d] being created, with dimensions [%dx%d]@(%d,%d)", priv->dialogid, childId, width, height, nX, nY); + priv->pFloatingWin = gtk_window_new(GTK_WINDOW_POPUP); + priv->m_nChildId = childId; + priv->m_nChildWidth = width; + priv->m_nChildHeight = height; + GtkWidget* pDrawingArea = gtk_drawing_area_new(); + gtk_container_add(GTK_CONTAINER(priv->pFloatingWin), pDrawingArea); + + gtk_window_set_transient_for(GTK_WINDOW(priv->pFloatingWin), GTK_WINDOW(dialog)); + gtk_window_set_destroy_with_parent(GTK_WINDOW(priv->pFloatingWin), true); + + gtk_widget_add_events(pDrawingArea, + GDK_BUTTON_PRESS_MASK + |GDK_POINTER_MOTION_MASK + |GDK_BUTTON_RELEASE_MASK + |GDK_BUTTON_MOTION_MASK); + + g_signal_connect(G_OBJECT(pDrawingArea), "draw", G_CALLBACK(gtv_lok_dialog_floating_win_draw), dialog); + g_signal_connect(G_OBJECT(pDrawingArea), "button-press-event", G_CALLBACK(gtv_lok_dialog_floating_win_signal_button), dialog); + g_signal_connect(G_OBJECT(pDrawingArea), "button-release-event", G_CALLBACK(gtv_lok_dialog_floating_win_signal_button), dialog); + g_signal_connect(G_OBJECT(pDrawingArea), "motion-notify-event", G_CALLBACK(gtv_lok_dialog_floating_win_signal_motion), dialog); + + gtk_widget_set_size_request(priv->pFloatingWin, 1, 1); + gtk_window_set_type_hint(GTK_WINDOW(priv->pFloatingWin), GDK_WINDOW_TYPE_HINT_POPUP_MENU); + gtk_window_set_screen(GTK_WINDOW(priv->pFloatingWin), gtk_window_get_screen(GTK_WINDOW(dialog))); + + gtk_widget_show_all(priv->pFloatingWin); + gtk_window_present(GTK_WINDOW(priv->pFloatingWin)); + gtk_widget_grab_focus(pDrawingArea); // Get the root coords of our new floating window GdkWindow* pGdkWin = gtk_widget_get_window(GTK_WIDGET(dialog)); @@ -664,7 +673,12 @@ void gtv_lok_dialog_child_invalidate(GtvLokDialog* dialog, int nX, int nY) int nrY = 0; gdk_window_get_root_coords(pGdkWin, nX, nY, &nrX, &nrY); gtk_window_move(GTK_WINDOW(priv->pFloatingWin), nrX, nrY); +} +void gtv_lok_dialog_child_invalidate(GtvLokDialog* dialog) +{ + GtvLokDialogPrivate* priv = getPrivate(dialog); + g_debug("Dialog [ %d ] child invalidate request", priv->dialogid); gtk_widget_queue_draw(priv->pFloatingWin); } @@ -677,12 +691,13 @@ void gtv_lok_dialog_child_close(GtvLokDialog* dialog) { gtk_widget_destroy(priv->pFloatingWin); priv->pFloatingWin = nullptr; + priv->m_nChildId = 0; + priv->m_nChildWidth = 0; + priv->m_nChildHeight = 0; } } - -GtkWidget* -gtv_lok_dialog_new(LOKDocView* pDocView, guint dialogId, guint width, guint height) +GtkWidget* gtv_lok_dialog_new(LOKDocView* pDocView, guint dialogId, guint width, guint height) { g_debug("Dialog [ %d ] of size: %d x %d created", dialogId, width, height); GtkWindow* pWindow = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx index 0f7002c359d7..2a5bfb5957f8 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx @@ -39,10 +39,14 @@ GtkWidget* gtv_lok_dialog_new(LOKDocView* pDocView, guint dialogId, guint width, void gtv_lok_dialog_invalidate(GtvLokDialog* dialog, const GdkRectangle& aRectangle); -void gtv_lok_dialog_child_invalidate(GtvLokDialog* dialog, int nX, int nY); +void gtv_lok_dialog_child_create(GtvLokDialog* dialog, guint childId, guint nX, guint nY, guint width, guint height); + +void gtv_lok_dialog_child_invalidate(GtvLokDialog* dialog); void gtv_lok_dialog_child_close(GtvLokDialog* dialog); +gboolean gtv_lok_dialog_is_parent_of(GtvLokDialog* dialog, guint childId); + G_END_DECLS #endif /* GTV_LOK_DIALOG_H */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx index 2c97bd4d7393..aa15a03a83e1 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx @@ -301,47 +301,60 @@ void LOKDocViewSigHandlers::comment(LOKDocView* pDocView, gchar* pComment, gpoin } } -void LOKDocViewSigHandlers::dialog(LOKDocView* pDocView, gchar* pPayload, gpointer) +void LOKDocViewSigHandlers::window(LOKDocView* pDocView, gchar* pPayload, gpointer) { GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); std::stringstream aStream(pPayload); boost::property_tree::ptree aRoot; boost::property_tree::read_json(aStream, aRoot); - const unsigned nDialogId = aRoot.get<unsigned>("dialogId"); + const unsigned nWinId = aRoot.get<unsigned>("id"); const std::string aAction = aRoot.get<std::string>("action"); if (aAction == "created") { + const std::string aType = aRoot.get<std::string>("type"); const std::string aSize = aRoot.get<std::string>("size"); - std::vector<int> aPoints = GtvHelpers::split<int>(aSize, ", ", 2); - GtkWidget* pDialog = gtv_lok_dialog_new(pDocView, nDialogId, aPoints[0], aPoints[1]); - g_info("created dialog, for dialogid: %d with size: %s", nDialogId, aSize.c_str()); + std::vector<int> aSizePoints = GtvHelpers::split<int>(aSize, ", ", 2); - gtv_application_window_register_child_window(window, GTK_WINDOW(pDialog)); - g_signal_connect(pDialog, "destroy", G_CALLBACK(destroyLokDialog), window); - g_signal_connect(pDialog, "delete-event", G_CALLBACK(deleteLokDialog), window); + if (aType == "dialog") + { + GtkWidget* pDialog = gtv_lok_dialog_new(pDocView, nWinId, aSizePoints[0], aSizePoints[1]); + g_info("created dialog, for dialogid: %d with size: %s", nWinId, aSize.c_str()); - gtk_window_set_resizable(GTK_WINDOW(pDialog), false); - gtk_widget_show_all(GTK_WIDGET(pDialog)); - gtk_window_present(GTK_WINDOW(pDialog)); + gtv_application_window_register_child_window(window, GTK_WINDOW(pDialog)); + g_signal_connect(pDialog, "destroy", G_CALLBACK(destroyLokDialog), window); + g_signal_connect(pDialog, "delete-event", G_CALLBACK(deleteLokDialog), window); - return; + gtk_window_set_resizable(GTK_WINDOW(pDialog), false); + gtk_widget_show_all(GTK_WIDGET(pDialog)); + gtk_window_present(GTK_WINDOW(pDialog)); + } + else if (aType == "child") + { + const unsigned nParentId = std::atoi(aRoot.get<std::string>("parentId").c_str()); + GtkWindow* pDialog = gtv_application_window_get_child_window_by_id(window, nParentId); + const std::string aPos = aRoot.get<std::string>("position"); + std::vector<int> aPosPoints = GtvHelpers::split<int>(aPos, ", ", 2); + gtv_lok_dialog_child_create(GTV_LOK_DIALOG(pDialog), nWinId, aPosPoints[0], aPosPoints[1], aSizePoints[0], aSizePoints[1]); + } } - - GList* pChildWins = gtv_application_window_get_all_child_windows(window); - GList* pIt = nullptr; - bool found = false; - for (pIt = pChildWins; !found && pIt != nullptr; pIt = pIt->next) + else { - guint nChildDialogId = 0; - g_object_get(pIt->data, "dialogid", &nChildDialogId, nullptr); - if (nDialogId == nChildDialogId) + // check if it's a child window + GtkWidget* pParent = gtv_application_window_get_parent(window, nWinId); + if (pParent) // it's a floating window in the dialog { - found = true; - + if (aAction == "invalidate") + gtv_lok_dialog_child_invalidate(GTV_LOK_DIALOG(pParent)); + else if (aAction == "close") + gtv_lok_dialog_child_close(GTV_LOK_DIALOG(pParent)); + } + else // it's the dialog window itself + { + GtkWindow* pDialog = gtv_application_window_get_child_window_by_id(window, nWinId); if (aAction == "close") - gtk_widget_destroy(GTK_WIDGET(pIt->data)); + gtk_widget_destroy(GTK_WIDGET(pDialog)); else if (aAction == "size_changed") { const std::string aSize = aRoot.get<std::string>("size"); @@ -349,16 +362,16 @@ void LOKDocViewSigHandlers::dialog(LOKDocView* pDocView, gchar* pPayload, gpoint if (aSizePoints.size() != 2) { g_error("Malformed size_changed callback"); - break; + return; } - g_object_set(G_OBJECT(pIt->data), + g_object_set(G_OBJECT(pDialog), "width", aSizePoints[0], "height", aSizePoints[1], nullptr); GdkRectangle aGdkRectangle = {0, 0, 0, 0}; - gtv_lok_dialog_invalidate(GTV_LOK_DIALOG(pIt->data), aGdkRectangle); + gtv_lok_dialog_invalidate(GTV_LOK_DIALOG(pDialog), aGdkRectangle); } else if (aAction == "invalidate") { @@ -373,51 +386,12 @@ void LOKDocViewSigHandlers::dialog(LOKDocView* pDocView, gchar* pPayload, gpoint catch(const std::exception& e) {} - gtv_lok_dialog_invalidate(GTV_LOK_DIALOG(pIt->data), aGdkRectangle); + gtv_lok_dialog_invalidate(GTV_LOK_DIALOG(pDialog), aGdkRectangle); } } } } -void LOKDocViewSigHandlers::dialogChild(LOKDocView* pDocView, gchar* pPayload, gpointer) -{ - GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); - - std::stringstream aStream(pPayload); - boost::property_tree::ptree aRoot; - boost::property_tree::read_json(aStream, aRoot); - const unsigned nDialogId = aRoot.get<unsigned>("dialogId"); - const std::string aAction = aRoot.get<std::string>("action"); - const std::string aPos = aRoot.get<std::string>("position"); - gchar** ppCoordinates = g_strsplit(aPos.c_str(), ", ", 2); - gchar** ppCoordinate = ppCoordinates; - int nX = 0; - int nY = 0; - - if (*ppCoordinate) - nX = atoi(*ppCoordinate); - ++ppCoordinate; - if (*ppCoordinate) - nY = atoi(*ppCoordinate); - - g_strfreev(ppCoordinates); - - GList* pChildWins = gtv_application_window_get_all_child_windows(window); - GList* pIt = nullptr; - for (pIt = pChildWins; pIt != nullptr; pIt = pIt->next) - { - guint nChildDialogId = 0; - g_object_get(pIt->data, "dialogid", &nChildDialogId, nullptr); - if (nDialogId == nChildDialogId) - { - if (aAction == "invalidate") - gtv_lok_dialog_child_invalidate(GTV_LOK_DIALOG(pIt->data), nX, nY); - else if (aAction == "close") - gtv_lok_dialog_child_close(GTV_LOK_DIALOG(pIt->data)); - } - } -} - gboolean LOKDocViewSigHandlers::configureEvent(GtkWidget* pWidget, GdkEventConfigure* /*pEvent*/, gpointer /*pData*/) { GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pWidget))); diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.hxx b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.hxx index 54f54b396bf3..aedc8d216ad0 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.hxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.hxx @@ -25,8 +25,7 @@ namespace LOKDocViewSigHandlers { void formulaChanged(LOKDocView* pDocView, char* pPayload, gpointer); void passwordRequired(LOKDocView* pDocView, char* pUrl, gboolean bModify, gpointer); void comment(LOKDocView* pDocView, gchar* pComment, gpointer); - void dialog(LOKDocView* pDocView, gchar* pDialogId, gpointer); - void dialogChild(LOKDocView* pDocView, gchar* pPayload, gpointer); + void window(LOKDocView* pDocView, gchar* pPayload, gpointer); gboolean configureEvent(GtkWidget* pWidget, GdkEventConfigure* pEvent, gpointer pData); } diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 607a8624ecc3..eae5c6225cd9 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -277,8 +277,7 @@ enum PASSWORD_REQUIRED, COMMENT, RULER, - DIALOG, - DIALOG_CHILD, + WINDOW, LAST_SIGNAL }; @@ -436,10 +435,8 @@ callbackTypeToString (int nType) return "LOK_CALLBACK_COMMENT"; case LOK_CALLBACK_RULER_UPDATE: return "LOK_CALLBACK_RULER_UPDATE"; - case LOK_CALLBACK_DIALOG: - return "LOK_CALLBACK_DIALOG"; - case LOK_CALLBACK_DIALOG_CHILD: - return "LOK_CALLBACK_DIALOG_CHILD"; + case LOK_CALLBACK_WINDOW: + return "LOK_CALLBACK_WINDOW"; } g_assert(false); return nullptr; @@ -1413,11 +1410,8 @@ callback (gpointer pData) case LOK_CALLBACK_RULER_UPDATE: g_signal_emit(pCallback->m_pDocView, doc_view_signals[RULER], 0, pCallback->m_aPayload.c_str()); break; - case LOK_CALLBACK_DIALOG: - g_signal_emit(pCallback->m_pDocView, doc_view_signals[DIALOG], 0, pCallback->m_aPayload.c_str()); - break; - case LOK_CALLBACK_DIALOG_CHILD: - g_signal_emit(pCallback->m_pDocView, doc_view_signals[DIALOG_CHILD], 0, pCallback->m_aPayload.c_str()); + case LOK_CALLBACK_WINDOW: + g_signal_emit(pCallback->m_pDocView, doc_view_signals[WINDOW], 0, pCallback->m_aPayload.c_str()); break; default: g_assert(false); @@ -3217,43 +3211,12 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) G_TYPE_STRING); /** - * LOKDocView::dialog-invalidate: + * LOKDocView::window * @pDocView: the #LOKDocView on which the signal is emitted - * @pDialogId: The uno command for the dialog (dialog ID) - */ - doc_view_signals[DIALOG] = - g_signal_new("dialog", - G_TYPE_FROM_CLASS(pGObjectClass), - G_SIGNAL_RUN_FIRST, - 0, - nullptr, nullptr, - g_cclosure_marshal_generic, - G_TYPE_NONE, 1, - G_TYPE_STRING); - - /** - * LOKDocView::dialog-child: - * @pDocView: the #LOKDocView on which the signal is emitted - * @pPayload: JSON described below: - * - * Invalidation corresponding to dialog's children. - * Eg: Floating window etc. - * - * Payload example: - * { - * "dialogID": "SpellDialog", - * "action": "close" - * } - * - * - dialogID is the UNO command of the dialog - * - action can be - * - close, means dialog child window is closed now - * - invalidate, means dialog child window is invalidated - * It also means that dialog child window is created if it's the first - * invalidate + * @pPayload: JSON containing the information, including id, about the window */ - doc_view_signals[DIALOG_CHILD] = - g_signal_new("dialog-child", + doc_view_signals[WINDOW] = + g_signal_new("window", G_TYPE_FROM_CLASS(pGObjectClass), G_SIGNAL_RUN_FIRST, 0, |