diff options
author | Noel Power <noel.power@novell.com> | 2011-03-24 17:45:51 +0000 |
---|---|---|
committer | Noel Power <noel.power@novell.com> | 2011-03-24 17:47:00 +0000 |
commit | ea0cb7fcf19c9487badaa6da021336d05d078415 (patch) | |
tree | 83fcbff0d988e987281fb8eee143bbe1da8b80fb /sw | |
parent | 572aed1751b98cf3299e06e6986366cf1dfc50d1 (diff) |
don't use legacy filter for word vba macro & Userform import, use oox instead
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/text/portxt.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 4 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.cxx | 4 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par.cxx | 131 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par3.cxx | 2 | ||||
-rw-r--r-- | sw/source/ui/docvw/edtwin.cxx | 7 |
6 files changed, 116 insertions, 34 deletions
diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx index c72c22fb02f9..a84ccb6b52de 100644 --- a/sw/source/core/text/portxt.cxx +++ b/sw/source/core/text/portxt.cxx @@ -820,7 +820,7 @@ void SwFieldFormPortion::Paint( const SwTxtPaintInfo& rInf ) const { if ( pBM->GetFieldname( ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ODF_FORMCHECKBOX ) ) ) { // a checkbox... - ICheckboxFieldmark* pCheckboxFm = dynamic_cast< ICheckboxFieldmark* >(pBM); + ICheckboxFieldmark* pCheckboxFm = reinterpret_cast< ICheckboxFieldmark* >(pBM); bool checked = pCheckboxFm->IsChecked(); rInf.DrawCheckBox(*this, checked); } diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 0b09e3f7115d..d2132ba4c980 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -656,7 +656,9 @@ void DocxAttributeOutput::WriteFFData( const FieldInfos& rInfos ) FieldMarkParamsHelper params( rFieldmark ); params.extractParam( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ODF_FORMCHECKBOX_NAME ) ), sName ); - const sw::mark::ICheckboxFieldmark* pCheckboxFm = dynamic_cast<const sw::mark::ICheckboxFieldmark*>(&rFieldmark); + const sw::mark::ICheckboxFieldmark* pCheckboxFm = NULL; + if ( rFieldmark.GetFieldname( ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ODF_FORMCHECKBOX ) ) ) + pCheckboxFm = reinterpret_cast<const sw::mark::ICheckboxFieldmark*>(&rFieldmark); if ( pCheckboxFm && pCheckboxFm->IsChecked() ) bChecked = true; diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index fe160b9493fe..81920922c145 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -3522,7 +3522,9 @@ void WW8Export::WriteFormData( const ::sw::mark::IFieldmark& rFieldmark ) return; const ::sw::mark::IFieldmark* pFieldmark = &rFieldmark; - const ::sw::mark::ICheckboxFieldmark* pAsCheckbox = dynamic_cast< const ::sw::mark::ICheckboxFieldmark* >( pFieldmark ); + const ::sw::mark::ICheckboxFieldmark* pAsCheckbox = NULL; + if ( rFieldmark.GetFieldname().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ODF_FORMCHECKBOX ) ) ) + pAsCheckbox = reinterpret_cast< const ::sw::mark::ICheckboxFieldmark* >( pFieldmark ); OSL_ENSURE(rFieldmark.GetFieldname().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ODF_FORMTEXT ) ) || diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 7bccdd6b027b..fd05e95c58b6 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -169,6 +169,98 @@ using namespace nsHdFtFlags; #include <unotools/pathoptions.hxx> #include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <comphelper/processfactory.hxx> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/script/vba/XVBACompatibility.hpp> +#include <com/sun/star/document/XImporter.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <comphelper/mediadescriptor.hxx> + +using ::comphelper::MediaDescriptor; +using ::comphelper::getProcessServiceFactory; + +class BasicProjImportHelper +{ + SwDocShell& mrDocShell; +public: + BasicProjImportHelper( SwDocShell& rShell ) : mrDocShell( rShell ) {} + bool import(); + bool import( const com::sun::star::uno::Sequence< com::sun::star::beans::NamedValue >& aArgSeq ); + rtl::OUString getProjectName(); +}; + +bool BasicProjImportHelper::import() +{ + uno::Sequence< beans::NamedValue > aArgSeq; + return import( aArgSeq ); +} + +bool BasicProjImportHelper::import( const uno::Sequence< beans::NamedValue >& aArgSeq ) +{ + bool bRet = false; + try + { + uno::Reference< lang::XComponent > xComponent( mrDocShell.GetModel(), uno::UNO_QUERY_THROW ); + // #TODO #FIXME, get rid of the uno access, better ( and less lines I suspect ) to + // access this directly ( just need to figure out what stream manipulation I need to + // do ) + uno::Reference< lang::XMultiServiceFactory > xFac( getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + uno::Reference< document::XImporter > xImporter; + if ( aArgSeq.getLength() ) + { + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[ 0 ] <<= getProcessServiceFactory(); + aArgs[ 1 ] <<= aArgSeq; + xImporter.set( xFac->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.oox.WordVbaProjectFilter" ) ), aArgs ), uno::UNO_QUERY_THROW ); + } + else + xImporter.set( xFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.oox.WordVbaProjectFilter" ) )), uno::UNO_QUERY_THROW ); + xImporter->setTargetDocument( xComponent ); + + MediaDescriptor aMediaDesc; + SfxMedium& rMedium = *mrDocShell.GetMedium(); + SfxItemSet* pItemSet = rMedium.GetItemSet(); + if( pItemSet ) + { + if( const SfxStringItem* pItem = static_cast< const SfxStringItem* >( pItemSet->GetItem( SID_FILE_NAME ) ) ) + aMediaDesc[ MediaDescriptor::PROP_URL() ] <<= ::rtl::OUString( pItem->GetValue() ); + if( const SfxStringItem* pItem = static_cast< const SfxStringItem* >( pItemSet->GetItem( SID_PASSWORD ) ) ) + aMediaDesc[ MediaDescriptor::PROP_PASSWORD() ] <<= ::rtl::OUString( pItem->GetValue() ); + } + aMediaDesc[ MediaDescriptor::PROP_INPUTSTREAM() ] <<= rMedium.GetInputStream(); + aMediaDesc[ MediaDescriptor::PROP_INTERACTIONHANDLER() ] <<= rMedium.GetInteractionHandler(); + + // call the filter + uno::Reference< document::XFilter > xFilter( xImporter, uno::UNO_QUERY_THROW ); + bRet = xFilter->filter( aMediaDesc.getAsConstPropertyValueList() ); + } + catch( uno::Exception& ) + { + bRet = false; + } + return bRet; +} + +rtl::OUString BasicProjImportHelper::getProjectName() +{ + rtl::OUString sProjName( RTL_CONSTASCII_USTRINGPARAM("Standard") ); + uno::Reference< beans::XPropertySet > xProps( mrDocShell.GetModel(), uno::UNO_QUERY ); + if ( xProps.is() ) + { + try + { + uno::Reference< script::vba::XVBACompatibility > xVBA( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ), uno::UNO_QUERY_THROW ); + sProjName = xVBA->getProjectName(); + + } + catch( uno::Exception& ) + { + } + } + return sProjName; +} + + class Sttb : TBBase { struct SBBItem @@ -4164,7 +4256,6 @@ bool SwWW8ImplReader::ReadGlobalTemplateSettings( const rtl::OUString& sCreatedF sal_Int32 nEntries = sGlobalTemplates.getLength(); bool bRes = true; - const SvtFilterOptions* pVBAFlags = SvtFilterOptions::Get(); for ( sal_Int32 i=0; i<nEntries; ++i ) { INetURLObject aObj; @@ -4180,16 +4271,11 @@ bool SwWW8ImplReader::ReadGlobalTemplateSettings( const rtl::OUString& sCreatedF SotStorageRef rRoot = new SotStorage( aURL, STREAM_STD_READWRITE, STORAGE_TRANSACTED ); - // Read Macro Projects - SvxImportMSVBasic aVBasic(*mpDocShell, *rRoot, - pVBAFlags->IsLoadWordBasicCode(), - pVBAFlags->IsLoadWordBasicStorage() ); - + BasicProjImportHelper aBasicImporter( *mpDocShell ); + // Import vba via oox filter + aBasicImporter.import(); - String s1(CREATE_CONST_ASC("Macros")); - String s2(CREATE_CONST_ASC("VBA")); - aVBasic.Import( s1, s2, !pVBAFlags->IsLoadWordBasicExecutable() ); - lcl_createTemplateToProjectEntry( xPrjNameCache, aURL, aVBasic.GetVBAProjectName() ); + lcl_createTemplateToProjectEntry( xPrjNameCache, aURL, aBasicImporter.getProjectName() ); // Read toolbars & menus SvStorageStreamRef refMainStream = rRoot->OpenSotStream( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WordDocument") ) ); refMainStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); @@ -4447,11 +4533,7 @@ sal_uLong SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos) if (mbNewDoc && pStg && !pGloss) /*meaningless for a glossary, cmc*/ { mpDocShell->SetIsTemplate( pWwFib->fDot ); // point at tgc record - const SvtFilterOptions* pVBAFlags = SvtFilterOptions::Get(); maTracer.EnterEnvironment(sw::log::eMacros); -// dissable below for 3.1 at the moment, 'cause it's kinda immature -// similarly the project reference in svx/source/msvba -#if 1 uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( mpDocShell->GetModel(), uno::UNO_QUERY_THROW ); uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW ); uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW ); @@ -4464,7 +4546,7 @@ sal_uLong SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos) // Read Global templates ReadGlobalTemplateSettings( sCreatedFrom, xPrjNameCache ); -#endif + // Create and insert Word vba Globals uno::Any aGlobs; uno::Sequence< uno::Any > aArgs(1); @@ -4474,20 +4556,15 @@ sal_uLong SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos) if (pBasicMan) pBasicMan->SetGlobalUNOConstant( "VBAGlobals", aGlobs ); - SvxImportMSVBasic aVBasic(*mpDocShell, *pStg, - pVBAFlags->IsLoadWordBasicCode(), - pVBAFlags->IsLoadWordBasicStorage() ); - String s1(CREATE_CONST_ASC("Macros")); - String s2(CREATE_CONST_ASC("VBA")); - int nRet = aVBasic.Import( s1, s2, !pVBAFlags->IsLoadWordBasicExecutable() ); -// dissable below for 3.1 at the moment, 'cause it's kinda immature -// similarly the project reference in svx/source/msvba -#if 1 - lcl_createTemplateToProjectEntry( xPrjNameCache, sCreatedFrom, aVBasic.GetVBAProjectName() ); + BasicProjImportHelper aBasicImporter( *mpDocShell ); + // Import vba via oox filter + bool bRet = aBasicImporter.import(); + + lcl_createTemplateToProjectEntry( xPrjNameCache, sCreatedFrom, aBasicImporter.getProjectName() ); WW8Customizations aCustomisations( pTableStream, *pWwFib ); aCustomisations.Import( mpDocShell ); -#endif - if( 2 & nRet ) + + if( bRet ) { maTracer.Log(sw::log::eContainsVisualBasic); rDoc.SetContainsMSVBasic(true); diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx index fd5edc4358b2..42ca75e60e95 100644 --- a/sw/source/filter/ww8/ww8par3.cxx +++ b/sw/source/filter/ww8/ww8par3.cxx @@ -225,7 +225,7 @@ eF_ResT SwWW8ImplReader::Read_F_FormCheckBox( WW8FieldDesc* pF, String& rStr ) OSL_ENSURE(pFieldmark!=NULL, "hmmm; why was the bookmark not created?"); if (pFieldmark!=NULL) { IFieldmark::parameter_map_t* const pParameters = pFieldmark->GetParameters(); - ICheckboxFieldmark* pCheckboxFm = dynamic_cast<ICheckboxFieldmark*>(pFieldmark); + ICheckboxFieldmark* pCheckboxFm = reinterpret_cast<ICheckboxFieldmark*>(pFieldmark); (*pParameters)[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMCHECKBOX_NAME))] = uno::makeAny(::rtl::OUString(aFormula.sTitle)); (*pParameters)[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMCHECKBOX_HELPTEXT))] = uno::makeAny(::rtl::OUString(aFormula.sToolTip)); diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx index 818aec6e04a3..c78cedad805c 100644 --- a/sw/source/ui/docvw/edtwin.cxx +++ b/sw/source/ui/docvw/edtwin.cxx @@ -2195,8 +2195,9 @@ KEYINPUT_CHECKTABLE_INSDEL: case KS_InsChar: if (rSh.GetChar(sal_False)==CH_TXT_ATR_FORMELEMENT) { - ::sw::mark::ICheckboxFieldmark* pFieldmark = - dynamic_cast< ::sw::mark::ICheckboxFieldmark* > + ::sw::mark::ICheckboxFieldmark* pFieldmark = NULL; + if ( rSh.GetCurrentFieldmark() && rSh.GetCurrentFieldmark()->GetFieldname().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ODF_FORMCHECKBOX ) ) ) + pFieldmark = reinterpret_cast< ::sw::mark::ICheckboxFieldmark* > (rSh.GetCurrentFieldmark()); OSL_ENSURE(pFieldmark, "Where is my FieldMark??"); @@ -4118,7 +4119,7 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt) IFieldmark *fieldBM = const_cast< IFieldmark* > ( aCntntAtPos.aFnd.pFldmark ); if (fieldBM->GetFieldname( ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ODF_FORMCHECKBOX ) ) ) { - ICheckboxFieldmark* pCheckboxFm = dynamic_cast<ICheckboxFieldmark*>(fieldBM); + ICheckboxFieldmark* pCheckboxFm = reinterpret_cast<ICheckboxFieldmark*>(fieldBM); pCheckboxFm->SetChecked(!pCheckboxFm->IsChecked()); pCheckboxFm->Invalidate(); rSh.InvalidateWindows( rView.GetVisArea() ); |