summaryrefslogtreecommitdiff
path: root/sd/source/ui/framework
diff options
context:
space:
mode:
authorSarper Akdemir <sarper.akdemir@allotropia.de>2024-06-07 21:14:44 +0200
committerSarper Akdemir <sarper.akdemir@allotropia.de>2024-06-28 14:25:36 +0200
commit5e143492320dac8cdf8b2956799ca366f3d8e72c (patch)
tree8a1493fa0126fa483da7770102d0386f3e382fdf /sd/source/ui/framework
parenta7d1a6f313b1ee73b8bd360a7dfb3f0fc56e64bf (diff)
tdf#33603: fix notespane (side/tool)bar interactions
Introduces OverridingShells that when set, makes the view act like the MainViewShell. The main use case is having more then one ViewShell in a single window, where context (toolbars, sidebars etc.) can jump in between different ViewShells. Uses OverridingShells to enable NotesPane to react ToolBarShells. Accessing the functionality of ToolBarShells without the previous hacks with slot forwarding. Change-Id: Icc9721d7f54097025bc9dc7ef7069aed856e6d96 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169658 Tested-by: Jenkins Reviewed-by: Sarper Akdemir <sarper.akdemir@allotropia.de>
Diffstat (limited to 'sd/source/ui/framework')
-rw-r--r--sd/source/ui/framework/module/ToolBarModule.cxx118
-rw-r--r--sd/source/ui/framework/module/ToolBarModule.hxx29
2 files changed, 129 insertions, 18 deletions
diff --git a/sd/source/ui/framework/module/ToolBarModule.cxx b/sd/source/ui/framework/module/ToolBarModule.cxx
index de7f3e583126..cf3fd880105e 100644
--- a/sd/source/ui/framework/module/ToolBarModule.cxx
+++ b/sd/source/ui/framework/module/ToolBarModule.cxx
@@ -18,10 +18,17 @@
*/
#include "ToolBarModule.hxx"
+#include <ViewShell.hxx>
#include <ViewShellBase.hxx>
+#include <ViewShellManager.hxx>
#include <DrawController.hxx>
+#include <EventMultiplexer.hxx>
#include <comphelper/servicehelper.hxx>
#include <framework/FrameworkHelper.hxx>
+#include <vcl/EnumContext.hxx>
+
+#include <com/sun/star/frame/XController.hpp>
+#include <comphelper/processfactory.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -76,6 +83,9 @@ ToolBarModule::ToolBarModule (
ToolBarModule::~ToolBarModule()
{
+ if (mpBase && mbListeningEventMultiplexer)
+ mpBase->GetEventMultiplexer()->RemoveEventListener(
+ LINK(this, ToolBarModule, EventMultiplexerListener));
}
void ToolBarModule::disposing(std::unique_lock<std::mutex>&)
@@ -93,6 +103,16 @@ void SAL_CALL ToolBarModule::notifyConfigurationChange (
if (!mxConfigurationController.is())
return;
+ // since EventMultiplexer isn't available when the ToolBarModule is
+ // initialized, subscribing the event listener hacked here.
+ if (!mbListeningEventMultiplexer && mpBase)
+ {
+ mpBase->GetEventMultiplexer()->AddEventListener(
+ LINK(this, ToolBarModule, EventMultiplexerListener));
+ mbListeningEventMultiplexer = true;
+ }
+
+
sal_Int32 nEventType = 0;
rEvent.UserData >>= nEventType;
switch (nEventType)
@@ -123,6 +143,34 @@ void SAL_CALL ToolBarModule::notifyConfigurationChange (
}
}
+void ToolBarModule::HandlePaneViewShellFocused(const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId)
+{
+ if(!mpBase)
+ return;
+
+ std::shared_ptr<FrameworkHelper> pFrameworkHelper(FrameworkHelper::Instance(*mpBase));
+ std::shared_ptr<ViewShell> pViewShell
+ = FrameworkHelper::GetViewShell(pFrameworkHelper->GetView(rxResourceId));
+
+ if(mpBase->GetMainViewShell() == pViewShell)
+ {
+ mpBase->GetViewShellManager()->RemoveOverridingMainShell();
+ return;
+ }
+
+ switch(pViewShell->GetShellType())
+ {
+ // shells that override mainviewshell functionality when used in a pane
+ case ViewShell::ST_NOTESPANEL:
+ mpBase->GetViewShellManager()->SetOverridingMainShell(pViewShell);
+ UpdateToolbars(pViewShell.get());
+ break;
+ default:
+ break;
+ }
+ mpToolBarManagerLock.reset();
+}
+
void ToolBarModule::HandleUpdateStart()
{
// Lock the ToolBarManager and tell it to lock the ViewShellManager as
@@ -149,23 +197,11 @@ void ToolBarModule::HandleUpdateEnd()
std::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
std::shared_ptr<FrameworkHelper> pFrameworkHelper (
FrameworkHelper::Instance(*mpBase));
- ViewShell* pViewShell
- = pFrameworkHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
- if (pViewShell != nullptr)
- {
- pToolBarManager->MainViewShellChanged(*pViewShell);
- pToolBarManager->SelectionHasChanged(
- *pViewShell,
- *pViewShell->GetView());
- pToolBarManager->PreUpdate();
- }
- else
- {
- pToolBarManager->MainViewShellChanged();
- pToolBarManager->PreUpdate();
- }
- }
+ auto pViewShell
+ = pFrameworkHelper->GetViewShell(FrameworkHelper::msCenterPaneURL);
+ UpdateToolbars(pViewShell.get());
+ }
// Releasing the update lock of the ToolBarManager will let the
// ToolBarManager with the help of the ViewShellManager take care of
// updating tool bars and view shell with the minimal amount of
@@ -173,6 +209,35 @@ void ToolBarModule::HandleUpdateEnd()
mpToolBarManagerLock.reset();
}
+void ToolBarModule::UpdateToolbars(ViewShell* pViewShell)
+{
+ // Update the set of visible tool bars and deactivate those that are
+ // no longer visible. This is done before the old view shell is
+ // destroyed in order to avoid unnecessary updates of those tool
+ // bars.
+ if (!mpBase)
+ return;
+
+ std::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
+
+ if(!pToolBarManager)
+ return;
+
+ if (pViewShell)
+ {
+ pToolBarManager->MainViewShellChanged(*pViewShell);
+ pToolBarManager->SelectionHasChanged(
+ *pViewShell,
+ *pViewShell->GetView());
+ pToolBarManager->PreUpdate();
+ }
+ else
+ {
+ pToolBarManager->MainViewShellChanged();
+ pToolBarManager->PreUpdate();
+ }
+}
+
void SAL_CALL ToolBarModule::disposing (const lang::EventObject& rEvent)
{
if (mxConfigurationController.is()
@@ -184,6 +249,27 @@ void SAL_CALL ToolBarModule::disposing (const lang::EventObject& rEvent)
}
}
+IMPL_LINK(ToolBarModule, EventMultiplexerListener, sd::tools::EventMultiplexerEvent&, rEvent,
+ void)
+{
+ if (!mpBase)
+ return;
+
+ switch(rEvent.meEventId)
+ {
+ case EventMultiplexerEventId::FocusShifted:
+ {
+ uno::Reference<drawing::framework::XResourceId> xResourceId{ rEvent.mxUserData,
+ UNO_QUERY };
+ if (xResourceId.is())
+ HandlePaneViewShellFocused(xResourceId);
+ break;
+ }
+ default:
+ break;
+ }
+}
+
} // end of namespace sd::framework
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/framework/module/ToolBarModule.hxx b/sd/source/ui/framework/module/ToolBarModule.hxx
index bf0c017ef981..f245e88f8562 100644
--- a/sd/source/ui/framework/module/ToolBarModule.hxx
+++ b/sd/source/ui/framework/module/ToolBarModule.hxx
@@ -20,20 +20,34 @@
#pragma once
#include <ToolBarManager.hxx>
+#include <tools/link.hxx>
#include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
+#include <com/sun/star/ui/XContextChangeEventListener.hpp>
#include <comphelper/compbase.hxx>
#include <o3tl/deleter.hxx>
#include <rtl/ref.hxx>
#include <memory>
-namespace com::sun::star::drawing::framework { class XConfigurationController; }
-namespace com::sun::star::frame { class XController; }
+namespace com::sun::star::drawing::framework
+{
+class XConfigurationController;
+class XResourceId;
+}
+namespace com::sun::star::frame
+{
+class XController;
+}
namespace sd {
class DrawController;
class ViewShellBase;
}
+namespace sd::tools
+{
+class EventMultiplexerEvent;
+}
+
namespace sd::framework {
typedef comphelper::WeakComponentImplHelper <
@@ -73,9 +87,20 @@ private:
ViewShellBase* mpBase;
std::unique_ptr<ToolBarManager::UpdateLock, o3tl::default_delete<ToolBarManager::UpdateLock>> mpToolBarManagerLock;
bool mbMainViewSwitchUpdatePending;
+ bool mbListeningEventMultiplexer = false;
+
+ /** Update toolbars via ToolbarManager
+
+ @param pViewShell may be nullptr
+ */
+ void UpdateToolbars(ViewShell* pViewShell);
void HandleUpdateStart();
void HandleUpdateEnd();
+ void HandlePaneViewShellFocused(
+ const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId);
+
+ DECL_LINK(EventMultiplexerListener, ::sd::tools::EventMultiplexerEvent&, void);
};
} // end of namespace sd::framework