From fb2382ad4f33b885650ad5156ccaec4e90661806 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Mon, 6 Jan 2020 10:49:31 +0300 Subject: tdf#130187: Don't crash on exiting print preview with Notebookbar Crash caused by this sequence (tested in Writer): 1. Closing print preview, frame is attached to controller; 2. This calls SfxNotebookBar::StateMethod 3. There notebookbar's listener is added to list of the controller's context change event listeners 4. Then in SwPagePreview::~SwPagePreview, notebookbar's listener is added to that list again 5. ContextChangeEventMultiplexer::addContextChangeEventListener detects second addition, and throws an unhandled exception. I don't know why starting listening is needed in SwPagePreview dtor; unfortunately commit d05b7b32d9ecb6fcb4a268eb68cdcee09bafa6dd doesn't say much about context and reasons. ControlListener is renamed to ControlListenerForCurrentController to emphasize that it operates on the current controller of notebookbar's frame; and its bListen parameter meaning was reverted: previously its "true" value awkwardly meant "stop listening". All direct operations with listener of notebookbar are replaced with calls to notebookbar's methods. In ContextChangeEventMultiplexer::addContextChangeEventListener, uno::UNO_QUERY_THROW was replaced with uno::UNO_QUERY, because not only chart controller may appear here, and it's not an error: e.g. SfxBaseController doesn't implement lang::XServiceInfo. Regression after commit d05b7b32d9ecb6fcb4a268eb68cdcee09bafa6dd. Change-Id: Ief1aed188d8f02a6cfe3ea25f4d082dfdf449f32 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86257 Tested-by: Jenkins Reviewed-by: Mike Kaganski Signed-off-by: Xisco Fauli Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87582 --- include/vcl/notebookbar.hxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/vcl/notebookbar.hxx b/include/vcl/notebookbar.hxx index af904ca2ae5f..457a64b9a206 100644 --- a/include/vcl/notebookbar.hxx +++ b/include/vcl/notebookbar.hxx @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace com { namespace sun { namespace star { namespace ui { class XContextChangeEventListener; } } } } @@ -39,17 +40,17 @@ public: void SetSystemWindow(SystemWindow* pSystemWindow); - const css::uno::Reference& getContextChangeEventListener() const { return m_pEventListener; } - void StateChanged(const StateChangedType nStateChange ) override; void DataChanged(const DataChangedEvent& rDCEvt) override; - void ControlListener(bool bListen); + void ControlListenerForCurrentController(bool bListen); + void StopListeningAllControllers(); private: VclPtr m_pSystemWindow; css::uno::Reference m_pEventListener; + std::set> m_alisteningControllers; std::vector m_pContextContainers; css::uno::Reference mxFrame; -- cgit