diff options
270 files changed, 10180 insertions, 5985 deletions
diff --git a/avmedia/source/gstreamer/gstframegrabber.cxx b/avmedia/source/gstreamer/gstframegrabber.cxx index bd55e11f8afe..49a6d9695fbc 100644 --- a/avmedia/source/gstreamer/gstframegrabber.cxx +++ b/avmedia/source/gstreamer/gstframegrabber.cxx @@ -31,6 +31,9 @@ #include <vcl/graph.hxx> #include <vcl/bmpacc.hxx> +#include <string> + + using namespace ::com::sun::star; namespace avmedia { namespace gst { diff --git a/avmedia/source/gstreamer/gstplayer.cxx b/avmedia/source/gstreamer/gstplayer.cxx index f082cfc5c513..614ff80ce352 100644 --- a/avmedia/source/gstreamer/gstplayer.cxx +++ b/avmedia/source/gstreamer/gstplayer.cxx @@ -66,6 +66,92 @@ struct GstBusSource : public GSource {} }; + +// ----------------------------------------------------------------------- +extern "C" +{ + +static gpointer +lcl_implThreadFunc( gpointer pData ) +{ + return( pData ? static_cast< Player* >( pData )->run() : NULL ); +} + +static gboolean +lcl_implBusCheck( GSource* pSource ) +{ + GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); + + return( pBusSource && + GST_IS_BUS( pBusSource->mpBus ) && + gst_bus_have_pending( GST_BUS_CAST( pBusSource->mpBus ) ) ); +} + + +static gboolean +lcl_implBusPrepare( GSource* pSource, gint* pTimeout ) +{ + if (pTimeout) + { + *pTimeout = 0; + } + + return lcl_implBusCheck(pSource); +} + +static gboolean +lcl_implBusDispatch( GSource* pSource, + GSourceFunc /*aCallback*/, + gpointer pData ) +{ + GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); + gboolean bRet = false; + + if( pData && pBusSource && GST_IS_BUS( pBusSource->mpBus ) ) + { + GstMessage* pMsg = gst_bus_pop( pBusSource->mpBus ); + + if( pMsg ) + { + bRet = static_cast< Player* >( pData )->busCallback( + pBusSource->mpBus, pMsg ); + gst_message_unref( pMsg ); + } + } + + return( bRet ); +} + +static void +lcl_implBusFinalize( GSource* pSource ) +{ + GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); + + if( pBusSource && pBusSource->mpBus ) + { + gst_object_unref( pBusSource->mpBus ); + pBusSource->mpBus = NULL; + } +} + +static gboolean +lcl_implIdleFunc( gpointer pData ) +{ + return( pData ? static_cast< Player* >( pData )->idle() : true ); +} + +static GstBusSyncReply +lcl_implHandleCreateWindowFunc( GstBus* pBus, GstMessage* pMsg, gpointer pData ) +{ + return (pData) + ? static_cast< Player* >( pData )->handleCreateWindow( pBus, pMsg ) + : GST_BUS_PASS; +} + +} // extern "C" + + + // --------------- // - Player - // --------------- @@ -102,7 +188,7 @@ Player::Player( GString* pURI ) : OSL_TRACE( ">>> --------------------------------" ); OSL_TRACE( ">>> Creating Player object with URL: %s", pURI->str ); - mpThread = g_thread_create( Player::implThreadFunc, this, true, NULL ); + mpThread = g_thread_create( &lcl_implThreadFunc, this, true, NULL ); } } @@ -329,10 +415,14 @@ double SAL_CALL Player::getRate() void SAL_CALL Player::setPlaybackLoop( sal_Bool bSet ) throw( uno::RuntimeException ) { - if( bSet && !isPlaybackLoop() ) - g_atomic_int_inc( &mnLooping ); - else if( !bSet && isPlaybackLoop() ) - g_atomic_int_dec_and_test( &mnLooping ); + if (bSet) + { + g_atomic_int_compare_and_exchange(&mnLooping, 0, 1); + } + else + { + g_atomic_int_compare_and_exchange(&mnLooping, 1, 0); + } } // ------------------------------------------------------------------------------ @@ -573,62 +663,6 @@ bool Player::implInitPlayer() } // ------------------------------------------------------------------------------ -gboolean Player::implBusPrepare( GSource* pSource, - gint* pTimeout ) -{ - if( pTimeout ) - { - *pTimeout = 0; - } - - return( implBusCheck( pSource ) ); -} - -// ------------------------------------------------------------------------------ -gboolean Player::implBusCheck( GSource* pSource ) -{ - GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); - - return( pBusSource && - GST_IS_BUS( pBusSource->mpBus ) && - gst_bus_have_pending( GST_BUS_CAST( pBusSource->mpBus ) ) ); -} - -// ------------------------------------------------------------------------------ -gboolean Player::implBusDispatch( GSource* pSource, - GSourceFunc /*aCallback*/, - gpointer pData ) -{ - GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); - gboolean bRet = false; - - if( pData && pBusSource && GST_IS_BUS( pBusSource->mpBus ) ) - { - GstMessage* pMsg = gst_bus_pop( pBusSource->mpBus ); - - if( pMsg ) - { - bRet = static_cast< Player* >( pData )->busCallback( pBusSource->mpBus, pMsg ); - gst_message_unref( pMsg ); - } - } - - return( bRet ); -} - -// ------------------------------------------------------------------------------ -void Player::implBusFinalize( GSource* pSource ) -{ - GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); - - if( pBusSource && pBusSource->mpBus ) - { - gst_object_unref( pBusSource->mpBus ); - pBusSource->mpBus = NULL; - } -} - -// ------------------------------------------------------------------------------ gboolean Player::busCallback( GstBus* /*pBus*/, GstMessage* pMsg ) { @@ -674,26 +708,6 @@ gboolean Player::busCallback( GstBus* /*pBus*/, } // ------------------------------------------------------------------------------ -gboolean Player::implIdleFunc( gpointer pData ) -{ - return( pData ? static_cast< Player* >( pData )->idle() : true ); -} - -// ------------------------------------------------------------------------------ -gpointer Player::implThreadFunc( gpointer pData ) -{ - return( pData ? static_cast< Player* >( pData )->run() : NULL ); -} - -// ------------------------------------------------------------------------------ -GstBusSyncReply Player::implHandleCreateWindowFunc( GstBus* pBus, - GstMessage* pMsg, - gpointer pData ) -{ - return( pData ? static_cast< Player* >( pData )->handleCreateWindow( pBus, pMsg ) : GST_BUS_PASS ); -} - -// ------------------------------------------------------------------------------ void Player::implHandleNewElementFunc( GstBin* /* pBin */, GstElement* pElement, gpointer pData ) @@ -800,16 +814,12 @@ void Player::implHandleNewPadFunc( GstElement* pElement, // ------------------------------------------------------------------------------ gboolean Player::idle() { - // test if main loop should quit and set flag mnQuit to 1 - bool bQuit = g_atomic_int_compare_and_exchange( &mnQuit, 1, 1 ); + // test if main loop should quit by comparing with 1 + // and set flag mnQuit to 0 so we call g_main_loop_quit exactly once + bool const bQuit = g_atomic_int_compare_and_exchange( &mnQuit, 1, 0 ); if( bQuit ) { - // set mnQuit back to 0 to avoid mutiple g_main_loop_quit calls - // in case Player::idle() is called again later; - // the flag should have been set only once within Ctor called from - // the application thread - g_atomic_int_dec_and_test( &mnQuit ); g_main_loop_quit( mpLoop ); } @@ -824,10 +834,10 @@ gpointer Player::run() { static GSourceFuncs aSourceFuncs = { - Player::implBusPrepare, - Player::implBusCheck, - Player::implBusDispatch, - Player::implBusFinalize, + &lcl_implBusPrepare, + &lcl_implBusCheck, + &lcl_implBusDispatch, + &lcl_implBusFinalize, NULL, NULL }; @@ -842,7 +852,7 @@ gpointer Player::run() // add idle callback GSource* pIdleSource = g_idle_source_new(); - g_source_set_callback( pIdleSource, Player::implIdleFunc, this, NULL ); + g_source_set_callback( pIdleSource, &lcl_implIdleFunc, this, NULL ); g_source_attach( pIdleSource, mpContext ); // add bus callback @@ -853,7 +863,7 @@ gpointer Player::run() // add bus sync handler to intercept video window creation for setting our own window gst_bus_set_sync_handler( static_cast< GstBusSource* >( pBusSource )->mpBus, - Player::implHandleCreateWindowFunc, this ); + &lcl_implHandleCreateWindowFunc, this ); // watch for all elements (and pads) that will be added to the playbin, // in order to retrieve properties like video width and height diff --git a/avmedia/source/gstreamer/gstplayer.hxx b/avmedia/source/gstreamer/gstplayer.hxx index d751e381258d..0793eaf8caf2 100644 --- a/avmedia/source/gstreamer/gstplayer.hxx +++ b/avmedia/source/gstreamer/gstplayer.hxx @@ -149,11 +149,7 @@ public: virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); - -protected: - - Player( GString* pURI = NULL ); - +// these are public because the C callbacks call them virtual gboolean busCallback( GstBus* pBus, GstMessage* pMsg ); @@ -164,6 +160,10 @@ protected: virtual GstBusSyncReply handleCreateWindow( GstBus* pBus, GstMessage* pMsg ); +protected: + + Player( GString* pURI = NULL ); + void implQuitThread(); bool implInitPlayer(); @@ -180,25 +180,6 @@ private: Player& operator=( const Player& ); - static gboolean implBusPrepare( GSource* pSource, - gint* pTimeout ); - - static gboolean implBusCheck( GSource* pSource ); - - static gboolean implBusDispatch( GSource* pSource, - GSourceFunc aCallback, - gpointer pData ); - - static void implBusFinalize( GSource* pSource ); - - static gboolean implIdleFunc( gpointer pData ); - - static gpointer implThreadFunc( gpointer pData ); - - static GstBusSyncReply implHandleCreateWindowFunc( GstBus* pBus, - GstMessage* pMsg, - gpointer pDData ); - static void implHandleNewElementFunc( GstBin* pBin, GstElement* pElement, gpointer pData ); diff --git a/avmedia/source/gstreamer/makefile.mk b/avmedia/source/gstreamer/makefile.mk index c648fcc77f89..857c5914b094 100644 --- a/avmedia/source/gstreamer/makefile.mk +++ b/avmedia/source/gstreamer/makefile.mk @@ -62,6 +62,8 @@ SHL1STDLIBS+=$(PKGCONFIG_LIBS) SHL1IMPLIB=i$(TARGET) SHL1LIBS=$(SLB)$/$(TARGET).lib SHL1DEF=$(MISC)$/$(SHL1TARGET).def +# on Solaris checkdll does not work: LD_LIBRARY_PATH breaks the 2 libxml2.so.2 +SHL1NOCHECK=t DEF1NAME=$(SHL1TARGET) DEF1EXPORTFILE=exports.dxp diff --git a/basic/inc/basic/sbxdef.hxx b/basic/inc/basic/sbxdef.hxx index 6dc9fe1d8d66..cc669fd03649 100644 --- a/basic/inc/basic/sbxdef.hxx +++ b/basic/inc/basic/sbxdef.hxx @@ -108,6 +108,7 @@ enum SbxDataType { const sal_uInt32 SBX_TYPE_WITH_EVENTS_FLAG = 0x10000; const sal_uInt32 SBX_TYPE_DIM_AS_NEW_FLAG = 0x20000; const sal_uInt32 SBX_FIXED_LEN_STRING_FLAG = 0x10000; // same value as above as no conflict possible +const sal_uInt32 SBX_TYPE_VAR_TO_DIM_FLAG = 0x40000; #endif @@ -320,6 +321,8 @@ enum SbxError { // Ergebnis einer Rechenoperation/Konversion #define SBX_WITH_EVENTS 0x0080 // Same value as unused SBX_HIDDEN #define SBX_DIM_AS_NEW 0x0800 // Same value as SBX_GBLSEARCH, cannot conflict as one // is used for objects, the other for variables only +#define SBX_VAR_TO_DIM 0x2000 // Same value as SBX_NO_BROADCAST, cannot conflict as + // used for variables without broadcaster only // Broadcaster-IDs: #define SBX_HINT_DYING SFX_HINT_DYING diff --git a/basic/inc/basic/vbahelper.hxx b/basic/inc/basic/vbahelper.hxx index 0d99387965fe..f83548f7e02c 100755..100644 --- a/basic/inc/basic/vbahelper.hxx +++ b/basic/inc/basic/vbahelper.hxx @@ -28,7 +28,9 @@ #ifndef BASIC_VBAHELPR_HXX #define BASIC_VBAHELPR_HXX +#include <com/sun/star/container/XEnumeration.hpp> #include <com/sun/star/frame/XModel.hpp> +#include <rtl/ustring.hxx> namespace basic { namespace vba { @@ -39,6 +41,21 @@ namespace vba { // ============================================================================ +/** Creates and returns an enumeration of all open documents of the same type + as the specified document. + + First, the global module manager (com.sun.star.frame.ModuleManager) is + asked for the type of the passed model, and all open documents with the + same type will be stored in an enumeration object. + + @param rxModel + A document model determining the type of the documents. + */ +::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > createDocumentsEnumeration( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel ); + +// ============================================================================ + /** Locks or unlocks the controllers of all documents that have the same type as the specified document. @@ -80,6 +97,38 @@ void enableContainerWindowsOfAllDocuments( // ============================================================================ +/** Registers the passed path as working directory for the application the + passed document belongs to. + + @param rxModel + A document model determining the type of the application whose working + directory has been changed. + + @param rPath + The new working directory. + */ +void registerCurrentDirectory( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel, + const ::rtl::OUString& rPath ); + +// ============================================================================ + +/** Returns the working directory of the application the passed document + belongs to. + + @param rxModel + A document model determining the type of the application whose working + directory is querried. + + @return + The working directory of the specified application, or an empty string + on error (e.g. if the passed document reference is empty). + */ +::rtl::OUString getCurrentDirectory( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel ); + +// ============================================================================ + } // namespace vba } // namespace basic diff --git a/basic/source/basmgr/vbahelper.cxx b/basic/source/basmgr/vbahelper.cxx index a09446f2e40b..0e9338b52c5e 100755..100644 --- a/basic/source/basmgr/vbahelper.cxx +++ b/basic/source/basmgr/vbahelper.cxx @@ -28,13 +28,18 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_basic.hxx" -#include "basic/vbahelper.hxx" +#include <basic/vbahelper.hxx> + +#include <map> +#include <vector> #include <com/sun/star/container/XEnumeration.hpp> #include <com/sun/star/frame/XDesktop.hpp> #include <com/sun/star/frame/XModel2.hpp> #include <com/sun/star/frame/XModuleManager.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <comphelper/processfactory.hxx> +#include <cppuhelper/implbase1.hxx> +#include <rtl/instance.hxx> namespace basic { namespace vba { @@ -45,64 +50,71 @@ using namespace ::com::sun::star; namespace { -/** Creates the global module manager needed to identify the type of documents. +/** Create an instance of a module manager. */ uno::Reference< frame::XModuleManager > lclCreateModuleManager() { uno::Reference< frame::XModuleManager > xModuleManager; try { - uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); + uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); xModuleManager.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ), uno::UNO_QUERY ); } catch( uno::Exception& ) { } - OSL_ENSURE( xModuleManager.is(), "::basic::vba::lclCreateModuleManager - cannot create module manager" ); return xModuleManager; } // ---------------------------------------------------------------------------- -/** Returns the document service name of the specified document. +/** Implementation of an enumeration of all open documents of the same type. */ -::rtl::OUString lclIdentifyDocument( const uno::Reference< frame::XModuleManager >& rxModuleManager, const uno::Reference< frame::XModel >& rxModel ) +class DocumentsEnumeration : public ::cppu::WeakImplHelper1< container::XEnumeration > { - ::rtl::OUString aServiceName; - if( rxModuleManager.is() ) - { - try - { - aServiceName = rxModuleManager->identify( rxModel ); - } - catch( uno::Exception& ) - { - } - OSL_ENSURE( aServiceName.getLength() > 0, "::basic::vba::lclIdentifyDocument - cannot identify document" ); - } - return aServiceName; -} - -// ---------------------------------------------------------------------------- +public: + DocumentsEnumeration( const uno::Reference< frame::XModel >& rxModel ); + virtual sal_Bool SAL_CALL hasMoreElements() throw (uno::RuntimeException); + virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); +private: + typedef ::std::vector< uno::Reference< frame::XModel > > ModelVector; + ModelVector maModels; + ModelVector::iterator maModelIt; +}; -/** Returns an enumeration of all open documents. - */ -uno::Reference< container::XEnumeration > lclCreateDocumentEnumeration() +DocumentsEnumeration::DocumentsEnumeration( const uno::Reference< frame::XModel >& rxModel ) { - uno::Reference< container::XEnumeration > xEnumeration; try { - uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); + uno::Reference< frame::XModuleManager > xModuleManager( lclCreateModuleManager(), uno::UNO_SET_THROW ); + ::rtl::OUString aIdentifier = xModuleManager->identify( rxModel ); + uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); uno::Reference< frame::XDesktop > xDesktop( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ) ), uno::UNO_QUERY_THROW ); uno::Reference< container::XEnumerationAccess > xComponentsEA( xDesktop->getComponents(), uno::UNO_SET_THROW ); - xEnumeration = xComponentsEA->createEnumeration(); - + uno::Reference< container::XEnumeration > xEnumeration( xComponentsEA->createEnumeration(), uno::UNO_SET_THROW ); + while( xEnumeration->hasMoreElements() ) + { + uno::Reference< frame::XModel > xCurrModel( xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); + if( xModuleManager->identify( xCurrModel ) == aIdentifier ) + maModels.push_back( xCurrModel ); + } } catch( uno::Exception& ) { } - OSL_ENSURE( xEnumeration.is(), "::basic::vba::lclCreateDocumentEnumeration - cannot create enumeration of all documents" ); - return xEnumeration; + maModelIt = maModels.begin(); +} + +sal_Bool SAL_CALL DocumentsEnumeration::hasMoreElements() throw (uno::RuntimeException) +{ + return maModelIt != maModels.end(); +} + +uno::Any SAL_CALL DocumentsEnumeration::nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) +{ + if( maModelIt == maModels.end() ) + throw container::NoSuchElementException(); + return uno::Any( *maModelIt++ ); } // ---------------------------------------------------------------------------- @@ -163,37 +175,39 @@ typedef void (*ModifyDocumentFunc)( const uno::Reference< frame::XModel >&, sal_ */ void lclIterateDocuments( ModifyDocumentFunc pModifyDocumentFunc, const uno::Reference< frame::XModel >& rxModel, sal_Bool bModificator ) { - uno::Reference< frame::XModuleManager > xModuleManager = lclCreateModuleManager(); - uno::Reference< container::XEnumeration > xDocumentsEnum = lclCreateDocumentEnumeration(); - ::rtl::OUString aIdentifier = lclIdentifyDocument( xModuleManager, rxModel ); - if( xModuleManager.is() && xDocumentsEnum.is() && (aIdentifier.getLength() > 0) ) + uno::Reference< container::XEnumeration > xDocumentsEnum( new DocumentsEnumeration( rxModel ) ); + // iterate over all open documents + while( xDocumentsEnum->hasMoreElements() ) try { - // iterate over all open documents - while( xDocumentsEnum->hasMoreElements() ) - { - try - { - uno::Reference< frame::XModel > xCurrModel( xDocumentsEnum->nextElement(), uno::UNO_QUERY_THROW ); - ::rtl::OUString aCurrIdentifier = lclIdentifyDocument( xModuleManager, xCurrModel ); - if( aCurrIdentifier == aIdentifier ) - pModifyDocumentFunc( xCurrModel, bModificator ); - } - catch( uno::Exception& ) - { - } - } + uno::Reference< frame::XModel > xCurrModel( xDocumentsEnum->nextElement(), uno::UNO_QUERY_THROW ); + pModifyDocumentFunc( xCurrModel, bModificator ); } - else + catch( uno::Exception& ) { - // no module manager, no documents enumeration, no identifier -> at least process the passed document - pModifyDocumentFunc( rxModel, bModificator ); } } +// ---------------------------------------------------------------------------- + +struct CurrDirPool +{ + ::osl::Mutex maMutex; + ::std::map< ::rtl::OUString, ::rtl::OUString > maCurrDirs; +}; + +struct StaticCurrDirPool : public ::rtl::Static< CurrDirPool, StaticCurrDirPool > {}; + } // namespace // ============================================================================ +uno::Reference< container::XEnumeration > createDocumentsEnumeration( const uno::Reference< frame::XModel >& rxModel ) +{ + return new DocumentsEnumeration( rxModel ); +} + +// ============================================================================ + void lockControllersOfAllDocuments( const uno::Reference< frame::XModel >& rxModel, sal_Bool bLockControllers ) { lclIterateDocuments( &lclLockControllers, rxModel, bLockControllers ); @@ -208,5 +222,45 @@ void enableContainerWindowsOfAllDocuments( const uno::Reference< frame::XModel > // ============================================================================ +void registerCurrentDirectory( const uno::Reference< frame::XModel >& rxModel, const ::rtl::OUString& rPath ) +{ + if( rPath.getLength() > 0 ) + { + CurrDirPool& rPool = StaticCurrDirPool::get(); + ::osl::MutexGuard aGuard( rPool.maMutex ); + try + { + uno::Reference< frame::XModuleManager > xModuleManager( lclCreateModuleManager(), uno::UNO_SET_THROW ); + ::rtl::OUString aIdentifier = xModuleManager->identify( rxModel ); + if( aIdentifier.getLength() > 0 ) + rPool.maCurrDirs[ aIdentifier ] = rPath; + } + catch( uno::Exception& ) + { + } + } +} + +// ============================================================================ + +::rtl::OUString getCurrentDirectory( const uno::Reference< frame::XModel >& rxModel ) +{ + ::rtl::OUString aPath; + CurrDirPool& rPool = StaticCurrDirPool::get(); + ::osl::MutexGuard aGuard( rPool.maMutex ); + try + { + uno::Reference< frame::XModuleManager > xModuleManager( lclCreateModuleManager(), uno::UNO_SET_THROW ); + ::rtl::OUString aIdentifier = xModuleManager->identify( rxModel ); + aPath = rPool.maCurrDirs[ aIdentifier ]; + } + catch( uno::Exception& ) + { + } + return aPath; +} + +// ============================================================================ + } // namespace vba } // namespace basic diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx index f8ffa46d48a5..bf7b00e2a633 100644 --- a/basic/source/classes/sb.cxx +++ b/basic/source/classes/sb.cxx @@ -42,6 +42,7 @@ #include <tools/shl.hxx> #include <tools/rc.hxx> #include <vcl/svapp.hxx> +#include <comphelper/processfactory.hxx> #include "sbunoobj.hxx" #include "sbjsmeth.hxx" #include "sbjsmod.hxx" @@ -136,6 +137,7 @@ void DocBasicItem::startListening() Any aThisComp; mrDocBasic.GetUNOConstant( "ThisComponent", aThisComp ); Reference< util::XCloseBroadcaster > xCloseBC( aThisComp, UNO_QUERY ); + mbDisposed = !xCloseBC.is(); if( xCloseBC.is() ) try { xCloseBC->addCloseListener( this ); } catch( uno::Exception& ) {} } @@ -437,7 +439,20 @@ SbxObject* SbiFactory::CreateObject( const String& rClass ) return new BasicCollection( aCollectionName ); } else - return NULL; + if( rClass.EqualsIgnoreCaseAscii( "FileSystemObject" ) ) + { + try + { + Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW ); + ::rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.FileSystemObject" ) ); + Reference< XInterface > xInterface( xFactory->createInstance( aServiceName ), UNO_SET_THROW ); + return new SbUnoObject( aServiceName, uno::makeAny( xInterface ) ); + } + catch( Exception& ) + {} + } + + return NULL; } @@ -934,8 +949,14 @@ void StarBASIC::SetModified( sal_Bool b ) SbxBase::SetModified( b ); } +extern void lcl_closeTraceFile(); + StarBASIC::~StarBASIC() { +#ifdef DBG_TRACE_BASIC + lcl_closeTraceFile(); +#endif + // Needs to be first action as it can trigger events disposeComVariablesForBasic( this ); @@ -2273,7 +2294,22 @@ void BasicCollection::CollRemove( SbxArray* pPar_ ) SbxVariable* p = pPar_->Get( 1 ); sal_Int32 nIndex = implGetIndex( p ); if( nIndex >= 0 && nIndex < (sal_Int32)xItemArray->Count32() ) + { xItemArray->Remove32( nIndex ); + + // Correct for stack if necessary + SbiInstance* pInst = pINST; + SbiRuntime* pRT = pInst ? pInst->pRun : NULL; + if( pRT ) + { + SbiForStack* pStack = pRT->FindForStackItemForCollection( this ); + if( pStack != NULL ) + { + if( pStack->nCurCollectionIndex >= nIndex ) + --pStack->nCurCollectionIndex; + } + } + } else SetError( SbERR_BAD_ARGUMENT ); } diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 13ae406cb305..6f20a68a274f 100755 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -1722,8 +1722,7 @@ String getBasicObjectTypeName( SbxObject* pObj ) return aName; } -bool checkUnoObjectType( SbUnoObject* pUnoObj, - const String& aClass ) +bool checkUnoObjectType( SbUnoObject* pUnoObj, const ::rtl::OUString& rClass ) { Any aToInspectObj = pUnoObj->getUnoAny(); TypeClass eType = aToInspectObj.getValueType().getTypeClass(); @@ -1740,6 +1739,21 @@ bool checkUnoObjectType( SbUnoObject* pUnoObj, Reference< XTypeProvider > xTypeProvider( x, UNO_QUERY ); if( xTypeProvider.is() ) { + /* Although interfaces in the ooo.vba namespace obey the IDL rules and + have a leading 'X', in Basic we want to be able to do something + like 'Dim wb As Workbooks' or 'Dim lb As MSForms.Label'. Here we + add a leading 'X' to the class name and a leading dot to the entire + type name. This results e.g. in '.XWorkbooks' or '.MSForms.XLabel' + which matches the interface names 'ooo.vba.excel.XWorkbooks' or + 'ooo.vba.msforms.XLabel'. + */ + ::rtl::OUString aClassName( sal_Unicode( '.' ) ); + sal_Int32 nClassNameDot = rClass.lastIndexOf( '.' ); + if( nClassNameDot >= 0 ) + aClassName += rClass.copy( 0, nClassNameDot + 1 ) + ::rtl::OUString( sal_Unicode( 'X' ) ) + rClass.copy( nClassNameDot + 1 ); + else + aClassName += ::rtl::OUString( sal_Unicode( 'X' ) ) + rClass; + Sequence< Type > aTypeSeq = xTypeProvider->getTypes(); const Type* pTypeArray = aTypeSeq.getConstArray(); sal_uInt32 nIfaceCount = aTypeSeq.getLength(); @@ -1753,8 +1767,8 @@ bool checkUnoObjectType( SbUnoObject* pUnoObj, DBG_ERROR("failed to get XIdlClass for type"); break; } - ::rtl::OUString sClassName = xClass->getName(); - if ( sClassName.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.XAutomationObject" ) ) ) ) + ::rtl::OUString aInterfaceName = xClass->getName(); + if ( aInterfaceName.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.XAutomationObject" ) ) ) ) { // there is a hack in the extensions/source/ole/oleobj.cxx to return the typename of the automation object, lets check if it // matches @@ -1767,20 +1781,15 @@ bool checkUnoObjectType( SbUnoObject* pUnoObj, // can't check type, leave it pass result = true; else - result = sTypeName.equals( aClass ); + result = sTypeName.equals( rClass ); } break; // finished checking automation object } - OSL_TRACE("Checking if object implements %s", - OUStringToOString( defaultNameSpace + aClass, - RTL_TEXTENCODING_UTF8 ).getStr() ); - // although interfaces in the ooo.vba.vba namespace - // obey the idl rules and have a leading X, in basic we - // want to be able to do something like - // 'dim wrkbooks as WorkBooks' - // so test assumes the 'X' has been dropped - sal_Int32 indexLastDot = sClassName.lastIndexOf('.'); - if ( indexLastDot > -1 && sClassName.copy( indexLastDot + 1).equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("X") ) + aClass ) ) + + // match interface name with passed class name + OSL_TRACE("Checking if object implements %s", OUStringToOString( aClassName, RTL_TEXTENCODING_UTF8 ).getStr() ); + if ( (aClassName.getLength() < aInterfaceName.getLength()) && + aInterfaceName.matchIgnoreAsciiCase( aClassName, aInterfaceName.getLength() - aClassName.getLength() ) ) { result = true; break; diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index c722e680fd8c..24b031e8f4e9 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -61,6 +61,7 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/script/ModuleType.hpp> #include <com/sun/star/script/vba/XVBACompatibility.hpp> +#include <com/sun/star/script/vba/VBAScriptEventId.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/document/XEventBroadcaster.hpp> #include <com/sun/star/document/XEventListener.hpp> @@ -88,10 +89,8 @@ using namespace com::sun::star; #include <cppuhelper/implbase1.hxx> #include <basic/sbobjmod.hxx> #include <com/sun/star/uno/XAggregation.hpp> -#include <map> #include <com/sun/star/script/XInvocation.hpp> - using namespace ::com::sun::star; using namespace com::sun::star::lang; using namespace com::sun::star::reflection; using namespace com::sun::star::beans; @@ -107,6 +106,7 @@ using namespace com::sun::star::script; #include <cppuhelper/implbase1.hxx> #include <comphelper/anytostring.hxx> #include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/VbQueryClose.hpp> typedef ::cppu::WeakImplHelper1< XInvocation > DocObjectWrapper_BASE; typedef ::std::map< sal_Int16, Any, ::std::less< sal_Int16 > > OutParamMap; @@ -451,24 +451,36 @@ TYPEINIT1(SbUserFormModule,SbObjModule) typedef std::vector<HighlightPortion> HighlightPortions; -bool getDefaultVBAMode( StarBASIC* pb ) +uno::Reference< frame::XModel > getDocumentModel( StarBASIC* pb ) { - bool bResult = false; - if ( pb && pb->IsDocBasic() ) + uno::Reference< frame::XModel > xModel; + if( pb && pb->IsDocBasic() ) { uno::Any aDoc; - if ( pb->GetUNOConstant( "ThisComponent", aDoc ) ) - { - uno::Reference< beans::XPropertySet > xProp( aDoc, uno::UNO_QUERY ); - if ( xProp.is() ) - { - uno::Reference< script::vba::XVBACompatibility > xVBAMode( xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BasicLibraries") ) ), uno::UNO_QUERY ); - if ( xVBAMode.is() ) - bResult = xVBAMode->getVBACompatibilityMode() == sal_True; - } - } + if( pb->GetUNOConstant( "ThisComponent", aDoc ) ) + xModel.set( aDoc, uno::UNO_QUERY ); } - return bResult; + return xModel; +} + +uno::Reference< vba::XVBACompatibility > getVBACompatibility( const uno::Reference< frame::XModel >& rxModel ) +{ + uno::Reference< vba::XVBACompatibility > xVBACompat; + try + { + uno::Reference< beans::XPropertySet > xModelProps( rxModel, uno::UNO_QUERY_THROW ); + xVBACompat.set( xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ), uno::UNO_QUERY ); + } + catch( uno::Exception& ) + { + } + return xVBACompat; +} + +bool getDefaultVBAMode( StarBASIC* pb ) +{ + uno::Reference< vba::XVBACompatibility > xVBACompat = getVBACompatibility( getDocumentModel( pb ) ); + return xVBACompat.is() && xVBACompat->getVBACompatibilityMode(); } class AsyncQuitHandler @@ -501,20 +513,6 @@ IMPL_LINK( AsyncQuitHandler, OnAsyncQuit, void*, /*pNull*/ ) return 0L; } -void VBAUnlockDocuments( StarBASIC* pBasic ) -{ - if ( pBasic && pBasic->IsDocBasic() ) - { - SbUnoObject* pGlobs = dynamic_cast< SbUnoObject* >( pBasic->Find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ThisComponent" ) ), SbxCLASS_DONTCARE ) ); - if ( pGlobs ) - { - uno::Reference< frame::XModel > xModel( pGlobs->getUnoAny(), uno::UNO_QUERY ); - ::basic::vba::lockControllersOfAllDocuments( xModel, sal_False ); - ::basic::vba::enableContainerWindowsOfAllDocuments( xModel, sal_True ); - } - } -} - ///////////////////////////////////////////////////////////////////////////// // Ein BASIC-Modul hat EXTSEARCH gesetzt, damit die im Modul enthaltenen @@ -833,7 +831,7 @@ void SbModule::SetSource( const String& r ) void SbModule::SetSource32( const ::rtl::OUString& r ) { // Default basic mode to library container mode, but.. allow Option VBASupport 0/1 override - SetVBACompat( getDefaultVBAMode( static_cast< StarBASIC*>( GetParent() ) ) ); + SetVBACompat( getDefaultVBAMode( static_cast< StarBASIC*>( GetParent() ) ) ); aOUSource = r; StartDefinitions(); SbiTokenizer aTok( r ); @@ -1031,6 +1029,8 @@ sal_uInt16 SbModule::Run( SbMethod* pMeth ) sal_uInt16 nRes = 0; sal_Bool bDelInst = sal_Bool( pINST == NULL ); StarBASICRef xBasic; + uno::Reference< frame::XModel > xModel; + uno::Reference< script::vba::XVBACompatibility > xVBACompat; if( bDelInst ) { #ifdef DBG_TRACE_BASIC @@ -1041,6 +1041,23 @@ sal_uInt16 SbModule::Run( SbMethod* pMeth ) pINST = new SbiInstance( (StarBASIC*) GetParent() ); + /* If a VBA script in a document is started, get the VBA compatibility + interface from the document Basic library container, and notify all + VBA script listeners about the started script. */ + if( mbVBACompat ) + { + StarBASIC* pBasic = static_cast< StarBASIC* >( GetParent() ); + if( pBasic && pBasic->IsDocBasic() ) try + { + xModel.set( getDocumentModel( pBasic ), uno::UNO_SET_THROW ); + xVBACompat.set( getVBACompatibility( xModel ), uno::UNO_SET_THROW ); + xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::SCRIPT_STARTED, GetName() ); + } + catch( uno::Exception& ) + { + } + } + // Launcher problem // i80726 The Find below will genarate an error in Testtool so we reset it unless there was one before already sal_Bool bWasError = SbxBase::GetError() != 0; @@ -1183,9 +1200,20 @@ sal_uInt16 SbModule::Run( SbMethod* pMeth ) ResetCapturedAssertions(); #endif - // VBA always ensures screenupdating is enabled after completing - if ( mbVBACompat ) - VBAUnlockDocuments( PTR_CAST( StarBASIC, GetParent() ) ); + if( xVBACompat.is() ) + { + // notify all VBA script listeners about the stopped script + try + { + xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::SCRIPT_STOPPED, GetName() ); + } + catch( uno::Exception& ) + { + } + // VBA always ensures screenupdating is enabled after completing + ::basic::vba::lockControllersOfAllDocuments( xModel, sal_False ); + ::basic::vba::enableContainerWindowsOfAllDocuments( xModel, sal_True ); + } #ifdef DBG_TRACE_BASIC dbg_DeInitTrace(); @@ -2276,8 +2304,9 @@ public: uno::Reference< document::XVbaMethodParameter > xVbaMethodParameter( xControl->getPeer(), uno::UNO_QUERY ); if ( xVbaMethodParameter.is() ) { +#endif sal_Int8 nCancel = 0; - sal_Int8 nCloseMode = 0; + sal_Int8 nCloseMode = ::ooo::vba::VbQueryClose::vbFormControlMenu; Sequence< Any > aParams; aParams.realloc(2); @@ -2286,14 +2315,13 @@ public: mpUserForm->triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ), aParams); +#if IN_THE_FUTURE xVbaMethodParameter->setVbaMethodParameter( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Cancel")), aParams[0]); return; } } } - - mpUserForm->triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ) ); #endif } //liuchen 2009-7-21 @@ -2403,15 +2431,14 @@ void SbUserFormModule::triggerMethod( const String& aMethodToRun ) Sequence< Any > aArguments; triggerMethod( aMethodToRun, aArguments ); } -void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any >& /*aArguments*/) + +void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any >& aArguments ) { OSL_TRACE("*** trigger %s ***", rtl::OUStringToOString( aMethodToRun, RTL_TEXTENCODING_UTF8 ).getStr() ); // Search method SbxVariable* pMeth = SbObjModule::Find( aMethodToRun, SbxCLASS_METHOD ); if( pMeth ) { -#if IN_THE_FUTURE - //liuchen 2009-7-21, support Excel VBA UserForm_QueryClose event with parameters if ( aArguments.getLength() > 0 ) // Setup parameters { SbxArrayRef xArray = new SbxArray; @@ -2439,8 +2466,6 @@ void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any pMeth->SetParameters( NULL ); } else -//liuchen 2009-7-21 -#endif { SbxValues aVals; pMeth->Get( aVals ); @@ -2532,7 +2557,7 @@ void SbUserFormModule::Unload() OSL_TRACE("** Unload() "); sal_Int8 nCancel = 0; - sal_Int8 nCloseMode = 1; + sal_Int8 nCloseMode = ::ooo::vba::VbQueryClose::vbFormCode; Sequence< Any > aParams; aParams.realloc(2); @@ -2542,7 +2567,7 @@ void SbUserFormModule::Unload() triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ), aParams); aParams[0] >>= nCancel; - if (nCancel == 1) + if (nCancel != 0) // Basic returns -1 for "True" { return; } @@ -2585,6 +2610,9 @@ void SbUserFormModule::InitObject() SbUnoObject* pGlobs = (SbUnoObject*)GetParent()->Find( aHook, SbxCLASS_DONTCARE ); if ( m_xModel.is() && pGlobs ) { + // broadcast INITIALIZE_USERFORM script event before the dialog is created + Reference< script::vba::XVBACompatibility > xVBACompat( getVBACompatibility( m_xModel ), uno::UNO_SET_THROW ); + xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::INITIALIZE_USERFORM, GetName() ); uno::Reference< lang::XMultiServiceFactory > xVBAFactory( pGlobs->getUnoAny(), uno::UNO_QUERY_THROW ); uno::Reference< lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); diff --git a/basic/source/comp/codegen.cxx b/basic/source/comp/codegen.cxx index a8c7e3f5330f..f59edfbb12e9 100644 --- a/basic/source/comp/codegen.cxx +++ b/basic/source/comp/codegen.cxx @@ -303,6 +303,8 @@ void SbiCodeGen::Save() nUserData |= nDefaultId; if( pPar->IsParamArray() ) nUserData |= PARAM_INFO_PARAMARRAY; + if( pPar->IsWithBrackets() ) + nUserData |= PARAM_INFO_WITHBRACKETS; if( nUserData ) { SbxParamInfo* pParam = (SbxParamInfo*)pInfo->GetParam( i ); diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx index 1ba8982404e4..03c4845569a7 100644 --- a/basic/source/comp/dim.cxx +++ b/basic/source/comp/dim.cxx @@ -51,7 +51,11 @@ SbiSymDef* SbiParser::VarDecl( SbiDimList** ppDim, sal_Bool bStatic, sal_Bool bC SbiDimList* pDim = NULL; // Klammern? if( Peek() == LPAREN ) + { pDim = new SbiDimList( this ); + if( !pDim->GetDims() ) + pDef->SetWithBrackets(); + } pDef->SetType( t ); if( bStatic ) pDef->SetStatic(); @@ -382,6 +386,9 @@ void SbiParser::DefVar( SbiOpcode eOp, sal_Bool bStatic ) if( nFixedStringLength >= 0 ) nOpnd2 |= (SBX_FIXED_LEN_STRING_FLAG + (sal_uInt32(nFixedStringLength) << 17)); // len = all bits above 0x10000 + if( pDim != NULL && pDim->GetDims() > 0 ) + nOpnd2 |= SBX_TYPE_VAR_TO_DIM_FLAG; + aGen.Gen( eOp2, pDef->GetId(), nOpnd2 ); } diff --git a/basic/source/comp/makefile.mk b/basic/source/comp/makefile.mk index d65f6a431e43..1e17b35cde61 100644 --- a/basic/source/comp/makefile.mk +++ b/basic/source/comp/makefile.mk @@ -53,7 +53,8 @@ EXCEPTIONSFILES= \ $(SLO)$/codegen.obj \ $(SLO)$/dim.obj \ $(SLO)$/exprtree.obj \ - $(SLO)$/parser.obj + $(SLO)$/parser.obj \ + $(SLO)$/sbcomp.obj # --- Targets -------------------------------------------------------------- diff --git a/basic/source/comp/sbcomp.cxx b/basic/source/comp/sbcomp.cxx index 12e368d1c7eb..1b3395b70526 100755 --- a/basic/source/comp/sbcomp.cxx +++ b/basic/source/comp/sbcomp.cxx @@ -33,7 +33,7 @@ #include "image.hxx" #include "sbtrace.hxx" #include <basic/sbobjmod.hxx> - +#include <stdio.h> //========================================================================== // Tracing, for debugging only @@ -44,12 +44,13 @@ #include <hash_map> // Trace ini file (set NULL to ignore) -static char GpTraceIniFile[] = "d:\\zBasic.Asm\\BasicTrace.ini"; +// can be overridden with the environment variable OOO_BASICTRACEINI +static char GpTraceIniFile[] = "~/BasicTrace.ini"; //static char* GpTraceIniFile = NULL; // Trace Settings, used if no ini file / not found in ini file -static char GpTraceFileNameDefault[] = "d:\\zBasic.Asm\\BasicTrace.txt"; +static char GpTraceFileNameDefault[] = "~/BasicTrace.txt"; static char* GpTraceFileName = GpTraceFileNameDefault; // GbTraceOn: @@ -63,6 +64,12 @@ static bool GbTraceOn = true; // with TraceCommand( "PCodeOn" / "PCodeOff" ), see below static bool GbIncludePCodes = false; +// GbInitOnlyAtOfficeStart: +// true = Tracing is only intialized onces after Office start when +// Basic runs the first time. Further calls to Basic, e.g. via events +// use the same output file. The trace ini file is not read again. +static bool GbInitOnlyAtOfficeStart = false; + static int GnIndentPerCallLevel = 4; static int GnIndentForPCode = 2; @@ -84,6 +91,37 @@ static int GnIndentForPCode = 2; long as it can be converted to string */ +#ifdef DBG_TRACE_PROFILING + +#include <algorithm> +#include <stack> +#include "canvas/elapsedtime.hxx" + +//*** Profiling *** +// GbTimerOn: +// true = including time stamps +static bool GbTimerOn = true; + +// GbTimeStampForEachStep: +// true = prints time stamp after each command / pcode (very slow) +static bool GbTimeStampForEachStep = false; + +// GbBlockAllAfterFirstFunctionUsage: +// true = everything (commands, pcodes, functions) is only printed +// for the first usage (improves performance when tracing / pro- +// filing large macros) +static bool GbBlockAllAfterFirstFunctionUsage = false; + +// GbBlockStepsAfterFirstFunctionUsage: +// true = commands / pcodes are only printed for the first time +// a function is executed. Afterwards only the entering/leaving +// messages are logged (improves performance when tracing / pro- +// filing large macros) +static bool GbBlockStepsAfterFirstFunctionUsage = false; + +#endif + + static void lcl_skipWhites( char*& rpc ) { while( *rpc == ' ' || *rpc == '\t' ) @@ -174,11 +212,28 @@ static void lcl_ReadIniFile( const char* pIniFileName ) if( strcmp( VarNameBuffer, "GbIncludePCodes") == 0 ) GbIncludePCodes = (strcmp( ValBuffer, "true" ) == 0); else + if( strcmp( VarNameBuffer, "GbInitOnlyAtOfficeStart") == 0 ) + GbInitOnlyAtOfficeStart = (strcmp( ValBuffer, "true" ) == 0); + else if( strcmp( VarNameBuffer, "GnIndentPerCallLevel") == 0 ) GnIndentPerCallLevel = strtol( ValBuffer, NULL, 10 ); else if( strcmp( VarNameBuffer, "GnIndentForPCode") == 0 ) GnIndentForPCode = strtol( ValBuffer, NULL, 10 ); +#ifdef DBG_TRACE_PROFILING + else + if( strcmp( VarNameBuffer, "GbTimerOn") == 0 ) + GbTimerOn = (strcmp( ValBuffer, "true" ) == 0); + else + if( strcmp( VarNameBuffer, "GbTimeStampForEachStep") == 0 ) + GbTimeStampForEachStep = (strcmp( ValBuffer, "true" ) == 0); + else + if( strcmp( VarNameBuffer, "GbBlockAllAfterFirstFunctionUsage") == 0 ) + GbBlockAllAfterFirstFunctionUsage = (strcmp( ValBuffer, "true" ) == 0); + else + if( strcmp( VarNameBuffer, "GbBlockStepsAfterFirstFunctionUsage") == 0 ) + GbBlockStepsAfterFirstFunctionUsage = (strcmp( ValBuffer, "true" ) == 0); +#endif } fclose( pFile ); } @@ -209,14 +264,14 @@ static void lcl_PrepareTraceForModule( SbModule* pModule ) pModule->Disassemble( aDisassemblyStr ); } -static void lcl_lineOut( const char* pFileName, const char* pStr, const char* pPreStr = NULL ) +static FILE* GpGlobalFile = NULL; + +static void lcl_lineOut( const char* pStr, const char* pPreStr = NULL, const char* pPostStr = NULL ) { - const char* pPrintFirst = (pPreStr != NULL) ? pPreStr : ""; - FILE* pFile = fopen( pFileName, "a+" ); - if( pFile != NULL ) + if( GpGlobalFile != NULL ) { - fprintf( pFile, "%s%s\n", pPrintFirst, pStr ); - fclose( pFile ); + fprintf( GpGlobalFile, "%s%s%s\n", pPreStr ? pPreStr : "", pStr, pPostStr ? pPostStr : "" ); + fflush( GpGlobalFile ); } } @@ -304,32 +359,198 @@ String lcl_dumpMethodParameters( SbMethod* pMethod ) // Public functions - static bool GbSavTraceOn = false; + +#ifdef DBG_TRACE_PROFILING +static canvas::tools::ElapsedTime* GpTimer = NULL; +static double GdStartTime = 0.0; +static double GdLastTime = 0.0; +static bool GbBlockSteps = false; +static bool GbBlockAll = false; + +struct FunctionItem +{ + String m_aCompleteFunctionName; + double m_dTotalTime; + double m_dNetTime; + int m_nCallCount; + bool m_bBlockAll; + bool m_bBlockSteps; + + FunctionItem( void ) + : m_dTotalTime( 0.0 ) + , m_dNetTime( 0.0 ) + , m_nCallCount( 0 ) + , m_bBlockAll( false ) + , m_bBlockSteps( false ) + {} +}; +typedef std::hash_map< ::rtl::OUString, FunctionItem*, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > FunctionItemMap; + +static std::stack< double > GaCallEnterTimeStack; +static std::stack< FunctionItem* > GaFunctionItemStack; +static FunctionItemMap GaFunctionItemMap; + +bool compareFunctionNetTime( FunctionItem* p1, FunctionItem* p2 ) +{ + return (p1->m_dNetTime > p2->m_dNetTime); +} + +void lcl_printTimeOutput( void ) +{ + // Overall time output + lcl_lineOut( "" ); + lcl_lineOut( "***** Time Output *****" ); + char TimeBuffer[500]; + double dTotalTime = GpTimer->getElapsedTime() - GdStartTime; + sprintf( TimeBuffer, "Total execution time = %f ms", dTotalTime*1000.0 ); + lcl_lineOut( TimeBuffer ); + lcl_lineOut( "" ); + + if( GbTimerOn ) + { + lcl_lineOut( "Functions:" ); + + std::vector<FunctionItem*> avFunctionItems; + + FunctionItemMap::iterator it; + for( it = GaFunctionItemMap.begin() ; it != GaFunctionItemMap.end() ; ++it ) + { + FunctionItem* pFunctionItem = it->second; + if( pFunctionItem != NULL ) + avFunctionItems.push_back( pFunctionItem ); + } + + std::sort( avFunctionItems.begin(), avFunctionItems.end(), compareFunctionNetTime ); + + std::vector<FunctionItem*>::iterator itv; + for( itv = avFunctionItems.begin() ; itv != avFunctionItems.end() ; ++itv ) + { + FunctionItem* pFunctionItem = *itv; + if( pFunctionItem != NULL ) + { + rtl::OUString aCompleteFunctionName = pFunctionItem->m_aCompleteFunctionName; + const char* pName = OUStringToOString( aCompleteFunctionName, RTL_TEXTENCODING_ASCII_US ).getStr(); + int nNameLen = aCompleteFunctionName.getLength(); + + double dFctTotalTime = pFunctionItem->m_dTotalTime; + double dFctNetTime = pFunctionItem->m_dNetTime; + double dFctTotalTimePercent = 100.0 * dFctTotalTime / dTotalTime; + double dFctNetTimePercent = 100.0 * dFctNetTime / dTotalTime; + int nSpaceCount = 30 - nNameLen; + if( nSpaceCount < 0 ) + nSpaceCount = 2; + sprintf( TimeBuffer, "%s:%sCalled %d times\t%f ms (%f%%) / net %f (%f%%) ms", + pName, lcl_getSpaces( nSpaceCount ), pFunctionItem->m_nCallCount, + dFctTotalTime*1000.0, dFctTotalTimePercent, dFctNetTime*1000.0, dFctNetTimePercent ); + lcl_lineOut( TimeBuffer ); + } + } + } +} +#endif + + +static bool GbInitTraceAlreadyCalled = false; + void dbg_InitTrace( void ) { - if( GpTraceIniFile != NULL ) + if( GbInitOnlyAtOfficeStart && GbInitTraceAlreadyCalled ) + { +#ifdef DBG_TRACE_PROFILING + if( GbTimerOn ) + GpTimer->continueTimer(); +#endif + GpGlobalFile = fopen( GpTraceFileName, "a+" ); + return; + } + GbInitTraceAlreadyCalled = true; + + if( const sal_Char* pcIniFileName = ::getenv( "OOO_BASICTRACEINI" ) ) + lcl_ReadIniFile( pcIniFileName ); + else if( GpTraceIniFile != NULL ) lcl_ReadIniFile( GpTraceIniFile ); - FILE* pFile = fopen( GpTraceFileName, "w" ); - if( pFile != NULL ) - fclose( pFile ); + GpGlobalFile = fopen( GpTraceFileName, "w" ); GbSavTraceOn = GbTraceOn; if( !GbTraceOn ) - lcl_lineOut( GpTraceFileName, "### Program started with trace off ###" ); + lcl_lineOut( "### Program started with trace off ###" ); + +#ifdef DBG_TRACE_PROFILING + GpTimer = new canvas::tools::ElapsedTime(); + GdStartTime = GpTimer->getElapsedTime(); + GdLastTime = GdStartTime; + GbBlockSteps = false; + GbBlockAll = false; +#endif } void dbg_DeInitTrace( void ) { GbTraceOn = GbSavTraceOn; + +#ifdef DBG_TRACE_PROFILING + while( !GaCallEnterTimeStack.empty() ) + GaCallEnterTimeStack.pop(); + while( !GaFunctionItemStack.empty() ) + GaFunctionItemStack.pop(); + + lcl_printTimeOutput(); + + for( FunctionItemMap::iterator it = GaFunctionItemMap.begin() ; it != GaFunctionItemMap.end() ; ++it ) + delete it->second; + GaFunctionItemMap.clear(); + + if( GpGlobalFile ) + { + fclose( GpGlobalFile ); + GpGlobalFile = NULL; + } + + if( GbInitOnlyAtOfficeStart ) + { + if( GbTimerOn ) + GpTimer->pauseTimer(); + } + else + { + delete GpTimer; + } +#endif } static sal_Int32 GnLastCallLvl = 0; +void dbg_tracePrint( const String& aStr, sal_Int32 nCallLvl, bool bCallLvlRelativeToCurrent ) +{ + if( bCallLvlRelativeToCurrent ) + nCallLvl += GnLastCallLvl; + + int nIndent = nCallLvl * GnIndentPerCallLevel; + lcl_lineOut( OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US ).getStr(), lcl_getSpaces( nIndent ) ); +} + void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) { if( !GbTraceOn ) return; + +#ifdef DBG_TRACE_PROFILING + if( GbBlockSteps || GbBlockAll ) + return; + + double dCurTime = 0.0; + bool bPrintTimeStamp = false; + if( GbTimerOn ) + { + GpTimer->pauseTimer(); + dCurTime = GpTimer->getElapsedTime(); + bPrintTimeStamp = GbTimeStampForEachStep; + } +#else + bool bPrintTimeStamp = false; +#endif + GnLastCallLvl = nCallLvl; SbModule* pTraceMod = pModule; @@ -346,14 +567,14 @@ void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) const char* pModuleNameStr = OUStringToOString( rtl::OUString( aModuleName ), RTL_TEXTENCODING_ASCII_US ).getStr(); char Buffer[200]; sprintf( Buffer, "TRACE ERROR: Unknown module \"%s\"", pModuleNameStr ); - lcl_lineOut( GpTraceFileName, Buffer ); + lcl_lineOut( Buffer ); return; } PCToTextDataMap* pInnerMap = it->second; if( pInnerMap == NULL ) { - lcl_lineOut( GpTraceFileName, "TRACE INTERNAL ERROR: No inner map" ); + lcl_lineOut( "TRACE INTERNAL ERROR: No inner map" ); return; } @@ -363,7 +584,7 @@ void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) const char* pModuleNameStr = OUStringToOString( rtl::OUString( aModuleName ), RTL_TEXTENCODING_ASCII_US ).getStr(); char Buffer[200]; sprintf( Buffer, "TRACE ERROR: No info for PC = %d in module \"%s\"", (int)nPC, pModuleNameStr ); - lcl_lineOut( GpTraceFileName, Buffer ); + lcl_lineOut( Buffer ); return; } @@ -371,24 +592,67 @@ void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) const TraceTextData& rTraceTextData = itInner->second; const rtl::OString& rStr_STMNT = rTraceTextData.m_aTraceStr_STMNT; + bool bSTMT = false; if( rStr_STMNT.getLength() ) - lcl_lineOut( GpTraceFileName, rStr_STMNT.getStr(), lcl_getSpaces( nIndent ) ); + bSTMT = true; + + char TimeBuffer[200]; +#ifdef DBG_TRACE_PROFILING + if( bPrintTimeStamp ) + { + double dDiffTime = dCurTime - GdLastTime; + GdLastTime = dCurTime; + sprintf( TimeBuffer, "\t\t// Time = %f ms / += %f ms", dCurTime*1000.0, dDiffTime*1000.0 ); + } +#endif + + if( bSTMT ) + { + lcl_lineOut( rStr_STMNT.getStr(), lcl_getSpaces( nIndent ), + (bPrintTimeStamp && !GbIncludePCodes) ? TimeBuffer : NULL ); + } if( !GbIncludePCodes ) + { +#ifdef DBG_TRACE_PROFILING + if( GbTimerOn ) + GpTimer->continueTimer(); +#endif return; + } nIndent += GnIndentForPCode; const rtl::OString& rStr_PCode = rTraceTextData.m_aTraceStr_PCode; if( rStr_PCode.getLength() ) - lcl_lineOut( GpTraceFileName, rStr_PCode.getStr(), lcl_getSpaces( nIndent ) ); + { + lcl_lineOut( rStr_PCode.getStr(), lcl_getSpaces( nIndent ), + bPrintTimeStamp ? TimeBuffer : NULL ); + } + +#ifdef DBG_TRACE_PROFILING + if( GbTimerOn ) + GpTimer->continueTimer(); +#endif } + void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, sal_Int32 nCallLvl, bool bLeave ) { static const char* pSeparator = "' ================================================================================"; if( !GbTraceOn ) return; + +#ifdef DBG_TRACE_PROFILING + double dCurTime = 0.0; + double dExecutionTime = 0.0; + if( GbTimerOn ) + { + dCurTime = GpTimer->getElapsedTime(); + GpTimer->pauseTimer(); + } +#endif + GnLastCallLvl = nCallLvl; SbModule* pTraceMod = pModule; @@ -399,39 +663,116 @@ void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, sal_Int32 nCallL pTraceMod = pClassModuleObj->getClassModule(); } + String aCompleteFunctionName = pTraceMod->GetName(); + if( pMethod != NULL ) + { + aCompleteFunctionName.AppendAscii( "::" ); + String aMethodName = pMethod->GetName(); + aCompleteFunctionName += aMethodName; + } + else + { + aCompleteFunctionName.AppendAscii( "/RunInit" ); + } + + bool bOwnBlockSteps = false; +#ifdef DBG_TRACE_PROFILING + bool bOwnBlockAll = false; + FunctionItem* pFunctionItem = NULL; + if( GbTimerOn ) + { + FunctionItemMap::iterator itFunctionItem = GaFunctionItemMap.find( aCompleteFunctionName ); + if( itFunctionItem != GaFunctionItemMap.end() ) + pFunctionItem = itFunctionItem->second; + + if( pFunctionItem == NULL ) + { + DBG_ASSERT( !bLeave, "No FunctionItem in leave!" ); + + pFunctionItem = new FunctionItem(); + pFunctionItem->m_aCompleteFunctionName = aCompleteFunctionName; + GaFunctionItemMap[ aCompleteFunctionName ] = pFunctionItem; + } + else if( GbBlockAllAfterFirstFunctionUsage && !bLeave ) + { + pFunctionItem->m_bBlockAll = true; + } + else if( GbBlockStepsAfterFirstFunctionUsage && !bLeave ) + { + pFunctionItem->m_bBlockSteps = true; + } + + if( bLeave ) + { + bOwnBlockAll = GbBlockAll; + bOwnBlockSteps = GbBlockSteps; + GbBlockAll = false; + GbBlockSteps = false; + + dExecutionTime = dCurTime - GaCallEnterTimeStack.top(); + GaCallEnterTimeStack.pop(); + + pFunctionItem->m_dTotalTime += dExecutionTime; + pFunctionItem->m_dNetTime += dExecutionTime; + pFunctionItem->m_nCallCount++; + + GaFunctionItemStack.pop(); + if( !GaFunctionItemStack.empty() ) + { + FunctionItem* pParentItem = GaFunctionItemStack.top(); + if( pParentItem != NULL ) + { + pParentItem->m_dNetTime -= dExecutionTime; + + GbBlockSteps = pParentItem->m_bBlockSteps; + GbBlockAll = pParentItem->m_bBlockAll; + } + } + } + else + { + GbBlockSteps = bOwnBlockSteps = pFunctionItem->m_bBlockSteps; + GbBlockAll = bOwnBlockAll = pFunctionItem->m_bBlockAll; + + GaCallEnterTimeStack.push( dCurTime ); + GaFunctionItemStack.push( pFunctionItem ); + } + } + + if( bOwnBlockAll ) + { + if( GbTimerOn ) + GpTimer->continueTimer(); + return; + } +#endif + if( nCallLvl > 0 ) nCallLvl--; int nIndent = nCallLvl * GnIndentPerCallLevel; - if( !bLeave ) + if( !bLeave && !bOwnBlockSteps ) { - lcl_lineOut( GpTraceFileName, "" ); - lcl_lineOut( GpTraceFileName, pSeparator, lcl_getSpaces( nIndent ) ); + lcl_lineOut( "" ); + lcl_lineOut( pSeparator, lcl_getSpaces( nIndent ) ); } String aStr; if( bLeave ) { - lcl_lineOut( GpTraceFileName, "}", lcl_getSpaces( nIndent ) ); - aStr.AppendAscii( "' Leaving " ); + if( !bOwnBlockSteps ) + { + lcl_lineOut( "}", lcl_getSpaces( nIndent ) ); + aStr.AppendAscii( "' Leaving " ); + } } else { aStr.AppendAscii( "Entering " ); } - String aModuleName = pTraceMod->GetName(); - aStr += aModuleName; - if( pMethod != NULL ) - { - aStr.AppendAscii( "::" ); - String aMethodName = pMethod->GetName(); - aStr += aMethodName; - } - else - { - aStr.AppendAscii( "/RunInit" ); - } + if( !bLeave || !bOwnBlockSteps ) + aStr += aCompleteFunctionName; - if( pClassModuleObj != NULL ) + if( !bOwnBlockSteps && pClassModuleObj != NULL ) { aStr.AppendAscii( "[this=" ); aStr += pClassModuleObj->GetName(); @@ -440,18 +781,37 @@ void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, sal_Int32 nCallL if( !bLeave ) aStr += lcl_dumpMethodParameters( pMethod ); - lcl_lineOut( GpTraceFileName, OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US ).getStr(), lcl_getSpaces( nIndent ) ); + const char* pPostStr = NULL; +#ifdef DBG_TRACE_PROFILING + char TimeBuffer[200]; + if( GbTimerOn && bLeave ) + { + sprintf( TimeBuffer, " // Execution Time = %f ms", dExecutionTime*1000.0 ); + pPostStr = TimeBuffer; + } +#endif + lcl_lineOut( (!bLeave || !bOwnBlockSteps) ? OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US ).getStr() : "}", + lcl_getSpaces( nIndent ), pPostStr ); if( !bLeave ) - lcl_lineOut( GpTraceFileName, "{", lcl_getSpaces( nIndent ) ); + lcl_lineOut( "{", lcl_getSpaces( nIndent ) ); - if( bLeave ) - lcl_lineOut( GpTraceFileName, "" ); + if( bLeave && !bOwnBlockSteps ) + lcl_lineOut( "" ); + +#ifdef DBG_TRACE_PROFILING + if( GbTimerOn ) + GpTimer->continueTimer(); +#endif } void dbg_traceNotifyError( SbError nTraceErr, const String& aTraceErrMsg, bool bTraceErrHandled, sal_Int32 nCallLvl ) { if( !GbTraceOn ) return; +#ifdef DBG_TRACE_PROFILING + if( GbBlockSteps || GbBlockAll ) + return; +#endif GnLastCallLvl = nCallLvl; rtl::OString aOTraceErrMsg = OUStringToOString( rtl::OUString( aTraceErrMsg ), RTL_TEXTENCODING_ASCII_US ); @@ -460,7 +820,7 @@ void dbg_traceNotifyError( SbError nTraceErr, const String& aTraceErrMsg, bool b const char* pHandledStr = bTraceErrHandled ? " / HANDLED" : ""; sprintf( Buffer, "*** ERROR%s, Id = %d, Msg = \"%s\" ***", pHandledStr, (int)nTraceErr, aOTraceErrMsg.getStr() ); int nIndent = nCallLvl * GnIndentPerCallLevel; - lcl_lineOut( GpTraceFileName, Buffer, lcl_getSpaces( nIndent ) ); + lcl_lineOut( Buffer, lcl_getSpaces( nIndent ) ); } void dbg_RegisterTraceTextForPC( SbModule* pModule, sal_uInt32 nPC, @@ -540,7 +900,7 @@ void RTL_Impl_TraceCommand( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite ) sprintf( Buffer, "### TRACE_PRINT: %s ###", pValStr ); int nIndent = GnLastCallLvl * GnIndentPerCallLevel; - lcl_lineOut( GpTraceFileName, Buffer, lcl_getSpaces( nIndent ) ); + lcl_lineOut( Buffer, lcl_getSpaces( nIndent ) ); if( eOld != SbxERR_OK ) SbxBase::SetError( eOld ); diff --git a/basic/source/comp/symtbl.cxx b/basic/source/comp/symtbl.cxx index 2688b5be28cf..cc6dc04fde65 100644 --- a/basic/source/comp/symtbl.cxx +++ b/basic/source/comp/symtbl.cxx @@ -302,6 +302,7 @@ SbiSymDef::SbiSymDef( const String& rName ) : aName( rName ) bOpt = bParamArray = bWithEvents = + bWithBrackets = bByVal = bChained = bGlobal = sal_False; diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx index 8700ae4129ba..28c90ff0bd87 100644 --- a/basic/source/comp/token.cxx +++ b/basic/source/comp/token.cxx @@ -561,7 +561,8 @@ SbiToken SbiTokenizer::Next() } special: // #i92642 - if( eCurTok != NIL && eCurTok != REM && eCurTok != EOLN && (tp->t == NAME || tp->t == LINE) ) + bool bStartOfLine = (eCurTok == NIL || eCurTok == REM || eCurTok == EOLN); + if( !bStartOfLine && (tp->t == NAME || tp->t == LINE) ) return eCurTok = SYMBOL; else if( tp->t == TEXT ) return eCurTok = SYMBOL; @@ -628,6 +629,9 @@ special: // #129904 Suppress system if( eTok == STOP && aSym.CompareIgnoreCaseToAscii( "system" ) == COMPARE_EQUAL ) eCurTok = SYMBOL; + + if( eTok == GET && bStartOfLine ) + eCurTok = SYMBOL; } else { diff --git a/basic/source/inc/codegen.hxx b/basic/source/inc/codegen.hxx index a496322bb6d7..9ba99e7ceae8 100644 --- a/basic/source/inc/codegen.hxx +++ b/basic/source/inc/codegen.hxx @@ -87,6 +87,7 @@ public: // #111897 PARAM_INFO flags start at 0x00010000 to not // conflict with DefaultId in SbxParamInfo::nUserData -#define PARAM_INFO_PARAMARRAY 0x0010000 +#define PARAM_INFO_PARAMARRAY 0x0010000 +#define PARAM_INFO_WITHBRACKETS 0x0020000 #endif diff --git a/basic/source/inc/namecont.hxx b/basic/source/inc/namecont.hxx index 7fd6eb06f607..c0e8191be307 100644 --- a/basic/source/inc/namecont.hxx +++ b/basic/source/inc/namecont.hxx @@ -29,6 +29,7 @@ #define BASIC_NAMECONTAINER_HXX #include <hash_map> + #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/lang/XInitialization.hpp> @@ -46,71 +47,41 @@ #include <com/sun/star/document/XStorageBasedDocument.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/deployment/XPackage.hpp> +#include <com/sun/star/script/vba/XVBACompatibility.hpp> +#include <com/sun/star/script/vba/XVBAScriptListener.hpp> +#include <com/sun/star/util/XChangesNotifier.hpp> + #include <osl/mutex.hxx> #include <unotools/eventlisteneradapter.hxx> +#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/compbase8.hxx> +#include <cppuhelper/interfacecontainer.hxx> #include <cppuhelper/weakref.hxx> #include <cppuhelper/component.hxx> #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/interfacecontainer.hxx> #include <cppuhelper/basemutex.hxx> #include <sot/storage.hxx> +#include <comphelper/listenernotification.hxx> #include <xmlscript/xmllib_imexp.hxx> -#include <com/sun/star/deployment/XPackage.hpp> - -#include <cppuhelper/implbase2.hxx> -#include <cppuhelper/compbase8.hxx> -#include <cppuhelper/interfacecontainer.hxx> -#include <com/sun/star/script/vba/XVBACompatibility.hpp> class BasicManager; namespace basic { -typedef ::cppu::WeakComponentImplHelper8< - ::com::sun::star::lang::XInitialization, - ::com::sun::star::script::XStorageBasedLibraryContainer, - ::com::sun::star::script::XLibraryContainerPassword, - ::com::sun::star::script::XLibraryContainerExport, - ::com::sun::star::script::XLibraryContainer3, - ::com::sun::star::container::XContainer, - ::com::sun::star::script::vba::XVBACompatibility, - ::com::sun::star::lang::XServiceInfo > LibraryContainerHelper; - -typedef ::cppu::WeakImplHelper2< ::com::sun::star::container::XNameContainer, - ::com::sun::star::container::XContainer > NameContainerHelper; - +//============================================================================ -struct hashName_Impl -{ - size_t operator()(const ::rtl::OUString Str) const - { - return (size_t)Str.hashCode(); - } -}; +typedef ::cppu::WeakImplHelper3< + ::com::sun::star::container::XNameContainer, + ::com::sun::star::container::XContainer, + ::com::sun::star::util::XChangesNotifier > NameContainer_BASE; -struct eqName_Impl +class NameContainer : public ::cppu::BaseMutex, public NameContainer_BASE { - sal_Bool operator()(const ::rtl::OUString Str1, const ::rtl::OUString Str2) const - { - return ( Str1 == Str2 ); - } -}; - -typedef std::hash_map -< - ::rtl::OUString, - sal_Int32, - hashName_Impl, - eqName_Impl -> -NameContainerNameMap; - - -//============================================================================ + typedef std::hash_map< ::rtl::OUString, sal_Int32, ::rtl::OUStringHash > NameContainerNameMap; -class NameContainer : public ::cppu::BaseMutex, public NameContainerHelper -{ NameContainerNameMap mHashMap; ::com::sun::star::uno::Sequence< ::rtl::OUString > mNames; ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > mValues; @@ -119,14 +90,16 @@ class NameContainer : public ::cppu::BaseMutex, public NameContainerHelper ::com::sun::star::uno::Type mType; ::com::sun::star::uno::XInterface* mpxEventSource; - ::cppu::OInterfaceContainerHelper maListenerContainer; + ::cppu::OInterfaceContainerHelper maContainerListeners; + ::cppu::OInterfaceContainerHelper maChangesListeners; public: NameContainer( const ::com::sun::star::uno::Type& rType ) : mnElementCount( 0 ) , mType( rType ) , mpxEventSource( NULL ) - , maListenerContainer( m_aMutex ) + , maContainerListeners( m_aMutex ) + , maChangesListeners( m_aMutex ) {} void setEventSource( ::com::sun::star::uno::XInterface* pxEventSource ) @@ -173,21 +146,18 @@ public: virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + + // Methods XChangesNotifier + virtual void SAL_CALL addChangesListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XChangesListener >& xListener ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeChangesListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XChangesListener >& xListener ) + throw (::com::sun::star::uno::RuntimeException); }; //============================================================================ -class SfxLibrary; - -enum InitMode -{ - DEFAULT, - CONTAINER_INIT_FILE, - LIBRARY_INIT_FILE, - OFFICE_DOCUMENT, - OLD_BASIC_STORAGE -}; - class ModifiableHelper { private: @@ -217,9 +187,42 @@ public: } }; -class SfxLibraryContainer :public LibraryContainerHelper - ,public ::utl::OEventListenerAdapter +//============================================================================ + +typedef ::comphelper::OListenerContainerBase< + ::com::sun::star::script::vba::XVBAScriptListener, + ::com::sun::star::script::vba::VBAScriptEvent > VBAScriptListenerContainer_BASE; + +class VBAScriptListenerContainer : public VBAScriptListenerContainer_BASE +{ +public: + explicit VBAScriptListenerContainer( ::osl::Mutex& rMutex ); + +private: + virtual bool implTypedNotify( + const ::com::sun::star::uno::Reference< ::com::sun::star::script::vba::XVBAScriptListener >& rxListener, + const ::com::sun::star::script::vba::VBAScriptEvent& rEvent ) + throw (::com::sun::star::uno::Exception); +}; + +//============================================================================ + +class SfxLibrary; + +typedef ::cppu::WeakComponentImplHelper8< + ::com::sun::star::lang::XInitialization, + ::com::sun::star::script::XStorageBasedLibraryContainer, + ::com::sun::star::script::XLibraryContainerPassword, + ::com::sun::star::script::XLibraryContainerExport, + ::com::sun::star::script::XLibraryContainer3, + ::com::sun::star::container::XContainer, + ::com::sun::star::script::vba::XVBACompatibility, + ::com::sun::star::lang::XServiceInfo > SfxLibraryContainer_BASE; + +class SfxLibraryContainer : public SfxLibraryContainer_BASE, public ::utl::OEventListenerAdapter { + VBAScriptListenerContainer maVBAScriptListeners; + sal_Int32 mnRunningVBAScripts; sal_Bool mbVBACompat; protected: ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; @@ -246,7 +249,14 @@ protected: BasicManager* mpBasMgr; sal_Bool mbOwnBasMgr; - InitMode meInitMode; + enum InitMode + { + DEFAULT, + CONTAINER_INIT_FILE, + LIBRARY_INIT_FILE, + OFFICE_DOCUMENT, + OLD_BASIC_STORAGE + } meInitMode; void implStoreLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName, @@ -508,10 +518,24 @@ public: virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException) = 0; // Methods XVBACompatibility - virtual ::sal_Bool SAL_CALL getVBACompatibilityMode() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setVBACompatibilityMode( ::sal_Bool _vbacompatmodeon ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getVBACompatibilityMode() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setVBACompatibilityMode( ::sal_Bool _vbacompatmodeon ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getRunningVBAScripts() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addVBAScriptListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::script::vba::XVBAScriptListener >& Listener ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeVBAScriptListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::script::vba::XVBAScriptListener >& Listener ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL broadcastVBAScriptEvent( sal_Int32 nIdentifier, const ::rtl::OUString& rModuleName ) + throw (::com::sun::star::uno::RuntimeException); }; +//============================================================================ + class LibraryContainerMethodGuard { private: @@ -529,12 +553,12 @@ public: } }; - //============================================================================ class SfxLibrary : public ::com::sun::star::container::XNameContainer , public ::com::sun::star::container::XContainer + , public ::com::sun::star::util::XChangesNotifier , public ::cppu::BaseMutex , public ::cppu::OComponentHelper { @@ -670,6 +694,14 @@ public: ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + // Methods XChangesNotifier + virtual void SAL_CALL addChangesListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XChangesListener >& xListener ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeChangesListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XChangesListener >& xListener ) + throw (::com::sun::star::uno::RuntimeException); + public: struct LibraryContainerAccess { friend class SfxLibraryContainer; private: LibraryContainerAccess() { } }; void removeElementWithoutChecks( const ::rtl::OUString& _rElementName, LibraryContainerAccess ) @@ -681,18 +713,19 @@ protected: virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const = 0; }; -//=================================================================== +//============================================================================ + class ScriptSubPackageIterator { - com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > m_xMainPackage; + com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > m_xMainPackage; - bool m_bIsValid; - bool m_bIsBundle; + bool m_bIsValid; + bool m_bIsBundle; com::sun::star::uno::Sequence< com::sun::star::uno::Reference - < com::sun::star::deployment::XPackage > > m_aSubPkgSeq; - sal_Int32 m_nSubPkgCount; - sal_Int32 m_iNextSubPkg; + < com::sun::star::deployment::XPackage > > m_aSubPkgSeq; + sal_Int32 m_nSubPkgCount; + sal_Int32 m_iNextSubPkg; com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implDetectScriptPackage( const com::sun::star::uno::Reference @@ -704,13 +737,7 @@ public: com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > getNextScriptSubPackage( bool& rbPureDialogLib ); }; -enum IteratorState -{ - USER_EXTENSIONS, - SHARED_EXTENSIONS, - BUNDLED_EXTENSIONS, - END_REACHED -}; +//============================================================================ class ScriptExtensionIterator { @@ -731,34 +758,37 @@ protected: com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextBundledScriptPackage( bool& rbPureDialogLib ); - com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext; + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext; - IteratorState m_eState; + enum IteratorState + { + USER_EXTENSIONS, + SHARED_EXTENSIONS, + BUNDLED_EXTENSIONS, + END_REACHED + } m_eState; com::sun::star::uno::Sequence< com::sun::star::uno::Reference - < com::sun::star::deployment::XPackage > > m_aUserPackagesSeq; - bool m_bUserPackagesLoaded; + < com::sun::star::deployment::XPackage > > m_aUserPackagesSeq; + bool m_bUserPackagesLoaded; com::sun::star::uno::Sequence< com::sun::star::uno::Reference - < com::sun::star::deployment::XPackage > > m_aSharedPackagesSeq; - bool m_bSharedPackagesLoaded; + < com::sun::star::deployment::XPackage > > m_aSharedPackagesSeq; + bool m_bSharedPackagesLoaded; com::sun::star::uno::Sequence< com::sun::star::uno::Reference - < com::sun::star::deployment::XPackage > > m_aBundledPackagesSeq; - bool m_bBundledPackagesLoaded; + < com::sun::star::deployment::XPackage > > m_aBundledPackagesSeq; + bool m_bBundledPackagesLoaded; + int m_iUserPackage; + int m_iSharedPackage; + int m_iBundledPackage; - int m_iUserPackage; - int m_iSharedPackage; - int m_iBundledPackage; - - - - ScriptSubPackageIterator* m_pScriptSubPackageIterator; + ScriptSubPackageIterator* m_pScriptSubPackageIterator; }; // end class ScriptExtensionIterator - +//============================================================================ } // namespace basic diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx index 46cd9d16521f..406bd487034c 100644 --- a/basic/source/inc/runtime.hxx +++ b/basic/source/inc/runtime.hxx @@ -465,6 +465,8 @@ public: SbxArray* GetLocals(); SbxArray* GetParams(); + SbiForStack* FindForStackItemForCollection( class BasicCollection* pCollection ); + SbxBase* FindElementExtern( const String& rName ); static bool isVBAEnabled(); diff --git a/basic/source/inc/sbtrace.hxx b/basic/source/inc/sbtrace.hxx index d91c7bdf16e8..6ab27050d263 100755 --- a/basic/source/inc/sbtrace.hxx +++ b/basic/source/inc/sbtrace.hxx @@ -30,6 +30,19 @@ //#define DBG_TRACE_BASIC +// ############################################################################### +// ### +// ### ATTENTION: +// ### +// ### - DBG_TRACE_PROFILING can only be activated together with DBG_TRACE_BASIC +// ### +// ### - If you activate DBG_TRACE_PROFILING you also need to uncomment line +// ### # SHL1STDLIBS+=$(CANVASTOOLSLIB) in basic/util/makefile.mk (search +// ### for DBG_TRACE_PROFILING there) +// ### +// ############################################################################### +//#define DBG_TRACE_PROFILING + #ifdef DBG_TRACE_BASIC void dbg_InitTrace( void ); void dbg_DeInitTrace( void ); diff --git a/basic/source/inc/scriptcont.hxx b/basic/source/inc/scriptcont.hxx index d788a73da0fc..9ef4c41c6ce3 100644 --- a/basic/source/inc/scriptcont.hxx +++ b/basic/source/inc/scriptcont.hxx @@ -35,11 +35,11 @@ class BasicManager; -//============================================================================ - namespace basic { +//============================================================================ + class SfxScriptLibraryContainer : public SfxLibraryContainer, public OldBasicPassword { ::rtl::OUString maScriptLanguage; @@ -140,16 +140,15 @@ public: }; //============================================================================ -typedef std::hash_map< ::rtl::OUString, ::com::sun::star::script::ModuleInfo, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > ModuleInfoMap; -typedef ::cppu::ImplHelper1 < ::com::sun::star::script::vba::XVBAModuleInfo - > SfxScriptLibrary_BASE; +typedef ::cppu::ImplHelper1< ::com::sun::star::script::vba::XVBAModuleInfo > SfxScriptLibrary_BASE; -class SfxScriptLibrary : public SfxLibrary - , public SfxScriptLibrary_BASE +class SfxScriptLibrary : public SfxLibrary, public SfxScriptLibrary_BASE { friend class SfxScriptLibraryContainer; + typedef std::hash_map< ::rtl::OUString, ::com::sun::star::script::ModuleInfo, ::rtl::OUStringHash > ModuleInfoMap; + sal_Bool mbLoadedSource; sal_Bool mbLoadedBinary; ModuleInfoMap mModuleInfos; @@ -194,7 +193,9 @@ protected: virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const; }; -} // namespace base +//============================================================================ + +} // namespace basic #endif diff --git a/basic/source/inc/symtbl.hxx b/basic/source/inc/symtbl.hxx index c30445d87634..576639dc5a45 100644 --- a/basic/source/inc/symtbl.hxx +++ b/basic/source/inc/symtbl.hxx @@ -133,6 +133,7 @@ protected: sal_Bool bGlobal : 1; // sal_True: Global-Variable sal_Bool bParamArray : 1; // sal_True: ParamArray parameter sal_Bool bWithEvents : 1; // sal_True: Declared WithEvents + sal_Bool bWithBrackets : 1; // sal_True: Followed by () sal_uInt16 nDefaultId; // Symbol number of default value short nFixedStringLength; // String length in: Dim foo As String*Length public: @@ -159,6 +160,7 @@ public: void SetOptional() { bOpt = sal_True; } void SetParamArray() { bParamArray = sal_True; } void SetWithEvents() { bWithEvents = sal_True; } + void SetWithBrackets(){ bWithBrackets = sal_True; } void SetByVal( sal_Bool bByVal_ = sal_True ) { bByVal = bByVal_; } void SetStatic( sal_Bool bAsStatic = sal_True ) { bStatic = bAsStatic; } @@ -170,6 +172,7 @@ public: sal_Bool IsOptional() const{ return bOpt; } sal_Bool IsParamArray() const{ return bParamArray; } sal_Bool IsWithEvents() const{ return bWithEvents; } + sal_Bool IsWithBrackets() const{ return bWithBrackets; } sal_Bool IsByVal() const { return bByVal; } sal_Bool IsStatic() const { return bStatic; } sal_Bool IsNew() const { return bNew; } diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 1d1f1c641547..640dd7e8bcbe 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -82,6 +82,7 @@ using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::ucb; using namespace com::sun::star::io; +using namespace com::sun::star::frame; #endif /* _USE_UNO */ @@ -96,6 +97,7 @@ using namespace com::sun::star::io; #include "iosys.hxx" #include "ddectrl.hxx" #include <sbintern.hxx> +#include <basic/vbahelper.hxx> #include <list> #include <math.h> @@ -118,6 +120,9 @@ using namespace com::sun::star::io; #include <basic/sbobjmod.hxx> +// from source/classes/sbxmod.cxx +Reference< XModel > getDocumentModel( StarBASIC* ); + static void FilterWhiteSpace( String& rStr ) { rStr.EraseAllChars( ' ' ); @@ -382,22 +387,48 @@ RTLFUNC(Asc) } } -RTLFUNC(Chr) +void implChr( SbxArray& rPar, bool bChrW ) { - (void)pBasic; - (void)bWrite; - if ( rPar.Count() < 2 ) StarBASIC::Error( SbERR_BAD_ARGUMENT ); else { SbxVariableRef pArg = rPar.Get( 1 ); - sal_Unicode aCh = (sal_Unicode)pArg->GetUShort(); - String aStr( aCh ); + + String aStr; + if( !bChrW && SbiRuntime::isVBAEnabled() ) + { + sal_Char c = (sal_Char)pArg->GetByte(); + ByteString s( c ); + aStr = String( s, gsl_getSystemTextEncoding() ); + } + else + { + sal_Unicode aCh = (sal_Unicode)pArg->GetUShort(); + aStr = String( aCh ); + } rPar.Get(0)->PutString( aStr ); } } +RTLFUNC(Chr) +{ + (void)pBasic; + (void)bWrite; + + bool bChrW = false; + implChr( rPar, bChrW ); +} + +RTLFUNC(ChrW) +{ + (void)pBasic; + (void)bWrite; + + bool bChrW = true; + implChr( rPar, bChrW ); +} + #ifdef UNX #define _MAX_PATH 260 @@ -481,7 +512,6 @@ RTLFUNC(CurDir) RTLFUNC(ChDir) // JSM { - (void)pBasic; (void)bWrite; rPar.Get(0)->PutEmpty(); @@ -504,6 +534,9 @@ RTLFUNC(ChDir) // JSM if( bError ) StarBASIC::Error( SbERR_PATH_NOT_FOUND ); #endif + // VBA: track current directory per document type (separately for Writer, Calc, Impress, etc.) + if( SbiRuntime::isVBAEnabled() ) + ::basic::vba::registerCurrentDirectory( getDocumentModel( pBasic ), rPar.Get(1)->GetString() ); } else StarBASIC::Error( SbERR_BAD_ARGUMENT ); diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx index 2f6d18685803..20eca1f985ff 100755..100644 --- a/basic/source/runtime/methods1.cxx +++ b/basic/source/runtime/methods1.cxx @@ -1075,6 +1075,10 @@ sal_Bool lcl_ReadSbxVariable( SbxVariable& rVar, SvStream* pStrm, { sal_uInt8 aByte; *pStrm >> aByte; + + if( bBinary && SbiRuntime::isVBAEnabled() && aByte == 1 && pStrm->IsEof() ) + aByte = 0; + rVar.PutByte( aByte ); } break; @@ -1185,7 +1189,8 @@ void PutGet( SbxArray& rPar, sal_Bool bPut ) } sal_Int16 nFileNo = rPar.Get(1)->GetInteger(); SbxVariable* pVar2 = rPar.Get(2); - sal_Bool bHasRecordNo = (sal_Bool)(pVar2->GetType() != SbxEMPTY); + SbxDataType eType2 = pVar2->GetType(); + sal_Bool bHasRecordNo = (sal_Bool)(eType2 != SbxEMPTY && eType2 != SbxERROR); long nRecordNo = pVar2->GetLong(); if ( nFileNo < 1 || ( bHasRecordNo && nRecordNo < 1 ) ) { diff --git a/basic/source/runtime/rtlproto.hxx b/basic/source/runtime/rtlproto.hxx index bba1867d3591..8594382bd733 100644 --- a/basic/source/runtime/rtlproto.hxx +++ b/basic/source/runtime/rtlproto.hxx @@ -157,6 +157,7 @@ extern RTLFUNC(Abs); extern RTLFUNC(Asc); extern RTLFUNC(Atn); extern RTLFUNC(Chr); +extern RTLFUNC(ChrW); extern RTLFUNC(Cos); extern RTLFUNC(CurDir); extern RTLFUNC(ChDir); // JSM diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index 10d25cc2292b..1a83a323931d 100644 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -648,6 +648,7 @@ void SbiRuntime::SetParameters( SbxArray* pParams ) // Methoden sind immer byval! sal_Bool bByVal = v->IsA( TYPE(SbxMethod) ); SbxDataType t = v->GetType(); + bool bTargetTypeIsArray = false; if( p ) { bByVal |= sal_Bool( ( p->eType & SbxBYREF ) == 0 ); @@ -656,9 +657,13 @@ void SbiRuntime::SetParameters( SbxArray* pParams ) if( !bByVal && t != SbxVARIANT && (!v->IsFixed() || (SbxDataType)(v->GetType() & 0x0FFF ) != t) ) bByVal = sal_True; + + bTargetTypeIsArray = (p->nUserData & PARAM_INFO_WITHBRACKETS) != 0; } if( bByVal ) { + if( bTargetTypeIsArray ) + t = SbxOBJECT; SbxVariable* v2 = new SbxVariable( t ); v2->SetFlag( SBX_READWRITE ); *v2 = *v; @@ -1237,6 +1242,26 @@ void SbiRuntime::ClearForStack() PopFor(); } +SbiForStack* SbiRuntime::FindForStackItemForCollection( class BasicCollection* pCollection ) +{ + SbiForStack* pRet = NULL; + + SbiForStack* p = pForStk; + while( p ) + { + SbxVariable* pVar = p->refEnd.Is() ? (SbxVariable*)p->refEnd : NULL; + if( p->eForType == FOR_EACH_COLLECTION && pVar != NULL && + (pCollection = PTR_CAST(BasicCollection,pVar)) == pCollection ) + { + pRet = p; + break; + } + } + + return pRet; +} + + ////////////////////////////////////////////////////////////////////////// // // DLL-Aufrufe diff --git a/basic/source/runtime/stdobj.cxx b/basic/source/runtime/stdobj.cxx index 92d8152e60f4..4004b40e882c 100644 --- a/basic/source/runtime/stdobj.cxx +++ b/basic/source/runtime/stdobj.cxx @@ -128,7 +128,7 @@ static Methods aMethods[] = { { "Chr", SbxSTRING, 1 | _FUNCTION, RTLNAME(Chr),0 }, { "string", SbxINTEGER, 0,NULL,0 }, -{ "ChrW", SbxSTRING, 1 | _FUNCTION | _COMPTMASK, RTLNAME(Chr),0}, +{ "ChrW", SbxSTRING, 1 | _FUNCTION | _COMPTMASK, RTLNAME(ChrW),0}, { "string", SbxINTEGER, 0,NULL,0 }, { "CInt", SbxINTEGER, 1 | _FUNCTION, RTLNAME(CInt),0 }, diff --git a/basic/source/runtime/step0.cxx b/basic/source/runtime/step0.cxx index 43c930e975d2..462726a4c55f 100644 --- a/basic/source/runtime/step0.cxx +++ b/basic/source/runtime/step0.cxx @@ -797,6 +797,8 @@ void SbiRuntime::DimImpl( SbxVariableRef refVar ) // AB 2.4.1996, auch Arrays ohne Dimensionsangaben zulassen (VB-komp.) if( pDims ) { + refVar->ResetFlag( SBX_VAR_TO_DIM ); + for( sal_uInt16 i = 1; i < pDims->Count(); ) { sal_Int32 lb = pDims->Get( i++ )->GetLong(); diff --git a/basic/source/runtime/step1.cxx b/basic/source/runtime/step1.cxx index 0a9572906cc8..4fd91b692a4b 100644 --- a/basic/source/runtime/step1.cxx +++ b/basic/source/runtime/step1.cxx @@ -38,8 +38,7 @@ #include "sbunoobj.hxx" #include "errobject.hxx" -bool checkUnoObjectType( SbUnoObject* refVal, - const String& aClass ); +bool checkUnoObjectType( SbUnoObject* refVal, const ::rtl::OUString& aClass ); // Laden einer numerischen Konstanten (+ID) diff --git a/basic/source/runtime/step2.cxx b/basic/source/runtime/step2.cxx index bbb3668b5b69..dc8ff0a5fd50 100755 --- a/basic/source/runtime/step2.cxx +++ b/basic/source/runtime/step2.cxx @@ -624,7 +624,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem ) else if( bVBAEnabled ) // !pObj { SbxArray* pParam = pElem->GetParameters(); - if( pParam != NULL ) + if( pParam != NULL && !pElem->IsSet( SBX_VAR_TO_DIM ) ) Error( SbERR_NO_OBJECT ); } } @@ -1141,6 +1141,10 @@ void SbiRuntime::implHandleSbxFlags( SbxVariable* pVar, SbxDataType t, sal_uInt3 aStr.Fill( nCount, 0 ); pVar->PutString( aStr ); } + + bool bVarToDim = ((nOp2 & SBX_TYPE_VAR_TO_DIM_FLAG) != 0); + if( bVarToDim ) + pVar->SetFlag( SBX_VAR_TO_DIM ); } // Einrichten einer lokalen Variablen (+StringID+Typ) diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx index fbf1429f9753..ae110f4bcf6e 100644 --- a/basic/source/uno/namecont.cxx +++ b/basic/source/uno/namecont.cxx @@ -34,17 +34,13 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <vcl/svapp.hxx> #include <vos/mutex.hxx> -#ifndef __RSC //autogen #include <tools/errinf.hxx> -#endif #include <osl/mutex.hxx> #include <vos/diagnose.hxx> #include <rtl/uri.hxx> #include <rtl/strbuf.hxx> #include <comphelper/processfactory.hxx> -#ifndef INCLUDED_COMPHELPER_ANYTOSTRING_HXX #include <comphelper/anytostring.hxx> -#endif #include "namecont.hxx" #include <basic/basicmanagerrepository.hxx> @@ -65,11 +61,9 @@ #include <com/sun/star/uno/DeploymentException.hpp> #include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/script/LibraryNotLoadedException.hpp> -#include "com/sun/star/deployment/ExtensionManager.hpp" +#include <com/sun/star/script/vba/VBAScriptEventId.hpp> +#include <com/sun/star/deployment/ExtensionManager.hpp> #include <comphelper/storagehelper.hxx> -#ifndef _RTL_USTRING_HXX_ -#include <comphelper/anytostring.hxx> -#endif #include <cppuhelper/exc_hlp.hxx> #include <basic/sbmod.hxx> @@ -165,25 +159,29 @@ void NameContainer::replaceByName( const OUString& aName, const Any& aElement ) // Fire event - ContainerEvent aEvent; - aEvent.Source = mpxEventSource; - aEvent.Accessor <<= aName; - aEvent.Element = aElement; - aEvent.ReplacedElement = aOldElement; + if( maContainerListeners.getLength() > 0 ) + { + ContainerEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Accessor <<= aName; + aEvent.Element = aElement; + aEvent.ReplacedElement = aOldElement; + maContainerListeners.notifyEach( &XContainerListener::elementReplaced, aEvent ); + } - OInterfaceIteratorHelper aIterator( maListenerContainer ); - while( aIterator.hasMoreElements() ) + /* After the container event has been fired (one listener will update the + core Basic manager), fire change event. Listeners can rely that the + Basic source code of the core Basic manager is up-to-date. */ + if( maChangesListeners.getLength() > 0 ) { - Reference< XInterface > xIface = aIterator.next(); - Reference< XContainerListener > xListener( xIface, UNO_QUERY ); - try - { - xListener->elementReplaced( aEvent ); - } - catch(RuntimeException&) - { - aIterator.remove(); - } + ChangesEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Base <<= aEvent.Source; + aEvent.Changes.realloc( 1 ); + aEvent.Changes[ 0 ].Accessor <<= aName; + aEvent.Changes[ 0 ].Element <<= aElement; + aEvent.Changes[ 0 ].ReplacedElement = aOldElement; + maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent ); } } @@ -211,33 +209,35 @@ void NameContainer::insertByName( const OUString& aName, const Any& aElement ) mHashMap[ aName ] = nCount; mnElementCount++; - // Fire event - ContainerEvent aEvent; - aEvent.Source = mpxEventSource; - aEvent.Accessor <<= aName; - aEvent.Element = aElement; + if( maContainerListeners.getLength() > 0 ) + { + ContainerEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Accessor <<= aName; + aEvent.Element = aElement; + maContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent ); + } - OInterfaceIteratorHelper aIterator( maListenerContainer ); - while( aIterator.hasMoreElements() ) + /* After the container event has been fired (one listener will update the + core Basic manager), fire change event. Listeners can rely that the + Basic source code of the core Basic manager is up-to-date. */ + if( maChangesListeners.getLength() > 0 ) { - Reference< XInterface > xIface = aIterator.next(); - Reference< XContainerListener > xListener( xIface, UNO_QUERY ); - try - { - xListener->elementInserted( aEvent ); - } - catch(RuntimeException&) - { - aIterator.remove(); - } + ChangesEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Base <<= aEvent.Source; + aEvent.Changes.realloc( 1 ); + aEvent.Changes[ 0 ].Accessor <<= aName; + aEvent.Changes[ 0 ].Element <<= aElement; + maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent ); } } -void NameContainer::removeByName( const OUString& Name ) +void NameContainer::removeByName( const OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException) { - NameContainerNameMap::iterator aIt = mHashMap.find( Name ); + NameContainerNameMap::iterator aIt = mHashMap.find( aName ); if( aIt == mHashMap.end() ) { throw NoSuchElementException(); @@ -259,26 +259,29 @@ void NameContainer::removeByName( const OUString& Name ) mValues.realloc( iLast ); mnElementCount--; - // Fire event - ContainerEvent aEvent; - aEvent.Source = mpxEventSource; - aEvent.Accessor <<= Name; - aEvent.Element = aOldElement; + if( maContainerListeners.getLength() > 0 ) + { + ContainerEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Accessor <<= aName; + aEvent.Element = aOldElement; + maContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvent ); + } - OInterfaceIteratorHelper aIterator( maListenerContainer ); - while( aIterator.hasMoreElements() ) + /* After the container event has been fired (one listener will update the + core Basic manager), fire change event. Listeners can rely that the + Basic source code of the core Basic manager is up-to-date. */ + if( maChangesListeners.getLength() > 0 ) { - Reference< XInterface > xIface = aIterator.next(); - Reference< XContainerListener > xListener( xIface, UNO_QUERY ); - try - { - xListener->elementRemoved( aEvent ); - } - catch(RuntimeException&) - { - aIterator.remove(); - } + ChangesEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Base <<= aEvent.Source; + aEvent.Changes.realloc( 1 ); + aEvent.Changes[ 0 ].Accessor <<= aName; + // aEvent.Changes[ 0 ].Element remains empty (meaning "replaced with nothing") + aEvent.Changes[ 0 ].ReplacedElement = aOldElement; + maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent ); } } @@ -290,7 +293,7 @@ void SAL_CALL NameContainer::addContainerListener( const Reference< XContainerLi if( !xListener.is() ) throw RuntimeException(); Reference< XInterface > xIface( xListener, UNO_QUERY ); - maListenerContainer.addInterface( xIface ); + maContainerListeners.addInterface( xIface ); } void SAL_CALL NameContainer::removeContainerListener( const Reference< XContainerListener >& xListener ) @@ -299,7 +302,26 @@ void SAL_CALL NameContainer::removeContainerListener( const Reference< XContaine if( !xListener.is() ) throw RuntimeException(); Reference< XInterface > xIface( xListener, UNO_QUERY ); - maListenerContainer.removeInterface( xIface ); + maContainerListeners.removeInterface( xIface ); +} + +// Methods XChangesNotifier +void SAL_CALL NameContainer::addChangesListener( const Reference< XChangesListener >& xListener ) + throw (RuntimeException) +{ + if( !xListener.is() ) + throw RuntimeException(); + Reference< XInterface > xIface( xListener, UNO_QUERY ); + maChangesListeners.addInterface( xIface ); +} + +void SAL_CALL NameContainer::removeChangesListener( const Reference< XChangesListener >& xListener ) + throw (RuntimeException) +{ + if( !xListener.is() ) + throw RuntimeException(); + Reference< XInterface > xIface( xListener, UNO_QUERY ); + maChangesListeners.removeInterface( xIface ); } //============================================================================ @@ -320,12 +342,28 @@ void ModifiableHelper::setModified( sal_Bool _bModified ) //============================================================================ +VBAScriptListenerContainer::VBAScriptListenerContainer( ::osl::Mutex& rMutex ) : + VBAScriptListenerContainer_BASE( rMutex ) +{ +} + +bool VBAScriptListenerContainer::implTypedNotify( const Reference< vba::XVBAScriptListener >& rxListener, const vba::VBAScriptEvent& rEvent ) throw (Exception) +{ + rxListener->notifyVBAScriptEvent( rEvent ); + return true; // notify all other listeners too +} + +//============================================================================ + // Implementation class SfxLibraryContainer DBG_NAME( SfxLibraryContainer ) // Ctor SfxLibraryContainer::SfxLibraryContainer( void ) - : LibraryContainerHelper( maMutex ) + : SfxLibraryContainer_BASE( maMutex ) + + , maVBAScriptListeners( maMutex ) + , mnRunningVBAScripts( 0 ) , mbVBACompat( sal_False ) , maModifiable( *this, maMutex ) , maNameContainer( getCppuType( (Reference< XNameAccess >*) NULL ) ) @@ -2649,6 +2687,9 @@ void SfxLibraryContainer::_disposing( const EventObject& _rSource ) // OComponentHelper void SAL_CALL SfxLibraryContainer::disposing() { + Reference< XModel > xModel = mxOwnerDocument; + EventObject aEvent( xModel.get() ); + maVBAScriptListeners.disposing( aEvent ); stopAllComponentListening(); mxOwnerDocument = WeakReference< XModel >(); } @@ -2838,7 +2879,7 @@ void SAL_CALL SfxLibraryContainer::setVBACompatibilityMode( ::sal_Bool _vbacompa */ if( mbVBACompat ) try { - Reference< frame::XModel > xModel( mxOwnerDocument ); // weak-ref -> ref + Reference< XModel > xModel( mxOwnerDocument ); // weak-ref -> ref Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW ); xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals" ) ) ); } @@ -2848,6 +2889,43 @@ void SAL_CALL SfxLibraryContainer::setVBACompatibilityMode( ::sal_Bool _vbacompa } } +sal_Int32 SAL_CALL SfxLibraryContainer::getRunningVBAScripts() throw (RuntimeException) +{ + LibraryContainerMethodGuard aGuard( *this ); + return mnRunningVBAScripts; +} + +void SAL_CALL SfxLibraryContainer::addVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener ) throw (RuntimeException) +{ + maVBAScriptListeners.addTypedListener( rxListener ); +} + +void SAL_CALL SfxLibraryContainer::removeVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener ) throw (RuntimeException) +{ + maVBAScriptListeners.removeTypedListener( rxListener ); +} + +void SAL_CALL SfxLibraryContainer::broadcastVBAScriptEvent( sal_Int32 nIdentifier, const ::rtl::OUString& rModuleName ) throw (RuntimeException) +{ + // own lock for accessing the number of running scripts + enterMethod(); + switch( nIdentifier ) + { + case vba::VBAScriptEventId::SCRIPT_STARTED: + ++mnRunningVBAScripts; + break; + case vba::VBAScriptEventId::SCRIPT_STOPPED: + --mnRunningVBAScripts; + break; + } + leaveMethod(); + + Reference< XModel > xModel = mxOwnerDocument; // weak-ref -> ref + Reference< XInterface > xSender( xModel, UNO_QUERY_THROW ); + vba::VBAScriptEvent aEvent( xSender, nIdentifier, rModuleName ); + maVBAScriptListeners.notify( aEvent ); +} + // Methods XServiceInfo ::sal_Bool SAL_CALL SfxLibraryContainer::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException) @@ -2941,7 +3019,9 @@ Any SAL_CALL SfxLibrary::queryInterface( const Type& rType ) aRet = Any( ::cppu::queryInterface( rType, static_cast< XContainer * >( this ), static_cast< XNameContainer * >( this ), - static_cast< XNameAccess * >( this ) ) ); + static_cast< XNameAccess * >( this ), + static_cast< XElementAccess * >( this ), + static_cast< XChangesNotifier * >( this ) ) ); //} if( !aRet.hasValue() ) aRet = OComponentHelper::queryInterface( rType ); @@ -3083,6 +3163,7 @@ Sequence< Type > SfxLibrary::getTypes() static OTypeCollection s_aTypes_NameContainer( ::getCppuType( (const Reference< XNameContainer > *)0 ), ::getCppuType( (const Reference< XContainer > *)0 ), + ::getCppuType( (const Reference< XChangesNotifier > *)0 ), OComponentHelper::getTypes() ); s_pTypes_NameContainer = &s_aTypes_NameContainer; } @@ -3110,9 +3191,6 @@ Sequence< sal_Int8 > SfxLibrary::getImplementationId() } } - -//============================================================================ - // Methods XContainer void SAL_CALL SfxLibrary::addContainerListener( const Reference< XContainerListener >& xListener ) throw (RuntimeException) @@ -3127,6 +3205,19 @@ void SAL_CALL SfxLibrary::removeContainerListener( const Reference< XContainerLi maNameContainer.removeContainerListener( xListener ); } +// Methods XChangesNotifier +void SAL_CALL SfxLibrary::addChangesListener( const Reference< XChangesListener >& xListener ) + throw (RuntimeException) +{ + maNameContainer.setEventSource( static_cast< XInterface* >( (OWeakObject*)this ) ); + maNameContainer.addChangesListener( xListener ); +} + +void SAL_CALL SfxLibrary::removeChangesListener( const Reference< XChangesListener >& xListener ) + throw (RuntimeException) +{ + maNameContainer.removeChangesListener( xListener ); +} //============================================================================ // Implementation class ScriptExtensionIterator diff --git a/basic/util/makefile.mk b/basic/util/makefile.mk index 31a4dcca8f8b..ae4456cbc923 100644 --- a/basic/util/makefile.mk +++ b/basic/util/makefile.mk @@ -66,6 +66,9 @@ SHL1STDLIBS= \ $(VOSLIB) \ $(XMLSCRIPTLIB) +# Uncomment the following line if DBG_TRACE_PROFILING is active in source/inc/sbtrace.hxx +# SHL1STDLIBS+=$(CANVASTOOLSLIB) + .IF "$(SOLAR_JAVA)" != "TRUE" SHL1STDLIBS+=$(SJLIB) .ENDIF diff --git a/comphelper/inc/comphelper/servicedecl.hxx b/comphelper/inc/comphelper/servicedecl.hxx index 5ea7972e29a2..a7d51824f7c0 100644 --- a/comphelper/inc/comphelper/servicedecl.hxx +++ b/comphelper/inc/comphelper/servicedecl.hxx @@ -27,26 +27,17 @@ #if ! defined(COMPHELPER_SERVICEDECL_HXX_INCLUDED) #define COMPHELPER_SERVICEDECL_HXX_INCLUDED -#if ! defined(INCLUDED_COMPHELPERDLLAPI_H) -#include "comphelper/comphelperdllapi.h" -#endif -#if ! defined(_CPPUHELPER_IMPLBASE1_HXX_) -#include "cppuhelper/implbase1.hxx" -#endif -#if ! defined(_COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_) -#include "com/sun/star/uno/XComponentContext.hpp" -#endif -#if ! defined(_COM_SUN_STAR_LANG_XSERVICEINFO_HPP_) -#include "com/sun/star/lang/XServiceInfo.hpp" -#endif -#if ! defined(_COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_) -#include "com/sun/star/registry/XRegistryKey.hpp" -#endif -#include "boost/utility.hpp" -#include "boost/function.hpp" -#include "boost/preprocessor/cat.hpp" -#include "boost/preprocessor/repetition.hpp" -#include "boost/preprocessor/seq/enum.hpp" +#include <comphelper/comphelperdllapi.h> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <uno/environment.h> +#include <boost/utility.hpp> +#include <boost/function.hpp> +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/repetition.hpp> +#include <boost/preprocessor/seq/enum.hpp> namespace comphelper { namespace service_decl { diff --git a/comphelper/inc/comphelper/storagehelper.hxx b/comphelper/inc/comphelper/storagehelper.hxx index 9d44b42e9514..92a2411d6441 100644 --- a/comphelper/inc/comphelper/storagehelper.hxx +++ b/comphelper/inc/comphelper/storagehelper.hxx @@ -44,6 +44,7 @@ #define ZIP_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) ) #define OFOPXML_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) ) +#define PACKAGE_ENCRYPTIONDATA_SHA256UTF8 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA256UTF8EncryptionKey" ) ) #define PACKAGE_ENCRYPTIONDATA_SHA1UTF8 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1UTF8EncryptionKey" ) ) #define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1MS1252EncryptionKey" ) ) @@ -164,7 +165,10 @@ public: throw ( ::com::sun::star::uno::Exception ); static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > - CreatePackageEncryptionData( const ::rtl::OUString& aPassword ); + CreatePackageEncryptionData( + const ::rtl::OUString& aPassword, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); static sal_Bool IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed ); static sal_Bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, sal_Bool bSlashAllowed ); diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx index 60ffa965fcf1..9b4e7a15cfca 100644 --- a/comphelper/source/misc/storagehelper.cxx +++ b/comphelper/source/misc/storagehelper.cxx @@ -34,6 +34,9 @@ #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/IllegalTypeException.hpp> +#include <com/sun/star/xml/crypto/XDigestContext.hpp> +#include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> #include <rtl/digest.h> @@ -422,18 +425,42 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromStream( } // ---------------------------------------------------------------------- -uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( const ::rtl::OUString& aPassword ) +uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( const ::rtl::OUString& aPassword, const uno::Reference< lang::XMultiServiceFactory >& xSF ) { // TODO/LATER: Should not the method be part of DocPasswordHelper? uno::Sequence< beans::NamedValue > aEncryptionData; + sal_Int32 nSha1Ind = 0; if ( aPassword.getLength() ) { + // generate SHA256 start key + try + { + uno::Reference< lang::XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory(); + if ( !xFactory.is() ) + throw uno::RuntimeException(); + + uno::Reference< xml::crypto::XDigestContextSupplier > xDigestContextSupplier( xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ), uno::UNO_QUERY_THROW ); + uno::Reference< xml::crypto::XDigestContext > xDigestContext( xDigestContextSupplier->getDigestContext( xml::crypto::DigestID::SHA256, uno::Sequence< beans::NamedValue >() ), uno::UNO_SET_THROW ); + + ::rtl::OString aUTF8Password( ::rtl::OUStringToOString( aPassword, RTL_TEXTENCODING_UTF8 ) ); + xDigestContext->updateDigest( uno::Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aUTF8Password.getStr() ), aUTF8Password.getLength() ) ); + uno::Sequence< sal_Int8 > aDigest = xDigestContext->finalizeDigestAndDispose(); + + aEncryptionData.realloc( ++nSha1Ind ); + aEncryptionData[0].Name = PACKAGE_ENCRYPTIONDATA_SHA256UTF8; + aEncryptionData[0].Value <<= aDigest; + } + catch ( uno::Exception& ) + { + OSL_ENSURE( false, "Can not create SHA256 digest!" ); + } + // MS_1252 encoding was used for SO60 document format password encoding, // this encoding supports only a minor subset of nonascii characters, // but for compatibility reasons it has to be used for old document formats - aEncryptionData.realloc( 2 ); - aEncryptionData[0].Name = PACKAGE_ENCRYPTIONDATA_SHA1UTF8; - aEncryptionData[1].Name = PACKAGE_ENCRYPTIONDATA_SHA1MS1252; + aEncryptionData.realloc( nSha1Ind + 2 ); + aEncryptionData[nSha1Ind].Name = PACKAGE_ENCRYPTIONDATA_SHA1UTF8; + aEncryptionData[nSha1Ind + 1].Name = PACKAGE_ENCRYPTIONDATA_SHA1MS1252; rtl_TextEncoding pEncoding[2] = { RTL_TEXTENCODING_UTF8, RTL_TEXTENCODING_MS_1252 }; @@ -449,11 +476,11 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( if ( nError != rtl_Digest_E_None ) { - aEncryptionData.realloc( 0 ); + aEncryptionData.realloc( nSha1Ind ); break; } - aEncryptionData[nInd].Value <<= uno::Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 ); + aEncryptionData[nSha1Ind+nInd].Value <<= uno::Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 ); } } diff --git a/configure.in b/configure.in index 99f2d63cc307..10dcbb3cba17 100644 --- a/configure.in +++ b/configure.in @@ -3042,16 +3042,18 @@ _ACEOF if test "$JDK" != "gcj" -o "$_gij_longver" -ge "40200"; then # check if JAVA_HOME was (maybe incorrectly?) set automatically to /usr if test "$JAVA_HOME" = "/usr" -a "x$with_jdk_home" = "x"; then - - if basename $(readlink $(readlink $JAVACOMPILER)) >/dev/null 2>/dev/null; then + javac_link_f=`readlink -f "$JAVACOMPILER" 2>/dev/null` + if test $? == 0 && test "$JAVACOMPILER" != "$javac_link_f"; then # try to recover first by looking whether we have a alternatives # system as in Debian or newer SuSEs where following /usr/bin/javac # over /etc/alternatives/javac leads to the right bindir where we # just need to strip a bit away to get a valid JAVA_HOME - JAVA_HOME=$(readlink $(readlink $JAVACOMPILER)) + # Solaris 11 is even worse, because target is relative, so use -f + JAVA_HOME="$javac_link_f" elif readlink $JAVACOMPILER >/dev/null 2>/dev/null; then - # maybe only one level of symlink (e.g. on Mac) - JAVA_HOME=$(readlink $JAVACOMPILER) + # Darwin readlink(1) is so primitive it doesn't even support -f + # maybe only one level of symlink (e.g. on Mac) + JAVA_HOME=`readlink $JAVACOMPILER` else # else warn AC_MSG_WARN([JAVA_HOME is set to /usr - this is very likely to be incorrect]) @@ -5475,7 +5477,12 @@ fi dnl We also need to check for --with-gnu-cp if test -z "$with_gnu_cp"; then - AC_PATH_PROGS(GNUCP, gnucp cp) + # check the place where the good stuff is hidden on Solaris... + if test -x /usr/gnu/bin/cp; then + GNUCP=/usr/gnu/bin/cp + else + AC_PATH_PROGS(GNUCP, gnucp cp) + fi if test -z $GNUCP; then AC_MSG_ERROR([Neither gnucp nor cp found. Install GNU cp and/or specify --with-gnu-cp=/path/to/it]) fi @@ -5754,6 +5761,7 @@ if test "$test_gtk" = "yes"; then if test "$ENABLE_GTK" = "TRUE" ; then PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.4 gdk-pixbuf-xlib-2.0 >= 2.2 ,,AC_MSG_ERROR([requirements to build the gtk-plugin not met. Use --disable-gtk or install the missing packages])) + PKG_CHECK_MODULES(GTHREAD, gthread-2.0,,AC_MSG_ERROR([requirements to build the gtk-plugin not met. Use --disable-gtk or install the missing packages])) BUILD_TYPE="$BUILD_TYPE GTK" if test "x$enable_systray" = "xyes"; then @@ -5790,6 +5798,8 @@ AC_SUBST(ENABLE_DBUS) AC_SUBST(ENABLE_SYSTRAY_GTK) AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) +AC_SUBST(GTHREAD_CFLAGS) +AC_SUBST(GTHREAD_LIBS) dnl =================================================================== dnl Check whether the GStreamer libraries are available. @@ -7013,7 +7023,11 @@ if test "$ANT_HOME" != "NO_ANT_HOME"; then if test -f $ANT_HOME/lib/ant/ant.jar; then ANT_LIB="$ANT_HOME/lib/ant" else - AC_MSG_ERROR([Ant libraries not found!]) + if test -f /usr/share/lib/ant/ant.jar; then + ANT_LIB=/usr/share/lib/ant + else + AC_MSG_ERROR([Ant libraries not found!]) + fi fi fi fi @@ -7100,7 +7114,11 @@ if test "$SOLAR_JAVA" != "" && test "$with_junit" != "no"; then if test -e /usr/share/java/junit4.jar; then OOO_JUNIT_JAR=/usr/share/java/junit4.jar else - OOO_JUNIT_JAR=/usr/share/java/junit.jar + if test -e /usr/share/lib/java/junit.jar; then + OOO_JUNIT_JAR=/usr/share/lib/java/junit.jar + else + OOO_JUNIT_JAR=/usr/share/java/junit.jar + fi fi else OOO_JUNIT_JAR=$with_junit diff --git a/desktop/source/deployment/dp_services.cxx b/desktop/source/deployment/dp_services.cxx index f3dc75ae39c5..c302d1d1cc42 100644 --- a/desktop/source/deployment/dp_services.cxx +++ b/desktop/source/deployment/dp_services.cxx @@ -84,8 +84,6 @@ bool singleton_entries( uno::Reference<registry::XRegistryKey> const& ); extern "C" { -struct uno_Environment; - void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** ) { diff --git a/filter/inc/filter/msfilter/msvbahelper.hxx b/filter/inc/filter/msfilter/msvbahelper.hxx index 94ece293ee20..05c9f0b122ed 100644 --- a/filter/inc/filter/msfilter/msvbahelper.hxx +++ b/filter/inc/filter/msfilter/msvbahelper.hxx @@ -50,6 +50,8 @@ struct MSFILTER_DLLPUBLIC MacroResolvedInfo MSFILTER_DLLPUBLIC String makeMacroURL( const String& sMacroName ); MSFILTER_DLLPUBLIC ::rtl::OUString extractMacroName( const ::rtl::OUString& rMacroUrl ); +MSFILTER_DLLPUBLIC ::rtl::OUString getDefaultProjectName( SfxObjectShell* pShell ); +MSFILTER_DLLPUBLIC ::rtl::OUString resolveVBAMacro( SfxObjectShell* pShell, const ::rtl::OUString& rLibName, const ::rtl::OUString& rModuleName, const ::rtl::OUString& rMacroName ); MSFILTER_DLLPUBLIC MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const ::rtl::OUString& rMacroName, bool bSearchGlobalTemplates = false ); MSFILTER_DLLPUBLIC sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArgs, com::sun::star::uno::Any& aRet, const com::sun::star::uno::Any& aCaller ); diff --git a/filter/source/msfilter/msvbahelper.cxx b/filter/source/msfilter/msvbahelper.cxx index 02fa3d60e248..415007c46aea 100644 --- a/filter/source/msfilter/msvbahelper.cxx +++ b/filter/source/msfilter/msvbahelper.cxx @@ -37,6 +37,7 @@ #include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/document/XDocumentInfoSupplier.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/script/ModuleType.hpp> #include <tools/urlobj.hxx> #include <osl/file.hxx> #include <unotools/pathoptions.hxx> @@ -170,6 +171,7 @@ SfxObjectShell* findShellForUrl( const rtl::OUString& sMacroURLOrPath ) // sMod can be empty ( but we really need the library to search in ) // if sMod is empty and a macro is found then sMod is updated +// if sMod is empty, only standard modules will be searched (no class, document, form modules) bool hasMacro( SfxObjectShell* pShell, const String& sLibrary, String& sMod, const String& sMacro ) { bool bFound = false; @@ -209,8 +211,12 @@ bool hasMacro( SfxObjectShell* pShell, const String& sLibrary, String& sMod, con { if( SbModule* pModule = pMethod->GetModule() ) { - sMod = pModule->GetName(); - bFound = true; + // when searching for a macro without module name, do not search in class/document/form modules + if( pModule->GetModuleType() == script::ModuleType::NORMAL ) + { + sMod = pModule->GetName(); + bFound = true; + } } } } @@ -218,6 +224,19 @@ bool hasMacro( SfxObjectShell* pShell, const String& sLibrary, String& sMod, con } return bFound; } + +::rtl::OUString getDefaultProjectName( SfxObjectShell* pShell ) +{ + ::rtl::OUString aPrjName; + if( BasicManager* pBasicMgr = pShell ? pShell->GetBasicManager() : 0 ) + { + aPrjName = pBasicMgr->GetName(); + if( aPrjName.getLength() == 0 ) + aPrjName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); + } + return aPrjName; +} + void parseMacro( const rtl::OUString& sMacro, String& sContainer, String& sModule, String& sProcedure ) { sal_Int32 nMacroDot = sMacro.lastIndexOf( '.' ); @@ -239,6 +258,18 @@ void parseMacro( const rtl::OUString& sMacro, String& sContainer, String& sModul sProcedure = sMacro; } +::rtl::OUString resolveVBAMacro( SfxObjectShell* pShell, const ::rtl::OUString& rLibName, const ::rtl::OUString& rModuleName, const ::rtl::OUString& rMacroName ) +{ + if( pShell ) + { + ::rtl::OUString aLibName = (rLibName.getLength() > 0) ? rLibName : getDefaultProjectName( pShell ); + String aModuleName = rModuleName; + if( hasMacro( pShell, aLibName, aModuleName, rMacroName ) ) + return ::rtl::OUStringBuffer( aLibName ).append( sal_Unicode( '.' ) ).append( aModuleName ).append( sal_Unicode( '.' ) ).append( rMacroName ).makeStringAndClear(); + } + return ::rtl::OUString(); +} + MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& MacroName, bool bSearchGlobalTemplates ) { if( !pShell ) @@ -282,18 +313,27 @@ MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& // macro format = Container.Module.Procedure String sContainer, sModule, sProcedure; parseMacro( aMacroName, sContainer, sModule, sProcedure ); - uno::Reference< container::XNameContainer > xPrjNameCache; +#if 0 // As long as service VBAProjectNameProvider isn't supported in the model, disable the createInstance call // (the ServiceNotRegisteredException is wrongly caught in ScModelObj::createInstance) - //uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY); - //if ( xSF.is() ) - // xPrjNameCache.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAProjectNameProvider" ) ) ), uno::UNO_QUERY ); + uno::Reference< container::XNameContainer > xPrjNameCache; + uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY); + if ( xSF.is() ) try + { + xPrjNameCache.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAProjectNameProvider" ) ) ), uno::UNO_QUERY ); + } + catch( uno::Exception& ) // createInstance may throw + { + } +#endif std::vector< rtl::OUString > sSearchList; if ( sContainer.Len() > 0 ) { +// service VBAProjectNameProvider not implemented +#if 0 // get the Project associated with the Container if ( xPrjNameCache.is() ) { @@ -304,22 +344,18 @@ MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& sContainer = sProject; } } +#endif sSearchList.push_back( sContainer ); // First Lib to search } else { // Ok, if we have no Container specified then we need to search them in order, this document, template this document created from, global templates, // get the name of Project/Library for 'this' document - rtl::OUString sThisProject; - BasicManager* pBasicMgr = pShell-> GetBasicManager(); - if ( pBasicMgr ) - { - if ( pBasicMgr->GetName().Len() ) - sThisProject = pBasicMgr->GetName(); - else // cater for the case where VBA is not enabled - sThisProject = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") ); - } + rtl::OUString sThisProject = getDefaultProjectName( pShell ); sSearchList.push_back( sThisProject ); // First Lib to search + +// service VBAProjectNameProvider not implemented +#if 0 if ( xPrjNameCache.is() ) { // is this document created from a template? @@ -376,7 +412,9 @@ MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& } } +#endif } + std::vector< rtl::OUString >::iterator it_end = sSearchList.end(); for ( std::vector< rtl::OUString >::iterator it = sSearchList.begin(); !aRes.mbFound && (it != it_end); ++it ) { diff --git a/framework/Library_fwe.mk b/framework/Library_fwe.mk index 5d30d108cde6..408a514c2f06 100644 --- a/framework/Library_fwe.mk +++ b/framework/Library_fwe.mk @@ -83,8 +83,6 @@ $(eval $(call gb_Library_add_exception_objects,fwe,\ framework/source/fwe/interaction/preventduplicateinteraction \ framework/source/fwe/xml/eventsconfiguration \ framework/source/fwe/xml/eventsdocumenthandler \ - framework/source/fwe/xml/imagesconfiguration \ - framework/source/fwe/xml/imagesdocumenthandler \ framework/source/fwe/xml/menuconfiguration \ framework/source/fwe/xml/menudocumenthandler \ framework/source/fwe/xml/saxnamespacefilter \ diff --git a/framework/Library_fwk.mk b/framework/Library_fwk.mk index a34a1bc59720..3953d129afc2 100644 --- a/framework/Library_fwk.mk +++ b/framework/Library_fwk.mk @@ -183,6 +183,8 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\ framework/source/uifactory/windowcontentfactorymanager \ framework/source/xml/acceleratorconfigurationreader \ framework/source/xml/acceleratorconfigurationwriter \ + framework/source/xml/imagesconfiguration \ + framework/source/xml/imagesdocumenthandler \ )) # vim: set noet sw=4 ts=4: diff --git a/framework/Package_inc.mk b/framework/Package_inc.mk index 6d1c03a5975b..d72dd52128b8 100644 --- a/framework/Package_inc.mk +++ b/framework/Package_inc.mk @@ -39,7 +39,6 @@ $(eval $(call gb_Package_add_file,framework_inc,inc/framework/undomanagerhelper. $(eval $(call gb_Package_add_file,framework_inc,inc/framework/imutex.hxx,framework/imutex.hxx)) $(eval $(call gb_Package_add_file,framework_inc,inc/framework/iguard.hxx,framework/iguard.hxx)) $(eval $(call gb_Package_add_file,framework_inc,inc/framework/imageproducer.hxx,framework/imageproducer.hxx)) -$(eval $(call gb_Package_add_file,framework_inc,inc/framework/imagesconfiguration.hxx,framework/imagesconfiguration.hxx)) $(eval $(call gb_Package_add_file,framework_inc,inc/framework/interaction.hxx,framework/interaction.hxx)) $(eval $(call gb_Package_add_file,framework_inc,inc/framework/menuconfiguration.hxx,framework/menuconfiguration.hxx)) $(eval $(call gb_Package_add_file,framework_inc,inc/framework/menuextensionsupplier.hxx,framework/menuextensionsupplier.hxx)) diff --git a/framework/inc/framework/imagesconfiguration.hxx b/framework/inc/xml/imagesconfiguration.hxx index 0771e2d8f7f1..3174e6d51b22 100644 --- a/framework/inc/framework/imagesconfiguration.hxx +++ b/framework/inc/xml/imagesconfiguration.hxx @@ -25,8 +25,8 @@ * ************************************************************************/ -#ifndef __FRAMEWORK_XML_IMAGESCONFIGURATION_HXX_ -#define __FRAMEWORK_XML_IMAGESCONFIGURATION_HXX_ +#ifndef FRAMEWORK_XML_IMAGESCONFIGURATION_HXX_ +#define FRAMEWORK_XML_IMAGESCONFIGURATION_HXX_ #include <framework/fwedllapi.h> #include <svl/svarray.hxx> @@ -50,7 +50,7 @@ enum ImageMaskMode ImageMaskMode_Bitmap }; -struct FWE_DLLPUBLIC ImageItemDescriptor +struct ImageItemDescriptor { ImageItemDescriptor() : nIndex( -1 ) {} @@ -58,7 +58,7 @@ struct FWE_DLLPUBLIC ImageItemDescriptor long nIndex; // index of the bitmap inside the bitmaplist }; -struct FWE_DLLPUBLIC ExternalImageItemDescriptor +struct ExternalImageItemDescriptor { String aCommandURL; // URL command to dispatch String aURL; // a URL to an external bitmap @@ -70,7 +70,7 @@ SV_DECL_PTRARR_DEL( ImageItemListDescriptor, ImageItemDescriptorPtr, 10, 2) typedef ExternalImageItemDescriptor* ExternalImageItemDescriptorPtr; SV_DECL_PTRARR_DEL( ExternalImageItemListDescriptor, ExternalImageItemDescriptorPtr, 10, 2) -struct FWE_DLLPUBLIC ImageListItemDescriptor +struct ImageListItemDescriptor { ImageListItemDescriptor() : nMaskMode( ImageMaskMode_Color ), pImageItemList( 0 ) {} @@ -89,7 +89,7 @@ struct FWE_DLLPUBLIC ImageListItemDescriptor typedef ImageListItemDescriptor* ImageListItemDescriptorPtr; SV_DECL_PTRARR_DEL( ImageListDescriptor, ImageListItemDescriptorPtr, 10, 2) -struct FWE_DLLPUBLIC ImageListsDescriptor +struct ImageListsDescriptor { ImageListsDescriptor() : pImageList( 0 ), pExternalImageList( 0 ) {} @@ -99,7 +99,7 @@ struct FWE_DLLPUBLIC ImageListsDescriptor ExternalImageItemListDescriptor* pExternalImageList; }; -class FWE_DLLPUBLIC ImagesConfiguration +class ImagesConfiguration { public: // #110897# diff --git a/framework/inc/xml/imagesdocumenthandler.hxx b/framework/inc/xml/imagesdocumenthandler.hxx index 59d1e4abdb3a..dd6201b5b9e3 100644 --- a/framework/inc/xml/imagesdocumenthandler.hxx +++ b/framework/inc/xml/imagesdocumenthandler.hxx @@ -25,8 +25,8 @@ * ************************************************************************/ -#ifndef __FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_ -#define __FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_ +#ifndef FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_ +#define FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_ #include <framework/fwedllapi.h> @@ -34,14 +34,12 @@ // interface includes //_________________________________________________________________________________________________________________ -#ifndef __COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_ #include <com/sun/star/xml/sax/XDocumentHandler.hpp> -#endif //_________________________________________________________________________________________________________________ // other includes //_________________________________________________________________________________________________________________ -#include <framework/imagesconfiguration.hxx> +#include <xml/imagesconfiguration.hxx> #include <threadhelp/threadhelpbase.hxx> #include <rtl/ustring.hxx> #include <cppuhelper/implbase1.hxx> @@ -59,7 +57,7 @@ namespace framework{ //***************************************************************************************************************** // Hash code function for using in all hash maps of follow implementation. -class FWE_DLLPUBLIC OReadImagesDocumentHandler : private ThreadHelpBase, // Struct for right initalization of lock member! Must be first of baseclasses. +class OReadImagesDocumentHandler : private ThreadHelpBase, // Struct for right initalization of lock member! Must be first of baseclasses. public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler > { public: @@ -160,7 +158,7 @@ class FWE_DLLPUBLIC OReadImagesDocumentHandler : private ThreadHelpBase, // S ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > m_xLocator; }; -class FWE_DLLPUBLIC OWriteImagesDocumentHandler : private ThreadHelpBase // Struct for right initalization of lock member! Must be first of baseclasses. +class OWriteImagesDocumentHandler : private ThreadHelpBase // Struct for right initalization of lock member! Must be first of baseclasses. { public: OWriteImagesDocumentHandler( diff --git a/framework/source/uiconfiguration/imagemanager.cxx b/framework/source/uiconfiguration/imagemanager.cxx index 2a57e72e1ce4..776af9982de4 100644 --- a/framework/source/uiconfiguration/imagemanager.cxx +++ b/framework/source/uiconfiguration/imagemanager.cxx @@ -27,9 +27,10 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_framework.hxx" + #include <uiconfiguration/imagemanager.hxx> #include <threadhelp/resetableguard.hxx> -#include <framework/imagesconfiguration.hxx> +#include <xml/imagesconfiguration.hxx> #include <uiconfiguration/graphicnameaccess.hxx> #include <services.h> #include "imagemanagerimpl.hxx" diff --git a/framework/source/uiconfiguration/imagemanagerimpl.cxx b/framework/source/uiconfiguration/imagemanagerimpl.cxx index 537fe623d633..d0caee82297e 100755 --- a/framework/source/uiconfiguration/imagemanagerimpl.cxx +++ b/framework/source/uiconfiguration/imagemanagerimpl.cxx @@ -27,9 +27,10 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_framework.hxx" + #include <imagemanagerimpl.hxx> #include <threadhelp/resetableguard.hxx> -#include <framework/imagesconfiguration.hxx> +#include <xml/imagesconfiguration.hxx> #include <uiconfiguration/graphicnameaccess.hxx> #include <services.h> diff --git a/framework/source/uiconfiguration/moduleimagemanager.cxx b/framework/source/uiconfiguration/moduleimagemanager.cxx index fc90dd102912..0e0f828a253f 100644 --- a/framework/source/uiconfiguration/moduleimagemanager.cxx +++ b/framework/source/uiconfiguration/moduleimagemanager.cxx @@ -27,10 +27,11 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_framework.hxx" + #include <rtl/logfile.hxx> #include <uiconfiguration/moduleimagemanager.hxx> #include <threadhelp/resetableguard.hxx> -#include <framework/imagesconfiguration.hxx> +#include <xml/imagesconfiguration.hxx> #include <uiconfiguration/graphicnameaccess.hxx> #include <services.h> #include "imagemanagerimpl.hxx" diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx index fd8e0d3fbcd7..9df04fa17ab4 100644 --- a/framework/source/uielement/menubarmanager.cxx +++ b/framework/source/uielement/menubarmanager.cxx @@ -134,16 +134,20 @@ static const char ITEM_DESCRIPTOR_LABEL[] = "Label"; static const char ITEM_DESCRIPTOR_TYPE[] = "Type"; static const char ITEM_DESCRIPTOR_MODULEIDENTIFIER[] = "ModuleIdentifier"; static const char ITEM_DESCRIPTOR_DISPATCHPROVIDER[] = "DispatchProvider"; -static const char ITEM_DESCRIPTOR_STYLE[] = "Style"; - -const sal_Int32 LEN_DESCRIPTOR_COMMANDURL = 10; -const sal_Int32 LEN_DESCRIPTOR_HELPURL = 7; -const sal_Int32 LEN_DESCRIPTOR_CONTAINER = 23; -const sal_Int32 LEN_DESCRIPTOR_LABEL = 5; -const sal_Int32 LEN_DESCRIPTOR_TYPE = 4; -const sal_Int32 LEN_DESCRIPTOR_MODULEIDENTIFIER = 16; -const sal_Int32 LEN_DESCRIPTOR_DISPATCHPROVIDER = 16; -static const sal_Int32 ITEM_DESCRIPTOR_STYLE_LEN = 5; +static const char ITEM_DESCRIPTOR_STYLE[] = "Style"; +static const char ITEM_DESCRIPTOR_ISVISIBLE[] = "IsVisible"; +static const char ITEM_DESCRIPTOR_ENABLED[] = "Enabled"; + +static const sal_Int32 LEN_DESCRIPTOR_COMMANDURL = 10; +static const sal_Int32 LEN_DESCRIPTOR_HELPURL = 7; +static const sal_Int32 LEN_DESCRIPTOR_CONTAINER = 23; +static const sal_Int32 LEN_DESCRIPTOR_LABEL = 5; +static const sal_Int32 LEN_DESCRIPTOR_TYPE = 4; +static const sal_Int32 LEN_DESCRIPTOR_MODULEIDENTIFIER = 16; +static const sal_Int32 LEN_DESCRIPTOR_DISPATCHPROVIDER = 16; +static const sal_Int32 LEN_DESCRIPTOR_STYLE = 5; +static const sal_Int32 LEN_DESCRIPTOR_ISVISIBLE = 9; +static const sal_Int32 LEN_DESCRIPTOR_ENABLED = 7; const sal_uInt16 ADDONMENU_MERGE_ITEMID_START = 1500; @@ -1757,6 +1761,8 @@ void MenuBarManager::FillMenu( rtl::OUString aLabel; rtl::OUString aHelpURL; rtl::OUString aModuleIdentifier( rModuleIdentifier ); + sal_Bool bShow(sal_True); + sal_Bool bEnabled(sal_True); sal_uInt16 nType = 0; Reference< XIndexAccess > xIndexContainer; Reference< XDispatchProvider > xDispatchProvider( rDispatchProvider ); @@ -1768,29 +1774,26 @@ void MenuBarManager::FillMenu( for ( int i = 0; i < aProp.getLength(); i++ ) { rtl::OUString aPropName = aProp[i].Name; - if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_COMMANDURL, - LEN_DESCRIPTOR_COMMANDURL )) + if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_COMMANDURL, LEN_DESCRIPTOR_COMMANDURL )) aProp[i].Value >>= aCommandURL; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_HELPURL, - LEN_DESCRIPTOR_HELPURL )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_HELPURL, LEN_DESCRIPTOR_HELPURL )) aProp[i].Value >>= aHelpURL; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_CONTAINER, - LEN_DESCRIPTOR_CONTAINER )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_CONTAINER, LEN_DESCRIPTOR_CONTAINER )) aProp[i].Value >>= xIndexContainer; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_LABEL, - LEN_DESCRIPTOR_LABEL )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_LABEL, LEN_DESCRIPTOR_LABEL )) aProp[i].Value >>= aLabel; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_TYPE, - LEN_DESCRIPTOR_TYPE )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_TYPE, LEN_DESCRIPTOR_TYPE )) aProp[i].Value >>= nType; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_MODULEIDENTIFIER, - LEN_DESCRIPTOR_MODULEIDENTIFIER )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_MODULEIDENTIFIER, LEN_DESCRIPTOR_MODULEIDENTIFIER )) aProp[i].Value >>= aModuleIdentifier; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_DISPATCHPROVIDER, - LEN_DESCRIPTOR_DISPATCHPROVIDER )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_DISPATCHPROVIDER, LEN_DESCRIPTOR_DISPATCHPROVIDER )) aProp[i].Value >>= xDispatchProvider; - else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_STYLE, ITEM_DESCRIPTOR_STYLE_LEN )) + else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_STYLE, LEN_DESCRIPTOR_STYLE )) aProp[i].Value >>= nStyle; + else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_ISVISIBLE, LEN_DESCRIPTOR_ISVISIBLE )) + aProp[i].Value >>= bShow; + else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_ENABLED, LEN_DESCRIPTOR_ENABLED )) + aProp[i].Value >>= bEnabled; } if ( nType == ::com::sun::star::ui::ItemType::DEFAULT ) @@ -1809,6 +1812,13 @@ void MenuBarManager::FillMenu( nBits |= MIB_RADIOCHECK; pMenu->SetItemBits( nId, nBits ); } + + if ( !bShow ) + pMenu->HideItem( nId ); + + if ( !bEnabled) + pMenu->EnableItem( nId, sal_False ); + if ( xIndexContainer.is() ) { PopupMenu* pNewPopupMenu = new PopupMenu; diff --git a/framework/source/fwe/xml/imagesconfiguration.cxx b/framework/source/xml/imagesconfiguration.cxx index d561a76d5995..946b5b9d0f11 100644 --- a/framework/source/fwe/xml/imagesconfiguration.cxx +++ b/framework/source/xml/imagesconfiguration.cxx @@ -27,12 +27,11 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_framework.hxx" -#include <framework/imagesconfiguration.hxx> + +#include <xml/imagesconfiguration.hxx> #include <services.h> -#ifndef __FRAMEWORK_CLASSES_IMAGESDOCUMENTHANDLER_HXX_ #include <xml/imagesdocumenthandler.hxx> -#endif #include <xml/saxnamespacefilter.hxx> //_________________________________________________________________________________________________________________ diff --git a/framework/source/fwe/xml/imagesdocumenthandler.cxx b/framework/source/xml/imagesdocumenthandler.cxx index cdf20958332a..cdf20958332a 100644 --- a/framework/source/fwe/xml/imagesdocumenthandler.cxx +++ b/framework/source/xml/imagesdocumenthandler.cxx diff --git a/gdk-pixbuf/gdk-pixbuf-2.23.0-win32.patch b/gdk-pixbuf/gdk-pixbuf-2.23.0-win32.patch index 2677ef0ca1c7..3c56febbad6b 100644 --- a/gdk-pixbuf/gdk-pixbuf-2.23.0-win32.patch +++ b/gdk-pixbuf/gdk-pixbuf-2.23.0-win32.patch @@ -197,7 +197,7 @@ @@ -1,9 +1,19 @@ -TOP = ..\.. PRJ_TOP = .. -+GLIB_TOP = $(PRJ_TOP)\..\..\..\..\..\glib\wntmsci12.pro\misc\build\glib-2.28.1 ++GLIB_TOP = PACKAGE = gdk_pixbuf PKG_VER = $(GDK_PIXBUF_VER) +GLIB_INC = -I$(OUTDIR)\inc\external\glib-2.0 @@ -212,7 +212,7 @@ +GDIPLUS_LIB = gdiplus.lib -!INCLUDE $(TOP)/glib/build/win32/make.msc -+!INCLUDE $(GLIB_TOP)\build\win32\make.msc ++!INCLUDE $(OUTDIR)\inc\external\glib-2.0\make.msc !IFNDEF PERL PERL = perl @@ -270,11 +270,11 @@ gdk-pixbuf-marshal.h: gdk-pixbuf-marshal.list - ..\..\glib\gobject\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --header >gdk-pixbuf-marshal.h -+ $(GLIB_TOP)\glib\gobject\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --header >gdk-pixbuf-marshal.h ++ $(OUTDIR)\bin\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --header >gdk-pixbuf-marshal.h gdk-pixbuf-marshal.c: gdk-pixbuf-marshal.h gdk-pixbuf-marshal.list - ..\..\glib\gobject\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --body >gdk-pixbuf-marshal.c -+ $(GLIB_TOP)\glib\gobject\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --body >gdk-pixbuf-marshal.c ++ $(OUTDIR)\bin\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --body >gdk-pixbuf-marshal.c -gdk-pixbuf-alias.h: gdk-pixbuf.symbols - perl makegdkpixbufalias.pl < gdk-pixbuf.symbols > gdk-pixbuf-alias.h @@ -333,7 +333,7 @@ # gdk-pixbuf-enum-types.h : $(gdk_pixbuf_headers) makefile.msc - $(PERL) $(GLIB)\gobject\glib-mkenums \ -+ $(PERL) $(PRJ_TOP)\glib-mkenums.pl \ ++ $(PERL) $(OUTDIR)\bin\glib-mkenums \ --fhead "#ifndef __GDK_PIXBUF__ENUM_TYPES_H__\n#define __GDK_PIXBUF_ENUM_TYPES_H__\n" \ --fprod "/* enumerations from \"@filename@\" */\n" \ --vhead "GType @enum_name@_get_type (void);\n#define GDK_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \ @@ -343,7 +343,7 @@ gdk-pixbuf-enum-types.c: $(gdk_pixbuf_headers) makefile.msc - $(PERL) $(GLIB)\gobject\glib-mkenums \ - --fhead "#include <gdk-pixbuf/gdk-pixbuf.h>" \ -+ $(PERL) $(PRJ_TOP)\glib-mkenums.pl \ ++ $(PERL) $(OUTDIR)\bin\glib-mkenums \ + --fhead "#include <gdk-pixbuf.h>" \ --fprod "\n/* enumerations from \"@filename@\" */" \ --vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \ @@ -370,11 +370,11 @@ -PACKAGE = pixops PRJ_TOP = ..\.. +PACKAGE = pixops -+GLIB_TOP = $(PRJ_TOP)\..\..\..\..\..\glib\wntmsci12.pro\misc\build\glib-2.28.1 ++GLIB_TOP = +GLIB_INC = -I$(OUTDIR)\inc\external\glib-2.0 -!INCLUDE $(TOP)/glib/build/win32/make.msc -+!INCLUDE $(GLIB_TOP)\build\win32\make.msc ++!INCLUDE $(OUTDIR)\inc\external\glib-2.0\make.msc -PKG_CFLAGS = -I.. $(GLIB_CFLAGS) +PKG_CFLAGS = -I.. $(SOLARINC) $(GLIB_INC) $(GLIB_CFLAGS) @@ -422,548 +422,6 @@ #include "pixops.h" #include "pixops-internal.h" ---- misc/gdk-pixbuf-2.23.0/glib-mkenums.pl 2011-03-24 04:59:07.281250000 +0100 -+++ misc/build/gdk-pixbuf-2.23.0/glib-mkenums.pl 2011-03-22 01:58:24.343750000 +0100 -@@ -1 +1,538 @@ --dummy -+#! perl.exe -+ -+use warnings; -+use File::Basename; -+use Safe; -+ -+# glib-mkenums.pl -+# Information about the current enumeration -+my $flags; # Is enumeration a bitmask? -+my $option_underscore_name; # Overriden underscore variant of the enum name -+ # for example to fix the cases we don't get the -+ # mixed-case -> underscorized transform right. -+my $option_lowercase_name; # DEPRECATED. A lower case name to use as part -+ # of the *_get_type() function, instead of the -+ # one that we guess. For instance, when an enum -+ # uses abnormal capitalization and we can not -+ # guess where to put the underscores. -+my $seenbitshift; # Have we seen bitshift operators? -+my $enum_prefix; # Prefix for this enumeration -+my $enumname; # Name for this enumeration -+my $enumshort; # $enumname without prefix -+my $enumname_prefix; # prefix of $enumname -+my $enumindex = 0; # Global enum counter -+my $firstenum = 1; # Is this the first enumeration per file? -+my @entries; # [ $name, $val ] for each entry -+my $sandbox = Safe->new; # sandbox for safe evaluation of expressions -+ -+sub parse_trigraph { -+ my $opts = shift; -+ my @opts; -+ -+ for $opt (split /\s*,\s*/, $opts) { -+ $opt =~ s/^\s*//; -+ $opt =~ s/\s*$//; -+ my ($key,$val) = $opt =~ /(\w+)(?:=(.+))?/; -+ defined $val or $val = 1; -+ push @opts, $key, $val; -+ } -+ @opts; -+} -+sub parse_entries { -+ my $file = shift; -+ my $file_name = shift; -+ my $looking_for_name = 0; -+ -+ while (<$file>) { -+ # read lines until we have no open comments -+ while (m@/\*([^*]|\*(?!/))*$@) { -+ my $new; -+ defined ($new = <$file>) || die "Unmatched comment in $ARGV"; -+ $_ .= $new; -+ } -+ # strip comments w/o options -+ s@/\*(?!<) -+ ([^*]+|\*(?!/))* -+ \*/@@gx; -+ -+ # strip newlines -+ s@\n@ @; -+ -+ # skip empty lines -+ next if m@^\s*$@; -+ -+ if ($looking_for_name) { -+ if (/^\s*(\w+)/) { -+ $enumname = $1; -+ return 1; -+ } -+ } -+ -+ # Handle include files -+ if (/^\#include\s*<([^>]*)>/ ) { -+ my $file= "../$1"; -+ open NEWFILE, $file or die "Cannot open include file $file: $!\n"; -+ -+ if (parse_entries (\*NEWFILE, $NEWFILE)) { -+ return 1; -+ } else { -+ next; -+ } -+ } -+ -+ if (/^\s*\}\s*(\w+)/) { -+ $enumname = $1; -+ $enumindex++; -+ return 1; -+ } -+ -+ if (/^\s*\}/) { -+ $enumindex++; -+ $looking_for_name = 1; -+ next; -+ } -+ -+ if (m@^\s* -+ (\w+)\s* # name -+ (?:=( # value -+ \s*\w+\s*\(.*\)\s* # macro with multiple args -+ | # OR -+ (?:[^,/]|/(?!\*))* # anything but a comma or comment -+ ))?,?\s* -+ (?:/\*< # options -+ (([^*]|\*(?!/))*) -+ >\s*\*/)?,? -+ \s*$ -+ @x) { -+ my ($name, $value, $options) = ($1,$2,$3); -+ -+ if (!defined $flags && defined $value && $value =~ /<</) { -+ $seenbitshift = 1; -+ } -+ -+ if (defined $options) { -+ my %options = parse_trigraph($options); -+ if (!defined $options{skip}) { -+ push @entries, [ $name, $value, $options{nick} ]; -+ } -+ } else { -+ push @entries, [ $name, $value ]; -+ } -+ } elsif (m@^\s*\#@) { -+ # ignore preprocessor directives -+ } else { -+ print STDERR "$0: $file_name:$.: Failed to parse `$_'\n"; -+ } -+ } -+ -+ return 0; -+} -+ -+sub version { -+ print "glib-mkenums version glib-@GLIB_VERSION@\n"; -+ print "glib-mkenums comes with ABSOLUTELY NO WARRANTY.\n"; -+ print "You may redistribute copies of glib-mkenums under the terms of\n"; -+ print "the GNU General Public License which can be found in the\n"; -+ print "GLib source package. Sources, examples and contact\n"; -+ print "information are available at http://www.gtk.org\n"; -+ exit 0; -+} -+sub usage { -+ print "Usage:\n"; -+ print " glib-mkenums [OPTION...] [FILES...]\n\n"; -+ print "Help Options:\n"; -+ print " -h, --help Show this help message\n\n"; -+ print "Utility Options:\n"; -+ print " --fhead <text> Output file header\n"; -+ print " --fprod <text> Per input file production\n"; -+ print " --ftail <text> Output file trailer\n"; -+ print " --eprod <text> Per enum text (produced prior to value itarations)\n"; -+ print " --vhead <text> Value header, produced before iterating over enum values\n"; -+ print " --vprod <text> Value text, produced for each enum value\n"; -+ print " --vtail <text> Value tail, produced after iterating over enum values\n"; -+ print " --comments <text> Comment structure\n"; -+ print " --template file Template file\n"; -+ print " -v, --version Print version informations\n\n"; -+ print "Production text substitutions:\n"; -+ print " \@EnumName\@ PrefixTheXEnum\n"; -+ print " \@enum_name\@ prefix_the_xenum\n"; -+ print " \@ENUMNAME\@ PREFIX_THE_XENUM\n"; -+ print " \@ENUMSHORT\@ THE_XENUM\n"; -+ print " \@ENUMPREFIX\@ PREFIX\n"; -+ print " \@VALUENAME\@ PREFIX_THE_XVALUE\n"; -+ print " \@valuenick\@ the-xvalue\n"; -+ print " \@valuenum\@ the integer value (limited support, Since: 2.26)\n"; -+ print " \@type\@ either enum or flags\n"; -+ print " \@Type\@ either Enum or Flags\n"; -+ print " \@TYPE\@ either ENUM or FLAGS\n"; -+ print " \@filename\@ name of current input file\n"; -+ print " \@basename\@ base name of the current input file (Since: 2.22)\n"; -+ exit 0; -+} -+ -+# production variables: -+my $fhead = ""; # output file header -+my $fprod = ""; # per input file production -+my $ftail = ""; # output file trailer -+my $eprod = ""; # per enum text (produced prior to value itarations) -+my $vhead = ""; # value header, produced before iterating over enum values -+my $vprod = ""; # value text, produced for each enum value -+my $vtail = ""; # value tail, produced after iterating over enum values -+my $comment_tmpl = ""; # comment template -+ -+sub read_template_file { -+ my ($file) = @_; -+ my %tmpl = ('file-header', $fhead, -+ 'file-production', $fprod, -+ 'file-tail', $ftail, -+ 'enumeration-production', $eprod, -+ 'value-header', $vhead, -+ 'value-production', $vprod, -+ 'value-tail', $vtail, -+ 'comment', $comment_tmpl); -+ my $in = 'junk'; -+ open (FILE, $file) || die "Can't open $file: $!\n"; -+ while (<FILE>) { -+ if (/^\/\*\*\*\s+(BEGIN|END)\s+([\w-]+)\s+\*\*\*\//) { -+ if (($in eq 'junk') && ($1 eq 'BEGIN') && (exists($tmpl{$2}))) { -+ $in = $2; -+ next; -+ } -+ elsif (($in eq $2) && ($1 eq 'END') && (exists($tmpl{$2}))) { -+ $in = 'junk'; -+ next; -+ } else { -+ die "Malformed template file $file\n"; -+ } -+ } -+ if (!($in eq 'junk')) { -+ $tmpl{$in} .= $_; -+ } -+ } -+ close (FILE); -+ if (!($in eq 'junk')) { -+ die "Malformed template file $file\n"; -+ } -+ $fhead = $tmpl{'file-header'}; -+ $fprod = $tmpl{'file-production'}; -+ $ftail = $tmpl{'file-tail'}; -+ $eprod = $tmpl{'enumeration-production'}; -+ $vhead = $tmpl{'value-header'}; -+ $vprod = $tmpl{'value-production'}; -+ $vtail = $tmpl{'value-tail'}; -+ $comment_tmpl = $tmpl{'comment'}; -+ -+ # default to C-style comments -+ $comment_tmpl = "/* \@comment\@ */" if $comment_tmpl eq ""; -+} -+ -+if (!defined $ARGV[0]) { -+ usage; -+} -+while ($_=$ARGV[0],/^-/) { -+ shift; -+ last if /^--$/; -+ if (/^--template$/) { read_template_file (shift); } -+ elsif (/^--fhead$/) { $fhead = $fhead . shift } -+ elsif (/^--fprod$/) { $fprod = $fprod . shift } -+ elsif (/^--ftail$/) { $ftail = $ftail . shift } -+ elsif (/^--eprod$/) { $eprod = $eprod . shift } -+ elsif (/^--vhead$/) { $vhead = $vhead . shift } -+ elsif (/^--vprod$/) { $vprod = $vprod . shift } -+ elsif (/^--vtail$/) { $vtail = $vtail . shift } -+ elsif (/^--comments$/) { $comment_tmpl = shift } -+ elsif (/^--help$/ || /^-h$/ || /^-\?$/) { usage; } -+ elsif (/^--version$/ || /^-v$/) { version; } -+ else { usage; } -+ last if not defined($ARGV[0]); -+} -+ -+# put auto-generation comment -+{ -+ my $comment = $comment_tmpl; -+ $comment =~ s/\@comment\@/Generated data (by glib-mkenums)/; -+ print "\n" . $comment . "\n\n"; -+} -+ -+if (length($fhead)) { -+ my $prod = $fhead; -+ my $base = basename ($ARGV[0]); -+ -+ $prod =~ s/\@filename\@/$ARGV[0]/g; -+ $prod =~ s/\@basename\@/$base/g; -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+} -+ -+while (<>) { -+ if (eof) { -+ close (ARGV); # reset line numbering -+ $firstenum = 1; # Flag to print filename at next enum -+ } -+ -+ # read lines until we have no open comments -+ while (m@/\*([^*]|\*(?!/))*$@) { -+ my $new; -+ defined ($new = <>) || die "Unmatched comment in $ARGV"; -+ $_ .= $new; -+ } -+ # strip comments w/o options -+ s@/\*(?!<) -+ ([^*]+|\*(?!/))* -+ \*/@@gx; -+ -+ if (m@^\s*typedef\s+enum\s* -+ ({)?\s* -+ (?:/\*< -+ (([^*]|\*(?!/))*) -+ >\s*\*/)? -+ \s*({)? -+ @x) { -+ if (defined $2) { -+ my %options = parse_trigraph ($2); -+ next if defined $options{skip}; -+ $enum_prefix = $options{prefix}; -+ $flags = $options{flags}; -+ $option_lowercase_name = $options{lowercase_name}; -+ $option_underscore_name = $options{underscore_name}; -+ } else { -+ $enum_prefix = undef; -+ $flags = undef; -+ $option_lowercase_name = undef; -+ $option_underscore_name = undef; -+ } -+ if (defined $option_lowercase_name) { -+ if (defined $option_underscore_name) { -+ print STDERR "$0: $ARGV:$.: lowercase_name overriden with underscore_name\n"; -+ $option_lowercase_name = undef; -+ } else { -+ print STDERR "$0: $ARGV:$.: lowercase_name is deprecated, use underscore_name\n"; -+ } -+ } -+ # Didn't have trailing '{' look on next lines -+ if (!defined $1 && !defined $4) { -+ while (<>) { -+ if (s/^\s*\{//) { -+ last; -+ } -+ } -+ } -+ -+ $seenbitshift = 0; -+ @entries = (); -+ -+ # Now parse the entries -+ parse_entries (\*ARGV, $ARGV); -+ -+ # figure out if this was a flags or enums enumeration -+ if (!defined $flags) { -+ $flags = $seenbitshift; -+ } -+ -+ # Autogenerate a prefix -+ if (!defined $enum_prefix) { -+ for (@entries) { -+ my $nick = $_->[2]; -+ if (!defined $nick) { -+ my $name = $_->[0]; -+ if (defined $enum_prefix) { -+ my $tmp = ~ ($name ^ $enum_prefix); -+ ($tmp) = $tmp =~ /(^\xff*)/; -+ $enum_prefix = $enum_prefix & $tmp; -+ } else { -+ $enum_prefix = $name; -+ } -+ } -+ } -+ if (!defined $enum_prefix) { -+ $enum_prefix = ""; -+ } else { -+ # Trim so that it ends in an underscore -+ $enum_prefix =~ s/_[^_]*$/_/; -+ } -+ } else { -+ # canonicalize user defined prefixes -+ $enum_prefix = uc($enum_prefix); -+ $enum_prefix =~ s/-/_/g; -+ $enum_prefix =~ s/(.*)([^_])$/$1$2_/; -+ } -+ -+ for $entry (@entries) { -+ my ($name,$num,$nick) = @{$entry}; -+ if (!defined $nick) { -+ ($nick = $name) =~ s/^$enum_prefix//; -+ $nick =~ tr/_/-/; -+ $nick = lc($nick); -+ @{$entry} = ($name, $num, $nick); -+ } -+ } -+ -+ -+ # Spit out the output -+ if (defined $option_underscore_name) { -+ $enumlong = uc $option_underscore_name; -+ $enumsym = lc $option_underscore_name; -+ $enumshort = $enumlong; -+ $enumshort =~ s/^[A-Z][A-Z0-9]*_//; -+ -+ $enumname_prefix = $enumlong; -+ $enumname_prefix =~ s/$enumshort$//; -+ } else { -+ # enumname is e.g. GMatchType -+ $enspace = $enumname; -+ $enspace =~ s/^([A-Z][a-z]*).*$/$1/; -+ -+ $enumshort = $enumname; -+ $enumshort =~ s/^[A-Z][a-z]*//; -+ $enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g; -+ $enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g; -+ $enumshort = uc($enumshort); -+ -+ $enumname_prefix = $enumname; -+ $enumname_prefix =~ s/^([A-Z][a-z]*).*$/$1/; -+ $enumname_prefix = uc($enumname_prefix); -+ -+ $enumlong = uc($enspace) . "_" . $enumshort; -+ $enumsym = lc($enspace) . "_" . lc($enumshort); -+ -+ if (defined($option_lowercase_name)) { -+ $enumsym = $option_lowercase_name; -+ } -+ } -+ -+ if ($firstenum) { -+ $firstenum = 0; -+ -+ if (length($fprod)) { -+ my $prod = $fprod; -+ my $base = basename ($ARGV); -+ -+ $prod =~ s/\@filename\@/$ARGV/g; -+ $prod =~ s/\@basename\@/$base/g; -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ } -+ -+ if (length($eprod)) { -+ my $prod = $eprod; -+ -+ $prod =~ s/\@enum_name\@/$enumsym/g; -+ $prod =~ s/\@EnumName\@/$enumname/g; -+ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; -+ $prod =~ s/\@ENUMNAME\@/$enumlong/g; -+ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; -+ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ -+ if (length($vhead)) { -+ my $prod = $vhead; -+ -+ $prod =~ s/\@enum_name\@/$enumsym/g; -+ $prod =~ s/\@EnumName\@/$enumname/g; -+ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; -+ $prod =~ s/\@ENUMNAME\@/$enumlong/g; -+ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; -+ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ -+ if (length($vprod)) { -+ my $prod = $vprod; -+ my $next_num = 0; -+ -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ for (@entries) { -+ my ($name,$num,$nick) = @{$_}; -+ my $tmp_prod = $prod; -+ -+ if ($prod =~ /\@valuenum\@/) { -+ # only attempt to eval the value if it is requested -+ # this prevents us from throwing errors otherwise -+ if (defined $num) { -+ # use sandboxed perl evaluation as a reasonable -+ # approximation to C constant folding -+ $num = $sandbox->reval ($num); -+ -+ # make sure it parsed to an integer -+ if (!defined $num or $num !~ /^-?\d+$/) { -+ die "Unable to parse enum value '$num'"; -+ } -+ } else { -+ $num = $next_num; -+ } -+ -+ $tmp_prod =~ s/\@valuenum\@/$num/g; -+ $next_num = $num + 1; -+ } -+ -+ $tmp_prod =~ s/\@VALUENAME\@/$name/g; -+ $tmp_prod =~ s/\@valuenick\@/$nick/g; -+ if ($flags) { $tmp_prod =~ s/\@type\@/flags/g; } else { $tmp_prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $tmp_prod =~ s/\@Type\@/Flags/g; } else { $tmp_prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $tmp_prod =~ s/\@TYPE\@/FLAGS/g; } else { $tmp_prod =~ s/\@TYPE\@/ENUM/g; } -+ chomp ($tmp_prod); -+ -+ print "$tmp_prod\n"; -+ } -+ } -+ -+ if (length($vtail)) { -+ my $prod = $vtail; -+ -+ $prod =~ s/\@enum_name\@/$enumsym/g; -+ $prod =~ s/\@EnumName\@/$enumname/g; -+ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; -+ $prod =~ s/\@ENUMNAME\@/$enumlong/g; -+ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; -+ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ } -+} -+ -+if (length($ftail)) { -+ my $prod = $ftail; -+ my $base = basename ($ARGV); -+ -+ $prod =~ s/\@filename\@/$ARGV/g; -+ $prod =~ s/\@basename\@/$base/g; -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+} -+ -+# put auto-generation comment -+{ -+ my $comment = $comment_tmpl; -+ $comment =~ s/\@comment\@/Generated data ends here/; -+ print "\n" . $comment . "\n\n"; -+} --- misc/gdk-pixbuf-2.23.0/msvc_recommended_pragmas.h 2011-03-24 04:59:07.625000000 +0100 +++ misc/build/gdk-pixbuf-2.23.0/msvc_recommended_pragmas.h 2011-03-22 01:58:24.359375000 +0100 @@ -1 +1,31 @@ diff --git a/glib/glib-2.28.1-win32-2.patch b/glib/glib-2.28.1-win32-2.patch new file mode 100644 index 000000000000..ee4b868f6b1a --- /dev/null +++ b/glib/glib-2.28.1-win32-2.patch @@ -0,0 +1,553 @@ +--- misc/glib-2.28.1/build/win32/make.msc 2011-04-01 16:52:15.676157900 +0200 ++++ misc/build/glib-2.28.1/build/win32/make.msc 2011-04-01 16:52:02.168385300 +0200 +@@ -55,7 +55,7 @@ + BABL_LIBS = $(BABL)\babl\babl-1.0.lib + + # force inclusion of the _right_ cairoversion.h even when using without installation +-CAIRO_CFLAGS = -FI $(CAIRO)\cairo-version.h -I $(CAIRO)\src -I $(CAIRO) ++CAIRO_CFLAGS = -I $(CAIRO)\src -I $(CAIRO) + CAIRO_LIBS = $(CAIRO)\src\libcairo.lib + + DIRENT_CFLAGS = -I ..\build\win32\dirent +--- misc/glib-2.28.1/gobject/glib-mkenums 2011-04-01 16:52:15.155128100 +0200 ++++ misc/build/glib-2.28.1/gobject/glib-mkenums 2011-04-01 16:51:30.994602300 +0200 +@@ -1 +1,538 @@ +-dummy ++#! perl.exe ++ ++use warnings; ++use File::Basename; ++use Safe; ++ ++# glib-mkenums.pl ++# Information about the current enumeration ++my $flags; # Is enumeration a bitmask? ++my $option_underscore_name; # Overriden underscore variant of the enum name ++ # for example to fix the cases we don't get the ++ # mixed-case -> underscorized transform right. ++my $option_lowercase_name; # DEPRECATED. A lower case name to use as part ++ # of the *_get_type() function, instead of the ++ # one that we guess. For instance, when an enum ++ # uses abnormal capitalization and we can not ++ # guess where to put the underscores. ++my $seenbitshift; # Have we seen bitshift operators? ++my $enum_prefix; # Prefix for this enumeration ++my $enumname; # Name for this enumeration ++my $enumshort; # $enumname without prefix ++my $enumname_prefix; # prefix of $enumname ++my $enumindex = 0; # Global enum counter ++my $firstenum = 1; # Is this the first enumeration per file? ++my @entries; # [ $name, $val ] for each entry ++my $sandbox = Safe->new; # sandbox for safe evaluation of expressions ++ ++sub parse_trigraph { ++ my $opts = shift; ++ my @opts; ++ ++ for $opt (split /\s*,\s*/, $opts) { ++ $opt =~ s/^\s*//; ++ $opt =~ s/\s*$//; ++ my ($key,$val) = $opt =~ /(\w+)(?:=(.+))?/; ++ defined $val or $val = 1; ++ push @opts, $key, $val; ++ } ++ @opts; ++} ++sub parse_entries { ++ my $file = shift; ++ my $file_name = shift; ++ my $looking_for_name = 0; ++ ++ while (<$file>) { ++ # read lines until we have no open comments ++ while (m@/\*([^*]|\*(?!/))*$@) { ++ my $new; ++ defined ($new = <$file>) || die "Unmatched comment in $ARGV"; ++ $_ .= $new; ++ } ++ # strip comments w/o options ++ s@/\*(?!<) ++ ([^*]+|\*(?!/))* ++ \*/@@gx; ++ ++ # strip newlines ++ s@\n@ @; ++ ++ # skip empty lines ++ next if m@^\s*$@; ++ ++ if ($looking_for_name) { ++ if (/^\s*(\w+)/) { ++ $enumname = $1; ++ return 1; ++ } ++ } ++ ++ # Handle include files ++ if (/^\#include\s*<([^>]*)>/ ) { ++ my $file= "../$1"; ++ open NEWFILE, $file or die "Cannot open include file $file: $!\n"; ++ ++ if (parse_entries (\*NEWFILE, $NEWFILE)) { ++ return 1; ++ } else { ++ next; ++ } ++ } ++ ++ if (/^\s*\}\s*(\w+)/) { ++ $enumname = $1; ++ $enumindex++; ++ return 1; ++ } ++ ++ if (/^\s*\}/) { ++ $enumindex++; ++ $looking_for_name = 1; ++ next; ++ } ++ ++ if (m@^\s* ++ (\w+)\s* # name ++ (?:=( # value ++ \s*\w+\s*\(.*\)\s* # macro with multiple args ++ | # OR ++ (?:[^,/]|/(?!\*))* # anything but a comma or comment ++ ))?,?\s* ++ (?:/\*< # options ++ (([^*]|\*(?!/))*) ++ >\s*\*/)?,? ++ \s*$ ++ @x) { ++ my ($name, $value, $options) = ($1,$2,$3); ++ ++ if (!defined $flags && defined $value && $value =~ /<</) { ++ $seenbitshift = 1; ++ } ++ ++ if (defined $options) { ++ my %options = parse_trigraph($options); ++ if (!defined $options{skip}) { ++ push @entries, [ $name, $value, $options{nick} ]; ++ } ++ } else { ++ push @entries, [ $name, $value ]; ++ } ++ } elsif (m@^\s*\#@) { ++ # ignore preprocessor directives ++ } else { ++ print STDERR "$0: $file_name:$.: Failed to parse `$_'\n"; ++ } ++ } ++ ++ return 0; ++} ++ ++sub version { ++ print "glib-mkenums version glib-@GLIB_VERSION@\n"; ++ print "glib-mkenums comes with ABSOLUTELY NO WARRANTY.\n"; ++ print "You may redistribute copies of glib-mkenums under the terms of\n"; ++ print "the GNU General Public License which can be found in the\n"; ++ print "GLib source package. Sources, examples and contact\n"; ++ print "information are available at http://www.gtk.org\n"; ++ exit 0; ++} ++sub usage { ++ print "Usage:\n"; ++ print " glib-mkenums [OPTION...] [FILES...]\n\n"; ++ print "Help Options:\n"; ++ print " -h, --help Show this help message\n\n"; ++ print "Utility Options:\n"; ++ print " --fhead <text> Output file header\n"; ++ print " --fprod <text> Per input file production\n"; ++ print " --ftail <text> Output file trailer\n"; ++ print " --eprod <text> Per enum text (produced prior to value itarations)\n"; ++ print " --vhead <text> Value header, produced before iterating over enum values\n"; ++ print " --vprod <text> Value text, produced for each enum value\n"; ++ print " --vtail <text> Value tail, produced after iterating over enum values\n"; ++ print " --comments <text> Comment structure\n"; ++ print " --template file Template file\n"; ++ print " -v, --version Print version informations\n\n"; ++ print "Production text substitutions:\n"; ++ print " \@EnumName\@ PrefixTheXEnum\n"; ++ print " \@enum_name\@ prefix_the_xenum\n"; ++ print " \@ENUMNAME\@ PREFIX_THE_XENUM\n"; ++ print " \@ENUMSHORT\@ THE_XENUM\n"; ++ print " \@ENUMPREFIX\@ PREFIX\n"; ++ print " \@VALUENAME\@ PREFIX_THE_XVALUE\n"; ++ print " \@valuenick\@ the-xvalue\n"; ++ print " \@valuenum\@ the integer value (limited support, Since: 2.26)\n"; ++ print " \@type\@ either enum or flags\n"; ++ print " \@Type\@ either Enum or Flags\n"; ++ print " \@TYPE\@ either ENUM or FLAGS\n"; ++ print " \@filename\@ name of current input file\n"; ++ print " \@basename\@ base name of the current input file (Since: 2.22)\n"; ++ exit 0; ++} ++ ++# production variables: ++my $fhead = ""; # output file header ++my $fprod = ""; # per input file production ++my $ftail = ""; # output file trailer ++my $eprod = ""; # per enum text (produced prior to value itarations) ++my $vhead = ""; # value header, produced before iterating over enum values ++my $vprod = ""; # value text, produced for each enum value ++my $vtail = ""; # value tail, produced after iterating over enum values ++my $comment_tmpl = ""; # comment template ++ ++sub read_template_file { ++ my ($file) = @_; ++ my %tmpl = ('file-header', $fhead, ++ 'file-production', $fprod, ++ 'file-tail', $ftail, ++ 'enumeration-production', $eprod, ++ 'value-header', $vhead, ++ 'value-production', $vprod, ++ 'value-tail', $vtail, ++ 'comment', $comment_tmpl); ++ my $in = 'junk'; ++ open (FILE, $file) || die "Can't open $file: $!\n"; ++ while (<FILE>) { ++ if (/^\/\*\*\*\s+(BEGIN|END)\s+([\w-]+)\s+\*\*\*\//) { ++ if (($in eq 'junk') && ($1 eq 'BEGIN') && (exists($tmpl{$2}))) { ++ $in = $2; ++ next; ++ } ++ elsif (($in eq $2) && ($1 eq 'END') && (exists($tmpl{$2}))) { ++ $in = 'junk'; ++ next; ++ } else { ++ die "Malformed template file $file\n"; ++ } ++ } ++ if (!($in eq 'junk')) { ++ $tmpl{$in} .= $_; ++ } ++ } ++ close (FILE); ++ if (!($in eq 'junk')) { ++ die "Malformed template file $file\n"; ++ } ++ $fhead = $tmpl{'file-header'}; ++ $fprod = $tmpl{'file-production'}; ++ $ftail = $tmpl{'file-tail'}; ++ $eprod = $tmpl{'enumeration-production'}; ++ $vhead = $tmpl{'value-header'}; ++ $vprod = $tmpl{'value-production'}; ++ $vtail = $tmpl{'value-tail'}; ++ $comment_tmpl = $tmpl{'comment'}; ++ ++ # default to C-style comments ++ $comment_tmpl = "/* \@comment\@ */" if $comment_tmpl eq ""; ++} ++ ++if (!defined $ARGV[0]) { ++ usage; ++} ++while ($_=$ARGV[0],/^-/) { ++ shift; ++ last if /^--$/; ++ if (/^--template$/) { read_template_file (shift); } ++ elsif (/^--fhead$/) { $fhead = $fhead . shift } ++ elsif (/^--fprod$/) { $fprod = $fprod . shift } ++ elsif (/^--ftail$/) { $ftail = $ftail . shift } ++ elsif (/^--eprod$/) { $eprod = $eprod . shift } ++ elsif (/^--vhead$/) { $vhead = $vhead . shift } ++ elsif (/^--vprod$/) { $vprod = $vprod . shift } ++ elsif (/^--vtail$/) { $vtail = $vtail . shift } ++ elsif (/^--comments$/) { $comment_tmpl = shift } ++ elsif (/^--help$/ || /^-h$/ || /^-\?$/) { usage; } ++ elsif (/^--version$/ || /^-v$/) { version; } ++ else { usage; } ++ last if not defined($ARGV[0]); ++} ++ ++# put auto-generation comment ++{ ++ my $comment = $comment_tmpl; ++ $comment =~ s/\@comment\@/Generated data (by glib-mkenums)/; ++ print "\n" . $comment . "\n\n"; ++} ++ ++if (length($fhead)) { ++ my $prod = $fhead; ++ my $base = basename ($ARGV[0]); ++ ++ $prod =~ s/\@filename\@/$ARGV[0]/g; ++ $prod =~ s/\@basename\@/$base/g; ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++} ++ ++while (<>) { ++ if (eof) { ++ close (ARGV); # reset line numbering ++ $firstenum = 1; # Flag to print filename at next enum ++ } ++ ++ # read lines until we have no open comments ++ while (m@/\*([^*]|\*(?!/))*$@) { ++ my $new; ++ defined ($new = <>) || die "Unmatched comment in $ARGV"; ++ $_ .= $new; ++ } ++ # strip comments w/o options ++ s@/\*(?!<) ++ ([^*]+|\*(?!/))* ++ \*/@@gx; ++ ++ if (m@^\s*typedef\s+enum\s* ++ ({)?\s* ++ (?:/\*< ++ (([^*]|\*(?!/))*) ++ >\s*\*/)? ++ \s*({)? ++ @x) { ++ if (defined $2) { ++ my %options = parse_trigraph ($2); ++ next if defined $options{skip}; ++ $enum_prefix = $options{prefix}; ++ $flags = $options{flags}; ++ $option_lowercase_name = $options{lowercase_name}; ++ $option_underscore_name = $options{underscore_name}; ++ } else { ++ $enum_prefix = undef; ++ $flags = undef; ++ $option_lowercase_name = undef; ++ $option_underscore_name = undef; ++ } ++ if (defined $option_lowercase_name) { ++ if (defined $option_underscore_name) { ++ print STDERR "$0: $ARGV:$.: lowercase_name overriden with underscore_name\n"; ++ $option_lowercase_name = undef; ++ } else { ++ print STDERR "$0: $ARGV:$.: lowercase_name is deprecated, use underscore_name\n"; ++ } ++ } ++ # Didn't have trailing '{' look on next lines ++ if (!defined $1 && !defined $4) { ++ while (<>) { ++ if (s/^\s*\{//) { ++ last; ++ } ++ } ++ } ++ ++ $seenbitshift = 0; ++ @entries = (); ++ ++ # Now parse the entries ++ parse_entries (\*ARGV, $ARGV); ++ ++ # figure out if this was a flags or enums enumeration ++ if (!defined $flags) { ++ $flags = $seenbitshift; ++ } ++ ++ # Autogenerate a prefix ++ if (!defined $enum_prefix) { ++ for (@entries) { ++ my $nick = $_->[2]; ++ if (!defined $nick) { ++ my $name = $_->[0]; ++ if (defined $enum_prefix) { ++ my $tmp = ~ ($name ^ $enum_prefix); ++ ($tmp) = $tmp =~ /(^\xff*)/; ++ $enum_prefix = $enum_prefix & $tmp; ++ } else { ++ $enum_prefix = $name; ++ } ++ } ++ } ++ if (!defined $enum_prefix) { ++ $enum_prefix = ""; ++ } else { ++ # Trim so that it ends in an underscore ++ $enum_prefix =~ s/_[^_]*$/_/; ++ } ++ } else { ++ # canonicalize user defined prefixes ++ $enum_prefix = uc($enum_prefix); ++ $enum_prefix =~ s/-/_/g; ++ $enum_prefix =~ s/(.*)([^_])$/$1$2_/; ++ } ++ ++ for $entry (@entries) { ++ my ($name,$num,$nick) = @{$entry}; ++ if (!defined $nick) { ++ ($nick = $name) =~ s/^$enum_prefix//; ++ $nick =~ tr/_/-/; ++ $nick = lc($nick); ++ @{$entry} = ($name, $num, $nick); ++ } ++ } ++ ++ ++ # Spit out the output ++ if (defined $option_underscore_name) { ++ $enumlong = uc $option_underscore_name; ++ $enumsym = lc $option_underscore_name; ++ $enumshort = $enumlong; ++ $enumshort =~ s/^[A-Z][A-Z0-9]*_//; ++ ++ $enumname_prefix = $enumlong; ++ $enumname_prefix =~ s/$enumshort$//; ++ } else { ++ # enumname is e.g. GMatchType ++ $enspace = $enumname; ++ $enspace =~ s/^([A-Z][a-z]*).*$/$1/; ++ ++ $enumshort = $enumname; ++ $enumshort =~ s/^[A-Z][a-z]*//; ++ $enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g; ++ $enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g; ++ $enumshort = uc($enumshort); ++ ++ $enumname_prefix = $enumname; ++ $enumname_prefix =~ s/^([A-Z][a-z]*).*$/$1/; ++ $enumname_prefix = uc($enumname_prefix); ++ ++ $enumlong = uc($enspace) . "_" . $enumshort; ++ $enumsym = lc($enspace) . "_" . lc($enumshort); ++ ++ if (defined($option_lowercase_name)) { ++ $enumsym = $option_lowercase_name; ++ } ++ } ++ ++ if ($firstenum) { ++ $firstenum = 0; ++ ++ if (length($fprod)) { ++ my $prod = $fprod; ++ my $base = basename ($ARGV); ++ ++ $prod =~ s/\@filename\@/$ARGV/g; ++ $prod =~ s/\@basename\@/$base/g; ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++ } ++ } ++ ++ if (length($eprod)) { ++ my $prod = $eprod; ++ ++ $prod =~ s/\@enum_name\@/$enumsym/g; ++ $prod =~ s/\@EnumName\@/$enumname/g; ++ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; ++ $prod =~ s/\@ENUMNAME\@/$enumlong/g; ++ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; ++ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } ++ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } ++ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++ } ++ ++ if (length($vhead)) { ++ my $prod = $vhead; ++ ++ $prod =~ s/\@enum_name\@/$enumsym/g; ++ $prod =~ s/\@EnumName\@/$enumname/g; ++ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; ++ $prod =~ s/\@ENUMNAME\@/$enumlong/g; ++ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; ++ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } ++ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } ++ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++ } ++ ++ if (length($vprod)) { ++ my $prod = $vprod; ++ my $next_num = 0; ++ ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ for (@entries) { ++ my ($name,$num,$nick) = @{$_}; ++ my $tmp_prod = $prod; ++ ++ if ($prod =~ /\@valuenum\@/) { ++ # only attempt to eval the value if it is requested ++ # this prevents us from throwing errors otherwise ++ if (defined $num) { ++ # use sandboxed perl evaluation as a reasonable ++ # approximation to C constant folding ++ $num = $sandbox->reval ($num); ++ ++ # make sure it parsed to an integer ++ if (!defined $num or $num !~ /^-?\d+$/) { ++ die "Unable to parse enum value '$num'"; ++ } ++ } else { ++ $num = $next_num; ++ } ++ ++ $tmp_prod =~ s/\@valuenum\@/$num/g; ++ $next_num = $num + 1; ++ } ++ ++ $tmp_prod =~ s/\@VALUENAME\@/$name/g; ++ $tmp_prod =~ s/\@valuenick\@/$nick/g; ++ if ($flags) { $tmp_prod =~ s/\@type\@/flags/g; } else { $tmp_prod =~ s/\@type\@/enum/g; } ++ if ($flags) { $tmp_prod =~ s/\@Type\@/Flags/g; } else { $tmp_prod =~ s/\@Type\@/Enum/g; } ++ if ($flags) { $tmp_prod =~ s/\@TYPE\@/FLAGS/g; } else { $tmp_prod =~ s/\@TYPE\@/ENUM/g; } ++ chomp ($tmp_prod); ++ ++ print "$tmp_prod\n"; ++ } ++ } ++ ++ if (length($vtail)) { ++ my $prod = $vtail; ++ ++ $prod =~ s/\@enum_name\@/$enumsym/g; ++ $prod =~ s/\@EnumName\@/$enumname/g; ++ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; ++ $prod =~ s/\@ENUMNAME\@/$enumlong/g; ++ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; ++ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } ++ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } ++ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++ } ++ } ++} ++ ++if (length($ftail)) { ++ my $prod = $ftail; ++ my $base = basename ($ARGV); ++ ++ $prod =~ s/\@filename\@/$ARGV/g; ++ $prod =~ s/\@basename\@/$base/g; ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++} ++ ++# put auto-generation comment ++{ ++ my $comment = $comment_tmpl; ++ $comment =~ s/\@comment\@/Generated data ends here/; ++ print "\n" . $comment . "\n\n"; ++} diff --git a/glib/makefile.mk b/glib/makefile.mk index d1ce6a88568b..e724baee219f 100755 --- a/glib/makefile.mk +++ b/glib/makefile.mk @@ -289,21 +289,24 @@ OUT2INC+=gobject/gvaluearray.h .ELIF "$(OS)"=="WNT" CONVERTFILES=gobject/gmarshal.c -PATCH_FILES=glib-2.28.1-win32.patch +PATCH_FILES=glib-2.28.1-win32.patch glib-2.28.1-win32-2.patch CONFIGURE_ACTION= ADDITIONAL_FILES= config.h \ gio/gvdb/makefile.msc \ gio/win32/makefile.msc \ glib/glibconfig.h \ - gmodule/gmoduleconf.h + gmodule/gmoduleconf.h \ + gobject/glib-mkenums BUILD_ACTION=nmake -f makefile.msc -OUT2BIN+=gio/libgio-2.0-0.dll -OUT2BIN+=glib/libglib-2.0-0.dll -OUT2BIN+=gmodule/libgmodule-2.0-0.dll -OUT2BIN+=gobject/libgobject-2.0-0.dll -OUT2BIN+=gthread/libgthread-2.0-0.dll +OUT2BIN+=gio$/libgio-2.0-0.dll +OUT2BIN+=glib$/libglib-2.0-0.dll +OUT2BIN+=gmodule$/libgmodule-2.0-0.dll +OUT2BIN+=gobject$/libgobject-2.0-0.dll +OUT2BIN+=gthread$/libgthread-2.0-0.dll +OUT2BIN+=gobject$/glib-mkenums +OUT2BIN+=gobject$/glib-genmarshal.exe OUT2LIB+=build/win32/dirent/dirent.lib OUT2LIB+=gio/gio-2.0.lib @@ -318,6 +321,8 @@ OUT2LIB+=gobject/glib-genmarshal.lib OUT2LIB+=gobject/gobject-2.0.lib OUT2LIB+=gthread/gthread-2.0.lib +OUT2INC+=build$/win32$/make.msc +OUT2INC+=build$/win32$/module.defs OUT2INC+=glib/glib.h OUT2INC+=glib/glib-object.h diff --git a/glib/prj/d.lst b/glib/prj/d.lst index eb6c2620a08a..851265ca79a2 100644 --- a/glib/prj/d.lst +++ b/glib/prj/d.lst @@ -12,6 +12,7 @@ symlink: %_DEST%\lib%_EXT%\libgobject-2.0.0.dylib %_DEST%\lib%_EXT%\libgobject-2 ..\%__SRC%\bin\*.dll %_DEST%\bin%_EXT% ..\%__SRC%\bin\glib-mkenums %_DEST%\bin%_EXT%\glib-mkenums ..\%__SRC%\bin\glib-genmarshal %_DEST%\bin%_EXT%\glib-genmarshal +..\%__SRC%\bin\glib-genmarshal.exe %_DEST%\bin%_EXT%\glib-genmarshal.exe ..\%__SRC%\lib\gio-2.0.lib %_DEST%\lib%_EXT%\gio-2.0.lib ..\%__SRC%\lib\gmodule-2.0.lib %_DEST%\lib%_EXT%\gmodule-2.0.lib ..\%__SRC%\lib\gthread-2.0.lib %_DEST%\lib%_EXT%\gthread-2.0.lib @@ -36,6 +37,8 @@ mkdir: %_DEST%\inc%_EXT%\external\glib-2.0 ..\%__SRC%\inc\glib.h %_DEST%\inc%_EXT%\external\glib-2.0\glib.h ..\%__SRC%\inc\glibconfig.h %_DEST%\inc%_EXT%\external\glib-2.0\glibconfig.h ..\%__SRC%\inc\gmodule.h %_DEST%\inc%_EXT%\external\glib-2.0\gmodule.h +..\%__SRC%\inc\make.msc %_DEST%\inc%_EXT%\external\glib-2.0\make.msc +..\%__SRC%\inc\module.defs %_DEST%\inc%_EXT%\external\glib-2.0\module.defs mkdir: %_DEST%\inc%_EXT%\external\glib-2.0\gio ..\%__SRC%\inc\gaction.h %_DEST%\inc%_EXT%\external\glib-2.0\gio\gaction.h diff --git a/offapi/com/sun/star/embed/Storage.idl b/offapi/com/sun/star/embed/Storage.idl index d34d736cf5cb..8a793d513476 100644 --- a/offapi/com/sun/star/embed/Storage.idl +++ b/offapi/com/sun/star/embed/Storage.idl @@ -356,7 +356,6 @@ published service Storage </p> */ [property, optional, readonly] boolean HasNonEncryptedEntries; - }; //============================================================================ diff --git a/offapi/com/sun/star/embed/XEncryptionProtectedSource2.idl b/offapi/com/sun/star/embed/XEncryptionProtectedSource2.idl index e590a5764178..5930e8490678 100644 --- a/offapi/com/sun/star/embed/XEncryptionProtectedSource2.idl +++ b/offapi/com/sun/star/embed/XEncryptionProtectedSource2.idl @@ -41,17 +41,19 @@ module com { module sun { module star { module embed { //============================================================================ /** This interface allows to set a password for an object. + + @since OOo 3.4 */ -published interface XEncryptionProtectedSource2: XEncryptionProtectedSource +interface XEncryptionProtectedSource2: XEncryptionProtectedSource { // ----------------------------------------------------------------------- /** sets an encryption data for the object. - @param aEncryptionData - the new encryption data + @param aEncryptionData + the new encryption data - @throws ::com::sun::star::io::IOException - in case the data could not be set + @throws ::com::sun::star::io::IOException + in case the data could not be set */ void setEncryptionData( [in] sequence< ::com::sun::star::beans::NamedValue > aEncryptionData ) raises( ::com::sun::star::io::IOException ); diff --git a/offapi/com/sun/star/embed/XEncryptionProtectedStorage.idl b/offapi/com/sun/star/embed/XEncryptionProtectedStorage.idl new file mode 100644 index 000000000000..30ec5621f669 --- /dev/null +++ b/offapi/com/sun/star/embed/XEncryptionProtectedStorage.idl @@ -0,0 +1,120 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#ifndef __com_sun_star_embed_XEncryptionProtectedStorage_idl__ +#define __com_sun_star_embed_XEncryptionProtectedStorage_idl__ + +#ifndef __com_sun_star_embed_XEncryptionProtectedSource2_idl__ +#include <com/sun/star/embed/XEncryptionProtectedSource2.idl> +#endif + +#ifndef __com_sun_star_beans_NamedValue_idl__ +#include <com/sun/star/beans/NamedValue.idl> +#endif + +#ifndef __com_sun_star_lang_IllegalArgumentException_idl__ +#include <com/sun/star/lang/IllegalArgumentException.idl> +#endif + +#ifndef __com_sun_star_xml_crypto_DigestID_idl__ +#include <com/sun/star/xml/crypto/DigestID.idl> +#endif + +#ifndef __com_sun_star_xml_crypto_CipherID_idl__ +#include <com/sun/star/xml/crypto/CipherID.idl> +#endif + +//============================================================================ + +module com { module sun { module star { module embed { + +//============================================================================ +/** This interface allows to set a password for an object. + + @since OOo 3.4 + */ +interface XEncryptionProtectedStorage: XEncryptionProtectedSource2 +{ + // ----------------------------------------------------------------------- + /** allows to set the encryption algorithms for the object. + <p> + The algorithms will of course be used only for streams that have been + marked to be encrypted. If no stream in the storage is marked to be + encrypted, the algorithms-related information may have no effect to + the result package. + </p> + + <p> + The following values could be part of the provided sequence: + </p> + <dl> + <dt>StartKeyGenerationAlgorithm</dt> + <dd> + specifies the algorithm that was used to generate + the EncryptionKey from the original password; in case + the contents should be decrypted, the algorithm might + be already known by the object; if a different one is + set an exception should be thrown to indicate the + error; it should take values from + <type scope="com::sun::star::xml:crypto">DigestID</type>. + </dd> + <dt>EncryptionAlgorithm</dt> + <dd> + specifies the algorithm that should be used to + encrypt/decrypt the contents; in case the contents + should be decrypted, the algorithm might be already + known by the object; if a different one is set + an exception should be thrown to indicate the error; + it should take values from + <type scope="com::sun::star::xml:crypto">CipherID</type>. + </dd> + <dt>ChecksumAlgorithm</dt> + <dd> + specifies the algorithm that was used to generate + the checksum of the encrypted data; in case + the contents should be decrypted, the algorithm might + be already known by the object; if a different one is + set an exception should be thrown to indicate the + error; it should take values from + <type scope="com::sun::star::xml:crypto">DigestID</type>. + </dd> + </dl> + */ + void setEncryptionAlgorithms( [in] sequence< ::com::sun::star::beans::NamedValue > aAlgorithms ) + raises( ::com::sun::star::lang::IllegalArgumentException ); + + // ----------------------------------------------------------------------- + /** allows to get the encryption algorithms of the object. + */ + sequence< ::com::sun::star::beans::NamedValue > getEncryptionAlgorithms(); +}; + +//============================================================================ + +}; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/embed/makefile.mk b/offapi/com/sun/star/embed/makefile.mk index 8ee156af48ba..c142086cdbf8 100644 --- a/offapi/com/sun/star/embed/makefile.mk +++ b/offapi/com/sun/star/embed/makefile.mk @@ -78,6 +78,7 @@ IDLFILES=\ XLinkFactory.idl\ XEncryptionProtectedSource.idl\ XEncryptionProtectedSource2.idl\ + XEncryptionProtectedStorage.idl\ XInplaceClient.idl\ XInsertObjectDialog.idl\ XWindowSupplier.idl\ diff --git a/offapi/com/sun/star/script/vba/VBAEventId.idl b/offapi/com/sun/star/script/vba/VBAEventId.idl index fda83a18d495..18b84b5ef14d 100755 --- a/offapi/com/sun/star/script/vba/VBAEventId.idl +++ b/offapi/com/sun/star/script/vba/VBAEventId.idl @@ -97,11 +97,11 @@ constants VBAEventId const long WORKBOOK_AFTERSAVE = 2007; /** New sheet inserted. Arguments: short nSheet. */ const long WORKBOOK_NEWSHEET = 2008; - /** Document window has been activated. No arguments. */ + /** Document window has been activated. Arguments: XController aController. */ const long WORKBOOK_WINDOWACTIVATE = 2009; - /** Document window has been deactivated. No arguments. */ + /** Document window has been deactivated. Arguments: XController aController. */ const long WORKBOOK_WINDOWDEACTIVATE = 2010; - /** Document window has been resized. No arguments. */ + /** Document window has been resized. Arguments: XController aController. */ const long WORKBOOK_WINDOWRESIZE = 2011; //------------------------------------------------------------------------- diff --git a/offapi/com/sun/star/script/vba/VBAScriptEvent.idl b/offapi/com/sun/star/script/vba/VBAScriptEvent.idl new file mode 100755 index 000000000000..c1fc7096bcee --- /dev/null +++ b/offapi/com/sun/star/script/vba/VBAScriptEvent.idl @@ -0,0 +1,73 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#ifndef __com_sun_star_script_vba_VBAScriptEvent_idl__ +#define __com_sun_star_script_vba_VBAScriptEvent_idl__ + +#include <com/sun/star/lang/EventObject.idl> + +//============================================================================= + +module com { module sun { module star { module script { module vba { + +//============================================================================= + +/** Describes a VBA script event fired via <member>XVBACompatibility:: + broadcastVBAScriptEvent</member>, and received by <member> + XVBAScriptListener::notifyVBAScriptEvent</member>. + + @see XVBACompatibility + @see XVBAScriptListener + */ +struct VBAScriptEvent : ::com::sun::star::lang::EventObject +{ + //------------------------------------------------------------------------- + + /** Identifies the type of the event. + + @see VBAScriptEventId + */ + long Identifier; + + //------------------------------------------------------------------------- + + /** Contains the name of the involved VBA module. + + @see VBAScriptEventId + */ + string ModuleName; + + //------------------------------------------------------------------------- +}; + +//============================================================================= + +}; }; }; }; }; + +//============================================================================= + +#endif diff --git a/offapi/com/sun/star/script/vba/VBAScriptEventId.idl b/offapi/com/sun/star/script/vba/VBAScriptEventId.idl new file mode 100755 index 000000000000..cc66a3fc098c --- /dev/null +++ b/offapi/com/sun/star/script/vba/VBAScriptEventId.idl @@ -0,0 +1,100 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#ifndef __com_sun_star_script_vba_VBAScriptEventId_idl__ +#define __com_sun_star_script_vba_VBAScriptEventId_idl__ + +//============================================================================= + +module com { module sun { module star { module script { module vba { + +//============================================================================= + +/** Identifies a VBA script event fired via <member>XVBACompatibility:: + broadcastVBAScriptEvent</member>, and received by <member> + XVBAScriptListener::notifyVBAScriptEvent</member>. + + @see VBAScriptEvent + @see XVBACompatibility + @see XVBAScriptListener + */ +constants VBAScriptEventId +{ + //------------------------------------------------------------------------- + /** This event is fired when a VBA script in the current document has been + started. + + <p>Several scripts may run simultaneously, e.g. when a running script + triggers a document event that starts another script.</p> + + <p>The number of running scripts can be obtained via <member> + XVBACompatibility::RunningVBAScripts</member>. The number returned + there will already contain the new script notified with this event.</p> + + <p>The member <member>VBAScriptEvent::ModuleName</member> of the event + object will contain the name of the code module that contains the + started script.</p> + */ + const long SCRIPT_STARTED = 0; + + //------------------------------------------------------------------------- + /** This event is fired when a VBA script in the current document stops + running. + + <p>Several scripts may run simultaneously, e.g. when a running script + triggers a document event that starts another script.</p> + + <p>The number of scripts still running can be obtained via <member> + XVBACompatibility::RunningVBAScripts</member>. The number returned + there will not contain the stopped script notified with this event + anymore.</p> + + <p>The member <member>VBAScriptEvent::ModuleName</member> of the event + object will contain the name of the code module that contains the + script that has been stopped.</p> + */ + const long SCRIPT_STOPPED = 1; + + //------------------------------------------------------------------------- + /** This event is fired when a VBA script in the current document tries to + instanciate a userform. + + <p>The member <member>VBAScriptEvent::ModuleName</member> of the event + object will contain the name of the userform module.</p> + */ + const long INITIALIZE_USERFORM = 2; + + //------------------------------------------------------------------------- +}; + +//============================================================================= + +}; }; }; }; }; + +//============================================================================= + +#endif diff --git a/offapi/com/sun/star/script/vba/XVBACompatibility.idl b/offapi/com/sun/star/script/vba/XVBACompatibility.idl index bfa9d01655fa..9c77046b1159 100644 --- a/offapi/com/sun/star/script/vba/XVBACompatibility.idl +++ b/offapi/com/sun/star/script/vba/XVBACompatibility.idl @@ -28,7 +28,8 @@ #ifndef __com_sun_star_script_vba_XVBACompatibility_idl__ #define __com_sun_star_script_vba_XVBACompatibility_idl__ -#include <com/sun/star/uno/XInterface.idl> +#include <com/sun/star/frame/XModel.idl> +#include <com/sun/star/script/vba/XVBAScriptListener.idl> //============================================================================= @@ -41,6 +42,22 @@ interface XVBACompatibility [attribute] boolean VBACompatibilityMode; //------------------------------------------------------------------------- + + [attribute, readonly] long RunningVBAScripts; + + //------------------------------------------------------------------------- + + [oneway] void addVBAScriptListener( [in] XVBAScriptListener Listener ); + + //------------------------------------------------------------------------- + + [oneway] void removeVBAScriptListener( [in] XVBAScriptListener Listener ); + + //------------------------------------------------------------------------- + + void broadcastVBAScriptEvent( [in] long Identifier, [in] string ModuleName ); + + //------------------------------------------------------------------------- }; }; }; }; }; }; diff --git a/offapi/com/sun/star/script/vba/XVBAEventProcessor.idl b/offapi/com/sun/star/script/vba/XVBAEventProcessor.idl index 4a3534de8412..1bc139243493 100755 --- a/offapi/com/sun/star/script/vba/XVBAEventProcessor.idl +++ b/offapi/com/sun/star/script/vba/XVBAEventProcessor.idl @@ -30,7 +30,6 @@ #include <com/sun/star/uno/XInterface.idl> #include <com/sun/star/lang/IllegalArgumentException.idl> -#include <com/sun/star/script/provider/ScriptFrameworkErrorException.idl> #include <com/sun/star/util/VetoException.idl> //============================================================================= @@ -75,23 +74,20 @@ interface XVBAEventProcessor The input arguments needed to create the argument list of the VBA event handler. + @return + <TRUE/>, if event handing is enabled, and the event handler macro + exists and has been invoked. + @throws <type scope="::com::sun::star::lang">IllegalArgumentException</type> if the passed event identifier is not supported, or if the passed arguments do not conform to the arguments expected by the specified event. - @throws <type scope="::com::sun::star::script::provider">ScriptFrameworkErrorException</type> - if the VBA event handler could not be invoked. Reasons may be, that - handling of VBA events is not enabled, that the VBA event handler - macro has not been found, or that the execution of the macro has - been aborted with an error. - @throws <type scope="::com::sun::star::util">VetoException</type> if the VBA event handler has indicated to veto the event. **/ - void processVbaEvent( [in] long nEventId, [in] sequence< any > aArgs ) + boolean processVbaEvent( [in] long nEventId, [in] sequence< any > aArgs ) raises (::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::script::provider::ScriptFrameworkErrorException, ::com::sun::star::util::VetoException); //------------------------------------------------------------------------- diff --git a/package/source/zipapi/XMemoryStream.cxx b/offapi/com/sun/star/script/vba/XVBAScriptListener.idl index c5ffe9ac874c..2f5594d3b416 100644..100755 --- a/package/source/zipapi/XMemoryStream.cxx +++ b/offapi/com/sun/star/script/vba/XVBAScriptListener.idl @@ -25,28 +25,27 @@ * ************************************************************************/ -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <XMemoryStream.hxx> +#ifndef __com_sun_star_script_vba_XVBAScriptListener_idl__ +#define __com_sun_star_script_vba_XVBAScriptListener_idl__ -using namespace com::sun::star::io; -using namespace com::sun::star::uno; +#include <com/sun/star/lang/XEventListener.idl> +#include <com/sun/star/script/vba/VBAScriptEvent.idl> -XMemoryStream::XMemoryStream ( com::sun::star::uno::Sequence < sal_Int8 > & rNewBuffer ) -: ZipPackageBuffer ( rNewBuffer ) -{ -} -XMemoryStream::~XMemoryStream(void) -{ -} -::com::sun::star::uno::Any SAL_CALL XMemoryStream::queryInterface( const com::sun::star::uno::Type& rType ) - throw(com::sun::star::uno::RuntimeException) +//============================================================================= + +module com { module sun { module star { module script { module vba { + +//============================================================================= + +interface XVBAScriptListener : ::com::sun::star::lang::XEventListener { - return ::cppu::queryInterface ( rType , - // OWeakObject interfaces - reinterpret_cast< XInterface* > ( this ) , - static_cast< XWeak* > ( this ) , - // my interfaces - static_cast< XInputStream* > ( this ) , - static_cast< XSeekable* > ( this ) ); -} + void notifyVBAScriptEvent( [in] VBAScriptEvent Event ); +}; + +//============================================================================= + +}; }; }; }; }; + +//============================================================================= + +#endif diff --git a/offapi/com/sun/star/script/vba/makefile.mk b/offapi/com/sun/star/script/vba/makefile.mk index 336be1b5e7a6..6f13245f7d1e 100755 --- a/offapi/com/sun/star/script/vba/makefile.mk +++ b/offapi/com/sun/star/script/vba/makefile.mk @@ -41,12 +41,15 @@ IDLFILES=\ VBAEventId.idl \ VBAEventProcessor.idl \ VBAMacroResolver.idl \ + VBAScriptEvent.idl \ + VBAScriptEventId.idl \ VBASpreadsheetEventProcessor.idl \ VBATextEventProcessor.idl \ XVBACompatibility.idl \ XVBAEventProcessor.idl \ XVBAMacroResolver.idl \ - XVBAModuleInfo.idl + XVBAModuleInfo.idl \ + XVBAScriptListener.idl # ------------------------------------------------------------------ diff --git a/offapi/com/sun/star/xml/crypto/CipherID.idl b/offapi/com/sun/star/xml/crypto/CipherID.idl new file mode 100644 index 000000000000..10b058167244 --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/CipherID.idl @@ -0,0 +1,60 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_CipherID_idl__ +#define __com_sun_star_xml_crypto_CipherID_idl__ + + +//============================================================================ + +module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** The constant set contains identifiers of supported cipher-creation + algorithms. + + @see <type>XCipherContextSupplier</type> + @since OOo 3.4 +*/ +constants CipherID +{ + //------------------------------------------------------------------------ + /** identifier of AES algorithm in CBC mode with W3C padding + */ + const long AES_CBC_W3C_PADDING = 1; + + //------------------------------------------------------------------------ + /** identifier of the Blowfish algorithm in 8-bit CFB mode + */ + const long BLOWFISH_CFB_8 = 2; +}; + +//============================================================================ + +}; }; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/xml/crypto/DigestID.idl b/offapi/com/sun/star/xml/crypto/DigestID.idl new file mode 100644 index 000000000000..14eb822de2fd --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/DigestID.idl @@ -0,0 +1,72 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_DigestID_idl__ +#define __com_sun_star_xml_crypto_DigestID_idl__ + + +//============================================================================ + +module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** The constant set contains identifiers of supported digest-creation + algorithms. + + @see <type>XDigestContextSupplier</type> + @since OOo 3.4 +*/ +constants DigestID +{ + //------------------------------------------------------------------------ + /** identifier of SHA-1 algorithm + */ + const long SHA1 = 1; + + //------------------------------------------------------------------------ + /** identifier of SHA-256 algorithm + */ + const long SHA256 = 2; + + //------------------------------------------------------------------------ + /** identifier of SHA-1 algorithm that is applied to the first kilobyte + of data. + */ + const long SHA1_1K = 3; + + //------------------------------------------------------------------------ + /** identifier of SHA-256 algorithm that is applied to the first kilobyte + of data. + */ + const long SHA256_1K = 4; +}; + +//============================================================================ + +}; }; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/xml/crypto/SEInitializer.idl b/offapi/com/sun/star/xml/crypto/SEInitializer.idl index e27bafd319e9..239ef92c9693 100644 --- a/offapi/com/sun/star/xml/crypto/SEInitializer.idl +++ b/offapi/com/sun/star/xml/crypto/SEInitializer.idl @@ -28,21 +28,19 @@ #ifndef __com_sun_star_xml_crypto_seinitializer_idl_ #define __com_sun_star_xml_crypto_seinitializer_idl_ -#include <com/sun/star/uno/XInterface.idl> -#include <com/sun/star/uno/Exception.idl> - #include <com/sun/star/xml/crypto/XSEInitializer.idl> - -#include <com/sun/star/lang/XServiceInfo.idl> +#include <com/sun/star/xml/crypto/XDigestContextSupplier.idl> +#include <com/sun/star/xml/crypto/XCipherContextSupplier.idl> module com { module sun { module star { module xml { module crypto { /** * Service of SEInitializer */ -published service SEInitializer { - interface com::sun::star::xml::crypto::XSEInitializer ; - interface com::sun::star::lang::XServiceInfo ; +service SEInitializer { + interface ::com::sun::star::xml::crypto::XSEInitializer; + interface ::com::sun::star::xml::crypto::XDigestContextSupplier; + interface ::com::sun::star::xml::crypto::XCipherContextSupplier; }; } ; } ; } ; } ; } ; diff --git a/offapi/com/sun/star/xml/crypto/XCipherContext.idl b/offapi/com/sun/star/xml/crypto/XCipherContext.idl new file mode 100644 index 000000000000..d2c086163f93 --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/XCipherContext.idl @@ -0,0 +1,89 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_xciphercontext_idl_ +#define __com_sun_star_xml_crypto_xciphercontext_idl_ + +#ifndef __com_sun_star_uno_XInterface_idl__ +#include <com/sun/star/uno/XInterface.idl> +#endif + +#ifndef __com_sun_star_lang_IllegalArgumentException_idl__ +#include <com/sun/star/lang/IllegalArgumentException.idl> +#endif + +#ifndef __com_sun_star_lang_DisposedException_idl__ +#include <com/sun/star/lang/DisposedException.idl> +#endif + +//============================================================================ + + module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** This interface allows to encrypt/decrypt data using the cipher context. + <p> + The algorithm as well as encryption data are specified on object creation. + </p> + + @see <type>XCipherContextSupplier</type> + @since OOo 3.4 + */ +interface XCipherContext : com::sun::star::uno::XInterface +{ + //------------------------------------------------------------------------ + /** encrypts/decrypts the data using the cipher. + <p> + Please have in mind, the cipher object state might depend from the + already encrypted/decrypted data ( it depends from the used + algorithm ). + </p> + + <p> + Whether the object does encryption or decryption is specified by + creation of the object. + </p> + + @param aData + data that should be encrypted/decrypted + */ + sequence<byte> convertWithCipherContext( [in] sequence< byte > aData ) + raises( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::lang::DisposedException ); + + //------------------------------------------------------------------------ + /** finalizes cipher and disposes context. + */ + sequence<byte> finalizeCipherContextAndDispose() + raises( ::com::sun::star::lang::DisposedException ); +}; + +//============================================================================ + +}; }; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/xml/crypto/XCipherContextSupplier.idl b/offapi/com/sun/star/xml/crypto/XCipherContextSupplier.idl new file mode 100644 index 000000000000..115cf7b0ee0f --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/XCipherContextSupplier.idl @@ -0,0 +1,91 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_xciphercontextsupplier_idl_ +#define __com_sun_star_xml_crypto_xciphercontextsupplier_idl_ + +#ifndef __com_sun_star_uno_XInterface_idl__ +#include <com/sun/star/uno/XInterface.idl> +#endif + +#ifndef __com_sun_star_beans_NamedValue_idl__ +#include <com/sun/star/beans/NamedValue.idl> +#endif + +#ifndef __com_sun_star_xml_crypto_XCipherContext_idl__ +#include <com/sun/star/xml/crypto/XCipherContext.idl> +#endif + +#ifndef __com_sun_star_lang_IllegalArgumentException_idl__ +#include <com/sun/star/lang/IllegalArgumentException.idl> +#endif + +//============================================================================ + + module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** This interface allows to get an object that allows to encrypt/decrypt data + using the specified algorithm. + + @since OOo 3.4 + */ +interface XCipherContextSupplier : com::sun::star::uno::XInterface +{ + //------------------------------------------------------------------------ + /** returns an object that allows to encrypt/decrypt data. + + @param nCipherID + the internal ID specifying the algorithm, + should take value from <type>CipherID</type> + + @param aKey + the key that should be used for the encryption + + @param aInitializationVector + the initialization vector that should be used for the encryption + + @param bEncryption + whether an encryption or decryption cipher should be created + <TRUE/> - Encryption + <FALSE/> - Decryption + + @param aParams + optional parameters that could be used to initialize the cipher, + + @throws ::com::sun::star::lang::IllegalArgumentException + one of provided arguments is illegal + */ + + XCipherContext getCipherContext( [in] long nCipherID, [in] sequence< byte > aKey, [in] sequence< byte > aInitializationVector, [in] boolean bEncryption, [in] sequence< ::com::sun::star::beans::NamedValue > aParams ) + raises( ::com::sun::star::lang::IllegalArgumentException ); +}; + +//============================================================================ + +}; }; }; }; }; + +#endif diff --git a/offapi/com/sun/star/xml/crypto/XDigestContext.idl b/offapi/com/sun/star/xml/crypto/XDigestContext.idl new file mode 100644 index 000000000000..f6218d9b6eda --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/XDigestContext.idl @@ -0,0 +1,74 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_xdigestcontext_idl_ +#define __com_sun_star_xml_crypto_xdigestcontext_idl_ + +#ifndef __com_sun_star_uno_XInterface_idl__ +#include <com/sun/star/uno/XInterface.idl> +#endif + +#ifndef __com_sun_star_lang_DisposedException_idl__ +#include <com/sun/star/lang/DisposedException.idl> +#endif + +//============================================================================ + + module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** This interface allows to generate the digest. + <p> + The algorithm to generate the digest is specified on object creation. + </p> + + @see <type>XDigestContextSupplier</type> + @since OOo 3.4 + */ +interface XDigestContext : com::sun::star::uno::XInterface +{ + //------------------------------------------------------------------------ + /** update the digest with the given data. + + @param aData + data that should be used to update the digest + */ + void updateDigest( [in] sequence< byte > aData ) + raises( ::com::sun::star::lang::DisposedException ); + + //------------------------------------------------------------------------ + /** finalizes digest and disposes context. + */ + sequence<byte> finalizeDigestAndDispose() + raises( ::com::sun::star::lang::DisposedException ); +}; + +//============================================================================ + +}; }; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/xml/crypto/XDigestContextSupplier.idl b/offapi/com/sun/star/xml/crypto/XDigestContextSupplier.idl new file mode 100644 index 000000000000..f421d8ff9c96 --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/XDigestContextSupplier.idl @@ -0,0 +1,83 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_xdigestcontextsupplier_idl_ +#define __com_sun_star_xml_crypto_xdigestcontextsupplier_idl_ + +#ifndef __com_sun_star_uno_XInterface_idl__ +#include <com/sun/star/uno/XInterface.idl> +#endif + +#ifndef __com_sun_star_beans_NamedValue_idl__ +#include <com/sun/star/beans/NamedValue.idl> +#endif + +#ifndef __com_sun_star_xml_crypto_XDigestContext_idl__ +#include <com/sun/star/xml/crypto/XDigestContext.idl> +#endif + +#ifndef __com_sun_star_lang_IllegalArgumentException_idl__ +#include <com/sun/star/lang/IllegalArgumentException.idl> +#endif + +//============================================================================ + + module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** This interface allows to get an object to generate a digest of a specified + format. + + @since OOo 3.4 + */ +interface XDigestContextSupplier : com::sun::star::uno::XInterface +{ + //------------------------------------------------------------------------ + /** returns an object that allows to generate the specified digest. + + @param nDigestID + the internal ID specifying the algorithm, + should take value from <type>DigestID</type> + + @param aParams + optional parameters that could be used to initialize the digest, + for example, it could contain a key and etc. + + @throws ::com::sun::star::lang::IllegalArgumentException + one of provided arguments is illegal + */ + XDigestContext getDigestContext( + [in] long nDigestID, + [in] sequence< ::com::sun::star::beans::NamedValue > aParams ) + raises( ::com::sun::star::lang::IllegalArgumentException ); +}; + +//============================================================================ + +}; }; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/xml/crypto/XSEInitializer.idl b/offapi/com/sun/star/xml/crypto/XSEInitializer.idl index eedbfa9551a4..bb0422148f57 100644 --- a/offapi/com/sun/star/xml/crypto/XSEInitializer.idl +++ b/offapi/com/sun/star/xml/crypto/XSEInitializer.idl @@ -41,13 +41,14 @@ published interface XXMLSecurityContext; published interface XSEInitializer : com::sun::star::uno::XInterface { /** - * Creates a security context. - * - * @param certificateDatabase the file or directory of the key materials - * @return the security context created + Creates a security context. + + @param aString + reserved for internal use. + + @return the security context created */ - com::sun::star::xml::crypto::XXMLSecurityContext createSecurityContext( - [in] string certificateDatabase); + ::com::sun::star::xml::crypto::XXMLSecurityContext createSecurityContext( [in] string aString ); /** * Frees a security context. diff --git a/offapi/com/sun/star/xml/crypto/makefile.mk b/offapi/com/sun/star/xml/crypto/makefile.mk index 4aa3957ac418..c03b2a76daf7 100644 --- a/offapi/com/sun/star/xml/crypto/makefile.mk +++ b/offapi/com/sun/star/xml/crypto/makefile.mk @@ -58,6 +58,12 @@ IDLFILES=\ XMLSignatureException.idl \ XMLEncryptionException.idl \ XUriBinding.idl \ + CipherID.idl \ + DigestID.idl \ + XCipherContext.idl \ + XCipherContextSupplier.idl \ + XDigestContext.idl \ + XDigestContextSupplier.idl \ SecurityOperationStatus.idl # ------------------------------------------------------------------ diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index 2475bd6f35ba..3572b37e3e82 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -2392,9 +2392,23 @@ <desc>ODFVER_LATEST</desc> </info> </enumeration> - </constraints> - <value>3</value> - </prop> + </constraints> + <value>3</value> + </prop> + <prop oor:name="UseSHA1InODF12" oor:type="xs:boolean"> + <info> + <author>MAV</author> + <desc>Specifies whether SHA1 algorithm instead of SHA256 should be used in ODF12 for StartKey and Checksum generation during encryption.</desc> + </info> + <value>false</value> + </prop> + <prop oor:name="UseBlowfishInODF12" oor:type="xs:boolean"> + <info> + <author>MAV</author> + <desc>Specifies whether Blowfish algorithm instead of AES should be used in ODF12 for encryption.</desc> + </info> + <value>false</value> + </prop> </group> </group> <group oor:name="Load"> diff --git a/oovbaapi/ooo/vba/XApplicationBase.idl b/oovbaapi/ooo/vba/XApplicationBase.idl index 1291276ae643..3d0e6c9ce0f5 100644 --- a/oovbaapi/ooo/vba/XApplicationBase.idl +++ b/oovbaapi/ooo/vba/XApplicationBase.idl @@ -45,7 +45,6 @@ interface XApplicationBase [attribute, readonly] string Version; [attribute, readonly] any VBE; - [attribute, readonly] any VBProjects; void Quit(); diff --git a/oovbaapi/ooo/vba/XCollectionBase.idl b/oovbaapi/ooo/vba/XCollectionBase.idl new file mode 100755 index 000000000000..245b252f7856 --- /dev/null +++ b/oovbaapi/ooo/vba/XCollectionBase.idl @@ -0,0 +1,56 @@ +/************************************************************************* + * + * Copyright 2010, Oracle and/or its affiliates. All rights reserved. + * + ************************************************************************/ + +#ifndef OOO_VBA_XOLLECTIONBASE_IDL +#define OOO_VBA_XOLLECTIONBASE_IDL + +#include <com/sun/star/container/XEnumerationAccess.idl> +#include <com/sun/star/script/XDefaultMethod.idl> + +//============================================================================= + +module ooo { module vba { + +//============================================================================= + +/** Base interface for VBA collections. + + Every VBA collection provides the number of items, an enumeration access of + all collection items (e.g. for the "For Each" loop), and a way to access + single items, usually via the method "Item". + + The various VBA collection objects expect a specific number of arguments in + the "Item" method, therefore this method is not part of this base interface + but has to be specified seperately in every derived interface. + */ +interface XCollectionBase +{ + //------------------------------------------------------------------------- + /** Provides an enumeration of all items in this collection. + */ + interface ::com::sun::star::container::XEnumerationAccess; + + //------------------------------------------------------------------------- + /** Provides the name of the default item access method. + + Usually this method is called "Item". The access method has to be + specified and implemented separately by every derived class. + */ + interface ::com::sun::star::script::XDefaultMethod; + + //------------------------------------------------------------------------- + /** Returns the number of items contained in this collection. + */ + [attribute, readonly] long Count; + + //------------------------------------------------------------------------- +}; + +//============================================================================= + +}; }; + +#endif diff --git a/oovbaapi/ooo/vba/XControlProvider.idl b/oovbaapi/ooo/vba/XControlProvider.idl index 23f890d5a1c3..df8b53bdfc72 100644 --- a/oovbaapi/ooo/vba/XControlProvider.idl +++ b/oovbaapi/ooo/vba/XControlProvider.idl @@ -51,8 +51,6 @@ module ooo { module vba { interface XControlProvider { ::ooo::vba::msforms::XControl createControl( [in] ::com::sun::star::drawing::XControlShape xControl, [in] ::com::sun::star::frame::XModel xDocOwner ); - ::ooo::vba::msforms::XControl createUserformControl( [in] ::com::sun::star::awt::XControl xControl, [in] ::com::sun::star::awt::XControl xDialog, [in] ::com::sun::star::frame::XModel xDocOwner ); - }; }; }; diff --git a/oovbaapi/ooo/vba/XExecutableDialog.idl b/oovbaapi/ooo/vba/XExecutableDialog.idl new file mode 100755 index 000000000000..8754c8071348 --- /dev/null +++ b/oovbaapi/ooo/vba/XExecutableDialog.idl @@ -0,0 +1,58 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#ifndef __ooo_vba_XExecutableDialog_idl__ +#define __ooo_vba_XExecutableDialog_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +//============================================================================= + +module ooo { module vba { + +/** The VBA equivalent to the UNO interface + <type scope="com::sun::star::ui::dialogs">XExecutableDialog</type>. + */ +interface XExecutableDialog +{ + /** Executes the dialog. + + @return + The return value is dependent on the calling context. Usually, on + cancelling the dialog the implementation will return <FALSE/>, + otherwise the return value will contain the expected result. + */ + any execute(); +}; + +//============================================================================= + +}; }; + +#endif + + diff --git a/oovbaapi/ooo/vba/excel/SheetObjects.idl b/oovbaapi/ooo/vba/excel/SheetObjects.idl index 5947c52ff4a0..0a2a3fd9ffe9 100644 --- a/oovbaapi/ooo/vba/excel/SheetObjects.idl +++ b/oovbaapi/ooo/vba/excel/SheetObjects.idl @@ -74,10 +74,10 @@ interface XGraphicObjects : com::sun::star::uno::XInterface /** Adds a new graphic object to the sheet this collection belongs to. The type of the object is determined by the type of the collection. - @param fLeft Position of the left border in points (1/72 inch). - @param fTop Position of the top border in points (1/72 inch). - @param fWidth Width of the object in points (1/72 inch). - @param fHeight Height of the object in points (1/72 inch). + @param Left Position of the left border in points (1/72 inch). + @param Top Position of the top border in points (1/72 inch). + @param Width Width of the object in points (1/72 inch). + @param Height Height of the object in points (1/72 inch). @return The created graphic object. */ @@ -102,10 +102,10 @@ interface XLineObjects : com::sun::star::uno::XInterface /** Adds a new line object to the sheet this collection belongs to. The type of the object is determined by the type of the collection. - @param fX1 Position of the first X coordinate in points (1/72 inch). - @param fY1 Position of the first Y coordinate in points (1/72 inch). - @param fX2 Position of the last X coordinate in points (1/72 inch). - @param fY2 Position of the last Y coordinate in points (1/72 inch). + @param X1 Position of the first X coordinate in points (1/72 inch). + @param Y1 Position of the first Y coordinate in points (1/72 inch). + @param X2 Position of the last X coordinate in points (1/72 inch). + @param Y2 Position of the last Y coordinate in points (1/72 inch). @return The created line object. */ @@ -123,11 +123,11 @@ interface XDrawings : com::sun::star::uno::XInterface { /** Adds a new polygon object to the sheet this collection belongs to. - @param fX1 Position of the first X coordinate in points (1/72 inch). - @param fY1 Position of the first Y coordinate in points (1/72 inch). - @param fX2 Position of the last X coordinate in points (1/72 inch). - @param fY2 Position of the last Y coordinate in points (1/72 inch). - @param bClosed True = outline closed (last and first point connected). + @param X1 Position of the first X coordinate in points (1/72 inch). + @param Y1 Position of the first Y coordinate in points (1/72 inch). + @param X2 Position of the last X coordinate in points (1/72 inch). + @param Y2 Position of the last Y coordinate in points (1/72 inch). + @param Closed True = outline closed (last and first point connected). @return The created polygon object. */ diff --git a/oovbaapi/ooo/vba/excel/XApplication.idl b/oovbaapi/ooo/vba/excel/XApplication.idl index 5ec821dbe8bb..267c9589bfae 100644 --- a/oovbaapi/ooo/vba/excel/XApplication.idl +++ b/oovbaapi/ooo/vba/excel/XApplication.idl @@ -64,15 +64,12 @@ interface XApplication [attribute] any CutCopyMode; [attribute] any StatusBar; [attribute] long Cursor; - [attribute] boolean EnableEvents; + [attribute] boolean EnableEvents; + [attribute] string DefaultFilePath; + [attribute, readonly] string LibraryPath; + [attribute, readonly] string TemplatesPath; + [attribute, readonly] string PathSeparator; - void setDefaultFilePath([in] string DefaultFilePath) raises(com::sun::star::script::BasicErrorException); - - string getDefaultFilePath() raises(com::sun::star::script::BasicErrorException); - - string LibraryPath() raises(com::sun::star::script::BasicErrorException); - string TemplatesPath() raises(com::sun::star::script::BasicErrorException); - string PathSeparator() raises(com::sun::star::script::BasicErrorException); //any CommandBars( [in] any Index ); any Workbooks( [in] any Index ); any Worksheets( [in] any Index ); @@ -93,10 +90,10 @@ interface XApplication void Volatile([in] any Volatile); void DoEvents(); any Caller( [in] any Index ); + any GetOpenFilename( [in] any FileFilter, [in] any FilterIndex, [in] any Title, [in] any ButtonText, [in] any MultiSelect ); + any GetSaveAsFilename( [in] any InitialFileName, [in] any FileFilter, [in] any FilterIndex, [in] any Title, [in] any ButtonText ); }; }; }; }; #endif - - diff --git a/oovbaapi/ooo/vba/makefile.mk b/oovbaapi/ooo/vba/makefile.mk index 4f6d378cfe3f..d1adc1c4252e 100644 --- a/oovbaapi/ooo/vba/makefile.mk +++ b/oovbaapi/ooo/vba/makefile.mk @@ -39,6 +39,7 @@ PACKAGE=ooo$/vba IDLFILES=\ XErrObject.idl \ XCollection.idl\ + XCollectionBase.idl\ XVBAToOOEventDescGen.idl\ XPropValue.idl\ XHelperInterface.idl\ @@ -58,6 +59,7 @@ IDLFILES=\ XGlobalsBase.idl\ XDocumentProperty.idl\ XDocumentProperties.idl\ + XExecutableDialog.idl\ XFontBase.idl\ XDialogsBase.idl\ XDialogBase.idl\ diff --git a/oovbaapi/ooo/vba/msforms/XButton.idl b/oovbaapi/ooo/vba/msforms/XCheckBox.idl index 24cf1ba26c60..7520a559b0d5 100644..100755 --- a/oovbaapi/ooo/vba/msforms/XButton.idl +++ b/oovbaapi/ooo/vba/msforms/XCheckBox.idl @@ -24,20 +24,23 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ -#ifndef __ooo_vba_msforms_XButton_idl__ -#define __ooo_vba_msforms_XButton_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#ifndef __ooo_vba_msforms_XCheckBox_idl__ +#define __ooo_vba_msforms_XCheckBox_idl__ + +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { //============================================================================= -interface XButton: com::sun::star::uno::XInterface + +interface XCheckBox { [attribute] string Caption; + [attribute] any Value; + [attribute, readonly] XNewFont Font; }; //============================================================================= diff --git a/oovbaapi/ooo/vba/msforms/XComboBox.idl b/oovbaapi/ooo/vba/msforms/XComboBox.idl index 5f2b66431eb8..51ca4a4135d1 100644 --- a/oovbaapi/ooo/vba/msforms/XComboBox.idl +++ b/oovbaapi/ooo/vba/msforms/XComboBox.idl @@ -24,26 +24,33 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XComboBox_idl__ #define __ooo_vba_msforms_XComboBox_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif - +#include <ooo/vba/msforms/XNewFont.idl> //============================================================================= module ooo { module vba { module msforms { - //============================================================================= -interface XComboBox: ::com::sun::star::uno::XInterface + +interface XComboBox { [attribute] any Value; [attribute] any ListIndex; - [attribute, readonly ] long ListCount; + [attribute, readonly] long ListCount; [attribute] string Text; + [attribute] long Style; + [attribute] long DropButtonStyle; + [attribute] long DragBehavior; + [attribute] long EnterFieldBehavior; + [attribute] long ListStyle; + [attribute] long TextAlign; + [attribute, readonly] long TextLength; + [attribute, readonly] XNewFont Font; + void AddItem( [in] any pvargItem, [in] any pvargIndex ); void removeItem( [in] any index ); void Clear(); diff --git a/oovbaapi/ooo/vba/msforms/XCommandButton.idl b/oovbaapi/ooo/vba/msforms/XCommandButton.idl new file mode 100644 index 000000000000..0e7697cbd162 --- /dev/null +++ b/oovbaapi/ooo/vba/msforms/XCommandButton.idl @@ -0,0 +1,56 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#ifndef __ooo_vba_msforms_XCommandButton_idl__ +#define __ooo_vba_msforms_XCommandButton_idl__ + +#include <ooo/vba/msforms/XNewFont.idl> + +//============================================================================= + +module ooo { module vba { module msforms { + +//============================================================================= + +interface XCommandButton +{ + [attribute] string Caption; + [attribute] boolean AutoSize; + [attribute] boolean Cancel; + [attribute] boolean Default; + [attribute] long BackColor; + [attribute] long ForeColor; + [attribute, readonly] XNewFont Font; +}; + +//============================================================================= + +}; }; }; + +#endif + + diff --git a/oovbaapi/ooo/vba/msforms/XControl.idl b/oovbaapi/ooo/vba/msforms/XControl.idl index 97ca9d152716..3cd1f2c3e75c 100644 --- a/oovbaapi/ooo/vba/msforms/XControl.idl +++ b/oovbaapi/ooo/vba/msforms/XControl.idl @@ -63,6 +63,7 @@ interface XControl [attribute] string Name; [attribute] string ControlTipText; [attribute] string Tag; + [attribute] long TabIndex; }; //============================================================================= diff --git a/package/source/zipapi/XMemoryStream.hxx b/oovbaapi/ooo/vba/msforms/XFrame.idl index 89db08a6c4ed..6038b61dd3bd 100644..100755 --- a/package/source/zipapi/XMemoryStream.hxx +++ b/oovbaapi/ooo/vba/msforms/XFrame.idl @@ -24,19 +24,32 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ -#ifndef _XMEMORY_STREAM_HXX -#define _XMEMORY_STREAM_HXX -#include <ZipPackageBuffer.hxx> +#ifndef __ooo_vba_msforms_XFrame_idl__ +#define __ooo_vba_msforms_XFrame_idl__ -class ZipPackage; +#include <ooo/vba/msforms/XNewFont.idl> -class XMemoryStream: public ZipPackageBuffer +//============================================================================= + +module ooo { module vba { module msforms { + +//============================================================================= + +interface XFrame { -public: - XMemoryStream ( com::sun::star::uno::Sequence < sal_Int8 > & rNewBuffer ); - virtual ~XMemoryStream(void); - virtual com::sun::star::uno::Any SAL_CALL queryInterface( const com::sun::star::uno::Type& rType ) - throw(com::sun::star::uno::RuntimeException); + [attribute] string Caption; + [attribute] long SpecialEffect; + [attribute] long BorderStyle; + [attribute, readonly] XNewFont Font; + + any Controls( [in] any Index ); }; + +//============================================================================= + +}; }; }; + +//============================================================================= + #endif diff --git a/oovbaapi/ooo/vba/msforms/XGroupBox.idl b/oovbaapi/ooo/vba/msforms/XGroupBox.idl index 9ed6f9d45046..9718f23e1c66 100644 --- a/oovbaapi/ooo/vba/msforms/XGroupBox.idl +++ b/oovbaapi/ooo/vba/msforms/XGroupBox.idl @@ -24,19 +24,22 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XGroupBox_idl__ #define __ooo_vba_msforms_XGroupBox_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { + //============================================================================= + interface XGroupBox { [attribute] string Caption; + [attribute, readonly] XNewFont Font; }; //============================================================================= diff --git a/oovbaapi/ooo/vba/msforms/XLabel.idl b/oovbaapi/ooo/vba/msforms/XLabel.idl index d757af5074d8..399127a091c8 100644 --- a/oovbaapi/ooo/vba/msforms/XLabel.idl +++ b/oovbaapi/ooo/vba/msforms/XLabel.idl @@ -24,21 +24,23 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XLabel_idl__ #define __ooo_vba_msforms_XLabel_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { //============================================================================= -interface XLabel: com::sun::star::uno::XInterface + +interface XLabel { [attribute] string Caption; [attribute] any Value; + [attribute, readonly] XNewFont Font; }; //============================================================================= diff --git a/oovbaapi/ooo/vba/msforms/XListBox.idl b/oovbaapi/ooo/vba/msforms/XListBox.idl index bdc0c6bfc660..63f9cce0bdf8 100644 --- a/oovbaapi/ooo/vba/msforms/XListBox.idl +++ b/oovbaapi/ooo/vba/msforms/XListBox.idl @@ -24,25 +24,27 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XListBox_idl__ #define __ooo_vba_msforms_XListBox_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { - //============================================================================= -interface XListBox: com::sun::star::uno::XInterface + +interface XListBox { [attribute] any Value; [attribute] string Text; [attribute] boolean MultiSelect; [attribute] any ListIndex; - [attribute, readonly ] long ListCount; + [attribute, readonly] long ListCount; + [attribute, readonly] XNewFont Font; + void AddItem( [in] any pvargItem, [in] any pvargIndex ); void removeItem( [in] any index ); void Clear(); diff --git a/oovbaapi/ooo/vba/msforms/XNewFont.idl b/oovbaapi/ooo/vba/msforms/XNewFont.idl new file mode 100755 index 000000000000..755dd510b63a --- /dev/null +++ b/oovbaapi/ooo/vba/msforms/XNewFont.idl @@ -0,0 +1,57 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#ifndef __ooo_vba_msforms_XNewFont_idl__ +#define __ooo_vba_msforms_XNewFont_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +//============================================================================= + +module ooo { module vba { module msforms { + +//============================================================================= + +interface XNewFont +{ + [attribute] string Name; + [attribute] double Size; + [attribute] short Charset; + [attribute] short Weight; + [attribute] boolean Bold; + [attribute] boolean Italic; + [attribute] boolean Underline; + [attribute] boolean Strikethrough; +}; + +//============================================================================= + +}; }; }; + +//============================================================================= + +#endif diff --git a/oovbaapi/ooo/vba/msforms/XRadioButton.idl b/oovbaapi/ooo/vba/msforms/XRadioButton.idl index b2289ce33331..2aced0e92e30 100644 --- a/oovbaapi/ooo/vba/msforms/XRadioButton.idl +++ b/oovbaapi/ooo/vba/msforms/XRadioButton.idl @@ -24,21 +24,23 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XRadioButton_idl__ #define __ooo_vba_msforms_XRadioButton_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { //============================================================================= -interface XRadioButton: com::sun::star::uno::XInterface + +interface XRadioButton { [attribute] string Caption; [attribute] any Value; + [attribute, readonly] XNewFont Font; }; //============================================================================= diff --git a/oovbaapi/ooo/vba/msforms/XTextBox.idl b/oovbaapi/ooo/vba/msforms/XTextBox.idl index 9c6b55e5ca6d..267fbf7f01cb 100644 --- a/oovbaapi/ooo/vba/msforms/XTextBox.idl +++ b/oovbaapi/ooo/vba/msforms/XTextBox.idl @@ -24,23 +24,28 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XTextBox_idl__ #define __ooo_vba_msforms_XTextBox_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { //============================================================================= -interface XTextBox: com::sun::star::uno::XInterface + +interface XTextBox { [attribute] string Text; [attribute] any Value; [attribute] long MaxLength; [attribute] boolean Multiline; + [attribute] long SpecialEffect; + [attribute] long BorderStyle; + [attribute, readonly] long TextLength; + [attribute, readonly] XNewFont Font; }; //============================================================================= diff --git a/oovbaapi/ooo/vba/msforms/XToggleButton.idl b/oovbaapi/ooo/vba/msforms/XToggleButton.idl index e66eea54babb..923f7e1e2203 100644 --- a/oovbaapi/ooo/vba/msforms/XToggleButton.idl +++ b/oovbaapi/ooo/vba/msforms/XToggleButton.idl @@ -24,22 +24,21 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XToggleButton_idl__ #define __ooo_vba_msforms_XToggleButton_idl__ -#ifndef __ooo_vba_msforms_XButton_idl__ -#include <ooo/vba/msforms/XButton.idl> -#endif -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XCommandButton.idl> + //============================================================================= module ooo { module vba { module msforms { + //============================================================================= + interface XToggleButton { - interface XButton; + interface XCommandButton; [attribute] any Value; }; diff --git a/oovbaapi/ooo/vba/msforms/XUserForm.idl b/oovbaapi/ooo/vba/msforms/XUserForm.idl index c06aa2902b53..1e54dd1b8f41 100644 --- a/oovbaapi/ooo/vba/msforms/XUserForm.idl +++ b/oovbaapi/ooo/vba/msforms/XUserForm.idl @@ -39,6 +39,8 @@ interface XUserForm //interface ::ooo::vba::XHelperInterface; interface ::com::sun::star::script::XInvocation; [attribute] string Caption; + [attribute] double InnerWidth; + [attribute] double InnerHeight; void Show(); void Hide(); void RePaint(); diff --git a/oovbaapi/ooo/vba/msforms/makefile.mk b/oovbaapi/ooo/vba/msforms/makefile.mk index 56ac4caf87cb..1d7d9ee166e5 100644 --- a/oovbaapi/ooo/vba/msforms/makefile.mk +++ b/oovbaapi/ooo/vba/msforms/makefile.mk @@ -38,10 +38,13 @@ PACKAGE=ooo$/vba$/msforms IDLFILES=\ MSFormReturnTypes.idl \ + XCheckBox.idl \ XComboBox.idl \ - XButton.idl \ + XCommandButton.idl \ XControl.idl \ + XFrame.idl \ XLabel.idl \ + XNewFont.idl \ XTextBox.idl \ XRadioButton.idl \ XShape.idl \ diff --git a/package/inc/EncryptedDataHeader.hxx b/package/inc/EncryptedDataHeader.hxx index a166397cce34..be2c7643ec51 100644 --- a/package/inc/EncryptedDataHeader.hxx +++ b/package/inc/EncryptedDataHeader.hxx @@ -31,21 +31,25 @@ /* The structure of this header is as follows: - Header signature 4 bytes - Version number 2 bytes - Iteraction count 4 bytes - Size 4 bytes - Salt length 2 bytes - IV length 2 bytes - Digest length 2 bytes - MediaType length 2 bytes - Salt content X bytes - IV content X bytes - digest content X bytes - MediaType X bytes + Header signature 4 bytes + Version number 2 bytes + Iteraction count 4 bytes + Size 4 bytes + EncAlgorithm 4 bytes + DigestAlgorithm 4 bytes + DerivedKeySize 4 bytes + StartKeyAlgorithm 4 bytes + Salt length 2 bytes + IV length 2 bytes + Digest length 2 bytes + MediaType length 2 bytes + Salt content X bytes + IV content X bytes + digest content X bytes + MediaType X bytes */ -const sal_uInt32 n_ConstHeader = 0x0502474dL; // "MG\002\005" -const sal_Int32 n_ConstHeaderSize = 22; // + salt length + iv length + digest length + mediatype length +const sal_uInt32 n_ConstHeader = 0x05024d4dL; // "MM\002\005" +const sal_Int32 n_ConstHeaderSize = 38; // + salt length + iv length + digest length + mediatype length const sal_Int16 n_ConstCurrentVersion = 1; #endif diff --git a/package/inc/EncryptionData.hxx b/package/inc/EncryptionData.hxx index 66d74f739b9c..5d49ae2b7b0f 100644 --- a/package/inc/EncryptionData.hxx +++ b/package/inc/EncryptionData.hxx @@ -30,14 +30,52 @@ #include <com/sun/star/uno/Sequence.hxx> #include <cppuhelper/weak.hxx> -class EncryptionData : public cppu::OWeakObject +class BaseEncryptionData : public cppu::OWeakObject { public: - // On export aKey holds the derived key - // On import aKey holds the hash of the user enterred key - com::sun::star::uno::Sequence < sal_Int8 > aKey; - com::sun::star::uno::Sequence < sal_uInt8 > aSalt, aInitVector, aDigest; - sal_Int32 nIterationCount; - EncryptionData(): nIterationCount ( 0 ){} + ::com::sun::star::uno::Sequence< sal_Int8 > m_aSalt; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aInitVector; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aDigest; + sal_Int32 m_nIterationCount; + + BaseEncryptionData() + : m_nIterationCount ( 0 ){} + + BaseEncryptionData( const BaseEncryptionData& aData ) + : cppu::OWeakObject() + , m_aSalt( aData.m_aSalt ) + , m_aInitVector( aData.m_aInitVector ) + , m_aDigest( aData.m_aDigest ) + , m_nIterationCount( aData.m_nIterationCount ) + {} }; + +class EncryptionData : public BaseEncryptionData +{ +public: + ::com::sun::star::uno::Sequence < sal_Int8 > m_aKey; + sal_Int32 m_nEncAlg; + sal_Int32 m_nCheckAlg; + sal_Int32 m_nDerivedKeySize; + sal_Int32 m_nStartKeyGenID; + + EncryptionData( const BaseEncryptionData& aData, const ::com::sun::star::uno::Sequence< sal_Int8 >& aKey, sal_Int32 nEncAlg, sal_Int32 nCheckAlg, sal_Int32 nDerivedKeySize, sal_Int32 nStartKeyGenID ) + : BaseEncryptionData( aData ) + , m_aKey( aKey ) + , m_nEncAlg( nEncAlg ) + , m_nCheckAlg( nCheckAlg ) + , m_nDerivedKeySize( nDerivedKeySize ) + , m_nStartKeyGenID( nStartKeyGenID ) + {} + + EncryptionData( const EncryptionData& aData ) + : BaseEncryptionData( aData ) + , m_aKey( aData.m_aKey ) + , m_nEncAlg( aData.m_nEncAlg ) + , m_nCheckAlg( aData.m_nCheckAlg ) + , m_nDerivedKeySize( aData.m_nDerivedKeySize ) + , m_nStartKeyGenID( aData.m_nStartKeyGenID ) + {} +}; + #endif diff --git a/package/inc/PackageConstants.hxx b/package/inc/PackageConstants.hxx index a23a22fcb888..90c73edf2ba7 100644 --- a/package/inc/PackageConstants.hxx +++ b/package/inc/PackageConstants.hxx @@ -31,21 +31,39 @@ const sal_Int32 n_ConstBufferSize = 32768; const sal_Int32 n_ConstMaxMemoryStreamSize = 20480; + +// by calculation of the digest we read 32 bytes more ( if available ) +// it allows to ignore the padding if the stream is longer than n_ConstDigestDecrypt since we read at least two blocks more; +// if the stream is shorter or equal the padding will be done successfully const sal_Int32 n_ConstDigestLength = 1024; +const sal_Int32 n_ConstDigestDecrypt = 1056; // 1024 + 32 // the constants related to the manifest.xml entries -#define PKG_MNFST_MEDIATYPE 0 -#define PKG_MNFST_VERSION 1 -#define PKG_MNFST_FULLPATH 2 +#define PKG_MNFST_MEDIATYPE 0 +#define PKG_MNFST_VERSION 1 +#define PKG_MNFST_FULLPATH 2 -#define PKG_MNFST_INIVECTOR 3 -#define PKG_MNFST_SALT 4 -#define PKG_MNFST_ITERATION 5 -#define PKG_MNFST_UCOMPSIZE 6 -#define PKG_MNFST_DIGEST 7 +#define PKG_MNFST_INIVECTOR 3 +#define PKG_MNFST_SALT 4 +#define PKG_MNFST_ITERATION 5 +#define PKG_MNFST_UCOMPSIZE 6 +#define PKG_MNFST_DIGEST 7 +#define PKG_MNFST_ENCALG 8 +#define PKG_MNFST_STARTALG 9 +#define PKG_MNFST_DIGESTALG 10 +#define PKG_MNFST_DERKEYSIZE 11 #define PKG_SIZE_NOENCR_MNFST 3 -#define PKG_SIZE_ENCR_MNFST 8 +#define PKG_SIZE_ENCR_MNFST 12 + +// the properties related constants +#define ENCRYPTION_KEY_PROPERTY "EncryptionKey" +#define STORAGE_ENCRYPTION_KEYS_PROPERTY "StorageEncryptionKeys" +#define ENCRYPTION_ALGORITHMS_PROPERTY "EncryptionAlgorithms" +#define HAS_ENCRYPTED_ENTRIES_PROPERTY "HasEncryptedEntries" +#define HAS_NONENCRYPTED_ENTRIES_PROPERTY "HasNonEncryptedEntries" +#define IS_INCONSISTENT_PROPERTY "IsInconsistent" +#define MEDIATYPE_FALLBACK_USED_PROPERTY "MediaTypeFallbackUsed" #endif diff --git a/package/inc/ZipFile.hxx b/package/inc/ZipFile.hxx index be8158c0ba4e..2be52615c90b 100644 --- a/package/inc/ZipFile.hxx +++ b/package/inc/ZipFile.hxx @@ -31,11 +31,15 @@ #include <com/sun/star/packages/zip/ZipIOException.hpp> #include <com/sun/star/packages/NoEncryptionException.hpp> #include <com/sun/star/packages/WrongPasswordException.hpp> +#include <com/sun/star/xml/crypto/XCipherContext.hpp> +#include <com/sun/star/xml/crypto/XDigestContext.hpp> + +#include <rtl/ref.hxx> + #include <ByteGrabber.hxx> #include <HashMaps.hxx> -#ifndef _INFLATER_HXX #include <Inflater.hxx> -#endif +#include <EncryptionData.hxx> #include <mutexholder.hxx> @@ -43,10 +47,7 @@ namespace com { namespace sun { namespace star { namespace lang { class XMultiServiceFactory; } namespace ucb { class XProgressHandler; } } } } -namespace vos -{ - template < class T > class ORef; -} + /* * We impose arbitrary but reasonable limit on ZIP files. */ @@ -55,9 +56,7 @@ namespace vos #define ZIP_MAXEXTRA 256 #define ZIP_MAXENTRIES (0x10000 - 2) -typedef void* rtlCipher; class ZipEnumeration; -class EncryptionData; class ZipFile { @@ -70,20 +69,20 @@ protected: Inflater aInflater; com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream; com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xSeek; - const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xFactory; + const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgressHandler; sal_Bool bRecoveryMode; com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createMemoryStream( ZipEntry & rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bRawStream, sal_Bool bDecrypt ); com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createFileStream( ZipEntry & rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bRawStream, sal_Bool bDecrypt ); @@ -91,12 +90,12 @@ protected: com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createUnbufferedStream( SotMutexHolderRef aMutexHolder, ZipEntry & rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Int8 nStreamMode, sal_Bool bDecrypt, ::rtl::OUString aMediaType = ::rtl::OUString() ); - sal_Bool hasValidPassword ( ZipEntry & rEntry, const vos::ORef < EncryptionData > &rData ); + sal_Bool hasValidPassword ( ZipEntry & rEntry, const ::rtl::Reference < EncryptionData > &rData ); sal_Bool checkSizeAndCRC( const ZipEntry& aEntry ); @@ -127,44 +126,59 @@ public: void setInputStream ( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewStream ); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bDecrypt, SotMutexHolderRef aMutexHolder ) throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException); - static sal_Bool StaticGetCipher ( const vos::ORef < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode ); - static void StaticFillHeader ( const vos::ORef < EncryptionData > & rData, + static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xArgFactory, + const ::rtl::Reference< EncryptionData >& xEncryptionData ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > StaticGetCipher( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xArgFactory, + const ::rtl::Reference< EncryptionData >& xEncryptionData, + bool bEncrypt ); + + static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData, sal_Int32 nSize, const ::rtl::OUString& aMediaType, sal_Int8 * & pHeader ); - static sal_Bool StaticFillData ( vos::ORef < EncryptionData > & rData, + static sal_Bool StaticFillData ( ::rtl::Reference < BaseEncryptionData > & rData, + sal_Int32 &rEncAlgorithm, + sal_Int32 &rChecksumAlgorithm, + sal_Int32 &rDerivedKeySize, + sal_Int32 &rStartKeyGenID, sal_Int32 &rSize, ::rtl::OUString& aMediaType, - ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &rStream ); + const ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream ); static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StaticGetDataFromRawStream( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream, - const vos::ORef < EncryptionData > &rData ) + const ::rtl::Reference < EncryptionData > &rData ) throw ( ::com::sun::star::packages::WrongPasswordException, ::com::sun::star::packages::zip::ZipIOException, ::com::sun::star::uno::RuntimeException ); - static sal_Bool StaticHasValidPassword ( const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer, - const vos::ORef < EncryptionData > &rData ); + static sal_Bool StaticHasValidPassword ( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer, + const ::rtl::Reference < EncryptionData > &rData ); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bDecrypt, SotMutexHolderRef aMutexHolder ) throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bDecrypt, SotMutexHolderRef aMutexHolder ) throw ( ::com::sun::star::packages::WrongPasswordException, @@ -174,7 +188,7 @@ public: ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getWrappedRawStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, const ::rtl::OUString& aMediaType, SotMutexHolderRef aMutexHolder ) throw ( ::com::sun::star::packages::NoEncryptionException, diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx index 345fe332b8cc..48fafb4c4a9c 100644 --- a/package/inc/ZipOutputStream.hxx +++ b/package/inc/ZipOutputStream.hxx @@ -27,43 +27,48 @@ #ifndef _ZIP_OUTPUT_STREAM_HXX #define _ZIP_OUTPUT_STREAM_HXX +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/xml/crypto/XCipherContext.hpp> +#include <com/sun/star/xml/crypto/XDigestContext.hpp> + #include <ByteChucker.hxx> -#ifndef _DEFLATER_HXX #include <Deflater.hxx> -#endif #include <CRC32.hxx> -#include <rtl/cipher.h> -#ifndef RTL_DIGEST_H_ -#include <rtl/digest.h> -#endif #include <vector> struct ZipEntry; -class EncryptionData; -namespace vos -{ - template < class T > class ORef; -} +class ZipPackageStream; + class ZipOutputStream { protected: - com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > xStream; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xStream; + ::std::vector < ZipEntry * > aZipList; - com::sun::star::uno::Sequence < sal_Int8 > aBuffer, aEncryptionBuffer; + + ::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer; + ::rtl::OUString sComment; Deflater aDeflater; - rtlCipher aCipher; - rtlDigest aDigest; + + ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext; + CRC32 aCRC; ByteChucker aChucker; ZipEntry *pCurrentEntry; sal_Int16 nMethod, nLevel, mnDigested; sal_Bool bFinished, bEncryptCurrentEntry; - EncryptionData *pCurrentEncryptData; + ZipPackageStream* m_pCurrentStream; public: - ZipOutputStream( com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > &xOStream ); + ZipOutputStream( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > &xOStream ); ~ZipOutputStream(); // rawWrite to support a direct write to the output stream @@ -78,7 +83,7 @@ public: void SAL_CALL setLevel( sal_Int32 nNewLevel ) throw(::com::sun::star::uno::RuntimeException); void SAL_CALL putNextEntry( ZipEntry& rEntry, - vos::ORef < EncryptionData > &rData, + ZipPackageStream* pStream, sal_Bool bEncrypt = sal_False ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); void SAL_CALL closeEntry( ) diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx index e3b8d44be183..f7b80f38b359 100644 --- a/package/inc/ZipPackage.hxx +++ b/package/inc/ZipPackage.hxx @@ -35,11 +35,12 @@ #include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/PropertyValue.hpp> -#ifndef _COM_SUN_STAR_LANG_XPSERVICEINFO_HPP_ +#include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> -#endif -#include <HashMaps.hxx> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> + +#include <HashMaps.hxx> #include <osl/file.h> #include <mutexholder.hxx> @@ -83,18 +84,24 @@ class ZipPackage : public cppu::WeakImplHelper7 protected: SotMutexHolderRef m_aMutexHolder; - ::com::sun::star::uno::Sequence < sal_Int8 > m_aEncryptionKey; - FolderHash m_aRecent; - ::rtl::OUString m_aURL; - sal_Bool m_bHasEncryptedEntries; - sal_Bool m_bHasNonEncryptedEntries; - sal_Bool m_bInconsistent; - sal_Bool m_bUseManifest; - sal_Bool m_bForceRecovery; + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey; - sal_Bool m_bMediaTypeFallbackUsed; - sal_Int32 m_nFormat; - sal_Bool m_bAllowRemoveOnInsert; + FolderHash m_aRecent; + ::rtl::OUString m_aURL; + + sal_Int32 m_nStartKeyGenerationID; + sal_Int32 m_nChecksumDigestID; + sal_Int32 m_nCommonEncryptionID; + sal_Bool m_bHasEncryptedEntries; + sal_Bool m_bHasNonEncryptedEntries; + + sal_Bool m_bInconsistent; + sal_Bool m_bForceRecovery; + + sal_Bool m_bMediaTypeFallbackUsed; + sal_Int32 m_nFormat; + sal_Bool m_bAllowRemoveOnInsert; InitialisationMode m_eMode; @@ -121,15 +128,20 @@ protected: const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xTempStream ); public: - ZipPackage (const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory); + ZipPackage( const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory ); virtual ~ZipPackage( void ); ZipFile& getZipFile() { return *m_pZipFile;} - const com::sun::star::uno::Sequence < sal_Int8 > & getEncryptionKey ( ) {return m_aEncryptionKey;} sal_Int32 getFormat() const { return m_nFormat; } + sal_Int32 GetStartKeyGenID() const { return m_nStartKeyGenerationID; } + sal_Int32 GetEncAlgID() const { return m_nCommonEncryptionID; } + sal_Int32 GetChecksumAlgID() const { return m_nChecksumDigestID; } + sal_Int32 GetDefaultDerivedKeySize() const { return m_nCommonEncryptionID == ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 32 : 16; } + SotMutexHolderRef GetSharedMutexRef() { return m_aMutexHolder; } void ConnectTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ); + const ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey(); // XInitialization virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) diff --git a/package/source/zippackage/ZipPackageEntry.hxx b/package/inc/ZipPackageEntry.hxx index 767d84511a12..767d84511a12 100644 --- a/package/source/zippackage/ZipPackageEntry.hxx +++ b/package/inc/ZipPackageEntry.hxx diff --git a/package/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx index 635aca16ba92..6a80f0effdaa 100644 --- a/package/inc/ZipPackageFolder.hxx +++ b/package/inc/ZipPackageFolder.hxx @@ -90,10 +90,10 @@ public: void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; } void setRemoveOnInsertMode_Impl( sal_Bool bRemove ) { this->mbAllowRemoveOnInsert = bRemove; } - bool saveChild(const rtl::OUString &rShortName, const com::sun::star::packages::ContentInfo &rInfo, rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, com::sun::star::uno::Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool); + bool saveChild(const rtl::OUString &rShortName, const com::sun::star::packages::ContentInfo &rInfo, rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, const com::sun::star::uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool & rRandomPool); // Recursive functions - void saveContents(rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, com::sun::star::uno::Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool) + void saveContents(rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, const com::sun::star::uno::Sequence< sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool) throw(::com::sun::star::uno::RuntimeException); void releaseUpwardRef(); diff --git a/package/source/zippackage/ZipPackageStream.hxx b/package/inc/ZipPackageStream.hxx index 38301d5e7d12..a3bbf73bf84c 100644 --- a/package/source/zippackage/ZipPackageStream.hxx +++ b/package/inc/ZipPackageStream.hxx @@ -29,15 +29,14 @@ #include <com/sun/star/io/XActiveDataSink.hpp> #include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/packages/XDataSinkEncrSupport.hpp> + +#include <rtl/ref.hxx> +#include <cppuhelper/implbase2.hxx> + #include <ZipPackageEntry.hxx> -#ifndef _VOS_REF_H_ -#include <vos/ref.hxx> -#endif #include <EncryptionData.hxx> -#ifndef _CPPUHELPER_IMPLBASE2_HXX -#include <cppuhelper/implbase2.hxx> -#endif #include <mutexholder.hxx> #define PACKAGE_STREAM_NOTSET 0 @@ -60,7 +59,15 @@ protected: const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; ZipPackage &rZipPackage; sal_Bool bToBeCompressed, bToBeEncrypted, bHaveOwnKey, bIsEncrypted; - vos::ORef < EncryptionData > xEncryptionData; + + ::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData; + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey; + + sal_Int32 m_nImportedStartKeyAlgorithm; + sal_Int32 m_nImportedEncryptionAlgorithm; + sal_Int32 m_nImportedChecksumAlgorithm; + sal_Int32 m_nImportedDerivedKeySize; sal_uInt8 m_nStreamMode; sal_uInt32 m_nMagicalHackPos; @@ -72,7 +79,9 @@ protected: sal_Bool m_bFromManifest; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& GetOwnSeekStream(); + bool m_bUseWinEncoding; + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnSeekStream(); public: sal_Bool HasOwnKey () const { return bHaveOwnKey;} @@ -84,46 +93,56 @@ public: sal_Bool IsFromManifest() const { return m_bFromManifest; } void SetFromManifest( sal_Bool bValue ) { m_bFromManifest = bValue; } - vos::ORef < EncryptionData > & getEncryptionData () - { return xEncryptionData;} - const com::sun::star::uno::Sequence < sal_Int8 >& getKey () const - { return xEncryptionData->aKey;} - const com::sun::star::uno::Sequence < sal_uInt8 >& getInitialisationVector () const - { return xEncryptionData->aInitVector;} - const com::sun::star::uno::Sequence < sal_uInt8 >& getDigest () const - { return xEncryptionData->aDigest;} - const com::sun::star::uno::Sequence < sal_uInt8 >& getSalt () const - { return xEncryptionData->aSalt;} + ::rtl::Reference< EncryptionData > GetEncryptionData( bool bWinEncoding = false ); + void SetBaseEncryptionData( const ::rtl::Reference< BaseEncryptionData >& xData ); + + ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey( bool bWinEncoding = false ); + + sal_Int32 GetStartKeyGenID(); + + const com::sun::star::uno::Sequence < sal_Int8 > getInitialisationVector () const + { return m_xBaseEncryptionData->m_aInitVector;} + const com::sun::star::uno::Sequence < sal_Int8 > getDigest () const + { return m_xBaseEncryptionData->m_aDigest;} + const com::sun::star::uno::Sequence < sal_Int8 > getSalt () const + { return m_xBaseEncryptionData->m_aSalt;} sal_Int32 getIterationCount () const - { return xEncryptionData->nIterationCount;} + { return m_xBaseEncryptionData->m_nIterationCount;} sal_Int32 getSize () const { return aEntry.nSize;} sal_uInt8 GetStreamMode() const { return m_nStreamMode; } sal_uInt32 GetMagicalHackPos() const { return m_nMagicalHackPos; } sal_uInt32 GetMagicalHackSize() const { return m_nMagicalHackSize; } + sal_Int32 GetEncryptionAlgorithm() const; + sal_Int32 GetBlockSize() const; void SetToBeCompressed (sal_Bool bNewValue) { bToBeCompressed = bNewValue;} void SetIsEncrypted (sal_Bool bNewValue) { bIsEncrypted = bNewValue;} + void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; } + void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; } + void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; } + void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; } void SetToBeEncrypted (sal_Bool bNewValue) { bToBeEncrypted = bNewValue; - if ( bToBeEncrypted && xEncryptionData.isEmpty()) - xEncryptionData = new EncryptionData; - else if ( !bToBeEncrypted && !xEncryptionData.isEmpty() ) - xEncryptionData.unbind(); + if ( bToBeEncrypted && !m_xBaseEncryptionData.is()) + m_xBaseEncryptionData = new BaseEncryptionData; + else if ( !bToBeEncrypted && m_xBaseEncryptionData.is() ) + m_xBaseEncryptionData.clear(); } void SetPackageMember (sal_Bool bNewValue); + void setKey (const com::sun::star::uno::Sequence < sal_Int8 >& rNewKey ) - { xEncryptionData->aKey = rNewKey;} - void setInitialisationVector (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewVector ) - { xEncryptionData->aInitVector = rNewVector;} - void setSalt (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewSalt ) - { xEncryptionData->aSalt = rNewSalt;} - void setDigest (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewDigest ) - { xEncryptionData->aDigest = rNewDigest;} + { m_aEncryptionKey = rNewKey; m_aStorageEncryptionKeys.realloc( 0 ); } + void setInitialisationVector (const com::sun::star::uno::Sequence < sal_Int8 >& rNewVector ) + { m_xBaseEncryptionData->m_aInitVector = rNewVector;} + void setSalt (const com::sun::star::uno::Sequence < sal_Int8 >& rNewSalt ) + { m_xBaseEncryptionData->m_aSalt = rNewSalt;} + void setDigest (const com::sun::star::uno::Sequence < sal_Int8 >& rNewDigest ) + { m_xBaseEncryptionData->m_aDigest = rNewDigest;} void setIterationCount (const sal_Int32 nNewCount) - { xEncryptionData->nIterationCount = nNewCount;} + { m_xBaseEncryptionData->m_nIterationCount = nNewCount;} void setSize (const sal_Int32 nNewSize); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnStreamNoWrap() { return xStream; } diff --git a/package/qa/storages/TestHelper.java b/package/qa/storages/TestHelper.java index dc28786513b1..1a67f2bfdf79 100644 --- a/package/qa/storages/TestHelper.java +++ b/package/qa/storages/TestHelper.java @@ -1434,24 +1434,24 @@ public class TestHelper { try { - byte pData[][] = new byte[1][22]; - if ( xHeadRawStream.readBytes( pData, 22 ) != 22 ) + byte pData[][] = new byte[1][38]; + if ( xHeadRawStream.readBytes( pData, 38 ) != 38 ) { Error( "Can't read header of encrypted stream '" + sStreamName + "' raw representations!" ); return false; } - if ( pData[0][0] != 0x4d || pData[0][1] != 0x47 || pData[0][2] != 0x02 || pData[0][3] != 0x05 ) + if ( pData[0][0] != 0x4d || pData[0][1] != 0x4d || pData[0][2] != 0x02 || pData[0][3] != 0x05 ) { Error( "No signature in the header of encrypted stream '" + sStreamName + "' raw representations!" ); return false; } int nVariableHeaderLength = - ( pData[0][14] + pData[0][15] * 0x100 ) // salt length - + ( pData[0][16] + pData[0][17] * 0x100 ) // iv length - + ( pData[0][18] + pData[0][19] * 0x100 ) // digest length - + ( pData[0][20] + pData[0][21] * 0x100 ); // mediatype length + ( pData[0][30] + pData[0][31] * 0x100 ) // salt length + + ( pData[0][32] + pData[0][33] * 0x100 ) // iv length + + ( pData[0][34] + pData[0][35] * 0x100 ) // digest length + + ( pData[0][36] + pData[0][37] * 0x100 ); // mediatype length xHeadRawStream.skipBytes( nVariableHeaderLength ); @@ -1467,7 +1467,7 @@ public class TestHelper { if ( nRead1 != nRead2 ) { - Error( "The encrypted stream '" + sStreamName + "' raw representations have different size!" ); + Error( "The encrypted stream '" + sStreamName + "' raw representations have different size! nRead1 - nRead2 = " + ( new Integer( nRead1 - nRead2 ) ).toString() ); return false; } diff --git a/package/source/manifest/Base64Codec.cxx b/package/source/manifest/Base64Codec.cxx index b9ffed0b0514..3539b2bb75b4 100644 --- a/package/source/manifest/Base64Codec.cxx +++ b/package/source/manifest/Base64Codec.cxx @@ -129,11 +129,11 @@ void ThreeByteToFourByte (const sal_uInt8* pBuffer, const sal_Int32 nStart, cons sBuffer.setCharAt(3, aBase64EncodeTable [nIndex]); } -void Base64Codec::encodeBase64(rtl::OUStringBuffer& aStrBuffer, const uno::Sequence < sal_uInt8 >& aPass) +void Base64Codec::encodeBase64(rtl::OUStringBuffer& aStrBuffer, const uno::Sequence < sal_Int8 >& aPass) { sal_Int32 i(0); sal_Int32 nBufferLength(aPass.getLength()); - const sal_uInt8* pBuffer = aPass.getConstArray(); + const sal_uInt8* pBuffer = reinterpret_cast< const sal_uInt8* >( aPass.getConstArray() ); while (i < nBufferLength) { rtl::OUStringBuffer sBuffer; @@ -183,7 +183,7 @@ void FourByteToThreeByte (sal_uInt8* pBuffer, sal_Int32& nLength, const sal_Int3 pBuffer[nStart + 2] = OneByte; } -void Base64Codec::decodeBase64(uno::Sequence< sal_uInt8 >& aBuffer, const rtl::OUString& sBuffer) +void Base64Codec::decodeBase64(uno::Sequence< sal_Int8 >& aBuffer, const rtl::OUString& sBuffer) { sal_Int32 nFirstLength((sBuffer.getLength() / 4) * 3); sal_uInt8* pBuffer = new sal_uInt8[nFirstLength]; @@ -199,6 +199,6 @@ void Base64Codec::decodeBase64(uno::Sequence< sal_uInt8 >& aBuffer, const rtl::O i += 4; k += 3; } - aBuffer = uno::Sequence<sal_uInt8>(pBuffer, nSecondLength); + aBuffer = uno::Sequence<sal_Int8>( reinterpret_cast< sal_Int8* >( pBuffer ), nSecondLength ); delete[] pBuffer; } diff --git a/package/source/manifest/Base64Codec.hxx b/package/source/manifest/Base64Codec.hxx index 04398c7bba29..f655ee54431a 100644 --- a/package/source/manifest/Base64Codec.hxx +++ b/package/source/manifest/Base64Codec.hxx @@ -39,7 +39,7 @@ class OUStringBuffer; class Base64Codec { public: - static void encodeBase64(rtl::OUStringBuffer& aStrBuffer, const com::sun::star::uno::Sequence<sal_uInt8>& aPass); - static void decodeBase64(com::sun::star::uno::Sequence<sal_uInt8>& aPass, const rtl::OUString& sBuffer); + static void encodeBase64(rtl::OUStringBuffer& aStrBuffer, const com::sun::star::uno::Sequence<sal_Int8>& aPass); + static void decodeBase64(com::sun::star::uno::Sequence<sal_Int8>& aPass, const rtl::OUString& sBuffer); }; #endif diff --git a/package/source/manifest/ManifestDefines.hxx b/package/source/manifest/ManifestDefines.hxx index d53337236bb2..a34648d892ec 100644 --- a/package/source/manifest/ManifestDefines.hxx +++ b/package/source/manifest/ManifestDefines.hxx @@ -53,15 +53,28 @@ #define ELEMENT_START_KEY_GENERATION "manifest:start-key-generation" #define ATTRIBUTE_START_KEY_GENERATION_NAME "manifest:start-key-generation-name" -#define ALGORITHM_SHA1 "SHA1" #define ATTRIBUTE_KEY_SIZE "manifest:key-size" -#define START_KEY_SIZE "20" #define ELEMENT_KEY_DERIVATION "manifest:key-derivation" #define ATTRIBUTE_KEY_DERIVATION_NAME "manifest:key-derivation-name" #define ATTRIBUTE_SALT "manifest:salt" #define ATTRIBUTE_ITERATION_COUNT "manifest:iteration-count" -#define CHECKSUM_TYPE "SHA1/1K" -#define DERIVED_KEY_SIZE "16" + +#define SHA256_URL "http://www.w3.org/2000/09/xmldsig#sha256" +#define SHA1_NAME "SHA1" +#define SHA1_URL "http://www.w3.org/2000/09/xmldsig#sha1" + +#define SHA1_1K_NAME "SHA1/1K" +#define SHA1_1K_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha1-1k" +#define SHA256_1K_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha256-1k" + +#define BLOWFISH_NAME "Blowfish CFB" +#define BLOWFISH_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#blowfish" +#define AES128_URL "http://www.w3.org/2001/04/xmlenc#aes128-cbc" +#define AES192_URL "http://www.w3.org/2001/04/xmlenc#aes192-cbc" +#define AES256_URL "http://www.w3.org/2001/04/xmlenc#aes256-cbc" + +#define PBKDF2_NAME "PBKDF2" +#define PBKDF2_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#pbkdf2" #endif diff --git a/package/source/manifest/ManifestExport.cxx b/package/source/manifest/ManifestExport.cxx index 6175bdc4e613..068ff48e2c69 100644 --- a/package/source/manifest/ManifestExport.cxx +++ b/package/source/manifest/ManifestExport.cxx @@ -27,86 +27,89 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_package.hxx" -#include <ManifestExport.hxx> -#include <ManifestDefines.hxx> -#ifndef _COM_SUN_STAR_XML_SAX_XATTRIBUTELIST_HXX -#include <com/sun/star/xml/sax/XAttributeList.hpp> -#endif -#include <rtl/ustrbuf.hxx> -#ifndef _BASE64_CODEC_HXX_ -#include <Base64Codec.hxx> -#endif + #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> -#ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HXX #include <com/sun/star/xml/sax/XDocumentHandler.hpp> -#endif -#ifndef _COM_SUN_STAR_XML_BEANS_PROPERTYVALUE_HPP +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <com/sun/star/beans/PropertyValue.hpp> -#endif +#include <com/sun/star/uno/RuntimeException.hpp> +#include <ManifestDefines.hxx> +#include <ManifestExport.hxx> +#include <Base64Codec.hxx> + +#include <rtl/ustrbuf.hxx> #include <comphelper/documentconstants.hxx> #include <comphelper/attributelist.hxx> -using namespace rtl; -using namespace com::sun::star::beans; -using namespace com::sun::star::uno; -using namespace com::sun::star::xml::sax; +using namespace ::com::sun::star; -ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const Sequence < Sequence < PropertyValue > > &rManList ) +ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > xHandler, const uno::Sequence< uno::Sequence < beans::PropertyValue > >& rManList ) { - const OUString sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ); - const OUString sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ); - const OUString sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ); - const OUString sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ); - const OUString sStartKeyGenerationElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) ); - const OUString sKeyDerivationElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ); - - const OUString sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ); - const OUString sMediaTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) ); - const OUString sVersionAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ); - const OUString sFullPathAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) ); - const OUString sSizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) ); - const OUString sKeySizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) ); - const OUString sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ); - const OUString sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ); - const OUString sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ); - const OUString sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ); - const OUString sStartKeyGenerationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) ); - const OUString sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ); - const OUString sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) ); - const OUString sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM) ); - - const OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); - const OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); - const OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); - const OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); - const OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); - const OUString sInitialisationVectorProperty( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); - const OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); - const OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); - - const OUString sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ); - const OUString sBlowfish ( RTL_CONSTASCII_USTRINGPARAM ( "Blowfish CFB" ) ); - const OUString sPBKDF2 ( RTL_CONSTASCII_USTRINGPARAM ( "PBKDF2" ) ); - const OUString sChecksumType ( RTL_CONSTASCII_USTRINGPARAM ( CHECKSUM_TYPE ) ); - const OUString sStartKeySize ( RTL_CONSTASCII_USTRINGPARAM ( START_KEY_SIZE ) ); - const OUString sDerivedKeySize ( RTL_CONSTASCII_USTRINGPARAM ( DERIVED_KEY_SIZE ) ); - const OUString sSHA1 ( RTL_CONSTASCII_USTRINGPARAM ( ALGORITHM_SHA1 ) ); + const ::rtl::OUString sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ); + const ::rtl::OUString sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ); + const ::rtl::OUString sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ); + const ::rtl::OUString sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ); + const ::rtl::OUString sStartKeyGenerationElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) ); + const ::rtl::OUString sKeyDerivationElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ); + + const ::rtl::OUString sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ); + const ::rtl::OUString sMediaTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) ); + const ::rtl::OUString sVersionAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ); + const ::rtl::OUString sFullPathAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) ); + const ::rtl::OUString sSizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) ); + const ::rtl::OUString sKeySizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) ); + const ::rtl::OUString sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ); + const ::rtl::OUString sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ); + const ::rtl::OUString sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ); + const ::rtl::OUString sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ); + const ::rtl::OUString sStartKeyGenerationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) ); + const ::rtl::OUString sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ); + const ::rtl::OUString sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) ); + const ::rtl::OUString sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM) ); + + const ::rtl::OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); + const ::rtl::OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); + const ::rtl::OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); + const ::rtl::OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); + const ::rtl::OUString sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ); + const ::rtl::OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); + const ::rtl::OUString sInitialisationVectorProperty( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); + const ::rtl::OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); + const ::rtl::OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); + const ::rtl::OUString sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ); + const ::rtl::OUString sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ); + const ::rtl::OUString sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ); + + const ::rtl::OUString sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ); + + const ::rtl::OUString sSHA256_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL ) ); + const ::rtl::OUString sSHA1_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_NAME ) ); + + const ::rtl::OUString sSHA1_1k_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_NAME ) ); + const ::rtl::OUString sSHA256_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_1K_URL ) ); + + const ::rtl::OUString sBlowfish_Name ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_NAME ) ); + const ::rtl::OUString sAES256_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES256_URL ) ); + + const ::rtl::OUString sPBKDF2_Name ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_NAME ) ); ::comphelper::AttributeList * pRootAttrList = new ::comphelper::AttributeList; - const Sequence < PropertyValue > *pSequence = rManList.getConstArray(); + const uno::Sequence < beans::PropertyValue > *pSequence = rManList.getConstArray(); const sal_uInt32 nManLength = rManList.getLength(); // find the mediatype of the document if any - OUString aDocMediaType; - OUString aDocVersion; + ::rtl::OUString aDocMediaType; + ::rtl::OUString aDocVersion; for (sal_uInt32 nInd = 0; nInd < nManLength ; nInd++ ) { - OUString aMediaType; - OUString aPath; - OUString aVersion; + ::rtl::OUString aMediaType; + ::rtl::OUString aPath; + ::rtl::OUString aVersion; - const PropertyValue *pValue = pSequence[nInd].getConstArray(); + const beans::PropertyValue *pValue = pSequence[nInd].getConstArray(); for (sal_uInt32 j = 0, nNum = pSequence[nInd].getLength(); j < nNum; j++, pValue++) { if (pValue->Name.equals (sMediaTypeProperty) ) @@ -126,7 +129,7 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S break; } - if ( aPath.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ) ) + if ( aPath.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ) ) { aDocMediaType = aMediaType; aDocVersion = aVersion; @@ -139,28 +142,28 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S sal_Bool bStoreStartKeyGeneration = sal_False; if ( aDocMediaType.getLength() ) { - if ( aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) ) ) - - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII ) ) ) ) + if ( aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) ) ) + + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII ) ) ) ) { // oasis format - pRootAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), + pRootAttrList->AddAttribute ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), sCdataAttribute, - OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_OASIS_NAMESPACE ) ) ); + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_OASIS_NAMESPACE ) ) ); bAcceptNonemptyVersion = sal_True; if ( aDocVersion.compareTo( ODFVER_012_TEXT ) >= 0 ) { @@ -168,7 +171,7 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S bStoreStartKeyGeneration = sal_True; // starting from ODF12 the version should be also in manifest:manifest element - pRootAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ), + pRootAttrList->AddAttribute ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ), sCdataAttribute, aDocVersion ); } @@ -177,21 +180,21 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S { // even if it is no SO6 format the namespace must be specified // thus SO6 format is used as default one - pRootAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), + pRootAttrList->AddAttribute ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), sCdataAttribute, - OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_NAMESPACE ) ) ); + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_NAMESPACE ) ) ); bProvideDTD = sal_True; } } - Reference < XAttributeList > xRootAttrList (pRootAttrList); + uno::Reference < xml::sax::XAttributeList > xRootAttrList (pRootAttrList); xHandler->startDocument(); - Reference < XExtendedDocumentHandler > xExtHandler ( xHandler, UNO_QUERY ); + uno::Reference < xml::sax::XExtendedDocumentHandler > xExtHandler ( xHandler, uno::UNO_QUERY ); if ( xExtHandler.is() && bProvideDTD ) { - OUString aDocType ( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_DOCTYPE ) ); + ::rtl::OUString aDocType ( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_DOCTYPE ) ); xExtHandler->unknown ( aDocType ); xHandler->ignorableWhitespace ( sWhiteSpace ); } @@ -200,9 +203,9 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S for (sal_uInt32 i = 0 ; i < nManLength ; i++) { ::comphelper::AttributeList *pAttrList = new ::comphelper::AttributeList; - const PropertyValue *pValue = pSequence[i].getConstArray(); - OUString aString; - const PropertyValue *pVector = NULL, *pSalt = NULL, *pIterationCount = NULL, *pDigest = NULL; + const beans::PropertyValue *pValue = pSequence[i].getConstArray(); + ::rtl::OUString aString; + const uno::Any *pVector = NULL, *pSalt = NULL, *pIterationCount = NULL, *pDigest = NULL, *pDigestAlg = NULL, *pEncryptAlg = NULL, *pStartKeyAlg = NULL, *pDerivedKeySize = NULL; for (sal_uInt32 j = 0, nNum = pSequence[i].getLength(); j < nNum; j++, pValue++) { if (pValue->Name.equals (sMediaTypeProperty) ) @@ -226,47 +229,87 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S { sal_Int32 nSize = 0; pValue->Value >>= nSize; - OUStringBuffer aBuffer; + ::rtl::OUStringBuffer aBuffer; aBuffer.append ( nSize ); pAttrList->AddAttribute ( sSizeAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); } else if (pValue->Name.equals (sInitialisationVectorProperty) ) - pVector = pValue; + pVector = &pValue->Value; else if (pValue->Name.equals (sSaltProperty) ) - pSalt = pValue; + pSalt = &pValue->Value; else if (pValue->Name.equals (sIterationCountProperty) ) - pIterationCount = pValue; + pIterationCount = &pValue->Value; else if (pValue->Name.equals ( sDigestProperty ) ) - pDigest = pValue; + pDigest = &pValue->Value; + else if (pValue->Name.equals ( sDigestAlgProperty ) ) + pDigestAlg = &pValue->Value; + else if (pValue->Name.equals ( sEncryptionAlgProperty ) ) + pEncryptAlg = &pValue->Value; + else if (pValue->Name.equals ( sStartKeyAlgProperty ) ) + pStartKeyAlg = &pValue->Value; + else if (pValue->Name.equals ( sDerivedKeySizeProperty ) ) + pDerivedKeySize = &pValue->Value; } + xHandler->ignorableWhitespace ( sWhiteSpace ); - Reference < XAttributeList > xAttrList ( pAttrList ); + uno::Reference < xml::sax::XAttributeList > xAttrList ( pAttrList ); xHandler->startElement( sFileEntryElement , xAttrList); - if ( pVector && pSalt && pIterationCount ) + if ( pVector && pSalt && pIterationCount && pDigest && pDigestAlg && pEncryptAlg && pStartKeyAlg && pDerivedKeySize ) { // ==== Encryption Data ::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList; - Reference < XAttributeList > xNewAttrList (pNewAttrList); - OUStringBuffer aBuffer; - Sequence < sal_uInt8 > aSequence; + uno::Reference < xml::sax::XAttributeList > xNewAttrList (pNewAttrList); + ::rtl::OUStringBuffer aBuffer; + uno::Sequence < sal_Int8 > aSequence; xHandler->ignorableWhitespace ( sWhiteSpace ); - if ( pDigest ) - { - pNewAttrList->AddAttribute ( sChecksumTypeAttribute, sCdataAttribute, sChecksumType ); - pDigest->Value >>= aSequence; - Base64Codec::encodeBase64 ( aBuffer, aSequence ); - pNewAttrList->AddAttribute ( sChecksumAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); - } + + // ==== Digest + ::rtl::OUString sChecksumType; + sal_Int32 nDigestAlgID = 0; + *pDigestAlg >>= nDigestAlgID; + if ( nDigestAlgID == xml::crypto::DigestID::SHA256_1K ) + sChecksumType = sSHA256_1k_URL; + else if ( nDigestAlgID == xml::crypto::DigestID::SHA1_1K ) + sChecksumType = sSHA1_1k_Name; + else + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected digest algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); + + pNewAttrList->AddAttribute ( sChecksumTypeAttribute, sCdataAttribute, sChecksumType ); + *pDigest >>= aSequence; + Base64Codec::encodeBase64( aBuffer, aSequence ); + pNewAttrList->AddAttribute ( sChecksumAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); + xHandler->startElement( sEncryptionDataElement , xNewAttrList); // ==== Algorithm pNewAttrList = new ::comphelper::AttributeList; xNewAttrList = pNewAttrList; - pNewAttrList->AddAttribute ( sAlgorithmNameAttribute, sCdataAttribute, sBlowfish ); + sal_Int32 nEncAlgID = 0; + sal_Int32 nDerivedKeySize = 0; + *pEncryptAlg >>= nEncAlgID; + *pDerivedKeySize >>= nDerivedKeySize; - pVector->Value >>= aSequence; + ::rtl::OUString sEncAlgName; + if ( nEncAlgID == xml::crypto::CipherID::AES_CBC_W3C_PADDING ) + { + OSL_ENSURE( nDerivedKeySize, "Unexpected key size is provided!" ); + if ( nDerivedKeySize != 32 ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected key size is provided!" ) ), uno::Reference< uno::XInterface >() ); + + sEncAlgName = sAES256_URL; + } + else if ( nEncAlgID == xml::crypto::CipherID::BLOWFISH_CFB_8 ) + { + sEncAlgName = sBlowfish_Name; + } + else + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpecte encryption algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); + + pNewAttrList->AddAttribute ( sAlgorithmNameAttribute, sCdataAttribute, sEncAlgName ); + + *pVector >>= aSequence; Base64Codec::encodeBase64 ( aBuffer, aSequence ); pNewAttrList->AddAttribute ( sInitialisationVectorAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); @@ -279,17 +322,20 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S pNewAttrList = new ::comphelper::AttributeList; xNewAttrList = pNewAttrList; - pNewAttrList->AddAttribute ( sKeyDerivationNameAttribute, sCdataAttribute, sPBKDF2 ); + pNewAttrList->AddAttribute ( sKeyDerivationNameAttribute, sCdataAttribute, sPBKDF2_Name ); if ( bStoreStartKeyGeneration ) - pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, sDerivedKeySize ); + { + aBuffer.append( nDerivedKeySize ); + pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); + } sal_Int32 nCount = 0; - pIterationCount->Value >>= nCount; + *pIterationCount >>= nCount; aBuffer.append (nCount); pNewAttrList->AddAttribute ( sIterationCountAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); - pSalt->Value >>= aSequence; + *pSalt >>= aSequence; Base64Codec::encodeBase64 ( aBuffer, aSequence ); pNewAttrList->AddAttribute ( sSaltAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); @@ -306,8 +352,26 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S pNewAttrList = new ::comphelper::AttributeList; xNewAttrList = pNewAttrList; - // currently SHA1 is used to generate 20-bytes start key - pNewAttrList->AddAttribute ( sStartKeyGenerationNameAttribute, sCdataAttribute, sSHA1 ); + ::rtl::OUString sStartKeyAlg; + ::rtl::OUString sStartKeySize; + sal_Int32 nStartKeyAlgID = 0; + *pStartKeyAlg >>= nStartKeyAlgID; + if ( nStartKeyAlgID == xml::crypto::DigestID::SHA256 ) + { + sStartKeyAlg = sSHA256_URL; + aBuffer.append( (sal_Int32)32 ); + sStartKeySize = aBuffer.makeStringAndClear(); + } + else if ( nStartKeyAlgID == xml::crypto::DigestID::SHA1 ) + { + sStartKeyAlg = sSHA1_Name; + aBuffer.append( (sal_Int32)20 ); + sStartKeySize = aBuffer.makeStringAndClear(); + } + else + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); + + pNewAttrList->AddAttribute ( sStartKeyGenerationNameAttribute, sCdataAttribute, sStartKeyAlg ); pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, sStartKeySize ); xHandler->ignorableWhitespace ( sWhiteSpace ); diff --git a/package/source/manifest/ManifestImport.cxx b/package/source/manifest/ManifestImport.cxx index 85de919a9acf..08999765cf7d 100644 --- a/package/source/manifest/ManifestImport.cxx +++ b/package/source/manifest/ManifestImport.cxx @@ -29,10 +29,11 @@ #include "precompiled_package.hxx" #include <ManifestImport.hxx> #include <ManifestDefines.hxx> -#ifndef _BASE64_CODEC_HXX_ #include <Base64Codec.hxx> -#endif + #include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <com/sun/star/beans/PropertyValue.hpp> using namespace com::sun::star::uno; @@ -45,12 +46,14 @@ using namespace std; ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManVector ) : nNumProperty ( 0 ) , bIgnoreEncryptData ( sal_False ) +, nDerivedKeySize( 0 ) , rManVector ( rNewManVector ) , sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ) , sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ) , sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ) , sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ) +, sStartKeyAlgElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) ) , sKeyDerivationElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ) , sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ) @@ -61,7 +64,9 @@ ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManV , sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ) , sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ) , sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ) +, sKeySizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) ) , sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ) +, sStartKeyAlgNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) ) , sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ) , sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM ) ) , sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) ) @@ -70,15 +75,33 @@ ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManV , sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ) , sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ) , sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ) +, sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ) , sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ) , sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ) , sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ) , sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ) +, sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ) +, sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ) +, sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ) , sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ) -, sBlowfish ( RTL_CONSTASCII_USTRINGPARAM ( "Blowfish CFB" ) ) -, sPBKDF2 ( RTL_CONSTASCII_USTRINGPARAM ( "PBKDF2" ) ) -, sChecksumType ( RTL_CONSTASCII_USTRINGPARAM ( CHECKSUM_TYPE ) ) + +, sSHA256_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL ) ) +, sSHA1_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_NAME ) ) +, sSHA1_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_URL ) ) + +, sSHA256_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_1K_URL ) ) +, sSHA1_1k_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_NAME ) ) +, sSHA1_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_URL ) ) + +, sBlowfish_Name ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_NAME ) ) +, sBlowfish_URL ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_URL ) ) +, sAES128_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES128_URL ) ) +, sAES192_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES192_URL ) ) +, sAES256_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES256_URL ) ) + +, sPBKDF2_Name ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_NAME ) ) +, sPBKDF2_URL ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_URL ) ) { aStack.reserve( 10 ); } @@ -143,15 +166,32 @@ void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Re if ( aConvertedName.equals( sEncryptionDataElement ) ) { // If this element exists, then this stream is encrypted and we need - // to store the initialisation vector, salt and iteration count used + // to import the initialisation vector, salt and iteration count used + nDerivedKeySize = 0; OUString aString = aConvertedAttribs[sChecksumTypeAttribute]; - if ( aString == sChecksumType && !bIgnoreEncryptData ) + if ( !bIgnoreEncryptData ) { - aString = aConvertedAttribs[sChecksumAttribute]; - Sequence < sal_uInt8 > aDecodeBuffer; - Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); - aSequence[nNumProperty].Name = sDigestProperty; - aSequence[nNumProperty++].Value <<= aDecodeBuffer; + if ( aString.equals( sSHA1_1k_Name ) || aString.equals( sSHA1_1k_URL ) ) + { + aSequence[nNumProperty].Name = sDigestAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1_1K; + } + else if ( aString.equals( sSHA256_1k_URL ) ) + { + aSequence[nNumProperty].Name = sDigestAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256_1K; + } + else + bIgnoreEncryptData = sal_True; + + if ( !bIgnoreEncryptData ) + { + aString = aConvertedAttribs[sChecksumAttribute]; + uno::Sequence < sal_Int8 > aDecodeBuffer; + Base64Codec::decodeBase64( aDecodeBuffer, aString ); + aSequence[nNumProperty].Name = sDigestProperty; + aSequence[nNumProperty++].Value <<= aDecodeBuffer; + } } } } @@ -159,38 +199,98 @@ void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Re { if ( aConvertedName == sAlgorithmElement ) { - OUString aString = aConvertedAttribs[sAlgorithmNameAttribute]; - if ( aString == sBlowfish && !bIgnoreEncryptData ) + if ( !bIgnoreEncryptData ) { - aString = aConvertedAttribs[sInitialisationVectorAttribute]; - Sequence < sal_uInt8 > aDecodeBuffer; - Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); - aSequence[nNumProperty].Name = sInitialisationVectorProperty; - aSequence[nNumProperty++].Value <<= aDecodeBuffer; + OUString aString = aConvertedAttribs[sAlgorithmNameAttribute]; + if ( aString.equals( sBlowfish_Name ) || aString.equals( sBlowfish_URL ) ) + { + aSequence[nNumProperty].Name = sEncryptionAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8; + } + else if ( aString.equals( sAES256_URL ) ) + { + aSequence[nNumProperty].Name = sEncryptionAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING; + OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 32, "Unexpected derived key length!" ); + nDerivedKeySize = 32; + } + else if ( aString.equals( sAES192_URL ) ) + { + aSequence[nNumProperty].Name = sEncryptionAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING; + OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 24, "Unexpected derived key length!" ); + nDerivedKeySize = 24; + } + else if ( aString.equals( sAES128_URL ) ) + { + aSequence[nNumProperty].Name = sEncryptionAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING; + OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 16, "Unexpected derived key length!" ); + nDerivedKeySize = 16; + } + else + bIgnoreEncryptData = sal_True; + + if ( !bIgnoreEncryptData ) + { + aString = aConvertedAttribs[sInitialisationVectorAttribute]; + uno::Sequence < sal_Int8 > aDecodeBuffer; + Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); + aSequence[nNumProperty].Name = sInitialisationVectorProperty; + aSequence[nNumProperty++].Value <<= aDecodeBuffer; + } } - else - // If we don't recognise the algorithm, then the key derivation info - // is useless to us - bIgnoreEncryptData = sal_True; } else if ( aConvertedName == sKeyDerivationElement ) { - OUString aString = aConvertedAttribs[sKeyDerivationNameAttribute]; - if ( aString == sPBKDF2 && !bIgnoreEncryptData ) + if ( !bIgnoreEncryptData ) + { + OUString aString = aConvertedAttribs[sKeyDerivationNameAttribute]; + if ( aString.equals( sPBKDF2_Name ) || aString.equals( sPBKDF2_URL ) ) + { + aString = aConvertedAttribs[sSaltAttribute]; + uno::Sequence < sal_Int8 > aDecodeBuffer; + Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); + aSequence[nNumProperty].Name = sSaltProperty; + aSequence[nNumProperty++].Value <<= aDecodeBuffer; + + aString = aConvertedAttribs[sIterationCountAttribute]; + aSequence[nNumProperty].Name = sIterationCountProperty; + aSequence[nNumProperty++].Value <<= aString.toInt32(); + + aString = aConvertedAttribs[sKeySizeAttribute]; + if ( aString.getLength() ) + { + sal_Int32 nKey = aString.toInt32(); + OSL_ENSURE( !nDerivedKeySize || nKey == nDerivedKeySize , "Provided derived key length differs from the expected one!" ); + nDerivedKeySize = nKey; + } + else if ( !nDerivedKeySize ) + nDerivedKeySize = 16; + else if ( nDerivedKeySize != 16 ) + OSL_ENSURE( sal_False, "Default derived key length differs from the expected one!" ); + + aSequence[nNumProperty].Name = sDerivedKeySizeProperty; + aSequence[nNumProperty++].Value <<= nDerivedKeySize; + } + else + bIgnoreEncryptData = sal_True; + } + } + else if ( aConvertedName == sStartKeyAlgElement ) + { + OUString aString = aConvertedAttribs[sStartKeyAlgNameAttribute]; + if ( aString.equals( sSHA256_URL ) ) + { + aSequence[nNumProperty].Name = sStartKeyAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256; + } + else if ( aString.equals( sSHA1_Name ) || aString.equals( sSHA1_URL ) ) { - aString = aConvertedAttribs[sSaltAttribute]; - Sequence < sal_uInt8 > aDecodeBuffer; - Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); - aSequence[nNumProperty].Name = sSaltProperty; - aSequence[nNumProperty++].Value <<= aDecodeBuffer; - - aString = aConvertedAttribs[sIterationCountAttribute]; - aSequence[nNumProperty].Name = sIterationCountProperty; - aSequence[nNumProperty++].Value <<= aString.toInt32(); + aSequence[nNumProperty].Name = sStartKeyAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1; } else - // If we don't recognise the key derivation technique, then the - // algorithm info is useless to us bIgnoreEncryptData = sal_True; } } diff --git a/package/source/manifest/ManifestImport.hxx b/package/source/manifest/ManifestImport.hxx index f83c8b6c49df..8c42960c220f 100644 --- a/package/source/manifest/ManifestImport.hxx +++ b/package/source/manifest/ManifestImport.hxx @@ -66,12 +66,14 @@ protected: sal_Int16 nNumProperty; ManifestStack aStack; sal_Bool bIgnoreEncryptData; + sal_Int32 nDerivedKeySize; ::std::vector < ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > > & rManVector; const ::rtl::OUString sFileEntryElement; const ::rtl::OUString sManifestElement; const ::rtl::OUString sEncryptionDataElement; const ::rtl::OUString sAlgorithmElement; + const ::rtl::OUString sStartKeyAlgElement; const ::rtl::OUString sKeyDerivationElement; const ::rtl::OUString sCdataAttribute; @@ -82,7 +84,9 @@ protected: const ::rtl::OUString sSaltAttribute; const ::rtl::OUString sInitialisationVectorAttribute; const ::rtl::OUString sIterationCountAttribute; + const ::rtl::OUString sKeySizeAttribute; const ::rtl::OUString sAlgorithmNameAttribute; + const ::rtl::OUString sStartKeyAlgNameAttribute; const ::rtl::OUString sKeyDerivationNameAttribute; const ::rtl::OUString sChecksumAttribute; const ::rtl::OUString sChecksumTypeAttribute; @@ -91,15 +95,33 @@ protected: const ::rtl::OUString sMediaTypeProperty; const ::rtl::OUString sVersionProperty; const ::rtl::OUString sIterationCountProperty; + const ::rtl::OUString sDerivedKeySizeProperty; const ::rtl::OUString sSaltProperty; const ::rtl::OUString sInitialisationVectorProperty; const ::rtl::OUString sSizeProperty; const ::rtl::OUString sDigestProperty; + const ::rtl::OUString sEncryptionAlgProperty; + const ::rtl::OUString sStartKeyAlgProperty; + const ::rtl::OUString sDigestAlgProperty; const ::rtl::OUString sWhiteSpace; - const ::rtl::OUString sBlowfish; - const ::rtl::OUString sPBKDF2; - const ::rtl::OUString sChecksumType; + + const ::rtl::OUString sSHA256_URL; + const ::rtl::OUString sSHA1_Name; + const ::rtl::OUString sSHA1_URL; + + const ::rtl::OUString sSHA256_1k_URL; + const ::rtl::OUString sSHA1_1k_Name; + const ::rtl::OUString sSHA1_1k_URL; + + const ::rtl::OUString sBlowfish_Name; + const ::rtl::OUString sBlowfish_URL; + const ::rtl::OUString sAES128_URL; + const ::rtl::OUString sAES192_URL; + const ::rtl::OUString sAES256_URL; + + const ::rtl::OUString sPBKDF2_Name; + const ::rtl::OUString sPBKDF2_URL; ::rtl::OUString PushNameAndNamespaces( const ::rtl::OUString& aName, diff --git a/package/source/manifest/UnoRegister.cxx b/package/source/manifest/UnoRegister.cxx index 34dd874206e1..41b35c95af57 100644 --- a/package/source/manifest/UnoRegister.cxx +++ b/package/source/manifest/UnoRegister.cxx @@ -39,6 +39,7 @@ #include <zipfileaccess.hxx> using namespace ::rtl; +using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::lang; @@ -65,9 +66,9 @@ extern "C" void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) { void * pRet = 0; - Reference< XMultiServiceFactory > xSMgr( + uno::Reference< XMultiServiceFactory > xSMgr( reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) ); - Reference< XSingleServiceFactory > xFactory; + uno::Reference< XSingleServiceFactory > xFactory; if (ManifestReader::static_getImplementationName().compareToAscii( pImplName ) == 0) xFactory = ManifestReader::createServiceFactory ( xSMgr ); diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index 9a5876b3e6df..2fd6a47c12ff 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -46,16 +46,18 @@ #include <comphelper/storagehelper.hxx> #include <comphelper/ofopxmlhelper.hxx> +#include <rtl/digest.h> +#include <rtl/logfile.hxx> +#include <rtl/instance.hxx> + +#include <PackageConstants.hxx> +#include <mutexholder.hxx> + #include "selfterminatefilestream.hxx" #include "owriteablestream.hxx" #include "oseekinstream.hxx" -#include "mutexholder.hxx" #include "xstorage.hxx" -#include <rtl/digest.h> -#include <rtl/logfile.hxx> -#include <rtl/instance.hxx> - // since the copying uses 32000 blocks usually, it makes sense to have a smaller size #define MAX_STORCACHE_SIZE 30000 @@ -110,15 +112,14 @@ namespace { //----------------------------------------------- void SetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySet >& xPropertySet, - const uno::Sequence< sal_Int8 >& aKey ) + const uno::Sequence< beans::NamedValue >& aKey ) { OSL_ENSURE( xPropertySet.is(), "No property set is provided!\n" ); if ( !xPropertySet.is() ) throw uno::RuntimeException(); - ::rtl::OUString aString_EncryptionKey = ::rtl::OUString::createFromAscii( "EncryptionKey" ); try { - xPropertySet->setPropertyValue( aString_EncryptionKey, uno::makeAny( aKey ) ); + xPropertySet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), uno::makeAny( aKey ) ); } catch ( uno::Exception& aException ) { @@ -136,9 +137,8 @@ uno::Any GetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySe if ( !xPropertySet.is() ) throw uno::RuntimeException(); - ::rtl::OUString aString_EncryptionKey = ::rtl::OUString::createFromAscii( "EncryptionKey" ); try { - return xPropertySet->getPropertyValue( aString_EncryptionKey ); + return xPropertySet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ); } catch ( uno::Exception& aException ) { @@ -151,16 +151,65 @@ uno::Any GetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySe } //----------------------------------------------- -sal_Bool SequencesEqual( uno::Sequence< sal_Int8 > aSequence1, uno::Sequence< sal_Int8 > aSequence2 ) +bool SequencesEqual( const uno::Sequence< sal_Int8 >& aSequence1, const uno::Sequence< sal_Int8 >& aSequence2 ) { if ( aSequence1.getLength() != aSequence2.getLength() ) - return sal_False; + return false; for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ ) if ( aSequence1[nInd] != aSequence2[nInd] ) - return sal_False; + return false; + + return true; +} + +//----------------------------------------------- +bool SequencesEqual( const uno::Sequence< beans::NamedValue >& aSequence1, const uno::Sequence< beans::NamedValue >& aSequence2 ) +{ + if ( aSequence1.getLength() != aSequence2.getLength() ) + return false; + + for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ ) + { + bool bHasMember = false; + uno::Sequence< sal_Int8 > aMember1; + sal_Int32 nMember1 = 0; + if ( ( aSequence1[nInd].Value >>= aMember1 ) ) + { + for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ ) + { + if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) ) + { + bHasMember = true; + + uno::Sequence< sal_Int8 > aMember2; + if ( !( aSequence2[nInd2].Value >>= aMember2 ) || !SequencesEqual( aMember1, aMember2 ) ) + return false; + } + } + } + else if ( ( aSequence1[nInd].Value >>= nMember1 ) ) + { + for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ ) + { + if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) ) + { + bHasMember = true; - return sal_True; + sal_Int32 nMember2 = 0; + if ( !( aSequence2[nInd2].Value >>= nMember2 ) || nMember1 != nMember2 ) + return false; + } + } + } + else + return false; + + if ( !bHasMember ) + return false; + } + + return true; } //----------------------------------------------- @@ -394,7 +443,7 @@ sal_Bool OWriteStream_Impl::IsEncrypted() // since a new key set to the package stream it should not be removed except the case when // the stream becomes nonencrypted - uno::Sequence< sal_Int8 > aKey; + uno::Sequence< beans::NamedValue > aKey; if ( bToBeEncr ) GetEncryptionKeyProperty_Impl( xPropSet ) >>= aKey; @@ -821,8 +870,8 @@ void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputSt throw uno::RuntimeException(); // set to be encrypted but do not use encryption key - xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "EncryptionKey" ), - uno::makeAny( uno::Sequence< sal_Int8 >() ) ); + xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ), + uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "Encrypted" ), uno::makeAny( sal_True ) ); } @@ -920,8 +969,8 @@ void OWriteStream_Impl::Commit() throw uno::RuntimeException(); // set to be encrypted but do not use encryption key - xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "EncryptionKey" ), - uno::makeAny( uno::Sequence< sal_Int8 >() ) ); + xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ), + uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "Encrypted" ), uno::makeAny( sal_True ) ); } @@ -930,8 +979,8 @@ void OWriteStream_Impl::Commit() if ( m_nStorageType != embed::StorageFormats::PACKAGE ) throw uno::RuntimeException(); - xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "EncryptionKey" ), - uno::makeAny( m_aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ) ); + xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ), + uno::makeAny( m_aEncryptionData.getAsConstNamedValueList() ) ); } // the stream should be free soon, after package is stored @@ -1264,7 +1313,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod } else { - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ); + SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() ); try { xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess ); @@ -1273,55 +1322,22 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod m_bHasCachedEncryptionData = sal_True; m_aEncryptionData = aEncryptionData; } - catch( packages::WrongPasswordException& ) - { - // retry with different encoding - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ) ); - try { - // the stream must be cashed to be resaved - xResultStream = GetStream_Impl( nStreamMode | embed::ElementModes::SEEKABLE, bHierarchyAccess ); - - m_bUseCommonEncryption = sal_False; // very important to set it to false - m_bHasCachedEncryptionData = sal_True; - m_aEncryptionData = aEncryptionData; - - // the stream must be resaved with new password encryption - if ( nStreamMode & embed::ElementModes::WRITE ) - { - FillTempGetFileName(); - m_bHasDataToFlush = sal_True; - - // TODO/LATER: should the notification be done? - if ( m_pParent ) - m_pParent->m_bIsModified = sal_True; - } - } - catch( packages::WrongPasswordException& aWrongPasswordException ) - { - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - AddLog( aWrongPasswordException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( uno::Exception& aException ) - { - AddLog( aException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - - OSL_ENSURE( sal_False, "Can't write encryption related properties!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - throw io::IOException(); // TODO: - } - } - catch( uno::Exception& aException ) + catch( packages::WrongPasswordException& aWrongPasswordException ) { - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - - AddLog( aException.Message ); + SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); + AddLog( aWrongPasswordException.Message ); AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); throw; } + catch ( uno::Exception& aException ) + { + AddLog( aException.Message ); + AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); + OSL_ENSURE( sal_False, "Can't write encryption related properties!\n" ); + SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); + throw io::IOException(); // TODO: + } } OSL_ENSURE( xResultStream.is(), "In case stream can not be retrieved an exception must be thrown!\n" ); @@ -1624,8 +1640,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar { // TODO: introduce last commited cashed password information and use it here // that means "use common pass" also should be remembered on flash - uno::Sequence< sal_Int8 > aNewKey = aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ); - uno::Sequence< sal_Int8 > aOldKey = aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ); + uno::Sequence< beans::NamedValue > aKey = aEncryptionData.getAsConstNamedValueList(); uno::Reference< beans::XPropertySet > xProps( m_xPackageStream, uno::UNO_QUERY ); if ( !xProps.is() ) @@ -1636,9 +1651,9 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar if ( !bEncr ) throw packages::NoEncryptionException(); - uno::Sequence< sal_Int8 > aEncrKey; - xProps->getPropertyValue( ::rtl::OUString::createFromAscii( "EncryptionKey" ) ) >>= aEncrKey; - if ( !SequencesEqual( aNewKey, aEncrKey ) && !SequencesEqual( aOldKey, aEncrKey ) ) + uno::Sequence< beans::NamedValue > aPackKey; + xProps->getPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) >>= aPackKey; + if ( !SequencesEqual( aKey, aPackKey ) ) throw packages::WrongPasswordException(); // the correct key must be set already @@ -1647,7 +1662,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar else { uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY ); - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ); + SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() ); try { xDataToCopy = m_xPackageStream->getDataStream(); @@ -1655,42 +1670,19 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar if ( !xDataToCopy.is() ) { OSL_ENSURE( sal_False, "Encrypted ZipStream must already have input stream inside!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - } - } - catch( packages::WrongPasswordException& aWrongPasswordException ) - { - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ) ); - try { - xDataToCopy = m_xPackageStream->getDataStream(); - - if ( !xDataToCopy.is() ) - { - OSL_ENSURE( sal_False, "Encrypted ZipStream must already have input stream inside!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - AddLog( aWrongPasswordException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - } - catch( uno::Exception& aException ) - { - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - AddLog( aException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; + SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); } } catch( uno::Exception& aException ) { OSL_ENSURE( sal_False, "Can't open encrypted stream!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); + SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); AddLog( aException.Message ); AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); throw; } - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); + SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); } // in case of new inserted package stream it is possible that input stream still was not set diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx index 851fea6b086b..e3c965e790c3 100644 --- a/package/source/xstor/xstorage.cxx +++ b/package/source/xstor/xstorage.cxx @@ -45,6 +45,7 @@ #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/beans/NamedValue.hpp> +#include <PackageConstants.hxx> #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/exc_hlp.hxx> @@ -571,7 +572,7 @@ void OStorage_Impl::GetStorageProperties() if ( !m_bControlMediaType ) { uno::Reference< beans::XPropertySet > xPackageProps( m_xPackage, uno::UNO_QUERY_THROW ); - xPackageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaTypeFallbackUsed" ) ) ) >>= m_bMTFallbackUsed; + xPackageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) >>= m_bMTFallbackUsed; xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= m_aMediaType; m_bControlMediaType = sal_True; @@ -749,9 +750,17 @@ void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDes { try { - uno::Reference< embed::XEncryptionProtectedSource2 > xEncr( xDest, uno::UNO_QUERY ); + uno::Reference< embed::XEncryptionProtectedStorage > xEncr( xDest, uno::UNO_QUERY ); if ( xEncr.is() ) + { xEncr->setEncryptionData( GetCommonRootEncryptionData().getAsConstNamedValueList() ); + + uno::Sequence< beans::NamedValue > aAlgorithms; + uno::Reference< beans::XPropertySet > xPackPropSet( m_xPackage, uno::UNO_QUERY_THROW ); + xPackPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) + >>= aAlgorithms; + xEncr->setEncryptionAlgorithms( aAlgorithms ); + } } catch( packages::NoEncryptionException& aNoEncryptionException ) { @@ -984,7 +993,9 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement, AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Handled exception" ) ) ); // If the common storage password does not allow to open the stream - // it must be copyed in raw way + // it could be copyed in raw way, the problem is that the StartKey should be the same + // in the ODF1.2 package, so an invalid package could be produced if the stream + // is copied from ODF1.1 package, where it is allowed to have different StartKeys uno::Reference< embed::XStorageRawAccess > xRawDest( xDest, uno::UNO_QUERY_THROW ); uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream(); xRawDest->insertRawEncrStreamElement( aName, xRawInStream ); @@ -2277,7 +2288,8 @@ uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType ) ( rType , static_cast<embed::XStorageRawAccess*> ( this ) , static_cast<embed::XEncryptionProtectedSource*> ( this ) - , static_cast<embed::XEncryptionProtectedSource2*> ( this ) ); + , static_cast<embed::XEncryptionProtectedSource2*> ( this ) + , static_cast<embed::XEncryptionProtectedStorage*> ( this ) ); } else { @@ -2337,6 +2349,7 @@ uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes() , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL ) + , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedStorage >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL ) , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); @@ -4696,18 +4709,23 @@ void SAL_CALL OStorage::removeEncryption() // TODO: check if the password is valid // update all streams that was encrypted with old password - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY ); - if ( !xPackPropSet.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - + uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); try { - xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ), - uno::makeAny( uno::Sequence< sal_Int8 >() ) ); + xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), + uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); m_pImpl->m_bHasCommonEncryptionData = sal_False; m_pImpl->m_aCommonEncryptionData.clear(); } + catch( uno::RuntimeException& aRException ) + { + m_pImpl->AddLog( aRException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + OSL_ENSURE( sal_False, "The call must not fail, it is pretty simple!" ); + throw; + } catch( uno::Exception& aException ) { m_pImpl->AddLog( aException.Message ); @@ -4761,24 +4779,161 @@ void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValu m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); uno::Any aCaught( ::cppu::getCaughtException() ); + throw lang::WrappedTargetRuntimeException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), + uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ), + aCaught ); + } + + uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); + try + { + ::comphelper::SequenceAsHashMap aEncryptionMap( aEncryptionData ); + xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), + uno::makeAny( aEncryptionMap.getAsConstNamedValueList() ) ); + + m_pImpl->m_bHasCommonEncryptionData = sal_True; + m_pImpl->m_aCommonEncryptionData = aEncryptionMap; + } + catch( uno::Exception& aException ) + { + m_pImpl->AddLog( aException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + } +} + +//____________________________________________________________________________________________________ +// XEncryptionProtectedStorage +//____________________________________________________________________________________________________ + +//----------------------------------------------- +void SAL_CALL OStorage::setEncryptionAlgorithms( const uno::Sequence< beans::NamedValue >& aAlgorithms ) + throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionAlgorithms" ); + + ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); + + if ( !m_pImpl ) + { + ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); + throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + + if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage + + if ( !aAlgorithms.getLength() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected empty encryption algorithms list!") ), uno::Reference< uno::XInterface >() ); + + OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionAlgorithms() method is not available for nonroot storages!\n" ); + if ( m_pData->m_bIsRoot ) + { + try { + m_pImpl->ReadContents(); + } + catch ( uno::RuntimeException& aRuntimeException ) + { + m_pImpl->AddLog( aRuntimeException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch ( uno::Exception& aException ) + { + m_pImpl->AddLog( aException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + uno::Any aCaught( ::cppu::getCaughtException() ); throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ), aCaught ); } - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY ); - if ( !xPackPropSet.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - + uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); try { - ::comphelper::SequenceAsHashMap aEncryptionMap( aEncryptionData ); - xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ), - uno::makeAny( aEncryptionMap.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ) ); + xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ), + uno::makeAny( aAlgorithms ) ); + } + catch ( uno::RuntimeException& aRuntimeException ) + { + m_pImpl->AddLog( aRuntimeException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( lang::IllegalArgumentException& aIAException ) + { + m_pImpl->AddLog( aIAException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - m_pImpl->m_bHasCommonEncryptionData = sal_True; - m_pImpl->m_aCommonEncryptionData = aEncryptionMap; + throw; + } + catch( uno::Exception& aException ) + { + m_pImpl->AddLog( aException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + } +} + +//----------------------------------------------- +uno::Sequence< beans::NamedValue > SAL_CALL OStorage::getEncryptionAlgorithms() + throw (uno::RuntimeException) +{ + RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getEncryptionAlgorithms" ); + + ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); + + if ( !m_pImpl ) + { + ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); + throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + + if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage + + uno::Sequence< beans::NamedValue > aResult; + OSL_ENSURE( m_pData->m_bIsRoot, "getEncryptionAlgorithms() method is not available for nonroot storages!\n" ); + if ( m_pData->m_bIsRoot ) + { + try { + m_pImpl->ReadContents(); + } + catch ( uno::RuntimeException& aRuntimeException ) + { + m_pImpl->AddLog( aRuntimeException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch ( uno::Exception& aException ) + { + m_pImpl->AddLog( aException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + uno::Any aCaught( ::cppu::getCaughtException() ); + throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), + uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), + uno::UNO_QUERY ), + aCaught ); + } + + uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); + try + { + xPackPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) >>= aResult; + } + catch ( uno::RuntimeException& aRuntimeException ) + { + m_pImpl->AddLog( aRuntimeException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; } catch( uno::Exception& aException ) { @@ -4789,6 +4944,7 @@ void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValu } } + return aResult; } @@ -4863,13 +5019,13 @@ void SAL_CALL OStorage::setPropertyValue( const ::rtl::OUString& aPropertyName, m_pImpl->m_bIsModified = sal_True; } } - else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAscii( "HasEncryptedEntries" ) - || aPropertyName.equalsAscii( "HasNonEncryptedEntries" ) - || aPropertyName.equalsAscii( "IsInconsistent" ) + else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAscii( HAS_ENCRYPTED_ENTRIES_PROPERTY ) + || aPropertyName.equalsAscii( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) + || aPropertyName.equalsAscii( IS_INCONSISTENT_PROPERTY ) || aPropertyName.equalsAscii( "URL" ) || aPropertyName.equalsAscii( "RepairPackage" ) ) ) || aPropertyName.equalsAscii( "IsRoot" ) - || aPropertyName.equalsAscii( "MediaTypeFallbackUsed" ) ) + || aPropertyName.equalsAscii( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); else throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -4943,7 +5099,7 @@ uno::Any SAL_CALL OStorage::getPropertyValue( const ::rtl::OUString& aPropertyNa if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE && ( aPropertyName.equalsAscii( "MediaType" ) - || aPropertyName.equalsAscii( "MediaTypeFallbackUsed" ) + || aPropertyName.equalsAscii( MEDIATYPE_FALLBACK_USED_PROPERTY ) || aPropertyName.equalsAscii( "Version" ) ) ) { try @@ -5000,9 +5156,9 @@ uno::Any SAL_CALL OStorage::getPropertyValue( const ::rtl::OUString& aPropertyNa return uno::makeAny( sal_False ); // RepairPackage } else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && ( aPropertyName.equalsAscii( "HasEncryptedEntries" ) - || aPropertyName.equalsAscii( "HasNonEncryptedEntries" ) - || aPropertyName.equalsAscii( "IsInconsistent" ) ) ) + && ( aPropertyName.equalsAscii( HAS_ENCRYPTED_ENTRIES_PROPERTY ) + || aPropertyName.equalsAscii( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) + || aPropertyName.equalsAscii( IS_INCONSISTENT_PROPERTY ) ) ) { try { m_pImpl->ReadContents(); diff --git a/package/source/xstor/xstorage.hxx b/package/source/xstor/xstorage.hxx index a49de3af6f3a..2baba695a55f 100644 --- a/package/source/xstor/xstorage.hxx +++ b/package/source/xstor/xstorage.hxx @@ -36,7 +36,7 @@ #include <com/sun/star/embed/XTransactedObject.hpp> #include <com/sun/star/embed/XTransactionBroadcaster.hpp> #include <com/sun/star/embed/XClassifiedObject.hpp> -#include <com/sun/star/embed/XEncryptionProtectedSource2.hpp> +#include <com/sun/star/embed/XEncryptionProtectedStorage.hpp> #include <com/sun/star/embed/XRelationshipAccess.hpp> #include <com/sun/star/util/XModifiable.hpp> #include <com/sun/star/container/XNameAccess.hpp> @@ -298,7 +298,7 @@ class OStorage : public ::com::sun::star::lang::XTypeProvider , public ::com::sun::star::util::XModifiable // , public ::com::sun::star::container::XNameAccess // , public ::com::sun::star::lang::XComponent - , public ::com::sun::star::embed::XEncryptionProtectedSource2 + , public ::com::sun::star::embed::XEncryptionProtectedStorage , public ::com::sun::star::beans::XPropertySet , public ::com::sun::star::embed::XOptimizedStorage , public ::com::sun::star::embed::XRelationshipAccess @@ -648,6 +648,13 @@ public: throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException ); + //____________________________________________________________________________________________________ + // XEncryptionProtectedStorage + //____________________________________________________________________________________________________ + + virtual void SAL_CALL setEncryptionAlgorithms( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aAlgorithms ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > SAL_CALL getEncryptionAlgorithms() throw (::com::sun::star::uno::RuntimeException); //____________________________________________________________________________________________________ // XPropertySet diff --git a/package/source/zipapi/EntryInputStream.cxx b/package/source/zipapi/EntryInputStream.cxx deleted file mode 100644 index 671ef7381f9d..000000000000 --- a/package/source/zipapi/EntryInputStream.cxx +++ /dev/null @@ -1,201 +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_package.hxx" -#include <EntryInputStream.hxx> -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <rtl/cipher.h> -#include <rtl/digest.h> -#include <memory.h> // for memcpy - -using namespace rtl; -using namespace com::sun::star; -using namespace com::sun::star::uno; -using namespace com::sun::star::packages::zip; -using namespace com::sun::star::packages::zip::ZipConstants; - -/** Provides access to the compressed data in a zipfile. - * - * 04/12/00 - uncompresses the stream into memory and seeks on it 'in memory' - * This and the ZipPackageBuffer used in the ZipOutputStream are memory hogs - * and will hopefully be replaced eventually - * - * Acts on the same underlying XInputStream as both the full Zip File and other - * EntryInputStreams, and thus must maintain its current position in the stream and - * seek to it before performing any reads. - */ - -EntryInputStream::EntryInputStream( Reference < io::XInputStream > xNewInput, - const ZipEntry & rNewEntry, - const vos::ORef < EncryptionData > &xEncryptData, - sal_Bool bGetRawStream) -: xStream( xNewInput ) -, xSeek( xNewInput, UNO_QUERY ) -, aEntry (rNewEntry ) -, nCurrent( 0 ) -, bHaveInMemory ( sal_False ) -, aInflater( sal_True ) -, aBuffer( 0 ) -, xEncryptionData (xEncryptData) -, bRawStream (bGetRawStream) -{ - if (bGetRawStream) - { - nUncompressedSize = aEntry.nMethod == DEFLATED ? aEntry.nCompressedSize : aEntry.nSize; - nEnd = aEntry.nOffset + nUncompressedSize; - } - else - { - nEnd = aEntry.nMethod == DEFLATED ? aEntry.nOffset + aEntry.nCompressedSize : aEntry.nOffset + aEntry.nSize; - nUncompressedSize = aEntry.nSize; - } -} -void EntryInputStream::readIntoMemory() - throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException) -{ - if (!bHaveInMemory) - { - Sequence < sal_Int8 > aReadBuffer; - xSeek->seek(aEntry.nOffset); - sal_Int32 nSize = aEntry.nMethod == DEFLATED ? aEntry.nCompressedSize : aEntry.nSize; - - if (nSize <0) - throw io::BufferSizeExceededException(::rtl::OUString(), *this); - - xStream->readBytes( aReadBuffer, nSize ); // Now it holds the raw stuff from disk - - if (xEncryptionData->aSalt.getLength()) - { - // Have salt, will travel - Sequence < sal_uInt8 > aDerivedKey (16); - rtlCipherError aResult; - Sequence < sal_Int8 > aDecryptBuffer; - - // Get the key - rtl_digest_PBKDF2 ( aDerivedKey.getArray(), 16, - reinterpret_cast < const sal_uInt8 * > (xEncryptionData->aKey.getConstArray()), - xEncryptionData->aKey.getLength(), - xEncryptionData->aSalt.getConstArray(), - xEncryptionData->aSalt.getLength(), - xEncryptionData->nIterationCount ); - - rtlCipher aCipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream); - aResult = rtl_cipher_init( aCipher, rtl_Cipher_DirectionDecode, - aDerivedKey.getConstArray(), - aDerivedKey.getLength(), - xEncryptionData->aInitVector.getConstArray(), - xEncryptionData->aInitVector.getLength()); - OSL_ASSERT (aResult == rtl_Cipher_E_None); - aDecryptBuffer.realloc ( nSize ); - aResult = rtl_cipher_decode ( aCipher, - aReadBuffer.getConstArray(), - nSize, - reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()), - nSize); - OSL_ASSERT (aResult == rtl_Cipher_E_None); - aReadBuffer = aDecryptBuffer; // Now it holds the decrypted data - } - if (bRawStream || aEntry.nMethod == STORED) - aBuffer = aReadBuffer; // bRawStream means the caller doesn't want it decompressed - else - { - aInflater.setInputSegment(aReadBuffer, 0, nSize ); - aBuffer.realloc( aEntry.nSize ); - aInflater.doInflate(aBuffer); - aInflater.end(); - } - bHaveInMemory = sal_True; - } -} -EntryInputStream::~EntryInputStream( void ) -{ -} - -sal_Int32 SAL_CALL EntryInputStream::readBytes( Sequence< sal_Int8 >& aData, - sal_Int32 nBytesToRead ) - throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException) -{ - if (nBytesToRead <0) - throw io::BufferSizeExceededException(::rtl::OUString(), *this); - if (!bHaveInMemory) - readIntoMemory(); - if (nBytesToRead + nCurrent > nUncompressedSize) - nBytesToRead = static_cast < sal_Int32> ( nUncompressedSize - nCurrent ); - - aData.realloc( nBytesToRead ); - memcpy(aData.getArray(), aBuffer.getConstArray() + nCurrent, nBytesToRead); - nCurrent+=nBytesToRead; - - return nBytesToRead; -} -sal_Int32 SAL_CALL EntryInputStream::readSomeBytes( Sequence< sal_Int8 >& aData, - sal_Int32 nMaxBytesToRead ) - throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException) -{ - return readBytes( aData, nMaxBytesToRead ); -} -void SAL_CALL EntryInputStream::skipBytes( sal_Int32 nBytesToSkip ) - throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException) -{ - if (nBytesToSkip < 0) - throw io::BufferSizeExceededException(::rtl::OUString(), *this); - - if (nBytesToSkip + nCurrent > nUncompressedSize) - nBytesToSkip = static_cast < sal_Int32 > (nUncompressedSize- nCurrent); - - nCurrent+=nBytesToSkip; -} -sal_Int32 SAL_CALL EntryInputStream::available( ) - throw(io::NotConnectedException, io::IOException, RuntimeException) -{ - return static_cast < sal_Int32 > (nUncompressedSize - nCurrent); -} -void SAL_CALL EntryInputStream::closeInput( ) - throw(io::NotConnectedException, io::IOException, RuntimeException) -{ -} - -void SAL_CALL EntryInputStream::seek( sal_Int64 location ) - throw(lang::IllegalArgumentException, io::IOException, RuntimeException) -{ - if (location > nUncompressedSize) - location = nUncompressedSize; - if (location <0) - location = 0; - nCurrent = location; -} -sal_Int64 SAL_CALL EntryInputStream::getPosition( ) - throw(io::IOException, RuntimeException) -{ - return nCurrent; -} -sal_Int64 SAL_CALL EntryInputStream::getLength( ) - throw(io::IOException, RuntimeException) -{ - return nUncompressedSize; -} diff --git a/package/source/zipapi/EntryInputStream.hxx b/package/source/zipapi/EntryInputStream.hxx deleted file mode 100644 index c04a5dc2d33b..000000000000 --- a/package/source/zipapi/EntryInputStream.hxx +++ /dev/null @@ -1,86 +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. - * - ************************************************************************/ -#ifndef _ENTRY_INPUT_STREAM_HXX -#define _ENTRY_INPUT_STREAM_HXX - -#include <cppuhelper/implbase2.hxx> // helper for implementations -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <Inflater.hxx> -#include <com/sun/star/packages/zip/ZipEntry.hpp> -#ifndef _VOS_REF_H_ -#include <vos/ref.hxx> -#endif -#ifndef _ENCRYPTION_DATA_HXX -#include <EncryptionData.hxx> -#endif -class EntryInputStream : public cppu::WeakImplHelper2< com::sun::star::io::XInputStream, - com::sun::star::io::XSeekable > -{ -protected: - com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xStream; - com::sun::star::uno::Reference< com::sun::star::io::XSeekable > xSeek; - sal_Int64 nEnd, nCurrent, nUncompressedSize; - sal_Bool bRawStream, bHaveInMemory, bEncrypted; - com::sun::star::uno::Sequence < sal_Int8 > aBuffer; - const vos::ORef < EncryptionData > xEncryptionData; - const com::sun::star::packages::zip::ZipEntry aEntry; - Inflater aInflater; - void readIntoMemory() - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); -public: - EntryInputStream( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xInput, - const com::sun::star::packages::zip::ZipEntry &rNewEntry, - const vos::ORef < EncryptionData > &xEncryptData, - sal_Bool bGetRawStream = sal_False); - virtual ~EntryInputStream(); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - // XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) - throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - /* -private: - void fill( void ); - */ -}; - -#endif diff --git a/package/source/zipapi/MemoryByteGrabber.hxx b/package/source/zipapi/MemoryByteGrabber.hxx index 8a8d96556bae..f27eaf4826ad 100644 --- a/package/source/zipapi/MemoryByteGrabber.hxx +++ b/package/source/zipapi/MemoryByteGrabber.hxx @@ -62,7 +62,7 @@ public: nBytesToRead = mnEnd - mnCurrent; aData.realloc ( nBytesToRead ); - memcpy ( aData.getArray(), mpBuffer + mnCurrent, nBytesToRead ); + rtl_copyMemory( aData.getArray(), mpBuffer + mnCurrent, nBytesToRead ); mnCurrent += nBytesToRead; return nBytesToRead; } diff --git a/package/source/zipapi/XFileStream.cxx b/package/source/zipapi/XFileStream.cxx deleted file mode 100644 index 9e7156ee82b3..000000000000 --- a/package/source/zipapi/XFileStream.cxx +++ /dev/null @@ -1,227 +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_package.hxx" -#include <XFileStream.hxx> -#include <EncryptionData.hxx> -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <PackageConstants.hxx> -#include <rtl/cipher.h> -#include <ZipFile.hxx> -#include <EncryptedDataHeader.hxx> -#include <com/sun/star/io/XOutputStream.hpp> - -using namespace com::sun::star::packages::zip::ZipConstants; -using namespace com::sun::star::io; -using namespace com::sun::star::uno; -using com::sun::star::lang::IllegalArgumentException; -using ::rtl::OUString; - -XFileStream::XFileStream( ZipEntry & rEntry, - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream, - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewTempStream, - const vos::ORef < EncryptionData > &rData, - sal_Bool bNewRawStream, - sal_Bool bIsEncrypted ) -: maEntry ( rEntry ) -, mxData ( rData ) -, mbRawStream ( bNewRawStream ) -, mbFinished ( sal_False ) -, mxTempIn ( xNewTempStream ) -, mxTempSeek ( xNewTempStream, UNO_QUERY ) -, mxTempOut ( xNewTempStream, UNO_QUERY ) -, mxZipStream ( xNewZipStream ) -, mxZipSeek ( xNewZipStream, UNO_QUERY ) -, maInflater ( sal_True ) -, maCipher ( NULL ) -{ - mnZipCurrent = maEntry.nOffset; - if (mbRawStream) - { - mnZipSize = maEntry.nMethod == DEFLATED ? maEntry.nCompressedSize : maEntry.nSize; - mnZipEnd = maEntry.nOffset + mnZipSize; - } - else - { - mnZipSize = maEntry.nSize; - mnZipEnd = maEntry.nMethod == DEFLATED ? maEntry.nOffset + maEntry.nCompressedSize : maEntry.nOffset + maEntry.nSize; - } - - if ( bIsEncrypted ) - { - sal_Bool bHaveEncryptData = ( !rData.isEmpty() && rData->aSalt.getLength() && rData->aInitVector.getLength() && rData->nIterationCount != 0 ) ? sal_True : sal_False; - - // if we have all the encrypted data, and want a raw stream, then prepend it to the stream, otherwise - // make a cipher so we can decrypt it - if ( bHaveEncryptData ) - { - if ( !bNewRawStream ) - ZipFile::StaticGetCipher ( rData, maCipher, sal_True ); - else - { - // Put in the EncryptedDataHeader - Sequence < sal_Int8 > aEncryptedDataHeader ( n_ConstHeaderSize + - rData->aInitVector.getLength() + - rData->aSalt.getLength() + - rData->aDigest.getLength() ); - sal_Int8 * pHeader = aEncryptedDataHeader.getArray(); - ZipFile::StaticFillHeader ( rData, rEntry.nSize, pHeader ); - mxTempOut->writeBytes ( aEncryptedDataHeader ); - mnZipSize += mxTempSeek->getPosition(); - mxTempSeek->seek ( 0 ); - } - } - } -} - -XFileStream::~XFileStream() -{ - if ( maCipher ) - rtl_cipher_destroy ( maCipher ); -} - -void XFileStream::fill( sal_Int64 nUntil) -{ - sal_Int32 nRead; - sal_Int64 nPosition = mxTempSeek->getPosition(); - mxTempSeek->seek ( mxTempSeek->getLength() ); - maBuffer.realloc ( n_ConstBufferSize ); - - while ( mxTempSeek->getLength() < nUntil ) - { - if ( !mbRawStream ) - { - while ( 0 == ( nRead = maInflater.doInflate( maBuffer ) ) ) - { - if ( maInflater.finished() || maInflater.needsDictionary() ) - { - // some error handling ? - return; - } - - sal_Int64 nDiff = mnZipEnd - mnZipCurrent; - if ( nDiff > 0 ) - { - mxZipSeek->seek ( mnZipCurrent ); - nRead = mxZipStream->readBytes ( maCompBuffer, static_cast < sal_Int32 > ( nDiff < n_ConstBufferSize ? nDiff : n_ConstBufferSize ) ); - mnZipCurrent += nRead; - // maCompBuffer now has the uncompressed data, check if we need to decrypt - // before passing to the Inflater - if ( maCipher ) - { - Sequence < sal_Int8 > aCryptBuffer ( nRead ); - rtlCipherError aResult = rtl_cipher_decode ( maCipher, - maCompBuffer.getConstArray(), - nRead, - reinterpret_cast < sal_uInt8 * > (aCryptBuffer.getArray()), - nRead); - OSL_ASSERT (aResult == rtl_Cipher_E_None); - maCompBuffer = aCryptBuffer; // Now it holds the decrypted data - - } - maInflater.setInput ( maCompBuffer ); - } - else - { - // some error handling ? - return; - } - } - } - else - { - sal_Int64 nDiff = mnZipEnd - mnZipCurrent; - mxZipSeek->seek ( mnZipCurrent ); - nRead = mxZipStream->readBytes ( maBuffer, static_cast < sal_Int32 > ( nDiff < n_ConstBufferSize ? nDiff : n_ConstBufferSize ) ); - mnZipCurrent += nRead; - } - Sequence < sal_Int8 > aTmpBuffer ( maBuffer.getConstArray(), nRead ); - mxTempOut->writeBytes ( aTmpBuffer ); - } - mxTempSeek->seek ( nPosition ); -} - -sal_Int32 SAL_CALL XFileStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - sal_Int64 nPosition = mxTempSeek->getPosition(); - if ( nPosition + nBytesToRead > mnZipSize ) - nBytesToRead = static_cast < sal_Int32 > ( mnZipSize - nPosition ); - - sal_Int64 nUntil = nBytesToRead + nPosition + n_ConstBufferSize; - if (nUntil > mnZipSize ) - nUntil = mnZipSize; - if ( nUntil > mxTempSeek->getLength() ) - fill ( nUntil ); - sal_Int32 nRead = mxTempIn->readBytes ( aData, nBytesToRead ); - return nRead; -} - -sal_Int32 SAL_CALL XFileStream::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - return readBytes ( aData, nMaxBytesToRead ); -} -void SAL_CALL XFileStream::skipBytes( sal_Int32 nBytesToSkip ) - throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - seek ( mxTempSeek->getPosition() + nBytesToSkip ); -} - -sal_Int32 SAL_CALL XFileStream::available( ) - throw( NotConnectedException, IOException, RuntimeException) -{ - return static_cast < sal_Int32 > ( mnZipSize - mxTempSeek->getPosition() ); -} - -void SAL_CALL XFileStream::closeInput( ) - throw( NotConnectedException, IOException, RuntimeException) -{ -} -void SAL_CALL XFileStream::seek( sal_Int64 location ) - throw( IllegalArgumentException, IOException, RuntimeException) -{ - if ( location > mnZipSize || location < 0 ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - if ( location > mxTempSeek->getLength() ) - { - sal_Int64 nUntil = location + n_ConstBufferSize > mnZipSize ? mnZipSize : location + n_ConstBufferSize; - fill ( nUntil ); - } - mxTempSeek->seek ( location ); -} -sal_Int64 SAL_CALL XFileStream::getPosition( ) - throw(IOException, RuntimeException) -{ - return mxTempSeek->getPosition(); -} -sal_Int64 SAL_CALL XFileStream::getLength( ) - throw(IOException, RuntimeException) -{ - return mnZipSize; -} diff --git a/package/source/zipapi/XFileStream.hxx b/package/source/zipapi/XFileStream.hxx deleted file mode 100644 index 0cf82c5f35cd..000000000000 --- a/package/source/zipapi/XFileStream.hxx +++ /dev/null @@ -1,96 +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. - * - ************************************************************************/ -#ifndef _XFILE_STREAM_HXX -#define _XFILE_STREAM_HXX - -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <cppuhelper/implbase2.hxx> -#ifndef _VOS_REF_H_ -#include <vos/ref.hxx> -#endif -#ifndef _INFLATER_HXX -#include <Inflater.hxx> -#endif -#include <ZipEntry.hxx> - -namespace com { namespace sun { namespace star { - namespace io { class XOutputStream; } -} } } -class EncryptionData; -typedef void* rtlCipher; -class XFileStream : public cppu::WeakImplHelper2 -< - com::sun::star::io::XInputStream, - com::sun::star::io::XSeekable -> -{ -protected: - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > mxZipStream; - com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxZipSeek; - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > mxTempIn; - com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxTempSeek; - com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > mxTempOut; - com::sun::star::uno::Sequence < sal_Int8 > maBuffer, maCompBuffer; - ZipEntry maEntry; - vos::ORef < EncryptionData > mxData; - rtlCipher maCipher; - Inflater maInflater; - sal_Bool mbRawStream, mbFinished; - sal_Int64 mnZipCurrent, mnZipEnd, mnZipSize; - void fill( sal_Int64 nUntil ); - -public: - XFileStream( ZipEntry & rEntry, - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream, - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewTempStream, - const vos::ORef < EncryptionData > &rData, - sal_Bool bRawStream, - sal_Bool bIsEncrypted ); - virtual ~XFileStream(); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - // XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) - throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); -}; -#endif diff --git a/package/source/zipapi/XUnbufferedStream.cxx b/package/source/zipapi/XUnbufferedStream.cxx index a75af35914a1..e8e16329eccc 100644 --- a/package/source/zipapi/XUnbufferedStream.cxx +++ b/package/source/zipapi/XUnbufferedStream.cxx @@ -27,12 +27,14 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_package.hxx" -#include <XUnbufferedStream.hxx> -#include <EncryptionData.hxx> + #include <com/sun/star/packages/zip/ZipConstants.hpp> #include <com/sun/star/packages/zip/ZipIOException.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> + +#include <XUnbufferedStream.hxx> +#include <EncryptionData.hxx> #include <PackageConstants.hxx> -#include <rtl/cipher.h> #include <ZipFile.hxx> #include <EncryptedDataHeader.hxx> #include <algorithm> @@ -47,6 +49,7 @@ using namespace ::com::sun::star; #endif +using namespace ::com::sun::star; using namespace com::sun::star::packages::zip::ZipConstants; using namespace com::sun::star::io; using namespace com::sun::star::uno; @@ -54,20 +57,22 @@ using com::sun::star::lang::IllegalArgumentException; using com::sun::star::packages::zip::ZipIOException; using ::rtl::OUString; -XUnbufferedStream::XUnbufferedStream( SotMutexHolderRef aMutexHolder, - ZipEntry & rEntry, - Reference < XInputStream > xNewZipStream, - const vos::ORef < EncryptionData > &rData, - sal_Int8 nStreamMode, - sal_Bool bIsEncrypted, - const ::rtl::OUString& aMediaType, - sal_Bool bRecoveryMode ) +XUnbufferedStream::XUnbufferedStream( + const uno::Reference< lang::XMultiServiceFactory >& xFactory, + SotMutexHolderRef aMutexHolder, + ZipEntry & rEntry, + Reference < XInputStream > xNewZipStream, + const ::rtl::Reference< EncryptionData >& rData, + sal_Int8 nStreamMode, + sal_Bool bIsEncrypted, + const ::rtl::OUString& aMediaType, + sal_Bool bRecoveryMode ) : maMutexHolder( aMutexHolder.Is() ? aMutexHolder : SotMutexHolderRef( new SotMutexHolder ) ) , mxZipStream ( xNewZipStream ) , mxZipSeek ( xNewZipStream, UNO_QUERY ) , maEntry ( rEntry ) , mxData ( rData ) -, maCipher ( NULL ) +, mnBlockSize( 1 ) , maInflater ( sal_True ) , mbRawStream ( nStreamMode == UNBUFF_STREAM_RAW || nStreamMode == UNBUFF_STREAM_WRAPPEDRAW ) , mbWrappedRaw ( nStreamMode == UNBUFF_STREAM_WRAPPEDRAW ) @@ -90,11 +95,15 @@ XUnbufferedStream::XUnbufferedStream( SotMutexHolderRef aMutexHolder, mnZipSize = maEntry.nSize; mnZipEnd = maEntry.nMethod == DEFLATED ? maEntry.nOffset + maEntry.nCompressedSize : maEntry.nOffset + maEntry.nSize; } - sal_Bool bHaveEncryptData = ( !rData.isEmpty() && rData->aSalt.getLength() && rData->aInitVector.getLength() && rData->nIterationCount != 0 ) ? sal_True : sal_False; + sal_Bool bHaveEncryptData = ( rData.is() && rData->m_aSalt.getLength() && rData->m_aInitVector.getLength() && rData->m_nIterationCount != 0 ) ? sal_True : sal_False; sal_Bool bMustDecrypt = ( nStreamMode == UNBUFF_STREAM_DATA && bHaveEncryptData && bIsEncrypted ) ? sal_True : sal_False; if ( bMustDecrypt ) - ZipFile::StaticGetCipher ( rData, maCipher, sal_True ); + { + m_xCipherContext = ZipFile::StaticGetCipher( xFactory, rData, false ); + mnBlockSize = ( rData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 16 : 1 ); + } + if ( bHaveEncryptData && mbWrappedRaw && bIsEncrypted ) { // if we have the data needed to decrypt it, but didn't want it decrypted (or @@ -103,24 +112,26 @@ XUnbufferedStream::XUnbufferedStream( SotMutexHolderRef aMutexHolder, // Make a buffer big enough to hold both the header and the data itself maHeader.realloc ( n_ConstHeaderSize + - rData->aInitVector.getLength() + - rData->aSalt.getLength() + - rData->aDigest.getLength() + + rData->m_aInitVector.getLength() + + rData->m_aSalt.getLength() + + rData->m_aDigest.getLength() + aMediaType.getLength() * sizeof( sal_Unicode ) ); sal_Int8 * pHeader = maHeader.getArray(); - ZipFile::StaticFillHeader ( rData, rEntry.nSize, aMediaType, pHeader ); + ZipFile::StaticFillHeader( rData, rEntry.nSize, aMediaType, pHeader ); mnHeaderToRead = static_cast < sal_Int16 > ( maHeader.getLength() ); } } // allows to read package raw stream -XUnbufferedStream::XUnbufferedStream( const Reference < XInputStream >& xRawStream, - const vos::ORef < EncryptionData > &rData ) +XUnbufferedStream::XUnbufferedStream( + const uno::Reference< lang::XMultiServiceFactory >& /*xFactory*/, + const Reference < XInputStream >& xRawStream, + const ::rtl::Reference< EncryptionData >& rData ) : maMutexHolder( new SotMutexHolder ) , mxZipStream ( xRawStream ) , mxZipSeek ( xRawStream, UNO_QUERY ) , mxData ( rData ) -, maCipher ( NULL ) +, mnBlockSize( 1 ) , maInflater ( sal_True ) , mbRawStream ( sal_False ) , mbWrappedRaw ( sal_False ) @@ -136,8 +147,8 @@ XUnbufferedStream::XUnbufferedStream( const Reference < XInputStream >& xRawStre OSL_ENSURE( mxZipSeek.is(), "The stream must be seekable!\n" ); // skip raw header, it must be already parsed to rData - mnZipCurrent = n_ConstHeaderSize + rData->aInitVector.getLength() + - rData->aSalt.getLength() + rData->aDigest.getLength(); + mnZipCurrent = n_ConstHeaderSize + rData->m_aInitVector.getLength() + + rData->m_aSalt.getLength() + rData->m_aDigest.getLength(); try { if ( mxZipSeek.is() ) @@ -149,13 +160,12 @@ XUnbufferedStream::XUnbufferedStream( const Reference < XInputStream >& xRawStre mnZipEnd = mnZipCurrent + mnZipSize; - ZipFile::StaticGetCipher ( rData, maCipher, sal_True ); + // the raw data will not be decrypted, no need for the cipher + // m_xCipherContext = ZipFile::StaticGetCipher( xFactory, rData, false ); } XUnbufferedStream::~XUnbufferedStream() { - if ( maCipher ) - rtl_cipher_destroy ( maCipher ); } sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) @@ -180,7 +190,7 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa { sal_Int16 nHeadRead = static_cast< sal_Int16 >(( nRequestedBytes > mnHeaderToRead ? mnHeaderToRead : nRequestedBytes )); - memcpy ( aData.getArray(), maHeader.getConstArray() + maHeader.getLength() - mnHeaderToRead, nHeadRead ); + rtl_copyMemory ( aData.getArray(), maHeader.getConstArray() + maHeader.getLength() - mnHeaderToRead, nHeadRead ); mnHeaderToRead = mnHeaderToRead - nHeadRead; if ( nHeadRead < nRequestedBytes ) @@ -242,12 +252,17 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "Dictionaries are not supported!" ) ), Reference< XInterface >() ); - sal_Int32 nDiff = static_cast < sal_Int32 > ( mnZipEnd - mnZipCurrent ); + sal_Int32 nDiff = static_cast< sal_Int32 >( mnZipEnd - mnZipCurrent ); if ( nDiff > 0 ) { mxZipSeek->seek ( mnZipCurrent ); - sal_Int32 nToRead = std::min ( nDiff, std::max ( nRequestedBytes, static_cast< sal_Int32 >( 8192 ) ) ); - sal_Int32 nZipRead = mxZipStream->readBytes ( maCompBuffer, nToRead ); + + sal_Int32 nToRead = std::max( nRequestedBytes, static_cast< sal_Int32 >( 8192 ) ); + if ( mnBlockSize > 1 ) + nToRead = nToRead + mnBlockSize - nToRead % mnBlockSize; + nToRead = std::min( nDiff, nToRead ); + + sal_Int32 nZipRead = mxZipStream->readBytes( maCompBuffer, nToRead ); if ( nZipRead < nToRead ) throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "No expected data!" ) ), Reference< XInterface >() ); @@ -255,23 +270,22 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa mnZipCurrent += nZipRead; // maCompBuffer now has the data, check if we need to decrypt // before passing to the Inflater - if ( maCipher ) + if ( m_xCipherContext.is() ) { if ( mbCheckCRC ) maCRC.update( maCompBuffer ); - Sequence < sal_Int8 > aCryptBuffer ( nZipRead ); - rtlCipherError aResult = - rtl_cipher_decode ( maCipher, - maCompBuffer.getConstArray(), - nZipRead, - reinterpret_cast < sal_uInt8 * > (aCryptBuffer.getArray()), - nZipRead); - if( aResult != rtl_Cipher_E_None ) { - OSL_ASSERT (aResult == rtl_Cipher_E_None); + maCompBuffer = m_xCipherContext->convertWithCipherContext( maCompBuffer ); + if ( mnZipCurrent == mnZipEnd ) + { + uno::Sequence< sal_Int8 > aSuffix = m_xCipherContext->finalizeCipherContextAndDispose(); + if ( aSuffix.getLength() ) + { + sal_Int32 nOldLen = maCompBuffer.getLength(); + maCompBuffer.realloc( nOldLen + aSuffix.getLength() ); + rtl_copyMemory( maCompBuffer.getArray() + nOldLen, aSuffix.getConstArray(), aSuffix.getLength() ); + } } - maCompBuffer = aCryptBuffer; // Now it holds the decrypted data - } maInflater.setInput ( maCompBuffer ); } @@ -290,7 +304,7 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa if ( mbCheckCRC && ( !mbRawStream || mbWrappedRaw ) ) { - if ( !maCipher && !mbWrappedRaw ) + if ( !m_xCipherContext.is() && !mbWrappedRaw ) maCRC.update( aData ); #if 0 diff --git a/package/source/zipapi/XUnbufferedStream.hxx b/package/source/zipapi/XUnbufferedStream.hxx index 321ec10b8032..f8878c25979a 100644 --- a/package/source/zipapi/XUnbufferedStream.hxx +++ b/package/source/zipapi/XUnbufferedStream.hxx @@ -32,8 +32,10 @@ #include <com/sun/star/io/XSeekable.hpp> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/xml/crypto/XCipherContext.hpp> + #include <cppuhelper/implbase1.hxx> -#include <vos/ref.hxx> +#include <rtl/ref.hxx> #include <Inflater.hxx> #include <ZipEntry.hxx> #include <CRC32.hxx> @@ -44,7 +46,6 @@ #define UNBUFF_STREAM_WRAPPEDRAW 2 class EncryptionData; -typedef void* rtlCipher; class XUnbufferedStream : public cppu::WeakImplHelper1 < com::sun::star::io::XInputStream @@ -57,8 +58,9 @@ protected: com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxZipSeek; com::sun::star::uno::Sequence < sal_Int8 > maCompBuffer, maHeader; ZipEntry maEntry; - vos::ORef < EncryptionData > mxData; - rtlCipher maCipher; + ::rtl::Reference< EncryptionData > mxData; + sal_Int32 mnBlockSize; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext; Inflater maInflater; sal_Bool mbRawStream, mbWrappedRaw, mbFinished; sal_Int16 mnHeaderToRead; @@ -68,18 +70,21 @@ protected: public: XUnbufferedStream( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, SotMutexHolderRef aMutexHolder, ZipEntry & rEntry, com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference< EncryptionData >& rData, sal_Int8 nStreamMode, sal_Bool bIsEncrypted, const ::rtl::OUString& aMediaType, sal_Bool bRecoveryMode ); // allows to read package raw stream - XUnbufferedStream( const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& xRawStream, - const vos::ORef < EncryptionData > &rData ); + XUnbufferedStream( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& xRawStream, + const ::rtl::Reference< EncryptionData >& rData ); virtual ~XUnbufferedStream(); diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index dcd5669897e3..4827f6879853 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -27,31 +27,36 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_package.hxx" -#include <ZipFile.hxx> -#include <ZipEnumeration.hxx> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/ucb/XProgressHandler.hpp> #include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <rtl/cipher.h> +#include <com/sun/star/xml/crypto/XCipherContext.hpp> +#include <com/sun/star/xml/crypto/XDigestContext.hpp> +#include <com/sun/star/xml/crypto/XCipherContextSupplier.hpp> +#include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> + +#include <comphelper/storagehelper.hxx> +#include <comphelper/processfactory.hxx> #include <rtl/digest.h> -/* -#include <XMemoryStream.hxx> -#include <XFileStream.hxx> -*/ + +#include <vector> + +#include "blowfishcontext.hxx" +#include "sha1context.hxx" +#include <ZipFile.hxx> +#include <ZipEnumeration.hxx> #include <XUnbufferedStream.hxx> #include <PackageConstants.hxx> #include <EncryptedDataHeader.hxx> #include <EncryptionData.hxx> #include <MemoryByteGrabber.hxx> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/ucb/XProgressHandler.hpp> -#ifndef _CRC32_HXX_ #include <CRC32.hxx> -#endif -#include <string.h> // for memcpy -#include <vector> - -#include <comphelper/storagehelper.hxx> +#define AES_CBC_BLOCK_SIZE 16 using namespace vos; using namespace rtl; @@ -67,13 +72,13 @@ using namespace com::sun::star::packages::zip::ZipConstants; /** This class is used to read entries from a zip file */ -ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise ) +ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise ) throw(IOException, ZipException, RuntimeException) : aGrabber(xInput) , aInflater (sal_True) , xStream(xInput) , xSeek(xInput, UNO_QUERY) -, xFactory ( xNewFactory ) +, m_xFactory ( xNewFactory ) , bRecoveryMode( sal_False ) { if (bInitialise) @@ -81,20 +86,20 @@ ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiSe if ( readCEN() == -1 ) { aEntries.clear(); - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), uno::Reference < XInterface > () ); } } } -ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise, sal_Bool bForceRecovery, Reference < XProgressHandler > xProgress ) +ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise, sal_Bool bForceRecovery, uno::Reference < XProgressHandler > xProgress ) throw(IOException, ZipException, RuntimeException) : aGrabber(xInput) , aInflater (sal_True) , xStream(xInput) , xSeek(xInput, UNO_QUERY) -, xFactory ( xNewFactory ) +, m_xFactory ( xNewFactory ) , xProgressHandler( xProgress ) , bRecoveryMode( bForceRecovery ) { @@ -107,7 +112,7 @@ ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiSe else if ( readCEN() == -1 ) { aEntries.clear(); - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), uno::Reference < XInterface > () ); } } } @@ -117,55 +122,94 @@ ZipFile::~ZipFile() aEntries.clear(); } -void ZipFile::setInputStream ( Reference < XInputStream > xNewStream ) +void ZipFile::setInputStream ( uno::Reference < XInputStream > xNewStream ) { ::osl::MutexGuard aGuard( m_aMutex ); xStream = xNewStream; - xSeek = Reference < XSeekable > ( xStream, UNO_QUERY ); + xSeek = uno::Reference < XSeekable > ( xStream, UNO_QUERY ); aGrabber.setInputStream ( xStream ); } -sal_Bool ZipFile::StaticGetCipher ( const ORef < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode ) +uno::Reference< xml::crypto::XDigestContext > ZipFile::StaticGetDigestContextForChecksum( const uno::Reference< lang::XMultiServiceFactory >& xArgFactory, const ::rtl::Reference< EncryptionData >& xEncryptionData ) +{ + uno::Reference< xml::crypto::XDigestContext > xDigestContext; + if ( xEncryptionData->m_nCheckAlg == xml::crypto::DigestID::SHA256_1K ) + { + uno::Reference< lang::XMultiServiceFactory > xFactory = xArgFactory; + if ( !xFactory.is() ) + xFactory.set( comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); + + uno::Reference< xml::crypto::XDigestContextSupplier > xDigestContextSupplier( + xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ), + uno::UNO_QUERY_THROW ); + + xDigestContext.set( xDigestContextSupplier->getDigestContext( xEncryptionData->m_nCheckAlg, uno::Sequence< beans::NamedValue >() ), uno::UNO_SET_THROW ); + } + else if ( xEncryptionData->m_nCheckAlg == xml::crypto::DigestID::SHA1_1K ) + xDigestContext.set( SHA1DigestContext::Create(), uno::UNO_SET_THROW ); + + return xDigestContext; +} + +uno::Reference< xml::crypto::XCipherContext > ZipFile::StaticGetCipher( const uno::Reference< lang::XMultiServiceFactory >& xArgFactory, const ::rtl::Reference< EncryptionData >& xEncryptionData, bool bEncrypt ) { - sal_Bool bResult = sal_False; - if ( ! xEncryptionData.isEmpty() ) + uno::Reference< xml::crypto::XCipherContext > xResult; + + try + { + uno::Sequence< sal_Int8 > aDerivedKey( xEncryptionData->m_nDerivedKeySize ); + if ( rtl_Digest_E_None != rtl_digest_PBKDF2( reinterpret_cast< sal_uInt8* >( aDerivedKey.getArray() ), + aDerivedKey.getLength(), + reinterpret_cast< const sal_uInt8 * > (xEncryptionData->m_aKey.getConstArray() ), + xEncryptionData->m_aKey.getLength(), + reinterpret_cast< const sal_uInt8 * > ( xEncryptionData->m_aSalt.getConstArray() ), + xEncryptionData->m_aSalt.getLength(), + xEncryptionData->m_nIterationCount ) ) + { + throw ZipIOException( ::rtl::OUString::createFromAscii( "Can not create derived key!\n" ), + uno::Reference< XInterface >() ); + } + + if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING ) + { + uno::Reference< lang::XMultiServiceFactory > xFactory = xArgFactory; + if ( !xFactory.is() ) + xFactory.set( comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); + + uno::Reference< xml::crypto::XCipherContextSupplier > xCipherContextSupplier( + xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ), + uno::UNO_QUERY_THROW ); + + xResult = xCipherContextSupplier->getCipherContext( xEncryptionData->m_nEncAlg, aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt, uno::Sequence< beans::NamedValue >() ); + } + else if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::BLOWFISH_CFB_8 ) + { + xResult = BlowfishCFB8CipherContext::Create( aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt ); + } + else + { + throw ZipIOException( ::rtl::OUString::createFromAscii( "Unknown cipher algorithm is requested!\n" ), + uno::Reference< XInterface >() ); + } + } + catch( uno::Exception& ) { - Sequence < sal_uInt8 > aDerivedKey (16); - rtlCipherError aResult; - Sequence < sal_Int8 > aDecryptBuffer; - - // Get the key - rtl_digest_PBKDF2 ( aDerivedKey.getArray(), 16, - reinterpret_cast < const sal_uInt8 * > (xEncryptionData->aKey.getConstArray() ), - xEncryptionData->aKey.getLength(), - reinterpret_cast < const sal_uInt8 * > ( xEncryptionData->aSalt.getConstArray() ), - xEncryptionData->aSalt.getLength(), - xEncryptionData->nIterationCount ); - - rCipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream); - aResult = rtl_cipher_init( rCipher, bDecode ? rtl_Cipher_DirectionDecode : rtl_Cipher_DirectionEncode, - aDerivedKey.getConstArray(), - aDerivedKey.getLength(), - reinterpret_cast < const sal_uInt8 * > ( xEncryptionData->aInitVector.getConstArray() ), - xEncryptionData->aInitVector.getLength()); - OSL_ASSERT (aResult == rtl_Cipher_E_None); - - bResult = ( aResult == rtl_Cipher_E_None ); + OSL_ENSURE( sal_False, "Can not create cipher context!" ); } - return bResult; + return xResult; } -void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData, +void ZipFile::StaticFillHeader( const ::rtl::Reference< EncryptionData >& rData, sal_Int32 nSize, const ::rtl::OUString& aMediaType, sal_Int8 * & pHeader ) { // I think it's safe to restrict vector and salt length to 2 bytes ! - sal_Int16 nIVLength = static_cast < sal_Int16 > ( rData->aInitVector.getLength() ); - sal_Int16 nSaltLength = static_cast < sal_Int16 > ( rData->aSalt.getLength() ); - sal_Int16 nDigestLength = static_cast < sal_Int16 > ( rData->aDigest.getLength() ); + sal_Int16 nIVLength = static_cast < sal_Int16 > ( rData->m_aInitVector.getLength() ); + sal_Int16 nSaltLength = static_cast < sal_Int16 > ( rData->m_aSalt.getLength() ); + sal_Int16 nDigestLength = static_cast < sal_Int16 > ( rData->m_aDigest.getLength() ); sal_Int16 nMediaTypeLength = static_cast < sal_Int16 > ( aMediaType.getLength() * sizeof( sal_Unicode ) ); // First the header @@ -179,7 +223,7 @@ void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData, *(pHeader++) = ( n_ConstCurrentVersion >> 8 ) & 0xFF; // Then the iteration Count - sal_Int32 nIterationCount = rData->nIterationCount; + sal_Int32 nIterationCount = rData->m_nIterationCount; *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 0 ) & 0xFF); *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 8 ) & 0xFF); *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 16 ) & 0xFF); @@ -191,6 +235,34 @@ void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData, *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 16 ) & 0xFF); *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 24 ) & 0xFF); + // Then the encryption algorithm + sal_Int32 nEncAlgID = rData->m_nEncAlg; + *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 0 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 8 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 16 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 24 ) & 0xFF); + + // Then the checksum algorithm + sal_Int32 nChecksumAlgID = rData->m_nCheckAlg; + *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 0 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 8 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 16 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 24 ) & 0xFF); + + // Then the derived key size + sal_Int32 nDerivedKeySize = rData->m_nDerivedKeySize; + *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 0 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 8 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 16 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 24 ) & 0xFF); + + // Then the start key generation algorithm + sal_Int32 nKeyAlgID = rData->m_nStartKeyGenID; + *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 0 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 8 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 16 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 24 ) & 0xFF); + // Then the salt length *(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 0 ) & 0xFF); *(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 8 ) & 0xFF); @@ -208,26 +280,30 @@ void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData, *(pHeader++) = static_cast< sal_Int8 >(( nMediaTypeLength >> 8 ) & 0xFF); // Then the salt content - memcpy ( pHeader, rData->aSalt.getConstArray(), nSaltLength ); + rtl_copyMemory ( pHeader, rData->m_aSalt.getConstArray(), nSaltLength ); pHeader += nSaltLength; // Then the IV content - memcpy ( pHeader, rData->aInitVector.getConstArray(), nIVLength ); + rtl_copyMemory ( pHeader, rData->m_aInitVector.getConstArray(), nIVLength ); pHeader += nIVLength; // Then the digest content - memcpy ( pHeader, rData->aDigest.getConstArray(), nDigestLength ); + rtl_copyMemory ( pHeader, rData->m_aDigest.getConstArray(), nDigestLength ); pHeader += nDigestLength; // Then the mediatype itself - memcpy ( pHeader, aMediaType.getStr(), nMediaTypeLength ); + rtl_copyMemory ( pHeader, aMediaType.getStr(), nMediaTypeLength ); pHeader += nMediaTypeLength; } -sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData, +sal_Bool ZipFile::StaticFillData ( ::rtl::Reference< BaseEncryptionData > & rData, + sal_Int32 &rEncAlg, + sal_Int32 &rChecksumAlg, + sal_Int32 &rDerivedKeySize, + sal_Int32 &rStartKeyGenID, sal_Int32 &rSize, ::rtl::OUString& aMediaType, - Reference < XInputStream > &rStream ) + const uno::Reference< XInputStream >& rStream ) { sal_Bool bOk = sal_False; const sal_Int32 nHeaderSize = n_ConstHeaderSize - 4; @@ -244,13 +320,33 @@ sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData, nCount |= ( pBuffer[nPos++] & 0xFF ) << 8; nCount |= ( pBuffer[nPos++] & 0xFF ) << 16; nCount |= ( pBuffer[nPos++] & 0xFF ) << 24; - rData->nIterationCount = nCount; + rData->m_nIterationCount = nCount; rSize = pBuffer[nPos++] & 0xFF; rSize |= ( pBuffer[nPos++] & 0xFF ) << 8; rSize |= ( pBuffer[nPos++] & 0xFF ) << 16; rSize |= ( pBuffer[nPos++] & 0xFF ) << 24; + rEncAlg = pBuffer[nPos++] & 0xFF; + rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 8; + rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 16; + rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 24; + + rChecksumAlg = pBuffer[nPos++] & 0xFF; + rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 8; + rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 16; + rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 24; + + rDerivedKeySize = pBuffer[nPos++] & 0xFF; + rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 8; + rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 16; + rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 24; + + rStartKeyGenID = pBuffer[nPos++] & 0xFF; + rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 8; + rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 16; + rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 24; + sal_Int16 nSaltLength = pBuffer[nPos++] & 0xFF; nSaltLength |= ( pBuffer[nPos++] & 0xFF ) << 8; sal_Int16 nIVLength = ( pBuffer[nPos++] & 0xFF ); @@ -263,16 +359,16 @@ sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData, if ( nSaltLength == rStream->readBytes ( aBuffer, nSaltLength ) ) { - rData->aSalt.realloc ( nSaltLength ); - memcpy ( rData->aSalt.getArray(), aBuffer.getConstArray(), nSaltLength ); + rData->m_aSalt.realloc ( nSaltLength ); + rtl_copyMemory ( rData->m_aSalt.getArray(), aBuffer.getConstArray(), nSaltLength ); if ( nIVLength == rStream->readBytes ( aBuffer, nIVLength ) ) { - rData->aInitVector.realloc ( nIVLength ); - memcpy ( rData->aInitVector.getArray(), aBuffer.getConstArray(), nIVLength ); + rData->m_aInitVector.realloc ( nIVLength ); + rtl_copyMemory ( rData->m_aInitVector.getArray(), aBuffer.getConstArray(), nIVLength ); if ( nDigestLength == rStream->readBytes ( aBuffer, nDigestLength ) ) { - rData->aDigest.realloc ( nDigestLength ); - memcpy ( rData->aDigest.getArray(), aBuffer.getConstArray(), nDigestLength ); + rData->m_aDigest.realloc ( nDigestLength ); + rtl_copyMemory ( rData->m_aDigest.getArray(), aBuffer.getConstArray(), nDigestLength ); if ( nMediaTypeLength == rStream->readBytes ( aBuffer, nMediaTypeLength ) ) { @@ -288,84 +384,107 @@ sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData, return bOk; } -Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const Reference< XInputStream >& xStream, - const ORef < EncryptionData > &rData ) +uno::Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory, + const uno::Reference< XInputStream >& xStream, + const ::rtl::Reference< EncryptionData > &rData ) throw ( packages::WrongPasswordException, ZipIOException, RuntimeException ) { - if ( rData.isEmpty() ) + if ( !rData.is() ) throw ZipIOException( OUString::createFromAscii( "Encrypted stream without encryption data!\n" ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); - if ( !rData->aKey.getLength() ) + if ( !rData->m_aKey.getLength() ) throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - Reference< XSeekable > xSeek( xStream, UNO_QUERY ); + uno::Reference< XSeekable > xSeek( xStream, UNO_QUERY ); if ( !xSeek.is() ) throw ZipIOException( OUString::createFromAscii( "The stream must be seekable!\n" ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); // if we have a digest, then this file is an encrypted one and we should // check if we can decrypt it or not - OSL_ENSURE( rData->aDigest.getLength(), "Can't detect password correctness without digest!\n" ); - if ( rData->aDigest.getLength() ) + OSL_ENSURE( rData->m_aDigest.getLength(), "Can't detect password correctness without digest!\n" ); + if ( rData->m_aDigest.getLength() ) { - sal_Int32 nSize = sal::static_int_cast< sal_Int32 >( xSeek->getLength() ); - nSize = nSize > n_ConstDigestLength ? n_ConstDigestLength : nSize; + sal_Int32 nSize = sal::static_int_cast< sal_Int32 >( xSeek->getLength() ); + if ( nSize > n_ConstDigestLength + 32 ) + nSize = n_ConstDigestLength + 32; // skip header - xSeek->seek( n_ConstHeaderSize + rData->aInitVector.getLength() + - rData->aSalt.getLength() + rData->aDigest.getLength() ); + xSeek->seek( n_ConstHeaderSize + rData->m_aInitVector.getLength() + + rData->m_aSalt.getLength() + rData->m_aDigest.getLength() ); // Only want to read enough to verify the digest Sequence < sal_Int8 > aReadBuffer ( nSize ); xStream->readBytes( aReadBuffer, nSize ); - if ( !StaticHasValidPassword( aReadBuffer, rData ) ) + if ( !StaticHasValidPassword( xFactory, aReadBuffer, rData ) ) throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } - return new XUnbufferedStream ( xStream, rData ); + return new XUnbufferedStream( xFactory, xStream, rData ); } -sal_Bool ZipFile::StaticHasValidPassword( const Sequence< sal_Int8 > &aReadBuffer, const ORef < EncryptionData > &rData ) +#if 0 +// for debugging purposes +void CheckSequence( const uno::Sequence< sal_Int8 >& aSequence ) { - if ( !rData.isValid() || !rData->aKey.getLength() ) + if ( aSequence.getLength() ) + { + sal_Int32* pPointer = *( (sal_Int32**)&aSequence ); + sal_Int32 nSize = *( pPointer + 1 ); + sal_Int32 nMemSize = *( pPointer - 2 ); + sal_Int32 nUsedMemSize = ( nSize + 4 * sizeof( sal_Int32 ) ); + OSL_ENSURE( nSize == aSequence.getLength() && nUsedMemSize + 7 - ( nUsedMemSize - 1 ) % 8 == nMemSize, "Broken Sequence!" ); + } +} +#endif + +sal_Bool ZipFile::StaticHasValidPassword( const uno::Reference< lang::XMultiServiceFactory >& xFactory, const Sequence< sal_Int8 > &aReadBuffer, const ::rtl::Reference< EncryptionData > &rData ) +{ + if ( !rData.is() || !rData->m_aKey.getLength() ) return sal_False; sal_Bool bRet = sal_False; - sal_Int32 nSize = aReadBuffer.getLength(); - - // make a temporary cipher - rtlCipher aCipher; - StaticGetCipher ( rData, aCipher, sal_True ); - - Sequence < sal_Int8 > aDecryptBuffer ( nSize ); - rtlDigest aDigest = rtl_digest_createSHA1(); - rtlDigestError aDigestResult; - Sequence < sal_uInt8 > aDigestSeq ( RTL_DIGEST_LENGTH_SHA1 ); - rtlCipherError aResult = rtl_cipher_decode ( aCipher, - aReadBuffer.getConstArray(), - nSize, - reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()), - nSize); - if(aResult != rtl_Cipher_E_None ) { - OSL_ASSERT ( aResult == rtl_Cipher_E_None); + + uno::Reference< xml::crypto::XCipherContext > xCipher( StaticGetCipher( xFactory, rData, false ), uno::UNO_SET_THROW ); + + uno::Sequence< sal_Int8 > aDecryptBuffer; + uno::Sequence< sal_Int8 > aDecryptBuffer2; + try + { + aDecryptBuffer = xCipher->convertWithCipherContext( aReadBuffer ); + aDecryptBuffer2 = xCipher->finalizeCipherContextAndDispose(); + } + catch( uno::Exception& ) + { + // decryption with padding will throw the exception in finalizing if the buffer represent only part of the stream + // it is no problem, actually this is why we read 32 additional bytes ( two of maximal possible encryption blocks ) + } + + if ( aDecryptBuffer2.getLength() ) + { + sal_Int32 nOldLen = aDecryptBuffer.getLength(); + aDecryptBuffer.realloc( nOldLen + aDecryptBuffer2.getLength() ); + rtl_copyMemory( aDecryptBuffer.getArray() + nOldLen, aDecryptBuffer2.getArray(), aDecryptBuffer2.getLength() ); } - aDigestResult = rtl_digest_updateSHA1 ( aDigest, - static_cast < const void * > ( aDecryptBuffer.getConstArray() ), nSize ); - OSL_ASSERT ( aDigestResult == rtl_Digest_E_None ); + if ( aDecryptBuffer.getLength() > n_ConstDigestLength ) + aDecryptBuffer.realloc( n_ConstDigestLength ); + + uno::Sequence< sal_Int8 > aDigestSeq; + uno::Reference< xml::crypto::XDigestContext > xDigestContext( StaticGetDigestContextForChecksum( xFactory, rData ), uno::UNO_SET_THROW ); - aDigestResult = rtl_digest_getSHA1 ( aDigest, aDigestSeq.getArray(), RTL_DIGEST_LENGTH_SHA1 ); - OSL_ASSERT ( aDigestResult == rtl_Digest_E_None ); + xDigestContext->updateDigest( aDecryptBuffer ); + aDigestSeq = xDigestContext->finalizeDigestAndDispose(); // If we don't have a digest, then we have to assume that the password is correct - if ( rData->aDigest.getLength() != 0 && - ( aDigestSeq.getLength() != rData->aDigest.getLength() || + if ( rData->m_aDigest.getLength() != 0 && + ( aDigestSeq.getLength() != rData->m_aDigest.getLength() || 0 != rtl_compareMemory ( aDigestSeq.getConstArray(), - rData->aDigest.getConstArray(), + rData->m_aDigest.getConstArray(), aDigestSeq.getLength() ) ) ) { // We should probably tell the user that the password they entered was wrong @@ -373,136 +492,44 @@ sal_Bool ZipFile::StaticHasValidPassword( const Sequence< sal_Int8 > &aReadBuffe else bRet = sal_True; - rtl_digest_destroySHA1 ( aDigest ); - return bRet; } -sal_Bool ZipFile::hasValidPassword ( ZipEntry & rEntry, const ORef < EncryptionData > &rData ) +sal_Bool ZipFile::hasValidPassword ( ZipEntry & rEntry, const ::rtl::Reference< EncryptionData >& rData ) { ::osl::MutexGuard aGuard( m_aMutex ); sal_Bool bRet = sal_False; - if ( rData->aKey.getLength() ) + if ( rData.is() && rData->m_aKey.getLength() ) { xSeek->seek( rEntry.nOffset ); sal_Int32 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize; // Only want to read enough to verify the digest - nSize = nSize > n_ConstDigestLength ? n_ConstDigestLength : nSize; + if ( nSize > n_ConstDigestDecrypt ) + nSize = n_ConstDigestDecrypt; + Sequence < sal_Int8 > aReadBuffer ( nSize ); xStream->readBytes( aReadBuffer, nSize ); - bRet = StaticHasValidPassword( aReadBuffer, rData ); + bRet = StaticHasValidPassword( m_xFactory, aReadBuffer, rData ); } + return bRet; } -#if 0 -Reference < XInputStream > ZipFile::createFileStream( - ZipEntry & rEntry, - const ORef < EncryptionData > &rData, - sal_Bool bRawStream, - sal_Bool bIsEncrypted ) -{ - static OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) ); - Reference < XInputStream > xTempStream = Reference < XInputStream > ( xFactory->createInstance ( sServiceName ), UNO_QUERY ); - return new XFileStream ( rEntry, xStream, xTempStream, rData, bRawStream, bIsEncrypted ); -} -Reference < XInputStream > ZipFile::createMemoryStream( - ZipEntry & rEntry, - const ORef < EncryptionData > &rData, - sal_Bool bRawStream, - sal_Bool bIsEncrypted ) -{ - sal_Int32 nUncompressedSize, nEnd; - if (bRawStream) - { - nUncompressedSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize; - nEnd = rEntry.nOffset + nUncompressedSize; - } - else - { - nUncompressedSize = rEntry.nSize; - nEnd = rEntry.nMethod == DEFLATED ? rEntry.nOffset + rEntry.nCompressedSize : rEntry.nOffset + rEntry.nSize; - } - sal_Int32 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize; - Sequence < sal_Int8 > aReadBuffer ( nSize ), aDecryptBuffer, aWriteBuffer; - rtlCipher aCipher; - - // If the encryption key is zero, we need to return the raw stream. First check if - // we have the salt. If we have the salt, then check if we have the encryption key - // if not, return rawStream instead. - - sal_Bool bHaveEncryptData = ( !rData.isEmpty() && rData->aSalt.getLength() && rData->aInitVector.getLength() && rData->nIterationCount != 0 ) ? sal_True : sal_False; - sal_Bool bMustDecrypt = ( !bRawStream && bHaveEncryptData && bIsEncrypted ) ? sal_True : sal_False; - - if ( bMustDecrypt ) - { - StaticGetCipher ( rData, aCipher, sal_True ); - aDecryptBuffer.realloc ( nSize ); - } - - if ( nSize <0 ) - throw IOException ( ); - - xSeek->seek( rEntry.nOffset ); - xStream->readBytes( aReadBuffer, nSize ); // Now it holds the raw stuff from disk - - if ( bMustDecrypt ) - { - rtlCipherError aResult = rtl_cipher_decode ( aCipher, - aReadBuffer.getConstArray(), - nSize, - reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()), - nSize); - OSL_ASSERT (aResult == rtl_Cipher_E_None); - aReadBuffer = aDecryptBuffer; // Now it holds the decrypted data - } - if (bRawStream || rEntry.nMethod == STORED) - aWriteBuffer = aReadBuffer; // bRawStream means the caller doesn't want it decompressed - else - { - aInflater.setInputSegment( aReadBuffer, 0, nSize ); - aWriteBuffer.realloc( nUncompressedSize ); - aInflater.doInflate( aWriteBuffer ); - aInflater.reset(); - } - - if ( bHaveEncryptData && !bMustDecrypt && bIsEncrypted ) - { - // if we have the data needed to decrypt it, but didn't want it decrypted (or - // we couldn't decrypt it due to wrong password), then we prepend this - // data to the stream - - // Make a buffer big enough to hold both the header and the data itself - Sequence < sal_Int8 > aEncryptedDataHeader ( n_ConstHeaderSize + - rData->aInitVector.getLength() + - rData->aSalt.getLength() + - rData->aDigest.getLength() + - aWriteBuffer.getLength() ); - sal_Int8 * pHeader = aEncryptedDataHeader.getArray(); - StaticFillHeader ( rData, rEntry.nSize, pHeader ); - memcpy ( pHeader, aWriteBuffer.getConstArray(), aWriteBuffer.getLength() ); - - // dump old buffer and point aWriteBuffer to the new one with the header - aWriteBuffer = aEncryptedDataHeader; - } - return Reference < XInputStream > ( new XMemoryStream ( aWriteBuffer ) ); -} -#endif -Reference < XInputStream > ZipFile::createUnbufferedStream( +uno::Reference< XInputStream > ZipFile::createUnbufferedStream( SotMutexHolderRef aMutexHolder, ZipEntry & rEntry, - const ORef < EncryptionData > &rData, + const ::rtl::Reference< EncryptionData > &rData, sal_Int8 nStreamMode, sal_Bool bIsEncrypted, ::rtl::OUString aMediaType ) { ::osl::MutexGuard aGuard( m_aMutex ); - return new XUnbufferedStream ( aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode ); + return new XUnbufferedStream ( m_xFactory, aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode ); } @@ -511,8 +538,8 @@ ZipEnumeration * SAL_CALL ZipFile::entries( ) return new ZipEnumeration ( aEntries ); } -Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, +uno::Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry, + const ::rtl::Reference< EncryptionData > &rData, sal_Bool bIsEncrypted, SotMutexHolderRef aMutexHolder ) throw(IOException, ZipException, RuntimeException) @@ -529,7 +556,7 @@ Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry, // if we have a digest, then this file is an encrypted one and we should // check if we can decrypt it or not - if ( bIsEncrypted && !rData.isEmpty() && rData->aDigest.getLength() ) + if ( bIsEncrypted && rData.is() && rData->m_aDigest.getLength() ) bNeedRawStream = !hasValidPassword ( rEntry, rData ); return createUnbufferedStream ( aMutexHolder, @@ -539,8 +566,8 @@ Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry, bIsEncrypted ); } -Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, +uno::Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry, + const ::rtl::Reference< EncryptionData > &rData, sal_Bool bIsEncrypted, SotMutexHolderRef aMutexHolder ) throw ( packages::WrongPasswordException, @@ -560,14 +587,14 @@ Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry, { // in case no digest is provided there is no way // to detect password correctness - if ( rData.isEmpty() ) + if ( !rData.is() ) throw ZipException( OUString::createFromAscii( "Encrypted stream without encryption data!\n" ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); // if we have a digest, then this file is an encrypted one and we should // check if we can decrypt it or not - OSL_ENSURE( rData->aDigest.getLength(), "Can't detect password correctness without digest!\n" ); - if ( rData->aDigest.getLength() && !hasValidPassword ( rEntry, rData ) ) + OSL_ENSURE( rData->m_aDigest.getLength(), "Can't detect password correctness without digest!\n" ); + if ( rData->m_aDigest.getLength() && !hasValidPassword ( rEntry, rData ) ) throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } else @@ -580,8 +607,8 @@ Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry, bIsEncrypted ); } -Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, +uno::Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry, + const ::rtl::Reference< EncryptionData >& rData, sal_Bool bIsEncrypted, SotMutexHolderRef aMutexHolder ) throw(IOException, ZipException, RuntimeException) @@ -594,9 +621,9 @@ Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry, return createUnbufferedStream ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_RAW, bIsEncrypted ); } -Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream( +uno::Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference< EncryptionData >& rData, const ::rtl::OUString& aMediaType, SotMutexHolderRef aMutexHolder ) throw ( packages::NoEncryptionException, @@ -606,7 +633,7 @@ Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream( { ::osl::MutexGuard aGuard( m_aMutex ); - if ( rData.isEmpty() ) + if ( !rData.is() ) throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); if ( rEntry.nOffset <= 0 ) @@ -628,7 +655,7 @@ sal_Bool ZipFile::readLOC( ZipEntry &rEntry ) aGrabber >> nTestSig; if (nTestSig != LOCSIG) - throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid LOC header (bad signature") ), Reference < XInterface > () ); + throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid LOC header (bad signature") ), uno::Reference < XInterface > () ); aGrabber >> nVersion; aGrabber >> nFlag; aGrabber >> nHow; @@ -665,7 +692,7 @@ sal_Bool ZipFile::readLOC( ZipEntry &rEntry ) if ( bBroken && !bRecoveryMode ) throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); return sal_True; } @@ -699,17 +726,17 @@ sal_Int32 ZipFile::findEND( ) } catch ( IllegalArgumentException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } catch ( NotConnectedException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } catch ( BufferSizeExceededException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } sal_Int32 ZipFile::readCEN() @@ -730,25 +757,25 @@ sal_Int32 ZipFile::readCEN() aGrabber >> nCenOff; if ( nTotal * CENHDR > nCenLen ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "invalid END header (bad entry count)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "invalid END header (bad entry count)") ), uno::Reference < XInterface > () ); if ( nTotal > ZIP_MAXENTRIES ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "too many entries in ZIP File") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "too many entries in ZIP File") ), uno::Reference < XInterface > () ); if ( nCenLen < 0 || nCenLen > nEndPos ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), uno::Reference < XInterface > () ); nCenPos = nEndPos - nCenLen; if ( nCenOff < 0 || nCenOff > nCenPos ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), uno::Reference < XInterface > () ); nLocPos = nCenPos - nCenOff; aGrabber.seek( nCenPos ); Sequence < sal_Int8 > aCENBuffer ( nCenLen ); sal_Int64 nRead = aGrabber.readBytes ( aCENBuffer, nCenLen ); if ( static_cast < sal_Int64 > ( nCenLen ) != nRead ) - throw ZipException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Error reading CEN into memory buffer!") ), Reference < XInterface > () ); + throw ZipException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Error reading CEN into memory buffer!") ), uno::Reference < XInterface > () ); MemoryByteGrabber aMemGrabber ( aCENBuffer ); @@ -760,19 +787,19 @@ sal_Int32 ZipFile::readCEN() { aMemGrabber >> nTestSig; if ( nTestSig != CENSIG ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad signature)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad signature)") ), uno::Reference < XInterface > () ); aMemGrabber.skipBytes ( 2 ); aMemGrabber >> aEntry.nVersion; if ( ( aEntry.nVersion & 1 ) == 1 ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (encrypted entry)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (encrypted entry)") ), uno::Reference < XInterface > () ); aMemGrabber >> aEntry.nFlag; aMemGrabber >> aEntry.nMethod; if ( aEntry.nMethod != STORED && aEntry.nMethod != DEFLATED) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad compression method)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad compression method)") ), uno::Reference < XInterface > () ); aMemGrabber >> aEntry.nTime; aMemGrabber >> aEntry.nCrc; @@ -788,13 +815,13 @@ sal_Int32 ZipFile::readCEN() aEntry.nOffset *= -1; if ( aEntry.nPathLen < 0 ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected name length" ) ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected name length" ) ), uno::Reference < XInterface > () ); if ( nCommentLen < 0 ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected comment length" ) ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected comment length" ) ), uno::Reference < XInterface > () ); if ( aEntry.nExtraLen < 0 ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected extra header info length") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected extra header info length") ), uno::Reference < XInterface > () ); // read always in UTF8, some tools seem not to set UTF8 bit aEntry.sPath = rtl::OUString::intern ( (sal_Char *) aMemGrabber.getCurrentPos(), @@ -802,14 +829,14 @@ sal_Int32 ZipFile::readCEN() RTL_TEXTENCODING_UTF8 ); if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aEntry.sPath, sal_True ) ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip entry has an invalid name.") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip entry has an invalid name.") ), uno::Reference < XInterface > () ); aMemGrabber.skipBytes( aEntry.nPathLen + aEntry.nExtraLen + nCommentLen ); aEntries[aEntry.sPath] = aEntry; } if (nCount != nTotal) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Count != Total") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Count != Total") ), uno::Reference < XInterface > () ); } catch ( IllegalArgumentException & ) { @@ -982,15 +1009,15 @@ sal_Int32 ZipFile::recover() } catch ( IllegalArgumentException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } catch ( NotConnectedException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } catch ( BufferSizeExceededException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } } diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx index 16457ec12493..338feb556378 100644 --- a/package/source/zipapi/ZipOutputStream.cxx +++ b/package/source/zipapi/ZipOutputStream.cxx @@ -27,19 +27,22 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_package.hxx" -#include <ZipOutputStream.hxx> + #include <com/sun/star/packages/zip/ZipConstants.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <comphelper/storagehelper.hxx> + #include <osl/time.h> + #include <EncryptionData.hxx> #include <PackageConstants.hxx> #include <ZipEntry.hxx> #include <ZipFile.hxx> -#include <vos/ref.hxx> -#include <com/sun/star/io/XOutputStream.hpp> - -#include <comphelper/storagehelper.hxx> +#include <ZipPackageStream.hxx> +#include <ZipOutputStream.hxx> using namespace rtl; +using namespace com::sun::star; using namespace com::sun::star::io; using namespace com::sun::star::uno; using namespace com::sun::star::packages; @@ -48,17 +51,18 @@ using namespace com::sun::star::packages::zip::ZipConstants; /** This class is used to write Zip files */ -ZipOutputStream::ZipOutputStream( Reference < XOutputStream > &xOStream ) -: xStream(xOStream) -, aBuffer(n_ConstBufferSize) +ZipOutputStream::ZipOutputStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory, + const uno::Reference < XOutputStream > &xOStream ) +: m_xFactory( xFactory ) +, xStream(xOStream) +, m_aDeflateBuffer(n_ConstBufferSize) , aDeflater(DEFAULT_COMPRESSION, sal_True) , aChucker(xOStream) , pCurrentEntry(NULL) , nMethod(DEFLATED) , bFinished(sal_False) , bEncryptCurrentEntry(sal_False) - - +, m_pCurrentStream(NULL) { } @@ -80,7 +84,7 @@ void SAL_CALL ZipOutputStream::setLevel( sal_Int32 nNewLevel ) } void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry, - vos::ORef < EncryptionData > &xEncryptData, + ZipPackageStream* pStream, sal_Bool bEncrypt) throw(IOException, RuntimeException) { @@ -94,18 +98,20 @@ void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry, rEntry.nFlag = 1 << 11; if (rEntry.nSize == -1 || rEntry.nCompressedSize == -1 || rEntry.nCrc == -1) + { + rEntry.nSize = rEntry.nCompressedSize = 0; rEntry.nFlag |= 8; + } if (bEncrypt) { bEncryptCurrentEntry = sal_True; - ZipFile::StaticGetCipher( xEncryptData, aCipher, sal_False ); - - aDigest = rtl_digest_createSHA1(); + m_xCipherContext = ZipFile::StaticGetCipher( m_xFactory, pStream->GetEncryptionData(), true ); + m_xDigestContext = ZipFile::StaticGetDigestContextForChecksum( m_xFactory, pStream->GetEncryptionData() ); mnDigested = 0; rEntry.nFlag |= 1 << 4; - pCurrentEncryptData = xEncryptData.getBodyPtr(); + m_pCurrentStream = pStream; } sal_Int32 nLOCLength = writeLOC(rEntry); rEntry.nOffset = static_cast < sal_Int32 > (aChucker.GetPosition()) - nLOCLength; @@ -145,11 +151,12 @@ void SAL_CALL ZipOutputStream::closeEntry( ) } else { - pEntry->nSize = aDeflater.getTotalIn(); - pEntry->nCompressedSize = aDeflater.getTotalOut(); + if ( !bEncryptCurrentEntry ) + { + pEntry->nSize = aDeflater.getTotalIn(); + pEntry->nCompressedSize = aDeflater.getTotalOut(); + } pEntry->nCrc = aCRC.getValue(); - if ( bEncryptCurrentEntry ) - pEntry->nSize = pEntry->nCompressedSize; writeEXT(*pEntry); } aDeflater.reset(); @@ -166,18 +173,22 @@ void SAL_CALL ZipOutputStream::closeEntry( ) if (bEncryptCurrentEntry) { - rtlDigestError aDigestResult; - aEncryptionBuffer.realloc ( 0 ); bEncryptCurrentEntry = sal_False; - rtl_cipher_destroy ( aCipher ); - pCurrentEncryptData->aDigest.realloc ( RTL_DIGEST_LENGTH_SHA1 ); - aDigestResult = rtl_digest_getSHA1 ( aDigest, - reinterpret_cast < sal_uInt8 * > ( pCurrentEncryptData->aDigest.getArray() ), - RTL_DIGEST_LENGTH_SHA1 ); - OSL_ASSERT( aDigestResult == rtl_Digest_E_None ); - rtl_digest_destroySHA1 ( aDigest ); + + m_xCipherContext.clear(); + + uno::Sequence< sal_Int8 > aDigestSeq; + if ( m_xDigestContext.is() ) + { + aDigestSeq = m_xDigestContext->finalizeDigestAndDispose(); + m_xDigestContext.clear(); + } + + if ( m_pCurrentStream ) + m_pCurrentStream->setDigest( aDigestSeq ); } pCurrentEntry = NULL; + m_pCurrentStream = NULL; } } @@ -242,41 +253,53 @@ void SAL_CALL ZipOutputStream::finish( ) void ZipOutputStream::doDeflate() { - sal_Int32 nLength = aDeflater.doDeflateSegment(aBuffer, 0, aBuffer.getLength()); - sal_Int32 nOldLength = aBuffer.getLength(); + sal_Int32 nLength = aDeflater.doDeflateSegment(m_aDeflateBuffer, 0, m_aDeflateBuffer.getLength()); if ( nLength > 0 ) { - Sequence < sal_Int8 > aTmpBuffer ( aBuffer.getConstArray(), nLength ); - const void *pTmpBuffer = static_cast < const void * > ( aTmpBuffer.getConstArray() ); - if (bEncryptCurrentEntry) + uno::Sequence< sal_Int8 > aTmpBuffer( m_aDeflateBuffer.getConstArray(), nLength ); + if ( bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() ) { // Need to update our digest before encryption... - rtlDigestError aDigestResult = rtl_Digest_E_None; - sal_Int16 nDiff = n_ConstDigestLength - mnDigested; + sal_Int32 nDiff = n_ConstDigestLength - mnDigested; if ( nDiff ) { - sal_Int16 nEat = static_cast < sal_Int16 > ( nDiff > nLength ? nLength : nDiff ); - aDigestResult = rtl_digest_updateSHA1 ( aDigest, pTmpBuffer, nEat ); - mnDigested = mnDigested + nEat; + sal_Int32 nEat = ::std::min( nLength, nDiff ); + uno::Sequence< sal_Int8 > aTmpSeq( aTmpBuffer.getConstArray(), nEat ); + m_xDigestContext->updateDigest( aTmpSeq ); + mnDigested = mnDigested + static_cast< sal_Int16 >( nEat ); } - OSL_ASSERT( aDigestResult == rtl_Digest_E_None ); - - aEncryptionBuffer.realloc ( nLength ); - rtlCipherError aCipherResult; - aCipherResult = rtl_cipher_encode ( aCipher, pTmpBuffer, - nLength, reinterpret_cast < sal_uInt8 * > (aEncryptionBuffer.getArray()), nLength ); - OSL_ASSERT( aCipherResult == rtl_Cipher_E_None ); + uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->convertWithCipherContext( aTmpBuffer ); aChucker.WriteBytes( aEncryptionBuffer ); - aCRC.update ( aEncryptionBuffer ); - aEncryptionBuffer.realloc ( nOldLength ); + + // the sizes as well as checksum for encrypted streams is calculated here + pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); + pCurrentEntry->nSize = pCurrentEntry->nCompressedSize; + aCRC.update( aEncryptionBuffer ); } else + { aChucker.WriteBytes ( aTmpBuffer ); + } + } + + if ( aDeflater.finished() && bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() ) + { + uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->finalizeCipherContextAndDispose(); + if ( aEncryptionBuffer.getLength() ) + { + aChucker.WriteBytes( aEncryptionBuffer ); + + // the sizes as well as checksum for encrypted streams is calculated hier + pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); + pCurrentEntry->nSize = pCurrentEntry->nCompressedSize; + aCRC.update( aEncryptionBuffer ); + } } } + void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) throw(IOException, RuntimeException) { @@ -293,7 +316,7 @@ void ZipOutputStream::writeCEN( const ZipEntry &rEntry ) throw(IOException, RuntimeException) { if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) ) - throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference< XInterface >() ); + throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() ); ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 ); sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); @@ -342,7 +365,7 @@ sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry ) throw(IOException, RuntimeException) { if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) ) - throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference< XInterface >() ); + throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() ); ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 ); sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); diff --git a/package/source/zipapi/blowfishcontext.cxx b/package/source/zipapi/blowfishcontext.cxx new file mode 100644 index 000000000000..1739bb15cde8 --- /dev/null +++ b/package/source/zipapi/blowfishcontext.cxx @@ -0,0 +1,122 @@ +/************************************************************************* + * + * 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_package.hxx" + +#include <rtl/cipher.h> +#include <rtl/ref.hxx> + +#include "blowfishcontext.hxx" + +using namespace ::com::sun::star; + +// static +uno::Reference< xml::crypto::XCipherContext > BlowfishCFB8CipherContext::Create( const uno::Sequence< sal_Int8 >& aDerivedKey, const uno::Sequence< sal_Int8 >& aInitVector, bool bEncrypt ) +{ + ::rtl::Reference< BlowfishCFB8CipherContext > xResult = new BlowfishCFB8CipherContext(); + xResult->m_pCipher = rtl_cipher_create( rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream ); + if ( !xResult->m_pCipher ) + throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not create cipher!\n" ), + uno::Reference< XInterface >() ); + + if ( rtl_Cipher_E_None != rtl_cipher_init( + xResult->m_pCipher, + bEncrypt ? rtl_Cipher_DirectionEncode : rtl_Cipher_DirectionDecode, + reinterpret_cast< const sal_uInt8* >( aDerivedKey.getConstArray() ), + aDerivedKey.getLength(), + reinterpret_cast< const sal_uInt8* >( aInitVector.getConstArray() ), + aInitVector.getLength() ) ) + { + throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not initialize cipher!\n" ), + uno::Reference< XInterface >() ); + } + + xResult->m_bEncrypt = bEncrypt; + + return uno::Reference< xml::crypto::XCipherContext >( xResult.get() ); +} + +BlowfishCFB8CipherContext::~BlowfishCFB8CipherContext() +{ + if ( m_pCipher ) + { + rtl_cipher_destroy ( m_pCipher ); + m_pCipher = NULL; + } +} + +uno::Sequence< sal_Int8 > SAL_CALL BlowfishCFB8CipherContext::convertWithCipherContext( const uno::Sequence< ::sal_Int8 >& aData ) + throw( lang::IllegalArgumentException, lang::DisposedException, uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_pCipher ) + throw lang::DisposedException(); + + uno::Sequence< sal_Int8 > aResult( aData.getLength() ); + rtlCipherError nError = rtl_Cipher_E_None; + + if ( m_bEncrypt ) + { + rtl_cipher_encode( m_pCipher, + aData.getConstArray(), + aData.getLength(), + reinterpret_cast< sal_uInt8* >( aResult.getArray() ), + aResult.getLength() ); + } + else + { + rtl_cipher_decode( m_pCipher, + aData.getConstArray(), + aData.getLength(), + reinterpret_cast< sal_uInt8* >( aResult.getArray() ), + aResult.getLength() ); + } + + if ( rtl_Cipher_E_None != nError ) + { + throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not decrypt/encrypt with cipher!\n" ), + uno::Reference< uno::XInterface >() ); + } + + return aResult; +} + +uno::Sequence< ::sal_Int8 > SAL_CALL BlowfishCFB8CipherContext::finalizeCipherContextAndDispose() + throw( lang::DisposedException, uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_pCipher ) + throw lang::DisposedException(); + + rtl_cipher_destroy ( m_pCipher ); + m_pCipher = NULL; + + return uno::Sequence< sal_Int8 >(); +} + + diff --git a/package/source/zipapi/blowfishcontext.hxx b/package/source/zipapi/blowfishcontext.hxx new file mode 100644 index 000000000000..49cce2fc0e65 --- /dev/null +++ b/package/source/zipapi/blowfishcontext.hxx @@ -0,0 +1,58 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#ifndef _BLOWFISHCONTEXT_HXX +#define _BLOWFISHCONTEXT_HXX + +#include <com/sun/star/xml/crypto/XCipherContext.hpp> + +#include <cppuhelper/implbase1.hxx> +#include <osl/mutex.hxx> + +class BlowfishCFB8CipherContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XCipherContext > +{ + ::osl::Mutex m_aMutex; + void* m_pCipher; + bool m_bEncrypt; + + BlowfishCFB8CipherContext() + : m_pCipher( NULL ) + , m_bEncrypt( false ) + {} + +public: + + virtual ~BlowfishCFB8CipherContext(); + + static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > + Create( const ::com::sun::star::uno::Sequence< sal_Int8 >& aDerivedKey, const ::com::sun::star::uno::Sequence< sal_Int8 >& aInitVector, bool bEncrypt ); + + virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL convertWithCipherContext( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeCipherContextAndDispose( ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); +}; + +#endif // _BLOWFISHCONTEXT_HXX + diff --git a/package/source/zipapi/makefile.mk b/package/source/zipapi/makefile.mk index a9548ace659b..79dbb0289a1c 100644 --- a/package/source/zipapi/makefile.mk +++ b/package/source/zipapi/makefile.mk @@ -45,8 +45,10 @@ SLOFILES= \ $(SLO)$/CRC32.obj \ $(SLO)$/ByteChucker.obj \ $(SLO)$/ByteGrabber.obj \ + $(SLO)$/blowfishcontext.obj \ $(SLO)$/Inflater.obj \ $(SLO)$/Deflater.obj \ + $(SLO)$/sha1context.obj \ $(SLO)$/ZipEnumeration.obj \ $(SLO)$/ZipFile.obj \ $(SLO)$/ZipOutputStream.obj \ diff --git a/package/source/zipapi/sha1context.cxx b/package/source/zipapi/sha1context.cxx new file mode 100644 index 000000000000..a71f20ad6f36 --- /dev/null +++ b/package/source/zipapi/sha1context.cxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * 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_package.hxx" + +#include <rtl/digest.h> +#include <rtl/ref.hxx> + +#include "sha1context.hxx" + +using namespace ::com::sun::star; + +// static +uno::Reference< xml::crypto::XDigestContext > SHA1DigestContext::Create() +{ + ::rtl::Reference< SHA1DigestContext > xResult = new SHA1DigestContext(); + xResult->m_pDigest = rtl_digest_createSHA1(); + if ( !xResult->m_pDigest ) + throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not create cipher!\n" ), + uno::Reference< XInterface >() ); + + return uno::Reference< xml::crypto::XDigestContext >( xResult.get() ); +} + +SHA1DigestContext::~SHA1DigestContext() +{ + if ( m_pDigest ) + { + rtl_digest_destroySHA1( m_pDigest ); + m_pDigest = NULL; + } +} + +void SAL_CALL SHA1DigestContext::updateDigest( const uno::Sequence< ::sal_Int8 >& aData ) + throw( lang::DisposedException, uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_pDigest ) + throw lang::DisposedException(); + + if ( rtl_Digest_E_None != rtl_digest_updateSHA1( m_pDigest, aData.getConstArray(), aData.getLength() ) ) + { + rtl_digest_destroySHA1( m_pDigest ); + m_pDigest = NULL; + + throw uno::RuntimeException(); + } +} + +uno::Sequence< ::sal_Int8 > SAL_CALL SHA1DigestContext::finalizeDigestAndDispose() + throw( lang::DisposedException, uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_pDigest ) + throw lang::DisposedException(); + + uno::Sequence< sal_Int8 > aResult( RTL_DIGEST_LENGTH_SHA1 ); + if ( rtl_Digest_E_None != rtl_digest_getSHA1( m_pDigest, reinterpret_cast< sal_uInt8* >( aResult.getArray() ), aResult.getLength() ) ) + { + rtl_digest_destroySHA1( m_pDigest ); + m_pDigest = NULL; + + throw uno::RuntimeException(); + } + + rtl_digest_destroySHA1( m_pDigest ); + m_pDigest = NULL; + + return aResult; +} + + diff --git a/package/source/zipapi/sha1context.hxx b/package/source/zipapi/sha1context.hxx new file mode 100644 index 000000000000..dbd1207ca792 --- /dev/null +++ b/package/source/zipapi/sha1context.hxx @@ -0,0 +1,57 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#ifndef _SHA1CONTEXT_HXX +#define _SHA1CONTEXT_HXX + +#include <com/sun/star/xml/crypto/XDigestContext.hpp> + +#include <cppuhelper/implbase1.hxx> +#include <osl/mutex.hxx> + +class SHA1DigestContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XDigestContext > +{ + ::osl::Mutex m_aMutex; + void* m_pDigest; + + SHA1DigestContext() + : m_pDigest( NULL ) + {} + +public: + + virtual ~SHA1DigestContext(); + + static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > + Create(); + + virtual void SAL_CALL updateDigest( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeDigestAndDispose() throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); + +}; + +#endif // _SHA1CONTEXT_HXX + diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index fca0e09f63bd..41d944288d53 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -16,7 +16,7 @@ * 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). + * ( 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 @@ -25,7 +25,7 @@ * ************************************************************************/ -// MARKER(update_precomp.py): autogen include statement, do not remove +// MARKER( update_precomp.py ): autogen include statement, do not remove #include "precompiled_package.hxx" #include <ZipPackage.hxx> #include <ZipPackageSink.hxx> @@ -63,6 +63,8 @@ #include <com/sun/star/embed/UseBackupException.hpp> #include <com/sun/star/embed/StorageFormats.hpp> #include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <cppuhelper/implbase1.hxx> #include <ContentInfo.hxx> #include <cppuhelper/typeprovider.hxx> @@ -83,6 +85,7 @@ #include <comphelper/storagehelper.hxx> #include <comphelper/ofopxmlhelper.hxx> #include <comphelper/documentconstants.hxx> +#include <comphelper/sequenceashashmap.hxx> using namespace rtl; using namespace std; @@ -154,35 +157,37 @@ public: class DummyInputStream : public ::cppu::WeakImplHelper1< XInputStream > { - virtual sal_Int32 SAL_CALL readBytes( Sequence< sal_Int8 >&, sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + virtual sal_Int32 SAL_CALL readBytes( uno::Sequence< sal_Int8 >&, sal_Int32 ) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) { return 0; } - virtual sal_Int32 SAL_CALL readSomeBytes( Sequence< sal_Int8 >&, sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + virtual sal_Int32 SAL_CALL readSomeBytes( uno::Sequence< sal_Int8 >&, sal_Int32 ) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) { return 0; } virtual void SAL_CALL skipBytes( sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) {} virtual sal_Int32 SAL_CALL available() - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) { return 0; } virtual void SAL_CALL closeInput() - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) {} }; //=========================================================================== -ZipPackage::ZipPackage (const uno::Reference < XMultiServiceFactory > &xNewFactory) +ZipPackage::ZipPackage ( const uno::Reference < XMultiServiceFactory > &xNewFactory ) : m_aMutexHolder( new SotMutexHolder ) +, m_nStartKeyGenerationID( xml::crypto::DigestID::SHA1 ) +, m_nChecksumDigestID( xml::crypto::DigestID::SHA1_1K ) +, m_nCommonEncryptionID( xml::crypto::CipherID::BLOWFISH_CFB_8 ) , m_bHasEncryptedEntries ( sal_False ) , m_bHasNonEncryptedEntries ( sal_False ) , m_bInconsistent ( sal_False ) -, m_bUseManifest ( sal_True ) , m_bForceRecovery ( sal_False ) , m_bMediaTypeFallbackUsed ( sal_False ) , m_nFormat( embed::StorageFormats::PACKAGE ) // package is the default format @@ -204,28 +209,19 @@ ZipPackage::~ZipPackage( void ) // So there is no need in explicit m_pRootFolder->releaseUpwardRef() call here any more // since m_pRootFolder has no parent and cleaning of it's children will be done automatically // during m_pRootFolder dieing by refcount. - -#if 0 - // As all folders and streams contain references to their parents, - // we must remove these references so that they will be deleted when - // the hash_map of the root folder is cleared, releasing all subfolders - // and substreams which in turn release theirs, etc. When m_xRootFolder is - // released when this destructor completes, the folder tree should be - // deleted fully (and automagically). - - m_pRootFolder->releaseUpwardRef(); -#endif } +//-------------------------------------------------------- void ZipPackage::parseManifest() { if ( m_nFormat == embed::StorageFormats::PACKAGE ) { sal_Bool bManifestParsed = sal_False; + bool bDifferentStartKeyAlgorithm = false; const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) ); if ( m_xRootFolder->hasByName( sMeta ) ) { - const OUString sManifest (RTL_CONSTASCII_USTRINGPARAM( "manifest.xml") ); + const OUString sManifest ( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ); try { uno::Reference< XUnoTunnel > xTunnel; @@ -236,11 +232,11 @@ void ZipPackage::parseManifest() { aAny = xMetaInfFolder->getByName( sManifest ); aAny >>= xTunnel; - uno::Reference < XActiveDataSink > xSink (xTunnel, UNO_QUERY); - if (xSink.is()) + uno::Reference < XActiveDataSink > xSink ( xTunnel, UNO_QUERY ); + if ( xSink.is() ) { OUString sManifestReader ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) ); - uno::Reference < XManifestReader > xReader (m_xFactory->createInstance( sManifestReader ), UNO_QUERY ); + uno::Reference < XManifestReader > xReader ( m_xFactory->createInstance( sManifestReader ), UNO_QUERY ); if ( xReader.is() ) { const OUString sPropFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); @@ -251,45 +247,57 @@ void ZipPackage::parseManifest() const OUString sPropIterationCount ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); const OUString sPropSize ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); const OUString sPropDigest ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); + const OUString sPropDerivedKeySize ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ); + const OUString sPropDigestAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ); + const OUString sPropEncryptionAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ); + const OUString sPropStartKeyAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ); - Sequence < Sequence < PropertyValue > > aManifestSequence = xReader->readManifestSequence ( xSink->getInputStream() ); + uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence = xReader->readManifestSequence ( xSink->getInputStream() ); sal_Int32 nLength = aManifestSequence.getLength(); - const Sequence < PropertyValue > *pSequence = aManifestSequence.getConstArray(); + const uno::Sequence < PropertyValue > *pSequence = aManifestSequence.getConstArray(); ZipPackageStream *pStream = NULL; ZipPackageFolder *pFolder = NULL; - for (sal_Int32 i = 0; i < nLength ; i++, pSequence++) + for ( sal_Int32 i = 0; i < nLength ; i++, pSequence++ ) { OUString sPath, sMediaType, sVersion; const PropertyValue *pValue = pSequence->getConstArray(); - const Any *pSalt = NULL, *pVector = NULL, *pCount = NULL, *pSize = NULL, *pDigest = NULL; - for (sal_Int32 j = 0, nNum = pSequence->getLength(); j < nNum; j++ ) + const Any *pSalt = NULL, *pVector = NULL, *pCount = NULL, *pSize = NULL, *pDigest = NULL, *pDigestAlg = NULL, *pEncryptionAlg = NULL, *pStartKeyAlg = NULL, *pDerivedKeySize = NULL; + for ( sal_Int32 j = 0, nNum = pSequence->getLength(); j < nNum; j++ ) { - if (pValue[j].Name.equals( sPropFullPath ) ) + if ( pValue[j].Name.equals( sPropFullPath ) ) pValue[j].Value >>= sPath; - else if (pValue[j].Name.equals( sPropVersion ) ) + else if ( pValue[j].Name.equals( sPropVersion ) ) pValue[j].Value >>= sVersion; - else if (pValue[j].Name.equals( sPropMediaType ) ) + else if ( pValue[j].Name.equals( sPropMediaType ) ) pValue[j].Value >>= sMediaType; - else if (pValue[j].Name.equals( sPropSalt ) ) - pSalt = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropInitialisationVector ) ) - pVector = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropIterationCount ) ) - pCount = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropSize ) ) - pSize = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropDigest ) ) - pDigest = &(pValue[j].Value); + else if ( pValue[j].Name.equals( sPropSalt ) ) + pSalt = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropInitialisationVector ) ) + pVector = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropIterationCount ) ) + pCount = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropSize ) ) + pSize = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropDigest ) ) + pDigest = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropDigestAlgorithm ) ) + pDigestAlg = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropEncryptionAlgorithm ) ) + pEncryptionAlg = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropStartKeyAlgorithm ) ) + pStartKeyAlg = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropDerivedKeySize ) ) + pDerivedKeySize = &( pValue[j].Value ); } - if (sPath.getLength() && hasByHierarchicalName ( sPath ) ) + if ( sPath.getLength() && hasByHierarchicalName ( sPath ) ) { aAny = getByHierarchicalName( sPath ); uno::Reference < XUnoTunnel > xUnoTunnel; aAny >>= xUnoTunnel; sal_Int64 nTest=0; - if ((nTest = xUnoTunnel->getSomething(ZipPackageFolder::static_getImplementationId())) != 0) + if ( (nTest = xUnoTunnel->getSomething( ZipPackageFolder::static_getImplementationId() )) != 0 ) { pFolder = reinterpret_cast < ZipPackageFolder* > ( nTest ); pFolder->SetMediaType ( sMediaType ); @@ -297,15 +305,16 @@ void ZipPackage::parseManifest() } else { - pStream = reinterpret_cast < ZipPackageStream* > ( xUnoTunnel->getSomething(ZipPackageStream::static_getImplementationId())); + pStream = reinterpret_cast < ZipPackageStream* > ( xUnoTunnel->getSomething( ZipPackageStream::static_getImplementationId() )); pStream->SetMediaType ( sMediaType ); pStream->SetFromManifest( sal_True ); - if (pSalt && pVector && pCount && pSize) + if ( pSalt && pVector && pCount && pSize && pDigest && pDigestAlg && pEncryptionAlg ) { - Sequence < sal_uInt8 > aSequence; - sal_Int32 nCount = 0, nSize = 0; - pStream->SetToBeEncrypted ( sal_True ); + uno::Sequence < sal_Int8 > aSequence; + sal_Int32 nCount = 0, nSize = 0, nDigestAlg = 0, nEncryptionAlg = 0, nDerivedKeySize = 16, nStartKeyAlg = xml::crypto::DigestID::SHA1; + + pStream->SetToBeEncrypted ( sal_True ); *pSalt >>= aSequence; pStream->setSalt ( aSequence ); @@ -319,18 +328,34 @@ void ZipPackage::parseManifest() *pSize >>= nSize; pStream->setSize ( nSize ); - if ( pDigest ) - { - *pDigest >>= aSequence; - pStream->setDigest ( aSequence ); - } + *pDigest >>= aSequence; + pStream->setDigest ( aSequence ); + + *pDigestAlg >>= nDigestAlg; + pStream->SetImportedChecksumAlgorithm( nDigestAlg ); + + *pEncryptionAlg >>= nEncryptionAlg; + pStream->SetImportedEncryptionAlgorithm( nEncryptionAlg ); + + if ( pDerivedKeySize ) + *pDerivedKeySize >>= nDerivedKeySize; + pStream->SetImportedDerivedKeySize( nDerivedKeySize ); + + if ( pStartKeyAlg ) + *pStartKeyAlg >>= nStartKeyAlg; + pStream->SetImportedStartKeyAlgorithm( nStartKeyAlg ); pStream->SetToBeCompressed ( sal_True ); pStream->SetToBeEncrypted ( sal_True ); pStream->SetIsEncrypted ( sal_True ); if ( !m_bHasEncryptedEntries && pStream->getName().equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) ) ) ) + { m_bHasEncryptedEntries = sal_True; + m_nStartKeyGenerationID = nStartKeyAlg; + m_nChecksumDigestID = nDigestAlg; + m_nCommonEncryptionID = nEncryptionAlg; + } } else m_bHasNonEncryptedEntries = sal_True; @@ -380,7 +405,7 @@ void ZipPackage::parseManifest() nRead = aData.getLength(); if ( nRead ) - aPackageMediatype = ::rtl::OUString( (sal_Char*)aData.getConstArray(), nRead, RTL_TEXTENCODING_ASCII_US ); + aPackageMediatype = ::rtl::OUString( ( sal_Char* )aData.getConstArray(), nRead, RTL_TEXTENCODING_ASCII_US ); } } @@ -409,24 +434,35 @@ void ZipPackage::parseManifest() m_bInconsistent = m_pRootFolder->LookForUnexpectedODF12Streams( ::rtl::OUString() ); - sal_Bool bODF12AndOlder = ( m_pRootFolder->GetVersion().compareTo( ODFVER_012_TEXT ) >= 0 ); - if ( !m_bForceRecovery && bODF12AndOlder && m_bInconsistent ) + sal_Bool bODF12AndNewer = ( m_pRootFolder->GetVersion().compareTo( ODFVER_012_TEXT ) >= 0 ); + if ( !m_bForceRecovery && bODF12AndNewer ) { - // this is an ODF1.2 document that contains streams not referred in the manifest.xml; - // in case of ODF1.2 documents without version in manifest.xml the property IsInconsistent - // should be checked later - throw ZipIOException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "there are streams not referred in manifest.xml\n" ) ), - uno::Reference< uno::XInterface >() ); + if ( m_bInconsistent ) + { + // this is an ODF1.2 document that contains streams not referred in the manifest.xml; + // in case of ODF1.2 documents without version in manifest.xml the property IsInconsistent + // should be checked later + throw ZipIOException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "there are streams not referred in manifest.xml\n" ) ), + uno::Reference< uno::XInterface >() ); + } + else if ( bDifferentStartKeyAlgorithm ) + { + // all the streams should be encrypted with the same StartKey in ODF1.2 + // TODO/LATER: in future the exception should be thrown + OSL_ENSURE( false, "ODF1.2 contains different StartKey Algorithms" ); + // throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "More than one Start Key Generation algorithm is specified!" ) ), uno::Reference< uno::XInterface >() ); + } } // in case it is a correct ODF1.2 document, the version must be set // and the META-INF folder is reserved for package format - if ( bODF12AndOlder ) + if ( bODF12AndNewer ) m_xRootFolder->removeByName( sMeta ); } } +//-------------------------------------------------------- void ZipPackage::parseContentType() { if ( m_nFormat == embed::StorageFormats::OFOPXML ) @@ -463,7 +499,7 @@ void ZipPackage::parseContentType() for ( nInd = 0; nInd < aContentTypeInfo[1].getLength(); nInd++ ) { ::rtl::OUString aPath; - if ( aContentTypeInfo[1][nInd].First.toChar() == (sal_Unicode)'/' ) + if ( aContentTypeInfo[1][nInd].First.toChar() == ( sal_Unicode )'/' ) aPath = aContentTypeInfo[1][nInd].First.copy( 1 ); else aPath = aContentTypeInfo[1][nInd].First; @@ -495,6 +531,7 @@ void ZipPackage::parseContentType() } } +//-------------------------------------------------------- void ZipPackage::getZipFileContents() { auto_ptr < ZipEnumeration > pEnum ( m_pZipFile->entries() ); @@ -504,7 +541,7 @@ void ZipPackage::getZipFileContents() sal_Int32 nOldIndex, nIndex, nStreamIndex; FolderHash::iterator aIter; - while (pEnum->hasMoreElements()) + while ( pEnum->hasMoreElements() ) { nIndex = nOldIndex = 0; pCurrent = m_pRootFolder; @@ -521,18 +558,18 @@ void ZipPackage::getZipFileContents() nStreamIndex = rName.lastIndexOf ( '/' ); if ( nStreamIndex != -1 ) { - sDirName = rName.copy ( 0, nStreamIndex); + sDirName = rName.copy ( 0, nStreamIndex ); aIter = m_aRecent.find ( sDirName ); if ( aIter != m_aRecent.end() ) - pCurrent = (*aIter).second; + pCurrent = ( *aIter ).second; } if ( pCurrent == m_pRootFolder ) { - while ( (nIndex = rName.indexOf('/', nOldIndex) ) != -1 ) + while ( ( nIndex = rName.indexOf( '/', nOldIndex ) ) != -1 ) { sTemp = rName.copy ( nOldIndex, nIndex - nOldIndex ); - if (nIndex == nOldIndex) + if ( nIndex == nOldIndex ) break; if ( !pCurrent->hasByName( sTemp ) ) { @@ -542,7 +579,7 @@ void ZipPackage::getZipFileContents() pCurrent = pPkgFolder; } else - pCurrent = pCurrent->doGetByName(sTemp).pFolder; + pCurrent = pCurrent->doGetByName( sTemp ).pFolder; nOldIndex = nIndex+1; } if ( nStreamIndex != -1 && sDirName.getLength() ) @@ -551,7 +588,7 @@ void ZipPackage::getZipFileContents() if ( rName.getLength() -1 != nStreamIndex ) { nStreamIndex++; - sTemp = rName.copy( nStreamIndex, rName.getLength() - nStreamIndex); + sTemp = rName.copy( nStreamIndex, rName.getLength() - nStreamIndex ); pPkgStream = new ZipPackageStream( *this, m_xFactory, m_bAllowRemoveOnInsert ); pPkgStream->SetPackageMember( sal_True ); pPkgStream->setZipEntryOnLoading( rEntry ); @@ -566,9 +603,9 @@ void ZipPackage::getZipFileContents() parseContentType(); } -// XInitialization -void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) - throw(Exception, RuntimeException) +//-------------------------------------------------------- +void SAL_CALL ZipPackage::initialize( const uno::Sequence< Any >& aArguments ) + throw( Exception, RuntimeException ) { RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "{ ZipPackage::initialize" ); sal_Bool bBadZipFile = sal_False, bHaveZipFile = sal_True; @@ -580,7 +617,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) for( int ind = 0; ind < aArguments.getLength(); ind++ ) { OUString aParamUrl; - if ( (aArguments[ind] >>= aParamUrl)) + if ( ( aArguments[ind] >>= aParamUrl )) { m_eMode = e_IMode_URL; try @@ -627,13 +664,13 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) if( !bHasSizeProperty || ( bHasSizeProperty && aSize ) ) { uno::Reference < XActiveDataSink > xSink = new ZipPackageSink; - if (aContent.openStream ( xSink ) ) + if ( aContent.openStream ( xSink ) ) m_xContentStream = xSink->getInputStream(); } else bHaveZipFile = sal_False; } - catch (com::sun::star::uno::Exception&) + catch ( com::sun::star::uno::Exception& ) { // Exception derived from uno::Exception thrown. This probably // means the file doesn't exist...we'll create it at @@ -641,13 +678,13 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) bHaveZipFile = sal_False; } } - else if ( (aArguments[ind] >>= m_xStream ) ) + else if ( ( aArguments[ind] >>= m_xStream ) ) { // a writable stream can implement both XStream & XInputStream m_eMode = e_IMode_XStream; m_xContentStream = m_xStream->getInputStream(); } - else if ( (aArguments[ind] >>= m_xContentStream) ) + else if ( ( aArguments[ind] >>= m_xContentStream ) ) { m_eMode = e_IMode_XInputStream; } @@ -715,7 +752,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) try { - if (m_xContentStream.is()) + if ( m_xContentStream.is() ) { // the stream must be seekable, if it is not it will be wrapped m_xContentStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( m_xContentStream, m_xFactory ); @@ -730,7 +767,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) else bHaveZipFile = sal_False; } - catch (com::sun::star::uno::Exception&) + catch ( com::sun::star::uno::Exception& ) { // Exception derived from uno::Exception thrown. This probably // means the file doesn't exist...we'll create it at @@ -773,22 +810,23 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::initialize" ); } +//-------------------------------------------------------- Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) - throw(NoSuchElementException, RuntimeException) + throw( NoSuchElementException, RuntimeException ) { OUString sTemp, sDirName; sal_Int32 nOldIndex, nIndex, nStreamIndex; FolderHash::iterator aIter; - if ( (nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) - return makeAny ( uno::Reference < XUnoTunnel > (m_pRootFolder) ); + if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) + return makeAny ( uno::Reference < XUnoTunnel > ( m_pRootFolder ) ); else { nStreamIndex = aName.lastIndexOf ( '/' ); bool bFolder = nStreamIndex == nIndex-1; if ( nStreamIndex != -1 ) { - sDirName = aName.copy ( 0, nStreamIndex); + sDirName = aName.copy ( 0, nStreamIndex ); aIter = m_aRecent.find ( sDirName ); if ( aIter != m_aRecent.end() ) { @@ -796,16 +834,16 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) { sal_Int32 nDirIndex = aName.lastIndexOf ( '/', nStreamIndex ); sTemp = aName.copy ( nDirIndex == -1 ? 0 : nDirIndex+1, nStreamIndex-nDirIndex-1 ); - if ( sTemp == (*aIter).second->getName() ) - return makeAny ( uno::Reference < XUnoTunnel > ( (*aIter).second ) ); + if ( sTemp == ( *aIter ).second->getName() ) + return makeAny ( uno::Reference < XUnoTunnel > ( ( *aIter ).second ) ); else m_aRecent.erase ( aIter ); } else { sTemp = aName.copy ( nStreamIndex + 1 ); - if ( (*aIter).second->hasByName( sTemp ) ) - return (*aIter).second->getByName( sTemp ); + if ( ( *aIter ).second->hasByName( sTemp ) ) + return ( *aIter ).second->getByName( sTemp ); else m_aRecent.erase( aIter ); } @@ -819,15 +857,15 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) nOldIndex = 0; ZipPackageFolder * pCurrent = m_pRootFolder; ZipPackageFolder * pPrevious = NULL; - while ( ( nIndex = aName.indexOf('/', nOldIndex)) != -1) + while ( ( nIndex = aName.indexOf( '/', nOldIndex )) != -1 ) { - sTemp = aName.copy (nOldIndex, nIndex - nOldIndex); + sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex ); if ( nIndex == nOldIndex ) break; if ( pCurrent->hasByName( sTemp ) ) { pPrevious = pCurrent; - pCurrent = pCurrent->doGetByName(sTemp).pFolder; + pCurrent = pCurrent->doGetByName( sTemp ).pFolder; } else throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -835,16 +873,16 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) } if ( bFolder ) { - if (nStreamIndex != -1 ) + if ( nStreamIndex != -1 ) m_aRecent[sDirName] = pPrevious; return makeAny ( uno::Reference < XUnoTunnel > ( pCurrent ) ); } else { - sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex); + sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex ); if ( pCurrent->hasByName ( sTemp ) ) { - if (nStreamIndex != -1 ) + if ( nStreamIndex != -1 ) m_aRecent[sDirName] = pCurrent; return pCurrent->getByName( sTemp ); } @@ -854,14 +892,15 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) } } +//-------------------------------------------------------- sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) - throw(RuntimeException) + throw( RuntimeException ) { OUString sTemp, sDirName; sal_Int32 nOldIndex, nIndex, nStreamIndex; FolderHash::iterator aIter; - if ( (nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) + if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) return sal_True; else { @@ -869,7 +908,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) bool bFolder = nStreamIndex == nIndex-1; if ( nStreamIndex != -1 ) { - sDirName = aName.copy ( 0, nStreamIndex); + sDirName = aName.copy ( 0, nStreamIndex ); aIter = m_aRecent.find ( sDirName ); if ( aIter != m_aRecent.end() ) { @@ -877,7 +916,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) { sal_Int32 nDirIndex = aName.lastIndexOf ( '/', nStreamIndex ); sTemp = aName.copy ( nDirIndex == -1 ? 0 : nDirIndex+1, nStreamIndex-nDirIndex-1 ); - if ( sTemp == (*aIter).second->getName() ) + if ( sTemp == ( *aIter ).second->getName() ) return sal_True; else m_aRecent.erase ( aIter ); @@ -885,7 +924,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) else { sTemp = aName.copy ( nStreamIndex + 1 ); - if ( (*aIter).second->hasByName( sTemp ) ) + if ( ( *aIter ).second->hasByName( sTemp ) ) return sal_True; else m_aRecent.erase( aIter ); @@ -900,9 +939,9 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) ZipPackageFolder * pCurrent = m_pRootFolder; ZipPackageFolder * pPrevious = NULL; nOldIndex = 0; - while ( ( nIndex = aName.indexOf('/', nOldIndex)) != -1) + while ( ( nIndex = aName.indexOf( '/', nOldIndex )) != -1 ) { - sTemp = aName.copy (nOldIndex, nIndex - nOldIndex); + sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex ); if ( nIndex == nOldIndex ) break; if ( pCurrent->hasByName( sTemp ) ) @@ -921,7 +960,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) } else { - sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex); + sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex ); if ( pCurrent->hasByName( sTemp ) ) { @@ -933,21 +972,22 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) } } -// XSingleServiceFactory -uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance( ) - throw(Exception, RuntimeException) +//-------------------------------------------------------- +uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance() + throw( Exception, RuntimeException ) { - uno::Reference < XInterface > xRef = *(new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert )); + uno::Reference < XInterface > xRef = *( new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert ) ); return xRef; } -uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const Sequence< Any >& aArguments ) - throw(Exception, RuntimeException) +//-------------------------------------------------------- +uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const uno::Sequence< Any >& aArguments ) + throw( Exception, RuntimeException ) { sal_Bool bArg = sal_False; uno::Reference < XInterface > xRef; if ( aArguments.getLength() ) aArguments[0] >>= bArg; - if (bArg) + if ( bArg ) xRef = *new ZipPackageFolder ( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert ); else xRef = *new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert ); @@ -955,16 +995,17 @@ uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( c return xRef; } +//-------------------------------------------------------- void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) { const OUString sMime ( RTL_CONSTASCII_USTRINGPARAM ( "mimetype" ) ); - if (m_xRootFolder->hasByName( sMime ) ) + if ( m_xRootFolder->hasByName( sMime ) ) m_xRootFolder->removeByName( sMime ); ZipEntry * pEntry = new ZipEntry; - sal_Int32 nBufferLength = m_pRootFolder->GetMediaType( ).getLength(); + sal_Int32 nBufferLength = m_pRootFolder->GetMediaType().getLength(); OString sMediaType = OUStringToOString( m_pRootFolder->GetMediaType(), RTL_TEXTENCODING_ASCII_US ); - Sequence< sal_Int8 > aType( (sal_Int8*)sMediaType.getStr(), + uno::Sequence< sal_Int8 > aType( ( sal_Int8* )sMediaType.getStr(), nBufferLength ); @@ -979,14 +1020,12 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) try { - vos::ORef < EncryptionData > xEmpty; - aZipOut.putNextEntry( *pEntry, xEmpty ); + aZipOut.putNextEntry( *pEntry, NULL ); aZipOut.write( aType, 0, nBufferLength ); aZipOut.closeEntry(); } catch ( ::com::sun::star::io::IOException & r ) { - VOS_ENSURE( 0, "Error adding mimetype to the ZipOutputStream" ); throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Error adding mimetype to the ZipOutputStream!" ) ), static_cast < OWeakObject * > ( this ), @@ -994,7 +1033,8 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) } } -void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< Sequence < PropertyValue > >& aManList ) +//-------------------------------------------------------- +void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList ) { // Write the manifest uno::Reference < XOutputStream > xManOutStream; @@ -1004,28 +1044,29 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< Sequence { ZipEntry * pEntry = new ZipEntry; ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize ); - xManOutStream = uno::Reference < XOutputStream > (*pBuffer, UNO_QUERY); + xManOutStream = uno::Reference < XOutputStream > ( *pBuffer, UNO_QUERY ); - pEntry->sPath = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml") ); + pEntry->sPath = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) ); pEntry->nMethod = DEFLATED; pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1; pEntry->nTime = ZipOutputStream::getCurrentDosTime(); - // Convert vector into a Sequence - Sequence < Sequence < PropertyValue > > aManifestSequence ( aManList.size() ); - Sequence < PropertyValue > * pSequence = aManifestSequence.getArray(); - for (vector < Sequence < PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end(); + // Convert vector into a uno::Sequence + uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence ( aManList.size() ); + sal_Int32 nInd = 0; + for ( vector < uno::Sequence < PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end(); aIter != aEnd; - aIter++, pSequence++) - *pSequence= (*aIter); + aIter++, nInd++ ) + { + aManifestSequence[nInd] = ( *aIter ); + } xWriter->writeManifestSequence ( xManOutStream, aManifestSequence ); sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() ); pBuffer->realloc( nBufferLength ); // the manifest.xml is never encrypted - so pass an empty reference - vos::ORef < EncryptionData > xEmpty; - aZipOut.putNextEntry( *pEntry, xEmpty ); + aZipOut.putNextEntry( *pEntry, NULL ); aZipOut.write( pBuffer->getSequence(), 0, nBufferLength ); aZipOut.closeEntry(); } @@ -1040,7 +1081,8 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< Sequence } } -void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequence < PropertyValue > >& aManList ) +//-------------------------------------------------------- +void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList ) { const OUString sFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); @@ -1049,12 +1091,12 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize ); uno::Reference< io::XOutputStream > xConTypeOutStream( *pBuffer, UNO_QUERY ); - pEntry->sPath = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml") ); + pEntry->sPath = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) ); pEntry->nMethod = DEFLATED; pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1; pEntry->nTime = ZipOutputStream::getCurrentDosTime(); - // Convert vector into a Sequence + // Convert vector into a uno::Sequence // TODO/LATER: use Defaulst entries in future uno::Sequence< beans::StringPair > aDefaultsSequence; uno::Sequence< beans::StringPair > aOverridesSequence( aManList.size() ); @@ -1062,18 +1104,18 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ for ( vector< uno::Sequence< beans::PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end(); aIter != aEnd; - aIter++) + aIter++ ) { ::rtl::OUString aPath; ::rtl::OUString aType; - OSL_ENSURE( (*aIter)[PKG_MNFST_MEDIATYPE].Name.equals( sMediaType ) && (*aIter)[PKG_MNFST_FULLPATH].Name.equals( sFullPath ), + OSL_ENSURE( ( *aIter )[PKG_MNFST_MEDIATYPE].Name.equals( sMediaType ) && ( *aIter )[PKG_MNFST_FULLPATH].Name.equals( sFullPath ), "The mediatype sequence format is wrong!\n" ); - (*aIter)[PKG_MNFST_MEDIATYPE].Value >>= aType; + ( *aIter )[PKG_MNFST_MEDIATYPE].Value >>= aType; if ( aType.getLength() ) { // only nonempty type makes sence here nSeqLength++; - (*aIter)[PKG_MNFST_FULLPATH].Value >>= aPath; + ( *aIter )[PKG_MNFST_FULLPATH].Value >>= aPath; aOverridesSequence[nSeqLength-1].First = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) + aPath; aOverridesSequence[nSeqLength-1].Second = aType; } @@ -1087,12 +1129,12 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ pBuffer->realloc( nBufferLength ); // there is no encryption in this format currently - vos::ORef < EncryptionData > xEmpty; - aZipOut.putNextEntry( *pEntry, xEmpty ); + aZipOut.putNextEntry( *pEntry, NULL ); aZipOut.write( pBuffer->getSequence(), 0, nBufferLength ); aZipOut.closeEntry(); } +//-------------------------------------------------------- void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream ) { m_xContentSeek.set( xInStream, uno::UNO_QUERY_THROW ); @@ -1106,6 +1148,7 @@ void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream m_pZipFile = new ZipFile ( m_xContentStream, m_xFactory, sal_False ); } +//-------------------------------------------------------- uno::Reference< io::XInputStream > ZipPackage::writeTempFile() { // In case the target local file does not exist or empty @@ -1152,9 +1195,9 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() } // Hand it to the ZipOutputStream: - ZipOutputStream aZipOut ( xTempOut ); - aZipOut.setMethod(DEFLATED); - aZipOut.setLevel(DEFAULT_COMPRESSION); + ZipOutputStream aZipOut( m_xFactory, xTempOut ); + aZipOut.setMethod( DEFLATED ); + aZipOut.setLevel( DEFAULT_COMPRESSION ); try { @@ -1167,7 +1210,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() if ( m_xRootFolder->hasByName( sMeta ) ) { - const OUString sManifest (RTL_CONSTASCII_USTRINGPARAM( "manifest.xml") ); + const OUString sManifest ( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ); uno::Reference< XUnoTunnel > xTunnel; Any aAny = m_xRootFolder->getByName( sMeta ); @@ -1192,7 +1235,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() } // Create a vector to store data for the manifest.xml file - vector < Sequence < PropertyValue > > aManList; + vector < uno::Sequence < PropertyValue > > aManList; const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); const OUString sVersion ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); @@ -1200,11 +1243,11 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() if ( m_nFormat == embed::StorageFormats::PACKAGE ) { - Sequence < PropertyValue > aPropSeq ( PKG_SIZE_NOENCR_MNFST ); + uno::Sequence < PropertyValue > aPropSeq( PKG_SIZE_NOENCR_MNFST ); aPropSeq [PKG_MNFST_MEDIATYPE].Name = sMediaType; - aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= m_pRootFolder->GetMediaType( ); + aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= m_pRootFolder->GetMediaType(); aPropSeq [PKG_MNFST_VERSION].Name = sVersion; - aPropSeq [PKG_MNFST_VERSION].Value <<= m_pRootFolder->GetVersion( ); + aPropSeq [PKG_MNFST_VERSION].Value <<= m_pRootFolder->GetVersion(); aPropSeq [PKG_MNFST_FULLPATH].Name = sFullPath; aPropSeq [PKG_MNFST_FULLPATH].Value <<= OUString ( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); @@ -1219,15 +1262,14 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() rtlRandomPool aRandomPool = rtl_random_createPool (); rtl_random_addBytes ( aRandomPool, &aTime, 8 ); - - // call saveContents (it will recursively save sub-directories + // call saveContents ( it will recursively save sub-directories OUString aEmptyString; - m_pRootFolder->saveContents( aEmptyString, aManList, aZipOut, m_aEncryptionKey, aRandomPool ); + m_pRootFolder->saveContents( aEmptyString, aManList, aZipOut, GetEncryptionKey(), aRandomPool ); // Clean up random pool memory rtl_random_destroyPool ( aRandomPool ); - if( m_bUseManifest && m_nFormat == embed::StorageFormats::PACKAGE ) + if( m_nFormat == embed::StorageFormats::PACKAGE ) { WriteManifest( aZipOut, aManList ); } @@ -1296,10 +1338,11 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() return xResult; } +//-------------------------------------------------------- uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput() { // open and truncate the original file - Content aOriginalContent (m_aURL, uno::Reference < XCommandEnvironment >() ); + Content aOriginalContent ( m_aURL, uno::Reference < XCommandEnvironment >() ); uno::Reference< XActiveDataStreamer > xSink = new ActiveDataStreamer; if ( m_eMode == e_IMode_URL ) @@ -1333,7 +1376,7 @@ uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput() aArg.Mode = OpenMode::DOCUMENT; aArg.Priority = 0; // unused aArg.Sink = xSink; - aArg.Properties = Sequence< Property >( 0 ); // unused + aArg.Properties = uno::Sequence< Property >( 0 ); // unused aOriginalContent.executeCommand( OUString::createFromAscii( "open" ), makeAny( aArg ) ); } @@ -1347,9 +1390,9 @@ uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput() return xSink; } -// XChangesBatch +//-------------------------------------------------------- void SAL_CALL ZipPackage::commitChanges() - throw(WrappedTargetException, RuntimeException) + throw( WrappedTargetException, RuntimeException ) { // lock the component for the time of commiting ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); @@ -1412,8 +1455,8 @@ void SAL_CALL ZipPackage::commitChanges() ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutputStream ); xOutputStream->flush(); uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( - xOutputStream, uno::UNO_QUERY); - if (asyncOutputMonitor.is()) { + xOutputStream, uno::UNO_QUERY ); + if ( asyncOutputMonitor.is() ) { asyncOutputMonitor->waitForCompletion(); } } @@ -1499,7 +1542,7 @@ void SAL_CALL ZipPackage::commitChanges() // if the file is still not corrupted, it can become after the next step aContent.executeCommand ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "transfer" ) ), aAny ); } - catch (::com::sun::star::uno::Exception& r) + catch ( ::com::sun::star::uno::Exception& r ) { if ( bCanBeCorrupted ) DisconnectFromTargetAndThrowException_Impl( xTempInStream ); @@ -1519,6 +1562,7 @@ void SAL_CALL ZipPackage::commitChanges() RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::commitChanges" ); } +//-------------------------------------------------------- void ZipPackage::DisconnectFromTargetAndThrowException_Impl( const uno::Reference< io::XInputStream >& xTempStream ) { m_xStream = uno::Reference< io::XStream >( xTempStream, uno::UNO_QUERY ); @@ -1547,15 +1591,47 @@ void ZipPackage::DisconnectFromTargetAndThrowException_Impl( const uno::Referenc makeAny ( aException ) ); } -sal_Bool SAL_CALL ZipPackage::hasPendingChanges( ) - throw(RuntimeException) +//-------------------------------------------------------- +const uno::Sequence< sal_Int8 > ZipPackage::GetEncryptionKey() +{ + uno::Sequence< sal_Int8 > aResult; + + if ( m_aStorageEncryptionKeys.getLength() ) + { + ::rtl::OUString aNameToFind; + if ( m_nStartKeyGenerationID == xml::crypto::DigestID::SHA256 ) + aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA256UTF8; + else if ( m_nStartKeyGenerationID == xml::crypto::DigestID::SHA1 ) + aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA1UTF8; + else + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); + + for ( sal_Int32 nInd = 0; nInd < m_aStorageEncryptionKeys.getLength(); nInd++ ) + if ( m_aStorageEncryptionKeys[nInd].Name.equals( aNameToFind ) ) + m_aStorageEncryptionKeys[nInd].Value >>= aResult; + + // empty keys are not allowed here + // so it is not important whether there is no key, or the key is empty, it is an error + if ( !aResult.getLength() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); + } + else + aResult = m_aEncryptionKey; + + return aResult; +} + +//-------------------------------------------------------- +sal_Bool SAL_CALL ZipPackage::hasPendingChanges() + throw( RuntimeException ) { return sal_False; } -Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges( ) - throw(RuntimeException) +//-------------------------------------------------------- +Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges() + throw( RuntimeException ) { - return Sequence < ElementChange > (); + return uno::Sequence < ElementChange > (); } /** @@ -1565,149 +1641,246 @@ Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges( ) uno::Reference < XInterface >SAL_CALL ZipPackage_createInstance( const uno::Reference< XMultiServiceFactory > & xMgr ) { - return uno::Reference< XInterface >( *new ZipPackage(xMgr) ); + return uno::Reference< XInterface >( *new ZipPackage( xMgr ) ); } +//-------------------------------------------------------- OUString ZipPackage::static_getImplementationName() { return OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.comp.ZipPackage" ) ); } +//-------------------------------------------------------- Sequence< OUString > ZipPackage::static_getSupportedServiceNames() { - Sequence< OUString > aNames(1); + uno::Sequence< OUString > aNames( 1 ); aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.Package" ) ); return aNames; } +//-------------------------------------------------------- sal_Bool SAL_CALL ZipPackage::static_supportsService( OUString const & rServiceName ) { return rServiceName == getSupportedServiceNames()[0]; } +//-------------------------------------------------------- OUString ZipPackage::getImplementationName() - throw (RuntimeException) + throw ( RuntimeException ) { return static_getImplementationName(); } +//-------------------------------------------------------- Sequence< OUString > ZipPackage::getSupportedServiceNames() - throw (RuntimeException) + throw ( RuntimeException ) { return static_getSupportedServiceNames(); } +//-------------------------------------------------------- sal_Bool SAL_CALL ZipPackage::supportsService( OUString const & rServiceName ) - throw (RuntimeException) + throw ( RuntimeException ) { return static_supportsService ( rServiceName ); } +//-------------------------------------------------------- uno::Reference < XSingleServiceFactory > ZipPackage::createServiceFactory( uno::Reference < XMultiServiceFactory > const & rServiceFactory ) { - return cppu::createSingleFactory (rServiceFactory, + return cppu::createSingleFactory ( rServiceFactory, static_getImplementationName(), ZipPackage_createInstance, - static_getSupportedServiceNames()); + static_getSupportedServiceNames() ); } namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } -// XUnoTunnel +//-------------------------------------------------------- Sequence< sal_Int8 > ZipPackage::getUnoTunnelImplementationId( void ) - throw (RuntimeException) + throw ( RuntimeException ) { ::cppu::OImplementationId &rId = lcl_ImplId::get(); return rId.getImplementationId(); } -sal_Int64 SAL_CALL ZipPackage::getSomething( const Sequence< sal_Int8 >& aIdentifier ) - throw(RuntimeException) +//-------------------------------------------------------- +sal_Int64 SAL_CALL ZipPackage::getSomething( const uno::Sequence< sal_Int8 >& aIdentifier ) + throw( RuntimeException ) { - if (aIdentifier.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) + if ( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) return reinterpret_cast < sal_Int64 > ( this ); return 0; } -uno::Reference< XPropertySetInfo > SAL_CALL ZipPackage::getPropertySetInfo( ) - throw(RuntimeException) +//-------------------------------------------------------- +uno::Reference< XPropertySetInfo > SAL_CALL ZipPackage::getPropertySetInfo() + throw( RuntimeException ) { return uno::Reference < XPropertySetInfo > (); } + +//-------------------------------------------------------- void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) - throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException ) { if ( m_nFormat != embed::StorageFormats::PACKAGE ) throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("HasEncryptedEntries") ) - ||aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("HasNonEncryptedEntries") ) - ||aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("IsInconsistent") ) - ||aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MediaTypeFallbackUsed") ) ) + if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) + ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) + ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( IS_INCONSISTENT_PROPERTY ) ) + ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) throw PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("EncryptionKey") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) ) { - if (!( aValue >>= m_aEncryptionKey ) || m_aEncryptionKey.getLength() == 0 ) + if ( !( aValue >>= m_aEncryptionKey ) ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_aStorageEncryptionKeys.realloc( 0 ); } - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseManifest") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) { - if (!( aValue >>= m_bUseManifest ) ) + // this property is only necessary to support raw passwords in storage API; + // because of this support the storage has to operate with more than one key dependent on storage generation algorithm; + // when this support is removed, the storage will get only one key from outside + // TODO/LATER: Get rid of this property as well as of support of raw passwords in storages + uno::Sequence< beans::NamedValue > aKeys; + if ( !( aValue >>= aKeys ) || ( aKeys.getLength() && aKeys.getLength() < 2 ) ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); + + if ( aKeys.getLength() ) + { + bool bHasSHA256 = false; + bool bHasSHA1 = false; + for ( sal_Int32 nInd = 0; nInd < aKeys.getLength(); nInd++ ) + { + if ( aKeys[nInd].Name.equals( PACKAGE_ENCRYPTIONDATA_SHA256UTF8 ) ) + bHasSHA256 = true; + if ( aKeys[nInd].Name.equals( PACKAGE_ENCRYPTIONDATA_SHA1UTF8 ) ) + bHasSHA1 = true; + } + + if ( !bHasSHA256 || !bHasSHA1 ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Expected keys are not provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + } + + m_aStorageEncryptionKeys = aKeys; + m_aEncryptionKey.realloc( 0 ); + } + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) + { + uno::Sequence< beans::NamedValue > aAlgorithms; + if ( m_pZipFile || !( aValue >>= aAlgorithms ) || aAlgorithms.getLength() == 0 ) + { + // the algorithms can not be changed if the file has a persistence based on the algorithms ( m_pZipFile ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected algorithms list is provided." ) ), uno::Reference< uno::XInterface >(), 2 ); + } + + for ( sal_Int32 nInd = 0; nInd < aAlgorithms.getLength(); nInd++ ) + { + if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StartKeyGenerationAlgorithm" ) ) ) + { + sal_Int32 nID = 0; + if ( !( aAlgorithms[nInd].Value >>= nID ) + || ( nID != xml::crypto::DigestID::SHA256 && nID != xml::crypto::DigestID::SHA1 ) ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_nStartKeyGenerationID = nID; + } + else if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "EncryptionAlgorithm" ) ) ) + { + sal_Int32 nID = 0; + if ( !( aAlgorithms[nInd].Value >>= nID ) + || ( nID != xml::crypto::CipherID::AES_CBC_W3C_PADDING && nID != xml::crypto::CipherID::BLOWFISH_CFB_8 ) ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_nCommonEncryptionID = nID; + } + else if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ChecksumAlgorithm" ) ) ) + { + sal_Int32 nID = 0; + if ( !( aAlgorithms[nInd].Value >>= nID ) + || ( nID != xml::crypto::DigestID::SHA1_1K && nID != xml::crypto::DigestID::SHA256_1K ) ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_nChecksumDigestID = nID; + } + else + { + OSL_ENSURE( sal_False, "Unexpected encryption algorithm is provided!" ); + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected algorithms list is provided." ) ), uno::Reference< uno::XInterface >(), 2 ); + } + } } else throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } + +//-------------------------------------------------------- Any SAL_CALL ZipPackage::getPropertyValue( const OUString& PropertyName ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { // TODO/LATER: Activate the check when zip-ucp is ready // if ( m_nFormat != embed::StorageFormats::PACKAGE ) // throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); Any aAny; - if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "EncryptionKey" ) ) ) + if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( ENCRYPTION_KEY_PROPERTY ) ) ) { aAny <<= m_aEncryptionKey; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "HasEncryptedEntries" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) { - aAny <<= m_bHasEncryptedEntries; + ::comphelper::SequenceAsHashMap aAlgorithms; + aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StartKeyGenerationAlgorithm" ) ) ] <<= m_nStartKeyGenerationID; + aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionAlgorithm" ) ) ] <<= m_nCommonEncryptionID; + aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChecksumAlgorithm" ) ) ] <<= m_nChecksumDigestID; + aAny <<= aAlgorithms.getAsConstNamedValueList(); return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "HasNonEncryptedEntries" ) ) ) + if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) { - aAny <<= m_bHasNonEncryptedEntries; + aAny <<= m_aStorageEncryptionKeys; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "IsInconsistent" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) ) { - aAny <<= m_bInconsistent; + aAny <<= m_bHasEncryptedEntries; + return aAny; + } + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) ) + { + aAny <<= m_bHasNonEncryptedEntries; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "UseManifest" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( IS_INCONSISTENT_PROPERTY ) ) ) { - aAny <<= m_bUseManifest; + aAny <<= m_bInconsistent; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "MediaTypeFallbackUsed" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) { aAny <<= m_bMediaTypeFallbackUsed; return aAny; } throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } +//-------------------------------------------------------- void SAL_CALL ZipPackage::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } +//-------------------------------------------------------- void SAL_CALL ZipPackage::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*aListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } +//-------------------------------------------------------- void SAL_CALL ZipPackage::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } +//-------------------------------------------------------- void SAL_CALL ZipPackage::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } diff --git a/package/source/zippackage/ZipPackageEntry.cxx b/package/source/zippackage/ZipPackageEntry.cxx index 7514e7b6f55a..a1f752174dc6 100644 --- a/package/source/zippackage/ZipPackageEntry.cxx +++ b/package/source/zippackage/ZipPackageEntry.cxx @@ -73,18 +73,18 @@ void SAL_CALL ZipPackageEntry::setName( const OUString& aName ) // unfortunately no other exception than RuntimeException can be thrown here // usually the package is used through storage implementation, the problem should be detected there if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_True ) ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected character is used in file name." ) ), Reference< XInterface >() ); + throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() ); msName = aName; if ( pParent ) pParent->doInsertByName ( this, sal_False ); } -Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( ) +uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( ) throw(RuntimeException) { - // return Reference< XInterface >( xParent, UNO_QUERY ); - return Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( pParent ), UNO_QUERY ); + // return uno::Reference< XInterface >( xParent, UNO_QUERY ); + return uno::Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( pParent ), UNO_QUERY ); } void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bInsert ) @@ -95,11 +95,11 @@ void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bIns pNewParent->doInsertByName ( this, sal_False ); } -void SAL_CALL ZipPackageEntry::setParent( const Reference< XInterface >& xNewParent ) +void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent ) throw(NoSupportException, RuntimeException) { sal_Int64 nTest(0); - Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY ); + uno::Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY ); if ( !xNewParent.is() || ( nTest = xTunnel->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 ) throw NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -113,24 +113,24 @@ void SAL_CALL ZipPackageEntry::setParent( const Reference< XInterface >& xNewPar } } //XPropertySet -Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( ) +uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( ) throw(RuntimeException) { - return Reference < beans::XPropertySetInfo > (); + return uno::Reference < beans::XPropertySetInfo > (); } -void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< beans::XPropertyChangeListener >& /*xListener*/ ) +void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } -void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< beans::XPropertyChangeListener >& /*aListener*/ ) +void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } -void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< beans::XVetoableChangeListener >& /*aListener*/ ) +void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } -void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< beans::XVetoableChangeListener >& /*aListener*/ ) +void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index 5bb5b4db89b6..0d78fe42cd34 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -46,23 +46,22 @@ #include <rtl/instance.hxx> #include <memory> +using namespace com::sun::star; using namespace com::sun::star::packages::zip::ZipConstants; using namespace com::sun::star::packages::zip; using namespace com::sun::star::packages; using namespace com::sun::star::container; using namespace com::sun::star::beans; using namespace com::sun::star::lang; -using namespace com::sun::star::uno; using namespace com::sun::star::io; using namespace cppu; -using namespace rtl; using namespace std; using namespace ::com::sun::star; using vos::ORef; -namespace { struct lcl_CachedImplId : public rtl::Static< Sequence < sal_Int8 >, lcl_CachedImplId > {}; } +namespace { struct lcl_CachedImplId : public rtl::Static< uno::Sequence < sal_Int8 >, lcl_CachedImplId > {}; } -ZipPackageFolder::ZipPackageFolder ( const Reference< XMultiServiceFactory >& xFactory, +ZipPackageFolder::ZipPackageFolder ( const uno::Reference< XMultiServiceFactory >& xFactory, sal_Int32 nFormat, sal_Bool bAllowRemoveOnInsert ) : m_xFactory( xFactory ) @@ -81,7 +80,7 @@ ZipPackageFolder::ZipPackageFolder ( const Reference< XMultiServiceFactory >& xF aEntry.nCompressedSize = 0; aEntry.nSize = 0; aEntry.nOffset = -1; - Sequence < sal_Int8 > &rCachedImplId = lcl_CachedImplId::get(); + uno::Sequence < sal_Int8 > &rCachedImplId = lcl_CachedImplId::get(); if ( !rCachedImplId.getLength() ) rCachedImplId = getImplementationId(); } @@ -99,7 +98,7 @@ sal_Bool ZipPackageFolder::LookForUnexpectedODF12Streams( const ::rtl::OUString& !bHasUnexpected && aCI != aEnd; aCI++) { - const OUString &rShortName = (*aCI).first; + const ::rtl::OUString &rShortName = (*aCI).first; const ContentInfo &rInfo = *(*aCI).second; if ( rInfo.bFolder ) @@ -111,7 +110,7 @@ sal_Bool ZipPackageFolder::LookForUnexpectedODF12Streams( const ::rtl::OUString& } else { - OUString sOwnPath = aPath + rShortName + OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); + ::rtl::OUString sOwnPath = aPath + rShortName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); bHasUnexpected = rInfo.pFolder->LookForUnexpectedODF12Streams( sOwnPath ); } } @@ -157,7 +156,7 @@ void ZipPackageFolder::setChildStreamsTypeByExtension( const beans::StringPair& aCI != aEnd; aCI++) { - const OUString &rShortName = (*aCI).first; + const ::rtl::OUString &rShortName = (*aCI).first; const ContentInfo &rInfo = *(*aCI).second; if ( rInfo.bFolder ) @@ -193,14 +192,14 @@ const ::com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageFolder::static_get } // XNameContainer -void SAL_CALL ZipPackageFolder::insertByName( const OUString& aName, const Any& aElement ) - throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) +void SAL_CALL ZipPackageFolder::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(IllegalArgumentException, ElementExistException, WrappedTargetException, uno::RuntimeException) { if (hasByName(aName)) throw ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); else { - Reference < XUnoTunnel > xRef; + uno::Reference < XUnoTunnel > xRef; aElement >>= xRef; if ( ( aElement >>= xRef ) ) { @@ -227,8 +226,8 @@ void SAL_CALL ZipPackageFolder::insertByName( const OUString& aName, const Any& throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); } } -void SAL_CALL ZipPackageFolder::removeByName( const OUString& Name ) - throw(NoSuchElementException, WrappedTargetException, RuntimeException) +void SAL_CALL ZipPackageFolder::removeByName( const ::rtl::OUString& Name ) + throw(NoSuchElementException, WrappedTargetException, uno::RuntimeException) { ContentHash::iterator aIter = maContents.find ( Name ); if ( aIter == maContents.end() ) @@ -236,55 +235,55 @@ void SAL_CALL ZipPackageFolder::removeByName( const OUString& Name ) maContents.erase( aIter ); } // XEnumerationAccess -Reference< XEnumeration > SAL_CALL ZipPackageFolder::createEnumeration( ) - throw(RuntimeException) +uno::Reference< XEnumeration > SAL_CALL ZipPackageFolder::createEnumeration( ) + throw(uno::RuntimeException) { - return Reference < XEnumeration> (new ZipPackageFolderEnumeration(maContents)); + return uno::Reference < XEnumeration> (new ZipPackageFolderEnumeration(maContents)); } // XElementAccess -Type SAL_CALL ZipPackageFolder::getElementType( ) - throw(RuntimeException) +uno::Type SAL_CALL ZipPackageFolder::getElementType( ) + throw(uno::RuntimeException) { - return ::getCppuType ((const Reference< XUnoTunnel > *) 0); + return ::getCppuType ((const uno::Reference< XUnoTunnel > *) 0); } sal_Bool SAL_CALL ZipPackageFolder::hasElements( ) - throw(RuntimeException) + throw(uno::RuntimeException) { return maContents.size() > 0; } // XNameAccess -ContentInfo& ZipPackageFolder::doGetByName( const OUString& aName ) - throw(NoSuchElementException, WrappedTargetException, RuntimeException) +ContentInfo& ZipPackageFolder::doGetByName( const ::rtl::OUString& aName ) + throw(NoSuchElementException, WrappedTargetException, uno::RuntimeException) { ContentHash::iterator aIter = maContents.find ( aName ); if ( aIter == maContents.end()) throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); return *(*aIter).second; } -Any SAL_CALL ZipPackageFolder::getByName( const OUString& aName ) - throw(NoSuchElementException, WrappedTargetException, RuntimeException) +uno::Any SAL_CALL ZipPackageFolder::getByName( const ::rtl::OUString& aName ) + throw(NoSuchElementException, WrappedTargetException, uno::RuntimeException) { - return makeAny ( doGetByName ( aName ).xTunnel ); + return uno::makeAny ( doGetByName ( aName ).xTunnel ); } -Sequence< OUString > SAL_CALL ZipPackageFolder::getElementNames( ) - throw(RuntimeException) +uno::Sequence< ::rtl::OUString > SAL_CALL ZipPackageFolder::getElementNames( ) + throw(uno::RuntimeException) { sal_uInt32 i=0, nSize = maContents.size(); - Sequence < OUString > aSequence ( nSize ); + uno::Sequence < ::rtl::OUString > aSequence ( nSize ); for ( ContentHash::const_iterator aIterator = maContents.begin(), aEnd = maContents.end(); aIterator != aEnd; ++i, ++aIterator) aSequence[i] = (*aIterator).first; return aSequence; } -sal_Bool SAL_CALL ZipPackageFolder::hasByName( const OUString& aName ) - throw(RuntimeException) +sal_Bool SAL_CALL ZipPackageFolder::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) { return maContents.find ( aName ) != maContents.end (); } // XNameReplace -void SAL_CALL ZipPackageFolder::replaceByName( const OUString& aName, const Any& aElement ) - throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException) +void SAL_CALL ZipPackageFolder::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, uno::RuntimeException) { if ( hasByName( aName ) ) removeByName( aName ); @@ -293,7 +292,7 @@ void SAL_CALL ZipPackageFolder::replaceByName( const OUString& aName, const Any& insertByName(aName, aElement); } -static void ImplSetStoredData( ZipEntry & rEntry, Reference < XInputStream> & rStream ) +static void ImplSetStoredData( ZipEntry & rEntry, uno::Reference< XInputStream> & rStream ) { // It's very annoying that we have to do this, but lots of zip packages // don't allow data descriptors for STORED streams, meaning we have to @@ -305,25 +304,29 @@ static void ImplSetStoredData( ZipEntry & rEntry, Reference < XInputStream> & rS rEntry.nCrc = aCRC32.getValue(); } -bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo &rInfo, OUString &rPath, std::vector < Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool &rRandomPool) +bool ZipPackageFolder::saveChild( const ::rtl::OUString &rShortName, const ContentInfo &rInfo, ::rtl::OUString &rPath, std::vector < uno::Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, const uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool &rRandomPool) { bool bSuccess = true; - const OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); - const OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); - const OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); - const OUString sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); - const OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); - const OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); - const OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); - const OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); - - Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST); + const ::rtl::OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); + const ::rtl::OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); + const ::rtl::OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); + const ::rtl::OUString sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); + const ::rtl::OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); + const ::rtl::OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); + const ::rtl::OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); + const ::rtl::OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); + const ::rtl::OUString sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ); + const ::rtl::OUString sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ); + const ::rtl::OUString sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ); + const ::rtl::OUString sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ); + + uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST); OSL_ENSURE( ( rInfo.bFolder && rInfo.pFolder ) || ( !rInfo.bFolder && rInfo.pStream ), "A valid child object is expected!" ); if ( rInfo.bFolder ) { - OUString sTempName = rPath + rShortName + OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); + ::rtl::OUString sTempName = rPath + rShortName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); if ( rInfo.pFolder->GetMediaType().getLength() ) { @@ -378,7 +381,7 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo sal_Int32 nOwnStreamOrigSize = bRawStream ? rInfo.pStream->GetMagicalHackSize() : rInfo.pStream->getSize(); sal_Bool bUseNonSeekableAccess = sal_False; - Reference < XInputStream > xStream; + uno::Reference < XInputStream > xStream; if ( !rInfo.pStream->IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed ) { // the stream is not a package member, not a raw stream, @@ -386,7 +389,7 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo // in this case nonseekable access can be used xStream = rInfo.pStream->GetOwnStreamNoWrap(); - Reference < XSeekable > xSeek ( xStream, UNO_QUERY ); + uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY ); bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() ); } @@ -402,7 +405,7 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo return bSuccess; } - Reference < XSeekable > xSeek ( xStream, UNO_QUERY ); + uno::Reference < XSeekable > xSeek ( xStream, uno::UNO_QUERY ); try { if ( xSeek.is() ) @@ -450,15 +453,13 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo } else { - VOS_ENSURE( 0, "The package component requires that every stream either be FROM a package or it must support XSeekable!" ); bSuccess = false; return bSuccess; } } } - catch ( Exception& ) + catch ( uno::Exception& ) { - VOS_ENSURE( 0, "The stream provided to the package component has problems!" ); bSuccess = false; return bSuccess; } @@ -467,9 +468,9 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo { if ( bToBeEncrypted && !bTransportOwnEncrStreamAsRaw ) { - Sequence < sal_uInt8 > aSalt ( 16 ), aVector ( 8 ); + uno::Sequence < sal_Int8 > aSalt( 16 ), aVector( rInfo.pStream->GetBlockSize() ); rtl_random_getBytes ( rRandomPool, aSalt.getArray(), 16 ); - rtl_random_getBytes ( rRandomPool, aVector.getArray(), 8 ); + rtl_random_getBytes ( rRandomPool, aVector.getArray(), aVector.getLength() ); sal_Int32 nIterationCount = 1024; if ( !rInfo.pStream->HasOwnKey() ) @@ -498,8 +499,20 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo if ( bRawStream || bTransportOwnEncrStreamAsRaw ) { + ::rtl::Reference< EncryptionData > xEncData = rInfo.pStream->GetEncryptionData(); + if ( !xEncData.is() ) + throw uno::RuntimeException(); + aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest(); + aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty; + aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg; + aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty; + aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID; + aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty; + aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg; + aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty; + aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize; } } } @@ -520,7 +533,6 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo if ( !xStream.is() ) { // Make sure that we actually _got_ a new one ! - VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" ); bSuccess = false; return bSuccess; } @@ -531,11 +543,11 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo if ( bRawStream ) xStream->skipBytes( rInfo.pStream->GetMagicalHackPos() ); - rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream->getEncryptionData(), sal_False ); + rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, sal_False ); // the entry is provided to the ZipOutputStream that will delete it pAutoTempEntry.release(); - Sequence < sal_Int8 > aSeq ( n_ConstBufferSize ); + uno::Sequence < sal_Int8 > aSeq ( n_ConstBufferSize ); sal_Int32 nLength; do @@ -549,12 +561,10 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo } catch ( ZipException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bSuccess = false; } catch ( IOException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bSuccess = false; } } @@ -576,7 +586,6 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo if ( !xStream.is() ) { // Make sure that we actually _got_ a new one ! - VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" ); bSuccess = false; return bSuccess; } @@ -590,12 +599,12 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo try { - rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream->getEncryptionData(), bToBeEncrypted); + rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream, bToBeEncrypted); // the entry is provided to the ZipOutputStream that will delete it pAutoTempEntry.release(); sal_Int32 nLength; - Sequence < sal_Int8 > aSeq (n_ConstBufferSize); + uno::Sequence < sal_Int8 > aSeq (n_ConstBufferSize); do { nLength = xStream->readBytes(aSeq, n_ConstBufferSize); @@ -607,19 +616,30 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo } catch ( ZipException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bSuccess = false; } catch ( IOException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bSuccess = false; } if ( bToBeEncrypted ) { + ::rtl::Reference< EncryptionData > xEncData = rInfo.pStream->GetEncryptionData(); + if ( !xEncData.is() ) + throw uno::RuntimeException(); + aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest(); + aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty; + aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg; + aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty; + aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID; + aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty; + aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg; + aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty; + aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize; + rInfo.pStream->SetIsEncrypted ( sal_True ); } } @@ -665,8 +685,8 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo return bSuccess; } -void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool &rRandomPool) - throw(RuntimeException) +void ZipPackageFolder::saveContents( ::rtl::OUString &rPath, std::vector < uno::Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, const uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool &rRandomPool ) + throw( uno::RuntimeException ) { bool bWritingFailed = false; @@ -681,18 +701,15 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr try { - vos::ORef < EncryptionData > aEmptyEncr; - rZipOut.putNextEntry ( *pTempEntry, aEmptyEncr, sal_False ); + rZipOut.putNextEntry( *pTempEntry, NULL, sal_False ); rZipOut.rawCloseEntry(); } catch ( ZipException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bWritingFailed = true; } catch ( IOException& ) { - VOS_ENSURE( 0, "Error writing ZipOutputStream" ); bWritingFailed = true; } } @@ -714,7 +731,7 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr aCI != aEnd; aCI++) { - const OUString &rShortName = (*aCI).first; + const ::rtl::OUString &rShortName = (*aCI).first; const ContentInfo &rInfo = *(*aCI).second; if ( !bMimeTypeStreamStored || !rShortName.equals( aMimeTypeStreamName ) ) @@ -722,7 +739,7 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr } if( bWritingFailed ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } void ZipPackageFolder::releaseUpwardRef( void ) @@ -754,8 +771,8 @@ void ZipPackageFolder::releaseUpwardRef( void ) #endif } -sal_Int64 SAL_CALL ZipPackageFolder::getSomething( const Sequence< sal_Int8 >& aIdentifier ) - throw(RuntimeException) +sal_Int64 SAL_CALL ZipPackageFolder::getSomething( const uno::Sequence< sal_Int8 >& aIdentifier ) + throw(uno::RuntimeException) { sal_Int64 nMe = 0; if ( aIdentifier.getLength() == 16 && @@ -763,8 +780,8 @@ sal_Int64 SAL_CALL ZipPackageFolder::getSomething( const Sequence< sal_Int8 >& a nMe = reinterpret_cast < sal_Int64 > ( this ); return nMe; } -void SAL_CALL ZipPackageFolder::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) - throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) +void SAL_CALL ZipPackageFolder::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, uno::RuntimeException) { if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MediaType"))) { @@ -781,8 +798,8 @@ void SAL_CALL ZipPackageFolder::setPropertyValue( const OUString& aPropertyName, else throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } -Any SAL_CALL ZipPackageFolder::getPropertyValue( const OUString& PropertyName ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) +uno::Any SAL_CALL ZipPackageFolder::getPropertyValue( const ::rtl::OUString& PropertyName ) + throw(UnknownPropertyException, WrappedTargetException, uno::RuntimeException) { if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) { @@ -790,18 +807,18 @@ Any SAL_CALL ZipPackageFolder::getPropertyValue( const OUString& PropertyName ) // if ( m_nFormat != embed::StorageFormats::PACKAGE ) // throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return makeAny ( sMediaType ); + return uno::makeAny ( sMediaType ); } else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Version" ) ) ) - return makeAny( m_sVersion ); + return uno::makeAny( m_sVersion ); else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) ) - return makeAny ( aEntry.nSize ); + return uno::makeAny ( aEntry.nSize ); else throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } void ZipPackageFolder::doInsertByName ( ZipPackageEntry *pEntry, sal_Bool bSetParent ) - throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) + throw(IllegalArgumentException, ElementExistException, WrappedTargetException, uno::RuntimeException) { try { @@ -818,21 +835,21 @@ void ZipPackageFolder::doInsertByName ( ZipPackageEntry *pEntry, sal_Bool bSetPa if ( bSetParent ) pEntry->setParent ( *this ); } -OUString ZipPackageFolder::getImplementationName() - throw (RuntimeException) +::rtl::OUString ZipPackageFolder::getImplementationName() + throw (uno::RuntimeException) { - return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageFolder" ) ); + return ::rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageFolder" ) ); } -Sequence< OUString > ZipPackageFolder::getSupportedServiceNames() - throw (RuntimeException) +uno::Sequence< ::rtl::OUString > ZipPackageFolder::getSupportedServiceNames() + throw (uno::RuntimeException) { - Sequence< OUString > aNames(1); - aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageFolder" ) ); + uno::Sequence< ::rtl::OUString > aNames(1); + aNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageFolder" ) ); return aNames; } -sal_Bool SAL_CALL ZipPackageFolder::supportsService( OUString const & rServiceName ) - throw (RuntimeException) +sal_Bool SAL_CALL ZipPackageFolder::supportsService( ::rtl::OUString const & rServiceName ) + throw (uno::RuntimeException) { return rServiceName == getSupportedServiceNames()[0]; } diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index da44dafa000b..79797b938f60 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -16,7 +16,7 @@ * 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). + * ( 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 @@ -25,7 +25,7 @@ * ************************************************************************/ -// MARKER(update_precomp.py): autogen include statement, do not remove +// MARKER( update_precomp.py ): autogen include statement, do not remove #include "precompiled_package.hxx" #include <com/sun/star/packages/zip/ZipConstants.hpp> #include <com/sun/star/embed/StorageFormats.hpp> @@ -34,6 +34,8 @@ #include <com/sun/star/io/XOutputStream.hpp> #include <com/sun/star/io/XStream.hpp> #include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <ZipPackageStream.hxx> @@ -66,21 +68,25 @@ const ::com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageStream::static_get } ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage, - const Reference< XMultiServiceFactory >& xFactory, + const uno::Reference< XMultiServiceFactory >& xFactory, sal_Bool bAllowRemoveOnInsert ) : m_xFactory( xFactory ) -, rZipPackage(rNewPackage) +, rZipPackage( rNewPackage ) , bToBeCompressed ( sal_True ) , bToBeEncrypted ( sal_False ) , bHaveOwnKey ( sal_False ) , bIsEncrypted ( sal_False ) -, xEncryptionData ( ) +, m_nImportedStartKeyAlgorithm( 0 ) +, m_nImportedEncryptionAlgorithm( 0 ) +, m_nImportedChecksumAlgorithm( 0 ) +, m_nImportedDerivedKeySize( 0 ) , m_nStreamMode( PACKAGE_STREAM_NOTSET ) , m_nMagicalHackPos( 0 ) , m_nMagicalHackSize( 0 ) , m_bHasSeekable( sal_False ) , m_bCompressedIsSetFromOutside( sal_False ) , m_bFromManifest( sal_False ) +, m_bUseWinEncoding( false ) { OSL_ENSURE( m_xFactory.is(), "No factory is provided to ZipPackageStream!\n" ); @@ -107,7 +113,7 @@ ZipPackageStream::~ZipPackageStream( void ) { } -void ZipPackageStream::setZipEntryOnLoading( const ZipEntry &rInEntry) +void ZipPackageStream::setZipEntryOnLoading( const ZipEntry &rInEntry ) { aEntry.nVersion = rInEntry.nVersion; aEntry.nFlag = rInEntry.nFlag; @@ -137,7 +143,7 @@ void ZipPackageStream::CloseOwnStreamIfAny() } //-------------------------------------------------------------------------- -uno::Reference< io::XInputStream >& ZipPackageStream::GetOwnSeekStream() +uno::Reference< io::XInputStream > ZipPackageStream::GetOwnSeekStream() { if ( !m_bHasSeekable && xStream.is() ) { @@ -146,10 +152,10 @@ uno::Reference< io::XInputStream >& ZipPackageStream::GetOwnSeekStream() // is accessed before commit it MUST be wrapped. // Wrap the stream in case it is not seekable xStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( xStream, m_xFactory ); - Reference< io::XSeekable > xSeek( xStream, UNO_QUERY ); + uno::Reference< io::XSeekable > xSeek( xStream, UNO_QUERY ); if ( !xSeek.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must support XSeekable!" ) ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); m_bHasSeekable = sal_True; } @@ -163,18 +169,18 @@ uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCop if ( m_nStreamMode != PACKAGE_STREAM_RAW || !GetOwnSeekStream().is() ) throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - if ( xEncryptionData.isEmpty() ) + if ( m_xBaseEncryptionData.is() ) throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Encrypted stream without encryption data!\n" ) ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); uno::Reference< io::XSeekable > xSeek( GetOwnSeekStream(), UNO_QUERY ); if ( !xSeek.is() ) throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must be seekable!\n" ) ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); // skip header - xSeek->seek( n_ConstHeaderSize + xEncryptionData->aInitVector.getLength() + - xEncryptionData->aSalt.getLength() + xEncryptionData->aDigest.getLength() ); + xSeek->seek( n_ConstHeaderSize + getInitialisationVector().getLength() + + getSalt().getLength() + getDigest().getLength() ); // create temporary stream uno::Reference < io::XOutputStream > xTempOut( @@ -194,17 +200,95 @@ uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCop } //-------------------------------------------------------------------------- -Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_Bool bAddHeaderForEncr ) +sal_Int32 ZipPackageStream::GetEncryptionAlgorithm() const { - if ( m_nStreamMode != PACKAGE_STREAM_DATA || !GetOwnSeekStream().is() || (bAddHeaderForEncr && !bToBeEncrypted) ) + return m_nImportedEncryptionAlgorithm ? m_nImportedEncryptionAlgorithm : rZipPackage.GetEncAlgID(); +} + +//-------------------------------------------------------------------------- +sal_Int32 ZipPackageStream::GetBlockSize() const +{ + return GetEncryptionAlgorithm() == ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 16 : 8; +} + +//-------------------------------------------------------------------------- +::rtl::Reference< EncryptionData > ZipPackageStream::GetEncryptionData( bool bUseWinEncoding ) +{ + ::rtl::Reference< EncryptionData > xResult; + if ( m_xBaseEncryptionData.is() ) + xResult = new EncryptionData( + *m_xBaseEncryptionData, + GetEncryptionKey( bUseWinEncoding ), + GetEncryptionAlgorithm(), + m_nImportedChecksumAlgorithm ? m_nImportedChecksumAlgorithm : rZipPackage.GetChecksumAlgID(), + m_nImportedDerivedKeySize ? m_nImportedDerivedKeySize : rZipPackage.GetDefaultDerivedKeySize(), + GetStartKeyGenID() ); + + return xResult; +} + +//-------------------------------------------------------------------------- +void ZipPackageStream::SetBaseEncryptionData( const ::rtl::Reference< BaseEncryptionData >& xData ) +{ + m_xBaseEncryptionData = xData; +} + +//-------------------------------------------------------------------------- +uno::Sequence< sal_Int8 > ZipPackageStream::GetEncryptionKey( bool bUseWinEncoding ) +{ + uno::Sequence< sal_Int8 > aResult; + sal_Int32 nKeyGenID = GetStartKeyGenID(); + bUseWinEncoding = ( bUseWinEncoding || m_bUseWinEncoding ); + + if ( bHaveOwnKey && m_aStorageEncryptionKeys.getLength() ) + { + ::rtl::OUString aNameToFind; + if ( nKeyGenID == xml::crypto::DigestID::SHA256 ) + aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA256UTF8; + else if ( nKeyGenID == xml::crypto::DigestID::SHA1 ) + { + aNameToFind = bUseWinEncoding ? PACKAGE_ENCRYPTIONDATA_SHA1MS1252 : PACKAGE_ENCRYPTIONDATA_SHA1UTF8; + } + else + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); + + for ( sal_Int32 nInd = 0; nInd < m_aStorageEncryptionKeys.getLength(); nInd++ ) + if ( m_aStorageEncryptionKeys[nInd].Name.equals( aNameToFind ) ) + m_aStorageEncryptionKeys[nInd].Value >>= aResult; + + // empty keys are not allowed here + // so it is not important whether there is no key, or the key is empty, it is an error + if ( !aResult.getLength() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); + } + else + aResult = m_aEncryptionKey; + + if ( !aResult.getLength() || !bHaveOwnKey ) + aResult = rZipPackage.GetEncryptionKey(); + + return aResult; +} + +//-------------------------------------------------------------------------- +sal_Int32 ZipPackageStream::GetStartKeyGenID() +{ + // generally should all the streams use the same Start Key + // but if raw copy without password takes place, we should preserve the imported algorithm + return m_nImportedStartKeyAlgorithm ? m_nImportedStartKeyAlgorithm : rZipPackage.GetStartKeyGenID(); +} + +//-------------------------------------------------------------------------- +uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_Bool bAddHeaderForEncr ) +{ + if ( m_nStreamMode != PACKAGE_STREAM_DATA || !GetOwnSeekStream().is() || ( bAddHeaderForEncr && !bToBeEncrypted ) ) throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); Sequence< sal_Int8 > aKey; if ( bToBeEncrypted ) { - aKey = ( xEncryptionData.isEmpty() || !bHaveOwnKey ) ? rZipPackage.getEncryptionKey() : - xEncryptionData->aKey; + aKey = GetEncryptionKey(); if ( !aKey.getLength() ) throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } @@ -220,7 +304,7 @@ Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_B // create a package based on it ZipPackage* pPackage = new ZipPackage( m_xFactory ); - Reference< XSingleServiceFactory > xPackageAsFactory( static_cast< XSingleServiceFactory* >( pPackage ) ); + uno::Reference< XSingleServiceFactory > xPackageAsFactory( static_cast< XSingleServiceFactory* >( pPackage ) ); if ( !xPackageAsFactory.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -229,14 +313,14 @@ Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_B pPackage->initialize( aArgs ); // create a new package stream - Reference< XDataSinkEncrSupport > xNewPackStream( xPackageAsFactory->createInstance(), UNO_QUERY ); + uno::Reference< XDataSinkEncrSupport > xNewPackStream( xPackageAsFactory->createInstance(), UNO_QUERY ); if ( !xNewPackStream.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); xNewPackStream->setDataStream( static_cast< io::XInputStream* >( new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ) ) ); - Reference< XPropertySet > xNewPSProps( xNewPackStream, UNO_QUERY ); + uno::Reference< XPropertySet > xNewPSProps( xNewPackStream, UNO_QUERY ); if ( !xNewPSProps.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -245,26 +329,26 @@ Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_B xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ), makeAny( bToBeCompressed ) ); if ( bToBeEncrypted ) { - xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ), makeAny( aKey ) ); + xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ), makeAny( aKey ) ); xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Encrypted" ) ), makeAny( sal_True ) ); } // insert a new stream in the package - Reference< XUnoTunnel > xTunnel; + uno::Reference< XUnoTunnel > xTunnel; Any aRoot = pPackage->getByHierarchicalName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ); aRoot >>= xTunnel; - Reference< container::XNameContainer > xRootNameContainer( xTunnel, UNO_QUERY ); + uno::Reference< container::XNameContainer > xRootNameContainer( xTunnel, UNO_QUERY ); if ( !xRootNameContainer.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - Reference< XUnoTunnel > xNPSTunnel( xNewPackStream, UNO_QUERY ); + uno::Reference< XUnoTunnel > xNPSTunnel( xNewPackStream, UNO_QUERY ); xRootNameContainer->insertByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "dummy" ) ), makeAny( xNPSTunnel ) ); // commit the temporary package pPackage->commitChanges(); // get raw stream from the temporary package - Reference< io::XInputStream > xInRaw; + uno::Reference< io::XInputStream > xInRaw; if ( bAddHeaderForEncr ) xInRaw = xNewPackStream->getRawStream(); else @@ -285,12 +369,12 @@ Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_B xTempSeek->seek( 0 ); // close raw stream, package stream and folder - xInRaw = Reference< io::XInputStream >(); - xNewPSProps = Reference< XPropertySet >(); - xNPSTunnel = Reference< XUnoTunnel >(); - xNewPackStream = Reference< XDataSinkEncrSupport >(); - xTunnel = Reference< XUnoTunnel >(); - xRootNameContainer = Reference< container::XNameContainer >(); + xInRaw = uno::Reference< io::XInputStream >(); + xNewPSProps = uno::Reference< XPropertySet >(); + xNPSTunnel = uno::Reference< XUnoTunnel >(); + xNewPackStream = uno::Reference< XDataSinkEncrSupport >(); + xTunnel = uno::Reference< XUnoTunnel >(); + xRootNameContainer = uno::Reference< container::XNameContainer >(); // return the stream representing the first temporary file return xTempIn; @@ -316,7 +400,7 @@ sal_Bool ZipPackageStream::ParsePackageRawStream() sal_Bool bOk = sal_False; - vos::ORef < EncryptionData > xTempEncrData; + ::rtl::Reference< BaseEncryptionData > xTempEncrData; sal_Int32 nMagHackSize = 0; Sequence < sal_Int8 > aHeader ( 4 ); @@ -332,17 +416,25 @@ sal_Bool ZipPackageStream::ParsePackageRawStream() if ( nHeader == n_ConstHeader ) { // this is one of our god-awful, but extremely devious hacks, everyone cheer - xTempEncrData = new EncryptionData; + xTempEncrData = new BaseEncryptionData; ::rtl::OUString aMediaType; - if ( ZipFile::StaticFillData ( xTempEncrData, nMagHackSize, aMediaType, GetOwnSeekStream() ) ) + sal_Int32 nEncAlgorithm = 0; + sal_Int32 nChecksumAlgorithm = 0; + sal_Int32 nDerivedKeySize = 0; + sal_Int32 nStartKeyGenID = 0; + if ( ZipFile::StaticFillData( xTempEncrData, nEncAlgorithm, nChecksumAlgorithm, nDerivedKeySize, nStartKeyGenID, nMagHackSize, aMediaType, GetOwnSeekStream() ) ) { // We'll want to skip the data we've just read, so calculate how much we just read // and remember it - m_nMagicalHackPos = n_ConstHeaderSize + xTempEncrData->aSalt.getLength() - + xTempEncrData->aInitVector.getLength() - + xTempEncrData->aDigest.getLength() + m_nMagicalHackPos = n_ConstHeaderSize + xTempEncrData->m_aSalt.getLength() + + xTempEncrData->m_aInitVector.getLength() + + xTempEncrData->m_aDigest.getLength() + aMediaType.getLength() * sizeof( sal_Unicode ); + m_nImportedEncryptionAlgorithm = nEncAlgorithm; + m_nImportedChecksumAlgorithm = nChecksumAlgorithm; + m_nImportedDerivedKeySize = nDerivedKeySize; + m_nImportedStartKeyAlgorithm = nStartKeyGenID; m_nMagicalHackSize = nMagHackSize; sMediaType = aMediaType; @@ -361,7 +453,7 @@ sal_Bool ZipPackageStream::ParsePackageRawStream() return sal_False; } - xEncryptionData = xTempEncrData; + m_xBaseEncryptionData = xTempEncrData; SetIsEncrypted ( sal_True ); // it's already compressed and encrypted bToBeEncrypted = bToBeCompressed = sal_False; @@ -383,11 +475,12 @@ void ZipPackageStream::SetPackageMember( sal_Bool bNewValue ) // XActiveDataSink //-------------------------------------------------------------------------- -void SAL_CALL ZipPackageStream::setInputStream( const Reference< io::XInputStream >& aStream ) - throw(RuntimeException) +void SAL_CALL ZipPackageStream::setInputStream( const uno::Reference< io::XInputStream >& aStream ) + throw( RuntimeException ) { // if seekable access is required the wrapping will be done on demand xStream = aStream; + m_nImportedEncryptionAlgorithm = 0; m_bHasSeekable = sal_False; SetPackageMember ( sal_False ); aEntry.nTime = -1; @@ -395,94 +488,100 @@ void SAL_CALL ZipPackageStream::setInputStream( const Reference< io::XInputStrea } //-------------------------------------------------------------------------- -Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawData() - throw(RuntimeException) +uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawData() + throw( RuntimeException ) { try { - if (IsPackageMember()) + if ( IsPackageMember() ) { - if ( !xEncryptionData.isEmpty() && !bHaveOwnKey ) - xEncryptionData->aKey = rZipPackage.getEncryptionKey(); - return rZipPackage.getZipFile().getRawData( aEntry, xEncryptionData, bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); } else if ( GetOwnSeekStream().is() ) { return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ); } else - return Reference < io::XInputStream > (); + return uno::Reference < io::XInputStream > (); } - catch (ZipException &)//rException) + catch ( ZipException & )//rException ) { - VOS_ENSURE( 0, "ZipException thrown");//rException.Message); - return Reference < io::XInputStream > (); + VOS_ENSURE( 0, "ZipException thrown" );//rException.Message ); + return uno::Reference < io::XInputStream > (); } - catch (Exception &) + catch ( Exception & ) { - VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n"); - return Reference < io::XInputStream > (); + VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n" ); + return uno::Reference < io::XInputStream > (); } } //-------------------------------------------------------------------------- -Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream( ) - throw(RuntimeException) +uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream() + throw( RuntimeException ) { try { - if (IsPackageMember()) + if ( IsPackageMember() ) { - if ( !xEncryptionData.isEmpty() && !bHaveOwnKey ) - xEncryptionData->aKey = rZipPackage.getEncryptionKey(); - return rZipPackage.getZipFile().getInputStream( aEntry, xEncryptionData, bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + return rZipPackage.getZipFile().getInputStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); } else if ( GetOwnSeekStream().is() ) { return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ); } else - return Reference < io::XInputStream > (); + return uno::Reference < io::XInputStream > (); } - catch (ZipException &)//rException) + catch ( ZipException & )//rException ) { - VOS_ENSURE( 0,"ZipException thrown");//rException.Message); - return Reference < io::XInputStream > (); + VOS_ENSURE( 0,"ZipException thrown" );//rException.Message ); + return uno::Reference < io::XInputStream > (); } - catch (Exception &) + catch ( Exception & ) { - VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n"); - return Reference < io::XInputStream > (); + VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n" ); + return uno::Reference < io::XInputStream > (); } } // XDataSinkEncrSupport //-------------------------------------------------------------------------- -Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream() +uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream() throw ( packages::WrongPasswordException, io::IOException, RuntimeException ) { // There is no stream attached to this object if ( m_nStreamMode == PACKAGE_STREAM_NOTSET ) - return Reference< io::XInputStream >(); + return uno::Reference< io::XInputStream >(); // this method can not be used together with old approach if ( m_nStreamMode == PACKAGE_STREAM_DETECT ) throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - if ( !xEncryptionData.isEmpty() && !bHaveOwnKey ) - xEncryptionData->aKey = rZipPackage.getEncryptionKey(); - - if (IsPackageMember()) + if ( IsPackageMember() ) { - if ( !xEncryptionData.isEmpty() && !bHaveOwnKey ) - xEncryptionData->aKey = rZipPackage.getEncryptionKey(); - - return rZipPackage.getZipFile().getDataStream( aEntry, xEncryptionData, bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + uno::Reference< io::XInputStream > xResult; + try + { + xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + } + catch( packages::WrongPasswordException& ) + { + // workaround for the encrypted documents generated with the old OOo1.x bug. + if ( rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 && !m_bUseWinEncoding ) + { + xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + m_bUseWinEncoding = true; + } + else + throw; + } + return xResult; } else if ( m_nStreamMode == PACKAGE_STREAM_RAW ) - return ZipFile::StaticGetDataFromRawStream( GetOwnSeekStream(), xEncryptionData ); + return ZipFile::StaticGetDataFromRawStream( m_xFactory, GetOwnSeekStream(), GetEncryptionData() ); else if ( GetOwnSeekStream().is() ) { return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ); @@ -492,25 +591,25 @@ Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream() } //-------------------------------------------------------------------------- -Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream() +uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream() throw ( packages::NoEncryptionException, io::IOException, uno::RuntimeException ) { // There is no stream attached to this object if ( m_nStreamMode == PACKAGE_STREAM_NOTSET ) - return Reference< io::XInputStream >(); + return uno::Reference< io::XInputStream >(); // this method can not be used together with old approach if ( m_nStreamMode == PACKAGE_STREAM_DETECT ) throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - if (IsPackageMember()) + if ( IsPackageMember() ) { - if ( !bIsEncrypted || xEncryptionData.isEmpty() ) + if ( !bIsEncrypted || !GetEncryptionData().is() ) throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return rZipPackage.getZipFile().getWrappedRawStream( aEntry, xEncryptionData, sMediaType, rZipPackage.GetSharedMutexRef() ); + return rZipPackage.getZipFile().getWrappedRawStream( aEntry, GetEncryptionData(), sMediaType, rZipPackage.GetSharedMutexRef() ); } else if ( GetOwnSeekStream().is() ) { @@ -527,7 +626,7 @@ Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream() //-------------------------------------------------------------------------- -void SAL_CALL ZipPackageStream::setDataStream( const Reference< io::XInputStream >& aStream ) +void SAL_CALL ZipPackageStream::setDataStream( const uno::Reference< io::XInputStream >& aStream ) throw ( io::IOException, RuntimeException ) { @@ -536,21 +635,21 @@ void SAL_CALL ZipPackageStream::setDataStream( const Reference< io::XInputStream } //-------------------------------------------------------------------------- -void SAL_CALL ZipPackageStream::setRawStream( const Reference< io::XInputStream >& aStream ) +void SAL_CALL ZipPackageStream::setRawStream( const uno::Reference< io::XInputStream >& aStream ) throw ( packages::EncryptionNotAllowedException, packages::NoRawFormatException, io::IOException, - RuntimeException) + RuntimeException ) { // wrap the stream in case it is not seekable - Reference< io::XInputStream > xNewStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( aStream, m_xFactory ); - Reference< io::XSeekable > xSeek( xNewStream, UNO_QUERY ); + uno::Reference< io::XInputStream > xNewStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( aStream, m_xFactory ); + uno::Reference< io::XSeekable > xSeek( xNewStream, UNO_QUERY ); if ( !xSeek.is() ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must support XSeekable!" ) ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); xSeek->seek( 0 ); - Reference< io::XInputStream > xOldStream = xStream; + uno::Reference< io::XInputStream > xOldStream = xStream; xStream = xNewStream; if ( !ParsePackageRawStream() ) { @@ -573,15 +672,15 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getPlainRawStream( { // There is no stream attached to this object if ( m_nStreamMode == PACKAGE_STREAM_NOTSET ) - return Reference< io::XInputStream >(); + return uno::Reference< io::XInputStream >(); // this method can not be used together with old approach if ( m_nStreamMode == PACKAGE_STREAM_DETECT ) throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - if (IsPackageMember()) + if ( IsPackageMember() ) { - return rZipPackage.getZipFile().getRawData( aEntry, xEncryptionData, bIsEncrypted, rZipPackage.GetSharedMutexRef() ); + return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() ); } else if ( GetOwnSeekStream().is() ) { @@ -594,14 +693,14 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getPlainRawStream( return TryToGetRawFromDataStream( sal_False ); } - return Reference< io::XInputStream >(); + return uno::Reference< io::XInputStream >(); } // XUnoTunnel //-------------------------------------------------------------------------- sal_Int64 SAL_CALL ZipPackageStream::getSomething( const Sequence< sal_Int8 >& aIdentifier ) - throw(RuntimeException) + throw( RuntimeException ) { sal_Int64 nMe = 0; if ( aIdentifier.getLength() == 16 && @@ -613,18 +712,18 @@ sal_Int64 SAL_CALL ZipPackageStream::getSomething( const Sequence< sal_Int8 >& a // XPropertySet //-------------------------------------------------------------------------- void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) - throw(beans::UnknownPropertyException, beans::PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) + throw( beans::UnknownPropertyException, beans::PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException ) { - if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MediaType"))) + if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" )) ) { if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE && rZipPackage.getFormat() != embed::StorageFormats::OFOPXML ) throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); if ( aValue >>= sMediaType ) { - if (sMediaType.getLength() > 0) + if ( sMediaType.getLength() > 0 ) { - if ( sMediaType.indexOf (OUString( RTL_CONSTASCII_USTRINGPARAM ( "text" ) ) ) != -1 + if ( sMediaType.indexOf ( OUString( RTL_CONSTASCII_USTRINGPARAM ( "text" ) ) ) != -1 || sMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM ( "application/vnd.sun.star.oleobject" ) ) ) ) bToBeCompressed = sal_True; else if ( !m_bCompressedIsSetFromOutside ) @@ -633,18 +732,18 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, } else throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "MediaType must be a string!\n" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); } - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Size") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) { if ( !( aValue >>= aEntry.nSize ) ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Size property!\n" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); } - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Encrypted") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) { if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE ) throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -655,25 +754,25 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, // In case of new raw stream, the stream must not be encrypted on storing if ( bEnc && m_nStreamMode == PACKAGE_STREAM_RAW ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Raw stream can not be encrypted on storing" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); bToBeEncrypted = bEnc; - if ( bToBeEncrypted && xEncryptionData.isEmpty()) - xEncryptionData = new EncryptionData; + if ( bToBeEncrypted && !m_xBaseEncryptionData.is() ) + m_xBaseEncryptionData = new BaseEncryptionData; } else throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Encrypted property!\n" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); } - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("EncryptionKey") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) ) { if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE ) throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - Sequence < sal_Int8 > aNewKey; + uno::Sequence< sal_Int8 > aNewKey; if ( !( aValue >>= aNewKey ) ) { @@ -684,31 +783,69 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, Sequence < sal_Int8 > aSequence ( nPathLength ); sal_Int8 *pArray = aSequence.getArray(); const sal_Unicode *pChar = sTempString.getStr(); - for ( sal_Int16 i = 0; i < nPathLength; i++) - pArray[i] = static_cast < const sal_Int8 > (pChar[i]); + for ( sal_Int16 i = 0; i < nPathLength; i++ ) + pArray[i] = static_cast < const sal_Int8 > ( pChar[i] ); aNewKey = aSequence; } else throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for EncryptionKey property!\n" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); } if ( aNewKey.getLength() ) { - if ( xEncryptionData.isEmpty()) - xEncryptionData = new EncryptionData; + if ( !m_xBaseEncryptionData.is() ) + m_xBaseEncryptionData = new BaseEncryptionData; + + m_aEncryptionKey = aNewKey; + // In case of new raw stream, the stream must not be encrypted on storing + bHaveOwnKey = sal_True; + if ( m_nStreamMode != PACKAGE_STREAM_RAW ) + bToBeEncrypted = sal_True; + } + else + { + bHaveOwnKey = sal_False; + m_aEncryptionKey.realloc( 0 ); + } + + m_aStorageEncryptionKeys.realloc( 0 ); + } + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) + { + if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE ) + throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + + uno::Sequence< beans::NamedValue > aKeys; + if ( !( aValue >>= aKeys ) ) + { + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for StorageEncryptionKeys property!\n" ) ), + uno::Reference< XInterface >(), + 2 ); + } + + if ( aKeys.getLength() ) + { + if ( !m_xBaseEncryptionData.is() ) + m_xBaseEncryptionData = new BaseEncryptionData; + + m_aStorageEncryptionKeys = aKeys; - xEncryptionData->aKey = aNewKey; // In case of new raw stream, the stream must not be encrypted on storing bHaveOwnKey = sal_True; if ( m_nStreamMode != PACKAGE_STREAM_RAW ) bToBeEncrypted = sal_True; } else + { bHaveOwnKey = sal_False; + m_aStorageEncryptionKeys.realloc( 0 ); + } + + m_aEncryptionKey.realloc( 0 ); } - else if (aPropertyName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) ) + else if ( aPropertyName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) ) { sal_Bool bCompr = sal_False; @@ -717,7 +854,7 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, // In case of new raw stream, the stream must not be encrypted on storing if ( bCompr && m_nStreamMode == PACKAGE_STREAM_RAW ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Raw stream can not be encrypted on storing" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); bToBeCompressed = bCompr; @@ -725,7 +862,7 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, } else throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Compressed property!\n" ) ), - Reference< XInterface >(), + uno::Reference< XInterface >(), 2 ); } else @@ -734,37 +871,42 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, //-------------------------------------------------------------------------- Any SAL_CALL ZipPackageStream::getPropertyValue( const OUString& PropertyName ) - throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( beans::UnknownPropertyException, WrappedTargetException, RuntimeException ) { Any aAny; - if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) + if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) { aAny <<= sMediaType; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) ) { aAny <<= aEntry.nSize; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Encrypted" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Encrypted" ) ) ) { aAny <<= ( m_nStreamMode == PACKAGE_STREAM_RAW ) ? sal_True : bToBeEncrypted; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WasEncrypted" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WasEncrypted" ) ) ) { aAny <<= bIsEncrypted; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) ) { aAny <<= bToBeCompressed; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "EncryptionKey" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) ) + { + aAny <<= m_aEncryptionKey; + return aAny; + } + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) { - aAny <<= xEncryptionData.isEmpty () ? Sequence < sal_Int8 > () : xEncryptionData->aKey; + aAny <<= m_aStorageEncryptionKeys; return aAny; } else @@ -772,30 +914,30 @@ Any SAL_CALL ZipPackageStream::getPropertyValue( const OUString& PropertyName ) } //-------------------------------------------------------------------------- -void ZipPackageStream::setSize (const sal_Int32 nNewSize) +void ZipPackageStream::setSize ( const sal_Int32 nNewSize ) { - if (aEntry.nCompressedSize != nNewSize ) + if ( aEntry.nCompressedSize != nNewSize ) aEntry.nMethod = DEFLATED; aEntry.nSize = nNewSize; } //-------------------------------------------------------------------------- OUString ZipPackageStream::getImplementationName() - throw (RuntimeException) + throw ( RuntimeException ) { return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageStream" ) ); } //-------------------------------------------------------------------------- Sequence< OUString > ZipPackageStream::getSupportedServiceNames() - throw (RuntimeException) + throw ( RuntimeException ) { - Sequence< OUString > aNames(1); + Sequence< OUString > aNames( 1 ); aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageStream" ) ); return aNames; } //-------------------------------------------------------------------------- sal_Bool SAL_CALL ZipPackageStream::supportsService( OUString const & rServiceName ) - throw (RuntimeException) + throw ( RuntimeException ) { return rServiceName == getSupportedServiceNames()[0]; } diff --git a/package/source/zippackage/zipfileaccess.cxx b/package/source/zippackage/zipfileaccess.cxx index 9acae56ad68a..d93e03803204 100644 --- a/package/source/zippackage/zipfileaccess.cxx +++ b/package/source/zippackage/zipfileaccess.cxx @@ -42,6 +42,7 @@ #include <EncryptionData.hxx> #include <ucbhelper/content.hxx> +#include <rtl/ref.hxx> #include <memory> @@ -253,7 +254,7 @@ uno::Any SAL_CALL OZipFileAccess::getByName( const ::rtl::OUString& aName ) throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second, - new EncryptionData(), + ::rtl::Reference< EncryptionData >(), sal_False, m_aMutexHolder ) ); @@ -368,7 +369,7 @@ uno::Reference< io::XInputStream > SAL_CALL OZipFileAccess::getStreamByPattern( if ( StringGoodForPattern_Impl( (*aIter).second.sPath, aPattern ) ) { uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second, - new EncryptionData(), + ::rtl::Reference< EncryptionData >(), sal_False, m_aMutexHolder ) ); diff --git a/padmin/Executable_spadmin.bin.mk b/padmin/Executable_spadmin.bin.mk index ae677c1c86b4..1197c4de1fff 100644 --- a/padmin/Executable_spadmin.bin.mk +++ b/padmin/Executable_spadmin.bin.mk @@ -53,6 +53,7 @@ $(eval $(call gb_Executable_add_linked_libs,spadmin.bin,\ cppu \ sal \ stl \ + $(gb_STDLIBS) \ )) $(eval $(call gb_Executable_add_exception_objects,spadmin.bin,\ diff --git a/padmin/Library_spa.mk b/padmin/Library_spa.mk index 47618720d283..cb74c4fe15c5 100644 --- a/padmin/Library_spa.mk +++ b/padmin/Library_spa.mk @@ -50,6 +50,7 @@ $(eval $(call gb_Library_add_linked_libs,spa,\ cppu \ sal \ vos3 \ + $(gb_STDLIBS) \ )) diff --git a/pango/makefile.mk b/pango/makefile.mk index c7f9d036a545..fddbbecf83a1 100644 --- a/pango/makefile.mk +++ b/pango/makefile.mk @@ -108,7 +108,7 @@ OUT2INC+=pango/pango-utils.h .ELIF "$(OS)"=="WNT" PATCH_FILES=pango-1.28.3-win32.patch -ADDITIONAL_FILES=config.h module.defs make.msc glib-mkenums.pl msvc_recommended_pragmas.h +ADDITIONAL_FILES=config.h msvc_recommended_pragmas.h CONFIGURE_DIR= CONFIGURE_ACTION= BUILD_DIR=./pango diff --git a/pango/pango-1.28.3-win32.patch b/pango/pango-1.28.3-win32.patch index 35ad6666b318..0aa1155c3a2f 100644 --- a/pango/pango-1.28.3-win32.patch +++ b/pango/pango-1.28.3-win32.patch @@ -51,7 +51,7 @@ +CAIRO_LIB = $(OUTDIR)\lib\cairo.lib +USP10_LIB = USP10.lib + -+!INCLUDE $(PRJ_TOP)\make.msc ++!INCLUDE $(OUTDIR)\inc\external\glib-2.0\make.msc !IFNDEF PERL PERL = perl @@ -172,7 +172,7 @@ pango-enum-types.h: $(pango_headers) makefile.msc - $(PERL) $(GLIB)\gobject\glib-mkenums \ -+ $(PERL) $(PRJ_TOP)\glib-mkenums.pl \ ++ $(PERL) $(OUTDIR)\bin\glib-mkenums \ --fhead "#ifndef __PANGO_ENUM_TYPES_H__\n#define __PANGO_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \ --fprod "/* enumerations from \"@filename@\" */\n" \ --vhead "GType @enum_name@_get_type (void);\n#define PANGO_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \ @@ -181,7 +181,7 @@ pango-enum-types.c: $(pango_headers) pango-enum-types.h makefile.msc - $(PERL) $(GLIB)\gobject\glib-mkenums \ -+ $(PERL) $(PRJ_TOP)\glib-mkenums.pl \ ++ $(PERL) $(OUTDIR)\bin\glib-mkenums \ --fhead "#include <pango.h>" \ --fprod "\n/* enumerations from \"@filename@\" */" \ --vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \ @@ -595,917 +595,6 @@ +/*almostempty*/ +#define PANGO_BINARY_AGE 0 +#define DHAVE_USP10_H 1 ---- misc/pango-1.28.3/make.msc 2011-03-26 08:32:25.068811600 +0100 -+++ misc/build/pango-1.28.3/make.msc 2011-03-26 09:00:42.356161600 +0100 -@@ -1 +1,237 @@ --dummy -+# Note that this file is hardly maintained, hardly usable without -+# manual editing, and not really part of a recommended way to build -+# GLib and related software with Microsoft's compilers. Only a few -+# persons use a build setup that involves this file. -+ -+# Common makefile definitions for building GLib, GTk+, and various -+# software that use these libraries with msvc on Win32 -+ -+# Debug builds shoud link with msvcrtd release build with msvcrt. -+!IFNDEF DEBUG -+# Full optimization: -+OPTIMIZE = -Ox -+# release with debug -+OPTIMIZE = -Zi -DG_ENABLE_DEBUG=1 -+CRUNTIME = -MD -+LINKDEBUG = /OPT:REF -+!ELSE -+# Debugging: -+OPTIMIZE = -+CRUNTIME = -MDd -+DEBUGINFO = -Zi -DG_ENABLE_DEBUG=1 -+LINKDEBUG = /debug /nodefaultlib:msvcrt.lib -+!ENDIF -+ -+LDFLAGS = /link /machine:ix86 $(LINKDEBUG) -+ -+!IFNDEF TOP -+TOP = .. -+!ENDIF -+ -+!IFNDEF PERL -+PERL = perl -+!ENDIF -+ -+XSLTPROC = d:\gnome-0\xsltproc -+ -+# paths and version numbers -+!INCLUDE module.defs -+ -+################ -+# CFLAGS and LIBS for the packages in module.defs. -+# In alphabetical order. -+ -+# Note that these CFLAGS and LIBS refer to stuff in "source" -+# directories. This is for historical reasons, and only useable if you -+# have the GLib, Pango, etc sources. If you use the prebuilt developer -+# packages, you should fix these to instead refer to the place where -+# you unzipped the developer packages. Easiest of all, run pkg-config -+# --cflags gtk+-2.0 (for instance), and paste its output as the -+# definition of GTK2_CFLAGS. Etc. -+ -+ATK_CFLAGS = -I $(ATK) -+ATK_LIBS = $(ATK)\atk\atk-$(ATK_VER).lib -+BABL_CFLAGS = -I $(BABL) -+BABL_LIBS = $(BABL)\babl\babl-1.0.lib -+ -+# force inclusion of the _right_ cairoversion.h even when using without installation -+CAIRO_CFLAGS = -I $(CAIRO)\src -I $(CAIRO) -+CAIRO_LIBS = $(CAIRO)\src\libcairo.lib -+ -+DIRENT_CFLAGS = -I ..\build\win32\dirent -+DIRENT_LIBS = ..\build\win32\dirent\dirent.lib -+ -+!IFNDEF EXIF -+EXIF_CFLAGS = -I $(DEVTOP)\include -+EXIF_LIBS = $(DEVTOP)\lib\exif.lib -+EXIF = 1 -+!ENDIF -+ -+# Don't know if Freetype2, FriBiDi and some others actually can be -+# built with MSVC, but one can produce an import library even if the -+# DLL was built with gcc. -+!IFDEF FREETYPE2 -+FREETYPE2_CFLAGS = -I $(FREETYPE2)\include -+FREETYPE2_LIBS = $(FREETYPE2)\obj\freetype-$(FREETYPE2_VER).lib -+!ELSE -+FREETYPE2_CFLAGS = -I $(DEVTOP)\include -I $(DEVTOP)\include\freetype2 -+FREETYPE2_LIBS = $(DEVTOP)\lib\freetype6.lib -+!ENDIF -+ -+!IFNDEF FONTCONFIG -+FONTCONFIG_CFLAGS = -I $(DEVTOP)\include -+FONTCONFIG_LIBS = $(DEVTOP)\lib\fontconfig.lib -+!ENDIF -+ -+GDK_PIXBUF_CFLAGS = -I $(GDK_PIXBUF) -+GDK_PIXBUF_LIBS = $(GTK2)\gdk-pixbuf\gdk_pixbuf-$(GDK_PIXBUF_VER).lib -+ -+GIMP_CFLAGS = -I $(GIMP) -+GIMP_PLUGIN_LIBS = $(GIMP)\libgimp\gimp-$(GIMP_VER).lib $(GIMP)\libgimp\gimpui-$(GIMP_VER).lib -+ -+# overide definition to use it as callable path -+GLIB = $(TOP)\glib -+ -+GLIB_CFLAGS = -I $(GLIB) -I $(GLIB)\glib -I $(GLIB)\gmodule $(INTL_CFLAGS) $(SOLARINC) -+GLIB_LIBS = $(GLIB)\glib\glib-$(GLIB_VER).lib $(GLIB)\gmodule\gmodule-$(GLIB_VER).lib $(GLIB)\gobject\gobject-$(GLIB_VER).lib $(GLIB)\gio\gio-$(GLIB_VER).lib -+GTHREAD_LIBS = $(GLIB)\gthread\gthread-$(GLIB_VER).lib -+ -+!IFNDEF GDK_PIXBUF -+GDK_PIXBUF_CFLAGS = $(GTK2_CFLAGS) -+GDK_PIXBUF_LIBS = $(GTK2_LIBS) -+!ENDIF -+ -+GNOMECANVAS_CFLAGS = -I $(GNOMECANVAS) -+GNOMECANVAS_LIBS = $(GNOMECANVAS)\libgnomecanvas\libgnomecanvas-$(GNOMECANVAS_VER).lib -+ -+GNOMEPRINT_CFLAGS = -I $(GNOMEPRINT) -+GNOMEPRINT_LIBS = $(GNOMEPRINT)\libgnomeprint\gnome-print-$(GNOMEPRINT_VER).lib -+ -+GNOMEPRINTUI_CFLAGS = -I $(GNOMEPRINTUI) -+GNOMEPRINTUI_LIBS = $(GNOMEPRINTUI)\libgnomeprintui\gnome-printui-$(GNOMEPRINTUI_VER).lib -+ -+GTK_CFLAGS = -I$(GTK)\gdk -I$(GTK)\gdk -I$(GTK) -+GTK_LIBS = $(GTK)\gtk\gtk.lib $(GTK)\gdk\gdk.lib -+ -+GTK2_CFLAGS = $(GLIB_CFLAGS) $(ATK_CFLAGS) -I$(GTK2)\gdk -I$(GTK2)\gdk -I$(GTK2) -I$(PANGO) -I$(ATK) $(CAIRO_CFLAGS) -+GTK2_LIBS = $(GTK2)\gtk\gtk-win32-$(GTK2_VER).lib $(GTK2)\gdk\gdk-win32-$(GTK2_VER).lib $(GTK2)\gdk-pixbuf\gdk_pixbuf-$(GTK2_VER).lib $(PANGO_LIBS) -+ -+GTKGLAREA_CFLAGS = -I $(GTKGLAREA) -+GTKGLAREA_LIBS = $(GTKGLAREA)\gtkgl\gtkgl-$(GTKGLAREA_VER).lib -+ -+GTKSOURCEVIEW_CFLAGS = -I $(GTKSOURCEVIEW) -+GTKSOURCEVIEW_LIBS = $(GTKSOURCEVIEW)\gtksourceview\gtksourceview.lib -+ -+LIBART_CFLAGS = -I$(LIBART)\.. -FIlibart_lgpl/art_config.h -+LIBART_LIBS = $(LIBART)\art_lgpl_2.lib -+ -+!IFNDEF INTL -+INTL_CFLAGS = -I $(OUTDIR)\inc\external -+INTL_LIBS = $(OUTDIR)/lib/intl.lib -+!ELSE -+INTL_CFLAGS = -I $(OUTDIR)\inc\external -+INTL_LIBS = $(OUTDIR)/lib/intl.lib -+!ENDIF -+ -+!IFDEF LCMS -+LCMS_CFLAGS = -DLCMS_DLL -I $(LCMS)\include -+LCMS_LIBS = $(LCMS)\Projects\VC6\Release\lcms.lib -+!ENDIF -+ -+LIBICONV_CFLAGS = -I $(LIBICONV)\include -+LIBICONV_LIBS = $(LIBICONV)\lib\iconv.lib -+ -+LIBXML_CFLAGS = -I $(LIBXML) -+LIBXML_LIBS = $(LIBXML)\xml-$(LIBXML_VER).lib -+ -+LIBXML2_CFLAGS = $(LIBICONV_CFLAGS) -I $(LIBXML2)\include -+LIBXML2_LIBS = $(LIBXML2)\libxml2.lib -+ -+LIBXSLT_CFLAGS = -I $(LIBXSLT) -+LIBXSLT_LIBS = $(LIBXSLT)\libxslt\libxslt.lib -+ -+LCMS_CFLAGS = -I $(LCMS)\include -DLCMS_DLL -+LCMS_LIBS = $(LCMS)\Projects\VC6\Release\lcms.lib -+ -+!IFNDEF JPEG -+JPEG_CFLAGS = -I $(DEVTOP)\include -+JPEG_LIBS = $(DEVTOP)\lib\jpeg.lib -+!ELSE -+JPEG_CFLAGS = -I $(JPEG) -+JPEG_LIBS = $(JPEG)\libjpeg.lib -+!ENDIF -+ -+OPENGL_CFLAGS = # None needed, headers bundled with the compiler -+OPENGL_LIBS = opengl32.lib lglu32.lib -+ -+PANGO_CFLAGS = -I $(PANGO) -+PANGO_LIBS = $(PANGO)\pango\pango-$(PANGO_VER).lib -+PANGOCAIRO_LIBS = $(PANGO_LIBS) $(PANGO)\pango\pangocairo-$(PANGO_VER).lib -+PANGOWIN32_LIBS = $(PANGO_LIBS) $(PANGO)\pango\pangowin32-$(PANGO_VER).lib -+PANGOFT2_LIBS = $(PANGO_LIBS) $(PANGO)\pango\pangoft2-$(PANGO_VER).lib -+ -+!IFDEF PNG -+PNG_CFLAGS = -I $(PNG) $(ZLIB_CFLAGS) -+PNG_LIBS = $(PNG)\projects\visualc6\Win32_LIB_Release\libpng.lib $(ZLIB_LIBS) -+!ELSE -+PNG_CFLAGS = -I $(DEVTOP)\include $(ZLIB_CFLAGS) -+PNG_LIBS = $(DEVTOP)\lib\libpng.lib $(ZLIB_LIBS) -+!ENDIF -+ -+RSVG_CFLAGS = -I $(RSVG)\.. -+RSVG_LIBS = $(RSVG)\librsvg-2.lib -+ -+SVG_CFLAGS = -I $(SVG)\src -+SVG_LIBS = $(SVG)\src\libsvg-$(SVG_VER).lib -+ -+!IFDEF TIFF -+TIFF_CFLAGS = -I $(TIFF)\libtiff -+# Use single import library for both libtiff DLL versions (with or -+# without LZW code). The user selects which DLL to use. -+TIFF_LIBS = $(TIFF)\libtiff\libtiff.lib $(JPEG_LIBS) $(ZLIB_LIBS) user32.lib -+!ELSE -+TIFF_CFLAGS = -I $(DEVTOP)\include -+TIFF_LIBS = $(DEVTOP)\lib\libtiff.lib -+!ENDIF -+ -+VIPS_CFLAGS = -I $(VIPS)/include -+VIPS_LIBS = $(VIPS)/libsrc/vips.lib -+ -+!IFDEF ZLIB -+ZLIB_CFLAGS = -I $(ZLIB) -+ZLIB_LIBS = $(OUTDIR)\lib\zlib.lib -+!ELSE -+ZLIB_CFLAGS = -I $(ZLIB) -+ZLIB_LIBS = $(OUTDIR)\lib\zlib.lib -+!ENDIF -+ -+################ -+# Compiler to use. -+ -+CCOMPILER = cl -+CC = $(CCOMPILER) $(OPTIMIZE) $(CRUNTIME) -W3 -nologo -+ -+################ -+# The including makefile should define INCLUDES, DEFINES and -+# DEPCFLAGS. INCLUDES are the includes related to the module being -+# built. DEFINES similarly. DEPCFLAGS should be set to a set of -+# GLIB_CFLAGS, GTK_CFLAGS etc corresponding to what other modules we -+# depend on. -+ -+CFLAGS = $(OPTIMIZE) $(DEBUGINFO) $(INCLUDES) $(DEFINES) $(DEPCFLAGS) -+# make cl/wcl386 compatible (c99 and cdecl) -+#OPTIMIZE = -Ox -+#CFLAGS = /passwopts:-za99 /passwopts:-ecc $(DEBUGINFO) $(INCLUDES) $(DEFINES) $(DEPCFLAGS) -+.c.i : -+ $(CC) $(CFLAGS) -E $< >$@ -+ -+# The default target should be "all" -+ -+default: all -+ -+clean:: -+ -del *.obj *.res *.i *.exe *.dll *.lib *.err *.map *.exp *.lk1 *.mk1 *.ilk *.manifest -+ -del *.pdb -+ -+# Needed by hacker rule to make makefile.msc from makefile.msc.in: -+SED = e:\cygwin\bin\sed ---- misc/pango-1.28.3/module.defs 2011-03-26 15:50:26.773265200 +0100 -+++ misc/build/pango-1.28.3/module.defs 2011-03-26 15:49:47.850892000 +0100 -@@ -1 +1,124 @@ --dummy -+# Note that this file is hardly maintained, hardly usable without -+# manual editing, and not really part of a recommended way to build -+# GLib and related software with Microsoft's compilers. Only a few -+# persons use a build setup that involves this file. -+ -+# This file is included by makefiles for both GNU Make (for gcc -+# (mingw) builds, and NMAKE (for MSVC builds). -+ -+MODULE_DEFS_INCLUDED=1 -+ -+# fallback if a specifc library is not contained in TOP (i.e. not self-compiled) -+DEVTOP=$(TOP)\..\other\dev -+ -+################ -+# The version macros define what versions of libraries to use. -+ -+# The version numbers are defined unconditionally. If you want to -+# produce a newer version of one of these libraries, the new number -+# should be defined in the specific project makefile _after_ including -+# this file (or make.{mingw,msc}). These version numbers are used in -+# the names of some import libraries. -+ -+# Please note that there are two (or three) ways to build the GLib -+# (and GTK+ etc) libraries on Win32: Either using the same -+# auto*/configure mechanism to generate makefiles as on Unix, and -+# libtool to handle DLL creation. This currently only works for gcc, -+# and even then it is hellish to set up to work 100% correctly. For -+# people using that, this file is totally irrelevant. -+ -+# Or, use hand-written makefiles, either for MSVC (these are called -+# makefile.msc and maintained by Hans Breuer), or for gcc -+# (makefile.mingw, by Tor Lillqvist). Only for GLib are the -+# makefile.mingw files believed to be up-to-date, for other modules -+# they have been left to rot after Tor started using the -+# autoconfiscated way of building. -+ -+# The stuff here uses the same name for (import) libraries as on Unix, -+# as libtool uses those, and the semi-official developer packages are -+# built using libtool. -+ -+ATK_VER = 1.0 -+CAIRO_VER = 1.4 -+FREETYPE2_VER = 2.0 -+GIMP_VER = 1.2 -+GDK_PIXBUF_VER = 2.0 -+GLIB_VER = 2.0 -+GTKGLAREA_VER = 1.2.2 -+GTK2_VER = 2.0 -+LIBGLADE_VER = 0.14 -+LIBICONV_VER = 1.7 -+LIBXML_VER = 1.8.7 -+LIBXML2_VER = 2.4.2 -+PANGO_VER = 1.0 -+POPT_VER = 1.4 -+SVG_VER = 0.1 -+RSVG_VER = 2.4 -+ -+################ -+# Locations of various source directories. TOP is defined in make.{mingw,msc} -+ -+# First stuff that is in the GNOME CVS repository. -+# In alphabetical order. -+ -+ATK = $(TOP)/atk -+BABL = $(TOP)/babl -+CAIRO = d:\devel\from-svn\other\cairo-1.8.4 -+GIMP = $(TOP)/gimp -+GEGL = $(TOP)/gegl -+GLIB = $(TOP)/glib -+GNOMECANVAS = $(TOP)\libgnomecanvas -+GNOMECANVAS_VER = 2.9 -+ -+# GTK+ 1.3.0, gtk-1-3-win32-production branch. Rename directory -+# to gtk+p after initial checkout from CVS. -+GTK = $(TOP)/gtk+p -+# GTK+ 2.0 -+GTK2 = $(TOP)/gtk+ -+GTKSOURCEVIEW = $(TOP)/gtksourceview -+GNOMEPRINT = $(TOP)\libgnomeprint -+GNOMEPRINT_VER = 2.8 -+LIBGLADE = $(TOP)/libglade -+LIBXML = $(TOP)/libxml-$(LIBXML_VER) -+LIBXML2 = $(TOP)/libxml2 -+#PANGO = $(TOP)/pango-1-8 -+PANGO = $(TOP)/pango -+ -+GNOMEPRINTUI = $(TOP)\libgnomeprintui -+GNOMEPRINTUI_VER = 2.2 -+ -+# Aux programs -+GLIB_GENMARSHAL = $(GLIB)/gobject/glib-genmarshal -+ -+# Stuff from other places. -+ -+# Note this was is specific to what tml happened to have on his disk -+# at some time in history. To really be able to recompile something -+# that uses for instance libjpeg, you should download a suitable -+# binary "developer" distribution of it, unpack it into some location, -+# and edit this file correspondingly. You should not take the versions -+# mentioned here too literally, use the latest version you can find, -+# or the ones the current GTK+ 2.0 for Windows uses. -+ -+#FREETYPE2 = $(TOP)/freetype2 -+GTKEXTRA = $(TOP)/gtk+extra -+GTKGLAREA = $(TOP)/gtkglarea -+#INTL = d:/devel/from-svn/other/intl-tml -+JPEG = d:/devel/from-svn/other/jpeg-6b -+LCMS = d:/devel/other/lcms-1.15 -+LIBART = $(TOP)/libart_lgpl -+LIBICONV = $(TOP)/libiconv-$(LIBICONV_VER) -+LIBXSLT = $(TOP)/libxslt -+#PNG = d:/devel/from-svn/other/lpng1224 -+RSVG = $(TOP)\librsvg -+SVG = $(TOP)\libsvg -+#TIFF = d:/devel/from-svn/other/tiff-3.7.2 -+#ZLIB = d:/devel/from-svn/other/zlib123 -+ -+# Headers from Microsoft's PlatformSDK (that aren't present in -+# mingw) are needed by a just a few packages when compiling with gcc. -+# This is just where tml has it installed. -+PLATFORMSDK = i:/src/psdk -+ -+# -+WTKIT = d:/devel/from-svn/other\wtkit126 ---- misc/pango-1.28.3/glib-mkenums.pl 2011-03-26 07:31:15.240588400 +0100 -+++ misc/build/pango-1.28.3/glib-mkenums.pl 2011-03-26 07:34:33.961882000 +0100 -@@ -1 +1,538 @@ --dummy -+#! perl.exe -+ -+use warnings; -+use File::Basename; -+use Safe; -+ -+# glib-mkenums.pl -+# Information about the current enumeration -+my $flags; # Is enumeration a bitmask? -+my $option_underscore_name; # Overriden underscore variant of the enum name -+ # for example to fix the cases we don't get the -+ # mixed-case -> underscorized transform right. -+my $option_lowercase_name; # DEPRECATED. A lower case name to use as part -+ # of the *_get_type() function, instead of the -+ # one that we guess. For instance, when an enum -+ # uses abnormal capitalization and we can not -+ # guess where to put the underscores. -+my $seenbitshift; # Have we seen bitshift operators? -+my $enum_prefix; # Prefix for this enumeration -+my $enumname; # Name for this enumeration -+my $enumshort; # $enumname without prefix -+my $enumname_prefix; # prefix of $enumname -+my $enumindex = 0; # Global enum counter -+my $firstenum = 1; # Is this the first enumeration per file? -+my @entries; # [ $name, $val ] for each entry -+my $sandbox = Safe->new; # sandbox for safe evaluation of expressions -+ -+sub parse_trigraph { -+ my $opts = shift; -+ my @opts; -+ -+ for $opt (split /\s*,\s*/, $opts) { -+ $opt =~ s/^\s*//; -+ $opt =~ s/\s*$//; -+ my ($key,$val) = $opt =~ /(\w+)(?:=(.+))?/; -+ defined $val or $val = 1; -+ push @opts, $key, $val; -+ } -+ @opts; -+} -+sub parse_entries { -+ my $file = shift; -+ my $file_name = shift; -+ my $looking_for_name = 0; -+ -+ while (<$file>) { -+ # read lines until we have no open comments -+ while (m@/\*([^*]|\*(?!/))*$@) { -+ my $new; -+ defined ($new = <$file>) || die "Unmatched comment in $ARGV"; -+ $_ .= $new; -+ } -+ # strip comments w/o options -+ s@/\*(?!<) -+ ([^*]+|\*(?!/))* -+ \*/@@gx; -+ -+ # strip newlines -+ s@\n@ @; -+ -+ # skip empty lines -+ next if m@^\s*$@; -+ -+ if ($looking_for_name) { -+ if (/^\s*(\w+)/) { -+ $enumname = $1; -+ return 1; -+ } -+ } -+ -+ # Handle include files -+ if (/^\#include\s*<([^>]*)>/ ) { -+ my $file= "../$1"; -+ open NEWFILE, $file or die "Cannot open include file $file: $!\n"; -+ -+ if (parse_entries (\*NEWFILE, $NEWFILE)) { -+ return 1; -+ } else { -+ next; -+ } -+ } -+ -+ if (/^\s*\}\s*(\w+)/) { -+ $enumname = $1; -+ $enumindex++; -+ return 1; -+ } -+ -+ if (/^\s*\}/) { -+ $enumindex++; -+ $looking_for_name = 1; -+ next; -+ } -+ -+ if (m@^\s* -+ (\w+)\s* # name -+ (?:=( # value -+ \s*\w+\s*\(.*\)\s* # macro with multiple args -+ | # OR -+ (?:[^,/]|/(?!\*))* # anything but a comma or comment -+ ))?,?\s* -+ (?:/\*< # options -+ (([^*]|\*(?!/))*) -+ >\s*\*/)?,? -+ \s*$ -+ @x) { -+ my ($name, $value, $options) = ($1,$2,$3); -+ -+ if (!defined $flags && defined $value && $value =~ /<</) { -+ $seenbitshift = 1; -+ } -+ -+ if (defined $options) { -+ my %options = parse_trigraph($options); -+ if (!defined $options{skip}) { -+ push @entries, [ $name, $value, $options{nick} ]; -+ } -+ } else { -+ push @entries, [ $name, $value ]; -+ } -+ } elsif (m@^\s*\#@) { -+ # ignore preprocessor directives -+ } else { -+ print STDERR "$0: $file_name:$.: Failed to parse `$_'\n"; -+ } -+ } -+ -+ return 0; -+} -+ -+sub version { -+ print "glib-mkenums version glib-@GLIB_VERSION@\n"; -+ print "glib-mkenums comes with ABSOLUTELY NO WARRANTY.\n"; -+ print "You may redistribute copies of glib-mkenums under the terms of\n"; -+ print "the GNU General Public License which can be found in the\n"; -+ print "GLib source package. Sources, examples and contact\n"; -+ print "information are available at http://www.gtk.org\n"; -+ exit 0; -+} -+sub usage { -+ print "Usage:\n"; -+ print " glib-mkenums [OPTION...] [FILES...]\n\n"; -+ print "Help Options:\n"; -+ print " -h, --help Show this help message\n\n"; -+ print "Utility Options:\n"; -+ print " --fhead <text> Output file header\n"; -+ print " --fprod <text> Per input file production\n"; -+ print " --ftail <text> Output file trailer\n"; -+ print " --eprod <text> Per enum text (produced prior to value itarations)\n"; -+ print " --vhead <text> Value header, produced before iterating over enum values\n"; -+ print " --vprod <text> Value text, produced for each enum value\n"; -+ print " --vtail <text> Value tail, produced after iterating over enum values\n"; -+ print " --comments <text> Comment structure\n"; -+ print " --template file Template file\n"; -+ print " -v, --version Print version informations\n\n"; -+ print "Production text substitutions:\n"; -+ print " \@EnumName\@ PrefixTheXEnum\n"; -+ print " \@enum_name\@ prefix_the_xenum\n"; -+ print " \@ENUMNAME\@ PREFIX_THE_XENUM\n"; -+ print " \@ENUMSHORT\@ THE_XENUM\n"; -+ print " \@ENUMPREFIX\@ PREFIX\n"; -+ print " \@VALUENAME\@ PREFIX_THE_XVALUE\n"; -+ print " \@valuenick\@ the-xvalue\n"; -+ print " \@valuenum\@ the integer value (limited support, Since: 2.26)\n"; -+ print " \@type\@ either enum or flags\n"; -+ print " \@Type\@ either Enum or Flags\n"; -+ print " \@TYPE\@ either ENUM or FLAGS\n"; -+ print " \@filename\@ name of current input file\n"; -+ print " \@basename\@ base name of the current input file (Since: 2.22)\n"; -+ exit 0; -+} -+ -+# production variables: -+my $fhead = ""; # output file header -+my $fprod = ""; # per input file production -+my $ftail = ""; # output file trailer -+my $eprod = ""; # per enum text (produced prior to value itarations) -+my $vhead = ""; # value header, produced before iterating over enum values -+my $vprod = ""; # value text, produced for each enum value -+my $vtail = ""; # value tail, produced after iterating over enum values -+my $comment_tmpl = ""; # comment template -+ -+sub read_template_file { -+ my ($file) = @_; -+ my %tmpl = ('file-header', $fhead, -+ 'file-production', $fprod, -+ 'file-tail', $ftail, -+ 'enumeration-production', $eprod, -+ 'value-header', $vhead, -+ 'value-production', $vprod, -+ 'value-tail', $vtail, -+ 'comment', $comment_tmpl); -+ my $in = 'junk'; -+ open (FILE, $file) || die "Can't open $file: $!\n"; -+ while (<FILE>) { -+ if (/^\/\*\*\*\s+(BEGIN|END)\s+([\w-]+)\s+\*\*\*\//) { -+ if (($in eq 'junk') && ($1 eq 'BEGIN') && (exists($tmpl{$2}))) { -+ $in = $2; -+ next; -+ } -+ elsif (($in eq $2) && ($1 eq 'END') && (exists($tmpl{$2}))) { -+ $in = 'junk'; -+ next; -+ } else { -+ die "Malformed template file $file\n"; -+ } -+ } -+ if (!($in eq 'junk')) { -+ $tmpl{$in} .= $_; -+ } -+ } -+ close (FILE); -+ if (!($in eq 'junk')) { -+ die "Malformed template file $file\n"; -+ } -+ $fhead = $tmpl{'file-header'}; -+ $fprod = $tmpl{'file-production'}; -+ $ftail = $tmpl{'file-tail'}; -+ $eprod = $tmpl{'enumeration-production'}; -+ $vhead = $tmpl{'value-header'}; -+ $vprod = $tmpl{'value-production'}; -+ $vtail = $tmpl{'value-tail'}; -+ $comment_tmpl = $tmpl{'comment'}; -+ -+ # default to C-style comments -+ $comment_tmpl = "/* \@comment\@ */" if $comment_tmpl eq ""; -+} -+ -+if (!defined $ARGV[0]) { -+ usage; -+} -+while ($_=$ARGV[0],/^-/) { -+ shift; -+ last if /^--$/; -+ if (/^--template$/) { read_template_file (shift); } -+ elsif (/^--fhead$/) { $fhead = $fhead . shift } -+ elsif (/^--fprod$/) { $fprod = $fprod . shift } -+ elsif (/^--ftail$/) { $ftail = $ftail . shift } -+ elsif (/^--eprod$/) { $eprod = $eprod . shift } -+ elsif (/^--vhead$/) { $vhead = $vhead . shift } -+ elsif (/^--vprod$/) { $vprod = $vprod . shift } -+ elsif (/^--vtail$/) { $vtail = $vtail . shift } -+ elsif (/^--comments$/) { $comment_tmpl = shift } -+ elsif (/^--help$/ || /^-h$/ || /^-\?$/) { usage; } -+ elsif (/^--version$/ || /^-v$/) { version; } -+ else { usage; } -+ last if not defined($ARGV[0]); -+} -+ -+# put auto-generation comment -+{ -+ my $comment = $comment_tmpl; -+ $comment =~ s/\@comment\@/Generated data (by glib-mkenums)/; -+ print "\n" . $comment . "\n\n"; -+} -+ -+if (length($fhead)) { -+ my $prod = $fhead; -+ my $base = basename ($ARGV[0]); -+ -+ $prod =~ s/\@filename\@/$ARGV[0]/g; -+ $prod =~ s/\@basename\@/$base/g; -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+} -+ -+while (<>) { -+ if (eof) { -+ close (ARGV); # reset line numbering -+ $firstenum = 1; # Flag to print filename at next enum -+ } -+ -+ # read lines until we have no open comments -+ while (m@/\*([^*]|\*(?!/))*$@) { -+ my $new; -+ defined ($new = <>) || die "Unmatched comment in $ARGV"; -+ $_ .= $new; -+ } -+ # strip comments w/o options -+ s@/\*(?!<) -+ ([^*]+|\*(?!/))* -+ \*/@@gx; -+ -+ if (m@^\s*typedef\s+enum\s* -+ ({)?\s* -+ (?:/\*< -+ (([^*]|\*(?!/))*) -+ >\s*\*/)? -+ \s*({)? -+ @x) { -+ if (defined $2) { -+ my %options = parse_trigraph ($2); -+ next if defined $options{skip}; -+ $enum_prefix = $options{prefix}; -+ $flags = $options{flags}; -+ $option_lowercase_name = $options{lowercase_name}; -+ $option_underscore_name = $options{underscore_name}; -+ } else { -+ $enum_prefix = undef; -+ $flags = undef; -+ $option_lowercase_name = undef; -+ $option_underscore_name = undef; -+ } -+ if (defined $option_lowercase_name) { -+ if (defined $option_underscore_name) { -+ print STDERR "$0: $ARGV:$.: lowercase_name overriden with underscore_name\n"; -+ $option_lowercase_name = undef; -+ } else { -+ print STDERR "$0: $ARGV:$.: lowercase_name is deprecated, use underscore_name\n"; -+ } -+ } -+ # Didn't have trailing '{' look on next lines -+ if (!defined $1 && !defined $4) { -+ while (<>) { -+ if (s/^\s*\{//) { -+ last; -+ } -+ } -+ } -+ -+ $seenbitshift = 0; -+ @entries = (); -+ -+ # Now parse the entries -+ parse_entries (\*ARGV, $ARGV); -+ -+ # figure out if this was a flags or enums enumeration -+ if (!defined $flags) { -+ $flags = $seenbitshift; -+ } -+ -+ # Autogenerate a prefix -+ if (!defined $enum_prefix) { -+ for (@entries) { -+ my $nick = $_->[2]; -+ if (!defined $nick) { -+ my $name = $_->[0]; -+ if (defined $enum_prefix) { -+ my $tmp = ~ ($name ^ $enum_prefix); -+ ($tmp) = $tmp =~ /(^\xff*)/; -+ $enum_prefix = $enum_prefix & $tmp; -+ } else { -+ $enum_prefix = $name; -+ } -+ } -+ } -+ if (!defined $enum_prefix) { -+ $enum_prefix = ""; -+ } else { -+ # Trim so that it ends in an underscore -+ $enum_prefix =~ s/_[^_]*$/_/; -+ } -+ } else { -+ # canonicalize user defined prefixes -+ $enum_prefix = uc($enum_prefix); -+ $enum_prefix =~ s/-/_/g; -+ $enum_prefix =~ s/(.*)([^_])$/$1$2_/; -+ } -+ -+ for $entry (@entries) { -+ my ($name,$num,$nick) = @{$entry}; -+ if (!defined $nick) { -+ ($nick = $name) =~ s/^$enum_prefix//; -+ $nick =~ tr/_/-/; -+ $nick = lc($nick); -+ @{$entry} = ($name, $num, $nick); -+ } -+ } -+ -+ -+ # Spit out the output -+ if (defined $option_underscore_name) { -+ $enumlong = uc $option_underscore_name; -+ $enumsym = lc $option_underscore_name; -+ $enumshort = $enumlong; -+ $enumshort =~ s/^[A-Z][A-Z0-9]*_//; -+ -+ $enumname_prefix = $enumlong; -+ $enumname_prefix =~ s/$enumshort$//; -+ } else { -+ # enumname is e.g. GMatchType -+ $enspace = $enumname; -+ $enspace =~ s/^([A-Z][a-z]*).*$/$1/; -+ -+ $enumshort = $enumname; -+ $enumshort =~ s/^[A-Z][a-z]*//; -+ $enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g; -+ $enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g; -+ $enumshort = uc($enumshort); -+ -+ $enumname_prefix = $enumname; -+ $enumname_prefix =~ s/^([A-Z][a-z]*).*$/$1/; -+ $enumname_prefix = uc($enumname_prefix); -+ -+ $enumlong = uc($enspace) . "_" . $enumshort; -+ $enumsym = lc($enspace) . "_" . lc($enumshort); -+ -+ if (defined($option_lowercase_name)) { -+ $enumsym = $option_lowercase_name; -+ } -+ } -+ -+ if ($firstenum) { -+ $firstenum = 0; -+ -+ if (length($fprod)) { -+ my $prod = $fprod; -+ my $base = basename ($ARGV); -+ -+ $prod =~ s/\@filename\@/$ARGV/g; -+ $prod =~ s/\@basename\@/$base/g; -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ } -+ -+ if (length($eprod)) { -+ my $prod = $eprod; -+ -+ $prod =~ s/\@enum_name\@/$enumsym/g; -+ $prod =~ s/\@EnumName\@/$enumname/g; -+ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; -+ $prod =~ s/\@ENUMNAME\@/$enumlong/g; -+ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; -+ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ -+ if (length($vhead)) { -+ my $prod = $vhead; -+ -+ $prod =~ s/\@enum_name\@/$enumsym/g; -+ $prod =~ s/\@EnumName\@/$enumname/g; -+ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; -+ $prod =~ s/\@ENUMNAME\@/$enumlong/g; -+ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; -+ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ -+ if (length($vprod)) { -+ my $prod = $vprod; -+ my $next_num = 0; -+ -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ for (@entries) { -+ my ($name,$num,$nick) = @{$_}; -+ my $tmp_prod = $prod; -+ -+ if ($prod =~ /\@valuenum\@/) { -+ # only attempt to eval the value if it is requested -+ # this prevents us from throwing errors otherwise -+ if (defined $num) { -+ # use sandboxed perl evaluation as a reasonable -+ # approximation to C constant folding -+ $num = $sandbox->reval ($num); -+ -+ # make sure it parsed to an integer -+ if (!defined $num or $num !~ /^-?\d+$/) { -+ die "Unable to parse enum value '$num'"; -+ } -+ } else { -+ $num = $next_num; -+ } -+ -+ $tmp_prod =~ s/\@valuenum\@/$num/g; -+ $next_num = $num + 1; -+ } -+ -+ $tmp_prod =~ s/\@VALUENAME\@/$name/g; -+ $tmp_prod =~ s/\@valuenick\@/$nick/g; -+ if ($flags) { $tmp_prod =~ s/\@type\@/flags/g; } else { $tmp_prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $tmp_prod =~ s/\@Type\@/Flags/g; } else { $tmp_prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $tmp_prod =~ s/\@TYPE\@/FLAGS/g; } else { $tmp_prod =~ s/\@TYPE\@/ENUM/g; } -+ chomp ($tmp_prod); -+ -+ print "$tmp_prod\n"; -+ } -+ } -+ -+ if (length($vtail)) { -+ my $prod = $vtail; -+ -+ $prod =~ s/\@enum_name\@/$enumsym/g; -+ $prod =~ s/\@EnumName\@/$enumname/g; -+ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; -+ $prod =~ s/\@ENUMNAME\@/$enumlong/g; -+ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; -+ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ } -+} -+ -+if (length($ftail)) { -+ my $prod = $ftail; -+ my $base = basename ($ARGV); -+ -+ $prod =~ s/\@filename\@/$ARGV/g; -+ $prod =~ s/\@basename\@/$base/g; -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+} -+ -+# put auto-generation comment -+{ -+ my $comment = $comment_tmpl; -+ $comment =~ s/\@comment\@/Generated data ends here/; -+ print "\n" . $comment . "\n\n"; -+} --- misc/pango-1.28.3/msvc_recommended_pragmas.h 2011-03-26 07:30:07.692848800 +0100 +++ misc/build/pango-1.28.3/msvc_recommended_pragmas.h 2011-03-26 07:34:43.524504400 +0100 @@ -1 +1,31 @@ diff --git a/reportbuilder/java/com/sun/star/report/function/metadata/makefile.mk b/reportbuilder/java/com/sun/star/report/function/metadata/makefile.mk index 9ba0c026c224..8694dec7c155 100644 --- a/reportbuilder/java/com/sun/star/report/function/metadata/makefile.mk +++ b/reportbuilder/java/com/sun/star/report/function/metadata/makefile.mk @@ -49,21 +49,18 @@ JAVAFILES := AuthorFunction.java \ TitleFunctionDescription.java \ MetaDataFunctionCategory.java -# PROPERTYFILES := $(shell @$(FIND) . -name "*.properties") -PROPERTYFILES:=$(CLASSDIR)$/$(PACKAGE)$/category.properties \ +COPYFILES := $(CLASSDIR)$/$(PACKAGE)$/category.properties \ $(CLASSDIR)$/$(PACKAGE)$/Title-Function.properties\ $(CLASSDIR)$/$(PACKAGE)$/category_en_US.properties \ $(CLASSDIR)$/$(PACKAGE)$/Author-Function.properties \ $(CLASSDIR)$/$(PACKAGE)$/Author-Function_en_US.properties \ $(CLASSDIR)$/$(PACKAGE)$/Title-Function_en_US.properties -L10NPROPERTYFILES = $(PROPERTYFILES) -ALLTAR : $(PROPERTYFILES) +ALLTAR : $(COPYFILES) # --- Targets ------------------------------------------------------ .INCLUDE : target.mk -.IF "$(WITH_LANG)"=="" -$(CLASSDIR)/$(PACKAGE)/%.properties : %.properties - @@-$(MKDIRHIER) $(@:d) - $(COMMAND_ECHO)$(COPY) $< $@ -.ENDIF +$(COPYFILES): $$(@:f) + +$(MKDIRHIER) $(CLASSDIR)$/$(PACKAGE) + +$(COPY) $< $@ + diff --git a/sal/osl/unx/util.c b/sal/osl/unx/util.c index 5ba04db56021..4a3f748c85bf 100644 --- a/sal/osl/unx/util.c +++ b/sal/osl/unx/util.c @@ -162,7 +162,7 @@ static int osl_getHWAddr(const char *ifname, char* hard_addr) * And now, the real thing: the get address */ -#ifdef SIOCGIFHWADDR +#if defined(SIOCGIFHWADDR) && !defined(SOLARIS) ret=ioctl(so, SIOCGIFHWADDR, &ifr); #else ret=ioctl(so, SIOCGIFADDR, &ifr); @@ -177,7 +177,7 @@ static int osl_getHWAddr(const char *ifname, char* hard_addr) close(so); -#ifdef SIOCGIFHWADDR +#if defined(SIOCGIFHWADDR) && !defined(SOLARIS) memcpy(hard_addr,ifr.ifr_hwaddr.sa_data,8); #else memcpy(hard_addr,ifr.ifr_ifru.ifru_addr.sa_data,8); diff --git a/sal/rtl/source/alloc_arena.c b/sal/rtl/source/alloc_arena.c index 6b57df355cad..1e2ea5a741e4 100644 --- a/sal/rtl/source/alloc_arena.c +++ b/sal/rtl/source/alloc_arena.c @@ -345,7 +345,6 @@ rtl_arena_hash_rescale ( ); #if 0 /* DBG */ - int i; for (i = 0; i < arena->m_hash_size; i++) { sal_Size k = 0; rtl_arena_segment_type ** segpp = &(arena->m_hash_table[i]); diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 4d989158952b..fc854e63ecbb 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -499,74 +499,23 @@ sal_Bool __EXPORT ScDocShell::Load( SfxMedium& rMedium ) void __EXPORT ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) { - uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = aDocument.GetVbaEventProcessor(); - if ( xVbaEvents.is() ) try + if (rHint.ISA(ScTablesHint) ) { - using namespace ::com::sun::star::script::vba::VBAEventId; - if (rHint.ISA(ScTablesHint) ) + const ScTablesHint& rScHint = static_cast< const ScTablesHint& >( rHint ); + if (rScHint.GetId() == SC_TAB_INSERTED) { - const ScTablesHint& rScHint = static_cast< const ScTablesHint& >( rHint ); - if (rScHint.GetId() == SC_TAB_INSERTED) + uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = aDocument.GetVbaEventProcessor(); + if ( xVbaEvents.is() ) try { uno::Sequence< uno::Any > aArgs( 1 ); aArgs[0] <<= rScHint.GetTab1(); - xVbaEvents->processVbaEvent( WORKBOOK_NEWSHEET, aArgs ); + xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_NEWSHEET, aArgs ); } - } - else if ( rHint.ISA( SfxEventHint ) ) - { - sal_uLong nEventId = static_cast< const SfxEventHint& >( rHint ).GetEventId(); - switch ( nEventId ) + catch( uno::Exception& ) { - case SFX_EVENT_ACTIVATEDOC: - { - uno::Sequence< uno::Any > aArgs; - xVbaEvents->processVbaEvent( WORKBOOK_ACTIVATE, aArgs ); - } - break; - case SFX_EVENT_DEACTIVATEDOC: - { - uno::Sequence< uno::Any > aArgs; - xVbaEvents->processVbaEvent( WORKBOOK_DEACTIVATE, aArgs ); - } - break; - case SFX_EVENT_OPENDOC: - { - uno::Sequence< uno::Any > aArgs; - xVbaEvents->processVbaEvent( WORKBOOK_OPEN, aArgs ); - } - break; - case SFX_EVENT_SAVEDOCDONE: - case SFX_EVENT_SAVEASDOCDONE: - case SFX_EVENT_SAVETODOCDONE: - { - uno::Sequence< uno::Any > aArgs( 1 ); - aArgs[ 0 ] <<= true; - xVbaEvents->processVbaEvent( WORKBOOK_AFTERSAVE, aArgs ); - } - break; - case SFX_EVENT_SAVEASDOCFAILED: - case SFX_EVENT_SAVEDOCFAILED: - case SFX_EVENT_SAVETODOCFAILED: - { - uno::Sequence< uno::Any > aArgs( 1 ); - aArgs[ 0 ] <<= false; - xVbaEvents->processVbaEvent( WORKBOOK_AFTERSAVE, aArgs ); - } - break; - case SFX_EVENT_CLOSEDOC: - { - // #163655# prevent event processing after model is disposed - aDocument.SetVbaEventProcessor( uno::Reference< script::vba::XVBAEventProcessor >() ); - uno::Reference< lang::XEventListener >( xVbaEvents, uno::UNO_QUERY_THROW )->disposing( lang::EventObject() ); - } - break; } } } - catch( uno::Exception& ) - { - } if (rHint.ISA(SfxSimpleHint)) // ohne Parameter { diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index d3ab32c66e81..daed78e09e82 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -104,6 +104,9 @@ using namespace com::sun::star; +// #i111553# provides the name of the VBA constant for this document type (e.g. 'ThisExcelDoc' for Calc) +#define SC_UNO_VBAGLOBNAME "VBAGlobalConstantName" + //------------------------------------------------------------------------ // alles ohne Which-ID, Map nur fuer PropertySetInfo @@ -118,6 +121,7 @@ const SfxItemPropertyMapEntry* lcl_GetDocOptPropertyMap() {MAP_CHAR_LEN(SC_UNO_AUTOCONTFOC), 0, &getBooleanCppuType(), 0, 0}, {MAP_CHAR_LEN(SC_UNO_BASICLIBRARIES), 0, &getCppuType((uno::Reference< script::XLibraryContainer >*)0), beans::PropertyAttribute::READONLY, 0}, {MAP_CHAR_LEN(SC_UNO_DIALOGLIBRARIES), 0, &getCppuType((uno::Reference< script::XLibraryContainer >*)0), beans::PropertyAttribute::READONLY, 0}, + {MAP_CHAR_LEN(SC_UNO_VBAGLOBNAME), 0, &getCppuType(static_cast< const rtl::OUString * >(0)), beans::PropertyAttribute::READONLY, 0}, {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN), PROP_UNO_CALCASSHOWN, &getBooleanCppuType(), 0, 0}, {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0, 0}, {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0, 0}, @@ -1908,6 +1912,15 @@ uno::Any SAL_CALL ScModelObj::getPropertyValue( const rtl::OUString& aPropertyNa { aRet <<= pDocShell->GetDialogContainer(); } + else if ( aString.EqualsAscii( SC_UNO_VBAGLOBNAME ) ) + { + /* #i111553# This property provides the name of the constant that + will be used to store this model in the global Basic manager. + That constant will be equivelant to 'ThisComponent' but for + each application, so e.g. a 'ThisExcelDoc' and a 'ThisWordDoc' + constant can co-exist, as required by VBA. */ + aRet <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ThisExcelDoc" ) ); + } else if ( aString.EqualsAscii( SC_UNO_RUNTIMEUID ) ) { aRet <<= getRuntimeUID(); diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx index 04d88935acfc..50623610b5b3 100644 --- a/sc/source/ui/vba/excelvbahelper.cxx +++ b/sc/source/ui/vba/excelvbahelper.cxx @@ -247,7 +247,7 @@ getViewFrame( const uno::Reference< frame::XModel >& xModel ) return NULL; } -uno::Reference< vba::XHelperInterface > +uno::Reference< XHelperInterface > getUnoSheetModuleObj( const uno::Reference< sheet::XSpreadsheet >& xSheet ) throw ( uno::RuntimeException ) { uno::Reference< beans::XPropertySet > xProps( xSheet, uno::UNO_QUERY_THROW ); @@ -258,8 +258,7 @@ getUnoSheetModuleObj( const uno::Reference< sheet::XSpreadsheet >& xSheet ) thro // are *NO* special document module objects ( of course being able to switch between vba/non vba mode at // the document in the future could fix this, especially IF the switching of the vba mode takes care to // create the special document module objects if they don't exist. - uno::Reference< XHelperInterface > xParent( ov::getUnoDocModule( sCodeName, GetDocShellFromRange( xSheet ) ), uno::UNO_QUERY ); - return xParent; + return getUnoDocModule( sCodeName, GetDocShellFromRange( xSheet ) ); } uno::Reference< XHelperInterface > diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index 290b34a949ca..fa278e527d91 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -40,6 +40,7 @@ #include <ooo/vba/excel/XlMousePointer.hpp> #include <com/sun/star/sheet/XNamedRanges.hpp> #include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <ooo/vba/XExecutableDialog.hpp> #include "vbaapplication.hxx" #include "vbaworkbooks.hxx" @@ -98,17 +99,6 @@ using namespace ::com::sun::star; uno::Any sbxToUnoValue( SbxVariable* pVar ); -class ActiveWorkbook : public ScVbaWorkbook -{ -protected: - virtual uno::Reference< frame::XModel > getModel() - { - return getCurrentExcelDoc(mxContext); - } -public: - ActiveWorkbook( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext) : ScVbaWorkbook( xParent, xContext ){} -}; - // ============================================================================ /** Global application settings shared by all open workbooks. */ @@ -215,47 +205,15 @@ ScVbaApplication::hasProperty( const ::rtl::OUString& Name ) throw(uno::RuntimeE uno::Reference< excel::XWorkbook > ScVbaApplication::getActiveWorkbook() throw (uno::RuntimeException) { - uno::Reference< excel::XWorkbook > xWrkbk; - ScDocShell* pShell = excel::getDocShell( getCurrentExcelDoc( mxContext ) ); - if ( pShell ) - { - String aName; - if ( pShell->GetDocument() ) - { - aName = pShell->GetDocument()->GetCodeName(); - xWrkbk.set( getUnoDocModule( aName, pShell ), uno::UNO_QUERY ); - // fallback ( e.g. it's possible a new document was created via the api ) - // in that case the document will not have the appropriate Document Modules - // #TODO #FIXME ( needs to be fixes as part of providing support for an overall document - // vba mode etc. ) - if ( !xWrkbk.is() ) - return new ActiveWorkbook( this, mxContext ); - } - } - return xWrkbk; + // will throw if active document is not in VBA compatibility mode (no object for codename) + return uno::Reference< excel::XWorkbook >( getVBADocument( getCurrentExcelDoc( mxContext ) ), uno::UNO_QUERY_THROW ); } uno::Reference< excel::XWorkbook > SAL_CALL ScVbaApplication::getThisWorkbook() throw (uno::RuntimeException) { - uno::Reference< excel::XWorkbook > xWrkbk; - ScDocShell* pShell = excel::getDocShell( getThisExcelDoc( mxContext ) ); - if ( pShell ) - { - String aName; - if ( pShell->GetDocument() ) - { - aName = pShell->GetDocument()->GetCodeName(); - xWrkbk.set( getUnoDocModule( aName, pShell ), uno::UNO_QUERY ); - // fallback ( e.g. it's possible a new document was created via the api ) - // in that case the document will not have the appropriate Document Modules - // #TODO #FIXME ( needs to be fixes as part of providing support for an overall document - // vba mode etc. ) - if ( !xWrkbk.is() ) - return new ActiveWorkbook( this, mxContext ); - } - } - return xWrkbk; + // should never throw as this model is in VBA compatibility mode + return uno::Reference< excel::XWorkbook >( getVBADocument( getThisExcelDoc( mxContext ) ), uno::UNO_QUERY_THROW ); } uno::Reference< XAssistant > SAL_CALL @@ -343,17 +301,8 @@ ScVbaApplication::Workbooks( const uno::Any& aIndex ) throw (uno::RuntimeExcepti uno::Any SAL_CALL ScVbaApplication::Worksheets( const uno::Any& aIndex ) throw (uno::RuntimeException) { - uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_QUERY ); - uno::Any result; - if ( xWorkbook.is() ) - result = xWorkbook->Worksheets( aIndex ); - - else - // Fixme - check if this is reasonable/desired behavior - throw uno::RuntimeException( rtl::OUString::createFromAscii( - "No ActiveWorkBook available" ), uno::Reference< uno::XInterface >() ); - - return result; + uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_SET_THROW ); + return xWorkbook->Worksheets( aIndex ); } uno::Any SAL_CALL @@ -384,10 +333,10 @@ ScVbaApplication::Dialogs( const uno::Any &aIndex ) throw (uno::RuntimeException uno::Reference< excel::XWindow > SAL_CALL ScVbaApplication::getActiveWindow() throw (uno::RuntimeException) { - // #FIXME sofar can't determine Parent uno::Reference< frame::XModel > xModel = getCurrentDocument(); - ScVbaWindow* pWin = new ScVbaWindow( uno::Reference< XHelperInterface >(), mxContext, xModel ); - uno::Reference< excel::XWindow > xWin( pWin ); + uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); + uno::Reference< XHelperInterface > xParent( getActiveWorkbook(), uno::UNO_QUERY_THROW ); + uno::Reference< excel::XWindow > xWin( new ScVbaWindow( xParent, mxContext, xModel, xController ) ); return xWin; } @@ -792,37 +741,36 @@ rtl::OUString ScVbaApplication::getOfficePath( const rtl::OUString& _sPathType ) } return sRetPath; } + void SAL_CALL -ScVbaApplication::setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ) throw (script::BasicErrorException, uno::RuntimeException) +ScVbaApplication::setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ) throw (uno::RuntimeException) { uno::Reference< beans::XPropertySet > xProps = lcl_getPathSettingsService( mxContext ); rtl::OUString aURL; osl::FileBase::getFileURLFromSystemPath( DefaultFilePath, aURL ); - xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work")), uno::makeAny( aURL ) ); - - + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work")), uno::Any( aURL ) ); } ::rtl::OUString SAL_CALL -ScVbaApplication::getDefaultFilePath( ) throw (script::BasicErrorException, uno::RuntimeException) +ScVbaApplication::getDefaultFilePath() throw (uno::RuntimeException) { return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work"))); } ::rtl::OUString SAL_CALL -ScVbaApplication::LibraryPath( ) throw (script::BasicErrorException, uno::RuntimeException) +ScVbaApplication::getLibraryPath() throw (uno::RuntimeException) { return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Basic"))); } ::rtl::OUString SAL_CALL -ScVbaApplication::TemplatesPath( ) throw (script::BasicErrorException, uno::RuntimeException) +ScVbaApplication::getTemplatesPath() throw (uno::RuntimeException) { return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Template"))); } ::rtl::OUString SAL_CALL -ScVbaApplication::PathSeparator( ) throw (script::BasicErrorException, uno::RuntimeException) +ScVbaApplication::getPathSeparator() throw (uno::RuntimeException) { static rtl::OUString sPathSep( RTL_CONSTASCII_USTRINGPARAM( FILE_PATH_SEPERATOR ) ); return sPathSep; @@ -1174,6 +1122,40 @@ ScVbaApplication::Caller( const uno::Any& /*aIndex*/ ) throw ( uno::RuntimeExcep return aRet; } +uno::Any SAL_CALL ScVbaApplication::GetOpenFilename( + const uno::Any& rFileFilter, const uno::Any& rFilterIndex, const uno::Any& rTitle, + const uno::Any& rButtonText, const uno::Any& rMultiSelect ) throw (uno::RuntimeException) +{ + uno::Sequence< uno::Any > aArgs( 6 ); + aArgs[ 0 ] <<= getThisExcelDoc( mxContext ); + aArgs[ 1 ] = rFileFilter; + aArgs[ 2 ] = rFilterIndex; + aArgs[ 3 ] = rTitle; + aArgs[ 4 ] = rButtonText; + aArgs[ 5 ] = rMultiSelect; + uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_SET_THROW ); + uno::Reference< XExecutableDialog > xFilePicker( xFactory->createInstanceWithArgumentsAndContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.OpenFilePicker" ) ), aArgs, mxContext ), uno::UNO_QUERY_THROW ); + return xFilePicker->execute(); +} + +uno::Any SAL_CALL ScVbaApplication::GetSaveAsFilename( + const uno::Any& rInitialFileName, const uno::Any& rFileFilter, const uno::Any& rFilterIndex, + const uno::Any& rTitle, const uno::Any& rButtonText ) throw (uno::RuntimeException) +{ + uno::Sequence< uno::Any > aArgs( 6 ); + aArgs[ 0 ] <<= getThisExcelDoc( mxContext ); + aArgs[ 1 ] = rInitialFileName; + aArgs[ 2 ] = rFileFilter; + aArgs[ 3 ] = rFilterIndex; + aArgs[ 4 ] = rTitle; + aArgs[ 5 ] = rButtonText; + uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_SET_THROW ); + uno::Reference< XExecutableDialog > xFilePicker( xFactory->createInstanceWithArgumentsAndContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.SaveAsFilePicker" ) ), aArgs, mxContext ), uno::UNO_QUERY_THROW ); + return xFilePicker->execute(); +} + uno::Reference< frame::XModel > ScVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException) { diff --git a/sc/source/ui/vba/vbaapplication.hxx b/sc/source/ui/vba/vbaapplication.hxx index bb696c967a37..b09fb66a8f91 100644 --- a/sc/source/ui/vba/vbaapplication.hxx +++ b/sc/source/ui/vba/vbaapplication.hxx @@ -73,11 +73,11 @@ public: virtual sal_Bool SAL_CALL hasProperty(const rtl::OUString& Name) throw(css::uno::RuntimeException); // XApplication - virtual ::rtl::OUString SAL_CALL PathSeparator( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); - virtual void SAL_CALL setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ) throw (css::script::BasicErrorException, css::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getDefaultFilePath( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL LibraryPath( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL TemplatesPath( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getDefaultFilePath() throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getPathSeparator() throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getLibraryPath() throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getTemplatesPath() throw (css::uno::RuntimeException); virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); virtual sal_Bool SAL_CALL getDisplayAlerts() throw (css::uno::RuntimeException); @@ -120,6 +120,8 @@ public: virtual void SAL_CALL Volatile( const css::uno::Any& Volatile ) throw (css::uno::RuntimeException ); virtual void SAL_CALL DoEvents() throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL Caller( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL GetOpenFilename( const css::uno::Any& rFileFilter, const css::uno::Any& rFilterIndex, const css::uno::Any& rTitle, const css::uno::Any& rButtonText, const css::uno::Any& rMultiSelect ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL GetSaveAsFilename( const css::uno::Any& rInitialFileName, const css::uno::Any& rFileFilter, const css::uno::Any& rFilterIndex, const css::uno::Any& rTitle, const css::uno::Any& rButtonText ) throw (css::uno::RuntimeException); // XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index 6ea807a16eae..e96b2d001e75 100755 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -27,21 +27,22 @@ #include "vbaeventshelper.hxx" +#include <com/sun/star/awt/XTopWindow.hpp> +#include <com/sun/star/awt/XTopWindowListener.hpp> #include <com/sun/star/awt/XWindowListener.hpp> #include <com/sun/star/frame/XBorderResizeListener.hpp> #include <com/sun/star/frame/XControllerBorder.hpp> +#include <com/sun/star/script/ModuleType.hpp> #include <com/sun/star/script/vba/VBAEventId.hpp> #include <com/sun/star/sheet/XCellRangeAddressable.hpp> #include <com/sun/star/sheet/XSheetCellRangeContainer.hpp> #include <com/sun/star/table/XCellRange.hpp> #include <com/sun/star/util/XChangesListener.hpp> #include <com/sun/star/util/XChangesNotifier.hpp> -#include <com/sun/star/util/XCloseListener.hpp> - -#include <ooo/vba/excel/XApplication.hpp> #include <cppuhelper/implbase4.hxx> #include <toolkit/unohlp.hxx> +#include <unotools/eventcfg.hxx> #include <vbahelper/helperdecl.hxx> #include <vcl/svapp.hxx> #include <vcl/window.hxx> @@ -54,6 +55,8 @@ using namespace ::com::sun::star; using namespace ::com::sun::star::script::vba::VBAEventId; using namespace ::ooo::vba; +using ::rtl::OUString; + // ============================================================================ namespace { @@ -65,9 +68,13 @@ SCTAB lclGetTabFromArgs( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nInde VbaEventsHelperBase::checkArgument( rArgs, nIndex ); // first try to extract a sheet index - SCTAB nTab = -1; + sal_Int32 nTab = -1; if( rArgs[ nIndex ] >>= nTab ) - return nTab; + { + if( (nTab < 0) || (nTab > MAXTAB) ) + throw lang::IllegalArgumentException(); + return static_cast< SCTAB >( nTab ); + } // try VBA Range object uno::Reference< excel::XRange > xVbaRange = getXSomethingFromArgs< excel::XRange >( rArgs, nIndex ); @@ -97,231 +104,271 @@ SCTAB lclGetTabFromArgs( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nInde throw lang::IllegalArgumentException(); } +/** Returns the AWT container window of the passed controller. */ +uno::Reference< awt::XWindow > lclGetWindowForController( const uno::Reference< frame::XController >& rxController ) +{ + if( rxController.is() ) try + { + uno::Reference< frame::XFrame > xFrame( rxController->getFrame(), uno::UNO_SET_THROW ); + return xFrame->getContainerWindow(); + } + catch( uno::Exception& ) + { + } + return 0; +} + } // namespace // ============================================================================ -typedef ::cppu::WeakImplHelper4< - awt::XWindowListener, util::XCloseListener, frame::XBorderResizeListener, util::XChangesListener > ScVbaEventsListener_BASE; +typedef ::cppu::WeakImplHelper4< awt::XTopWindowListener, awt::XWindowListener, frame::XBorderResizeListener, util::XChangesListener > ScVbaEventListener_BASE; // This class is to process Workbook window related event -class ScVbaEventsListener : public ScVbaEventsListener_BASE +class ScVbaEventListener : public ScVbaEventListener_BASE { public : - ScVbaEventsListener( ScVbaEventsHelper& rVbaEvents, const uno::Reference< frame::XModel >& rxModel, ScDocShell* pDocShell ); - virtual ~ScVbaEventsListener(); - - void startListening(); - void stopListening(); + ScVbaEventListener( ScVbaEventsHelper& rVbaEvents, const uno::Reference< frame::XModel >& rxModel, ScDocShell* pDocShell ); + virtual ~ScVbaEventListener(); + + /** Starts listening to the passed document controller. */ + void startControllerListening( const uno::Reference< frame::XController >& rxController ); + /** Stops listening to the passed document controller. */ + void stopControllerListening( const uno::Reference< frame::XController >& rxController ); + + // XTopWindowListener + virtual void SAL_CALL windowOpened( const lang::EventObject& rEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowClosing( const lang::EventObject& rEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowClosed( const lang::EventObject& rEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowMinimized( const lang::EventObject& rEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowNormalized( const lang::EventObject& rEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowActivated( const lang::EventObject& rEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowDeactivated( const lang::EventObject& rEvent ) throw (uno::RuntimeException); // XWindowListener - virtual void SAL_CALL windowResized( const awt::WindowEvent& aEvent ) throw (uno::RuntimeException); - virtual void SAL_CALL windowMoved( const awt::WindowEvent& aEvent ) throw (uno::RuntimeException); - virtual void SAL_CALL windowShown( const lang::EventObject& aEvent ) throw (uno::RuntimeException); - virtual void SAL_CALL windowHidden( const lang::EventObject& aEvent ) throw (uno::RuntimeException); - virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw (uno::RuntimeException); - - // XCloseListener - virtual void SAL_CALL queryClosing( const lang::EventObject& Source, ::sal_Bool GetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException); - virtual void SAL_CALL notifyClosing( const lang::EventObject& Source ) throw (uno::RuntimeException); + virtual void SAL_CALL windowResized( const awt::WindowEvent& rEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowMoved( const awt::WindowEvent& rEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowShown( const lang::EventObject& rEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowHidden( const lang::EventObject& rEvent ) throw (uno::RuntimeException); // XBorderResizeListener - virtual void SAL_CALL borderWidthsChanged( const uno::Reference< uno::XInterface >& aObject, const frame::BorderWidths& aNewSize ) throw (uno::RuntimeException); + virtual void SAL_CALL borderWidthsChanged( const uno::Reference< uno::XInterface >& rSource, const frame::BorderWidths& aNewSize ) throw (uno::RuntimeException); // XChangesListener - virtual void SAL_CALL changesOccurred( const util::ChangesEvent& aEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL changesOccurred( const util::ChangesEvent& rEvent ) throw (uno::RuntimeException); + + // XEventListener + virtual void SAL_CALL disposing( const lang::EventObject& rEvent ) throw (uno::RuntimeException); private: - uno::Reference< frame::XFrame > getFrame(); - uno::Reference< awt::XWindow > getContainerWindow(); - bool isMouseReleased(); - DECL_LINK( fireResizeMacro, void* ); + /** Starts listening to the document model. */ + void startModelListening(); + /** Stops listening to the document model. */ + void stopModelListening(); + + /** Returns the controller for the passed VCL window. */ + uno::Reference< frame::XController > getControllerForWindow( Window* pWindow ) const; + + /** Calls the Workbook_Window[Activate|Deactivate] event handler. */ + void processWindowActivateEvent( Window* pWindow, bool bActivate ); + /** Posts a Workbook_WindowResize user event. */ + void postWindowResizeEvent( Window* pWindow ); + /** Callback link for Application::PostUserEvent(). */ + DECL_LINK( processWindowResizeEvent, Window* ); private: - ::osl::Mutex maMutex; - ScVbaEventsHelper& mrVbaEvents; + typedef ::std::map< Window*, uno::Reference< frame::XController > > WindowControllerMap; + + ::osl::Mutex maMutex; + ScVbaEventsHelper& mrVbaEvents; uno::Reference< frame::XModel > mxModel; - ScDocShell* mpDocShell; - bool mbWindowResized; - bool mbBorderChanged; - bool mbDisposed; + ScDocShell* mpDocShell; + WindowControllerMap maControllers; /// Maps VCL top windows to their controllers. + Window* mpActiveWindow; /// Currently activated window, to prevent multiple (de)activation. + bool mbWindowResized; /// True = window resize system event processed. + bool mbBorderChanged; /// True = borders changed system event processed. + bool mbDisposed; }; // ---------------------------------------------------------------------------- -ScVbaEventsListener::ScVbaEventsListener( ScVbaEventsHelper& rVbaEvents, const uno::Reference< frame::XModel >& rxModel, ScDocShell* pDocShell ) : +ScVbaEventListener::ScVbaEventListener( ScVbaEventsHelper& rVbaEvents, const uno::Reference< frame::XModel >& rxModel, ScDocShell* pDocShell ) : mrVbaEvents( rVbaEvents ), mxModel( rxModel ), mpDocShell( pDocShell ), + mpActiveWindow( 0 ), mbWindowResized( false ), mbBorderChanged( false ), mbDisposed( !rxModel.is() ) { - OSL_TRACE( "ScVbaEventsListener::ScVbaEventsListener( 0x%x ) - ctor ", this ); + if( !mxModel.is() ) + return; + + startModelListening(); + try + { + uno::Reference< frame::XController > xController( mxModel->getCurrentController(), uno::UNO_QUERY_THROW ); + startControllerListening( xController ); + } + catch( uno::Exception& ) + { + } } -ScVbaEventsListener::~ScVbaEventsListener() +ScVbaEventListener::~ScVbaEventListener() { - OSL_TRACE( "ScVbaEventsListener::~ScVbaEventsListener( 0x%x ) - dtor ", this ); - stopListening(); } -void ScVbaEventsListener::startListening() +void ScVbaEventListener::startControllerListening( const uno::Reference< frame::XController >& rxController ) { - if( !mbDisposed ) + ::osl::MutexGuard aGuard( maMutex ); + + uno::Reference< awt::XWindow > xWindow = lclGetWindowForController( rxController ); + if( xWindow.is() ) + try { xWindow->addWindowListener( this ); } catch( uno::Exception& ) {} + + uno::Reference< awt::XTopWindow > xTopWindow( xWindow, uno::UNO_QUERY ); + if( xTopWindow.is() ) + try { xTopWindow->addTopWindowListener( this ); } catch( uno::Exception& ) {} + + uno::Reference< frame::XControllerBorder > xControllerBorder( rxController, uno::UNO_QUERY ); + if( xControllerBorder.is() ) + try { xControllerBorder->addBorderResizeListener( this ); } catch( uno::Exception& ) {} + + if( Window* pWindow = VCLUnoHelper::GetWindow( xWindow ) ) + maControllers[ pWindow ] = rxController; +} + +void ScVbaEventListener::stopControllerListening( const uno::Reference< frame::XController >& rxController ) +{ + ::osl::MutexGuard aGuard( maMutex ); + + uno::Reference< awt::XWindow > xWindow = lclGetWindowForController( rxController ); + if( xWindow.is() ) + try { xWindow->removeWindowListener( this ); } catch( uno::Exception& ) {} + + uno::Reference< awt::XTopWindow > xTopWindow( xWindow, uno::UNO_QUERY ); + if( xTopWindow.is() ) + try { xTopWindow->removeTopWindowListener( this ); } catch( uno::Exception& ) {} + + uno::Reference< frame::XControllerBorder > xControllerBorder( rxController, uno::UNO_QUERY ); + if( xControllerBorder.is() ) + try { xControllerBorder->removeBorderResizeListener( this ); } catch( uno::Exception& ) {} + + if( Window* pWindow = VCLUnoHelper::GetWindow( xWindow ) ) { - // add window listener - try - { - uno::Reference< awt::XWindow > xWindow( getContainerWindow(), uno::UNO_QUERY_THROW ); - xWindow->addWindowListener( this ); - } - catch( uno::Exception& ) - { - } - // add close listener - try - { - uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( mxModel, uno::UNO_QUERY_THROW ); - xCloseBroadcaster->addCloseListener( this ); - } - catch( uno::Exception& ) - { - } - // add Border resize listener - try - { - uno::Reference< frame::XControllerBorder > xControllerBorder( mxModel->getCurrentController(), uno::UNO_QUERY_THROW ); - xControllerBorder->addBorderResizeListener( this ); - } - catch( uno::Exception& ) - { - } - // add content change listener - try - { - uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, uno::UNO_QUERY_THROW ); - xChangesNotifier->addChangesListener( this ); - } - catch( uno::Exception& ) - { - } + maControllers.erase( pWindow ); + if( pWindow == mpActiveWindow ) + mpActiveWindow = 0; } } -void ScVbaEventsListener::stopListening() +void SAL_CALL ScVbaEventListener::windowOpened( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException) +{ +} + +void SAL_CALL ScVbaEventListener::windowClosing( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException) { +} + +void SAL_CALL ScVbaEventListener::windowClosed( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException) +{ +} + +void SAL_CALL ScVbaEventListener::windowMinimized( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException) +{ +} + +void SAL_CALL ScVbaEventListener::windowNormalized( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException) +{ +} + +void SAL_CALL ScVbaEventListener::windowActivated( const lang::EventObject& rEvent ) throw (uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( maMutex ); + if( !mbDisposed ) { - try - { - uno::Reference< awt::XWindow > xWindow( getContainerWindow(), uno::UNO_QUERY_THROW ); - xWindow->removeWindowListener( this ); - } - catch( uno::Exception& ) - { - } - try - { - uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( mxModel, uno::UNO_QUERY_THROW ); - xCloseBroadcaster->removeCloseListener( this ); - } - catch( uno::Exception& ) - { - } - try - { - uno::Reference< frame::XControllerBorder > xControllerBorder( mxModel->getCurrentController(), uno::UNO_QUERY_THROW ); - xControllerBorder->removeBorderResizeListener( this ); - } - catch( uno::Exception& ) - { - } - try - { - uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, uno::UNO_QUERY_THROW ); - xChangesNotifier->removeChangesListener( this ); - } - catch( uno::Exception& ) + uno::Reference< awt::XWindow > xWindow( rEvent.Source, uno::UNO_QUERY ); + Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); + OSL_TRACE( "ScVbaEventListener::windowActivated - pWindow = 0x%x, mpActiveWindow = 0x%x", pWindow, mpActiveWindow ); + // do not fire activation event multiple time for the same window + if( pWindow && (pWindow != mpActiveWindow) ) { + // if another window is active, fire deactivation event first + if( mpActiveWindow ) + processWindowActivateEvent( mpActiveWindow, false ); + // fire activation event for the new window + processWindowActivateEvent( pWindow, true ); + mpActiveWindow = pWindow; } } - mbDisposed = true; } -void SAL_CALL ScVbaEventsListener::windowResized( const awt::WindowEvent& /*aEvent*/ ) throw ( uno::RuntimeException ) +void SAL_CALL ScVbaEventListener::windowDeactivated( const lang::EventObject& rEvent ) throw (uno::RuntimeException) { ::osl::MutexGuard aGuard( maMutex ); - // Workbook_window_resize event - mbWindowResized = true; - if( !mbDisposed && mbBorderChanged ) + + if( !mbDisposed ) { - if( /*Window* pWindow =*/ VCLUnoHelper::GetWindow( getContainerWindow() ) ) - { - mbBorderChanged = mbWindowResized = false; - acquire(); // ensure we don't get deleted before the event is handled - Application::PostUserEvent( LINK( this, ScVbaEventsListener, fireResizeMacro ), 0 ); - } + uno::Reference< awt::XWindow > xWindow( rEvent.Source, uno::UNO_QUERY ); + Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); + OSL_TRACE( "ScVbaEventListener::windowDeactivated - pWindow = 0x%x, mpActiveWindow = 0x%x", pWindow, mpActiveWindow ); + // do not fire the deactivation event, if the window is not active (prevent multiple deactivation) + if( pWindow && (pWindow == mpActiveWindow) ) + processWindowActivateEvent( pWindow, false ); + // forget pointer to the active window + mpActiveWindow = 0; } } -void SAL_CALL ScVbaEventsListener::windowMoved( const awt::WindowEvent& /*aEvent*/ ) throw ( uno::RuntimeException ) +void SAL_CALL ScVbaEventListener::windowResized( const awt::WindowEvent& rEvent ) throw (uno::RuntimeException) { - // not interest this time -} + ::osl::MutexGuard aGuard( maMutex ); -void SAL_CALL ScVbaEventsListener::windowShown( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException ) -{ - // not interest this time + mbWindowResized = true; + if( !mbDisposed && mbBorderChanged ) + { + uno::Reference< awt::XWindow > xWindow( rEvent.Source, uno::UNO_QUERY ); + postWindowResizeEvent( VCLUnoHelper::GetWindow( xWindow ) ); + } } -void SAL_CALL ScVbaEventsListener::windowHidden( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException ) +void SAL_CALL ScVbaEventListener::windowMoved( const awt::WindowEvent& /*rEvent*/ ) throw (uno::RuntimeException) { - // not interest this time } -void SAL_CALL ScVbaEventsListener::disposing( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException ) +void SAL_CALL ScVbaEventListener::windowShown( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException) { - ::osl::MutexGuard aGuard( maMutex ); - OSL_TRACE( "ScVbaEventsListener::disposing( 0x%x )", this ); - mbDisposed = true; } -void SAL_CALL ScVbaEventsListener::queryClosing( const lang::EventObject& /*Source*/, sal_Bool /*GetsOwnership*/ ) throw (util::CloseVetoException, uno::RuntimeException) +void SAL_CALL ScVbaEventListener::windowHidden( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException) { - // it can cancel the close, but need to throw a CloseVetoException, and it will be transmit to caller. } -void SAL_CALL ScVbaEventsListener::notifyClosing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException) +void SAL_CALL ScVbaEventListener::borderWidthsChanged( const uno::Reference< uno::XInterface >& rSource, const frame::BorderWidths& /*aNewSize*/ ) throw (uno::RuntimeException) { ::osl::MutexGuard aGuard( maMutex ); - stopListening(); -} -void SAL_CALL ScVbaEventsListener::borderWidthsChanged( const uno::Reference< uno::XInterface >& /*aObject*/, const frame::BorderWidths& /*aNewSize*/ ) throw (uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( maMutex ); - // work with WindowResized event to guard Window Resize event. mbBorderChanged = true; if( !mbDisposed && mbWindowResized ) { - if( /*Window* pWindow =*/ VCLUnoHelper::GetWindow( getContainerWindow() ) ) - { - mbWindowResized = mbBorderChanged = false; - acquire(); // ensure we don't get deleted before the timer fires. - Application::PostUserEvent( LINK( this, ScVbaEventsListener, fireResizeMacro ), 0 ); - } + uno::Reference< frame::XController > xController( rSource, uno::UNO_QUERY ); + uno::Reference< awt::XWindow > xWindow = lclGetWindowForController( xController ); + postWindowResizeEvent( VCLUnoHelper::GetWindow( xWindow ) ); } } -void SAL_CALL ScVbaEventsListener::changesOccurred( const util::ChangesEvent& aEvent ) throw (uno::RuntimeException) +void SAL_CALL ScVbaEventListener::changesOccurred( const util::ChangesEvent& rEvent ) throw (uno::RuntimeException) { - sal_Int32 nCount = aEvent.Changes.getLength(); - if( nCount == 0 ) + ::osl::MutexGuard aGuard( maMutex ); + + sal_Int32 nCount = rEvent.Changes.getLength(); + if( mbDisposed || !mpDocShell || (nCount == 0) ) return; - util::ElementChange aChange = aEvent.Changes[ 0 ]; - rtl::OUString sOperation; + util::ElementChange aChange = rEvent.Changes[ 0 ]; + OUString sOperation; aChange.Accessor >>= sOperation; if( !sOperation.equalsIgnoreAsciiCaseAscii("cell-change") ) return; @@ -334,7 +381,7 @@ void SAL_CALL ScVbaEventsListener::changesOccurred( const util::ChangesEvent& aE { uno::Sequence< uno::Any > aArgs( 1 ); aArgs[0] <<= xRangeObj; - mrVbaEvents.processVbaEvent( WORKSHEET_CHANGE, aArgs ); + mrVbaEvents.processVbaEventNoThrow( WORKSHEET_CHANGE, aArgs ); } return; } @@ -342,7 +389,7 @@ void SAL_CALL ScVbaEventsListener::changesOccurred( const util::ChangesEvent& aE ScRangeList aRangeList; for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex ) { - aChange = aEvent.Changes[ nIndex ]; + aChange = rEvent.Changes[ nIndex ]; aChange.Accessor >>= sOperation; uno::Reference< table::XCellRange > xRangeObj; aChange.ReplacedElement >>= xRangeObj; @@ -358,62 +405,117 @@ void SAL_CALL ScVbaEventsListener::changesOccurred( const util::ChangesEvent& aE } } - if( (aRangeList.Count() > 0) && mpDocShell ) + if( aRangeList.Count() > 0 ) { uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( mpDocShell, aRangeList ) ); uno::Sequence< uno::Any > aArgs(1); aArgs[0] <<= xRanges; - mrVbaEvents.processVbaEvent( WORKSHEET_CHANGE, aArgs ); + mrVbaEvents.processVbaEventNoThrow( WORKSHEET_CHANGE, aArgs ); } } -// ---------------------------------------------------------------------------- +void SAL_CALL ScVbaEventListener::disposing( const lang::EventObject& rEvent ) throw (uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( maMutex ); + + uno::Reference< frame::XModel > xModel( rEvent.Source, uno::UNO_QUERY ); + if( xModel.is() ) + { + OSL_ENSURE( xModel.get() == mxModel.get(), "ScVbaEventListener::disposing - disposing from unknown model" ); + stopModelListening(); + mbDisposed = true; + return; + } + + uno::Reference< frame::XController > xController( rEvent.Source, uno::UNO_QUERY ); + if( xController.is() ) + { + stopControllerListening( xController ); + return; + } +} -uno::Reference< frame::XFrame > ScVbaEventsListener::getFrame() +// private -------------------------------------------------------------------- + +void ScVbaEventListener::startModelListening() { - if( !mbDisposed && mxModel.is() ) try + try { - uno::Reference< frame::XController > xController( mxModel->getCurrentController(), uno::UNO_QUERY_THROW ); - return xController->getFrame(); + uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, uno::UNO_QUERY_THROW ); + xChangesNotifier->addChangesListener( this ); } catch( uno::Exception& ) { } - return uno::Reference< frame::XFrame >(); } -uno::Reference< awt::XWindow > ScVbaEventsListener::getContainerWindow() +void ScVbaEventListener::stopModelListening() { try { - uno::Reference< frame::XFrame > xFrame( getFrame(), uno::UNO_SET_THROW ); - return xFrame->getContainerWindow(); + uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, uno::UNO_QUERY_THROW ); + xChangesNotifier->removeChangesListener( this ); } catch( uno::Exception& ) { } - return uno::Reference< awt::XWindow >(); } -bool ScVbaEventsListener::isMouseReleased() +uno::Reference< frame::XController > ScVbaEventListener::getControllerForWindow( Window* pWindow ) const { - if( Window* pWindow = VCLUnoHelper::GetWindow( getContainerWindow() ) ) + WindowControllerMap::const_iterator aIt = maControllers.find( pWindow ); + return (aIt == maControllers.end()) ? uno::Reference< frame::XController >() : aIt->second; +} + +void ScVbaEventListener::processWindowActivateEvent( Window* pWindow, bool bActivate ) +{ + uno::Reference< frame::XController > xController = getControllerForWindow( pWindow ); + if( xController.is() ) { - Window::PointerState aPointerState = pWindow->GetPointerState(); - return (aPointerState.mnState & ( MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT )) == 0; + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= xController; + mrVbaEvents.processVbaEventNoThrow( bActivate ? WORKBOOK_WINDOWACTIVATE : WORKBOOK_WINDOWDEACTIVATE, aArgs ); } - return false; } -IMPL_LINK( ScVbaEventsListener, fireResizeMacro, void*, EMPTYARG ) +void ScVbaEventListener::postWindowResizeEvent( Window* pWindow ) { - if( !mbDisposed && isMouseReleased() ) try + // check that the passed window is still alive (it must be registered in maControllers) + if( pWindow && (maControllers.count( pWindow ) > 0) ) { - mrVbaEvents.processVbaEvent( WORKBOOK_WINDOWRESIZE, uno::Sequence< uno::Any >() ); + mbWindowResized = mbBorderChanged = false; + acquire(); // ensure we don't get deleted before the timer fires + Application::PostUserEvent( LINK( this, ScVbaEventListener, processWindowResizeEvent ), pWindow ); } - catch( uno::Exception& ) +} + +IMPL_LINK( ScVbaEventListener, processWindowResizeEvent, Window*, EMPTYARG pWindow ) +{ + ::osl::MutexGuard aGuard( maMutex ); + + /* Check that the passed window is still alive (it must be registered in + maControllers). While closing a document, postWindowResizeEvent() may + be called on the last window which posts a user event via + Application::PostUserEvent to call this event handler. VCL will trigger + the handler some time later. Sometimes, the window gets deleted before. + This is handled via the disposing() function which removes the window + pointer from the member maControllers. Thus, checking whether + maControllers contains pWindow ensures that the window is still alive. */ + if( !mbDisposed && pWindow && (maControllers.count( pWindow ) > 0) ) { - // #163419# do not throw exceptions into application core + // do not fire event unless all mouse buttons have been released + Window::PointerState aPointerState = pWindow->GetPointerState(); + if( (aPointerState.mnState & (MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT)) == 0 ) + { + uno::Reference< frame::XController > xController = getControllerForWindow( pWindow ); + if( xController.is() ) + { + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= xController; + // #163419# do not throw exceptions into application core + mrVbaEvents.processVbaEventNoThrow( WORKBOOK_WINDOWRESIZE, aArgs ); + } + } } release(); return 0; @@ -431,19 +533,19 @@ ScVbaEventsHelper::ScVbaEventsHelper( const uno::Sequence< uno::Any >& rArgs, co if( !mxModel.is() || !mpDocShell || !mpDoc ) return; -#define REGISTER_EVENT( eventid, eventname, type, cancelindex, worksheet ) \ - registerEventHandler( eventid, eventname, type, cancelindex, uno::Any( worksheet ) ) - +#define REGISTER_EVENT( eventid, moduletype, classname, eventname, cancelindex, worksheet ) \ + registerEventHandler( eventid, moduletype, classname "_" eventname, cancelindex, uno::Any( worksheet ) ) +#define REGISTER_AUTO_EVENT( eventid, eventname ) \ + REGISTER_EVENT( AUTO_##eventid, script::ModuleType::NORMAL, "Auto", eventname, -1, false ) #define REGISTER_WORKBOOK_EVENT( eventid, eventname, cancelindex ) \ - REGISTER_EVENT( WORKBOOK_##eventid, "Workbook_" eventname, EVENTHANDLER_DOCUMENT, cancelindex, false ) - + REGISTER_EVENT( WORKBOOK_##eventid, script::ModuleType::DOCUMENT, "Workbook", eventname, cancelindex, false ) #define REGISTER_WORKSHEET_EVENT( eventid, eventname, cancelindex ) \ - REGISTER_EVENT( WORKSHEET_##eventid, "Worksheet_" eventname, EVENTHANDLER_DOCUMENT, cancelindex, true ); \ - REGISTER_EVENT( (USERDEFINED_START + WORKSHEET_##eventid), "Workbook_Sheet" eventname, EVENTHANDLER_DOCUMENT, (((cancelindex) >= 0) ? ((cancelindex) + 1) : -1), false ) + REGISTER_EVENT( WORKSHEET_##eventid, script::ModuleType::DOCUMENT, "Worksheet", eventname, cancelindex, true ); \ + REGISTER_EVENT( (USERDEFINED_START + WORKSHEET_##eventid), script::ModuleType::DOCUMENT, "Workbook", "Sheet" eventname, (((cancelindex) >= 0) ? ((cancelindex) + 1) : -1), false ) // global - REGISTER_EVENT( AUTO_OPEN, "Auto_Open", EVENTHANDLER_GLOBAL, -1, false ); - REGISTER_EVENT( AUTO_CLOSE, "Auto_Close", EVENTHANDLER_GLOBAL, -1, false ); + REGISTER_AUTO_EVENT( OPEN, "Open" ); + REGISTER_AUTO_EVENT( CLOSE, "Close" ); // Workbook REGISTER_WORKBOOK_EVENT( ACTIVATE, "Activate", -1 ); @@ -468,19 +570,68 @@ ScVbaEventsHelper::ScVbaEventsHelper( const uno::Sequence< uno::Any >& rArgs, co REGISTER_WORKSHEET_EVENT( SELECTIONCHANGE, "SelectionChange", -1 ); REGISTER_WORKSHEET_EVENT( FOLLOWHYPERLINK, "FollowHyperlink", -1 ); -#undef REGISTER_EVENT -#undef REGISTER_WORKBOOK_EVENT #undef REGISTER_WORKSHEET_EVENT +#undef REGISTER_WORKBOOK_EVENT +#undef REGISTER_AUTO_EVENT +#undef REGISTER_EVENT } ScVbaEventsHelper::~ScVbaEventsHelper() { } -void SAL_CALL ScVbaEventsHelper::disposing( const lang::EventObject& rSource ) throw (uno::RuntimeException) +void SAL_CALL ScVbaEventsHelper::notifyEvent( const css::document::EventObject& rEvent ) throw (css::uno::RuntimeException) { - mxListener.clear(); - VbaEventsHelperBase::disposing( rSource ); + static const uno::Sequence< uno::Any > saEmptyArgs; + if( (rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_OPENDOC )) || + (rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_CREATEDOC )) ) // CREATEDOC triggered e.g. during VBA Workbooks.Add + { + processVbaEventNoThrow( WORKBOOK_OPEN, saEmptyArgs ); + } + else if( rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_ACTIVATEDOC ) ) + { + processVbaEventNoThrow( WORKBOOK_ACTIVATE, saEmptyArgs ); + } + else if( rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_DEACTIVATEDOC ) ) + { + processVbaEventNoThrow( WORKBOOK_DEACTIVATE, saEmptyArgs ); + } + else if( (rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_SAVEDOCDONE )) || + (rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_SAVEASDOCDONE )) || + (rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_SAVETODOCDONE )) ) + { + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= true; + processVbaEventNoThrow( WORKBOOK_AFTERSAVE, aArgs ); + } + else if( (rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_SAVEDOCFAILED )) || + (rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_SAVEASDOCFAILED )) || + (rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_SAVETODOCFAILED )) ) + { + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= false; + processVbaEventNoThrow( WORKBOOK_AFTERSAVE, aArgs ); + } + else if( rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ) ) + { + /* Trigger the WORKBOOK_WINDOWDEACTIVATE and WORKBOOK_DEACTIVATE + events and stop listening to the model (done in base class). */ + uno::Reference< frame::XController > xController( mxModel->getCurrentController() ); + if( xController.is() ) + { + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= xController; + processVbaEventNoThrow( WORKBOOK_WINDOWDEACTIVATE, aArgs ); + } + processVbaEventNoThrow( WORKBOOK_DEACTIVATE, saEmptyArgs ); + } + else if( rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_VIEWCREATED ) ) + { + uno::Reference< frame::XController > xController( mxModel->getCurrentController() ); + if( mxListener.get() && xController.is() ) + mxListener->startControllerListening( xController ); + } + VbaEventsHelperBase::notifyEvent( rEvent ); } // protected ------------------------------------------------------------------ @@ -492,25 +643,35 @@ bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, if( !mpShell || !mpDoc ) throw uno::RuntimeException(); - // framework and Calc fire a few events before 'opened', ignore them - bool bExecuteEvent = mbOpened; + /* For document events: check if events are enabled via the + Application.EnableEvents symbol (this is an Excel-only attribute). + Check this again for every event, as the event handler may change the + state of the EnableEvents symbol. Global events such as AUTO_OPEN and + AUTO_CLOSE are always enabled. */ + bool bExecuteEvent = (rInfo.mnModuleType != script::ModuleType::DOCUMENT) || ScVbaApplication::getDocumentEventsEnabled(); + + // framework and Calc fire a few events before 'OnLoad', ignore them + if( bExecuteEvent ) + bExecuteEvent = (rInfo.mnEventId == WORKBOOK_OPEN) ? !mbOpened : mbOpened; // special handling for some events - switch( rInfo.mnEventId ) + if( bExecuteEvent ) switch( rInfo.mnEventId ) { case WORKBOOK_OPEN: - bExecuteEvent = !mbOpened; - if( bExecuteEvent ) - { - // execute delayed Activate event too (see above) - rEventQueue.push_back( WORKBOOK_ACTIVATE ); - rEventQueue.push_back( WORKBOOK_WINDOWACTIVATE ); - rEventQueue.push_back( AUTO_OPEN ); - } + { + // execute delayed Activate event too (see above) + rEventQueue.push_back( WORKBOOK_ACTIVATE ); + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= mxModel->getCurrentController(); + rEventQueue.push_back( EventQueueEntry( WORKBOOK_WINDOWACTIVATE, aArgs ) ); + rEventQueue.push_back( AUTO_OPEN ); + // remember initial selection + maOldSelection <<= mxModel->getCurrentSelection(); + } break; case WORKSHEET_SELECTIONCHANGE: // if selection is not changed, then do not fire the event - bExecuteEvent = bExecuteEvent && isSelectionChanged( rArgs, 0 ); + bExecuteEvent = isSelectionChanged( rArgs, 0 ); break; } @@ -520,14 +681,6 @@ bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, bool bSheetEvent = false; if( (rInfo.maUserData >>= bSheetEvent) && bSheetEvent ) rEventQueue.push_back( EventQueueEntry( rInfo.mnEventId + USERDEFINED_START, rArgs ) ); - - /* For document events: check if events are enabled via the - Application.EnableEvents symbol (this is an Excel-only attribute). - Check this again for every event, as the event handler may change - the state of the EnableEvents symbol. Global events such as - AUTO_OPEN and AUTO_CLOSE are always enabled. */ - if( rInfo.meType == EVENTHANDLER_DOCUMENT ) - bExecuteEvent = ScVbaApplication::getDocumentEventsEnabled(); } return bExecuteEvent; @@ -574,7 +727,7 @@ uno::Sequence< uno::Any > ScVbaEventsHelper::implBuildArgumentList( const EventH case WORKBOOK_WINDOWDEACTIVATE: case WORKBOOK_WINDOWRESIZE: aVbaArgs.realloc( 1 ); - aVbaArgs[ 0 ] = createWindow(); + aVbaArgs[ 0 ] = createWindow( rArgs, 0 ); break; // 1 arg: worksheet case WORKBOOK_NEWSHEET: @@ -625,7 +778,7 @@ uno::Sequence< uno::Any > ScVbaEventsHelper::implBuildArgumentList( const EventH } void ScVbaEventsHelper::implPostProcessEvent( EventQueue& rEventQueue, - const EventHandlerInfo& rInfo, bool /*bSuccess*/, bool bCancel ) throw (uno::RuntimeException) + const EventHandlerInfo& rInfo, bool bCancel ) throw (uno::RuntimeException) { switch( rInfo.mnEventId ) { @@ -633,10 +786,7 @@ void ScVbaEventsHelper::implPostProcessEvent( EventQueue& rEventQueue, mbOpened = true; // register the listeners if( !mxListener.is() ) - { - mxListener = new ScVbaEventsListener( *this, mxModel, mpDocShell ); - mxListener->startListening(); - } + mxListener = new ScVbaEventListener( *this, mxModel, mpDocShell ); break; case WORKBOOK_BEFORECLOSE: /* Execute Auto_Close only if not cancelled by event handler, but @@ -647,7 +797,7 @@ void ScVbaEventsHelper::implPostProcessEvent( EventQueue& rEventQueue, } } -::rtl::OUString ScVbaEventsHelper::implGetDocumentModuleName( const EventHandlerInfo& rInfo, +OUString ScVbaEventsHelper::implGetDocumentModuleName( const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& rArgs ) const throw (lang::IllegalArgumentException) { bool bSheetEvent = false; @@ -746,11 +896,13 @@ uno::Any ScVbaEventsHelper::createHyperlink( const uno::Sequence< uno::Any >& rA return uno::Any( xHyperlink ); } -uno::Any ScVbaEventsHelper::createWindow() const throw (uno::RuntimeException) +uno::Any ScVbaEventsHelper::createWindow( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) const + throw (lang::IllegalArgumentException, uno::RuntimeException) { - uno::Sequence< uno::Any > aArgs( 2 ); - aArgs[ 0 ] <<= createVBAUnoAPIService( mpShell, "ooo.vba.Application" ); + uno::Sequence< uno::Any > aArgs( 3 ); + aArgs[ 0 ] <<= getVBADocument( mxModel ); aArgs[ 1 ] <<= mxModel; + aArgs[ 2 ] <<= getXSomethingFromArgs< frame::XController >( rArgs, nIndex, false ); uno::Reference< uno::XInterface > xWindow( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Window", aArgs ), uno::UNO_SET_THROW ); return uno::Any( xWindow ); } diff --git a/sc/source/ui/vba/vbaeventshelper.hxx b/sc/source/ui/vba/vbaeventshelper.hxx index f1e8a4fb712d..4e7e3b52f610 100755 --- a/sc/source/ui/vba/vbaeventshelper.hxx +++ b/sc/source/ui/vba/vbaeventshelper.hxx @@ -25,15 +25,15 @@ * ************************************************************************/ -#ifndef SC_VBAEVENTS_HXX -#define SC_VBAEVENTS_HXX +#ifndef SC_VBAEVENTSHELPER_HXX +#define SC_VBAEVENTSHELPER_HXX #include <rtl/ref.hxx> #include <vbahelper/vbaeventshelperbase.hxx> #include "excelvbahelper.hxx" #include "rangelst.hxx" -class ScVbaEventsListener; +class ScVbaEventListener; // ============================================================================ @@ -45,13 +45,12 @@ public: const css::uno::Reference< css::uno::XComponentContext >& rxContext ); virtual ~ScVbaEventsHelper(); - // XEventListener - virtual void SAL_CALL disposing( const css::lang::EventObject& rSource ) throw (css::uno::RuntimeException); + virtual void SAL_CALL notifyEvent( const css::document::EventObject& rEvent ) throw (css::uno::RuntimeException); protected: virtual bool implPrepareEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::uno::RuntimeException); virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList( const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException); - virtual void implPostProcessEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, bool bSuccess, bool bCancel ) throw (css::uno::RuntimeException); + virtual void implPostProcessEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, bool bCancel ) throw (css::uno::RuntimeException); virtual ::rtl::OUString implGetDocumentModuleName( const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) const throw (css::lang::IllegalArgumentException); private: @@ -65,11 +64,11 @@ private: css::uno::Any createRange( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) const throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); /** Creates a VBA Hyperlink object (the argument must contain a UNO cell). */ css::uno::Any createHyperlink( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) const throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); - /** Creates a VBA Window object. */ - css::uno::Any createWindow() const throw (css::uno::RuntimeException); + /** Creates a VBA Window object (the argument must contain a model controller). */ + css::uno::Any createWindow( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) const throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); private: - ::rtl::Reference< ScVbaEventsListener > mxListener; + ::rtl::Reference< ScVbaEventListener > mxListener; css::uno::Any maOldSelection; ScDocShell* mpDocShell; ScDocument* mpDoc; diff --git a/sc/source/ui/vba/vbaformat.cxx b/sc/source/ui/vba/vbaformat.cxx index 3b0ba2367c1a..0186b5a78645 100644 --- a/sc/source/ui/vba/vbaformat.cxx +++ b/sc/source/ui/vba/vbaformat.cxx @@ -62,10 +62,10 @@ ScVbaFormat< Ifc1 >::ScVbaFormat( const uno::Reference< XHelperInterface >& xPar { try { - mxServiceInfo.set( mxPropertySet, uno::UNO_QUERY_THROW ); if ( !mxModel.is() ) DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XModel Interface could not be retrieved") ) ); - mxNumberFormatsSupplier.set( mxModel, uno::UNO_QUERY_THROW ); + // mxServiceInfo is unused, + // mxNumberFormatsSupplier is initialized when needed in initializeNumberFormats. } catch (uno::Exception& ) { diff --git a/sc/source/ui/vba/vbaformat.hxx b/sc/source/ui/vba/vbaformat.hxx index bfa88d6c7cb8..b875f84c69cd 100644 --- a/sc/source/ui/vba/vbaformat.hxx +++ b/sc/source/ui/vba/vbaformat.hxx @@ -52,7 +52,6 @@ protected: css::uno::Reference< css::util::XNumberFormats > xNumberFormats; css::uno::Reference< css::util::XNumberFormatTypes > xNumberFormatTypes; css::uno::Reference< css::frame::XModel > mxModel; - css::uno::Reference< css::lang::XServiceInfo > mxServiceInfo; css::uno::Reference< css::beans::XPropertyState > xPropertyState; sal_Bool mbCheckAmbiguoity; sal_Bool mbAddIndent; @@ -69,7 +68,6 @@ public: ScVbaFormat( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet, const css::uno::Reference< css::frame::XModel >& xModel, bool bCheckAmbiguoity ) throw ( css::script::BasicErrorException ); virtual ~ScVbaFormat() {} virtual css::uno::Reference< ov::XHelperInterface > thisHelperIface() = 0; - css::uno::Reference< css::lang::XServiceInfo > getXServiceInfo() { return mxServiceInfo; } void SAL_CALL setAddIndent( const css::uno::Any& _BAddIndent) throw( css::uno::RuntimeException ) { _BAddIndent >>= mbAddIndent; } css::uno::Any SAL_CALL getAddIndent() throw( css::uno::RuntimeException ) { return css::uno::makeAny( mbAddIndent ); } // Interface Methods diff --git a/sc/source/ui/vba/vbaglobals.cxx b/sc/source/ui/vba/vbaglobals.cxx index c70a7f83726d..f9ab063937cf 100644 --- a/sc/source/ui/vba/vbaglobals.cxx +++ b/sc/source/ui/vba/vbaglobals.cxx @@ -234,11 +234,9 @@ ScVbaGlobals::getDebug() throw (uno::RuntimeException) { try // return empty object on error { - uno::Sequence< uno::Any > aArgs( 1 ); - aArgs[ 0 ] <<= uno::Reference< XHelperInterface >( this ); uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); - uno::Reference< uno::XInterface > xVBADebug = xServiceManager->createInstanceWithArgumentsAndContext( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.Debug" ) ), aArgs, mxContext ); + uno::Reference< uno::XInterface > xVBADebug = xServiceManager->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.Debug" ) ), mxContext ); return uno::Any( xVBADebug ); } catch( uno::Exception& ) diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 5cb6d44fc902..72f300d6463a 100755 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -406,7 +406,7 @@ ScDocShell* getDocShellFromRange( const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException ) { // need the ScCellRangesBase to get docshell - uno::Reference< uno::XInterface > xIf( xRange, uno::UNO_QUERY_THROW ); + uno::Reference< uno::XInterface > xIf( xRange ); return getDocShellFromIf(xIf ); } @@ -414,7 +414,7 @@ ScDocShell* getDocShellFromRanges( const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges ) throw ( uno::RuntimeException ) { // need the ScCellRangesBase to get docshell - uno::Reference< uno::XInterface > xIf( xRanges, uno::UNO_QUERY_THROW ); + uno::Reference< uno::XInterface > xIf( xRanges ); return getDocShellFromIf(xIf ); } @@ -426,7 +426,8 @@ uno::Reference< frame::XModel > getModelFromXIf( const uno::Reference< uno::XInt uno::Reference< frame::XModel > getModelFromRange( const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException ) { - uno::Reference< uno::XInterface > xIf( xRange, uno::UNO_QUERY_THROW ); + // the XInterface for getImplementation can be any derived interface, no need for queryInterface + uno::Reference< uno::XInterface > xIf( xRange ); return getModelFromXIf( xIf ); } @@ -1469,9 +1470,9 @@ uno::Reference< XCollection >& ScVbaRange::getBorders() void ScVbaRange::visitArray( ArrayVisitor& visitor ) { - uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW ); - sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount(); - sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount(); + table::CellRangeAddress aRangeAddr = lclGetRangeAddress( mxRange ); + sal_Int32 nRowCount = aRangeAddr.EndRow - aRangeAddr.StartRow + 1; + sal_Int32 nColCount = aRangeAddr.EndColumn - aRangeAddr.StartColumn + 1; for ( sal_Int32 i=0; i<nRowCount; ++i ) { for ( sal_Int32 j=0; j<nColCount; ++j ) @@ -3572,9 +3573,12 @@ ScVbaRange::End( ::sal_Int32 Direction ) throw (uno::RuntimeException) bool ScVbaRange::isSingleCellRange() { - uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY); - if ( xColumnRowRange.is() && xColumnRowRange->getRows()->getCount() == 1 && xColumnRowRange->getColumns()->getCount() == 1 ) - return true; + uno::Reference< sheet::XCellRangeAddressable > xAddressable( mxRange, uno::UNO_QUERY ); + if ( xAddressable.is() ) + { + table::CellRangeAddress aRangeAddr = xAddressable->getRangeAddress(); + return ( aRangeAddr.EndColumn == aRangeAddr.StartColumn && aRangeAddr.EndRow == aRangeAddr.StartRow ); + } return false; } diff --git a/sc/source/ui/vba/vbawindow.cxx b/sc/source/ui/vba/vbawindow.cxx index 5964fe98317c..ed10e52cca7a 100644 --- a/sc/source/ui/vba/vbawindow.cxx +++ b/sc/source/ui/vba/vbawindow.cxx @@ -59,11 +59,9 @@ typedef std::hash_map< rtl::OUString, SCTAB, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > NameIndexHash; -typedef std::vector < uno::Reference< sheet::XSpreadsheet > > Sheets; +typedef std::vector< uno::Reference< sheet::XSpreadsheet > > Sheets; -typedef ::cppu::WeakImplHelper1< container::XEnumeration - -> Enumeration_BASE; +typedef ::cppu::WeakImplHelper1< container::XEnumeration > Enumeration_BASE; typedef ::cppu::WeakImplHelper3< container::XEnumerationAccess , com::sun::star::container::XIndexAccess @@ -200,13 +198,20 @@ public: }; -ScVbaWindow::ScVbaWindow( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : WindowImpl_BASE( xParent, xContext, xModel ) +ScVbaWindow::ScVbaWindow( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< frame::XModel >& xModel, + const uno::Reference< frame::XController >& xController ) throw (uno::RuntimeException) : + WindowImpl_BASE( xParent, xContext, xModel, xController ) { init(); } -ScVbaWindow::ScVbaWindow( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & xContext ) - : WindowImpl_BASE( args, xContext ) +ScVbaWindow::ScVbaWindow( + const uno::Sequence< uno::Any >& args, + const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) : + WindowImpl_BASE( args, xContext ) { init(); } @@ -218,20 +223,42 @@ ScVbaWindow::init() still zero. The implementation of ActivePane() uses a UNO reference of this (to set this window as parent of the pane obejct). This requires the own refcount to be non-zero, otherwise this instance will be - desctructed immediately! */ + desctructed immediately! Guard the call to ActivePane() in try/catch to + not miss the decrementation of the reference count on exception. */ osl_incrementInterlockedCount( &m_refCount ); - uno::Reference< frame::XController > xController( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); - m_xViewPane.set( xController, uno::UNO_QUERY_THROW ); - m_xViewFreezable.set( xController, uno::UNO_QUERY_THROW ); - m_xViewSplitable.set( xController, uno::UNO_QUERY_THROW ); - m_xPane.set( ActivePane(), uno::UNO_QUERY_THROW ); - m_xDevice.set( xController->getFrame()->getComponentWindow(), uno::UNO_QUERY_THROW ); + try + { + m_xPane = ActivePane(); + } + catch( uno::Exception& ) + { + } osl_decrementInterlockedCount( &m_refCount ); } +uno::Reference< beans::XPropertySet > +ScVbaWindow::getControllerProps() throw (uno::RuntimeException) +{ + return uno::Reference< beans::XPropertySet >( getController(), uno::UNO_QUERY_THROW ); +} + +uno::Reference< beans::XPropertySet > +ScVbaWindow::getFrameProps() throw (uno::RuntimeException) +{ + return uno::Reference< beans::XPropertySet >( getController()->getFrame(), uno::UNO_QUERY_THROW ); +} + +uno::Reference< awt::XDevice > +ScVbaWindow::getDevice() throw (uno::RuntimeException) +{ + return uno::Reference< awt::XDevice >( getWindow(), uno::UNO_QUERY_THROW ); +} + void ScVbaWindow::Scroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft, bool bLargeScroll ) throw (uno::RuntimeException) { + if( !m_xPane.is() ) + throw uno::RuntimeException(); if( bLargeScroll ) m_xPane->LargeScroll( Down, Up, ToRight, ToLeft ); else @@ -253,7 +280,7 @@ ScVbaWindow::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::A uno::Any SAL_CALL ScVbaWindow::SelectedSheets( const uno::Any& aIndex ) throw (uno::RuntimeException) { - uno::Reference< container::XEnumerationAccess > xEnumAccess( new SelectedSheetsEnumAccess( mxContext, m_xModel ) ); + uno::Reference< container::XEnumerationAccess > xEnumAccess( new SelectedSheetsEnumAccess( mxContext, m_xModel ) ); // #FIXME needs a workbook as a parent uno::Reference< excel::XWorksheets > xSheets( new ScVbaWorksheets( uno::Reference< XHelperInterface >(), mxContext, xEnumAccess, m_xModel ) ); if ( aIndex.hasValue() ) @@ -283,16 +310,6 @@ ScVbaWindow::ScrollWorkbookTabs( const uno::Any& /*Sheets*/, const uno::Any& /*P */ } -uno::Reference< beans::XPropertySet > -getPropsFromModel( const uno::Reference< frame::XModel >& xModel ) -{ - uno::Reference< frame::XController > xController = xModel->getCurrentController(); - if ( !xController.is() ) - throw uno::RuntimeException( rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM ("No controller for model") ), uno::Reference< uno::XInterface >() ); - return uno::Reference< beans::XPropertySet >( xController->getFrame(), uno::UNO_QUERY ); -} - uno::Any SAL_CALL ScVbaWindow::getCaption() throw (uno::RuntimeException) @@ -300,9 +317,8 @@ ScVbaWindow::getCaption() throw (uno::RuntimeException) static rtl::OUString sCrud(RTL_CONSTASCII_USTRINGPARAM(" - OpenOffice.org Calc" ) ); static sal_Int32 nCrudLen = sCrud.getLength(); - uno::Reference< beans::XPropertySet > xProps = getPropsFromModel( m_xModel ); rtl::OUString sTitle; - xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SC_UNONAME_TITLE ) ) ) >>= sTitle; + getFrameProps()->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SC_UNONAME_TITLE ) ) ) >>= sTitle; sal_Int32 nCrudIndex = sTitle.indexOf( sCrud ); // adjust title ( by removing crud ) // sCrud string present @@ -338,16 +354,14 @@ ScVbaWindow::getCaption() throw (uno::RuntimeException) void SAL_CALL ScVbaWindow::setCaption( const uno::Any& _caption ) throw (uno::RuntimeException) { - - uno::Reference< beans::XPropertySet > xProps = getPropsFromModel( m_xModel ); - xProps->setPropertyValue( rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM ( SC_UNONAME_TITLE ) ) , _caption ); + getFrameProps()->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_TITLE ) ), _caption ); } uno::Any SAL_CALL ScVbaWindow::getScrollRow() throw (uno::RuntimeException) { sal_Int32 nValue = 0; + // !! TODO !! get view shell from controller ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); if ( pViewShell ) { @@ -361,6 +375,7 @@ ScVbaWindow::getScrollRow() throw (uno::RuntimeException) void SAL_CALL ScVbaWindow::setScrollRow( const uno::Any& _scrollrow ) throw (uno::RuntimeException) { + // !! TODO !! get view shell from controller ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); if ( pViewShell ) { @@ -376,6 +391,7 @@ uno::Any SAL_CALL ScVbaWindow::getScrollColumn() throw (uno::RuntimeException) { sal_Int32 nValue = 0; + // !! TODO !! get view shell from controller ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); if ( pViewShell ) { @@ -389,6 +405,7 @@ ScVbaWindow::getScrollColumn() throw (uno::RuntimeException) void SAL_CALL ScVbaWindow::setScrollColumn( const uno::Any& _scrollcolumn ) throw (uno::RuntimeException) { + // !! TODO !! get view shell from controller ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); if ( pViewShell ) { @@ -404,6 +421,7 @@ uno::Any SAL_CALL ScVbaWindow::getWindowState() throw (uno::RuntimeException) { sal_Int32 nwindowState = xlNormal; + // !! TODO !! get view shell from controller ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame(); WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow(); @@ -422,6 +440,7 @@ ScVbaWindow::setWindowState( const uno::Any& _windowstate ) throw (uno::RuntimeE { sal_Int32 nwindowState = xlMaximized; _windowstate >>= nwindowState; + // !! TODO !! get view shell from controller ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame(); WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow(); @@ -456,7 +475,8 @@ ScVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& FileName, const uno::Reference< excel::XPane > SAL_CALL ScVbaWindow::ActivePane() throw (script::BasicErrorException, uno::RuntimeException) { - return new ScVbaPane( this, mxContext, m_xModel, m_xViewPane ); + uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW ); + return new ScVbaPane( this, mxContext, m_xModel, xViewPane ); } uno::Reference< excel::XRange > SAL_CALL @@ -484,10 +504,9 @@ ScVbaWindow::RangeSelection() throw (script::BasicErrorException, uno::RuntimeEx ::sal_Bool SAL_CALL ScVbaWindow::getDisplayGridlines() throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHOWGRID ) ); sal_Bool bGrid = sal_True; - xProps->getPropertyValue( sName ) >>= bGrid; + getControllerProps()->getPropertyValue( sName ) >>= bGrid; return bGrid; } @@ -495,131 +514,125 @@ ScVbaWindow::getDisplayGridlines() throw (uno::RuntimeException) void SAL_CALL ScVbaWindow::setDisplayGridlines( ::sal_Bool _displaygridlines ) throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHOWGRID ) ); - xProps->setPropertyValue( sName, uno::makeAny( _displaygridlines )); + getControllerProps()->setPropertyValue( sName, uno::makeAny( _displaygridlines )); } ::sal_Bool SAL_CALL ScVbaWindow::getDisplayHeadings() throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_COLROWHDR ) ); sal_Bool bHeading = sal_True; - xProps->getPropertyValue( sName ) >>= bHeading; + getControllerProps()->getPropertyValue( sName ) >>= bHeading; return bHeading; } void SAL_CALL ScVbaWindow::setDisplayHeadings( ::sal_Bool _bDisplayHeadings ) throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_COLROWHDR ) ); - xProps->setPropertyValue( sName, uno::makeAny( _bDisplayHeadings )); + getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayHeadings )); } ::sal_Bool SAL_CALL ScVbaWindow::getDisplayHorizontalScrollBar() throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_HORSCROLL ) ); sal_Bool bHorizontalScrollBar = sal_True; - xProps->getPropertyValue( sName ) >>= bHorizontalScrollBar; + getControllerProps()->getPropertyValue( sName ) >>= bHorizontalScrollBar; return bHorizontalScrollBar; } void SAL_CALL ScVbaWindow::setDisplayHorizontalScrollBar( ::sal_Bool _bDisplayHorizontalScrollBar ) throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_HORSCROLL ) ); - xProps->setPropertyValue( sName, uno::makeAny( _bDisplayHorizontalScrollBar )); + getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayHorizontalScrollBar )); } ::sal_Bool SAL_CALL ScVbaWindow::getDisplayOutline() throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_OUTLSYMB ) ); sal_Bool bOutline = sal_True; - xProps->getPropertyValue( sName ) >>= bOutline; + getControllerProps()->getPropertyValue( sName ) >>= bOutline; return bOutline; } void SAL_CALL ScVbaWindow::setDisplayOutline( ::sal_Bool _bDisplayOutline ) throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_OUTLSYMB ) ); - xProps->setPropertyValue( sName, uno::makeAny( _bDisplayOutline )); + getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayOutline )); } ::sal_Bool SAL_CALL ScVbaWindow::getDisplayVerticalScrollBar() throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_VERTSCROLL ) ); sal_Bool bVerticalScrollBar = sal_True; - xProps->getPropertyValue( sName ) >>= bVerticalScrollBar; + getControllerProps()->getPropertyValue( sName ) >>= bVerticalScrollBar; return bVerticalScrollBar; } void SAL_CALL ScVbaWindow::setDisplayVerticalScrollBar( ::sal_Bool _bDisplayVerticalScrollBar ) throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_VERTSCROLL ) ); - xProps->setPropertyValue( sName, uno::makeAny( _bDisplayVerticalScrollBar )); + getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayVerticalScrollBar )); } ::sal_Bool SAL_CALL ScVbaWindow::getDisplayWorkbookTabs() throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHEETTABS ) ); sal_Bool bWorkbookTabs = sal_True; - xProps->getPropertyValue( sName ) >>= bWorkbookTabs; + getControllerProps()->getPropertyValue( sName ) >>= bWorkbookTabs; return bWorkbookTabs; } void SAL_CALL ScVbaWindow::setDisplayWorkbookTabs( ::sal_Bool _bDisplayWorkbookTabs ) throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHEETTABS ) ); - xProps->setPropertyValue( sName, uno::makeAny( _bDisplayWorkbookTabs )); + getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayWorkbookTabs )); } ::sal_Bool SAL_CALL ScVbaWindow::getFreezePanes() throw (uno::RuntimeException) { - return m_xViewFreezable->hasFrozenPanes(); + uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW ); + return xViewFreezable->hasFrozenPanes(); } void SAL_CALL ScVbaWindow::setFreezePanes( ::sal_Bool /*_bFreezePanes*/ ) throw (uno::RuntimeException) { - if( m_xViewSplitable->getIsWindowSplit() ) + uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XViewSplitable > xViewSplitable( xViewPane, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewPane, uno::UNO_QUERY_THROW ); + if( xViewSplitable->getIsWindowSplit() ) { // if there is a split we freeze at the split sal_Int32 nColumn = getSplitColumn(); sal_Int32 nRow = getSplitRow(); - m_xViewFreezable->freezeAtPosition( nColumn, nRow ); + xViewFreezable->freezeAtPosition( nColumn, nRow ); } else { // otherwise we freeze in the center of the visible sheet - table::CellRangeAddress aCellRangeAddress = m_xViewPane->getVisibleRange(); + table::CellRangeAddress aCellRangeAddress = xViewPane->getVisibleRange(); sal_Int32 nColumn = aCellRangeAddress.StartColumn + (( aCellRangeAddress.EndColumn - aCellRangeAddress.StartColumn )/2 ); sal_Int32 nRow = aCellRangeAddress.StartRow + (( aCellRangeAddress.EndRow - aCellRangeAddress.StartRow )/2 ); - m_xViewFreezable->freezeAtPosition( nColumn, nRow ); + xViewFreezable->freezeAtPosition( nColumn, nRow ); } } ::sal_Bool SAL_CALL ScVbaWindow::getSplit() throw (uno::RuntimeException) { - return m_xViewSplitable->getIsWindowSplit(); + uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); + return xViewSplitable->getIsWindowSplit(); } void SAL_CALL @@ -627,14 +640,16 @@ ScVbaWindow::setSplit( ::sal_Bool _bSplit ) throw (uno::RuntimeException) { if( !_bSplit ) { - m_xViewSplitable->splitAtPosition(0,0); + uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); + xViewSplitable->splitAtPosition(0,0); } else { + uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW ); uno::Reference< excel::XRange > xRange = ActiveCell(); sal_Int32 nRow = xRange->getRow(); sal_Int32 nColumn = xRange->getColumn(); - m_xViewFreezable->freezeAtPosition( nColumn-1, nRow-1 ); + xViewFreezable->freezeAtPosition( nColumn-1, nRow-1 ); SplitAtDefinedPosition( sal_True ); } } @@ -642,7 +657,8 @@ ScVbaWindow::setSplit( ::sal_Bool _bSplit ) throw (uno::RuntimeException) sal_Int32 SAL_CALL ScVbaWindow::getSplitColumn() throw (uno::RuntimeException) { - return m_xViewSplitable->getSplitColumn(); + uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); + return xViewSplitable->getSplitColumn(); } void SAL_CALL @@ -650,9 +666,10 @@ ScVbaWindow::setSplitColumn( sal_Int32 _splitcolumn ) throw (uno::RuntimeExcepti { if( getSplitColumn() != _splitcolumn ) { + uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW ); sal_Bool bFrozen = getFreezePanes(); sal_Int32 nRow = getSplitRow(); - m_xViewFreezable->freezeAtPosition( _splitcolumn, nRow ); + xViewFreezable->freezeAtPosition( _splitcolumn, nRow ); SplitAtDefinedPosition( !bFrozen ); } } @@ -660,22 +677,23 @@ ScVbaWindow::setSplitColumn( sal_Int32 _splitcolumn ) throw (uno::RuntimeExcepti double SAL_CALL ScVbaWindow::getSplitHorizontal() throw (uno::RuntimeException) { - double fSplitHorizontal = m_xViewSplitable->getSplitHorizontal(); - double fHoriPoints = PixelsToPoints( m_xDevice, fSplitHorizontal, sal_True ); - return fHoriPoints; + uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); + return PixelsToPoints( getDevice(), xViewSplitable->getSplitHorizontal(), sal_True ); } void SAL_CALL ScVbaWindow::setSplitHorizontal( double _splithorizontal ) throw (uno::RuntimeException) { - double fHoriPixels = PointsToPixels( m_xDevice, _splithorizontal, sal_True ); - m_xViewSplitable->splitAtPosition( static_cast<sal_Int32>( fHoriPixels ), 0 ); + uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); + double fHoriPixels = PointsToPixels( getDevice(), _splithorizontal, sal_True ); + xViewSplitable->splitAtPosition( static_cast< sal_Int32 >( fHoriPixels ), 0 ); } sal_Int32 SAL_CALL ScVbaWindow::getSplitRow() throw (uno::RuntimeException) { - sal_Int32 nValue = m_xViewSplitable->getSplitRow(); + uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); + sal_Int32 nValue = xViewSplitable->getSplitRow(); return nValue ? nValue - 1 : nValue; } @@ -684,9 +702,10 @@ ScVbaWindow::setSplitRow( sal_Int32 _splitrow ) throw (uno::RuntimeException) { if( getSplitRow() != _splitrow ) { + uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW ); sal_Bool bFrozen = getFreezePanes(); sal_Int32 nColumn = getSplitColumn(); - m_xViewFreezable->freezeAtPosition( nColumn , _splitrow ); + xViewFreezable->freezeAtPosition( nColumn , _splitrow ); SplitAtDefinedPosition( !bFrozen ); } } @@ -694,33 +713,33 @@ ScVbaWindow::setSplitRow( sal_Int32 _splitrow ) throw (uno::RuntimeException) double SAL_CALL ScVbaWindow::getSplitVertical() throw (uno::RuntimeException) { - double fSplitVertical = m_xViewSplitable->getSplitVertical(); - double fVertiPoints = PixelsToPoints( m_xDevice, fSplitVertical, sal_False ); - return fVertiPoints; + uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); + return PixelsToPoints( getDevice(), xViewSplitable->getSplitVertical(), sal_False ); } void SAL_CALL ScVbaWindow::setSplitVertical(double _splitvertical ) throw (uno::RuntimeException) { - double fVertiPixels = PointsToPixels( m_xDevice, _splitvertical, sal_False ); - m_xViewSplitable->splitAtPosition( 0, static_cast<sal_Int32>( fVertiPixels ) ); + uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); + double fVertiPixels = PointsToPixels( getDevice(), _splitvertical, sal_False ); + xViewSplitable->splitAtPosition( 0, static_cast<sal_Int32>( fVertiPixels ) ); } void ScVbaWindow::SplitAtDefinedPosition(sal_Bool _bUnFreezePane) { - sal_Int32 nVertSplit = m_xViewSplitable->getSplitVertical(); - sal_Int32 nHoriSplit = m_xViewSplitable->getSplitHorizontal(); + uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewSplitable, uno::UNO_QUERY_THROW ); + sal_Int32 nVertSplit = xViewSplitable->getSplitVertical(); + sal_Int32 nHoriSplit = xViewSplitable->getSplitHorizontal(); if( _bUnFreezePane ) - { - m_xViewFreezable->freezeAtPosition(0,0); - } - m_xViewSplitable->splitAtPosition(nHoriSplit, nVertSplit); + xViewFreezable->freezeAtPosition(0,0); + xViewSplitable->splitAtPosition(nHoriSplit, nVertSplit); } uno::Any SAL_CALL ScVbaWindow::getZoom() throw (uno::RuntimeException) { - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps = getControllerProps(); rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_ZOOMTYPE ) ); sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH; xProps->getPropertyValue( sName ) >>= nZoomType; @@ -785,6 +804,7 @@ ScVbaWindow::setView( const uno::Any& _view) throw (uno::RuntimeException) default: DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); } + // !! TODO !! get view shell from controller ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); if ( pViewShell ) dispatchExecute( pViewShell, nSlot ); @@ -793,7 +813,7 @@ ScVbaWindow::setView( const uno::Any& _view) throw (uno::RuntimeException) uno::Reference< excel::XRange > SAL_CALL ScVbaWindow::getVisibleRange() throw (uno::RuntimeException) { - uno::Reference< container::XIndexAccess > xPanesIA( m_xViewPane, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xPanesIA( getController(), uno::UNO_QUERY_THROW ); uno::Reference< sheet::XViewPane > xTopLeftPane( xPanesIA->getByIndex( 0 ), uno::UNO_QUERY_THROW ); uno::Reference< excel::XPane > xPane( new ScVbaPane( this, mxContext, m_xModel, xTopLeftPane ) ); return xPane->getVisibleRange(); @@ -803,7 +823,7 @@ sal_Int32 SAL_CALL ScVbaWindow::PointsToScreenPixelsX(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException) { sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points ); - double fConvertFactor = (m_xDevice->getInfo().PixelPerMeterX/100000); + double fConvertFactor = (getDevice()->getInfo().PixelPerMeterX/100000); return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters ); } @@ -811,7 +831,7 @@ sal_Int32 SAL_CALL ScVbaWindow::PointsToScreenPixelsY(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException) { sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points ); - double fConvertFactor = (m_xDevice->getInfo().PixelPerMeterY/100000); + double fConvertFactor = (getDevice()->getInfo().PixelPerMeterY/100000); return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters ); } @@ -819,6 +839,7 @@ void SAL_CALL ScVbaWindow::PrintOut( const css::uno::Any& From, const css::uno::Any&To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ) throw (css::script::BasicErrorException, css::uno::RuntimeException) { // need test, print current active sheet + // !! TODO !! get view shell from controller PrintOutHelper( excel::getBestViewShell( m_xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, sal_True ); } @@ -826,6 +847,7 @@ void SAL_CALL ScVbaWindow::PrintPreview( const css::uno::Any& EnableChanges ) throw (css::script::BasicErrorException, css::uno::RuntimeException) { // need test, print preview current active sheet + // !! TODO !! get view shell from controller PrintPreviewHelper( EnableChanges, excel::getBestViewShell( m_xModel ) ); } diff --git a/sc/source/ui/vba/vbawindow.hxx b/sc/source/ui/vba/vbawindow.hxx index d58d2a07cb4b..d183ee346185 100644 --- a/sc/source/ui/vba/vbawindow.hxx +++ b/sc/source/ui/vba/vbawindow.hxx @@ -27,7 +27,6 @@ #ifndef SC_VBA_WINDOW_HXX #define SC_VBA_WINDOW_HXX -#include <cppuhelper/implbase1.hxx> #include <ooo/vba/excel/XWindow.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/sheet/XViewPane.hpp> @@ -46,19 +45,30 @@ typedef cppu::ImplInheritanceHelper1< VbaWindowBase, ov::excel::XWindow > Window class ScVbaWindow : public WindowImpl_BASE { private: - css::uno::Reference< css::sheet::XViewPane > m_xViewPane; - css::uno::Reference< css::sheet::XViewFreezable > m_xViewFreezable; - css::uno::Reference< css::sheet::XViewSplitable > m_xViewSplitable; css::uno::Reference< ov::excel::XPane > m_xPane; - css::uno::Reference< css::awt::XDevice > m_xDevice; + void init(); + css::uno::Reference< css::beans::XPropertySet > getControllerProps() throw (css::uno::RuntimeException); + css::uno::Reference< css::beans::XPropertySet > getFrameProps() throw (css::uno::RuntimeException); + css::uno::Reference< css::awt::XDevice > getDevice() throw (css::uno::RuntimeException); + protected: void SplitAtDefinedPosition(sal_Bool _bUnFreezePane); + public: - void Scroll( const css::uno::Any& Down, const css::uno::Any& Up, const css::uno::Any& ToRight, const css::uno::Any& ToLeft, bool bLargeScroll = false ) throw (css::uno::RuntimeException); + void Scroll( const css::uno::Any& Down, const css::uno::Any& Up, const css::uno::Any& ToRight, const css::uno::Any& ToLeft, bool bLargeScroll = false ) throw (css::uno::RuntimeException); + public: - ScVbaWindow( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::frame::XModel >& xModel ); - ScVbaWindow( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext > const& xContext ); + ScVbaWindow( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::frame::XModel >& xModel, + const css::uno::Reference< css::frame::XController >& xController ) + throw (css::uno::RuntimeException); + ScVbaWindow( + const css::uno::Sequence< css::uno::Any >& aArgs, + const css::uno::Reference< css::uno::XComponentContext >& xContext ) + throw (css::uno::RuntimeException); // XWindow virtual css::uno::Reference< ov::excel::XRange > SAL_CALL ActiveCell( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); diff --git a/sc/source/ui/vba/vbawindows.cxx b/sc/source/ui/vba/vbawindows.cxx index 3ddc5f5b3b45..80f215629126 100644 --- a/sc/source/ui/vba/vbawindows.cxx +++ b/sc/source/ui/vba/vbawindows.cxx @@ -53,7 +53,9 @@ uno::Reference< XHelperInterface > lcl_createWorkbookHIParent( const uno::Refere uno::Any ComponentToWindow( const uno::Any& aSource, uno::Reference< uno::XComponentContext > & xContext, const uno::Any& aApplication ) { uno::Reference< frame::XModel > xModel( aSource, uno::UNO_QUERY_THROW ); - uno::Reference< excel::XWindow > xWin( new ScVbaWindow( lcl_createWorkbookHIParent( xModel, xContext, aApplication ), xContext,xModel ) ); + // !! TODO !! iterate over all controllers + uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); + uno::Reference< excel::XWindow > xWin( new ScVbaWindow( lcl_createWorkbookHIParent( xModel, xContext, aApplication ), xContext, xModel, xController ) ); return uno::makeAny( xWin ); } @@ -138,8 +140,10 @@ public: { m_windows.push_back( xNext ); uno::Reference< frame::XModel > xModel( xNext, uno::UNO_QUERY_THROW ); // that the spreadsheetdocument is a xmodel is a given + // !! TODO !! iterate over all controllers + uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); uno::Reference< XHelperInterface > xTemp; // temporary needed for g++ 3.3.5 - ScVbaWindow window( xTemp, m_xContext, xModel ); + ScVbaWindow window( xTemp, m_xContext, xModel, xController ); rtl::OUString sCaption; window.getCaption() >>= sCaption; namesToIndices[ sCaption ] = nIndex++; diff --git a/sc/source/ui/vba/vbaworkbook.cxx b/sc/source/ui/vba/vbaworkbook.cxx index 1e2acd6252b8..e0d50c592e6c 100644 --- a/sc/source/ui/vba/vbaworkbook.cxx +++ b/sc/source/ui/vba/vbaworkbook.cxx @@ -218,14 +218,9 @@ ScVbaWorkbook::getActiveSheet() throw (uno::RuntimeException) { uno::Reference< frame::XModel > xModel( getCurrentExcelDoc( mxContext ), uno::UNO_SET_THROW ); uno::Reference< sheet::XSpreadsheetView > xView( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); - uno::Reference< beans::XPropertySet > xSheetProps( xView->getActiveSheet(), uno::UNO_QUERY_THROW ); - // #162503# return the original document module wrapper object, instead of a new instance - ::rtl::OUString aCodeName; - xSheetProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_CODENAME ) ) ) >>= aCodeName; - ScDocShell* pShell = excel::getDocShell( xModel ); - if( !pShell ) - throw uno::RuntimeException(); - return uno::Reference< excel::XWorksheet >( getUnoDocModule( aCodeName, pShell ), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheet > xSheet( xView->getActiveSheet(), uno::UNO_SET_THROW ); + // #162503# return the original sheet module wrapper object, instead of a new instance + return uno::Reference< excel::XWorksheet >( excel::getUnoSheetModuleObj( xSheet ), uno::UNO_QUERY_THROW ); } uno::Any SAL_CALL diff --git a/sc/source/ui/vba/vbaworkbooks.cxx b/sc/source/ui/vba/vbaworkbooks.cxx index a9f1970be34e..9fec863f5463 100644 --- a/sc/source/ui/vba/vbaworkbooks.cxx +++ b/sc/source/ui/vba/vbaworkbooks.cxx @@ -134,18 +134,6 @@ void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& } } } - - /* Trigger the Workbook_Open event, event processor will register - itself as listener for specific events. */ - try - { - uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pShell->GetDocument()->GetVbaEventProcessor(), uno::UNO_SET_THROW ); - uno::Sequence< uno::Any > aArgs; - xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_OPEN, aArgs ); - } - catch( uno::Exception& ) - { - } } } @@ -157,19 +145,14 @@ getWorkbook( uno::Reference< uno::XComponentContext >& xContext, const uno::Refe if( !xModel.is() ) return uno::Any(); - ScDocShell* pShell = excel::getDocShell( xModel ); - if ( pShell ) + uno::Reference< excel::XWorkbook > xWb( getVBADocument( xModel ), uno::UNO_QUERY ); + if ( xWb.is() ) { - String sCodeName = pShell->GetDocument()->GetCodeName(); - uno::Reference< uno::XInterface > xIf = getUnoDocModule( sCodeName, pShell ); - if ( xIf.is() ) - { - OSL_TRACE(" *** Returning Module uno Object *** "); - return uno::makeAny( xIf ); - } + OSL_TRACE(" *** Returning Module uno Object *** "); + return uno::Any( xWb ); } - ScVbaWorkbook *pWb = new ScVbaWorkbook( xParent, xContext, xModel ); + ScVbaWorkbook *pWb = new ScVbaWorkbook( xParent, xContext, xModel ); return uno::Any( uno::Reference< excel::XWorkbook > (pWb) ); } diff --git a/sc/source/ui/vba/vbaworksheets.cxx b/sc/source/ui/vba/vbaworksheets.cxx index bd21cb396c66..cf74f90b5941 100644 --- a/sc/source/ui/vba/vbaworksheets.cxx +++ b/sc/source/ui/vba/vbaworksheets.cxx @@ -68,23 +68,6 @@ typedef std::vector< uno::Reference< sheet::XSpreadsheet > > SheetMap; // #FIXME #TODO the implementation of the Sheets collections sucks, // e.g. there is no support for tracking sheets added/removed from the collection -uno::Reference< uno::XInterface > -lcl_getModulAsUnoObject( const uno::Reference< sheet::XSpreadsheet >& xSheet, const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) -{ - uno::Reference< uno::XInterface > xRet; - if ( !xSheet.is() ) - throw uno::RuntimeException(); - uno::Reference< beans::XPropertySet > xProps( xSheet, uno::UNO_QUERY_THROW ); - rtl::OUString sName; - xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_CODENAME ) ) ) >>= sName; - - ScDocShell* pShell = excel::getDocShell( xModel ); - - if ( pShell ) - xRet = getUnoDocModule( sName, pShell ); - return xRet; -} - class WorkSheetsEnumeration : public SheetEnumeration_BASE { SheetMap mSheetMap; @@ -173,16 +156,16 @@ public: virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) { uno::Reference< sheet::XSpreadsheet > xSheet( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); - uno::Reference< uno::XInterface > xIf = lcl_getModulAsUnoObject( xSheet, m_xModel ); + uno::Reference< XHelperInterface > xIf = excel::getUnoSheetModuleObj( xSheet ); uno::Any aRet; if ( !xIf.is() ) - { + { // if the Sheet is in a document created by the api unfortunately ( at the // moment, it actually wont have the special Document modules uno::Reference< excel::XWorksheet > xNewSheet( new ScVbaWorksheet( m_xParent, m_xContext, xSheet, m_xModel ) ); aRet <<= xNewSheet; - } - else + } + else aRet <<= xIf; return aRet; } @@ -220,7 +203,7 @@ uno::Any ScVbaWorksheets::createCollectionObject( const uno::Any& aSource ) { uno::Reference< sheet::XSpreadsheet > xSheet( aSource, uno::UNO_QUERY ); - uno::Reference< XInterface > xIf = lcl_getModulAsUnoObject( xSheet, mxModel ); + uno::Reference< XHelperInterface > xIf = excel::getUnoSheetModuleObj( xSheet ); uno::Any aRet; if ( !xIf.is() ) { diff --git a/sc/util/makefile.mk b/sc/util/makefile.mk index dd0a6043c8fd..a7ce2f9407dc 100644 --- a/sc/util/makefile.mk +++ b/sc/util/makefile.mk @@ -311,6 +311,7 @@ SHL9STDLIBS= \ $(VCLLIB) \ $(TKLIB) \ $(MSFILTERLIB) \ + $(UNOTOOLSLIB) \ $(FORLIB) SHL9DEPN=$(SHL1TARGETN) $(SHL8TARGETN) diff --git a/scripting/source/dlgprov/dlgevtatt.cxx b/scripting/source/dlgprov/dlgevtatt.cxx index 6c3694ea237d..ab2b52ae7d55 100644 --- a/scripting/source/dlgprov/dlgevtatt.cxx +++ b/scripting/source/dlgprov/dlgevtatt.cxx @@ -45,14 +45,13 @@ #include <com/sun/star/script/provider/XScriptProvider.hpp> #include <com/sun/star/script/provider/XScriptProviderFactory.hpp> #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp> +#include <com/sun/star/script/vba/XVBACompatibility.hpp> #include <com/sun/star/lang/NoSuchMethodException.hpp> #include <com/sun/star/reflection/XIdlMethod.hpp> #include <com/sun/star/beans/MethodConcept.hpp> #include <com/sun/star/beans/XMaterialHolder.hpp> #include <ooo/vba/XVBAToOOEventDescGen.hpp> -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <vbahelper/vbaaccesshelper.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::awt; @@ -175,19 +174,17 @@ namespace dlgprov // handler for Script & ::rtl::OUString::createFromAscii( "vnd.sun.star.UNO:" ) listernersForTypes[ rtl::OUString::createFromAscii("vnd.sun.star.UNO") ] = new DialogUnoScriptListenerImpl( rxContext, rxModel, rxControl, rxHandler, rxIntrospect, bProviderMode ); listernersForTypes[ rtl::OUString::createFromAscii("vnd.sun.star.script") ] = new DialogSFScriptListenerImpl( rxContext, rxModel ); - // Note: in a future cws ( npower13_ObjectModule ) it will be possible - // to determine the vba mode from the basiclibrary container, the tunnel hack - // below can then be replaced - SfxObjectShell* pFoundShell = NULL; - if ( rxModel.is() ) + + // determine the VBA compatibility mode from the Basic library container + try + { + uno::Reference< beans::XPropertySet > xModelProps( rxModel, uno::UNO_QUERY_THROW ); + uno::Reference< script::vba::XVBACompatibility > xVBACompat( + xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ), uno::UNO_QUERY_THROW ); + mbUseFakeVBAEvents = xVBACompat->getVBACompatibilityMode(); + } + catch( uno::Exception& ) { - uno::Reference< lang::XUnoTunnel > xObjShellTunnel( rxModel, uno::UNO_QUERY ); - if ( xObjShellTunnel.is() ) - { - pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId())); - if ( pFoundShell ) - mbUseFakeVBAEvents = ooo::vba::isAlienExcelDoc( *pFoundShell ); - } } if ( mbUseFakeVBAEvents ) listernersForTypes[ rtl::OUString::createFromAscii("VBAInterop") ] = new DialogVBAScriptListenerImpl( rxContext, rxControl, rxModel ); diff --git a/set_soenv.in b/set_soenv.in index 2584984e9046..6a8c65baa246 100644 --- a/set_soenv.in +++ b/set_soenv.in @@ -214,7 +214,7 @@ if ( $platform =~ m/solaris/ ) $CPU = "I"; $CPUNAME = "INTEL"; $JRELIBDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386"; - $JRETOOLKITDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."motif21"; + $JRETOOLKITDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."xawt"; $JRETHREADDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."i386".$ds."native_threads"; } @@ -230,7 +230,7 @@ if ( $platform =~ m/solaris/ ) $CPU = "S"; $CPUNAME = "SPARC"; $JRELIBDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc"; - $JRETOOLKITDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc".$ds."motif21"; + $JRETOOLKITDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc".$ds."xawt"; $JRETHREADDIR = '$JAVA_HOME'.$ds."jre".$ds."lib".$ds."sparc".$ds."native_threads"; } @@ -1628,6 +1628,8 @@ ToFile( "DEFAULT_TO_ENGLISH_FOR_PACKING", "yes", "e" ); ToFile( "ENABLE_GTK", "@ENABLE_GTK@", "e" ); ToFile( "GTK_CFLAGS", "@GTK_CFLAGS@", "e" ); ToFile( "GTK_LIBS", "@GTK_LIBS@", "e" ); +ToFile( "GTHREAD_CFLAGS", "@GTHREAD_CFLAGS@", "e" ); +ToFile( "GTHREAD_LIBS", "@GTHREAD_LIBS@", "e" ); ToFile( "ENABLE_SYSTRAY_GTK", "@ENABLE_SYSTRAY_GTK@", "e" ); ToFile( "ENABLE_STATIC_GTK", "@ENABLE_STATIC_GTK@", "e" ); ToFile( "ENABLE_GSTREAMER", "@ENABLE_GSTREAMER@", "e" ); diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx index 281a87c962f7..8b76024c1afb 100644 --- a/sfx2/source/appl/appopen.cxx +++ b/sfx2/source/appl/appopen.cxx @@ -288,8 +288,9 @@ private: } catch( const uno::Exception& ) { - // unknown error, do not try to ask again - eResult = ::comphelper::DocPasswordVerifierResult_ABORT; + // unknown error, report it as wrong password + // TODO/LATER: we need an additional way to report unknown problems in this case + eResult = ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD; } return eResult; } diff --git a/sfx2/source/doc/DocumentMetadataAccess.cxx b/sfx2/source/doc/DocumentMetadataAccess.cxx index df0781be8877..0ff55513c547 100644 --- a/sfx2/source/doc/DocumentMetadataAccess.cxx +++ b/sfx2/source/doc/DocumentMetadataAccess.cxx @@ -699,11 +699,11 @@ writeStream(struct DocumentMetadataAccess_Impl & i_rImpl, buf.append(dir).append(static_cast<sal_Unicode>('/')); writeStream(i_rImpl, xDir, i_xGraphName, rest, buf.makeStringAndClear()); - } - const uno::Reference<embed::XTransactedObject> xTransaction( - i_xStorage, uno::UNO_QUERY); - if (xTransaction.is()) { - xTransaction->commit(); + uno::Reference<embed::XTransactedObject> const xTransaction( + xDir, uno::UNO_QUERY); + if (xTransaction.is()) { + xTransaction->commit(); + } } } catch (uno::RuntimeException &) { throw; diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index 2ccf5fa7a849..1df7d2b01920 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -670,6 +670,10 @@ sal_Int8 ModelData_Impl::CheckSaveAcceptable( sal_Int8 nCurStatus ) //------------------------------------------------------------------------- sal_Int8 ModelData_Impl::CheckStateForSave() { + // if the document is readonly or a new one a SaveAs operation must be used + if ( !GetStorable()->hasLocation() || GetStorable()->isReadonly() ) + return STATUS_SAVEAS; + // check acceptable entries for media descriptor sal_Bool bVersInfoNeedsStore = sal_False; ::comphelper::SequenceAsHashMap aAcceptedArgs; @@ -701,10 +705,6 @@ sal_Int8 ModelData_Impl::CheckStateForSave() if ( !GetModifiable()->isModified() && !bVersInfoNeedsStore ) return STATUS_NO_ACTION; - // if the document is readonly or a new one a SaveAs operation must be used - if ( !GetStorable()->hasLocation() || GetStorable()->isReadonly() ) - return STATUS_SAVEAS; - // check that the old filter is acceptable ::rtl::OUString aOldFilterName = GetDocProps().getUnpackedValueOrDefault( aFilterNameString, diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 9a86e962cac6..38f30b78974a 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -67,9 +67,12 @@ #include <com/sun/star/embed/XLinkageSupport.hpp> #include <com/sun/star/embed/EntryInitModes.hpp> #include <com/sun/star/embed/XOptimizedStorage.hpp> +#include <com/sun/star/embed/XEncryptionProtectedStorage.hpp> #include <com/sun/star/io/XTruncate.hpp> #include <com/sun/star/util/XModifiable.hpp> #include <com/sun/star/security/XDocumentDigitalSignatures.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> #include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> @@ -357,24 +360,51 @@ void SfxObjectShell::SetupStorage( const uno::Reference< embed::XStorage >& xSto const_cast<SfxObjectShell*>( this )->SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); } - ::rtl::OUString aVersion; SvtSaveOptions aSaveOpt; SvtSaveOptions::ODFDefaultVersion nDefVersion = aSaveOpt.GetODFDefaultVersion(); - // older versions can not have this property set, it exists only starting from ODF1.2 - if ( nDefVersion >= SvtSaveOptions::ODFVER_012 ) - aVersion = ODFVER_012_TEXT; + uno::Sequence< beans::NamedValue > aEncryptionAlgs( 3 ); + aEncryptionAlgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StartKeyGenerationAlgorithm" ) ); + aEncryptionAlgs[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionAlgorithm" ) ); + aEncryptionAlgs[2].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChecksumAlgorithm" ) ); + // the default values, that should be used for ODF1.1 and older formats + aEncryptionAlgs[0].Value <<= xml::crypto::DigestID::SHA1; + aEncryptionAlgs[1].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8; + aEncryptionAlgs[2].Value <<= xml::crypto::DigestID::SHA1_1K; - if ( aVersion.getLength() ) + if ( nDefVersion >= SvtSaveOptions::ODFVER_012 ) { try { - xProps->setPropertyValue( ::rtl::OUString::createFromAscii( "Version" ), uno::makeAny( aVersion ) ); + // older versions can not have this property set, it exists only starting from ODF1.2 + xProps->setPropertyValue( ::rtl::OUString::createFromAscii( "Version" ), uno::makeAny( ODFVER_012_TEXT ) ); } catch( uno::Exception& ) { } + + if ( !aSaveOpt.IsUseSHA1InODF12() ) + { + aEncryptionAlgs[0].Value <<= xml::crypto::DigestID::SHA256; + aEncryptionAlgs[2].Value <<= xml::crypto::DigestID::SHA256_1K; + } + if ( !aSaveOpt.IsUseBlowfishInODF12() ) + aEncryptionAlgs[1].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING; + } + + try + { + // set the encryption algorithms accordingly; + // the setting does not trigger encryption, + // it just provides the format for the case that contents should be encrypted + uno::Reference< embed::XEncryptionProtectedStorage > xEncr( xStorage, uno::UNO_QUERY_THROW ); + xEncr->setEncryptionAlgorithms( aEncryptionAlgs ); } + catch( uno::Exception& ) + { + const_cast<SfxObjectShell*>( this )->SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); + } + } } } diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index 3da1f374af1c..19169e90b984 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -29,6 +29,7 @@ #include "precompiled_sfx2.hxx" #include "arrdecl.hxx" +#include <map> #include <cppuhelper/implbase1.hxx> @@ -41,15 +42,9 @@ #include <com/sun/star/frame/XTitle.hpp> #include <vos/mutex.hxx> -#ifndef _SV_RESARY_HXX #include <tools/resary.hxx> -#endif -#ifndef _MSGBOX_HXX //autogen #include <vcl/msgbox.hxx> -#endif -#ifndef _WRKWIN_HXX //autogen #include <vcl/wrkwin.hxx> -#endif #include <vcl/svapp.hxx> #include <svl/eitem.hxx> #include <tools/rtti.hxx> @@ -64,15 +59,11 @@ #include <sfx2/signaturestate.hxx> #include <sfx2/sfxmodelfactory.hxx> -#ifndef _BASIC_SBUNO_HXX #include <basic/sbuno.hxx> -#endif #include <svtools/sfxecode.hxx> #include <svtools/ehdl.hxx> #include <unotools/printwarningoptions.hxx> -#ifndef _UNOTOOLS_PROCESSFACTORY_HXX #include <comphelper/processfactory.hxx> -#endif #include <com/sun/star/document/XStorageBasedDocument.hpp> #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp> @@ -132,8 +123,37 @@ DBG_NAME(SfxObjectShell) #define DocumentInfo #include "sfxslots.hxx" +namespace { + static WeakReference< XInterface > s_xCurrentComponent; +// remember all registered components for VBA compatibility, to be able to remove them on disposing the model +typedef ::std::map< XInterface*, ::rtl::OString > VBAConstantNameMap; +static VBAConstantNameMap s_aRegisteredVBAConstants; + +::rtl::OString lclGetVBAGlobalConstName( const Reference< XInterface >& rxComponent ) +{ + OSL_ENSURE( rxComponent.is(), "lclGetVBAGlobalConstName - missing component" ); + + VBAConstantNameMap::iterator aIt = s_aRegisteredVBAConstants.find( rxComponent.get() ); + if( aIt != s_aRegisteredVBAConstants.end() ) + return aIt->second; + + uno::Reference< beans::XPropertySet > xProps( rxComponent, uno::UNO_QUERY ); + if( xProps.is() ) try + { + ::rtl::OUString aConstName; + xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobalConstantName" ) ) ) >>= aConstName; + return ::rtl::OUStringToOString( aConstName, RTL_TEXTENCODING_ASCII_US ); + } + catch( uno::Exception& ) // not supported + { + } + return ::rtl::OString(); +} + +} // namespace + //========================================================================= @@ -164,14 +184,29 @@ void SAL_CALL SfxModelListener_Impl::notifyClosing( const com::sun::star::lang:: void SAL_CALL SfxModelListener_Impl::disposing( const com::sun::star::lang::EventObject& _rEvent ) throw ( com::sun::star::uno::RuntimeException ) { - // am I ThisComponent in AppBasic? ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + // am I ThisComponent in AppBasic? if ( SfxObjectShell::GetCurrentComponent() == _rEvent.Source ) { // remove ThisComponent reference from AppBasic SfxObjectShell::SetCurrentComponent( Reference< XInterface >() ); } + /* Remove VBA component from AppBasic. As every application registers its + own current component, the disposed component may not be the "current + component" of the SfxObjectShell. */ + if ( _rEvent.Source.is() ) + { + VBAConstantNameMap::iterator aIt = s_aRegisteredVBAConstants.find( _rEvent.Source.get() ); + if ( aIt != s_aRegisteredVBAConstants.end() ) + { + if ( BasicManager* pAppMgr = SFX_APP()->GetBasicManager() ) + pAppMgr->SetGlobalUNOConstant( aIt->second.getStr(), Any( Reference< XInterface >() ) ); + s_aRegisteredVBAConstants.erase( aIt ); + } + } + if ( !mpDoc->Get_Impl()->bClosing ) // GCC stuerzt ab, wenn schon im dtor, also vorher Flag abfragen mpDoc->DoClose(); @@ -908,8 +943,8 @@ sal_uInt16 SfxObjectShell::GetAutoStyleFilterIndex() void SfxObjectShell::SetCurrentComponent( const Reference< XInterface >& _rxComponent ) { - Reference< XInterface > xTest(s_xCurrentComponent); - if ( _rxComponent == xTest ) + Reference< XInterface > xOldCurrentComp(s_xCurrentComponent); + if ( _rxComponent == xOldCurrentComp ) // nothing to do return; // note that "_rxComponent.get() == s_xCurrentComponent.get().get()" is /sufficient/, but not @@ -920,7 +955,31 @@ void SfxObjectShell::SetCurrentComponent( const Reference< XInterface >& _rxComp BasicManager* pAppMgr = SFX_APP()->GetBasicManager(); s_xCurrentComponent = _rxComponent; if ( pAppMgr ) - pAppMgr->SetGlobalUNOConstant( "ThisComponent", makeAny( _rxComponent ) ); + { + // set "ThisComponent" for Basic + pAppMgr->SetGlobalUNOConstant( "ThisComponent", Any( _rxComponent ) ); + + // set new current component for VBA compatibility + if ( _rxComponent.is() ) + { + ::rtl::OString aVBAConstName = lclGetVBAGlobalConstName( _rxComponent ); + if ( aVBAConstName.getLength() > 0 ) + { + pAppMgr->SetGlobalUNOConstant( aVBAConstName.getStr(), Any( _rxComponent ) ); + s_aRegisteredVBAConstants[ _rxComponent.get() ] = aVBAConstName; + } + } + // no new component passed -> remove last registered VBA component + else if ( xOldCurrentComp.is() ) + { + ::rtl::OString aVBAConstName = lclGetVBAGlobalConstName( xOldCurrentComp ); + if ( aVBAConstName.getLength() > 0 ) + { + pAppMgr->SetGlobalUNOConstant( aVBAConstName.getStr(), Any( Reference< XInterface >() ) ); + s_aRegisteredVBAConstants.erase( xOldCurrentComp.get() ); + } + } + } } Reference< XInterface > SfxObjectShell::GetCurrentComponent() diff --git a/solenv/bin/checkdll.sh b/solenv/bin/checkdll.sh index a9a502c7f6af..efafb6b8ef60 100755 --- a/solenv/bin/checkdll.sh +++ b/solenv/bin/checkdll.sh @@ -42,7 +42,7 @@ if [ -x $checkdll ]; then -L) shift; option=$1;; --) break;; esac - case "${libpath+X}" in + case "${libpath:+X}" in X) libpath=$libpath:$option;; *) libpath=$option;; esac diff --git a/solenv/gbuild/Output.mk b/solenv/gbuild/Output.mk index dabb9b080d09..1056548e9442 100644 --- a/solenv/gbuild/Output.mk +++ b/solenv/gbuild/Output.mk @@ -97,8 +97,8 @@ gb_Output_COLOR_ERROR := $(gb_Output_COLOR_RESETANDESCAPE)[37;1;41m define gb_Output__format_type $(subst :, ,$(word 2,$(1) \ - $(gb_Output_COLOR_OUTBUILD_LEVEL$(3))[:$(gb_Output_COLOR_INBUILD_LEVEL$(3))__.oO:$(subst $(WHITESPACE),:,$(2))$(gb_Output_COLOR_OUTBUILD_LEVEL$(3)):] \ - $(gb_Output_COLOR_OUTCLEAN_LEVEL$(3))[:$(gb_Output_COLOR_INCLEAN_LEVEL$(3))Xx.__:$(subst $(WHITESPACE),:,$(2))$(gb_Output_COLOR_OUTCLEAN_LEVEL$(3)):]))$(gb_Output_COLOR_RESET) + $(gb_Output_COLOR_OUTBUILD_LEVEL$(3))[:$(gb_Output_COLOR_INBUILD_LEVEL$(3))build:$(subst $(WHITESPACE),:,$(2))$(gb_Output_COLOR_OUTBUILD_LEVEL$(3)):] \ + $(gb_Output_COLOR_OUTCLEAN_LEVEL$(3))[:$(gb_Output_COLOR_INCLEAN_LEVEL$(3))clean:$(subst $(WHITESPACE),:,$(2))$(gb_Output_COLOR_OUTCLEAN_LEVEL$(3)):]))$(gb_Output_COLOR_RESET) endef define gb_Output_info diff --git a/solenv/gbuild/platform/solaris.mk b/solenv/gbuild/platform/solaris.mk index f39f3e559385..30ba1350f532 100644 --- a/solenv/gbuild/platform/solaris.mk +++ b/solenv/gbuild/platform/solaris.mk @@ -101,6 +101,8 @@ gb_LinkTarget_LDFLAGS := \ -temp=/tmp \ -w \ -mt \ + -Bdirect \ + -z defs \ -z combreloc \ -norunpath \ -PIC \ @@ -248,11 +250,16 @@ gb_Library_OOOEXT := ss$(gb_Library_PLAINEXT) gb_Library_UNOEXT := .uno$(gb_Library_PLAINEXT) endif +gb_STDLIBS := \ + Crun \ + m \ + c \ + gb_Library_PLAINLIBS_NONE += \ + $(gb_STDLIBS) \ dl \ freetype \ jpeg \ - m \ pthread \ X11 \ Xext \ diff --git a/solenv/inc/minor.mk b/solenv/inc/minor.mk index 89c11311ca3d..4b42cd7b34c9 100644 --- a/solenv/inc/minor.mk +++ b/solenv/inc/minor.mk @@ -1,5 +1,5 @@ RSCVERSION=300 -RSCREVISION=300m105(Build:9581) -BUILD=9581 -LAST_MINOR=m105 +RSCREVISION=300m106(Build:9582) +BUILD=9582 +LAST_MINOR=m106 SOURCEVERSION=DEV300 diff --git a/svtools/Library_svt.mk b/svtools/Library_svt.mk index f1c5dfef1590..c7dab0f17746 100644 --- a/svtools/Library_svt.mk +++ b/svtools/Library_svt.mk @@ -34,6 +34,7 @@ $(eval $(call gb_Library_add_precompiled_header,svt,$(SRCDIR)/svtools/inc/pch/pr $(eval $(call gb_Library_set_componentfile,svt,svtools/util/svt)) $(eval $(call gb_Library_set_include,svt,\ + -I$(OUTDIR)/inc/external/jpeg \ $$(INCLUDE) \ -I$(WORKDIR)/inc/svtools \ -I$(WORKDIR)/inc/ \ diff --git a/svtools/source/filter/jpeg/jpeg.cxx b/svtools/source/filter/jpeg/jpeg.cxx index 6f157a248ddc..2f43b1b025f3 100644 --- a/svtools/source/filter/jpeg/jpeg.cxx +++ b/svtools/source/filter/jpeg/jpeg.cxx @@ -34,8 +34,8 @@ extern "C" { #include "stdio.h" #include "jpeg.h" - #include "jpeg/jpeglib.h" - #include "jpeg/jerror.h" + #include "jpeglib.h" + #include "jerror.h" } #define _JPEGPRIVATE diff --git a/svx/inc/svx/xoutbmp.hxx b/svx/inc/svx/xoutbmp.hxx index 1d0fca8de220..6dd59dbd6e57 100644..100755 --- a/svx/inc/svx/xoutbmp.hxx +++ b/svx/inc/svx/xoutbmp.hxx @@ -43,6 +43,7 @@ #define XOUTBMP_CONTOUR_HORZ 0x00000001L #define XOUTBMP_CONTOUR_VERT 0x00000002L #define XOUTBMP_CONTOUR_EDGEDETECT 0x00000004L +#define XOUTBMP_DONT_ADD_EXTENSION 0x00000008L #define XOUTBMP_DONT_EXPAND_FILENAME 0x10000000L #define XOUTBMP_USE_GIF_IF_POSSIBLE 0x20000000L diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx index e8958bf82479..62c434097699 100644..100755 --- a/svx/source/xoutdev/_xoutbmp.cxx +++ b/svx/source/xoutdev/_xoutbmp.cxx @@ -367,7 +367,8 @@ sal_uInt16 XOutBitmap::WriteGraphic( const Graphic& rGraphic, String& rFileName, if( aExt.Len() ) { - aURL.setExtension( aExt ); + if( 0 == (nFlags & XOUTBMP_DONT_ADD_EXTENSION)) + aURL.setExtension( aExt ); rFileName = aURL.GetMainURL( INetURLObject::NO_DECODE ); SfxMedium aMedium( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_SHARE_DENYNONE | STREAM_TRUNC, sal_True ); @@ -472,7 +473,8 @@ sal_uInt16 XOutBitmap::WriteGraphic( const Graphic& rGraphic, String& rFileName, if( ( GRFILTER_FORMAT_NOTFOUND != nFilter ) && ( aGraphic.GetType() != GRAPHIC_NONE ) ) { - aURL.setExtension( aExt ); + if( 0 == (nFlags & XOUTBMP_DONT_ADD_EXTENSION)) + aURL.setExtension( aExt ); rFileName = aURL.GetMainURL( INetURLObject::NO_DECODE ); nErr = ExportGraphic( aGraphic, aURL, *pFilter, nFilter, NULL ); } diff --git a/sw/source/core/draw/dflyobj.cxx b/sw/source/core/draw/dflyobj.cxx index 73616b18fc36..1fac4a1634a7 100644 --- a/sw/source/core/draw/dflyobj.cxx +++ b/sw/source/core/draw/dflyobj.cxx @@ -473,6 +473,52 @@ SwFrmFmt *SwVirtFlyDrawObj::GetFmt() |* *************************************************************************/ +// --> OD #i102707# +namespace +{ + class RestoreMapMode + { + public: + explicit RestoreMapMode( ViewShell* pViewShell ) + : mbMapModeRestored( false ) + , mpOutDev( pViewShell->GetOut() ) + { + if ( pViewShell->getPrePostMapMode() != mpOutDev->GetMapMode() ) + { + mpOutDev->Push(PUSH_MAPMODE); + + GDIMetaFile* pMetaFile = mpOutDev->GetConnectMetaFile(); + if ( pMetaFile && + pMetaFile->IsRecord() && !pMetaFile->IsPause() ) + { + ASSERT( false, + "MapMode restoration during meta file creation is somehow suspect - using <SetRelativeMapMode(..)>, but not sure, if correct." ) + mpOutDev->SetRelativeMapMode( pViewShell->getPrePostMapMode() ); + } + else + { + mpOutDev->SetMapMode( pViewShell->getPrePostMapMode() ); + } + + mbMapModeRestored = true; + } + }; + + ~RestoreMapMode() + { + if ( mbMapModeRestored ) + { + mpOutDev->Pop(); + } + }; + + private: + bool mbMapModeRestored; + OutputDevice* mpOutDev; + }; +} +// <-- + void SwVirtFlyDrawObj::wrap_DoPaintObject() const { ViewShell* pShell = pFlyFrm->getRootFrm()->GetCurrShell(); @@ -482,31 +528,29 @@ void SwVirtFlyDrawObj::wrap_DoPaintObject() const // but no paints. IsPaintInProgress() depends on SW repaint, so, as long // as SW paints self and calls DrawLayer() for Heaven and Hell, this will // be correct - if(pShell && pShell->IsDrawingLayerPaintInProgress()) + if ( pShell && pShell->IsDrawingLayerPaintInProgress() ) { sal_Bool bDrawObject(sal_True); - if(!SwFlyFrm::IsPaint((SdrObject*)this, pShell)) + if ( !SwFlyFrm::IsPaint( (SdrObject*)this, pShell ) ) { bDrawObject = sal_False; } - if(bDrawObject) + if ( bDrawObject ) { - if(!pFlyFrm->IsFlyInCntFrm()) + if ( !pFlyFrm->IsFlyInCntFrm() ) { // it is also necessary to restore the VCL MapMode from ViewInformation since e.g. // the VCL PixelRenderer resets it at the used OutputDevice. Unfortunately, this // excludes shears and rotates which are not expressable in MapMode. - OutputDevice* pOut = pShell->GetOut(); - - pOut->Push(PUSH_MAPMODE); - pOut->SetMapMode(pShell->getPrePostMapMode()); + // OD #i102707# + // new helper class to restore MapMode - restoration, only if + // needed and consideration of paint for meta file creation . + RestoreMapMode aRestoreMapModeIfNeeded( pShell ); // paint the FlyFrame (use standard VCL-Paint) - pFlyFrm->Paint(GetFlyFrm()->Frm()); - - pOut->Pop(); + pFlyFrm->Paint( GetFlyFrm()->Frm() ); } } } diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx index a5d54b82bfa6..eaf548d31d04 100644 --- a/sw/source/core/undo/undobj.cxx +++ b/sw/source/core/undo/undobj.cxx @@ -134,7 +134,7 @@ void SwUndRng::SetPaM( SwPaM & rPam, sal_Bool bCorrToCntnt ) const } SwPaM & SwUndRng::AddUndoRedoPaM( - ::sw::UndoRedoContext & rContext, bool bCorrToCntnt) const + ::sw::UndoRedoContext & rContext, bool const bCorrToCntnt) const { SwPaM & rPaM( rContext.GetCursorSupplier().CreateNewShellCursor() ); SetPaM( rPaM, bCorrToCntnt ); diff --git a/sw/source/ui/app/docsh2.cxx b/sw/source/ui/app/docsh2.cxx index 068ea736db3e..311d22271767 100755 --- a/sw/source/ui/app/docsh2.cxx +++ b/sw/source/ui/app/docsh2.cxx @@ -1113,6 +1113,8 @@ void SwDocShell::Execute(SfxRequest& rReq) case FN_OUTLINE_TO_CLIPBOARD: case FN_OUTLINE_TO_IMPRESS: { + sal_Bool bEnable = IsEnableSetModified(); + EnableSetModified( sal_False ); WriterRef xWrt; // mba: looks as if relative URLs don't make sense here ::GetRTFWriter( 'O', String(), xWrt ); @@ -1120,6 +1122,7 @@ void SwDocShell::Execute(SfxRequest& rReq) pStrm->SetBufferSize( 16348 ); SwWriter aWrt( *pStrm, *GetDoc() ); ErrCode eErr = aWrt.Write( xWrt ); + EnableSetModified( bEnable ); if( !ERRCODE_TOERROR( eErr ) ) { pStrm->Seek( STREAM_SEEK_TO_END ); diff --git a/sw/source/ui/dochdl/swdtflvr.cxx b/sw/source/ui/dochdl/swdtflvr.cxx index 1c9caac9b5e2..c12b4a9e7878 100644..100755 --- a/sw/source/ui/dochdl/swdtflvr.cxx +++ b/sw/source/ui/dochdl/swdtflvr.cxx @@ -154,24 +154,6 @@ using namespace nsTransferBufferType; #define DDE_TXT_ENCODING gsl_getSystemTextEncoding() -//--------------------------------------------- -// this struct conforms to the Microsoft -// OBJECTDESCRIPTOR -> see oleidl.h -// (MS platform sdk) -//--------------------------------------------- - -struct OleObjectDescriptor -{ - sal_uInt32 cbSize; - ClsId clsid; - sal_uInt32 dwDrawAspect; - Size sizel; - Point pointl; - sal_uInt32 dwStatus; - sal_uInt32 dwFullUserTypeName; - sal_uInt32 dwSrcOfCopy; -}; - class SwTrnsfrDdeLink : public ::sfx2::SvBaseLink { String sName; @@ -831,6 +813,10 @@ int SwTransferable::PrepareForCopy( sal_Bool bIsCut ) AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ); + // --> OD #i98753# + // set size of embedded object at the object description structure + aObjDesc.maSize = OutputDevice::LogicToLogic( pWrtShell->GetObjSize(), MAP_TWIP, MAP_100TH_MM ); + // <-- PrepareOLE( aObjDesc ); AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ); @@ -1688,7 +1674,9 @@ int SwTransferable::_PasteFileContent( TransferableDataHelper& rData, Link aOldLink( rSh.GetChgLnk() ); rSh.SetChgLnk( Link() ); + const SwPosition& rInsPos = *rSh.GetCrsr()->Start(); SwReader aReader( *pStream, aEmptyStr, String(), *rSh.GetCrsr() ); + rSh.SaveTblBoxCntnt( &rInsPos ); if( IsError( aReader.Read( *pRead )) ) nResId = ERR_CLPBRD_READ; else diff --git a/sw/source/ui/docvw/romenu.cxx b/sw/source/ui/docvw/romenu.cxx index 681eab61dee9..a50d89f7bb30 100644..100755 --- a/sw/source/ui/docvw/romenu.cxx +++ b/sw/source/ui/docvw/romenu.cxx @@ -424,7 +424,7 @@ String ExportGraphic( const Graphic &rGraphic, const String &rGrfName ) SvtPathOptions aPathOpt; String sGrfPath( aPathOpt.GetGraphicPath() ); - FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_SIMPLE, 0 ); + FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION, 0 ); Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker(); // aExpDlg.SetHelpId(HID_FILEDLG_ROMENU); @@ -512,7 +512,7 @@ String ExportGraphic( const Graphic &rGraphic, const String &rGrfName ) nFilter = GRFILTER_FORMAT_DONTKNOW; String aFilter( rGF.GetExportFormatShortName( nFilter ) ); XOutBitmap::WriteGraphic( rGraphic, sPath, aFilter, - XOUTBMP_DONT_EXPAND_FILENAME ); + XOUTBMP_DONT_EXPAND_FILENAME|XOUTBMP_DONT_ADD_EXTENSION ); return sPath; } } diff --git a/sw/source/ui/inc/view.hxx b/sw/source/ui/inc/view.hxx index bbf32cdea482..61d4d4b8702c 100644..100755 --- a/sw/source/ui/inc/view.hxx +++ b/sw/source/ui/inc/view.hxx @@ -284,6 +284,7 @@ class SW_DLLPUBLIC SwView: public SfxViewShell bInMailMerge : 1, bInDtor : 1, //detect destructor to prevent creating of sub shells while closing bOldShellWasPagePreView : 1, + bIsPreviewDoubleClick : 1, // #i114045# bMakeSelectionVisible : 1 // #b6330459# transport the bookmark selection ; diff --git a/sw/source/ui/uiview/view.cxx b/sw/source/ui/uiview/view.cxx index 2d392b4658ad..de524dd2706a 100644..100755 --- a/sw/source/ui/uiview/view.cxx +++ b/sw/source/ui/uiview/view.cxx @@ -787,7 +787,8 @@ SwView::SwView( SfxViewFrame *_pFrame, SfxViewShell* pOldSh ) nRightBorderDistance( 0 ), bInMailMerge(sal_False), bInDtor(sal_False), - bOldShellWasPagePreView(sal_False) + bOldShellWasPagePreView(sal_False), + bIsPreviewDoubleClick(sal_False) { // OD 18.12.2002 #103492# - According to discussion with MBA and further // investigations, no old SfxViewShell will be set as parameter <pOldSh>, @@ -844,6 +845,7 @@ SwView::SwView( SfxViewFrame *_pFrame, SfxViewShell* pOldSh ) sNewCrsrPos = ((SwPagePreView*)pExistingSh)->GetNewCrsrPos(); nNewPage = ((SwPagePreView*)pExistingSh)->GetNewPage(); bOldShellWasPagePreView = sal_True; + bIsPreviewDoubleClick = sNewCrsrPos.Len() > 0 || nNewPage != USHRT_MAX; } else if( pExistingSh->IsA( TYPE( SwSrcView ) ) ) bOldShellWasSrcView = sal_True; @@ -1292,7 +1294,7 @@ void SwView::ReadUserData( const String &rUserData, sal_Bool bBrowse ) void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >& rSequence, sal_Bool bBrowse ) { - if(GetDocShell()->IsPreview()) + if(GetDocShell()->IsPreview()||bIsPreviewDoubleClick) return; //#i43146# go to the last editing position when opening own files bool bIsOwnDocument = lcl_IsOwnDocument( *this ); diff --git a/sw/source/ui/vba/vbaapplication.cxx b/sw/source/ui/vba/vbaapplication.cxx index 8056f9ae3deb..aa7832a54dc5 100644 --- a/sw/source/ui/vba/vbaapplication.cxx +++ b/sw/source/ui/vba/vbaapplication.cxx @@ -97,7 +97,9 @@ uno::Reference< word::XWindow > SAL_CALL SwVbaApplication::getActiveWindow() throw (uno::RuntimeException) { // #FIXME sofar can't determine Parent - return new SwVbaWindow( uno::Reference< XHelperInterface >(), mxContext, getCurrentDocument() ); + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_SET_THROW ); + uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); + return new SwVbaWindow( uno::Reference< XHelperInterface >(), mxContext, xModel, xController ); } uno::Reference<word::XSystem > SAL_CALL diff --git a/sw/source/ui/vba/vbaeventshelper.cxx b/sw/source/ui/vba/vbaeventshelper.cxx index b2270b009ca9..197f02911e49 100755 --- a/sw/source/ui/vba/vbaeventshelper.cxx +++ b/sw/source/ui/vba/vbaeventshelper.cxx @@ -26,6 +26,7 @@ ************************************************************************/ #include "vbaeventshelper.hxx" +#include <com/sun/star/script/ModuleType.hpp> #include <com/sun/star/script/vba/VBAEventId.hpp> #include <vbahelper/helperdecl.hxx> @@ -38,12 +39,13 @@ using namespace ::ooo::vba; SwVbaEventsHelper::SwVbaEventsHelper( uno::Sequence< css::uno::Any > const& aArgs, uno::Reference< uno::XComponentContext > const& xContext ) : VbaEventsHelperBase( aArgs, xContext ) { - registerEventHandler( DOCUMENT_NEW, "Document_New", EVENTHANDLER_DOCUMENT ); - registerEventHandler( AUTO_NEW, "AutoNew", EVENTHANDLER_GLOBAL ); - registerEventHandler( DOCUMENT_OPEN, "Document_Open", EVENTHANDLER_DOCUMENT ); - registerEventHandler( AUTO_OPEN, "AutoOpen", EVENTHANDLER_GLOBAL ); - registerEventHandler( DOCUMENT_CLOSE, "Document_Close", EVENTHANDLER_DOCUMENT ); - registerEventHandler( AUTO_CLOSE, "AutoClose", EVENTHANDLER_GLOBAL ); + using namespace ::com::sun::star::script::ModuleType; + registerEventHandler( DOCUMENT_NEW, DOCUMENT, "Document_New" ); + registerEventHandler( AUTO_NEW, NORMAL, "AutoNew" ); + registerEventHandler( DOCUMENT_OPEN, DOCUMENT, "Document_Open" ); + registerEventHandler( AUTO_OPEN, NORMAL, "AutoOpen" ); + registerEventHandler( DOCUMENT_CLOSE, DOCUMENT, "Document_Close" ); + registerEventHandler( AUTO_CLOSE, NORMAL, "AutoClose" ); } SwVbaEventsHelper::~SwVbaEventsHelper() @@ -76,7 +78,7 @@ uno::Sequence< uno::Any > SwVbaEventsHelper::implBuildArgumentList( const EventH } void SwVbaEventsHelper::implPostProcessEvent( EventQueue& /*rEventQueue*/, - const EventHandlerInfo& /*rInfo*/, bool /*bSuccess*/, bool /*bCancel*/ ) throw (uno::RuntimeException) + const EventHandlerInfo& /*rInfo*/, bool /*bCancel*/ ) throw (uno::RuntimeException) { // nothing to do after any event } diff --git a/sw/source/ui/vba/vbaeventshelper.hxx b/sw/source/ui/vba/vbaeventshelper.hxx index 7f951bdaa452..044eaa33885e 100755 --- a/sw/source/ui/vba/vbaeventshelper.hxx +++ b/sw/source/ui/vba/vbaeventshelper.hxx @@ -43,7 +43,7 @@ public: protected: virtual bool implPrepareEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::uno::RuntimeException); virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList( const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException); - virtual void implPostProcessEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, bool bSuccess, bool bCancel ) throw (css::uno::RuntimeException); + virtual void implPostProcessEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, bool bCancel ) throw (css::uno::RuntimeException); virtual ::rtl::OUString implGetDocumentModuleName( const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) const throw (css::lang::IllegalArgumentException); }; diff --git a/sw/source/ui/vba/vbawindow.cxx b/sw/source/ui/vba/vbawindow.cxx index e3d9bddbc7aa..d74e25b39686 100644 --- a/sw/source/ui/vba/vbawindow.cxx +++ b/sw/source/ui/vba/vbawindow.cxx @@ -35,7 +35,12 @@ using namespace ::com::sun::star; using namespace ::ooo::vba; -SwVbaWindow::SwVbaWindow( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : WindowImpl_BASE( xParent, xContext, xModel ) +SwVbaWindow::SwVbaWindow( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< frame::XModel >& xModel, + const uno::Reference< frame::XController >& xController ) throw (uno::RuntimeException) : + WindowImpl_BASE( xParent, xContext, xModel, xController ) { } diff --git a/sw/source/ui/vba/vbawindow.hxx b/sw/source/ui/vba/vbawindow.hxx index 0809d2b73685..4893aa818399 100644 --- a/sw/source/ui/vba/vbawindow.hxx +++ b/sw/source/ui/vba/vbawindow.hxx @@ -38,8 +38,12 @@ typedef cppu::ImplInheritanceHelper1< VbaWindowBase, ov::word::XWindow > WindowI class SwVbaWindow : public WindowImpl_BASE { public: - SwVbaWindow( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::frame::XModel >& xModel ); - + SwVbaWindow( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::frame::XModel >& xModel, + const css::uno::Reference< css::frame::XController >& xController ) + throw (css::uno::RuntimeException); // Attributes virtual css::uno::Any SAL_CALL getView() throw (css::uno::RuntimeException); diff --git a/ucb/source/ucp/gvfs/gvfs_content.cxx b/ucb/source/ucp/gvfs/gvfs_content.cxx index 3b1d726f9304..666c0616ba0e 100644 --- a/ucb/source/ucp/gvfs/gvfs_content.cxx +++ b/ucb/source/ucp/gvfs/gvfs_content.cxx @@ -1177,7 +1177,7 @@ uno::Any Content::mapVFSException( const GnomeVFSResult result, sal_Bool bWrite switch (result) { case GNOME_VFS_OK: - g_error ("VFS_OK mapped to exception."); + g_warning("VFS_OK mapped to exception."); break; case GNOME_VFS_ERROR_EOF: g_warning ("VFS_EOF not handled somewhere."); diff --git a/unotools/inc/unotools/saveopt.hxx b/unotools/inc/unotools/saveopt.hxx index 22cf75c5be3d..9dab6150a8ad 100644 --- a/unotools/inc/unotools/saveopt.hxx +++ b/unotools/inc/unotools/saveopt.hxx @@ -53,7 +53,9 @@ public: E_DOPRETTYPRINTING, E_WARNALIENFORMAT, E_LOADDOCPRINTER, - E_ODFDEFAULTVERSION + E_ODFDEFAULTVERSION, + E_USESHA1INODF12, + E_USEBLOWFISHINODF12 }; // keep enum values sorted that a less or greater compare maps to older and newer versions! @@ -119,6 +121,12 @@ public: void SetODFDefaultVersion( ODFDefaultVersion eVersion ); ODFDefaultVersion GetODFDefaultVersion() const; + void SetUseSHA1InODF12( sal_Bool bUse ); + sal_Bool IsUseSHA1InODF12() const; + + void SetUseBlowfishInODF12( sal_Bool bUse ); + sal_Bool IsUseBlowfishInODF12() const; + sal_Bool IsReadOnly( EOption eOption ) const; }; diff --git a/unotools/source/config/saveopt.cxx b/unotools/source/config/saveopt.cxx index 379ba65dc9e6..6a30149c555f 100644 --- a/unotools/source/config/saveopt.cxx +++ b/unotools/source/config/saveopt.cxx @@ -79,7 +79,11 @@ class SvtSaveOptions_Impl : public utl::ConfigItem bSaveUnpacked, bDoPrettyPrinting, bWarnAlienFormat, - bLoadDocPrinter; + bLoadDocPrinter, + bUseSHA1InODF12, + bUseBlowfishInODF12; + + SvtSaveOptions::ODFDefaultVersion eODFDefaultVersion; sal_Bool bROAutoSaveTime, bROUseUserData, @@ -95,9 +99,9 @@ class SvtSaveOptions_Impl : public utl::ConfigItem bROWarnAlienFormat, bRODoPrettyPrinting, bROLoadDocPrinter, - bROODFDefaultVersion; - - SvtSaveOptions::ODFDefaultVersion eODFDefaultVersion; + bROODFDefaultVersion, + bROUseSHA1InODF12, + bROUseBlowfishInODF12; public: SvtSaveOptions_Impl(); @@ -120,6 +124,9 @@ public: sal_Bool IsPrettyPrintingEnabled( ) const { return bDoPrettyPrinting; } sal_Bool IsWarnAlienFormat() const { return bWarnAlienFormat; } sal_Bool IsLoadDocPrinter() const { return bLoadDocPrinter; } + sal_Bool IsUseSHA1InODF12() const { return bUseSHA1InODF12; } + sal_Bool IsUseBlowfishInODF12() const { return bUseBlowfishInODF12; } + SvtSaveOptions::ODFDefaultVersion GetODFDefaultVersion() const { return eODFDefaultVersion; } @@ -137,6 +144,8 @@ public: void EnablePrettyPrinting( sal_Bool _bDoPP ); void SetWarnAlienFormat( sal_Bool _bDoPP ); void SetLoadDocPrinter( sal_Bool bNew ); + void SetUseSHA1InODF12( sal_Bool bUse ); + void SetUseBlowfishInODF12( sal_Bool bUse ); void SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eNew ); sal_Bool IsReadOnly( SvtSaveOptions::EOption eOption ) const; @@ -279,6 +288,24 @@ void SvtSaveOptions_Impl::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersio } } +void SvtSaveOptions_Impl::SetUseSHA1InODF12( sal_Bool bUse ) +{ + if ( !bROUseSHA1InODF12 && bUseSHA1InODF12 != bUse ) + { + bUseSHA1InODF12 = bUse; + SetModified(); + } +} + +void SvtSaveOptions_Impl::SetUseBlowfishInODF12( sal_Bool bUse ) +{ + if ( !bROUseBlowfishInODF12 && bUseBlowfishInODF12 != bUse ) + { + bUseBlowfishInODF12 = bUse; + SetModified(); + } +} + sal_Bool SvtSaveOptions_Impl::IsReadOnly( SvtSaveOptions::EOption eOption ) const { sal_Bool bReadOnly = CFG_READONLY_DEFAULT; @@ -329,6 +356,12 @@ sal_Bool SvtSaveOptions_Impl::IsReadOnly( SvtSaveOptions::EOption eOption ) cons case SvtSaveOptions::E_ODFDEFAULTVERSION : bReadOnly = bROLoadDocPrinter; break; + case SvtSaveOptions::E_USESHA1INODF12: + bReadOnly = bROUseSHA1InODF12; + break; + case SvtSaveOptions::E_USEBLOWFISHINODF12: + bReadOnly = bROUseBlowfishInODF12; + break; } return bReadOnly; } @@ -349,6 +382,8 @@ sal_Bool SvtSaveOptions_Impl::IsReadOnly( SvtSaveOptions::EOption eOption ) cons #define INTERNET 13 #define SAVEWORKINGSET 14 #define ODFDEFAULTVERSION 15 +#define USESHA1INODF12 16 +#define USEBLOWFISHINODF12 17 Sequence< OUString > GetPropertyNames() { @@ -369,7 +404,9 @@ Sequence< OUString > GetPropertyNames() "URL/FileSystem", "URL/Internet", "WorkingSet", - "ODF/DefaultVersion" + "ODF/DefaultVersion", + "ODF/UseSHA1InODF12", + "ODF/UseBlowfishInODF12" }; const int nCount = sizeof( aPropNames ) / sizeof( const char* ); @@ -399,6 +436,9 @@ SvtSaveOptions_Impl::SvtSaveOptions_Impl() , bDoPrettyPrinting( sal_False ) , bWarnAlienFormat( sal_True ) , bLoadDocPrinter( sal_True ) + , bUseSHA1InODF12( sal_False ) + , bUseBlowfishInODF12( sal_False ) + , eODFDefaultVersion( SvtSaveOptions::ODFVER_LATEST ) , bROAutoSaveTime( CFG_READONLY_DEFAULT ) , bROUseUserData( CFG_READONLY_DEFAULT ) , bROBackup( CFG_READONLY_DEFAULT ) @@ -414,7 +454,8 @@ SvtSaveOptions_Impl::SvtSaveOptions_Impl() , bRODoPrettyPrinting( CFG_READONLY_DEFAULT ) , bROLoadDocPrinter( CFG_READONLY_DEFAULT ) , bROODFDefaultVersion( CFG_READONLY_DEFAULT ) - , eODFDefaultVersion( SvtSaveOptions::ODFVER_LATEST ) + , bROUseSHA1InODF12( CFG_READONLY_DEFAULT ) + , bROUseBlowfishInODF12( CFG_READONLY_DEFAULT ) { Sequence< OUString > aNames = GetPropertyNames(); Sequence< Any > aValues = GetProperties( aNames ); @@ -527,6 +568,16 @@ SvtSaveOptions_Impl::SvtSaveOptions_Impl() bROLoadDocPrinter = pROStates[nProp]; break; + case USESHA1INODF12: + bUseSHA1InODF12 = bTemp; + bROUseSHA1InODF12 = pROStates[nProp]; + break; + + case USEBLOWFISHINODF12: + bUseBlowfishInODF12 = bTemp; + bROUseBlowfishInODF12 = pROStates[nProp]; + break; + default : DBG_ERRORFILE( "invalid index to load a path" ); } @@ -704,6 +755,23 @@ void SvtSaveOptions_Impl::Commit() ++nRealCount; } break; + case USESHA1INODF12: + if (!bROUseSHA1InODF12) + { + pValues[nRealCount] <<= bUseSHA1InODF12; + pNames[nRealCount] = pOrgNames[i]; + ++nRealCount; + } + break; + case USEBLOWFISHINODF12: + if (!bROUseBlowfishInODF12) + { + pValues[nRealCount] <<= bUseBlowfishInODF12; + pNames[nRealCount] = pOrgNames[i]; + ++nRealCount; + } + break; + default: DBG_ERRORFILE( "invalid index to save a path" ); } @@ -995,6 +1063,26 @@ SvtSaveOptions::ODFDefaultVersion SvtSaveOptions::GetODFDefaultVersion() const return pImp->pSaveOpt->GetODFDefaultVersion(); } +void SvtSaveOptions::SetUseSHA1InODF12( sal_Bool bUse ) +{ + pImp->pSaveOpt->SetUseSHA1InODF12( bUse ); +} + +sal_Bool SvtSaveOptions::IsUseSHA1InODF12() const +{ + return pImp->pSaveOpt->IsUseSHA1InODF12(); +} + +void SvtSaveOptions::SetUseBlowfishInODF12( sal_Bool bUse ) +{ + pImp->pSaveOpt->SetUseBlowfishInODF12( bUse ); +} + +sal_Bool SvtSaveOptions::IsUseBlowfishInODF12() const +{ + return pImp->pSaveOpt->IsUseBlowfishInODF12(); +} + sal_Bool SvtSaveOptions::IsReadOnly( SvtSaveOptions::EOption eOption ) const { return pImp->pSaveOpt->IsReadOnly(eOption); diff --git a/vbahelper/Library_msforms.mk b/vbahelper/Library_msforms.mk index 3e23c492f32b..58a90a7ccd42 100755 --- a/vbahelper/Library_msforms.mk +++ b/vbahelper/Library_msforms.mk @@ -50,17 +50,17 @@ $(eval $(call gb_Library_add_linked_libs,msforms,\ comphelper \ cppu \ cppuhelper \ + sal \ + sb \ + sfx \ svl \ svt \ + svx \ + stl \ + tk \ tl \ - sal \ vbahelper \ - sfx \ - svx \ vcl \ - tk \ - sb \ - stl \ $(gb_STDLIBS) \ )) @@ -79,6 +79,7 @@ $(eval $(call gb_Library_add_exception_objects,msforms,\ vbahelper/source/msforms/vbalistbox \ vbahelper/source/msforms/vbalistcontrolhelper \ vbahelper/source/msforms/vbamultipage \ + vbahelper/source/msforms/vbanewfont \ vbahelper/source/msforms/vbapages \ vbahelper/source/msforms/vbaprogressbar \ vbahelper/source/msforms/vbaradiobutton \ diff --git a/vbahelper/Library_vbahelper.mk b/vbahelper/Library_vbahelper.mk index 722b66d709a1..af6b4089ada8 100755 --- a/vbahelper/Library_vbahelper.mk +++ b/vbahelper/Library_vbahelper.mk @@ -50,25 +50,27 @@ $(eval $(call gb_Library_set_defs,vbahelper,\ # add libraries to be linked to vbahelper; again these names need to be given as # specified in Repository.mk $(eval $(call gb_Library_add_linked_libs,vbahelper,\ + comphelper \ cppu \ cppuhelper \ - comphelper \ - sb \ - tl \ + msfilter \ sal \ + sb \ sfx \ stl \ - svt \ - vcl \ svl \ - msfilter \ + svt \ tk \ + tl \ + utl \ + vcl \ $(gb_STDLIBS) \ )) # add all source files that shall be compiled with exceptions enabled # the name is relative to $(SRCROOT) and must not contain an extension $(eval $(call gb_Library_add_exception_objects,vbahelper,\ + vbahelper/source/vbahelper/collectionbase \ vbahelper/source/vbahelper/vbaapplicationbase \ vbahelper/source/vbahelper/vbacolorformat \ vbahelper/source/vbahelper/vbacommandbar \ diff --git a/vbahelper/Package_inc.mk b/vbahelper/Package_inc.mk index 6d8033aa5b02..385fbf15a625 100755 --- a/vbahelper/Package_inc.mk +++ b/vbahelper/Package_inc.mk @@ -26,6 +26,7 @@ #************************************************************************* $(eval $(call gb_Package_Package,vbahelper_inc,$(SRCDIR)/vbahelper/inc)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/collectionbase.hxx,vbahelper/collectionbase.hxx)) $(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/helperdecl.hxx,vbahelper/helperdecl.hxx)) $(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbaaccesshelper.hxx,vbahelper/vbaaccesshelper.hxx)) $(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbaapplicationbase.hxx,vbahelper/vbaapplicationbase.hxx)) @@ -47,5 +48,6 @@ $(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbashaperange.hxx, $(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbashapes.hxx,vbahelper/vbashapes.hxx)) $(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbatextframe.hxx,vbahelper/vbatextframe.hxx)) $(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbawindowbase.hxx,vbahelper/vbawindowbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/weakreference.hxx,vbahelper/weakreference.hxx)) # vim: set noet sw=4 ts=4: diff --git a/vbahelper/inc/vbahelper/collectionbase.hxx b/vbahelper/inc/vbahelper/collectionbase.hxx new file mode 100755 index 000000000000..ebb5bf8f2b9a --- /dev/null +++ b/vbahelper/inc/vbahelper/collectionbase.hxx @@ -0,0 +1,214 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2011 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. + * + ************************************************************************/ + +#ifndef VBAHELPER_COLLECTIONBASE_HXX +#define VBAHELPER_COLLECTIONBASE_HXX + +#include <vector> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/container/XElementAccess.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <ooo/vba/XCollectionBase.hpp> +#include <cppuhelper/implbase1.hxx> +#include <vbahelper/vbahelper.hxx> + +namespace vbahelper { + +// ============================================================================ + +typedef ::cppu::WeakImplHelper1< ov::XCollectionBase > CollectionBase_BASE; + +/** Base class of VBA objects implementing the VBA collection concept. + + This base class intentionally does not include the interface + XHelperInterface supported by all application VBA object. There may be + other VBA objects that do not support the special methods provided by + XHelperInterface. + */ +class VBAHELPER_DLLPUBLIC CollectionBase : public CollectionBase_BASE +{ +public: + /** Enumerates different container types a VBA collection can be based on. */ + enum ContainerType + { + /** Container elements are VBA items. + + The initial container contains the final VBA items provided by the + VBA collection. No conversion takes place on item access. + */ + CONTAINER_NATIVE_VBA, + + /** Container elements will be converted to VBA items on demand. + + The initial container contains intermediate objects (e.g. UNO + objects) which will be converted to VBA items everytime the item is + accessed (e.g. item access method, enumeration). Changes in the + initial container are reflected by the collection. + */ + CONTAINER_CONVERT_ON_DEMAND, + }; + + // ------------------------------------------------------------------------ + + CollectionBase( const css::uno::Type& rElementType ); + + // ------------------------------------------------------------------------ + + // attributes + virtual sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException); + // XDefaultMethod + virtual ::rtl::OUString SAL_CALL getDefaultMethodName() throw (css::uno::RuntimeException); + + // ------------------------------------------------------------------------ + + /** Associates this collection with the passed UNO container. + + @param rxElementAccess + The UNO container with the elements of this collection. Shall + support either XIndexAccess or XNameAccess, may support both. + + If the container does not support XIndexAccess, index access is + simulated based on the order returned by the function + XNameAccess::getElementNames(). + + If the container does not support XNameAccess, name access is + simulated by iterating the elements via index access and asking the + elements for their name via the interface XNamed. If the elements + do not support XNamed, the elements cannot be accessed by name. + + @param eContainerType + Specifies the type of the passed container. + */ + void initContainer( + const css::uno::Reference< css::container::XElementAccess >& rxElementAccess, + ContainerType eContainerType ) throw (css::uno::RuntimeException); + + /** Initializes this collection with copies of all elements in the passed + temporary STL vector. + + @param rElements + The STL vector with the named elements of this collection. + @param eContainerType + Specifies the type of the passed vector. + */ + void initElements( + const ::std::vector< css::uno::Reference< css::container::XNamed > >& rElements, + ContainerType eContainerType ) throw (css::uno::RuntimeException); + + /** Initializes this collection with copies of all elements in the passed + temporary STL vector. + + @param rElements + The STL vector with the named elements of this collection. + @param eContainerType + Specifies the type of the passed vector. + */ + void initElements( + const ::std::vector< css::beans::NamedValue >& rElements, + ContainerType eContainerType ) throw (css::uno::RuntimeException); + + /** Returns a VBA implementation object from the passed element. + + If the container type is CONTAINER_NATIVE_VBA, returns the passed + object unmodified. If the container type is CONTAINER_CONVERT_ON_DEMAND, + calls the virtual function implCreateCollectionItem() that implements + creation of the VBA implmentation object. + + @param rElement + The container element the VBA implementation object is based on. + + @param rIndex + The index or name that has been used to access the item. + */ + css::uno::Any createCollectionItem( + const css::uno::Any& rElement, + const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + + /** Returns a collection item specified by its one-based item index. + + @param nIndex + The one-based index of the collection item. + */ + css::uno::Any getItemByIndex( sal_Int32 nIndex ) throw (css::uno::RuntimeException); + + /** Returns a collection item specified by its name. + + @param rName + The name of the collection item. + */ + css::uno::Any getItemByName( const ::rtl::OUString& rName ) throw (css::uno::RuntimeException); + + /** Returns a collection item specified by its index or name. + + @param rIndex + The index or name of the collection item. May be empty, in that + case the entire collection is returned. + */ + css::uno::Any getAnyItemOrThis( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + + /** Returns a collection item of a specific type specified by its index or + name. + + @param rIndex + The index or name of the collection item. + */ + template< typename XType > + inline css::uno::Reference< XType > getAnyItem( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException) + { css::uno::Any aRet; if( rIndex.hasValue() ) aRet = getAnyItemOrThis( rIndex ); return css::uno::Reference< XType >( aRet, css::uno::UNO_QUERY_THROW ); } + +protected: + /** Derived classes implement creation of a VBA implementation object from + the passed intermediate container element. + + May be kept unimplemented if container type is CONTAINER_NATIVE_VBA. + + @param rElement + The container element the VBA implementation object is based on. + + @param rIndex + The index or name used to access the item. Can be used by + implementations as a hint how to find or convert the VBA object. + */ + virtual css::uno::Any implCreateCollectionItem( const css::uno::Any& rElement, const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + +private: + css::uno::Reference< css::container::XIndexAccess > mxIndexAccess; + css::uno::Reference< css::container::XNameAccess > mxNameAccess; + css::uno::Type maElementType; + bool mbConvertOnDemand; +}; + +// ============================================================================ + +} // namespace vbahelper + +#endif diff --git a/vbahelper/inc/vbahelper/vbaapplicationbase.hxx b/vbahelper/inc/vbahelper/vbaapplicationbase.hxx index 6902bc7b5042..10cf0ba6ab70 100644 --- a/vbahelper/inc/vbahelper/vbaapplicationbase.hxx +++ b/vbahelper/inc/vbahelper/vbaapplicationbase.hxx @@ -60,7 +60,6 @@ public: virtual css::uno::Any SAL_CALL CommandBars( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getVersion() throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL getVBE() throw (css::uno::RuntimeException); - virtual css::uno::Any SAL_CALL getVBProjects() throw (css::uno::RuntimeException); virtual void SAL_CALL Run( const ::rtl::OUString& MacroName, const css::uno::Any& varg1, const css::uno::Any& varg2, const css::uno::Any& varg3, const css::uno::Any& varg4, const css::uno::Any& varg5, const css::uno::Any& varg6, const css::uno::Any& varg7, const css::uno::Any& varg8, const css::uno::Any& varg9, const css::uno::Any& varg10, const css::uno::Any& varg11, const css::uno::Any& varg12, const css::uno::Any& varg13, const css::uno::Any& varg14, const css::uno::Any& varg15, const css::uno::Any& varg16, const css::uno::Any& varg17, const css::uno::Any& varg18, const css::uno::Any& varg19, const css::uno::Any& varg20, const css::uno::Any& varg21, const css::uno::Any& varg22, const css::uno::Any& varg23, const css::uno::Any& varg24, const css::uno::Any& varg25, const css::uno::Any& varg26, const css::uno::Any& varg27, const css::uno::Any& varg28, const css::uno::Any& varg29, const css::uno::Any& varg30 ) throw (css::uno::RuntimeException); virtual void SAL_CALL OnTime( const css::uno::Any& aEarliestTime, const ::rtl::OUString& aFunction, const css::uno::Any& aLatestTime, const css::uno::Any& aSchedule ) throw (css::uno::RuntimeException); diff --git a/vbahelper/inc/vbahelper/vbacollectionimpl.hxx b/vbahelper/inc/vbahelper/vbacollectionimpl.hxx index 601d996a5e64..da0fd29267ae 100644 --- a/vbahelper/inc/vbahelper/vbacollectionimpl.hxx +++ b/vbahelper/inc/vbahelper/vbacollectionimpl.hxx @@ -88,8 +88,8 @@ private: /** A wrapper that holds a com.sun.star.container.XEnumeration or a com.sun.star.container.XIndexAccess and provides an enumeration of VBA objects. - The method nextElement() needs to be implemented by the derived class. This - class can be used to convert an enumeration or an index container + The method createCollectionObject() needs to be implemented by the derived + class. This class can be used to convert an enumeration or an index container containing UNO objects to an enumeration providing the related VBA objects. */ class VBAHELPER_DLLPUBLIC SimpleEnumerationBase : public EnumerationHelper_BASE diff --git a/vbahelper/inc/vbahelper/vbadocumentbase.hxx b/vbahelper/inc/vbahelper/vbadocumentbase.hxx index 2588b7da1720..d1c7320fbfb1 100644 --- a/vbahelper/inc/vbahelper/vbadocumentbase.hxx +++ b/vbahelper/inc/vbahelper/vbadocumentbase.hxx @@ -37,6 +37,7 @@ class VBAHELPER_DLLPUBLIC VbaDocumentBase : public VbaDocumentBase_BASE { protected: css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::uno::XInterface > mxVBProject; protected: virtual css::uno::Reference< css::frame::XModel > getModel() { return mxModel; } VbaDocumentBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext); diff --git a/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx b/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx index 659837535ace..dc554d6a043f 100755 --- a/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx +++ b/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx @@ -28,20 +28,26 @@ #ifndef VBAHELPER_VBAEVENTSHELPERBASE_HXX #define VBAHELPER_VBAEVENTSHELPERBASE_HXX -#include <com/sun/star/lang/XEventListener.hpp> -#include <com/sun/star/script/vba/XVBAEventProcessor.hpp> -#include <cppuhelper/implbase2.hxx> -#include <map> #include <deque> +#include <hash_map> +#include <map> +#include <com/sun/star/document/XEventListener.hpp> +#include <com/sun/star/script/vba/XVBAEventProcessor.hpp> +#include <com/sun/star/util/XChangesListener.hpp> +#include <cppuhelper/implbase3.hxx> #include "vbahelper/vbahelper.hxx" namespace com { namespace sun { namespace star { + namespace script { namespace vba { class XVBAModuleInfo; } } namespace uno { class XComponentContext; } } } } // ============================================================================ -typedef ::cppu::WeakImplHelper2< css::script::vba::XVBAEventProcessor, css::lang::XEventListener > VbaEventsHelperBase_BASE; +typedef ::cppu::WeakImplHelper3< + css::script::vba::XVBAEventProcessor, + css::document::XEventListener, + css::util::XChangesListener > VbaEventsHelperBase_BASE; class VBAHELPER_DLLPUBLIC VbaEventsHelperBase : public VbaEventsHelperBase_BASE { @@ -51,15 +57,24 @@ public: const css::uno::Reference< css::uno::XComponentContext >& xContext ); virtual ~VbaEventsHelperBase(); - // XVBAEventProcessor + // script::vba::XVBAEventProcessor virtual sal_Bool SAL_CALL hasVbaEventHandler( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); - virtual void SAL_CALL processVbaEvent( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::script::provider::ScriptFrameworkErrorException, css::util::VetoException, css::uno::RuntimeException); + virtual sal_Bool SAL_CALL processVbaEvent( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::util::VetoException, css::uno::RuntimeException); - // XEventListener - virtual void SAL_CALL disposing( const css::lang::EventObject& aSource ) throw (css::uno::RuntimeException); + // document::XEventListener + virtual void SAL_CALL notifyEvent( const css::document::EventObject& rEvent ) throw (css::uno::RuntimeException); + + // util::XChangesListener + virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& rEvent ) throw (css::uno::RuntimeException); + + // lang::XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& rEvent ) throw (css::uno::RuntimeException); // little helpers --------------------------------------------------------- + /** Helper to execute event handlers without throwing any exceptions. */ + void processVbaEventNoThrow( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ); + /** Throws, if the passed sequence does not contain a value at the specified index. */ static inline void checkArgument( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException) { if( (nIndex < 0) || (nIndex >= rArgs.getLength()) ) throw css::lang::IllegalArgumentException(); } @@ -72,12 +87,11 @@ public: protected: // ------------------------------------------------------------------------ - enum EventHandlerType { EVENTHANDLER_GLOBAL, EVENTHANDLER_DOCUMENT }; struct EventHandlerInfo { sal_Int32 mnEventId; + sal_Int32 mnModuleType; ::rtl::OUString maMacroName; - EventHandlerType meType; sal_Int32 mnCancelIndex; css::uno::Any maUserData; }; @@ -85,14 +99,14 @@ protected: /** Registers a supported event handler. @param nEventId Event identifier from com.sun.star.script.vba.VBAEventId. + @param nModuleType Type of the module containing the event handler. @param pcMacroName Name of the associated VBA event handler macro. - @param eType Document event or global event. @param nCancelIndex 0-based index of Cancel parameter, or -1. @param rUserData User data for free usage in derived implementations. */ void registerEventHandler( sal_Int32 nEventId, + sal_Int32 nModuleType, const sal_Char* pcMacroName, - EventHandlerType eType = EVENTHANDLER_DOCUMENT, sal_Int32 nCancelIndex = -1, const css::uno::Any& rUserData = css::uno::Any() ); @@ -124,7 +138,6 @@ protected: virtual void implPostProcessEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, - bool bSuccess, bool bCancel ) throw (css::uno::RuntimeException) = 0; /** Derived classes have to return the name of the Basic document module. */ @@ -133,25 +146,42 @@ protected: const css::uno::Sequence< css::uno::Any >& rArgs ) const throw (css::lang::IllegalArgumentException) = 0; private: + typedef ::std::map< sal_Int32, ::rtl::OUString > ModulePathMap; + + /** Starts listening at the document model. */ + void startListening(); + /** Stops listening at the document model. */ + void stopListening(); + /** Returns the event handler info struct for the specified event, or throws. */ const EventHandlerInfo& getEventHandlerInfo( sal_Int32 nEventId ) const throw (css::lang::IllegalArgumentException); /** Searches the event handler in the document and returns its full script path. */ ::rtl::OUString getEventHandlerPath( const EventHandlerInfo& rInfo, - const css::uno::Sequence< css::uno::Any >& rArgs ) const throw (css::lang::IllegalArgumentException); + const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); - /** Removes this instance from all broadcasters. */ - void stopListening(); + /** On first call, accesses the Basic library containing the VBA source code. */ + void ensureVBALibrary() throw (css::uno::RuntimeException); + + /** Returns the type of the Basic module with the specified name. */ + sal_Int32 getModuleType( const ::rtl::OUString& rModuleName ) throw (css::uno::RuntimeException); + + /** Updates the map containing paths to event handlers for a Basic module. */ + ModulePathMap& updateModulePathMap( const ::rtl::OUString& rModuleName ) throw (css::uno::RuntimeException); protected: css::uno::Reference< css::frame::XModel > mxModel; SfxObjectShell* mpShell; private: - typedef ::std::map< sal_Int32, EventHandlerInfo > EventHandlerMap; + typedef ::std::map< sal_Int32, EventHandlerInfo > EventHandlerInfoMap; + typedef ::std::hash_map< ::rtl::OUString, ModulePathMap, ::rtl::OUStringHash > EventHandlerPathMap; - EventHandlerMap maEvents; + EventHandlerInfoMap maEventInfos; + EventHandlerPathMap maEventPaths; + css::uno::Reference< css::script::vba::XVBAModuleInfo > mxModuleInfos; + ::rtl::OUString maLibraryName; bool mbDisposed; }; diff --git a/vbahelper/inc/vbahelper/vbahelper.hxx b/vbahelper/inc/vbahelper/vbahelper.hxx index 22dc9a8f6cc8..bf20541eff1e 100644 --- a/vbahelper/inc/vbahelper/vbahelper.hxx +++ b/vbahelper/inc/vbahelper/vbahelper.hxx @@ -63,7 +63,12 @@ namespace ooo throw css::lang::IllegalArgumentException(); return aSomething; } - VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell ); + + class XHelperInterface; + + /** Returns the VBA document implementation object representing the passed UNO document model. */ + VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getVBADocument( const css::uno::Reference< css::frame::XModel >& xModel ); + VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell ); VBAHELPER_DLLPUBLIC SfxObjectShell* getSfxObjShell( const css::uno::Reference< css::frame::XModel >& xModel ) throw ( css::uno::RuntimeException); VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShell* pShell, const sal_Char* _pAsciiName ) throw (css::uno::RuntimeException); @@ -90,18 +95,32 @@ namespace ooo VBAHELPER_DLLPUBLIC void PrintOutHelper( SfxViewShell* pViewShell, const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName, sal_Bool bSelection ); VBAHELPER_DLLPUBLIC void PrintPreviewHelper( const css::uno::Any& EnableChanges, SfxViewShell* ); - /** Extracts a boolean value from the passed Any, which may contain sal_Bool or an integer or floating-point value. - Returns false, if the Any is empty or contains an incompatible type. */ - VBAHELPER_DLLPUBLIC bool extractBoolFromAny( bool& rbValue, const css::uno::Any& rAny ); - /** Extracts a boolean value from the passed Any, which may contain sal_Bool or an integer or floating-point value. + /** Extracts a 32-bit integer value from the passed Any, which may contain an integer or floating-point value. + Throws, if the Any is empty or contains an incompatible type. */ + VBAHELPER_DLLPUBLIC sal_Int32 extractIntFromAny( const css::uno::Any& rAny ) throw (css::uno::RuntimeException); + /** Extracts a 32-bit integer value from the passed Any, which may contain an integer or floating-point value. + Returns nDefault, if rAny is empty. Throws, if the Any contains an incompatible type. */ + VBAHELPER_DLLPUBLIC sal_Int32 extractIntFromAny( const css::uno::Any& rAny, sal_Int32 nDefault ) throw (css::uno::RuntimeException); + + /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value. Throws, if the Any is empty or contains an incompatible type. */ VBAHELPER_DLLPUBLIC bool extractBoolFromAny( const css::uno::Any& rAny ) throw (css::uno::RuntimeException); + /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value. + Returns bDefault, if rAny is empty. Throws, if the Any contains an incompatible type. */ + VBAHELPER_DLLPUBLIC bool extractBoolFromAny( const css::uno::Any& rAny, bool bDefault ) throw (css::uno::RuntimeException); + + /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string. + Throws, if the Any is empty or contains an incompatible type. */ + VBAHELPER_DLLPUBLIC ::rtl::OUString extractStringFromAny( const css::uno::Any& rAny, bool bUppercaseBool = false ) throw (css::uno::RuntimeException); + /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string. + Returns rDefault, if rAny is empty. Throws, if the Any contains an incompatible type. */ + VBAHELPER_DLLPUBLIC ::rtl::OUString extractStringFromAny( const css::uno::Any& rAny, const ::rtl::OUString& rDefault, bool bUppercaseBool = false ) throw (css::uno::RuntimeException); VBAHELPER_DLLPUBLIC rtl::OUString getAnyAsString( const css::uno::Any& pvargItem ) throw ( css::uno::RuntimeException ); VBAHELPER_DLLPUBLIC rtl::OUString VBAToRegexp(const rtl::OUString &rIn, bool bForLike = false); // needs to be in an uno service ( already this code is duplicated in basic ) - VBAHELPER_DLLPUBLIC double getPixelTo100thMillimeterConversionFactor( css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical); - VBAHELPER_DLLPUBLIC double PointsToPixels( css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical); - VBAHELPER_DLLPUBLIC double PixelsToPoints( css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical); + VBAHELPER_DLLPUBLIC double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical); + VBAHELPER_DLLPUBLIC double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical); + VBAHELPER_DLLPUBLIC double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical); VBAHELPER_DLLPUBLIC sal_Int32 PointsToHmm( double fPoints ); VBAHELPER_DLLPUBLIC double HmmToPoints( sal_Int32 nHmm ); VBAHELPER_DLLPUBLIC sal_Int32 getPointerStyle( const css::uno::Reference< css::frame::XModel >& ); @@ -135,14 +154,21 @@ class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes // probably should replace { public: virtual ~AbstractGeometryAttributes() {} - virtual double getLeft() = 0; + virtual double getLeft() const = 0; virtual void setLeft( double ) = 0; - virtual double getTop() = 0; + virtual double getTop() const = 0; virtual void setTop( double ) = 0; - virtual double getHeight() = 0; + virtual double getHeight() const = 0; virtual void setHeight( double ) = 0; - virtual double getWidth() = 0; + virtual double getWidth() const = 0; virtual void setWidth( double ) = 0; + + virtual double getInnerHeight() const { return 0.0; } + virtual void setInnerHeight( double ) {} + virtual double getInnerWidth() const { return 0.0; } + virtual void setInnerWidth( double ) {} + virtual double getOffsetX() const { return 0.0; } + virtual double getOffsetY() const { return 0.0; } }; namespace msforms { @@ -156,20 +182,13 @@ protected: public: ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape) throw (css::script::BasicErrorException ); - double getHeight(); - - void setHeight(double _fheight) throw ( css::script::BasicErrorException ); - - double getWidth(); - + double getHeight() const; + void setHeight(double _fheight) throw ( css::script::BasicErrorException ); + double getWidth() const; void setWidth(double _fWidth) throw ( css::script::BasicErrorException ); - - double getLeft(); - + double getLeft() const; void setLeft(double _fLeft); - - double getTop(); - + double getTop() const; void setTop(double _fTop); }; @@ -178,13 +197,13 @@ class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes : public AbstractGeom std::auto_ptr< ShapeHelper > m_pShapeHelper; public: ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape ); - virtual double getLeft(); + virtual double getLeft() const; virtual void setLeft( double nLeft ); - virtual double getTop(); + virtual double getTop() const; virtual void setTop( double nTop ); - virtual double getHeight(); + virtual double getHeight() const; virtual void setHeight( double nHeight ); - virtual double getWidth(); + virtual double getWidth() const; virtual void setWidth( double nWidth); virtual ~ConcreteXShapeGeometryAttributes(); }; @@ -195,19 +214,39 @@ public: #define VBA_WIDTH "Width" class VBAHELPER_DLLPUBLIC UserFormGeometryHelper : public AbstractGeometryAttributes { +public: + UserFormGeometryHelper( + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::awt::XControl >& xControl, + double fOffsetX, double fOffsetY ); + virtual double getLeft() const; + virtual void setLeft( double fLeft ); + virtual double getTop() const; + virtual void setTop( double fTop ); + virtual double getWidth() const; + virtual void setWidth( double fWidth ); + virtual double getHeight() const; + virtual void setHeight( double fHeight ); + virtual double getInnerWidth() const; + virtual void setInnerWidth( double fWidth ); + virtual double getInnerHeight() const; + virtual void setInnerHeight( double fHeight ); + virtual double getOffsetX() const; + virtual double getOffsetY() const; + +private: + double implGetPos( bool bPosY ) const; + void implSetPos( double fPos, bool bPosY ); + double implGetSize( bool bHeight, bool bOuter ) const; + void implSetSize( double fSize, bool bHeight, bool bOuter ); + +private: css::uno::Reference< css::awt::XWindow > mxWindow; + css::uno::Reference< css::beans::XPropertySet > mxModelProps; + css::uno::Reference< css::awt::XUnitConversion > mxUnitConv; + double mfOffsetX; + double mfOffsetY; sal_Bool mbDialog; - -public: - UserFormGeometryHelper( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::awt::XControl >& xControl ); - virtual double getLeft(); - virtual void setLeft( double nLeft ); - virtual double getTop(); - virtual void setTop( double nTop ); - virtual double getHeight(); - virtual void setHeight( double nHeight ); - virtual double getWidth(); - virtual void setWidth( double nWidth); }; class VBAHELPER_DLLPUBLIC ContainerUtilities @@ -230,8 +269,8 @@ public: static void exception( css::uno::Exception& ex ) throw( css::script::BasicErrorException ); }; - } // openoffice -} // org + } // vba +} // ooo namespace ov = ooo::vba; diff --git a/vbahelper/inc/vbahelper/vbawindowbase.hxx b/vbahelper/inc/vbahelper/vbawindowbase.hxx index f42c2a19854e..e9f1d40e4bd4 100644 --- a/vbahelper/inc/vbahelper/vbawindowbase.hxx +++ b/vbahelper/inc/vbahelper/vbawindowbase.hxx @@ -24,24 +24,30 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef VBA_WINDOWBASE_HXX #define VBA_WINDOWBASE_HXX -#include <cppuhelper/implbase1.hxx> -#include <ooo/vba/XWindowBase.hpp> -#include <com/sun/star/frame/XModel.hpp> -#include <com/sun/star/awt/XDevice.hpp> +#include <ooo/vba/XWindowBase.hpp> +#include <com/sun/star/awt/XWindow2.hpp> +#include <com/sun/star/frame/XController.hpp> #include <vbahelper/vbahelperinterface.hxx> -typedef InheritedHelperInterfaceImpl1<ov::XWindowBase > WindowBaseImpl_BASE; +typedef InheritedHelperInterfaceImpl1< ov::XWindowBase > WindowBaseImpl_BASE; class VBAHELPER_DLLPUBLIC VbaWindowBase : public WindowBaseImpl_BASE { -protected: - css::uno::Reference< css::frame::XModel > m_xModel; public: - VbaWindowBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::frame::XModel >& xModel ); - VbaWindowBase( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext > const& xContext ); + VbaWindowBase( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::frame::XModel >& xModel, + const css::uno::Reference< css::frame::XController >& xController ) + throw (css::uno::RuntimeException); + VbaWindowBase( + css::uno::Sequence< css::uno::Any > const& aArgs, + css::uno::Reference< css::uno::XComponentContext > const& xContext ) + throw (css::uno::RuntimeException); // XWindowBase virtual sal_Int32 SAL_CALL getHeight() throw (css::uno::RuntimeException) ; @@ -58,6 +64,19 @@ public: // XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +protected: + css::uno::Reference< css::frame::XController > getController() throw (css::uno::RuntimeException); + css::uno::Reference< css::awt::XWindow > getWindow() throw (css::uno::RuntimeException); + css::uno::Reference< css::awt::XWindow2 > getWindow2() throw (css::uno::RuntimeException); + + css::uno::Reference< css::frame::XModel > m_xModel; + +private: + void construct( const css::uno::Reference< css::frame::XController >& xController ) throw (css::uno::RuntimeException); + + css::uno::WeakReference< css::frame::XController > m_xController; + css::uno::WeakReference< css::awt::XWindow > m_xWindow; }; #endif //VBA_WINDOWBASE_HXX diff --git a/vbahelper/inc/vbahelper/weakreference.hxx b/vbahelper/inc/vbahelper/weakreference.hxx new file mode 100755 index 000000000000..661f3bc5d73e --- /dev/null +++ b/vbahelper/inc/vbahelper/weakreference.hxx @@ -0,0 +1,94 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2011 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. + * + ************************************************************************/ + +#ifndef VBAHELPER_WEAKREFERENCE_HXX +#define VBAHELPER_WEAKREFERENCE_HXX + +#include <cppuhelper/weakref.hxx> +#include <rtl/ref.hxx> + +namespace vbahelper { + +// ============================================================================ + +/** A weak reference holding any UNO implementation object. + + The held object must implement the ::com::sun::star::uno::XWeak interface. + + In difference to the ::com::sun::star::uno::WeakReference<> implementation + from cppuhelper/weakref.hxx, the class type of this weak reference is not + restricted to UNO interface types, but can be used for any C++ class type + implementing the XWeak interface somehow (e.g. ::cppu::WeakImplHelperN<>, + ::cppu::ImplInheritanceHelperN<>, etc.). + */ +template< typename ObjectType > +class WeakReference +{ +public: + /** Default constructor. Creates an empty weak reference. + */ + inline explicit WeakReference() SAL_THROW( () ) : mpObject( 0 ) {} + + /** Initializes this weak reference with the passed reference to an object. + */ + inline explicit WeakReference( const ::rtl::Reference< ObjectType >& rxObject ) SAL_THROW( () ) : + mxWeakRef( rxObject.get() ), mpObject( rxObject.get() ) {} + + /** Releases this weak reference and takes over the passed reference. + */ + inline WeakReference& SAL_CALL operator=( const ::rtl::Reference< ObjectType >& rxObject ) SAL_THROW( () ) + { + mxWeakRef = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XWeak >( rxObject.get() ); + mpObject = rxObject.get(); + return *this; + } + + /** Gets an RTL reference to the referenced object. + + @return Reference or null, if the weakly referenced object is gone. + */ + inline SAL_CALL operator ::rtl::Reference< ObjectType >() SAL_THROW( () ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XWeak > xRef = mxWeakRef; + ::rtl::Reference< ObjectType > xObject; + if( xRef.is() ) + xObject = mpObject; + else + mpObject = 0; + return xObject; + } + +private: + ::com::sun::star::uno::WeakReference< ::com::sun::star::uno::XWeak > mxWeakRef; + ObjectType* mpObject; +}; + +// ============================================================================ + +} // namespace vbahelper + +#endif diff --git a/vbahelper/prj/build.lst b/vbahelper/prj/build.lst index 312c9b062233..be2e516de360 100644 --- a/vbahelper/prj/build.lst +++ b/vbahelper/prj/build.lst @@ -1,3 +1,3 @@ -vba vbahelper : oovbaapi offuh basic sfx2 svx filter cppuhelper vcl comphelper svtools tools sal LIBXSLT:libxslt NULL +vba vbahelper : oovbaapi offuh basic sfx2 svx filter cppuhelper vcl comphelper svtools tools sal unotools LIBXSLT:libxslt NULL vba vbahelper usr1 - all vba_mkout NULL vba vbahelper\prj nmake - all vba_prj NULL diff --git a/vbahelper/source/msforms/vbabutton.cxx b/vbahelper/source/msforms/vbabutton.cxx index 21693128c899..775a05cbb5b5 100644 --- a/vbahelper/source/msforms/vbabutton.cxx +++ b/vbahelper/source/msforms/vbabutton.cxx @@ -24,8 +24,9 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #include "vbabutton.hxx" -#include <vector> +#include "vbanewfont.hxx" using namespace com::sun::star; using namespace ooo::vba; @@ -51,6 +52,56 @@ ScVbaButton::setCaption( const rtl::OUString& _caption ) throw (::com::sun::star m_xProps->setPropertyValue( LABEL, uno::makeAny( _caption ) ); } +sal_Bool SAL_CALL ScVbaButton::getAutoSize() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaButton::setAutoSize( sal_Bool /*bAutoSize*/ ) throw (uno::RuntimeException) +{ +} + +sal_Bool SAL_CALL ScVbaButton::getCancel() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaButton::setCancel( sal_Bool /*bCancel*/ ) throw (uno::RuntimeException) +{ +} + +sal_Bool SAL_CALL ScVbaButton::getDefault() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaButton::setDefault( sal_Bool /*bDefault*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaButton::getBackColor() throw (uno::RuntimeException) +{ + return 0; +} + +void SAL_CALL ScVbaButton::setBackColor( sal_Int32 /*nBackColor*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaButton::getForeColor() throw (uno::RuntimeException) +{ + return 0; +} + +void SAL_CALL ScVbaButton::setForeColor( sal_Int32 /*nForeColor*/ ) throw (uno::RuntimeException) +{ +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaButton::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + rtl::OUString& ScVbaButton::getServiceImplName() { diff --git a/vbahelper/source/msforms/vbabutton.hxx b/vbahelper/source/msforms/vbabutton.hxx index 1c65c293f76c..93a55e1bf73a 100644 --- a/vbahelper/source/msforms/vbabutton.hxx +++ b/vbahelper/source/msforms/vbabutton.hxx @@ -27,12 +27,12 @@ #ifndef SC_VBA_BUTTON_HXX #define SC_VBA_BUTTON_HXX #include <cppuhelper/implbase1.hxx> -#include <ooo/vba/msforms/XButton.hpp> +#include <ooo/vba/msforms/XCommandButton.hpp> #include "vbacontrol.hxx" #include <vbahelper/vbahelper.hxx> -typedef cppu::ImplInheritanceHelper1< ScVbaControl, ov::msforms::XButton > ButtonImpl_BASE; +typedef cppu::ImplInheritanceHelper1< ScVbaControl, ov::msforms::XCommandButton > ButtonImpl_BASE; class ScVbaButton : public ButtonImpl_BASE { @@ -41,6 +41,17 @@ public: // Attributes virtual rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getAutoSize() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAutoSize( sal_Bool bAutoSize ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getCancel() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCancel( sal_Bool bCancel ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getDefault() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDefault( sal_Bool bDefault ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getBackColor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBackColor( sal_Int32 nBackColor ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getForeColor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setForeColor( sal_Int32 nForeColor ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); //XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); diff --git a/vbahelper/source/msforms/vbacheckbox.cxx b/vbahelper/source/msforms/vbacheckbox.cxx index e9ea64f772b6..329586cf6b27 100644 --- a/vbahelper/source/msforms/vbacheckbox.cxx +++ b/vbahelper/source/msforms/vbacheckbox.cxx @@ -24,9 +24,10 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #include "vbacheckbox.hxx" +#include "vbanewfont.hxx" #include <vbahelper/helperdecl.hxx> -#include <vector> using namespace com::sun::star; using namespace ooo::vba; @@ -83,6 +84,12 @@ ScVbaCheckbox::setValue( const uno::Any& _value ) throw (css::uno::RuntimeExcept } m_xProps->setPropertyValue( STATE, uno::makeAny( nValue ) ); } + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaCheckbox::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + rtl::OUString& ScVbaCheckbox::getServiceImplName() { diff --git a/vbahelper/source/msforms/vbacheckbox.hxx b/vbahelper/source/msforms/vbacheckbox.hxx index 34d0828e0c66..59e4d7e75e49 100644 --- a/vbahelper/source/msforms/vbacheckbox.hxx +++ b/vbahelper/source/msforms/vbacheckbox.hxx @@ -27,12 +27,12 @@ #ifndef SC_VBA_CHECKBOX_HXX #define SC_VBA_CHECKBOX_HXX #include <cppuhelper/implbase2.hxx> -#include <ooo/vba/msforms/XRadioButton.hpp> +#include <ooo/vba/msforms/XCheckBox.hpp> #include "vbacontrol.hxx" #include <vbahelper/vbahelper.hxx> -typedef cppu::ImplInheritanceHelper2< ScVbaControl, ov::msforms::XRadioButton, css::script::XDefaultProperty > CheckBoxImpl_BASE; +typedef cppu::ImplInheritanceHelper2< ScVbaControl, ov::msforms::XCheckBox, css::script::XDefaultProperty > CheckBoxImpl_BASE; class ScVbaCheckbox : public CheckBoxImpl_BASE { @@ -43,6 +43,7 @@ public: virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); // XDefaultProperty rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } //XHelperInterface diff --git a/vbahelper/source/msforms/vbacombobox.cxx b/vbahelper/source/msforms/vbacombobox.cxx index 0b5f1af30bb7..9a75fa5cbaa1 100644 --- a/vbahelper/source/msforms/vbacombobox.cxx +++ b/vbahelper/source/msforms/vbacombobox.cxx @@ -24,8 +24,15 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #include "vbacombobox.hxx" -#include <vector> +#include "vbanewfont.hxx" +#include <ooo/vba/msforms/fmStyle.hpp> +#include <ooo/vba/msforms/fmDropButtonStyle.hpp> +#include <ooo/vba/msforms/fmDragBehavior.hpp> +#include <ooo/vba/msforms/fmEnterFieldBehavior.hpp> +#include <ooo/vba/msforms/fmListStyle.hpp> +#include <ooo/vba/msforms/fmTextAlign.hpp> using namespace com::sun::star; using namespace ooo::vba; @@ -41,9 +48,17 @@ const static rtl::OUString CONTROLSOURCEPROP( RTL_CONSTASCII_USTRINGPARAM("DataF ScVbaComboBox::ScVbaComboBox( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper, bool bDialogType ) : ComboBoxImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ), mbDialogType( bDialogType ) { - mpListHelper.reset( new ListControlHelper( m_xProps ) ); - // grab the default value property name - m_xProps->getPropertyValue( CONTROLSOURCEPROP ) >>= sSourceName; + mpListHelper.reset( new ListControlHelper( m_xProps ) ); + try + { + // grab the default value property name + m_xProps->getPropertyValue( CONTROLSOURCEPROP ) >>= sSourceName; + } + catch( uno::Exception& ) + { + } + if( sSourceName.getLength() == 0 ) + sSourceName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) ); } // Attributes @@ -103,7 +118,8 @@ ScVbaComboBox::getListIndex() throw (uno::RuntimeException) void SAL_CALL ScVbaComboBox::setValue( const uno::Any& _value ) throw (uno::RuntimeException) { - m_xProps->setPropertyValue( sSourceName, _value ); + // booleans are converted to uppercase strings + m_xProps->setPropertyValue( sSourceName, uno::Any( extractStringFromAny( _value, ::rtl::OUString(), true ) ) ); } // see Value @@ -131,22 +147,22 @@ ScVbaComboBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) void SAL_CALL ScVbaComboBox::removeItem( const uno::Any& index ) throw (uno::RuntimeException) - { +{ mpListHelper->removeItem( index ); } void SAL_CALL ScVbaComboBox::Clear( ) throw (uno::RuntimeException) - { +{ mpListHelper->Clear(); - } +} void SAL_CALL ScVbaComboBox::setRowSource( const rtl::OUString& _rowsource ) throw (css::uno::RuntimeException) { ScVbaControl::setRowSource( _rowsource ); mpListHelper->setRowSource( _rowsource ); - } +} sal_Int32 SAL_CALL ScVbaComboBox::getListCount() throw (uno::RuntimeException) @@ -158,7 +174,71 @@ uno::Any SAL_CALL ScVbaComboBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException) { return mpListHelper->List( pvargIndex, pvarColumn ); - } +} + +sal_Int32 SAL_CALL ScVbaComboBox::getStyle() throw (uno::RuntimeException) +{ + return msforms::fmStyle::fmStyleDropDownCombo; +} + +void SAL_CALL ScVbaComboBox::setStyle( sal_Int32 /*nStyle*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getDropButtonStyle() throw (uno::RuntimeException) +{ + return msforms::fmDropButtonStyle::fmDropButtonStyleArrow; +} + +void SAL_CALL ScVbaComboBox::setDropButtonStyle( sal_Int32 /*nDropButtonStyle*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getDragBehavior() throw (uno::RuntimeException) +{ + return msforms::fmDragBehavior::fmDragBehaviorDisabled; +} + +void SAL_CALL ScVbaComboBox::setDragBehavior( sal_Int32 /*nDragBehavior*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getEnterFieldBehavior() throw (uno::RuntimeException) +{ + return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll; +} + +void SAL_CALL ScVbaComboBox::setEnterFieldBehavior( sal_Int32 /*nEnterFieldBehavior*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getListStyle() throw (uno::RuntimeException) +{ + return msforms::fmListStyle::fmListStylePlain; +} + +void SAL_CALL ScVbaComboBox::setListStyle( sal_Int32 /*nListStyle*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getTextAlign() throw (uno::RuntimeException) +{ + return msforms::fmTextAlign::fmTextAlignLeft; +} + +void SAL_CALL ScVbaComboBox::setTextAlign( sal_Int32 /*nTextAlign*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getTextLength() throw (uno::RuntimeException) +{ + return getText().getLength(); +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaComboBox::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} rtl::OUString& ScVbaComboBox::getServiceImplName() diff --git a/vbahelper/source/msforms/vbacombobox.hxx b/vbahelper/source/msforms/vbacombobox.hxx index 28215d16dcd7..c73b617a743b 100644 --- a/vbahelper/source/msforms/vbacombobox.hxx +++ b/vbahelper/source/msforms/vbacombobox.hxx @@ -58,6 +58,20 @@ public: virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getText() throw (css::uno::RuntimeException); virtual void SAL_CALL setText( const ::rtl::OUString& _text ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStyle( sal_Int32 nStyle ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getDropButtonStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDropButtonStyle( sal_Int32 nDropButtonStyle ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getDragBehavior() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDragBehavior( sal_Int32 nDragBehavior ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getEnterFieldBehavior() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEnterFieldBehavior( sal_Int32 nEnterFieldBehavior ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getListStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setListStyle( sal_Int32 nListStyle ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getTextAlign() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTextAlign( sal_Int32 nTextAlign ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getTextLength() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); // Methods virtual void SAL_CALL AddItem( const css::uno::Any& pvargItem, const css::uno::Any& pvargIndex ) throw (css::uno::RuntimeException); diff --git a/vbahelper/source/msforms/vbacontrol.cxx b/vbahelper/source/msforms/vbacontrol.cxx index ed9f83a7c647..780191885049 100644 --- a/vbahelper/source/msforms/vbacontrol.cxx +++ b/vbahelper/source/msforms/vbacontrol.cxx @@ -43,8 +43,8 @@ #ifdef VBA_OOBUILD_HACK #include <svtools/bindablecontrolhelper.hxx> #endif -#include"vbacontrol.hxx" -#include"vbacombobox.hxx" +#include "vbacontrol.hxx" +#include "vbacombobox.hxx" #include "vbabutton.hxx" #include "vbalabel.hxx" #include "vbatextbox.hxx" @@ -397,99 +397,104 @@ void SAL_CALL ScVbaControl::setTag( const ::rtl::OUString& aTag ) m_aControlTag = aTag; } - -//ScVbaControlFactory - -ScVbaControlFactory::ScVbaControlFactory( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel ): m_xContext( xContext ), m_xControl( xControl ), m_xModel( xModel ) +sal_Int32 SAL_CALL ScVbaControl::getTabIndex() throw (uno::RuntimeException) { + return 1; } -ScVbaControl* ScVbaControlFactory::createControl( const uno::Reference< uno::XInterface >& xParent ) throw (uno::RuntimeException) +void SAL_CALL ScVbaControl::setTabIndex( sal_Int32 /*nTabIndex*/ ) throw (uno::RuntimeException) { - uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY ); - if ( xControlShape.is() ) // form controls - return createControl( xControlShape, xParent ); - uno::Reference< awt::XControl > xControl( m_xControl, uno::UNO_QUERY ); - if ( !xControl.is() ) - throw uno::RuntimeException(); // really we should be more informative - return createControl( xControl, xParent ); } -ScVbaControl* ScVbaControlFactory::createControl(const uno::Reference< drawing::XControlShape >& xControlShape, const uno::Reference< uno::XInterface >& /*xParent*/ ) throw (uno::RuntimeException) +//ScVbaControlFactory + +/*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createShapeControl( + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< drawing::XControlShape >& xControlShape, + const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) { uno::Reference< beans::XPropertySet > xProps( xControlShape->getControl(), uno::UNO_QUERY_THROW ); sal_Int32 nClassId = -1; const static rtl::OUString sClassId( RTL_CONSTASCII_USTRINGPARAM("ClassId") ); xProps->getPropertyValue( sClassId ) >>= nClassId; uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess + uno::Reference< drawing::XShape > xShape( xControlShape, uno::UNO_QUERY_THROW ); + ::std::auto_ptr< ConcreteXShapeGeometryAttributes > xGeoHelper( new ConcreteXShapeGeometryAttributes( xContext, xShape ) ); + switch( nClassId ) { case form::FormComponentType::COMBOBOX: - return new ScVbaComboBox( xVbaParent, m_xContext, xControlShape, m_xModel, new ConcreteXShapeGeometryAttributes( m_xContext, uno::Reference< drawing::XShape >( xControlShape, uno::UNO_QUERY_THROW ) ) ); + return new ScVbaComboBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); case form::FormComponentType::COMMANDBUTTON: - return new ScVbaButton( xVbaParent, m_xContext, xControlShape, m_xModel, new ConcreteXShapeGeometryAttributes( m_xContext, uno::Reference< drawing::XShape >( xControlShape, uno::UNO_QUERY_THROW ) ) ); + return new ScVbaButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); case form::FormComponentType::FIXEDTEXT: - return new ScVbaLabel( xVbaParent, m_xContext, xControlShape, m_xModel, new ConcreteXShapeGeometryAttributes( m_xContext, uno::Reference< drawing::XShape >( xControlShape, uno::UNO_QUERY_THROW ) ) ); + return new ScVbaLabel( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); case form::FormComponentType::TEXTFIELD: - return new ScVbaTextBox( xVbaParent, m_xContext, xControlShape, m_xModel, new ConcreteXShapeGeometryAttributes( m_xContext, uno::Reference< drawing::XShape >( xControlShape, uno::UNO_QUERY_THROW ) ) ); + return new ScVbaTextBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); case form::FormComponentType::RADIOBUTTON: - return new ScVbaRadioButton( xVbaParent, m_xContext, xControlShape, m_xModel, new ConcreteXShapeGeometryAttributes( m_xContext, uno::Reference< drawing::XShape >( xControlShape, uno::UNO_QUERY_THROW ) ) ); + return new ScVbaRadioButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); case form::FormComponentType::LISTBOX: - return new ScVbaListBox( xVbaParent, m_xContext, xControlShape, m_xModel, new ConcreteXShapeGeometryAttributes( m_xContext, uno::Reference< drawing::XShape >( xControlShape, uno::UNO_QUERY_THROW ) ) ); + return new ScVbaListBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); case form::FormComponentType::SPINBUTTON: - return new ScVbaSpinButton( xVbaParent, m_xContext, xControlShape, m_xModel, new ConcreteXShapeGeometryAttributes( m_xContext, uno::Reference< drawing::XShape >( xControlShape, uno::UNO_QUERY_THROW ) ) ); + return new ScVbaSpinButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); case form::FormComponentType::IMAGECONTROL: - return new ScVbaImage( xVbaParent, m_xContext, xControlShape, m_xModel, new ConcreteXShapeGeometryAttributes( m_xContext, uno::Reference< drawing::XShape >( xControlShape, uno::UNO_QUERY_THROW ) ) ); - default: - throw uno::RuntimeException( rtl::OUString::createFromAscii( - "Donot support this Control Type." ), uno::Reference< uno::XInterface >() ); + return new ScVbaImage( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); } + throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control." ), uno::Reference< uno::XInterface >() ); } -ScVbaControl* ScVbaControlFactory::createControl( const uno::Reference< awt::XControl >& xControl, const uno::Reference< uno::XInterface >& xParent ) throw (uno::RuntimeException) +/*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createUserformControl( + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< awt::XControl >& xControl, + const uno::Reference< awt::XControl >& xDialog, + const uno::Reference< frame::XModel >& xModel, + double fOffsetX, double fOffsetY ) throw (uno::RuntimeException) { uno::Reference< beans::XPropertySet > xProps( xControl->getModel(), uno::UNO_QUERY_THROW ); uno::Reference< lang::XServiceInfo > xServiceInfo( xProps, uno::UNO_QUERY_THROW ); - ScVbaControl* pControl = NULL; + uno::Reference< msforms::XControl > xVBAControl; uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess + ::std::auto_ptr< UserFormGeometryHelper > xGeoHelper( new UserFormGeometryHelper( xContext, xControl, fOffsetX, fOffsetY ) ); + if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlCheckBoxModel") ) ) ) - pControl = new ScVbaCheckbox( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); + xVBAControl.set( new ScVbaCheckbox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlRadioButtonModel") ) ) ) - pControl = new ScVbaRadioButton( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); + xVBAControl.set( new ScVbaRadioButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlEditModel") ) ) ) - pControl = new ScVbaTextBox( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ), true ); + xVBAControl.set( new ScVbaTextBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), true ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlButtonModel") ) ) ) { sal_Bool bToggle = sal_False; xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Toggle") ) ) >>= bToggle; if ( bToggle ) - pControl = new ScVbaToggleButton( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); + xVBAControl.set( new ScVbaToggleButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); else - pControl = new ScVbaButton( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); + xVBAControl.set( new ScVbaButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); } else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlComboBoxModel") ) ) ) - pControl = new ScVbaComboBox( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ), true ); + xVBAControl.set( new ScVbaComboBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), true ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlListBoxModel") ) ) ) - pControl = new ScVbaListBox( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); + xVBAControl.set( new ScVbaListBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlFixedTextModel") ) ) ) - pControl = new ScVbaLabel( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); + xVBAControl.set( new ScVbaLabel( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlImageControlModel") ) ) ) - pControl = new ScVbaImage( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); + xVBAControl.set( new ScVbaImage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlProgressBarModel") ) ) ) - pControl = new ScVbaProgressBar( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); + xVBAControl.set( new ScVbaProgressBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlGroupBoxModel") ) ) ) - pControl = new ScVbaFrame( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); + xVBAControl.set( new ScVbaFrame( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlScrollBarModel") ) ) ) - pControl = new ScVbaScrollBar( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); + xVBAControl.set( new ScVbaScrollBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoMultiPageModel") ) ) ) - pControl = new ScVbaMultiPage( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ), xParent ); + xVBAControl.set( new ScVbaMultiPage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlSpinButtonModel") ) ) ) - pControl = new ScVbaSpinButton( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); + xVBAControl.set( new ScVbaSpinButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.custom.awt.UnoControlSystemAXContainerModel") ) ) ) - pControl = new VbaSystemAXControl( xVbaParent, m_xContext, xControl, m_xModel, new UserFormGeometryHelper( m_xContext, xControl ) ); - else - throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control " ), uno::Reference< uno::XInterface >() ); - return pControl; + xVBAControl.set( new VbaSystemAXControl( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + + if( xVBAControl.is() ) + return xVBAControl; + throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control." ), uno::Reference< uno::XInterface >() ); } rtl::OUString& @@ -520,7 +525,6 @@ class ControlProviderImpl : public ControlProvider_BASE public: ControlProviderImpl( const uno::Reference< uno::XComponentContext >& xCtx ) : m_xCtx( xCtx ) {} virtual uno::Reference< msforms::XControl > SAL_CALL createControl( const uno::Reference< drawing::XControlShape >& xControl, const uno::Reference< frame::XModel >& xDocOwner ) throw (uno::RuntimeException); - virtual uno::Reference< msforms::XControl > SAL_CALL createUserformControl( const uno::Reference< awt::XControl >& xControl, const uno::Reference< awt::XControl >& xDialog, const uno::Reference< frame::XModel >& xDocOwner ) throw (uno::RuntimeException); }; uno::Reference< msforms::XControl > SAL_CALL @@ -528,27 +532,10 @@ ControlProviderImpl::createControl( const uno::Reference< drawing::XControlShape { uno::Reference< msforms::XControl > xControlToReturn; if ( xControlShape.is() ) - { - ScVbaControlFactory controlFactory( m_xCtx, xControlShape, xDocOwner ); - xControlToReturn.set( controlFactory.createControl( xDocOwner ) ); - } + xControlToReturn = ScVbaControlFactory::createShapeControl( m_xCtx, xControlShape, xDocOwner ); return xControlToReturn; } -uno::Reference< msforms::XControl > SAL_CALL -ControlProviderImpl::createUserformControl( const uno::Reference< awt::XControl >& xControl, const uno::Reference< awt::XControl >& xDialog, const uno::Reference< frame::XModel >& xDocOwner ) throw (uno::RuntimeException) -{ - uno::Reference< msforms::XControl > xControlToReturn; - if ( xControl.is() && xDialog.is() ) - { - - ScVbaControlFactory controlFactory( m_xCtx, xControl, xDocOwner ); - xControlToReturn.set( controlFactory.createControl( xDialog->getModel() ) ); - ScVbaControl* pControl = dynamic_cast< ScVbaControl* >( xControlToReturn.get() ); - pControl->setGeometryHelper( new UserFormGeometryHelper( m_xCtx, xControl ) ); - } - return xControlToReturn; -} namespace controlprovider { diff --git a/vbahelper/source/msforms/vbacontrol.hxx b/vbahelper/source/msforms/vbacontrol.hxx index 247eabfe95e8..e421f919b6a4 100644 --- a/vbahelper/source/msforms/vbacontrol.hxx +++ b/vbahelper/source/msforms/vbacontrol.hxx @@ -93,6 +93,8 @@ public: virtual void SAL_CALL setControlTipText( const rtl::OUString& ) throw (css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getTag() throw (css::uno::RuntimeException); virtual void SAL_CALL setTag( const ::rtl::OUString& aTag ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getTabIndex() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTabIndex( sal_Int32 nTabIndex ) throw (css::uno::RuntimeException); //remove resouce because ooo.vba.excel.XControl is a wrapper of com.sun.star.drawing.XControlShape virtual void removeResouce() throw( css::uno::RuntimeException ); //XHelperInterface @@ -104,15 +106,21 @@ public: class ScVbaControlFactory { public: - ScVbaControlFactory( const css::uno::Reference< css::uno::XComponentContext >& xContext, - const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel ); - ScVbaControl* createControl( const css::uno::Reference< css::uno::XInterface >& xParent ) throw ( css::uno::RuntimeException ); + static css::uno::Reference< ov::msforms::XControl > createShapeControl( + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::drawing::XControlShape >& xControlShape, + const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + + static css::uno::Reference< ov::msforms::XControl > createUserformControl( + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::awt::XControl >& xControl, + const css::uno::Reference< css::awt::XControl >& xDialog, + const css::uno::Reference< css::frame::XModel >& xModel, + double fOffsetX, double fOffsetY ) throw (css::uno::RuntimeException); + private: - ScVbaControl* createControl( const css::uno::Reference< css::awt::XControl >&, const css::uno::Reference< css::uno::XInterface >& ) throw ( css::uno::RuntimeException ); - ScVbaControl* createControl( const css::uno::Reference< css::drawing::XControlShape >&, const css::uno::Reference< css::uno::XInterface >& ) throw ( css::uno::RuntimeException ); - css::uno::Reference< css::uno::XComponentContext > m_xContext; - css::uno::Reference< css::uno::XInterface > m_xControl; - css::uno::Reference< css::frame::XModel > m_xModel; + ScVbaControlFactory(); + ~ScVbaControlFactory(); }; #endif//SC_VBA_CONTROL_HXX diff --git a/vbahelper/source/msforms/vbacontrols.cxx b/vbahelper/source/msforms/vbacontrols.cxx index 8d01687ef905..7411f7ad9463 100644 --- a/vbahelper/source/msforms/vbacontrols.cxx +++ b/vbahelper/source/msforms/vbacontrols.cxx @@ -27,13 +27,18 @@ #include <com/sun/star/awt/XControl.hpp> #include <com/sun/star/awt/XControlContainer.hpp> +#include <com/sun/star/awt/FontWeight.hpp> +#include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/awt/FontStrikeout.hpp> +#include <com/sun/star/awt/FontUnderline.hpp> #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/script/XInvocation.hpp> #include <com/sun/star/lang/WrappedTargetException.hpp> #include "vbacontrols.hxx" +#include "vbacontrol.hxx" #include <cppuhelper/implbase2.hxx> -#include <ooo/vba//XControlProvider.hpp> +#include <ooo/vba/XControlProvider.hpp> #include <hash_map> using namespace com::sun::star; @@ -153,11 +158,28 @@ class ControlsEnumWrapper : public EnumerationHelper_BASE uno::Reference<uno::XComponentContext > m_xContext; uno::Reference<container::XIndexAccess > m_xIndexAccess; uno::Reference<awt::XControl > m_xDlg; + uno::Reference< frame::XModel > m_xModel; + double mfOffsetX; + double mfOffsetY; sal_Int32 nIndex; public: - ControlsEnumWrapper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess, const uno::Reference< awt::XControl >& xDlg ) : m_xParent( xParent ), m_xContext( xContext), m_xIndexAccess( xIndexAccess ), m_xDlg( xDlg ), nIndex( 0 ) {} + ControlsEnumWrapper( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< container::XIndexAccess >& xIndexAccess, + const uno::Reference< awt::XControl >& xDlg, + const uno::Reference< frame::XModel >& xModel, + double fOffsetX, double fOffsetY ) : + m_xParent( xParent ), + m_xContext( xContext), + m_xIndexAccess( xIndexAccess ), + m_xDlg( xDlg ), + m_xModel( xModel ), + mfOffsetX( fOffsetX ), + mfOffsetY( fOffsetY ), + nIndex( 0 ) {} virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) { @@ -168,14 +190,12 @@ public: { if ( nIndex < m_xIndexAccess->getCount() ) { - uno::Reference< frame::XModel > xModel; uno::Reference< awt::XControl > xControl; m_xIndexAccess->getByIndex( nIndex++ ) >>= xControl; - uno::Reference<lang::XMultiComponentFactory > xServiceManager( m_xContext->getServiceManager(), uno::UNO_QUERY_THROW ); - uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), m_xContext ), uno::UNO_QUERY_THROW ); - - uno::Reference< msforms::XControl > xVBAControl( xControlProvider->createUserformControl( xControl, m_xDlg, xModel ) ); + uno::Reference< msforms::XControl > xVBAControl; + if ( xControl.is() && m_xDlg.is() ) + xVBAControl = ScVbaControlFactory::createUserformControl( m_xContext, xControl, m_xDlg, m_xModel, mfOffsetX, mfOffsetY ); return uno::makeAny( xVBAControl ); } throw container::NoSuchElementException(); @@ -190,17 +210,24 @@ lcl_controlsWrapper( const uno::Reference< awt::XControl >& xDlg ) return new ControlArrayWrapper( xDlg ); } -ScVbaControls::ScVbaControls( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, - const css::uno::Reference< awt::XControl >& xDialog ) - : ControlsImpl_BASE( xParent, xContext, lcl_controlsWrapper( xDialog ) ) +ScVbaControls::ScVbaControls( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const css::uno::Reference< awt::XControl >& xDialog, + const uno::Reference< frame::XModel >& xModel, + double fOffsetX, double fOffsetY ) : + ControlsImpl_BASE( xParent, xContext, lcl_controlsWrapper( xDialog ) ), + mxDialog( xDialog ), + mxModel( xModel ), + mfOffsetX( fOffsetX ), + mfOffsetY( fOffsetY ) { - mxDialog.set( xDialog, uno::UNO_QUERY ); } uno::Reference< container::XEnumeration > ScVbaControls::createEnumeration() throw (uno::RuntimeException) { - uno::Reference< container::XEnumeration > xEnum( new ControlsEnumWrapper( mxParent, mxContext, m_xIndexAccess, mxDialog ) ); + uno::Reference< container::XEnumeration > xEnum( new ControlsEnumWrapper( mxParent, mxContext, m_xIndexAccess, mxDialog, mxModel, mfOffsetX, mfOffsetY ) ); if ( !xEnum.is() ) throw uno::RuntimeException(); return xEnum; @@ -210,15 +237,9 @@ uno::Any ScVbaControls::createCollectionObject( const css::uno::Any& aSource ) { // Create control from awt::XControl - uno::Reference< awt::XControl > xControl; - aSource >>= xControl; - uno::Reference< frame::XModel > xModel; - uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); - uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), mxContext ), uno::UNO_QUERY_THROW ); - - uno::Reference< msforms::XControl > xVBAControl( xControlProvider->createUserformControl( xControl, mxDialog, xModel ) ); - - return uno::makeAny( xVBAControl ); + uno::Reference< awt::XControl > xControl( aSource, uno::UNO_QUERY_THROW ); + uno::Reference< msforms::XControl > xVBAControl = ScVbaControlFactory::createUserformControl( mxContext, xControl, mxDialog, mxModel, mfOffsetX, mfOffsetY ); + return uno::Any( xVBAControl ); } void SAL_CALL @@ -261,23 +282,117 @@ uno::Any SAL_CALL ScVbaControls::Add( const uno::Any& Object, const uno::Any& St aNewName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Control" ) ); sal_Int32 nInd = 0; - while( xDialogContainer->hasByName( aNewName ) && nInd < SAL_MAX_INT32 ) + while( xDialogContainer->hasByName( aNewName ) && (nInd < SAL_MAX_INT32) ) { aNewName = aComServiceName; - aNewName += ::rtl::OUString::valueOf( nInd ); + aNewName += ::rtl::OUString::valueOf( nInd++ ); } } + double fDefWidth = 72.0, fDefHeight = 18.0; if ( aComServiceName.getLength() ) { - uno::Reference< awt::XControlModel > xNewModel( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.custom.awt.UnoControlSystemAXContainerModel" ) ) ), uno::UNO_QUERY_THROW ); + // create a UNO control model based on the passed control type + uno::Reference< awt::XControlModel > xNewModel; + bool bFontSupport = false; + bool bNativeAX = false; + if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.CommandButton.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 24.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.Label.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFixedTextModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.Image.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlImageControlModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 72.0; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.CheckBox.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlCheckBoxModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 108.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.OptionButton.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlRadioButtonModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 108.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.TextBox.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlEditModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ListBox.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlListBoxModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ComboBox.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlComboBoxModel" ) ) ), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( xNewModel, uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Dropdown" ) ), uno::Any( true ) ); + fDefWidth = 72.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ToggleButton.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ) ), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( xNewModel, uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Toggle" ) ), uno::Any( true ) ); + fDefWidth = 72.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.Frame.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlGroupBoxModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 216.0; fDefHeight = 144.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.SpinButton.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlSpinButtonModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 12.75; fDefHeight = 25.5; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ScrollBar.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlScrollBarModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 12.75; fDefHeight = 63.8; + } + else + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.custom.awt.UnoControlSystemAXContainerModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 18.0; + bNativeAX = true; + } + // need to set a few font properties to get rid of the default DONT_KNOW values + if( bFontSupport ) + { + uno::Reference< beans::XPropertySet > xModelProps( xNewModel, uno::UNO_QUERY_THROW ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ), uno::Any( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Tahoma" ) ) ) ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ), uno::Any( float( 8.0 ) ) ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ), uno::Any( awt::FontWeight::NORMAL ) ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ), uno::Any( awt::FontSlant_NONE ) ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ), uno::Any( awt::FontUnderline::NONE ) ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ), uno::Any( awt::FontStrikeout::NONE ) ); + } xDialogContainer->insertByName( aNewName, uno::makeAny( xNewModel ) ); uno::Reference< awt::XControlContainer > xControlContainer( mxDialog, uno::UNO_QUERY_THROW ); xNewControl = xControlContainer->getControl( aNewName ); - try + if( bNativeAX ) try { uno::Reference< script::XInvocation > xControlInvoke( xNewControl, uno::UNO_QUERY_THROW ); @@ -299,6 +414,11 @@ uno::Any SAL_CALL ScVbaControls::Add( const uno::Any& Object, const uno::Any& St UpdateCollectionIndex( lcl_controlsWrapper( mxDialog ) ); aResult <<= xNewControl; aResult = createCollectionObject( aResult ); + uno::Reference< msforms::XControl > xVBAControl( aResult, uno::UNO_QUERY_THROW ); + if( fDefWidth > 0.0 ) + xVBAControl->setWidth( fDefWidth ); + if( fDefHeight > 0.0 ) + xVBAControl->setHeight( fDefHeight ); } else throw uno::RuntimeException(); @@ -376,21 +496,5 @@ ScVbaControls::getElementType() throw (uno::RuntimeException) { return ooo::vba::msforms::XControl::static_type(0); } -rtl::OUString& -ScVbaControls::getServiceImplName() -{ - static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaControls") ); - return sImplName; -} -uno::Sequence< rtl::OUString > -ScVbaControls::getServiceNames() -{ - static uno::Sequence< rtl::OUString > aServiceNames; - if ( aServiceNames.getLength() == 0 ) - { - aServiceNames.realloc( 1 ); - aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Controls" ) ); - } - return aServiceNames; -} +VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaControls, "ooo.vba.msforms.Controls" ) diff --git a/vbahelper/source/msforms/vbacontrols.hxx b/vbahelper/source/msforms/vbacontrols.hxx index a72506609531..4b4838a45a8e 100644 --- a/vbahelper/source/msforms/vbacontrols.hxx +++ b/vbahelper/source/msforms/vbacontrols.hxx @@ -38,19 +38,17 @@ typedef CollTestImplHelper< ov::msforms::XControls > ControlsImpl_BASE; class ScVbaControls : public ControlsImpl_BASE { - css::uno::Reference< css::awt::XControl > mxDialog; - -protected: - virtual rtl::OUString& getServiceImplName(); - virtual css::uno::Sequence<rtl::OUString> getServiceNames(); - public: - ScVbaControls( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, - const css::uno::Reference< css::awt::XControl >& xDialog ); + ScVbaControls( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::awt::XControl >& xDialog, + const css::uno::Reference< css::frame::XModel >& xModel, + double fOffsetX, double fOffsetY ); // XControls virtual void SAL_CALL Move( double cx, double cy ) throw (css::uno::RuntimeException); - virtual ::com::sun::star::uno::Any SAL_CALL Add( const ::com::sun::star::uno::Any& Object, const ::com::sun::star::uno::Any& StringKey, const ::com::sun::star::uno::Any& Before, const ::com::sun::star::uno::Any& After ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL Remove( const ::com::sun::star::uno::Any& StringKeyOrIndex ) throw (::com::sun::star::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Add( const css::uno::Any& Object, const css::uno::Any& StringKey, const css::uno::Any& Before, const css::uno::Any& After ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Remove( const css::uno::Any& StringKeyOrIndex ) throw (css::uno::RuntimeException); // XEnumerationAccess virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); @@ -59,6 +57,15 @@ public: // ScVbaCollectionBaseImpl virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + // XHelperInterface + VBAHELPER_DECL_XHELPERINTERFACE + +private: + css::uno::Reference< css::awt::XControl > mxDialog; + css::uno::Reference< css::frame::XModel > mxModel; + double mfOffsetX; + double mfOffsetY; }; + #endif //SC_VBA_OLEOBJECTS_HXX diff --git a/vbahelper/source/msforms/vbaframe.cxx b/vbahelper/source/msforms/vbaframe.cxx index c470ee0097e4..4a1fe6a58b49 100644 --- a/vbahelper/source/msforms/vbaframe.cxx +++ b/vbahelper/source/msforms/vbaframe.cxx @@ -24,62 +24,83 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #include "vbaframe.hxx" -#include <vector> +#include "vbanewfont.hxx" +#include "vbacontrols.hxx" +#include <ooo/vba/msforms/fmBorderStyle.hpp> +#include <ooo/vba/msforms/fmSpecialEffect.hpp> using namespace com::sun::star; using namespace ooo::vba; const static rtl::OUString LABEL( RTL_CONSTASCII_USTRINGPARAM("Label") ); -ScVbaFrame::ScVbaFrame( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ) : FrameImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) + +ScVbaFrame::ScVbaFrame( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< uno::XInterface >& xControl, + const uno::Reference< frame::XModel >& xModel, + ov::AbstractGeometryAttributes* pGeomHelper, + const css::uno::Reference< css::awt::XControl >& xDialog ) : + FrameImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ), + mxDialog( xDialog ) { } -// Attributes -rtl::OUString SAL_CALL -ScVbaFrame::getCaption() throw (css::uno::RuntimeException) +// XFrame attributes + +rtl::OUString SAL_CALL ScVbaFrame::getCaption() throw (css::uno::RuntimeException) { rtl::OUString Label; m_xProps->getPropertyValue( LABEL ) >>= Label; return Label; } -void SAL_CALL -ScVbaFrame::setCaption( const rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL ScVbaFrame::setCaption( const rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException) { m_xProps->setPropertyValue( LABEL, uno::makeAny( _caption ) ); } -uno::Any SAL_CALL -ScVbaFrame::getValue() throw (css::uno::RuntimeException) +sal_Int32 SAL_CALL ScVbaFrame::getSpecialEffect() throw (uno::RuntimeException) { - return uno::makeAny( getCaption() ); + return msforms::fmSpecialEffect::fmSpecialEffectEtched; } -void SAL_CALL -ScVbaFrame::setValue( const uno::Any& _value ) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL ScVbaFrame::setSpecialEffect( sal_Int32 /*nSpecialEffect*/ ) throw (uno::RuntimeException) { - rtl::OUString sCaption; - _value >>= sCaption; - setCaption( sCaption ); } -rtl::OUString& -ScVbaFrame::getServiceImplName() +sal_Int32 SAL_CALL ScVbaFrame::getBorderStyle() throw (uno::RuntimeException) { - static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFrame") ); - return sImplName; + return msforms::fmBorderStyle::fmBorderStyleNone; } -uno::Sequence< rtl::OUString > -ScVbaFrame::getServiceNames() +void SAL_CALL ScVbaFrame::setBorderStyle( sal_Int32 /*nBorderStyle*/ ) throw (uno::RuntimeException) { - static uno::Sequence< rtl::OUString > aServiceNames; - if ( aServiceNames.getLength() == 0 ) - { - aServiceNames.realloc( 1 ); - aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.Frame" ) ); - } - return aServiceNames; } + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaFrame::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + +// XFrame methods + +uno::Any SAL_CALL ScVbaFrame::Controls( const uno::Any& rIndex ) throw (uno::RuntimeException) +{ + // horizontal anchor of frame children is inside border line (add one unit to compensate border line width) + double fOffsetX = mpGeometryHelper->getOffsetX() + getLeft() + 1.0; + // vertical anchor of frame children is inside border line (add half of text height and one unit to compensate border line width) + double fOffsetY = mpGeometryHelper->getOffsetY() + getTop() + (getFont()->getSize() / 2.0) + 1.0; + + uno::Reference< XCollection > xControls( new ScVbaControls( this, mxContext, mxDialog, m_xModel, fOffsetX, fOffsetY ) ); + if( rIndex.hasValue() ) + return uno::Any( xControls->Item( rIndex, uno::Any() ) ); + return uno::Any( xControls ); +} + +// XHelperInterface + +VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaFrame, "ooo.vba.msforms.Frame" ) diff --git a/vbahelper/source/msforms/vbaframe.hxx b/vbahelper/source/msforms/vbaframe.hxx index 567e58b57272..d76f31230bba 100644 --- a/vbahelper/source/msforms/vbaframe.hxx +++ b/vbahelper/source/msforms/vbaframe.hxx @@ -27,24 +27,39 @@ #ifndef SC_VBA_FRAME_HXX #define SC_VBA_FRAME_HXX #include <cppuhelper/implbase1.hxx> -#include <ooo/vba/msforms/XLabel.hpp> +#include <ooo/vba/msforms/XFrame.hpp> #include "vbacontrol.hxx" #include <vbahelper/vbahelper.hxx> -typedef cppu::ImplInheritanceHelper1< ScVbaControl, ov::msforms::XLabel > FrameImpl_BASE; +typedef cppu::ImplInheritanceHelper1< ScVbaControl, ov::msforms::XFrame > FrameImpl_BASE; class ScVbaFrame : public FrameImpl_BASE { public: - ScVbaFrame( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); - // Attributes - virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); - virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + ScVbaFrame( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::uno::XInterface >& xControl, + const css::uno::Reference< css::frame::XModel >& xModel, + ov::AbstractGeometryAttributes* pGeomHelper, + const css::uno::Reference< css::awt::XControl >& xDialog ); + + // XFrame attributes virtual rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getSpecialEffect() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSpecialEffect( sal_Int32 nSpecialEffect ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getBorderStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBorderStyle( sal_Int32 nBorderStyle ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + // XFrame methods + css::uno::Any SAL_CALL Controls( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); //XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +private: + css::uno::Reference< css::awt::XControl > mxDialog; }; #endif //SC_VBA_LABEL_HXX diff --git a/vbahelper/source/msforms/vbalabel.cxx b/vbahelper/source/msforms/vbalabel.cxx index 9bf7a7e001bf..d5aa1176e3d3 100644 --- a/vbahelper/source/msforms/vbalabel.cxx +++ b/vbahelper/source/msforms/vbalabel.cxx @@ -24,8 +24,9 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #include "vbalabel.hxx" -#include <vector> +#include "vbanewfont.hxx" using namespace com::sun::star; using namespace ooo::vba; @@ -64,6 +65,10 @@ ScVbaLabel::setValue( const uno::Any& _value ) throw (::com::sun::star::uno::Run setCaption( sCaption ); } +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaLabel::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} rtl::OUString& ScVbaLabel::getServiceImplName() diff --git a/vbahelper/source/msforms/vbalabel.hxx b/vbahelper/source/msforms/vbalabel.hxx index af3bc074c54d..2dcee186d58b 100644 --- a/vbahelper/source/msforms/vbalabel.hxx +++ b/vbahelper/source/msforms/vbalabel.hxx @@ -44,6 +44,7 @@ public: virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); virtual rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); //XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); diff --git a/vbahelper/source/msforms/vbalistbox.cxx b/vbahelper/source/msforms/vbalistbox.cxx index 17f8c8341588..8829c8ae7256 100644 --- a/vbahelper/source/msforms/vbalistbox.cxx +++ b/vbahelper/source/msforms/vbalistbox.cxx @@ -24,12 +24,12 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ -#include <com/sun/star/form/validation/XValidatableFormComponent.hpp> #include "vbalistbox.hxx" -#include <vector> +#include "vbanewfont.hxx" #include <comphelper/anytostring.hxx> #include <com/sun/star/script/ArrayWrapper.hpp> +#include <com/sun/star/form/validation/XValidatableFormComponent.hpp> using namespace com::sun::star; using namespace ooo::vba; @@ -267,6 +267,11 @@ ScVbaListBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) t return mpListHelper->List( pvargIndex, pvarColumn ); } +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaListBox::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + rtl::OUString& ScVbaListBox::getServiceImplName() { diff --git a/vbahelper/source/msforms/vbalistbox.hxx b/vbahelper/source/msforms/vbalistbox.hxx index 3d0797e2b7b2..7dbda1837cb0 100644 --- a/vbahelper/source/msforms/vbalistbox.hxx +++ b/vbahelper/source/msforms/vbalistbox.hxx @@ -60,9 +60,10 @@ public: virtual void SAL_CALL setText( const ::rtl::OUString& _text ) throw (css::uno::RuntimeException); virtual sal_Bool SAL_CALL getMultiSelect() throw (css::uno::RuntimeException); virtual void SAL_CALL setMultiSelect( sal_Bool _multiselect ) throw (css::uno::RuntimeException); - virtual css::uno::Any SAL_CALL Selected( ::sal_Int32 index ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); // Methods + virtual css::uno::Any SAL_CALL Selected( ::sal_Int32 index ) throw (css::uno::RuntimeException); virtual void SAL_CALL AddItem( const css::uno::Any& pvargItem, const css::uno::Any& pvargIndex ) throw (css::uno::RuntimeException); virtual void SAL_CALL removeItem( const css::uno::Any& index ) throw (css::uno::RuntimeException); virtual void SAL_CALL Clear( ) throw (css::uno::RuntimeException); diff --git a/vbahelper/source/msforms/vbamultipage.cxx b/vbahelper/source/msforms/vbamultipage.cxx index b6587c9b2367..78590f0fd85b 100644 --- a/vbahelper/source/msforms/vbamultipage.cxx +++ b/vbahelper/source/msforms/vbamultipage.cxx @@ -68,9 +68,16 @@ ScVbaMultiPage::getPages( sal_Int32 nPages ) return new PagesImpl( nPages ); } -ScVbaMultiPage::ScVbaMultiPage( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper, const uno::Reference< uno::XInterface >& xDialog ) : MultiPageImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +ScVbaMultiPage::ScVbaMultiPage( + const uno::Reference< ov::XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< uno::XInterface >& xControl, + const uno::Reference< frame::XModel >& xModel, + AbstractGeometryAttributes* pGeomHelper, + const uno::Reference< awt::XControl >& xDialog ) : + MultiPageImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) { - mxDialogProps.set( xDialog, uno::UNO_QUERY_THROW ); + mxDialogProps.set( xDialog->getModel(), uno::UNO_QUERY_THROW ); // set dialog step to value of multipage pseudo model setValue(getValue()); } diff --git a/vbahelper/source/msforms/vbamultipage.hxx b/vbahelper/source/msforms/vbamultipage.hxx index 4a54525cf95f..328a71b61592 100644 --- a/vbahelper/source/msforms/vbamultipage.hxx +++ b/vbahelper/source/msforms/vbamultipage.hxx @@ -42,7 +42,14 @@ class ScVbaMultiPage : public MultiPageImpl_BASE css::uno::Reference< css::container::XIndexAccess > getPages( sal_Int32 nPages ); css::uno::Reference< css::beans::XPropertySet > mxDialogProps; public: - ScVbaMultiPage( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper, const css::uno::Reference< css::uno::XInterface >& xDialog ); + ScVbaMultiPage( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::uno::XInterface >& xControl, + const css::uno::Reference< css::frame::XModel >& xModel, + ov::AbstractGeometryAttributes* pGeomHelper, + const css::uno::Reference< css::awt::XControl >& xDialog ); + // Attributes virtual sal_Int32 SAL_CALL getValue() throw (css::uno::RuntimeException); virtual void SAL_CALL setValue( sal_Int32 _value ) throw (css::uno::RuntimeException); diff --git a/vbahelper/source/msforms/vbanewfont.cxx b/vbahelper/source/msforms/vbanewfont.cxx new file mode 100755 index 000000000000..f487b4e6919c --- /dev/null +++ b/vbahelper/source/msforms/vbanewfont.cxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#include <vbanewfont.hxx> +#include <com/sun/star/awt/FontWeight.hpp> +#include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/awt/FontStrikeout.hpp> +#include <com/sun/star/awt/FontUnderline.hpp> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +// ============================================================================ + +VbaNewFont::VbaNewFont( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< beans::XPropertySet >& rxModelProps ) throw (uno::RuntimeException) : + VbaNewFont_BASE( rxParent, rxContext ), + mxProps( rxModelProps, uno::UNO_SET_THROW ) +{ +} + +// XNewFont attributes + +::rtl::OUString SAL_CALL VbaNewFont::getName() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ) ); + return aAny.get< ::rtl::OUString >(); +} + +void SAL_CALL VbaNewFont::setName( const ::rtl::OUString& rName ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ), + uno::Any( rName ) ); +} + +double SAL_CALL VbaNewFont::getSize() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ) ); + return aAny.get< float >(); +} + +void SAL_CALL VbaNewFont::setSize( double fSize ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ), + uno::Any( static_cast< float >( fSize ) ) ); +} + +sal_Int16 SAL_CALL VbaNewFont::getCharset() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontCharset" ) ) ); + return rtl_getBestWindowsCharsetFromTextEncoding( static_cast< rtl_TextEncoding >( aAny.get< sal_Int16 >() ) ); +} + +void SAL_CALL VbaNewFont::setCharset( sal_Int16 nCharset ) throw (uno::RuntimeException) +{ + rtl_TextEncoding eFontEnc = RTL_TEXTENCODING_DONTKNOW; + if( (0 <= nCharset) && (nCharset <= SAL_MAX_UINT8) ) + eFontEnc = rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( nCharset ) ); + if( eFontEnc == RTL_TEXTENCODING_DONTKNOW ) + throw uno::RuntimeException(); + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontCharset" ) ), + uno::Any( static_cast< sal_Int16 >( eFontEnc ) ) ); +} + +sal_Int16 SAL_CALL VbaNewFont::getWeight() throw (uno::RuntimeException) +{ + return getBold() ? 700 : 400; +} + +void SAL_CALL VbaNewFont::setWeight( sal_Int16 nWeight ) throw (uno::RuntimeException) +{ + setBold( nWeight >= 700 ); +} + +sal_Bool SAL_CALL VbaNewFont::getBold() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ) ); + return aAny.get< float >() > awt::FontWeight::NORMAL; +} + +void SAL_CALL VbaNewFont::setBold( sal_Bool bBold ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ), + uno::Any( bBold ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL ) ); +} + +sal_Bool SAL_CALL VbaNewFont::getItalic() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ) ); + return aAny.get< awt::FontSlant >() != awt::FontSlant_NONE; +} + +void SAL_CALL VbaNewFont::setItalic( sal_Bool bItalic ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ), + uno::Any( bItalic ? awt::FontSlant_ITALIC : awt::FontSlant_NONE ) ); +} + +sal_Bool SAL_CALL VbaNewFont::getUnderline() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ) ); + return aAny.get< sal_Int16 >() != awt::FontUnderline::NONE; +} + +void SAL_CALL VbaNewFont::setUnderline( sal_Bool bUnderline ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ), + uno::Any( bUnderline ? awt::FontUnderline::SINGLE : awt::FontUnderline::NONE ) ); +} + +sal_Bool SAL_CALL VbaNewFont::getStrikethrough() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ) ); + return aAny.get< sal_Int16 >() != awt::FontStrikeout::NONE; +} + +void SAL_CALL VbaNewFont::setStrikethrough( sal_Bool bStrikethrough ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ), + uno::Any( bStrikethrough ? awt::FontStrikeout::SINGLE : awt::FontStrikeout::NONE ) ); +} + +// XHelperInterface + +VBAHELPER_IMPL_XHELPERINTERFACE( VbaNewFont, "ooo.vba.msforms.NewFont" ) + +// ============================================================================ diff --git a/vbahelper/source/msforms/vbanewfont.hxx b/vbahelper/source/msforms/vbanewfont.hxx new file mode 100755 index 000000000000..d59d5caa139c --- /dev/null +++ b/vbahelper/source/msforms/vbanewfont.hxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#ifndef VBAHELPER_MSFORMS_VBANEWFONT_HXX +#define VBAHELPER_MSFORMS_VBANEWFONT_HXX + +#include <ooo/vba/msforms/XNewFont.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +// ============================================================================ + +typedef InheritedHelperInterfaceImpl1< ov::msforms::XNewFont > VbaNewFont_BASE; + +class VbaNewFont : public VbaNewFont_BASE +{ +public: + VbaNewFont( + const css::uno::Reference< ov::XHelperInterface >& rxParent, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::beans::XPropertySet >& rxModelProps ) throw (css::uno::RuntimeException); + + // XNewFont attributes + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const ::rtl::OUString& rName ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getSize() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSize( double fSize ) throw (css::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getCharset() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCharset( sal_Int16 nCharset ) throw (css::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getWeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWeight( sal_Int16 nWeight ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getBold() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBold( sal_Bool bBold ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getItalic() throw (css::uno::RuntimeException); + virtual void SAL_CALL setItalic( sal_Bool bItalic ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getUnderline() throw (css::uno::RuntimeException); + virtual void SAL_CALL setUnderline( sal_Bool bUnderline ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getStrikethrough() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStrikethrough( sal_Bool bStrikethrough ) throw (css::uno::RuntimeException); + + // XHelperInterface + VBAHELPER_DECL_XHELPERINTERFACE + +private: + css::uno::Reference< css::beans::XPropertySet > mxProps; +}; + +// ============================================================================ + +#endif diff --git a/vbahelper/source/msforms/vbaradiobutton.cxx b/vbahelper/source/msforms/vbaradiobutton.cxx index 94d12c5823ba..12ee1ad8ae41 100644 --- a/vbahelper/source/msforms/vbaradiobutton.cxx +++ b/vbahelper/source/msforms/vbaradiobutton.cxx @@ -24,8 +24,9 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #include "vbaradiobutton.hxx" -#include <vector> +#include "vbanewfont.hxx" using namespace com::sun::star; using namespace ooo::vba; @@ -84,6 +85,11 @@ ScVbaRadioButton::setValue( const uno::Any& _value ) throw (uno::RuntimeExceptio m_xProps->setPropertyValue( STATE, uno::makeAny( nValue ) ); } +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaRadioButton::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + rtl::OUString& ScVbaRadioButton::getServiceImplName() { diff --git a/vbahelper/source/msforms/vbaradiobutton.hxx b/vbahelper/source/msforms/vbaradiobutton.hxx index a0de21ae5d0e..3da00eb0765e 100644 --- a/vbahelper/source/msforms/vbaradiobutton.hxx +++ b/vbahelper/source/msforms/vbaradiobutton.hxx @@ -42,6 +42,7 @@ public: virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); virtual void SAL_CALL setValue(const com::sun::star::uno::Any&) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); //XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); diff --git a/vbahelper/source/msforms/vbatextbox.cxx b/vbahelper/source/msforms/vbatextbox.cxx index 2d83d41d77c3..b6aedcdceaf6 100644 --- a/vbahelper/source/msforms/vbatextbox.cxx +++ b/vbahelper/source/msforms/vbatextbox.cxx @@ -24,16 +24,16 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ -#include <com/sun/star/text/XTextRange.hpp> #include "vbatextbox.hxx" -#include <vector> +#include "vbanewfont.hxx" +#include <com/sun/star/text/XTextRange.hpp> +#include <ooo/vba/msforms/fmBorderStyle.hpp> +#include <ooo/vba/msforms/fmSpecialEffect.hpp> using namespace com::sun::star; using namespace ooo::vba; - - ScVbaTextBox::ScVbaTextBox( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper, bool bDialog ) : TextBoxImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ), mbDialog( bDialog ) { } @@ -48,7 +48,8 @@ ScVbaTextBox::getValue() throw (css::uno::RuntimeException) void SAL_CALL ScVbaTextBox::setValue( const uno::Any& _value ) throw (css::uno::RuntimeException) { - rtl::OUString sVal = getAnyAsString( _value ); + // booleans are converted to uppercase strings + rtl::OUString sVal = extractStringFromAny( _value, true ); setText( sVal ); } @@ -114,6 +115,34 @@ ScVbaTextBox::setMultiline( sal_Bool _multiline ) throw (css::uno::RuntimeExcept (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ), aValue); } +sal_Int32 SAL_CALL ScVbaTextBox::getSpecialEffect() throw (uno::RuntimeException) +{ + return msforms::fmSpecialEffect::fmSpecialEffectSunken; +} + +void SAL_CALL ScVbaTextBox::setSpecialEffect( sal_Int32 /*nSpecialEffect*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaTextBox::getBorderStyle() throw (uno::RuntimeException) +{ + return msforms::fmBorderStyle::fmBorderStyleNone; +} + +void SAL_CALL ScVbaTextBox::setBorderStyle( sal_Int32 /*nBorderStyle*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaTextBox::getTextLength() throw (uno::RuntimeException) +{ + return getText().getLength(); +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaTextBox::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + rtl::OUString& ScVbaTextBox::getServiceImplName() { diff --git a/vbahelper/source/msforms/vbatextbox.hxx b/vbahelper/source/msforms/vbatextbox.hxx index 0553e047488e..586bceb607a0 100644 --- a/vbahelper/source/msforms/vbatextbox.hxx +++ b/vbahelper/source/msforms/vbatextbox.hxx @@ -47,6 +47,12 @@ public: virtual void SAL_CALL setMaxLength( sal_Int32 _maxlength ) throw (css::uno::RuntimeException); virtual sal_Bool SAL_CALL getMultiline() throw (css::uno::RuntimeException); virtual void SAL_CALL setMultiline( sal_Bool _multiline ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getSpecialEffect() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSpecialEffect( sal_Int32 nSpecialEffect ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getBorderStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBorderStyle( sal_Int32 nBorderStyle ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getTextLength() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); // XDefaultProperty rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } //XHelperInterface diff --git a/vbahelper/source/msforms/vbatogglebutton.cxx b/vbahelper/source/msforms/vbatogglebutton.cxx index 071651ff8a36..d1a3b40d6eb7 100644 --- a/vbahelper/source/msforms/vbatogglebutton.cxx +++ b/vbahelper/source/msforms/vbatogglebutton.cxx @@ -24,8 +24,9 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #include "vbatogglebutton.hxx" -#include <vector> +#include "vbanewfont.hxx" using namespace com::sun::star; using namespace ooo::vba; @@ -79,6 +80,56 @@ ScVbaToggleButton::setValue( const uno::Any& _value ) throw (uno::RuntimeExcepti m_xProps->setPropertyValue( STATE, uno::makeAny( nState ) ); } +sal_Bool SAL_CALL ScVbaToggleButton::getAutoSize() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaToggleButton::setAutoSize( sal_Bool /*bAutoSize*/ ) throw (uno::RuntimeException) +{ +} + +sal_Bool SAL_CALL ScVbaToggleButton::getCancel() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaToggleButton::setCancel( sal_Bool /*bCancel*/ ) throw (uno::RuntimeException) +{ +} + +sal_Bool SAL_CALL ScVbaToggleButton::getDefault() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaToggleButton::setDefault( sal_Bool /*bDefault*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaToggleButton::getBackColor() throw (uno::RuntimeException) +{ + return 0; +} + +void SAL_CALL ScVbaToggleButton::setBackColor( sal_Int32 /*nBackColor*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaToggleButton::getForeColor() throw (uno::RuntimeException) +{ + return 0; +} + +void SAL_CALL ScVbaToggleButton::setForeColor( sal_Int32 /*nForeColor*/ ) throw (uno::RuntimeException) +{ +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaToggleButton::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + rtl::OUString& ScVbaToggleButton::getServiceImplName() { diff --git a/vbahelper/source/msforms/vbatogglebutton.hxx b/vbahelper/source/msforms/vbatogglebutton.hxx index bfdd68d09642..d2bf4c6b7f17 100644 --- a/vbahelper/source/msforms/vbatogglebutton.hxx +++ b/vbahelper/source/msforms/vbatogglebutton.hxx @@ -43,9 +43,19 @@ public: // Attributes virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); - virtual rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getAutoSize() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAutoSize( sal_Bool bAutoSize ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getCancel() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCancel( sal_Bool bCancel ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getDefault() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDefault( sal_Bool bDefault ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getBackColor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBackColor( sal_Int32 nBackColor ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getForeColor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setForeColor( sal_Int32 nForeColor ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); //XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); diff --git a/vbahelper/source/msforms/vbauserform.cxx b/vbahelper/source/msforms/vbauserform.cxx index 16bc97babd7d..3eb799205389 100644 --- a/vbahelper/source/msforms/vbauserform.cxx +++ b/vbahelper/source/msforms/vbauserform.cxx @@ -54,7 +54,7 @@ ScVbaUserForm::ScVbaUserForm( uno::Sequence< uno::Any > const& aArgs, uno::Refer m_xDialog.set( m_xControl, uno::UNO_QUERY_THROW ); uno::Reference< awt::XControl > xControl( m_xDialog, uno::UNO_QUERY_THROW ); m_xProps.set( xControl->getModel(), uno::UNO_QUERY_THROW ); - setGeometryHelper( new UserFormGeometryHelper( xContext, xControl ) ); + setGeometryHelper( new UserFormGeometryHelper( xContext, xControl, 0.0, 0.0 ) ); } ScVbaUserForm::~ScVbaUserForm() @@ -105,18 +105,38 @@ ScVbaUserForm::Show( ) throw (uno::RuntimeException) } rtl::OUString SAL_CALL -ScVbaUserForm::getCaption() throw (::com::sun::star::uno::RuntimeException) +ScVbaUserForm::getCaption() throw (uno::RuntimeException) { rtl::OUString sCaption; m_xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") ) ) >>= sCaption; return sCaption; } void -ScVbaUserForm::setCaption( const ::rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException) +ScVbaUserForm::setCaption( const ::rtl::OUString& _caption ) throw (uno::RuntimeException) { m_xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") ), uno::makeAny( _caption ) ); } +double SAL_CALL ScVbaUserForm::getInnerWidth() throw (uno::RuntimeException) +{ + return mpGeometryHelper->getInnerWidth(); +} + +void SAL_CALL ScVbaUserForm::setInnerWidth( double fInnerWidth ) throw (uno::RuntimeException) +{ + mpGeometryHelper->setInnerWidth( fInnerWidth ); +} + +double SAL_CALL ScVbaUserForm::getInnerHeight() throw (uno::RuntimeException) +{ + return mpGeometryHelper->getInnerHeight(); +} + +void SAL_CALL ScVbaUserForm::setInnerHeight( double fInnerHeight ) throw (uno::RuntimeException) +{ + mpGeometryHelper->setInnerHeight( fInnerHeight ); +} + void SAL_CALL ScVbaUserForm::Hide( ) throw (uno::RuntimeException) { @@ -202,13 +222,7 @@ ScVbaUserForm::getValue( const ::rtl::OUString& aPropertyName ) throw (beans::Un uno::Reference< awt::XControlContainer > xContainer( m_xDialog, uno::UNO_QUERY_THROW ); uno::Reference< awt::XControl > xControl = xContainer->getControl( aPropertyName ); if ( xControl.is() ) - { - ScVbaControlFactory aFac( mxContext, xControl, m_xModel ); - uno::Reference< msforms::XControl > xVBAControl( aFac.createControl( xDialogControl->getModel() ) ); - ScVbaControl* pControl = dynamic_cast< ScVbaControl* >( xVBAControl.get() ); - pControl->setGeometryHelper( new UserFormGeometryHelper( mxContext, xControl ) ); - aResult = uno::makeAny( xVBAControl ); - } + aResult <<= ScVbaControlFactory::createUserformControl( mxContext, xControl, xDialogControl, m_xModel, mpGeometryHelper->getOffsetX(), mpGeometryHelper->getOffsetY() ); } return aResult; @@ -225,7 +239,7 @@ ScVbaUserForm::Controls( const uno::Any& index ) throw (uno::RuntimeException) // if the dialog already closed we should do nothing, but the VBA will call methods of the Controls objects // thus we have to provide a dummy object in this case uno::Reference< awt::XControl > xDialogControl( m_xDialog, uno::UNO_QUERY ); - uno::Reference< XCollection > xControls( new ScVbaControls( this, mxContext, xDialogControl ) ); + uno::Reference< XCollection > xControls( new ScVbaControls( this, mxContext, xDialogControl, m_xModel, mpGeometryHelper->getOffsetX(), mpGeometryHelper->getOffsetY() ) ); if ( index.hasValue() ) return uno::makeAny( xControls->Item( index, uno::Any() ) ); return uno::makeAny( xControls ); diff --git a/vbahelper/source/msforms/vbauserform.hxx b/vbahelper/source/msforms/vbauserform.hxx index 71e8b4f62aa9..1777a979b9f2 100644 --- a/vbahelper/source/msforms/vbauserform.hxx +++ b/vbahelper/source/msforms/vbauserform.hxx @@ -50,18 +50,22 @@ public: // XUserForm virtual void SAL_CALL RePaint( ) throw (css::uno::RuntimeException); virtual void SAL_CALL Show( ) throw (css::uno::RuntimeException); - // XIntrospection - virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection( ) throw (css::uno::RuntimeException); - virtual css::uno::Any SAL_CALL invoke( const ::rtl::OUString& aFunctionName, const css::uno::Sequence< css::uno::Any >& aParams, css::uno::Sequence< ::sal_Int16 >& aOutParamIndex, css::uno::Sequence< css::uno::Any >& aOutParam ) throw (css::lang::IllegalArgumentException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException); virtual void SAL_CALL setValue( const ::rtl::OUString& aPropertyName, const css::uno::Any& aValue ) throw (css::beans::UnknownPropertyException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException); virtual css::uno::Any SAL_CALL getValue( const ::rtl::OUString& aPropertyName ) throw (css::beans::UnknownPropertyException, css::uno::RuntimeException); - virtual ::sal_Bool SAL_CALL hasMethod( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException); - virtual ::sal_Bool SAL_CALL hasProperty( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getCaption() throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setCaption( const ::rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getInnerWidth() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setInnerWidth( double fInnerWidth ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getInnerHeight() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setInnerHeight( double fInnerHeight ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL Hide( ) throw (css::uno::RuntimeException); virtual void SAL_CALL UnloadObject( ) throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL Controls( const css::uno::Any& index ) throw (css::uno::RuntimeException); + // XIntrospection + virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL invoke( const ::rtl::OUString& aFunctionName, const css::uno::Sequence< css::uno::Any >& aParams, css::uno::Sequence< ::sal_Int16 >& aOutParamIndex, css::uno::Sequence< css::uno::Any >& aOutParam ) throw (css::lang::IllegalArgumentException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL hasMethod( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL hasProperty( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException); //XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); diff --git a/vbahelper/source/vbahelper/collectionbase.cxx b/vbahelper/source/vbahelper/collectionbase.cxx new file mode 100755 index 000000000000..16fc673f54d5 --- /dev/null +++ b/vbahelper/source/vbahelper/collectionbase.cxx @@ -0,0 +1,332 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2011 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. + * + ************************************************************************/ + +#include <vbahelper/collectionbase.hxx> + +#include <map> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <cppuhelper/implbase2.hxx> + +namespace vbahelper { + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +// ============================================================================ + +namespace { + +// ---------------------------------------------------------------------------- + +class CollectionEnumeration : public ::cppu::WeakImplHelper1< container::XEnumeration > +{ +public: + explicit CollectionEnumeration( const ::rtl::Reference< CollectionBase >& rxCollection ); + virtual sal_Bool SAL_CALL hasMoreElements() throw (uno::RuntimeException); + virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); + +private: + ::rtl::Reference< CollectionBase > mxCollection; + sal_Int32 mnCurrIndex; +}; + +CollectionEnumeration::CollectionEnumeration( const ::rtl::Reference< CollectionBase >& rxCollection ) : + mxCollection( rxCollection ), + mnCurrIndex( 1 ) // collection expects one-based indexes +{ +} + +sal_Bool SAL_CALL CollectionEnumeration::hasMoreElements() throw (uno::RuntimeException) +{ + return mnCurrIndex <= mxCollection->getCount(); +} + +uno::Any SAL_CALL CollectionEnumeration::nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) +{ + if( hasMoreElements() ) + return mxCollection->getItemByIndex( mnCurrIndex++ ); + throw container::NoSuchElementException(); +} + +// ---------------------------------------------------------------------------- + +struct IsLessIgnoreCase +{ + inline bool operator()( const ::rtl::OUString& rName1, const ::rtl::OUString& rName2 ) const + { return ::rtl_ustr_compareIgnoreAsciiCase_WithLength( rName1.getStr(), rName1.getLength(), rName2.getStr(), rName2.getLength() ) < 0; } +}; + +// ---------------------------------------------------------------------------- + +class SequenceToContainer : public ::cppu::WeakImplHelper2< container::XIndexAccess, container::XNameAccess > +{ +public: + explicit SequenceToContainer( const ::std::vector< uno::Reference< container::XNamed > >& rElements, const uno::Type& rElementType ); + explicit SequenceToContainer( const ::std::vector< beans::NamedValue >& rElements, const uno::Type& rElementType ); + // XIndexAccess + virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException); + virtual uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException); + // XNameAccess + virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& rName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); + virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() throw (uno::RuntimeException); + virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException); + // XElementAccess + virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException); + virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException); + +private: + typedef uno::Sequence< ::rtl::OUString > ElementNameSequence; + typedef ::std::vector< uno::Any > ElementVector; + typedef ::std::map< ::rtl::OUString, uno::Any, IsLessIgnoreCase > ElementMap; + + ElementNameSequence maElementNames; + ElementVector maElements; + ElementMap maElementMap; + uno::Type maElementType; +}; + +SequenceToContainer::SequenceToContainer( const ::std::vector< uno::Reference< container::XNamed > >& rElements, const uno::Type& rElementType ) : + maElementType( rElementType ) +{ + maElementNames.realloc( static_cast< sal_Int32 >( rElements.size() ) ); + maElements.reserve( rElements.size() ); + ::rtl::OUString* pElementName = maElementNames.getArray(); + for( ::std::vector< uno::Reference< container::XNamed > >::const_iterator aIt = rElements.begin(), aEnd = rElements.end(); aIt != aEnd; ++aIt, ++pElementName ) + { + uno::Reference< container::XNamed > xNamed = *aIt; + *pElementName = xNamed->getName(); + maElements.push_back( uno::Any( xNamed ) ); + // same name may occur multiple times, VBA returns first occurance + if( maElementMap.count( *pElementName ) == 0 ) + maElementMap[ *pElementName ] <<= xNamed; + } +} + +SequenceToContainer::SequenceToContainer( const ::std::vector< beans::NamedValue >& rElements, const uno::Type& rElementType ) : + maElementType( rElementType ) +{ + maElementNames.realloc( static_cast< sal_Int32 >( rElements.size() ) ); + maElements.reserve( rElements.size() ); + ::rtl::OUString* pElementName = maElementNames.getArray(); + for( ::std::vector< beans::NamedValue >::const_iterator aIt = rElements.begin(), aEnd = rElements.end(); aIt != aEnd; ++aIt, ++pElementName ) + { + *pElementName = aIt->Name; + maElements.push_back( aIt->Value ); + // same name may occur multiple times, VBA returns first occurance + if( maElementMap.count( *pElementName ) == 0 ) + maElementMap[ *pElementName ] = aIt->Value; + } +} + +sal_Int32 SAL_CALL SequenceToContainer::getCount() throw (uno::RuntimeException) +{ + return static_cast< sal_Int32 >( maElements.size() ); +} + +uno::Any SAL_CALL SequenceToContainer::getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) +{ + if( (0 <= nIndex) && (nIndex < getCount()) ) + return maElements[ static_cast< size_t >( nIndex ) ]; + throw lang::IndexOutOfBoundsException(); +} + +uno::Any SAL_CALL SequenceToContainer::getByName( const ::rtl::OUString& rName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) +{ + ElementMap::iterator aIt = maElementMap.find( rName ); + if( aIt != maElementMap.end() ) + return aIt->second; + throw container::NoSuchElementException(); +} + +uno::Sequence< ::rtl::OUString > SAL_CALL SequenceToContainer::getElementNames() throw (uno::RuntimeException) +{ + return maElementNames; +} + +sal_Bool SAL_CALL SequenceToContainer::hasByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException) +{ + return maElementMap.count( rName ) > 0; +} + +uno::Type SAL_CALL SequenceToContainer::getElementType() throw (uno::RuntimeException) +{ + return maElementType; +} + +sal_Bool SAL_CALL SequenceToContainer::hasElements() throw (uno::RuntimeException) +{ + return !maElements.empty(); +} + +} // namespace + +// ============================================================================ + +CollectionBase::CollectionBase( const uno::Type& rElementType ) : + maElementType( rElementType ), + mbConvertOnDemand( false ) +{ +} + +sal_Int32 SAL_CALL CollectionBase::getCount() throw (uno::RuntimeException) +{ + if( mxIndexAccess.is() ) + return mxIndexAccess->getCount(); + if( mxNameAccess.is() ) + return mxNameAccess->getElementNames().getLength(); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); +} + +uno::Reference< container::XEnumeration > SAL_CALL CollectionBase::createEnumeration() throw (uno::RuntimeException) +{ + return new CollectionEnumeration( this ); +} + +uno::Type SAL_CALL CollectionBase::getElementType() throw (uno::RuntimeException) +{ + return maElementType; +} + +sal_Bool SAL_CALL CollectionBase::hasElements() throw (uno::RuntimeException) +{ + if( mxIndexAccess.is() ) + return mxIndexAccess->hasElements(); + if( mxNameAccess.is() ) + return mxNameAccess->hasElements(); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); +} + +::rtl::OUString SAL_CALL CollectionBase::getDefaultMethodName() throw (uno::RuntimeException) +{ + static ::rtl::OUString saDefMethodName( RTL_CONSTASCII_USTRINGPARAM( "Item" ) ); + return saDefMethodName; +} + +// ---------------------------------------------------------------------------- + +void CollectionBase::initContainer( + const uno::Reference< container::XElementAccess >& rxElementAccess, + ContainerType eContainerType ) throw (uno::RuntimeException) +{ + mxIndexAccess.set( rxElementAccess, uno::UNO_QUERY ); + mxNameAccess.set( rxElementAccess, uno::UNO_QUERY ); + switch( eContainerType ) + { + case CONTAINER_NATIVE_VBA: + mbConvertOnDemand = false; + break; + case CONTAINER_CONVERT_ON_DEMAND: + mbConvertOnDemand = true; + break; + } +} + +void CollectionBase::initElements( const ::std::vector< uno::Reference< container::XNamed > >& rElements, ContainerType eContainerType ) throw (uno::RuntimeException) +{ + // SequenceToContainer derives twice from XElementAccess, need to resolve ambiguity + initContainer( static_cast< container::XIndexAccess* >( new SequenceToContainer( rElements, maElementType ) ), eContainerType ); +} + +void CollectionBase::initElements( const ::std::vector< beans::NamedValue >& rElements, ContainerType eContainerType ) throw (uno::RuntimeException) +{ + // SequenceToContainer derives twice from XElementAccess, need to resolve ambiguity + initContainer( static_cast< container::XIndexAccess* >( new SequenceToContainer( rElements, maElementType ) ), eContainerType ); +} + +uno::Any CollectionBase::createCollectionItem( const uno::Any& rElement, const uno::Any& rIndex ) throw (css::uno::RuntimeException) +{ + uno::Any aItem = mbConvertOnDemand ? implCreateCollectionItem( rElement, rIndex ) : rElement; + if( aItem.hasValue() ) + return aItem; + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item." ) ), 0 ); +} + +uno::Any CollectionBase::getItemByIndex( sal_Int32 nIndex ) throw (uno::RuntimeException) +{ + if( mxIndexAccess.is() ) + { + if( (1 <= nIndex) && (nIndex <= mxIndexAccess->getCount()) ) + // createCollectionItem() will convert from container element to VBA item + return createCollectionItem( mxIndexAccess->getByIndex( nIndex - 1 ), uno::Any( nIndex ) ); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Index out of bounds." ) ), 0 ); + } + if( mxNameAccess.is() ) + { + uno::Sequence< ::rtl::OUString > aElementNames = mxNameAccess->getElementNames(); + if( (1 <= nIndex) && (nIndex <= aElementNames.getLength()) ) + // createCollectionItem() will convert from container element to VBA item + return createCollectionItem( mxNameAccess->getByName( aElementNames[ nIndex - 1 ] ), uno::Any( aElementNames[ nIndex - 1 ] ) ); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Index out of bounds." ) ), 0 ); + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); +} + +uno::Any CollectionBase::getItemByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException) +{ + if( mxNameAccess.is() ) + { + if( rName.getLength() > 0 ) + // createCollectionItem() will convert from container element to VBA item + return createCollectionItem( mxNameAccess->getByName( rName ), uno::Any( rName ) ); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item name." ) ), 0 ); + } + if( mxIndexAccess.is() ) + { + for( sal_Int32 nIndex = 0, nSize = mxIndexAccess->getCount(); nIndex < nSize; ++nIndex ) + { + uno::Any aElement = mxIndexAccess->getByIndex( nIndex ); + uno::Reference< container::XNamed > xNamed( aElement, uno::UNO_QUERY ); + if( xNamed.is() && xNamed->getName().equalsIgnoreAsciiCase( rName ) ) + // createCollectionItem() will convert from container element to VBA item + return createCollectionItem( aElement, uno::Any( nIndex ) ); + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item name." ) ), 0 ); + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); +} + +uno::Any CollectionBase::getAnyItemOrThis( const uno::Any& rIndex ) throw (uno::RuntimeException) +{ + if( !rIndex.hasValue() ) + return uno::Any( uno::Reference< XCollectionBase >( this ) ); + if( rIndex.has< ::rtl::OUString >() ) + return getItemByName( rIndex.get< ::rtl::OUString >() ); + // extractIntFromAny() throws if no index can be extracted + return getItemByIndex( extractIntFromAny( rIndex ) ); +} + +// protected ------------------------------------------------------------------ + +uno::Any CollectionBase::implCreateCollectionItem( const uno::Any& /*rElement*/, const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException) +{ + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Creation of VBA implementation object not implemented." ) ), 0 ); +} + +// ============================================================================ + +} // namespace vbahelper diff --git a/vbahelper/source/vbahelper/vbaapplicationbase.cxx b/vbahelper/source/vbahelper/vbaapplicationbase.cxx index 54d280094f2c..5ae0a2c23890 100644 --- a/vbahelper/source/vbahelper/vbaapplicationbase.cxx +++ b/vbahelper/source/vbahelper/vbaapplicationbase.cxx @@ -387,12 +387,12 @@ uno::Any SAL_CALL VbaApplicationBase::getVBE() throw (uno::RuntimeException) { try // return empty object on error { - uno::Sequence< uno::Any > aArgs( 2 ); - aArgs[ 0 ] <<= uno::Reference< XHelperInterface >( this ); - aArgs[ 1 ] <<= getCurrentDocument(); + // "VBE" object does not have a parent, but pass document model to be able to determine application type + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= getCurrentDocument(); uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); uno::Reference< uno::XInterface > xVBE = xServiceManager->createInstanceWithArgumentsAndContext( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBE" ) ), aArgs, mxContext ); + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.vbide.VBE" ) ), aArgs, mxContext ); return uno::Any( xVBE ); } catch( uno::Exception& ) @@ -401,25 +401,6 @@ uno::Any SAL_CALL VbaApplicationBase::getVBE() throw (uno::RuntimeException) return uno::Any(); } -uno::Any SAL_CALL -VbaApplicationBase::getVBProjects() throw (uno::RuntimeException) -{ - try // return empty object on error - { - uno::Sequence< uno::Any > aArgs( 2 ); - aArgs[ 0 ] <<= uno::Reference< XHelperInterface >( this ); - aArgs[ 1 ] <<= getCurrentDocument(); - uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); - uno::Reference< uno::XInterface > xVBProjects = xServiceManager->createInstanceWithArgumentsAndContext( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBProjects" ) ), aArgs, mxContext ); - return uno::Any( xVBProjects ); - } - catch( uno::Exception& ) - { - } - return uno::Any(); -} - rtl::OUString& VbaApplicationBase::getServiceImplName() { diff --git a/vbahelper/source/vbahelper/vbacommandbar.cxx b/vbahelper/source/vbahelper/vbacommandbar.cxx index 1e8d21d53583..11cbacb79894 100644 --- a/vbahelper/source/vbahelper/vbacommandbar.cxx +++ b/vbahelper/source/vbahelper/vbacommandbar.cxx @@ -154,14 +154,7 @@ ScVbaCommandBar::Delete( ) throw (script::BasicErrorException, uno::RuntimeExce uno::Any SAL_CALL ScVbaCommandBar::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException) { - uno::Reference< awt::XMenu > xMenu; - if( m_bIsMenu ) - { - uno::Reference< frame::XLayoutManager > xLayoutManager = pCBarHelper->getLayoutManager(); - uno::Reference< beans::XPropertySet > xPropertySet( xLayoutManager->getElement( m_sResourceUrl ), uno::UNO_QUERY_THROW ); - xMenu.set( xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("XMenuBar") ), uno::UNO_QUERY ); - } - uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, m_xBarSettings, pCBarHelper, m_xBarSettings, m_sResourceUrl, xMenu ) ); + uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, m_xBarSettings, pCBarHelper, m_xBarSettings, m_sResourceUrl ) ); if( aIndex.hasValue() ) { return xCommandBarControls->Item( aIndex, uno::Any() ); diff --git a/vbahelper/source/vbahelper/vbacommandbarcontrol.cxx b/vbahelper/source/vbahelper/vbacommandbarcontrol.cxx index 157d54eca7d5..d57bc00644a5 100644 --- a/vbahelper/source/vbahelper/vbacommandbarcontrol.cxx +++ b/vbahelper/source/vbahelper/vbacommandbarcontrol.cxx @@ -91,50 +91,37 @@ ScVbaCommandBarControl::setOnAction( const ::rtl::OUString& _onaction ) throw (u ::sal_Bool SAL_CALL ScVbaCommandBarControl::getVisible() throw (uno::RuntimeException) { - /*sal_Bool bVisible = sal_True; - uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("IsVisible") ); + sal_Bool bVisible = sal_True; + uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ) ); if( aValue.hasValue() ) aValue >>= bVisible; - return bVisible;*/ - return getEnabled(); - + return bVisible; } void SAL_CALL ScVbaCommandBarControl::setVisible( ::sal_Bool _visible ) throw (uno::RuntimeException) { - /*uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("IsVisible") ); + uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ) ); if( aValue.hasValue() ) { - setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("IsVisible"), uno::makeAny( _visible ) ); + setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ), uno::makeAny( _visible ) ); ApplyChange(); - }*/ - setEnabled( _visible); + } } ::sal_Bool SAL_CALL ScVbaCommandBarControl::getEnabled() throw (uno::RuntimeException) { sal_Bool bEnabled = sal_True; - rtl::OUString aCommandURLappendix = rtl::OUString::createFromAscii("___"); - rtl::OUString aCommandURL ; - if( m_xParentMenu.is() ) + uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ) ); + if( aValue.hasValue() ) { - // currently only the menu in the MenuBat support Enable/Disable - // FIXME: how to support the menu item in Toolbar - bEnabled = m_xParentMenu->isItemEnabled( m_xParentMenu->getItemId( sal::static_int_cast< sal_Int16 >( m_nPosition ) ) ); + aValue >>= bEnabled; } else { // emulated with Visible - //bEnabled = getVisible(); - uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("CommandURL") ); - if (aValue >>= aCommandURL){ - if (0 == aCommandURL.indexOf(aCommandURLappendix)){ - bEnabled = sal_False; - } - } - + bEnabled = getVisible(); } return bEnabled; } @@ -142,30 +129,16 @@ ScVbaCommandBarControl::getEnabled() throw (uno::RuntimeException) void SAL_CALL ScVbaCommandBarControl::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException) { - rtl::OUString aCommandURL ; - rtl::OUString aCommandURLappendix = rtl::OUString::createFromAscii("___"); - rtl::OUStringBuffer aCommandURLSringBuffer; - if( m_xParentMenu.is() ) + uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ) ); + if( aValue.hasValue() ) { - // currently only the menu in the MenuBat support Enable/Disable - m_xParentMenu->enableItem( m_xParentMenu->getItemId( sal::static_int_cast< sal_Int16 >( m_nPosition ) ), _enabled ); + setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ), uno::makeAny( _enabled ) ); + ApplyChange(); } else { - uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("CommandURL") ); - if (aValue >>= aCommandURL){ - if (0 == aCommandURL.indexOf(aCommandURLappendix)){ - aCommandURL = aCommandURL.copy(3); - } - if (false == _enabled){ - aCommandURLSringBuffer = aCommandURLappendix; - } - aCommandURLSringBuffer.append(aCommandURL); - setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("CommandURL"), uno::makeAny( aCommandURLSringBuffer.makeStringAndClear()) ); - ApplyChange(); - } // emulated with Visible - //setVisible( _enabled ); + setVisible( _enabled ); } } @@ -206,14 +179,7 @@ ScVbaCommandBarControl::Controls( const uno::Any& aIndex ) throw (script::BasicE if( !xSubMenu.is() ) throw uno::RuntimeException(); - uno::Reference< awt::XMenu > xMenu; - if( m_xParentMenu.is() ) - { - sal_Int16 nItemId = m_xParentMenu->getItemId( sal::static_int_cast< sal_Int16 >( m_nPosition ) ); - xMenu.set( m_xParentMenu->getPopupMenu( nItemId ), uno::UNO_QUERY ); - } - - uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, xSubMenu, pCBarHelper, m_xBarSettings, m_sResourceUrl, xMenu ) ); + uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, xSubMenu, pCBarHelper, m_xBarSettings, m_sResourceUrl ) ); if( aIndex.hasValue() ) { return xCommandBarControls->Item( aIndex, uno::Any() ); @@ -241,12 +207,11 @@ ScVbaCommandBarControl::getServiceNames() } //////////// ScVbaCommandBarPopup ////////////////////////////// -ScVbaCommandBarPopup::ScVbaCommandBarPopup( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary, const css::uno::Reference< css::awt::XMenu >& xMenu ) throw (css::uno::RuntimeException) : CommandBarPopup_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl ) +ScVbaCommandBarPopup::ScVbaCommandBarPopup( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarPopup_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl ) { m_nPosition = nPosition; m_bTemporary = bTemporary; m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues; - m_xParentMenu = xMenu; } rtl::OUString& @@ -268,12 +233,11 @@ ScVbaCommandBarPopup::getServiceNames() } //////////// ScVbaCommandBarButton ////////////////////////////// -ScVbaCommandBarButton::ScVbaCommandBarButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary, const css::uno::Reference< css::awt::XMenu >& xMenu ) throw (css::uno::RuntimeException) : CommandBarButton_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl ) +ScVbaCommandBarButton::ScVbaCommandBarButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarButton_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl ) { m_nPosition = nPosition; m_bTemporary = bTemporary; m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues; - m_xParentMenu = xMenu; } rtl::OUString& diff --git a/vbahelper/source/vbahelper/vbacommandbarcontrol.hxx b/vbahelper/source/vbahelper/vbacommandbarcontrol.hxx index a165f8e1cccd..5066ba75eea0 100644 --- a/vbahelper/source/vbahelper/vbacommandbarcontrol.hxx +++ b/vbahelper/source/vbahelper/vbacommandbarcontrol.hxx @@ -43,10 +43,9 @@ class ScVbaCommandBarControl : public CommandBarControl_BASE protected: VbaCommandBarHelperRef pCBarHelper; rtl::OUString m_sResourceUrl; - css::uno::Reference< css::container::XIndexAccess > m_xCurrentSettings; - css::uno::Reference< css::container::XIndexAccess > m_xBarSettings; - css::uno::Sequence< css::beans::PropertyValue > m_aPropertyValues; - css::uno::Reference< css::awt::XMenu > m_xParentMenu; + css::uno::Reference< css::container::XIndexAccess > m_xCurrentSettings; + css::uno::Reference< css::container::XIndexAccess > m_xBarSettings; + css::uno::Sequence< css::beans::PropertyValue > m_aPropertyValues; sal_Int32 m_nPosition; sal_Bool m_bTemporary; @@ -87,7 +86,7 @@ typedef cppu::ImplInheritanceHelper1< ScVbaCommandBarControl, ov::XCommandBarPop class ScVbaCommandBarPopup : public CommandBarPopup_BASE { public: - ScVbaCommandBarPopup( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary, const css::uno::Reference< css::awt::XMenu >& xMenu ) throw (css::uno::RuntimeException); + ScVbaCommandBarPopup( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException); virtual sal_Int32 SAL_CALL getType() throw (css::uno::RuntimeException) { @@ -102,7 +101,7 @@ typedef cppu::ImplInheritanceHelper1< ScVbaCommandBarControl, ov::XCommandBarBut class ScVbaCommandBarButton : public CommandBarButton_BASE { public: - ScVbaCommandBarButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary, const css::uno::Reference< css::awt::XMenu >& xMenu ) throw (css::uno::RuntimeException); + ScVbaCommandBarButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException); virtual sal_Int32 SAL_CALL getType() throw (css::uno::RuntimeException) { diff --git a/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx b/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx index 634b4a0e9395..da218d007736 100644 --- a/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx +++ b/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx @@ -55,14 +55,20 @@ public: } }; -ScVbaCommandBarControls::ScVbaCommandBarControls( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess>& xIndexAccess, VbaCommandBarHelperRef pHelper, const uno::Reference< container::XIndexAccess>& xBarSettings, const rtl::OUString& sResourceUrl, const uno::Reference< awt::XMenu >& xMenu ) throw (uno::RuntimeException) : CommandBarControls_BASE( xParent, xContext, xIndexAccess ), pCBarHelper( pHelper ), m_xBarSettings( xBarSettings ), m_sResourceUrl( sResourceUrl ), m_xMenu( xMenu ) +ScVbaCommandBarControls::ScVbaCommandBarControls( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess>& xIndexAccess, VbaCommandBarHelperRef pHelper, const uno::Reference< container::XIndexAccess>& xBarSettings, const rtl::OUString& sResourceUrl ) throw (uno::RuntimeException) : CommandBarControls_BASE( xParent, xContext, xIndexAccess ), pCBarHelper( pHelper ), m_xBarSettings( xBarSettings ), m_sResourceUrl( sResourceUrl ) { m_bIsMenu = sResourceUrl.equalsAscii( ITEM_MENUBAR_URL ) ? sal_True : sal_False; } -uno::Sequence< beans::PropertyValue > ScVbaCommandBarControls::CreateMenuItemData( const rtl::OUString& sCommandURL, const rtl::OUString& sHelpURL, const rtl::OUString& sLabel, sal_uInt16 nType, const uno::Any& aSubMenu ) +uno::Sequence< beans::PropertyValue > ScVbaCommandBarControls::CreateMenuItemData( const rtl::OUString& sCommandURL, + const rtl::OUString& sHelpURL, + const rtl::OUString& sLabel, + sal_uInt16 nType, + const uno::Any& aSubMenu, + sal_Bool isVisible, + sal_Bool isEnabled ) { - uno::Sequence< beans::PropertyValue > aProps(5); + uno::Sequence< beans::PropertyValue > aProps(7); aProps[0].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_COMMANDURL ); aProps[0].Value <<= sCommandURL; @@ -74,6 +80,10 @@ uno::Sequence< beans::PropertyValue > ScVbaCommandBarControls::CreateMenuItemDat aProps[3].Value <<= nType; aProps[4].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_CONTAINER ); aProps[4].Value = aSubMenu; + aProps[5].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ); + aProps[5].Value <<= isVisible; + aProps[6].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ); + aProps[6].Value <<= isEnabled; return aProps; } @@ -124,9 +134,9 @@ ScVbaCommandBarControls::createCollectionObject( const uno::Any& aSource ) getPropertyValue( aProps, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_CONTAINER ) ) >>= xSubMenu; ScVbaCommandBarControl* pNewCommandBarControl = NULL; if( xSubMenu.is() ) - pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True, m_xMenu ); + pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True ); else - pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True, m_xMenu ); + pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True ); return uno::makeAny( uno::Reference< XCommandBarControl > ( pNewCommandBarControl ) ); } @@ -202,7 +212,7 @@ ScVbaCommandBarControls::Add( const uno::Any& Type, const uno::Any& Id, const un sal_uInt16 nItemType = 0; if( IsMenu() ) { - aProps = CreateMenuItemData( sCommandUrl, sHelpUrl, sLabel, nItemType, aSubMenu ); + aProps = CreateMenuItemData( sCommandUrl, sHelpUrl, sLabel, nItemType, aSubMenu, true, true ); } else { @@ -217,12 +227,11 @@ ScVbaCommandBarControls::Add( const uno::Any& Type, const uno::Any& Id, const un pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings ); - // sometimes it would crash if passing m_xMenu instead of uno::Reference< awt::XMenu >() in Linux. ScVbaCommandBarControl* pNewCommandBarControl = NULL; if( nType == office::MsoControlType::msoControlPopup ) - pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary, uno::Reference< awt::XMenu >() ); + pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary ); else - pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary, uno::Reference< awt::XMenu >() ); + pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary ); return uno::Reference< XCommandBarControl >( pNewCommandBarControl ); } diff --git a/vbahelper/source/vbahelper/vbacommandbarcontrols.hxx b/vbahelper/source/vbahelper/vbacommandbarcontrols.hxx index 0b35773660d1..79a4a8c5a5fe 100644 --- a/vbahelper/source/vbahelper/vbacommandbarcontrols.hxx +++ b/vbahelper/source/vbahelper/vbacommandbarcontrols.hxx @@ -38,17 +38,22 @@ typedef CollTestImplHelper< ov::XCommandBarControls > CommandBarControls_BASE; class ScVbaCommandBarControls : public CommandBarControls_BASE { private: - VbaCommandBarHelperRef pCBarHelper; - css::uno::Reference< css::container::XIndexAccess > m_xBarSettings; - rtl::OUString m_sResourceUrl; - css::uno::Reference< css::awt::XMenu > m_xMenu; - sal_Bool m_bIsMenu; + VbaCommandBarHelperRef pCBarHelper; + css::uno::Reference< css::container::XIndexAccess > m_xBarSettings; + rtl::OUString m_sResourceUrl; + sal_Bool m_bIsMenu; - css::uno::Sequence< css::beans::PropertyValue > CreateMenuItemData( const rtl::OUString& sCommandURL, const rtl::OUString& sHelpURL, const rtl::OUString& sLabel, sal_uInt16 nType, const css::uno::Any& aSubMenu ); + css::uno::Sequence< css::beans::PropertyValue > CreateMenuItemData( const rtl::OUString& sCommandURL, + const rtl::OUString& sHelpURL, + const rtl::OUString& sLabel, + sal_uInt16 nType, + const css::uno::Any& aSubMenu, + sal_Bool isVisible, + sal_Bool isEnabled ); css::uno::Sequence< css::beans::PropertyValue > CreateToolbarItemData( const rtl::OUString& sCommandURL, const rtl::OUString& sHelpURL, const rtl::OUString& sLabel, sal_uInt16 nType, const css::uno::Any& aSubMenu, sal_Bool isVisible, sal_Int32 nStyle ); public: - ScVbaCommandBarControls( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, const css::uno::Reference< css::awt::XMenu >& xMenu ) throw( css::uno::RuntimeException ); + ScVbaCommandBarControls( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl ) throw( css::uno::RuntimeException ); sal_Bool IsMenu(){ return m_bIsMenu; } // XEnumerationAccess diff --git a/vbahelper/source/vbahelper/vbacommandbarhelper.hxx b/vbahelper/source/vbahelper/vbacommandbarhelper.hxx index 1fa41d7141b3..93c6e5f55457 100644 --- a/vbahelper/source/vbahelper/vbacommandbarhelper.hxx +++ b/vbahelper/source/vbahelper/vbacommandbarhelper.hxx @@ -47,6 +47,7 @@ static const char ITEM_DESCRIPTOR_STYLE[] = "Style"; static const char ITEM_DESCRIPTOR_ISVISIBLE[] = "IsVisible"; static const char ITEM_DESCRIPTOR_RESOURCEURL[] = "ResourceURL"; static const char ITEM_DESCRIPTOR_UINAME[] = "UIName"; +static const char ITEM_DESCRIPTOR_ENABLED[] = "Enabled"; static const char ITEM_MENUBAR_URL[] = "private:resource/menubar/menubar"; static const char ITEM_TOOLBAR_URL[] = "private:resource/toolbar/"; diff --git a/vbahelper/source/vbahelper/vbadocumentbase.cxx b/vbahelper/source/vbahelper/vbadocumentbase.cxx index 087e7188c8f6..291bc6ad2931 100644 --- a/vbahelper/source/vbahelper/vbadocumentbase.cxx +++ b/vbahelper/source/vbahelper/vbadocumentbase.cxx @@ -38,6 +38,7 @@ #include <com/sun/star/frame/XFrame.hpp> #include <com/sun/star/document/XEmbeddedScripts.hpp> //Michael E. Bohn #include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/XApplicationBase.hpp> #include <cppuhelper/exc_hlp.hxx> #include <comphelper/unwrapargs.hxx> @@ -265,20 +266,21 @@ VbaDocumentBase::Activate() throw (uno::RuntimeException) uno::Any SAL_CALL VbaDocumentBase::getVBProject() throw (uno::RuntimeException) { - try // return empty object on error + if( !mxVBProject.is() ) try { + uno::Reference< XApplicationBase > xApp( Application(), uno::UNO_QUERY_THROW ); + uno::Reference< XInterface > xVBE( xApp->getVBE(), uno::UNO_QUERY_THROW ); uno::Sequence< uno::Any > aArgs( 2 ); - aArgs[ 0 ] <<= uno::Reference< XHelperInterface >( this ); - aArgs[ 1 ] <<= getModel(); + aArgs[ 0 ] <<= xVBE; // the VBE + aArgs[ 1 ] <<= getModel(); // document model for script container access uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); - uno::Reference< uno::XInterface > xVBProjects = xServiceManager->createInstanceWithArgumentsAndContext( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBProject" ) ), aArgs, mxContext ); - return uno::Any( xVBProjects ); + mxVBProject = xServiceManager->createInstanceWithArgumentsAndContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.vbide.VBProject" ) ), aArgs, mxContext ); } catch( uno::Exception& ) { } - return uno::Any(); + return uno::Any( mxVBProject ); } rtl::OUString& diff --git a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx index 8000a7cdf66e..5e2cf949c473 100755 --- a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx +++ b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx @@ -26,34 +26,40 @@ ************************************************************************/ #include "vbahelper/vbaeventshelperbase.hxx" +#include <com/sun/star/document/XEventBroadcaster.hpp> +#include <com/sun/star/script/ModuleType.hpp> +#include <com/sun/star/script/vba/XVBAModuleInfo.hpp> +#include <com/sun/star/util/XChangesNotifier.hpp> #include <filter/msfilter/msvbahelper.hxx> +#include <unotools/eventcfg.hxx> using namespace ::com::sun::star; using namespace ::ooo::vba; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + // ============================================================================ VbaEventsHelperBase::VbaEventsHelperBase( const uno::Sequence< uno::Any >& rArgs, const uno::Reference< uno::XComponentContext >& /*xContext*/ ) : mpShell( 0 ), - mbDisposed( false ) + mbDisposed( true ) { try { mxModel = getXSomethingFromArgs< frame::XModel >( rArgs, 0, false ); mpShell = getSfxObjShell( mxModel ); - - // add dispose listener - uno::Reference< lang::XComponent > xComponent( mxModel, uno::UNO_QUERY_THROW ); - xComponent->addEventListener( this ); } catch( uno::Exception& ) { } + mbDisposed = mpShell == 0; + startListening(); } VbaEventsHelperBase::~VbaEventsHelperBase() { - stopListening(); + OSL_ENSURE( mbDisposed, "VbaEventsHelperBase::~VbaEventsHelperBase - missing disposing notification" ); } sal_Bool SAL_CALL VbaEventsHelperBase::hasVbaEventHandler( sal_Int32 nEventId, const uno::Sequence< uno::Any >& rArgs ) @@ -65,8 +71,8 @@ sal_Bool SAL_CALL VbaEventsHelperBase::hasVbaEventHandler( sal_Int32 nEventId, c return getEventHandlerPath( rInfo, rArgs ).getLength() > 0; } -void SAL_CALL VbaEventsHelperBase::processVbaEvent( sal_Int32 nEventId, const uno::Sequence< uno::Any >& rArgs ) - throw (lang::IllegalArgumentException, script::provider::ScriptFrameworkErrorException, util::VetoException, uno::RuntimeException) +sal_Bool SAL_CALL VbaEventsHelperBase::processVbaEvent( sal_Int32 nEventId, const uno::Sequence< uno::Any >& rArgs ) + throw (lang::IllegalArgumentException, util::VetoException, uno::RuntimeException) { /* Derived classes may add new event identifiers to be processed while processing the original event. All unprocessed events are collected in @@ -79,9 +85,9 @@ void SAL_CALL VbaEventsHelperBase::processVbaEvent( sal_Int32 nEventId, const un handler receives the Cancel value of the previous event handler. */ bool bCancel = false; - /* bSuccess will change to true if at least one event handler has been - executed successfully. */ - bool bSuccess = false; + /* bExecuted will change to true if at least one event handler has been + found and executed. */ + bool bExecuted = false; /* Loop as long as there are more events to be processed. Derived classes may add new events to be processed in the virtual implPrepareEvent() @@ -98,15 +104,15 @@ void SAL_CALL VbaEventsHelperBase::processVbaEvent( sal_Int32 nEventId, const un const EventHandlerInfo& rInfo = getEventHandlerInfo( aEventQueue.front().mnEventId ); uno::Sequence< uno::Any > aEventArgs = aEventQueue.front().maArgs; aEventQueue.pop_front(); + OSL_TRACE( "VbaEventsHelperBase::processVbaEvent( \"%s\" )", ::rtl::OUStringToOString( rInfo.maMacroName, RTL_TEXTENCODING_UTF8 ).getStr() ); /* Let derived classes prepare the event, they may add new events for next iteration. If false is returned, the event handler must not be called. */ - bool bEventSuccess = false; if( implPrepareEvent( aEventQueue, rInfo, aEventArgs ) ) { // search the event handler macro in the document - ::rtl::OUString aMacroPath = getEventHandlerPath( rInfo, aEventArgs ); + OUString aMacroPath = getEventHandlerPath( rInfo, aEventArgs ); if( aMacroPath.getLength() > 0 ) { // build the argument list @@ -120,96 +126,225 @@ void SAL_CALL VbaEventsHelperBase::processVbaEvent( sal_Int32 nEventId, const un } // execute the event handler uno::Any aRet, aCaller; - bEventSuccess = executeMacro( mpShell, aMacroPath, aVbaArgs, aRet, aCaller ); - // extract new cancel value + executeMacro( mpShell, aMacroPath, aVbaArgs, aRet, aCaller ); + // extract new cancel value (may be boolean or any integer type) if( rInfo.mnCancelIndex >= 0 ) { - if( rInfo.mnCancelIndex >= aVbaArgs.getLength() ) - throw lang::IllegalArgumentException(); - // cancel value may be boolean or any integer type, Any(bool) does not extract to sal_Int32 - bool bNewCancel = false; - sal_Int32 nNewCancel = 0; - if( aVbaArgs[ rInfo.mnCancelIndex ] >>= bNewCancel ) - bCancel = bNewCancel; - else if( aVbaArgs[ rInfo.mnCancelIndex ] >>= nNewCancel ) - bCancel = nNewCancel != 0; + checkArgument( aVbaArgs, rInfo.mnCancelIndex ); + bCancel = extractBoolFromAny( aVbaArgs[ rInfo.mnCancelIndex ] ); } + // event handler has been found + bExecuted = true; } - // global success, if at least one event handler succeeded - bSuccess |= bEventSuccess; } // post processing (also, if event handler does not exist, or disabled, or on error - implPostProcessEvent( aEventQueue, rInfo, bEventSuccess, bCancel ); + implPostProcessEvent( aEventQueue, rInfo, bCancel ); } // if event handlers want to cancel the event, do so regardless of any errors if( bCancel ) throw util::VetoException(); - // if no event handler finished successfully, throw - if( !bSuccess ) - throw script::provider::ScriptFrameworkErrorException(); + // return true, if at least one event handler has been found + return bExecuted; } -void SAL_CALL VbaEventsHelperBase::disposing( const lang::EventObject& /*aSource*/ ) throw (uno::RuntimeException) +void SAL_CALL VbaEventsHelperBase::notifyEvent( const document::EventObject& rEvent ) throw (uno::RuntimeException) { - OSL_TRACE( "VbaEventsHelperBase::disposing" ); - stopListening(); - mbDisposed = true; + OSL_TRACE( "VbaEventsHelperBase::notifyEvent( \"%s\" )", ::rtl::OUStringToOString( rEvent.EventName, RTL_TEXTENCODING_UTF8 ).getStr() ); + if( rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ) ) + stopListening(); +} + +void SAL_CALL VbaEventsHelperBase::changesOccurred( const util::ChangesEvent& rEvent ) throw (uno::RuntimeException) +{ + // make sure the VBA library exists + try + { + ensureVBALibrary(); + } + catch( uno::Exception& ) + { + return; + } + + // check that the sender of the event is the VBA library + uno::Reference< script::vba::XVBAModuleInfo > xSender( rEvent.Base, uno::UNO_QUERY ); + if( mxModuleInfos.get() != xSender.get() ) + return; + + // process all changed modules + for( sal_Int32 nIndex = 0, nLength = rEvent.Changes.getLength(); nIndex < nLength; ++nIndex ) + { + const util::ElementChange& rChange = rEvent.Changes[ nIndex ]; + OUString aModuleName; + if( (rChange.Accessor >>= aModuleName) && (aModuleName.getLength() > 0) ) try + { + // invalidate event handler path map depending on module type + if( getModuleType( aModuleName ) == script::ModuleType::NORMAL ) + // paths to global event handlers are stored with empty key (will be searched in all normal code modules) + maEventPaths.erase( OUString() ); + else + // paths to class/form/document event handlers are keyed by module name + maEventPaths.erase( aModuleName ); + } + catch( uno::Exception& ) + { + } + } +} + +void SAL_CALL VbaEventsHelperBase::disposing( const lang::EventObject& rEvent ) throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xSender( rEvent.Source, uno::UNO_QUERY ); + if( xSender.is() ) + stopListening(); +} + +void VbaEventsHelperBase::processVbaEventNoThrow( sal_Int32 nEventId, const uno::Sequence< uno::Any >& rArgs ) +{ + try + { + processVbaEvent( nEventId, rArgs ); + } + catch( uno::Exception& ) + { + } } // protected ------------------------------------------------------------------ -void VbaEventsHelperBase::registerEventHandler( sal_Int32 nEventId, - const sal_Char* pcMacroName, EventHandlerType eType, sal_Int32 nCancelIndex, const uno::Any& rUserData ) +void VbaEventsHelperBase::registerEventHandler( sal_Int32 nEventId, sal_Int32 nModuleType, + const sal_Char* pcMacroName, sal_Int32 nCancelIndex, const uno::Any& rUserData ) { - EventHandlerInfo& rInfo = maEvents[ nEventId ]; + EventHandlerInfo& rInfo = maEventInfos[ nEventId ]; rInfo.mnEventId = nEventId; - rInfo.maMacroName = ::rtl::OUString::createFromAscii( pcMacroName ); - rInfo.meType = eType; + rInfo.mnModuleType = nModuleType; + rInfo.maMacroName = OUString::createFromAscii( pcMacroName ); rInfo.mnCancelIndex = nCancelIndex; rInfo.maUserData = rUserData; } // private -------------------------------------------------------------------- +void VbaEventsHelperBase::startListening() +{ + if( mbDisposed ) + return; + + uno::Reference< document::XEventBroadcaster > xEventBroadcaster( mxModel, uno::UNO_QUERY ); + if( xEventBroadcaster.is() ) + try { xEventBroadcaster->addEventListener( this ); } catch( uno::Exception& ) {} +} + +void VbaEventsHelperBase::stopListening() +{ + if( mbDisposed ) + return; + + uno::Reference< document::XEventBroadcaster > xEventBroadcaster( mxModel, uno::UNO_QUERY ); + if( xEventBroadcaster.is() ) + try { xEventBroadcaster->removeEventListener( this ); } catch( uno::Exception& ) {} + + mxModel.clear(); + mpShell = 0; + maEventInfos.clear(); + mbDisposed = true; +} + const VbaEventsHelperBase::EventHandlerInfo& VbaEventsHelperBase::getEventHandlerInfo( sal_Int32 nEventId ) const throw (lang::IllegalArgumentException) { - EventHandlerMap::const_iterator aIt = maEvents.find( nEventId ); - if( aIt == maEvents.end() ) + EventHandlerInfoMap::const_iterator aIt = maEventInfos.find( nEventId ); + if( aIt == maEventInfos.end() ) throw lang::IllegalArgumentException(); return aIt->second; } -::rtl::OUString VbaEventsHelperBase::getEventHandlerPath( const EventHandlerInfo& rInfo, - const uno::Sequence< uno::Any >& rArgs ) const throw (lang::IllegalArgumentException) +OUString VbaEventsHelperBase::getEventHandlerPath( const EventHandlerInfo& rInfo, + const uno::Sequence< uno::Any >& rArgs ) throw (lang::IllegalArgumentException, uno::RuntimeException) { - ::rtl::OUString aMacroName; - switch( rInfo.meType ) + OUString aModuleName; + switch( rInfo.mnModuleType ) { - case EVENTHANDLER_GLOBAL: - aMacroName = rInfo.maMacroName; + // global event handlers may exist in any standard code module + case script::ModuleType::NORMAL: break; - case EVENTHANDLER_DOCUMENT: - aMacroName = ::rtl::OUStringBuffer( implGetDocumentModuleName( rInfo, rArgs ) ). - append( sal_Unicode( '.' ) ).append( rInfo.maMacroName ).makeStringAndClear(); + + // document event: get name of the code module associated to the event sender + case script::ModuleType::DOCUMENT: + aModuleName = implGetDocumentModuleName( rInfo, rArgs ); + if( aModuleName.getLength() == 0 ) + throw lang::IllegalArgumentException(); break; + + default: + throw uno::RuntimeException(); // unsupported module type } - MacroResolvedInfo aMacroInfo = resolveVBAMacro( mpShell, aMacroName, false ); - return aMacroInfo.mbFound ? ::rtl::OUString( aMacroInfo.msResolvedMacro ) : ::rtl::OUString(); + + /* Performance improvement: Check the list of existing event handlers + instead of searching in Basic source code every time. */ + EventHandlerPathMap::iterator aIt = maEventPaths.find( aModuleName ); + ModulePathMap& rPathMap = (aIt == maEventPaths.end()) ? updateModulePathMap( aModuleName ) : aIt->second; + return rPathMap[ rInfo.mnEventId ]; } -void VbaEventsHelperBase::stopListening() +void VbaEventsHelperBase::ensureVBALibrary() throw (uno::RuntimeException) { - if( !mbDisposed ) try + if( !mxModuleInfos.is() ) try { - uno::Reference< lang::XComponent > xComponent( mxModel, uno::UNO_QUERY_THROW ); - xComponent->removeEventListener( this ); + maLibraryName = getDefaultProjectName( mpShell ); + if( maLibraryName.getLength() == 0 ) + throw uno::RuntimeException(); + uno::Reference< beans::XPropertySet > xModelProps( mxModel, uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xBasicLibs( xModelProps->getPropertyValue( + OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ), uno::UNO_QUERY_THROW ); + mxModuleInfos.set( xBasicLibs->getByName( maLibraryName ), uno::UNO_QUERY_THROW ); + // listen to changes in the VBA source code + uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModuleInfos, uno::UNO_QUERY_THROW ); + xChangesNotifier->addChangesListener( this ); } catch( uno::Exception& ) { + // error accessing the Basic library, so this object is useless + stopListening(); + throw uno::RuntimeException(); + } +} + +sal_Int32 VbaEventsHelperBase::getModuleType( const OUString& rModuleName ) throw (uno::RuntimeException) +{ + // make sure the VBA library exists + ensureVBALibrary(); + + // no module specified: global event handler in standard code modules + if( rModuleName.getLength() == 0 ) + return script::ModuleType::NORMAL; + + // get module type from module info + try + { + return mxModuleInfos->getModuleInfo( rModuleName ).ModuleType; + } + catch( uno::Exception& ) + { + } + throw uno::RuntimeException(); +} + +VbaEventsHelperBase::ModulePathMap& VbaEventsHelperBase::updateModulePathMap( const ::rtl::OUString& rModuleName ) throw (uno::RuntimeException) +{ + // get type of the specified module (throws on error) + sal_Int32 nModuleType = getModuleType( rModuleName ); + // search for all event handlers + ModulePathMap& rPathMap = maEventPaths[ rModuleName ]; + for( EventHandlerInfoMap::iterator aIt = maEventInfos.begin(), aEnd = maEventInfos.end(); aIt != aEnd; ++aIt ) + { + const EventHandlerInfo& rInfo = aIt->second; + if( rInfo.mnModuleType == nModuleType ) + rPathMap[ rInfo.mnEventId ] = resolveVBAMacro( mpShell, maLibraryName, rModuleName, rInfo.maMacroName ); } + return rPathMap; } // ============================================================================ diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx index cfce8b49e3d1..2a13124a741e 100644 --- a/vbahelper/source/vbahelper/vbahelper.cxx +++ b/vbahelper/source/vbahelper/vbahelper.cxx @@ -628,82 +628,87 @@ void PrintOutHelper( SfxViewShell* pViewShell, const uno::Any& From, const uno:: dispatchExecute( pViewShell, SID_VIEWSHELL1 ); } -bool extractBoolFromAny( bool& rbValue, const uno::Any& rAny ) +sal_Int32 extractIntFromAny( const uno::Any& rAny ) throw (uno::RuntimeException) { - if( rAny >>= rbValue ) return true; - - sal_Int64 nSigned = 0; - if( rAny >>= nSigned ) { rbValue = nSigned != 0; return true; } - - sal_uInt64 nUnsigned = 0; - if( rAny >>= nUnsigned ) { rbValue = nUnsigned > 0; return true; } - - double fDouble = 0.0; - if( rAny >>= fDouble ) { rbValue = fDouble != 0.0; return true; } + switch( rAny.getValueType().getTypeClass() ) + { + case uno::TypeClass_FLOAT: + return static_cast< sal_Int32 >( rAny.get< float >() ); + case uno::TypeClass_DOUBLE: + return static_cast< sal_Int32 >( rAny.get< double >() ); + case uno::TypeClass_BYTE: + case uno::TypeClass_SHORT: + case uno::TypeClass_LONG: + return rAny.get< sal_Int32 >(); + default:; + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to integer." ) ), 0 ); +} - return false; +sal_Int32 extractIntFromAny( const uno::Any& rAny, sal_Int32 nDefault ) throw (uno::RuntimeException) +{ + return rAny.hasValue() ? extractIntFromAny( rAny ) : nDefault; } bool extractBoolFromAny( const uno::Any& rAny ) throw (uno::RuntimeException) { - bool bValue = false; - if( extractBoolFromAny( bValue, rAny ) ) - return bValue; - throw uno::RuntimeException(); + switch( rAny.getValueType().getTypeClass() ) + { + case uno::TypeClass_BOOLEAN: + return rAny.get< bool >(); + case uno::TypeClass_FLOAT: + return rAny.get< float >() != 0.0; + case uno::TypeClass_DOUBLE: + return rAny.get< double >() != 0.0; + case uno::TypeClass_BYTE: + case uno::TypeClass_SHORT: + case uno::TypeClass_LONG: + return rAny.get< sal_Int32 >() != 0; + case uno::TypeClass_HYPER: + return rAny.get< sal_Int64 >() != 0; + default:; + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to boolean." ) ), 0 ); } -rtl::OUString getAnyAsString( const uno::Any& pvargItem ) throw ( uno::RuntimeException ) +bool extractBoolFromAny( const uno::Any& rAny, bool bDefault ) throw (uno::RuntimeException) +{ + return rAny.hasValue() ? extractBoolFromAny( rAny ) : bDefault; +} + +::rtl::OUString extractStringFromAny( const uno::Any& rAny, bool bUppercaseBool ) throw (uno::RuntimeException) { - uno::Type aType = pvargItem.getValueType(); - uno::TypeClass eTypeClass = aType.getTypeClass(); - rtl::OUString sString; - switch ( eTypeClass ) + switch( rAny.getValueType().getTypeClass() ) { - case uno::TypeClass_BOOLEAN: - { - sal_Bool bBool = sal_False; - pvargItem >>= bBool; - sString = rtl::OUString::valueOf( bBool ); - break; - } case uno::TypeClass_STRING: - pvargItem >>= sString; - break; + return rAny.get< ::rtl::OUString >(); + case uno::TypeClass_BOOLEAN: + return bUppercaseBool ? + (rAny.get< bool >() ? ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TRUE" ) ) : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FALSE" ) )) : + ::rtl::OUString::valueOf( (sal_Bool)rAny.get< bool >() ); case uno::TypeClass_FLOAT: - { - float aFloat = 0; - pvargItem >>= aFloat; - sString = rtl::OUString::valueOf( aFloat ); - break; - } + return ::rtl::OUString::valueOf( rAny.get< float >() ); case uno::TypeClass_DOUBLE: - { - double aDouble = 0; - pvargItem >>= aDouble; - sString = rtl::OUString::valueOf( aDouble ); - break; - } + return ::rtl::OUString::valueOf( rAny.get< double >() ); + case uno::TypeClass_BYTE: case uno::TypeClass_SHORT: case uno::TypeClass_LONG: - case uno::TypeClass_BYTE: - { - sal_Int32 aNum = 0; - pvargItem >>= aNum; - sString = rtl::OUString::valueOf( aNum ); - break; - } - + return ::rtl::OUString::valueOf( rAny.get< sal_Int32 >() ); case uno::TypeClass_HYPER: - { - sal_Int64 aHyper = 0; - pvargItem >>= aHyper; - sString = rtl::OUString::valueOf( aHyper ); - break; - } - default: - throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid type, can't convert" ), uno::Reference< uno::XInterface >() ); + return ::rtl::OUString::valueOf( rAny.get< sal_Int64 >() ); + default:; } - return sString; + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to string." ) ), 0 ); +} + +::rtl::OUString extractStringFromAny( const uno::Any& rAny, const ::rtl::OUString& rDefault, bool bUppercaseBool ) throw (uno::RuntimeException) +{ + return rAny.hasValue() ? extractStringFromAny( rAny, bUppercaseBool ) : rDefault; +} + +rtl::OUString getAnyAsString( const uno::Any& pvargItem ) throw ( uno::RuntimeException ) +{ + return extractStringFromAny( pvargItem ); } @@ -840,7 +845,7 @@ rtl::OUString VBAToRegexp(const rtl::OUString &rIn, bool bForLike ) return sResult.makeStringAndClear( ); } -double getPixelTo100thMillimeterConversionFactor( css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical) +double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical) { double fConvertFactor = 1.0; if( bVertical ) @@ -854,12 +859,12 @@ double getPixelTo100thMillimeterConversionFactor( css::uno::Reference< css::awt: return fConvertFactor; } -double PointsToPixels( css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical) +double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical) { double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); return PointsToHmm( fPoints ) * fConvertFactor; } -double PixelsToPoints( css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical) +double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical) { double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); return HmmToPoints( fPixels/fConvertFactor ); @@ -994,128 +999,176 @@ sal_Bool setPropertyValue( uno::Sequence< beans::PropertyValue >& aProp, const r // ====UserFormGeomentryHelper==== //--------------------------------------------- -UserFormGeometryHelper::UserFormGeometryHelper( const uno::Reference< uno::XComponentContext >& /*xContext*/, const uno::Reference< awt::XControl >& xControl ) -: mbDialog( uno::Reference< awt::XDialog >( xControl, uno::UNO_QUERY ).is() ) +UserFormGeometryHelper::UserFormGeometryHelper( + const uno::Reference< uno::XComponentContext >& /*xContext*/, + const uno::Reference< awt::XControl >& xControl, + double fOffsetX, double fOffsetY ) : + mfOffsetX( fOffsetX ), + mfOffsetY( fOffsetY ), + mbDialog( uno::Reference< awt::XDialog >( xControl, uno::UNO_QUERY ).is() ) { if ( !xControl.is() ) throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No control is provided!" ) ), uno::Reference< uno::XInterface >() ); mxWindow.set( xControl->getPeer(), uno::UNO_QUERY_THROW ); + mxModelProps.set( xControl->getModel(), uno::UNO_QUERY_THROW ); + mxUnitConv.set( mxWindow, uno::UNO_QUERY_THROW ); } -//--------------------------------------------- -double UserFormGeometryHelper::getLeft() +double UserFormGeometryHelper::getLeft() const { - return mxWindow->getPosSize().X; + return implGetPos( false ); } -//--------------------------------------------- -void UserFormGeometryHelper::setLeft( double nLeft ) +void UserFormGeometryHelper::setLeft( double fLeft ) { - mxWindow->setPosSize( nLeft, mxWindow->getPosSize().Y, 0, 0, awt::PosSize::POS ); + implSetPos( fLeft, false ); } -//--------------------------------------------- -double UserFormGeometryHelper::getTop() +double UserFormGeometryHelper::getTop() const { - return mxWindow->getPosSize().Y; + return implGetPos( true ); } -//--------------------------------------------- -void UserFormGeometryHelper::setTop( double nTop ) +void UserFormGeometryHelper::setTop( double fTop ) { - mxWindow->setPosSize( mxWindow->getPosSize().X, nTop, 0, 0, awt::PosSize::POS ); + implSetPos( fTop, true ); } -//--------------------------------------------- -double UserFormGeometryHelper::getWidth() +double UserFormGeometryHelper::getWidth() const { - if ( mbDialog ) - { - const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); - if ( pWindow ) - { - // get the size with decoration - Rectangle aResult = pWindow->GetWindowExtentsRelative( NULL ); - return aResult.getWidth(); - } - } + return implGetSize( false, true ); +} + +void UserFormGeometryHelper::setWidth( double fWidth ) +{ + implSetSize( fWidth, false, true ); +} - return mxWindow->getPosSize().Width; +double UserFormGeometryHelper::getHeight() const +{ + return implGetSize( true, true ); } -//--------------------------------------------- -void UserFormGeometryHelper::setWidth( double nWidth ) +void UserFormGeometryHelper::setHeight( double fHeight ) { - sal_Int64 nNewWidth = nWidth; + implSetSize( fHeight, true, true ); +} - if ( mbDialog ) - { - const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); - if ( pWindow ) - { - // set the size with decoration - Rectangle aRDecor = pWindow->GetWindowExtentsRelative( NULL ); - if ( !aRDecor.IsEmpty() ) - { - sal_Int64 nDecor = aRDecor.getWidth(); - sal_Int64 nUnDecor = mxWindow->getPosSize().Width; - if ( nWidth < nDecor - nUnDecor ) - nUnDecor = nDecor - nWidth; // avoid negative size - nNewWidth = nWidth + nUnDecor - nDecor; - } - } - } +double UserFormGeometryHelper::getInnerWidth() const +{ + return implGetSize( false, false ); +} - mxWindow->setPosSize( 0, 0, nNewWidth, 0, awt::PosSize::WIDTH ); +void UserFormGeometryHelper::setInnerWidth( double fWidth ) +{ + implSetSize( fWidth, false, false ); } -//--------------------------------------------- -double UserFormGeometryHelper::getHeight() +double UserFormGeometryHelper::getInnerHeight() const +{ + return implGetSize( true, false ); +} + +void UserFormGeometryHelper::setInnerHeight( double fHeight ) +{ + implSetSize( fHeight, true, false ); +} + +double UserFormGeometryHelper::getOffsetX() const +{ + return mfOffsetX; +} + +double UserFormGeometryHelper::getOffsetY() const +{ + return mfOffsetY; +} + +// ---------------------------------------------------------------------------- + +static const ::rtl::OUString saPosXName( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ); +static const ::rtl::OUString saPosYName( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ); +static const ::rtl::OUString saWidthName( RTL_CONSTASCII_USTRINGPARAM( "Width" ) ); +static const ::rtl::OUString saHeightName( RTL_CONSTASCII_USTRINGPARAM( "Height" ) ); + +double UserFormGeometryHelper::implGetPos( bool bPosY ) const +{ + sal_Int32 nPosAppFont = mxModelProps->getPropertyValue( bPosY ? saPosYName : saPosXName ).get< sal_Int32 >(); + // appfont to pixel + awt::Point aPosPixel = mxUnitConv->convertPointToPixel( awt::Point( nPosAppFont, nPosAppFont ), util::MeasureUnit::APPFONT ); + // pixel to VBA points + awt::Point aPosPoint = mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::POINT ); + return bPosY ? (aPosPoint.Y - mfOffsetY) : (aPosPoint.X - mfOffsetX); +} + +void UserFormGeometryHelper::implSetPos( double fPos, bool bPosY ) { - if ( mbDialog ) + // convert passed VBA points to pixels + sal_Int32 nPosPixel = static_cast< sal_Int32 >( fPos + (bPosY ? mfOffsetY : mfOffsetX) ); + awt::Point aPosPixel = mxUnitConv->convertPointToPixel( awt::Point( nPosPixel, nPosPixel ), util::MeasureUnit::POINT ); + // pixel to appfont + awt::Point aPosAppFont = mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::APPFONT ); + mxModelProps->setPropertyValue( bPosY ? saPosYName : saPosXName, uno::Any( bPosY ? aPosAppFont.Y : aPosAppFont.X ) ); +} + +double UserFormGeometryHelper::implGetSize( bool bHeight, bool bOuter ) const +{ + sal_Int32 nSizeAppFont = mxModelProps->getPropertyValue( bHeight ? saHeightName : saWidthName ).get< sal_Int32 >(); + // appfont to pixel + awt::Size aSizePixel = mxUnitConv->convertSizeToPixel( awt::Size( nSizeAppFont, nSizeAppFont ), util::MeasureUnit::APPFONT ); + + /* The VBA symbols 'Width' and 'Height' return the outer size including + window decoration (in difference to the symbols 'InnerWidth' and + 'InnerHeight'), but the window API returns the inner size. */ + if( mbDialog && bOuter ) { - const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); - if ( pWindow ) + if( const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ) ) { - // get the size with decoration - Rectangle aResult = pWindow->GetWindowExtentsRelative( NULL ); - return aResult.getHeight(); + Rectangle aOuterRect = pWindow->GetWindowExtentsRelative( NULL ); + aSizePixel = awt::Size( aOuterRect.getWidth(), aOuterRect.getHeight() ); } } - return mxWindow->getPosSize().Height; + // pixel to VBA points + awt::Size aSizePoint = mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::POINT ); + return bHeight ? aSizePoint.Height : aSizePoint.Width; } -//--------------------------------------------- -void UserFormGeometryHelper::setHeight( double nHeight ) +void UserFormGeometryHelper::implSetSize( double fSize, bool bHeight, bool bOuter ) { - sal_Int64 nNewHeight = nHeight; - if ( mbDialog ) + // convert passed VBA points to pixels + sal_Int32 nSize = static_cast< sal_Int32 >( fSize ); + awt::Size aSizePixel = mxUnitConv->convertSizeToPixel( awt::Size( nSize, nSize ), util::MeasureUnit::POINT ); + + /* The VBA symbols 'Width' and 'Height' set the outer size (in difference + to the symbols 'InnerWidth' and 'InnerHeight'), but the dialog model + expects the inner size. We have to remove the window extents from the + pixel height to get the same result. */ + if ( mbDialog && bOuter ) { - const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ); - if ( pWindow ) + if( const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ) ) { - // set the size with decoration - Rectangle aRDecor = pWindow->GetWindowExtentsRelative( NULL ); - if ( !aRDecor.IsEmpty() ) + Rectangle aOuterRect = pWindow->GetWindowExtentsRelative( NULL ); + if( !aOuterRect.IsEmpty() ) { - sal_Int64 nDecor = aRDecor.getHeight(); - sal_Int64 nUnDecor = mxWindow->getPosSize().Height; - if ( nHeight < nDecor - nUnDecor ) - nUnDecor = nDecor - nHeight; // avoid negative size - nNewHeight = nHeight + nUnDecor - nDecor; + awt::Rectangle aInnerRect = mxWindow->getPosSize(); + sal_Int32 nDecorWidth = aOuterRect.getWidth() - aInnerRect.Width; + sal_Int32 nDecorHeight = aOuterRect.getHeight() - aInnerRect.Height; + aSizePixel.Width = ::std::max< sal_Int32 >( aSizePixel.Width - nDecorWidth, 1 ); + aSizePixel.Height = ::std::max< sal_Int32 >( aSizePixel.Height - nDecorHeight, 1 ); } } } - mxWindow->setPosSize( 0, 0, 0, nNewHeight, awt::PosSize::HEIGHT ); + awt::Size aSizeAppFont = mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::APPFONT ); + mxModelProps->setPropertyValue( bHeight ? saHeightName : saWidthName, uno::Any( bHeight ? aSizeAppFont.Height : aSizeAppFont.Width ) ); } -// ============ +// ============================================================================ - double ConcreteXShapeGeometryAttributes::getLeft() + double ConcreteXShapeGeometryAttributes::getLeft() const { return m_pShapeHelper->getLeft(); } @@ -1123,7 +1176,7 @@ void UserFormGeometryHelper::setHeight( double nHeight ) { m_pShapeHelper->setLeft( nLeft ); } - double ConcreteXShapeGeometryAttributes::getTop() + double ConcreteXShapeGeometryAttributes::getTop() const { return m_pShapeHelper->getTop(); } @@ -1132,7 +1185,7 @@ void UserFormGeometryHelper::setHeight( double nHeight ) m_pShapeHelper->setTop( nTop ); } - double ConcreteXShapeGeometryAttributes::getHeight() + double ConcreteXShapeGeometryAttributes::getHeight() const { return m_pShapeHelper->getHeight(); } @@ -1140,7 +1193,7 @@ void UserFormGeometryHelper::setHeight( double nHeight ) { m_pShapeHelper->setHeight( nHeight ); } - double ConcreteXShapeGeometryAttributes::getWidth() + double ConcreteXShapeGeometryAttributes::getWidth() const { return m_pShapeHelper->getWidth(); } @@ -1156,7 +1209,7 @@ void UserFormGeometryHelper::setHeight( double nHeight ) throw css::uno::RuntimeException( rtl::OUString::createFromAscii("No valid shape for helper"), css::uno::Reference< css::uno::XInterface >() ); } - double ShapeHelper::getHeight() + double ShapeHelper::getHeight() const { return Millimeter::getInPoints(xShape->getSize().Height); } @@ -1177,7 +1230,7 @@ void UserFormGeometryHelper::setHeight( double nHeight ) } - double ShapeHelper::getWidth() + double ShapeHelper::getWidth() const { return Millimeter::getInPoints(xShape->getSize().Width); } @@ -1197,7 +1250,7 @@ void UserFormGeometryHelper::setHeight( double nHeight ) } - double ShapeHelper::getLeft() + double ShapeHelper::getLeft() const { return Millimeter::getInPoints(xShape->getPosition().X); } @@ -1211,7 +1264,7 @@ void UserFormGeometryHelper::setHeight( double nHeight ) } - double ShapeHelper::getTop() + double ShapeHelper::getTop() const { return Millimeter::getInPoints(xShape->getPosition().Y); } @@ -1279,38 +1332,50 @@ void UserFormGeometryHelper::setHeight( double nHeight ) return points; } - uno::Reference< uno::XInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell ) - { - uno::Reference< uno::XInterface > xIf; - if ( pShell ) - { - rtl::OUString sProj( RTL_CONSTASCII_USTRINGPARAM("Standard") ); - BasicManager* pBasMgr = pShell->GetBasicManager(); - if ( pBasMgr && pBasMgr->GetName().Len() ) - sProj = pShell->GetBasicManager()->GetName(); - StarBASIC* pBasic = pShell->GetBasicManager()->GetLib( sProj ); - if ( pBasic ) - { - SbModule* pMod = pBasic->FindModule( aModName ); - if ( pMod ) - xIf = pMod->GetUnoModule(); - } - } - return xIf; - } +uno::Reference< XHelperInterface > getVBADocument( const uno::Reference< frame::XModel >& xModel ) +{ + uno::Reference< XHelperInterface > xIf; + try + { + uno::Reference< beans::XPropertySet > xDocProps( xModel, uno::UNO_QUERY_THROW ); + ::rtl::OUString aCodeName; + xDocProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CodeName" ) ) ) >>= aCodeName; + xIf = getUnoDocModule( aCodeName, getSfxObjShell( xModel ) ); + } + catch( uno::Exception& ) + { + } + return xIf; +} - SfxObjectShell* getSfxObjShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) - { - SfxObjectShell* pFoundShell = NULL; - if ( xModel.is() ) - { - uno::Reference< lang::XUnoTunnel > xObjShellTunnel( xModel, uno::UNO_QUERY_THROW ); - pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId())); - } - if ( !pFoundShell ) - throw uno::RuntimeException(); - return pFoundShell; - } +uno::Reference< XHelperInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell ) +{ + uno::Reference< XHelperInterface > xIf; + if ( pShell ) + { + rtl::OUString sProj( RTL_CONSTASCII_USTRINGPARAM("Standard") ); + BasicManager* pBasMgr = pShell->GetBasicManager(); + if ( pBasMgr && pBasMgr->GetName().Len() ) + sProj = pBasMgr->GetName(); + if( StarBASIC* pBasic = pShell->GetBasicManager()->GetLib( sProj ) ) + if( SbModule* pMod = pBasic->FindModule( aModName ) ) + xIf.set( pMod->GetUnoModule(), uno::UNO_QUERY ); + } + return xIf; +} + +SfxObjectShell* getSfxObjShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) +{ + SfxObjectShell* pFoundShell = NULL; + if ( xModel.is() ) + { + uno::Reference< lang::XUnoTunnel > xObjShellTunnel( xModel, uno::UNO_QUERY_THROW ); + pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId())); + } + if ( !pFoundShell ) + throw uno::RuntimeException(); + return pFoundShell; +} } // openoffice } //org diff --git a/vbahelper/source/vbahelper/vbawindowbase.cxx b/vbahelper/source/vbahelper/vbawindowbase.cxx index 54546a394690..132caef8b5e1 100644 --- a/vbahelper/source/vbahelper/vbawindowbase.cxx +++ b/vbahelper/source/vbahelper/vbawindowbase.cxx @@ -24,137 +24,113 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ -#include <vbahelper/helperdecl.hxx> -#include <vbahelper/vbawindowbase.hxx> -#include <com/sun/star/awt/XWindow.hpp> -#include <com/sun/star/awt/XWindow2.hpp> + +#include "vbahelper/vbawindowbase.hxx" +#include "vbahelper/helperdecl.hxx" #include <com/sun/star/awt/PosSize.hpp> using namespace ::com::sun::star; using namespace ::ooo::vba; -VbaWindowBase::VbaWindowBase( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : WindowBaseImpl_BASE( xParent, xContext ), m_xModel( xModel ) +VbaWindowBase::VbaWindowBase( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const css::uno::Reference< css::frame::XModel >& xModel, + const uno::Reference< frame::XController >& xController ) throw (uno::RuntimeException) : + WindowBaseImpl_BASE( xParent, xContext ), + m_xModel( xModel, uno::UNO_SET_THROW ) { + construct( xController ); } -VbaWindowBase::VbaWindowBase( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & xContext ) - : WindowBaseImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), - m_xModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ) +VbaWindowBase::VbaWindowBase( uno::Sequence< uno::Any > const & args, + uno::Reference< uno::XComponentContext > const & xContext ) throw (uno::RuntimeException) : + WindowBaseImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0, false ), xContext ), + m_xModel( getXSomethingFromArgs< frame::XModel >( args, 1, false ) ) { + construct( getXSomethingFromArgs< frame::XController >( args, 2 ) ); } sal_Bool SAL_CALL VbaWindowBase::getVisible() throw (uno::RuntimeException) { - sal_Bool bVisible = sal_True; - uno::Reference< frame::XController > xController( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); - uno::Reference< css::awt::XWindow > xWindow (xController->getFrame()->getContainerWindow(), uno::UNO_QUERY_THROW ); - uno::Reference< css::awt::XWindow2 > xWindow2 (xWindow, uno::UNO_QUERY_THROW ); - if( xWindow2.is() ) - { - bVisible = xWindow2->isVisible(); - } - return bVisible; + return getWindow2()->isVisible(); } void SAL_CALL -VbaWindowBase::setVisible(sal_Bool _visible) throw (uno::RuntimeException) -{ - uno::Reference< frame::XController > xController( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); - uno::Reference< css::awt::XWindow > xWindow (xController->getFrame()->getContainerWindow(), uno::UNO_QUERY_THROW ); - if( xWindow.is() ) - { - xWindow->setVisible( _visible ); - } -} - -css::awt::Rectangle getPosSize( const uno::Reference< frame::XModel >& xModel ) +VbaWindowBase::setVisible( sal_Bool _visible ) throw (uno::RuntimeException) { - css::awt::Rectangle aRect; - uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); - uno::Reference< css::awt::XWindow > xWindow (xController->getFrame()->getContainerWindow(), uno::UNO_QUERY_THROW ); - if( xWindow.is() ) - { - aRect = xWindow->getPosSize(); - } - return aRect; + getWindow2()->setVisible( _visible ); } -void setPosSize( const uno::Reference< frame::XModel >& xModel, sal_Int32 nValue, sal_uInt16 nFlag ) +void setPosSize( const uno::Reference< awt::XWindow >& xWindow, sal_Int32 nValue, sal_Int16 nFlag ) { - uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); - uno::Reference< css::awt::XWindow > xWindow (xController->getFrame()->getContainerWindow(), uno::UNO_QUERY_THROW ); - if( xWindow.is() ) + css::awt::Rectangle aRect = xWindow->getPosSize(); + switch( nFlag ) { - css::awt::Rectangle aRect = xWindow->getPosSize(); - switch( nFlag ) - { - case css::awt::PosSize::X: - xWindow->setPosSize( nValue, aRect.Y, 0, 0, css::awt::PosSize::X ); - break; - case css::awt::PosSize::Y: - xWindow->setPosSize( aRect.X, nValue, 0, 0, css::awt::PosSize::Y ); - break; - case css::awt::PosSize::WIDTH: - xWindow->setPosSize( 0, 0, nValue, aRect.Height, css::awt::PosSize::WIDTH ); - break; - case css::awt::PosSize::HEIGHT: - xWindow->setPosSize( 0, 0, aRect.Width, nValue, css::awt::PosSize::HEIGHT ); - break; - default: - break; - } + case css::awt::PosSize::X: + xWindow->setPosSize( nValue, aRect.Y, 0, 0, css::awt::PosSize::X ); + break; + case css::awt::PosSize::Y: + xWindow->setPosSize( aRect.X, nValue, 0, 0, css::awt::PosSize::Y ); + break; + case css::awt::PosSize::WIDTH: + xWindow->setPosSize( 0, 0, nValue, aRect.Height, css::awt::PosSize::WIDTH ); + break; + case css::awt::PosSize::HEIGHT: + xWindow->setPosSize( 0, 0, aRect.Width, nValue, css::awt::PosSize::HEIGHT ); + break; + default: + break; } } sal_Int32 SAL_CALL VbaWindowBase::getHeight() throw (uno::RuntimeException) { - css::awt::Rectangle aRect = getPosSize(m_xModel); - return aRect.Height; + return getWindow()->getPosSize().Height; } void SAL_CALL VbaWindowBase::setHeight( sal_Int32 _height ) throw (uno::RuntimeException) { - setPosSize(m_xModel, _height, css::awt::PosSize::HEIGHT); + setPosSize( getWindow(), _height, css::awt::PosSize::HEIGHT ); } sal_Int32 SAL_CALL VbaWindowBase::getLeft() throw (uno::RuntimeException) { - css::awt::Rectangle aRect = getPosSize(m_xModel); - return aRect.X; + return getWindow()->getPosSize().X; } void SAL_CALL VbaWindowBase::setLeft( sal_Int32 _left ) throw (uno::RuntimeException) { - setPosSize(m_xModel, _left, css::awt::PosSize::X); + setPosSize( getWindow(), _left, css::awt::PosSize::X ); } + sal_Int32 SAL_CALL VbaWindowBase::getTop() throw (uno::RuntimeException) { - css::awt::Rectangle aRect = getPosSize(m_xModel); - return aRect.Y; + return getWindow()->getPosSize().Y; } void SAL_CALL VbaWindowBase::setTop( sal_Int32 _top ) throw (uno::RuntimeException) { - setPosSize(m_xModel, _top, css::awt::PosSize::Y); + setPosSize( getWindow(), _top, css::awt::PosSize::Y ); } + sal_Int32 SAL_CALL VbaWindowBase::getWidth() throw (uno::RuntimeException) { - css::awt::Rectangle aRect = getPosSize(m_xModel); - return aRect.Width; + return getWindow()->getPosSize().Width; } void SAL_CALL VbaWindowBase::setWidth( sal_Int32 _width ) throw (uno::RuntimeException) { - setPosSize(m_xModel, _width, css::awt::PosSize::WIDTH); + setPosSize( getWindow(), _width, css::awt::PosSize::WIDTH ); } rtl::OUString& @@ -175,3 +151,27 @@ VbaWindowBase::getServiceNames() } return aServiceNames; } + +uno::Reference< frame::XController > VbaWindowBase::getController() throw (css::uno::RuntimeException) +{ + return uno::Reference< frame::XController >( m_xController, uno::UNO_SET_THROW ); +} + +uno::Reference< awt::XWindow > VbaWindowBase::getWindow() throw (uno::RuntimeException) +{ + return uno::Reference< awt::XWindow >( m_xWindow, uno::UNO_SET_THROW ); +} + +uno::Reference< awt::XWindow2 > VbaWindowBase::getWindow2() throw (uno::RuntimeException) +{ + return uno::Reference< awt::XWindow2 >( getWindow(), uno::UNO_QUERY_THROW ); +} + +void VbaWindowBase::construct( const uno::Reference< frame::XController >& xController ) throw (uno::RuntimeException) +{ + if( !xController.is() ) throw uno::RuntimeException(); + uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW ); + uno::Reference< awt::XWindow > xWindow( xFrame->getContainerWindow(), uno::UNO_SET_THROW ); + m_xController = xController; + m_xWindow = xWindow; +} diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index fa5b3013a9fe..e8ad1bcaed64 100755 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -78,6 +78,7 @@ $(eval $(call gb_Library_add_linked_libs,vcl,\ cppu \ sal \ vos3 \ + $(gb_STDLIBS) \ )) ifneq ($(ENABLE_GRAPHITE),) diff --git a/vcl/Library_vclplug_gen.mk b/vcl/Library_vclplug_gen.mk index 9d0dea8b580f..52f4d7a362e9 100755 --- a/vcl/Library_vclplug_gen.mk +++ b/vcl/Library_vclplug_gen.mk @@ -60,6 +60,7 @@ $(eval $(call gb_Library_add_linked_libs,vclplug_gen,\ Xext \ SM \ ICE \ + $(gb_STDLIBS) \ )) $(eval $(call gb_Library_add_exception_objects,vclplug_gen,\ diff --git a/vcl/Library_vclplug_gtk.mk b/vcl/Library_vclplug_gtk.mk index 129ef1060272..feb63e06e794 100755 --- a/vcl/Library_vclplug_gtk.mk +++ b/vcl/Library_vclplug_gtk.mk @@ -61,7 +61,8 @@ endif $(eval $(call gb_Library_set_ldflags,vclplug_gtk,\ $$(LDFLAGS) \ - $$(GTK_LIBS)\ + $$(GTK_LIBS) \ + $$(GTHREAD_LIBS) \ )) $(eval $(call gb_Library_add_linked_libs,vclplug_gtk,\ @@ -88,6 +89,7 @@ $(eval $(call gb_Library_add_linked_libs,vclplug_gtk,\ Xext \ SM \ ICE \ + $(gb_STDLIBS) \ )) $(eval $(call gb_Library_add_exception_objects,vclplug_gtk,\ diff --git a/vcl/Library_vclplug_svp.mk b/vcl/Library_vclplug_svp.mk index 1289c6b53a83..3051c0ce863e 100755 --- a/vcl/Library_vclplug_svp.mk +++ b/vcl/Library_vclplug_svp.mk @@ -66,6 +66,7 @@ $(eval $(call gb_Library_add_linked_libs,vclplug_svp,\ Xext \ SM \ ICE \ + $(gb_STDLIBS) \ )) $(eval $(call gb_Library_add_exception_objects,vclplug_svp,\ diff --git a/xmlsecurity/inc/xmlsecurity/digitalsignaturesdialog.hxx b/xmlsecurity/inc/xmlsecurity/digitalsignaturesdialog.hxx index d40f2ebf4a12..1acc3733e2d3 100644 --- a/xmlsecurity/inc/xmlsecurity/digitalsignaturesdialog.hxx +++ b/xmlsecurity/inc/xmlsecurity/digitalsignaturesdialog.hxx @@ -132,8 +132,8 @@ public: sal_Bool bReadOnly, const ::rtl::OUString& sODFVersion, bool bHasDocumentSignature); ~DigitalSignaturesDialog(); - // Initialize the dialog and the security environment, returns sal_True on success - sal_Bool Init( const rtl::OUString& rTokenName ); + // Initialize the dialog and the security environment, returns TRUE on success + sal_Bool Init(); // Set the storage which should be signed or verified void SetStorage( const cssu::Reference < css::embed::XStorage >& rxStore ); diff --git a/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx b/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx index 4869b4728567..932c37f81252 100644 --- a/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx +++ b/xmlsecurity/inc/xmlsecurity/xmlsignaturehelper.hxx @@ -132,10 +132,9 @@ public: XMLSignatureHelper(const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& mrCtx ); ~XMLSignatureHelper(); - // Initialize the security context with given crypto token. - // Empty string means default crypto token. - // Returns true for success. - bool Init( const rtl::OUString& rTokenPath ); + // Initialize the security context with default crypto token. + // Returns true for success. + bool Init(); // Set UriBinding to create input streams to open files. // Default implementation is capable to open files from disk. diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index e8eddefb51cf..0c8250848efa 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -220,7 +220,7 @@ sal_Bool DocumentDigitalSignatures::ImplViewSignatures( sal_Bool bChanges = sal_False; DigitalSignaturesDialog aSignaturesDialog( NULL, mxCtx, eMode, bReadOnly, m_sODFVersion, m_bHasDocumentSignature); - bool bInit = aSignaturesDialog.Init( rtl::OUString() ); + bool bInit = aSignaturesDialog.Init(); DBG_ASSERT( bInit, "Error initializing security context!" ); if ( bInit ) { @@ -276,7 +276,7 @@ DocumentDigitalSignatures::ImplVerifySignatures( XMLSignatureHelper aSignatureHelper( mxCtx ); - bool bInit = aSignatureHelper.Init( rtl::OUString() ); + bool bInit = aSignatureHelper.Init(); DBG_ASSERT( bInit, "Error initializing security context!" ); @@ -379,7 +379,7 @@ void DocumentDigitalSignatures::manageTrustedSources( ) throw (RuntimeException Reference< dcss::xml::crypto::XSecurityEnvironment > xSecEnv; XMLSignatureHelper aSignatureHelper( mxCtx ); - if ( aSignatureHelper.Init( rtl::OUString() ) ) + if ( aSignatureHelper.Init() ) xSecEnv = aSignatureHelper.GetSecurityEnvironment(); MacroSecurity aDlg( NULL, mxCtx, xSecEnv ); @@ -391,7 +391,7 @@ void DocumentDigitalSignatures::showCertificate( { XMLSignatureHelper aSignatureHelper( mxCtx ); - bool bInit = aSignatureHelper.Init( rtl::OUString() ); + bool bInit = aSignatureHelper.Init(); DBG_ASSERT( bInit, "Error initializing security context!" ); diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index 15ac9b591c48..51f9924a61ed 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -266,9 +266,9 @@ DigitalSignaturesDialog::~DigitalSignaturesDialog() { } -sal_Bool DigitalSignaturesDialog::Init( const rtl::OUString& rTokenName ) +sal_Bool DigitalSignaturesDialog::Init() { - bool bInit = maSignatureHelper.Init( rTokenName ); + bool bInit = maSignatureHelper.Init(); DBG_ASSERT( bInit, "Error initializing security context!" ); diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx index dd3ae00f69c1..d2def9648476 100644 --- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx +++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx @@ -73,11 +73,9 @@ XMLSignatureHelper::XMLSignatureHelper( const uno::Reference< uno::XComponentCon XMLSignatureHelper::~XMLSignatureHelper() { - if ( mxSEInitializer.is() && mxSecurityContext.is() ) - mxSEInitializer->freeSecurityContext( mxSecurityContext ); } -bool XMLSignatureHelper::Init( const rtl::OUString& rTokenPath ) +bool XMLSignatureHelper::Init() { DBG_ASSERT( !mxSEInitializer.is(), "XMLSignatureHelper::Init - mxSEInitializer already set!" ); DBG_ASSERT( !mxSecurityContext.is(), "XMLSignatureHelper::Init - mxSecurityContext already set!" ); @@ -85,7 +83,7 @@ bool XMLSignatureHelper::Init( const rtl::OUString& rTokenPath ) ImplCreateSEInitializer(); if ( mxSEInitializer.is() ) - mxSecurityContext = mxSEInitializer->createSecurityContext( rTokenPath ); + mxSecurityContext = mxSEInitializer->createSecurityContext( ::rtl::OUString() ); return mxSecurityContext.is(); } @@ -420,25 +418,6 @@ sal_Int32 XMLSignatureHelper::GetSecurityEnvironmentNumber() return (mxSecurityContext.is()?(mxSecurityContext->getSecurityEnvironmentNumber()): 0); } - -/* -void XMLSignatureHelper::createSecurityContext( rtl::OUString tokenPath ) -{ - if ( !mxSEInitializer.is() ) - ImplCreateSEInitializer(); - - mxSecurityContext = mxSEInitializer->createSecurityContext(tokenPath); -} - -void XMLSignatureHelper::freeSecurityContext() -{ - if ( !mxSEInitializer.is() ) - ImplCreateSEInitializer(); - - mxSEInitializer->freeSecurityContext( mxSecurityContext ); -} -*/ - IMPL_LINK( XMLSignatureHelper, SignatureCreationResultListener, XMLSignatureCreationResult*, pResult ) { maCreationResults.insert( maCreationResults.begin() + maCreationResults.size(), *pResult ); diff --git a/xmlsecurity/source/helper/xmlsignaturehelper2.cxx b/xmlsecurity/source/helper/xmlsignaturehelper2.cxx index c701adefd445..83988e872b49 100644 --- a/xmlsecurity/source/helper/xmlsignaturehelper2.cxx +++ b/xmlsecurity/source/helper/xmlsignaturehelper2.cxx @@ -31,6 +31,7 @@ #include <xmlsecurity/xmlsignaturehelper.hxx> #include <xmlsignaturehelper2.hxx> +#include <tools/solar.h> #include <unotools/streamhelper.hxx> #include <com/sun/star/embed/XStorage.hpp> diff --git a/xmlsecurity/source/xmlsec/makefile.mk b/xmlsecurity/source/xmlsec/makefile.mk index 44b668b84765..36b30f4f25a3 100644 --- a/xmlsecurity/source/xmlsec/makefile.mk +++ b/xmlsecurity/source/xmlsec/makefile.mk @@ -49,11 +49,11 @@ CFLAGS+=-DSYSTEM_LIBXML $(LIBXML_CFLAGS) .ENDIF .IF "$(CRYPTO_ENGINE)" == "mscrypto" -CDEFS += -DXMLSEC_CRYPTO_MSCRYPTO -DXMLSEC_NO_XSLT -.ELSE -CDEFS += -DXMLSEC_CRYPTO_NSS -DXMLSEC_NO_XSLT +CDEFS += -DXMLSEC_CRYPTO_MSCRYPTO .ENDIF +CDEFS += -DXMLSEC_NO_XSLT + # --- Files -------------------------------------------------------- SLOFILES = \ $(SLO)$/biginteger.obj \ diff --git a/xmlsecurity/source/xmlsec/mscrypt/xsec_mscrypt.cxx b/xmlsecurity/source/xmlsec/mscrypt/xsec_mscrypt.cxx index 87b7bf035cc5..8044cd403c83 100644 --- a/xmlsecurity/source/xmlsec/mscrypt/xsec_mscrypt.cxx +++ b/xmlsecurity/source/xmlsec/mscrypt/xsec_mscrypt.cxx @@ -51,86 +51,6 @@ using namespace ::com::sun::star::registry; extern "C" { -sal_Bool SAL_CALL mscrypt_component_writeInfo( void* /*pServiceManager*/ , void* pRegistryKey ) -{ - sal_Bool result = sal_False; - sal_Int32 i ; - OUString sKeyName ; - Reference< XRegistryKey > xNewKey ; - Sequence< OUString > seqServices ; - Reference< XRegistryKey > xKey( reinterpret_cast< XRegistryKey* >( pRegistryKey ) ) ; - - if( xKey.is() ) { - // try { - // XMLSignature_MSCryptImpl - sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ; - sKeyName += XMLSignature_MSCryptImpl::impl_getImplementationName() ; - sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ; - - xNewKey = xKey->createKey( sKeyName ) ; - if( xNewKey.is() ) { - seqServices = XMLSignature_MSCryptImpl::impl_getSupportedServiceNames() ; - for( i = seqServices.getLength() ; i -- ; ) - xNewKey->createKey( seqServices.getConstArray()[i] ) ; - } - - // XMLEncryption_MSCryptImpl - sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ; - sKeyName += XMLEncryption_MSCryptImpl::impl_getImplementationName() ; - sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ; - - xNewKey = xKey->createKey( sKeyName ) ; - if( xNewKey.is() ) { - seqServices = XMLEncryption_MSCryptImpl::impl_getSupportedServiceNames() ; - for( i = seqServices.getLength() ; i -- ; ) - xNewKey->createKey( seqServices.getConstArray()[i] ) ; - } - - // XMLSecurityContext_MSCryptImpl - sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ; - sKeyName += XMLSecurityContext_MSCryptImpl::impl_getImplementationName() ; - sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ; - - xNewKey = xKey->createKey( sKeyName ) ; - if( xNewKey.is() ) { - seqServices = XMLSecurityContext_MSCryptImpl::impl_getSupportedServiceNames() ; - for( i = seqServices.getLength() ; i -- ; ) - xNewKey->createKey( seqServices.getConstArray()[i] ) ; - } - - // SecurityEnvironment_MSCryptImpl - sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ; - sKeyName += SecurityEnvironment_MSCryptImpl::impl_getImplementationName() ; - sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ; - - xNewKey = xKey->createKey( sKeyName ) ; - if( xNewKey.is() ) { - seqServices = SecurityEnvironment_MSCryptImpl::impl_getSupportedServiceNames() ; - for( i = seqServices.getLength() ; i -- ; ) - xNewKey->createKey( seqServices.getConstArray()[i] ) ; - } - - // SEInitializer_MSCryptImpl - sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ; - sKeyName += SEInitializer_MSCryptImpl_getImplementationName() ; - sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ; - - xNewKey = xKey->createKey( sKeyName ) ; - if( xNewKey.is() ) { - seqServices = SEInitializer_MSCryptImpl_getSupportedServiceNames() ; - for( i = seqServices.getLength() ; i -- ; ) - xNewKey->createKey( seqServices.getConstArray()[i] ) ; - } - - return sal_True; - //} catch( InvalidRegistryException & ) { - // //we should not ignore exceptions - // return sal_False ; - //} - } - return result; -} - void* SAL_CALL mscrypt_component_getFactory( const sal_Char* pImplName , void* pServiceManager , void* /*pRegistryKey*/ ) { void* pRet = 0; diff --git a/xmlsecurity/source/xmlsec/nss/ciphercontext.cxx b/xmlsecurity/source/xmlsec/nss/ciphercontext.cxx new file mode 100644 index 000000000000..93a17e3514b7 --- /dev/null +++ b/xmlsecurity/source/xmlsec/nss/ciphercontext.cxx @@ -0,0 +1,276 @@ + /************************************************************************* + * + * 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. + * + ************************************************************************/ + +#include <precompiled_xmlsecurity.hxx> + +#include <osl/time.h> +#include <rtl/random.h> +#include <rtl/ref.hxx> + +#include "ciphercontext.hxx" + +using namespace ::com::sun::star; + +uno::Reference< xml::crypto::XCipherContext > OCipherContext::Create( CK_MECHANISM_TYPE nNSSCipherID, const uno::Sequence< ::sal_Int8 >& aKey, const uno::Sequence< ::sal_Int8 >& aInitializationVector, bool bEncryption, bool bW3CPadding ) +{ + ::rtl::Reference< OCipherContext > xResult = new OCipherContext; + + xResult->m_pSlot = PK11_GetBestSlot( nNSSCipherID, NULL ); + if ( xResult->m_pSlot ) + { + SECItem aKeyItem = { siBuffer, const_cast< unsigned char* >( reinterpret_cast< const unsigned char* >( aKey.getConstArray() ) ), aKey.getLength() }; + xResult->m_pSymKey = PK11_ImportSymKey( xResult->m_pSlot, nNSSCipherID, PK11_OriginDerive, bEncryption ? CKA_ENCRYPT : CKA_DECRYPT, &aKeyItem, NULL ); + if ( xResult->m_pSymKey ) + { + SECItem aIVItem = { siBuffer, const_cast< unsigned char* >( reinterpret_cast< const unsigned char* >( aInitializationVector.getConstArray() ) ), aInitializationVector.getLength() }; + xResult->m_pSecParam = PK11_ParamFromIV( nNSSCipherID, &aIVItem ); + if ( xResult->m_pSecParam ) + { + xResult->m_pContext = PK11_CreateContextBySymKey( nNSSCipherID, bEncryption ? CKA_ENCRYPT : CKA_DECRYPT, xResult->m_pSymKey, xResult->m_pSecParam); + if ( xResult->m_pContext ) + { + xResult->m_bEncryption = bEncryption; + xResult->m_bW3CPadding = bW3CPadding; + xResult->m_bPadding = bW3CPadding || ( PK11_GetPadMechanism( nNSSCipherID ) == nNSSCipherID ); + xResult->m_nBlockSize = PK11_GetBlockSize( nNSSCipherID, xResult->m_pSecParam ); + if ( xResult->m_nBlockSize <= SAL_MAX_INT8 ) + return xResult.get(); + } + } + } + } + + return uno::Reference< xml::crypto::XCipherContext >(); +} + +void OCipherContext::Dispose() +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_pContext ) + { + PK11_DestroyContext( m_pContext, PR_TRUE ); + m_pContext = NULL; + } + + if ( m_pSecParam ) + { + SECITEM_FreeItem( m_pSecParam, PR_TRUE ); + m_pSecParam = NULL; + } + + if ( m_pSymKey ) + { + PK11_FreeSymKey( m_pSymKey ); + m_pSymKey = NULL; + } + + if ( m_pSlot ) + { + PK11_FreeSlot( m_pSlot ); + m_pSlot = NULL; + } + + m_bDisposed = true; +} + +uno::Sequence< ::sal_Int8 > SAL_CALL OCipherContext::convertWithCipherContext( const uno::Sequence< ::sal_Int8 >& aData ) + throw ( lang::IllegalArgumentException, lang::DisposedException, uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bBroken ) + throw uno::RuntimeException(); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + uno::Sequence< sal_Int8 > aToConvert; + if ( aData.getLength() ) + { + sal_Int32 nOldLastBlockLen = m_aLastBlock.getLength(); + OSL_ENSURE( nOldLastBlockLen <= m_nBlockSize, "Unexpected last block size!" ); + + sal_Int32 nAvailableData = nOldLastBlockLen + aData.getLength(); + sal_Int32 nToConvertLen = nAvailableData; + if ( m_bEncryption || !m_bW3CPadding ) + { + if ( nAvailableData % m_nBlockSize == 0 ) + nToConvertLen = nAvailableData; + else if ( nAvailableData < m_nBlockSize ) + nToConvertLen = 0; + else + nToConvertLen = nAvailableData - nAvailableData % m_nBlockSize; + } + else + { + // decryption with W3C padding needs at least one block for finalizing + if ( nAvailableData < m_nBlockSize * 2 ) + nToConvertLen = 0; + else + nToConvertLen = nAvailableData - nAvailableData % m_nBlockSize - m_nBlockSize; + } + + aToConvert.realloc( nToConvertLen ); + if ( nToConvertLen == 0 ) + { + m_aLastBlock.realloc( nOldLastBlockLen + aData.getLength() ); + rtl_copyMemory( m_aLastBlock.getArray() + nOldLastBlockLen, aData.getConstArray(), aData.getLength() ); + // aToConvert stays empty + } + else if ( nToConvertLen < nOldLastBlockLen ) + { + rtl_copyMemory( aToConvert.getArray(), m_aLastBlock.getConstArray(), nToConvertLen ); + rtl_copyMemory( m_aLastBlock.getArray(), m_aLastBlock.getConstArray() + nToConvertLen, nOldLastBlockLen - nToConvertLen ); + m_aLastBlock.realloc( nOldLastBlockLen - nToConvertLen + aData.getLength() ); + rtl_copyMemory( m_aLastBlock.getArray() + nOldLastBlockLen - nToConvertLen, aData.getConstArray(), aData.getLength() ); + } + else + { + rtl_copyMemory( aToConvert.getArray(), m_aLastBlock.getConstArray(), nOldLastBlockLen ); + if ( nToConvertLen > nOldLastBlockLen ) + rtl_copyMemory( aToConvert.getArray() + nOldLastBlockLen, aData.getConstArray(), nToConvertLen - nOldLastBlockLen ); + m_aLastBlock.realloc( nAvailableData - nToConvertLen ); + rtl_copyMemory( m_aLastBlock.getArray(), aData.getConstArray() + nToConvertLen - nOldLastBlockLen, nAvailableData - nToConvertLen ); + } + } + + uno::Sequence< sal_Int8 > aResult; + OSL_ENSURE( aToConvert.getLength() % m_nBlockSize == 0, "Unexpected size of the data to encrypt!" ); + if ( aToConvert.getLength() ) + { + int nResultLen = 0; + aResult.realloc( aToConvert.getLength() + m_nBlockSize ); + if ( PK11_CipherOp( m_pContext, reinterpret_cast< unsigned char* >( aResult.getArray() ), &nResultLen, aResult.getLength(), const_cast< unsigned char* >( reinterpret_cast< const unsigned char* >( aToConvert.getConstArray() ) ), aToConvert.getLength() ) != SECSuccess ) + { + m_bBroken = true; + Dispose(); + throw uno::RuntimeException(); + } + + m_nConverted += aToConvert.getLength(); + aResult.realloc( nResultLen ); + } + + return aResult; +} + +uno::Sequence< ::sal_Int8 > SAL_CALL OCipherContext::finalizeCipherContextAndDispose() + throw (lang::DisposedException, uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bBroken ) + throw uno::RuntimeException(); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + OSL_ENSURE( m_nBlockSize <= SAL_MAX_INT8, "Unexpected block size!" ); + OSL_ENSURE( m_nConverted % m_nBlockSize == 0, "Unexpected amount of bytes is already converted!" ); + sal_Int32 nSizeForPadding = ( m_nConverted + m_aLastBlock.getLength() ) % m_nBlockSize; + + // if it is decryption, the amount of data should be rounded to the block size even in case of padding + if ( ( !m_bPadding || !m_bEncryption ) && nSizeForPadding ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "The data should contain complete blocks only." ) ), uno::Reference< uno::XInterface >() ); + + if ( m_bW3CPadding && m_bEncryption ) + { + // in this case the last block should be smaller than standtard block + // it will be increased with the padding + OSL_ENSURE( m_aLastBlock.getLength() < m_nBlockSize, "Unexpected size of cashed incomplete last block!" ); + + // W3CPadding handling for encryption + sal_Int32 nPaddingSize = m_nBlockSize - nSizeForPadding; + sal_Int32 nOldLastBlockLen = m_aLastBlock.getLength(); + m_aLastBlock.realloc( nOldLastBlockLen + nPaddingSize ); + + if ( nPaddingSize > 1 ) + { + TimeValue aTime; + osl_getSystemTime( &aTime ); + rtlRandomPool aRandomPool = rtl_random_createPool(); + rtl_random_addBytes( aRandomPool, &aTime, 8 ); + rtl_random_getBytes( aRandomPool, m_aLastBlock.getArray() + nOldLastBlockLen, nPaddingSize - 1 ); + rtl_random_destroyPool ( aRandomPool ); + } + m_aLastBlock[m_aLastBlock.getLength() - 1] = static_cast< sal_Int8 >( nPaddingSize ); + } + + // finally should the last block be smaller than two standard blocks + OSL_ENSURE( m_aLastBlock.getLength() < m_nBlockSize * 2 , "Unexpected size of cashed incomplete last block!" ); + + uno::Sequence< sal_Int8 > aResult; + if ( m_aLastBlock.getLength() ) + { + int nPrefResLen = 0; + aResult.realloc( m_aLastBlock.getLength() + m_nBlockSize ); + if ( PK11_CipherOp( m_pContext, reinterpret_cast< unsigned char* >( aResult.getArray() ), &nPrefResLen, aResult.getLength(), const_cast< unsigned char* >( reinterpret_cast< const unsigned char* >( m_aLastBlock.getConstArray() ) ), m_aLastBlock.getLength() ) != SECSuccess ) + { + m_bBroken = true; + Dispose(); + throw uno::RuntimeException(); + } + + aResult.realloc( nPrefResLen ); + m_aLastBlock.realloc( 0 ); + } + + sal_Int32 nPrefixLen = aResult.getLength(); + aResult.realloc( nPrefixLen + m_nBlockSize * 2 ); + unsigned nFinalLen = 0; + if ( PK11_DigestFinal( m_pContext, reinterpret_cast< unsigned char* >( aResult.getArray() + nPrefixLen ), &nFinalLen, aResult.getLength() - nPrefixLen ) != SECSuccess ) + { + m_bBroken = true; + Dispose(); + throw uno::RuntimeException(); + } + + aResult.realloc( nPrefixLen + nFinalLen ); + + if ( m_bW3CPadding && !m_bEncryption ) + { + // W3CPadding handling for decryption + // aResult should have anough data, since we let m_aLastBlock be big enough in case of decryption + OSL_ENSURE( aResult.getLength() >= m_nBlockSize, "Not enough data to handle the padding!" ); + + sal_Int8 nBytesToRemove = aResult[aResult.getLength() - 1]; + if ( nBytesToRemove <= 0 || nBytesToRemove > aResult.getLength() ) + { + m_bBroken = true; + Dispose(); + throw uno::RuntimeException(); + } + + aResult.realloc( aResult.getLength() - nBytesToRemove ); + } + + Dispose(); + + return aResult; +} + diff --git a/xmlsecurity/source/xmlsec/nss/ciphercontext.hxx b/xmlsecurity/source/xmlsec/nss/ciphercontext.hxx new file mode 100644 index 000000000000..1574a6238bd4 --- /dev/null +++ b/xmlsecurity/source/xmlsec/nss/ciphercontext.hxx @@ -0,0 +1,89 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#ifndef _CIPHERCONTEXT_HXX +#define _CIPHERCONTEXT_HXX + +#include <com/sun/star/xml/crypto/XCipherContext.hpp> + +#include <cppuhelper/implbase1.hxx> +#include <osl/mutex.hxx> +#include <pk11pub.h> + +class OCipherContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XCipherContext > +{ +private: + ::osl::Mutex m_aMutex; + + PK11SlotInfo* m_pSlot; + PK11SymKey* m_pSymKey; + SECItem* m_pSecParam; + PK11Context* m_pContext; + + sal_Int32 m_nBlockSize; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aLastBlock; + + bool m_bEncryption; + bool m_bPadding; + bool m_bW3CPadding; + sal_Int64 m_nConverted; + + bool m_bDisposed; + bool m_bBroken; + + void Dispose(); + + OCipherContext() + : m_pSlot( NULL ) + , m_pSymKey( NULL ) + , m_pSecParam( NULL ) + , m_pContext( NULL ) + , m_nBlockSize( 0 ) + , m_bEncryption( false ) + , m_bPadding( false ) + , m_bW3CPadding( false ) + , m_nConverted( 0 ) + , m_bDisposed( false ) + , m_bBroken( false ) + {} + +public: + + virtual ~OCipherContext() + { + Dispose(); + } + + static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > Create( CK_MECHANISM_TYPE nNSSCipherID, const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aKey, const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aInitializationVector, bool bEncryption, bool bW3CPadding ); + + // XCipherContext + virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL convertWithCipherContext( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeCipherContextAndDispose( ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); +}; + +#endif + diff --git a/xmlsecurity/source/xmlsec/nss/digestcontext.cxx b/xmlsecurity/source/xmlsec/nss/digestcontext.cxx new file mode 100644 index 000000000000..4b3a0d094bd9 --- /dev/null +++ b/xmlsecurity/source/xmlsec/nss/digestcontext.cxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#include <precompiled_xmlsecurity.hxx> + +#include <pk11pub.h> +#include "digestcontext.hxx" + +using namespace ::com::sun::star; + +ODigestContext::~ODigestContext() +{ + if ( m_pContext ) + { + PK11_DestroyContext( m_pContext, PR_TRUE ); + m_pContext = NULL; + } +} + +void SAL_CALL ODigestContext::updateDigest( const uno::Sequence< ::sal_Int8 >& aData ) + throw (lang::DisposedException, uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bBroken ) + throw uno::RuntimeException(); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_b1KData || m_nDigested < 1024 ) + { + uno::Sequence< sal_Int8 > aToDigest = aData; + if ( m_b1KData && m_nDigested + aData.getLength() > 1024 ) + aToDigest.realloc( 1024 - m_nDigested ); + + if ( PK11_DigestOp( m_pContext, reinterpret_cast< const unsigned char* >( aToDigest.getConstArray() ), aToDigest.getLength() ) != SECSuccess ) + { + PK11_DestroyContext( m_pContext, PR_TRUE ); + m_pContext = NULL; + m_bBroken = true; + throw uno::RuntimeException(); + } + + m_nDigested += aToDigest.getLength(); + } +} + +uno::Sequence< ::sal_Int8 > SAL_CALL ODigestContext::finalizeDigestAndDispose() + throw (lang::DisposedException, uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bBroken ) + throw uno::RuntimeException(); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + uno::Sequence< sal_Int8 > aResult( m_nDigestLength ); + unsigned int nResultLen = 0; + if ( PK11_DigestFinal( m_pContext, reinterpret_cast< unsigned char* >( aResult.getArray() ), &nResultLen, aResult.getLength() ) != SECSuccess ) + { + PK11_DestroyContext( m_pContext, PR_TRUE ); + m_pContext = NULL; + m_bBroken = true; + throw uno::RuntimeException(); + } + + PK11_DestroyContext( m_pContext, PR_TRUE ); + m_pContext = NULL; + m_bDisposed = true; + + aResult.realloc( nResultLen ); + return aResult; +} + diff --git a/xmlsecurity/source/xmlsec/nss/digestcontext.hxx b/xmlsecurity/source/xmlsec/nss/digestcontext.hxx new file mode 100644 index 000000000000..8f9ef475a485 --- /dev/null +++ b/xmlsecurity/source/xmlsec/nss/digestcontext.hxx @@ -0,0 +1,68 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#ifndef _DIGESTCONTEXT_HXX +#define _DIGESTCONTEXT_HXX + +#include <com/sun/star/xml/crypto/XDigestContext.hpp> + +#include <cppuhelper/implbase1.hxx> +#include <osl/mutex.hxx> + +class ODigestContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XDigestContext > +{ +private: + ::osl::Mutex m_aMutex; + + PK11Context* m_pContext; + sal_Int32 m_nDigestLength; + bool m_b1KData; + sal_Int32 m_nDigested; + + bool m_bDisposed; + bool m_bBroken; + +public: + ODigestContext( PK11Context* pContext, sal_Int32 nDigestLength, bool b1KData ) + : m_pContext( pContext ) + , m_nDigestLength( nDigestLength ) + , m_b1KData( b1KData ) + , m_nDigested( 0 ) + , m_bDisposed( false ) + , m_bBroken( false ) + {} + + virtual ~ODigestContext(); + + + // XDigestContext + virtual void SAL_CALL updateDigest( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeDigestAndDispose() throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); +}; + +#endif + diff --git a/xmlsecurity/source/xmlsec/nss/makefile.mk b/xmlsecurity/source/xmlsec/nss/makefile.mk index f4ba0bde768e..5e968a334ed5 100644 --- a/xmlsecurity/source/xmlsec/nss/makefile.mk +++ b/xmlsecurity/source/xmlsec/nss/makefile.mk @@ -41,12 +41,6 @@ ENABLE_EXCEPTIONS = TRUE CFLAGS+=-DSYSTEM_LIBXML $(LIBXML_CFLAGS) .ENDIF -.IF "$(CRYPTO_ENGINE)" != "nss" -LIBTARGET=NO -.ENDIF - -.IF "$(CRYPTO_ENGINE)" == "nss" - .IF "$(WITH_MOZILLA)" == "NO" || "$(ENABLE_NSS_MODULE)"!="YES" .IF "$(SYSTEM_MOZILLA)" != "YES" @all: @@ -108,7 +102,11 @@ $(MOZ_INC)$/profile \ #.ENDIF .ENDIF -CDEFS += -DXMLSEC_CRYPTO_NSS -DXMLSEC_NO_XSLT +.IF "$(CRYPTO_ENGINE)" == "nss" +CDEFS += -DXMLSEC_CRYPTO_NSS +.ENDIF + +CDEFS += -DXMLSEC_NO_XSLT # --- Files -------------------------------------------------------- @@ -124,18 +122,22 @@ SOLARINC += -I$(NSS_INC) .ENDIF SLOFILES = \ + $(SLO)$/nssinitializer.obj \ + $(SLO)$/digestcontext.obj \ + $(SLO)$/ciphercontext.obj \ + $(SLO)$/xsec_nss.obj + +.IF "$(CRYPTO_ENGINE)" == "nss" +SLOFILES += \ $(SLO)$/securityenvironment_nssimpl.obj \ + $(SLO)$/seinitializer_nssimpl.obj \ $(SLO)$/xmlencryption_nssimpl.obj \ $(SLO)$/xmlsecuritycontext_nssimpl.obj \ $(SLO)$/xmlsignature_nssimpl.obj \ $(SLO)$/x509certificate_nssimpl.obj \ - $(SLO)$/seinitializer_nssimpl.obj \ - $(SLO)$/xsec_nss.obj \ $(SLO)$/sanextension_nssimpl.obj \ $(SLO)$/secerror.obj - - .ENDIF # --- Targets ------------------------------------------------------ diff --git a/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx new file mode 100644 index 000000000000..ded32952d410 --- /dev/null +++ b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx @@ -0,0 +1,521 @@ +/************************************************************************* + * + * 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_xmlsecurity.hxx" + +/* + * Turn off DEBUG Assertions + */ +#ifdef _DEBUG + #define _DEBUG_WAS_DEFINED _DEBUG + #undef _DEBUG +#else + #undef _DEBUG_WAS_DEFINED +#endif + +/* + * and turn off the additional virtual methods which are part of some interfaces when compiled + * with debug + */ +#ifdef DEBUG + #define DEBUG_WAS_DEFINED DEBUG + #undef DEBUG +#else + #undef DEBUG_WAS_DEFINED +#endif + + +#include <com/sun/star/mozilla/XMozillaBootstrap.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> + +#include <sal/types.h> +#include <rtl/instance.hxx> +#include <rtl/bootstrap.hxx> +#include <rtl/string.hxx> +#include <rtl/strbuf.hxx> +#include <osl/file.hxx> +#include <osl/thread.h> +#include <tools/debug.hxx> +#include <rtl/logfile.hxx> + +#include "seinitializer_nssimpl.hxx" +#include "../diagnose.hxx" + +#include "securityenvironment_nssimpl.hxx" +#include "digestcontext.hxx" +#include "ciphercontext.hxx" + +#include <nspr.h> +#include <cert.h> +#include <nss.h> +#include <pk11pub.h> +#include <secmod.h> +#include <nssckbi.h> + + +namespace css = ::com::sun::star; +namespace cssu = css::uno; +namespace cssl = css::lang; +namespace cssxc = css::xml::crypto; + +using namespace xmlsecurity; +using namespace com::sun::star; +using ::rtl::OUString; +using ::rtl::OString; + +#define IMPLEMENTATION_NAME "com.sun.star.xml.security.bridge.xmlsec.NSSInitializer_NssImpl" + +#define ROOT_CERTS "Root Certs for OpenOffice.org" + +extern "C" void nsscrypto_finalize(); + + +namespace +{ + +bool nsscrypto_initialize( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF, bool & out_nss_init ); + +struct InitNSSInitialize +{ + css::uno::Reference< css::lang::XMultiServiceFactory > mxMSF; + + InitNSSInitialize( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF ) + : mxMSF( xMSF ) + { + } + + bool * operator()() + { + static bool bInitialized = false; + bool bNSSInit = false; + bInitialized = nsscrypto_initialize( mxMSF, bNSSInit ); + if (bNSSInit) + atexit(nsscrypto_finalize ); + return & bInitialized; + } +}; + +struct GetNSSInitStaticMutex +{ + ::osl::Mutex* operator()() + { + static ::osl::Mutex aNSSInitMutex; + return &aNSSInitMutex; + } +}; + +void deleteRootsModule() +{ + SECMODModule *RootsModule = 0; + SECMODModuleList *list = SECMOD_GetDefaultModuleList(); + SECMODListLock *lock = SECMOD_GetDefaultModuleListLock(); + SECMOD_GetReadLock(lock); + + while (!RootsModule && list) + { + SECMODModule *module = list->module; + + for (int i=0; i < module->slotCount; i++) + { + PK11SlotInfo *slot = module->slots[i]; + if (PK11_IsPresent(slot)) + { + if (PK11_HasRootCerts(slot)) + { + xmlsec_trace("The root certifificates module \"%s" + "\" is already loaded: \n%s", + module->commonName, module->dllName); + + RootsModule = SECMOD_ReferenceModule(module); + break; + } + } + } + list = list->next; + } + SECMOD_ReleaseReadLock(lock); + + if (RootsModule) + { + PRInt32 modType; + if (SECSuccess == SECMOD_DeleteModule(RootsModule->commonName, &modType)) + { + xmlsec_trace("Deleted module \"%s\".", RootsModule->commonName); + } + else + { + xmlsec_trace("Failed to delete \"%s\" : \n%s", + RootsModule->commonName, RootsModule->dllName); + } + SECMOD_DestroyModule(RootsModule); + RootsModule = 0; + } +} + +::rtl::OString getMozillaCurrentProfile( const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF ) +{ + ::rtl::OString sResult; + // first, try to get the profile from "MOZILLA_CERTIFICATE_FOLDER" + char* pEnv = getenv( "MOZILLA_CERTIFICATE_FOLDER" ); + if ( pEnv ) + { + sResult = ::rtl::OString( pEnv ); + RTL_LOGFILE_PRODUCT_TRACE1( "XMLSEC: Using env MOZILLA_CERTIFICATE_FOLDER: %s", sResult.getStr() ); + } + else + { + mozilla::MozillaProductType productTypes[4] = { + mozilla::MozillaProductType_Thunderbird, + mozilla::MozillaProductType_Mozilla, + mozilla::MozillaProductType_Firefox, + mozilla::MozillaProductType_Default }; + int nProduct = 4; + + uno::Reference<uno::XInterface> xInstance = rxMSF->createInstance( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap")) ); + OSL_ENSURE( xInstance.is(), "failed to create instance" ); + + uno::Reference<mozilla::XMozillaBootstrap> xMozillaBootstrap + = uno::Reference<mozilla::XMozillaBootstrap>(xInstance,uno::UNO_QUERY); + OSL_ENSURE( xMozillaBootstrap.is(), "failed to create instance" ); + + if (xMozillaBootstrap.is()) + { + for (int i=0; i<nProduct; i++) + { + ::rtl::OUString profile = xMozillaBootstrap->getDefaultProfile(productTypes[i]); + + if (profile != NULL && profile.getLength()>0) + { + ::rtl::OUString sProfilePath = xMozillaBootstrap->getProfilePath( productTypes[i], profile ); + sResult = ::rtl::OUStringToOString( sProfilePath, osl_getThreadTextEncoding() ); + RTL_LOGFILE_PRODUCT_TRACE1( "XMLSEC: Using Mozilla Profile: %s", sResult.getStr() ); + } + } + } + + RTL_LOGFILE_PRODUCT_TRACE( "XMLSEC: No Mozilla Profile found!" ); + } + + return sResult; +} + +//Older versions of Firefox (FF), for example FF2, and Thunderbird (TB) 2 write +//the roots certificate module (libnssckbi.so), which they use, into the +//profile. This module will then already be loaded during NSS_Init (and the +//other init functions). This fails in two cases. First, FF3 was used to create +//the profile, or possibly used that profile before, and second the profile was +//used on a different platform. +// +//Then one needs to add the roots module oneself. This should be done with +//SECMOD_LoadUserModule rather then SECMOD_AddNewModule. The latter would write +//the location of the roots module to the profile, which makes FF2 and TB2 use +//it instead of there own module. +// +//When using SYSTEM_MOZILLA then the libnss3.so lib is typically found in +///usr/lib. This folder may, however, NOT contain the roots certificate +//module. That is, just providing the library name in SECMOD_LoadUserModule or +//SECMOD_AddNewModule will FAIL to load the mozilla unless the LD_LIBRARY_PATH +//contains an FF or TB installation. +//ATTENTION: DO NOT call this function directly instead use initNSS +//return true - whole initialization was successful +//param out_nss_init = true: at least the NSS initialization (NSS_InitReadWrite +//was successful and therefor NSS_Shutdown should be called when terminating. +bool nsscrypto_initialize( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF, bool & out_nss_init ) +{ + bool return_value = true; + + // this method must be called only once, no need for additional lock + rtl::OString sCertDir; + + (void) xMSF; +#ifdef XMLSEC_CRYPTO_NSS + if ( xMSF.is() ) + sCertDir = getMozillaCurrentProfile( xMSF ); +#endif + xmlsec_trace( "Using profile: %s", sCertDir.getStr() ); + + PR_Init( PR_USER_THREAD, PR_PRIORITY_NORMAL, 1 ) ; + + // there might be no profile + if ( sCertDir.getLength() > 0 ) + { + if( NSS_InitReadWrite( sCertDir.getStr() ) != SECSuccess ) + { + xmlsec_trace("Initializing NSS with profile failed."); + char * error = NULL; + + PR_GetErrorText(error); + if (error) + xmlsec_trace("%s",error); + return false ; + } + } + else + { + xmlsec_trace("Initializing NSS without profile."); + if ( NSS_NoDB_Init(NULL) != SECSuccess ) + { + xmlsec_trace("Initializing NSS without profile failed."); + char * error = NULL; + PR_GetErrorText(error); + if (error) + xmlsec_trace("%s",error); + return false ; + } + } + out_nss_init = true; + +#ifdef XMLSEC_CRYPTO_NSS +#if defined SYSTEM_MOZILLA + if (!SECMOD_HasRootCerts()) + { +#endif + deleteRootsModule(); + +#if defined SYSTEM_MOZILLA + OUString rootModule(RTL_CONSTASCII_USTRINGPARAM("libnssckbi"SAL_DLLEXTENSION)); +#else + OUString rootModule(RTL_CONSTASCII_USTRINGPARAM("${OOO_BASE_DIR}/program/libnssckbi"SAL_DLLEXTENSION)); +#endif + ::rtl::Bootstrap::expandMacros(rootModule); + + OUString rootModulePath; + if (::osl::File::E_None == ::osl::File::getSystemPathFromFileURL(rootModule, rootModulePath)) + { + ::rtl::OString ospath = ::rtl::OUStringToOString(rootModulePath, osl_getThreadTextEncoding()); + ::rtl::OStringBuffer pkcs11moduleSpec; + pkcs11moduleSpec.append("name=\""); + pkcs11moduleSpec.append(ROOT_CERTS); + pkcs11moduleSpec.append("\" library=\""); + pkcs11moduleSpec.append(ospath.getStr()); + pkcs11moduleSpec.append("\""); + + SECMODModule * RootsModule = + SECMOD_LoadUserModule( + const_cast<char*>(pkcs11moduleSpec.makeStringAndClear().getStr()), + 0, // no parent + PR_FALSE); // do not recurse + + if (RootsModule) + { + + bool found = RootsModule->loaded; + + SECMOD_DestroyModule(RootsModule); + RootsModule = 0; + if (found) + xmlsec_trace("Added new root certificate module " + "\""ROOT_CERTS"\" contained in \n%s", ospath.getStr()); + else + { + xmlsec_trace("FAILED to load the new root certificate module " + "\""ROOT_CERTS"\" contained in \n%s", ospath.getStr()); + return_value = false; + } + } + else + { + xmlsec_trace("FAILED to add new root certifice module: " + "\""ROOT_CERTS"\" contained in \n%s", ospath.getStr()); + return_value = false; + + } + } + else + { + xmlsec_trace("Adding new root certificate module failed."); + return_value = false; + } +#if SYSTEM_MOZILLA + } +#endif +#endif + + return return_value; +} + + +// must be extern "C" because we pass the function pointer to atexit +extern "C" void nsscrypto_finalize() +{ + SECMODModule *RootsModule = SECMOD_FindModule(ROOT_CERTS); + + if (RootsModule) + { + + if (SECSuccess == SECMOD_UnloadUserModule(RootsModule)) + { + xmlsec_trace("Unloaded module \""ROOT_CERTS"\"."); + } + else + { + xmlsec_trace("Failed unloadeding module \""ROOT_CERTS"\"."); + } + SECMOD_DestroyModule(RootsModule); + } + else + { + xmlsec_trace("Unloading module \""ROOT_CERTS + "\" failed because it was not found."); + } + PK11_LogoutAll(); + NSS_Shutdown(); +} +} // namespace + +ONSSInitializer::ONSSInitializer( + const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF) + :mxMSF( rxMSF ) +{ +} + +ONSSInitializer::~ONSSInitializer() +{ +} + +bool ONSSInitializer::initNSS( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF ) +{ + return *rtl_Instance< bool, InitNSSInitialize, ::osl::MutexGuard, GetNSSInitStaticMutex > + ::create( InitNSSInitialize( xMSF ), GetNSSInitStaticMutex() ); +} + +css::uno::Reference< css::xml::crypto::XDigestContext > SAL_CALL ONSSInitializer::getDigestContext( ::sal_Int32 nDigestID, const css::uno::Sequence< css::beans::NamedValue >& aParams ) + throw (css::lang::IllegalArgumentException, css::uno::RuntimeException) +{ + SECOidTag nNSSDigestID = SEC_OID_UNKNOWN; + sal_Int32 nDigestLength = 0; + bool b1KData = false; + if ( nDigestID == css::xml::crypto::DigestID::SHA256 + || nDigestID == css::xml::crypto::DigestID::SHA256_1K ) + { + nNSSDigestID = SEC_OID_SHA256; + nDigestLength = 32; + b1KData = ( nDigestID == css::xml::crypto::DigestID::SHA256_1K ); + } + else if ( nDigestID == css::xml::crypto::DigestID::SHA1 + || nDigestID == css::xml::crypto::DigestID::SHA1_1K ) + { + nNSSDigestID = SEC_OID_SHA1; + nDigestLength = 20; + b1KData = ( nDigestID == css::xml::crypto::DigestID::SHA1_1K ); + } + else + throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected digest requested." ) ), css::uno::Reference< css::uno::XInterface >(), 1 ); + + if ( aParams.getLength() ) + throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected arguments provided for digest creation." ) ), css::uno::Reference< css::uno::XInterface >(), 2 ); + + css::uno::Reference< css::xml::crypto::XDigestContext > xResult; + if( initNSS( mxMSF ) ) + { + PK11Context* pContext = PK11_CreateDigestContext( nNSSDigestID ); + if ( pContext && PK11_DigestBegin( pContext ) == SECSuccess ) + xResult = new ODigestContext( pContext, nDigestLength, b1KData ); + } + + return xResult; +} + +css::uno::Reference< css::xml::crypto::XCipherContext > SAL_CALL ONSSInitializer::getCipherContext( ::sal_Int32 nCipherID, const css::uno::Sequence< ::sal_Int8 >& aKey, const css::uno::Sequence< ::sal_Int8 >& aInitializationVector, ::sal_Bool bEncryption, const css::uno::Sequence< css::beans::NamedValue >& aParams ) + throw (css::lang::IllegalArgumentException, css::uno::RuntimeException) +{ + CK_MECHANISM_TYPE nNSSCipherID = 0; + bool bW3CPadding = false; + if ( nCipherID == css::xml::crypto::CipherID::AES_CBC_W3C_PADDING ) + { + nNSSCipherID = CKM_AES_CBC; + bW3CPadding = true; + + if ( aKey.getLength() != 16 && aKey.getLength() != 24 && aKey.getLength() != 32 ) + throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected key length." ) ), css::uno::Reference< css::uno::XInterface >(), 2 ); + + if ( aParams.getLength() ) + throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected arguments provided for cipher creation." ) ), css::uno::Reference< css::uno::XInterface >(), 5 ); + } + else + throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected cipher requested." ) ), css::uno::Reference< css::uno::XInterface >(), 1 ); + + css::uno::Reference< css::xml::crypto::XCipherContext > xResult; + if( initNSS( mxMSF ) ) + { + if ( aInitializationVector.getLength() != PK11_GetIVLength( nNSSCipherID ) ) + throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected length of initialization vector." ) ), css::uno::Reference< css::uno::XInterface >(), 3 ); + + xResult = OCipherContext::Create( nNSSCipherID, aKey, aInitializationVector, bEncryption, bW3CPadding ); + } + + return xResult; +} + +rtl::OUString ONSSInitializer_getImplementationName () + throw (cssu::RuntimeException) +{ + + return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) ); +} + +sal_Bool SAL_CALL ONSSInitializer_supportsService( const rtl::OUString& ServiceName ) + throw (cssu::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( NSS_SERVICE_NAME )); +} + +cssu::Sequence< rtl::OUString > SAL_CALL ONSSInitializer_getSupportedServiceNames( ) + throw (cssu::RuntimeException) +{ + cssu::Sequence < rtl::OUString > aRet(1); + rtl::OUString* pArray = aRet.getArray(); + pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( NSS_SERVICE_NAME ) ); + return aRet; +} + +cssu::Reference< cssu::XInterface > SAL_CALL ONSSInitializer_createInstance( const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr) + throw( cssu::Exception ) +{ + return (cppu::OWeakObject*) new ONSSInitializer( rSMgr ); +} + +/* XServiceInfo */ +rtl::OUString SAL_CALL ONSSInitializer::getImplementationName() + throw (cssu::RuntimeException) +{ + return ONSSInitializer_getImplementationName(); +} +sal_Bool SAL_CALL ONSSInitializer::supportsService( const rtl::OUString& rServiceName ) + throw (cssu::RuntimeException) +{ + return ONSSInitializer_supportsService( rServiceName ); +} +cssu::Sequence< rtl::OUString > SAL_CALL ONSSInitializer::getSupportedServiceNames( ) + throw (cssu::RuntimeException) +{ + return ONSSInitializer_getSupportedServiceNames(); +} + diff --git a/xmlsecurity/source/xmlsec/nss/nssinitializer.hxx b/xmlsecurity/source/xmlsec/nss/nssinitializer.hxx new file mode 100644 index 000000000000..6e7fed190d60 --- /dev/null +++ b/xmlsecurity/source/xmlsec/nss/nssinitializer.hxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#ifndef _NSSINITIALIZER_HXX +#define _NSSINITIALIZER_HXX + +#include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp> +#include <com/sun/star/xml/crypto/XCipherContextSupplier.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <cppuhelper/implbase3.hxx> + +#define NSS_SERVICE_NAME "com.sun.star.xml.crypto.NSSInitializer" + +class ONSSInitializer : public cppu::WeakImplHelper3 +< + ::com::sun::star::xml::crypto::XDigestContextSupplier, + ::com::sun::star::xml::crypto::XCipherContextSupplier, + ::com::sun::star::lang::XServiceInfo +> +{ +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; + + ONSSInitializer() + {} + +public: + ONSSInitializer( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF ); + virtual ~ONSSInitializer(); + + bool initNSS( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &xMSF ); + + /* XDigestContextSupplier */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > SAL_CALL getDigestContext( ::sal_Int32 nDigestID, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aParams ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + /* XCipherContextSupplier */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > SAL_CALL getCipherContext( ::sal_Int32 nCipherID, const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aKey, const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aInitializationVector, ::sal_Bool bEncryption, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aParams ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + /* XServiceInfo */ + virtual rtl::OUString SAL_CALL getImplementationName() + throw (::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL supportsService( const rtl::OUString& ServiceName ) + throw (::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() + throw (::com::sun::star::uno::RuntimeException); +}; + +rtl::OUString ONSSInitializer_getImplementationName() + throw ( ::com::sun::star::uno::RuntimeException ); + +sal_Bool SAL_CALL ONSSInitializer_supportsService( const rtl::OUString& ServiceName ) + throw ( ::com::sun::star::uno::RuntimeException ); + +com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL ONSSInitializer_getSupportedServiceNames() + throw ( ::com::sun::star::uno::RuntimeException ); + +com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > +SAL_CALL ONSSInitializer_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ) + throw ( ::com::sun::star::uno::Exception ); + +#endif + diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx index f004d0195f88..ca99ee379a9c 100644 --- a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx @@ -87,7 +87,29 @@ extern X509Certificate_NssImpl* NssPrivKeyToXCert( SECKEYPrivateKey* ) ; struct UsageDescription { SECCertificateUsage usage; - char const * const description; + char const* description; + + UsageDescription() + : usage( certificateUsageCheckAllUsages ) + , description( NULL ) + {} + + UsageDescription( SECCertificateUsage i_usage, char const* i_description ) + : usage( i_usage ) + , description( i_description ) + {} + + UsageDescription( const UsageDescription& aDescription ) + : usage( aDescription.usage ) + , description( aDescription.description ) + {} + + UsageDescription& operator =( const UsageDescription& aDescription ) + { + usage = aDescription.usage; + description = aDescription.description; + return *this; + } }; @@ -906,14 +928,12 @@ verifyCertificate( const Reference< csss::XCertificate >& aCert, // certificateUsageAnyCA // certificateUsageProtectedObjectSigner - UsageDescription arUsages[] = - { - {certificateUsageSSLClient, "certificateUsageSSLClient" }, - {certificateUsageSSLServer, "certificateUsageSSLServer" }, - {certificateUsageSSLCA, "certificateUsageSSLCA" }, - {certificateUsageEmailSigner, "certificateUsageEmailSigner"}, //only usable for end certs - {certificateUsageEmailRecipient, "certificateUsageEmailRecipient"} - }; + UsageDescription arUsages[5]; + arUsages[0] = UsageDescription( certificateUsageSSLClient, "certificateUsageSSLClient" ); + arUsages[1] = UsageDescription( certificateUsageSSLServer, "certificateUsageSSLServer" ); + arUsages[2] = UsageDescription( certificateUsageSSLCA, "certificateUsageSSLCA" ); + arUsages[3] = UsageDescription( certificateUsageEmailSigner, "certificateUsageEmailSigner" ); + arUsages[4] = UsageDescription( certificateUsageEmailRecipient, "certificateUsageEmailRecipient" ); int numUsages = sizeof(arUsages) / sizeof(UsageDescription); for (int i = 0; i < numUsages; i++) diff --git a/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx index e42d97ebc756..5c56124c880a 100644 --- a/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx @@ -49,344 +49,44 @@ #undef DEBUG_WAS_DEFINED #endif - #include <sal/types.h> -#include "rtl/instance.hxx" -#include "rtl/bootstrap.hxx" -#include "rtl/string.hxx" -#include "rtl/strbuf.hxx" -#include "osl/file.hxx" -#include "osl/thread.h" +#include <rtl/bootstrap.hxx> +#include <rtl/string.hxx> +#include <rtl/strbuf.hxx> +#include <osl/file.hxx> +#include <osl/thread.h> #include <tools/debug.hxx> #include <rtl/logfile.hxx> #include "seinitializer_nssimpl.hxx" -#include "../diagnose.hxx" - #include "securityenvironment_nssimpl.hxx" -#include <com/sun/star/mozilla/XMozillaBootstrap.hpp> -#include "nspr.h" -#include "cert.h" -#include "nss.h" -#include "secmod.h" -#include "nssckbi.h" +#include <nspr.h> +#include <cert.h> +#include <nss.h> +#include <pk11pub.h> +#include <secmod.h> +#include <nssckbi.h> -namespace cssu = com::sun::star::uno; -namespace cssl = com::sun::star::lang; -namespace cssxc = com::sun::star::xml::crypto; +namespace css = ::com::sun::star; +namespace cssu = css::uno; +namespace cssl = css::lang; +namespace cssxc = css::xml::crypto; -using namespace xmlsecurity; using namespace com::sun::star; using ::rtl::OUString; using ::rtl::OString; -#define SERVICE_NAME "com.sun.star.xml.crypto.SEInitializer" +#define SE_SERVICE_NAME "com.sun.star.xml.crypto.SEInitializer" #define IMPLEMENTATION_NAME "com.sun.star.xml.security.bridge.xmlsec.SEInitializer_NssImpl" #define SECURITY_ENVIRONMENT "com.sun.star.xml.crypto.SecurityEnvironment" #define SECURITY_CONTEXT "com.sun.star.xml.crypto.XMLSecurityContext" - -#define ROOT_CERTS "Root Certs for OpenOffice.org" - - -extern "C" void nsscrypto_finalize(); - - -namespace -{ - -bool nsscrypto_initialize( const char * sProfile, bool & out_nss_init); - -struct InitNSSInitialize -{ - //path to the database folder - const OString m_sProfile; - InitNSSInitialize(const OString & sProfile): m_sProfile(sProfile) {}; - bool * operator()() - { - static bool bInitialized = false; - bool bNSSInit = false; - bInitialized = nsscrypto_initialize(m_sProfile.getStr(), bNSSInit); - if (bNSSInit) - atexit(nsscrypto_finalize ); - return & bInitialized; - - } -}; - -bool * initNSS(const OString & sProfile) -{ - return rtl_Instance< bool, InitNSSInitialize, - ::osl::MutexGuard, ::osl::GetGlobalMutex >::create( - InitNSSInitialize(sProfile), ::osl::GetGlobalMutex()); -} - -void deleteRootsModule() -{ - SECMODModule *RootsModule = 0; - SECMODModuleList *list = SECMOD_GetDefaultModuleList(); - SECMODListLock *lock = SECMOD_GetDefaultModuleListLock(); - SECMOD_GetReadLock(lock); - - while (!RootsModule && list) - { - SECMODModule *module = list->module; - - for (int i=0; i < module->slotCount; i++) - { - PK11SlotInfo *slot = module->slots[i]; - if (PK11_IsPresent(slot)) - { - if (PK11_HasRootCerts(slot)) - { - xmlsec_trace("The root certifificates module \"%s" - "\" is already loaded: \n%s", - module->commonName, module->dllName); - - RootsModule = SECMOD_ReferenceModule(module); - break; - } - } - } - list = list->next; - } - SECMOD_ReleaseReadLock(lock); - - if (RootsModule) - { - PRInt32 modType; - if (SECSuccess == SECMOD_DeleteModule(RootsModule->commonName, &modType)) - { - xmlsec_trace("Deleted module \"%s\".", RootsModule->commonName); - } - else - { - xmlsec_trace("Failed to delete \"%s\" : \n%s", - RootsModule->commonName, RootsModule->dllName); - } - SECMOD_DestroyModule(RootsModule); - RootsModule = 0; - } -} - -namespace{ - void getAndPrintPRErrorText() - { - char error[1024] = "Cannot get error text from function PR_GetErrorText()."; - PRInt32 size = PR_GetErrorTextLength(); - if (size < (int) sizeof(error)) - { - PR_GetErrorText(error); - } - xmlsec_trace("%s",error); - } -} - -//Older versions of Firefox (FF), for example FF2, and Thunderbird (TB) 2 write -//the roots certificate module (libnssckbi.so), which they use, into the -//profile. This module will then already be loaded during NSS_Init (and the -//other init functions). This fails in two cases. First, FF3 was used to create -//the profile, or possibly used that profile before, and second the profile was -//used on a different platform. -// -//Then one needs to add the roots module oneself. This should be done with -//SECMOD_LoadUserModule rather then SECMOD_AddNewModule. The latter would write -//the location of the roots module to the profile, which makes FF2 and TB2 use -//it instead of there own module. -// -//When using SYSTEM_MOZILLA then the libnss3.so lib is typically found in -///usr/lib. This folder may, however, NOT contain the roots certificate -//module. That is, just providing the library name in SECMOD_LoadUserModule or -//SECMOD_AddNewModule will FAIL to load the mozilla unless the LD_LIBRARY_PATH -//contains an FF or TB installation. -//ATTENTION: DO NOT call this function directly instead use initNSS -//return true - whole initialization was successful -//param out_nss_init = true: at least the NSS initialization (NSS_InitReadWrite -//was successful and therefor NSS_Shutdown should be called when terminating. -bool nsscrypto_initialize( const char* token, bool & out_nss_init ) -{ - bool return_value = true; - - xmlsec_trace("Using profile: %s", token); - - PR_Init( PR_USER_THREAD, PR_PRIORITY_NORMAL, 1 ) ; - - //token may be an empty string - if (token != NULL && strlen(token) > 0) - { - if( NSS_InitReadWrite( token ) != SECSuccess ) - { - xmlsec_trace("Initializing NSS with profile failed."); - getAndPrintPRErrorText(); - return false ; - } - } - else - { - xmlsec_trace("Initializing NSS without profile."); - if ( NSS_NoDB_Init(NULL) != SECSuccess ) - { - xmlsec_trace("Initializing NSS without profile failed."); - getAndPrintPRErrorText(); - return false ; - } - } - out_nss_init = true; - -#if defined SYSTEM_MOZILLA - if (!SECMOD_HasRootCerts()) - { -#endif - deleteRootsModule(); - -#if defined SYSTEM_MOZILLA - OUString rootModule(RTL_CONSTASCII_USTRINGPARAM("libnssckbi"SAL_DLLEXTENSION)); -#else - OUString rootModule(RTL_CONSTASCII_USTRINGPARAM("${OOO_BASE_DIR}/program/libnssckbi"SAL_DLLEXTENSION)); -#endif - ::rtl::Bootstrap::expandMacros(rootModule); - - OUString rootModulePath; - if (::osl::File::E_None == ::osl::File::getSystemPathFromFileURL(rootModule, rootModulePath)) - { - ::rtl::OString ospath = ::rtl::OUStringToOString(rootModulePath, osl_getThreadTextEncoding()); - ::rtl::OStringBuffer pkcs11moduleSpec; - pkcs11moduleSpec.append("name=\""); - pkcs11moduleSpec.append(ROOT_CERTS); - pkcs11moduleSpec.append("\" library=\""); - pkcs11moduleSpec.append(ospath.getStr()); - pkcs11moduleSpec.append("\""); - - SECMODModule * RootsModule = - SECMOD_LoadUserModule( - const_cast<char*>(pkcs11moduleSpec.makeStringAndClear().getStr()), - 0, // no parent - PR_FALSE); // do not recurse - - if (RootsModule) - { - - bool found = RootsModule->loaded; - - SECMOD_DestroyModule(RootsModule); - RootsModule = 0; - if (found) - xmlsec_trace("Added new root certificate module " - "\""ROOT_CERTS"\" contained in \n%s", ospath.getStr()); - else - { - xmlsec_trace("FAILED to load the new root certificate module " - "\""ROOT_CERTS"\" contained in \n%s", ospath.getStr()); - return_value = false; - } - } - else - { - xmlsec_trace("FAILED to add new root certifice module: " - "\""ROOT_CERTS"\" contained in \n%s", ospath.getStr()); - return_value = false; - - } - } - else - { - xmlsec_trace("Adding new root certificate module failed."); - return_value = false; - } -#if SYSTEM_MOZILLA - } -#endif - - return return_value; -} - -// must be extern "C" because we pass the function pointer to atexit -extern "C" void nsscrypto_finalize() -{ - SECMODModule *RootsModule = SECMOD_FindModule(ROOT_CERTS); - - if (RootsModule) - { - - if (SECSuccess == SECMOD_UnloadUserModule(RootsModule)) - { - xmlsec_trace("Unloaded module \""ROOT_CERTS"\"."); - } - else - { - xmlsec_trace("Failed unloadeding module \""ROOT_CERTS"\"."); - } - SECMOD_DestroyModule(RootsModule); - } - else - { - xmlsec_trace("Unloading module \""ROOT_CERTS - "\" failed because it was not found."); - } - PK11_LogoutAll(); - NSS_Shutdown(); -} - - -bool getMozillaCurrentProfile( - const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &rxMSF, - rtl::OUString& profilePath) -{ - /* - * first, try to get the profile from "MOZILLA_CERTIFICATE_FOLDER" - */ - char * env = getenv("MOZILLA_CERTIFICATE_FOLDER"); - if (env) - { - profilePath = rtl::OUString::createFromAscii( env ); - RTL_LOGFILE_PRODUCT_TRACE1( "XMLSEC: Using env MOZILLA_CERTIFICATE_FOLDER: %s", rtl::OUStringToOString( profilePath, RTL_TEXTENCODING_ASCII_US ).getStr() ); - return true; - } - else - { - mozilla::MozillaProductType productTypes[4] = { - mozilla::MozillaProductType_Thunderbird, - mozilla::MozillaProductType_Mozilla, - mozilla::MozillaProductType_Firefox, - mozilla::MozillaProductType_Default }; - int nProduct = 4; - - uno::Reference<uno::XInterface> xInstance = rxMSF->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap")) ); - OSL_ENSURE( xInstance.is(), "failed to create instance" ); - - uno::Reference<mozilla::XMozillaBootstrap> xMozillaBootstrap - = uno::Reference<mozilla::XMozillaBootstrap>(xInstance,uno::UNO_QUERY); - OSL_ENSURE( xMozillaBootstrap.is(), "failed to create instance" ); - - if (xMozillaBootstrap.is()) - { - for (int i=0; i<nProduct; i++) - { - ::rtl::OUString profile = xMozillaBootstrap->getDefaultProfile(productTypes[i]); - - if (profile != NULL && profile.getLength()>0) - { - profilePath = xMozillaBootstrap->getProfilePath(productTypes[i],profile); - RTL_LOGFILE_PRODUCT_TRACE1( "XMLSEC: Using Mozilla Profile: %s", rtl::OUStringToOString( profilePath, RTL_TEXTENCODING_ASCII_US ).getStr() ); - return true; - } - } - } - - RTL_LOGFILE_PRODUCT_TRACE( "XMLSEC: No Mozilla Profile found!" ); - return false; - } -} - -} // namespace - SEInitializer_NssImpl::SEInitializer_NssImpl( - const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &rxMSF) - :mxMSF( rxMSF ) + const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF ) { + mxMSF = rxMSF; } SEInitializer_NssImpl::~SEInitializer_NssImpl() @@ -395,36 +95,14 @@ SEInitializer_NssImpl::~SEInitializer_NssImpl() /* XSEInitializer */ cssu::Reference< cssxc::XXMLSecurityContext > SAL_CALL - SEInitializer_NssImpl::createSecurityContext( - const rtl::OUString& sCertDB ) + SEInitializer_NssImpl::createSecurityContext( const ::rtl::OUString& ) throw (cssu::RuntimeException) { CERTCertDBHandle *pCertHandle = NULL ; - rtl::OString sCertDir; - if( sCertDB.getLength() ) - { - sCertDir = rtl::OString(sCertDB, sCertDB.getLength(), RTL_TEXTENCODING_ASCII_US); - } - else - { - static rtl::OString* pDefaultCertDir = NULL; - if ( !pDefaultCertDir ) - { - pDefaultCertDir = new rtl::OString; - rtl::OUString ouCertDir; - - - if ( getMozillaCurrentProfile(mxMSF, ouCertDir) ) - *pDefaultCertDir = rtl::OString(ouCertDir, ouCertDir.getLength(), RTL_TEXTENCODING_ASCII_US); - } - sCertDir = *pDefaultCertDir; - - } - if( ! *initNSS( sCertDir.getStr() ) ) - { + if( !initNSS( mxMSF ) ) return NULL; - } + pCertHandle = CERT_GetDefaultCertDB() ; try @@ -480,18 +158,18 @@ rtl::OUString SEInitializer_NssImpl_getImplementationName () sal_Bool SAL_CALL SEInitializer_NssImpl_supportsService( const rtl::OUString& ServiceName ) throw (cssu::RuntimeException) { - return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME )); + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SE_SERVICE_NAME )) || ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( NSS_SERVICE_NAME )); } cssu::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl_getSupportedServiceNames( ) throw (cssu::RuntimeException) { - cssu::Sequence < rtl::OUString > aRet(1); + cssu::Sequence < rtl::OUString > aRet(2); rtl::OUString* pArray = aRet.getArray(); - pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); + pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SE_SERVICE_NAME ) ); + pArray[1] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( NSS_SERVICE_NAME ) ); return aRet; } -#undef SERVICE_NAME cssu::Reference< cssu::XInterface > SAL_CALL SEInitializer_NssImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr) throw( cssu::Exception ) diff --git a/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx index 70075adc84e3..469d19bcb331 100644 --- a/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx +++ b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx @@ -29,52 +29,29 @@ #define _SEINITIALIZERIMPL_HXX #include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp> -#ifndef _COM_SUN_STAR_XML_CRYPTO_SEINITIALIZER_HPP_ #include <com/sun/star/xml/crypto/XSEInitializer.hpp> -#endif -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <cppuhelper/implbase2.hxx> + +#include <cppuhelper/implbase1.hxx> #include <libxml/tree.h> -class SEInitializer_NssImpl : public cppu::WeakImplHelper2 +#include "nssinitializer.hxx" + +class SEInitializer_NssImpl : public cppu::ImplInheritanceHelper1 < - com::sun::star::xml::crypto::XSEInitializer, - com::sun::star::lang::XServiceInfo + ONSSInitializer, + ::com::sun::star::xml::crypto::XSEInitializer > -/****** SEInitializer_NssImpl.hxx/CLASS SEInitializer_NssImpl *********** - * - * NAME - * SEInitializer_NssImpl -- Class to initialize a Security Context - * instance - * - * FUNCTION - * Use this class to initialize a XmlSec based Security Context - * instance. After this instance is used up, use this class to free this - * instance. - * - * HISTORY - * 05.01.2004 - Interface supported: XSEInitializer, XSEInitializer - * - * AUTHOR - * Michael Mi - * Email: michael.mi@sun.com - ******************************************************************************/ { -private: - com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF; - public: - SEInitializer_NssImpl(const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &rxMSF); + SEInitializer_NssImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF ); virtual ~SEInitializer_NssImpl(); /* XSEInitializer */ - virtual com::sun::star::uno::Reference< - com::sun::star::xml::crypto::XXMLSecurityContext > - SAL_CALL createSecurityContext( const rtl::OUString& certDB ) - throw (com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::xml::crypto::XXMLSecurityContext > + SAL_CALL createSecurityContext( const ::rtl::OUString& ) + throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL freeSecurityContext( const com::sun::star::uno::Reference< com::sun::star::xml::crypto::XXMLSecurityContext >& securityContext ) @@ -82,27 +59,27 @@ public: /* XServiceInfo */ virtual rtl::OUString SAL_CALL getImplementationName( ) - throw (com::sun::star::uno::RuntimeException); + throw (::com::sun::star::uno::RuntimeException); virtual sal_Bool SAL_CALL supportsService( const rtl::OUString& ServiceName ) - throw (com::sun::star::uno::RuntimeException); + throw (::com::sun::star::uno::RuntimeException); - virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames( ) - throw (com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames( ) + throw (::com::sun::star::uno::RuntimeException); }; rtl::OUString SEInitializer_NssImpl_getImplementationName() - throw ( com::sun::star::uno::RuntimeException ); + throw ( ::com::sun::star::uno::RuntimeException ); sal_Bool SAL_CALL SEInitializer_NssImpl_supportsService( const rtl::OUString& ServiceName ) - throw ( com::sun::star::uno::RuntimeException ); + throw ( ::com::sun::star::uno::RuntimeException ); com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl_getSupportedServiceNames( ) - throw ( com::sun::star::uno::RuntimeException ); + throw ( ::com::sun::star::uno::RuntimeException ); -com::sun::star::uno::Reference< com::sun::star::uno::XInterface > -SAL_CALL SEInitializer_NssImpl_createInstance( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rSMgr) - throw ( com::sun::star::uno::Exception ); +com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > +SAL_CALL SEInitializer_NssImpl_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) + throw ( ::com::sun::star::uno::Exception ); #endif diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx index c8a612fae7e0..5028edb391d1 100644 --- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx @@ -128,13 +128,13 @@ sal_Int16 SAL_CALL X509Certificate_NssImpl :: getVersion() throw ( ::com::sun::s //Convert the time to readable local time PR_ExplodeTime( notBefore, PR_LocalTimeParameters, &explTime ) ; - dateTime.HundredthSeconds = explTime.tm_usec / 1000 ; - dateTime.Seconds = explTime.tm_sec ; - dateTime.Minutes = explTime.tm_min ; - dateTime.Hours = explTime.tm_hour ; - dateTime.Day = explTime.tm_mday ; - dateTime.Month = explTime.tm_month+1 ; - dateTime.Year = explTime.tm_year ; + dateTime.HundredthSeconds = static_cast< sal_Int16 >( explTime.tm_usec / 1000 ); + dateTime.Seconds = static_cast< sal_Int16 >( explTime.tm_sec ); + dateTime.Minutes = static_cast< sal_Int16 >( explTime.tm_min ); + dateTime.Hours = static_cast< sal_Int16 >( explTime.tm_hour ); + dateTime.Day = static_cast< sal_Int16 >( explTime.tm_mday ); + dateTime.Month = static_cast< sal_Int16 >( explTime.tm_month+1 ); + dateTime.Year = static_cast< sal_Int16 >( explTime.tm_year ); return dateTime ; } else { @@ -157,13 +157,13 @@ sal_Int16 SAL_CALL X509Certificate_NssImpl :: getVersion() throw ( ::com::sun::s //Convert the time to readable local time PR_ExplodeTime( notAfter, PR_LocalTimeParameters, &explTime ) ; - dateTime.HundredthSeconds = explTime.tm_usec / 1000 ; - dateTime.Seconds = explTime.tm_sec ; - dateTime.Minutes = explTime.tm_min ; - dateTime.Hours = explTime.tm_hour ; - dateTime.Day = explTime.tm_mday ; - dateTime.Month = explTime.tm_month+1 ; - dateTime.Year = explTime.tm_year ; + dateTime.HundredthSeconds = static_cast< sal_Int16 >( explTime.tm_usec / 1000 ); + dateTime.Seconds = static_cast< sal_Int16 >( explTime.tm_sec ); + dateTime.Minutes = static_cast< sal_Int16 >( explTime.tm_min ); + dateTime.Hours = static_cast< sal_Int16 >( explTime.tm_hour ); + dateTime.Day = static_cast< sal_Int16 >( explTime.tm_mday ); + dateTime.Month = static_cast< sal_Int16 >( explTime.tm_month+1 ); + dateTime.Year = static_cast< sal_Int16 >( explTime.tm_year ); return dateTime ; } else { diff --git a/xmlsecurity/source/xmlsec/nss/xsec_nss.cxx b/xmlsecurity/source/xmlsec/nss/xsec_nss.cxx index 344f76bf3e5d..03d32451759c 100644 --- a/xmlsecurity/source/xmlsec/nss/xsec_nss.cxx +++ b/xmlsecurity/source/xmlsec/nss/xsec_nss.cxx @@ -51,106 +51,46 @@ using namespace ::com::sun::star::registry; extern "C" { -sal_Bool SAL_CALL nss_component_writeInfo( void* /*pServiceManager*/ , void* pRegistryKey ) -{ - sal_Bool result = sal_False; - sal_Int32 i ; - OUString sKeyName ; - Reference< XRegistryKey > xNewKey ; - Sequence< OUString > seqServices ; - Reference< XRegistryKey > xKey( reinterpret_cast< XRegistryKey* >( pRegistryKey ) ) ; - - if( xKey.is() ) { - // try { - // XMLSignature_NssImpl - sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ; - sKeyName += XMLSignature_NssImpl::impl_getImplementationName() ; - sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ; - - xNewKey = xKey->createKey( sKeyName ) ; - if( xNewKey.is() ) { - seqServices = XMLSignature_NssImpl::impl_getSupportedServiceNames() ; - for( i = seqServices.getLength() ; i -- ; ) - xNewKey->createKey( seqServices.getConstArray()[i] ) ; - } - - // XMLEncryption_NssImpl - sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ; - sKeyName += XMLEncryption_NssImpl::impl_getImplementationName() ; - sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ; - - xNewKey = xKey->createKey( sKeyName ) ; - if( xNewKey.is() ) { - seqServices = XMLEncryption_NssImpl::impl_getSupportedServiceNames() ; - for( i = seqServices.getLength() ; i -- ; ) - xNewKey->createKey( seqServices.getConstArray()[i] ) ; - } - - // XMLSecurityContext_NssImpl - sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ; - sKeyName += XMLSecurityContext_NssImpl::impl_getImplementationName() ; - sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ; - - xNewKey = xKey->createKey( sKeyName ) ; - if( xNewKey.is() ) { - seqServices = XMLSecurityContext_NssImpl::impl_getSupportedServiceNames() ; - for( i = seqServices.getLength() ; i -- ; ) - xNewKey->createKey( seqServices.getConstArray()[i] ) ; - } - - // SecurityEnvironment_NssImpl - sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ; - sKeyName += SecurityEnvironment_NssImpl::impl_getImplementationName() ; - sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ; - - xNewKey = xKey->createKey( sKeyName ) ; - if( xNewKey.is() ) { - seqServices = SecurityEnvironment_NssImpl::impl_getSupportedServiceNames() ; - for( i = seqServices.getLength() ; i -- ; ) - xNewKey->createKey( seqServices.getConstArray()[i] ) ; - } - - // SEInitializer_NssImpl - sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ; - sKeyName += SEInitializer_NssImpl_getImplementationName() ; - sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ; - - xNewKey = xKey->createKey( sKeyName ) ; - if( xNewKey.is() ) { - seqServices = SEInitializer_NssImpl_getSupportedServiceNames() ; - for( i = seqServices.getLength() ; i -- ; ) - xNewKey->createKey( seqServices.getConstArray()[i] ) ; - } - - return sal_True; - //} catch( InvalidRegistryException & ) { - // //we should not ignore exceptions - // return sal_False ; - //} - } - return result; -} - void* SAL_CALL nss_component_getFactory( const sal_Char* pImplName , void* pServiceManager , void* /*pRegistryKey*/ ) { void* pRet = 0; Reference< XSingleServiceFactory > xFactory ; - if( pImplName != NULL && pServiceManager != NULL ) { - if( XMLSignature_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) { + if( pImplName != NULL && pServiceManager != NULL ) + { +#ifdef XMLSEC_CRYPTO_NSS + if( SEInitializer_NssImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) + { + xFactory = Reference< XSingleServiceFactory >( createSingleFactory( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), + OUString::createFromAscii( pImplName ), + SEInitializer_NssImpl_createInstance, SEInitializer_NssImpl_getSupportedServiceNames() ) ); + } + else if( XMLSignature_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) + { xFactory = XMLSignature_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ; - } else if( XMLSecurityContext_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) { + } + else if( XMLSecurityContext_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) + { xFactory = XMLSecurityContext_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ; - } else if( SecurityEnvironment_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) { + } + else if( SecurityEnvironment_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) + { xFactory = SecurityEnvironment_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ; - } else if( XMLEncryption_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) { + } + else if( XMLEncryption_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) + { xFactory = XMLEncryption_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ; - } else if( SEInitializer_NssImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) { + } +#else + if( ONSSInitializer_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) + { xFactory = Reference< XSingleServiceFactory >( createSingleFactory( reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), OUString::createFromAscii( pImplName ), - SEInitializer_NssImpl_createInstance, SEInitializer_NssImpl_getSupportedServiceNames() ) ); + ONSSInitializer_createInstance, ONSSInitializer_getSupportedServiceNames() ) ); } +#endif } if( xFactory.is() ) { diff --git a/xmlsecurity/source/xmlsec/xsec_xmlsec.cxx b/xmlsecurity/source/xmlsec/xsec_xmlsec.cxx index 44f11b8d0874..3fba8c69820f 100644 --- a/xmlsecurity/source/xmlsec/xsec_xmlsec.cxx +++ b/xmlsecurity/source/xmlsec/xsec_xmlsec.cxx @@ -93,9 +93,7 @@ Reference< XInterface > SerialNumberAdapterImpl_createInstance( extern "C" { -#if defined( XMLSEC_CRYPTO_NSS ) extern void* nss_component_getFactory( const sal_Char*, void*, void* ); -#endif #if defined( XMLSEC_CRYPTO_MSCRYPTO ) extern void* mscrypt_component_getFactory( const sal_Char*, void*, void* ); @@ -140,11 +138,9 @@ void* SAL_CALL component_getFactory( const sal_Char* pImplName , void* pServiceM xFactory->acquire() ; pRet = xFactory.get() ; } else { -#if defined( XMLSEC_CRYPTO_NSS ) pRet = nss_component_getFactory( pImplName, pServiceManager, pRegistryKey ) ; if( pRet != NULL ) return pRet ; -#endif #if defined( XMLSEC_CRYPTO_MSCRYPTO ) pRet = mscrypt_component_getFactory( pImplName, pServiceManager, pRegistryKey ) ; diff --git a/xmlsecurity/util/makefile.mk b/xmlsecurity/util/makefile.mk index 75ef30c7c5ac..4f60f4babe0e 100644 --- a/xmlsecurity/util/makefile.mk +++ b/xmlsecurity/util/makefile.mk @@ -83,10 +83,10 @@ SHL2LIBS= \ .IF "$(CRYPTO_ENGINE)" == "mscrypto" SHL2LIBS += \ $(SLB)$/xs_mscrypt.lib -.ELSE +.ENDIF + SHL2LIBS += \ $(SLB)$/xs_nss.lib -.ENDIF .ENDIF @@ -117,19 +117,22 @@ SHL2STDLIBS += $(NSS_LIB) .IF "$(CRYPTO_ENGINE)" == "mscrypto" SHL2STDLIBS+= $(MSCRYPTOLIBS) +# SHL2STDLIBS+= $(XMLSECLIB) $(LIBXML2LIB) $(NSS3LIB) $(NSPR4LIB) $(PLC4LIB) +SHL2STDLIBS+= $(NSS3LIB) $(NSPR4LIB) .ELSE SHL2STDLIBS+= $(NSSCRYPTOLIBS) .ENDIF + SHL2IMPLIB = $(SHL2TARGET) SHL2DEF = $(MISC)$/$(SHL2TARGET).def DEF2NAME = $(SHL2TARGET) .IF "$(CRYPTO_ENGINE)" == "mscrypto" DEF2EXPORTFILE = exports_xsmscrypt.dxp -.ELSE -DEF2EXPORTFILE = exports_xsnss.dxp .ENDIF +DEF2EXPORTFILE = exports_xsnss.dxp + SRSFILELIST= \ $(SRS)$/component.srs \ $(SRS)$/dialogs.srs diff --git a/xmlsecurity/util/xsec_xmlsec.component b/xmlsecurity/util/xsec_xmlsec.component index de991899f026..df4c2a7b26ee 100644 --- a/xmlsecurity/util/xsec_xmlsec.component +++ b/xmlsecurity/util/xsec_xmlsec.component @@ -32,6 +32,7 @@ <service name="com.sun.star.security.SerialNumberAdapter"/> </implementation> <implementation name="com.sun.star.xml.security.bridge.xmlsec.SEInitializer_NssImpl"> + <service name="com.sun.star.xml.crypto.NSSInitializer"/> <service name="com.sun.star.xml.crypto.SEInitializer"/> </implementation> <implementation name="com.sun.star.xml.security.bridge.xmlsec.SecurityEnvironment_NssImpl"> diff --git a/xmlsecurity/util/xsec_xmlsec.windows.component b/xmlsecurity/util/xsec_xmlsec.windows.component index fb11cc6e9d36..7b4ef87a9480 100644 --- a/xmlsecurity/util/xsec_xmlsec.windows.component +++ b/xmlsecurity/util/xsec_xmlsec.windows.component @@ -31,6 +31,9 @@ <implementation name="com.sun.star.security.SerialNumberAdapter"> <service name="com.sun.star.security.SerialNumberAdapter"/> </implementation> + <implementation name="com.sun.star.xml.security.bridge.xmlsec.NSSInitializer_NssImpl"> + <service name="com.sun.star.xml.crypto.NSSInitializer"/> + </implementation> <implementation name="com.sun.star.xml.security.bridge.xmlsec.SEInitializer_MSCryptImpl"> <service name="com.sun.star.xml.crypto.SEInitializer"/> </implementation> |