2010-10-12 15:53:47 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-09-18 15:33:13 +00:00
/*************************************************************************
*
2008-04-11 07:31:07 +00:00
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
2000-09-18 15:33:13 +00:00
*
2010-02-12 15:01:35 +01:00
* Copyright 2000 , 2010 Oracle and / or its affiliates .
2000-09-18 15:33:13 +00:00
*
2008-04-11 07:31:07 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2000-09-18 15:33:13 +00:00
*
2008-04-11 07:31:07 +00:00
* This file is part of OpenOffice . org .
2000-09-18 15:33:13 +00:00
*
2008-04-11 07:31:07 +00:00
* OpenOffice . org is free software : you can redistribute it and / or modify
* it under the terms of the GNU Lesser General Public License version 3
* only , as published by the Free Software Foundation .
2000-09-18 15:33:13 +00:00
*
2008-04-11 07:31:07 +00:00
* OpenOffice . org is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Lesser General Public License version 3 for more details
* ( a copy is included in the LICENSE file that accompanied this code ) .
2000-09-18 15:33:13 +00:00
*
2008-04-11 07:31:07 +00:00
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice . org . If not , see
* < http : //www.openoffice.org/license.html>
* for a copy of the LGPLv3 License .
2000-09-18 15:33:13 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-09-16 12:59:33 +00:00
// MARKER(update_precomp.py): autogen include statement, do not remove
# include "precompiled_framework.hxx"
2000-09-18 15:33:13 +00:00
//_________________________________________________________________________________________________________________
// my own includes
//_________________________________________________________________________________________________________________
# include <helper/oframes.hxx>
2001-06-11 09:29:50 +00:00
# include <threadhelp/resetableguard.hxx>
2000-09-18 15:33:13 +00:00
//_________________________________________________________________________________________________________________
// interface includes
//_________________________________________________________________________________________________________________
# include <com/sun/star/frame/XDesktop.hpp>
# include <com/sun/star/frame/FrameSearchFlag.hpp>
//_________________________________________________________________________________________________________________
// includes of other projects
//_________________________________________________________________________________________________________________
2001-06-11 09:29:50 +00:00
# include <vcl/svapp.hxx>
2000-09-18 15:33:13 +00:00
//_________________________________________________________________________________________________________________
// namespace
//_________________________________________________________________________________________________________________
namespace framework {
using namespace : : com : : sun : : star : : container ;
using namespace : : com : : sun : : star : : frame ;
using namespace : : com : : sun : : star : : lang ;
using namespace : : com : : sun : : star : : uno ;
using namespace : : cppu ;
using namespace : : osl ;
using namespace : : rtl ;
using namespace : : std ;
2000-10-16 10:54:42 +00:00
using namespace : : vos ;
2000-09-18 15:33:13 +00:00
//_________________________________________________________________________________________________________________
// non exported const
//_________________________________________________________________________________________________________________
//_________________________________________________________________________________________________________________
// non exported definitions
//_________________________________________________________________________________________________________________
//_________________________________________________________________________________________________________________
// declarations
//_________________________________________________________________________________________________________________
//*****************************************************************************************************************
// constructor
//*****************************************************************************************************************
OFrames : : OFrames ( const Reference < XMultiServiceFactory > & xFactory ,
const Reference < XFrame > & xOwner ,
FrameContainer * pFrameContainer )
// Init baseclasses first
2001-06-11 09:29:50 +00:00
: ThreadHelpBase ( & Application : : GetSolarMutex ( ) )
2000-09-18 15:33:13 +00:00
// Init member
2001-06-11 09:29:50 +00:00
, m_xFactory ( xFactory )
, m_xOwner ( xOwner )
, m_pFrameContainer ( pFrameContainer )
, m_bRecursiveSearchProtection ( sal_False )
2000-09-18 15:33:13 +00:00
{
// Safe impossible cases
// Method is not defined for ALL incoming parameters!
2001-06-11 09:29:50 +00:00
LOG_ASSERT ( impldbg_checkParameter_OFramesCtor ( xFactory , xOwner , pFrameContainer ) , " OFrames::OFrames() \n Invalid parameter detected! \n " )
2000-09-18 15:33:13 +00:00
}
//*****************************************************************************************************************
// (proteced!) destructor
//*****************************************************************************************************************
OFrames : : ~ OFrames ( )
{
// Reset instance, free memory ....
impl_resetObject ( ) ;
}
//*****************************************************************************************************************
// XFrames
//*****************************************************************************************************************
void SAL_CALL OFrames : : append ( const Reference < XFrame > & xFrame ) throw ( RuntimeException )
{
// Ready for multithreading
2001-06-11 09:29:50 +00:00
ResetableGuard aGuard ( m_aLock ) ;
2000-09-18 15:33:13 +00:00
// Safe impossible cases
// Method is not defined for ALL incoming parameters!
LOG_ASSERT ( impldbg_checkParameter_append ( xFrame ) , " OFrames::append() \n Invalid parameter detected! \n " )
// Do the follow only, if owner instance valid!
// Lock owner for follow operations - make a "hard reference"!
Reference < XFramesSupplier > xOwner ( m_xOwner . get ( ) , UNO_QUERY ) ;
if ( xOwner . is ( ) = = sal_True )
{
// Append frame to the end of the container ...
m_pFrameContainer - > append ( xFrame ) ;
// Set owner of this instance as parent of the new frame in container!
xFrame - > setCreator ( xOwner ) ;
}
// Else; Do nothing! Ouer owner is dead.
LOG_ASSERT ( ! ( xOwner . is ( ) = = sal_False ) , " OFrames::append() \n Ouer owner is dead - you can't append any frames ...! \n " )
}
//*****************************************************************************************************************
// XFrames
//*****************************************************************************************************************
void SAL_CALL OFrames : : remove ( const Reference < XFrame > & xFrame ) throw ( RuntimeException )
{
// Ready for multithreading
2001-06-11 09:29:50 +00:00
ResetableGuard aGuard ( m_aLock ) ;
2000-09-18 15:33:13 +00:00
// Safe impossible cases
// Method is not defined for ALL incoming parameters!
LOG_ASSERT ( impldbg_checkParameter_remove ( xFrame ) , " OFrames::remove() \n Invalid parameter detected! \n " )
// Do the follow only, if owner instance valid!
// Lock owner for follow operations - make a "hard reference"!
Reference < XFramesSupplier > xOwner ( m_xOwner . get ( ) , UNO_QUERY ) ;
if ( xOwner . is ( ) = = sal_True )
{
// Search frame and remove it from container ...
m_pFrameContainer - > remove ( xFrame ) ;
// Don't reset owner-property of removed frame!
// This must do the caller of this method himself.
// See documentation of interface XFrames for further informations.
}
// Else; Do nothing! Ouer owner is dead.
LOG_ASSERT ( ! ( xOwner . is ( ) = = sal_False ) , " OFrames::remove() \n Ouer owner is dead - you can't remove any frames ...! \n " )
}
//*****************************************************************************************************************
// XFrames
//*****************************************************************************************************************
Sequence < Reference < XFrame > > SAL_CALL OFrames : : queryFrames ( sal_Int32 nSearchFlags ) throw ( RuntimeException )
{
// Ready for multithreading
2001-06-11 09:29:50 +00:00
ResetableGuard aGuard ( m_aLock ) ;
2000-09-18 15:33:13 +00:00
// Safe impossible cases
// Method is not defined for ALL incoming parameters!
LOG_ASSERT ( impldbg_checkParameter_queryFrames ( nSearchFlags ) , " OFrames::queryFrames() \n Invalid parameter detected! \n " )
// Set default return value. (empty sequence)
Sequence < Reference < XFrame > > seqFrames ;
// Do the follow only, if owner instance valid.
// Lock owner for follow operations - make a "hard reference"!
Reference < XFrame > xOwner ( m_xOwner . get ( ) , UNO_QUERY ) ;
if ( xOwner . is ( ) = = sal_True )
{
2000-09-26 12:01:15 +00:00
// Work only, if search was not started here ...!
2001-03-29 12:17:17 +00:00
if ( m_bRecursiveSearchProtection = = sal_False )
2000-09-18 15:33:13 +00:00
{
2000-09-26 12:01:15 +00:00
// This class is a helper for services, which must implement XFrames.
// His parent and childs are MY parent and childs to.
// All searchflags are supported by this implementation!
// If some flags should not be supported - don't call me with this flags!!!
//_____________________________________________________________________________________________________________
// Search with AUTO-flag is not supported yet!
// We think about right implementation.
LOG_ASSERT ( ! ( nSearchFlags & FrameSearchFlag : : AUTO ) , " OFrames::queryFrames() \n Search with AUTO-flag is not supported yet! \n We think about right implementation. \n " )
// If searched for tasks ...
// Its not supported yet.
LOG_ASSERT ( ! ( nSearchFlags & FrameSearchFlag : : AUTO ) , " OFrames::queryFrames() \n Search for tasks not supported yet! \n " )
//_____________________________________________________________________________________________________________
// Search for ALL and GLOBAL is superflous!
// We support all necessary flags, from which these two flags are derived.
// ALL = PARENT + SELF + CHILDREN + SIBLINGS
// GLOBAL = ALL + TASKS
//_____________________________________________________________________________________________________________
// Add parent to list ... if any exist!
if ( nSearchFlags & FrameSearchFlag : : PARENT )
{
Reference < XFrame > xParent ( xOwner - > getCreator ( ) , UNO_QUERY ) ;
if ( xParent . is ( ) = = sal_True )
{
Sequence < Reference < XFrame > > seqParent ( 1 ) ;
seqParent [ 0 ] = xParent ;
impl_appendSequence ( seqFrames , seqParent ) ;
}
}
//_____________________________________________________________________________________________________________
// Add owner to list if SELF is searched.
if ( nSearchFlags & FrameSearchFlag : : SELF )
{
Sequence < Reference < XFrame > > seqSelf ( 1 ) ;
seqSelf [ 0 ] = xOwner ;
impl_appendSequence ( seqFrames , seqSelf ) ;
}
//_____________________________________________________________________________________________________________
// Add SIBLINGS to list.
if ( nSearchFlags & FrameSearchFlag : : SIBLINGS )
2000-09-18 15:33:13 +00:00
{
// Else; start a new search.
// Protect this instance against recursive calls from parents.
2001-03-29 12:17:17 +00:00
m_bRecursiveSearchProtection = sal_True ;
2000-09-18 15:33:13 +00:00
// Ask parent of my owner for frames and append results to return list.
2000-09-26 12:01:15 +00:00
Reference < XFramesSupplier > xParent ( xOwner - > getCreator ( ) , UNO_QUERY ) ;
2000-09-18 15:33:13 +00:00
// If a parent exist ...
if ( xParent . is ( ) = = sal_True )
{
// ... ask him for right frames.
2000-09-26 12:01:15 +00:00
impl_appendSequence ( seqFrames , xParent - > getFrames ( ) - > queryFrames ( nSearchFlags ) ) ;
2000-09-18 15:33:13 +00:00
}
// We have all searched informations.
// Reset protection-mode.
2001-03-29 12:17:17 +00:00
m_bRecursiveSearchProtection = sal_False ;
2000-09-18 15:33:13 +00:00
}
2000-09-26 12:01:15 +00:00
//_____________________________________________________________________________________________________________
// If searched for children, step over all elements in container and collect the informations.
if ( nSearchFlags & FrameSearchFlag : : CHILDREN )
2000-09-18 15:33:13 +00:00
{
2000-09-26 12:01:15 +00:00
// Don't search for parents, siblings and self at childrens!
// These things are supported by this instance himself.
sal_Int32 nChildSearchFlags = FrameSearchFlag : : SELF | FrameSearchFlag : : CHILDREN ;
// Step over all items of container and ask childrens for frames.
sal_uInt32 nCount = m_pFrameContainer - > getCount ( ) ;
for ( sal_uInt32 nIndex = 0 ; nIndex < nCount ; + + nIndex )
{
// We don't must control this conversion.
// We have done this at append()!
Reference < XFramesSupplier > xItem ( ( * m_pFrameContainer ) [ nIndex ] , UNO_QUERY ) ;
impl_appendSequence ( seqFrames , xItem - > getFrames ( ) - > queryFrames ( nChildSearchFlags ) ) ;
}
2000-09-18 15:33:13 +00:00
}
}
}
// Else; Do nothing! Ouer owner is dead.
LOG_ASSERT ( ! ( xOwner . is ( ) = = sal_False ) , " OFrames::queryFrames() \n Ouer owner is dead - you can't query for frames ...! \n " )
// Resturn result of this operation.
return seqFrames ;
}
//*****************************************************************************************************************
// XIndexAccess
//*****************************************************************************************************************
sal_Int32 SAL_CALL OFrames : : getCount ( ) throw ( RuntimeException )
{
// Ready for multithreading
2001-06-11 09:29:50 +00:00
ResetableGuard aGuard ( m_aLock ) ;
2000-09-18 15:33:13 +00:00
// Set default return value.
sal_Int32 nCount = 0 ;
// Do the follow only, if owner instance valid.
// Lock owner for follow operations - make a "hard reference"!
Reference < XFrame > xOwner ( m_xOwner . get ( ) , UNO_QUERY ) ;
if ( xOwner . is ( ) = = sal_True )
{
// Set CURRENT size of container for return.
nCount = m_pFrameContainer - > getCount ( ) ;
}
// Return result.
return nCount ;
}
//*****************************************************************************************************************
// XIndexAccess
//*****************************************************************************************************************
Any SAL_CALL OFrames : : getByIndex ( sal_Int32 nIndex ) throw ( IndexOutOfBoundsException ,
WrappedTargetException ,
RuntimeException )
{
// Ready for multithreading
2001-06-11 09:29:50 +00:00
ResetableGuard aGuard ( m_aLock ) ;
2000-09-18 15:33:13 +00:00
2006-06-19 10:18:57 +00:00
sal_uInt32 nCount = m_pFrameContainer - > getCount ( ) ;
if ( nIndex < 0 | | ( sal : : static_int_cast < sal_uInt32 > ( nIndex ) > = nCount ) )
throw IndexOutOfBoundsException ( OUString : : createFromAscii ( " OFrames::getByIndex - Index out of bounds " ) ,
( OWeakObject * ) this ) ;
2000-09-18 15:33:13 +00:00
// Set default return value.
Any aReturnValue ;
// Do the follow only, if owner instance valid.
// Lock owner for follow operations - make a "hard reference"!
Reference < XFrame > xOwner ( m_xOwner . get ( ) , UNO_QUERY ) ;
if ( xOwner . is ( ) = = sal_True )
{
// Get element form container.
// (If index not valid, FrameContainer return NULL!)
2002-05-23 11:54:59 +00:00
aReturnValue < < = ( * m_pFrameContainer ) [ nIndex ] ;
2000-09-18 15:33:13 +00:00
}
// Return result of this operation.
return aReturnValue ;
}
//*****************************************************************************************************************
// XElementAccess
//*****************************************************************************************************************
Type SAL_CALL OFrames : : getElementType ( ) throw ( RuntimeException )
{
// This "container" support XFrame-interfaces only!
return : : getCppuType ( ( const Reference < XFrame > * ) NULL ) ;
}
//*****************************************************************************************************************
// XElementAccess
//*****************************************************************************************************************
sal_Bool SAL_CALL OFrames : : hasElements ( ) throw ( RuntimeException )
{
// Ready for multithreading
2001-06-11 09:29:50 +00:00
ResetableGuard aGuard ( m_aLock ) ;
2000-09-18 15:33:13 +00:00
// Set default return value.
sal_Bool bHasElements = sal_False ;
// Do the follow only, if owner instance valid.
// Lock owner for follow operations - make a "hard reference"!
Reference < XFrame > xOwner ( m_xOwner . get ( ) , UNO_QUERY ) ;
if ( xOwner . is ( ) = = sal_True )
{
// If some elements exist ...
if ( m_pFrameContainer - > getCount ( ) > 0 )
{
// ... change this state value!
bHasElements = sal_True ;
}
}
// Return result of this operation.
return bHasElements ;
}
//*****************************************************************************************************************
// proteced method
//*****************************************************************************************************************
void OFrames : : impl_resetObject ( )
{
// Attention:
// Write this for multiple calls - NOT AT THE SAME TIME - but for more then one call again)!
// It exist two ways to call this method. From destructor and from disposing().
// I can't say, which one is the first. Normaly the disposing-call - but other way ....
// This instance can't work if the weakreference to owner is invalid!
// Destroy this to reset this object.
m_xOwner = WeakReference < XFrame > ( ) ;
// Reset pointer to shared container to!
m_pFrameContainer = NULL ;
}
//*****************************************************************************************************************
// private method
//*****************************************************************************************************************
void OFrames : : impl_appendSequence ( Sequence < Reference < XFrame > > & seqDestination ,
const Sequence < Reference < XFrame > > & seqSource )
{
// Get some informations about the sequences.
sal_Int32 nSourceCount = seqSource . getLength ( ) ;
sal_Int32 nDestinationCount = seqDestination . getLength ( ) ;
const Reference < XFrame > * pSourceAccess = seqSource . getConstArray ( ) ;
Reference < XFrame > * pDestinationAccess = seqDestination . getArray ( ) ;
// Get memory for result list.
Sequence < Reference < XFrame > > seqResult ( nSourceCount + nDestinationCount ) ;
Reference < XFrame > * pResultAccess = seqResult . getArray ( ) ;
sal_Int32 nResultPosition = 0 ;
// Copy all items from first sequence.
for ( sal_Int32 nSourcePosition = 0 ; nSourcePosition < nSourceCount ; + + nSourcePosition )
{
pResultAccess [ nResultPosition ] = pSourceAccess [ nSourcePosition ] ;
+ + nResultPosition ;
}
// Don't manipulate nResultPosition between these two loops!
// Its the current position in the result list.
// Copy all items from second sequence.
for ( sal_Int32 nDestinationPosition = 0 ; nDestinationPosition < nDestinationCount ; + + nDestinationPosition )
{
pResultAccess [ nResultPosition ] = pDestinationAccess [ nDestinationPosition ] ;
+ + nResultPosition ;
}
// Return result of this operation.
seqDestination . realloc ( 0 ) ;
seqDestination = seqResult ;
}
//_________________________________________________________________________________________________________________
// debug methods
//_________________________________________________________________________________________________________________
/*-----------------------------------------------------------------------------------------------------------------
The follow methods checks the parameter for other functions . If a parameter or his value is non valid ,
we return " sal_False " . ( else sal_True ) This mechanism is used to throw an ASSERT !
ATTENTION
If you miss a test for one of this parameters , contact the autor or add it himself ! ( ? )
But . . . look for right testing ! See using of this methods !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
# ifdef ENABLE_ASSERTIONS
//*****************************************************************************************************************
// An instance of this class can only work with valid initialization.
// We share the mutex with ouer owner class, need a valid factory to instanciate new services and
// use the access to ouer owner for some operations.
sal_Bool OFrames : : impldbg_checkParameter_OFramesCtor ( const Reference < XMultiServiceFactory > & xFactory ,
const Reference < XFrame > & xOwner ,
FrameContainer * pFrameContainer )
{
// Set default return value.
sal_Bool bOK = sal_True ;
// Check parameter.
if (
( & xFactory = = NULL ) | |
( & xOwner = = NULL ) | |
( xFactory . is ( ) = = sal_False ) | |
( xOwner . is ( ) = = sal_False ) | |
2001-03-29 12:17:17 +00:00
( pFrameContainer = = NULL )
2000-09-18 15:33:13 +00:00
)
{
bOK = sal_False ;
}
// Return result of check.
return bOK ;
}
//*****************************************************************************************************************
// Its only allowed to add valid references to container.
// AND - alle frames must support XFrames-interface!
sal_Bool OFrames : : impldbg_checkParameter_append ( const Reference < XFrame > & xFrame )
{
// Set default return value.
sal_Bool bOK = sal_True ;
// Check parameter.
if (
( & xFrame = = NULL ) | |
( xFrame . is ( ) = = sal_False )
)
{
bOK = sal_False ;
}
// Return result of check.
return bOK ;
}
//*****************************************************************************************************************
// Its only allowed to add valid references to container...
// ... => You can only delete valid references!
sal_Bool OFrames : : impldbg_checkParameter_remove ( const Reference < XFrame > & xFrame )
{
// Set default return value.
sal_Bool bOK = sal_True ;
// Check parameter.
if (
( & xFrame = = NULL ) | |
( xFrame . is ( ) = = sal_False )
)
{
bOK = sal_False ;
}
// Return result of check.
return bOK ;
}
//*****************************************************************************************************************
// A search for frames must initiate with right flags.
// Some one are superflous and not supported yet. But here we control only the range of incoming parameter!
sal_Bool OFrames : : impldbg_checkParameter_queryFrames ( sal_Int32 nSearchFlags )
{
// Set default return value.
sal_Bool bOK = sal_True ;
// Check parameter.
if (
( nSearchFlags ! = FrameSearchFlag : : AUTO ) & &
( ! ( nSearchFlags & FrameSearchFlag : : PARENT ) ) & &
( ! ( nSearchFlags & FrameSearchFlag : : SELF ) ) & &
( ! ( nSearchFlags & FrameSearchFlag : : CHILDREN ) ) & &
( ! ( nSearchFlags & FrameSearchFlag : : CREATE ) ) & &
( ! ( nSearchFlags & FrameSearchFlag : : SIBLINGS ) ) & &
( ! ( nSearchFlags & FrameSearchFlag : : TASKS ) ) & &
( ! ( nSearchFlags & FrameSearchFlag : : ALL ) ) & &
( ! ( nSearchFlags & FrameSearchFlag : : GLOBAL ) )
)
{
bOK = sal_False ;
}
// Return result of check.
return bOK ;
}
# endif // #ifdef ENABLE_ASSERTIONS
} // namespace framework
2010-10-12 15:53:47 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */