2001-01-09 14:43:04 +00:00
/*************************************************************************
*
* $ RCSfile : genericcontroller . cxx , v $
*
2004-11-16 13:31:01 +00:00
* $ Revision : 1.56 $
2001-01-09 14:43:04 +00:00
*
2004-11-16 13:31:01 +00:00
* last change : $ Author : obo $ $ Date : 2004 - 11 - 16 14 : 31 : 01 $
2001-01-09 14:43:04 +00:00
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc . , October , 2000
*
* GNU Lesser General Public License Version 2.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* Copyright 2000 by Sun Microsystems , Inc .
* 901 San Antonio Road , Palo Alto , CA 94303 , USA
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 , as published by the Free Software Foundation .
*
* This library 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 for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston ,
* MA 02111 - 1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 ( 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.openoffice.org/license.html.
*
* Software provided under this License is provided on an AS IS basis ,
* WITHOUT WARRANTY OF ANY KIND , EITHER EXPRESSED OR IMPLIED , INCLUDING ,
* WITHOUT LIMITATION , WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS ,
* MERCHANTABLE , FIT FOR A PARTICULAR PURPOSE , OR NON - INFRINGING .
* See the License for the specific provisions governing your rights and
* obligations concerning the Software .
*
* The Initial Developer of the Original Code is : Sun Microsystems , Inc .
*
* Copyright : 2000 by Sun Microsystems , Inc .
*
* All Rights Reserved .
*
* Contributor ( s ) : _______________________________________
*
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# ifndef DBAUI_GENERICCONTROLLER_HXX
# include "genericcontroller.hxx"
# endif
# ifndef _COMPHELPER_UNO3_HXX_
# include <comphelper/uno3.hxx>
# endif
# ifndef _TOOLKIT_AWT_VCLXWINDOW_HXX_
# include <toolkit/awt/vclxwindow.hxx>
# endif
# ifndef DBACCESS_UI_BROWSER_ID_HXX
# include "browserids.hxx"
# endif
2004-08-02 14:34:22 +00:00
# ifndef _SV_SVAPP_HXX //autogen
# include <vcl/svapp.hxx>
# endif
2001-04-23 08:30:31 +00:00
# ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
# include <toolkit/helper/vclunohelper.hxx>
# endif
2001-01-09 14:43:04 +00:00
# ifndef DBAUI_DATAVIEW_HXX
# include "dataview.hxx"
# endif
# ifndef _TOOLS_DEBUG_HXX
# include <tools/debug.hxx>
# endif
# ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
# include "dbustrings.hrc"
# endif
# ifndef _VCL_STDTEXT_HXX
# include <vcl/stdtext.hxx>
# endif
2001-06-21 16:51:14 +00:00
# ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
# include <cppuhelper/typeprovider.hxx>
# endif
# ifndef _COMPHELPER_SEQUENCE_HXX_
# include <comphelper/sequence.hxx>
# endif
2001-03-15 07:29:16 +00:00
# ifndef _COMPHELPER_EXTRACT_HXX_
# include <comphelper/extract.hxx>
2001-01-09 14:43:04 +00:00
# endif
# ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
# include <com/sun/star/sdbc/XDataSource.hpp>
# endif
2001-02-27 14:11:05 +00:00
# ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
# include <com/sun/star/sdb/SQLContext.hpp>
# endif
2001-01-09 14:43:04 +00:00
# ifndef _COM_SUN_STAR_SDB_XCOMPLETEDCONNECTION_HPP_
# include <com/sun/star/sdb/XCompletedConnection.hpp>
# endif
# ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
# include <com/sun/star/beans/XPropertySet.hpp>
# endif
# ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
# include <com/sun/star/task/XInteractionHandler.hpp>
# endif
2002-06-26 07:17:57 +00:00
# ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_
# include <com/sun/star/util/XCloseable.hpp>
# endif
2001-02-23 14:17:34 +00:00
# ifndef DBAUI_TOOLS_HXX
# include "UITools.hxx"
2001-01-09 14:43:04 +00:00
# endif
2004-11-16 13:31:01 +00:00
# ifndef _DBAUI_COMMON_TYPES_HXX_
# include "commontypes.hxx"
# endif
2001-03-30 12:04:24 +00:00
# ifndef _SV_WAITOBJ_HXX
# include <vcl/waitobj.hxx>
# endif
2001-04-24 13:36:44 +00:00
# ifndef _URLOBJ_HXX
# include <tools/urlobj.hxx>
# endif
# ifndef SVTOOLS_URIHELPER_HXX
# include <svtools/urihelper.hxx>
# endif
2001-05-10 11:25:36 +00:00
# ifndef _DBAUI_DATASOURCECONNECTOR_HXX_
# include "datasourceconnector.hxx"
# endif
2002-08-26 06:52:15 +00:00
# ifndef INCLUDED_SVTOOLS_MODULEOPTIONS_HXX
# include <svtools/moduleoptions.hxx>
# endif
# ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
# include <com/sun/star/frame/FrameSearchFlag.hpp>
# endif
2004-08-02 14:34:22 +00:00
# ifndef _COM_SUN_STAR_UTIL_XMODIFIABLE_HPP_
# include <com/sun/star/util/XModifiable.hpp>
# endif
2004-02-25 14:32:25 +00:00
# ifndef _RTL_USTRING_HXX_
# include <rtl/ustring.hxx>
# endif
2001-10-26 12:10:16 +00:00
# include <algorithm>
2001-01-09 14:43:04 +00:00
using namespace : : com : : sun : : star : : uno ;
using namespace : : com : : sun : : star : : beans ;
using namespace : : com : : sun : : star : : frame ;
using namespace : : com : : sun : : star : : util ;
using namespace : : com : : sun : : star : : lang ;
using namespace : : com : : sun : : star : : container ;
using namespace : : com : : sun : : star : : sdbc ;
using namespace : : com : : sun : : star : : sdb ;
using namespace : : com : : sun : : star : : task ;
2001-04-23 08:30:31 +00:00
using namespace : : com : : sun : : star : : awt ;
2001-01-09 14:43:04 +00:00
using namespace : : dbtools ;
using namespace : : dbaui ;
using namespace : : comphelper ;
2002-01-24 16:43:35 +00:00
// -------------------------------------------------------------------------
# define ALL_FEATURES -1
2004-11-16 13:31:01 +00:00
// -------------------------------------------------------------------------
typedef : : std : : hash_map < sal_Int16 , sal_Int16 > CommandHashMap ;
typedef : : std : : list < DispatchInformation > DispatchInfoList ;
2002-01-24 16:43:35 +00:00
// -------------------------------------------------------------------------
const : : rtl : : OUString & getConfirmDeletionURL ( )
{
static const : : rtl : : OUString sConfirmDeletionURL ( RTL_CONSTASCII_USTRINGPARAM ( " .uno:FormSlots/ConfirmDeletion " ) ) ;
return sConfirmDeletionURL ;
}
2001-01-09 14:43:04 +00:00
// -------------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
OGenericUnoController : : OGenericUnoController ( const Reference < XMultiServiceFactory > & _rM )
2001-08-14 11:13:32 +00:00
: OGenericUnoController_COMPBASE ( m_aMutex )
2001-03-01 14:17:55 +00:00
, m_aAsyncInvalidateAll ( LINK ( this , OGenericUnoController , OnAsyncInvalidateAll ) )
2001-09-19 12:20:12 +00:00
, m_aAsyncCloseTask ( LINK ( this , OGenericUnoController , OnAsyncCloseTask ) )
2001-01-09 14:43:04 +00:00
, m_xMultiServiceFacatory ( _rM )
, m_bCurrentlyModified ( sal_False )
, m_bFrameUiActive ( sal_False )
, m_pView ( NULL )
2004-11-16 13:31:01 +00:00
# if OSL_DEBUG_LEVEL >= 2
, m_bDescribingSupportedFeatures ( false )
# endif
2001-01-09 14:43:04 +00:00
{
try
{
2002-01-24 16:43:35 +00:00
m_xUrlTransformer = Reference < XURLTransformer > ( _rM - > createInstance ( : : rtl : : OUString : : createFromAscii ( " com.sun.star.util.URLTransformer " ) ) , UNO_QUERY ) ;
2001-01-09 14:43:04 +00:00
}
catch ( Exception & )
{
}
}
2004-11-16 13:31:01 +00:00
// -----------------------------------------------------------------------------
OGenericUnoController : : ~ OGenericUnoController ( )
{
}
2001-01-09 14:43:04 +00:00
// -----------------------------------------------------------------------------
sal_Bool OGenericUnoController : : Construct ( Window * pParent )
{
2001-08-23 13:46:27 +00:00
OSL_ENSURE ( getView ( ) , " the view is NULL! " ) ;
if ( getView ( ) )
{
getView ( ) - > Construct ( ) ;
getView ( ) - > Show ( ) ;
}
2004-11-16 13:31:01 +00:00
# if OSL_DEBUG_LEVEL >= 2
m_bDescribingSupportedFeatures = true ;
# endif
describeSupportedFeatures ( ) ;
# if OSL_DEBUG_LEVEL >= 2
m_bDescribingSupportedFeatures = false ;
# endif
2001-01-09 14:43:04 +00:00
// create the database context
2001-06-21 16:51:14 +00:00
DBG_ASSERT ( m_xMultiServiceFacatory . is ( ) , " OGenericUnoController::Construct need a service factory! " ) ;
2001-01-09 14:43:04 +00:00
try
{
m_xDatabaseContext = Reference < XNameAccess > ( m_xMultiServiceFacatory - > createInstance ( SERVICE_SDB_DATABASECONTEXT ) , UNO_QUERY ) ;
}
catch ( Exception & )
{
2001-06-21 16:51:14 +00:00
DBG_ERROR ( " OGenericUnoController::Construct: could not create (or start listening at) the database context! " ) ;
2001-01-09 14:43:04 +00:00
}
if ( ! m_xDatabaseContext . is ( ) )
{ // at least notify the user. Though the whole component does not make any sense without the database context ...
ShowServiceNotAvailableError ( getView ( ) , String ( SERVICE_SDB_DATABASECONTEXT ) , sal_True ) ;
}
return sal_True ;
}
//------------------------------------------------------------------------------
IMPL_LINK ( OGenericUnoController , OnAsyncInvalidateAll , void * , EMPTYARG )
{
2002-06-05 07:15:05 +00:00
if ( ! OGenericUnoController_COMPBASE : : rBHelper . bInDispose & & ! OGenericUnoController_COMPBASE : : rBHelper . bDisposed )
2001-05-22 07:51:23 +00:00
InvalidateFeature_Impl ( ) ;
2001-01-09 14:43:04 +00:00
return 0L ;
}
// -----------------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
Reference < XWindow > OGenericUnoController : : getComponentWindow ( ) const
2001-01-09 14:43:04 +00:00
{
2002-01-24 16:43:35 +00:00
return VCLUnoHelper : : GetInterface ( getView ( ) ) ;
2001-01-09 14:43:04 +00:00
}
2004-08-02 14:34:22 +00:00
// -----------------------------------------------------------------------------
void OGenericUnoController : : impl_initialize ( const Sequence < Any > & aArguments )
{
}
2001-01-09 14:43:04 +00:00
// -------------------------------------------------------------------------
void SAL_CALL OGenericUnoController : : initialize ( const Sequence < Any > & aArguments ) throw ( Exception , RuntimeException )
{
2004-08-02 14:34:22 +00:00
vos : : OGuard aSolarGuard ( Application : : GetSolarMutex ( ) ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2002-01-24 16:43:35 +00:00
Reference < XWindow > xParent ;
Reference < XFrame > xFrame ;
2001-01-09 14:43:04 +00:00
PropertyValue aValue ;
const Any * pBegin = aArguments . getConstArray ( ) ;
const Any * pEnd = pBegin + aArguments . getLength ( ) ;
2002-01-24 16:43:35 +00:00
for ( ; pBegin ! = pEnd ; + + pBegin )
2001-01-09 14:43:04 +00:00
{
2002-01-24 16:43:35 +00:00
if ( ( * pBegin > > = aValue ) & & ( 0 = = aValue . Name . compareToAscii ( " Frame " ) ) )
2001-01-09 14:43:04 +00:00
{
if ( ( aValue . Value > > = xFrame ) & & xFrame . is ( ) )
{
xParent = xFrame - > getContainerWindow ( ) ;
VCLXWindow * pParentComponent = VCLXWindow : : GetImplementation ( xParent ) ;
Window * pParentWin = pParentComponent ? pParentComponent - > GetWindow ( ) : NULL ;
if ( ! pParentWin )
{
throw Exception ( : : rtl : : OUString : : createFromAscii ( " Parent window is null " ) , * this ) ;
}
2004-10-22 11:03:46 +00:00
Construct ( pParentWin ) ;
2001-01-09 14:43:04 +00:00
break ; // no more needed here
}
else
{
2001-03-23 12:33:59 +00:00
OSL_ENSURE ( 0 , " OGenericUnoController::initialize: Frame is null! " ) ;
2001-01-09 14:43:04 +00:00
}
}
}
2004-08-02 14:34:22 +00:00
impl_initialize ( aArguments ) ;
if ( xFrame . is ( ) )
xFrame - > setComponent ( getComponentWindow ( ) , this ) ;
2001-01-09 14:43:04 +00:00
}
2001-06-21 16:51:14 +00:00
//------------------------------------------------------------------------------
Any SAL_CALL OGenericUnoController : : queryInterface ( const Type & _rType ) throw ( RuntimeException )
{
2001-08-14 11:13:32 +00:00
Any aReturn = OGenericUnoController_COMPBASE : : queryInterface ( _rType ) ;
2001-06-21 16:51:14 +00:00
if ( ! aReturn . hasValue ( ) )
2001-08-14 11:13:32 +00:00
aReturn = OGenericUnoController_CTRBASE : : queryInterface ( _rType ) ;
2001-06-21 16:51:14 +00:00
return aReturn ;
}
//------------------------------------------------------------------------------
void SAL_CALL OGenericUnoController : : acquire ( ) throw ( )
{
2001-08-14 11:13:32 +00:00
OGenericUnoController_COMPBASE : : acquire ( ) ;
2001-06-21 16:51:14 +00:00
}
//------------------------------------------------------------------------------
void SAL_CALL OGenericUnoController : : release ( ) throw ( )
{
2001-08-14 11:13:32 +00:00
OGenericUnoController_COMPBASE : : release ( ) ;
2001-06-21 16:51:14 +00:00
}
//------------------------------------------------------------------------------
Sequence < Type > SAL_CALL OGenericUnoController : : getTypes ( ) throw ( RuntimeException )
{
return : : comphelper : : concatSequences (
2001-08-14 11:13:32 +00:00
OGenericUnoController_COMPBASE : : getTypes ( ) ,
OGenericUnoController_CTRBASE : : getTypes ( )
2001-06-21 16:51:14 +00:00
) ;
}
//------------------------------------------------------------------------------
Sequence < sal_Int8 > SAL_CALL OGenericUnoController : : getImplementationId ( ) throw ( RuntimeException )
{
2001-08-15 12:14:59 +00:00
static : : cppu : : OImplementationId * pId = 0 ;
if ( ! pId )
{
: : osl : : MutexGuard aGuard ( : : osl : : Mutex : : getGlobalMutex ( ) ) ;
if ( ! pId )
{
static : : cppu : : OImplementationId aId ;
pId = & aId ;
}
}
return pId - > getImplementationId ( ) ;
2001-06-21 16:51:14 +00:00
}
2002-01-24 16:43:35 +00:00
// -------------------------------------------------------------------------
sal_Bool OGenericUnoController : : startFrameListening ( )
{
if ( m_xCurrentFrame . is ( ) )
m_xCurrentFrame - > addFrameActionListener ( static_cast < XFrameActionListener * > ( this ) ) ;
return m_xCurrentFrame . is ( ) ;
}
// -------------------------------------------------------------------------
void OGenericUnoController : : stopFrameListening ( )
{
if ( m_xCurrentFrame . is ( ) )
m_xCurrentFrame - > removeFrameActionListener ( static_cast < XFrameActionListener * > ( this ) ) ;
}
2001-01-09 14:43:04 +00:00
// -------------------------------------------------------------------------
void OGenericUnoController : : disposing ( const EventObject & Source ) throw ( RuntimeException )
{
// our frame ?
2002-01-24 16:43:35 +00:00
Reference < XFrame > xSourceFrame ( Source . Source , UNO_QUERY ) ;
if ( xSourceFrame = = m_xCurrentFrame )
stopFrameListening ( ) ;
2001-01-09 14:43:04 +00:00
}
//------------------------------------------------------------------------
void OGenericUnoController : : modified ( const EventObject & aEvent ) throw ( RuntimeException )
{
2004-10-22 08:04:44 +00:00
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2004-08-02 14:34:22 +00:00
if ( ! isDataSourceReadOnly ( ) )
{
Reference < XModifiable > xModi ( aEvent . Source , UNO_QUERY ) ;
if ( xModi . is ( ) )
m_bCurrentlyModified = m_bCurrentlyModified | | xModi - > isModified ( ) ; // can only be reset by save
else
m_bCurrentlyModified = sal_True ;
}
2002-01-24 16:43:35 +00:00
InvalidateFeature ( ID_BROWSER_SAVEDOC ) ;
2001-01-09 14:43:04 +00:00
InvalidateFeature ( ID_BROWSER_UNDO ) ;
}
// -----------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
void OGenericUnoController : : attachFrame ( const Reference < XFrame > & xFrame ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
2002-01-24 16:43:35 +00:00
stopFrameListening ( ) ;
2001-01-09 14:43:04 +00:00
m_xCurrentFrame = xFrame ;
2002-01-24 16:43:35 +00:00
if ( startFrameListening ( ) )
2001-01-09 14:43:04 +00:00
m_bFrameUiActive = m_xCurrentFrame - > isActive ( ) ;
2004-08-02 14:34:22 +00:00
loadMenu ( xFrame ) ;
if ( m_xCurrentFrame . is ( ) )
updateTitle ( ) ;
}
// -----------------------------------------------------------------------------
void OGenericUnoController : : updateTitle ( )
{
2001-01-09 14:43:04 +00:00
}
2004-09-09 08:41:47 +00:00
// -----------------------------------------------------------------------------
2004-11-16 13:31:01 +00:00
struct CommandCollector : public : : std : : unary_function < SupportedFeatures : : value_type , void >
2001-01-09 14:43:04 +00:00
{
2004-11-16 13:31:01 +00:00
sal_uInt16 m_nFeature ;
StringBag & m_rFeatureCommands ;
CommandCollector ( sal_uInt16 _nFeature , StringBag & _rFeatureCommands )
: m_nFeature ( _nFeature )
, m_rFeatureCommands ( _rFeatureCommands )
{
}
2001-01-09 14:43:04 +00:00
2004-11-16 13:31:01 +00:00
void operator ( ) ( const SupportedFeatures : : value_type & lhs )
2001-01-09 14:43:04 +00:00
{
2004-11-16 13:31:01 +00:00
if ( lhs . second . nFeatureId = = m_nFeature )
m_rFeatureCommands . insert ( lhs . first ) ;
2001-01-09 14:43:04 +00:00
}
2004-09-09 08:41:47 +00:00
} ;
2001-01-09 14:43:04 +00:00
// -----------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
void OGenericUnoController : : ImplBroadcastFeatureState ( const : : rtl : : OUString & _rFeature , const Reference < XStatusListener > & xListener , sal_Bool _bIgnoreCache )
2001-01-09 14:43:04 +00:00
{
2004-11-16 13:31:01 +00:00
sal_uInt16 nFeat = m_aSupportedFeatures [ _rFeature ] . nFeatureId ;
FeatureState aFeatState ( GetState ( nFeat ) ) ;
2001-01-09 14:43:04 +00:00
FeatureState & rCachedState = m_aStateCache [ nFeat ] ; // creates if neccessary
if ( ! _bIgnoreCache )
{
// check if we really need to notify the listeners : this method may be called much more often than needed, so check
// the cached state of the feature
sal_Bool bAlreadyCached = ( m_aStateCache . find ( nFeat ) ! = m_aStateCache . end ( ) ) ;
if ( bAlreadyCached & & ( rCachedState . bEnabled = = aFeatState . bEnabled ) )
{ // the enabled flag hasn't changed, maybe the state ?
if ( rCachedState . aState . getValueTypeClass ( ) = = aFeatState . aState . getValueTypeClass ( ) )
{ // at least the type of the state hasn't
sal_Bool bEqualValue = sal_False ;
switch ( rCachedState . aState . getValueTypeClass ( ) )
{
case TypeClass_VOID :
bEqualValue = ! aFeatState . aState . hasValue ( ) ;
break ;
case TypeClass_BOOLEAN :
bEqualValue = : : comphelper : : getBOOL ( rCachedState . aState ) = = : : comphelper : : getBOOL ( aFeatState . aState ) ;
break ;
case TypeClass_SHORT :
bEqualValue = : : comphelper : : getINT16 ( rCachedState . aState ) = = : : comphelper : : getINT16 ( aFeatState . aState ) ;
break ;
case TypeClass_LONG :
bEqualValue = : : comphelper : : getINT32 ( rCachedState . aState ) = = : : comphelper : : getINT32 ( aFeatState . aState ) ;
break ;
case TypeClass_STRING :
bEqualValue = : : comphelper : : getString ( rCachedState . aState ) . equals ( : : comphelper : : getString ( aFeatState . aState ) ) ;
break ;
default :
DBG_ERROR ( " OGenericUnoController::ImplBroadcastFeatureState : unknown state type (not implemented yet) ! " ) ;
break ;
}
if ( bEqualValue )
return ;
}
}
}
rCachedState = aFeatState ;
2002-01-24 16:43:35 +00:00
FeatureStateEvent aEvent ;
2001-01-09 14:43:04 +00:00
aEvent . FeatureURL . Complete = _rFeature ;
if ( m_xUrlTransformer . is ( ) )
m_xUrlTransformer - > parseStrict ( aEvent . FeatureURL ) ;
2002-01-24 16:43:35 +00:00
aEvent . Source = ( XDispatch * ) this ;
2001-01-09 14:43:04 +00:00
aEvent . IsEnabled = aFeatState . bEnabled ;
aEvent . Requery = aFeatState . bRequery ;
aEvent . State = aFeatState . aState ;
// a special listener ?
if ( xListener . is ( ) )
xListener - > statusChanged ( aEvent ) ;
else
2002-01-24 16:43:35 +00:00
{ // no -> iterate through all listeners responsible for the URL
2004-11-16 13:31:01 +00:00
StringBag aFeatureCommands ;
: : std : : for_each (
m_aSupportedFeatures . begin ( ) ,
m_aSupportedFeatures . end ( ) ,
CommandCollector ( nFeat , aFeatureCommands )
) ;
2004-09-09 08:41:47 +00:00
2001-01-09 14:43:04 +00:00
DispatchIterator iterSearch = m_arrStatusListener . begin ( ) ;
DispatchIterator iterEnd = m_arrStatusListener . end ( ) ;
while ( iterSearch ! = iterEnd )
{
DispatchTarget & rCurrent = * iterSearch ;
2004-11-16 13:31:01 +00:00
if ( aFeatureCommands . find ( rCurrent . aURL . Complete ) ! = aFeatureCommands . end ( ) )
2004-09-09 08:41:47 +00:00
{
aEvent . FeatureURL . Complete = rCurrent . aURL . Complete ;
if ( m_xUrlTransformer . is ( ) )
m_xUrlTransformer - > parseStrict ( aEvent . FeatureURL ) ;
2001-01-09 14:43:04 +00:00
rCurrent . xListener - > statusChanged ( aEvent ) ;
2004-09-09 08:41:47 +00:00
}
2001-01-09 14:43:04 +00:00
+ + iterSearch ;
}
}
}
// -----------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
void OGenericUnoController : : InvalidateFeature ( const : : rtl : : OUString & _rURLPath , const Reference < XStatusListener > & _xListener , sal_Bool _bForceBroadcast )
2001-01-09 14:43:04 +00:00
{
2004-11-16 13:31:01 +00:00
ImplInvalidateFeature ( m_aSupportedFeatures [ _rURLPath ] . nFeatureId , _xListener , _bForceBroadcast ) ;
2001-01-09 14:43:04 +00:00
}
2002-01-24 16:43:35 +00:00
2001-01-09 14:43:04 +00:00
// -----------------------------------------------------------------------------
void OGenericUnoController : : InvalidateFeature_Impl ( )
{
2001-02-19 11:07:30 +00:00
# ifdef DBG_UTIL
static sal_Int32 s_nRecursions = 0 ;
+ + s_nRecursions ;
# endif
2001-01-09 14:43:04 +00:00
sal_Bool bEmpty = sal_True ;
2001-02-12 12:56:51 +00:00
FeaturePair aNextFeature ;
2001-01-09 14:43:04 +00:00
{
: : osl : : MutexGuard aGuard ( m_aFeatureMutex ) ;
bEmpty = m_aFeaturesToInvalidate . empty ( ) ;
2001-02-12 12:56:51 +00:00
if ( ! bEmpty )
aNextFeature = m_aFeaturesToInvalidate . front ( ) ;
2001-01-09 14:43:04 +00:00
}
while ( ! bEmpty )
{
2002-01-24 16:43:35 +00:00
if ( ALL_FEATURES = = aNextFeature . nId )
2001-02-19 11:07:30 +00:00
{
2001-01-09 14:43:04 +00:00
InvalidateAll_Impl ( ) ;
2001-02-19 11:07:30 +00:00
break ;
}
2001-01-09 14:43:04 +00:00
else
{
2002-01-24 16:43:35 +00:00
SupportedFeatures : : iterator aFeaturePos = : : std : : find_if (
m_aSupportedFeatures . begin ( ) ,
m_aSupportedFeatures . end ( ) ,
2004-11-16 13:31:01 +00:00
: : std : : bind2nd ( SupportedFeaturesEqualId ( ) , aNextFeature . nId )
2002-01-24 16:43:35 +00:00
) ;
2004-11-16 13:31:01 +00:00
OSL_ENSURE ( m_aSupportedFeatures . end ( ) ! = aFeaturePos , " OGenericUnoController::InvalidateFeature_Impl: out of interest: please tell FS how you got this assertion ... " ) ;
2002-01-24 16:43:35 +00:00
if ( m_aSupportedFeatures . end ( ) ! = aFeaturePos )
// we really know this feature
ImplBroadcastFeatureState ( aFeaturePos - > first , aNextFeature . xListener , aNextFeature . bForceBroadcast ) ;
2001-01-09 14:43:04 +00:00
}
2001-02-19 11:07:30 +00:00
: : osl : : MutexGuard aGuard ( m_aFeatureMutex ) ;
m_aFeaturesToInvalidate . pop_front ( ) ;
bEmpty = m_aFeaturesToInvalidate . empty ( ) ;
if ( ! bEmpty )
aNextFeature = m_aFeaturesToInvalidate . front ( ) ;
2001-01-09 14:43:04 +00:00
}
2001-02-19 11:07:30 +00:00
# ifdef DBG_UTIL
- - s_nRecursions ;
# endif
2001-01-09 14:43:04 +00:00
}
2001-02-19 11:07:30 +00:00
2001-01-09 14:43:04 +00:00
// -----------------------------------------------------------------------
2004-08-02 14:34:22 +00:00
void OGenericUnoController : : ImplInvalidateFeature ( sal_Int32 _nId , const Reference < : : com : : sun : : star : : frame : : XStatusListener > & _xListener , sal_Bool _bForceBroadcast )
2001-01-09 14:43:04 +00:00
{
FeaturePair aPair ;
aPair . nId = _nId ;
aPair . xListener = _xListener ;
aPair . bForceBroadcast = _bForceBroadcast ;
2002-01-24 16:43:35 +00:00
sal_Bool bWasEmpty ;
2001-01-09 14:43:04 +00:00
{
: : osl : : MutexGuard aGuard ( m_aFeatureMutex ) ;
bWasEmpty = m_aFeaturesToInvalidate . empty ( ) ;
m_aFeaturesToInvalidate . push_back ( aPair ) ;
}
2002-01-24 16:43:35 +00:00
if ( bWasEmpty )
2001-01-09 14:43:04 +00:00
m_aAsyncInvalidateAll . Call ( ) ;
}
2002-01-24 18:23:16 +00:00
// -----------------------------------------------------------------------
void OGenericUnoController : : InvalidateFeature ( sal_uInt16 _nId , const Reference < XStatusListener > & _xListener , sal_Bool _bForceBroadcast )
{
ImplInvalidateFeature ( _nId , _xListener , _bForceBroadcast ) ;
}
2001-01-09 14:43:04 +00:00
// -----------------------------------------------------------------------
void OGenericUnoController : : InvalidateAll ( )
{
2002-01-24 18:23:16 +00:00
ImplInvalidateFeature ( ALL_FEATURES , NULL , sal_True ) ;
2001-01-09 14:43:04 +00:00
}
2002-01-24 16:43:35 +00:00
2001-01-09 14:43:04 +00:00
// -----------------------------------------------------------------------------
void OGenericUnoController : : InvalidateAll_Impl ( )
{
// ---------------------------------
// invalidate all aupported features
2004-11-16 13:31:01 +00:00
for ( SupportedFeatures : : const_iterator aIter = m_aSupportedFeatures . begin ( ) ;
aIter ! = m_aSupportedFeatures . end ( ) ;
+ + aIter
)
ImplBroadcastFeatureState ( aIter - > first , NULL , sal_True ) ;
2001-01-09 14:43:04 +00:00
{
: : osl : : MutexGuard aGuard ( m_aFeatureMutex ) ;
2001-02-19 11:07:30 +00:00
DBG_ASSERT ( m_aFeaturesToInvalidate . size ( ) , " OGenericUnoController::InvalidateAll_Impl: to be called from within InvalidateFeature_Impl only! " ) ;
2001-01-09 14:43:04 +00:00
m_aFeaturesToInvalidate . pop_front ( ) ;
if ( ! m_aFeaturesToInvalidate . empty ( ) )
m_aAsyncInvalidateAll . Call ( ) ;
}
}
// -----------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
Reference < XDispatch > OGenericUnoController : : queryDispatch ( const URL & aURL , const : : rtl : : OUString & aTargetFrameName , sal_Int32 nSearchFlags ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
2002-01-24 16:43:35 +00:00
Reference < XDispatch > xReturn ;
2001-01-09 14:43:04 +00:00
2002-01-24 16:43:35 +00:00
// URL's we can handle ourself?
if ( aURL . Complete . equals ( getConfirmDeletionURL ( ) )
| | ( m_aSupportedFeatures . find ( aURL . Complete ) ! = m_aSupportedFeatures . end ( ) )
)
{
xReturn = static_cast < XDispatch * > ( this ) ;
}
// no? -> ask the slave dispatcher
else if ( m_xSlaveDispatcher . is ( ) )
{
xReturn = m_xSlaveDispatcher - > queryDispatch ( aURL , aTargetFrameName , nSearchFlags ) ;
}
2001-01-09 14:43:04 +00:00
2002-01-24 16:43:35 +00:00
// outta here
return xReturn ;
2001-01-09 14:43:04 +00:00
}
// -----------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
Sequence < Reference < XDispatch > > OGenericUnoController : : queryDispatches ( const Sequence < DispatchDescriptor > & aDescripts ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
2002-01-24 16:43:35 +00:00
Sequence < Reference < XDispatch > > aReturn ;
sal_Int32 nLen = aDescripts . getLength ( ) ;
if ( nLen )
{
aReturn . realloc ( nLen ) ;
Reference < XDispatch > * pReturn = aReturn . getArray ( ) ;
const Reference < XDispatch > * pReturnEnd = aReturn . getArray ( ) + nLen ;
const DispatchDescriptor * pDescripts = aDescripts . getConstArray ( ) ;
2001-01-09 14:43:04 +00:00
2002-01-24 16:43:35 +00:00
for ( ; pReturn ! = pReturnEnd ; + + pReturn , + + pDescripts )
{
* pReturn = queryDispatch ( pDescripts - > FeatureURL , pDescripts - > FrameName , pDescripts - > SearchFlags ) ;
}
}
2001-01-09 14:43:04 +00:00
return aReturn ;
}
// -----------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
Reference < XDispatchProvider > OGenericUnoController : : getSlaveDispatchProvider ( void ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
return m_xSlaveDispatcher ;
}
// -----------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
void OGenericUnoController : : setSlaveDispatchProvider ( const Reference < XDispatchProvider > & _xNewProvider ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
m_xSlaveDispatcher = _xNewProvider ;
}
// -----------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
Reference < XDispatchProvider > OGenericUnoController : : getMasterDispatchProvider ( void ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
return m_xMasterDispatcher ;
}
// -----------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
void OGenericUnoController : : setMasterDispatchProvider ( const Reference < XDispatchProvider > & _xNewProvider ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
m_xMasterDispatcher = _xNewProvider ;
}
// -----------------------------------------------------------------------
2002-02-19 12:54:45 +00:00
void OGenericUnoController : : dispatch ( const URL & _aURL , const Sequence < PropertyValue > & aArgs ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
2004-09-09 08:41:47 +00:00
executeUnChecked ( _aURL , aArgs ) ;
2001-01-09 14:43:04 +00:00
}
// -----------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
void OGenericUnoController : : addStatusListener ( const Reference < XStatusListener > & aListener , const URL & _rURL ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
2002-01-24 16:43:35 +00:00
// remeber the listener together with the URL
2001-04-24 13:36:44 +00:00
m_arrStatusListener . insert ( m_arrStatusListener . end ( ) , DispatchTarget ( _rURL , aListener ) ) ;
2001-01-09 14:43:04 +00:00
// initially broadcast the state
2001-05-02 11:46:24 +00:00
ImplBroadcastFeatureState ( _rURL . Complete , aListener , sal_True ) ;
2001-01-09 14:43:04 +00:00
// force the new state to be broadcasted to the new listener
}
// -----------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
void OGenericUnoController : : removeStatusListener ( const Reference < XStatusListener > & aListener , const URL & _rURL ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
DispatchIterator iterSearch = m_arrStatusListener . begin ( ) ;
2001-04-24 13:36:44 +00:00
sal_Bool bRemoveForAll = ( _rURL . Complete . getLength ( ) = = 0 ) ;
2002-01-24 16:43:35 +00:00
while ( iterSearch ! = m_arrStatusListener . end ( ) )
2001-01-09 14:43:04 +00:00
{
DispatchTarget & rCurrent = * iterSearch ;
if ( ( rCurrent . xListener = = aListener )
& & ( bRemoveForAll
2001-04-24 13:36:44 +00:00
| | ( rCurrent . aURL . Complete . equals ( _rURL . Complete ) )
2001-01-09 14:43:04 +00:00
)
)
{
2002-01-24 16:43:35 +00:00
m_arrStatusListener . erase ( iterSearch ) ;
2001-01-09 14:43:04 +00:00
if ( ! bRemoveForAll )
2002-01-24 16:43:35 +00:00
// remove the listener only for the given URL, so we can exit the loop after deletion
2001-01-09 14:43:04 +00:00
break ;
}
else
+ + iterSearch ;
}
2001-04-24 13:36:44 +00:00
SupportedFeatures : : const_iterator aIter = m_aSupportedFeatures . find ( _rURL . Complete ) ;
2001-01-09 14:43:04 +00:00
if ( aIter ! = m_aSupportedFeatures . end ( ) )
{ // clear the cache for that feature
2004-11-16 13:31:01 +00:00
StateCacheIterator aCachePos = m_aStateCache . find ( aIter - > second . nFeatureId ) ;
if ( aCachePos ! = m_aStateCache . end ( ) )
m_aStateCache . erase ( aCachePos ) ;
2001-01-09 14:43:04 +00:00
}
// now remove the listener from the deque
: : osl : : MutexGuard aGuard ( m_aFeatureMutex ) ;
2001-08-27 05:57:24 +00:00
m_aFeaturesToInvalidate . erase (
: : std : : remove_if ( m_aFeaturesToInvalidate . begin ( ) ,
m_aFeaturesToInvalidate . end ( ) ,
: : std : : bind2nd ( FeaturePairFunctor ( ) , aListener ) )
, m_aFeaturesToInvalidate . end ( ) ) ;
2001-01-09 14:43:04 +00:00
}
// -----------------------------------------------------------------------
2001-03-01 14:17:55 +00:00
void OGenericUnoController : : disposing ( )
2001-01-09 14:43:04 +00:00
{
{
EventObject aDisposeEvent ;
2001-06-21 16:51:14 +00:00
aDisposeEvent . Source = static_cast < XWeak * > ( this ) ;
2004-08-02 14:34:22 +00:00
Dispatch aStatusListener = m_arrStatusListener ;
Dispatch : : iterator aEnd = aStatusListener . end ( ) ;
for ( Dispatch : : iterator aIter = aStatusListener . begin ( ) ; aIter ! = aEnd ; + + aIter )
{
aIter - > xListener - > disposing ( aDisposeEvent ) ;
}
m_arrStatusListener . clear ( ) ;
2001-01-09 14:43:04 +00:00
}
2004-08-02 14:34:22 +00:00
m_xDatabaseContext = NULL ;
2001-01-09 14:43:04 +00:00
{
: : osl : : MutexGuard aGuard ( m_aFeatureMutex ) ;
2001-01-23 09:35:13 +00:00
m_aAsyncInvalidateAll . CancelCall ( ) ;
2001-01-09 14:43:04 +00:00
m_aFeaturesToInvalidate . clear ( ) ;
}
// check out from all the objects we are listening
// the frame
2002-01-24 16:43:35 +00:00
stopFrameListening ( ) ;
2001-01-09 14:43:04 +00:00
}
// -----------------------------------------------------------------------
2001-10-18 05:50:04 +00:00
void OGenericUnoController : : addEventListener ( const Reference < XEventListener > & aListener ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
2001-08-14 11:13:32 +00:00
OGenericUnoController_COMPBASE : : addEventListener ( aListener ) ;
2001-01-09 14:43:04 +00:00
}
// -----------------------------------------------------------------------
2001-10-18 05:50:04 +00:00
void OGenericUnoController : : removeEventListener ( const Reference < XEventListener > & aListener ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
2001-08-14 11:13:32 +00:00
OGenericUnoController_COMPBASE : : removeEventListener ( aListener ) ;
2001-01-09 14:43:04 +00:00
}
//------------------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
void OGenericUnoController : : frameAction ( const FrameActionEvent & aEvent ) throw ( RuntimeException )
2001-01-09 14:43:04 +00:00
{
2002-01-24 16:43:35 +00:00
if ( ( XFrame * ) aEvent . Frame . get ( ) = = ( XFrame * ) m_xCurrentFrame . get ( ) )
2002-11-19 08:28:50 +00:00
m_bFrameUiActive = ( FrameAction_FRAME_UI_ACTIVATED = = aEvent . Action )
| | ( FrameAction_FRAME_ACTIVATED = = aEvent . Action ) ;
2001-01-09 14:43:04 +00:00
}
2004-11-16 13:31:01 +00:00
2001-01-09 14:43:04 +00:00
//------------------------------------------------------------------------------
2004-11-16 13:31:01 +00:00
void OGenericUnoController : : implDescribeSupportedFeature ( const sal_Char * _pAsciiCommandURL ,
sal_uInt16 _nFeatureId , sal_Int16 _nCommandGroup )
2001-01-09 14:43:04 +00:00
{
2004-11-16 13:31:01 +00:00
# if OSL_DEBUG_LEVEL >= 2
OSL_ENSURE ( m_bDescribingSupportedFeatures , " OGenericUnoController::implDescribeSupportedFeature: bad timing for this call! " ) ;
# endif
ControllerFeature aFeature ;
aFeature . Command = : : rtl : : OUString : : createFromAscii ( _pAsciiCommandURL ) ;
aFeature . nFeatureId = _nFeatureId ;
aFeature . GroupId = _nCommandGroup ;
# if OSL_DEBUG_LEVEL > 0
OSL_ENSURE ( m_aSupportedFeatures . find ( aFeature . Command ) = = m_aSupportedFeatures . end ( ) ,
" OGenericUnoController::implDescribeSupportedFeature: this feature is already there! " ) ;
# endif
m_aSupportedFeatures [ aFeature . Command ] = aFeature ;
}
2004-09-09 08:41:47 +00:00
2004-11-16 13:31:01 +00:00
//------------------------------------------------------------------------------
void OGenericUnoController : : describeSupportedFeatures ( )
{
// add all supported features
implDescribeSupportedFeature ( " .uno:Copy " , ID_BROWSER_COPY , CommandGroup : : EDIT ) ;
implDescribeSupportedFeature ( " .uno:Cut " , ID_BROWSER_CUT , CommandGroup : : EDIT ) ;
implDescribeSupportedFeature ( " .uno:Paste " , ID_BROWSER_PASTE , CommandGroup : : EDIT ) ;
implDescribeSupportedFeature ( " .uno:ClipboardFormatItems " , ID_BROWSER_CLIPBOARD_FORMAT_ITEMS ) ;
implDescribeSupportedFeature ( " .uno:DSBEditDoc " , ID_BROWSER_EDITDOC , CommandGroup : : DOCUMENT ) ;
2001-01-09 14:43:04 +00:00
}
//------------------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
FeatureState OGenericUnoController : : GetState ( sal_uInt16 nId ) const
2001-01-09 14:43:04 +00:00
{
FeatureState aReturn ;
// (disabled automatically)
try
{
switch ( nId )
{
case ID_BROWSER_UNDO :
case ID_BROWSER_SAVEDOC :
aReturn . bEnabled = sal_True ;
2004-09-09 08:41:47 +00:00
break ;
case 99 :
aReturn . bEnabled = sal_False ;
break ;
2001-01-09 14:43:04 +00:00
}
}
catch ( Exception & e )
{
# if DBG_UTIL
String sMessage ( " OGenericUnoController::GetState( " , RTL_TEXTENCODING_ASCII_US ) ;
sMessage + = String : : CreateFromInt32 ( nId ) ;
sMessage . AppendAscii ( " ) : catched an exception ! message : " ) ;
sMessage + = ( const sal_Unicode * ) e . Message ;
DBG_ERROR ( ByteString ( sMessage , gsl_getSystemTextEncoding ( ) ) . GetBuffer ( ) ) ;
# else
e ; // make compiler happy
# endif
}
return aReturn ;
}
2001-08-16 09:39:41 +00:00
//------------------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
URL OGenericUnoController : : getURLForId ( sal_Int32 _nId ) const
2001-01-09 14:43:04 +00:00
{
URL aReturn ;
2002-01-24 16:43:35 +00:00
if ( m_xUrlTransformer . is ( ) )
2001-08-27 05:57:24 +00:00
{
2002-01-24 16:43:35 +00:00
SupportedFeatures : : const_iterator aIter = : : std : : find_if (
m_aSupportedFeatures . begin ( ) ,
m_aSupportedFeatures . end ( ) ,
2004-11-16 13:31:01 +00:00
: : std : : bind2nd ( SupportedFeaturesEqualId ( ) , _nId )
2002-01-24 16:43:35 +00:00
) ;
if ( m_aSupportedFeatures . end ( ) ! = aIter & & aIter - > first . getLength ( ) )
2001-01-09 14:43:04 +00:00
{
2001-08-27 05:57:24 +00:00
aReturn . Complete = aIter - > first ;
2002-01-24 16:43:35 +00:00
m_xUrlTransformer - > parseStrict ( aReturn ) ;
2001-01-09 14:43:04 +00:00
}
2001-08-27 05:57:24 +00:00
}
2001-01-09 14:43:04 +00:00
return aReturn ;
}
2001-05-10 11:25:36 +00:00
2001-01-09 14:43:04 +00:00
//-------------------------------------------------------------------------
sal_Bool SAL_CALL OGenericUnoController : : supportsService ( const : : rtl : : OUString & ServiceName ) throw ( RuntimeException )
{
Sequence < : : rtl : : OUString > aSupported ( getSupportedServiceNames ( ) ) ;
2002-01-24 16:43:35 +00:00
2001-01-09 14:43:04 +00:00
const : : rtl : : OUString * pArray = aSupported . getConstArray ( ) ;
2002-01-24 16:43:35 +00:00
const : : rtl : : OUString * pArrayEnd = aSupported . getConstArray ( ) + aSupported . getLength ( ) ;
for ( ; ( pArray ! = pArrayEnd ) & & ! pArray - > equals ( ServiceName ) ; + + pArray )
;
return pArray ! = pArrayEnd ;
2001-01-09 14:43:04 +00:00
}
2001-05-10 11:25:36 +00:00
2001-01-09 14:43:04 +00:00
// -----------------------------------------------------------------------------
2001-05-10 11:25:36 +00:00
void OGenericUnoController : : startConnectionListening ( const Reference < XConnection > & _rxConnection )
2001-01-09 14:43:04 +00:00
{
2001-05-10 11:25:36 +00:00
// we have to remove ourself before dispoing the connection
Reference < XComponent > xComponent ( _rxConnection , UNO_QUERY ) ;
if ( xComponent . is ( ) )
2001-06-21 16:51:14 +00:00
xComponent - > addEventListener ( static_cast < XFrameActionListener * > ( this ) ) ;
2001-05-10 11:25:36 +00:00
}
2001-01-09 14:43:04 +00:00
2001-05-10 11:25:36 +00:00
// -----------------------------------------------------------------------------
void OGenericUnoController : : stopConnectionListening ( const Reference < XConnection > & _rxConnection )
{
// we have to remove ourself before dispoing the connection
Reference < XComponent > xComponent ( _rxConnection , UNO_QUERY ) ;
if ( xComponent . is ( ) )
2001-06-21 16:51:14 +00:00
xComponent - > removeEventListener ( static_cast < XFrameActionListener * > ( this ) ) ;
2001-05-10 11:25:36 +00:00
}
2004-08-02 14:34:22 +00:00
// -----------------------------------------------------------------------------
Reference < XConnection > OGenericUnoController : : connect (
const Reference < XDataSource > & _xDataSource
, sal_Bool _bStartListening
)
{
WaitObject aWaitCursor ( getView ( ) ) ;
const : : rtl : : OUString sNoContext ;
ODatasourceConnector aConnector ( m_xMultiServiceFacatory , getView ( ) , sNoContext , sNoContext ) ;
Reference < XConnection > xConnection = aConnector . connect ( _xDataSource ) ;
2001-01-26 13:15:24 +00:00
2004-08-02 14:34:22 +00:00
// be notified when connection is in disposing
if ( _bStartListening )
startConnectionListening ( xConnection ) ;
return xConnection ;
}
2001-05-10 11:25:36 +00:00
// -----------------------------------------------------------------------------
2001-08-15 05:47:21 +00:00
Reference < XConnection > OGenericUnoController : : connect ( const : : rtl : : OUString & _rDataSourceName , sal_Bool _bStartListening )
{
const : : rtl : : OUString sNoContext ;
return connect ( _rDataSourceName , sNoContext , sNoContext , _bStartListening ) ;
}
// -----------------------------------------------------------------------------
Reference < XConnection > OGenericUnoController : : connect (
const : : rtl : : OUString & _rDataSourceName , const : : rtl : : OUString & _rContextInformation ,
const : : rtl : : OUString & _rContextDetails , sal_Bool _bStartListening )
2001-05-10 11:25:36 +00:00
{
WaitObject aWaitCursor ( getView ( ) ) ;
2001-01-09 14:43:04 +00:00
2001-08-15 05:47:21 +00:00
ODatasourceConnector aConnector ( m_xMultiServiceFacatory , getView ( ) , _rContextInformation , _rContextDetails ) ;
Reference < XConnection > xConnection = aConnector . connect ( _rDataSourceName ) ;
2001-01-09 14:43:04 +00:00
2001-05-10 11:25:36 +00:00
// be notified when connection is in disposing
if ( _bStartListening )
startConnectionListening ( xConnection ) ;
2001-01-15 08:37:29 +00:00
return xConnection ;
}
2001-05-10 11:25:36 +00:00
2001-01-15 08:37:29 +00:00
// -----------------------------------------------------------------------------
void OGenericUnoController : : showError ( const SQLExceptionInfo & _rInfo )
{
2001-02-23 14:17:34 +00:00
: : dbaui : : showError ( _rInfo , getView ( ) , getORB ( ) ) ;
2001-01-09 14:43:04 +00:00
}
2001-02-23 14:17:34 +00:00
// -----------------------------------------------------------------------------
2004-09-09 08:41:47 +00:00
Reference < drafts : : com : : sun : : star : : frame : : XLayoutManager > OGenericUnoController : : getLayoutManager ( const Reference < XFrame > & _xFrame ) const
2001-04-24 13:36:44 +00:00
{
2004-02-25 14:32:25 +00:00
Reference < XPropertySet > xPropSet ( _xFrame , UNO_QUERY ) ;
Reference < drafts : : com : : sun : : star : : frame : : XLayoutManager > xLayoutManager ;
if ( xPropSet . is ( ) )
{
try
{
2004-08-02 14:34:22 +00:00
xLayoutManager . set ( xPropSet - > getPropertyValue ( rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " LayoutManager " ) ) ) , UNO_QUERY ) ;
2004-02-25 14:32:25 +00:00
}
catch ( Exception & )
{
}
}
2004-09-09 08:41:47 +00:00
return xLayoutManager ;
}
// -----------------------------------------------------------------------------
void OGenericUnoController : : loadMenu ( const Reference < XFrame > & _xFrame )
{
Reference < drafts : : com : : sun : : star : : frame : : XLayoutManager > xLayoutManager = getLayoutManager ( _xFrame ) ;
2004-02-25 14:32:25 +00:00
if ( xLayoutManager . is ( ) )
2004-09-09 08:41:47 +00:00
{
xLayoutManager - > lock ( ) ;
2004-02-25 14:32:25 +00:00
xLayoutManager - > createElement ( rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " private:resource/menubar/menubar " ) ) ) ;
2004-09-09 08:41:47 +00:00
xLayoutManager - > createElement ( rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " private:resource/toolbar/toolbar " ) ) ) ;
xLayoutManager - > unlock ( ) ;
xLayoutManager - > doLayout ( ) ;
}
2004-10-22 11:03:46 +00:00
onLoadedMenu ( xLayoutManager ) ;
2004-09-09 08:41:47 +00:00
}
2004-10-22 11:03:46 +00:00
2004-09-09 08:41:47 +00:00
// -----------------------------------------------------------------------------
2004-10-22 11:03:46 +00:00
void OGenericUnoController : : onLoadedMenu ( const Reference < drafts : : com : : sun : : star : : frame : : XLayoutManager > & _xLayoutManager )
2004-09-09 08:41:47 +00:00
{
2004-10-22 11:03:46 +00:00
// not interested in
2001-04-24 13:36:44 +00:00
}
2004-10-22 11:03:46 +00:00
2001-04-24 13:36:44 +00:00
// -----------------------------------------------------------------------------
void OGenericUnoController : : closeTask ( )
{
2001-09-19 12:20:12 +00:00
m_aAsyncCloseTask . Call ( ) ;
}
// -----------------------------------------------------------------------------
IMPL_LINK ( OGenericUnoController , OnAsyncCloseTask , void * , EMPTYARG )
{
if ( ! OGenericUnoController_COMPBASE : : rBHelper . bInDispose )
{
2002-06-24 09:29:26 +00:00
try
{
2002-10-30 13:00:16 +00:00
/*AS // #104032# OJ
2002-10-11 07:53:05 +00:00
URL aURL ;
aURL . Complete = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " .uno:CloseDoc " ) ) ;
if ( m_xUrlTransformer . is ( ) )
m_xUrlTransformer - > parseStrict ( aURL ) ;
Reference < XDispatchProvider > xDispProv ( m_xCurrentFrame , UNO_QUERY ) ;
Reference < XDispatch > xCloseDispatch ;
if ( xDispProv . is ( ) )
xCloseDispatch = xDispProv - > queryDispatch ( aURL , m_xCurrentFrame - > getName ( ) , FrameSearchFlag : : SELF ) ;
OSL_ENSURE ( xCloseDispatch . is ( ) , " SbaTableQueryBrowser::OnAsyncCloseTask: could not get a dispatcher! " ) ;
if ( xCloseDispatch . is ( ) & & xCloseDispatch ! = * this )
{
xCloseDispatch - > dispatch ( aURL , Sequence < PropertyValue > ( ) ) ;
}
2002-10-30 13:00:16 +00:00
else */
2002-10-11 07:53:05 +00:00
{
Reference < : : com : : sun : : star : : util : : XCloseable > xCloseable ( m_xCurrentFrame , UNO_QUERY ) ;
if ( xCloseable . is ( ) )
xCloseable - > close ( sal_False ) ; // false - holds the owner ship for this frame inside this object!
}
}
catch ( const Exception & ) { }
2001-09-19 12:20:12 +00:00
}
return 0L ;
2001-04-24 13:36:44 +00:00
}
// -----------------------------------------------------------------------------
2001-10-18 05:50:04 +00:00
Any SAL_CALL OGenericUnoController : : getViewData ( void ) throw ( RuntimeException )
{
return Any ( ) ;
}
// -----------------------------------------------------------------------------
void SAL_CALL OGenericUnoController : : restoreViewData ( const Any & Data ) throw ( RuntimeException )
{
}
// -----------------------------------------------------------------------------
2002-01-24 16:43:35 +00:00
sal_Bool SAL_CALL OGenericUnoController : : attachModel ( const Reference < XModel > & xModel ) throw ( RuntimeException )
2001-10-18 05:50:04 +00:00
{
return sal_False ;
}
// -----------------------------------------------------------------------------
2004-09-09 08:41:47 +00:00
void OGenericUnoController : : executeUnChecked ( const : : com : : sun : : star : : util : : URL & _rCommand , const Sequence < PropertyValue > & aArgs )
2002-02-11 11:43:58 +00:00
{
2004-11-16 13:31:01 +00:00
SupportedFeatures : : const_iterator aIter = m_aSupportedFeatures . find ( _rCommand . Complete ) ;
2002-02-11 11:43:58 +00:00
if ( aIter ! = m_aSupportedFeatures . end ( ) )
2004-11-16 13:31:01 +00:00
Execute ( aIter - > second . nFeatureId , aArgs ) ;
2002-02-11 11:43:58 +00:00
}
// -----------------------------------------------------------------------------
2004-09-09 08:41:47 +00:00
void OGenericUnoController : : executeChecked ( const : : com : : sun : : star : : util : : URL & _rCommand , const Sequence < PropertyValue > & aArgs )
2002-02-11 11:43:58 +00:00
{
2004-11-16 13:31:01 +00:00
SupportedFeatures : : const_iterator aIter = m_aSupportedFeatures . find ( _rCommand . Complete ) ;
if ( aIter ! = m_aSupportedFeatures . end ( ) )
2002-02-11 11:43:58 +00:00
{
2004-11-16 13:31:01 +00:00
sal_uInt16 nFeatureId = aIter - > second . nFeatureId ;
if ( GetState ( nFeatureId ) . bEnabled )
Execute ( nFeatureId , aArgs ) ;
2002-02-11 11:43:58 +00:00
}
}
// -----------------------------------------------------------------------------
2002-08-26 06:52:15 +00:00
//------------------------------------------------------------------------------
namespace
{
: : rtl : : OUString lcl_getModuleHelpModuleName ( const Reference < XFrame > & _rxFrame )
{
const sal_Char * pReturn = NULL ;
try
{
// get the model of the document in the given frame
Reference < XController > xController ;
if ( _rxFrame . is ( ) )
xController = _rxFrame - > getController ( ) ;
Reference < XModel > xModel ;
if ( xController . is ( ) )
xModel = xController - > getModel ( ) ;
Reference < XServiceInfo > xSI ( xModel , UNO_QUERY ) ;
if ( ! xSI . is ( ) )
{ // try to go up the frame hierarchy
Reference < XFrame > xParentFrame ;
if ( _rxFrame . is ( ) )
xParentFrame = xParentFrame . query ( _rxFrame - > getCreator ( ) ) ;
// did we find a parent frame? Which is no top-level frame?
if ( xParentFrame . is ( ) & & ! _rxFrame - > isTop ( ) )
// TODO: to prevent framework assertions, re-insert this "isTop" once 98303 is fixed
return lcl_getModuleHelpModuleName ( xParentFrame ) ;
}
else
{
2003-04-15 15:03:18 +00:00
# if OSL_DEBUG_LEVEL > 0
2002-08-26 06:52:15 +00:00
Sequence < : : rtl : : OUString > sServiceNames = xSI - > getSupportedServiceNames ( ) ;
const : : rtl : : OUString * pLoop = sServiceNames . getConstArray ( ) ;
for ( sal_Int32 i = 0 ; i < sServiceNames . getLength ( ) ; + + i , + + pLoop )
{
sal_Int32 nDummy = 0 ;
}
# endif
// check which service we know ....
static const sal_Char * pTransTable [ ] = {
2004-08-02 14:34:22 +00:00
" com.sun.star.sdb.DatabaseDocument " , " sdatabase " ,
2002-08-26 06:52:15 +00:00
" com.sun.star.text.TextDocument " , " swriter " ,
" com.sun.star.sheet.SpreadsheetDocument " , " scalc " ,
" com.sun.star.presentation.PresentationDocument " , " simpress " ,
" com.sun.star.drawing.DrawingDocument " , " sdraw " ,
" com.sun.star.formula.FormularProperties " , " smath " ,
" com.sun.star.chart.ChartDocument " , " schart "
} ;
OSL_ENSURE ( ( sizeof ( pTransTable ) / sizeof ( pTransTable [ 0 ] ) ) % 2 = = 0 ,
" lcl_getModuleHelpModuleName: odd size of translation table! " ) ;
// loop through the table
sal_Int32 nTableEntries = ( sizeof ( pTransTable ) / sizeof ( pTransTable [ 0 ] ) ) / 2 ;
const sal_Char * * pDocumentService = pTransTable ;
const sal_Char * * pHelpModuleName = pTransTable + 1 ;
for ( sal_Int32 j = 0 ; j < nTableEntries ; + + j )
{
if ( xSI - > supportsService ( : : rtl : : OUString : : createFromAscii ( * pDocumentService ) ) )
{ // found a table entry which matches the model's services
pReturn = * pHelpModuleName ;
break ;
}
+ + pDocumentService ; + + pDocumentService ;
+ + pHelpModuleName ; + + pHelpModuleName ;
}
}
if ( ! pReturn )
{
// could not determine the document type we're living in
// ->fallback
SvtModuleOptions aModOpt ;
if ( aModOpt . IsModuleInstalled ( SvtModuleOptions : : E_SWRITER ) )
pReturn = " swriter " ;
2004-08-02 14:34:22 +00:00
else if ( aModOpt . IsModuleInstalled ( SvtModuleOptions : : E_SDATABASE ) )
pReturn = " sdatabase " ;
2002-08-26 06:52:15 +00:00
else if ( aModOpt . IsModuleInstalled ( SvtModuleOptions : : E_SCALC ) )
pReturn = " scalc " ;
else if ( aModOpt . IsModuleInstalled ( SvtModuleOptions : : E_SIMPRESS ) )
pReturn = " simpress " ;
else if ( aModOpt . IsModuleInstalled ( SvtModuleOptions : : E_SDRAW ) )
pReturn = " sdraw " ;
else if ( aModOpt . IsModuleInstalled ( SvtModuleOptions : : E_SMATH ) )
pReturn = " smath " ;
else if ( aModOpt . IsModuleInstalled ( SvtModuleOptions : : E_SCHART ) )
pReturn = " schart " ;
else if ( aModOpt . IsModuleInstalled ( SvtModuleOptions : : E_SBASIC ) )
pReturn = " sbasic " ;
else
{
OSL_ENSURE ( sal_False , " lcl_getModuleHelpModuleName: no installed module found " ) ;
}
}
}
catch ( const Exception & )
{
OSL_ENSURE ( sal_False , " lcl_getModuleHelpModuleName: caught an exception! " ) ;
}
if ( ! pReturn )
pReturn = " swriter " ;
return : : rtl : : OUString : : createFromAscii ( pReturn ) ;
}
}
//------------------------------------------------------------------------------
void OGenericUnoController : : openHelpAgent ( sal_Int32 _nHelpId )
{
try
{
URL aURL = createHelpAgentURL ( lcl_getModuleHelpModuleName ( getFrame ( ) ) , _nHelpId ) ;
if ( m_xUrlTransformer . is ( ) )
m_xUrlTransformer - > parseStrict ( aURL ) ;
Reference < XDispatchProvider > xDispProv ( m_xCurrentFrame , UNO_QUERY ) ;
Reference < XDispatch > xHelpDispatch ;
if ( xDispProv . is ( ) )
xHelpDispatch = xDispProv - > queryDispatch ( aURL , : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " _helpagent " ) ) , FrameSearchFlag : : PARENT | FrameSearchFlag : : SELF ) ;
OSL_ENSURE ( xHelpDispatch . is ( ) , " SbaTableQueryBrowser::openHelpAgent: could not get a dispatcher! " ) ;
if ( xHelpDispatch . is ( ) )
{
xHelpDispatch - > dispatch ( aURL , Sequence < PropertyValue > ( ) ) ;
}
}
catch ( const Exception & )
{
OSL_ENSURE ( sal_False , " SbaTableQueryBrowser::openHelpAgent: caught an exception while executing the dispatch! " ) ;
}
}
// -----------------------------------------------------------------------------
2003-03-19 16:57:12 +00:00
Reference < : : com : : sun : : star : : awt : : XWindow > OGenericUnoController : : getTopMostContainerWindow ( ) const
{
Reference < : : com : : sun : : star : : awt : : XWindow > xWindow ;
// get the top most window
if ( m_xCurrentFrame . is ( ) )
{
xWindow = m_xCurrentFrame - > getContainerWindow ( ) ;
Reference < XFrame > xFrame = m_xCurrentFrame ;
while ( xFrame . is ( ) & & ! xFrame - > isTop ( ) )
{
2004-08-02 14:34:22 +00:00
xFrame . set ( xFrame - > getCreator ( ) , UNO_QUERY ) ;
2003-03-19 16:57:12 +00:00
}
if ( xFrame . is ( ) )
xWindow = xFrame - > getContainerWindow ( ) ;
}
return xWindow ;
}
// -----------------------------------------------------------------------------
2004-08-02 14:34:22 +00:00
void OGenericUnoController : : setTitle ( const : : rtl : : OUString & _sName )
{
try
{
Reference < XPropertySet > xProp ( m_xCurrentFrame , UNO_QUERY ) ;
if ( xProp . is ( ) & & xProp - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_TITLE ) )
{
xProp - > setPropertyValue ( PROPERTY_TITLE , makeAny ( _sName ) ) ;
}
}
catch ( Exception )
{
OSL_ENSURE ( 0 , " Exception catched while setting the title! " ) ;
}
}
// -----------------------------------------------------------------------------
2004-09-09 08:41:47 +00:00
void OGenericUnoController : : executeChecked ( sal_uInt16 _nCommandId , const Sequence < PropertyValue > & aArgs )
2004-08-02 14:34:22 +00:00
{
if ( isCommandEnabled ( _nCommandId ) )
2004-09-09 08:41:47 +00:00
Execute ( _nCommandId , aArgs ) ;
2004-08-02 14:34:22 +00:00
}
2004-11-16 13:31:01 +00:00
2004-08-02 14:34:22 +00:00
// -----------------------------------------------------------------------------
sal_Bool OGenericUnoController : : isCommandEnabled ( sal_uInt16 _nCommandId ) const
{
return GetState ( _nCommandId ) . bEnabled ;
}
2004-11-16 13:31:01 +00:00
2004-08-02 14:34:22 +00:00
// -----------------------------------------------------------------------------
2004-09-09 08:41:47 +00:00
sal_Bool OGenericUnoController : : isCommandEnabled ( const : : com : : sun : : star : : util : : URL & _rCommand ) const
{
OSL_ENSURE ( _rCommand . Complete . getLength ( ) , " Empty command url! " ) ;
sal_Bool bIsEnabled = sal_False ;
2004-11-16 13:31:01 +00:00
SupportedFeatures : : const_iterator aIter = m_aSupportedFeatures . find ( _rCommand . Complete ) ;
if ( aIter ! = m_aSupportedFeatures . end ( ) )
bIsEnabled = isCommandEnabled ( aIter - > second . nFeatureId ) ;
2004-09-09 08:41:47 +00:00
return bIsEnabled ;
}
2004-11-16 13:31:01 +00:00
// -----------------------------------------------------------------------------
Sequence < : : sal_Int16 > SAL_CALL OGenericUnoController : : getSupportedCommandGroups ( ) throw ( RuntimeException )
{
CommandHashMap aCmdHashMap ;
for ( SupportedFeatures : : const_iterator aIter = m_aSupportedFeatures . begin ( ) ;
aIter ! = m_aSupportedFeatures . end ( ) ;
+ + aIter
)
aCmdHashMap . insert ( CommandHashMap : : value_type ( aIter - > second . GroupId , 0 ) ) ;
Sequence < sal_Int16 > aCommandGroups ( aCmdHashMap . size ( ) ) ;
: : std : : transform ( aCmdHashMap . begin ( ) ,
aCmdHashMap . end ( ) ,
aCommandGroups . getArray ( ) ,
: : std : : select1st < CommandHashMap : : value_type > ( )
) ;
return aCommandGroups ;
}
// -----------------------------------------------------------------------------
Sequence < DispatchInformation > SAL_CALL OGenericUnoController : : getConfigurableDispatchInformation ( : : sal_Int16 CommandGroup ) throw ( RuntimeException )
{
DispatchInfoList aInformationList ;
DispatchInformation aDispatchInfo ;
for ( SupportedFeatures : : const_iterator aIter = m_aSupportedFeatures . begin ( ) ;
aIter ! = m_aSupportedFeatures . end ( ) ;
+ + aIter
)
{
if ( sal_Int16 ( aIter - > second . GroupId ) = = CommandGroup )
{
aDispatchInfo = aIter - > second ;
aInformationList . push_back ( aDispatchInfo ) ;
}
}
Sequence < DispatchInformation > aInformation ( aInformationList . size ( ) ) ;
: : std : : transform ( aInformationList . begin ( ) ,
aInformationList . end ( ) ,
aInformation . getArray ( ) ,
: : std : : identity < DispatchInformation > ( )
) ;
return aInformation ;
}