diff options
Diffstat (limited to 'dbaccess/source')
103 files changed, 6181 insertions, 2318 deletions
diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx index cd39719a6..01ec6231c 100644 --- a/dbaccess/source/core/api/RowSet.cxx +++ b/dbaccess/source/core/api/RowSet.cxx @@ -1575,7 +1575,11 @@ void ORowSet::setStatementResultSetType( const Reference< XPropertySet >& _rxSta { ResultSetType::SCROLL_INSENSITIVE, ResultSetConcurrency::READ_ONLY }, { ResultSetType::FORWARD_ONLY, ResultSetConcurrency::READ_ONLY } }; - for ( sal_Int32 i=0; i<5; ++i ) + sal_Int32 i=0; + if ( m_xActiveConnection->getMetaData()->isReadOnly() ) + i = 2; // if the database is read-only we only should use read-only concurrency + + for ( ; i<5; ++i ) { nResultSetType = nCharacteristics[i][0]; nResultSetConcurrency = nCharacteristics[i][1]; @@ -1897,6 +1901,8 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi if(!xColumn.is()) { // no column found so we could look at the position i + //bReFetchName = sal_True; + //sColumnLabel = ::rtl::OUString(); Reference<XIndexAccess> xIndexAccess(m_xColumns,UNO_QUERY); if(xIndexAccess.is() && i <= xIndexAccess->getCount()) { @@ -1906,7 +1912,9 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi { Sequence< ::rtl::OUString> aSeq = m_xColumns->getElementNames(); if( i <= aSeq.getLength()) + { m_xColumns->getByName(aSeq.getConstArray()[i-1]) >>= xColumn; + } } } if(bReFetchName && xColumn.is()) @@ -2314,6 +2322,12 @@ sal_Bool ORowSet::impl_buildActiveCommand_throw() { xQuery->getPropertyValue(PROPERTY_COMMAND) >>= sCommand; xQuery->getPropertyValue(PROPERTY_ESCAPE_PROCESSING) >>= bDoEscapeProcessing; + if ( bDoEscapeProcessing != m_bUseEscapeProcessing ) + { + sal_Bool bOldValue = m_bUseEscapeProcessing; + m_bUseEscapeProcessing = bDoEscapeProcessing; + fireProperty(PROPERTY_ID_ESCAPE_PROCESSING,bOldValue,bDoEscapeProcessing); + } ::rtl::OUString aCatalog,aSchema,aTable; xQuery->getPropertyValue(PROPERTY_UPDATE_CATALOGNAME) >>= aCatalog; diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx index 96edf3224..11e7d05fb 100644 --- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx +++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx @@ -34,6 +34,7 @@ #include "dbastrings.hrc" #include "HelperCollections.hxx" #include "SingleSelectQueryComposer.hxx" +#include "sdbcoretools.hxx" /** === begin UNO includes === **/ #include <com/sun/star/beans/PropertyAttribute.hpp> @@ -225,24 +226,11 @@ OSingleSelectQueryComposer::OSingleSelectQueryComposer(const Reference< XNameAcc OSL_ENSURE(m_sDecimalSep.getLength() == 1,"OSingleSelectQueryComposer::OSingleSelectQueryComposer decimal separator is not 1 length"); try { - Reference< XChild> xChild(_xConnection, UNO_QUERY); - if(xChild.is()) + Any aValue; + Reference<XInterface> xDs = dbaccess::getDataSource(_xConnection); + if ( dbtools::getDataSourceSetting(xDs,static_cast <rtl::OUString> (PROPERTY_BOOLEANCOMPARISONMODE),aValue) ) { - Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY); - if ( xProp.is() ) - { - Sequence< PropertyValue > aInfo; - xProp->getPropertyValue(PROPERTY_INFO) >>= aInfo; - const PropertyValue* pBegin = aInfo.getConstArray(); - const PropertyValue* pEnd = pBegin + aInfo.getLength(); - for (; pBegin != pEnd; ++pBegin) - { - if ( pBegin->Name == static_cast <rtl::OUString> (PROPERTY_BOOLEANCOMPARISONMODE) ) - { - OSL_VERIFY( pBegin->Value >>= m_nBoolCompareMode ); - } - } - } + OSL_VERIFY( aValue >>= m_nBoolCompareMode ); } } catch(Exception&) diff --git a/dbaccess/source/core/api/View.cxx b/dbaccess/source/core/api/View.cxx new file mode 100644 index 000000000..3644c4f42 --- /dev/null +++ b/dbaccess/source/core/api/View.cxx @@ -0,0 +1,161 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: View.cxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" + +#include "View.hxx" +#include "dbastrings.hrc" + +#include "connectivity/dbexception.hxx" +#include "connectivity/dbtools.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/lang/WrappedTargetException.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +/** === end UNO includes === **/ + +#include <cppuhelper/exc_hlp.hxx> +#include <tools/diagnose_ex.h> +#include <unotools/sharedunocomponent.hxx> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using namespace ::com::sun::star::uno; + using ::com::sun::star::sdbc::XDatabaseMetaData; + using ::com::sun::star::sdbc::SQLException; + using ::com::sun::star::sdbc::XConnection; + using ::com::sun::star::lang::WrappedTargetException; + using ::com::sun::star::lang::XMultiServiceFactory; + using ::com::sun::star::sdbc::XResultSet; + using ::com::sun::star::sdbc::XStatement; + using ::com::sun::star::lang::DisposedException; + using ::com::sun::star::sdbc::XRow; + /** === end UNO using === **/ + + ::rtl::OUString lcl_getServiceNameForSetting(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,const ::rtl::OUString& i_sSetting) + { + ::rtl::OUString sSupportService; + Any aValue; + if ( dbtools::getDataSourceSetting(_xConnection,i_sSetting,aValue) ) + { + aValue >>= sSupportService; + } + return sSupportService; + } + //==================================================================== + //= View + //==================================================================== + //-------------------------------------------------------------------- + View::View( const Reference< XConnection >& _rxConnection, sal_Bool _bCaseSensitive, + const ::rtl::OUString& _rCatalogName,const ::rtl::OUString& _rSchemaName, const ::rtl::OUString& _rName ) + :View_Base( _bCaseSensitive, _rName, _rxConnection->getMetaData(), 0, ::rtl::OUString(), _rSchemaName, _rCatalogName ) + { + m_nCommandHandle = getProperty(PROPERTY_COMMAND).Handle; + try + { + Reference<XMultiServiceFactory> xFac(_rxConnection,UNO_QUERY_THROW); + static const ::rtl::OUString s_sViewAccess(RTL_CONSTASCII_USTRINGPARAM("ViewAccessServiceName")); + m_xViewAccess.set(xFac->createInstance(lcl_getServiceNameForSetting(_rxConnection,s_sViewAccess)),UNO_QUERY); + } + catch(const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + //-------------------------------------------------------------------- + View::~View() + { + } + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_REFCOUNT( View, View_Base ) + IMPLEMENT_GET_IMPLEMENTATION_ID( View ) + // ------------------------------------------------------------------------- + Any SAL_CALL View::queryInterface( const Type & _rType ) throw(RuntimeException) + { + if(_rType == getCppuType( (Reference<XAlterView>*)0) && !m_xViewAccess.is() ) + return Any(); + Any aReturn = View_Base::queryInterface( _rType ); + if ( !aReturn.hasValue() ) + aReturn = View_IBASE::queryInterface( _rType ); + return aReturn; + } + // ------------------------------------------------------------------------- + Sequence< Type > SAL_CALL View::getTypes( ) throw(RuntimeException) + { + Type aAlterType = getCppuType( (Reference<XAlterView>*)0); + + Sequence< Type > aTypes( ::comphelper::concatSequences(View_Base::getTypes(),View_IBASE::getTypes()) ); + ::std::vector<Type> aOwnTypes; + aOwnTypes.reserve(aTypes.getLength()); + + const Type* pIter = aTypes.getConstArray(); + const Type* pEnd = pIter + aTypes.getLength(); + for(;pIter != pEnd ;++pIter) + { + if( (*pIter != aAlterType || m_xViewAccess.is()) ) + aOwnTypes.push_back(*pIter); + } + + Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0]; + return Sequence< Type >(pTypes, aOwnTypes.size()); + } + + //-------------------------------------------------------------------- + void SAL_CALL View::alterCommand( const ::rtl::OUString& _rNewCommand ) throw (SQLException, RuntimeException) + { + OSL_ENSURE(m_xViewAccess.is(),"Illegal call to AlterView!"); + m_xViewAccess->alterCommand(this,_rNewCommand); + } + + //-------------------------------------------------------------------- + void SAL_CALL View::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const + { + if ( _nHandle == m_nCommandHandle && m_xViewAccess.is() ) + { + // retrieve the very current command, don't rely on the base classes cached value + // (which we initialized empty, anyway) + _rValue <<= m_xViewAccess->getCommand(const_cast<View*>(this)); + return; + } + + View_Base::getFastPropertyValue( _rValue, _nHandle ); + } + // ----------------------------------------------------------------------------- +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/api/column.cxx b/dbaccess/source/core/api/column.cxx index dab1a3123..43412bb02 100644 --- a/dbaccess/source/core/api/column.cxx +++ b/dbaccess/source/core/api/column.cxx @@ -414,7 +414,16 @@ sdbcx::ObjectType OColumns::appendObject( const ::rtl::OUString& _rForName, cons else if ( m_pTable && !m_pTable->isNew() ) { if ( m_bAddColumn ) - xReturn = OColumns_BASE::appendObject( _rForName, descriptor ); + { + Reference< ::com::sun::star::sdb::tools::XTableAlteration> xAlterService = m_pTable->getAlterService(); + if ( xAlterService.is() ) + { + xAlterService->addColumn(m_pTable,descriptor); + xReturn = createObject( _rForName ); + } + else + xReturn = OColumns_BASE::appendObject( _rForName, descriptor ); + } else ::dbtools::throwGenericSQLException( DBA_RES( RID_STR_NO_COLUMN_ADD ), static_cast<XChild*>(static_cast<TXChild*>(this)) ); } @@ -440,7 +449,13 @@ void OColumns::dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName) else if ( m_pTable && !m_pTable->isNew() ) { if ( m_bDropColumn ) - OColumns_BASE::dropObject(_nPos,_sElementName); + { + Reference< ::com::sun::star::sdb::tools::XTableAlteration> xAlterService = m_pTable->getAlterService(); + if ( xAlterService.is() ) + xAlterService->dropColumn(m_pTable,_sElementName); + else + OColumns_BASE::dropObject(_nPos,_sElementName); + } else ::dbtools::throwGenericSQLException( DBA_RES( RID_STR_NO_COLUMN_DROP ), static_cast<XChild*>(static_cast<TXChild*>(this)) ); } diff --git a/dbaccess/source/core/api/definitioncolumn.cxx b/dbaccess/source/core/api/definitioncolumn.cxx index 91885ee52..c3976e077 100644 --- a/dbaccess/source/core/api/definitioncolumn.cxx +++ b/dbaccess/source/core/api/definitioncolumn.cxx @@ -189,7 +189,7 @@ rtl::OUString OTableColumn::getImplementationName( ) throw (RuntimeException) DBG_NAME( OQueryColumn ); // ------------------------------------------------------------------------- -OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn, const Reference< XConnection >& _rxConnection ) +OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn, const Reference< XConnection >& _rxConnection,const ::rtl::OUString& _sNewName ) :OTableColumnDescriptor( false /* do not act as descriptor */ ) { const sal_Int32 nPropAttr = PropertyAttribute::READONLY; @@ -207,7 +207,14 @@ OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn, co OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_TYPE ) >>= m_nType ); OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_ISAUTOINCREMENT ) >>= m_bAutoIncrement ); OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_ISCURRENCY ) >>= m_bCurrency ); - OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_NAME ) >>= m_sName ); + if ( _sNewName.getLength() ) + { + m_sName = _sNewName; + } + else + { + OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_NAME ) >>= m_sName ); + } m_bRowVersion = sal_False; Reference< XPropertySetInfo > xPSI( _rxParserColumn->getPropertySetInfo(), UNO_SET_THROW ); diff --git a/dbaccess/source/core/api/makefile.mk b/dbaccess/source/core/api/makefile.mk index 308a9e6c7..afd42c991 100644 --- a/dbaccess/source/core/api/makefile.mk +++ b/dbaccess/source/core/api/makefile.mk @@ -70,6 +70,7 @@ SLOFILES= \ $(SLO)$/SingleSelectQueryComposer.obj \ $(SLO)$/HelperCollections.obj \ $(SLO)$/datasettings.obj \ + $(SLO)$/View.obj \ $(SLO)$/columnsettings.obj # --- Targets ---------------------------------- diff --git a/dbaccess/source/core/api/query.cxx b/dbaccess/source/core/api/query.cxx index 86d7610c5..a18f65bd0 100644 --- a/dbaccess/source/core/api/query.cxx +++ b/dbaccess/source/core/api/query.cxx @@ -188,9 +188,10 @@ void OQuery::rebuildColumns() m_pColumnMediator = NULL; Reference<XColumnsSupplier> xColSup(m_xCommandDefinition,UNO_QUERY); + Reference< XNameAccess > xColumnDefinitions; if ( xColSup.is() ) { - Reference< XNameAccess > xColumnDefinitions = xColSup->getColumns(); + xColumnDefinitions = xColSup->getColumns(); if ( xColumnDefinitions.is() ) m_pColumnMediator = new OContainerMediator( m_pColumns, xColumnDefinitions, m_xConnection, OContainerMediator::eColumns ); } @@ -233,19 +234,29 @@ void OQuery::rebuildColumns() } Sequence< ::rtl::OUString> aNames = xColumns->getElementNames(); - const ::rtl::OUString* pBegin = aNames.getConstArray(); - const ::rtl::OUString* pEnd = pBegin + aNames.getLength(); - for ( ;pBegin != pEnd; ++pBegin) + Sequence< ::rtl::OUString> aDefintionNames; + bool bApplyDefinitionNames = false; + //if ( xColumnDefinitions.is() ) + //{ + // aDefintionNames = xColumnDefinitions->getElementNames(); + // bApplyDefinitionNames = aDefintionNames.getLength() == aNames.getLength(); + //} + + ::rtl::OUString sEmpty; + const ::rtl::OUString* pIter = aNames.getConstArray(); + const ::rtl::OUString* pEnd = pIter + aNames.getLength(); + for ( sal_Int32 i = 0;pIter != pEnd; ++pIter,++i) { - Reference<XPropertySet> xSource(xColumns->getByName( *pBegin ),UNO_QUERY); - OQueryColumn* pColumn = new OQueryColumn( xSource, m_xConnection ); + Reference<XPropertySet> xSource(xColumns->getByName( *pIter ),UNO_QUERY); + OQueryColumn* pColumn = new OQueryColumn( xSource, m_xConnection, bApplyDefinitionNames ? aDefintionNames[i] : sEmpty); Reference< XChild > xChild( *pColumn, UNO_QUERY_THROW ); xChild->setParent( *this ); - implAppendColumn( *pBegin, pColumn ); + ::rtl::OUString sNewName = bApplyDefinitionNames ? aDefintionNames[i] : *pIter; + implAppendColumn( sNewName, pColumn ); Reference< XPropertySet > xDest( *pColumn, UNO_QUERY_THROW ); if ( m_pColumnMediator.is() ) - m_pColumnMediator->notifyElementCreated( *pBegin, xDest ); + m_pColumnMediator->notifyElementCreated( sNewName, xDest ); } } catch( const SQLContext& e ) diff --git a/dbaccess/source/core/api/resultcolumn.cxx b/dbaccess/source/core/api/resultcolumn.cxx index 4bebffc7b..27532a3f2 100644 --- a/dbaccess/source/core/api/resultcolumn.cxx +++ b/dbaccess/source/core/api/resultcolumn.cxx @@ -107,20 +107,26 @@ void OResultColumn::impl_determineIsRowVersion_nothrow() getPropertyValue( PROPERTY_TABLENAME ) >>= sTable; getPropertyValue( PROPERTY_NAME ) >>= sColumnName; - Reference< XResultSet > xVersionColumns = m_xDBMetaData->getVersionColumns( - makeAny( sCatalog ), sSchema, sTable ); - if ( xVersionColumns.is() ) // allowed to be NULL + try { - Reference< XRow > xResultRow( xVersionColumns, UNO_QUERY_THROW ); - while ( xVersionColumns->next() ) + Reference< XResultSet > xVersionColumns = m_xDBMetaData->getVersionColumns( + makeAny( sCatalog ), sSchema, sTable ); + if ( xVersionColumns.is() ) // allowed to be NULL { - if ( xResultRow->getString( 2 ) == sColumnName ) + Reference< XRow > xResultRow( xVersionColumns, UNO_QUERY_THROW ); + while ( xVersionColumns->next() ) { - m_aIsRowVersion <<= (sal_Bool)(sal_True); - break; + if ( xResultRow->getString( 2 ) == sColumnName ) + { + m_aIsRowVersion <<= (sal_Bool)(sal_True); + break; + } } } } + catch(const SQLException&) + { + } } catch( const Exception& ) { diff --git a/dbaccess/source/core/api/table.cxx b/dbaccess/source/core/api/table.cxx index c80c46fbd..ec6c8e97b 100644 --- a/dbaccess/source/core/api/table.cxx +++ b/dbaccess/source/core/api/table.cxx @@ -28,77 +28,33 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_dbaccess.hxx" -#ifndef _DBA_CORE_TABLE_HXX_ #include "table.hxx" -#endif -#ifndef _DBACORE_DEFINITIONCOLUMN_HXX_ #include <definitioncolumn.hxx> -#endif -#ifndef DBACCESS_SHARED_DBASTRINGS_HRC #include "dbastrings.hrc" -#endif -#ifndef _DBA_CORE_RESOURCE_HXX_ #include "core_resource.hxx" -#endif -#ifndef _DBA_CORE_RESOURCE_HRC_ #include "core_resource.hrc" -#endif -#ifndef _TOOLS_DEBUG_HXX -#include <tools/debug.hxx> -#endif +#include "CIndexes.hxx" -#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <tools/debug.hxx> #include <cppuhelper/typeprovider.hxx> -#endif -#ifndef _COMPHELPER_ENUMHELPER_HXX_ #include <comphelper/enumhelper.hxx> -#endif -#ifndef _COMPHELPER_CONTAINER_HXX_ #include <comphelper/container.hxx> -#endif -#ifndef _COMPHELPER_SEQUENCE_HXX_ #include <comphelper/sequence.hxx> -#endif -#ifndef _COMPHELPER_TYPES_HXX_ #include <comphelper/types.hxx> -#endif -#ifndef _COM_SUN_STAR_UTIL_XREFRESHLISTENER_HPP_ +//#include <comphelper/extract.hxx> #include <com/sun/star/util/XRefreshListener.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ #include <com/sun/star/sdbc/XConnection.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ #include <com/sun/star/sdbc/XRow.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_ #include <com/sun/star/sdbcx/Privilege.hpp> -#endif +#include <com/sun/star/sdbc/XResultSetMetaData.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> + #include <connectivity/TKeys.hxx> -#ifndef DBACCESS_INDEXES_HXX_ -#include "CIndexes.hxx" -#endif -#ifndef _CONNECTIVITY_DBTOOLS_HXX_ #include <connectivity/dbtools.hxx> -#endif -#ifndef _DBHELPER_DBEXCEPTION_HXX_ #include <connectivity/dbexception.hxx> -#endif -#ifndef _COMPHELPER_EXTRACT_HXX_ -#include <comphelper/extract.hxx> -#endif -#ifndef DBACORE_SDBCORETOOLS_HXX + #include "sdbcoretools.hxx" -#endif -#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATA_HPP_ -#include <com/sun/star/sdbc/XResultSetMetaData.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_ -#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> -#endif -#ifndef DBA_CONTAINERMEDIATOR_HXX #include "ContainerMediator.hxx" -#endif #include <rtl/logfile.hxx> using namespace dbaccess; @@ -149,6 +105,7 @@ ODBTable::ODBTable(connectivity::sdbcx::OCollection* _pTables :OTable_Base(_pTables,_rxConn, _rxConn->getMetaData().is() && _rxConn->getMetaData()->supportsMixedCaseQuotedIdentifiers()) ,m_nPrivileges(-1) { + DBG_CTOR(ODBTable, NULL); RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTable::ODBTable" ); } // ------------------------------------------------------------------------- @@ -308,18 +265,18 @@ void ODBTable::construct() describeProperties(aProps); if(!_nId) { - Property* pBegin = aProps.getArray(); - Property* pEnd = pBegin + aProps.getLength(); - for(;pBegin != pEnd;++pBegin) + Property* pIter = aProps.getArray(); + Property* pEnd = pIter + aProps.getLength(); + for(;pIter != pEnd;++pIter) { - if (0 == pBegin->Name.compareToAscii(PROPERTY_CATALOGNAME)) - pBegin->Attributes = PropertyAttribute::READONLY; - else if (0 == pBegin->Name.compareToAscii(PROPERTY_SCHEMANAME)) - pBegin->Attributes = PropertyAttribute::READONLY; - else if (0 == pBegin->Name.compareToAscii(PROPERTY_DESCRIPTION)) - pBegin->Attributes = PropertyAttribute::READONLY; - else if (0 == pBegin->Name.compareToAscii(PROPERTY_NAME)) - pBegin->Attributes = PropertyAttribute::READONLY; + if (0 == pIter->Name.compareToAscii(PROPERTY_CATALOGNAME)) + pIter->Attributes = PropertyAttribute::READONLY; + else if (0 == pIter->Name.compareToAscii(PROPERTY_SCHEMANAME)) + pIter->Attributes = PropertyAttribute::READONLY; + else if (0 == pIter->Name.compareToAscii(PROPERTY_DESCRIPTION)) + pIter->Attributes = PropertyAttribute::READONLY; + else if (0 == pIter->Name.compareToAscii(PROPERTY_NAME)) + pIter->Attributes = PropertyAttribute::READONLY; } } @@ -337,14 +294,11 @@ IMPLEMENT_SERVICE_INFO1(ODBTable, "com.sun.star.sdb.dbaccess.ODBTable", SERVICE_ Any SAL_CALL ODBTable::queryInterface( const Type & rType ) throw(RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTable::getInfoHelper" ); - Any aRet; - if(rType == getCppuType( (Reference<XRename>*)0)) + if(rType == getCppuType( (Reference<XRename>*)0) && !getRenameService().is() ) return Any(); - if(rType == getCppuType( (Reference<XAlterTable>*)0)) + if(rType == getCppuType( (Reference<XAlterTable>*)0) && !getAlterService().is() ) return Any(); - aRet = OTable_Base::queryInterface( rType); - - return aRet; + return OTable_Base::queryInterface( rType); } // ------------------------------------------------------------------------- Sequence< Type > SAL_CALL ODBTable::getTypes( ) throw(RuntimeException) @@ -357,12 +311,12 @@ Sequence< Type > SAL_CALL ODBTable::getTypes( ) throw(RuntimeException) ::std::vector<Type> aOwnTypes; aOwnTypes.reserve(aTypes.getLength()); - const Type* pBegin = aTypes.getConstArray(); - const Type* pEnd = pBegin + aTypes.getLength(); - for(;pBegin != pEnd ;++pBegin) + const Type* pIter = aTypes.getConstArray(); + const Type* pEnd = pIter + aTypes.getLength(); + for(;pIter != pEnd ;++pIter) { - if(*pBegin != aRenameType && *pBegin != aAlterType) - aOwnTypes.push_back(*pBegin); + if( (*pIter != aRenameType || getRenameService().is()) && (*pIter != aAlterType || getAlterService().is())) + aOwnTypes.push_back(*pIter); } Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0]; @@ -370,10 +324,17 @@ Sequence< Type > SAL_CALL ODBTable::getTypes( ) throw(RuntimeException) } // XRename, //------------------------------------------------------------------------------ -void SAL_CALL ODBTable::rename( const ::rtl::OUString& /*_rNewName*/ ) throw(SQLException, ElementExistException, RuntimeException) +void SAL_CALL ODBTable::rename( const ::rtl::OUString& _rNewName ) throw(SQLException, ElementExistException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTable::rename" ); - throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() ); + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed); + if ( !getRenameService().is() ) + throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() ); + + Reference<XPropertySet> xTable(this); + getRenameService()->rename(xTable,_rNewName); + ::connectivity::OTable_TYPEDEF::rename(_rNewName); } // XAlterTable, @@ -382,55 +343,15 @@ void SAL_CALL ODBTable::alterColumnByName( const ::rtl::OUString& _rName, const { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTable::alterColumnByName" ); ::osl::MutexGuard aGuard(m_aMutex); - checkDisposed( - connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed); - if(m_pColumns->hasByName(_rName)) - { - ::rtl::OUString sSql = ::rtl::OUString::createFromAscii("ALTER TABLE "); - ::rtl::OUString aQuote; - Reference<XDatabaseMetaData> xMeta = getMetaData(); - if ( xMeta.is() ) - aQuote = xMeta->getIdentifierQuoteString( ); - ::rtl::OUString sComposedName; - - sComposedName = ::dbtools::composeTableName( xMeta, m_CatalogName, m_SchemaName, m_Name, sal_True, ::dbtools::eInTableDefinitions ); - if(!sComposedName.getLength()) - ::dbtools::throwFunctionSequenceException(*this); - - sSql += sComposedName; - sSql += ::rtl::OUString::createFromAscii(" ALTER "); - sSql += ::dbtools::quoteName(aQuote,_rName); - - ::rtl::OUString sNewDefaultValue,sDefaultValue; - - Reference<XPropertySet> xColumn; - m_pColumns->getByName(_rName) >>= xColumn; - if(_rxDescriptor->getPropertySetInfo()->hasPropertyByName(PROPERTY_DEFAULTVALUE)) - _rxDescriptor->getPropertyValue(PROPERTY_DEFAULTVALUE) >>= sNewDefaultValue; - if(xColumn.is() && xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_DEFAULTVALUE)) - xColumn->getPropertyValue(PROPERTY_DEFAULTVALUE) >>= sDefaultValue; - - if(sNewDefaultValue != sDefaultValue && getMetaData().is() ) - { - if(sNewDefaultValue.getLength()) - { - sSql += ::rtl::OUString::createFromAscii(" SET DEFAULT "); - sSql += sNewDefaultValue; - } - else - sSql += ::rtl::OUString::createFromAscii(" DROP DEFAULT"); - OSL_ENSURE(getMetaData()->getConnection().is(),"Connection is null!"); - Reference< XStatement > xStmt = getMetaData()->getConnection()->createStatement( ); - if(xStmt.is()) - xStmt->execute(sSql); - } - else - // not supported - throw SQLException(DBACORE_RESSTRING(RID_STR_NO_ALTER_COLUMN_DEF),*this,SQLSTATE_GENERAL,1000,Any() ); - } - else - // not supported - throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_NAME),*this,SQLSTATE_GENERAL,1000,Any() ); + checkDisposed(connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed); + if ( !getAlterService().is() ) + throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() ); + + if ( !m_pColumns->hasByName(_rName) ) + throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,Any() ); + + Reference<XPropertySet> xTable(this); + getAlterService()->alterColumnByName(xTable,_rName,_rxDescriptor); m_pColumns->refresh(); } // ----------------------------------------------------------------------------- @@ -473,8 +394,8 @@ sdbcx::OCollection* ODBTable::createColumns(const TStringVector& _rNames) RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTable::createColumns" ); Reference<XDatabaseMetaData> xMeta = getMetaData(); OColumns* pCol = new OColumns(*this, m_aMutex, NULL, isCaseSensitive(), _rNames, this,this, - xMeta.is() && xMeta->supportsAlterTableWithAddColumn(), - xMeta.is() && xMeta->supportsAlterTableWithDropColumn()); + getAlterService().is() || (xMeta.is() && xMeta->supportsAlterTableWithAddColumn()), + getAlterService().is() || (xMeta.is() && xMeta->supportsAlterTableWithDropColumn())); static_cast<OColumnsHelper*>(pCol)->setParent(this); pCol->setParent(*this); m_pColumnMediator = new OContainerMediator( pCol, m_xColumnDefinitions, getConnection(), OContainerMediator::eColumns ); @@ -494,7 +415,3 @@ sdbcx::OCollection* ODBTable::createIndexes(const TStringVector& _rNames) return new OIndexes(this,m_aMutex,_rNames,NULL); } // ----------------------------------------------------------------------------- - - - - diff --git a/dbaccess/source/core/api/viewcontainer.cxx b/dbaccess/source/core/api/viewcontainer.cxx index cc53d63e8..42412aa2e 100644 --- a/dbaccess/source/core/api/viewcontainer.cxx +++ b/dbaccess/source/core/api/viewcontainer.cxx @@ -28,74 +28,30 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_dbaccess.hxx" -#ifndef _DBA_CORE_VIEWCONTAINER_HXX_ #include "viewcontainer.hxx" -#endif -#ifndef DBACCESS_SHARED_DBASTRINGS_HRC #include "dbastrings.hrc" -#endif -#ifndef _TOOLS_DEBUG_HXX +#include "core_resource.hxx" +#include "core_resource.hrc" +#include "View.hxx" + #include <tools/debug.hxx> -#endif -#ifndef _WLDCRD_HXX #include <tools/wldcrd.hxx> -#endif -#ifndef _COMPHELPER_ENUMHELPER_HXX_ #include <comphelper/enumhelper.hxx> -#endif -#ifndef _DBA_CORE_RESOURCE_HXX_ -#include "core_resource.hxx" -#endif -#ifndef _DBA_CORE_RESOURCE_HRC_ -#include "core_resource.hrc" -#endif +#include <comphelper/types.hxx> +#include <connectivity/dbtools.hxx> +#include <comphelper/extract.hxx> +#include <connectivity/dbexception.hxx> +#include <rtl/ustrbuf.hxx> -#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ #include <com/sun/star/beans/XPropertySet.hpp> -#endif - -#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ #include <com/sun/star/sdbc/XConnection.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_ #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_ -#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_ -#include <com/sun/star/sdbcx/XTablesSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ #include <com/sun/star/sdbc/KeyRule.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ -#include <com/sun/star/sdbcx/KeyType.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ #include <com/sun/star/sdbc/ColumnValue.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ #include <com/sun/star/sdbc/XRow.hpp> -#endif -#ifndef _COMPHELPER_TYPES_HXX_ -#include <comphelper/types.hxx> -#endif -#ifndef _CONNECTIVITY_DBTOOLS_HXX_ -#include <connectivity/dbtools.hxx> -#endif -#ifndef _COMPHELPER_EXTRACT_HXX_ -#include <comphelper/extract.hxx> -#endif -#ifndef _DBHELPER_DBEXCEPTION_HXX_ -#include <connectivity/dbexception.hxx> -#endif -#ifndef _CONNECTIVITY_SDBCX_VIEW_HXX_ -#include <connectivity/sdbcx/VView.hxx> -#endif -#ifndef _RTL_USTRBUF_HXX_ -#include <rtl/ustrbuf.hxx> -#endif +#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> +#include <com/sun/star/sdbcx/XTablesSupplier.hpp> +#include <com/sun/star/sdbcx/KeyType.hpp> using namespace dbaccess; using namespace dbtools; @@ -156,14 +112,12 @@ ObjectType OViewContainer::createObject(const ::rtl::OUString& _rName) sSchema, sTable, ::dbtools::eInDataManipulation); - return new ::connectivity::sdbcx::OView(isCaseSensitive(), - sTable, - m_xMetaData, - 0, - ::rtl::OUString(), - sSchema, - sCatalog - ); + return new View(m_xConnection, + isCaseSensitive(), + sCatalog, + sSchema, + sTable + ); } return xProp; diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 822d91a43..10028cdb8 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -38,6 +38,7 @@ #include "dbastrings.hrc" #include "ModelImpl.hxx" #include "userinformation.hxx" +#include "sdbcoretools.hxx" /** === begin UNO includes === **/ #include <com/sun/star/container/XSet.hpp> @@ -53,7 +54,6 @@ #include <comphelper/interaction.hxx> #include <comphelper/mediadescriptor.hxx> -#include <comphelper/namedvaluecollection.hxx> #include <comphelper/seqstream.hxx> #include <comphelper/sequence.hxx> #include <connectivity/dbexception.hxx> @@ -296,7 +296,7 @@ void DocumentStorageAccess::commitStorages() SAL_THROW(( IOException, RuntimeExc ++aIter ) { - m_pModelImplementation->commitStorageIfWriteable( aIter->second ); + tools::stor::commitStorageIfWriteable( aIter->second ); } } catch(const WrappedTargetException&) @@ -317,7 +317,7 @@ bool DocumentStorageAccess::commitEmbeddedStorage( bool _bPreventRootCommits ) { NamedStorages::const_iterator pos = m_aExposedStorages.find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "database" ) ) ); if ( pos != m_aExposedStorages.end() ) - bSuccess = m_pModelImplementation->commitStorageIfWriteable( pos->second ); + bSuccess = tools::stor::commitStorageIfWriteable( pos->second ); } catch( Exception& ) { @@ -808,27 +808,41 @@ const Reference< XNumberFormatsSupplier > & ODatabaseModelImpl::getNumberFormats } return m_xNumberFormatsSupplier; } + // ----------------------------------------------------------------------------- -void ODatabaseModelImpl::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArgs ) +void ODatabaseModelImpl::setDocFileLocation( const ::rtl::OUString& i_rLoadedFrom ) { - ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs ); + ENSURE_OR_THROW( i_rLoadedFrom.getLength(), "invalid URL" ); + m_sDocFileLocation = i_rLoadedFrom; +} - ::rtl::OUString sDocumentLocation( aMediaDescriptor.getOrDefault( "SalvagedFile", _rURL ) ); - if ( !sDocumentLocation.getLength() ) - // this indicates "the document is being recovered, but _rURL already is the real document URL, - // not the temporary document location" - sDocumentLocation = _rURL; +// ----------------------------------------------------------------------------- +void ODatabaseModelImpl::setResource( const ::rtl::OUString& i_rDocumentURL, const Sequence< PropertyValue >& _rArgs ) +{ + ENSURE_OR_THROW( i_rDocumentURL.getLength(), "invalid URL" ); + ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs ); +#if OSL_DEBUG_LEVEL > 0 if ( aMediaDescriptor.has( "SalvagedFile" ) ) - aMediaDescriptor.remove( "SalvagedFile" ); + { + ::rtl::OUString sSalvagedFile( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) ); + // If SalvagedFile is an empty string, this indicates "the document is being recovered, but i_rDocumentURL already + // is the real document URL, not the temporary document location" + if ( !sSalvagedFile.getLength() ) + sSalvagedFile = i_rDocumentURL; + + OSL_ENSURE( sSalvagedFile == i_rDocumentURL, "ODatabaseModelImpl::setResource: inconsistency!" ); + // nowadays, setResource should only be called with the logical URL of the document + } +#endif - m_aArgs = stripLoadArguments( aMediaDescriptor ); + m_aMediaDescriptor = stripLoadArguments( aMediaDescriptor ); - switchToURL( sDocumentLocation, _rURL ); + impl_switchToLogicalURL( i_rDocumentURL ); } // ----------------------------------------------------------------------------- -Sequence< PropertyValue > ODatabaseModelImpl::stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments ) +::comphelper::NamedValueCollection ODatabaseModelImpl::stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments ) { OSL_ENSURE( !_rArguments.has( "Model" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (1)!" ); OSL_ENSURE( !_rArguments.has( "ViewName" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (2)!" ); @@ -836,7 +850,7 @@ Sequence< PropertyValue > ODatabaseModelImpl::stripLoadArguments( const ::comphe ::comphelper::NamedValueCollection aMutableArgs( _rArguments ); aMutableArgs.remove( "Model" ); aMutableArgs.remove( "ViewName" ); - return aMutableArgs.getPropertyValues(); + return aMutableArgs; } // ----------------------------------------------------------------------------- @@ -870,11 +884,9 @@ Reference< XStorage > ODatabaseModelImpl::getOrCreateRootStorage() if ( xStorageFactory.is() ) { Any aSource; - ::comphelper::NamedValueCollection aArgs( m_aArgs ); - - aSource = aArgs.get( "Stream" ); + aSource = m_aMediaDescriptor.get( "Stream" ); if ( !aSource.hasValue() ) - aSource = aArgs.get( "InputStream" ); + aSource = m_aMediaDescriptor.get( "InputStream" ); if ( !aSource.hasValue() && m_sDocFileLocation.getLength() ) aSource <<= m_sDocFileLocation; // TODO: shouldn't we also check URL? @@ -950,48 +962,12 @@ bool ODatabaseModelImpl::commitEmbeddedStorage( bool _bPreventRootCommits ) } // ----------------------------------------------------------------------------- -namespace -{ - bool lcl_storageIsWritable_nothrow( const Reference< XStorage >& _rxStorage ) - { - if ( !_rxStorage.is() ) - return false; - - sal_Int32 nMode = ElementModes::READ; - try - { - Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW ); - xStorageProps->getPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nMode; - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - return ( nMode & ElementModes::WRITE ) != 0; - } -} - -// ----------------------------------------------------------------------------- -bool ODatabaseModelImpl::commitStorageIfWriteable( const Reference< XStorage >& _rxStorage ) SAL_THROW(( IOException, WrappedTargetException, RuntimeException )) -{ - bool bSuccess = false; - Reference<XTransactedObject> xTrans( _rxStorage, UNO_QUERY ); - if ( xTrans.is() ) - { - if ( lcl_storageIsWritable_nothrow( _rxStorage ) ) - xTrans->commit(); - bSuccess = true; - } - return bSuccess; -} -// ----------------------------------------------------------------------------- bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage ) SAL_THROW(()) { bool bSuccess = false; try { - bSuccess = commitStorageIfWriteable( _rxStorage ); + bSuccess = tools::stor::commitStorageIfWriteable( _rxStorage ); } catch( const Exception& ) { @@ -1066,7 +1042,7 @@ Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _b // then nobody would call the doc's attachResource. So, we do it here, to ensure it's in a proper // state, fires all events, and so on. // #i105505# / 2009-10-02 / frank.schoenheit@sun.com - xModel->attachResource( xModel->getURL(), m_aArgs ); + xModel->attachResource( xModel->getURL(), m_aMediaDescriptor.getPropertyValues() ); } if ( _bInitialize ) @@ -1179,6 +1155,17 @@ const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings() AsciiPropertyValue( "PreferDosLikeLineEnds", makeAny( (sal_Bool)sal_False ) ), AsciiPropertyValue( "FormsCheckRequiredFields", makeAny( (sal_Bool)sal_True ) ), AsciiPropertyValue( "EscapeDateTime", makeAny( (sal_Bool)sal_True ) ), + + // known services to handle database tasks + AsciiPropertyValue( "TableAlterationServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "TableRenameServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "ViewAlterationServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "ViewAccessServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "CommandDefinitions", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "Forms", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "Reports", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "KeyAlterationServiceName", makeAny( ::rtl::OUString() ) ), + AsciiPropertyValue( "IndexAlterationServiceName", makeAny( ::rtl::OUString() ) ), AsciiPropertyValue() }; @@ -1216,9 +1203,8 @@ bool ODatabaseModelImpl::adjustMacroMode_AutoReject() // ----------------------------------------------------------------------------- bool ODatabaseModelImpl::checkMacrosOnLoading() { - ::comphelper::NamedValueCollection aArgs( m_aArgs ); Reference< XInteractionHandler > xInteraction; - xInteraction = aArgs.getOrDefault( "InteractionHandler", xInteraction ); + xInteraction = m_aMediaDescriptor.getOrDefault( "InteractionHandler", xInteraction ); return m_aMacroMode.checkMacrosOnLoading( xInteraction ); } @@ -1344,38 +1330,41 @@ Reference< XStorage > ODatabaseModelImpl::impl_switchToStorage_throw( const Refe lcl_rebaseScriptStorage_throw( m_xBasicLibraries, m_xDocumentStorage.getTyped() ); lcl_rebaseScriptStorage_throw( m_xDialogLibraries, m_xDocumentStorage.getTyped() ); - m_bReadOnly = !lcl_storageIsWritable_nothrow( m_xDocumentStorage.getTyped() ); + m_bReadOnly = !tools::stor::storageIsWritable_nothrow( m_xDocumentStorage.getTyped() ); // TODO: our data source, if it exists, must broadcast the change of its ReadOnly property return m_xDocumentStorage.getTyped(); } // ----------------------------------------------------------------------------- -void ODatabaseModelImpl::switchToURL( const ::rtl::OUString& _rDocumentLocation, const ::rtl::OUString& _rDocumentURL ) +void ODatabaseModelImpl::impl_switchToLogicalURL( const ::rtl::OUString& i_rDocumentURL ) { - // register at the database context, or change registration - const bool bURLChanged = ( _rDocumentURL != m_sDocumentURL ); + if ( i_rDocumentURL == m_sDocumentURL ) + return; + const ::rtl::OUString sOldURL( m_sDocumentURL ); - if ( bURLChanged ) + // update our name, if necessary + if ( ( m_sName == m_sDocumentURL ) // our name is our old URL + || ( !m_sName.getLength() ) // we do not have a name, yet (i.e. are not registered at the database context) + ) { - if ( ( m_sName == m_sDocumentURL ) // our name is our old URL - || ( !m_sName.getLength() ) // we do not have a name, yet (i.e. are not registered at the database context) - ) + INetURLObject aURL( i_rDocumentURL ); + if ( aURL.GetProtocol() != INET_PROT_NOT_VALID ) { - INetURLObject aURL( _rDocumentURL ); - if ( aURL.GetProtocol() != INET_PROT_NOT_VALID ) - { - m_sName = _rDocumentURL; - // TODO: our data source must broadcast the change of the Name property - } + m_sName = i_rDocumentURL; + // TODO: our data source must broadcast the change of the Name property } } - // remember both - m_sDocFileLocation = _rDocumentLocation.getLength() ? _rDocumentLocation : _rDocumentURL; - m_sDocumentURL = _rDocumentURL; + // remember URL + m_sDocumentURL = i_rDocumentURL; - if ( bURLChanged && m_pDBContext ) + // update our location, if necessary + if ( m_sDocFileLocation.getLength() == 0 ) + m_sDocFileLocation = m_sDocumentURL; + + // register at the database context, or change registration + if ( m_pDBContext ) { if ( sOldURL.getLength() ) m_pDBContext->databaseDocumentURLChange( sOldURL, m_sDocumentURL ); @@ -1396,8 +1385,7 @@ sal_Int16 ODatabaseModelImpl::getCurrentMacroExecMode() const sal_Int16 nCurrentMode = MacroExecMode::NEVER_EXECUTE; try { - ::comphelper::NamedValueCollection aArgs( m_aArgs ); - nCurrentMode = aArgs.getOrDefault( "MacroExecutionMode", nCurrentMode ); + nCurrentMode = m_aMediaDescriptor.getOrDefault( "MacroExecutionMode", nCurrentMode ); } catch( const Exception& ) { @@ -1409,28 +1397,20 @@ sal_Int16 ODatabaseModelImpl::getCurrentMacroExecMode() const // ----------------------------------------------------------------------------- sal_Bool ODatabaseModelImpl::setCurrentMacroExecMode( sal_uInt16 nMacroMode ) { - try - { - ::comphelper::NamedValueCollection aArgs( m_aArgs ); - aArgs.put( "MacroExecutionMode", nMacroMode ); - aArgs >>= m_aArgs; - return sal_True; - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - - return sal_False; + m_aMediaDescriptor.put( "MacroExecutionMode", nMacroMode ); + return sal_True; } // ----------------------------------------------------------------------------- ::rtl::OUString ODatabaseModelImpl::getDocumentLocation() const { - // don't return getURL() (or m_sDocumentURL, which is the same). In case we were recovered - // after a previous crash of OOo, m_sDocFileLocation points to the file which were loaded from, - // and this is the one we need for security checks. - return getDocFileLocation(); + return getURL(); + // formerly, we returned getDocFileLocation here, which is the location of the file from which we + // recovered the "real" document. + // However, during CWS autorecovery evolving, we clarified (with MAV/MT) the role of XModel::getURL and + // XStorable::getLocation. In this course, we agreed that for a macro security check, the *document URL* + // (not the recovery file URL) is to be used: The recovery file lies in the backup folder, and by definition, + // this folder is considered to be secure. So, the document URL needs to be used to decide about the security. } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/core/dataaccess/ModelImpl.hxx b/dbaccess/source/core/dataaccess/ModelImpl.hxx index 4273d9d3d..36fdc427e 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.hxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.hxx @@ -70,6 +70,7 @@ /** === end UNO includes === **/ #include <comphelper/broadcasthelper.hxx> +#include <comphelper/namedvaluecollection.hxx> #include <comphelper/proparrhlp.hxx> #include <comphelper/sharedmutex.hxx> #include <connectivity/CommonTools.hxx> @@ -207,7 +208,7 @@ private: ODatabaseContext* m_pDBContext; DocumentEventsData m_aDocumentEvents; - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aArgs; + ::comphelper::NamedValueCollection m_aMediaDescriptor; /// the URL the document was loaded from ::rtl::OUString m_sDocFileLocation; @@ -318,14 +319,18 @@ public: DocumentEventsData& getDocumentEvents() { return m_aDocumentEvents; } - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& - getResource() const { return m_aArgs; } + const ::comphelper::NamedValueCollection& + getMediaDescriptor() const { return m_aMediaDescriptor; } - void attachResource( + void setResource( const ::rtl::OUString& _rURL, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs ); + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs + ); + void setDocFileLocation( + const ::rtl::OUString& i_rLoadedFrom + ); - static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > + static ::comphelper::NamedValueCollection stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments ); // other stuff @@ -341,16 +346,6 @@ public: /// commits our storage void commitRootStorage(); - /// commits a given storage if it's not readonly - static bool commitStorageIfWriteable( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage - ) - SAL_THROW(( - ::com::sun::star::io::IOException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException - )); - /// commits a given storage if it's not readonly, ignoring (but asserting) all errors static bool commitStorageIfWriteable_ignoreErrors( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage @@ -488,19 +483,6 @@ public: const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage ); - /** switches to the given document location/URL - - The document location is the URL of the file from which the document has been loaded. - The document URL is the "intended location" of the document. It differs from the location - if and only if the document was loaded as part of a document recovery process. In this case, - the location points to some temporary file, but the URL is the URL of the file which has been - just recovered. The next store operation would operate on the URL, not the location. - */ - void switchToURL( - const ::rtl::OUString& _rDocumentLocation, - const ::rtl::OUString& _rDocumentURL - ); - /** returns the macro mode imposed by an external instance, which passed it to attachResource */ sal_Int16 getImposedMacroExecMode() const @@ -536,6 +518,14 @@ private: void impl_construct_nothrow(); ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > impl_switchToStorage_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage ); + + /** switches to the given document URL, which denotes the logical URL of the document, not necessariy the + URL where the doc was loaded/recovered from + */ + void impl_switchToLogicalURL( + const ::rtl::OUString& i_rDocumentURL + ); + }; /** a small base class for UNO components whose functionality depends on a ODatabaseModelImpl diff --git a/dbaccess/source/core/dataaccess/connection.cxx b/dbaccess/source/core/dataaccess/connection.cxx index 5e0aff026..00df5b9c2 100644 --- a/dbaccess/source/core/dataaccess/connection.cxx +++ b/dbaccess/source/core/dataaccess/connection.cxx @@ -39,6 +39,7 @@ #include "ContainerMediator.hxx" #include "SingleSelectQueryComposer.hxx" #include "querycomposer.hxx" +#include "sdbcoretools.hxx" /** === begin UNO includes === **/ #include <com/sun/star/sdb/CommandType.hpp> @@ -74,6 +75,10 @@ using namespace ::comphelper; using namespace ::cppu; using namespace ::dbtools; +using ::com::sun::star::sdb::tools::XTableName; +using ::com::sun::star::sdb::tools::XObjectNames; +using ::com::sun::star::sdb::tools::XDataSourceMetaData; + //........................................................................ namespace dbaccess { @@ -614,7 +619,7 @@ void OConnection::refresh(const Reference< XNameAccess >& _rToBeRefreshed) RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dataaccess", "Ocke.Janssen@sun.com", "OConnection::refresh" ); if ( _rToBeRefreshed == Reference< XNameAccess >(m_pTables) ) { - if (!m_pTables->isInitialized()) + if (m_pTables && !m_pTables->isInitialized()) { impl_fillTableFilter(); // check if our "master connection" can supply tables @@ -632,7 +637,7 @@ void OConnection::refresh(const Reference< XNameAccess >& _rToBeRefreshed) } else if ( _rToBeRefreshed == Reference< XNameAccess >(m_pViews) ) { - if (!m_pViews->isInitialized()) + if (m_pViews && !m_pViews->isInitialized()) { impl_fillTableFilter(); // check if our "master connection" can supply tables @@ -726,6 +731,21 @@ Reference< XInterface > SAL_CALL OConnection::createInstance( const ::rtl::OUStr xRet = new OSingleSelectQueryComposer( getTables(),this, m_aContext ); m_aComposers.push_back(WeakReferenceHelper(xRet)); } + else + { + if ( _sServiceSpecifier.getLength() ) + { + TSupportServices::iterator aFind = m_aSupportServices.find(_sServiceSpecifier); + if ( aFind == m_aSupportServices.end() ) + { + Sequence<Any> aArgs(1); + Reference<XConnection> xMy(this); + aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection")),makeAny(xMy)); + aFind = m_aSupportServices.insert(TSupportServices::value_type(_sServiceSpecifier,m_aContext.createComponentWithArguments(_sServiceSpecifier,aArgs))).first; + } + return aFind->second; + } + } return Reference< XInterface >(xRet,UNO_QUERY); } // ----------------------------------------------------------------------------- @@ -795,7 +815,7 @@ void OConnection::impl_loadConnectionTools_throw() } // ----------------------------------------------------------------------------- -Reference< tools::XTableName > SAL_CALL OConnection::createTableName( ) throw (RuntimeException) +Reference< XTableName > SAL_CALL OConnection::createTableName( ) throw (RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dataaccess", "Ocke.Janssen@sun.com", "OConnection::createTableName" ); MutexGuard aGuard(m_aMutex); @@ -806,7 +826,7 @@ Reference< tools::XTableName > SAL_CALL OConnection::createTableName( ) throw ( } // ----------------------------------------------------------------------------- -Reference< tools::XObjectNames > SAL_CALL OConnection::getObjectNames( ) throw (RuntimeException) +Reference< XObjectNames > SAL_CALL OConnection::getObjectNames( ) throw (RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dataaccess", "Ocke.Janssen@sun.com", "OConnection::getObjectNames" ); MutexGuard aGuard(m_aMutex); @@ -817,7 +837,7 @@ Reference< tools::XObjectNames > SAL_CALL OConnection::getObjectNames( ) throw } // ----------------------------------------------------------------------------- -Reference< tools::XDataSourceMetaData > SAL_CALL OConnection::getDataSourceMetaData( ) throw (RuntimeException) +Reference< XDataSourceMetaData > SAL_CALL OConnection::getDataSourceMetaData( ) throw (RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dataaccess", "Ocke.Janssen@sun.com", "OConnection::getDataSourceMetaData" ); MutexGuard aGuard(m_aMutex); diff --git a/dbaccess/source/core/dataaccess/connection.hxx b/dbaccess/source/core/dataaccess/connection.hxx index cd6497826..321c4ae63 100644 --- a/dbaccess/source/core/dataaccess/connection.hxx +++ b/dbaccess/source/core/dataaccess/connection.hxx @@ -27,62 +27,25 @@ #ifndef _DBA_CORE_CONNECTION_HXX_ #define _DBA_CORE_CONNECTION_HXX_ -#ifndef _DBASHARED_APITOOLS_HXX_ #include "apitools.hxx" -#endif -#ifndef _DBA_CORE_QUERYCONTAINER_HXX_ #include "querycontainer.hxx" -#endif -#ifndef _DBA_CORE_TABLECONTAINER_HXX_ #include "tablecontainer.hxx" -#endif -#ifndef _DBA_CORE_VIEWCONTAINER_HXX_ #include "viewcontainer.hxx" -#endif -#ifndef DBA_CORE_REFRESHLISTENER_HXX #include "RefreshListener.hxx" -#endif -#ifndef DBTOOLS_WARNINGSCONTAINER_HXX -#include <connectivity/warningscontainer.hxx> -#endif /** === begin UNO includes === **/ -#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_ #include <com/sun/star/container/XChild.hpp> -#endif -#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ #include <com/sun/star/lang/DisposedException.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSERFACTORY_HPP_ #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XCOMMANDPREPARATION_HPP_ #include <com/sun/star/sdb/XCommandPreparation.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_ #include <com/sun/star/sdbcx/XTablesSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_ #include <com/sun/star/sdbcx/XViewsSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XUSERSSUPPLIER_HPP_ #include <com/sun/star/sdbcx/XUsersSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XGROUPSSUPPLIER_HPP_ #include <com/sun/star/sdbcx/XGroupsSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XQUERIESSUPPLIER_HPP_ #include <com/sun/star/sdb/XQueriesSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ #include <com/sun/star/lang/XMultiServiceFactory.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_TOOLS_XCONNECTIONTOOLS_HPP_ #include <com/sun/star/sdb/tools/XConnectionTools.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_APPLICATION_XTABLEUIPROVIDER_HPP_ #include <com/sun/star/sdb/application/XTableUIProvider.hpp> -#endif /** === end UNO includes === **/ #if ! defined(INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_14) @@ -90,14 +53,10 @@ #define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 14 #include <comphelper/implbase_var.hxx> #endif - -#ifndef COMPHELPER_COMPONENTCONTEXT_HXX #include <comphelper/componentcontext.hxx> -#endif - -#ifndef _CONNECTIVITY_CONNECTIONWRAPPER_HXX_ +#include <comphelper/stl_types.hxx> #include <connectivity/ConnectionWrapper.hxx> -#endif +#include <connectivity/warningscontainer.hxx> //........................................................................ namespace dbaccess @@ -148,6 +107,11 @@ protected: ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XConnectionTools > m_xConnectionTools; ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XTableUIProvider > m_xTableUIProvider; + // defines the helper services for example to query the command of a view + // @ see com.sun.star.sdb.tools.XViewAccess + DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>, TSupportServices); + TSupportServices m_aSupportServices; + OTableContainer* m_pTables; OViewContainer* m_pViews; diff --git a/dbaccess/source/core/dataaccess/databasecontext.cxx b/dbaccess/source/core/dataaccess/databasecontext.cxx index 1c39d6be7..39a6ef73b 100644 --- a/dbaccess/source/core/dataaccess/databasecontext.cxx +++ b/dbaccess/source/core/dataaccess/databasecontext.cxx @@ -385,7 +385,7 @@ Reference< XInterface > ODatabaseContext::loadObjectFromURL(const ::rtl::OUStrin ::comphelper::NamedValueCollection aArgs; aArgs.put( "URL", _sURL ); aArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG ); - aArgs.put( "InteractionHandler", m_aContext.createComponent( "com.sun.star.sdb.InteractionHandler" ) ); + aArgs.put( "InteractionHandler", m_aContext.createComponent( "com.sun.star.task.InteractionHandler" ) ); Sequence< PropertyValue > aResource( aArgs.getPropertyValues() ); xLoad->load( aResource ); diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 11d17a717..d748154d8 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -38,6 +38,7 @@ #include "databasecontext.hxx" #include "documentcontainer.hxx" #include "sdbcoretools.hxx" +#include "recovery/dbdocrecovery.hxx" /** === begin UNO includes === **/ #include <com/sun/star/beans/Optional.hpp> @@ -60,6 +61,8 @@ #include <com/sun/star/ui/XUIConfigurationStorage.hpp> #include <com/sun/star/view/XSelectionSupplier.hpp> #include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/ucb/XContent.hpp> +#include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp> /** === end UNO includes === **/ #include <comphelper/documentconstants.hxx> @@ -71,6 +74,11 @@ #include <comphelper/numberedcollection.hxx> #include <comphelper/property.hxx> #include <comphelper/storagehelper.hxx> +#include <comphelper/genericpropertyset.hxx> +#include <comphelper/property.hxx> + +#include <connectivity/dbtools.hxx> + #include <cppuhelper/exc_hlp.hxx> #include <framework/titlehelper.hxx> #include <unotools/saveopt.hxx> @@ -110,6 +118,8 @@ using namespace ::cppu; using namespace ::osl; using ::com::sun::star::awt::XWindow; +using ::com::sun::star::ucb::XContent; +using ::com::sun::star::sdb::application::XDatabaseDocumentUI; //........................................................................ namespace dbaccess @@ -132,7 +142,7 @@ bool ViewMonitor::onControllerConnected( const Reference< XController >& _rxCont } //-------------------------------------------------------------------------- -void ViewMonitor::onSetCurrentController( const Reference< XController >& _rxController ) +bool ViewMonitor::onSetCurrentController( const Reference< XController >& _rxController ) { // we interpret this as "loading the document (including UI) is finished", // if and only if this is the controller which was last connected, and it was the @@ -142,6 +152,8 @@ void ViewMonitor::onSetCurrentController( const Reference< XController >& _rxCon // notify the respective events if ( bLoadFinished ) m_rEventNotifier.notifyDocumentEventAsync( m_bIsNewDocument ? "OnNew" : "OnLoad" ); + + return bLoadFinished; } //============================================================ @@ -168,6 +180,7 @@ ODatabaseDocument::ODatabaseDocument(const ::rtl::Reference<ODatabaseModelImpl>& ,m_eInitState( NotInitialized ) ,m_bClosing( false ) ,m_bAllowDocumentScripting( false ) + ,m_bHasBeenRecovered( false ) { DBG_CTOR(ODatabaseDocument,NULL); OSL_TRACE( "DD: ctor: %p: %p", this, m_pImpl.get() ); @@ -372,15 +385,15 @@ namespace } // ----------------------------------------------------------------------------- - static Sequence< PropertyValue > lcl_appendFileNameToDescriptor( const Sequence< PropertyValue >& _rDescriptor, const ::rtl::OUString _rURL ) + static Sequence< PropertyValue > lcl_appendFileNameToDescriptor( const ::comphelper::NamedValueCollection& _rDescriptor, const ::rtl::OUString _rURL ) { - ::comphelper::NamedValueCollection aMediaDescriptor( _rDescriptor ); + ::comphelper::NamedValueCollection aMutableDescriptor( _rDescriptor ); if ( _rURL.getLength() ) { - aMediaDescriptor.put( "FileName", _rURL ); - aMediaDescriptor.put( "URL", _rURL ); + aMutableDescriptor.put( "FileName", _rURL ); + aMutableDescriptor.put( "URL", _rURL ); } - return aMediaDescriptor.getPropertyValues(); + return aMutableDescriptor.getPropertyValues(); } } @@ -422,9 +435,9 @@ void ODatabaseDocument::impl_reset_nothrow() void ODatabaseDocument::impl_import_nolck_throw( const ::comphelper::ComponentContext _rContext, const Reference< XInterface >& _rxTargetComponent, const ::comphelper::NamedValueCollection& _rResource ) { - Sequence< Any > aFilterArgs; + Sequence< Any > aFilterCreationArgs; Reference< XStatusIndicator > xStatusIndicator; - lcl_extractAndStartStatusIndicator( _rResource, xStatusIndicator, aFilterArgs ); + lcl_extractAndStartStatusIndicator( _rResource, xStatusIndicator, aFilterCreationArgs ); /** property map for import info set */ comphelper::PropertyMapEntry aExportInfoMap[] = @@ -437,19 +450,20 @@ void ODatabaseDocument::impl_import_nolck_throw( const ::comphelper::ComponentCo xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")), uno::makeAny(_rResource.getOrDefault("URL",::rtl::OUString()))); xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("content.xml")))); - const sal_Int32 nCount = aFilterArgs.getLength(); - aFilterArgs.realloc(nCount + 1); - aFilterArgs[nCount] <<= xInfoSet; + const sal_Int32 nCount = aFilterCreationArgs.getLength(); + aFilterCreationArgs.realloc(nCount + 1); + aFilterCreationArgs[nCount] <<= xInfoSet; Reference< XImporter > xImporter( - _rContext.createComponentWithArguments( "com.sun.star.comp.sdb.DBFilter", aFilterArgs ), + _rContext.createComponentWithArguments( "com.sun.star.comp.sdb.DBFilter", aFilterCreationArgs ), UNO_QUERY_THROW ); Reference< XComponent > xComponent( _rxTargetComponent, UNO_QUERY_THROW ); xImporter->setTargetDocument( xComponent ); Reference< XFilter > xFilter( xImporter, UNO_QUERY_THROW ); - xFilter->filter( ODatabaseModelImpl::stripLoadArguments( _rResource ) ); + Sequence< PropertyValue > aFilterArgs( ODatabaseModelImpl::stripLoadArguments( _rResource ).getPropertyValues() ); + xFilter->filter( aFilterArgs ); if ( xStatusIndicator.is() ) xStatusIndicator->end(); @@ -537,14 +551,176 @@ void SAL_CALL ODatabaseDocument::load( const Sequence< PropertyValue >& _Argumen } // ----------------------------------------------------------------------------- +namespace +{ + // ......................................................................... + bool lcl_hasAnyModifiedSubComponent_throw( const Reference< XController >& i_rController ) + { + Reference< XDatabaseDocumentUI > xDatabaseUI( i_rController, UNO_QUERY_THROW ); + + Sequence< Reference< XComponent > > aComponents( xDatabaseUI->getSubComponents() ); + const Reference< XComponent >* component = aComponents.getConstArray(); + const Reference< XComponent >* componentsEnd = aComponents.getConstArray() + aComponents.getLength(); + + bool isAnyModified = false; + for ( ; component != componentsEnd; ++component ) + { + Reference< XModifiable > xModify( *component, UNO_QUERY ); + if ( xModify.is() ) + { + isAnyModified = xModify->isModified(); + continue; + } + + // TODO: clarify: anything else to care for? Both the sub componbents with and without model + // should support the XModifiable interface, so I think nothing more is needed here. + OSL_ENSURE( false, "lcl_hasAnyModifiedSubComponent_throw: anything left to do here?" ); + } + + return isAnyModified; + } +} + +// ----------------------------------------------------------------------------- +::sal_Bool SAL_CALL ODatabaseDocument::wasModifiedSinceLastSave() throw ( RuntimeException ) +{ + DocumentGuard aGuard( *this ); + + // The implementation here is somewhat sloppy, in that it returns whether *any* part of the whole + // database document, including opened sub components, is modified. This is more than what is requested: + // We need to return <TRUE/> if the doc itself, or any of the opened sub components, has been modified + // since the last call to any of the save* methods, or since the document has been loaded/created. + // However, the API definition explicitly allows to be that sloppy ... + + if ( isModified() ) + return sal_True; + + // auto recovery is an "UI feature", it is to restore the UI the user knows. Thus, + // we ask our connected controllers, not simply our existing form/report definitions. + // (There is some information which even cannot be obtained without asking the controller. + // For instance, newly created, but not yet saved, forms/reports are acessible via the + // controller only, but not via the model.) + + try + { + for ( Controllers::const_iterator ctrl = m_aControllers.begin(); + ctrl != m_aControllers.end(); + ++ctrl + ) + { + if ( lcl_hasAnyModifiedSubComponent_throw( *ctrl ) ) + return sal_True; + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + return sal_False; +} + +// ----------------------------------------------------------------------------- +void SAL_CALL ODatabaseDocument::storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) +{ + DocumentGuard aGuard( *this ); + ModifyLock aLock( *this ); + + try + { + // create a storage for the target location + Reference< XStorage > xTargetStorage( impl_createStorageFor_throw( i_TargetLocation ) ); + + // first store the document as a whole into this storage + impl_storeToStorage_throw( xTargetStorage, i_MediaDescriptor, aGuard ); + + // save the sub components which need saving + DatabaseDocumentRecovery aDocRecovery( m_pImpl->m_aContext); + aDocRecovery.saveModifiedSubComponents( xTargetStorage, m_aControllers ); + + // commit the root storage + tools::stor::commitStorageIfWriteable( xTargetStorage ); + } + catch( const Exception& ) + { + Any aError = ::cppu::getCaughtException(); + if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) + || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() ) + || aError.isExtractableTo( ::cppu::UnoType< WrappedTargetException >::get() ) + ) + { + // allowed to leave + throw; + } + + throw WrappedTargetException( ::rtl::OUString(), *this, aError ); + } +} + +// ----------------------------------------------------------------------------- +void SAL_CALL ODatabaseDocument::recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) +{ + DocumentGuard aGuard( *this, DocumentGuard::InitMethod ); + + if ( i_SourceLocation.getLength() == 0 ) + throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); + + try + { + // load the document itself, by simply delegating to our "load" method + + // our load implementation expects the SalvagedFile and URL to be in the media descriptor + ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor ); + aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile ); + aMediaDescriptor.put( "URL", i_SourceLocation ); + + aGuard.clear(); // (load has an own guarding scheme) + load( aMediaDescriptor.getPropertyValues() ); + + // Without a controller, we are unable to recover the sub components, as they're always tied to a controller. + // So, everything else is done when the first controller is connected. + m_bHasBeenRecovered = true; + + // tell the impl that we've been loaded from the given location + m_pImpl->setDocFileLocation( i_SourceLocation ); + + // by definition (of XDocumentRecovery), we're responsible for delivering a fully-initialized document, + // which includes an attachResource call. + const ::rtl::OUString sLogicalDocumentURL( i_SalvagedFile.getLength() ? i_SalvagedFile : i_SourceLocation ); + impl_attachResource( sLogicalDocumentURL, aMediaDescriptor.getPropertyValues(), aGuard ); + // <- SYNCHRONIZED + } + catch( const Exception& ) + { + Any aError = ::cppu::getCaughtException(); + if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) + || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() ) + || aError.isExtractableTo( ::cppu::UnoType< WrappedTargetException >::get() ) + ) + { + // allowed to leave + throw; + } + + throw WrappedTargetException( ::rtl::OUString(), *this, aError ); + } +} + +// ----------------------------------------------------------------------------- // XModel sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException) { DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit ); + return impl_attachResource( _rURL, _rArguments, aGuard ); +} - if ( ( _rURL == getURL() ) - && ( _rArguments.getLength() == 1 ) - && ( _rArguments[0].Name.compareToAscii( "BreakMacroSignature" ) == 0 ) +// ----------------------------------------------------------------------------- +sal_Bool ODatabaseDocument::impl_attachResource( const ::rtl::OUString& i_rLogicalDocumentURL, + const Sequence< PropertyValue >& i_rMediaDescriptor, DocumentGuard& _rDocGuard ) +{ + if ( ( i_rLogicalDocumentURL == getURL() ) + && ( i_rMediaDescriptor.getLength() == 1 ) + && ( i_rMediaDescriptor[0].Name.compareToAscii( "BreakMacroSignature" ) == 0 ) ) { // this is a BAD hack of the Basic importer code ... there should be a dedicated API for this, @@ -553,7 +729,14 @@ sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rUR // (we do not support macro signatures, so we can ignore this call) } - m_pImpl->attachResource( _rURL, _rArguments ); + // if no URL has been provided, the caller was lazy enough to not call our getURL - which is not allowed anymore, + // now since getURL and getLocation both return the same, so calling one of those should be simple. + ::rtl::OUString sDocumentURL( i_rLogicalDocumentURL ); + OSL_ENSURE( sDocumentURL.getLength(), "ODatabaseDocument::impl_attachResource: invalid URL!" ); + if ( !sDocumentURL.getLength() ) + sDocumentURL = getURL(); + + m_pImpl->setResource( sDocumentURL, i_rMediaDescriptor ); if ( impl_isInitializing() ) { // this means we've just been loaded, and this is the attachResource call which follows @@ -565,7 +748,7 @@ sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rUR // should know this before anybody actually uses the object. m_bAllowDocumentScripting = ( m_pImpl->determineEmbeddedMacros() != ODatabaseModelImpl::eSubDocumentMacros ); - aGuard.clear(); + _rDocGuard.clear(); // <- SYNCHRONIZED m_aEventNotifier.notifyDocumentEvent( "OnLoadFinished" ); } @@ -584,7 +767,7 @@ sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rUR Sequence< PropertyValue > SAL_CALL ODatabaseDocument::getArgs( ) throw (RuntimeException) { DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); - return m_pImpl->getResource(); + return m_pImpl->getMediaDescriptor().getPropertyValues(); } // ----------------------------------------------------------------------------- @@ -592,6 +775,16 @@ void SAL_CALL ODatabaseDocument::connectController( const Reference< XController { DocumentGuard aGuard( *this ); +#if OSL_DEBUG_LEVEL > 0 + for ( Controllers::const_iterator controller = m_aControllers.begin(); + controller != m_aControllers.end(); + ++controller + ) + { + OSL_ENSURE( *controller != _xController, "ODatabaseDocument::connectController: this controller is already connected!" ); + } +#endif + m_aControllers.push_back( _xController ); m_aEventNotifier.notifyDocumentEventAsync( "OnViewCreated", Reference< XController2 >( _xController, UNO_QUERY ) ); @@ -688,8 +881,29 @@ void SAL_CALL ODatabaseDocument::setCurrentController( const Reference< XControl m_xCurrentController = _xController; - m_aViewMonitor.onSetCurrentController( _xController ); + if ( !m_aViewMonitor.onSetCurrentController( _xController ) ) + return; + + // check if there are sub components to recover from our document storage + bool bAttemptRecovery = m_bHasBeenRecovered; + if ( !bAttemptRecovery && m_pImpl->getMediaDescriptor().has( "ForceRecovery" ) ) + // do not use getOrDefault, it will throw for invalid types, which is not desired here + m_pImpl->getMediaDescriptor().get( "ForceRecovery" ) >>= bAttemptRecovery; + + if ( !bAttemptRecovery ) + return; + + try + { + DatabaseDocumentRecovery aDocRecovery( m_pImpl->m_aContext ); + aDocRecovery.recoverSubDocuments( m_pImpl->getRootStorage(), _xController ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } + // ----------------------------------------------------------------------------- Reference< XInterface > SAL_CALL ODatabaseDocument::getCurrentSelection( ) throw (RuntimeException) { @@ -714,6 +928,8 @@ sal_Bool SAL_CALL ODatabaseDocument::hasLocation( ) throw (RuntimeException) { DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit ); return m_pImpl->getURL(); + // both XStorable::getLocation and XModel::getURL have to return the URL of the document, *not* + // the location of the file which the docunment was possibly recovered from (which would be getDocFileLocation) } // ----------------------------------------------------------------------------- sal_Bool SAL_CALL ODatabaseDocument::isReadonly( ) throw (RuntimeException) @@ -726,15 +942,53 @@ void SAL_CALL ODatabaseDocument::store( ) throw (IOException, RuntimeException) { DocumentGuard aGuard( *this ); - if ( m_pImpl->getDocFileLocation() == m_pImpl->getURL() ) - if ( m_pImpl->m_bDocumentReadOnly ) - throw IOException(); + ::rtl::OUString sDocumentURL( m_pImpl->getURL() ); + if ( sDocumentURL.getLength() ) + { + if ( m_pImpl->getDocFileLocation() == m_pImpl->getURL() ) + if ( m_pImpl->m_bDocumentReadOnly ) + throw IOException(); + + impl_storeAs_throw( m_pImpl->getURL(), m_pImpl->getMediaDescriptor(), SAVE, aGuard ); + return; + } + + // if we have no URL, but did survive the DocumentGuard above, then we've been inited via XLoadable::initNew, + // i.e. we're based on a temporary storage + OSL_ENSURE( m_pImpl->getDocFileLocation().getLength() == 0, "ODatabaseDocument::store: unexpected URL inconsistency!" ); - impl_storeAs_throw( m_pImpl->getURL(), m_pImpl->getResource(), SAVE, aGuard ); + try + { + impl_storeToStorage_throw( m_pImpl->getRootStorage(), m_pImpl->getMediaDescriptor().getPropertyValues(), aGuard ); + } + catch( const Exception& ) + { + Any aError = ::cppu::getCaughtException(); + if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) + || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() ) + ) + { + // allowed to leave + throw; + } + impl_throwIOExceptionCausedBySave_throw( aError, ::rtl::OUString() ); + } } // ----------------------------------------------------------------------------- -void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const Sequence< PropertyValue>& _rArguments, +void ODatabaseDocument::impl_throwIOExceptionCausedBySave_throw( const Any& i_rError, const ::rtl::OUString& i_rTargetURL ) const +{ + ::rtl::OUString sErrorMessage = extractExceptionMessage( m_pImpl->m_aContext, i_rError ); + sErrorMessage = ResourceManager::loadString( + RID_STR_ERROR_WHILE_SAVING, + "$location$", i_rTargetURL, + "$message$", sErrorMessage + ); + throw IOException( sErrorMessage, *const_cast< ODatabaseDocument* >( this ) ); +} + +// ----------------------------------------------------------------------------- +void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const ::comphelper::NamedValueCollection& _rArguments, const StoreType _eType, DocumentGuard& _rGuard ) throw ( IOException, RuntimeException ) { OSL_PRECOND( ( _eType == SAVE ) || ( _eType == SAVE_AS ), @@ -780,6 +1034,12 @@ void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const m_pImpl->disposeStorages(); + // each and every document definition obtained via m_xForms and m_xReports depends + // on the sub storages which we just disposed. So, dispose the forms/reports collections, too. + // This ensures that they're re-created when needed. + clearObjectContainer( m_xForms ); + clearObjectContainer( m_xReports ); + xNewRootStorage = m_pImpl->switchToStorage( xTargetStorage ); m_pImpl->m_bDocumentReadOnly = sal_False; @@ -791,7 +1051,8 @@ void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const impl_storeToStorage_throw( xCurrentStorage, aMediaDescriptor, _rGuard ); // success - tell our impl - m_pImpl->attachResource( _rURL, aMediaDescriptor ); + m_pImpl->setDocFileLocation( _rURL ); + m_pImpl->setResource( _rURL, aMediaDescriptor ); // if we are in an initialization process, then this is finished, now that we stored the document if ( bIsInitializationProcess ) @@ -813,13 +1074,7 @@ void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const throw; } - ::rtl::OUString sErrorMessage = extractExceptionMessage( m_pImpl->m_aContext, aError ); - sErrorMessage = ResourceManager::loadString( - RID_STR_ERROR_WHILE_SAVING, - "$location$", _rURL, - "$message$", sErrorMessage - ); - throw IOException( sErrorMessage, *this ); + impl_throwIOExceptionCausedBySave_throw( aError, _rURL ); } // notify the document event @@ -934,7 +1189,7 @@ void ODatabaseDocument::impl_storeToStorage_throw( const Reference< XStorage >& lcl_triggerStatusIndicator_throw( aWriteArgs, _rDocGuard, false ); // commit target storage - OSL_VERIFY( ODatabaseModelImpl::commitStorageIfWriteable( _rxTargetStorage ) ); + OSL_VERIFY( tools::stor::commitStorageIfWriteable( _rxTargetStorage ) ); } catch( const IOException& ) { throw; } catch( const RuntimeException& ) { throw; } @@ -980,16 +1235,7 @@ void SAL_CALL ODatabaseDocument::storeToURL( const ::rtl::OUString& _rURL, const throw; } - Exception aExcept; - aError >>= aExcept; - - ::rtl::OUString sErrorMessage = extractExceptionMessage( m_pImpl->m_aContext, aError ); - sErrorMessage = ResourceManager::loadString( - RID_STR_ERROR_WHILE_SAVING, - "$location$", _rURL, - "$message$", sErrorMessage - ); - throw IOException( sErrorMessage, *this ); + impl_throwIOExceptionCausedBySave_throw( aError, _rURL ); } m_aEventNotifier.notifyDocumentEventAsync( "OnSaveToDone", NULL, makeAny( _rURL ) ); @@ -1145,8 +1391,25 @@ Reference< XNameAccess > ODatabaseDocument::impl_getDocumentContainer_throw( ODa Reference< XNameAccess > xContainer = rContainerRef; if ( !xContainer.is() ) { - TContentPtr& rContainerData( m_pImpl->getObjectContainer( _eType ) ); - rContainerRef = xContainer = new ODocumentContainer( m_pImpl->m_aContext.getLegacyServiceFactory(), *this, rContainerData, bFormsContainer ); + Any aValue; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xMy(*this); + if ( dbtools::getDataSourceSetting(xMy,bFormsContainer ? "Forms" : "Reports",aValue) ) + { + ::rtl::OUString sSupportService; + aValue >>= sSupportService; + if ( sSupportService.getLength() ) + { + Sequence<Any> aArgs(1); + aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DatabaseDocument")),makeAny(xMy)); + xContainer.set(m_pImpl->m_aContext.createComponentWithArguments(sSupportService,aArgs),UNO_QUERY); + rContainerRef = xContainer; + } + } + if ( !xContainer.is() ) + { + TContentPtr& rContainerData( m_pImpl->getObjectContainer( _eType ) ); + rContainerRef = xContainer = new ODocumentContainer( m_pImpl->m_aContext.getLegacyServiceFactory(), *this, rContainerData, bFormsContainer ); + } impl_reparent_nothrow( xContainer ); } return xContainer; diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx index 517bbedea..a299d984e 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/core/dataaccess/databasedocument.hxx @@ -57,11 +57,12 @@ #include <com/sun/star/frame/XLoadable.hpp> #include <com/sun/star/document/XEventBroadcaster.hpp> #include <com/sun/star/document/XDocumentEventBroadcaster.hpp> +#include <com/sun/star/document/XDocumentRecovery.hpp> /** === end UNO includes === **/ -#if ! defined(INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_16) -#define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_16 -#define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 16 +#if ! defined(INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_17) +#define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_17 +#define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 17 #include <comphelper/implbase_var.hxx> #endif @@ -121,8 +122,12 @@ public: ); /** to be called when a controller is set as current controller + @return <TRUE/> + if and only if the controller connection indicates that loading the document is finished. This + is the case if the given controller has previously been connected, and it was the first controller + ever for which this happened. */ - void onSetCurrentController( + bool onSetCurrentController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController ); @@ -140,7 +145,7 @@ private: //============================================================ //= ODatabaseDocument //============================================================ -typedef ::comphelper::WeakComponentImplHelper16 < ::com::sun::star::frame::XModel2 +typedef ::comphelper::WeakComponentImplHelper17 < ::com::sun::star::frame::XModel2 , ::com::sun::star::util::XModifiable , ::com::sun::star::frame::XStorable , ::com::sun::star::document::XEventBroadcaster @@ -156,6 +161,7 @@ typedef ::comphelper::WeakComponentImplHelper16 < ::com::sun::star::frame::XMo , ::com::sun::star::script::provider::XScriptProviderSupplier , ::com::sun::star::document::XEventsSupplier , ::com::sun::star::frame::XLoadable + , ::com::sun::star::document::XDocumentRecovery > ODatabaseDocument_OfficeDocument; typedef ::cppu::ImplHelper3< ::com::sun::star::frame::XTitle @@ -204,6 +210,7 @@ class ODatabaseDocument :public ModelDependentComponent // ModelDepe InitState m_eInitState; bool m_bClosing; bool m_bAllowDocumentScripting; + bool m_bHasBeenRecovered; enum StoreType { SAVE, SAVE_AS }; /** stores the document to the given URL, rebases it to the respective new storage, if necessary, resets @@ -221,7 +228,7 @@ class ODatabaseDocument :public ModelDependentComponent // ModelDepe */ void impl_storeAs_throw( const ::rtl::OUString& _rURL, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rArguments, + const ::comphelper::NamedValueCollection& _rArguments, const StoreType _eType, DocumentGuard& _rGuard ) @@ -422,6 +429,11 @@ public: virtual void SAL_CALL initNew( ) throw (::com::sun::star::frame::DoubleInitializationException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL load( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) throw (::com::sun::star::frame::DoubleInitializationException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + // css.document.XDocumentRecovery + virtual ::sal_Bool SAL_CALL wasModifiedSinceLastSave() throw ( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); + virtual void SAL_CALL recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); + // XTitle virtual ::rtl::OUString SAL_CALL getTitle( ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setTitle( const ::rtl::OUString& sTitle ) throw (::com::sun::star::uno::RuntimeException); @@ -598,6 +610,31 @@ private: const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, DocumentGuard& _rDocGuard ) const; + + + /** impl-version of attachResource + + @param i_rLogicalDocumentURL + denotes the logical URL of the document, to be reported by getURL/getLocation + @param i_rMediaDescriptor + denotes additional document parameters + @param _rDocGuard + is the guard which currently protects the document instance + + */ + sal_Bool impl_attachResource( + const ::rtl::OUString& i_rLogicalDocumentURL, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rMediaDescriptor, + DocumentGuard& _rDocGuard + ); + + /** throws an IOException with the message as defined in the RID_STR_ERROR_WHILE_SAVING resource, wrapping + the given caught non-IOException error + */ + void impl_throwIOExceptionCausedBySave_throw( + const ::com::sun::star::uno::Any& i_rError, + const ::rtl::OUString& i_rTargetURL + ) const; }; /** an extended version of the ModelMethodGuard, which also cares for the initialization state diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx index 213ac8afe..e3f75ef69 100644 --- a/dbaccess/source/core/dataaccess/datasource.cxx +++ b/dbaccess/source/core/dataaccess/datasource.cxx @@ -39,6 +39,7 @@ #include "SharedConnection.hxx" #include "databasedocument.hxx" + /** === begin UNO includes === **/ #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> @@ -67,6 +68,7 @@ #include <comphelper/sequence.hxx> #include <comphelper/string.hxx> #include <connectivity/dbexception.hxx> +#include <connectivity/dbtools.hxx> #include <cppuhelper/typeprovider.hxx> #include <tools/debug.hxx> #include <tools/diagnose_ex.h> @@ -1337,8 +1339,24 @@ Reference< XNameAccess > SAL_CALL ODatabaseSource::getQueryDefinitions( ) throw( Reference< XNameAccess > xContainer = m_pImpl->m_xCommandDefinitions; if ( !xContainer.is() ) { - TContentPtr& rContainerData( m_pImpl->getObjectContainer( ODatabaseModelImpl::E_QUERY ) ); - xContainer = new OCommandContainer( m_pImpl->m_aContext.getLegacyServiceFactory(), *this, rContainerData, sal_False ); + Any aValue; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xMy(*this); + if ( dbtools::getDataSourceSetting(xMy,"CommandDefinitions",aValue) ) + { + ::rtl::OUString sSupportService; + aValue >>= sSupportService; + if ( sSupportService.getLength() ) + { + Sequence<Any> aArgs(1); + aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataSource")),makeAny(xMy)); + xContainer.set(m_pImpl->m_aContext.createComponentWithArguments(sSupportService,aArgs),UNO_QUERY); + } + } + if ( !xContainer.is() ) + { + TContentPtr& rContainerData( m_pImpl->getObjectContainer( ODatabaseModelImpl::E_QUERY ) ); + xContainer = new OCommandContainer( m_pImpl->m_aContext.getLegacyServiceFactory(), *this, rContainerData, sal_False ); + } m_pImpl->m_xCommandDefinitions = xContainer; } return xContainer; diff --git a/dbaccess/source/core/dataaccess/documentcontainer.cxx b/dbaccess/source/core/dataaccess/documentcontainer.cxx index ba0b20705..5d20a2885 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.cxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.cxx @@ -82,6 +82,7 @@ #endif #include "core_resource.hxx" #include "core_resource.hrc" +#include <comphelper/namedvaluecollection.hxx> #include <vcl/svapp.hxx> #include <vos/mutex.hxx> @@ -202,6 +203,20 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstance( const ::rtl { return createInstanceWithArguments( aServiceSpecifier, Sequence< Any >() ); } + +namespace +{ + template< class TYPE > + void lcl_extractAndRemove( ::comphelper::NamedValueCollection& io_rArguments, const ::rtl::OUString& i_rName, TYPE& o_rValue ) + { + if ( io_rArguments.has( i_rName ) ) + { + io_rArguments.get_ensureType( i_rName, o_rValue ); + io_rArguments.remove( i_rName ); + } + } +} + // ----------------------------------------------------------------------------- Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& _aArguments ) throw (Exception, RuntimeException) { @@ -211,36 +226,47 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments { MutexGuard aGuard(m_aMutex); - ::rtl::OUString sName, sPersistentName, sURL, sMediaType; + // extrat known arguments + ::rtl::OUString sName, sPersistentName, sURL, sMediaType, sDocServiceName; Reference< XCommandProcessor > xCopyFrom; Reference< XConnection > xConnection; + sal_Bool bAsTemplate( sal_False ); Sequence< sal_Int8 > aClassID; - sal_Bool bAsTemplate = sal_False; ::comphelper::NamedValueCollection aArgs( _aArguments ); - sName = aArgs.getOrDefault( (::rtl::OUString)PROPERTY_NAME, sName ); - sPersistentName = aArgs.getOrDefault( (::rtl::OUString)PROPERTY_PERSISTENT_NAME, sPersistentName ); - xCopyFrom = aArgs.getOrDefault( (::rtl::OUString)PROPERTY_EMBEDDEDOBJECT, xCopyFrom ); - sURL = aArgs.getOrDefault( (::rtl::OUString)PROPERTY_URL, sURL ); - xConnection = aArgs.getOrDefault( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, xConnection ); - bAsTemplate = aArgs.getOrDefault( (::rtl::OUString)PROPERTY_AS_TEMPLATE, bAsTemplate ); - sMediaType = aArgs.getOrDefault( (::rtl::OUString)INFO_MEDIATYPE, sMediaType ); - - if ( aArgs.has( "ClassID" ) ) + lcl_extractAndRemove( aArgs, PROPERTY_NAME, sName ); + lcl_extractAndRemove( aArgs, PROPERTY_PERSISTENT_NAME, sPersistentName ); + lcl_extractAndRemove( aArgs, PROPERTY_URL, sURL ); + lcl_extractAndRemove( aArgs, PROPERTY_EMBEDDEDOBJECT, xCopyFrom ); + lcl_extractAndRemove( aArgs, PROPERTY_ACTIVE_CONNECTION, xConnection ); + lcl_extractAndRemove( aArgs, PROPERTY_AS_TEMPLATE, bAsTemplate ); + lcl_extractAndRemove( aArgs, INFO_MEDIATYPE, sMediaType ); + lcl_extractAndRemove( aArgs, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentServiceName" ) ), sDocServiceName ); + + // ClassID has two allowed types, so a special treatment here + Any aClassIDArg = aArgs.get( "ClassID" ); + if ( aClassIDArg.hasValue() ) { - Any aClassIDValue = aArgs.get( "ClassID" ); - // class IDs might be passed as byte sequence ... - if ( !( aClassIDValue >>= aClassID ) ) + if ( !( aClassIDArg >>= aClassID ) ) { - // ... or as string - ::rtl::OUString sClassID; - aClassIDValue >>= sClassID; - aClassID = ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( sClassID ); + // Extended for usage also with a string + ::rtl::OUString sClassIDString; + if ( !( aClassIDArg >>= sClassIDString ) ) + throw IllegalArgumentException( ::rtl::OUString(), *this, 2 ); + + aClassID = ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( sClassIDString ); } + +#if OSL_DEBUG_LEVEL > 0 + ::rtl::OUString sClassIDString = ::comphelper::MimeConfigurationHelper::GetStringClassIDRepresentation( aClassID ); + (void)sClassIDString; +#endif + aArgs.remove( "ClassID" ); } + // Everything which now is still present in the arguments is passed to the embedded object + const Sequence< PropertyValue > aCreationArgs( aArgs.getPropertyValues() ); const ODefinitionContainer_Impl& rDefinitions( getDefinitions() ); - sal_Bool bNew = ( 0 == sPersistentName.getLength() ); if ( bNew ) { @@ -273,8 +299,18 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments } else { - if ( bNeedClassID && sMediaType.getLength() ) - ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType, m_aContext, aClassID ); + if ( bNeedClassID ) + { + if ( sMediaType.getLength() ) + ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType, m_aContext, aClassID ); + else if ( sDocServiceName.getLength() ) + { + ::comphelper::MimeConfigurationHelper aConfigHelper( m_aContext.getLegacyServiceFactory() ); + const Sequence< NamedValue > aProps( aConfigHelper.GetObjectPropsByDocumentName( sDocServiceName ) ); + const ::comphelper::NamedValueCollection aMediaTypeProps( aProps ); + aClassID = aMediaTypeProps.getOrDefault( "ClassID", Sequence< sal_Int8 >() ); + } + } } } @@ -292,8 +328,17 @@ Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments } else pElementImpl = aFind->second; - - xContent = new ODocumentDefinition( *this, m_aContext.getLegacyServiceFactory(), pElementImpl, m_bFormsContainer, aClassID, xConnection ); + + ::rtl::Reference< ODocumentDefinition > pDocDef = new ODocumentDefinition( *this, m_aContext.getLegacyServiceFactory(), pElementImpl, m_bFormsContainer ); + if ( aClassID.getLength() ) + { + pDocDef->initialLoad( aClassID, aCreationArgs, xConnection ); + } + else + { + OSL_ENSURE( aCreationArgs.getLength() == 0, "ODocumentContainer::createInstance: additional creation args are lost, if you do not provide a class ID." ); + } + xContent = pDocDef.get(); if ( sURL.getLength() ) { @@ -551,28 +596,15 @@ Reference< XComponent > SAL_CALL ODocumentContainer::loadComponentFromURL( const { Command aCommand; - static const ::rtl::OUString s_sOpenMode = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OpenMode")); - const PropertyValue* pIter = Arguments.getConstArray(); - const PropertyValue* pEnd = pIter + Arguments.getLength(); - for( ; pIter != pEnd ; ++pIter) - { - if ( pIter->Name == s_sOpenMode ) - { - pIter->Value >>= aCommand.Name; - break; - } - } - if ( !aCommand.Name.getLength() ) // default mode - aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("open")); + ::comphelper::NamedValueCollection aArgs( Arguments ); + aCommand.Name = aArgs.getOrDefault( "OpenMode", ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ) ); + aArgs.remove( "OpenMode" ); + OpenCommandArgument2 aOpenCommand; aOpenCommand.Mode = OpenMode::DOCUMENT; + aArgs.put( "OpenCommandArgument", aOpenCommand ); - Sequence< PropertyValue > aArguments(Arguments); - sal_Int32 nLen = aArguments.getLength(); - aArguments.realloc(nLen + 1); - - aArguments[nLen].Value <<= aOpenCommand; - aCommand.Argument <<= aArguments; + aCommand.Argument <<= aArgs.getPropertyValues(); xComp.set(xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >()),UNO_QUERY); } } @@ -664,6 +696,24 @@ void SAL_CALL ODocumentContainer::replaceByHierarchicalName( const ::rtl::OUStri xNameContainer->replaceByName(sName,_aElement); } + +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODocumentContainer::getHierarchicalName() throw (RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + return impl_getHierarchicalName( false ); +} + +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODocumentContainer::composeHierarchicalName( const ::rtl::OUString& i_rRelativeName ) throw (IllegalArgumentException, NoSupportException, RuntimeException) +{ + ::rtl::OUStringBuffer aBuffer; + aBuffer.append( getHierarchicalName() ); + aBuffer.append( sal_Unicode( '/' ) ); + aBuffer.append( i_rRelativeName ); + return aBuffer.makeStringAndClear(); +} + // ----------------------------------------------------------------------------- ::rtl::Reference<OContentHelper> ODocumentContainer::getContent(const ::rtl::OUString& _sName) const { diff --git a/dbaccess/source/core/dataaccess/documentcontainer.hxx b/dbaccess/source/core/dataaccess/documentcontainer.hxx index e747aa368..f401d68b6 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.hxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.hxx @@ -31,8 +31,8 @@ #ifndef _DBA_CORE_DEFINITIONCONTAINER_HXX_ #include "definitioncontainer.hxx" #endif -#ifndef _CPPUHELPER_IMPLBASE4_HXX_ -#include <cppuhelper/implbase4.hxx> +#ifndef _CPPUHELPER_IMPLBASE5_HXX_ +#include <cppuhelper/implbase5.hxx> #endif #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ #include <com/sun/star/lang/XMultiServiceFactory.hpp> @@ -43,6 +43,9 @@ #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMECONTAINER_HPP_ #include <com/sun/star/container/XHierarchicalNameContainer.hpp> #endif +#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAME_HPP_ +#include <com/sun/star/container/XHierarchicalName.hpp> +#endif #ifndef _COM_SUN_STAR_EMBED_XTRANSACTEDOBJECT_HPP_ #include <com/sun/star/embed/XTransactedObject.hpp> #endif @@ -60,9 +63,10 @@ namespace dbaccess { //........................................................................ -typedef ::cppu::ImplHelper4 < ::com::sun::star::frame::XComponentLoader +typedef ::cppu::ImplHelper5 < ::com::sun::star::frame::XComponentLoader , ::com::sun::star::lang::XMultiServiceFactory , ::com::sun::star::container::XHierarchicalNameContainer + , ::com::sun::star::container::XHierarchicalName , ::com::sun::star::embed::XTransactedObject > ODocumentContainer_Base; //========================================================================== @@ -111,6 +115,10 @@ public: virtual void SAL_CALL insertByHierarchicalName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL removeByHierarchicalName( const ::rtl::OUString& Name ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + // XHierarchicalName + virtual ::rtl::OUString SAL_CALL getHierarchicalName( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL composeHierarchicalName( const ::rtl::OUString& aRelativeName ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); + // XNameContainer virtual void SAL_CALL removeByName( const ::rtl::OUString& _rName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index af9798ab4..c40282a15 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -249,6 +249,7 @@ #include <com/sun/star/io/WrongFormatException.hpp> #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp> #include <com/sun/star/sdb/application/DatabaseObject.hpp> +#include <com/sun/star/util/XModifiable2.hpp> using namespace ::com::sun::star; using namespace view; @@ -415,6 +416,40 @@ namespace dbaccess }; //================================================================== + // LockModifiable + //================================================================== + class LockModifiable + { + public: + LockModifiable( const Reference< XInterface >& i_rModifiable ) + :m_xModifiable( i_rModifiable, UNO_QUERY ) + { + OSL_ENSURE( m_xModifiable.is(), "LockModifiable::LockModifiable: invalid component!" ); + if ( m_xModifiable.is() ) + { + if ( !m_xModifiable->isSetModifiedEnabled() ) + { + // somebody already locked that, no need to lock it, again, and no need to unlock it later + m_xModifiable.clear(); + } + else + { + m_xModifiable->disableSetModified(); + } + } + } + + ~LockModifiable() + { + if ( m_xModifiable.is() ) + m_xModifiable->enableSetModified(); + } + + private: + Reference< XModifiable2 > m_xModifiable; + }; + + //================================================================== // LifetimeCoupler //================================================================== typedef ::cppu::WeakImplHelper1 < css::lang::XEventListener @@ -531,6 +566,15 @@ namespace dbaccess } } } +#if OSL_DEBUG_LEVEL > 0 + // alternative, shorter approach + const Sequence< NamedValue > aProps( aConfigHelper.GetObjectPropsByMediaType( _rMediaType ) ); + const ::comphelper::NamedValueCollection aMediaTypeProps( aProps ); + const ::rtl::OUString sAlternativeResult = aMediaTypeProps.getOrDefault( "ObjectDocumentServiceName", ::rtl::OUString() ); + OSL_ENSURE( sAlternativeResult == sResult, "ODocumentDefinition::GetDocumentServiceFromMediaType: failed, this approach is *not* equivalent (1)!" ); + const Sequence< sal_Int8 > aAlternativeClassID = aMediaTypeProps.getOrDefault( "ClassID", Sequence< sal_Int8 >() ); + OSL_ENSURE( aAlternativeClassID == _rClassId, "ODocumentDefinition::GetDocumentServiceFromMediaType: failed, this approach is *not* equivalent (2)!" ); +#endif } catch ( Exception& ) { @@ -545,14 +589,9 @@ namespace dbaccess DBG_NAME(ODocumentDefinition) //-------------------------------------------------------------------------- -ODocumentDefinition::ODocumentDefinition(const Reference< XInterface >& _rxContainer - , const Reference< XMultiServiceFactory >& _xORB - ,const TContentPtr& _pImpl - , sal_Bool _bForm - , const Sequence< sal_Int8 >& _aClassID - ,const Reference<XConnection>& _xConnection - ) - :OContentHelper(_xORB,_rxContainer,_pImpl) +ODocumentDefinition::ODocumentDefinition( const Reference< XInterface >& _rxContainer, const Reference< XMultiServiceFactory >& _xORB, + const TContentPtr& _pImpl, sal_Bool _bForm ) + :OContentHelper(_xORB,_rxContainer,_pImpl) ,OPropertyStateContainer(OContentHelper::rBHelper) ,m_pInterceptor(NULL) ,m_bForm(_bForm) @@ -563,9 +602,19 @@ ODocumentDefinition::ODocumentDefinition(const Reference< XInterface >& _rxConta { DBG_CTOR(ODocumentDefinition, NULL); registerProperties(); - if ( _aClassID.getLength() ) - loadEmbeddedObject( _xConnection, _aClassID, Sequence< PropertyValue >(), false, false ); } + +//-------------------------------------------------------------------------- +void ODocumentDefinition::initialLoad( const Sequence< sal_Int8 >& i_rClassID, const Sequence< PropertyValue >& i_rCreationArgs, + const Reference< XConnection >& i_rConnection ) +{ + OSL_ENSURE( i_rClassID.getLength(), "ODocumentDefinition::initialLoad: illegal class ID!" ); + if ( !i_rClassID.getLength() ) + return; + + loadEmbeddedObject( i_rConnection, i_rClassID, i_rCreationArgs, false, false ); +} + //-------------------------------------------------------------------------- ODocumentDefinition::~ODocumentDefinition() { @@ -628,15 +677,39 @@ IMPLEMENT_SERVICE_INFO1(ODocumentDefinition,"com.sun.star.comp.dba.ODocumentDefi //-------------------------------------------------------------------------- void ODocumentDefinition::registerProperties() { - registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED, - &m_pImpl->m_aProps.aTitle, ::getCppuType(&m_pImpl->m_aProps.aTitle)); - registerProperty(PROPERTY_AS_TEMPLATE, PROPERTY_ID_AS_TEMPLATE, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED, - &m_pImpl->m_aProps.bAsTemplate, ::getCppuType(&m_pImpl->m_aProps.bAsTemplate)); - registerProperty(PROPERTY_PERSISTENT_NAME, PROPERTY_ID_PERSISTENT_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED, - &m_pImpl->m_aProps.sPersistentName, ::getCppuType(&m_pImpl->m_aProps.sPersistentName)); - registerProperty(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm")), PROPERTY_ID_IS_FORM, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED, - &m_bForm, ::getCppuType(&m_bForm)); +#define REGISTER_PROPERTY( name, location ) \ + registerProperty( PROPERTY_##name, PROPERTY_ID_##name, PropertyAttribute::READONLY, &location, ::getCppuType( &location ) ); + +#define REGISTER_PROPERTY_BV( name, location ) \ + registerProperty( PROPERTY_##name, PROPERTY_ID_##name, PropertyAttribute::CONSTRAINED | PropertyAttribute::BOUND | PropertyAttribute::READONLY, &location, ::getCppuType( &location ) ); + + REGISTER_PROPERTY_BV( NAME, m_pImpl->m_aProps.aTitle ); + REGISTER_PROPERTY ( AS_TEMPLATE, m_pImpl->m_aProps.bAsTemplate ); + REGISTER_PROPERTY ( PERSISTENT_NAME, m_pImpl->m_aProps.sPersistentName ); + REGISTER_PROPERTY ( IS_FORM, m_bForm ); +} + +// ----------------------------------------------------------------------------- +void SAL_CALL ODocumentDefinition::getFastPropertyValue( Any& o_rValue, sal_Int32 i_nHandle ) const +{ + if ( i_nHandle == PROPERTY_ID_PERSISTENT_PATH ) + { + ::rtl::OUString sPersistentPath; + if ( m_pImpl->m_aProps.sPersistentName.getLength() ) + { + ::rtl::OUStringBuffer aBuffer; + aBuffer.append( ODatabaseModelImpl::getObjectContainerStorageName( m_bForm ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT ) ); + aBuffer.append( sal_Unicode( '/' ) ); + aBuffer.append( m_pImpl->m_aProps.sPersistentName ); + sPersistentPath = aBuffer.makeStringAndClear(); + } + o_rValue <<= sPersistentPath; + return; + } + + OPropertyStateContainer::getFastPropertyValue( o_rValue, i_nHandle ); } + // ----------------------------------------------------------------------------- Reference< XPropertySetInfo > SAL_CALL ODocumentDefinition::getPropertySetInfo( ) throw(RuntimeException) { @@ -654,10 +727,21 @@ IPropertyArrayHelper& ODocumentDefinition::getInfoHelper() //-------------------------------------------------------------------------- IPropertyArrayHelper* ODocumentDefinition::createArrayHelper( ) const { + // properties maintained by our base class (see registerProperties) Sequence< Property > aProps; - describeProperties(aProps); - return new OPropertyArrayHelper(aProps); + describeProperties( aProps ); + + // properties not maintained by our base class + Sequence< Property > aManualProps( 1 ); + aManualProps[0].Name = PROPERTY_PERSISTENT_PATH; + aManualProps[0].Handle = PROPERTY_ID_PERSISTENT_PATH; + aManualProps[0].Type = ::getCppuType( static_cast< const ::rtl::OUString* >( NULL ) ); + aManualProps[0].Attributes = PropertyAttribute::READONLY; + + return new OPropertyArrayHelper( ::comphelper::concatSequences( aProps, aManualProps ) ); } + +// ----------------------------------------------------------------------------- class OExecuteImpl { sal_Bool& m_rbSet; @@ -665,6 +749,7 @@ public: OExecuteImpl(sal_Bool& _rbSet) : m_rbSet(_rbSet){ m_rbSet=sal_True; } ~OExecuteImpl(){ m_rbSet = sal_False; } }; + // ----------------------------------------------------------------------------- namespace { @@ -694,7 +779,7 @@ void ODocumentDefinition::impl_removeFrameFromDesktop_throw( const ::comphelper: } // ----------------------------------------------------------------------------- -void ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow() +void ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow( const bool i_bReactivated ) { try { @@ -718,10 +803,10 @@ void ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow() // ensure that we ourself are kept alive as long as the embedded object's frame is // opened - LifetimeCoupler::couple( *this, Reference< XComponent >( xFrame, UNO_QUERY_THROW ) ); + LifetimeCoupler::couple( *this, xFrame.get() ); // init the edit view - if ( m_bForm && m_bOpenInDesign ) + if ( m_bForm && m_bOpenInDesign && !i_bReactivated ) impl_initFormEditView( xController ); } catch( const RuntimeException& ) @@ -831,6 +916,9 @@ void ODocumentDefinition::impl_initFormEditView( const Reference< XController >& Reference< XViewSettingsSupplier > xSettingsSupplier( _rxController, UNO_QUERY_THROW ); Reference< XPropertySet > xViewSettings( xSettingsSupplier->getViewSettings(), UNO_QUERY_THROW ); + // the below code could indirectly tamper with the "modified" flag of the model, temporarily disable this + LockModifiable aLockModify( _rxController->getModel() ); + // The visual area size can be changed by the setting of the following properties // so it should be restored later PreserveVisualAreaSize aPreserveVisAreaSize( _rxController->getModel() ); @@ -848,9 +936,6 @@ void ODocumentDefinition::impl_initFormEditView( const Reference< XController >& xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowOnlineLayout")),makeAny(sal_True)); xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RasterSubdivisionX")),makeAny(sal_Int32(5))); xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RasterSubdivisionY")),makeAny(sal_Int32(5))); - - Reference< XModifiable > xModifiable( _rxController->getModel(), UNO_QUERY_THROW ); - xModifiable->setModified( sal_False ); } catch( const Exception& ) { @@ -859,6 +944,39 @@ void ODocumentDefinition::impl_initFormEditView( const Reference< XController >& } // ----------------------------------------------------------------------------- +void ODocumentDefinition::impl_showOrHideComponent_throw( const bool i_bShow ) +{ + const sal_Int32 nCurrentState = m_xEmbeddedObject.is() ? m_xEmbeddedObject->getCurrentState() : EmbedStates::LOADED; + switch ( nCurrentState ) + { + default: + case EmbedStates::LOADED: + throw embed::WrongStateException( ::rtl::OUString(), *this ); + + case EmbedStates::RUNNING: + if ( !i_bShow ) + // fine, a running (and not yet active) object is never visible + return; + { + LockModifiable aLockModify( impl_getComponent_throw() ); + m_xEmbeddedObject->changeState( EmbedStates::ACTIVE ); + impl_onActivateEmbeddedObject_nothrow( false ); + } + break; + + case EmbedStates::ACTIVE: + { + Reference< XModel > xEmbeddedDoc( impl_getComponent_throw( true ), UNO_QUERY_THROW ); + Reference< XController > xEmbeddedController( xEmbeddedDoc->getCurrentController(), UNO_SET_THROW ); + Reference< XFrame > xEmbeddedFrame( xEmbeddedController->getFrame(), UNO_SET_THROW ); + Reference< XWindow > xEmbeddedWindow( xEmbeddedFrame->getContainerWindow(), UNO_SET_THROW ); + xEmbeddedWindow->setVisible( i_bShow ); + } + break; + } +} + +// ----------------------------------------------------------------------------- Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, const bool _bActivate, const Reference< XCommandEnvironment >& _rxEnvironment ) { @@ -871,7 +989,7 @@ Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, cons // for the document, default to the interaction handler as used for loading the DB doc // This might be overwritten below, when examining _rOpenArgument. - ::comphelper::NamedValueCollection aDBDocArgs( m_pImpl->m_pDataSource->getResource() ); + const ::comphelper::NamedValueCollection& aDBDocArgs( m_pImpl->m_pDataSource->getMediaDescriptor() ); Reference< XInteractionHandler > xHandler( aDBDocArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) ); if ( xHandler.is() ) aDocumentArgs.put( "InteractionHandler", xHandler ); @@ -963,10 +1081,6 @@ Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, cons } aDocumentArgs.put( "MacroExecutionMode", *aDocumentMacroMode ); - - if ( xConnection.is() ) - m_xLastKnownConnection = xConnection; - if ( ( nOpenMode == OpenMode::ALL ) || ( nOpenMode == OpenMode::FOLDERS ) || ( nOpenMode == OpenMode::DOCUMENTS ) @@ -1030,8 +1144,14 @@ Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, cons if ( _bActivate && !bOpenHidden ) { + LockModifiable aLockModify( impl_getComponent_throw() ); m_xEmbeddedObject->changeState( EmbedStates::ACTIVE ); - ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow(); + impl_onActivateEmbeddedObject_nothrow( false ); + } + else + { + // ensure that we ourself are kept alive as long as the document is open + LifetimeCoupler::couple( *this, xModel.get() ); } if ( !m_bForm && m_pImpl->m_aProps.bAsTemplate && !m_bOpenInDesign ) @@ -1077,14 +1197,17 @@ Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 Co sal_Int32 nCurrentState = m_xEmbeddedObject->getCurrentState(); bool bIsActive = ( nCurrentState == EmbedStates::ACTIVE ); - // exception: new-style reports always create a new document when "open" is executed - Reference< report::XReportDefinition > xReportDefinition( getComponent(), UNO_QUERY ); - bool bIsAliveNewStyleReport = ( xReportDefinition.is() && ( bOpen || bOpenForMail ) ); - - if ( bIsActive && !bIsAliveNewStyleReport ) + if ( bIsActive ) { - ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow(); - return makeAny( getComponent() ); + // exception: new-style reports always create a new document when "open" is executed + Reference< report::XReportDefinition > xReportDefinition( impl_getComponent_throw( false ), UNO_QUERY ); + bool bIsAliveNewStyleReport = ( xReportDefinition.is() && ( bOpen || bOpenForMail ) ); + + if ( !bIsAliveNewStyleReport ) + { + impl_onActivateEmbeddedObject_nothrow( true ); + return makeAny( getComponent() ); + } } } @@ -1117,16 +1240,6 @@ Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 Co Reference< XStorage> xStorage = getContainerStorage(); // ----------------------------------------------------------------------------- xStorage->copyElementTo(m_pImpl->m_aProps.sPersistentName,xDest,sPersistentName); - /*loadEmbeddedObject( true ); - Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY); - if ( xPersist.is() ) - { - xPersist->storeToEntry(xStorage,sPersistentName,Sequence<PropertyValue>(),Sequence<PropertyValue>()); - xPersist->storeOwn(); - m_xEmbeddedObject->changeState(EmbedStates::LOADED); - } - else - throw CommandAbortedException();*/ } else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "preview" ) ) ) { @@ -1182,6 +1295,14 @@ Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 Co { aRet <<= impl_close_throw(); } + else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "show" ) ) ) + { + impl_showOrHideComponent_throw( true ); + } + else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "hide" ) ) ) + { + impl_showOrHideComponent_throw( false ); + } else { aRet = OContentHelper::execute(aCommand,CommandId,Environment); @@ -1361,7 +1482,7 @@ sal_Bool ODocumentDefinition::save(sal_Bool _bApprove) pRequest->addContinuation(pAbort); // create the handler, let it handle the request - Reference< XInteractionHandler > xHandler( m_aContext.createComponent( (::rtl::OUString)SERVICE_SDB_INTERACTION_HANDLER ), UNO_QUERY ); + Reference< XInteractionHandler > xHandler( m_aContext.createComponent( (::rtl::OUString)SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY ); if ( xHandler.is() ) xHandler->handle(xRequest); @@ -1371,16 +1492,16 @@ sal_Bool ODocumentDefinition::save(sal_Bool _bApprove) return sal_True; if ( pDocuSave && pDocuSave->wasSelected() ) { - ::osl::MutexGuard aGuard(m_aMutex); - Reference<XNameContainer> xNC(pDocuSave->getContent(),UNO_QUERY); - if ( xNC.is() ) - { - m_pImpl->m_aProps.aTitle = pDocuSave->getName(); - Reference< XContent> xContent = this; - xNC->insertByName(pDocuSave->getName(),makeAny(xContent)); + Reference<XNameContainer> xNC( pDocuSave->getContent(), UNO_QUERY_THROW ); - updateDocumentTitle(); - } + ::osl::ResettableMutexGuard aGuard( m_aMutex ); + NameChangeNotifier aNameChangeAndNotify( *this, pDocuSave->getName(), aGuard ); + m_pImpl->m_aProps.aTitle = pDocuSave->getName(); + + Reference< XContent> xContent = this; + xNC->insertByName(pDocuSave->getName(),makeAny(xContent)); + + updateDocumentTitle(); } } @@ -1436,7 +1557,7 @@ sal_Bool ODocumentDefinition::saveAs() pRequest->addContinuation(pAbort); // create the handler, let it handle the request - Reference< XInteractionHandler > xHandler(m_aContext.createComponent(::rtl::OUString(SERVICE_SDB_INTERACTION_HANDLER)), UNO_QUERY); + Reference< XInteractionHandler > xHandler(m_aContext.createComponent(::rtl::OUString(SERVICE_TASK_INTERACTION_HANDLER)), UNO_QUERY); if ( xHandler.is() ) xHandler->handle(xRequest); @@ -1578,8 +1699,30 @@ sal_Bool ODocumentDefinition::objectSupportsEmbeddedScripts() const } // ----------------------------------------------------------------------------- +void ODocumentDefinition::separateOpenCommandArguments( const Sequence< PropertyValue >& i_rOpenCommandArguments, + ::comphelper::NamedValueCollection& o_rDocumentLoadArgs, ::comphelper::NamedValueCollection& o_rEmbeddedObjectDescriptor ) +{ + ::comphelper::NamedValueCollection aOpenCommandArguments( i_rOpenCommandArguments ); + + const sal_Char* pObjectDescriptorArgs[] = + { + "RecoveryStorage" + }; + for ( size_t i=0; i < sizeof( pObjectDescriptorArgs ) / sizeof( pObjectDescriptorArgs[0] ); ++i ) + { + if ( aOpenCommandArguments.has( pObjectDescriptorArgs[i] ) ) + { + o_rEmbeddedObjectDescriptor.put( pObjectDescriptorArgs[i], aOpenCommandArguments.get( pObjectDescriptorArgs[i] ) ); + aOpenCommandArguments.remove( pObjectDescriptorArgs[i] ); + } + } + + o_rDocumentLoadArgs.merge( aOpenCommandArguments, false ); +} + +// ----------------------------------------------------------------------------- Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XConnection>& _xConnection, const bool _bSuppressMacros, const bool _bReadOnly, - const Sequence< PropertyValue >& _rAdditionalArgs, Sequence< PropertyValue >& _out_rEmbeddedObjectDescriptor ) + const Sequence< PropertyValue >& i_rOpenCommandArguments, Sequence< PropertyValue >& _out_rEmbeddedObjectDescriptor ) { // ......................................................................... // (re-)create interceptor, and put it into the descriptor of the embedded object @@ -1598,6 +1741,10 @@ Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XC aEmbeddedDescriptor.put( "OutplaceDispatchInterceptor", xInterceptor ); // ......................................................................... + ::comphelper::NamedValueCollection aMediaDesc; + separateOpenCommandArguments( i_rOpenCommandArguments, aMediaDesc, aEmbeddedDescriptor ); + + // ......................................................................... // create the OutplaceFrameProperties, and put them into the descriptor of the embedded object ::comphelper::NamedValueCollection OutplaceFrameProperties; OutplaceFrameProperties.put( "TopWindow", (sal_Bool)sal_True ); @@ -1630,11 +1777,12 @@ Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XC aEmbeddedDescriptor.put( "EmbeddedScriptSupport", (sal_Bool)objectSupportsEmbeddedScripts() ); // ......................................................................... - // pass the descriptor of the embedded object to the caller - aEmbeddedDescriptor >>= _out_rEmbeddedObjectDescriptor; + // tell the embedded object to not participate in the document recovery game - the DB doc will handle it + aEmbeddedDescriptor.put( "DocumentRecoverySupport", (sal_Bool)sal_False ); // ......................................................................... - ::comphelper::NamedValueCollection aMediaDesc( _rAdditionalArgs ); + // pass the descriptor of the embedded object to the caller + aEmbeddedDescriptor >>= _out_rEmbeddedObjectDescriptor; // ......................................................................... // create the ComponentData, and put it into the document's media descriptor @@ -1657,8 +1805,8 @@ Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XC return aMediaDesc.getPropertyValues(); } // ----------------------------------------------------------------------------- -void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _xConnection, const Sequence< sal_Int8 >& _aClassID, - const Sequence< PropertyValue >& _rAdditionalArgs, const bool _bSuppressMacros, const bool _bReadOnly ) +void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& i_rConnection, const Sequence< sal_Int8 >& _aClassID, + const Sequence< PropertyValue >& i_rOpenCommandArguments, const bool _bSuppressMacros, const bool _bReadOnly ) { if ( !m_xEmbeddedObject.is() ) { @@ -1684,7 +1832,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x // the com.sun.star.report.pentaho.SOReportJobFactory is not present. if ( !m_bForm && !sDocumentService.equalsAscii("com.sun.star.text.TextDocument")) { - // we seems to be a new report, check if report extension is present. + // we seem to be a "new style" report, check if report extension is present. Reference< XContentEnumerationAccess > xEnumAccess( m_aContext.getLegacyServiceFactory(), UNO_QUERY ); const ::rtl::OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_aContext.getLegacyServiceFactory()); Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName); @@ -1710,7 +1858,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x Sequence< PropertyValue > aEmbeddedObjectDescriptor; Sequence< PropertyValue > aLoadArgs( fillLoadArgs( - _xConnection, _bSuppressMacros, _bReadOnly, _rAdditionalArgs, aEmbeddedObjectDescriptor ) ); + i_rConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) ); m_xEmbeddedObject.set(xEmbedFactory->createInstanceUserInit(aClassID ,sDocumentService @@ -1732,8 +1880,9 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x m_xEmbeddedObject->changeState(EmbedStates::RUNNING); if ( bSetSize ) { - awt::Size aSize( DEFAULT_WIDTH, DEFAULT_HEIGHT ); + LockModifiable aLockModify( impl_getComponent_throw( false ) ); + awt::Size aSize( DEFAULT_WIDTH, DEFAULT_HEIGHT ); m_xEmbeddedObject->setVisualAreaSize(Aspects::MSOLE_CONTENT,aSize); } } @@ -1755,7 +1904,7 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x Sequence< PropertyValue > aEmbeddedObjectDescriptor; Sequence< PropertyValue > aLoadArgs( fillLoadArgs( - _xConnection, _bSuppressMacros, _bReadOnly, _rAdditionalArgs, aEmbeddedObjectDescriptor ) ); + i_rConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) ); Reference<XCommonEmbedPersist> xCommon(m_xEmbeddedObject,UNO_QUERY); OSL_ENSURE(xCommon.is(),"unsupported interface!"); @@ -1772,21 +1921,25 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x // then just re-set some model parameters try { - Reference< XModel > xModel( getComponent(), UNO_QUERY_THROW ); - Sequence< PropertyValue > aArgs = xModel->getArgs(); - - ::comphelper::NamedValueCollection aMediaDesc( aArgs ); - ::comphelper::NamedValueCollection aArguments( _rAdditionalArgs ); - aMediaDesc.merge( aArguments, sal_False ); - - lcl_putLoadArgs( aMediaDesc, optional_bool(), optional_bool() ); + // ensure the media descriptor doesn't contain any values which are intended for the + // EmbeddedObjectDescriptor only + ::comphelper::NamedValueCollection aEmbeddedObjectDescriptor; + ::comphelper::NamedValueCollection aNewMediaDesc; + separateOpenCommandArguments( i_rOpenCommandArguments, aNewMediaDesc, aEmbeddedObjectDescriptor ); + + // merge the new media descriptor into the existing media descriptor + const Reference< XModel > xModel( getComponent(), UNO_QUERY_THROW ); + const Sequence< PropertyValue > aArgs = xModel->getArgs(); + ::comphelper::NamedValueCollection aExistentMediaDesc( aArgs ); + aExistentMediaDesc.merge( aNewMediaDesc, sal_False ); + + lcl_putLoadArgs( aExistentMediaDesc, optional_bool(), optional_bool() ); // don't put _bSuppressMacros and _bReadOnly here - if the document was already // loaded, we should not tamper with its settings. // #i88977# / 2008-05-05 / frank.schoenheit@sun.com // #i86872# / 2008-03-13 / frank.schoenheit@sun.com - aMediaDesc >>= aArgs; - xModel->attachResource( xModel->getURL(), aArgs ); + xModel->attachResource( xModel->getURL(), aExistentMediaDesc.getPropertyValues() ); } catch( const Exception& ) { @@ -1812,6 +1965,9 @@ void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _x DBG_UNHANDLED_EXCEPTION(); } } + + if ( i_rConnection.is() ) + m_xLastKnownConnection = i_rConnection; } // ----------------------------------------------------------------------------- @@ -1863,18 +2019,18 @@ void ODocumentDefinition::onCommandGetDocumentProperties( Any& _rProps ) } } // ----------------------------------------------------------------------------- -Reference< util::XCloseable> ODocumentDefinition::getComponent() throw (RuntimeException) +Reference< util::XCloseable > ODocumentDefinition::impl_getComponent_throw( const bool i_ForceCreate ) { OSL_ENSURE(m_xEmbeddedObject.is(),"Illegal call for embeddedObject"); - Reference< util::XCloseable> xComp; + Reference< util::XCloseable > xComp; if ( m_xEmbeddedObject.is() ) { - int nOldState = m_xEmbeddedObject->getCurrentState(); - int nState = nOldState; - if ( nOldState == EmbedStates::LOADED ) + int nState = m_xEmbeddedObject->getCurrentState(); + if ( ( nState == EmbedStates::LOADED ) && i_ForceCreate ) { m_xEmbeddedObject->changeState( EmbedStates::RUNNING ); - nState = EmbedStates::RUNNING; + nState = m_xEmbeddedObject->getCurrentState(); + OSL_ENSURE( nState == EmbedStates::RUNNING, "ODocumentDefinition::impl_getComponent_throw: could not switch to RUNNING!" ); } if ( nState == EmbedStates::ACTIVE || nState == EmbedStates::RUNNING ) @@ -1891,6 +2047,13 @@ Reference< util::XCloseable> ODocumentDefinition::getComponent() throw (RuntimeE } // ----------------------------------------------------------------------------- +Reference< util::XCloseable > ODocumentDefinition::getComponent() throw (RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + return impl_getComponent_throw( true ); +} + +// ----------------------------------------------------------------------------- namespace { Reference< XDatabaseDocumentUI > lcl_getDatabaseDocumentUI( ODatabaseModelImpl& _rModelImpl ) @@ -2011,13 +2174,29 @@ void SAL_CALL ODocumentDefinition::store( ) throw (WrappedTargetException, Runt return bSuccess; } +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODocumentDefinition::getHierarchicalName() throw (RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + return impl_getHierarchicalName( false ); +} + +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODocumentDefinition::composeHierarchicalName( const ::rtl::OUString& i_rRelativeName ) throw (IllegalArgumentException, NoSupportException, RuntimeException) +{ + ::rtl::OUStringBuffer aBuffer; + aBuffer.append( getHierarchicalName() ); + aBuffer.append( sal_Unicode( '/' ) ); + aBuffer.append( i_rRelativeName ); + return aBuffer.makeStringAndClear(); +} // ----------------------------------------------------------------------------- void SAL_CALL ODocumentDefinition::rename( const ::rtl::OUString& _rNewName ) throw (SQLException, ElementExistException, RuntimeException) { try { - osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex); + ::osl::ResettableMutexGuard aGuard(m_aMutex); if ( _rNewName.equals( m_pImpl->m_aProps.aTitle ) ) return; @@ -2026,16 +2205,9 @@ void SAL_CALL ODocumentDefinition::rename( const ::rtl::OUString& _rNewName ) th if ( _rNewName.indexOf( '/' ) != -1 ) m_aErrorHelper.raiseException( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES, *this ); - sal_Int32 nHandle = PROPERTY_ID_NAME; - Any aOld = makeAny( m_pImpl->m_aProps.aTitle ); - Any aNew = makeAny( _rNewName ); - - aGuard.clear(); - fire(&nHandle, &aNew, &aOld, 1, sal_True ); + NameChangeNotifier aNameChangeAndNotify( *this, _rNewName, aGuard ); m_pImpl->m_aProps.aTitle = _rNewName; - fire(&nHandle, &aNew, &aOld, 1, sal_False ); - ::osl::ClearableGuard< ::osl::Mutex > aGuard2( m_aMutex ); if ( m_xEmbeddedObject.is() && m_xEmbeddedObject->getCurrentState() == EmbedStates::ACTIVE ) updateDocumentTitle(); } @@ -2076,7 +2248,11 @@ bool ODocumentDefinition::prepareClose() // by the embedding component. Thus, we do the suspend call here. // #i49370# / 2005-06-09 / frank.schoenheit@sun.com - Reference< XModel > xModel( getComponent(), UNO_QUERY ); + Reference< util::XCloseable > xComponent( impl_getComponent_throw( false ) ); + if ( !xComponent.is() ) + return true; + + Reference< XModel > xModel( xComponent, UNO_QUERY ); Reference< XController > xController; if ( xModel.is() ) xController = xModel->getCurrentController(); @@ -2190,6 +2366,43 @@ void SAL_CALL ODocumentDefinition::notifyClosing( const lang::EventObject& /*Sou void SAL_CALL ODocumentDefinition::disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException) { } + +// ----------------------------------------------------------------------------- +void ODocumentDefinition::firePropertyChange( sal_Int32 i_nHandle, const Any& i_rNewValue, const Any& i_rOldValue, + sal_Bool i_bVetoable, const NotifierAccess ) +{ + fire( &i_nHandle, &i_rNewValue, &i_rOldValue, 1, i_bVetoable ); +} + +// ============================================================================= +// NameChangeNotifier +// ============================================================================= +// ----------------------------------------------------------------------------- +NameChangeNotifier::NameChangeNotifier( ODocumentDefinition& i_rDocumentDefinition, const ::rtl::OUString& i_rNewName, + ::osl::ResettableMutexGuard& i_rClearForNotify ) + :m_rDocumentDefinition( i_rDocumentDefinition ) + ,m_aOldValue( makeAny( i_rDocumentDefinition.getCurrentName() ) ) + ,m_aNewValue( makeAny( i_rNewName ) ) + ,m_rClearForNotify( i_rClearForNotify ) +{ + impl_fireEvent_throw( sal_True ); +} + +// ----------------------------------------------------------------------------- +NameChangeNotifier::~NameChangeNotifier() +{ + impl_fireEvent_throw( sal_False ); +} + +// ----------------------------------------------------------------------------- +void NameChangeNotifier::impl_fireEvent_throw( const sal_Bool i_bVetoable ) +{ + m_rClearForNotify.clear(); + m_rDocumentDefinition.firePropertyChange( + PROPERTY_ID_NAME, m_aNewValue, m_aOldValue, i_bVetoable, ODocumentDefinition::NotifierAccess() ); + m_rClearForNotify.reset(); +} + //........................................................................ } // namespace dbaccess //........................................................................ diff --git a/dbaccess/source/core/dataaccess/documentdefinition.hxx b/dbaccess/source/core/dataaccess/documentdefinition.hxx index cd8176cd2..b011728a6 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.hxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.hxx @@ -31,8 +31,8 @@ #ifndef _CPPUHELPER_PROPSHLP_HXX #include <cppuhelper/propshlp.hxx> #endif -#ifndef _CPPUHELPER_IMPLBASE3_HXX_ -#include <cppuhelper/implbase3.hxx> +#ifndef _CPPUHELPER_IMPLBASE4_HXX_ +#include <cppuhelper/implbase4.hxx> #endif #ifndef DBA_CONTENTHELPER_HXX #include "ContentHelper.hxx" @@ -63,6 +63,12 @@ #endif #include <com/sun/star/sdb/XSubDocument.hpp> #include <com/sun/star/util/XCloseListener.hpp> +#include <com/sun/star/container/XHierarchicalName.hpp> + +namespace comphelper +{ + class NamedValueCollection; +} //........................................................................ namespace dbaccess @@ -76,9 +82,10 @@ namespace dbaccess //= document //========================================================================== -typedef ::cppu::ImplHelper3 < ::com::sun::star::embed::XComponentSupplier +typedef ::cppu::ImplHelper4 < ::com::sun::star::embed::XComponentSupplier , ::com::sun::star::sdb::XSubDocument , ::com::sun::star::util::XCloseListener + , ::com::sun::star::container::XHierarchicalName > ODocumentDefinition_Base; class ODocumentDefinition @@ -104,14 +111,18 @@ protected: public: ODocumentDefinition( - const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContainer - ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& - ,const TContentPtr& _pImpl - ,sal_Bool _bForm - ,const ::com::sun::star::uno::Sequence< sal_Int8 >& _aClassID = ::com::sun::star::uno::Sequence< sal_Int8 >() - ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection = ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>() + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContainer, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&, + const TContentPtr& _pImpl, + sal_Bool _bForm ); + void initialLoad( + const ::com::sun::star::uno::Sequence< sal_Int8 >& i_rClassID, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rCreationArgs, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& i_rConnection + ); + // com::sun::star::lang::XTypeProvider DECLARE_TYPEPROVIDER( ); @@ -124,6 +135,12 @@ public: // ::com::sun::star::beans::XPropertySet virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); + // OPropertySetHelper + virtual void SAL_CALL getFastPropertyValue( + ::com::sun::star::uno::Any& o_rValue, + sal_Int32 i_nHandle + ) const; + // XComponentSupplier virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > SAL_CALL getComponent( ) throw (::com::sun::star::uno::RuntimeException); @@ -133,6 +150,10 @@ public: virtual void SAL_CALL store( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL close( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + // XHierarchicalName + virtual ::rtl::OUString SAL_CALL getHierarchicalName( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL composeHierarchicalName( const ::rtl::OUString& aRelativeName ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); + // OPropertySetHelper virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); @@ -194,10 +215,20 @@ public: ::com::sun::star::uno::Sequence< sal_Int8 >& _rClassId ); + struct NotifierAccess { friend class NameChangeNotifier; private: NotifierAccess() { } }; + const ::rtl::OUString& getCurrentName() const { return m_pImpl->m_aProps.aTitle; } + void firePropertyChange( + sal_Int32 i_nHandle, + const ::com::sun::star::uno::Any& i_rNewValue, + const ::com::sun::star::uno::Any& i_rOldValue, + sal_Bool i_bVetoable, + const NotifierAccess + ); + private: /** does necessary initializations after our embedded object has been switched to ACTIVE */ - void impl_onActivateEmbeddedObject_nothrow(); + void impl_onActivateEmbeddedObject_nothrow( const bool i_bReactivated ); /** initializes a newly created view/controller of a form which is displaying our embedded object @@ -220,19 +251,27 @@ private: /** opens the UI for this sub document */ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - impl_openUI_nolck_throw( bool _bForEditing ); + impl_openUI_nolck_throw( bool _bForEditing ); /** stores our document, if it's already loaded */ - void - impl_store_throw(); + void impl_store_throw(); /** closes our document, if it's open */ - bool - impl_close_throw(); + bool impl_close_throw(); + + /** returns our component, creates it if necessary + */ + ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > + impl_getComponent_throw( const bool i_ForceCreate = true ); + + /** shows or hides our component + + The embedded object must exist, and be in state LOADED, at least. + */ + void impl_showOrHideComponent_throw( const bool i_bShow ); -private: // OPropertyArrayUsageHelper virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; @@ -244,7 +283,6 @@ private: // OContentHelper overridables virtual ::rtl::OUString determineContentType() const; -private: /** fills the load arguments */ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > @@ -252,10 +290,30 @@ private: const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection, const bool _bSuppressMacros, const bool _bReadOnly, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rAdditionalArgs, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rOpenCommandArguments, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _out_rEmbeddedObjectDescriptor ); + /** splits the given arguments to an "open*" command into arguments for loading the document, and arguments to be + put into the EmbeddedObjectDescriptor + + Any values already present in <code>o_rDocumentLoadArgs</code> and <code>o_rEmbeddedObjectDescriptor</code> + will be overwritten by values from <code>i_rOpenCommandArguments</code>, if applicable, otherwise they will + be preserved. + + @param i_rOpenCommandArguments + the arguments passed to the "open*" command at the content + @param o_rDocumentLoadArgs + the arguments to be passed when actually loading the embedded document. + @param o_rEmbeddedObjectDescriptor + the EmbeddedObjectDescriptor to be passed when initializing the embedded object + */ + void separateOpenCommandArguments( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rOpenCommandArguments, + ::comphelper::NamedValueCollection& o_rDocumentLoadArgs, + ::comphelper::NamedValueCollection& o_rEmbeddedObjectDescriptor + ); + /** loads the EmbeddedObject if not already loaded @param _aClassID If set, it will be used to create the embedded object. @@ -321,6 +379,27 @@ private: const bool _bActivate, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& _rxEnvironment ); +private: + using ::cppu::OPropertySetHelper::getFastPropertyValue; +}; + +class NameChangeNotifier +{ +public: + NameChangeNotifier( + ODocumentDefinition& i_rDocumentDefinition, + const ::rtl::OUString& i_rNewName, + ::osl::ResettableMutexGuard& i_rClearForNotify + ); + ~NameChangeNotifier(); + +private: + ODocumentDefinition& m_rDocumentDefinition; + const ::com::sun::star::uno::Any m_aOldValue; + const ::com::sun::star::uno::Any m_aNewValue; + mutable ::osl::ResettableMutexGuard& m_rClearForNotify; + + void impl_fireEvent_throw( const sal_Bool i_bVetoable ); }; //........................................................................ diff --git a/dbaccess/source/core/dataaccess/makefile.mk b/dbaccess/source/core/dataaccess/makefile.mk index 5d804e911..831eae349 100644 --- a/dbaccess/source/core/dataaccess/makefile.mk +++ b/dbaccess/source/core/dataaccess/makefile.mk @@ -61,7 +61,7 @@ SLOFILES= \ $(SLO)$/ModelImpl.obj \ $(SLO)$/documentevents.obj \ $(SLO)$/documenteventexecutor.obj \ - $(SLO)$/documenteventnotifier.obj + $(SLO)$/documenteventnotifier.obj \ # --- Targets ---------------------------------- diff --git a/dbaccess/source/core/inc/ContentHelper.hxx b/dbaccess/source/core/inc/ContentHelper.hxx index dfd81695a..65bd10489 100644 --- a/dbaccess/source/core/inc/ContentHelper.hxx +++ b/dbaccess/source/core/inc/ContentHelper.hxx @@ -107,10 +107,12 @@ namespace dbaccess sal_Bool bAsTemplate; // AsTemplate ::rtl::OUString sPersistentName;// persistent name of the document - // @@@ Add other properties supported by your content. - ContentProperties() - : bIsDocument( sal_True ), bIsFolder( sal_False ), bAsTemplate( sal_False ) {} + :bIsDocument( sal_True ) + ,bIsFolder( sal_False ) + ,bAsTemplate( sal_False ) + { + } }; class OContentHelper_Impl diff --git a/dbaccess/source/core/inc/View.hxx b/dbaccess/source/core/inc/View.hxx new file mode 100644 index 000000000..49d4b9190 --- /dev/null +++ b/dbaccess/source/core/inc/View.hxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: View.hxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef DBACCESS_VIEW_HXX +#define DBACCESS_VIEW_HXX + +#include "connectivity/sdbcx/VView.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/sdbcx/XAlterView.hpp> +#include <com/sun/star/sdb/tools/XViewAccess.hpp> +/** === end UNO includes === **/ + +#include <comphelper/uno3.hxx> +#include <cppuhelper/implbase1.hxx> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= View + //==================================================================== + typedef ::connectivity::sdbcx::OView View_Base; + typedef ::cppu::ImplHelper1< ::com::sun::star::sdbcx::XAlterView > View_IBASE; + class View :public View_Base + ,public View_IBASE + { + public: + View( + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, + sal_Bool _bCaseSensitive, + const ::rtl::OUString& _rCatalogName, + const ::rtl::OUString& _rSchemaName, + const ::rtl::OUString& _rName + ); + + // UNO + DECLARE_XINTERFACE() + DECLARE_XTYPEPROVIDER() + + // XAlterView + virtual void SAL_CALL alterCommand( const ::rtl::OUString& NewCommand ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + + protected: + virtual ~View(); + + protected: + // OPropertyContainer + virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& _rValue, sal_Int32 _nHandle ) const; + + private: + ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XViewAccess> m_xViewAccess; + sal_Int32 m_nCommandHandle; + private: + using View_Base::getFastPropertyValue; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // DBACCESS_VIEW_HXX diff --git a/dbaccess/source/core/inc/definitioncolumn.hxx b/dbaccess/source/core/inc/definitioncolumn.hxx index 019a70c5c..b9ea45cd3 100644 --- a/dbaccess/source/core/inc/definitioncolumn.hxx +++ b/dbaccess/source/core/inc/definitioncolumn.hxx @@ -164,7 +164,8 @@ namespace dbaccess public: OQueryColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxParserColumn, - const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, + const ::rtl::OUString& _sNewName ); // XTypeProvider diff --git a/dbaccess/source/core/inc/recovery/dbdocrecovery.hxx b/dbaccess/source/core/inc/recovery/dbdocrecovery.hxx new file mode 100644 index 000000000..afc3ba88a --- /dev/null +++ b/dbaccess/source/core/inc/recovery/dbdocrecovery.hxx @@ -0,0 +1,92 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#ifndef DBACCESS_DBDOCRECOVERY_HXX +#define DBACCESS_DBDOCRECOVERY_HXX + +#include "dbaccessdllapi.h" + +/** === begin UNO includes === **/ +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/frame/XController.hpp> +/** === end UNO includes === **/ + +#include <vector> +#include <memory> + +namespace comphelper +{ + class ComponentContext; +} + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= DatabaseDocumentRecovery + //==================================================================== + struct DatabaseDocumentRecovery_Data; + class DBACCESS_DLLPRIVATE DatabaseDocumentRecovery + { + public: + DatabaseDocumentRecovery( + const ::comphelper::ComponentContext& i_rContext + ); + ~DatabaseDocumentRecovery(); + + /** saves the modified sub components of the given controller(s) to the "recovery" sub storage of the document + storage. + + @throws ::com::sun::star::uno::Exception + in case of an error. + */ + void saveModifiedSubComponents( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rTargetStorage, + const ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > >& i_rControllers + ); + + /** recovery sub components from the given document storage, if applicable + + If the given document storage does not contain a recovery folder, the method silently returns. + + @throws ::com::sun::star::uno::Exception + in case of an error. + */ + void recoverSubDocuments( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rDocumentStorage, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& i_rTargetController + ); + + private: + const ::std::auto_ptr< DatabaseDocumentRecovery_Data > m_pData; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // DBACCESS_DBDOCRECOVERY_HXX diff --git a/dbaccess/source/core/inc/sdbcoretools.hxx b/dbaccess/source/core/inc/sdbcoretools.hxx index d11767bd6..a5f7ad284 100644 --- a/dbaccess/source/core/inc/sdbcoretools.hxx +++ b/dbaccess/source/core/inc/sdbcoretools.hxx @@ -28,8 +28,14 @@ #ifndef DBACORE_SDBCORETOOLS_HXX #define DBACORE_SDBCORETOOLS_HXX +/** === begin UNO includes === **/ #include <com/sun/star/util/XNumberFormatsSupplier.hpp> #include <com/sun/star/sdbc/XConnection.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/io/IOException.hpp> +#include <com/sun/star/lang/WrappedTargetException.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> +/** === end UNO includes === **/ namespace comphelper { @@ -49,32 +55,32 @@ namespace dbaccess getDataSource( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDependentObject ); // ----------------------------------------------------------------------------- - /** retrieves a particular indirect data source setting - - @param _rxDataSource - a data source component - @param _pAsciiSettingsName - the ASCII name of the setting to obtain - @param _rSettingsValue - the value of the setting, upon successfull return - - @return - <FALSE/> if the setting is not present in the <member scope="com::sun::star::sdb">DataSource::Info</member> - member of the data source - <TRUE/> otherwise - */ - bool getDataSourceSetting( - const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDataSource, - const sal_Char* _pAsciiSettingsName, - ::com::sun::star::uno::Any& /* [out] */ _rSettingsValue - ); // ----------------------------------------------------------------------------- /** retrieves a to-be-displayed string for a given caught exception; */ ::rtl::OUString extractExceptionMessage( const ::comphelper::ComponentContext& _rContext, const ::com::sun::star::uno::Any& _rError ); -//......................................................................... + namespace tools + { + namespace stor + { + bool storageIsWritable_nothrow( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage + ); + + /// commits a given storage if it's not readonly + bool commitStorageIfWriteable( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage + ) + SAL_THROW(( + ::com::sun::star::io::IOException, + ::com::sun::star::lang::WrappedTargetException + )); + } + + } + } // namespace dbaccess //......................................................................... diff --git a/dbaccess/source/core/inc/table.hxx b/dbaccess/source/core/inc/table.hxx index 64c0f1407..ec35f805d 100644 --- a/dbaccess/source/core/inc/table.hxx +++ b/dbaccess/source/core/inc/table.hxx @@ -28,58 +28,24 @@ #ifndef _DBA_CORE_TABLE_HXX_ #define _DBA_CORE_TABLE_HXX_ -#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_ #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_ #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XINDEXESSUPPLIER_HPP_ #include <com/sun/star/sdbcx/XIndexesSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XKEYSSUPPLIER_HPP_ #include <com/sun/star/sdbcx/XKeysSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XRENAME_HPP_ #include <com/sun/star/sdbcx/XRename.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XALTERTABLE_HPP_ #include <com/sun/star/sdbcx/XAlterTable.hpp> -#endif -#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ #include <com/sun/star/lang/XServiceInfo.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ #include <com/sun/star/sdbc/XRow.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ #include <com/sun/star/sdbc/XConnection.hpp> -#endif -#ifndef _CPPUHELPER_COMPBASE2_HXX_ #include <cppuhelper/compbase7.hxx> -#endif -#ifndef _DBASHARED_APITOOLS_HXX_ #include "apitools.hxx" -#endif -#ifndef _DBA_CORE_DATASETTINGS_HXX_ #include "datasettings.hxx" -#endif -#ifndef _DBA_COREAPI_COLUMN_HXX_ #include <column.hxx> -#endif -#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ #include <connectivity/CommonTools.hxx> -#endif -#ifndef CONNECTIVITY_TABLEHELPER_HXX #include <connectivity/TTableHelper.hxx> -#endif -#ifndef _COMPHELPER_UNO3_HXX_ #include <comphelper/uno3.hxx> -#endif -#ifndef COMPHELPER_IDPROPERTYARRAYUSAGEHELPER_HXX #include <comphelper/IdPropArrayHelper.hxx> -#endif namespace dbaccess { diff --git a/dbaccess/source/core/misc/DatabaseDataProvider.cxx b/dbaccess/source/core/misc/DatabaseDataProvider.cxx index 0f959a8b5..ec6f6cbb9 100644 --- a/dbaccess/source/core/misc/DatabaseDataProvider.cxx +++ b/dbaccess/source/core/misc/DatabaseDataProvider.cxx @@ -34,6 +34,7 @@ #include <connectivity/FValue.hxx> #include <connectivity/dbtools.hxx> #include <rtl/ustrbuf.hxx> +#include <rtl/math.hxx> #include <com/sun/star/task/XInteractionHandler.hpp> #include <com/sun/star/sdb/XCompletedExecution.hpp> @@ -630,7 +631,14 @@ void DatabaseDataProvider::impl_fillInternalDataProvider_throw(sal_Bool _bHasCat for (sal_Int32 j = _bHasCategories ? 2 : 1,i = 0; j <= nCount; ++j,++i) { aValue.fill(j,aColumnTypes[j-1],xRow); - aRow.push_back(aValue.getDouble()); + if ( aValue.isNull() ) + { + double nValue; + ::rtl::math::setNan( &nValue ); + aRow.push_back(nValue); + } + else + aRow.push_back(aValue.getDouble()); } // for (sal_Int32 j = 2,i = 0; j <= nCount; ++j,++i) aDataValues.push_back(aRow); } // while( xRes->next() && (!m_RowLimit || nRowCount < m_RowLimit) ) diff --git a/dbaccess/source/core/misc/dbastrings.cxx b/dbaccess/source/core/misc/dbastrings.cxx index 8b9ee059c..771da8075 100644 --- a/dbaccess/source/core/misc/dbastrings.cxx +++ b/dbaccess/source/core/misc/dbastrings.cxx @@ -43,6 +43,7 @@ namespace dbaccess //============================================================ //= Properties //============================================================ - IMPLEMENT_CONSTASCII_USTRING(PROPERTY_APPLYFORMDESIGNMODE, "ApplyFormDesignMode"); - + IMPLEMENT_CONSTASCII_USTRING( PROPERTY_APPLYFORMDESIGNMODE, "ApplyFormDesignMode" ); + IMPLEMENT_CONSTASCII_USTRING( PROPERTY_IS_FORM, "IsForm" ); + IMPLEMENT_CONSTASCII_USTRING( PROPERTY_PERSISTENT_PATH, "PersistentPath" ); } diff --git a/dbaccess/source/core/misc/sdbcoretools.cxx b/dbaccess/source/core/misc/sdbcoretools.cxx index f7008f8ad..6fb936cb4 100644 --- a/dbaccess/source/core/misc/sdbcoretools.cxx +++ b/dbaccess/source/core/misc/sdbcoretools.cxx @@ -38,6 +38,8 @@ #include <com/sun/star/util/XModifiable.hpp> #include <com/sun/star/sdb/XDocumentDataSource.hpp> #include <com/sun/star/task/XInteractionRequestStringResolver.hpp> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/embed/ElementModes.hpp> /** === end UNO includes === **/ #include <tools/diagnose_ex.h> @@ -55,10 +57,12 @@ namespace dbaccess using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::util; + using namespace ::com::sun::star::io; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::task; + using namespace ::com::sun::star::embed; using namespace ::com::sun::star::container; // ========================================================================= @@ -88,39 +92,6 @@ namespace dbaccess return xReturn; } - // ------------------------------------------------------------------------- - bool getDataSourceSetting( const Reference< XInterface >& _rxDataSource, const sal_Char* _pAsciiSettingsName, - Any& /* [out] */ _rSettingsValue ) - { - bool bIsPresent = false; - try - { - Reference< XPropertySet > xDataSource( _rxDataSource, UNO_QUERY ); - OSL_ENSURE( xDataSource.is(), "getDataSourceSetting: invalid data source object!" ); - if ( !xDataSource.is() ) - return false; - - Sequence< PropertyValue > aSettings; - OSL_VERIFY( xDataSource->getPropertyValue( PROPERTY_INFO ) >>= aSettings ); - const PropertyValue* pSetting = aSettings.getConstArray(); - const PropertyValue* pSettingEnd = aSettings.getConstArray() + aSettings.getLength(); - for ( ; pSetting != pSettingEnd; ++pSetting ) - { - if ( pSetting->Name.equalsAscii( _pAsciiSettingsName ) ) - { - _rSettingsValue = pSetting->Value; - bIsPresent = true; - break; - } - } - } - catch( const Exception& ) - { - OSL_ENSURE( sal_False, "getDataSourceSetting: caught an exception!" ); - } - return bIsPresent; - } - // ----------------------------------------------------------------------------- ::rtl::OUString extractExceptionMessage( const ::comphelper::ComponentContext& _rContext, const Any& _rError ) { @@ -160,7 +131,44 @@ namespace dbaccess return sDisplayMessage; } -// ----------------------------------------------------------------------------- + namespace tools { namespace stor { + + // ----------------------------------------------------------------------------- + bool storageIsWritable_nothrow( const Reference< XStorage >& _rxStorage ) + { + if ( !_rxStorage.is() ) + return false; + + sal_Int32 nMode = ElementModes::READ; + try + { + Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW ); + xStorageProps->getPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nMode; + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return ( nMode & ElementModes::WRITE ) != 0; + } + + // ----------------------------------------------------------------------------- + bool commitStorageIfWriteable( const Reference< XStorage >& _rxStorage ) SAL_THROW(( IOException, WrappedTargetException, RuntimeException )) + { + bool bSuccess = false; + Reference< XTransactedObject > xTrans( _rxStorage, UNO_QUERY ); + if ( xTrans.is() ) + { + if ( storageIsWritable_nothrow( _rxStorage ) ) + xTrans->commit(); + bSuccess = true; + } + return bSuccess; + } + + } } // tools::stor + //......................................................................... } // namespace dbaccess //......................................................................... diff --git a/dbaccess/source/core/recovery/dbdocrecovery.cxx b/dbaccess/source/core/recovery/dbdocrecovery.cxx new file mode 100644 index 000000000..6833d7faf --- /dev/null +++ b/dbaccess/source/core/recovery/dbdocrecovery.cxx @@ -0,0 +1,436 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "recovery/dbdocrecovery.hxx" +#include "sdbcoretools.hxx" +#include "storagetextstream.hxx" +#include "subcomponentrecovery.hxx" +#include "subcomponents.hxx" +#include "dbastrings.hrc" + +/** === begin UNO includes === **/ +#include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/document/XStorageBasedDocument.hpp> +#include <com/sun/star/io/XTextOutputStream.hpp> +#include <com/sun/star/io/XTextInputStream.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <com/sun/star/io/XActiveDataSink.hpp> +#include <com/sun/star/util/XModifiable.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +/** === end UNO includes === **/ + +#include <comphelper/componentcontext.hxx> +#include <comphelper/namedvaluecollection.hxx> +#include <rtl/ustrbuf.hxx> +#include <tools/diagnose_ex.h> + +#include <algorithm> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::embed::XStorage; + using ::com::sun::star::frame::XController; + using ::com::sun::star::sdb::application::XDatabaseDocumentUI; + using ::com::sun::star::lang::XComponent; + using ::com::sun::star::document::XStorageBasedDocument; + using ::com::sun::star::beans::PropertyValue; + using ::com::sun::star::io::XStream; + using ::com::sun::star::io::XTextOutputStream; + using ::com::sun::star::io::XActiveDataSource; + using ::com::sun::star::io::XTextInputStream; + using ::com::sun::star::io::XActiveDataSink; + using ::com::sun::star::frame::XModel; + using ::com::sun::star::util::XModifiable; + using ::com::sun::star::beans::XPropertySet; + using ::com::sun::star::lang::XMultiServiceFactory; + /** === end UNO using === **/ + + namespace ElementModes = ::com::sun::star::embed::ElementModes; + + //==================================================================== + //= helpers + //==================================================================== + namespace + { + // ......................................................................... + static void lcl_getPersistentRepresentation( const MapStringToCompDesc::value_type& i_rComponentDesc, ::rtl::OUStringBuffer& o_rBuffer ) + { + o_rBuffer.append( i_rComponentDesc.first ); + o_rBuffer.append( sal_Unicode( '=' ) ); + o_rBuffer.append( i_rComponentDesc.second.sName ); + o_rBuffer.append( sal_Unicode( ',' ) ); + o_rBuffer.append( sal_Unicode( i_rComponentDesc.second.bForEditing ? '1' : '0' ) ); + } + + // ......................................................................... + static bool lcl_extractCompDesc( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rStorName, SubComponentDescriptor& o_rCompDesc ) + { + const sal_Int32 nEqualSignPos = i_rIniLine.indexOf( sal_Unicode( '=' ) ); + if ( nEqualSignPos < 1 ) + { + OSL_ENSURE( false, "lcl_extractCompDesc: invalid map file entry - unexpected pos of '='" ); + return false; + } + o_rStorName = i_rIniLine.copy( 0, nEqualSignPos ); + + const sal_Int32 nCommaPos = i_rIniLine.lastIndexOf( sal_Unicode( ',' ) ); + if ( nCommaPos != i_rIniLine.getLength() - 2 ) + { + OSL_ENSURE( false, "lcl_extractCompDesc: invalid map file entry - unexpected pos of ','" ); + return false; + } + o_rCompDesc.sName = i_rIniLine.copy( nEqualSignPos + 1, nCommaPos - nEqualSignPos - 1 ); + o_rCompDesc.bForEditing = ( i_rIniLine.getStr()[ nCommaPos + 1 ] == '1' ); + return true; + } + + // ......................................................................... + static const ::rtl::OUString& lcl_getRecoveryDataSubStorageName() + { + static const ::rtl::OUString s_sRecDataStorName( RTL_CONSTASCII_USTRINGPARAM( "recovery" ) ); + return s_sRecDataStorName; + } + // ......................................................................... + static const ::rtl::OUString& lcl_getObjectMapStreamName() + { + static const ::rtl::OUString s_sObjectMapStreamName( RTL_CONSTASCII_USTRINGPARAM( "storage-component-map.ini" ) ); + return s_sObjectMapStreamName; + } + + // ......................................................................... + static const ::rtl::OUString& lcl_getMapStreamEncodingName() + { + static const ::rtl::OUString s_sMapStreamEncodingName( RTL_CONSTASCII_USTRINGPARAM( "UTF-8" ) ); + return s_sMapStreamEncodingName; + } + + // ......................................................................... + static void lcl_writeObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, + const MapStringToCompDesc& i_mapStorageToCompDesc ) + { + if ( i_mapStorageToCompDesc.empty() ) + // nothing to do + return; + + StorageTextOutputStream aTextOutput( i_rContext, i_rStorage, lcl_getObjectMapStreamName() ); + + aTextOutput.writeLine( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[storages]" ) ) ); + + for ( MapStringToCompDesc::const_iterator stor = i_mapStorageToCompDesc.begin(); + stor != i_mapStorageToCompDesc.end(); + ++stor + ) + { + ::rtl::OUStringBuffer aLine; + lcl_getPersistentRepresentation( *stor, aLine ); + + aTextOutput.writeLine( aLine.makeStringAndClear() ); + } + + aTextOutput.writeLine(); + } + + // ......................................................................... + static bool lcl_isSectionStart( const ::rtl::OUString& i_rIniLine, ::rtl::OUString& o_rSectionName ) + { + const sal_Int32 nLen = i_rIniLine.getLength(); + if ( ( nLen > 0 ) && ( i_rIniLine.getStr()[0] == '[' ) && ( i_rIniLine.getStr()[ nLen - 1 ] == ']' ) ) + { + o_rSectionName = i_rIniLine.copy( 1, nLen -2 ); + return true; + } + return false; + } + + // ......................................................................... + static void lcl_stripTrailingLineFeed( ::rtl::OUString& io_rLine ) + { + const sal_Int32 nLen = io_rLine.getLength(); + if ( ( nLen > 0 ) && ( io_rLine.getStr()[ nLen - 1 ] == '\n' ) ) + io_rLine = io_rLine.copy( 0, nLen - 1 ); + } + + // ......................................................................... + static void lcl_readObjectMap_throw( const ::comphelper::ComponentContext& i_rContext, const Reference< XStorage >& i_rStorage, + MapStringToCompDesc& o_mapStorageToObjectName ) + { + ENSURE_OR_THROW( i_rStorage.is(), "invalid storage" ); + if ( !i_rStorage->hasByName( lcl_getObjectMapStreamName() ) ) + { // nothing to do, though suspicious + OSL_ENSURE( false, "lcl_readObjectMap_throw: if there's no map file, then there's expected to be no storage, too!" ); + return; + } + + Reference< XStream > xIniStream( i_rStorage->openStreamElement( + lcl_getObjectMapStreamName(), ElementModes::READ ), UNO_SET_THROW ); + + Reference< XTextInputStream > xTextInput( i_rContext.createComponent( "com.sun.star.io.TextInputStream" ), UNO_QUERY_THROW ); + xTextInput->setEncoding( lcl_getMapStreamEncodingName() ); + + Reference< XActiveDataSink > xDataSink( xTextInput, UNO_QUERY_THROW ); + xDataSink->setInputStream( xIniStream->getInputStream() ); + + ::rtl::OUString sCurrentSection; + bool bCurrentSectionIsKnownToBeUnsupported = true; + while ( !xTextInput->isEOF() ) + { + ::rtl::OUString sLine = xTextInput->readLine(); + lcl_stripTrailingLineFeed( sLine ); + + if ( sLine.getLength() == 0 ) + continue; + + if ( lcl_isSectionStart( sLine, sCurrentSection ) ) + { + bCurrentSectionIsKnownToBeUnsupported = false; + continue; + } + + if ( bCurrentSectionIsKnownToBeUnsupported ) + continue; + + // the only section we support so far is "storages" + if ( !sCurrentSection.equalsAscii( "storages" ) ) + { + bCurrentSectionIsKnownToBeUnsupported = true; + continue; + } + + ::rtl::OUString sStorageName; + SubComponentDescriptor aCompDesc; + if ( !lcl_extractCompDesc( sLine, sStorageName, aCompDesc ) ) + continue; + o_mapStorageToObjectName[ sStorageName ] = aCompDesc; + } + } + + // ......................................................................... + static void lcl_markModified( const Reference< XComponent >& i_rSubComponent ) + { + const Reference< XModifiable > xModify( i_rSubComponent, UNO_QUERY ); + if ( !xModify.is() ) + { + OSL_ENSURE( false, "lcl_markModified: unhandled case!" ); + return; + } + + xModify->setModified( sal_True ); + } + } + + //==================================================================== + //= DatabaseDocumentRecovery_Data + //==================================================================== + struct DBACCESS_DLLPRIVATE DatabaseDocumentRecovery_Data + { + const ::comphelper::ComponentContext aContext; + + DatabaseDocumentRecovery_Data( const ::comphelper::ComponentContext& i_rContext ) + :aContext( i_rContext ) + { + } + }; + + //==================================================================== + //= DatabaseDocumentRecovery + //==================================================================== + //-------------------------------------------------------------------- + DatabaseDocumentRecovery::DatabaseDocumentRecovery( const ::comphelper::ComponentContext& i_rContext ) + :m_pData( new DatabaseDocumentRecovery_Data( i_rContext ) ) + { + } + + //-------------------------------------------------------------------- + DatabaseDocumentRecovery::~DatabaseDocumentRecovery() + { + } + + //-------------------------------------------------------------------- + void DatabaseDocumentRecovery::saveModifiedSubComponents( const Reference< XStorage >& i_rTargetStorage, + const ::std::vector< Reference< XController > >& i_rControllers ) + { + ENSURE_OR_THROW( i_rTargetStorage.is(), "invalid document storage" ); + + // create a sub storage for recovery data + if ( i_rTargetStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) + i_rTargetStorage->removeElement( lcl_getRecoveryDataSubStorageName() ); + Reference< XStorage > xRecoveryStorage = i_rTargetStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READWRITE ); + + // store recovery data for open sub components of the given controller(s) + if ( !i_rControllers.empty() ) + { + ENSURE_OR_THROW( i_rControllers.size() == 1, "can't handle more than one controller" ); + // At the moment, there can be only one view to a database document. If we ever allow for more than this, + // then we need a concept for sub documents opened from different controllers (i.e. two document views, + // and the user opens the very same form in both views). And depending on this, we need a concept for + // how those are saved to the recovery file. + + MapCompTypeToCompDescs aMapCompDescs; + + for ( ::std::vector< Reference< XController > >::const_iterator ctrl = i_rControllers.begin(); + ctrl != i_rControllers.end(); + ++ctrl + ) + { + Reference< XDatabaseDocumentUI > xDatabaseUI( *ctrl, UNO_QUERY_THROW ); + Sequence< Reference< XComponent > > aComponents( xDatabaseUI->getSubComponents() ); + + const Reference< XComponent >* component = aComponents.getConstArray(); + const Reference< XComponent >* componentEnd = aComponents.getConstArray() + aComponents.getLength(); + for ( ; component != componentEnd; ++component ) + { + SubComponentRecovery aComponentRecovery( m_pData->aContext, xDatabaseUI, *component ); + aComponentRecovery.saveToRecoveryStorage( xRecoveryStorage, aMapCompDescs ); + } + } + + for ( MapCompTypeToCompDescs::const_iterator map = aMapCompDescs.begin(); + map != aMapCompDescs.end(); + ++map + ) + { + Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( + SubComponentRecovery::getComponentsStorageName( map->first ), ElementModes::WRITE | ElementModes::NOCREATE ) ); + lcl_writeObjectMap_throw( m_pData->aContext, xComponentsStor, map->second ); + tools::stor::commitStorageIfWriteable( xComponentsStor ); + } + } + + // commit the recovery storage + tools::stor::commitStorageIfWriteable( xRecoveryStorage ); + } + + //-------------------------------------------------------------------- + void DatabaseDocumentRecovery::recoverSubDocuments( const Reference< XStorage >& i_rDocumentStorage, + const Reference< XController >& i_rTargetController ) + { + ENSURE_OR_THROW( i_rDocumentStorage.is(), "illegal document storage" ); + Reference< XDatabaseDocumentUI > xDocumentUI( i_rTargetController, UNO_QUERY_THROW ); + + if ( !i_rDocumentStorage->hasByName( lcl_getRecoveryDataSubStorageName() ) ) + // that's allowed + return; + + // the "recovery" sub storage + Reference< XStorage > xRecoveryStorage = i_rDocumentStorage->openStorageElement( lcl_getRecoveryDataSubStorageName(), ElementModes::READ ); + + // read the map from sub storages to object names + MapCompTypeToCompDescs aMapCompDescs; + SubComponentType aKnownTypes[] = { TABLE, QUERY, FORM, REPORT, RELATION_DESIGN }; + for ( size_t i = 0; i < sizeof( aKnownTypes ) / sizeof( aKnownTypes[0] ); ++i ) + { + if ( !xRecoveryStorage->hasByName( SubComponentRecovery::getComponentsStorageName( aKnownTypes[i] ) ) ) + continue; + + Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( + SubComponentRecovery::getComponentsStorageName( aKnownTypes[i] ), ElementModes::READ ) ); + lcl_readObjectMap_throw( m_pData->aContext, xComponentsStor, aMapCompDescs[ aKnownTypes[i] ] ); + xComponentsStor->dispose(); + } + + // recover all sub components as indicated by the map + for ( MapCompTypeToCompDescs::const_iterator map = aMapCompDescs.begin(); + map != aMapCompDescs.end(); + ++map + ) + { + const SubComponentType eComponentType = map->first; + + // the storage for all components of the current type + Reference< XStorage > xComponentsStor( xRecoveryStorage->openStorageElement( + SubComponentRecovery::getComponentsStorageName( eComponentType ), ElementModes::READ ), UNO_QUERY_THROW ); + + // loop thru all components of this type + for ( MapStringToCompDesc::const_iterator stor = map->second.begin(); + stor != map->second.end(); + ++stor + ) + { + const ::rtl::OUString sComponentName( stor->second.sName ); + if ( !xComponentsStor->hasByName( stor->first ) ) + { + #if OSL_DEBUG_LEVEL > 0 + ::rtl::OStringBuffer message; + message.append( "DatabaseDocumentRecovery::recoverSubDocuments: inconsistent recovery storage: storage '" ); + message.append( ::rtl::OUStringToOString( stor->first, RTL_TEXTENCODING_ASCII_US ) ); + message.append( "' not found in '" ); + message.append( ::rtl::OUStringToOString( SubComponentRecovery::getComponentsStorageName( eComponentType ), RTL_TEXTENCODING_ASCII_US ) ); + message.append( "', but required per map file!" ); + OSL_ENSURE( false, message.makeStringAndClear() ); + #endif + continue; + } + + // the controller needs to have a connection to be able to open sub components + if ( !xDocumentUI->isConnected() ) + xDocumentUI->connect(); + + // recover the single component + Reference< XStorage > xCompStor( xComponentsStor->openStorageElement( stor->first, ElementModes::READ ) ); + SubComponentRecovery aComponentRecovery( m_pData->aContext, xDocumentUI, eComponentType ); + Reference< XComponent > xSubComponent( aComponentRecovery.recoverFromStorage( xCompStor, sComponentName, stor->second.bForEditing ) ); + + // at the moment, we only store, during session save, sub components which are modified. So, set this + // recovered sub component to "modified", too. + lcl_markModified( xSubComponent ); + } + + xComponentsStor->dispose(); + } + + xRecoveryStorage->dispose(); + + // now that we successfully recovered, removed the "recovery" sub storage + try + { + i_rDocumentStorage->removeElement( lcl_getRecoveryDataSubStorageName() ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/recovery/makefile.mk b/dbaccess/source/core/recovery/makefile.mk new file mode 100644 index 000000000..c13334bbc --- /dev/null +++ b/dbaccess/source/core/recovery/makefile.mk @@ -0,0 +1,58 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.10.2.3 $ +# +# This file is part of OpenOffice.org. +# +# 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. +# +# 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). +# +# 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. +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJINC=$(PRJ)$/source +PRJNAME=dbaccess +TARGET=recovery + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/dba.pmk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/dbdocrecovery.obj \ + $(SLO)$/subcomponentloader.obj \ + $(SLO)$/storagestream.obj \ + $(SLO)$/storagexmlstream.obj \ + $(SLO)$/storagetextstream.obj \ + $(SLO)$/subcomponentrecovery.obj \ + $(SLO)$/settingsimport.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/dbaccess/source/core/recovery/settingsimport.cxx b/dbaccess/source/core/recovery/settingsimport.cxx new file mode 100644 index 000000000..c30792b78 --- /dev/null +++ b/dbaccess/source/core/recovery/settingsimport.cxx @@ -0,0 +1,294 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "settingsimport.hxx" + +/** === begin UNO includes === **/ +/** === end UNO includes === **/ + +#include <tools/diagnose_ex.h> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::xml::sax::XAttributeList; + /** === end UNO using === **/ + + //==================================================================== + //= SettingsImport + //==================================================================== + //-------------------------------------------------------------------- + SettingsImport::SettingsImport() + :m_refCount( 0 ) + { + } + + //-------------------------------------------------------------------- + SettingsImport::~SettingsImport() + { + } + + //-------------------------------------------------------------------- + oslInterlockedCount SAL_CALL SettingsImport::acquire() + { + return osl_incrementInterlockedCount( &m_refCount ); + } + + //-------------------------------------------------------------------- + oslInterlockedCount SAL_CALL SettingsImport::release() + { + oslInterlockedCount newCount = osl_decrementInterlockedCount( &m_refCount ); + if ( newCount == 0 ) + delete this; + return newCount; + } + + //-------------------------------------------------------------------- + void SettingsImport::startElement( const Reference< XAttributeList >& i_rAttributes ) + { + // find the name of the setting + if ( i_rAttributes.is() ) + { + m_sItemName = i_rAttributes->getValueByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "config:name" ) ) ); + m_sItemType = i_rAttributes->getValueByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "config:type" ) ) ); + } + } + + //-------------------------------------------------------------------- + void SettingsImport::endElement() + { + } + + //-------------------------------------------------------------------- + void SettingsImport::characters( const ::rtl::OUString& i_rCharacters ) + { + m_aCharacters.append( i_rCharacters ); + } + + //-------------------------------------------------------------------- + void SettingsImport::split( const ::rtl::OUString& i_rElementName, ::rtl::OUString& o_rNamespace, ::rtl::OUString& o_rLocalName ) + { + o_rNamespace = ::rtl::OUString(); + o_rLocalName = i_rElementName; + const sal_Int32 nSeparatorPos = i_rElementName.indexOf( ':' ); + if ( nSeparatorPos > -1 ) + { + o_rNamespace = i_rElementName.copy( 0, nSeparatorPos ); + o_rLocalName = i_rElementName.copy( nSeparatorPos + 1 ); + } + + OSL_ENSURE( o_rNamespace.equalsAscii( "config" ), "SettingsImport::split: unexpected namespace!" ); + // our recovery file is kind of hand-made, so there shouldn't be anything else than "config". + // If there is, then just ignore it ... + } + + //==================================================================== + //= IgnoringSettingsImport + //==================================================================== + //-------------------------------------------------------------------- + ::rtl::Reference< SettingsImport > IgnoringSettingsImport::nextState( const ::rtl::OUString& i_rElementName ) + { + (void)i_rElementName; + return this; + } + + //==================================================================== + //= OfficeSettingsImport + //==================================================================== + //-------------------------------------------------------------------- + OfficeSettingsImport::OfficeSettingsImport( ::comphelper::NamedValueCollection& o_rSettings ) + :m_rSettings( o_rSettings ) + { + } + + //-------------------------------------------------------------------- + OfficeSettingsImport::~OfficeSettingsImport() + { + } + + //-------------------------------------------------------------------- + ::rtl::Reference< SettingsImport > OfficeSettingsImport::nextState( const ::rtl::OUString& i_rElementName ) + { + // separate the namespace part from the element name + ::rtl::OUString sNamespace; + ::rtl::OUString sLocalName; + split( i_rElementName, sNamespace, sLocalName ); + + if ( sLocalName.equalsAscii( "config-item-set" ) ) + return new ConfigItemSetImport( m_rSettings ); + +#if OSL_DEBUG_LEVEL > 0 + ::rtl::OString sMessage( "unknown (or unsupported at this place) element name '" ); + sMessage += ::rtl::OUStringToOString( i_rElementName, RTL_TEXTENCODING_UTF8 ); + sMessage += "', ignoring"; + OSL_ENSURE( false, sMessage.getStr() ); +#endif + return new IgnoringSettingsImport; + } + + //==================================================================== + //= ConfigItemImport + //==================================================================== + //-------------------------------------------------------------------- + ConfigItemImport::ConfigItemImport( ::comphelper::NamedValueCollection& o_rSettings ) + :m_rSettings( o_rSettings ) + { + } + + //-------------------------------------------------------------------- + ConfigItemImport::~ConfigItemImport() + { + } + + //-------------------------------------------------------------------- + ::rtl::Reference< SettingsImport > ConfigItemImport::nextState( const ::rtl::OUString& i_rElementName ) + { + OSL_ENSURE( false, "ConfigItemImport::nextState: unexpected: this class is responsible for child-less items only!" ); + (void)i_rElementName; + return new IgnoringSettingsImport; + } + + //-------------------------------------------------------------------- + void ConfigItemImport::endElement() + { + SettingsImport::endElement(); + + const ::rtl::OUString sItemName( getItemName() ); + ENSURE_OR_RETURN_VOID( sItemName.getLength(), "no item name -> no item value" ); + Any aValue; + getItemValue( aValue ); + m_rSettings.put( sItemName, aValue ); + } + + //-------------------------------------------------------------------- + void ConfigItemImport::getItemValue( ::com::sun::star::uno::Any& o_rValue ) const + { + o_rValue.clear(); + + // the characters building up th evalue + ::rtl::OUStringBuffer aCharacters( getAccumulatedCharacters() ); + const ::rtl::OUString sValue = aCharacters.makeStringAndClear(); + + const ::rtl::OUString& rItemType( getItemType() ); + ENSURE_OR_RETURN_VOID( rItemType.getLength(), "no item type -> no item value" ); + + if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_INT ) ) + { + sal_Int32 nValue(0); + if ( SvXMLUnitConverter::convertNumber( nValue, sValue ) ) + o_rValue <<= nValue; + else + { + OSL_ENSURE( false, "ConfigItemImport::getItemValue: could not convert an int value!" ); + } + } + else if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_BOOLEAN ) ) + { + sal_Bool nValue( sal_False ); + if ( SvXMLUnitConverter::convertBool( nValue, sValue ) ) + o_rValue <<= nValue; + else + { + OSL_ENSURE( false, "ConfigItemImport::getItemValue: could not convert a boolean value!" ); + } + } + else if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_STRING ) ) + { + o_rValue <<= sValue; + } +#if OSL_DEBUG_LEVEL > 0 + else + { + ::rtl::OString sMessage( "ConfigItemImport::getItemValue: unsupported item type '" ); + sMessage += ::rtl::OUStringToOString( rItemType, RTL_TEXTENCODING_UTF8 ); + sMessage += "', ignoring"; + OSL_ENSURE( false, sMessage.getStr() ); + } +#endif + } + + //==================================================================== + //= ConfigItemSetImport + //==================================================================== + //-------------------------------------------------------------------- + ConfigItemSetImport::ConfigItemSetImport( ::comphelper::NamedValueCollection& o_rSettings ) + :ConfigItemImport( o_rSettings ) + { + } + + //-------------------------------------------------------------------- + ConfigItemSetImport::~ConfigItemSetImport() + { + } + + //-------------------------------------------------------------------- + ::rtl::Reference< SettingsImport > ConfigItemSetImport::nextState( const ::rtl::OUString& i_rElementName ) + { + // separate the namespace part from the element name + ::rtl::OUString sNamespace; + ::rtl::OUString sLocalName; + split( i_rElementName, sNamespace, sLocalName ); + + if ( sLocalName.equalsAscii( "config-item-set" ) ) + return new ConfigItemSetImport( m_aChildSettings ); + if ( sLocalName.equalsAscii( "config-item" ) ) + return new ConfigItemImport( m_aChildSettings ); + +#if OSL_DEBUG_LEVEL > 0 + ::rtl::OString sMessage( "unknown element name '" ); + sMessage += ::rtl::OUStringToOString( i_rElementName, RTL_TEXTENCODING_UTF8 ); + sMessage += "', ignoring"; + OSL_ENSURE( false, sMessage.getStr() ); +#endif + return new IgnoringSettingsImport; + } + + //-------------------------------------------------------------------- + void ConfigItemSetImport::getItemValue( Any& o_rValue ) const + { + o_rValue <<= m_aChildSettings.getPropertyValues(); + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/recovery/settingsimport.hxx b/dbaccess/source/core/recovery/settingsimport.hxx new file mode 100644 index 000000000..372f084f7 --- /dev/null +++ b/dbaccess/source/core/recovery/settingsimport.hxx @@ -0,0 +1,190 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#ifndef SETTINGSIMPORT_HXX +#define SETTINGSIMPORT_HXX + +/** === begin UNO includes === **/ +#include <com/sun/star/xml/sax/XAttributeList.hpp> +/** === end UNO includes === **/ + +#include <comphelper/namedvaluecollection.hxx> +#include <rtl/ref.hxx> +#include <rtl/ustrbuf.hxx> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= SettingsImport + //==================================================================== + /** a simplified version of xmloff/DocumentSettingsContext + + It would be nice if the DocumentSettingsContext would not be that tightly interwoven with the SvXMLImport + class, so we could re-use it here ... + */ + class SettingsImport : public ::rtl::IReference + { + public: + SettingsImport(); + + // IReference + virtual oslInterlockedCount SAL_CALL acquire(); + virtual oslInterlockedCount SAL_CALL release(); + + // own overriables + virtual ::rtl::Reference< SettingsImport > nextState( + const ::rtl::OUString& i_rElementName + ) = 0; + virtual void startElement( + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& i_rAttributes + ); + virtual void endElement(); + virtual void characters( const ::rtl::OUString& i_rCharacters ); + + protected: + virtual ~SettingsImport(); + + protected: + static void split( const ::rtl::OUString& i_rElementName, ::rtl::OUString& o_rNamespace, ::rtl::OUString& o_rLocalName ); + + protected: + const ::rtl::OUString& getItemName() const { return m_sItemName; } + const ::rtl::OUString& getItemType() const { return m_sItemType; } + const ::rtl::OUStringBuffer& getAccumulatedCharacters() const { return m_aCharacters; } + + private: + oslInterlockedCount m_refCount; + // value of the config:name attribute, if any + ::rtl::OUString m_sItemName; + // value of the config:type attribute, if any + ::rtl::OUString m_sItemType; + // accumulated characters, if any + ::rtl::OUStringBuffer m_aCharacters; + }; + + //==================================================================== + //= IgnoringSettingsImport + //==================================================================== + class IgnoringSettingsImport : public SettingsImport + { + public: + IgnoringSettingsImport() + { + } + + // SettingsImport overridables + virtual ::rtl::Reference< SettingsImport > nextState( + const ::rtl::OUString& i_rElementName + ); + + private: + ~IgnoringSettingsImport() + { + } + }; + + //==================================================================== + //= OfficeSettingsImport + //==================================================================== + class OfficeSettingsImport : public SettingsImport + { + public: + OfficeSettingsImport( ::comphelper::NamedValueCollection& o_rSettings ); + + // SettingsImport overridables + virtual ::rtl::Reference< SettingsImport > nextState( + const ::rtl::OUString& i_rElementName + ); + + protected: + ~OfficeSettingsImport(); + + private: + // the settings collection to which |this| will contribute a single setting + ::comphelper::NamedValueCollection& m_rSettings; + }; + + //==================================================================== + //= ConfigItemSetImport + //==================================================================== + class ConfigItemImport : public SettingsImport + { + public: + ConfigItemImport( ::comphelper::NamedValueCollection& o_rSettings ); + + protected: + ~ConfigItemImport(); + + public: + // SettingsImport overridables + virtual ::rtl::Reference< SettingsImport > nextState( + const ::rtl::OUString& i_rElementName + ); + virtual void endElement(); + + protected: + // own overridables + /// retrieves the value represented by the element + virtual void getItemValue( ::com::sun::star::uno::Any& o_rValue ) const; + + private: + // the settings collection to which |this| will contribute a single setting + ::comphelper::NamedValueCollection& m_rSettings; + }; + + //==================================================================== + //= ConfigItemSetImport + //==================================================================== + class ConfigItemSetImport : public ConfigItemImport + { + public: + ConfigItemSetImport( ::comphelper::NamedValueCollection& o_rSettings ); + + protected: + ~ConfigItemSetImport(); + + public: + // SettingsImport overridables + virtual ::rtl::Reference< SettingsImport > nextState( + const ::rtl::OUString& i_rElementName + ); + + protected: + // ConfigItemImport overridables + virtual void getItemValue( ::com::sun::star::uno::Any& o_rValue ) const; + + private: + /// the settings represented by our child elements + ::comphelper::NamedValueCollection m_aChildSettings; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // SETTINGSIMPORT_HXX diff --git a/dbaccess/source/core/recovery/storagestream.cxx b/dbaccess/source/core/recovery/storagestream.cxx new file mode 100644 index 000000000..c02569b3b --- /dev/null +++ b/dbaccess/source/core/recovery/storagestream.cxx @@ -0,0 +1,126 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "storagestream.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/embed/ElementModes.hpp> +/** === end UNO includes === **/ + +#include <tools/diagnose_ex.h> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::embed::XStorage; + using ::com::sun::star::io::XStream; + /** === end UNO using === **/ + namespace ElementModes = ::com::sun::star::embed::ElementModes; + + //==================================================================== + //= StorageOutputStream + //==================================================================== + //-------------------------------------------------------------------- + StorageOutputStream::StorageOutputStream( const ::comphelper::ComponentContext& i_rContext, + const Reference< XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ) + :m_rContext( i_rContext ) + { + ENSURE_OR_THROW( i_rParentStorage.is(), "illegal stream" ); + + const Reference< XStream > xStream( + i_rParentStorage->openStreamElement( i_rStreamName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + m_xOutputStream.set( xStream->getOutputStream(), UNO_SET_THROW ); + } + + //-------------------------------------------------------------------- + StorageOutputStream::~StorageOutputStream() + { + } + + //-------------------------------------------------------------------- + void StorageOutputStream::close() + { + ENSURE_OR_RETURN_VOID( m_xOutputStream.is(), "already closed" ); + m_xOutputStream->closeOutput(); + m_xOutputStream.clear(); + + // if you add additional functionality here, be aware that there are derived classes which + // (legitimately) do not call this method here. + } + + //==================================================================== + //= StorageInputStream + //==================================================================== + //-------------------------------------------------------------------- + StorageInputStream::StorageInputStream( const ::comphelper::ComponentContext& i_rContext, + const Reference< XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ) + :m_rContext( i_rContext ) + { + ENSURE_OR_THROW( i_rParentStorage.is(), "illegal stream" ); + + const Reference< XStream > xStream( + i_rParentStorage->openStreamElement( i_rStreamName, ElementModes::READ ), UNO_QUERY_THROW ); + m_xInputStream.set( xStream->getInputStream(), UNO_SET_THROW ); + } + + //-------------------------------------------------------------------- + StorageInputStream::~StorageInputStream() + { + } + + //-------------------------------------------------------------------- + void StorageInputStream::close() + { + ENSURE_OR_RETURN_VOID( m_xInputStream.is(), "already closed" ); + m_xInputStream->closeInput(); + m_xInputStream.clear(); + + // if you add additional functionality here, be aware that there are derived classes which + // (legitimately) do not call this method here. + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/recovery/storagestream.hxx b/dbaccess/source/core/recovery/storagestream.hxx new file mode 100644 index 000000000..91503221f --- /dev/null +++ b/dbaccess/source/core/recovery/storagestream.hxx @@ -0,0 +1,109 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#ifndef STORAGESTREAM_HXX +#define STORAGESTREAM_HXX + +#include "dbaccessdllapi.h" + +/** === begin UNO includes === **/ +#include <com/sun/star/embed/XStorage.hpp> +/** === end UNO includes === **/ + +namespace comphelper +{ + class ComponentContext; +} + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= StorageOutputStream + //==================================================================== + /** convenience wrapper around a stream living in a storage + */ + class DBACCESS_DLLPRIVATE StorageOutputStream + { + public: + StorageOutputStream( + const ::comphelper::ComponentContext& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ); + virtual ~StorageOutputStream(); + + /** simply calls closeOutput on our output stream, override to extend/modify this behavior + */ + virtual void close(); + + protected: + const ::comphelper::ComponentContext& getContext() const { return m_rContext; } + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& + getOutputStream() const { return m_xOutputStream; } + + private: + const ::comphelper::ComponentContext& m_rContext; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > + m_xOutputStream; + }; + + //==================================================================== + //= StorageInputStream + //==================================================================== + /** convenience wrapper around a stream living in a storage + */ + class DBACCESS_DLLPRIVATE StorageInputStream + { + public: + StorageInputStream( + const ::comphelper::ComponentContext& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ); + virtual ~StorageInputStream(); + + /** simply calls closeInput on our input stream, override to extend/modify this behavior + */ + virtual void close(); + + protected: + const ::comphelper::ComponentContext& getContext() const { return m_rContext; } + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& + getInputStream() const { return m_xInputStream; } + + private: + const ::comphelper::ComponentContext& m_rContext; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > + m_xInputStream; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // STORAGESTREAM_HXX diff --git a/dbaccess/source/core/recovery/storagetextstream.cxx b/dbaccess/source/core/recovery/storagetextstream.cxx new file mode 100644 index 000000000..0a680a192 --- /dev/null +++ b/dbaccess/source/core/recovery/storagetextstream.cxx @@ -0,0 +1,130 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "storagetextstream.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/io/XTextOutputStream.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +/** === end UNO includes === **/ + +#include <comphelper/componentcontext.hxx> +#include <tools/diagnose_ex.h> + +//...................................................................................................................... +namespace dbaccess +{ +//...................................................................................................................... + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::embed::XStorage; + using ::com::sun::star::io::XTextOutputStream; + using ::com::sun::star::io::XActiveDataSource; + /** === end UNO using === **/ + + //================================================================================================================== + //= StorageTextOutputStream_Data + //================================================================================================================== + struct StorageTextOutputStream_Data + { + Reference< XTextOutputStream > xTextOutput; + }; + + //================================================================================================================== + //= helper + //================================================================================================================== + namespace + { + //-------------------------------------------------------------------------------------------------------------- + static const ::rtl::OUString& lcl_getTextStreamEncodingName() + { + static const ::rtl::OUString s_sMapStreamEncodingName( RTL_CONSTASCII_USTRINGPARAM( "UTF-8" ) ); + return s_sMapStreamEncodingName; + } + + //-------------------------------------------------------------------------------------------------------------- + static const ::rtl::OUString& lcl_getLineFeed() + { + static const ::rtl::OUString s_sLineFeed( sal_Unicode( '\n' ) ); + return s_sLineFeed; + } + } + + //================================================================================================================== + //= StorageTextOutputStream + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + StorageTextOutputStream::StorageTextOutputStream( const ::comphelper::ComponentContext& i_rContext, + const Reference< XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ) + :StorageOutputStream( i_rContext, i_rParentStorage, i_rStreamName ) + ,m_pData( new StorageTextOutputStream_Data ) + { + m_pData->xTextOutput.set( i_rContext.createComponent( "com.sun.star.io.TextOutputStream" ), UNO_QUERY_THROW ); + m_pData->xTextOutput->setEncoding( lcl_getTextStreamEncodingName() ); + + Reference< XActiveDataSource > xDataSource( m_pData->xTextOutput, UNO_QUERY_THROW ); + xDataSource->setOutputStream( getOutputStream() ); + } + + //------------------------------------------------------------------------------------------------------------------ + StorageTextOutputStream::~StorageTextOutputStream() + { + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageTextOutputStream::writeLine( const ::rtl::OUString& i_rLine ) + { + ENSURE_OR_RETURN_VOID( m_pData->xTextOutput.is(), "no text output" ); + + m_pData->xTextOutput->writeString( i_rLine ); + m_pData->xTextOutput->writeString( lcl_getLineFeed() ); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageTextOutputStream::writeLine() + { + ENSURE_OR_RETURN_VOID( m_pData->xTextOutput.is(), "no text output" ); + + m_pData->xTextOutput->writeString( lcl_getLineFeed() ); + } + +//...................................................................................................................... +} // namespace dbaccess +//...................................................................................................................... diff --git a/dbaccess/source/core/recovery/storagetextstream.hxx b/dbaccess/source/core/recovery/storagetextstream.hxx new file mode 100644 index 000000000..19ec4bcdc --- /dev/null +++ b/dbaccess/source/core/recovery/storagetextstream.hxx @@ -0,0 +1,66 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#ifndef STORAGETEXTSTREAM_HXX +#define STORAGETEXTSTREAM_HXX + +#include "storagestream.hxx" + +/** === begin UNO includes === **/ +/** === end UNO includes === **/ + +#include <memory> + +//...................................................................................................................... +namespace dbaccess +{ +//...................................................................................................................... + + //================================================================================================================== + //= StorageTextStream + //================================================================================================================== + struct StorageTextOutputStream_Data; + class DBACCESS_DLLPRIVATE StorageTextOutputStream : public StorageOutputStream + { + public: + StorageTextOutputStream( + const ::comphelper::ComponentContext& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ); + ~StorageTextOutputStream(); + + void writeLine( const ::rtl::OUString& i_rLine ); + void writeLine(); + + private: + ::std::auto_ptr< StorageTextOutputStream_Data > m_pData; + }; + +//...................................................................................................................... +} // namespace dbaccess +//...................................................................................................................... + +#endif // STORAGETEXTSTREAM_HXX diff --git a/dbaccess/source/core/recovery/storagexmlstream.cxx b/dbaccess/source/core/recovery/storagexmlstream.cxx new file mode 100644 index 000000000..47a326842 --- /dev/null +++ b/dbaccess/source/core/recovery/storagexmlstream.cxx @@ -0,0 +1,197 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "storagexmlstream.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <com/sun/star/xml/sax/XParser.hpp> +/** === end UNO includes === **/ + +#include <comphelper/componentcontext.hxx> +#include <cppuhelper/implbase1.hxx> +#include <rtl/ref.hxx> +#include <tools/diagnose_ex.h> +#include <xmloff/attrlist.hxx> + +#include <stack> + +//...................................................................................................................... +namespace dbaccess +{ +//...................................................................................................................... + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::embed::XStorage; + using ::com::sun::star::xml::sax::XDocumentHandler; + using ::com::sun::star::xml::sax::XAttributeList; + using ::com::sun::star::io::XStream; + using ::com::sun::star::io::XOutputStream; + using ::com::sun::star::io::XActiveDataSource; + using ::com::sun::star::xml::sax::XParser; + using ::com::sun::star::xml::sax::InputSource; + /** === end UNO using === **/ + + //================================================================================================================== + //= StorageXMLOutputStream_Data + //================================================================================================================== + struct StorageXMLOutputStream_Data + { + Reference< XDocumentHandler > xHandler; + ::std::stack< ::rtl::OUString > aElements; + ::rtl::Reference< SvXMLAttributeList > xAttributes; + }; + + //================================================================================================================== + //= StorageXMLOutputStream + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + StorageXMLOutputStream::StorageXMLOutputStream( const ::comphelper::ComponentContext& i_rContext, + const Reference< XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName ) + :StorageOutputStream( i_rContext, i_rParentStorage, i_rStreamName ) + ,m_pData( new StorageXMLOutputStream_Data ) + { + const Reference< XActiveDataSource > xSaxWriter( i_rContext.createComponent( "com.sun.star.xml.sax.Writer" ), UNO_QUERY_THROW ); + xSaxWriter->setOutputStream( getOutputStream() ); + + m_pData->xHandler.set( xSaxWriter, UNO_QUERY_THROW ); + m_pData->xHandler->startDocument(); + + m_pData->xAttributes = new SvXMLAttributeList; + } + + //------------------------------------------------------------------------------------------------------------------ + StorageXMLOutputStream::~StorageXMLOutputStream() + { + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::close() + { + ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "illegal document handler" ); + m_pData->xHandler->endDocument(); + // do not call the base class, it would call closeOutput on the output stream, which is already done by + // endDocument + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::addAttribute( const ::rtl::OUString& i_rName, const ::rtl::OUString& i_rValue ) const + { + m_pData->xAttributes->AddAttribute( i_rName, i_rValue ); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::startElement( const ::rtl::OUString& i_rElementName ) const + { + ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" ); + + m_pData->xHandler->startElement( i_rElementName, m_pData->xAttributes.get() ); + m_pData->xAttributes = new SvXMLAttributeList; + m_pData->aElements.push( i_rElementName ); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::endElement() const + { + ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" ); + ENSURE_OR_RETURN_VOID( !m_pData->aElements.empty(), "no element on the stack" ); + + const ::rtl::OUString sElementName( m_pData->aElements.top() ); + m_pData->xHandler->endElement( sElementName ); + m_pData->aElements.pop(); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::ignorableWhitespace( const ::rtl::OUString& i_rWhitespace ) const + { + ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" ); + + m_pData->xHandler->ignorableWhitespace( i_rWhitespace ); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLOutputStream::characters( const ::rtl::OUString& i_rCharacters ) const + { + ENSURE_OR_RETURN_VOID( m_pData->xHandler.is(), "no document handler" ); + + m_pData->xHandler->characters( i_rCharacters ); + } + + //================================================================================================================== + //= StorageXMLInputStream_Data + //================================================================================================================== + struct StorageXMLInputStream_Data + { + Reference< XParser > xParser; + }; + + //================================================================================================================== + //= StorageXMLInputStream + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + StorageXMLInputStream::StorageXMLInputStream( const ::comphelper::ComponentContext& i_rContext, + const Reference< XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName ) + :StorageInputStream( i_rContext, i_rParentStorage, i_rStreamName ) + ,m_pData( new StorageXMLInputStream_Data ) + { + m_pData->xParser.set( i_rContext.createComponent( "com.sun.star.xml.sax.Parser" ), UNO_QUERY_THROW ); + } + + //------------------------------------------------------------------------------------------------------------------ + void StorageXMLInputStream::import( const Reference< XDocumentHandler >& i_rHandler ) + { + ENSURE_OR_THROW( i_rHandler.is(), "illegal document handler (NULL)" ); + + InputSource aInputSource; + aInputSource.aInputStream = getInputStream(); + + m_pData->xParser->setDocumentHandler( i_rHandler ); + m_pData->xParser->parseStream( aInputSource ); + } + + //------------------------------------------------------------------------------------------------------------------ + StorageXMLInputStream::~StorageXMLInputStream() + { + } + +//...................................................................................................................... +} // namespace dbaccess +//...................................................................................................................... diff --git a/dbaccess/source/core/recovery/storagexmlstream.hxx b/dbaccess/source/core/recovery/storagexmlstream.hxx new file mode 100644 index 000000000..572c86a69 --- /dev/null +++ b/dbaccess/source/core/recovery/storagexmlstream.hxx @@ -0,0 +1,113 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#ifndef STORAGEXMLSTREAM_HXX +#define STORAGEXMLSTREAM_HXX + +#include "storagestream.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +/** === end UNO includes === **/ + +#include <memory> + +namespace comphelper +{ + class ComponentContext; +} + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= StorageXMLOutputStream + //==================================================================== + struct StorageXMLOutputStream_Data; + class DBACCESS_DLLPRIVATE StorageXMLOutputStream : public StorageOutputStream + { + public: + StorageXMLOutputStream( + const ::comphelper::ComponentContext& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ); + ~StorageXMLOutputStream(); + + // StorageOutputStream overridables + virtual void close(); + + void addAttribute( const ::rtl::OUString& i_rName, const ::rtl::OUString& i_rValue ) const; + + void startElement( const ::rtl::OUString& i_rElementName ) const; + void endElement() const; + + void ignorableWhitespace( const ::rtl::OUString& i_rWhitespace ) const; + void characters( const ::rtl::OUString& i_rCharacters ) const; + + private: + StorageXMLOutputStream(); // never implemented + StorageXMLOutputStream( const StorageXMLOutputStream& ); // never implemented + StorageXMLOutputStream& operator=( const StorageXMLOutputStream& ); // never implemented + + private: + ::std::auto_ptr< StorageXMLOutputStream_Data > m_pData; + }; + + //==================================================================== + //= StorageXMLInputStream + //==================================================================== + struct StorageXMLInputStream_Data; + class DBACCESS_DLLPRIVATE StorageXMLInputStream : public StorageInputStream + { + public: + StorageXMLInputStream( + const ::comphelper::ComponentContext& i_rContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rParentStorage, + const ::rtl::OUString& i_rStreamName + ); + ~StorageXMLInputStream(); + + void import( + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& i_rHandler + ); + + private: + StorageXMLInputStream(); // never implemented + StorageXMLInputStream( const StorageXMLInputStream& ); // never implemented + StorageXMLInputStream& operator=( const StorageXMLInputStream& ); // never implemented + + private: + ::std::auto_ptr< StorageXMLInputStream_Data > m_pData; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // STORAGEXMLSTREAM_HXX diff --git a/dbaccess/source/core/recovery/subcomponentloader.cxx b/dbaccess/source/core/recovery/subcomponentloader.cxx new file mode 100644 index 000000000..5ea946f2e --- /dev/null +++ b/dbaccess/source/core/recovery/subcomponentloader.cxx @@ -0,0 +1,200 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "subcomponentloader.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/ucb/Command.hpp> +#include <com/sun/star/frame/XController2.hpp> +/** === end UNO includes === **/ + +#include <tools/diagnose_ex.h> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::frame::XController; + using ::com::sun::star::frame::XFrame; + using ::com::sun::star::awt::XWindow; + using ::com::sun::star::awt::WindowEvent; + using ::com::sun::star::lang::EventObject; + using ::com::sun::star::ucb::Command; + using ::com::sun::star::ucb::XCommandProcessor; + using ::com::sun::star::frame::XController2; + using ::com::sun::star::lang::XComponent; + /** === end UNO using === **/ + + //==================================================================== + //= SubComponentLoader + //==================================================================== + struct DBACCESS_DLLPRIVATE SubComponentLoader_Data + { + const Reference< XCommandProcessor > xDocDefCommands; + const Reference< XComponent > xNonDocComponent; + Reference< XWindow > xAppComponentWindow; + + SubComponentLoader_Data( const Reference< XCommandProcessor >& i_rDocumentDefinition ) + :xDocDefCommands( i_rDocumentDefinition, UNO_SET_THROW ) + ,xNonDocComponent() + { + } + + SubComponentLoader_Data( const Reference< XComponent >& i_rNonDocumentComponent ) + :xDocDefCommands() + ,xNonDocComponent( i_rNonDocumentComponent, UNO_SET_THROW ) + { + } + }; + + //==================================================================== + //= helper + //==================================================================== + namespace + { + //................................................................ + void lcl_onWindowShown_nothrow( const SubComponentLoader_Data& i_rData ) + { + try + { + if ( i_rData.xDocDefCommands.is() ) + { + Command aCommandOpen; + aCommandOpen.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "show" ) ); + + const sal_Int32 nCommandIdentifier = i_rData.xDocDefCommands->createCommandIdentifier(); + i_rData.xDocDefCommands->execute( aCommandOpen, nCommandIdentifier, NULL ); + } + else + { + const Reference< XController > xController( i_rData.xNonDocComponent, UNO_QUERY_THROW ); + const Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW ); + const Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_SET_THROW ); + xWindow->setVisible( sal_True ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + } + + //==================================================================== + //= SubComponentLoader + //==================================================================== + //-------------------------------------------------------------------- + SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController, + const Reference< XCommandProcessor >& i_rSubDocumentDefinition ) + :m_pData( new SubComponentLoader_Data( i_rSubDocumentDefinition ) ) + { + // add as window listener to the controller's container window, so we get notified when it is shown + Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW ); + m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW ); + + osl_incrementInterlockedCount( &m_refCount ); + { + m_pData->xAppComponentWindow->addWindowListener( this ); + } + osl_decrementInterlockedCount( &m_refCount ); + } + + //-------------------------------------------------------------------- + SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController, + const Reference< XComponent >& i_rNonDocumentComponent ) + :m_pData( new SubComponentLoader_Data( i_rNonDocumentComponent ) ) + { + // add as window listener to the controller's container window, so we get notified when it is shown + Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW ); + m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW ); + + osl_incrementInterlockedCount( &m_refCount ); + { + m_pData->xAppComponentWindow->addWindowListener( this ); + } + osl_decrementInterlockedCount( &m_refCount ); + } + + //-------------------------------------------------------------------- + SubComponentLoader::~SubComponentLoader() + { + delete m_pData, m_pData = NULL; + } + + //-------------------------------------------------------------------- + void SAL_CALL SubComponentLoader::windowResized( const WindowEvent& i_rEvent ) throw (RuntimeException) + { + // not interested in + (void)i_rEvent; + } + + //-------------------------------------------------------------------- + void SAL_CALL SubComponentLoader::windowMoved( const WindowEvent& i_rEvent ) throw (RuntimeException) + { + // not interested in + (void)i_rEvent; + } + + //-------------------------------------------------------------------- + void SAL_CALL SubComponentLoader::windowShown( const EventObject& i_rEvent ) throw (RuntimeException) + { + (void)i_rEvent; + + lcl_onWindowShown_nothrow( *m_pData ); + m_pData->xAppComponentWindow->removeWindowListener( this ); + } + + //-------------------------------------------------------------------- + void SAL_CALL SubComponentLoader::windowHidden( const EventObject& i_rEvent ) throw (RuntimeException) + { + // not interested in + (void)i_rEvent; + } + + //-------------------------------------------------------------------- + void SAL_CALL SubComponentLoader::disposing( const EventObject& i_rEvent ) throw (RuntimeException) + { + // not interested in + (void)i_rEvent; + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/recovery/subcomponentloader.hxx b/dbaccess/source/core/recovery/subcomponentloader.hxx new file mode 100644 index 000000000..96c98fe45 --- /dev/null +++ b/dbaccess/source/core/recovery/subcomponentloader.hxx @@ -0,0 +1,87 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#ifndef SUBCOMPONENTLOADER_HXX +#define SUBCOMPONENTLOADER_HXX + +#include "dbaccessdllapi.h" + +/** === begin UNO includes === **/ +#include <com/sun/star/awt/XWindowListener.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/ucb/XCommandProcessor.hpp> +/** === end UNO includes === **/ + +#include <cppuhelper/implbase1.hxx> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= SubComponentLoader + //==================================================================== + typedef ::cppu::WeakImplHelper1 < ::com::sun::star::awt::XWindowListener + > SubComponentLoader_Base; + struct SubComponentLoader_Data; + /** is a helper class which loads/opens a given sub component as soon as the main application + window becomes visible. + */ + class DBACCESS_DLLPRIVATE SubComponentLoader : public SubComponentLoader_Base + { + public: + SubComponentLoader( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& i_rApplicationController, + const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandProcessor >& i_rSubDocumentDefinition + ); + + SubComponentLoader( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& i_rApplicationController, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& i_rNonDocumentComponent + ); + + // XWindowListener + virtual void SAL_CALL windowResized( const ::com::sun::star::awt::WindowEvent& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL windowMoved( const ::com::sun::star::awt::WindowEvent& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL windowShown( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL windowHidden( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + + protected: + virtual ~SubComponentLoader(); + + private: + SubComponentLoader_Data* m_pData; + }; + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // SUBCOMPONENTLOADER_HXX diff --git a/dbaccess/source/core/recovery/subcomponentrecovery.cxx b/dbaccess/source/core/recovery/subcomponentrecovery.cxx new file mode 100644 index 000000000..c2ec6c6f0 --- /dev/null +++ b/dbaccess/source/core/recovery/subcomponentrecovery.cxx @@ -0,0 +1,702 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#include "precompiled_dbaccess.hxx" + +#include "subcomponentrecovery.hxx" + +#include "sdbcoretools.hxx" +#include "storagexmlstream.hxx" +#include "subcomponentloader.hxx" +#include "settingsimport.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/frame/XModuleManager.hpp> +#include <com/sun/star/document/XStorageBasedDocument.hpp> +#include <com/sun/star/ucb/XCommandProcessor.hpp> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/sdb/XFormDocumentsSupplier.hpp> +#include <com/sun/star/sdb/XReportDocumentsSupplier.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +/** === end UNO includes === **/ + +#include <comphelper/namedvaluecollection.hxx> +#include <connectivity/dbtools.hxx> +#include <tools/diagnose_ex.h> +#include <xmloff/XMLSettingsExportContext.hxx> +#include <xmloff/SettingsExportHelper.hxx> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::lang::XMultiServiceFactory; + using ::com::sun::star::embed::XStorage; + using ::com::sun::star::sdb::application::XDatabaseDocumentUI; + using ::com::sun::star::beans::Pair; + using ::com::sun::star::frame::XModuleManager; + using ::com::sun::star::lang::XComponent; + using ::com::sun::star::frame::XModel; + using ::com::sun::star::frame::XController; + using ::com::sun::star::beans::XPropertySet; + using ::com::sun::star::beans::PropertyValue; + using ::com::sun::star::document::XStorageBasedDocument; + using ::com::sun::star::ucb::XCommandProcessor; + using ::com::sun::star::container::XHierarchicalNameAccess; + using ::com::sun::star::sdb::XFormDocumentsSupplier; + using ::com::sun::star::sdb::XReportDocumentsSupplier; + using ::com::sun::star::xml::sax::SAXException; + using ::com::sun::star::xml::sax::XLocator; + using ::com::sun::star::xml::sax::XDocumentHandler; + using ::com::sun::star::xml::sax::XAttributeList; + /** === end UNO using === **/ + + namespace ElementModes = ::com::sun::star::embed::ElementModes; + + + //==================================================================== + //= helper + //==================================================================== + namespace + { + // ......................................................................... + static const ::rtl::OUString& lcl_getComponentStorageBaseName( const SubComponentType i_eType ) + { + static const ::rtl::OUString s_sFormBaseName( RTL_CONSTASCII_USTRINGPARAM( "form" ) ); + static const ::rtl::OUString s_sReportBaseName( RTL_CONSTASCII_USTRINGPARAM( "report" ) ); + static const ::rtl::OUString s_sTableBaseName( RTL_CONSTASCII_USTRINGPARAM( "table" ) ); + static const ::rtl::OUString s_sQueryBaseName( RTL_CONSTASCII_USTRINGPARAM( "query" ) ); + + switch ( i_eType ) + { + case FORM: + return s_sFormBaseName; + case REPORT: + return s_sReportBaseName; + case TABLE: + return s_sTableBaseName; + case QUERY: + return s_sQueryBaseName; + default: + break; + } + + OSL_ENSURE( false, "lcl_getComponentStorageBaseName: unimplemented case!" ); + static const ::rtl::OUString s_sFallback; + return s_sFallback; + } + + // ......................................................................... + static SubComponentType lcl_databaseObjectToSubComponentType( const sal_Int32 i_nObjectType ) + { + switch ( i_nObjectType ) + { + case DatabaseObject::TABLE: return TABLE; + case DatabaseObject::QUERY: return QUERY; + case DatabaseObject::FORM: return FORM; + case DatabaseObject::REPORT:return REPORT; + default: + break; + } + return UNKNOWN; + } + + // ......................................................................... + static bool lcl_determineReadOnly( const Reference< XComponent >& i_rComponent ) + { + Reference< XModel > xDocument( i_rComponent, UNO_QUERY ); + if ( !xDocument.is() ) + { + Reference< XController > xController( i_rComponent, UNO_QUERY_THROW ); + xDocument = xController->getModel(); + } + + if ( !xDocument.is() ) + return false; + + ::comphelper::NamedValueCollection aDocArgs( xDocument->getArgs() ); + return aDocArgs.getOrDefault( "ReadOnly", false ); + } + + // ......................................................................... + static Reference< XCommandProcessor > lcl_getSubComponentDef_nothrow( const Reference< XDatabaseDocumentUI >& i_rAppUI, + const SubComponentType i_eType, const ::rtl::OUString& i_rName ) + { + Reference< XController > xController( i_rAppUI, UNO_QUERY_THROW ); + ENSURE_OR_RETURN( ( i_eType == FORM ) || ( i_eType == REPORT ), "lcl_getSubComponentDef_nothrow: illegal controller", NULL ); + + Reference< XCommandProcessor > xCommandProcessor; + try + { + Reference< XHierarchicalNameAccess > xDefinitionContainer; + if ( i_eType == FORM ) + { + Reference< XFormDocumentsSupplier > xSuppForms( xController->getModel(), UNO_QUERY_THROW ); + xDefinitionContainer.set( xSuppForms->getFormDocuments(), UNO_QUERY_THROW ); + } + else + { + Reference< XReportDocumentsSupplier > xSuppReports( xController->getModel(), UNO_QUERY_THROW ); + xDefinitionContainer.set( xSuppReports->getReportDocuments(), UNO_QUERY_THROW ); + } + xCommandProcessor.set( xDefinitionContainer->getByHierarchicalName( i_rName ), UNO_QUERY_THROW ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return xCommandProcessor; + } + + // ......................................................................... + static const ::rtl::OUString& lcl_getSettingsStreamName() + { + static const ::rtl::OUString s_sStatementStreamName( RTL_CONSTASCII_USTRINGPARAM( "settings.xml" ) ); + return s_sStatementStreamName; + } + + // ......................................................................... + static const ::rtl::OUString& lcl_getCurrentQueryDesignName() + { + static const ::rtl::OUString s_sQuerySettingsName( RTL_CONSTASCII_USTRINGPARAM( "ooo:current-query-design" ) ); + return s_sQuerySettingsName; + } + } + + //==================================================================== + //= SettingsExportContext + //==================================================================== + class DBACCESS_DLLPRIVATE SettingsExportContext : public ::xmloff::XMLSettingsExportContext + { + public: + SettingsExportContext( const ::comphelper::ComponentContext& i_rContext, const StorageXMLOutputStream& i_rDelegator ) + :m_rContext( i_rContext ) + ,m_rDelegator( i_rDelegator ) + ,m_aNamespace( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_NP_CONFIG ) ) + { + } + + virtual ~SettingsExportContext() + { + } + + public: + virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const ::rtl::OUString& i_rValue ); + virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue ); + virtual void StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const sal_Bool i_bIgnoreWhitespace ); + virtual void EndElement ( const sal_Bool i_bIgnoreWhitespace ); + virtual void Characters( const ::rtl::OUString& i_rCharacters ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + GetServiceFactory() const; + + private: + ::rtl::OUString impl_prefix( const ::xmloff::token::XMLTokenEnum i_eToken ) + { + ::rtl::OUStringBuffer aQualifiedName( m_aNamespace ); + aQualifiedName.append( sal_Unicode( ':' ) ); + aQualifiedName.append( ::xmloff::token::GetXMLToken( i_eToken ) ); + return aQualifiedName.makeStringAndClear(); + } + + private: + const ::comphelper::ComponentContext& m_rContext; + const StorageXMLOutputStream& m_rDelegator; + const ::rtl::OUStringBuffer m_aNamespace; + }; + + //-------------------------------------------------------------------- + void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const ::rtl::OUString& i_rValue ) + { + m_rDelegator.addAttribute( impl_prefix( i_eName ), i_rValue ); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue ) + { + m_rDelegator.addAttribute( impl_prefix( i_eName ), ::xmloff::token::GetXMLToken( i_eValue ) ); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const sal_Bool i_bIgnoreWhitespace ) + { + if ( i_bIgnoreWhitespace ) + m_rDelegator.ignorableWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); + + m_rDelegator.startElement( impl_prefix( i_eName ) ); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::EndElement( const sal_Bool i_bIgnoreWhitespace ) + { + if ( i_bIgnoreWhitespace ) + m_rDelegator.ignorableWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); + m_rDelegator.endElement(); + } + + //-------------------------------------------------------------------- + void SettingsExportContext::Characters( const ::rtl::OUString& i_rCharacters ) + { + m_rDelegator.characters( i_rCharacters ); + } + + //-------------------------------------------------------------------- + Reference< XMultiServiceFactory > SettingsExportContext::GetServiceFactory() const + { + return m_rContext.getLegacyServiceFactory(); + } + + //================================================================================================================== + //= SettingsDocumentHandler + //================================================================================================================== + typedef ::cppu::WeakImplHelper1 < XDocumentHandler + > SettingsDocumentHandler_Base; + class DBACCESS_DLLPRIVATE SettingsDocumentHandler : public SettingsDocumentHandler_Base + { + public: + SettingsDocumentHandler() + { + } + + protected: + virtual ~SettingsDocumentHandler() + { + } + + public: + // XDocumentHandler + virtual void SAL_CALL startDocument( ) throw (SAXException, RuntimeException); + virtual void SAL_CALL endDocument( ) throw (SAXException, RuntimeException); + virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const Reference< XAttributeList >& xAttribs ) throw (SAXException, RuntimeException); + virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) throw (SAXException, RuntimeException); + virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (SAXException, RuntimeException); + virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (SAXException, RuntimeException); + virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (SAXException, RuntimeException); + virtual void SAL_CALL setDocumentLocator( const Reference< XLocator >& xLocator ) throw (SAXException, RuntimeException); + + const ::comphelper::NamedValueCollection& getSettings() const { return m_aSettings; } + + private: + ::std::stack< ::rtl::Reference< SettingsImport > > m_aStates; + ::comphelper::NamedValueCollection m_aSettings; + }; + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::startDocument( ) throw (SAXException, RuntimeException) + { + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::endDocument( ) throw (SAXException, RuntimeException) + { + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::startElement( const ::rtl::OUString& i_Name, const Reference< XAttributeList >& i_Attribs ) throw (SAXException, RuntimeException) + { + ::rtl::Reference< SettingsImport > pNewState; + + if ( m_aStates.empty() ) + { + if ( i_Name.equalsAscii( "office:settings" ) ) + { + pNewState = new OfficeSettingsImport( m_aSettings ); + } + else + { + OSL_ENSURE( false, "SettingsDocumentHandler::startElement: invalid settings file!" ); + // Yes, that's not correct. Somebody could, in theory, give us a document which starts with "foo:settings", + // where "foo" is mapped to the proper namespace URL. + // However, there's no need to bother with this. The "recovery" sub storage we're recovering from is + // not part of ODF, so we can impose any format restrictions on it ... + } + } + else + { + ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() ); + pNewState = pCurrentState->nextState( i_Name ); + } + + ENSURE_OR_THROW( pNewState.is(), "no new state - aborting import" ); + pNewState->startElement( i_Attribs ); + + m_aStates.push( pNewState ); + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::endElement( const ::rtl::OUString& i_Name ) throw (SAXException, RuntimeException) + { + ENSURE_OR_THROW( !m_aStates.empty(), "no active element" ); + (void)i_Name; + + ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() ); + pCurrentState->endElement(); + m_aStates.pop(); + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::characters( const ::rtl::OUString& i_Chars ) throw (SAXException, RuntimeException) + { + ENSURE_OR_THROW( !m_aStates.empty(), "no active element" ); + + ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() ); + pCurrentState->characters( i_Chars ); + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (SAXException, RuntimeException) + { + // ignore them - that's why they're called "ignorable" + (void)aWhitespaces; + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::processingInstruction( const ::rtl::OUString& i_Target, const ::rtl::OUString& i_Data ) throw (SAXException, RuntimeException) + { + OSL_ENSURE( false, "SettingsDocumentHandler::processingInstruction: unexpected ..." ); + (void)i_Target; + (void)i_Data; + } + + //-------------------------------------------------------------------- + void SAL_CALL SettingsDocumentHandler::setDocumentLocator( const Reference< XLocator >& i_Locator ) throw (SAXException, RuntimeException) + { + (void)i_Locator; + } + + //==================================================================== + //= SubComponentRecovery + //==================================================================== + //-------------------------------------------------------------------- + const ::rtl::OUString SubComponentRecovery::getComponentsStorageName( const SubComponentType i_eType ) + { + static const ::rtl::OUString s_sFormsStorageName( RTL_CONSTASCII_USTRINGPARAM( "forms" ) ); + static const ::rtl::OUString s_sReportsStorageName( RTL_CONSTASCII_USTRINGPARAM( "reports" ) ); + static const ::rtl::OUString s_sTablesStorageName( RTL_CONSTASCII_USTRINGPARAM( "tables" ) ); + static const ::rtl::OUString s_sQueriesStorageName( RTL_CONSTASCII_USTRINGPARAM( "queries" ) ); + static const ::rtl::OUString s_sRelationsStorageName( RTL_CONSTASCII_USTRINGPARAM( "relations" ) ); + + switch ( i_eType ) + { + case FORM: + return s_sFormsStorageName; + case REPORT: + return s_sReportsStorageName; + case TABLE: + return s_sTablesStorageName; + case QUERY: + return s_sQueriesStorageName; + case RELATION_DESIGN: + return s_sRelationsStorageName; + default: + break; + } + + OSL_ENSURE( false, "SubComponentRecovery::getComponentsStorageName: unimplemented case!" ); + static const ::rtl::OUString s_sFallback; + return s_sFallback; + } + + //-------------------------------------------------------------------- + void SubComponentRecovery::saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage, + MapCompTypeToCompDescs& io_mapCompDescs ) + { + if ( m_eType == UNKNOWN ) + // quite fatal, but has already been reported (as assertion) before + return; + + // open the sub storage for the given kind of components + const ::rtl::OUString& rStorageName( getComponentsStorageName( m_eType ) ); + const Reference< XStorage > xComponentsStorage( i_rRecoveryStorage->openStorageElement( + rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + + // find a free sub storage name, and create Yet Another Sub Storage + const ::rtl::OUString& rBaseName( lcl_getComponentStorageBaseName( m_eType ) ); + const ::rtl::OUString sStorName = ::dbtools::createUniqueName( xComponentsStorage.get(), rBaseName, true ); + const Reference< XStorage > xObjectStor( xComponentsStorage->openStorageElement( + sStorName, ElementModes::READWRITE ), UNO_QUERY_THROW ); + + switch ( m_eType ) + { + case FORM: + case REPORT: + impl_saveSubDocument_throw( xObjectStor ); + break; + + case QUERY: + impl_saveQueryDesign_throw( xObjectStor ); + break; + + default: + // TODO + OSL_ENSURE( false, "SubComponentRecoverys::saveToRecoveryStorage: unimplemented case!" ); + break; + } + + // commit the storage(s) + tools::stor::commitStorageIfWriteable( xObjectStor ); + tools::stor::commitStorageIfWriteable( xComponentsStorage ); + + // remember the relationship from the component name to the storage name + MapStringToCompDesc& rMapCompDescs = io_mapCompDescs[ m_eType ]; + OSL_ENSURE( rMapCompDescs.find( sStorName ) == rMapCompDescs.end(), + "SubComponentRecoverys::saveToRecoveryStorage: object name already used!" ); + rMapCompDescs[ sStorName ] = m_aCompDesc; + } + + //-------------------------------------------------------------------- + void SubComponentRecovery::impl_identifyComponent_throw() + { + // ask the controller + Pair< sal_Int32, ::rtl::OUString > aComponentIdentity = m_xDocumentUI->identifySubComponent( m_xComponent ); + m_eType = lcl_databaseObjectToSubComponentType( aComponentIdentity.First ); + m_aCompDesc.sName = aComponentIdentity.Second; + + // what the controller didn't give us is the information whether this is in edit mode or not ... + Reference< XModuleManager > xModuleManager( m_rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW ); + const ::rtl::OUString sModuleIdentifier = xModuleManager->identify( m_xComponent ); + + switch ( m_eType ) + { + case TABLE: + m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.TableDesign" ); + break; + + case QUERY: + m_aCompDesc.bForEditing = sModuleIdentifier.equalsAscii( "com.sun.star.sdb.QueryDesign" ); + break; + + case REPORT: + if ( sModuleIdentifier.equalsAscii( "com.sun.star.report.ReportDefinition" ) ) + { + // it's an SRB report desginer + m_aCompDesc.bForEditing = true; + break; + } + // fall through + + case FORM: + m_aCompDesc.bForEditing = !lcl_determineReadOnly( m_xComponent ); + break; + + default: + if ( sModuleIdentifier.equalsAscii( "com.sun.star.sdb.RelationDesign" ) ) + { + m_eType = RELATION_DESIGN; + m_aCompDesc.bForEditing = true; + } + else + { + OSL_ENSURE( false, "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the given sub component!" ); + } + break; + } + + OSL_POSTCOND( m_eType != UNKNOWN, + "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the component!" ); + } + + //-------------------------------------------------------------------- + void SubComponentRecovery::impl_saveQueryDesign_throw( const Reference< XStorage >& i_rObjectStorage ) + { + ENSURE_OR_THROW( m_eType == QUERY, "illegal sub component type" ); + ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" ); + + // retrieve the current query design (which might differ from what we can retrieve as ActiveCommand property, since + // the latter is updated only upon successful save of the design) + Reference< XPropertySet > xDesignerProps( m_xComponent, UNO_QUERY_THROW ); + Sequence< PropertyValue > aCurrentQueryDesign; + OSL_VERIFY( xDesignerProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CurrentQueryDesign" ) ) ) >>= aCurrentQueryDesign ); + + // write the query design + StorageXMLOutputStream aDesignOutput( m_rContext, i_rObjectStorage, lcl_getSettingsStreamName() ); + SettingsExportContext aSettingsExportContext( m_rContext, aDesignOutput ); + + const ::rtl::OUString sWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) ); + + aDesignOutput.startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "office:settings" ) ) ); + aDesignOutput.ignorableWhitespace( sWhitespace ); + + XMLSettingsExportHelper aSettingsExporter( aSettingsExportContext ); + aSettingsExporter.exportAllSettings( aCurrentQueryDesign, lcl_getCurrentQueryDesignName() ); + + aDesignOutput.ignorableWhitespace( sWhitespace ); + aDesignOutput.endElement(); + aDesignOutput.close(); + } + + //-------------------------------------------------------------------- + void SubComponentRecovery::impl_saveSubDocument_throw( const Reference< XStorage >& i_rObjectStorage ) + { + ENSURE_OR_THROW( ( m_eType == FORM ) || ( m_eType == REPORT ), "illegal sub component type" ); + ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" ); + + // store the document into the storage + Reference< XStorageBasedDocument > xStorageDocument( m_xComponent, UNO_QUERY_THROW ); + xStorageDocument->storeToStorage( i_rObjectStorage, Sequence< PropertyValue >() ); + } + + //-------------------------------------------------------------------- + Reference< XComponent > SubComponentRecovery::impl_recoverSubDocument_throw( const Reference< XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, const bool i_bForEditing ) + { + Reference< XComponent > xSubComponent; + Reference< XCommandProcessor > xDocDefinition; + + ::comphelper::NamedValueCollection aLoadArgs; + aLoadArgs.put( "RecoveryStorage", i_rRecoveryStorage ); + + // load/create the sub component hidden. We'll show it when the main app window is shown. + aLoadArgs.put( "Hidden", true ); + + if ( i_rComponentName.getLength() ) + { + xDocDefinition = lcl_getSubComponentDef_nothrow( m_xDocumentUI, m_eType, i_rComponentName ); + xSubComponent.set( m_xDocumentUI->loadComponentWithArguments( + m_eType, + i_rComponentName, + i_bForEditing, + aLoadArgs.getPropertyValues() + ), + UNO_SET_THROW + ); + } + else + { + Reference< XComponent > xDocDefComponent; + xSubComponent.set( m_xDocumentUI->createComponentWithArguments( + m_eType, + aLoadArgs.getPropertyValues(), + xDocDefComponent + ), + UNO_SET_THROW + ); + + xDocDefinition.set( xDocDefComponent, UNO_QUERY ); + OSL_ENSURE( xDocDefinition.is(), "DatabaseDocumentRecovery::recoverSubDocuments: loaded a form/report, but don't have a document definition?!" ); + } + + if ( xDocDefinition.is() ) + { + Reference< XController > xController( m_xDocumentUI, UNO_QUERY_THROW ); + Reference< XInterface > xLoader( *new SubComponentLoader( xController, xDocDefinition ) ); + (void)xLoader; + } + + return xSubComponent; + } + + //-------------------------------------------------------------------- + Reference< XComponent > SubComponentRecovery::impl_recoverQueryDesign_throw( const Reference< XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, const bool i_bForEditing ) + { + Reference< XComponent > xSubComponent; + + // first read the settings query design settings from the storage + StorageXMLInputStream aDesignInput( m_rContext, i_rRecoveryStorage, lcl_getSettingsStreamName() ); + + ::rtl::Reference< SettingsDocumentHandler > pDocHandler( new SettingsDocumentHandler ); + aDesignInput.import( pDocHandler.get() ); + + const ::comphelper::NamedValueCollection& rSettings( pDocHandler->getSettings() ); + const Any aCurrentQueryDesign = rSettings.get( lcl_getCurrentQueryDesignName() ); +#if OSL_DEBUG_LEVEL > 0 + Sequence< PropertyValue > aQueryDesignLayout; + OSL_VERIFY( aCurrentQueryDesign >>= aQueryDesignLayout ); +#endif + + // then load the query designer + ::comphelper::NamedValueCollection aLoadArgs; + aLoadArgs.put( "CurrentQueryDesign", aCurrentQueryDesign ); + aLoadArgs.put( "Hidden", true ); + + if ( i_rComponentName.getLength() ) + { + xSubComponent.set( m_xDocumentUI->loadComponentWithArguments( + m_eType, + i_rComponentName, + i_bForEditing, + aLoadArgs.getPropertyValues() + ), + UNO_SET_THROW + ); + } + else + { + Reference< XComponent > xDummy; + xSubComponent.set( m_xDocumentUI->createComponentWithArguments( + m_eType, + aLoadArgs.getPropertyValues(), + xDummy + ), + UNO_SET_THROW + ); + } + + Reference< XController > xController( m_xDocumentUI, UNO_QUERY_THROW ); + Reference< XInterface > xLoader( *new SubComponentLoader( xController, xSubComponent ) ); + (void)xLoader; + + return xSubComponent; + } + + //-------------------------------------------------------------------- + Reference< XComponent > SubComponentRecovery::recoverFromStorage( const Reference< XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, const bool i_bForEditing ) + { + Reference< XComponent > xSubComponent; + switch ( m_eType ) + { + case FORM: + case REPORT: + xSubComponent = impl_recoverSubDocument_throw( i_rRecoveryStorage, i_rComponentName, i_bForEditing ); + break; + case QUERY: + xSubComponent = impl_recoverQueryDesign_throw( i_rRecoveryStorage, i_rComponentName, i_bForEditing ); + break; + default: + OSL_ENSURE( false, "SubComponentRecovery::recoverFromStorage: unimplemented case!" ); + break; + } + return xSubComponent; + } + +//........................................................................ +} // namespace dbaccess +//........................................................................ diff --git a/dbaccess/source/core/recovery/subcomponentrecovery.hxx b/dbaccess/source/core/recovery/subcomponentrecovery.hxx new file mode 100644 index 000000000..dee2436d9 --- /dev/null +++ b/dbaccess/source/core/recovery/subcomponentrecovery.hxx @@ -0,0 +1,126 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#ifndef SUBCOMPONENTRECOVERY_HXX +#define SUBCOMPONENTRECOVERY_HXX + +#include "subcomponents.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp> +#include <com/sun/star/embed/XStorage.hpp> +/** === end UNO includes === **/ + +#include <comphelper/componentcontext.hxx> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + //==================================================================== + //= SubComponentRecovery + //==================================================================== + class DBACCESS_DLLPRIVATE SubComponentRecovery + { + public: + SubComponentRecovery( const ::comphelper::ComponentContext& i_rContext, const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& i_rController, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& i_rComponent ) + :m_rContext( i_rContext ) + ,m_xDocumentUI( i_rController, ::com::sun::star::uno::UNO_SET_THROW ) + ,m_xComponent( i_rComponent ) + ,m_eType( UNKNOWN ) + ,m_aCompDesc() + { + impl_identifyComponent_throw(); + } + + SubComponentRecovery( const ::comphelper::ComponentContext& i_rContext, const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& i_rController, + const SubComponentType i_eType ) + :m_rContext( i_rContext ) + ,m_xDocumentUI( i_rController, ::com::sun::star::uno::UNO_SET_THROW ) + ,m_xComponent() + ,m_eType( i_eType ) + ,m_aCompDesc() + { + } + + // only to be used after being constructed with a component + void saveToRecoveryStorage( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage, + MapCompTypeToCompDescs& io_mapCompDescs + ); + + // only to be used after being constructed with a type + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + recoverFromStorage( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, + const bool i_bForEditing + ); + + static const ::rtl::OUString getComponentsStorageName( const SubComponentType i_eType ); + + private: + void impl_saveSubDocument_throw( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rObjectStorage + ); + + void impl_saveQueryDesign_throw( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rObjectStorage + ); + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + impl_recoverSubDocument_throw( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, + const bool i_bForEditing + ); + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + impl_recoverQueryDesign_throw( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage, + const ::rtl::OUString& i_rComponentName, + const bool i_bForEditing + ); + + void impl_identifyComponent_throw(); + + private: + const ::comphelper::ComponentContext& m_rContext; + ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI > + m_xDocumentUI; + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + m_xComponent; + SubComponentType m_eType; + SubComponentDescriptor m_aCompDesc; + }; + + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // SUBCOMPONENTRECOVERY_HXX diff --git a/dbaccess/source/core/recovery/subcomponents.hxx b/dbaccess/source/core/recovery/subcomponents.hxx new file mode 100644 index 000000000..65a837355 --- /dev/null +++ b/dbaccess/source/core/recovery/subcomponents.hxx @@ -0,0 +1,88 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* 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. +* +* 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). +* +* 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. +************************************************************************/ + +#ifndef SUBCOMPONENTS_HXX +#define SUBCOMPONENTS_HXX + +#include "dbaccessdllapi.h" + +/** === begin UNO includes === **/ +#include <com/sun/star/sdb/application/DatabaseObject.hpp> +/** === end UNO includes === **/ + +#include <rtl/ustring.hxx> + +#include <hash_map> +#include <map> + +//........................................................................ +namespace dbaccess +{ +//........................................................................ + + namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; + + // ------------------------------------------------------------------- + enum SubComponentType + { + TABLE = DatabaseObject::TABLE, + QUERY = DatabaseObject::QUERY, + FORM = DatabaseObject::FORM, + REPORT = DatabaseObject::REPORT, + + RELATION_DESIGN = 1000, + + UNKNOWN = 10001 + }; + + // ------------------------------------------------------------------- + struct DBACCESS_DLLPRIVATE SubComponentDescriptor + { + ::rtl::OUString sName; + bool bForEditing; + + SubComponentDescriptor() + :sName() + ,bForEditing( false ) + { + } + + SubComponentDescriptor( const ::rtl::OUString& i_rName, const bool i_bForEditing ) + :sName( i_rName ) + ,bForEditing( i_bForEditing ) + { + } + }; + + // ------------------------------------------------------------------- + typedef ::std::hash_map< ::rtl::OUString, SubComponentDescriptor, ::rtl::OUStringHash > MapStringToCompDesc; + typedef ::std::map< SubComponentType, MapStringToCompDesc > MapCompTypeToCompDescs; + + +//........................................................................ +} // namespace dbaccess +//........................................................................ + +#endif // SUBCOMPONENTS_HXX diff --git a/dbaccess/source/filter/xml/dbloader2.cxx b/dbaccess/source/filter/xml/dbloader2.cxx index 0ce273673..cc823d92a 100644 --- a/dbaccess/source/filter/xml/dbloader2.cxx +++ b/dbaccess/source/filter/xml/dbloader2.cxx @@ -445,7 +445,7 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const :: if ( !aMediaDesc.has( "InteractionHandler" ) ) { Reference< XInteractionHandler > xHandler; - if ( m_aContext.createComponent( "com.sun.star.sdb.InteractionHandler", xHandler ) ) + if ( m_aContext.createComponent( "com.sun.star.task.InteractionHandler", xHandler ) ) aMediaDesc.put( "InteractionHandler", xHandler ); } @@ -544,22 +544,20 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const :: } } - Reference< XController2 > xController; if ( bSuccess ) { try { Reference< XModel2 > xModel2( xModel, UNO_QUERY_THROW ); - xController = xModel2->createViewController( sViewName, Sequence< PropertyValue >(), rFrame ); + Reference< XController2 > xController( xModel2->createViewController( sViewName, Sequence< PropertyValue >(), rFrame ), UNO_QUERY_THROW ); - bSuccess = xController.is(); - if ( bSuccess ) - { - xController->attachModel( xModel ); - rFrame->setComponent( xController->getComponentWindow(), xController.get() ); - xController->attachFrame( rFrame ); - xModel->setCurrentController( xController.get() ); - } + xController->attachModel( xModel ); + xModel->connectController( xController.get() ); + rFrame->setComponent( xController->getComponentWindow(), xController.get() ); + xController->attachFrame( rFrame ); + xModel->setCurrentController( xController.get() ); + + bSuccess = sal_True; } catch( const Exception& ) { diff --git a/dbaccess/source/filter/xml/xmlDatabase.cxx b/dbaccess/source/filter/xml/xmlDatabase.cxx index 88aa8b706..67b97edb3 100644 --- a/dbaccess/source/filter/xml/xmlDatabase.cxx +++ b/dbaccess/source/filter/xml/xmlDatabase.cxx @@ -27,45 +27,20 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_dbaccess.hxx" -#ifndef DBA_XMLDATABASE_HXX #include "xmlDatabase.hxx" -#endif -#ifndef DBA_XMLFILTER_HXX #include "xmlfilter.hxx" -#endif -#ifndef _XMLOFF_XMLTOKEN_HXX #include <xmloff/xmltoken.hxx> -#endif -#ifndef _XMLOFF_XMLNMSPE_HXX #include <xmloff/xmlnmspe.hxx> -#endif -#ifndef DBA_XMLDATASOURCE_HXX #include "xmlDataSource.hxx" -#endif -#ifndef DBA_XMLDOCUMENTS_HXX #include "xmlDocuments.hxx" -#endif -#ifndef DBA_XMLENUMS_HXX #include "xmlEnums.hxx" -#endif -#ifndef _COM_SUN_STAR_SDB_XREPORTDOCUMENTSSUPPLIER_HPP_ #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XFORMDOCUMENTSSUPPLIER_HPP_ #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_ #include <com/sun/star/sdbcx/XTablesSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XQUERYDEFINITIONSSUPPLIER_HPP_ #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp> -#endif -#ifndef DBACCESS_SHARED_XMLSTRINGS_HRC #include "xmlstrings.hrc" -#endif -#ifndef _TOOLS_DEBUG_HXX #include <tools/debug.hxx> -#endif +#include <connectivity/dbtools.hxx> namespace dbaxml { @@ -108,25 +83,46 @@ SvXMLImportContext* OXMLDatabase::CreateChildContext( case XML_TOK_FORMS: { GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); - Reference<XFormDocumentsSupplier> xSup(GetOwnImport().GetModel(),UNO_QUERY); - if ( xSup.is() ) - pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getFormDocuments(),SERVICE_NAME_FORM_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"Forms",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference<XFormDocumentsSupplier> xSup(GetOwnImport().GetModel(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getFormDocuments(),SERVICE_NAME_FORM_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + } } break; case XML_TOK_REPORTS: { GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); - Reference<XReportDocumentsSupplier> xSup(GetOwnImport().GetModel(),UNO_QUERY); - if ( xSup.is() ) - pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getReportDocuments(),SERVICE_NAME_REPORT_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"Reports",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference<XReportDocumentsSupplier> xSup(GetOwnImport().GetModel(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getReportDocuments(),SERVICE_NAME_REPORT_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + } } break; case XML_TOK_QUERIES: { GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); - Reference<XQueryDefinitionsSupplier> xSup(GetOwnImport().getDataSource(),UNO_QUERY); - if ( xSup.is() ) - pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getQueryDefinitions(),SERVICE_NAME_QUERY_COLLECTION); + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"CommandDefinitions",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference<XQueryDefinitionsSupplier> xSup(GetOwnImport().getDataSource(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getQueryDefinitions(),SERVICE_NAME_QUERY_COLLECTION); + } } break; case XML_TOK_TABLES: diff --git a/dbaccess/source/filter/xml/xmlExport.cxx b/dbaccess/source/filter/xml/xmlExport.cxx index 766f03e3a..e501032f8 100644 --- a/dbaccess/source/filter/xml/xmlExport.cxx +++ b/dbaccess/source/filter/xml/xmlExport.cxx @@ -28,82 +28,37 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_dbaccess.hxx" -#ifndef DBA_XMLEXPORT_HXX #include "xmlExport.hxx" -#endif -#ifndef DBA_XMLAUTOSTYLE_HXX #include "xmlAutoStyle.hxx" -#endif -#ifndef _FLT_REGHELPER_HXX_ #include "flt_reghelper.hxx" -#endif -#ifndef _XMLOFF_PROGRESSBARHELPER_HXX #include <xmloff/ProgressBarHelper.hxx> -#endif -#ifndef _XMLOFF_XMLTOKEN_HXX #include <xmloff/xmltoken.hxx> -#endif -#ifndef _XMLOFF_TEXTIMP_HXX_ #include <xmloff/txtimp.hxx> -#endif -#ifndef _XMLOFF_XMLNMSPE_HXX #include <xmloff/xmlnmspe.hxx> -#endif -#ifndef _XMLOFF_XMLUCONV_HXX #include <xmloff/xmluconv.hxx> -#endif -#ifndef _XMLOFF_NMSPMAP_HXX #include <xmloff/nmspmap.hxx> -#endif -#ifndef _COMPHELPER_TYPES_HXX_ #include <comphelper/types.hxx> -#endif -#ifndef DBACCESS_SHARED_XMLSTRINGS_HRC #include "xmlstrings.hrc" -#endif -#ifndef DBA_XMLENUMS_HXX #include "xmlEnums.hxx" -#endif -#ifndef _XMLOFF_NMSPMAP_HXX #include <xmloff/nmspmap.hxx> -#endif -#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSTATE_HPP_ #include <com/sun/star/beans/XPropertyState.hpp> -#endif -#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ #include <com/sun/star/beans/PropertyAttribute.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XFORMDOCUMENTSSUPPLIER_HPP_ #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XOFFICEDATABASEDOCUMENT_HPP_ #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XREPORTDOCUMENTSSUPPLIER_HPP_ #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XQUERYDEFINITIONSSUPPLIER_HPP_ #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp> -#endif #include <com/sun/star/sdbcx/XTablesSupplier.hpp> #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> -#ifndef _COM_SUN_STAR_AWT_TEXTALIGN_HPP_ #include <com/sun/star/awt/TextAlign.hpp> -#endif -#ifndef _XMLOFF_XMLUCONV_HXX #include <xmloff/xmluconv.hxx> -#endif -#ifndef DBA_XMLHELPER_HXX #include "xmlHelper.hxx" -#endif -#ifndef _COM_SUN_STAR_AWT_FONTDESCRIPTOR_HPP_ #include <com/sun/star/awt/FontDescriptor.hpp> -#endif #include <svl/filenotation.hxx> #include <unotools/pathoptions.hxx> #include <tools/diagnose_ex.h> #include <connectivity/DriversConfig.hxx> +#include <connectivity/dbtools.hxx> #include <boost/optional.hpp> @@ -1107,47 +1062,68 @@ void ODBExport::exportColumns(const Reference<XColumnsSupplier>& _xColSup) // ----------------------------------------------------------------------------- void ODBExport::exportForms() { - Reference<XFormDocumentsSupplier> xSup(GetModel(),UNO_QUERY); - if ( xSup.is() ) + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"Forms",aValue); + aValue >>= sService; + if ( !sService.getLength() ) { - Reference< XNameAccess > xCollection = xSup->getFormDocuments(); - if ( xCollection.is() && xCollection->hasElements() ) + Reference<XFormDocumentsSupplier> xSup(GetModel(),UNO_QUERY); + if ( xSup.is() ) { - ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportComponent); - exportCollection(xCollection,XML_FORMS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc); + Reference< XNameAccess > xCollection = xSup->getFormDocuments(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportComponent); + exportCollection(xCollection,XML_FORMS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc); + } } } } // ----------------------------------------------------------------------------- void ODBExport::exportReports() { - Reference<XReportDocumentsSupplier> xSup(GetModel(),UNO_QUERY); - if ( xSup.is() ) + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"Reports",aValue); + aValue >>= sService; + if ( !sService.getLength() ) { - Reference< XNameAccess > xCollection = xSup->getReportDocuments(); - if ( xCollection.is() && xCollection->hasElements() ) + Reference<XReportDocumentsSupplier> xSup(GetModel(),UNO_QUERY); + if ( xSup.is() ) { - ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportComponent); - exportCollection(xCollection,XML_REPORTS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc); + Reference< XNameAccess > xCollection = xSup->getReportDocuments(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportComponent); + exportCollection(xCollection,XML_REPORTS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc); + } } } } // ----------------------------------------------------------------------------- void ODBExport::exportQueries(sal_Bool _bExportContext) { - Reference<XQueryDefinitionsSupplier> xSup(getDataSource(),UNO_QUERY); - if ( xSup.is() ) + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"CommandDefinitions",aValue); + aValue >>= sService; + if ( !sService.getLength() ) { - Reference< XNameAccess > xCollection = xSup->getQueryDefinitions(); - if ( xCollection.is() && xCollection->hasElements() ) + Reference<XQueryDefinitionsSupplier> xSup(getDataSource(),UNO_QUERY); + if ( xSup.is() ) { - ::std::auto_ptr< ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > > pMemFunc; - if ( _bExportContext ) - pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportQuery) ); - else - pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportAutoStyle) ); + Reference< XNameAccess > xCollection = xSup->getQueryDefinitions(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::std::auto_ptr< ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > > pMemFunc; + if ( _bExportContext ) + pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportQuery) ); + else + pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportAutoStyle) ); - exportCollection(xCollection,XML_QUERIES,XML_QUERY_COLLECTION,_bExportContext,*pMemFunc); + exportCollection(xCollection,XML_QUERIES,XML_QUERY_COLLECTION,_bExportContext,*pMemFunc); + } } } } diff --git a/dbaccess/source/filter/xml/xmlfilter.cxx b/dbaccess/source/filter/xml/xmlfilter.cxx index 776a50614..07ef531a3 100644 --- a/dbaccess/source/filter/xml/xmlfilter.cxx +++ b/dbaccess/source/filter/xml/xmlfilter.cxx @@ -114,6 +114,7 @@ #endif #include <com/sun/star/frame/XComponentLoader.hpp> #include <com/sun/star/frame/FrameSearchFlag.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #ifndef _SV_SVAPP_HXX //autogen #include <vcl/svapp.hxx> #endif @@ -130,6 +131,7 @@ #include <comphelper/mimeconfighelper.hxx> #include <comphelper/documentconstants.hxx> #include <comphelper/uno3.hxx> +#include <cppuhelper/exc_hlp.hxx> #include <osl/thread.hxx> #include <connectivity/CommonTools.hxx> #include <connectivity/DriversConfig.hxx> @@ -511,72 +513,64 @@ sal_Bool ODBFilter::implImport( const Sequence< PropertyValue >& rDescriptor ) SfxMediumRef pMedium = new SfxMedium( sFileName, ( STREAM_READ | STREAM_NOCREATE ), FALSE, 0 ); uno::Reference< embed::XStorage > xStorage; - if( pMedium ) + try { - try - { - xStorage = pMedium->GetStorage( sal_False ); - // nError = pMedium->GetError(); - } - catch(const Exception&) - { - } + xStorage.set( pMedium->GetStorage( sal_False ), UNO_QUERY_THROW ); + } + catch( const Exception& ) + { + Any aError = ::cppu::getCaughtException(); + if ( aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() ) ) + throw; + throw lang::WrappedTargetRuntimeException( ::rtl::OUString(), *this, aError ); } - OSL_ENSURE(xStorage.is(),"No Storage for read!"); - if ( xStorage.is() ) + uno::Reference<sdb::XOfficeDatabaseDocument> xOfficeDoc(GetModel(),UNO_QUERY_THROW); + m_xDataSource.set(xOfficeDoc->getDataSource(),UNO_QUERY_THROW); + uno::Reference<beans::XPropertyChangeListener> xListener = new DatasourceURLListener(getServiceFactory()); + m_xDataSource->addPropertyChangeListener(PROPERTY_URL,xListener); + uno::Reference< XNumberFormatsSupplier > xNum(m_xDataSource->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER),UNO_QUERY); + SetNumberFormatsSupplier(xNum); + + uno::Reference<XComponent> xModel(GetModel(),UNO_QUERY); + sal_Int32 nRet = ReadThroughComponent( xStorage + ,xModel + ,"settings.xml" + ,"Settings.xml" + ,getServiceFactory() + ,this + ); + + if ( nRet == 0 ) + nRet = ReadThroughComponent( xStorage + ,xModel + ,"content.xml" + ,"Content.xml" + ,getServiceFactory() + ,this + ); + + bRet = nRet == 0; + + if ( bRet ) { - uno::Reference<sdb::XOfficeDatabaseDocument> xOfficeDoc(GetModel(),UNO_QUERY_THROW); - m_xDataSource.set(xOfficeDoc->getDataSource(),UNO_QUERY_THROW); - uno::Reference<beans::XPropertyChangeListener> xListener = new DatasourceURLListener(getServiceFactory()); - m_xDataSource->addPropertyChangeListener(PROPERTY_URL,xListener); - uno::Reference< XNumberFormatsSupplier > xNum(m_xDataSource->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER),UNO_QUERY); - SetNumberFormatsSupplier(xNum); - - uno::Reference<XComponent> xModel(GetModel(),UNO_QUERY); - sal_Int32 nRet = ReadThroughComponent( xStorage - ,xModel - ,"settings.xml" - ,"Settings.xml" - ,getServiceFactory() - ,this - ); - - if ( nRet == 0 ) - nRet = ReadThroughComponent( xStorage - ,xModel - ,"content.xml" - ,"Content.xml" - ,getServiceFactory() - ,this - ); - - bRet = nRet == 0; - - if ( bRet ) - { - uno::Reference< XModifiable > xModi(GetModel(),UNO_QUERY); - if ( xModi.is() ) - xModi->setModified(sal_False); - } - else + uno::Reference< XModifiable > xModi(GetModel(),UNO_QUERY); + if ( xModi.is() ) + xModi->setModified(sal_False); + } + else + { + switch( nRet ) { - switch( nRet ) + case ERRCODE_IO_BROKENPACKAGE: + // TODO/LATER: no way to transport the error outside from the filter! + break; + default: { - case ERRCODE_IO_BROKENPACKAGE: - if( xStorage.is() ) - { - // TODO/LATER: no way to transport the error outside from the filter! - break; - } - // fall through intented - default: - { - // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly! But for now this is the only way! - ErrorHandler::HandleError( nRet ); - if( nRet & ERRCODE_WARNING_MASK ) - bRet = sal_True; - } + // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly! But for now this is the only way! + ErrorHandler::HandleError( nRet ); + if( nRet & ERRCODE_WARNING_MASK ) + bRet = sal_True; } } } diff --git a/dbaccess/source/inc/dbastrings.hrc b/dbaccess/source/inc/dbastrings.hrc index f0a65c170..db629f1ce 100644 --- a/dbaccess/source/inc/dbastrings.hrc +++ b/dbaccess/source/inc/dbastrings.hrc @@ -45,7 +45,9 @@ namespace dbaccess //============================================================ //= Properties //============================================================ - DECLARE_CONSTASCII_USTRING(PROPERTY_APPLYFORMDESIGNMODE); + DECLARE_CONSTASCII_USTRING( PROPERTY_APPLYFORMDESIGNMODE ); + DECLARE_CONSTASCII_USTRING( PROPERTY_IS_FORM ); + DECLARE_CONSTASCII_USTRING( PROPERTY_PERSISTENT_PATH ); } #endif // DBACCESS_SHARED_DBASTRINGS_HRC diff --git a/dbaccess/source/inc/stringconstants.hrc b/dbaccess/source/inc/stringconstants.hrc index 16e67984f..939272dea 100644 --- a/dbaccess/source/inc/stringconstants.hrc +++ b/dbaccess/source/inc/stringconstants.hrc @@ -180,6 +180,8 @@ #define PROPERTY_ID_THOUSAND_DELIMITER 140 #define PROPERTY_ID_ENCODING 141 #define PROPERTY_ID_HELP_URL 142 +#define PROPERTY_ID_PERSISTENT_PATH 143 +#define PROPERTY_ID_CURRENT_QUERY_DESIGN 144 //============================================================ //= property names @@ -375,7 +377,6 @@ DECLARE_CONSTASCII_USTRING(SERVICE_SDBCX_TABLES); DECLARE_CONSTASCII_USTRING(SERVICE_SDB_QUERIES); DECLARE_CONSTASCII_USTRING(SERVICE_SDBC_DRIVERMANAGER); DECLARE_CONSTASCII_USTRING(SERVICE_SDBC_CONNECTIONPOOL); -DECLARE_CONSTASCII_USTRING(SERVICE_SDB_INTERACTION_HANDLER); DECLARE_CONSTASCII_USTRING(SERVICE_TASK_INTERACTION_HANDLER); DECLARE_CONSTASCII_USTRING(SERVICE_FRAME_DESKTOP); DECLARE_CONSTASCII_USTRING(SERVICE_SDB_ADABASCREATIONDIALOG); diff --git a/dbaccess/source/inc/stringconstants.inc b/dbaccess/source/inc/stringconstants.inc index babee6ccc..4639167bd 100644 --- a/dbaccess/source/inc/stringconstants.inc +++ b/dbaccess/source/inc/stringconstants.inc @@ -219,7 +219,6 @@ IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDBC_DRIVERMANAGER, "com.sun.star.sdbc.Driv IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDBC_CONNECTIONPOOL, "com.sun.star.sdbc.ConnectionPool"); IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDBCX_INDEXCOLUMN, "com.sun.star.sdbcx.IndexColumn"); IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDBCX_KEYCOLUMN, "com.sun.star.sdbcx.KeyColumn"); -IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDB_INTERACTION_HANDLER, "com.sun.star.sdb.InteractionHandler"); IMPLEMENT_CONSTASCII_USTRING(SERVICE_TASK_INTERACTION_HANDLER, "com.sun.star.task.InteractionHandler"); IMPLEMENT_CONSTASCII_USTRING(SERVICE_FRAME_DESKTOP, "com.sun.star.frame.Desktop"); IMPLEMENT_CONSTASCII_USTRING(SERVICE_SDB_ADABASCREATIONDIALOG, "com.sun.star.sdb.AdabasCreationDialog"); diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index dc14ace91..4b1285f26 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -75,8 +75,8 @@ #include <com/sun/star/sdb/application/DatabaseObject.hpp> #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp> #include <com/sun/star/document/XDocumentEventBroadcaster.hpp> +#include <com/sun/star/container/XHierarchicalName.hpp> /** === end UNO includes === **/ - #include <tools/debug.hxx> #include <tools/diagnose_ex.h> #include <tools/string.hxx> @@ -342,8 +342,8 @@ OApplicationController::~OApplicationController() osl_incrementInterlockedCount( &m_refCount ); dispose(); } - ::std::auto_ptr< Window> aTemp(m_pView); - m_pView = NULL; + ::std::auto_ptr< Window> aTemp( getView() ); + clearView(); DBG_DTOR(OApplicationController,NULL); } @@ -442,7 +442,8 @@ void SAL_CALL OApplicationController::disposing() } } - m_aModelConnector.clear(); + m_xModel->disconnectController( this ); + m_xModel.clear(); } } @@ -451,15 +452,15 @@ void SAL_CALL OApplicationController::disposing() DBG_UNHANDLED_EXCEPTION(); } - m_pView = NULL; + clearView(); OApplicationController_CBASE::disposing(); // here the m_refCount must be equal 5 } //-------------------------------------------------------------------- sal_Bool OApplicationController::Construct(Window* _pParent) { - m_pView = new OApplicationView( _pParent, getORB(), *this, m_ePreviewMode ); - m_pView->SetUniqueId(UID_APP_VIEW); + setView( * new OApplicationView( _pParent, getORB(), *this, m_ePreviewMode ) ); + getView()->SetUniqueId(UID_APP_VIEW); // late construction sal_Bool bSuccess = sal_False; @@ -478,8 +479,8 @@ sal_Bool OApplicationController::Construct(Window* _pParent) if ( !bSuccess ) { - ::std::auto_ptr< Window> aTemp(m_pView); - m_pView = NULL; + ::std::auto_ptr< Window> aTemp( getView() ); + clearView(); return sal_False; } @@ -508,8 +509,8 @@ void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) thr Reference<XConnection> xCon(_rSource.Source, UNO_QUERY); if ( xCon.is() ) { - DBG_ASSERT( ( m_xDataSourceConnection == xCon ) && getContainer() && ( getContainer()->getElementType() == E_TABLE ), - "OApplicationController::disposing: the below code will ignore this call - why?" ); + DBG_ASSERT( m_xDataSourceConnection == xCon, + "OApplicationController::disposing: which connection does this come from?" ); if ( getContainer() && getContainer()->getElementType() == E_TABLE ) getContainer()->clearPages(); @@ -522,7 +523,6 @@ void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) thr else if ( _rSource.Source == m_xModel ) { m_xModel.clear(); - m_aModelConnector.clear(); } else if ( _rSource.Source == m_xDataSource ) { @@ -1242,7 +1242,7 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa { ElementType eType = E_TABLE; sal_Bool bAutoPilot = sal_False; - sal_Bool bSQLView = sal_False; + ::comphelper::NamedValueCollection aCreationArgs; switch( _nId ) { @@ -1265,10 +1265,10 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa bAutoPilot = sal_True; eType = E_QUERY; break; - case ID_NEW_QUERY_SQL: - bSQLView = sal_True; - // run through case ID_NEW_QUERY_DESIGN: + aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, sal_True ); + // run through + case ID_NEW_QUERY_SQL: eType = E_QUERY; break; case ID_NEW_TABLE_DESIGN_AUTO_PILOT: @@ -1282,7 +1282,10 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa if ( bAutoPilot ) getContainer()->PostUserEvent( LINK( this, OApplicationController, OnCreateWithPilot ), reinterpret_cast< void* >( eType ) ); else - newElement( eType, bSQLView ); + { + Reference< XComponent > xDocDefinition; + newElement( eType, aCreationArgs, xDocDefinition ); + } } break; case SID_APP_NEW_FOLDER: @@ -1298,10 +1301,13 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa SharedConnection xConnection( ensureConnection() ); if ( xConnection.is() ) { - QueryDesigner aDesigner( getORB(), this, getFrame(), true, SID_DB_NEW_VIEW_SQL == _nId ); + QueryDesigner aDesigner( getORB(), this, getFrame(), true ); + + ::comphelper::NamedValueCollection aCreationArgs; + aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, ID_NEW_VIEW_DESIGN == _nId ); Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); - Reference< XComponent > xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY ); + Reference< XComponent > xComponent( aDesigner.createNew( xDataSource, aCreationArgs ), UNO_QUERY ); onDocumentOpened( ::rtl::OUString(), E_QUERY, E_OPEN_DESIGN, xComponent, NULL ); } } @@ -1840,14 +1846,17 @@ Reference< XComponent > OApplicationController::openElementWithArguments( const case E_REPORT: case E_FORM: { - ::std::auto_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType ); - if ( !aHelper->isConnected() ) - break; + if ( !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode ) ) + { + ::std::auto_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType ); + if ( !aHelper->isConnected() ) + break; - Reference< XComponent > xDefinition; - xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments ); + Reference< XComponent > xDefinition; + xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments ); - onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition ); + onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition ); + } } break; @@ -1866,20 +1875,33 @@ Reference< XComponent > OApplicationController::openElementWithArguments( const Any aDataSource; if ( _eOpenMode == E_OPEN_DESIGN ) { - sal_Bool bQuerySQLMode =( _nInstigatorCommand == SID_DB_APP_EDIT_SQL_VIEW ); + bool bAddViewTypeArg = false; if ( _eType == E_TABLE ) { if ( impl_isAlterableView_nothrow( _sName ) ) - pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true, bQuerySQLMode ) ); + { + pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true ) ); + bAddViewTypeArg = true; + } else + { pDesigner.reset( new TableDesigner( getORB(), this, m_aCurrentFrame.getFrame() ) ); + } } else if ( _eType == E_QUERY ) { - pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false, bQuerySQLMode ) ); + pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false ) ); + bAddViewTypeArg = true; } aDataSource <<= m_xDataSource; + + if ( bAddViewTypeArg ) + { + const bool bQueryGraphicalMode =( _nInstigatorCommand != SID_DB_APP_EDIT_SQL_VIEW ); + aArguments.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, bQueryGraphicalMode ); + } + } else { @@ -1891,7 +1913,7 @@ Reference< XComponent > OApplicationController::openElementWithArguments( const aDataSource <<= getDatabaseName(); } - xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments.getPropertyValues() ) ); + xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments ) ); onDocumentOpened( _sName, _eType, _eOpenMode, xRet, NULL ); } } @@ -1932,14 +1954,11 @@ void OApplicationController::newElementWithPilot( ElementType _eType ) if ( aHelper->isConnected() ) { sal_Int32 nCommandType = -1; - const ::rtl::OUString sName(getCurrentlySelectedName(nCommandType)); - Reference< XComponent > xComponent,xDefinition; + const ::rtl::OUString sCurrentSelected( getCurrentlySelectedName( nCommandType ) ); if ( E_REPORT == _eType ) - xComponent = aHelper->newReportWithPilot(xDefinition,nCommandType,sName); + aHelper->newReportWithPilot( nCommandType, sCurrentSelected ); else - xComponent = aHelper->newFormWithPilot(xDefinition,nCommandType,sName); - - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition ); + aHelper->newFormWithPilot( nCommandType, sCurrentSelected ); } } break; @@ -1949,68 +1968,76 @@ void OApplicationController::newElementWithPilot( ElementType _eType ) ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType); if ( aHelper->isConnected() ) { - Reference< XComponent > xComponent; if ( E_QUERY == _eType ) - xComponent = aHelper->newQueryWithPilot(); + aHelper->newQueryWithPilot(); else - xComponent = aHelper->newTableWithPilot(); - - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, NULL ); + aHelper->newTableWithPilot(); } } break; case E_NONE: break; } + + // no need for onDocumentOpened, the table wizard opens the created table by using + // XDatabaseDocumentUI::loadComponent method. } // ----------------------------------------------------------------------------- -void OApplicationController::newElement( ElementType _eType, sal_Bool _bSQLView ) +Reference< XComponent > OApplicationController::newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments, + Reference< XComponent >& o_rDocumentDefinition ) { OSL_ENSURE(getContainer(),"View is NULL! -> GPF"); + Reference< XComponent > xComponent; + o_rDocumentDefinition.clear(); + switch ( _eType ) { case E_FORM: case E_REPORT: - { - ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType); - if ( aHelper->isConnected() ) - { - Reference< XComponent > xComponent,xDefinition; - sal_Int32 nCommandType = -1; - const ::rtl::OUString sName(getCurrentlySelectedName(nCommandType)); - xComponent = aHelper->newDocument(_eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT,xDefinition,nCommandType,sName); - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition ); - } - } - break; + { + ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess( _eType ); + if ( !aHelper->isConnected() ) + break; + + xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT, i_rAdditionalArguments, o_rDocumentDefinition ); + } + break; + case E_QUERY: case E_TABLE: - { - ::std::auto_ptr< DatabaseObjectView > pDesigner; - SharedConnection xConnection( ensureConnection() ); - if ( xConnection.is() ) - { - if ( _eType == E_TABLE ) - { - pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) ); - } - else if ( _eType == E_QUERY ) - { - pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false, _bSQLView ) ); - } + { + ::std::auto_ptr< DatabaseObjectView > pDesigner; + SharedConnection xConnection( ensureConnection() ); + if ( !xConnection.is() ) + break; - Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); - Reference< XComponent > xComponent( pDesigner->createNew( xDataSource ), UNO_QUERY ); - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, NULL ); - } + if ( _eType == E_TABLE ) + { + pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) ); } - break; + else if ( _eType == E_QUERY ) + { + pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false ) ); + } + + Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); + xComponent.set( pDesigner->createNew( xDataSource, i_rAdditionalArguments ), UNO_QUERY ); + } + break; + default: + OSL_ENSURE( false, "OApplicationController::newElement: illegal type!" ); break; } + + if ( xComponent.is() ) + onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, o_rDocumentDefinition ); + + return xComponent; } + // ----------------------------------------------------------------------------- void OApplicationController::addContainerListener(const Reference<XNameAccess>& _xCollection) { @@ -2583,7 +2610,7 @@ Reference< XModel > SAL_CALL OApplicationController::getModel(void) throw( Runt } // ----------------------------------------------------------------------------- -void OApplicationController::onConnectedModel() +void OApplicationController::onAttachedFrame() { sal_Int32 nConnectedControllers( 0 ); try @@ -2612,9 +2639,15 @@ void OApplicationController::onConnectedModel() // ----------------------------------------------------------------------------- IMPL_LINK( OApplicationController, OnFirstControllerConnected, void*, /**/ ) { + ::osl::MutexGuard aGuard( getMutex() ); + + if ( !m_xModel.is() ) + { + OSL_ENSURE( false, "OApplicationController::OnFirstControllerConnected: too late!" ); + } + // if we have forms or reports which contain macros/scripts, then show a warning // which suggests the user to migrate them to the database document - Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY ); if ( xDocumentScripts.is() ) { @@ -2660,6 +2693,14 @@ IMPL_LINK( OApplicationController, OnFirstControllerConnected, void*, /**/ ) } // ----------------------------------------------------------------------------- +void SAL_CALL OApplicationController::attachFrame( const Reference< XFrame > & i_rxFrame ) throw( RuntimeException ) +{ + OApplicationController_CBASE::attachFrame( i_rxFrame ); + if ( getFrame().is() ) + onAttachedFrame(); +} + +// ----------------------------------------------------------------------------- sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > & _rxModel) throw( RuntimeException ) { ::osl::MutexGuard aGuard( getMutex() ); @@ -2675,16 +2716,13 @@ sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > // at least: remove as property change listener from the old model/data source m_xModel = _rxModel; - if ( _rxModel.is() ) + if ( m_xModel.is() ) { m_xDocumentModify.set( m_xModel, UNO_QUERY_THROW ); - m_aModelConnector.connect( _rxModel, this ); - onConnectedModel(); } else { m_xDocumentModify.clear(); - m_aModelConnector.clear(); } m_xDataSource.set(xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference<XDataSource>(),UNO_QUERY); @@ -2760,7 +2798,7 @@ void OApplicationController::containerFound( const Reference< XContainer >& _xCo try { sName = getContainer()->getQualifiedName( NULL ); - OSL_ENSURE( sName.getLength(), "OApplicationController::newElementWithPilot: no name given!" ); + OSL_ENSURE( sName.getLength(), "OApplicationController::getCurrentlySelectedName: no name given!" ); } catch( const Exception& ) { diff --git a/dbaccess/source/ui/app/AppController.hxx b/dbaccess/source/ui/app/AppController.hxx index d47874208..03029d062 100644 --- a/dbaccess/source/ui/app/AppController.hxx +++ b/dbaccess/source/ui/app/AppController.hxx @@ -32,7 +32,6 @@ #include "AppElementType.hxx" #include "callbacks.hxx" #include "commontypes.hxx" -#include "documentcontroller.hxx" #include "dsntypes.hxx" #include "genericcontroller.hxx" #include "linkeddocuments.hxx" @@ -120,8 +119,6 @@ namespace dbaui ::cppu::OInterfaceContainerHelper m_aContextMenuInterceptors; - ModelControllerConnector - m_aModelConnector; TContainerVector m_aCurrentContainers; // the containers where we are listener on ::rtl::Reference< SubComponentManager > m_pSubComponentManager; @@ -197,10 +194,15 @@ namespace dbaui /** opens a new frame for creation or auto pilot @param _eType Defines the type to open - @param _bSQLView - If <TRUE/> the query design will be opened in SQL view, otherwise not. + @param i_rAdditionalArguments + Additional arguments to pass when creating the component */ - void newElement( ElementType _eType , sal_Bool _bSQLView ); + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + newElement( + ElementType _eType, + const ::comphelper::NamedValueCollection& i_rAdditionalArguments, + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_rDocumentDefinition + ); /** creates a new database object, using an auto pilot @param _eType @@ -384,12 +386,12 @@ namespace dbaui */ void showPreviewFor( const ElementType _eType,const ::rtl::OUString& _sName ); - /** called when we just connected to a new, non-NULL model + /** called we were attached to a frame In particular, this is called *after* the controller has been announced to the model (XModel::connectController) */ - void onConnectedModel(); + void onAttachedFrame(); /// determines whether the given table name denotes a view which can be altered bool impl_isAlterableView_nothrow( const ::rtl::OUString& _rTableOrViewName ) const; @@ -402,7 +404,7 @@ namespace dbaui /** verifies the object type denotes a valid DatabaseObject, and the object name denotes an existing object of this type. Throws if not. */ - void impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::rtl::OUString& _rObjectName ); + void impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::boost::optional< ::rtl::OUString >& i_rObjectName ); protected: // ---------------------------------------------------------------- @@ -443,6 +445,7 @@ namespace dbaui SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); // ::com::sun::star::frame::XController + virtual void SAL_CALL attachFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > & xFrame) throw( ::com::sun::star::uno::RuntimeException ); virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException ); virtual sal_Bool SAL_CALL attachModel(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xModel) throw( ::com::sun::star::uno::RuntimeException ); virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SAL_CALL getModel(void) throw( ::com::sun::star::uno::RuntimeException ); @@ -462,9 +465,12 @@ namespace dbaui virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > > SAL_CALL getSubComponents() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL isConnected( ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL connect( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::beans::Pair< ::sal_Int32, ::rtl::OUString > SAL_CALL identifySubComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& SubComponent ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL closeSubComponents( ) throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponent( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponentWithArguments( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL createComponent( ::sal_Int32 ObjectType, ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_DocumentDefinition ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL createComponentWithArguments( ::sal_Int32 ObjectType, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments, ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_DocumentDefinition ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); // XContextMenuInterception virtual void SAL_CALL registerContextMenuInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XContextMenuInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException); diff --git a/dbaccess/source/ui/app/AppControllerDnD.cxx b/dbaccess/source/ui/app/AppControllerDnD.cxx index 8d4bbad93..abb5ed8da 100644 --- a/dbaccess/source/ui/app/AppControllerDnD.cxx +++ b/dbaccess/source/ui/app/AppControllerDnD.cxx @@ -610,7 +610,7 @@ void OApplicationController::getSelectionElementNames(::std::vector< ::rtl::OUSt } ::std::auto_ptr< OLinkedDocumentsAccess > pDocuments( new OLinkedDocumentsAccess( - getView(), m_aCurrentFrame.getFrame(), getORB(), xDocContainer, xConnection, getDatabaseName() + getView(), this, getORB(), xDocContainer, xConnection, getDatabaseName() ) ); return pDocuments; } diff --git a/dbaccess/source/ui/app/AppControllerGen.cxx b/dbaccess/source/ui/app/AppControllerGen.cxx index 5ecf8a6ce..7d2575220 100644 --- a/dbaccess/source/ui/app/AppControllerGen.cxx +++ b/dbaccess/source/ui/app/AppControllerGen.cxx @@ -87,6 +87,7 @@ namespace dbaui using namespace ::dbtools; using namespace ::connectivity; using namespace ::svx; +using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::awt; using namespace ::com::sun::star::util; @@ -104,6 +105,7 @@ using namespace ::com::sun::star::ucb; using ::com::sun::star::util::XCloseable; using ::com::sun::star::ui::XContextMenuInterceptor; /** === end UNO using === **/ + namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; namespace ErrorCondition = ::com::sun::star::sdb::ErrorCondition; @@ -325,15 +327,22 @@ void SAL_CALL OApplicationController::propertyChange( const PropertyChangeEvent& ::rtl::OUString sOldName,sNewName; evt.OldValue >>= sOldName; evt.NewValue >>= sNewName; - Reference<XChild> xChild(evt.Source,UNO_QUERY); - if ( xChild.is() ) + + // if the old name is empty, then this is a newly inserted content. We're notified of it via the + // elementInserted method, so there's no need to handle it here. + + if ( sOldName.getLength() ) { - Reference<XContent> xContent(xChild->getParent(),UNO_QUERY); - if ( xContent.is() ) - sOldName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sOldName; - } + Reference<XChild> xChild(evt.Source,UNO_QUERY); + if ( xChild.is() ) + { + Reference<XContent> xContent(xChild->getParent(),UNO_QUERY); + if ( xContent.is() ) + sOldName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sOldName; + } - getContainer()->elementReplaced( eType , sOldName, sNewName ); + getContainer()->elementReplaced( eType , sOldName, sNewName ); + } } } @@ -362,6 +371,7 @@ Reference< XWindow > SAL_CALL OApplicationController::getApplicationMainWindow() // ----------------------------------------------------------------------------- Sequence< Reference< XComponent > > SAL_CALL OApplicationController::getSubComponents() throw (RuntimeException) { + ::osl::MutexGuard aGuard( getMutex() ); return m_pSubComponentManager->getSubComponents(); } @@ -382,6 +392,9 @@ Reference< XConnection > SAL_CALL OApplicationController::getActiveConnection() // ----------------------------------------------------------------------------- void SAL_CALL OApplicationController::connect( ) throw (SQLException, RuntimeException) { + ::vos::OGuard aSolarGuard(Application::GetSolarMutex()); + ::osl::MutexGuard aGuard( getMutex() ); + SQLExceptionInfo aError; SharedConnection xConnection = ensureConnection( &aError ); if ( !xConnection.is() ) @@ -397,8 +410,29 @@ void SAL_CALL OApplicationController::connect( ) throw (SQLException, RuntimeEx } // ----------------------------------------------------------------------------- +beans::Pair< ::sal_Int32, ::rtl::OUString > SAL_CALL OApplicationController::identifySubComponent( const Reference< XComponent >& i_rSubComponent ) throw (IllegalArgumentException, RuntimeException) +{ + ::osl::MutexGuard aGuard( getMutex() ); + + sal_Int32 nType = -1; + ::rtl::OUString sName; + + if ( !m_pSubComponentManager->lookupSubComponent( i_rSubComponent, sName, nType ) ) + throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); + + if ( nType == SID_DB_APP_DSRELDESIGN ) + // this is somewhat hacky ... we're expected to return a DatabaseObject value. However, there is no such + // value for the relation design. /me thinks we should change the API definition here ... + nType = -1; + + return beans::Pair< ::sal_Int32, ::rtl::OUString >( nType, sName ); +} + +// ----------------------------------------------------------------------------- ::sal_Bool SAL_CALL OApplicationController::closeSubComponents( ) throw (RuntimeException) { + ::vos::OGuard aSolarGuard(Application::GetSolarMutex()); + ::osl::MutexGuard aGuard( getMutex() ); return m_pSubComponentManager->closeSubComponents(); } @@ -424,7 +458,7 @@ namespace } // ----------------------------------------------------------------------------- -void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::rtl::OUString& _rObjectName ) +void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::boost::optional< ::rtl::OUString >& i_rObjectName ) { // ensure we're connected if ( !isConnected() ) @@ -441,6 +475,9 @@ void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int ) throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); + if ( !i_rObjectName ) + return; + // ensure an existing object Reference< XNameAccess > xContainer( getElements( lcl_objectType2ElementType( _nObjectType ) ) ); if ( !xContainer.is() ) @@ -453,19 +490,19 @@ void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int { case DatabaseObject::TABLE: case DatabaseObject::QUERY: - bExistentObject = xContainer->hasByName( _rObjectName ); + bExistentObject = xContainer->hasByName( *i_rObjectName ); break; case DatabaseObject::FORM: case DatabaseObject::REPORT: { Reference< XHierarchicalNameAccess > xHierarchy( xContainer, UNO_QUERY_THROW ); - bExistentObject = xHierarchy->hasByHierarchicalName( _rObjectName ); + bExistentObject = xHierarchy->hasByHierarchicalName( *i_rObjectName ); } break; } if ( !bExistentObject ) - throw NoSuchElementException( _rObjectName, *this ); + throw NoSuchElementException( *i_rObjectName, *this ); } // ----------------------------------------------------------------------------- @@ -496,6 +533,29 @@ Reference< XComponent > SAL_CALL OApplicationController::loadComponentWithArgume } // ----------------------------------------------------------------------------- +Reference< XComponent > SAL_CALL OApplicationController::createComponent( ::sal_Int32 i_nObjectType, Reference< XComponent >& o_DocumentDefinition ) throw (IllegalArgumentException, SQLException, RuntimeException) +{ + return createComponentWithArguments( i_nObjectType, Sequence< PropertyValue >(), o_DocumentDefinition ); +} + +// ----------------------------------------------------------------------------- +Reference< XComponent > SAL_CALL OApplicationController::createComponentWithArguments( ::sal_Int32 i_nObjectType, const Sequence< PropertyValue >& i_rArguments, Reference< XComponent >& o_DocumentDefinition ) throw (IllegalArgumentException, SQLException, RuntimeException) +{ + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( getMutex() ); + + impl_validateObjectTypeAndName_throw( i_nObjectType, ::boost::optional< ::rtl::OUString >() ); + + Reference< XComponent > xComponent( newElement( + lcl_objectType2ElementType( i_nObjectType ), + ::comphelper::NamedValueCollection( i_rArguments ), + o_DocumentDefinition + ) ); + + return xComponent; +} + +// ----------------------------------------------------------------------------- void SAL_CALL OApplicationController::registerContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException) { if ( _Interceptor.is() ) diff --git a/dbaccess/source/ui/app/AppDetailPageHelper.cxx b/dbaccess/source/ui/app/AppDetailPageHelper.cxx index e30636345..746b7ec1c 100644 --- a/dbaccess/source/ui/app/AppDetailPageHelper.cxx +++ b/dbaccess/source/ui/app/AppDetailPageHelper.cxx @@ -1286,15 +1286,11 @@ void OAppDetailPageHelper::showPreview( const ::rtl::OUString& _sDataSourceName, ) ); pDispatcher->setTargetFrame( m_xFrame ); - Sequence < PropertyValue > aArgs( 4 ); - aArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Preview")); - aArgs[0].Value <<= sal_True; - aArgs[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")); - aArgs[1].Value <<= sal_True; - aArgs[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AsTemplate")); - aArgs[2].Value <<= sal_False; - aArgs[3].Name = PROPERTY_SHOWMENU; - aArgs[3].Value <<= sal_False; + ::comphelper::NamedValueCollection aArgs; + aArgs.put( "Preview", sal_True ); + aArgs.put( "ReadOnly", sal_True ); + aArgs.put( "AsTemplate", sal_False ); + aArgs.put( (::rtl::OUString)PROPERTY_SHOWMENU, sal_False ); Reference< XController > xPreview( pDispatcher->openExisting( makeAny( _sDataSourceName ), _sName, aArgs ), UNO_QUERY ); sal_Bool bClearPreview = !xPreview.is(); diff --git a/dbaccess/source/ui/app/subcomponentmanager.cxx b/dbaccess/source/ui/app/subcomponentmanager.cxx index 55b9b4902..251ba9b8d 100644 --- a/dbaccess/source/ui/app/subcomponentmanager.cxx +++ b/dbaccess/source/ui/app/subcomponentmanager.cxx @@ -26,6 +26,7 @@ #include "subcomponentmanager.hxx" #include "AppController.hxx" +#include "dbustrings.hrc" /** === begin UNO includes === **/ #include <com/sun/star/frame/XFrame.hpp> @@ -36,6 +37,7 @@ #include <com/sun/star/embed/XComponentSupplier.hpp> #include <com/sun/star/ucb/XCommandProcessor.hpp> #include <com/sun/star/document/XDocumentEventBroadcaster.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> /** === end UNO includes === **/ #include <tools/diagnose_ex.h> @@ -46,10 +48,10 @@ #include <algorithm> #include <functional> -//........................................................................ +//...................................................................................................................... namespace dbaui { -//........................................................................ +//...................................................................................................................... /** === begin UNO using === **/ using ::com::sun::star::uno::Reference; @@ -76,40 +78,61 @@ namespace dbaui using ::com::sun::star::ucb::XCommandProcessor; using ::com::sun::star::ucb::Command; using ::com::sun::star::document::XDocumentEventBroadcaster; + using ::com::sun::star::beans::XPropertySet; + using ::com::sun::star::beans::PropertyChangeEvent; /** === end UNO using === **/ - //============================================================================== + //================================================================================================================== //= helper structs - //============================================================================== + //================================================================================================================== namespace { + //.............................................................................................................. struct SubComponentDescriptor { + /// the name of the sub component, empty if it is yet unsaved + ::rtl::OUString sName; + /// type of the component - an ElementType value, except for relation design + sal_Int32 nComponentType; + /// the mode in which the sub component has been opened + ElementOpenMode eOpenMode; /// the frame which the component resides in. Must not be <NULL/> Reference< XFrame > xFrame; /// the controller of the sub component. Must not be <NULL/> Reference< XController > xController; /// the model of the sub component. Might be <NULL/> Reference< XModel > xModel; - /// the document definition which holds the component, if any - Reference< XCommandProcessor > xComponentCommandProcessor; + /// the document definition which holds the component, if any; as CommandProcessor + Reference< XCommandProcessor > xComponentCommandProcessor; + /// the document definition which holds the component, if any; as PropertySet + Reference< XPropertySet > xDocumentDefinitionProperties; SubComponentDescriptor() - :xFrame() + :sName() + ,nComponentType( -1 ) + ,eOpenMode( E_OPEN_NORMAL ) + ,xFrame() ,xController() ,xModel() { } - SubComponentDescriptor( const Reference< XComponent >& _rxComponent ) + SubComponentDescriptor( const ::rtl::OUString& i_rName, const sal_Int32 i_nComponentType, + const ElementOpenMode i_eOpenMode, const Reference< XComponent >& i_rComponent ) + :sName( i_rName ) + ,nComponentType( i_nComponentType ) + ,eOpenMode( i_eOpenMode ) { - if ( !impl_constructFrom( _rxComponent ) ) + if ( !impl_constructFrom( i_rComponent ) ) { - Reference< XComponentSupplier > xCompSupp( _rxComponent, UNO_QUERY_THROW ); + // i_rComponent is neither a model, nor a controller, nor a frame + // => it must be a css.sdb.DocumentDefinition + Reference< XComponentSupplier > xCompSupp( i_rComponent, UNO_QUERY_THROW ); Reference< XComponent > xComponent( xCompSupp->getComponent(), UNO_QUERY_THROW ); if ( !impl_constructFrom( xComponent ) ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Illegal component type." ) ), NULL ); - xComponentCommandProcessor.set( _rxComponent, UNO_QUERY_THROW ); + xComponentCommandProcessor.set( i_rComponent, UNO_QUERY_THROW ); + xDocumentDefinitionProperties.set( i_rComponent, UNO_QUERY_THROW ); } } @@ -153,6 +176,7 @@ namespace dbaui } }; + //.............................................................................................................. struct SelectSubComponent : public ::std::unary_function< SubComponentDescriptor, Reference< XComponent > > { Reference< XComponent > operator()( const SubComponentDescriptor _desc ) const @@ -164,55 +188,37 @@ namespace dbaui } }; - struct SubComponentAccessor - { - /// the name of the sub component - ::rtl::OUString sName; - /// type of the component - usually an ElementType value - sal_Int32 nComponentType; - /// the mode in which the sub component has been opened - ElementOpenMode eOpenMode; + //.............................................................................................................. + typedef ::std::vector< SubComponentDescriptor > SubComponents; - SubComponentAccessor() - :sName() - ,nComponentType( sal_Int32( E_NONE ) ) - ,eOpenMode( E_OPEN_NORMAL ) - { - } - - SubComponentAccessor( const ::rtl::OUString& _rName, const sal_Int32 _nCompType, const ElementOpenMode _eMode ) - :sName( _rName ) - ,nComponentType( _nCompType ) - ,eOpenMode( _eMode ) - { - } - }; - - struct SubComponentAccessorHash : public ::std::unary_function< SubComponentAccessor, size_t > + //.............................................................................................................. + struct SubComponentMatch : public ::std::unary_function< SubComponentDescriptor, bool > { - size_t operator()( const SubComponentAccessor& _lhs ) const + public: + SubComponentMatch( const ::rtl::OUString& i_rName, const sal_Int32 i_nComponentType, + const ElementOpenMode i_eOpenMode ) + :m_sName( i_rName ) + ,m_nComponentType( i_nComponentType ) + ,m_eOpenMode( i_eOpenMode ) { - return _lhs.sName.hashCode() + _lhs.nComponentType + size_t( _lhs.eOpenMode ); } - }; - struct SubComponentAccessorEqual : public ::std::binary_function< SubComponentAccessor, SubComponentAccessor, bool > - { - bool operator()( const SubComponentAccessor& _lhs, const SubComponentAccessor& _rhs ) const + + bool operator()( const SubComponentDescriptor& i_rCompareWith ) const { - return ( _lhs.sName == _rhs.sName ) - && ( _lhs.nComponentType == _rhs.nComponentType ) - && ( _lhs.eOpenMode == _rhs.eOpenMode ); + return ( m_sName == i_rCompareWith.sName ) + && ( m_nComponentType == i_rCompareWith.nComponentType ) + && ( m_eOpenMode == i_rCompareWith.eOpenMode ); } + private: + const ::rtl::OUString m_sName; + const sal_Int32 m_nComponentType; + const ElementOpenMode m_eOpenMode; }; - - typedef ::std::hash_map< SubComponentAccessor, SubComponentDescriptor, SubComponentAccessorHash, SubComponentAccessorEqual > - SubComponentMap; - } - //============================================================================== + //================================================================================================================== //= SubComponentManager_Data - //============================================================================== + //================================================================================================================== struct SubComponentManager_Data { SubComponentManager_Data( OApplicationController& _rController, const ::comphelper::SharedMutex& _rMutex ) @@ -223,35 +229,36 @@ namespace dbaui OApplicationController& m_rController; mutable ::comphelper::SharedMutex m_aMutex; - SubComponentMap m_aComponents; + SubComponents m_aComponents; ::osl::Mutex& getMutex() const { return m_aMutex; } }; - //==================================================================== + //================================================================================================================== //= SubComponentManager - //==================================================================== - //-------------------------------------------------------------------- + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ SubComponentManager::SubComponentManager( OApplicationController& _rController, const ::comphelper::SharedMutex& _rMutex ) :m_pData( new SubComponentManager_Data( _rController, _rMutex ) ) { } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ SubComponentManager::~SubComponentManager() { } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ void SubComponentManager::disposing() { ::osl::MutexGuard aGuard( m_pData->getMutex() ); m_pData->m_aComponents.clear(); } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ namespace { + //.............................................................................................................. bool lcl_fallbackToAnotherController( SubComponentDescriptor& _rCompDesc ) { Reference< XController > xFallback; @@ -289,7 +296,7 @@ namespace dbaui return false; } - //---------------------------------------------------------------- + //.............................................................................................................. bool lcl_closeComponent( const Reference< XCommandProcessor >& _rxCommandProcessor ) { bool bSuccess = false; @@ -310,7 +317,7 @@ namespace dbaui return bSuccess; } - //---------------------------------------------------------------- + //.............................................................................................................. bool lcl_closeComponent( const SubComponentDescriptor& _rComponent ) { if ( _rComponent.xComponentCommandProcessor.is() ) @@ -338,7 +345,7 @@ namespace dbaui return bSuccess; } - // ----------------------------------------------------------------------------- + //.............................................................................................................. void lcl_notifySubComponentEvent( const SubComponentManager_Data& _rData, const sal_Char* _pAsciiEventName, const SubComponentDescriptor& _rComponent ) { @@ -358,43 +365,74 @@ namespace dbaui } } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ + void SAL_CALL SubComponentManager::propertyChange( const PropertyChangeEvent& i_rEvent ) throw (RuntimeException) + { + if ( i_rEvent.PropertyName != PROPERTY_NAME ) + // by definition, it's allowed to broadcast more than what we've registered for + return; + + // find the sub component whose name changed + for ( SubComponents::iterator comp = m_pData->m_aComponents.begin(); + comp != m_pData->m_aComponents.end(); + ++comp + ) + { + if ( comp->xDocumentDefinitionProperties != i_rEvent.Source ) + continue; + + ::rtl::OUString sNewName; + OSL_VERIFY( i_rEvent.NewValue >>= sNewName ); + + #if OSL_DEBUG_LEVEL > 0 + ::rtl::OUString sOldKnownName( comp->sName ); + ::rtl::OUString sOldName; + OSL_VERIFY( i_rEvent.OldValue >>= sOldName ); + OSL_ENSURE( sOldName == sOldKnownName, "SubComponentManager::propertyChange: inconsistency in the old names!" ); + #endif + + comp->sName = sNewName; + break; + } + } + + //------------------------------------------------------------------------------------------------------------------ void SAL_CALL SubComponentManager::disposing( const EventObject& _rSource ) throw (RuntimeException) { ::osl::ClearableMutexGuard aGuard( m_pData->getMutex() ); SubComponentDescriptor aClosedComponent; - for ( SubComponentMap::iterator comp = m_pData->m_aComponents.begin(); + for ( SubComponents::iterator comp = m_pData->m_aComponents.begin(); comp != m_pData->m_aComponents.end(); ++comp ) { bool bRemove = false; - if ( comp->second.xController == _rSource.Source ) + if ( comp->xController == _rSource.Source ) { - if ( !comp->second.xModel.is() ) + if ( !comp->xModel.is() ) { bRemove = true; } else { // maybe this is just one view to the sub document, and only this view is closed - if ( !lcl_fallbackToAnotherController( comp->second ) ) + if ( !lcl_fallbackToAnotherController( *comp ) ) { bRemove = true; } } } - else if ( comp->second.xModel == _rSource.Source ) + else if ( comp->xModel == _rSource.Source ) { bRemove = true; } if ( bRemove ) { - aClosedComponent = comp->second; + aClosedComponent = *comp; m_pData->m_aComponents.erase( comp ); break; } @@ -407,7 +445,7 @@ namespace dbaui } } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ Sequence< Reference< XComponent> > SubComponentManager::getSubComponents() const { ::osl::MutexGuard aGuard( m_pData->getMutex() ); @@ -417,12 +455,12 @@ namespace dbaui m_pData->m_aComponents.begin(), m_pData->m_aComponents.end(), aComponents.getArray(), - ::std::compose1( SelectSubComponent(), ::std::select2nd< SubComponentMap::value_type >() ) + SelectSubComponent() ); return aComponents; } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ sal_Bool SubComponentManager::closeSubComponents() { ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); @@ -430,16 +468,13 @@ namespace dbaui try { - typedef ::std::vector< SubComponentAccessor > ComponentAccessors; - ComponentAccessors aClosedComponents; - - SubComponentMap aComponents( m_pData->m_aComponents ); - for ( SubComponentMap::const_iterator comp = aComponents.begin(); - comp != aComponents.end(); + SubComponents aWorkingCopy( m_pData->m_aComponents ); + for ( SubComponents::const_iterator comp = aWorkingCopy.begin(); + comp != aWorkingCopy.end(); ++comp ) { - lcl_closeComponent( comp->second ); + lcl_closeComponent( *comp ); } } catch ( const Exception& ) @@ -450,78 +485,120 @@ namespace dbaui return empty(); } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ bool SubComponentManager::empty() const { ::osl::MutexGuard aGuard( m_pData->getMutex() ); return m_pData->m_aComponents.empty(); } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ void SubComponentManager::onSubComponentOpened( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType, const ElementOpenMode _eOpenMode, const Reference< XComponent >& _rxComponent ) { ::osl::ClearableMutexGuard aGuard( m_pData->getMutex() ); - // put into map - SubComponentAccessor aKey( _rName, _nComponentType, _eOpenMode ); - SubComponentDescriptor aElement( _rxComponent ); +#if OSL_DEBUG_LEVEL > 0 + if ( _rName.getLength() ) + { + // check there does not already exist such a component + SubComponents::const_iterator existentPos = ::std::find_if( + m_pData->m_aComponents.begin(), + m_pData->m_aComponents.end(), + SubComponentMatch( _rName, _nComponentType, _eOpenMode ) + ); + OSL_ENSURE( existentPos == m_pData->m_aComponents.end(), "already existent!" ); + } +#endif + SubComponentDescriptor aElement( _rName, _nComponentType, _eOpenMode, _rxComponent ); ENSURE_OR_THROW( aElement.xModel.is() || aElement.xController.is(), "illegal component" ); - m_pData->m_aComponents.insert( SubComponentMap::value_type( - aKey, aElement - ) ) ; + m_pData->m_aComponents.push_back( aElement ); // add as listener if ( aElement.xController.is() ) aElement.xController->addEventListener( this ); if ( aElement.xModel.is() ) aElement.xModel->addEventListener( this ); + if ( aElement.xDocumentDefinitionProperties.is() ) + aElement.xDocumentDefinitionProperties->addPropertyChangeListener( PROPERTY_NAME, this ); // notify this to interested parties aGuard.clear(); lcl_notifySubComponentEvent( *m_pData, "OnSubComponentOpened", aElement ); } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ bool SubComponentManager::activateSubFrame( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType, const ElementOpenMode _eOpenMode ) const { ::osl::MutexGuard aGuard( m_pData->getMutex() ); - SubComponentAccessor aKey( _rName, _nComponentType, _eOpenMode ); - SubComponentMap::const_iterator pos = m_pData->m_aComponents.find( aKey ); + SubComponents::const_iterator pos = ::std::find_if( + m_pData->m_aComponents.begin(), + m_pData->m_aComponents.end(), + SubComponentMatch( _rName, _nComponentType, _eOpenMode ) + ); if ( pos == m_pData->m_aComponents.end() ) // no component with this name/type/open mode return false; - const Reference< XFrame > xFrame( pos->second.xFrame, UNO_SET_THROW ); + const Reference< XFrame > xFrame( pos->xFrame, UNO_SET_THROW ); const Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW ); xTopWindow->toFront(); return true; } - // ----------------------------------------------------------------------------- - bool SubComponentManager::closeSubFrames( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType ) + //------------------------------------------------------------------------------------------------------------------ + bool SubComponentManager::closeSubFrames( const ::rtl::OUString& i_rName, const sal_Int32 _nComponentType ) { ::osl::MutexGuard aGuard( m_pData->getMutex() ); + ENSURE_OR_RETURN_FALSE( i_rName.getLength(), "SubComponentManager::closeSubFrames: illegal name!" ); - SubComponentMap aWorkingCopy( m_pData->m_aComponents ); - for ( SubComponentMap::const_iterator comp = aWorkingCopy.begin(); + SubComponents aWorkingCopy( m_pData->m_aComponents ); + for ( SubComponents::const_iterator comp = aWorkingCopy.begin(); comp != aWorkingCopy.end(); ++comp ) { - if ( ( comp->first.sName != _rName ) || ( comp->first.nComponentType != _nComponentType ) ) + if ( ( comp->sName != i_rName ) || ( comp->nComponentType != _nComponentType ) ) continue; - if ( !lcl_closeComponent( comp->second ) ) + if ( !lcl_closeComponent( *comp ) ) return false; } return true; } -//........................................................................ + //------------------------------------------------------------------------------------------------------------------ + bool SubComponentManager::lookupSubComponent( const Reference< XComponent >& i_rComponent, + ::rtl::OUString& o_rName, sal_Int32& o_rComponentType ) + { + for ( SubComponents::const_iterator comp = m_pData->m_aComponents.begin(); + comp != m_pData->m_aComponents.end(); + ++comp + ) + { + if ( ( comp->xModel.is() + && ( comp->xModel == i_rComponent ) + ) + || ( comp->xController.is() + && ( comp->xController == i_rComponent ) + ) + || ( comp->xFrame.is() + && ( comp->xFrame == i_rComponent ) + ) + ) + { + o_rName = comp->sName; + o_rComponentType = comp->nComponentType; + return true; + } + } + return false; + } + +//...................................................................................................................... } // namespace dbaui -//........................................................................ +//...................................................................................................................... diff --git a/dbaccess/source/ui/app/subcomponentmanager.hxx b/dbaccess/source/ui/app/subcomponentmanager.hxx index c79f25913..d84cef286 100644 --- a/dbaccess/source/ui/app/subcomponentmanager.hxx +++ b/dbaccess/source/ui/app/subcomponentmanager.hxx @@ -30,7 +30,7 @@ #include "AppElementType.hxx" /** === begin UNO includes === **/ -#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/beans/XPropertyChangeListener.hpp> #include <com/sun/star/frame/XController.hpp> /** === end UNO includes === **/ @@ -50,7 +50,7 @@ namespace dbaui //==================================================================== //= SubComponentManager //==================================================================== - typedef ::cppu::WeakImplHelper1 < ::com::sun::star::lang::XEventListener + typedef ::cppu::WeakImplHelper1 < ::com::sun::star::beans::XPropertyChangeListener > SubComponentManager_Base; class SubComponentManager : public SubComponentManager_Base { @@ -60,6 +60,9 @@ namespace dbaui void disposing(); + // XPropertyChangeListener + virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException); + // XEventListener virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); @@ -103,6 +106,24 @@ namespace dbaui const ::rtl::OUString& _rName, const sal_Int32 _nComponentType ); + + /** searches for the given sub component + + @param i_rComponent + the sub component to look up + @param o_rName + contains, upon successful return, the name of the sub component + @param o_nComponentType + contains, upon successful return, the type of the sub component + @return + <TRUE/> if and only if the component was found + */ + bool lookupSubComponent( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& i_rComponent, + ::rtl::OUString& o_rName, + sal_Int32& o_rComponentType + ); + private: ::std::auto_ptr< SubComponentManager_Data > m_pData; }; diff --git a/dbaccess/source/ui/browser/brwctrlr.cxx b/dbaccess/source/ui/browser/brwctrlr.cxx index 087212a6b..1d08aa456 100644 --- a/dbaccess/source/ui/browser/brwctrlr.cxx +++ b/dbaccess/source/ui/browser/brwctrlr.cxx @@ -628,7 +628,6 @@ SbaXDataBrowserController::SbaXDataBrowserController(const Reference< ::com::sun ,m_sStateSaveRecord(ModuleRes(RID_STR_SAVE_CURRENT_RECORD)) ,m_sStateUndoRecord(ModuleRes(RID_STR_UNDO_MODIFY_RECORD)) ,m_sModuleIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DataSourceBrowser" ) ) ) - ,m_pLoadThread(NULL) ,m_pFormControllerImpl(NULL) ,m_nPendingLoadFinished(0) ,m_nFormActionNestingLevel(0) @@ -828,7 +827,7 @@ sal_Bool SbaXDataBrowserController::Construct(Window* pParent) // --------------- // create the view - m_pView = new UnoDataBrowserView( pParent, *this, getORB() ); + setView( * new UnoDataBrowserView( pParent, *this, getORB() ) ); if (!getBrowserView()) return sal_False; @@ -1290,45 +1289,6 @@ void SbaXDataBrowserController::elementReplaced(const ::com::sun::star::containe sal_Bool SbaXDataBrowserController::suspend(sal_Bool /*bSuspend*/) throw( RuntimeException ) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::suspend" ); - // have a pending open operation ? - if (PendingLoad()) - { - ::vos::OGuard aGuard(Application::GetSolarMutex()); - if (m_nPendingLoadFinished != 0) - { // clean up directly. Otherwise there may be a pending asynchronous call - // to OnOpenFinishedMainThread, which won't be executed before we leave - // this method. Sounds like a classic infinite loop. - Application::RemoveUserEvent(m_nPendingLoadFinished); - LINK(this, SbaXDataBrowserController, OnOpenFinishedMainThread).Call(NULL); - } - else - { // set m_bClosingKillOpen to ensure that the our termination handler reacts according - // it's context - m_bClosingKillOpen = sal_True; - - // normally we would now just wait for termination of the load thread, but there is a small problem : - // In the current thread the global solar mutex is locked (that's for sure). If the loading of the - // form tries to acquire (blocking) the solar mutex, too, and we loop waiting for the other thread - // we have a classic deadlock. And bet your ass that ANYBODY in the foreign thread tries to lock - // the solar mutex. Almost all the UNO-capsules around normal C++ classes use the solar mutex for - // "thread safety" (which doesn't deserve that name anymore ;), e.g. the XNumberFormatter-implementation - // does. - // So we have to do a fake : we tell the loading thread that we aren't interested in the results anymore - // and the thread deletes itself (and the data source) as soon as it is done. As it holds the last - // references to the form (and thus, indirectly, to the grid) they will be cleared as soon as the thread dies. - // So all is fine. Except the small flaw that the form is still loading in the background while the - // window that should display it is already dead. - // If we could release the solar mutex in this thread and block it 'til the loader is finished we could - // solve it in a less dirty way, but uinfortunatelly we don't know how often this thread acquired the mutex. - // With high effort we could reach this with releasing the mutex until a third thread - which has to be - // created - can acquire it.Then we block, the third thread releases the mutex (and dies) and the loader - // thread would be able to finish. But that sounds difficult and fault-prone, so I think it's not worth it ... - ((LoadFormThread*)m_pLoadThread)->SetTerminationHdl(Link()); - // and of course we tell the thread to stop .... - ((LoadFormThread*)m_pLoadThread)->StopIt(); - } - - } DBG_ASSERT(m_nPendingLoadFinished == 0, "SbaXDataBrowserController::suspend : there shouldn't be a pending load !"); m_aAsyncGetCellFocus.CancelCall(); @@ -1344,42 +1304,30 @@ void SbaXDataBrowserController::disposing() // the base class SbaXDataBrowserController_Base::OGenericUnoController::disposing(); - if (!PendingLoad()) + // the data source + Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY); + if (xFormSet.is()) { - // don't do the removeXxxListener calls if there is a pending load, this may lead to a deadlock : - // as in this thread the SolarMutex is locked (that's for sure) and removeXxxListener locks - // the form's mutex. But in the loading thread both mutexes are acquired in reverse order. - // That's no problem that we don't remove ourself here, as the load thread is responsible for the form - // at the moment. So if the loading is finished, the form will be disposed (by the load thread), and - // we get the "disposing" event where we can do the removeXxxListener calls. - // The alternative for this handling would be that the form has two mutexes : one for handling it's - // listeners and properties and so on, on for it's pure cursor actions - - // the data source - Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY); - if (xFormSet.is()) - { - xFormSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this)); - xFormSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this)); - xFormSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this)); - xFormSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this)); - xFormSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this)); - xFormSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this)); - xFormSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this)); - xFormSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this)); - } + xFormSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this)); + xFormSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this)); + xFormSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this)); + xFormSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this)); + xFormSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this)); + xFormSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this)); + xFormSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this)); + xFormSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this)); + } - Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY); - if (xFormError.is()) - xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this); + Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY); + if (xFormError.is()) + xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this); - if (m_xLoadable.is()) - m_xLoadable->removeLoadListener(this); + if (m_xLoadable.is()) + m_xLoadable->removeLoadListener(this); - Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(getRowSet(), UNO_QUERY); - if (xFormParameter.is()) - xFormParameter->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this); - } + Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(getRowSet(), UNO_QUERY); + if (xFormParameter.is()) + xFormParameter->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this); removeModelListeners(getControlModel()); @@ -1395,31 +1343,24 @@ void SbaXDataBrowserController::disposing() { removeControlListeners(getBrowserView()->getGridControl()); // don't delete explicitly, this is done by the owner (and user) of this controller (me hopes ...) - m_pView = NULL; + clearView(); } if(m_aInvalidateClipboard.IsActive()) m_aInvalidateClipboard.Stop(); - // dispose the data source - // if there is a pending load we decided to give the responsibility for the data source to the open thread - // (see ::suspend) - if (!PendingLoad()) + // dispose the row set + try { - try - { - ::comphelper::disposeComponent(m_xRowSet); - - m_xRowSet = NULL; - m_xColumnsSupplier = NULL; - m_xLoadable = NULL; + ::comphelper::disposeComponent(m_xRowSet); - m_nRowSetPrivileges = 0; - } - catch(const Exception&) - { - DBG_UNHANDLED_EXCEPTION(); - } + m_xRowSet = NULL; + m_xColumnsSupplier = NULL; + m_xLoadable = NULL; + } + catch(Exception&) + { + DBG_UNHANDLED_EXCEPTION(); } try { @@ -1539,7 +1480,7 @@ sal_Bool SbaXDataBrowserController::approveParameter(const ::com::sun::star::for pParamRequest->addContinuation(pAbort); // create the handler, let it handle the request - Reference< XInteractionHandler > xHandler(getORB()->createInstance(SERVICE_SDB_INTERACTION_HANDLER), UNO_QUERY); + Reference< XInteractionHandler > xHandler(getORB()->createInstance(SERVICE_TASK_INTERACTION_HANDLER), UNO_QUERY); if (xHandler.is()) xHandler->handle(xParamRequest); @@ -1637,9 +1578,6 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const aReturn.bEnabled = m_xParser->getFilter().getLength() || m_xParser->getHavingClause().getLength() || m_xParser->getOrder().getLength(); return aReturn; } - // no chance while loading the form - if (PendingLoad()) - return aReturn; // no chance without valid models if (isValid() && !isValidCursor()) return aReturn; @@ -1730,7 +1668,7 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const { // a native statement can't be filtered or sorted const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY); - if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING))) + if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() ) break; Reference< XPropertySet > xCurrentField = getBoundField(); @@ -1749,7 +1687,7 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const break; case ID_BROWSER_FILTERCRIT: - if ( m_bCannotSelectUnfiltered ) + if ( m_bCannotSelectUnfiltered && m_xParser.is() ) { aReturn.bEnabled = sal_True; break; @@ -1758,7 +1696,7 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const case ID_BROWSER_ORDERCRIT: { const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY); - if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING))) + if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() ) break; aReturn.bEnabled = getRowSet().is() @@ -2659,45 +2597,6 @@ IMPL_LINK(SbaXDataBrowserController, OnCanceledNotFound, FmFoundRecordInformatio } //------------------------------------------------------------------------------ -IMPL_LINK(SbaXDataBrowserController, OnOpenFinishedMainThread, void*, EMPTYARG) -{ - ::vos::OGuard aGuard(Application::GetSolarMutex()); - if (!m_nPendingLoadFinished) - // it's possible that the direct call of this link from within suspend caused this method to be executed - // in another thread while we were waiting for the mutex in this thread - return 0; - m_nPendingLoadFinished = 0; - - if ( static_cast< LoadFormThread* >( m_pLoadThread )->WasCanceled() ) - setLoadingCancelled(); - - delete m_pLoadThread; - m_pLoadThread = NULL; - - LoadFinished(sal_False); - - return 0L; -} - -//------------------------------------------------------------------------------ -IMPL_LINK(SbaXDataBrowserController, OnOpenFinished, void*, EMPTYARG) -{ - ::osl::MutexGuard aCheckGuard(m_aAsyncLoadSafety); - - if (m_bClosingKillOpen) - { - delete m_pLoadThread; - m_pLoadThread = NULL; - } - else - // all cleaning has to run in the main thread, not here (this is called synchronously from the LoadThread) - // so we use an user event - m_nPendingLoadFinished = Application::PostUserEvent(LINK(this, SbaXDataBrowserController, OnOpenFinishedMainThread)); - - return 0L; -} - -//------------------------------------------------------------------------------ IMPL_LINK(SbaXDataBrowserController, OnAsyncGetCellFocus, void*, EMPTYARG) { SbaGridControl* pVclGrid = getBrowserView() ? getBrowserView()->getVclControl() : NULL; @@ -3067,171 +2966,6 @@ bool LoadFormHelper::WaitUntilReallyLoaded(bool _bOnlyIfLoaded) return true; } -//================================================================== -// LoadFormThread - a thread for asynchronously loading a form -//================================================================== -//------------------------------------------------------------------------------ -void LoadFormThread::run() -{ - // On instantiation of a SfxCancellable the application is notified and 'switches on' the red stop button. - // Unfortunally this is conditioned with the acquirement of the solar mutex, and the application tries - // only once and ignores the notification if it fails. - // To prevent that we get the solar mutex and _block_ 'til we got it. - // As we are in the 'top level execution' of this thread (with a rather small stack and no other mutexes locked) - // we shouldn't experience problems with deadlocks ... - ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex()); - ThreadStopper* pStopper = new ThreadStopper(this, m_sStopperCaption); - aSolarGuard.clear(); - - // we're not canceled yet - ::osl::ClearableMutexGuard aResetGuard(m_aAccessSafety); - m_bCanceled = sal_False; - aResetGuard.clear(); - - LoadFormHelper* pHelper = new LoadFormHelper(m_xRowSet); - pHelper->acquire(); - - // start it - bool bErrorOccured = false; - Reference< XLoadable > xLoadable(m_xRowSet, UNO_QUERY); - try - { - Reference< XRowSet > xMove(m_xRowSet, UNO_QUERY); - DBG_ASSERT(xLoadable.is() && xMove.is(), "LoadFormThread::run : invalid cursor !"); - xLoadable->load(); - // go to the first record if the load was successfull. - Reference< XColumnsSupplier > xColumnsSupplier(m_xRowSet, UNO_QUERY); - Reference< ::com::sun::star::container::XNameAccess > xCols = xColumnsSupplier.is() ? xColumnsSupplier->getColumns() : Reference< ::com::sun::star::container::XNameAccess > (); - if (xCols.is() && xCols->hasElements()) - xMove->first(); - else - bErrorOccured = true; - } - catch(Exception&) - { - bErrorOccured = true; - } - - // check if we were canceled - ::osl::ClearableMutexGuard aTestGuard(m_aAccessSafety); - bool bReallyCanceled = m_bCanceled ? true : false;; - aTestGuard.clear(); - - bReallyCanceled |= bErrorOccured; - - // the load on the form is "slightly asyncronous" (which isn't covered by it's specification, anyway), so wait - // some time .... - // (though me thinks that the load of the new api is synchronous, so we won't need this LoadFormHelper anymore ...) - if (!bReallyCanceled) - pHelper->WaitUntilReallyLoaded(true); - - pHelper->cancel(); - pHelper->release(); - - // yes, we were, but eventually the cancel request didn't reach the data source in time - if (bReallyCanceled && xLoadable.is() && xLoadable->isLoaded()) - xLoadable->unload(); - - pStopper->OwnerTerminated(); - // this will cause the stopper to delete itself (in the main thread) so we don't have to take care of the - // solar mutex -} - -//------------------------------------------------------------------------------ -void LoadFormThread::onTerminated() -{ - ::osl::ClearableMutexGuard aGuard(m_aAccessSafety); - if (m_aTerminationHandler.IsSet()) - { - // within the call of our termination handler we may be deleted, so do anything which is a member - // access before the call ... - // FS - #69801# - 02.12.99 - Link aHandler(m_aTerminationHandler); - aGuard.clear(); - aHandler.Call(this); - } - else - { - // we are fully responsible for the data source and for ourself, so dispose the former ... - try - { - ::comphelper::disposeComponent(m_xRowSet); - - m_xRowSet = NULL; - } - catch(Exception&) - { - OSL_ENSURE(0,"Exception thrown by dispose"); - } - // ... and delete the latter - aGuard.clear(); // like above - releasing the mutex is a member access ... - delete this; - } -} - -//------------------------------------------------------------------------------ -void LoadFormThread::StopIt() -{ - ::osl::ClearableMutexGuard aResetGuard(m_aAccessSafety); - m_bCanceled = sal_True; - aResetGuard.clear(); - - Reference< XColumnsSupplier > xColumnsSupplier(m_xRowSet, UNO_QUERY); - if (!xColumnsSupplier.is()) - { - DBG_ERROR("LoadFormThread::StopIt : invalid data source !"); - return; - } - Reference< ::com::sun::star::container::XNameAccess > xCols(xColumnsSupplier->getColumns(), UNO_QUERY); - if (!xCols.is() || !xCols->hasElements()) - // the cursor isn't alive, don't need to cancel - return; - - Reference< ::com::sun::star::util::XCancellable > xCancel(m_xRowSet, UNO_QUERY); - if (xCancel.is()) - { - try { xCancel->cancel(); } catch(SQLException&) {} - // with this the cursor returns from it's load call, this terminates our run, this get's our termination handler to - // be called - // (the try-catch is just in case the cancel wasn't neccessary anymore) - } -} - -//------------------------------------------------------------------------------ -LoadFormThread::ThreadStopper::ThreadStopper(LoadFormThread* pOwner, const String& rTitle) - :SfxCancellable(SFX_APP()->GetCancelManager(), rTitle) - ,m_pOwner(pOwner) -{ -} - -//------------------------------------------------------------------------------ -void LoadFormThread::ThreadStopper::Cancel() -{ - if (!m_pOwner) - return; - - ::osl::MutexGuard aGuard(m_pOwner->m_aAccessSafety); - if (IsCancelled()) - // we already did pass this to our owner - return; - - SfxCancellable::Cancel(); - m_pOwner->StopIt(); -} - -//------------------------------------------------------------------------------ -void LoadFormThread::ThreadStopper::OwnerTerminated() -{ - m_pOwner = NULL; - Application::PostUserEvent(LINK(this, LoadFormThread::ThreadStopper, OnDeleteInMainThread), this); -} - -//------------------------------------------------------------------------------ -IMPL_LINK(LoadFormThread::ThreadStopper, OnDeleteInMainThread, LoadFormThread::ThreadStopper*, pThis) -{ - delete pThis; - return 0L; -} // ----------------------------------------------------------------------------- sal_Int16 SbaXDataBrowserController::getCurrentColumnPosition() { diff --git a/dbaccess/source/ui/browser/dataview.cxx b/dbaccess/source/ui/browser/dataview.cxx index 6ef40c4cb..9268866d6 100644 --- a/dbaccess/source/ui/browser/dataview.cxx +++ b/dbaccess/source/ui/browser/dataview.cxx @@ -37,6 +37,7 @@ #ifndef _COMPHELPER_TYPES_HXX_ #include <comphelper/types.hxx> #endif +#include <comphelper/namedvaluecollection.hxx> #ifndef _SFXAPP_HXX //autogen wg. SFX_APP #include <sfx2/app.hxx> #endif @@ -58,6 +59,7 @@ #ifndef _SVTOOLS_IMGDEF_HXX #include <svtools/imgdef.hxx> #endif +#include <tools/diagnose_ex.h> //......................................................................... namespace dbaui @@ -218,6 +220,27 @@ namespace dbaui // Check if we need to get new images for normal/high contrast mode m_rController.notifyHiContrastChanged(); } + + if ( nType == STATE_CHANGE_INITSHOW ) + { + // now that there's a view which is finally visible, remove the "Hidden" value from the + // model's arguments. + try + { + Reference< XController > xController( m_rController.getXController(), UNO_SET_THROW ); + Reference< XModel > xModel( xController->getModel(), UNO_QUERY ); + if ( xModel.is() ) + { + ::comphelper::NamedValueCollection aArgs( xModel->getArgs() ); + aArgs.remove( "Hidden" ); + xModel->attachResource( xModel->getURL(), aArgs.getPropertyValues() ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } } // ----------------------------------------------------------------------------- void ODataView::DataChanged( const DataChangedEvent& rDCEvt ) diff --git a/dbaccess/source/ui/browser/dsEntriesNoExp.cxx b/dbaccess/source/ui/browser/dsEntriesNoExp.cxx index 5a57f46bd..865503ac3 100644 --- a/dbaccess/source/ui/browser/dsEntriesNoExp.cxx +++ b/dbaccess/source/ui/browser/dsEntriesNoExp.cxx @@ -116,9 +116,21 @@ SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( SvLBoxEntry* return etTableOrView; if (pQueries == pEntryParent) + { + DBTreeListUserData* pEntryData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData()); + if ( pEntryData ) + return pEntryData->eType; + return etQuery; + } + while( pEntryParent != pQueries ) + { + pEntryParent = m_pTreeView->getListBox().GetParent(pEntryParent); + if ( !pEntryParent ) + return etUnknown; + } - return etUnknown; + return etQueryContainer; } //------------------------------------------------------------------------------ void SbaTableQueryBrowser::select(SvLBoxEntry* _pEntry, sal_Bool _bSelect) diff --git a/dbaccess/source/ui/browser/genericcontroller.cxx b/dbaccess/source/ui/browser/genericcontroller.cxx index 8fcd1f079..d0b1ff925 100644 --- a/dbaccess/source/ui/browser/genericcontroller.cxx +++ b/dbaccess/source/ui/browser/genericcontroller.cxx @@ -248,6 +248,7 @@ DBG_NAME(OGenericUnoController) // ------------------------------------------------------------------------- OGenericUnoController::OGenericUnoController(const Reference< XMultiServiceFactory >& _rM) :OGenericUnoController_Base( getMutex() ) + ,m_pView(NULL) #ifdef DBG_UTIL ,m_bDescribingSupportedFeatures( false ) #endif @@ -255,7 +256,6 @@ OGenericUnoController::OGenericUnoController(const Reference< XMultiServiceFacto ,m_aAsyncCloseTask(LINK(this, OGenericUnoController, OnAsyncCloseTask)) ,m_xServiceFactory(_rM) ,m_aCurrentFrame( *this ) - ,m_pView(NULL) ,m_bPreview(sal_False) ,m_bReadOnly(sal_False) ,m_bCurrentlyModified(sal_False) @@ -283,13 +283,13 @@ OGenericUnoController::OGenericUnoController(const Reference< XMultiServiceFacto // ----------------------------------------------------------------------------- OGenericUnoController::OGenericUnoController() :OGenericUnoController_Base( getMutex() ) + ,m_pView(NULL) #ifdef DBG_UTIL ,m_bDescribingSupportedFeatures( false ) #endif ,m_aAsyncInvalidateAll(LINK(this, OGenericUnoController, OnAsyncInvalidateAll)) ,m_aAsyncCloseTask(LINK(this, OGenericUnoController, OnAsyncCloseTask)) ,m_aCurrentFrame( *this ) - ,m_pView(NULL) ,m_bPreview(sal_False) ,m_bReadOnly(sal_False) ,m_bCurrentlyModified(sal_False) @@ -412,7 +412,7 @@ void SAL_CALL OGenericUnoController::initialize( const Sequence< Any >& aArgumen // no one clears my view if I won't ::std::auto_ptr<Window> aTemp(m_pView); m_pView = NULL; - throw e; + throw; } } @@ -477,6 +477,14 @@ Reference< XWindow > SAL_CALL OGenericUnoController::getComponentWindow() throw } // ----------------------------------------------------------------------- +Sequence< PropertyValue > SAL_CALL OGenericUnoController::getCreationArguments() throw (RuntimeException) +{ + // currently we do not support any creation args, so anything passed to XModel2::createViewController would be + // lost, so we can equally return an empty sequence here + return Sequence< PropertyValue >(); +} + +// ----------------------------------------------------------------------- void OGenericUnoController::attachFrame( const Reference< XFrame >& _rxFrame ) throw( RuntimeException ) { vos::OGuard aSolarGuard( Application::GetSolarMutex() ); diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx index a8ebfa519..70f7aa774 100644 --- a/dbaccess/source/ui/browser/unodatbr.cxx +++ b/dbaccess/source/ui/browser/unodatbr.cxx @@ -516,6 +516,8 @@ sal_Bool SbaTableQueryBrowser::InitializeGridModel(const Reference< ::com::sun:: DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData()); OSL_ENSURE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeGridModel: No table available!" ); + if ( !pData->xObjectProperties.is() ) + return sal_False; ::rtl::OUString* pStringIter = aProperties.getArray(); Any* pValueIter = aValues.getArray(); @@ -729,7 +731,7 @@ Reference<XPropertySet> getColumnHelper(SvLBoxEntry* _pCurrentlyDisplayed,const ::rtl::OUString aName; _rxSource->getPropertyValue(PROPERTY_NAME) >>= aName; if(xNames.is() && xNames->hasByName(aName)) - ::cppu::extractInterface(xRet,xNames->getByName(aName)); + xRet.set(xNames->getByName(aName),UNO_QUERY); } return xRet; } @@ -1097,7 +1099,47 @@ SvLBoxEntry* SbaTableQueryBrowser::getObjectEntry(const ::rtl::OUString& _rDataS m_pTreeView->getListBox().Expand(pCommandType); // look for the object - pObject = m_pTreeView->getListBox().GetEntryPosByName(_rCommand, pCommandType); + ::rtl::OUString sCommand = _rCommand; + sal_Int32 nIndex = 0; + do + { + ::rtl::OUString sPath = sCommand.getToken( 0, '/', nIndex ); + pObject = m_pTreeView->getListBox().GetEntryPosByName(sPath, pCommandType); + pCommandType = pObject; + if ( nIndex >= 0 ) + { + if (ensureEntryObject(pObject)) + { + DBTreeListUserData* pParentData = static_cast< DBTreeListUserData* >( pObject->GetUserData() ); + Reference< XNameAccess > xCollection( pParentData->xContainer, UNO_QUERY ); + sal_Int32 nIndex2 = nIndex; + sPath = sCommand.getToken( 0, '/', nIndex2 ); + try + { + if ( xCollection->hasByName(sPath) ) + { + if(!m_pTreeView->getListBox().GetEntryPosByName(sPath,pObject)) + { + Reference<XNameAccess> xChild(xCollection->getByName(sPath),UNO_QUERY); + DBTreeListUserData* pEntryData = new DBTreeListUserData; + pEntryData->eType = etQuery; + if ( xChild.is() ) + { + pEntryData->eType = etQueryContainer; + } + implAppendEntry( pObject, sPath, pEntryData, pEntryData->eType ); + } + } + } + catch(Exception&) + { + DBG_ERROR("SbaTableQueryBrowser::populateTree: could not fill the tree"); + } + } + } + // m_pTreeView->getListBox().Expand(pCommandType); + } + while ( nIndex >= 0 ); } } } @@ -1616,10 +1658,6 @@ FeatureState SbaTableQueryBrowser::GetState(sal_uInt16 nId) const if (isValid() && !isValidCursor() && nId != ID_BROWSER_CLOSE) return aReturn; - // no chance while loading the form - if (PendingLoad()) - return aReturn; - switch (nId) { case ID_BROWSER_INSERTCOLUMNS: @@ -1988,7 +2026,7 @@ void SbaTableQueryBrowser::initializeTreeModel() } } // ------------------------------------------------------------------------- -sal_Bool SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAccess, +void SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAccess, SvLBoxEntry* _pParent, EntryType _eEntryType) { @@ -2005,34 +2043,39 @@ sal_Bool SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xName { if(!m_pTreeView->getListBox().GetEntryPosByName(*pIter,_pParent)) { + Reference<XNameAccess> xChild(_xNameAccess->getByName(*pIter),UNO_QUERY); DBTreeListUserData* pEntryData = new DBTreeListUserData; pEntryData->eType = _eEntryType; - implAppendEntry( _pParent, *pIter, pEntryData, _eEntryType ); + if ( _eEntryType == etQuery && xChild.is() ) + { + pEntryData->eType = etQueryContainer; + } + implAppendEntry( _pParent, *pIter, pEntryData, pEntryData->eType ); } } } catch(Exception&) { DBG_ERROR("SbaTableQueryBrowser::populateTree: could not fill the tree"); - return sal_False; } - return sal_True; } //------------------------------------------------------------------------------ -void SbaTableQueryBrowser::implAppendEntry( SvLBoxEntry* _pParent, const String& _rName, void* _pUserData, EntryType _eEntryType ) +SvLBoxEntry* SbaTableQueryBrowser::implAppendEntry( SvLBoxEntry* _pParent, const String& _rName, void* _pUserData, EntryType _eEntryType ) { ::std::auto_ptr< ImageProvider > pImageProvider( getImageProviderFor( _pParent ) ); Image aImage, aImageHC; pImageProvider->getImages( _rName, getDatabaseObjectType( _eEntryType ), aImage, aImageHC ); - SvLBoxEntry* pNewEntry = m_pTreeView->getListBox().InsertEntry( _rName, _pParent, sal_False, LIST_APPEND, _pUserData ); + SvLBoxEntry* pNewEntry = m_pTreeView->getListBox().InsertEntry( _rName, _pParent, _eEntryType == etQueryContainer , LIST_APPEND, _pUserData ); m_pTreeView->getListBox().SetExpandedEntryBmp( pNewEntry, aImage, BMP_COLOR_NORMAL ); m_pTreeView->getListBox().SetCollapsedEntryBmp( pNewEntry, aImage, BMP_COLOR_NORMAL ); m_pTreeView->getListBox().SetExpandedEntryBmp( pNewEntry, aImageHC, BMP_COLOR_HIGHCONTRAST ); m_pTreeView->getListBox().SetCollapsedEntryBmp( pNewEntry, aImageHC, BMP_COLOR_HIGHCONTRAST ); + + return pNewEntry; } //------------------------------------------------------------------------------ @@ -2163,29 +2206,54 @@ sal_Bool SbaTableQueryBrowser::ensureEntryObject( SvLBoxEntry* _pEntry ) break; } - try { - Reference< XQueryDefinitionsSupplier > xQuerySup; - m_xDatabaseContext->getByName( getDataSourceAcessor( pDataSourceEntry ) ) >>= xQuerySup; - if (xQuerySup.is()) + SvLBoxEntry* pParent = m_pTreeView->getListBox().GetParent(_pEntry); + if ( pParent != pDataSourceEntry ) { - Reference< XNameAccess > xQueryDefs = xQuerySup->getQueryDefinitions(); - Reference< XContainer > xCont(xQueryDefs, UNO_QUERY); - if (xCont.is()) - // add as listener to get notified if elements are inserted or removed - xCont->addContainerListener(this); - - pEntryData->xContainer = xQueryDefs; + SvLBoxString* pString = (SvLBoxString*)_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING); + OSL_ENSURE(pString,"There must be a string item!"); + ::rtl::OUString aName(pString->GetText()); + DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pParent->GetUserData()); + try + { + Reference< XNameAccess > xNameAccess(pData->xContainer,UNO_QUERY); + if ( xNameAccess.is() ) + pEntryData->xContainer.set(xNameAccess->getByName(aName),UNO_QUERY); + } + catch(const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + bSuccess = pEntryData->xContainer.is(); } - else { - DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: no XQueryDefinitionsSupplier interface!"); + else + { + try + { + Reference< XQueryDefinitionsSupplier > xQuerySup; + m_xDatabaseContext->getByName( getDataSourceAcessor( pDataSourceEntry ) ) >>= xQuerySup; + if (xQuerySup.is()) + { + Reference< XNameAccess > xQueryDefs = xQuerySup->getQueryDefinitions(); + Reference< XContainer > xCont(xQueryDefs, UNO_QUERY); + if (xCont.is()) + // add as listener to get notified if elements are inserted or removed + xCont->addContainerListener(this); + + pEntryData->xContainer = xQueryDefs; + bSuccess = pEntryData->xContainer.is(); + } + else { + DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: no XQueryDefinitionsSupplier interface!"); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } break; default: @@ -2340,7 +2408,18 @@ IMPL_LINK(SbaTableQueryBrowser, OnSelectionChange, void*, /*NOINTERESTEDIN*/) { return implSelect( m_pTreeView->getListBox().FirstSelected() ) ? 1L : 0L; } - +//------------------------------------------------------------------------------ +SvLBoxEntry* SbaTableQueryBrowser::implGetConnectionEntry(SvLBoxEntry* _pEntry) const +{ + SvLBoxEntry* pCurrentEntry = _pEntry; + DBTreeListUserData* pEntryData = static_cast< DBTreeListUserData* >( pCurrentEntry->GetUserData() ); + while(pEntryData->eType != etDatasource ) + { + pCurrentEntry = m_pTreeModel->GetParent(pCurrentEntry); + pEntryData = static_cast< DBTreeListUserData* >( pCurrentEntry->GetUserData() ); + } + return pCurrentEntry; +} //------------------------------------------------------------------------------ bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry ) { @@ -2366,7 +2445,7 @@ bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry ) DBTreeListUserData* pContainerData = static_cast<DBTreeListUserData*>(pContainer->GetUserData()); // get the entry for the datasource - SvLBoxEntry* pConnection = m_pTreeModel->GetParent(pContainer); + SvLBoxEntry* pConnection = implGetConnectionEntry(pContainer); DBTreeListUserData* pConData = static_cast<DBTreeListUserData*>(pConnection->GetUserData()); // reinitialize the rowset @@ -2377,12 +2456,26 @@ bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry ) xRowSetProps->getPropertyValue(PROPERTY_COMMAND) >>= aOldName; sal_Int32 nOldType = 0; xRowSetProps->getPropertyValue(PROPERTY_COMMAND_TYPE) >>= nOldType; - Reference<XConnection> xOldConnection; - ::cppu::extractInterface(xOldConnection,xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION)); + Reference<XConnection> xOldConnection(xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION),UNO_QUERY); + // the name of the table or query SvLBoxString* pString = (SvLBoxString*)_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING); OSL_ENSURE(pString,"There must be a string item!"); - ::rtl::OUString aName(pString->GetText().GetBuffer()); + const ::rtl::OUString sSimpleName = pString->GetText(); + ::rtl::OUStringBuffer sNameBuffer(sSimpleName); + if ( etQueryContainer == pContainerData->eType ) + { + SvLBoxEntry* pTemp = pContainer; + while( m_pTreeModel->GetParent(pTemp) != pConnection ) + { + sNameBuffer.insert(0,sal_Unicode('/')); + pString = (SvLBoxString*)pTemp->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING); + OSL_ENSURE(pString,"There must be a string item!"); + sNameBuffer.insert(0,pString->GetText()); + pTemp = m_pTreeModel->GetParent(pTemp); + } + } + ::rtl::OUString aName = sNameBuffer.makeStringAndClear(); sal_Int32 nCommandType = ( etTableContainer == pContainerData->eType) ? CommandType::TABLE @@ -2440,9 +2533,14 @@ bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry ) break; case CommandType::QUERY: { - Reference<XQueriesSupplier> xSup( pConData->xConnection, UNO_QUERY ); - if(xSup.is()) - xNameAccess = xSup->getQueries(); + if ( pContainerData->xContainer.is() ) + xNameAccess.set( pContainerData->xContainer, UNO_QUERY ); + else + { + Reference<XQueriesSupplier> xSup( pConData->xConnection, UNO_QUERY ); + if(xSup.is()) + xNameAccess = xSup->getQueries(); + } } break; } @@ -2450,13 +2548,13 @@ bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry ) sStatus.SearchAndReplaceAscii("$name$", aName); BrowserViewStatusDisplay aShowStatus(static_cast<UnoDataBrowserView*>(getView()), sStatus); - if(xNameAccess.is() && xNameAccess->hasByName(aName)) + if(xNameAccess.is() && xNameAccess->hasByName(sSimpleName)) { DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData()); if ( !pData->xObjectProperties.is() ) { Reference<XInterface> xObject; - if(xNameAccess->getByName(aName) >>= xObject) // remember the table or query object + if(xNameAccess->getByName(sSimpleName) >>= xObject) // remember the table or query object { pData->xObjectProperties = pData->xObjectProperties.query( xObject ); // if the query contains a parameterized statement and preview is enabled we won't get any data. @@ -3279,7 +3377,7 @@ void SbaTableQueryBrowser::implAdministrate( SvLBoxEntry* _pApplyTo ) { Reference< XInteractionHandler > xInteractionHandler( getORB()->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.InteractionHandler" ) ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ), UNO_QUERY ); OSL_ENSURE( xInteractionHandler.is(), "SbaTableQueryBrowser::implAdministrate: no interaction handler available!" ); @@ -3496,7 +3594,7 @@ void SbaTableQueryBrowser::loadMenu(const Reference< XFrame >& _xFrame) { SvLBoxEntry* pContainer = m_pTreeModel->GetParent(m_pCurrentlyDisplayed); // get the entry for the datasource - SvLBoxEntry* pConnection = m_pTreeModel->GetParent(pContainer); + SvLBoxEntry* pConnection = implGetConnectionEntry(pContainer); ::rtl::OUString sName = m_pTreeView->getListBox().GetEntryText(m_pCurrentlyDisplayed); sTitle = GetEntryText( pConnection ); INetURLObject aURL(sTitle); diff --git a/dbaccess/source/ui/dlg/DbAdminImpl.cxx b/dbaccess/source/ui/dlg/DbAdminImpl.cxx index 70a7e5bf0..27f0191cf 100644 --- a/dbaccess/source/ui/dlg/DbAdminImpl.cxx +++ b/dbaccess/source/ui/dlg/DbAdminImpl.cxx @@ -353,6 +353,11 @@ void ODbDataSourceAdministrationHelper::clearPassword() // ----------------------------------------------------------------------------- Reference< XDriver > ODbDataSourceAdministrationHelper::getDriver() { + return getDriver(getConnectionURL()); +} +// ----------------------------------------------------------------------------- +Reference< XDriver > ODbDataSourceAdministrationHelper::getDriver(const ::rtl::OUString& _sURL) +{ // get the global DriverManager Reference< XDriverAccess > xDriverManager; String sCurrentActionError = String(ModuleRes(STR_COULDNOTCREATE_DRIVERMANAGER)); @@ -373,11 +378,11 @@ Reference< XDriver > ODbDataSourceAdministrationHelper::getDriver() throw SQLException(sCurrentActionError, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any()); - Reference< XDriver > xDriver = xDriverManager->getDriverByURL(getConnectionURL()); + Reference< XDriver > xDriver = xDriverManager->getDriverByURL(_sURL); if (!xDriver.is()) { sCurrentActionError = String(ModuleRes(STR_NOREGISTEREDDRIVER)); - sCurrentActionError.SearchAndReplaceAscii("#connurl#", getConnectionURL()); + sCurrentActionError.SearchAndReplaceAscii("#connurl#", _sURL); // will be caught and translated into an SQLContext exception throw SQLException(sCurrentActionError, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any()); } diff --git a/dbaccess/source/ui/dlg/DbAdminImpl.hxx b/dbaccess/source/ui/dlg/DbAdminImpl.hxx index 5487f03e7..f470bd5c1 100644 --- a/dbaccess/source/ui/dlg/DbAdminImpl.hxx +++ b/dbaccess/source/ui/dlg/DbAdminImpl.hxx @@ -137,6 +137,7 @@ namespace dbaui /** return the corresponding driver for the selected URL */ ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > getDriver(); + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > getDriver(const ::rtl::OUString& _sURL); /** returns the data source the dialog is currently working with */ diff --git a/dbaccess/source/ui/dlg/dbwizsetup.cxx b/dbaccess/source/ui/dlg/dbwizsetup.cxx index 2d91294e8..8aa20d6ad 100644 --- a/dbaccess/source/ui/dlg/dbwizsetup.cxx +++ b/dbaccess/source/ui/dlg/dbwizsetup.cxx @@ -942,8 +942,15 @@ sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument() { ::rtl::OUString sEmbeddedURL = m_pCollection->getEmbeddedDatabase(); ::connectivity::DriversConfig aDriverConfig(getORB()); - if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() ) + try + { + if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() || !m_pImpl->getDriver(sEmbeddedURL).is() ) sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:")); + } + catch(const Exception&) + { + sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:")); + } return sEmbeddedURL; } @@ -1118,7 +1125,7 @@ sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument() m_xFrameLoader.set( m_xDesktop, UNO_QUERY_THROW ); m_xInteractionHandler.set( _rxORB->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.InteractionHandler" ) ) + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ), UNO_QUERY_THROW ); } diff --git a/dbaccess/source/ui/inc/JoinController.hxx b/dbaccess/source/ui/inc/JoinController.hxx index ceb80f46f..b21a81561 100644 --- a/dbaccess/source/ui/inc/JoinController.hxx +++ b/dbaccess/source/ui/inc/JoinController.hxx @@ -49,6 +49,11 @@ #endif #include <boost/shared_ptr.hpp> +namespace comphelper +{ + class NamedValueCollection; +} + class VCLXWindow; namespace dbaui { @@ -79,22 +84,22 @@ namespace dbaui virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs); /** loads the information for the windows. - @param _aViewProps + @param i_rViewSettings The properties which comes from the layout information. */ - void loadTableWindows(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _aViewProps); + void loadTableWindows( const ::comphelper::NamedValueCollection& i_rViewSettings ); /** loads the information for one window. @param _rTable The properties which comes from the layout information. */ - void loadTableWindow(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rTable); + void loadTableWindow( const ::comphelper::NamedValueCollection& i_rTableWindowSettings ); /** saves the TableWindows structure in a sequence of property values @param _rViewProps Contains the new sequence. */ - void saveTableWindows(::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rViewProps); + void saveTableWindows( ::comphelper::NamedValueCollection& o_rViewSettings ) const; virtual ~OJoinController(); public: @@ -109,7 +114,7 @@ namespace dbaui // --------------------------------------------------------------- // OSingleDocumentController overridables virtual void reconnect( sal_Bool _bUI ); - virtual void setModified( sal_Bool _bModified = sal_True ); + virtual void impl_onModifyChanged(); // --------------------------------------------------------------- // own overridables diff --git a/dbaccess/source/ui/inc/QueryDesignView.hxx b/dbaccess/source/ui/inc/QueryDesignView.hxx index 628f14131..7c68d552a 100644 --- a/dbaccess/source/ui/inc/QueryDesignView.hxx +++ b/dbaccess/source/ui/inc/QueryDesignView.hxx @@ -164,6 +164,10 @@ namespace dbaui */ bool initByParseIterator( ::dbtools::SQLExceptionInfo* _pErrorInfo ); + void initByFieldDescriptions( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rFieldDescriptions + ); + ::connectivity::OSQLParseNode* getPredicateTreeFromEntry( OTableFieldDescRef pEntry, const String& _sCriteria, ::rtl::OUString& _rsErrorMessage, diff --git a/dbaccess/source/ui/inc/QueryViewSwitch.hxx b/dbaccess/source/ui/inc/QueryViewSwitch.hxx index 2265450f7..54cdbd2f2 100644 --- a/dbaccess/source/ui/inc/QueryViewSwitch.hxx +++ b/dbaccess/source/ui/inc/QueryViewSwitch.hxx @@ -75,6 +75,7 @@ namespace dbaui old state) */ bool switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo ); + void forceInitialView(); sal_Bool isSlotEnabled(sal_Int32 _nSlotId); void setSlotEnabled(sal_Int32 _nSlotId,sal_Bool _bEnable); void setNoneVisbleRow(sal_Int32 _nRows); @@ -93,6 +94,10 @@ namespace dbaui protected: // return the Rectangle where I can paint myself virtual void resizeDocumentView(Rectangle& rRect); + + private: + void impl_forceSQLView(); + bool impl_postViewSwitch( const bool i_bGraphicalDesign, const bool i_bSuccess ); }; } #endif // DBAUI_QUERYVIEWSWITCH_HXX diff --git a/dbaccess/source/ui/inc/RelationController.hxx b/dbaccess/source/ui/inc/RelationController.hxx index 739052d17..34817abbc 100644 --- a/dbaccess/source/ui/inc/RelationController.hxx +++ b/dbaccess/source/ui/inc/RelationController.hxx @@ -57,7 +57,7 @@ namespace dbaui // execute a feature virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs); - ORelationDesignView* getRelationView() { return static_cast<ORelationDesignView*>(m_pView); } + ORelationDesignView* getRelationView() { return static_cast<ORelationDesignView*>( getView() ); } void loadData(); TTableWindowData::value_type existsTable(const ::rtl::OUString& _rComposedTableName,sal_Bool _bCase) const; diff --git a/dbaccess/source/ui/inc/TableController.hxx b/dbaccess/source/ui/inc/TableController.hxx index 073cebf0b..19e6a07dd 100644 --- a/dbaccess/source/ui/inc/TableController.hxx +++ b/dbaccess/source/ui/inc/TableController.hxx @@ -127,7 +127,7 @@ namespace dbaui inline sal_Bool isAutoIncrementValueEnabled() const { return m_bAllowAutoIncrementValue; } inline const ::rtl::OUString& getAutoIncrementValue() const { return m_sAutoIncrementValue; } - virtual void setModified(sal_Bool _bModified=sal_True); + virtual void impl_onModifyChanged(); // const ::connectivity::OSQLParseNode* getParseTree() const { return m_aSqlIterator.getParseTree();} // need for undo's and redo's diff --git a/dbaccess/source/ui/inc/TableFieldDescription.hxx b/dbaccess/source/ui/inc/TableFieldDescription.hxx index ebd8ed9fd..d930f489b 100644 --- a/dbaccess/source/ui/inc/TableFieldDescription.hxx +++ b/dbaccess/source/ui/inc/TableFieldDescription.hxx @@ -44,13 +44,19 @@ #include <vos/ref.hxx> #endif +namespace comphelper +{ + class NamedValueCollection; +} + class Window; namespace dbaui { class OTableFieldDesc : public ::vos::OReference { private: - ::std::vector< ::rtl::OUString> m_vecCriteria; + ::std::vector< ::rtl::OUString > + m_aCriteria; ::rtl::OUString m_aTableName; ::rtl::OUString m_aAliasName; // table range @@ -128,18 +134,18 @@ namespace dbaui sal_Bool HasCriteria() const { - ::std::vector< ::rtl::OUString>::const_iterator aIter = m_vecCriteria.begin(); - ::std::vector< ::rtl::OUString>::const_iterator aEnd = m_vecCriteria.end(); + ::std::vector< ::rtl::OUString>::const_iterator aIter = m_aCriteria.begin(); + ::std::vector< ::rtl::OUString>::const_iterator aEnd = m_aCriteria.end(); for(;aIter != aEnd;++aIter) if(aIter->getLength()) break; return aIter != aEnd; } - const ::std::vector< ::rtl::OUString>& GetCriteria() const { return m_vecCriteria;} + const ::std::vector< ::rtl::OUString>& GetCriteria() const { return m_aCriteria; } - void Load(const ::com::sun::star::beans::PropertyValue& _rProperty); - void Save(::com::sun::star::beans::PropertyValue& _rProperty); + void Load( const ::com::sun::star::beans::PropertyValue& i_rSettings, const bool i_bIncludingCriteria ); + void Save( ::comphelper::NamedValueCollection& o_rSettings, const bool i_bIncludingCriteria ); }; //------------------------------------------------------------------ diff --git a/dbaccess/source/ui/inc/brwctrlr.hxx b/dbaccess/source/ui/inc/brwctrlr.hxx index ee54e66d8..80380a223 100644 --- a/dbaccess/source/ui/inc/brwctrlr.hxx +++ b/dbaccess/source/ui/inc/brwctrlr.hxx @@ -53,7 +53,6 @@ #include <svtools/transfer.hxx> #include <osl/mutex.hxx> #include <vos/thread.hxx> -#include <svl/cancel.hxx> #include <cppuhelper/implbase9.hxx> #include <svtools/cliplistener.hxx> @@ -121,7 +120,6 @@ namespace dbaui ::rtl::OUString m_sModuleIdentifier; // members for asynchronous load operations - ::vos::OThread* m_pLoadThread; // the thread wherein the form is loaded FormControllerImpl* m_pFormControllerImpl; // implementing the XFormController ULONG m_nPendingLoadFinished; // the event used to tell ourself that the load is finished @@ -165,7 +163,7 @@ namespace dbaui public: SbaXDataBrowserController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM); - UnoDataBrowserView* getBrowserView() const { return static_cast< UnoDataBrowserView*>(m_pView); } + UnoDataBrowserView* getBrowserView() const { return static_cast< UnoDataBrowserView*>(getView()); } // late construction virtual sal_Bool Construct(Window* pParent); @@ -318,9 +316,6 @@ namespace dbaui // a PropertySet corresponding to the cursor field a column is bound to // if nViewPos is (sal_uInt16)-1 (the default) then the field for the current column will be retrieved - sal_Bool PendingLoad() const { return m_pLoadThread != NULL; } - // is there an asyncronous load operation in progress ? - void enterFormAction(); void leaveFormAction(); @@ -361,74 +356,10 @@ namespace dbaui DECL_LINK(OnFoundData, FmFoundRecordInformation*); DECL_LINK(OnCanceledNotFound, FmFoundRecordInformation*); - // callbacks for the completed loading process - DECL_LINK(OnOpenFinished, void*); - DECL_LINK(OnOpenFinishedMainThread, void*); - // OnOpenFinsihed is called in a foreign thread (the one which does the loading) so it simply posts the - // OnOpenFinishedMainThread-link (which will be called in the main thread, then) as user event. - // (the alternative would be to lock the SolarMutex in OnOpenFinished to avoid problems with the needed updates, - // but playing with this mutex seems very hazardous to me ....) DECL_LINK(OnAsyncGetCellFocus, void*); DECL_LINK( OnAsyncDisplayError, void* ); }; - - //================================================================== - // LoadFormThread - a thread for asynchronously loading a form - //================================================================== - class LoadFormThread : public ::vos::OThread - { - ::osl::Mutex m_aAccessSafety; // for securing the multi-thread access - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xRowSet; // the data source to be loaded - - Link m_aTerminationHandler; // the handler to be called upon termination - sal_Bool m_bCanceled; // StopIt has been called ? - String m_sStopperCaption; // the caption for the ThreadStopper - - // a ThreadStopper will be instantiated so that the open can be canceled via the UI - class ThreadStopper : protected SfxCancellable - { - LoadFormThread* m_pOwner; - - public: - ThreadStopper(LoadFormThread* pOwner, const String& rTitle); - virtual ~ThreadStopper() { } - - virtual void Cancel(); - - virtual void OwnerTerminated(); - // Normally the Owner (a LoadFormThread) would delete the stopper when terminated. - // Unfortunally the application doesn't remove the 'red light' when a SfxCancellable is deleted - // if it (the app) can't acquire the solar mutex. The deletion is IGNORED then. So we have to make - // sure that a) the stopper is deleted from inside the main thread (where the solar mutex is locked) - // and b) that in the time between the termination of the thread and the deletion of the stopper - // the latter doesn't access the former. - // The OwnerTerminated cares for both aspects. - // SO DON'T DELETE THE STOPPER EXPLICITLY ! - - protected: - // HACK HACK HACK HACK HACK : this should be private, but MSVC doesn't accept the LINK-macro then .... - DECL_LINK(OnDeleteInMainThread, ThreadStopper*); - }; - friend class LoadFormThread::ThreadStopper; - - public: - LoadFormThread(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > & _xRowSet, const String& _rStopperCaption) : m_xRowSet(_xRowSet), m_sStopperCaption(_rStopperCaption) { } - - virtual void SAL_CALL run(); - virtual void SAL_CALL onTerminated(); - - void SetTerminationHdl(const Link& aTermHdl) { m_aTerminationHandler = aTermHdl; } - // the handler will be called synchronously (the parameter is a pointer to the thread) - // if no termination handler is set, the thread disposes the data source and deletes - // itself upon termination - - // cancels the process. to be called from another thread (of course ;) - void StopIt(); - - // ask if the load canceled - sal_Bool WasCanceled() const { return m_bCanceled; } - }; } #endif // _SBA_BWRCTRLR_HXX diff --git a/dbaccess/source/ui/inc/databaseobjectview.hxx b/dbaccess/source/ui/inc/databaseobjectview.hxx index 3141183a9..949edefaf 100644 --- a/dbaccess/source/ui/inc/databaseobjectview.hxx +++ b/dbaccess/source/ui/inc/databaseobjectview.hxx @@ -64,6 +64,7 @@ #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ #include <com/sun/star/uno/Sequence.hxx> #endif +#include <comphelper/namedvaluecollection.hxx> #include <boost/shared_ptr.hpp> @@ -90,10 +91,11 @@ namespace dbaui m_xApplication; ::rtl::OUString m_sComponentURL; + private: ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > doDispatch( - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDispatchArguments + const ::comphelper::NamedValueCollection& i_rDispatchArgs ); protected: @@ -113,11 +115,11 @@ namespace dbaui virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > doCreateView( const ::com::sun::star::uno::Any& _rDataSource, const ::rtl::OUString& _rObjectName, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rCreationArgs + const ::comphelper::NamedValueCollection& i_rCreationArgs ); virtual void fillDispatchArgs( - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDispatchArguments, + ::comphelper::NamedValueCollection& i_rDispatchArgs, const ::com::sun::star::uno::Any& _rDataSource, const ::rtl::OUString& _rObjectName ); @@ -155,7 +157,8 @@ namespace dbaui */ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > createNew( - const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource >& _xDataSource + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource >& _xDataSource, + const ::comphelper::NamedValueCollection& i_rDispatchArgs = ::comphelper::NamedValueCollection() ); /** opens a view for an existent object @@ -173,7 +176,7 @@ namespace dbaui openExisting( const ::com::sun::star::uno::Any& _aDataSource, const ::rtl::OUString& _rName, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs + const ::comphelper::NamedValueCollection& i_rDispatchArgs ); }; @@ -183,12 +186,11 @@ namespace dbaui class QueryDesigner : public DatabaseObjectView { protected: - sal_Int32 m_nCommandType; - sal_Bool m_bPreferSQLView; + sal_Int32 m_nCommandType; protected: virtual void fillDispatchArgs( - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDispatchArguments, + ::comphelper::NamedValueCollection& i_rDispatchArgs, const ::com::sun::star::uno::Any& _aDataSource, const ::rtl::OUString& _rObjectName ); @@ -198,8 +200,7 @@ namespace dbaui const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxApplication, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame, - bool _bCreateView, - sal_Bool _bPreferSQLView + bool _bCreateView ); }; @@ -210,7 +211,7 @@ namespace dbaui { protected: virtual void fillDispatchArgs( - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDispatchArguments, + ::comphelper::NamedValueCollection& i_rDispatchArgs, const ::com::sun::star::uno::Any& _aDataSource, const ::rtl::OUString& _rObjectName ); @@ -218,7 +219,7 @@ namespace dbaui virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > doCreateView( const ::com::sun::star::uno::Any& _rDataSource, const ::rtl::OUString& _rObjectName, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rCreationArgs + const ::comphelper::NamedValueCollection& i_rCreationArgs ); public: @@ -251,7 +252,7 @@ namespace dbaui protected: virtual void fillDispatchArgs( - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDispatchArguments, + ::comphelper::NamedValueCollection& i_rDispatchArgs, const ::com::sun::star::uno::Any& _aDataSource, const ::rtl::OUString& _rQualifiedName ); diff --git a/dbaccess/source/ui/inc/linkeddocuments.hxx b/dbaccess/source/ui/inc/linkeddocuments.hxx index 3c308e263..a17fea929 100644 --- a/dbaccess/source/ui/inc/linkeddocuments.hxx +++ b/dbaccess/source/ui/inc/linkeddocuments.hxx @@ -52,6 +52,7 @@ #ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_ #include <com/sun/star/ucb/XContent.hpp> #endif +#include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp> #ifndef _LINK_HXX #include <tools/link.hxx> #endif @@ -80,8 +81,8 @@ namespace dbaui m_xDocumentContainer; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> m_xConnection; - ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > - m_xParentFrame; + ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI > + m_xDocumentUI; Window* m_pDialogParent; String m_sCurrentlyEditing; ::rtl::OUString @@ -89,13 +90,13 @@ namespace dbaui public: OLinkedDocumentsAccess( - Window* _pDialogParent - ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame - ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB - ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxContainer - ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection - ,const ::rtl::OUString& _sDataSourceName - ); + Window* _pDialogParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& i_rDocumentUI, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxContainer, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection, + const ::rtl::OUString& _sDataSourceName + ); ~OLinkedDocumentsAccess(); inline sal_Bool isConnected() const { return m_xConnection.is(); } @@ -110,30 +111,21 @@ namespace dbaui ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > newDocument( - sal_Int32 _nNewFormId, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _xDefinition, - const sal_Int32 _nCommandType, - const ::rtl::OUString& _sObjectName + sal_Int32 i_nActionID, + const ::comphelper::NamedValueCollection& i_rCreationArgs, + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_rDefinition ); - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - newFormWithPilot( - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _xDefinition, + void newFormWithPilot( const sal_Int32 _nCommandType = -1, const ::rtl::OUString& _rObjectName = ::rtl::OUString() ); - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - newReportWithPilot( - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _xDefinition, + void newReportWithPilot( const sal_Int32 _nCommandType = -1, const ::rtl::OUString& _rObjectName = ::rtl::OUString() ); - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - newQueryWithPilot(); - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > - newTableWithPilot(); + void newQueryWithPilot(); + void newTableWithPilot(); enum RESULT { @@ -145,15 +137,14 @@ namespace dbaui ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > impl_open( const ::rtl::OUString& _rLinkName, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _xDefinition, + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _xDefinition, ElementOpenMode _eOpenMode, const ::comphelper::NamedValueCollection& _rAdditionalArgs ); - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + void impl_newWithPilot( const char* _pWizardService, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _xDefinition, const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName ); diff --git a/dbaccess/source/ui/inc/querycontainerwindow.hxx b/dbaccess/source/ui/inc/querycontainerwindow.hxx index 5229a0cd9..a6d677c24 100644 --- a/dbaccess/source/ui/inc/querycontainerwindow.hxx +++ b/dbaccess/source/ui/inc/querycontainerwindow.hxx @@ -115,6 +115,7 @@ namespace dbaui bool reset( ::dbtools::SQLExceptionInfo* _pErrorInfo ) { return m_pViewSwitch->reset( _pErrorInfo ); } bool switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo ); + void forceInitialView(); virtual void GetFocus(); diff --git a/dbaccess/source/ui/inc/querycontroller.hxx b/dbaccess/source/ui/inc/querycontroller.hxx index 8fe587988..ee7f8cb6b 100644 --- a/dbaccess/source/ui/inc/querycontroller.hxx +++ b/dbaccess/source/ui/inc/querycontroller.hxx @@ -53,6 +53,11 @@ #include <connectivity/sqlparse.hxx> #include <svl/undo.hxx> +namespace comphelper +{ + class NamedValueCollection; +} + class VCLXWindow; namespace dbaui { @@ -122,8 +127,8 @@ namespace dbaui void executeQuery(); bool doSaveAsDoc(sal_Bool _bSaveAs); - void saveViewSettings(::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rViewProps); - void loadViewSettings(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rViewProps); + void saveViewSettings( ::comphelper::NamedValueCollection& o_rViewSettings, const bool i_includingCriteria ) const; + void loadViewSettings( const ::comphelper::NamedValueCollection& o_rViewSettings ); ::rtl::OUString translateStatement( bool _bFireStatementChange = true ); ::rtl::OUString getDefaultName() const; @@ -139,7 +144,7 @@ namespace dbaui virtual void reconnect( sal_Bool _bUI ); virtual ::rtl::OUString getPrivateTitle( ) const; - OQueryContainerWindow* getContainer() const { return static_cast< OQueryContainerWindow* >( getView() ); } + OQueryContainerWindow* getContainer() const { return static_cast< OQueryContainerWindow* >( getView() ); } public: OQueryController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM); @@ -150,7 +155,7 @@ namespace dbaui void clearFields(); - virtual void setModified(sal_Bool _bModified=sal_True); + virtual void impl_onModifyChanged(); // should the statement be parsed by our own sql parser sal_Bool isEsacpeProcessing() const { return m_bEscapeProcessing; } @@ -167,6 +172,9 @@ namespace dbaui sal_Int32 getColWidth(sal_uInt16 _nColPos) const; + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& + getFieldInformation() const { return m_aFieldInformation; } + ::connectivity::OSQLParser& getParser() { return m_aSqlParser; } ::connectivity::OSQLParseTreeIterator& getParseIterator() { return *m_pSqlIterator; } @@ -192,18 +200,38 @@ namespace dbaui static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); + // XController + virtual ::com::sun::star::uno::Any SAL_CALL getViewData(void) throw( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL restoreViewData(const ::com::sun::star::uno::Any& Data) throw( ::com::sun::star::uno::RuntimeException ); + private: virtual void onLoadedMenu(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager >& _xLayoutManager); // OPropertyArrayUsageHelper virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; + // OPropertySetHelper + virtual sal_Bool SAL_CALL convertFastPropertyValue( + ::com::sun::star::uno::Any& rConvertedValue, + ::com::sun::star::uno::Any& rOldValue, + sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue + ) throw (::com::sun::star::lang::IllegalArgumentException); + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue + ) throw (::com::sun::star::uno::Exception ); + virtual void SAL_CALL getFastPropertyValue( + ::com::sun::star::uno::Any& rValue, + sal_Int32 nHandle + ) const; + virtual OJoinDesignView* getJoinView(); // ask the user if the design should be saved when it is modified virtual short saveModified(); virtual void reset(); virtual void impl_initialize(); - void impl_reset(); + void impl_reset( const bool i_bIgnoreQuerySettings = false ); /// tells the user that we needed to switch to SQL view automatically void impl_showAutoSQLViewError( const ::com::sun::star::uno::Any& _rErrorDetails ); @@ -222,6 +250,9 @@ namespace dbaui private: DECL_LINK( OnExecuteAddTable, void* ); + + private: + using OQueryController_PBase::getFastPropertyValue; }; } #endif // DBAUI_QUERYCONTROLLER_HXX diff --git a/dbaccess/source/ui/inc/unodatbr.hxx b/dbaccess/source/ui/inc/unodatbr.hxx index dd083c85e..fa50bd40a 100644 --- a/dbaccess/source/ui/inc/unodatbr.hxx +++ b/dbaccess/source/ui/inc/unodatbr.hxx @@ -371,7 +371,7 @@ namespace dbaui */ void closeConnection(SvLBoxEntry* _pEntry,sal_Bool _bDisposeConnection = sal_True); - sal_Bool populateTree(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xNameAccess, SvLBoxEntry* _pParent, EntryType _eEntryType); + void populateTree(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xNameAccess, SvLBoxEntry* _pParent, EntryType _eEntryType); void initializeTreeModel(); /** search in the tree for query- or tablecontainer equal to this interface and return @@ -430,8 +430,9 @@ namespace dbaui sal_Bool _bSelectDirect = sal_False ); + SvLBoxEntry* implGetConnectionEntry(SvLBoxEntry* _pEntry) const; /// inserts an entry into the tree - void implAppendEntry( + SvLBoxEntry* implAppendEntry( SvLBoxEntry* _pParent, const String& _rName, void* _pUserData, diff --git a/dbaccess/source/ui/misc/HtmlReader.cxx b/dbaccess/source/ui/misc/HtmlReader.cxx index 5a7fd9737..cd8983fe6 100644 --- a/dbaccess/source/ui/misc/HtmlReader.cxx +++ b/dbaccess/source/ui/misc/HtmlReader.cxx @@ -506,6 +506,8 @@ sal_Bool OHTMLReader::CreateTable(int nToken) else if ( m_sCurrent.Len() ) aColumnName = m_sCurrent; + aColumnName.EraseLeadingChars(); + aColumnName.EraseTrailingChars(); CreateDefaultColumn(aColumnName); aColumnName.Erase(); m_sCurrent.Erase(); @@ -550,6 +552,8 @@ sal_Bool OHTMLReader::CreateTable(int nToken) if ( m_sCurrent.Len() ) aColumnName = m_sCurrent; + aColumnName.EraseLeadingChars(); + aColumnName.EraseTrailingChars(); if(aColumnName.Len()) CreateDefaultColumn(aColumnName); diff --git a/dbaccess/source/ui/misc/UITools.cxx b/dbaccess/source/ui/misc/UITools.cxx index 4a6fbcc17..8a6e16e28 100644 --- a/dbaccess/source/ui/misc/UITools.cxx +++ b/dbaccess/source/ui/misc/UITools.cxx @@ -375,11 +375,11 @@ SQLExceptionInfo createConnection( const Reference< ::com::sun::star::beans::XPr } else { // instantiate the default SDB interaction handler - Reference< XInteractionHandler > xHandler(_rMF->createInstance(SERVICE_SDB_INTERACTION_HANDLER), UNO_QUERY); + Reference< XInteractionHandler > xHandler(_rMF->createInstance(SERVICE_TASK_INTERACTION_HANDLER), UNO_QUERY); if (!xHandler.is()) { OSL_ENSURE(sal_False, "createConnection: could not instantiate an interaction handler!"); - // ShowServiceNotAvailableError(NULL, String(SERVICE_SDB_INTERACTION_HANDLER), sal_True); + // ShowServiceNotAvailableError(NULL, String(SERVICE_TASK_INTERACTION_HANDLER), sal_True); // TODO: a real parent! } else diff --git a/dbaccess/source/ui/misc/WCopyTable.cxx b/dbaccess/source/ui/misc/WCopyTable.cxx index c0ea3de40..29367b494 100644 --- a/dbaccess/source/ui/misc/WCopyTable.cxx +++ b/dbaccess/source/ui/misc/WCopyTable.cxx @@ -706,7 +706,7 @@ OCopyTableWizard::OCopyTableWizard( Window* pParent, const ::rtl::OUString& _rDe ::dbaui::fillTypeInfo( _xConnection, m_sTypeNames, m_aTypeInfo, m_aTypeInfoIndex ); ::dbaui::fillTypeInfo( _xConnection, m_sTypeNames, m_aDestTypeInfo, m_aDestTypeInfoIndex ); - m_xInteractionHandler.set( m_xFactory->createInstance( SERVICE_SDB_INTERACTION_HANDLER ), UNO_QUERY); + m_xInteractionHandler.set( m_xFactory->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY); OCopyTable* pPage1( new OCopyTable( this ) ); pPage1->disallowViews(); diff --git a/dbaccess/source/ui/misc/WTypeSelect.cxx b/dbaccess/source/ui/misc/WTypeSelect.cxx index 390c22495..ba4f4e6b6 100644 --- a/dbaccess/source/ui/misc/WTypeSelect.cxx +++ b/dbaccess/source/ui/misc/WTypeSelect.cxx @@ -320,6 +320,8 @@ IMPL_LINK( OWizTypeSelect, ColumnSelectHdl, MultiListBox *, /*pListBox*/ ) OFieldDescription* pField = static_cast<OFieldDescription*>(m_lbColumnNames.GetEntryData(m_lbColumnNames.GetEntryPos(aColumnName))); if(pField) m_aTypeControl.DisplayData(pField); + + m_aTypeControl.Enable(m_lbColumnNames.GetSelectEntryCount() == 1 ); return 0; } // ----------------------------------------------------------------------- diff --git a/dbaccess/source/ui/misc/databaseobjectview.cxx b/dbaccess/source/ui/misc/databaseobjectview.cxx index 272b30176..469a477d3 100644 --- a/dbaccess/source/ui/misc/databaseobjectview.cxx +++ b/dbaccess/source/ui/misc/databaseobjectview.cxx @@ -46,7 +46,6 @@ #include <comphelper/extract.hxx> #include <comphelper/sequence.hxx> -#include <comphelper/namedvaluecollection.hxx> #include <connectivity/dbtools.hxx> #include <osl/diagnose.h> #include <toolkit/helper/vclunohelper.hxx> @@ -75,11 +74,11 @@ namespace dbaui const Reference< XDatabaseDocumentUI >& _rxApplication, const Reference< XFrame >& _rxParentFrame, const ::rtl::OUString& _rComponentURL ) - :m_xORB ( _rxORB ) - ,m_xParentFrame ( _rxParentFrame ) - ,m_xFrameLoader ( ) - ,m_xApplication ( _rxApplication ) - ,m_sComponentURL( _rComponentURL ) + :m_xORB ( _rxORB ) + ,m_xParentFrame ( _rxParentFrame ) + ,m_xFrameLoader ( ) + ,m_xApplication ( _rxApplication ) + ,m_sComponentURL ( _rComponentURL ) { OSL_ENSURE( m_xORB.is(), "DatabaseObjectView::DatabaseObjectView: invalid service factory!" ); OSL_ENSURE( m_xApplication.is(), "DatabaseObjectView::DatabaseObjectView: invalid connection!" ); @@ -95,32 +94,33 @@ namespace dbaui } //---------------------------------------------------------------------- - Reference< XComponent > DatabaseObjectView::createNew(const Reference< XDataSource >& _xDataSource ) + Reference< XComponent > DatabaseObjectView::createNew( const Reference< XDataSource >& _xDataSource, const ::comphelper::NamedValueCollection& i_rDispatchArgs ) { - return doCreateView( makeAny( _xDataSource ), ::rtl::OUString(), Sequence< PropertyValue >() ); + return doCreateView( makeAny( _xDataSource ), ::rtl::OUString(), i_rDispatchArgs ); } //---------------------------------------------------------------------- - Reference< XComponent > DatabaseObjectView::openExisting( const Any& _rDataSource, const ::rtl::OUString& _rName, const Sequence< PropertyValue >& _rArgs ) + Reference< XComponent > DatabaseObjectView::openExisting( const Any& _rDataSource, const ::rtl::OUString& _rName, + const ::comphelper::NamedValueCollection& i_rDispatchArgs ) { - return doCreateView( _rDataSource, _rName, _rArgs ); + return doCreateView( _rDataSource, _rName, i_rDispatchArgs ); } //---------------------------------------------------------------------- Reference< XComponent > DatabaseObjectView::doCreateView( const Any& _rDataSource, const ::rtl::OUString& _rObjectName, - const Sequence< PropertyValue >& _rCreationArgs ) + const ::comphelper::NamedValueCollection& i_rCreationArgs ) { - Sequence< PropertyValue > aDispatchArgs; - fillDispatchArgs( aDispatchArgs, _rDataSource, _rObjectName ); + ::comphelper::NamedValueCollection aDispatchArgs; - ::comphelper::NamedValueCollection aDispArgs( aDispatchArgs ); - aDispArgs.merge( _rCreationArgs, true ); + aDispatchArgs.merge( i_rCreationArgs, false ); // false => do not overwrite + fillDispatchArgs( aDispatchArgs, _rDataSource, _rObjectName ); + aDispatchArgs.merge( i_rCreationArgs, true ); // true => do overwrite - return doDispatch( aDispArgs.getPropertyValues() ); + return doDispatch( aDispatchArgs ); } //---------------------------------------------------------------------- - Reference< XComponent > DatabaseObjectView::doDispatch( const Sequence< PropertyValue >& _rArgs ) + Reference< XComponent > DatabaseObjectView::doDispatch( const ::comphelper::NamedValueCollection& i_rDispatchArgs ) { Reference< XComponent > xReturn; if ( m_xORB.is() ) @@ -160,7 +160,7 @@ namespace dbaui m_sComponentURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_self")), 0, - _rArgs + i_rDispatchArgs.getPropertyValues() ); if ( !xReturn.is() ) @@ -176,29 +176,23 @@ namespace dbaui //---------------------------------------------------------------------- void DatabaseObjectView::fillDispatchArgs( - Sequence< PropertyValue >& _rDispatchArguments, + ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource, const ::rtl::OUString& /* _rName */ ) { - sal_Int32 nPos = _rDispatchArguments.getLength(); - _rDispatchArguments.realloc( nPos + 2 ); - ::rtl::OUString sDataSource; Reference<XDataSource> xDataSource; if ( _aDataSource >>= sDataSource ) { - _rDispatchArguments[nPos ].Name = PROPERTY_DATASOURCENAME; - _rDispatchArguments[nPos++].Value <<= sDataSource; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_DATASOURCENAME, sDataSource ); } else if ( _aDataSource >>= xDataSource ) { - _rDispatchArguments[nPos ].Name = PROPERTY_DATASOURCE; - _rDispatchArguments[nPos++].Value <<= xDataSource; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_DATASOURCE, xDataSource ); } - _rDispatchArguments[nPos ].Name = PROPERTY_ACTIVE_CONNECTION; - _rDispatchArguments[nPos++].Value <<= getConnection(); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, getConnection() ); } //====================================================================== @@ -206,48 +200,32 @@ namespace dbaui //====================================================================== //---------------------------------------------------------------------- QueryDesigner::QueryDesigner( const Reference< XMultiServiceFactory >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication, - const Reference< XFrame >& _rxParentFrame, - bool _bCreateView, sal_Bool _bPreferSQLView ) - :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, static_cast< ::rtl::OUString >( _bCreateView ? URL_COMPONENT_VIEWDESIGN : URL_COMPONENT_QUERYDESIGN ) ) + const Reference< XFrame >& _rxParentFrame, bool _bCreateView ) + :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, _bCreateView ? URL_COMPONENT_VIEWDESIGN : URL_COMPONENT_QUERYDESIGN ) ,m_nCommandType( _bCreateView ? CommandType::TABLE : CommandType::QUERY ) - ,m_bPreferSQLView( _bPreferSQLView ) { } //---------------------------------------------------------------------- - void QueryDesigner::fillDispatchArgs( Sequence< PropertyValue >& _rDispatchArguments, const Any& _aDataSource, + void QueryDesigner::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource, const ::rtl::OUString& _rObjectName ) { - DatabaseObjectView::fillDispatchArgs( _rDispatchArguments, _aDataSource, _rObjectName ); + DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rObjectName ); - bool bIncludeQueryName = 0 != _rObjectName.getLength(); - bool bEditViewAsSQLCommand = ( m_nCommandType == CommandType::TABLE ) && m_bPreferSQLView; + const bool bIncludeQueryName = 0 != _rObjectName.getLength(); + const bool bGraphicalDesign = i_rDispatchArgs.getOrDefault( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, sal_True ); + const bool bEditViewAsSQLCommand = ( m_nCommandType == CommandType::TABLE ) && !bGraphicalDesign; - sal_Int32 nPos = _rDispatchArguments.getLength(); - - sal_Int32 nNewLen = _rDispatchArguments.getLength() + 2; - if ( bIncludeQueryName ) - ++nNewLen; - if ( bEditViewAsSQLCommand ) - ++nNewLen; - _rDispatchArguments.realloc( nNewLen ); - - _rDispatchArguments[nPos ].Name = PROPERTY_GRAPHICAL_DESIGN; - _rDispatchArguments[nPos++].Value <<= ::cppu::bool2any( !m_bPreferSQLView ); - - _rDispatchArguments[nPos ].Name = PROPERTY_COMMAND_TYPE; - _rDispatchArguments[nPos++].Value <<= m_nCommandType; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_COMMAND_TYPE, m_nCommandType ); if ( bIncludeQueryName ) { - _rDispatchArguments[nPos ].Name = PROPERTY_COMMAND; - _rDispatchArguments[nPos++].Value <<= _rObjectName; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_COMMAND, _rObjectName ); } if ( bEditViewAsSQLCommand ) { - _rDispatchArguments[nPos ].Name = PROPERTY_ESCAPE_PROCESSING; - _rDispatchArguments[nPos++].Value <<= sal_Bool( sal_False ); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, sal_False ); } } @@ -261,24 +239,20 @@ namespace dbaui } //---------------------------------------------------------------------- - void TableDesigner::fillDispatchArgs( Sequence< PropertyValue >& _rDispatchArguments, const Any& _aDataSource, + void TableDesigner::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource, const ::rtl::OUString& _rObjectName ) { - DatabaseObjectView::fillDispatchArgs( _rDispatchArguments, _aDataSource, _rObjectName ); - sal_Bool bIncludeName = 0 != _rObjectName.getLength(); + DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rObjectName ); - if (bIncludeName) + if ( 0 != _rObjectName.getLength() ) { - sal_Int32 nPos = _rDispatchArguments.getLength(); - _rDispatchArguments.realloc(_rDispatchArguments.getLength() + 1); - _rDispatchArguments[nPos ].Name = PROPERTY_CURRENTTABLE; - _rDispatchArguments[nPos++].Value <<= _rObjectName; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_CURRENTTABLE, _rObjectName ); } } //---------------------------------------------------------------------- Reference< XComponent > TableDesigner::doCreateView( const Any& _rDataSource, const ::rtl::OUString& _rObjectName, - const Sequence< PropertyValue >& _rCreationArgs ) + const ::comphelper::NamedValueCollection& i_rCreationArgs ) { bool bIsNewDesign = ( _rObjectName.getLength() == 0 ); @@ -288,7 +262,7 @@ namespace dbaui xDesigner = impl_getConnectionProvidedDesigner_nothrow( _rObjectName ); if ( !xDesigner.is() ) - return DatabaseObjectView::doCreateView( _rDataSource, _rObjectName, _rCreationArgs ); + return DatabaseObjectView::doCreateView( _rDataSource, _rObjectName, i_rCreationArgs ); // try whether the designer is a dialog Reference< XExecutableDialog > xDialog( xDesigner, UNO_QUERY_THROW ); @@ -333,10 +307,10 @@ namespace dbaui } //---------------------------------------------------------------------- - void ResultSetBrowser::fillDispatchArgs(Sequence< PropertyValue >& _rDispatchArguments, const Any& _aDataSource, + void ResultSetBrowser::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource, const ::rtl::OUString& _rQualifiedName) { - DatabaseObjectView::fillDispatchArgs( _rDispatchArguments, _aDataSource, _rQualifiedName ); + DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rQualifiedName ); OSL_ENSURE( 0 != _rQualifiedName.getLength(),"A Table name must be set"); ::rtl::OUString sCatalog; ::rtl::OUString sSchema; @@ -344,26 +318,15 @@ namespace dbaui if ( m_bTable ) ::dbtools::qualifiedNameComponents( getConnection()->getMetaData(), _rQualifiedName, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation ); - sal_Int32 nPos = _rDispatchArguments.getLength(); - _rDispatchArguments.realloc( _rDispatchArguments.getLength() + 3 + ( m_bTable ? 3 : 0 ) ); - - _rDispatchArguments[nPos ].Name = PROPERTY_COMMAND_TYPE; - _rDispatchArguments[nPos++].Value <<= (m_bTable ? CommandType::TABLE : CommandType::QUERY); - - _rDispatchArguments[nPos ].Name = PROPERTY_COMMAND; - _rDispatchArguments[nPos++].Value <<= _rQualifiedName; - - _rDispatchArguments[nPos ].Name = PROPERTY_ENABLE_BROWSER; - _rDispatchArguments[nPos++].Value <<= sal_False; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_COMMAND_TYPE, (m_bTable ? CommandType::TABLE : CommandType::QUERY) ); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_COMMAND, _rQualifiedName ); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_ENABLE_BROWSER, sal_False ); if ( m_bTable ) { - _rDispatchArguments[nPos ].Name = PROPERTY_UPDATE_CATALOGNAME; - _rDispatchArguments[nPos++].Value <<= sCatalog; - _rDispatchArguments[nPos ].Name = PROPERTY_UPDATE_SCHEMANAME; - _rDispatchArguments[nPos++].Value <<= sSchema; - _rDispatchArguments[nPos ].Name = PROPERTY_UPDATE_TABLENAME; - _rDispatchArguments[nPos++].Value <<= sTable; + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_UPDATE_CATALOGNAME, sCatalog ); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_UPDATE_SCHEMANAME, sSchema ); + i_rDispatchArgs.put( (::rtl::OUString)PROPERTY_UPDATE_TABLENAME, sTable ); } } diff --git a/dbaccess/source/ui/misc/datasourceconnector.cxx b/dbaccess/source/ui/misc/datasourceconnector.cxx index ca9f34097..e657c6117 100644 --- a/dbaccess/source/ui/misc/datasourceconnector.cxx +++ b/dbaccess/source/ui/misc/datasourceconnector.cxx @@ -192,9 +192,9 @@ namespace dbaui if ( !xHandler.is() ) { // instantiate the default SDB interaction handler - xHandler = Reference< XInteractionHandler >( m_xORB->createInstance( SERVICE_SDB_INTERACTION_HANDLER ), UNO_QUERY ); + xHandler = Reference< XInteractionHandler >( m_xORB->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY ); if ( !xHandler.is() ) - ShowServiceNotAvailableError(m_pErrorMessageParent, String(SERVICE_SDB_INTERACTION_HANDLER), sal_True); + ShowServiceNotAvailableError(m_pErrorMessageParent, (::rtl::OUString)SERVICE_TASK_INTERACTION_HANDLER, sal_True); } if ( xHandler.is() ) diff --git a/dbaccess/source/ui/misc/documentcontroller.cxx b/dbaccess/source/ui/misc/documentcontroller.cxx deleted file mode 100644 index 731b5e850..000000000 --- a/dbaccess/source/ui/misc/documentcontroller.cxx +++ /dev/null @@ -1,137 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * 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. - * - * 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). - * - * 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. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_dbaccess.hxx" - -#include "documentcontroller.hxx" - -/** === begin UNO includes === **/ -/** === end UNO includes === **/ - -#include <tools/debug.hxx> -#include <tools/diagnose_ex.h> - -//........................................................................ -namespace dbaui -{ -//........................................................................ - - using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::frame; - - //==================================================================== - //= ModelControllerConnector - //==================================================================== - DBG_NAME( ModelControllerConnector ) - //-------------------------------------------------------------------- - ModelControllerConnector::ModelControllerConnector() - { - DBG_CTOR( ModelControllerConnector, NULL ); - } - - //-------------------------------------------------------------------- - ModelControllerConnector::ModelControllerConnector( const ModelControllerConnector& _rSource ) - { - DBG_CTOR( ModelControllerConnector, NULL ); - impl_copyFrom( _rSource ); - } - - //-------------------------------------------------------------------- - ModelControllerConnector& ModelControllerConnector::operator=( const ModelControllerConnector& _rSource ) - { - if ( this != &_rSource ) - impl_copyFrom( _rSource ); - return *this; - } - - //-------------------------------------------------------------------- - void ModelControllerConnector::connect( const Reference< XModel >& _rxModel, const Reference< XController >& _rxController ) - { - impl_disconnect(); - - m_xModel = _rxModel; - m_xController = _rxController; - - impl_connect(); - } - - //-------------------------------------------------------------------- - void ModelControllerConnector::impl_copyFrom( const ModelControllerConnector& _rSource ) - { - Model aNewModel( _rSource.m_xModel ); - Controller aNewController( _rSource.m_xController ); - - impl_disconnect(); - - m_xModel = aNewModel; - m_xController = aNewController; - - impl_connect(); - } - - //-------------------------------------------------------------------- - ModelControllerConnector::~ModelControllerConnector() - { - impl_disconnect(); - DBG_DTOR( ModelControllerConnector, NULL ); - } - - //-------------------------------------------------------------------- - void ModelControllerConnector::impl_connect() - { - try - { - Reference< XModel > xModel = m_xModel; - if ( xModel.is() && m_xController.is() ) - xModel->connectController( m_xController ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - - //-------------------------------------------------------------------- - void ModelControllerConnector::impl_disconnect() - { - try - { - Reference< XModel > xModel = m_xModel; - if ( xModel.is() && m_xController.is() ) - xModel->disconnectController( m_xController ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - -//........................................................................ -} // namespace dbaui -//........................................................................ - diff --git a/dbaccess/source/ui/misc/linkeddocuments.cxx b/dbaccess/source/ui/misc/linkeddocuments.cxx index e7654efa3..ce018989f 100644 --- a/dbaccess/source/ui/misc/linkeddocuments.cxx +++ b/dbaccess/source/ui/misc/linkeddocuments.cxx @@ -64,8 +64,8 @@ #ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_ #include <com/sun/star/ucb/XCommandProcessor.hpp> #endif -#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_ -#include <com/sun/star/ucb/OpenCommandArgument2.hpp> +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT_HPP_ +#include <com/sun/star/ucb/OpenCommandArgument.hpp> #endif #ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_ #include <com/sun/star/ucb/OpenMode.hpp> @@ -152,6 +152,7 @@ namespace dbaui using namespace ::com::sun::star::util; using namespace ::com::sun::star::ucb; using namespace ::com::sun::star::sdbc; + using namespace ::com::sun::star::sdb::application; using namespace ::com::sun::star::task; using namespace ::svt; @@ -189,17 +190,13 @@ namespace dbaui //================================================================== DBG_NAME(OLinkedDocumentsAccess) //------------------------------------------------------------------ - OLinkedDocumentsAccess::OLinkedDocumentsAccess(Window* _pDialogParent - , const Reference< XFrame >& _rxParentFrame - , const Reference< XMultiServiceFactory >& _rxORB - , const Reference< XNameAccess >& _rxContainer - , const Reference< XConnection>& _xConnection - , const ::rtl::OUString& _sDataSourceName - ) + OLinkedDocumentsAccess::OLinkedDocumentsAccess( Window* _pDialogParent, const Reference< XDatabaseDocumentUI >& i_rDocumentUI, + const Reference< XMultiServiceFactory >& _rxORB, const Reference< XNameAccess >& _rxContainer, + const Reference< XConnection>& _xConnection, const ::rtl::OUString& _sDataSourceName ) :m_xORB(_rxORB) ,m_xDocumentContainer(_rxContainer) ,m_xConnection(_xConnection) - ,m_xParentFrame(_rxParentFrame) + ,m_xDocumentUI( i_rDocumentUI ) ,m_pDialogParent(_pDialogParent) ,m_sDataSourceName(_sDataSourceName) { @@ -268,112 +265,101 @@ namespace dbaui return xRet; } //------------------------------------------------------------------ - Reference< XComponent> OLinkedDocumentsAccess::impl_newWithPilot( const char* _pWizardService, - Reference< XComponent >& _xDefinition, const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName ) + void OLinkedDocumentsAccess::impl_newWithPilot( const char* _pWizardService, + const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName ) { - Reference< XComponent> xRet; try { - ::svx::ODataAccessDescriptor aDesc; - aDesc.setDataSource(m_sDataSourceName); + ::comphelper::NamedValueCollection aArgs; + aArgs.put( "DataSourceName", m_sDataSourceName ); + + if ( m_xConnection.is() ) + aArgs.put( "ActiveConnection", m_xConnection ); + if ( _rObjectName.getLength() && ( _nCommandType != -1 ) ) { - aDesc[::svx::daCommandType] <<= _nCommandType; - aDesc[::svx::daCommand] <<= _rObjectName; + aArgs.put( "CommandType", _nCommandType ); + aArgs.put( "Command", _rObjectName ); } - if ( m_xConnection.is() ) - aDesc[::svx::daConnection] <<= m_xConnection; - - Sequence<Any> aSeq = aDesc.createAnySequence(); - const sal_Int32 nLength = aSeq.getLength(); - aSeq.realloc(nLength + 1 ); - PropertyValue aVal; - aVal.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentFrame")); - aVal.Value <<= m_xParentFrame; - aSeq[nLength] <<= aVal; + + aArgs.put( "DocumentUI", m_xDocumentUI ); - Reference< XJobExecutor > xFormWizard; + Reference< XJobExecutor > xWizard; { WaitObject aWaitCursor( m_pDialogParent ); - xFormWizard.set(m_xORB->createInstanceWithArguments(::rtl::OUString::createFromAscii(_pWizardService),aSeq),UNO_QUERY); - } - if ( xFormWizard.is() ) - { - xFormWizard->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("start"))); - Reference<XPropertySet> xProp(xFormWizard,UNO_QUERY); - if ( xProp.is() ) - { - Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo(); - if ( xInfo->hasPropertyByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Document"))) ) - { - _xDefinition.set(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentDefinition"))),UNO_QUERY); - xRet.set(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Document"))),UNO_QUERY); - } - } - xFormWizard->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("end"))); - ::comphelper::disposeComponent(xFormWizard); + xWizard.set( m_xORB->createInstanceWithArguments( + ::rtl::OUString::createFromAscii( _pWizardService ), + aArgs.getWrappedPropertyValues() + ), UNO_QUERY_THROW ); } + + xWizard->trigger( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "start" ) ) ); + ::comphelper::disposeComponent( xWizard ); } catch(const Exception& e) { - (void) e; - OSL_ENSURE(sal_False, "OLinkedDocumentsAccess::newWithPilot: caught an exception while loading the object!"); + DBG_UNHANDLED_EXCEPTION(); } - return xRet; } //------------------------------------------------------------------ - Reference< XComponent> OLinkedDocumentsAccess::newFormWithPilot(Reference< XComponent >& _xDefinition,const sal_Int32 _nCommandType,const ::rtl::OUString& _rObjectName) + void OLinkedDocumentsAccess::newFormWithPilot( const sal_Int32 _nCommandType,const ::rtl::OUString& _rObjectName ) { - return impl_newWithPilot( "com.sun.star.wizards.form.CallFormWizard", _xDefinition, _nCommandType, _rObjectName ); + impl_newWithPilot( "com.sun.star.wizards.form.CallFormWizard", _nCommandType, _rObjectName ); } //------------------------------------------------------------------ - Reference< XComponent> OLinkedDocumentsAccess::newReportWithPilot( Reference< XComponent >& _xDefinition, const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName ) + void OLinkedDocumentsAccess::newReportWithPilot( const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName ) { - return impl_newWithPilot( "com.sun.star.wizards.report.CallReportWizard", _xDefinition, _nCommandType, _rObjectName ); + impl_newWithPilot( "com.sun.star.wizards.report.CallReportWizard", _nCommandType, _rObjectName ); } //------------------------------------------------------------------ - Reference< XComponent> OLinkedDocumentsAccess::newTableWithPilot() + void OLinkedDocumentsAccess::newTableWithPilot() { - Reference< XComponent > xDefinition; - return impl_newWithPilot( "com.sun.star.wizards.table.CallTableWizard", xDefinition, -1, ::rtl::OUString() ); + impl_newWithPilot( "com.sun.star.wizards.table.CallTableWizard", -1, ::rtl::OUString() ); } //------------------------------------------------------------------ - Reference< XComponent> OLinkedDocumentsAccess::newQueryWithPilot() + void OLinkedDocumentsAccess::newQueryWithPilot() { - Reference< XComponent > xDefinition; - return impl_newWithPilot( "com.sun.star.wizards.query.CallQueryWizard", xDefinition, -1, ::rtl::OUString() ); + impl_newWithPilot( "com.sun.star.wizards.query.CallQueryWizard", -1, ::rtl::OUString() ); } //------------------------------------------------------------------ - Reference< XComponent > OLinkedDocumentsAccess::newDocument( sal_Int32 _nNewFormId, Reference< XComponent >& _xDefinition, const sal_Int32 _nCommandType, const ::rtl::OUString& _sObjectName ) + Reference< XComponent > OLinkedDocumentsAccess::newDocument( sal_Int32 i_nActionID, + const ::comphelper::NamedValueCollection& i_rCreationArgs, Reference< XComponent >& o_rDefinition ) { OSL_ENSURE(m_xDocumentContainer.is(), "OLinkedDocumentsAccess::newDocument: invalid document container!"); - // determine the URL to use for the new document + // determine the class ID to use for the new document Sequence<sal_Int8> aClassId; - switch (_nNewFormId) + if ( !i_rCreationArgs.has( "ClassID" ) + && !i_rCreationArgs.has( "MediaType" ) + && !i_rCreationArgs.has( "DocumentServiceName" ) + ) { - case ID_FORM_NEW_TEXT: - aClassId = lcl_GetSequenceClassID(SO3_SW_CLASSID); - OSL_ENSURE(aClassId == comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_SW_CLASSID),"Not equal"); - break; + switch ( i_nActionID ) + { + case ID_FORM_NEW_TEXT: + aClassId = lcl_GetSequenceClassID(SO3_SW_CLASSID); + OSL_ENSURE(aClassId == comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_SW_CLASSID),"Not equal"); + break; - case ID_FORM_NEW_CALC: - aClassId = lcl_GetSequenceClassID(SO3_SC_CLASSID); - break; + case ID_FORM_NEW_CALC: + aClassId = lcl_GetSequenceClassID(SO3_SC_CLASSID); + break; - case ID_FORM_NEW_IMPRESS: - aClassId = lcl_GetSequenceClassID(SO3_SIMPRESS_CLASSID); - break; - case ID_REPORT_NEW_TEXT: - aClassId = comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90); - break; + case ID_FORM_NEW_IMPRESS: + aClassId = lcl_GetSequenceClassID(SO3_SIMPRESS_CLASSID); + break; - case SID_DB_FORM_NEW_PILOT: - default: - OSL_ENSURE(sal_False, "OLinkedDocumentsAccess::newDocument: please use newFormWithPilot!"); - return Reference< XComponent >(); + case ID_REPORT_NEW_TEXT: + aClassId = comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90); + break; + + default: + OSL_ENSURE( sal_False, "OLinkedDocumentsAccess::newDocument: please use newFormWithPilot!" ); + return Reference< XComponent >(); + } } + // load the document as template Reference< XComponent > xNewDocument; try @@ -382,36 +368,37 @@ namespace dbaui Reference<XMultiServiceFactory> xORB(m_xDocumentContainer,UNO_QUERY); if ( xORB.is() ) { - Sequence< Any > aArguments(2); - - PropertyValue aValue; - - aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ClassID")); - aValue.Value <<= aClassId; - aArguments[0] <<= aValue; - - aValue.Name = PROPERTY_ACTIVE_CONNECTION; - aValue.Value <<= m_xConnection; - aArguments[1] <<= aValue; - - Reference<XCommandProcessor> xContent(xORB->createInstanceWithArguments(SERVICE_SDB_DOCUMENTDEFINITION,aArguments),UNO_QUERY); - if ( xContent.is() ) + ::comphelper::NamedValueCollection aCreationArgs( i_rCreationArgs ); + if ( aClassId.getLength() ) + aCreationArgs.put( "ClassID", aClassId ); + aCreationArgs.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, m_xConnection ); + + // separate values which are real creation args from args relevant for opening the doc + ::comphelper::NamedValueCollection aCommandArgs; + if ( aCreationArgs.has( "Hidden" ) ) { - _xDefinition.set(xContent,UNO_QUERY); - Command aCommand; - aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("openDesign")); - OpenCommandArgument2 aOpenCommand; - aOpenCommand.Mode = OpenMode::DOCUMENT; - aCommand.Argument <<= aOpenCommand; - WaitObject aWaitCursor( m_pDialogParent ); - xNewDocument.set(xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >()),UNO_QUERY); - Reference<XPropertySet> xProp(xNewDocument,UNO_QUERY); - if ( xProp.is() && _sObjectName.getLength() ) - { - xProp->setPropertyValue(PROPERTY_COMMAND_TYPE,makeAny(_nCommandType)); - xProp->setPropertyValue(PROPERTY_COMMAND,makeAny(_sObjectName)); - } + aCommandArgs.put( "Hidden", aCreationArgs.get( "Hidden" ) ); + aCreationArgs.remove( "Hidden" ); } + + Reference< XCommandProcessor > xContent( xORB->createInstanceWithArguments( + SERVICE_SDB_DOCUMENTDEFINITION, + aCreationArgs.getWrappedPropertyValues() + ), + UNO_QUERY_THROW + ); + o_rDefinition.set( xContent, UNO_QUERY ); + + // put the OpenMode into the OpenArgs + OpenCommandArgument aOpenModeArg; + aOpenModeArg.Mode = OpenMode::DOCUMENT; + aCommandArgs.put( "OpenMode", aOpenModeArg ); + + Command aCommand; + aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) ); + aCommand.Argument <<= aCommandArgs.getPropertyValues(); + WaitObject aWaitCursor( m_pDialogParent ); + xNewDocument.set( xContent->execute( aCommand, xContent->createCommandIdentifier(), NULL ), UNO_QUERY ); } } catch(const Exception& ) diff --git a/dbaccess/source/ui/misc/makefile.mk b/dbaccess/source/ui/misc/makefile.mk index 77f4f7e72..7f9bbed56 100644 --- a/dbaccess/source/ui/misc/makefile.mk +++ b/dbaccess/source/ui/misc/makefile.mk @@ -72,7 +72,6 @@ SLOFILES= \ $(SLO)$/WColumnSelect.obj \ $(SLO)$/WExtendPages.obj \ $(SLO)$/WNameMatch.obj \ - $(SLO)$/documentcontroller.obj \ $(SLO)$/ToolBoxHelper.obj \ $(SLO)$/stringlistitem.obj \ $(SLO)$/charsets.obj \ diff --git a/dbaccess/source/ui/misc/singledoccontroller.cxx b/dbaccess/source/ui/misc/singledoccontroller.cxx index d9301f001..deffd8f3f 100644 --- a/dbaccess/source/ui/misc/singledoccontroller.cxx +++ b/dbaccess/source/ui/misc/singledoccontroller.cxx @@ -94,6 +94,7 @@ namespace dbaui using ::com::sun::star::uno::UNO_SET_THROW; using ::com::sun::star::uno::UNO_QUERY_THROW; using ::com::sun::star::frame::XUntitledNumbers; + using ::com::sun::star::beans::PropertyVetoException; /** === end UNO using === **/ class DataSourceHolder @@ -140,6 +141,9 @@ namespace dbaui OModuleClient m_aModuleClient; ::dbtools::SQLExceptionInfo m_aCurrentError; // contains the current error which can be set through IEnvironment + ::cppu::OInterfaceContainerHelper + m_aModifyListeners; + // <properties> SharedConnection m_xConnection; ::dbtools::DatabaseMetaData m_aSdbMetaData; @@ -154,8 +158,9 @@ namespace dbaui sal_Bool m_bModified; // is the data modified bool m_bNotAttached; - OSingleDocumentControllerImpl() + OSingleDocumentControllerImpl( ::osl::Mutex& i_rMutex ) :m_aDocScriptSupport() + ,m_aModifyListeners( i_rMutex ) ,m_nDocStartNumber(0) ,m_bSuspended( sal_False ) ,m_bEditable(sal_True) @@ -185,7 +190,7 @@ namespace dbaui //-------------------------------------------------------------------- OSingleDocumentController::OSingleDocumentController(const Reference< XMultiServiceFactory >& _rxORB) :OSingleDocumentController_Base( _rxORB ) - ,m_pImpl(new OSingleDocumentControllerImpl()) + ,m_pImpl( new OSingleDocumentControllerImpl( getMutex() ) ) { } @@ -540,15 +545,6 @@ namespace dbaui InvalidateFeature(ID_BROWSER_UNDO); InvalidateFeature(ID_BROWSER_REDO); } - // ----------------------------------------------------------------------------- - void OSingleDocumentController::setModified(sal_Bool _bModified) - { - m_pImpl->m_bModified = _bModified; - InvalidateFeature(ID_BROWSER_SAVEDOC); - - if ( isFeatureSupported( ID_BROWSER_SAVEASDOC ) ) - InvalidateFeature(ID_BROWSER_SAVEASDOC); - } // ----------------------------------------------------------------------------- ::rtl::OUString OSingleDocumentController::getDataSourceName() const @@ -591,12 +587,6 @@ namespace dbaui } // ----------------------------------------------------------------------------- - sal_Bool OSingleDocumentController::isModified() const - { - return m_pImpl->m_bModified; - } - - // ----------------------------------------------------------------------------- void OSingleDocumentController::setEditable(sal_Bool _bEditable) { m_pImpl->m_bEditable = _bEditable; @@ -702,6 +692,57 @@ namespace dbaui return Reference< XEmbeddedScripts >( getDatabaseDocument(), UNO_QUERY_THROW ); } + // ----------------------------------------------------------------------------- + void SAL_CALL OSingleDocumentController::addModifyListener( const Reference< XModifyListener >& i_Listener ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( getMutex() ); + m_pImpl->m_aModifyListeners.addInterface( i_Listener ); + } + + // ----------------------------------------------------------------------------- + void SAL_CALL OSingleDocumentController::removeModifyListener( const Reference< XModifyListener >& i_Listener ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( getMutex() ); + m_pImpl->m_aModifyListeners.removeInterface( i_Listener ); + } + + // ----------------------------------------------------------------------------- + ::sal_Bool SAL_CALL OSingleDocumentController::isModified( ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( getMutex() ); + return impl_isModified(); + } + + // ----------------------------------------------------------------------------- + void SAL_CALL OSingleDocumentController::setModified( ::sal_Bool i_bModified ) throw (PropertyVetoException, RuntimeException) + { + ::osl::ClearableMutexGuard aGuard( getMutex() ); + + if ( m_pImpl->m_bModified == i_bModified ) + return; + + m_pImpl->m_bModified = i_bModified; + impl_onModifyChanged(); + + EventObject aEvent( *this ); + aGuard.clear(); + m_pImpl->m_aModifyListeners.notifyEach( &XModifyListener::modified, aEvent ); + } + + // ----------------------------------------------------------------------------- + sal_Bool OSingleDocumentController::impl_isModified() const + { + return m_pImpl->m_bModified; + } + + // ----------------------------------------------------------------------------- + void OSingleDocumentController::impl_onModifyChanged() + { + InvalidateFeature( ID_BROWSER_SAVEDOC ); + if ( isFeatureSupported( ID_BROWSER_SAVEASDOC ) ) + InvalidateFeature( ID_BROWSER_SAVEASDOC ); + } + //........................................................................ } // namespace dbaui //........................................................................ diff --git a/dbaccess/source/ui/querydesign/JoinController.cxx b/dbaccess/source/ui/querydesign/JoinController.cxx index 007d697d3..0f9fd8507 100644 --- a/dbaccess/source/ui/querydesign/JoinController.cxx +++ b/dbaccess/source/ui/querydesign/JoinController.cxx @@ -280,7 +280,7 @@ void OJoinController::disposing() OJoinController_BASE::disposing(); - m_pView = NULL; + clearView(); m_vTableConnectionData.clear(); m_vTableData.clear(); @@ -294,10 +294,10 @@ void OJoinController::reconnect( sal_Bool _bUI ) } // ----------------------------------------------------------------------------- -void OJoinController::setModified(sal_Bool _bModified) +void OJoinController::impl_onModifyChanged() { - OJoinController_BASE::setModified(_bModified); - InvalidateFeature(SID_RELATION_ADD_RELATION); + OJoinController_BASE::impl_onModifyChanged(); + InvalidateFeature( SID_RELATION_ADD_RELATION ); } // ----------------------------------------------------------------------------- void OJoinController::SaveTabWinPosSize(OTableWindow* pTabWin, long nOffsetX, long nOffsetY) @@ -326,9 +326,6 @@ FeatureState OJoinController::GetState(sal_uInt16 _nId) const case ID_BROWSER_EDITDOC: aReturn.bChecked = isEditable(); break; - case ID_BROWSER_SAVEDOC: - aReturn.bEnabled = isConnected() && isModified(); - break; case ID_BROWSER_ADDTABLE: aReturn.bEnabled = ( getView() != NULL ) && const_cast< OJoinController* >( this )->getJoinView()->getTableView()->IsAddAllowed(); @@ -455,73 +452,45 @@ sal_Bool SAL_CALL OJoinController::suspend(sal_Bool _bSuspend) throw( RuntimeExc return bCheck; } // ----------------------------------------------------------------------------- -void OJoinController::loadTableWindows(const Sequence<PropertyValue>& aViewProps) +void OJoinController::loadTableWindows( const ::comphelper::NamedValueCollection& i_rViewSettings ) { m_vTableData.clear(); - const PropertyValue *pIter = aViewProps.getConstArray(); - const PropertyValue *pEnd = pIter + aViewProps.getLength(); - for (; pIter != pEnd; ++pIter) + m_aMinimumTableViewSize = Point(); + + Sequence< PropertyValue > aWindowData; + aWindowData = i_rViewSettings.getOrDefault( "Tables", aWindowData ); + + const PropertyValue* pTablesIter = aWindowData.getConstArray(); + const PropertyValue* pTablesEnd = pTablesIter + aWindowData.getLength(); + for ( ; pTablesIter != pTablesEnd; ++pTablesIter ) { - if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Tables" ) ) ) - { - m_aMinimumTableViewSize = Point(); - Sequence<PropertyValue> aWindow; - pIter->Value >>= aWindow; - const PropertyValue *pTablesIter = aWindow.getConstArray(); - const PropertyValue *pTablesEnd = pTablesIter + aWindow.getLength(); - for (; pTablesIter != pTablesEnd; ++pTablesIter) - { - Sequence<PropertyValue> aTable; - pTablesIter->Value >>= aTable; - loadTableWindow(aTable); - } - if ( m_aMinimumTableViewSize != Point() ) - { - getJoinView()->getScrollHelper()->resetRange(m_aMinimumTableViewSize); - } - break; - } + ::comphelper::NamedValueCollection aSingleTableData( pTablesIter->Value ); + loadTableWindow( aSingleTableData ); + } + if ( m_aMinimumTableViewSize != Point() ) + { + getJoinView()->getScrollHelper()->resetRange( m_aMinimumTableViewSize ); } } + // ----------------------------------------------------------------------------- -void OJoinController::loadTableWindow(const Sequence<PropertyValue>& _rTable) +void OJoinController::loadTableWindow( const ::comphelper::NamedValueCollection& i_rTableWindowSettings ) { sal_Int32 nX = -1, nY = -1, nHeight = -1, nWidth = -1; ::rtl::OUString sComposedName,sTableName,sWindowName; sal_Bool bShowAll = false; - const PropertyValue *pIter = _rTable.getConstArray(); - const PropertyValue *pEnd = pIter + _rTable.getLength(); - for (; pIter != pEnd; ++pIter) - { - if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ComposedName" ) ) ) - pIter->Value >>= sComposedName; - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "TableName" ) ) ) - pIter->Value >>= sTableName; - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WindowName" ) ) ) - pIter->Value >>= sWindowName; - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WindowTop" ) ) ) - { - pIter->Value >>= nY; - } - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WindowLeft" ) ) ) - { - pIter->Value >>= nX; - } - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WindowWidth" ) ) ) - { - pIter->Value >>= nWidth; - } - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WindowHeight" ) ) ) - { - pIter->Value >>= nHeight; - } - else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ShowAll" ) ) ) - { - pIter->Value >>= bShowAll; - } - } + + sComposedName = i_rTableWindowSettings.getOrDefault( "ComposedName", sComposedName ); + sTableName = i_rTableWindowSettings.getOrDefault( "TableName", sTableName ); + sWindowName = i_rTableWindowSettings.getOrDefault( "WindowName", sWindowName ); + nY = i_rTableWindowSettings.getOrDefault( "WindowTop", nY ); + nX = i_rTableWindowSettings.getOrDefault( "WindowLeft", nX ); + nWidth = i_rTableWindowSettings.getOrDefault( "WindowWidth", nWidth ); + nHeight = i_rTableWindowSettings.getOrDefault( "WindowHeight", nHeight ); + bShowAll = i_rTableWindowSettings.getOrDefault( "ShowAll", bShowAll ); + TTableWindowData::value_type pData = createTableWindowData(sComposedName,sTableName,sWindowName); if ( pData ) { @@ -536,56 +505,31 @@ void OJoinController::loadTableWindow(const Sequence<PropertyValue>& _rTable) } } // ----------------------------------------------------------------------------- -void OJoinController::saveTableWindows(Sequence<PropertyValue>& _rViewProps) +void OJoinController::saveTableWindows( ::comphelper::NamedValueCollection& o_rViewSettings ) const { if ( !m_vTableData.empty() ) { - PropertyValue *pViewIter = _rViewProps.getArray(); - PropertyValue *pEnd = pViewIter + _rViewProps.getLength(); - const static ::rtl::OUString s_sTables(RTL_CONSTASCII_USTRINGPARAM("Tables")); - for (; pViewIter != pEnd && pViewIter->Name != s_sTables; ++pViewIter) - ; - - if ( pViewIter == pEnd ) - { - sal_Int32 nLen = _rViewProps.getLength(); - _rViewProps.realloc( nLen + 1 ); - pViewIter = _rViewProps.getArray() + nLen; - pViewIter->Name = s_sTables; - } - - Sequence<PropertyValue> aTables(m_vTableData.size()); - PropertyValue *pIter = aTables.getArray(); - - Sequence<PropertyValue> aWindow(8); + ::comphelper::NamedValueCollection aAllTablesData; - TTableWindowData::iterator aIter = m_vTableData.begin(); - TTableWindowData::iterator aEnd = m_vTableData.end(); - for(sal_Int32 i = 1;aIter != aEnd;++aIter,++pIter,++i) + TTableWindowData::const_iterator aIter = m_vTableData.begin(); + TTableWindowData::const_iterator aEnd = m_vTableData.end(); + for ( sal_Int32 i = 1; aIter != aEnd; ++aIter, ++i ) { - pIter->Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Table")) + ::rtl::OUString::valueOf(i); - - sal_Int32 nPos = 0; - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ComposedName")); - aWindow[nPos++].Value <<= (*aIter)->GetComposedName(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TableName")); - aWindow[nPos++].Value <<= (*aIter)->GetTableName(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WindowName")); - aWindow[nPos++].Value <<= (*aIter)->GetWinName(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WindowTop")); - aWindow[nPos++].Value <<= (*aIter)->GetPosition().Y(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WindowLeft")); - aWindow[nPos++].Value <<= (*aIter)->GetPosition().X(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WindowWidth")); - aWindow[nPos++].Value <<= (*aIter)->GetSize().Width(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WindowHeight")); - aWindow[nPos++].Value <<= (*aIter)->GetSize().Height(); - aWindow[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowAll")); - aWindow[nPos++].Value <<= (*aIter)->IsShowAll(); - - pIter->Value <<= aWindow; + ::comphelper::NamedValueCollection aWindowData; + aWindowData.put( "ComposedName", (*aIter)->GetComposedName() ); + aWindowData.put( "TableName", (*aIter)->GetTableName() ); + aWindowData.put( "WindowName", (*aIter)->GetWinName() ); + aWindowData.put( "WindowTop", (*aIter)->GetPosition().Y() ); + aWindowData.put( "WindowLeft", (*aIter)->GetPosition().X() ); + aWindowData.put( "WindowWidth", (*aIter)->GetSize().Width() ); + aWindowData.put( "WindowHeight", (*aIter)->GetSize().Height() ); + aWindowData.put( "ShowAll", (*aIter)->IsShowAll() ); + + const ::rtl::OUString sTableName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Table" ) ) + ::rtl::OUString::valueOf( i ) ); + aAllTablesData.put( sTableName, aWindowData.getPropertyValues() ); } - pViewIter->Value <<= aTables; + + o_rViewSettings.put( "Tables", aAllTablesData.getPropertyValues() ); } } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx index c290cbb79..fcc65664a 100644 --- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx +++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx @@ -709,7 +709,7 @@ namespace // if we have a none numeric field, the table alias could be in the name // otherwise we are not allowed to do this (e.g. 0.1 * PRICE ) - if ( !pEntryField->isNumeric() ) + if ( !pEntryField->isOtherFunction() ) { // we have to look if we have alias.* here but before we have to check if the column doesn't already exist String sTemp = rFieldName; @@ -1223,7 +1223,7 @@ namespace if (pParseNode.get()) { ::rtl::OUString sGroupBy; - pParseNode->parseNodeToStr( sGroupBy, + pParseNode->getChild(0)->parseNodeToStr( sGroupBy, xConnection, &rController.getParser().getContext(), sal_False, @@ -1989,6 +1989,7 @@ namespace (*aIter) = NULL; OTableFields().swap( rUnUsedFields ); } + //------------------------------------------------------------------------------ SqlParseError InitFromParseNodeImpl(OQueryDesignView* _pView,OSelectionBrowseBox* _pSelectionBrw) { @@ -2232,11 +2233,17 @@ namespace SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct)) { ::rtl::OUString aColumns; - pColumnRef->parseNodeToStr( aColumns, - xConnection, - &rController.getParser().getContext(), - sal_True, - sal_True); // quote is to true because we need quoted elements inside the function + pColumnRef->parseNodeToPredicateStr(aColumns, + xConnection, + rController.getNumberFormatter(), + _pView->getLocale(), + static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()), + &rController.getParser().getContext()); + //pColumnRef->parseNodeToStr( aColumns, + // xConnection, + // &rController.getParser().getContext(), + // sal_True, + // sal_True); // quote is to true because we need quoted elements inside the function sal_Int32 nFunctionType = FKT_NONE; ::connectivity::OSQLParseNode* pParamRef = NULL; @@ -2596,7 +2603,7 @@ IMPL_LINK( OQueryDesignView, SplitHdl, void*, /*p*/ ) m_bInSplitHandler = sal_True; m_aSplitter.SetPosPixel( Point( m_aSplitter.GetPosPixel().X(),m_aSplitter.GetSplitPosPixel() ) ); static_cast<OQueryController&>(getController()).setSplitPos(m_aSplitter.GetSplitPosPixel()); - static_cast<OQueryController&>(getController()).setModified(); + static_cast<OQueryController&>(getController()).setModified( sal_True ); Resize(); m_bInSplitHandler = sal_True; } @@ -3171,6 +3178,30 @@ void OQueryDesignView::setNoneVisbleRow(sal_Int32 _nRows) { m_pSelectionBox->SetNoneVisbleRow(_nRows); } + +// ----------------------------------------------------------------------------- +void OQueryDesignView::initByFieldDescriptions( const Sequence< PropertyValue >& i_rFieldDescriptions ) +{ + OQueryController& rController = static_cast< OQueryController& >( getController() ); + + m_pSelectionBox->PreFill(); + m_pSelectionBox->SetReadOnly( rController.isReadOnly() ); + m_pSelectionBox->Fill(); + + for ( const PropertyValue* field = i_rFieldDescriptions.getConstArray(); + field != i_rFieldDescriptions.getConstArray() + i_rFieldDescriptions.getLength(); + ++field + ) + { + ::vos::ORef< OTableFieldDesc > pField( new OTableFieldDesc() ); + pField->Load( *field, true ); + InsertField( pField, sal_True, sal_False ); + } + + rController.getUndoMgr()->Clear(); + m_pSelectionBox->Invalidate(); +} + // ----------------------------------------------------------------------------- bool OQueryDesignView::initByParseIterator( ::dbtools::SQLExceptionInfo* _pErrorInfo ) { diff --git a/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx b/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx index 34e15b825..bd1d07a93 100644 --- a/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx +++ b/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx @@ -205,37 +205,68 @@ OQueryContainerWindow* OQueryViewSwitch::getContainer() const } // ----------------------------------------------------------------------------- -bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo ) +void OQueryViewSwitch::impl_forceSQLView() { - sal_Bool bRet = sal_True; - sal_Bool bGraphicalDesign = static_cast<OQueryController&>(m_pDesignView->getController()).isGraphicalDesign(); - OAddTableDlg* pAddTabDialog( getAddTableDialog() ); - OQueryContainerWindow* pContainer = getContainer(); + // hide the "Add Table" dialog + m_bAddTableDialogWasVisible = pAddTabDialog ? pAddTabDialog->IsVisible() : false; + if ( m_bAddTableDialogWasVisible ) + pAddTabDialog->Hide(); + + // tell the views they're in/active + m_pDesignView->stopTimer(); + m_pTextView->getSqlEdit()->startTimer(); + + // set the most recent statement at the text view + m_pTextView->clear(); + m_pTextView->setStatement(static_cast<OQueryController&>(m_pDesignView->getController()).getStatement()); +} + +// ----------------------------------------------------------------------------- +void OQueryViewSwitch::forceInitialView() +{ + OQueryController& rQueryController( static_cast< OQueryController& >( m_pDesignView->getController() ) ); + const sal_Bool bGraphicalDesign = rQueryController.isGraphicalDesign(); if ( !bGraphicalDesign ) + impl_forceSQLView(); + else { - // hide the "Add Table" dialog - m_bAddTableDialogWasVisible = pAddTabDialog ? pAddTabDialog->IsVisible() : false; - if ( m_bAddTableDialogWasVisible ) - pAddTabDialog->Hide(); + // tell the text view it's inactive now + m_pTextView->getSqlEdit()->stopTimer(); + + // update the "Add Table" dialog + OAddTableDlg* pAddTabDialog( getAddTableDialog() ); + if ( pAddTabDialog ) + pAddTabDialog->Update(); - // tell the views they're in/active - m_pDesignView->stopTimer(); - m_pTextView->getSqlEdit()->startTimer(); + // initialize the design view + m_pDesignView->initByFieldDescriptions( rQueryController.getFieldInformation() ); - // set the most recent statement at the text view - m_pTextView->clear(); - m_pTextView->setStatement(static_cast<OQueryController&>(m_pDesignView->getController()).getStatement()); + // tell the design view it's active now + m_pDesignView->startTimer(); + } + + impl_postViewSwitch( bGraphicalDesign, true ); +} + +// ----------------------------------------------------------------------------- +bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo ) +{ + sal_Bool bRet = sal_True; + sal_Bool bGraphicalDesign = static_cast<OQueryController&>(m_pDesignView->getController()).isGraphicalDesign(); + + if ( !bGraphicalDesign ) + { + impl_forceSQLView(); } else { // tell the text view it's inactive now m_pTextView->getSqlEdit()->stopTimer(); - ::rtl::OUString sOldStatement = static_cast<OQueryController&>(m_pDesignView->getController()).getStatement(); - // update the "Add Table" dialog + OAddTableDlg* pAddTabDialog( getAddTableDialog() ); if ( pAddTabDialog ) pAddTabDialog->Update(); @@ -246,24 +277,34 @@ bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo ) m_pDesignView->startTimer(); } - if ( bRet ) + return impl_postViewSwitch( bGraphicalDesign, bRet ); +} + +// ----------------------------------------------------------------------------- +bool OQueryViewSwitch::impl_postViewSwitch( const bool i_bGraphicalDesign, const bool i_bSuccess ) +{ + if ( i_bSuccess ) { - m_pTextView->Show ( !bGraphicalDesign ); - m_pDesignView->Show ( bGraphicalDesign ); - if ( bGraphicalDesign && m_bAddTableDialogWasVisible && pAddTabDialog ) - pAddTabDialog->Show(); + m_pTextView->Show ( !i_bGraphicalDesign ); + m_pDesignView->Show ( i_bGraphicalDesign ); + OAddTableDlg* pAddTabDialog( getAddTableDialog() ); + if ( pAddTabDialog ) + if ( i_bGraphicalDesign && m_bAddTableDialogWasVisible ) + pAddTabDialog->Show(); GrabFocus(); } + OQueryContainerWindow* pContainer = getContainer(); if ( pContainer ) pContainer->Resize(); m_pDesignView->getController().getUndoMgr()->Clear(); m_pDesignView->getController().InvalidateAll(); - return bRet; + return i_bSuccess; } + // ----------------------------------------------------------------------------- OAddTableDlg* OQueryViewSwitch::getAddTableDialog() { diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx index 0726fa4ea..156fdf99d 100644 --- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx +++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx @@ -754,11 +754,22 @@ sal_Bool OSelectionBrowseBox::saveField(const String& _sFieldName,OTableFieldDes bool bInternational = ( nPass % 2 ) == 0; ::rtl::OUString sSql; - sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT ")); if ( bQuote ) sSql += ::dbtools::quoteName( xMetaData->getIdentifierQuoteString(), _sFieldName ); else sSql += _sFieldName; + + if ( _pEntry->isAggreateFunction() ) + { + DBG_ASSERT(_pEntry->GetFunction().getLength(),"Functionname darf hier nicht leer sein! ;-("); + ::rtl::OUStringBuffer aTmpStr2( _pEntry->GetFunction()); + aTmpStr2.appendAscii("("); + aTmpStr2.append(sSql); + aTmpStr2.appendAscii(")"); + sSql = aTmpStr2.makeStringAndClear(); + } + + sSql = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT ")) + sSql; if ( sFieldAlias.getLength() ) { // always quote the alias name there canbe no function in it sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ")); @@ -1357,7 +1368,7 @@ void OSelectionBrowseBox::RemoveColumn(USHORT _nColumnId) ActivateCell( nCurrentRow, nCurCol ); - rController.setModified(); + rController.setModified( sal_True ); invalidateUndoRedo(); } @@ -1644,7 +1655,7 @@ void OSelectionBrowseBox::InsertColumn(OTableFieldDescRef pEntry, USHORT& _nColu Invalidate( aInvalidRect ); ActivateCell( nCurrentRow, nCurCol ); - static_cast<OQueryController&>(getDesignView()->getController()).setModified(); + static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True ); invalidateUndoRedo(); } @@ -2022,7 +2033,7 @@ void OSelectionBrowseBox::CellModified() } break; } - static_cast<OQueryController&>(getDesignView()->getController()).setModified(); + static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True ); } //------------------------------------------------------------------------------ @@ -2127,12 +2138,12 @@ void OSelectionBrowseBox::Command(const CommandEvent& rEvt) break; case ID_QUERY_DISTINCT: static_cast<OQueryController&>(getDesignView()->getController()).setDistinct(!static_cast<OQueryController&>(getDesignView()->getController()).isDistinct()); - static_cast<OQueryController&>(getDesignView()->getController()).setModified(); + static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True ); static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature( SID_QUERY_DISTINCT_VALUES ); break; } - static_cast<OQueryController&>(getDesignView()->getController()).setModified(); + static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True ); } } else @@ -2465,7 +2476,7 @@ void OSelectionBrowseBox::SetCellContents(sal_Int32 nRow, USHORT nColId, const S if (bWasEditing) ActivateCell(nCellIndex, nColId); - static_cast<OQueryController&>(getDesignView()->getController()).setModified(); + static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True ); } //------------------------------------------------------------------------------ sal_uInt32 OSelectionBrowseBox::GetTotalCellWidth(long nRow, sal_uInt16 nColId) const @@ -2493,7 +2504,7 @@ void OSelectionBrowseBox::ColumnResized(sal_uInt16 nColId) DBG_ASSERT(nPos <= getFields().size(),"ColumnResized:: nColId sollte nicht groesser als List::count sein!"); OTableFieldDescRef pEntry = getEntry(nPos-1); DBG_ASSERT(pEntry.isValid(), "OSelectionBrowseBox::ColumnResized : keine FieldDescription !"); - static_cast<OQueryController&>(getDesignView()->getController()).setModified(); + static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True ); EditBrowseBox::ColumnResized(nColId); if ( pEntry.isValid()) diff --git a/dbaccess/source/ui/querydesign/TableFieldDescription.cxx b/dbaccess/source/ui/querydesign/TableFieldDescription.cxx index 535fe5d21..472739f9c 100644 --- a/dbaccess/source/ui/querydesign/TableFieldDescription.cxx +++ b/dbaccess/source/ui/querydesign/TableFieldDescription.cxx @@ -37,9 +37,9 @@ #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ #include <com/sun/star/sdbc/DataType.hpp> #endif -#ifndef _COMPHELPER_STREAMSECTION_HXX_ -#include <comphelper/streamsection.hxx> -#endif +#include <comphelper/namedvaluecollection.hxx> + +#include <functional> using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::uno; @@ -96,7 +96,7 @@ OTableFieldDesc& OTableFieldDesc::operator=( const OTableFieldDesc& rRS ) if (&rRS == this) return *this; - m_vecCriteria = rRS.m_vecCriteria; + m_aCriteria = rRS.GetCriteria(); m_aTableName = rRS.GetTable(); m_aAliasName = rRS.GetAlias(); // table range m_aFieldName = rRS.GetField(); // column @@ -127,7 +127,7 @@ sal_Bool OTableFieldDesc::operator==( const OTableFieldDesc& rDesc ) m_aFieldName != rDesc.GetField() || m_aTableName != rDesc.GetTable() || m_bGroupBy != rDesc.IsGroupBy() || - m_vecCriteria != rDesc.GetCriteria() || + m_aCriteria != rDesc.GetCriteria() || m_bVisible != rDesc.IsVisible() ); } @@ -136,13 +136,13 @@ sal_Bool OTableFieldDesc::operator==( const OTableFieldDesc& rDesc ) void OTableFieldDesc::SetCriteria( sal_uInt16 nIdx, const ::rtl::OUString& rCrit) { DBG_CHKTHIS(OTableFieldDesc,NULL); - if (nIdx < m_vecCriteria.size()) - m_vecCriteria[nIdx] = rCrit; + if (nIdx < m_aCriteria.size()) + m_aCriteria[nIdx] = rCrit; else { - for(sal_Int32 i=m_vecCriteria.size();i<nIdx;++i) - m_vecCriteria.push_back( ::rtl::OUString()); - m_vecCriteria.push_back(rCrit); + for(sal_Int32 i=m_aCriteria.size();i<nIdx;++i) + m_aCriteria.push_back( ::rtl::OUString()); + m_aCriteria.push_back(rCrit); } } @@ -151,92 +151,94 @@ void OTableFieldDesc::SetCriteria( sal_uInt16 nIdx, const ::rtl::OUString& rCrit { DBG_CHKTHIS(OTableFieldDesc,NULL); ::rtl::OUString aRetStr; - if( nIdx < m_vecCriteria.size()) - aRetStr = m_vecCriteria[nIdx]; + if( nIdx < m_aCriteria.size()) + aRetStr = m_aCriteria[nIdx]; return aRetStr; } // ----------------------------------------------------------------------------- -void OTableFieldDesc::Load(const ::com::sun::star::beans::PropertyValue& _rProperty) +namespace { - DBG_CHKTHIS(OTableFieldDesc,NULL); - Sequence<PropertyValue> aFieldDesc; - _rProperty.Value >>= aFieldDesc; - //if ( aFieldDesc.getLength() == 12 ) + struct SelectPropertyValueAsString : public ::std::unary_function< PropertyValue, ::rtl::OUString > { - sal_Int32 nCount = aFieldDesc.getLength(); - for (sal_Int32 nPos = 0; nPos < nCount; ++nPos) + ::rtl::OUString operator()( const PropertyValue& i_rPropValue ) const { - if ( aFieldDesc[nPos].Name.equalsAscii("AliasName") ) - aFieldDesc[nPos].Value >>= m_aAliasName; - else if ( aFieldDesc[nPos].Name.equalsAscii("TableName") ) - aFieldDesc[nPos].Value >>= m_aTableName; - else if ( aFieldDesc[nPos].Name.equalsAscii("FieldName") ) - aFieldDesc[nPos].Value >>= m_aFieldName; - else if ( aFieldDesc[nPos].Name.equalsAscii("FieldAlias") ) - aFieldDesc[nPos].Value >>= m_aFieldAlias; - else if ( aFieldDesc[nPos].Name.equalsAscii("FunctionName") ) - aFieldDesc[nPos].Value >>= m_aFunctionName; - else if ( aFieldDesc[nPos].Name.equalsAscii("DataType") ) - aFieldDesc[nPos].Value >>= m_eDataType; - else if ( aFieldDesc[nPos].Name.equalsAscii("FunctionType") ) - aFieldDesc[nPos].Value >>= m_eFunctionType; - else if ( aFieldDesc[nPos].Name.equalsAscii("FieldType") ) - { - sal_Int32 nTemp = 0; - aFieldDesc[nPos].Value >>= nTemp; - m_eFieldType = static_cast<ETableFieldType>(nTemp); - } - else if ( aFieldDesc[nPos].Name.equalsAscii("OrderDir") ) - { - sal_Int32 nTemp = 0; - aFieldDesc[nPos].Value >>= nTemp; - m_eOrderDir = static_cast<EOrderDir>(nTemp); - } - else if ( aFieldDesc[nPos].Name.equalsAscii("ColWidth") ) - aFieldDesc[nPos].Value >>= m_nColWidth; - else if ( aFieldDesc[nPos].Name.equalsAscii("GroupBy") ) - aFieldDesc[nPos].Value >>= m_bGroupBy; - else if ( aFieldDesc[nPos].Name.equalsAscii("Visible") ) - aFieldDesc[nPos].Value >>= m_bVisible; + ::rtl::OUString sValue; + OSL_VERIFY( i_rPropValue.Value >>= sValue ); + return sValue; } + }; +} + +// ----------------------------------------------------------------------------- +void OTableFieldDesc::Load( const ::com::sun::star::beans::PropertyValue& i_rSettings, const bool i_bIncludingCriteria ) +{ + DBG_CHKTHIS(OTableFieldDesc,NULL); + + ::comphelper::NamedValueCollection aFieldDesc( i_rSettings.Value ); + m_aAliasName = aFieldDesc.getOrDefault( "AliasName", m_aAliasName ); + m_aTableName = aFieldDesc.getOrDefault( "TableName", m_aTableName ); + m_aFieldName = aFieldDesc.getOrDefault( "FieldName", m_aFieldName ); + m_aFieldAlias = aFieldDesc.getOrDefault( "FieldAlias", m_aFieldAlias ); + m_aFunctionName = aFieldDesc.getOrDefault( "FunctionName", m_aFunctionName ); + m_eDataType = aFieldDesc.getOrDefault( "DataType", m_eDataType ); + m_eFunctionType = aFieldDesc.getOrDefault( "FunctionType", m_eFunctionType ); + m_nColWidth = aFieldDesc.getOrDefault( "ColWidth", m_nColWidth ); + m_bGroupBy = aFieldDesc.getOrDefault( "GroupBy", m_bGroupBy ); + m_bVisible = aFieldDesc.getOrDefault( "Visible", m_bVisible ); + + m_eFieldType = static_cast< ETableFieldType >( aFieldDesc.getOrDefault( "FieldType", static_cast< sal_Int32 >( m_eFieldType ) ) ); + m_eOrderDir = static_cast< EOrderDir >( aFieldDesc.getOrDefault( "OrderDir", static_cast< sal_Int32 >( m_eOrderDir ) ) ); + + if ( i_bIncludingCriteria ) + { + const Sequence< PropertyValue > aCriteria( aFieldDesc.getOrDefault( "Criteria", Sequence< PropertyValue >() ) ); + m_aCriteria.resize( aCriteria.getLength() ); + ::std::transform( + aCriteria.getConstArray(), + aCriteria.getConstArray() + aCriteria.getLength(), + m_aCriteria.begin(), + SelectPropertyValueAsString() + ); } } //------------------------------------------------------------------------------ -void OTableFieldDesc::Save(::com::sun::star::beans::PropertyValue& _rProperty) +void OTableFieldDesc::Save( ::comphelper::NamedValueCollection& o_rSettings, const bool i_bIncludingCriteria ) { DBG_CHKTHIS(OTableFieldDesc,NULL); + o_rSettings.put( "AliasName", m_aAliasName ); + o_rSettings.put( "TableName", m_aTableName ); + o_rSettings.put( "FieldName", m_aFieldName ); + o_rSettings.put( "FieldAlias", m_aFieldAlias ); + o_rSettings.put( "FunctionName", m_aFunctionName ); + o_rSettings.put( "DataType", m_eDataType ); + o_rSettings.put( "FunctionType", (sal_Int32)m_eFunctionType ); + o_rSettings.put( "FieldType", (sal_Int32)m_eFieldType ); + o_rSettings.put( "OrderDir", (sal_Int32)m_eOrderDir ); + o_rSettings.put( "ColWidth", m_nColWidth ); + o_rSettings.put( "GroupBy", m_bGroupBy ); + o_rSettings.put( "Visible", m_bVisible ); + + if ( i_bIncludingCriteria ) + { + if ( !m_aCriteria.empty() ) + { + sal_Int32 c = 0; + Sequence< PropertyValue > aCriteria( m_aCriteria.size() ); + for ( ::std::vector< ::rtl::OUString >::const_iterator crit = m_aCriteria.begin(); + crit != m_aCriteria.end(); + ++crit, ++c + ) + { + aCriteria[c].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Criterion_" ) ) + ::rtl::OUString::valueOf( c ); + aCriteria[c].Value <<= *crit; + } - Sequence<PropertyValue> aFieldDesc(13); - sal_Int32 nPos = 0; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AliasName")); - aFieldDesc[nPos++].Value <<= m_aAliasName; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TableName")); - aFieldDesc[nPos++].Value <<= m_aTableName; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldName")); - aFieldDesc[nPos++].Value <<= m_aFieldName; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldAlias")); - aFieldDesc[nPos++].Value <<= m_aFieldAlias; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FunctionName")); - aFieldDesc[nPos++].Value <<= m_aFunctionName; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataType")); - aFieldDesc[nPos++].Value <<= m_eDataType; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FunctionType")); - aFieldDesc[nPos++].Value <<= (sal_Int32)m_eFunctionType; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldType")); - aFieldDesc[nPos++].Value <<= (sal_Int32)m_eFieldType; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OrderDir")); - aFieldDesc[nPos++].Value <<= (sal_Int32)m_eOrderDir; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ColWidth")); - aFieldDesc[nPos++].Value <<= m_nColWidth; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GroupBy")); - aFieldDesc[nPos++].Value <<= m_bGroupBy; - aFieldDesc[nPos].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Visible")); - aFieldDesc[nPos++].Value <<= m_bVisible; - - _rProperty.Value <<= aFieldDesc; + o_rSettings.put( "Criteria", aCriteria ); + } + } } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/querydesign/querycontainerwindow.cxx b/dbaccess/source/ui/querydesign/querycontainerwindow.cxx index d19fa761e..6daa54afb 100644 --- a/dbaccess/source/ui/querydesign/querycontainerwindow.cxx +++ b/dbaccess/source/ui/querydesign/querycontainerwindow.cxx @@ -123,6 +123,12 @@ namespace dbaui } // ----------------------------------------------------------------------------- + void OQueryContainerWindow::forceInitialView() + { + return m_pViewSwitch->forceInitialView(); + } + + // ----------------------------------------------------------------------------- void OQueryContainerWindow::resizeAll( const Rectangle& _rPlayground ) { Rectangle aPlayground( _rPlayground ); diff --git a/dbaccess/source/ui/querydesign/querycontroller.cxx b/dbaccess/source/ui/querydesign/querycontroller.cxx index 17717dafe..e3dd6541f 100644 --- a/dbaccess/source/ui/querydesign/querycontroller.cxx +++ b/dbaccess/source/ui/querydesign/querycontroller.cxx @@ -78,6 +78,7 @@ #include <comphelper/basicio.hxx> #include <comphelper/extract.hxx> +#include <comphelper/property.hxx> #include <comphelper/seqstream.hxx> #include <comphelper/streamsection.hxx> #include <comphelper/types.hxx> @@ -371,6 +372,50 @@ Reference< XPropertySetInfo > SAL_CALL OQueryController::getPropertySetInfo() th } //------------------------------------------------------------------------- +sal_Bool SAL_CALL OQueryController::convertFastPropertyValue( Any& o_rConvertedValue, Any& o_rOldValue, sal_Int32 i_nHandle, const Any& i_rValue ) throw (IllegalArgumentException) +{ + return OPropertyContainer::convertFastPropertyValue( o_rConvertedValue, o_rOldValue, i_nHandle, i_rValue ); +} + +//------------------------------------------------------------------------- +void SAL_CALL OQueryController::setFastPropertyValue_NoBroadcast( sal_Int32 i_nHandle, const Any& i_rValue ) throw ( Exception ) +{ + OPropertyContainer::setFastPropertyValue_NoBroadcast( i_nHandle, i_rValue ); +} + +//------------------------------------------------------------------------- +void SAL_CALL OQueryController::getFastPropertyValue( Any& o_rValue, sal_Int32 i_nHandle ) const +{ + switch ( i_nHandle ) + { + case PROPERTY_ID_CURRENT_QUERY_DESIGN: + { + ::comphelper::NamedValueCollection aCurrentDesign; + aCurrentDesign.put( "GraphicalDesign", isGraphicalDesign() ); + aCurrentDesign.put( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, m_bEscapeProcessing ); + + if ( isGraphicalDesign() ) + { + getContainer()->SaveUIConfig(); + saveViewSettings( aCurrentDesign, true ); + aCurrentDesign.put( "Statement", m_sStatement ); + } + else + { + aCurrentDesign.put( "Statement", getContainer()->getStatement() ); + } + + o_rValue <<= aCurrentDesign.getPropertyValues(); + } + break; + + default: + OPropertyContainer::getFastPropertyValue( o_rValue, i_nHandle ); + break; + } +} + +//------------------------------------------------------------------------- ::cppu::IPropertyArrayHelper& OQueryController::getInfoHelper() { return *const_cast< OQueryController* >( this )->getArrayHelper(); @@ -380,7 +425,24 @@ Reference< XPropertySetInfo > SAL_CALL OQueryController::getPropertySetInfo() th ::cppu::IPropertyArrayHelper* OQueryController::createArrayHelper( ) const { Sequence< Property > aProps; - describeProperties(aProps); + describeProperties( aProps ); + + // one additional property: + const sal_Int32 nLength = aProps.getLength(); + aProps.realloc( nLength + 1 ); + aProps[ nLength ] = Property( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CurrentQueryDesign" ) ), + PROPERTY_ID_CURRENT_QUERY_DESIGN, + ::cppu::UnoType< Sequence< PropertyValue > >::get(), + PropertyAttribute::READONLY + ); + + ::std::sort( + aProps.getArray(), + aProps.getArray() + aProps.getLength(), + ::comphelper::PropertyCompareByName() + ); + return new ::cppu::OPropertyArrayHelper(aProps); } @@ -445,7 +507,7 @@ FeatureState OQueryController::GetState(sal_uInt16 _nId) const aReturn.bEnabled = !editingCommand() && !editingView() && (!m_bGraphicalDesign || !(m_vTableFieldDesc.empty() || m_vTableData.empty())); break; case ID_BROWSER_SAVEDOC: - aReturn.bEnabled = isModified() && (!m_bGraphicalDesign || !(m_vTableFieldDesc.empty() || m_vTableData.empty())); + aReturn.bEnabled = impl_isModified() && (!m_bGraphicalDesign || !(m_vTableFieldDesc.empty() || m_vTableData.empty())); break; case SID_PRINTDOCDIRECT: break; @@ -794,6 +856,9 @@ void OQueryController::impl_initialize() ::rtl::OUString sCommand; m_nCommandType = CommandType::QUERY; + // °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° + // ° reading parameters + // °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° // legacy parameters first (later overwritten by regular parameters) ::rtl::OUString sIndependentSQLCommand; if ( rArguments.get_ensureType( "IndependentSQLCommand", sIndependentSQLCommand ) ) @@ -863,6 +928,37 @@ void OQueryController::impl_initialize() m_bGraphicalDesign = false; } + // ................................................................................................................. + // . initial design + bool bForceInitialDesign = false; + Sequence< PropertyValue > aCurrentQueryDesignProps; + aCurrentQueryDesignProps = rArguments.getOrDefault( "CurrentQueryDesign", aCurrentQueryDesignProps ); + + if ( aCurrentQueryDesignProps.getLength() ) + { + ::comphelper::NamedValueCollection aCurrentQueryDesign( aCurrentQueryDesignProps ); + if ( aCurrentQueryDesign.has( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN ) ) + { + aCurrentQueryDesign.get_ensureType( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, m_bGraphicalDesign ); + } + if ( aCurrentQueryDesign.has( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING ) ) + { + aCurrentQueryDesign.get_ensureType( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, m_bEscapeProcessing ); + } + if ( aCurrentQueryDesign.has( "Statement" ) ) + { + ::rtl::OUString sStatement; + aCurrentQueryDesign.get_ensureType( "Statement", sStatement ); + aCurrentQueryDesign.remove( "Statement" ); + setStatement_fireEvent( sStatement ); + } + + loadViewSettings( aCurrentQueryDesign ); + + bForceInitialDesign = true; + } + + // °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° if ( !ensureConnected( sal_False ) ) { // we have no connection so what else should we do m_bGraphicalDesign = sal_False; @@ -917,19 +1013,29 @@ void OQueryController::impl_initialize() try { getContainer()->initialize(); - impl_reset(); + impl_reset( bForceInitialDesign ); - bool bAttemptedGraphicalDesign = m_bGraphicalDesign; SQLExceptionInfo aError; - impl_setViewMode( &aError ); + const bool bAttemptedGraphicalDesign = m_bGraphicalDesign; + + if ( bForceInitialDesign ) + { + getContainer()->forceInitialView(); + } + else + { + impl_setViewMode( &aError ); + } + if ( aError.isValid() && bAttemptedGraphicalDesign && !m_bGraphicalDesign ) { + // we tried initializing the graphical view, this failed, and we were automatically switched to SQL + // view => tell this to the user if ( !editingView() ) { impl_showAutoSQLViewError( aError.get() ); } } - getUndoMgr()->Clear(); @@ -1011,7 +1117,7 @@ sal_Bool OQueryController::Construct(Window* pParent) { // TODO: we have to check if we should create the text- or the design- view - m_pView = new OQueryContainerWindow( pParent, *this, getORB() ); + setView( * new OQueryContainerWindow( pParent, *this, getORB() ) ); return OJoinController::Construct(pParent); } @@ -1043,9 +1149,9 @@ void OQueryController::describeSupportedFeatures() #endif } // ----------------------------------------------------------------------------- -void OQueryController::setModified(sal_Bool _bModified) +void OQueryController::impl_onModifyChanged() { - OJoinController::setModified(_bModified); + OJoinController::impl_onModifyChanged(); InvalidateFeature(SID_BROWSER_CLEAR_QUERY); InvalidateFeature(ID_BROWSER_SAVEASDOC); InvalidateFeature(ID_BROWSER_QUERY_EXECUTE); @@ -1093,69 +1199,41 @@ void OQueryController::reconnect(sal_Bool _bUI) InvalidateAll(); } } + // ----------------------------------------------------------------------------- -void OQueryController::saveViewSettings(Sequence<PropertyValue>& _rViewProps) +void OQueryController::saveViewSettings( ::comphelper::NamedValueCollection& o_rViewSettings, const bool i_includingCriteria ) const { - OTableFields::const_iterator aFieldIter = m_vTableFieldDesc.begin(); - OTableFields::const_iterator aFieldEnd = m_vTableFieldDesc.end(); - sal_Int32 nCount = 0; - for(;aFieldIter != aFieldEnd;++aFieldIter) - { - if(!(*aFieldIter)->IsEmpty()) - ++nCount; - } + saveTableWindows( o_rViewSettings ); - sal_Int32 nLen = _rViewProps.getLength(); + OTableFields::const_iterator field = m_vTableFieldDesc.begin(); + OTableFields::const_iterator fieldEnd = m_vTableFieldDesc.end(); - _rViewProps.realloc( nLen + 2 + (nCount != 0 ? 1 : 0) ); - PropertyValue *pIter = _rViewProps.getArray() + nLen; - - if ( nCount != 0 ) + ::comphelper::NamedValueCollection aAllFieldsData; + ::comphelper::NamedValueCollection aFieldData; + for ( sal_Int32 i = 1; field != fieldEnd; ++field, ++i ) { - pIter->Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fields")); - - Sequence<PropertyValue> aFields(nCount); - PropertyValue *pFieldsIter = aFields.getArray(); - // the fielddata - aFieldIter = m_vTableFieldDesc.begin(); - for(sal_Int32 i = 1;aFieldIter !=aFieldEnd;++aFieldIter,++i) + if ( !(*field)->IsEmpty() ) { - if ( !(*aFieldIter)->IsEmpty() ) - { - pFieldsIter->Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Field")) + ::rtl::OUString::valueOf(i); - (*aFieldIter)->Save(*pFieldsIter++); - } + aFieldData.clear(); + (*field)->Save( aFieldData, i_includingCriteria ); + + const ::rtl::OUString sFieldSettingName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Field" ) ) + ::rtl::OUString::valueOf( i ); + aAllFieldsData.put( sFieldSettingName, aFieldData.getPropertyValues() ); } - pIter->Value <<= aFields; - ++pIter; } - pIter->Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SplitterPosition")); - pIter->Value <<= m_nSplitPos; - ++pIter; - pIter->Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VisibleRows")); - pIter->Value <<= m_nVisibleRows; + o_rViewSettings.put( "Fields", aAllFieldsData.getPropertyValues() ); + o_rViewSettings.put( "SplitterPosition", m_nSplitPos ); + o_rViewSettings.put( "VisibleRows", m_nVisibleRows ); } // ----------------------------------------------------------------------------- -void OQueryController::loadViewSettings(const Sequence<PropertyValue>& _rViewProps) +void OQueryController::loadViewSettings( const ::comphelper::NamedValueCollection& o_rViewSettings ) { - const PropertyValue *pIter = _rViewProps.getConstArray(); - const PropertyValue *pEnd = pIter + _rViewProps.getLength(); - for (; pIter != pEnd; ++pIter) - { - if ( pIter->Name.equalsAscii("SplitterPosition") ) - { - pIter->Value >>= m_nSplitPos; - } - else if ( pIter->Name.equalsAscii("VisibleRows") ) - { - pIter->Value >>= m_nVisibleRows; - } - else if ( pIter->Name.equalsAscii("Fields") ) - { - pIter->Value >>= m_aFieldInformation; - } - } + loadTableWindows( o_rViewSettings ); + + m_nSplitPos = o_rViewSettings.getOrDefault( "SplitterPosition", m_nSplitPos ); + m_nVisibleRows = o_rViewSettings.getOrDefault( "VisibleRows", m_nVisibleRows ); + m_aFieldInformation = o_rViewSettings.getOrDefault( "Fields", m_aFieldInformation ); } // ----------------------------------------------------------------------------- sal_Int32 OQueryController::getColWidth(sal_uInt16 _nColPos) const @@ -1163,7 +1241,7 @@ sal_Int32 OQueryController::getColWidth(sal_uInt16 _nColPos) const if ( _nColPos < m_aFieldInformation.getLength() ) { ::std::auto_ptr<OTableFieldDesc> pField( new OTableFieldDesc()); - pField->Load(m_aFieldInformation[_nColPos]); + pField->Load( m_aFieldInformation[ _nColPos ], false ); return pField->GetColWidth(); } return 0; @@ -1435,12 +1513,7 @@ bool OQueryController::doSaveAsDoc(sal_Bool _bSaveAs) xQuery->setPropertyValue( PROPERTY_UPDATE_TABLENAME, makeAny( m_sUpdateTableName ) ); xQuery->setPropertyValue( PROPERTY_ESCAPE_PROCESSING,::cppu::bool2any( m_bEscapeProcessing ) ); - // layout information - getContainer()->SaveUIConfig(); - Sequence< PropertyValue > aLayout; - saveTableWindows( aLayout ); - saveViewSettings( aLayout ); - xQuery->setPropertyValue( PROPERTY_LAYOUTINFORMATION, makeAny( aLayout ) ); + xQuery->setPropertyValue( PROPERTY_LAYOUTINFORMATION, getViewData() ); } } @@ -1588,13 +1661,13 @@ short OQueryController::saveModified() return nRet; } // ----------------------------------------------------------------------------- -void OQueryController::impl_reset() +void OQueryController::impl_reset( const bool i_bForceCurrentControllerSettings ) { bool bValid = false; Sequence< PropertyValue > aLayoutInformation; // get command from the query if a query name was supplied - if ( !editingCommand() ) + if ( !i_bForceCurrentControllerSettings && !editingCommand() ) { if ( m_sName.getLength() ) { @@ -1644,15 +1717,14 @@ void OQueryController::impl_reset() { try { - // load the layoutInformation - loadTableWindows(aLayoutInformation); - loadViewSettings(aLayoutInformation); + loadViewSettings( aLayoutInformation ); } catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); } } + if ( m_sStatement.getLength() ) { setQueryComposer(); @@ -1676,7 +1748,7 @@ void OQueryController::impl_reset() m_pSqlIterator->traverseAll(); if ( m_pSqlIterator->hasErrors() ) { - if ( !editingView() ) + if ( !i_bForceCurrentControllerSettings && !editingView() ) { impl_showAutoSQLViewError( makeAny( m_pSqlIterator->getErrors() ) ); } @@ -1685,7 +1757,7 @@ void OQueryController::impl_reset() } else { - if ( !editingView() ) + if ( !i_bForceCurrentControllerSettings && !editingView() ) { String aTitle(ModuleRes(STR_SVT_SQL_SYNTAX_ERROR)); OSQLMessageBox aDlg(getView(),aTitle,aErrorMsg); @@ -1773,6 +1845,23 @@ bool OQueryController::allowQueries() const } // ----------------------------------------------------------------------------- +Any SAL_CALL OQueryController::getViewData() throw( RuntimeException ) +{ + ::osl::MutexGuard aGuard( getMutex() ); + + getContainer()->SaveUIConfig(); + + ::comphelper::NamedValueCollection aViewSettings; + saveViewSettings( aViewSettings, false ); + + return makeAny( aViewSettings.getPropertyValues() ); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OQueryController::restoreViewData(const Any& /*Data*/) throw( RuntimeException ) +{ + // TODO +} + // ----------------------------------------------------------------------------- } // namespace dbaui // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/relationdesign/RelationController.cxx b/dbaccess/source/ui/relationdesign/RelationController.cxx index b26d3dc09..c32fbb75b 100644 --- a/dbaccess/source/ui/relationdesign/RelationController.cxx +++ b/dbaccess/source/ui/relationdesign/RelationController.cxx @@ -157,7 +157,7 @@ FeatureState ORelationController::GetState(sal_uInt16 _nId) const aReturn.bChecked = false; break; case ID_BROWSER_SAVEDOC: - aReturn.bEnabled = haveDataSource() && isModified(); + aReturn.bEnabled = haveDataSource() && impl_isModified(); break; default: aReturn = OJoinController::GetState(_nId); @@ -186,20 +186,21 @@ void ORelationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue { if ( haveDataSource() && getDataSource()->getPropertySetInfo()->hasPropertyByName(PROPERTY_LAYOUTINFORMATION) ) { - Sequence<PropertyValue> aWindows; - saveTableWindows(aWindows); - getDataSource()->setPropertyValue(PROPERTY_LAYOUTINFORMATION,makeAny(aWindows)); + ::comphelper::NamedValueCollection aWindowsData; + saveTableWindows( aWindowsData ); + getDataSource()->setPropertyValue( PROPERTY_LAYOUTINFORMATION, makeAny( aWindowsData.getPropertyValues() ) ); setModified(sal_False); } } - catch(Exception&) + catch ( const Exception& ) { + DBG_UNHANDLED_EXCEPTION(); } } } break; case SID_RELATION_ADD_RELATION: - static_cast<ORelationTableView*>(static_cast<ORelationDesignView*>(m_pView)->getTableView())->AddNewRelation(); + static_cast<ORelationTableView*>(static_cast<ORelationDesignView*>( getView() )->getTableView())->AddNewRelation(); break; default: OJoinController::Execute(_nId,aArgs); @@ -260,10 +261,8 @@ void ORelationController::impl_initialize() // ----------------------------------------------------------------------------- sal_Bool ORelationController::Construct(Window* pParent) { - m_pView = new ORelationDesignView( pParent, *this, getORB() ); + setView( * new ORelationDesignView( pParent, *this, getORB() ) ); OJoinController::Construct(pParent); -// m_pView->Construct(); -// m_pView->Show(); return sal_True; } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/tabledesign/TableController.cxx b/dbaccess/source/ui/tabledesign/TableController.cxx index b176dc8d7..9b45c0eea 100644 --- a/dbaccess/source/ui/tabledesign/TableController.cxx +++ b/dbaccess/source/ui/tabledesign/TableController.cxx @@ -204,7 +204,7 @@ void OTableController::stopTableListening() void OTableController::disposing() { OTableController_BASE::disposing(); - m_pView = NULL; + clearView(); m_vRowList.clear(); } @@ -224,7 +224,7 @@ FeatureState OTableController::GetState(sal_uInt16 _nId) const aReturn.bEnabled = m_bNew || isEditable();// the editable flag is set through this one -> || isAddAllowed() || isDropAllowed() || isAlterAllowed(); break; case ID_BROWSER_SAVEDOC: - aReturn.bEnabled = isModified(); + aReturn.bEnabled = impl_isModified(); if ( aReturn.bEnabled ) { ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aIter = ::std::find_if(m_vRowList.begin(),m_vRowList.end(), @@ -253,7 +253,7 @@ FeatureState OTableController::GetState(sal_uInt16 _nId) const break; case SID_INDEXDESIGN: aReturn.bEnabled = - ( ( ((!m_bNew && isModified()) || isModified()) + ( ( ((!m_bNew && impl_isModified()) || impl_isModified()) || Reference< XIndexesSupplier >(m_xTable, UNO_QUERY).is() ) && isConnected() @@ -576,7 +576,7 @@ void OTableController::impl_initialize() // ----------------------------------------------------------------------------- sal_Bool OTableController::Construct(Window* pParent) { - m_pView = new OTableDesignView( pParent, getORB(), *this ); + setView( * new OTableDesignView( pParent, getORB(), *this ) ); OTableController_BASE::Construct(pParent); // m_pView->Construct(); // m_pView->Show(); @@ -668,10 +668,10 @@ SfxUndoManager* OTableController::getUndoMgr() return &m_aUndoManager; } // ----------------------------------------------------------------------------- -void OTableController::setModified(sal_Bool _bModified) +void OTableController::impl_onModifyChanged() { - OSingleDocumentController::setModified(_bModified); - InvalidateFeature(SID_INDEXDESIGN); + OSingleDocumentController::impl_onModifyChanged(); + InvalidateFeature( SID_INDEXDESIGN ); } // ----------------------------------------------------------------------------- void SAL_CALL OTableController::disposing( const EventObject& _rSource ) throw(RuntimeException) diff --git a/dbaccess/source/ui/uno/copytablewizard.cxx b/dbaccess/source/ui/uno/copytablewizard.cxx index 3c15024c9..abec37723 100644 --- a/dbaccess/source/ui/uno/copytablewizard.cxx +++ b/dbaccess/source/ui/uno/copytablewizard.cxx @@ -1518,7 +1518,7 @@ void SAL_CALL CopyTableWizard::initialize( const Sequence< Any >& _rArguments ) ); } if ( !m_xInteractionHandler.is() ) - m_xInteractionHandler.set( m_aContext.createComponent( "com.sun.star.sdb.InteractionHandler" ), UNO_QUERY_THROW ); + m_xInteractionHandler.set( m_aContext.createComponent( "com.sun.star.task.InteractionHandler" ), UNO_QUERY_THROW ); InteractionHandler xSourceDocHandler; Reference< XPropertySet > xSourceDescriptor( impl_ensureDataAccessDescriptor_throw( _rArguments, 0, m_xSourceConnection, xSourceDocHandler ) ); diff --git a/dbaccess/source/ui/uno/dbinteraction.cxx b/dbaccess/source/ui/uno/dbinteraction.cxx index 18761b5d2..135838d79 100644 --- a/dbaccess/source/ui/uno/dbinteraction.cxx +++ b/dbaccess/source/ui/uno/dbinteraction.cxx @@ -97,7 +97,8 @@ extern "C" void SAL_CALL createRegistryInfo_OInteractionHandler() { - static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OInteractionHandler > aOInteractionHandler_AutoRegistration; + static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::SQLExceptionInteractionHandler > aSQLExceptionInteractionHandler_AutoRegistration; + static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::LegacyInteractionHandler > aLegacyInteractionHandler_AutoRegistration; } //......................................................................... @@ -113,62 +114,70 @@ namespace dbaui using namespace ::dbtools; //========================================================================= - //= OInteractionHandler + //= BasicInteractionHandler //========================================================================= //------------------------------------------------------------------------- - OInteractionHandler::OInteractionHandler(const Reference< XMultiServiceFactory >& _rxORB) - :m_xORB(_rxORB) + BasicInteractionHandler::BasicInteractionHandler( const Reference< XMultiServiceFactory >& _rxORB, const bool i_bFallbackToGeneric ) + :m_xORB( _rxORB ) + ,m_bFallbackToGeneric( i_bFallbackToGeneric ) { + OSL_ENSURE( !m_bFallbackToGeneric, + "BasicInteractionHandler::BasicInteractionHandler: enabling legacy behavior, there should be no clients of this anymore!" ); } //------------------------------------------------------------------------- - IMPLEMENT_SERVICE_INFO1_STATIC(OInteractionHandler, "com.sun.star.comp.dbu.OInteractionHandler", "com.sun.star.sdb.InteractionHandler"); + ::sal_Bool SAL_CALL BasicInteractionHandler::handleInteractionRequest( const Reference< XInteractionRequest >& i_rRequest ) throw (RuntimeException) + { + return impl_handle_throw( i_rRequest ); + } //------------------------------------------------------------------------- - void SAL_CALL OInteractionHandler::handle(const Reference< XInteractionRequest >& _rxRequest) throw(RuntimeException) + void SAL_CALL BasicInteractionHandler::handle( const Reference< XInteractionRequest >& i_rRequest ) throw(RuntimeException) { - Any aRequest; - if (_rxRequest.is()) - { - try { aRequest = _rxRequest->getRequest(); } - catch(RuntimeException&) { } - } - DBG_ASSERT(aRequest.hasValue(), "OInteractionHandler::handle: invalid request!"); - if (!aRequest.hasValue()) + impl_handle_throw( i_rRequest ); + } + + //------------------------------------------------------------------------- + sal_Bool BasicInteractionHandler::impl_handle_throw( const Reference< XInteractionRequest >& i_Request ) + { + Any aRequest( i_Request->getRequest() ); + DBG_ASSERT(aRequest.hasValue(), "BasicInteractionHandler::handle: invalid request!"); + if ( !aRequest.hasValue() ) // no request -> no handling - return; + return sal_False; - Sequence< Reference< XInteractionContinuation > > aContinuations; - try { aContinuations = _rxRequest->getContinuations(); } - catch(RuntimeException&) { } + Sequence< Reference< XInteractionContinuation > > aContinuations( i_Request->getContinuations() ); // try to extract an SQLException (or one of it's derived members - SQLExceptionInfo aInfo(aRequest); - if (aInfo.isValid()) + SQLExceptionInfo aInfo( aRequest ); + if ( aInfo.isValid() ) { - implHandle(aInfo, aContinuations); - return; + implHandle( aInfo, aContinuations ); + return sal_True; } ParametersRequest aParamRequest; - if (aRequest >>= aParamRequest) - { // it's an authentication request - implHandle(aParamRequest, aContinuations); - return; + if ( aRequest >>= aParamRequest ) + { + implHandle( aParamRequest, aContinuations ); + return sal_True; } DocumentSaveRequest aDocuRequest; - if (aRequest >>= aDocuRequest) - { // it's an document request - implHandle(aDocuRequest, aContinuations); - return; + if ( aRequest >>= aDocuRequest ) + { + implHandle( aDocuRequest, aContinuations ); + return sal_True; } - OSL_VERIFY( implHandleUnknown( _rxRequest ) ); + if ( m_bFallbackToGeneric ) + return implHandleUnknown( i_Request ); + + return sal_False; } //------------------------------------------------------------------------- - void OInteractionHandler::implHandle(const ParametersRequest& _rParamRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) + void BasicInteractionHandler::implHandle(const ParametersRequest& _rParamRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) { ::vos::OGuard aGuard(Application::GetSolarMutex()); // want to open a dialog .... @@ -179,7 +188,7 @@ namespace dbaui Reference< XInteractionSupplyParameters > xParamCallback; if (-1 != nParamPos) xParamCallback = Reference< XInteractionSupplyParameters >(_rContinuations[nParamPos], UNO_QUERY); - DBG_ASSERT(xParamCallback.is(), "OInteractionHandler::implHandle(ParametersRequest): can't set the parameters without an appropriate interaction handler!s"); + DBG_ASSERT(xParamCallback.is(), "BasicInteractionHandler::implHandle(ParametersRequest): can't set the parameters without an appropriate interaction handler!s"); // determine the style of the dialog, dependent on the present continuation types WinBits nDialogStyle = WB_OK | WB_DEF_OK; @@ -212,7 +221,7 @@ namespace dbaui } //------------------------------------------------------------------------- - void OInteractionHandler::implHandle(const SQLExceptionInfo& _rSqlInfo, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) + void BasicInteractionHandler::implHandle(const SQLExceptionInfo& _rSqlInfo, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) { ::vos::OGuard aGuard(Application::GetSolarMutex()); // want to open a dialog .... @@ -254,14 +263,14 @@ namespace dbaui if ( nApprovePos != -1 ) _rContinuations[ nApprovePos ]->select(); else - OSL_ENSURE( nResult != RET_YES, "OInteractionHandler::implHandle: no handler for YES!" ); + OSL_ENSURE( nResult != RET_YES, "BasicInteractionHandler::implHandle: no handler for YES!" ); break; case RET_NO: if ( nDisapprovePos != -1 ) _rContinuations[ nDisapprovePos ]->select(); else - OSL_ENSURE( false, "OInteractionHandler::implHandle: no handler for NO!" ); + OSL_ENSURE( false, "BasicInteractionHandler::implHandle: no handler for NO!" ); break; case RET_CANCEL: @@ -270,13 +279,13 @@ namespace dbaui else if ( nDisapprovePos != -1 ) _rContinuations[ nDisapprovePos ]->select(); else - OSL_ENSURE( false, "OInteractionHandler::implHandle: no handler for CANCEL!" ); + OSL_ENSURE( false, "BasicInteractionHandler::implHandle: no handler for CANCEL!" ); break; case RET_RETRY: if ( nRetryPos != -1 ) _rContinuations[ nRetryPos ]->select(); else - OSL_ENSURE( false, "OInteractionHandler::implHandle: where does the RETRY come from?" ); + OSL_ENSURE( false, "BasicInteractionHandler::implHandle: where does the RETRY come from?" ); break; } } @@ -286,7 +295,7 @@ namespace dbaui } } //------------------------------------------------------------------------- - void OInteractionHandler::implHandle(const DocumentSaveRequest& _rDocuRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) + void BasicInteractionHandler::implHandle(const DocumentSaveRequest& _rDocuRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) { ::vos::OGuard aGuard(Application::GetSolarMutex()); // want to open a dialog .... @@ -315,7 +324,7 @@ namespace dbaui if (-1 != nDocuPos) { Reference< XInteractionDocumentSave > xCallback(_rContinuations[nDocuPos], UNO_QUERY); - DBG_ASSERT(xCallback.is(), "OInteractionHandler::implHandle(DocumentSaveRequest): can't save document without an appropriate interaction handler!s"); + DBG_ASSERT(xCallback.is(), "BasicInteractionHandler::implHandle(DocumentSaveRequest): can't save document without an appropriate interaction handler!s"); // determine the style of the dialog, dependent on the present continuation types WinBits nDialogStyle = WB_OK | WB_DEF_OK; @@ -354,7 +363,7 @@ namespace dbaui } //------------------------------------------------------------------------- - bool OInteractionHandler::implHandleUnknown( const Reference< XInteractionRequest >& _rxRequest ) + bool BasicInteractionHandler::implHandleUnknown( const Reference< XInteractionRequest >& _rxRequest ) { Reference< XInteractionHandler > xFallbackHandler; if ( m_xORB.is() ) @@ -368,7 +377,7 @@ namespace dbaui } //------------------------------------------------------------------------- - sal_Int32 OInteractionHandler::getContinuation(Continuation _eCont, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) + sal_Int32 BasicInteractionHandler::getContinuation(Continuation _eCont, const Sequence< Reference< XInteractionContinuation > >& _rContinuations) { const Reference< XInteractionContinuation >* pContinuations = _rContinuations.getConstArray(); for (sal_Int32 i=0; i<_rContinuations.getLength(); ++i, ++pContinuations) @@ -405,6 +414,15 @@ namespace dbaui return -1; } + //========================================================================== + //= SQLExceptionInteractionHandler + //========================================================================== + IMPLEMENT_SERVICE_INFO1_STATIC( SQLExceptionInteractionHandler, "com.sun.star.comp.dbaccess.DatabaseInteractionHandler", "com.sun.star.sdb.DatabaseInteractionHandler" ); + + //========================================================================== + //= LegacyInteractionHandler + //========================================================================== + IMPLEMENT_SERVICE_INFO1_STATIC( LegacyInteractionHandler, "com.sun.star.comp.dbaccess.LegacyInteractionHandler", "com.sun.star.sdb.InteractionHandler" ); //......................................................................... } // namespace dbaui diff --git a/dbaccess/source/ui/uno/dbinteraction.hxx b/dbaccess/source/ui/uno/dbinteraction.hxx index 3944672e2..847fc7859 100644 --- a/dbaccess/source/ui/uno/dbinteraction.hxx +++ b/dbaccess/source/ui/uno/dbinteraction.hxx @@ -32,30 +32,17 @@ #include <cppuhelper/implbase2.hxx> #endif -#ifndef _DBAUI_MODULE_DBU_HXX_ #include "moduledbu.hxx" -#endif -#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include "apitools.hxx" + +/** === begin UNO includes === **/ #include <com/sun/star/lang/XServiceInfo.hpp> -#endif -#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_ -#include <com/sun/star/task/XInteractionHandler.hpp> -#endif -#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/task/XInteractionHandler2.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> -#endif -#ifndef _COM_SUN_STAR_UCB_AUTHENTICATIONREQUEST_HPP_ #include <com/sun/star/ucb/AuthenticationRequest.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_PARAMETERSREQUEST_HPP_ #include <com/sun/star/sdb/ParametersRequest.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_DOCUMENTSAVEREQUEST_HPP_ #include <com/sun/star/sdb/DocumentSaveRequest.hpp> -#endif -#ifndef _DBASHARED_APITOOLS_HXX_ -#include "apitools.hxx" -#endif +/** === end UNO includes === **/ namespace dbtools { @@ -68,11 +55,11 @@ namespace dbaui //......................................................................... //========================================================================= - //= OInteractionHandler + //= BasicInteractionHandler //========================================================================= typedef ::cppu::WeakImplHelper2 < ::com::sun::star::lang::XServiceInfo - , ::com::sun::star::task::XInteractionHandler - > OInteractionHandler_Base; + , ::com::sun::star::task::XInteractionHandler2 + > BasicInteractionHandler_Base; /** implements an <type scope="com.sun.star.task">XInteractionHandler</type> for database related interaction requests. <p/> @@ -84,22 +71,30 @@ namespace dbaui standard error dialog for the (maybe chained) exception given</li> </ul> */ - class OInteractionHandler - :public OInteractionHandler_Base + class BasicInteractionHandler + :public BasicInteractionHandler_Base { - OModuleClient m_aModuleClient; - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > - m_xORB; + const OModuleClient m_aModuleClient; + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + m_xORB; + const bool m_bFallbackToGeneric; + public: - OInteractionHandler(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB); + BasicInteractionHandler( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB, + const bool i_bFallbackToGeneric + ); - // XServiceInfo - DECLARE_SERVICE_INFO_STATIC(); + // XInteractionHandler2 + virtual ::sal_Bool SAL_CALL handleInteractionRequest( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& Request ) throw (::com::sun::star::uno::RuntimeException); - // XInteractionHandler + // XInteractionHandler virtual void SAL_CALL handle( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& Request ) throw(::com::sun::star::uno::RuntimeException); protected: + sal_Bool + impl_handle_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& i_Request ); + /// handle SQLExceptions (and derived classes) void implHandle( const ::dbtools::SQLExceptionInfo& _rSqlInfo, @@ -138,6 +133,53 @@ namespace dbaui const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& _rContinuations); }; + //========================================================================= + //= SQLExceptionInteractionHandler + //========================================================================= + class SQLExceptionInteractionHandler : public BasicInteractionHandler + { + public: + SQLExceptionInteractionHandler( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB + ) + :BasicInteractionHandler( i_rORB, false ) + { + } + + // XServiceInfo + DECLARE_SERVICE_INFO_STATIC(); + }; + + //========================================================================= + //= SQLExceptionInteractionHandler + //========================================================================= + /** an implementation for the legacy css.sdb.InteractionHandler + + css.sdb.InteractionHandler is deprecated, as it does not only handle database related interactions, + but also delegates all kind of unknown requests to a css.task.InteractionHandler. + + In today's architecture, there's only one central css.task.InteractionHandler, which is to be used + for all requests. Depending on configuration information, it decides which handler implementation + to delegate a request to. + + SQLExceptionInteractionHandler is the delegatee which handles only database related interactions. + LegacyInteractionHandler is the version which first checks for a database related interaction, and + forwards everything else to the css.task.InteractionHandler. + */ + class LegacyInteractionHandler : public BasicInteractionHandler + { + public: + LegacyInteractionHandler( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rORB + ) + :BasicInteractionHandler( i_rORB, true ) + { + } + + // XServiceInfo + DECLARE_SERVICE_INFO_STATIC(); + }; + //......................................................................... } // namespace dbaui //......................................................................... |