tdf#139830: keep the right context for chart after view switch (impress).

Change-Id: Ida345dd884a09b88e35e0df6f9520528c910d9d8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109791
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109898
Tested-by: Jenkins
diff --git a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
index c0264c4..05a5715 100644
--- a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
+++ b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
@@ -56,6 +56,7 @@
#include <vcl/EnumContext.hxx>
#include <svx/sidebar/ContextChangeEventMultiplexer.hxx>
#include <tools/diagnose_ex.h>
#include <sfx2/sidebar/SidebarController.hxx>

using namespace ::sd::slidesorter;
#define ShellClass_SlideSorterViewShell
@@ -67,9 +68,28 @@ using namespace ::com::sun::star::drawing::framework;

using ::sd::framework::FrameworkHelper;
using ::vcl::EnumContext;
using namespace sfx2::sidebar;

namespace sd::slidesorter {

namespace {

bool inChartContext(sd::View* pView)
{
    if (!pView)
        return false;

    SfxViewShell* pViewShell = pView->GetSfxViewShell();
    SidebarController* pSidebar = SidebarController::GetSidebarControllerForView(pViewShell);
    if (pSidebar)
        return pSidebar->hasChartContextCurrently();

    return false;
}

} // anonymous namespace


SFX_IMPL_INTERFACE(SlideSorterViewShell, SfxShell)

void SlideSorterViewShell::InitInterface_Impl()
@@ -441,6 +461,17 @@ void SlideSorterViewShell::ArrangeGUIElements()

void SlideSorterViewShell::Activate (bool bIsMDIActivate)
{
    if(inChartContext(GetView()))
    {
        // Avoid context changes for chart during activation / deactivation.
        const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false));

        ViewShell::Activate(bIsMDIActivate);

        SfxShell::SetContextBroadcasterEnabled(bIsContextBroadcasterEnabled);
        return;
    }

    ViewShell::Activate(bIsMDIActivate);
    if (mbIsArrangeGUIElementsPending)
        ArrangeGUIElements();