/* -*- 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 .
*/
// This enum can be used to set different active states of frames enum EActiveState
{
E_INACTIVE, // I am not a member of active path in tree and I don't have the focus.
E_ACTIVE, // I am in the middle of an active path in tree and I don't have the focus.
E_FOCUS // I have the focus now. I must be a member of an active path!
};
/*-************************************************************************************************************ @short implements a normal frame of hierarchy @descr An instance of this class can be a normal node in a frame tree. A frame supports influencing its subtree, finding of subframes, activate- and deactivate-mechanisms as well as set/get of a frame window, component or controller.
*/ class XFrameImpl: private cppu::BaseMutex, public cppu::PartialWeakComponentImplHelper<
css::lang::XServiceInfo, css::frame::XFrame2, css::awt::XWindowListener,
css::awt::XTopWindowListener, css::awt::XFocusListener,
css::document::XActionLockable, css::util::XCloseable,
css::frame::XComponentLoader, css::frame::XTitle,
css::frame::XTitleChangeBroadcaster, css::beans::XPropertySet,
css::beans::XPropertySetInfo>
{ public:
/** set a new owner for this helper. * * This owner is used as source for all broadcasted events. * Further we hold it weak, because we don't wish to be disposed() .-)
*/ void impl_setPropertyChangeBroadcaster(XFrameImpl& rBroadcaster);
/** add a new property info to the set of supported ones. * * @param aProperty * describes the new property. * * @throw [css::beans::PropertyExistException] * if a property with the same name already exists. * * Note: The consistence of the whole set of properties is not checked here. * Meaning e.g. a handle which exists more than once is not detected. * The owner of this class has to be sure, that no new property * clashes with an existing one.
*/ void impl_addPropertyInfo(const css::beans::Property& aProperty);
/** mark the object as "dead".
*/ void impl_disablePropertySet();
/*-**************************************************************************************************** @short helper methods @descr The following methods are needed at different points in our code (more than once!).
@attention Threadsafe methods are signed by "implts_..."!
*/
/// reference to factory, which has created this instance
css::uno::Reference< css::uno::XComponentContext > m_xContext; /// reference to factory helper to create status indicator objects
css::uno::Reference< css::task::XStatusIndicatorFactory > m_xIndicatorFactoryHelper; /// points to an external set progress, which should be used instead of the internal one.
css::uno::WeakReference< css::task::XStatusIndicator > m_xIndicatorInterception; /// helper for XDispatch/Provider and interception interfaces
rtl::Reference< InterceptionHelper > m_xDispatchHelper; /// helper for XFrames, XIndexAccess and XElementAccess interfaces
rtl::Reference< OFrames > m_xFramesHelper; /// container for ALL Listeners
comphelper::OMultiTypeInterfaceContainerHelper2 m_aListenerContainer; /// parent of this frame
css::uno::Reference< css::frame::XFramesSupplier > m_xParent; /// containerwindow of this frame for embedded components
css::uno::Reference< css::awt::XWindow > m_xContainerWindow; /// window of the actual component
css::uno::Reference< css::awt::XWindow > m_xComponentWindow; /// controller of the actual frame
css::uno::Reference< css::frame::XController > m_xController; /// listen to drag & drop
rtl::Reference< OpenFileDropTargetListener > m_xDropTargetListener; /// state, if I am a member of an active path in the tree or I have the focus or...
EActiveState m_eActiveState; /// name of this frame
OUString m_sName; /// frame has no parent or the parent is a task or the desktop bool m_bIsFrameTop; /// due to FrameActionEvent bool m_bConnected;
sal_Int16 m_nExternalLockCount; /// is used for dispatch recording and will be set/get from outside. Only the frame provides it!
css::uno::Reference< css::frame::XDispatchRecorderSupplier > m_xDispatchRecorderSupplier; /// ref counted class to support disabling commands defined by configuration file
SvtCommandOptions m_aCommandOptions; /// in case of CloseVetoException on method close() was thrown by ourselves, we must close ourselves later if no internal processes are running bool m_bSelfClose; /// indicates, if this frame is used in hidden mode or not bool m_bIsHidden; /// The container window has WindowExtendedStyle::DocHidden set. bool m_bDocHidden = false; /// Is used to layout the child windows of the frame.
css::uno::Reference< css::frame::XLayoutManager2 > m_xLayoutManager;
rtl::Reference< DispatchInformationProvider > m_xDispatchInfoHelper;
rtl::Reference< TitleHelper > m_xTitleHelper;
// hold it weak ... otherwise this helper has to be "killed" explicitly .-)
unotools::WeakReference< XFrameImpl > m_xBroadcaster;
FrameContainer m_aChildFrameContainer; /// array of child frames /** * URL of the file that is being loaded. During the loading we don't have a controller yet.
*/
OUString m_aURL;
};
/*-**************************************************************************************************** @short standard constructor to create instance by factory @descr This constructor initializes a new instance of this class by valid factory, and will be set valid values on its member and base classes.
@attention a) Don't use your own reference during a UNO-Service-ctor! There is no guarantee, that you will succeed (e.g. using your reference as parameter to initialize some member). Do such things in the DEFINE_INIT_SERVICE() method, which is called automatically after your ctor!!! b) Base class OBroadcastHelper is a typedef in namespace cppu! The Microsoft compiler has some problems to handle it right by using namespace explicitly ::cppu::OBroadcastHelper. If we write it without a namespace or expand the typedef to OBroadcastHelperVar<...> -> it will be OK!? I don't know why! (other compilers not tested, but it works!)
@seealso method DEFINE_INIT_SERVICE()
@param xContext is the multi service manager, which creates this instance. The value must be different from NULL! @onerror ASSERT in debug version or nothing in release version.
*/
XFrameImpl::XFrameImpl( css::uno::Reference< css::uno::XComponentContext > xContext )
: PartialWeakComponentImplHelper(m_aMutex) // init member
, m_xContext (std::move( xContext ))
, m_aListenerContainer ( m_aMutex )
, m_eActiveState ( E_INACTIVE )
, m_bIsFrameTop ( true ) // I think we are top without a parent and there is no parent yet!
, m_bConnected ( false ) // There exists no component inside of us => sal_False, we are not connected!
, m_nExternalLockCount ( 0 )
, m_bSelfClose ( false ) // Important!
, m_bIsHidden ( true )
, m_lSimpleChangeListener ( m_aMutex )
, m_lVetoChangeListener ( m_aMutex )
{
}
// Initialize a new DispatchHelper-object to handle dispatches. // We use this helper as a slave for our interceptor helper, not directly! // But the helper is an event listener in THIS instance!
rtl::Reference<DispatchProvider> xDispatchProvider = new DispatchProvider( m_xContext, this );
m_xDispatchInfoHelper = new DispatchInformationProvider(m_xContext, this);
// Initialize a new interception helper object to handle dispatches and implement an interceptor mechanism. // Set created dispatch provider as slowest slave of it. // Hold interception helper by reference only - not by pointer! // So it's easier to destroy it.
m_xDispatchHelper = new InterceptionHelper( this, xDispatchProvider );
// Initialize a new XFrames-helper-object to handle XIndexAccess and XElementAccess. // We only hold the member as reference and not as pointer! // Attention: we share our frame container with this helper. Container itself is threadsafe ... So I think we can do that. // But look at dispose() for the right order of deinitialization.
m_xFramesHelper = new OFrames( this, &m_aChildFrameContainer );
// Initialize the drop target listener. // We only hold the member as reference and not as pointer!
m_xDropTargetListener = new OpenFileDropTargetListener( m_xContext, this );
// Safe impossible cases // We can't work without these helpers!
SAL_WARN_IF( !xDispatchProvider.is(), "fwk.frame", "XFrameImpl::XFrameImpl(): Slowest slave for dispatch- and interception helper " "is not valid. XDispatchProvider, XDispatch, XDispatchProviderInterception are not full supported!" );
SAL_WARN_IF( !m_xDispatchHelper.is(), "fwk.frame", "XFrameImpl::XFrameImpl(): Interception helper is not valid. XDispatchProvider, " "XDispatch, XDispatchProviderInterception are not full supported!" );
SAL_WARN_IF( !m_xFramesHelper.is(), "fwk.frame", "XFrameImpl::XFrameImpl(): Frames helper is not valid. XFrames, " "XIndexAccess and XElementAccess are not supported!" );
SAL_WARN_IF( !m_xDropTargetListener.is(), "fwk.frame", "XFrameImpl::XFrameImpl(): DropTarget helper is not valid. " "Drag and drop without functionality!" );
// establish notifications for changing of "disabled commands" configuration during runtime
m_aCommandOptions.EstablishFrameCallback(this);
// Create an initial layout manager // Create layout manager and connect it to the newly created frame
m_xLayoutManager = css::frame::LayoutManager::create(m_xContext);
/*-************************************************************************************************************ @interface XComponentLoader @short try to load given URL into a task @descr You can give us some information about the content, which you will load into a frame. We search or create this target for you, make a type detection of the given URL and try to load it. As result of this operation we return the new created component or nothing, if loading failed. @param "sURL" , URL, which represents the content @param "sTargetFrameName" , name of target frame or special value like "_self", "_blank" ... @param "nSearchFlags" , optional arguments for frame search, if target is not a special one @param "lArguments" , optional arguments for loading @return A valid component reference, if loading was successful. A null reference otherwise.
@onerror We return a null reference. @threadsafe yes
*/
css::uno::Reference< css::lang::XComponent > SAL_CALL XFrameImpl::loadComponentFromURL( const OUString& sURL, const OUString& sTargetFrameName,
sal_Int32 nSearchFlags, const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
{
checkDisposed();
if (bOnMainThread)
{ // Make sure that we own the solar mutex, otherwise later // vcl::SolarThreadExecutor::execute() will release the solar mutex, even if it's owned by // another thread, leading to an std::abort() at the end.
SolarMutexGuard g;
/*-**************************************************************************************************** @short return access to append or remove children on desktop @descr We don't implement this interface directly. We use a helper class to do this. If you wish to add or delete children to/from the container, call this method to get a reference to the helper.
@seealso class OFrames @return A reference to the helper which answers your queries.
@onerror A null reference is returned.
*/
css::uno::Reference< css::frame::XFrames > SAL_CALL XFrameImpl::getFrames()
{
checkDisposed();
SolarMutexGuard g; // Return access to all child frames to caller. // Our childframe container is implemented in helper class OFrames and used as a reference m_xFramesHelper! return m_xFramesHelper;
}
/*-**************************************************************************************************** @short get the current active child frame @descr It must be a frame, too. Direct children of a frame are frames only! No task or desktop is accepted. We don't save this information directly in this class. We use our container-helper to do that.
@seealso class OFrameContainer @seealso method setActiveFrame() @return A reference to our current active childframe, if any exist. @return A null reference, if nobody is active.
@onerror A null reference is returned.
*/
css::uno::Reference< css::frame::XFrame > SAL_CALL XFrameImpl::getActiveFrame()
{
checkDisposed();
SolarMutexGuard g; // Return current active frame. // This information is available via the container. return m_aChildFrameContainer.getActive();
}
/*-**************************************************************************************************** @short set the new active direct child frame @descr It must be a frame, too. Direct children of frame are frames only! No task or desktop is accepted. We don't save this information directly in this class. We use our container-helper to do that.
@seealso class OFrameContainer @seealso method getActiveFrame()
@param "xFrame", reference to new active child. It must be an already existing child! @onerror An assertion is thrown and element is ignored, if the given frame isn't already a child of us.
*/ void SAL_CALL XFrameImpl::setActiveFrame( const css::uno::Reference< css::frame::XFrame >& xFrame )
{
checkDisposed();
/* SAFE AREA ----------------------------------------------------------------------------------------------- */
SolarMutexResettableGuard aWriteLock;
// Copy necessary member for threadsafe access! // m_aChildFrameContainer itself is threadsafe and it lives if we live!!!
css::uno::Reference< css::frame::XFrame > xActiveChild = m_aChildFrameContainer.getActive();
EActiveState eActiveState = m_eActiveState;
aWriteLock.clear(); /* UNSAFE AREA --------------------------------------------------------------------------------------------- */
// Don't work, if "new" active frame isn't different from current one! // (xFrame==NULL is allowed to UNSET it!) if( xActiveChild != xFrame )
{ // ... otherwise set new and deactivate old one.
m_aChildFrameContainer.setActive( xFrame ); if (
( eActiveState != E_INACTIVE ) &&
xActiveChild.is()
)
{
xActiveChild->deactivate();
}
}
if( xFrame.is() )
{ // If last active frame had focus ... // ... reset state to ACTIVE and send right FrameActionEvent for focus lost. if( eActiveState == E_FOCUS )
{
aWriteLock.reset();
eActiveState = E_ACTIVE;
m_eActiveState = eActiveState;
aWriteLock.clear();
implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_UI_DEACTIVATING );
}
// If last active frame was active ... // but new one is not it ... // ... set it as the active one. if ( eActiveState == E_ACTIVE && !xFrame->isActive() )
{
xFrame->activate();
}
} else // If this frame is active and has no active subframe anymore it is UI active too if( eActiveState == E_ACTIVE )
{
aWriteLock.reset();
eActiveState = E_FOCUS;
m_eActiveState = eActiveState;
aWriteLock.clear();
implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_UI_ACTIVATED );
}
}
/*-**************************************************************************************************** initialize new created layout manager
**/ void lcl_enableLayoutManager(const css::uno::Reference< css::frame::XLayoutManager2 >& xLayoutManager, const css::uno::Reference< css::frame::XFrame >& xFrame )
{ // Provide container window to our layout manager implementation
xLayoutManager->attachFrame(xFrame);
xFrame->addFrameActionListener(xLayoutManager);
rtl::Reference<DockingAreaDefaultAcceptor> xDockingAreaAcceptor = new DockingAreaDefaultAcceptor(xFrame);
xLayoutManager->setDockingAreaAcceptor(xDockingAreaAcceptor);
}
/*-**************************************************************************************************** @short initialize frame instance @descr A frame needs a window. This method sets a new one, but should only be called once! We use this window to listen for window events and to forward them to our set component. It's used as a parent of component window, too.
@seealso method getContainerWindow() @seealso method setComponent() @seealso member m_xContainerWindow
@param "xWindow", reference to a new container window - must be valid! @onerror We do nothing.
*/ void SAL_CALL XFrameImpl::initialize( const css::uno::Reference< css::awt::XWindow >& xWindow )
{ /* UNSAFE AREA --------------------------------------------------------------------------------------------- */ if (!xWindow.is()) throw css::uno::RuntimeException(
u"XFrameImpl::initialize() called without a valid container window reference."_ustr, static_cast< css::frame::XFrame* >(this));
checkDisposed();
/* SAFE AREA ----------------------------------------------------------------------------------------------- */
SolarMutexResettableGuard aWriteLock;
// This must be the first call of this method! // We should initialize our object and open it for working. if ( m_xContainerWindow.is() ) throw css::uno::RuntimeException(
u"XFrameImpl::initialized() is called more than once, which is not useful nor allowed."_ustr, static_cast< css::frame::XFrame* >(this));
// Set the new window.
m_xContainerWindow = xWindow;
// if window is initially visible, we will never get a windowShowing event
VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xWindow); if (pWindow)
{ if (pWindow->IsVisible())
m_bIsHidden = false;
m_bDocHidden
= static_cast<bool>(pWindow->GetExtendedStyle() & WindowExtendedStyle::DocHidden);
}
// Release lock, because we call some impl methods, which are threadsafe by themselves. // If we hold this lock - we will produce our own deadlock!
aWriteLock.clear(); /* UNSAFE AREA --------------------------------------------------------------------------------------------- */
// Avoid enabling the layout manager for hidden frames: it's expensive and // provides little value. if (xLayoutManager.is() && !m_bDocHidden)
lcl_enableLayoutManager(xLayoutManager, this);
// Initialize title functionality
m_xTitleHelper = new TitleHelper( m_xContext, xThis, nullptr );
}
/*-**************************************************************************************************** @short returns currently set container window @descr The ContainerWindow property is used as a container for the component in this frame. So this object implements a container interface too. The instantiation of the container window is done by the user of this class. The frame is the owner of its container window.
@seealso method initialize() @return A reference to the currently set containerwindow.
@onerror A null reference is returned.
*/
css::uno::Reference< css::awt::XWindow > SAL_CALL XFrameImpl::getContainerWindow()
{
SolarMutexGuard g; return m_xContainerWindow;
}
/*-**************************************************************************************************** @short set parent frame @descr We need a parent to support some functionality! e.g. findFrame() By the way, we use the chance to set internal information about our top state. So we must not check this information during every isTop() call. We are top, if our parent is the desktop instance or we have no parent.
/*-**************************************************************************************************** @short returns current parent frame @descr The Creator is the parent frame container. If it is NULL, the frame is the topmost one.
@seealso method setCreator() @return A reference to currently set parent frame container.
@onerror A null reference is returned.
*/
css::uno::Reference< css::frame::XFramesSupplier > SAL_CALL XFrameImpl::getCreator()
{
checkDisposed();
SolarMutexGuard g; return m_xParent;
}
/*-**************************************************************************************************** @short returns currently set name of frame @descr This name is used to find the target of findFrame() or queryDispatch() calls.
@seealso method setName() @return Current set name of frame.
@onerror An empty string is returned.
*/
OUString SAL_CALL XFrameImpl::getName()
{
SolarMutexGuard g; return m_sName;
}
/*-**************************************************************************************************** @short set new name for frame @descr This name is used to find the target of findFrame() or queryDispatch() calls.
@attention Special names like "_blank", "_self" aren't allowed... "_beamer" is an exception to this rule!
@seealso method getName()
@param "sName", new frame name. @onerror We do nothing.
*/ void SAL_CALL XFrameImpl::setName( const OUString& sName )
{
SolarMutexGuard g; // Set new name... but look for invalid special target names! // They are not allowed to set. if (TargetHelper::isValidNameForFrame(sName))
m_sName = sName;
}
/*-**************************************************************************************************** @short search for frames @descr This method searches for a frame with the specified name. Frames may contain other frames (e.g. a frameset) and may be contained in other frames. This hierarchy is searched by this method. First some special names are taken into account, i.e. "", "_self", "_top", "_blank" etc. The nSearchFlags are ignored when comparing these names with sTargetFrameName, further steps are controlled by the search flags. If allowed, the name of the frame itself is compared with the desired one, then ( again if allowed ) the method findFrame() is called for all children, for siblings and as last for the parent frame. If no frame with the given name is found until the top frames container, a new top one is created, if this is allowed by a special flag. The new frame also gets the desired name.
@param sTargetFrameName special names (_blank, _self) or real name of target frame @param nSearchFlags optional flags which regulate search for non special target frames
@return A reference to found or maybe new created frame. @threadsafe yes
*/
css::uno::Reference< css::frame::XFrame > SAL_CALL XFrameImpl::findFrame( const OUString& sTargetFrameName,
sal_Int32 nSearchFlags )
{
css::uno::Reference< css::frame::XFrame > xTarget;
// 0) Ignore wrong parameters! // We don't support searching for the following special targets. // If we reject these requests, we don't have to keep checking for such names // in the code that follows. If we do not reject them, very wrong // search results may occur!
if ( sTargetFrameName == SPECIALTARGET_DEFAULT ) // valid for dispatches - not for findFrame()!
{ return nullptr;
}
// I) Check for special defined targets first which must be handled exclusive. // Force using of "if() else if() ..."
// get threadsafe some members which are necessary for the functionality that follows /* SAFE { */
SolarMutexResettableGuard aReadLock;
css::uno::Reference< css::frame::XFrame > xParent = m_xParent; bool bIsTopFrame = m_bIsFrameTop; bool bIsTopWindow = WindowHelper::isTopWindow(m_xContainerWindow);
aReadLock.clear(); /* } SAFE */
// I.I) "_blank" // Not allowed for a normal frame, but for the desktop. // Use helper class to do so. It uses the desktop automatically.
// I.III) "_top" // If we are not the top frame in this hierarchy, we must forward the request to our parent. // Otherwise we must return ourselves.
elseif ( sTargetFrameName==SPECIALTARGET_TOP )
{ if (bIsTopFrame)
xTarget = this; elseif (xParent.is()) // If we are not top - the parent MUST exist. But may it's better to check it again .-)
xTarget = xParent->findFrame(SPECIALTARGET_TOP,0);
}
// I.IV) "_self", "" // This means this frame in every case.
// I.V) "_beamer" // This is a special sub frame of any task. We must return it if we found it among our direct children // or create it there if it does not already exist. // Note: such a beamer exists for task(top) frames only!
elseif ( sTargetFrameName==SPECIALTARGET_BEAMER )
{ // We are a task => search or create the beamer if (bIsTopWindow)
{
xTarget = m_aChildFrameContainer.searchOnDirectChildrens(SPECIALTARGET_BEAMER); if ( ! xTarget.is() )
{ /* TODO Creation not supported yet! Wait for new layout manager service because we can't plug it inside already opened document of this frame.
*/
}
} // We aren't a task => forward the request to our parent or ignore it. elseif (xParent.is())
xTarget = xParent->findFrame(SPECIALTARGET_BEAMER,0);
}
else
{
// II) Otherwise use optional given search flags. // Force using of combinations of such flags. It means there is no "else" part in the used if() statements. // But we must break further searches if target was already found. // Order of using flags is fixed: SELF - CHILDREN - SIBLINGS - PARENT // TASK and CREATE are handled as special cases.
// get threadsafe some members which are necessary for the functionality that follows /* SAFE { */
aReadLock.reset();
OUString sOwnName = m_sName;
aReadLock.clear(); /* } SAFE */
// II.I) SELF // Check for the right name. If it's the searched one return ourselves, otherwise // ignore this flag.
// II.II) CHILDREN // Search among all children for the given target name. // An empty name value can't occur here - because it must be already handled as "_self" // before. The used helper function of the container doesn't create any frame. // It only makes a deep search.
// II.III) TASKS // This is a special flag. It regulates search only on this task tree or allows searching among // all the other ones (which are sibling trees of us) as well. // Upper search must stop at this frame if we are the topmost one and the TASK flag is not set // or we can ignore it if we have no valid parent.
// II.III.I) SIBLINGS // Search among all our direct siblings, meaning all the children of our parent. // Use this flag in combination with TASK. We must suppress such an upper search if // the user has not set it and if we are a top frame. // Attention: don't forward this request to our parent as a findFrame() call. // In such cases we must protect ourselves from recursive calls. // Use a snapshot of our parent. But don't use queryFrames() of XFrames interface. // Because it returns all siblings and all their children including our children, // if we call it with the CHILDREN flag. We don't need that - we only need the direct container // items of our parent to start searches there. So we must use the container interface // XIndexAccess instead of XFrames.
if (
( ! xTarget.is() ) &&
(nSearchFlags & css::frame::FrameSearchFlag::SIBLINGS) &&
( xParent.is() ) // search among siblings is impossible without a parent
)
{
css::uno::Reference< css::frame::XFramesSupplier > xSupplier( xParent, css::uno::UNO_QUERY ); if (xSupplier.is())
{
css::uno::Reference< css::container::XIndexAccess > xContainer = xSupplier->getFrames(); if (xContainer.is())
{
sal_Int32 nCount = xContainer->getCount(); for( sal_Int32 i=0; i<nCount; ++i )
{
css::uno::Reference< css::frame::XFrame > xSibling; if ( // control unpacking
( !(xContainer->getByIndex(i)>>=xSibling) ) || // check for valid items
( ! xSibling.is() ) || // ignore ourselves! (We are a part of this container too, but search among our children was already done.)
( xSibling==static_cast< ::cppu::OWeakObject* >(this) )
)
{ continue;
}
// Don't allow upper search here! Use the appropriate flags to regulate it. // And only allow deep search among children, if it was allowed for us as well.
sal_Int32 nRightFlags = css::frame::FrameSearchFlag::SELF; if (nSearchFlags & css::frame::FrameSearchFlag::CHILDREN)
nRightFlags |= css::frame::FrameSearchFlag::CHILDREN;
xTarget = xSibling->findFrame(sTargetFrameName, nRightFlags ); // perform search and break further searching if a result exists if (xTarget.is()) break;
}
}
}
}
// II.III.II) PARENT // Forward search to our parent (if it exists). // To avoid recursive and superfluous calls (which can occur if we allow it // to search among its children too) we must change the used search flags.
// II.IV) CREATE // If we haven't found any valid target frame by using normal flags, but the user allowed us to create // a new one, we should do that. The used TaskCreator uses Desktop instance automatically as parent!
/*-**************************************************************************************************** @descr Returns sal_True, if this frame is a "top frame", otherwise sal_False. The "m_bIsFrameTop" member must be set in the ctor or setCreator() method. A top frame is a member of the top frame container or a member of the task frame container. Both containers can create new frames if the findFrame() method of their css::frame::XFrame interface is called with a frame name not yet known.
@seealso ctor @seealso method setCreator() @seealso method findFrame() @return true, if is it a top frame ... false otherwise.
@onerror No error should occur!
*/
sal_Bool SAL_CALL XFrameImpl::isTop()
{
checkDisposed();
SolarMutexGuard g; // This information is set in setCreator(). // We are top, if our parent is a task or the desktop or if no parent exists! return m_bIsFrameTop;
}
/*-**************************************************************************************************** @short activate frame in hierarchy @descr This feature is used to mark active paths in our frame hierarchy. You can be a listener for this event to react to it and change some internal states or something else.
/* SAFE AREA ----------------------------------------------------------------------------------------------- */
SolarMutexResettableGuard aWriteLock;
// Copy necessary member and free the lock. // It's not necessary for m_aChildFrameContainer, because // it is threadsafe by itself and lives if we live.
css::uno::Reference< css::frame::XFrame > xActiveChild = m_aChildFrameContainer.getActive();
css::uno::Reference< css::frame::XFramesSupplier > xParent = m_xParent;
css::uno::Reference< css::frame::XFrame > xThis(this);
EActiveState eState = m_eActiveState;
aWriteLock.clear(); /* UNSAFE AREA --------------------------------------------------------------------------------------------- */
// 1) If I am not active before... if( eState == E_INACTIVE )
{ // ... do it then.
aWriteLock.reset();
eState = E_ACTIVE;
m_eActiveState = eState;
aWriteLock.clear(); // Deactivate sibling path and forward activation to parent, if any parent exists! if( xParent.is() )
{ // Set THIS frame as active child of parent every time and activate it. // We MUST have a valid path from bottom to top as active path! // But we must deactivate the old active sibling path first.
// Attention: deactivation of an active path, deactivates the whole path from bottom to top! // But we only wish to deactivate the found sibling-tree. // [ see deactivate() / step 4) for further information! ]
xParent->setActiveFrame( xThis );
// Then we can activate from here to top. // Attention: we are ACTIVE now. And the parent will call activate() at us! // But we do nothing then! We are already activated.
xParent->activate();
} // It's necessary to send event NOW, not before. // Activation goes from bottom to top! // That's the reason to activate parent first and send event now.
implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_ACTIVATED );
}
// 2) I was active before or currently activated and there is a path from here to bottom, who CAN be active. // But our direct child of path is not active yet. // (It can be, if activation occurs in the middle of a current path!) // In this case we activate path to bottom to set focus on the correct frame! if ( eState == E_ACTIVE && xActiveChild.is() && !xActiveChild->isActive() )
{
xActiveChild->activate();
}
// 3) I was active before or currently activated. But if I have no active child => I will get the focus! if ( eState == E_ACTIVE && !xActiveChild.is() )
{
aWriteLock.reset();
eState = E_FOCUS;
m_eActiveState = eState;
aWriteLock.clear();
implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_UI_ACTIVATED );
}
}
/*-**************************************************************************************************** @short deactivate frame in hierarchy @descr This feature is used to deactivate paths in our frame hierarchy. You can be a listener for this event to react to it and change some internal states or something else.
/* SAFE AREA ----------------------------------------------------------------------------------------------- */
SolarMutexResettableGuard aWriteLock;
// Copy necessary member and free the lock.
css::uno::Reference< css::frame::XFrame > xActiveChild = m_aChildFrameContainer.getActive();
css::uno::Reference< css::frame::XFramesSupplier > xParent = m_xParent;
css::uno::Reference< css::frame::XFrame > xThis(this);
EActiveState eState = m_eActiveState;
aWriteLock.clear(); /* UNSAFE AREA --------------------------------------------------------------------------------------------- */
// Work only, if there is something to do! if( eState == E_INACTIVE ) return;
// 1) Deactivate all active children. if ( xActiveChild.is() && xActiveChild->isActive() )
{
xActiveChild->deactivate();
}
// 2) If I have the focus, I will lose it now. if( eState == E_FOCUS )
{ // Set new state INACTIVE(!) and send message to all listeners. // Don't set ACTIVE as new state. This frame is deactivated the next time due to activate().
aWriteLock.reset();
eState = E_ACTIVE;
m_eActiveState = eState;
aWriteLock.clear();
implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_UI_DEACTIVATING );
}
// 3) If I am active, I will be deactivated now. if( eState == E_ACTIVE )
{ // Set new state and send message to all listeners.
aWriteLock.reset();
eState = E_INACTIVE;
m_eActiveState = eState;
aWriteLock.clear();
implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_DEACTIVATING );
}
// 4) If there is a path from here to my parent, // I am at the top or in the middle of a deactivated subtree and the action was started here. // I must deactivate all frames from here to top, which are members of the current path. // Stop, if THIS frame is not the active frame of our parent! if ( xParent.is() && xParent->getActiveFrame() == xThis )
{ // We MUST break the path - otherwise we will get the focus instead of our parent! // Attention: our parent will not call us again - WE ARE NOT ACTIVE YET! // [ see step 3 and condition "if ( m_eActiveState!=INACTIVE ) ..." in this method! ]
xParent->deactivate();
}
}
/*-**************************************************************************************************** @short returns active state @descr Call it to get information about current active state of this frame.
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.