/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/** A CallbackCaller registers as listener at an XConfigurationController object and waits for the notification of one type of event. When that event is received, or when the CallbackCaller detects at its construction that the event will not be sent in the near future, the actual callback object is called and the CallbackCaller destroys itself.
*/ class CallbackCaller
: public CallbackCallerInterfaceBase
{ public: /** Create a new CallbackCaller object. This object controls its own lifetime by acquiring a reference to itself in the constructor. When it detects that the event will not be notified in the near future (because the queue of pending configuration change operations is empty and therefore no event will be sent int the near future, it does not acquires a reference and thus initiates its destruction in the constructor.) @param rBase This ViewShellBase object is used to determine the XConfigurationController at which to register. @param rsEventType The event type which the callback is waiting for. @param pCallback The callback object which is to be notified. The caller will typically release his reference to the caller so that when the CallbackCaller dies (after having called the callback) the callback is destroyed.
*/
CallbackCaller ( const ::sd::ViewShellBase& rBase,
OUString sEventType,
::sd::framework::FrameworkHelper::ConfigurationChangeEventFilter aFilter,
::sd::framework::FrameworkHelper::Callback aCallback);
/** This class helps controlling the lifetime of the FrameworkHelper. Register at a ViewShellBase object and an XController object and call Dispose() at the associated FrameworkHelper object when one of them and Release() when both of them are destroyed.
*/ class LifetimeController
: public LifetimeControllerInterfaceBase, public SfxListener
{ public: explicit LifetimeController (::sd::ViewShellBase& rBase); virtual ~LifetimeController() override;
/** XEventListener. This method is called when the frame::XController is being destroyed.
*/ using WeakComponentImplHelperBase::disposing; virtualvoid SAL_CALL disposing (const lang::EventObject& rEvent) override;
/** This method is called when the ViewShellBase is being destroyed.
*/ virtualvoid Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint) override;
/** When one or both of the mbListeningToViewShellBase and mbListeningToController members were modified then call this method to either dispose or release the associated FrameworkHelper.
*/ void Update();
};
/** The ViewURLMap is used to translate between the view URLs used by the drawing framework and the enums defined in the ViewShell class.
*/ class FrameworkHelper::ViewURLMap
: public std::unordered_map<
OUString,
ViewShell::ShellType>
{ public:
ViewURLMap() {}
};
const OUString & FrameworkHelper::GetViewURL (ViewShell::ShellType eType)
{ switch (eType)
{ case ViewShell::ST_IMPRESS : return msImpressViewURL; case ViewShell::ST_DRAW : return msDrawViewURL; case ViewShell::ST_OUTLINE : return msOutlineViewURL; case ViewShell::ST_NOTES : return msNotesViewURL; case ViewShell::ST_HANDOUT : return msHandoutViewURL; case ViewShell::ST_SLIDE_SORTER : return msSlideSorterURL; case ViewShell::ST_PRESENTATION : return msPresentationViewURL; case ViewShell::ST_SIDEBAR : return msSidebarViewURL; case ViewShell::ST_NOTESPANEL: return msNotesPanelViewURL; default: return EMPTY_OUSTRING;
}
}
namespace
{
void updateEditMode(const Reference<XView> &xView, const EditMode eEMode, bool updateFrameView)
{ // Ensure we have the expected edit mode // The check is only for DrawViewShell as OutlineViewShell // and SlideSorterViewShell have no master mode const ::std::shared_ptr<ViewShell> pCenterViewShell (FrameworkHelper::GetViewShell(xView));
DrawViewShell* pDrawViewShell
= dynamic_cast<DrawViewShell*>(pCenterViewShell.get()); if (pDrawViewShell != nullptr)
{
pCenterViewShell->Broadcast (
ViewShellHint(ViewShellHint::HINT_CHANGE_EDIT_MODE_START));
pDrawViewShell->ChangeEditMode(eEMode, pDrawViewShell->IsLayerModeActive()); if (updateFrameView)
pDrawViewShell->WriteFrameViewData();
/** A callback that sets a flag to a specified value when the callback is called.
*/ class FlagUpdater
{ public: explicit FlagUpdater (bool& rFlag) : mrFlag(rFlag) {} voidoperator() (bool) const {mrFlag = true;} private: bool& mrFlag;
};
CallbackCaller::CallbackCaller ( const ::sd::ViewShellBase& rBase,
OUString rsEventType,
::sd::framework::FrameworkHelper::ConfigurationChangeEventFilter aFilter,
::sd::framework::FrameworkHelper::Callback aCallback)
: msEventType(std::move(rsEventType)),
maFilter(std::move(aFilter)),
maCallback(std::move(aCallback))
{ try
{
sd::DrawController* pDrawController = rBase.GetDrawController(); if (!pDrawController) return;
mxConfigurationController = pDrawController->getConfigurationController(); if (mxConfigurationController.is())
{ if (mxConfigurationController->hasPendingRequests())
mxConfigurationController->addConfigurationChangeListener(this,msEventType,Any()); else
{ // There are no requests waiting to be processed. Therefore // no event, especially not the one we are waiting for, will // be sent in the near future and the callback would never be // called. // Call the callback now and tell him that the event it is // waiting for was not sent.
mxConfigurationController = nullptr;
maCallback(false);
}
}
} catch (RuntimeException&)
{
DBG_UNHANDLED_EXCEPTION("sd");
}
}
maCallback(true); if (mxConfigurationController.is())
{ // Reset the reference to the configuration controller so that // dispose() will not try to remove the listener a second time.
Reference<XConfigurationController> xCC (mxConfigurationController);
mxConfigurationController = nullptr;
// Removing this object from the controller may very likely lead // to its destruction, so no calls after that.
xCC->removeConfigurationChangeListener(this);
}
}
LifetimeController::LifetimeController (::sd::ViewShellBase& rBase)
: mrBase(rBase),
mbListeningToViewShellBase(false),
mbListeningToController(false)
{ // Register as listener at the ViewShellBase. Because that is not done // via a reference we have to increase the reference count manually. // This is necessary even though listening to the XController did // increase the reference count because the controller may release its // reference to us before the ViewShellBase is destroyed.
StartListening(mrBase);
acquire();
mbListeningToViewShellBase = true;
void LifetimeController::Update()
{ if (mbListeningToViewShellBase && mbListeningToController)
{ // Both the controller and the ViewShellBase are alive. Keep // waiting for their destruction.
} elseif (mbListeningToViewShellBase)
{ // The controller has been destroyed but the ViewShellBase is still // alive. Dispose the associated FrameworkHelper but keep it around // so that no new instance is created for the dying framework.
::sd::framework::FrameworkHelper::DisposeInstance(mrBase);
} else
{ // Both the controller and the ViewShellBase have been destroyed. // Remove the FrameworkHelper so that the next call its Instance() // method can create a new instance.
::sd::framework::FrameworkHelper::ReleaseInstance(mrBase);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.