From 727c2303cb70a62a35f2e7ff7cd47cdb3ccd556d Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Sat, 2 Dec 2017 02:47:38 +0530 Subject: [PATCH] lokdialog: multiview: Do not mix one view with other In GTV, use correct application window object to fetch the dialog object. Use correct view shell to notify window (dialogs, etc.) callbacks. Change-Id: I7d82b39d4522a4b4904e156757a032c342c71efb --- include/sfx2/lokhelper.hxx | 3 ++- .../gtktiledviewer/gtv-application-window.cxx | 23 ++++++++----------- .../gtktiledviewer/gtv-application-window.hxx | 2 -- .../gtv-lokdocview-signal-handlers.cxx | 9 ++++---- sfx2/source/dialog/basedlgs.cxx | 5 +--- sfx2/source/view/lokhelper.cxx | 8 ++++--- sfx2/source/view/viewsh.cxx | 2 +- 7 files changed, 22 insertions(+), 30 deletions(-) diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index f342b502e810..52c9b9763eae 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -42,7 +42,8 @@ public: /// Same as notifyOtherViews(), but works on a selected "other" view, not on all of them. static void notifyOtherView(SfxViewShell* pThisView, SfxViewShell const* pOtherView, int nType, const OString& rKey, const OString& rPayload); /// Emits a LOK_CALLBACK_WINDOW - static void notifyWindow(vcl::LOKWindowId nWindowId, + static void notifyWindow(const SfxViewShell* pThisView, + vcl::LOKWindowId nWindowId, const OUString& rAction, const std::vector& rPayload = std::vector()); /// Emits a LOK_CALLBACK_INVALIDATE_TILES, but tweaks it according to setOptionalFeatures() if needed. diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx index f58884c79207..d9c709604a28 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx @@ -315,7 +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, "window", G_CALLBACK(LOKDocViewSigHandlers::window), nullptr); + g_signal_connect(window->lokdocview, "window", G_CALLBACK(LOKDocViewSigHandlers::window), window); g_signal_connect(window->lokdocview, "configure-event", G_CALLBACK(LOKDocViewSigHandlers::configureEvent), nullptr); } @@ -402,6 +402,9 @@ gtv_application_window_get_part_broadcast(GtvApplicationWindow* window) void gtv_application_window_register_child_window(GtvApplicationWindow* window, GtkWindow* pChildWin) { + guint dialogid = 0; + g_object_get(G_OBJECT(pChildWin), "dialogid", &dialogid, nullptr); + g_debug("Register child window: dialogid [%d] in window[%p]", dialogid, window); GtvApplicationWindowPrivate* priv = getPrivate(window); if (pChildWin) priv->m_pChildWindows = g_list_append(priv->m_pChildWindows, pChildWin); @@ -410,6 +413,9 @@ gtv_application_window_register_child_window(GtvApplicationWindow* window, GtkWi void gtv_application_window_unregister_child_window(GtvApplicationWindow* window, GtkWindow* pChildWin) { + guint dialogid = 0; + g_object_get(G_OBJECT(pChildWin), "dialogid", &dialogid, nullptr); + g_debug("Unregister child window: dialogid [%d] in window[%p]", dialogid, window); GtvApplicationWindowPrivate* priv = getPrivate(window); if (pChildWin) { @@ -432,7 +438,6 @@ gtv_application_window_get_child_window_by_id(GtvApplicationWindow* window, guin { guint dialogId = 0; g_object_get(G_OBJECT(pIt->data), "dialogid", &dialogId, nullptr); - if (dialogId == nWinId) { ret = GTK_WINDOW(pIt->data); @@ -443,7 +448,8 @@ gtv_application_window_get_child_window_by_id(GtvApplicationWindow* window, guin return ret; } -GtkWidget* gtv_application_window_get_parent(GtvApplicationWindow* window, guint nWinId) +GtkWidget* +gtv_application_window_get_parent(GtvApplicationWindow* window, guint nWinId) { GtvApplicationWindowPrivate* priv = getPrivate(window); GList* pIt = nullptr; @@ -455,17 +461,6 @@ GtkWidget* gtv_application_window_get_parent(GtvApplicationWindow* window, guint 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 -GList* -gtv_application_window_get_all_child_windows(GtvApplicationWindow* window) -{ - GtvApplicationWindowPrivate* priv = getPrivate(window); - return priv->m_pChildWindows; -} - GtvApplicationWindow* gtv_application_window_new(GtkApplication* app) { diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application-window.hxx b/libreofficekit/qa/gtktiledviewer/gtv-application-window.hxx index 78e9bae3e97f..748195c5aff0 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-application-window.hxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-application-window.hxx @@ -105,8 +105,6 @@ void gtv_application_window_unregister_child_window(GtvApplicationWindow* window 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 diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx index aa15a03a83e1..78f940cb33c7 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx @@ -301,9 +301,9 @@ void LOKDocViewSigHandlers::comment(LOKDocView* pDocView, gchar* pComment, gpoin } } -void LOKDocViewSigHandlers::window(LOKDocView* pDocView, gchar* pPayload, gpointer) +void LOKDocViewSigHandlers::window(LOKDocView* pDocView, gchar* pPayload, gpointer pData) { - GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(pData); std::stringstream aStream(pPayload); boost::property_tree::ptree aRoot; @@ -350,9 +350,8 @@ void LOKDocViewSigHandlers::window(LOKDocView* pDocView, gchar* pPayload, gpoint 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); + else if (GtkWindow* pDialog = gtv_application_window_get_child_window_by_id(window, nWinId)) + { // it's the dialog window itself if (aAction == "close") gtk_widget_destroy(GTK_WIDGET(pDialog)); else if (aAction == "size_changed") diff --git a/sfx2/source/dialog/basedlgs.cxx b/sfx2/source/dialog/basedlgs.cxx index 16b69cd9c0aa..1de5c4fb2f79 100644 --- a/sfx2/source/dialog/basedlgs.cxx +++ b/sfx2/source/dialog/basedlgs.cxx @@ -249,12 +249,9 @@ void SfxModelessDialog::StateChanged( StateChangedType nStateChange ) if (comphelper::LibreOfficeKit::isActive() && pViewShell) { SetLOKNotifier(pViewShell); - // Below method doesn't really give the exact dimensions, - // Check GetSizePixel() ? - const Size aOptimalSize = GetOptimalSize(); std::vector aItems; aItems.emplace_back(std::make_pair("type", "dialog")); - aItems.emplace_back(std::make_pair("size", aOptimalSize.toString())); + aItems.emplace_back(std::make_pair("size", GetOptimalSize().toString())); pViewShell->notifyWindow(GetLOKWindowId(), "created", aItems); } diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index d78763acd3f0..135c36003192 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -144,10 +144,13 @@ void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OS } } -void SfxLokHelper::notifyWindow(vcl::LOKWindowId nLOKWindowId, +void SfxLokHelper::notifyWindow(const SfxViewShell* pThisView, + vcl::LOKWindowId nLOKWindowId, const OUString& rAction, const std::vector& rPayload) { + assert(pThisView); + if (SfxLokHelper::getViewsCount() <= 0 || nLOKWindowId == 0) return; @@ -164,8 +167,7 @@ void SfxLokHelper::notifyWindow(vcl::LOKWindowId nLOKWindowId, } aPayload += "}"; - if (SfxViewShell* pViewShell = SfxViewShell::Current()) - pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_WINDOW, aPayload.getStr()); + pThisView->libreOfficeKitViewCallback(LOK_CALLBACK_WINDOW, aPayload.getStr()); } void SfxLokHelper::notifyInvalidation(SfxViewShell const* pThisView, const OString& rPayload) diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 437a8a744db4..2c38ac071a31 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -1950,7 +1950,7 @@ Reference< view::XRenderable > SfxViewShell::GetRenderable() void SfxViewShell::notifyWindow(vcl::LOKWindowId nDialogId, const OUString& rAction, const std::vector& rPayload) const { - SfxLokHelper::notifyWindow(nDialogId, rAction, rPayload); + SfxLokHelper::notifyWindow(this, nDialogId, rAction, rPayload); } uno::Reference< datatransfer::clipboard::XClipboardNotifier > SfxViewShell::GetClipboardNotifier()