diff options
author | Noel Power <noel.power@novell.com> | 2010-10-06 10:16:50 +0100 |
---|---|---|
committer | Noel Power <noel.power@novell.com> | 2010-10-06 10:16:50 +0100 |
commit | 9a3f243c89bd53b0dc06c19bdccaa402c9e32c14 (patch) | |
tree | 136e33fe6d405ea1175c45246c8e13385fc28a4b /sw | |
parent | c1369970be1d2c0cb19edcac4e1d010635c89730 (diff) |
initial commit for vba blob ( not including container_control stuff )
Diffstat (limited to 'sw')
64 files changed, 2764 insertions, 437 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index bd4ed2836a2b..aa5bc1b06448 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -79,9 +79,7 @@ class SwList; #include "comphelper/implementationreference.hxx" #include <com/sun/star/chart2/data/XDataProvider.hpp> #include <com/sun/star/linguistic2/XProofreadingIterator.hpp> -#ifdef FUTURE_VBA #include <com/sun/star/script/vba/XVBAEventProcessor.hpp> -#endif #include <hash_map> #include <stringhash.hxx> @@ -408,9 +406,8 @@ class SW_DLLPUBLIC SwDoc : // table of forbidden characters of this document vos::ORef<SvxForbiddenCharactersTable> xForbiddenCharsTable; -#ifdef FUTURE_VBA com::sun::star::uno::Reference< com::sun::star::script::vba::XVBAEventProcessor > mxVbaEvents; -#endif + com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> m_xTemplateToProjectCache; // --> OD 2007-10-26 #i83479# public: struct lessThanNodeNum @@ -2136,9 +2133,9 @@ public: { return n32DummyCompatabilityOptions2; } -#ifdef FUTURE_VBA com::sun::star::uno::Reference< com::sun::star::script::vba::XVBAEventProcessor > GetVbaEventProcessor(); -#endif + void SetVBATemplateToProjectCache( com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& xCache ) { m_xTemplateToProjectCache = xCache; }; + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > GetVBATemplateToProjectCache() { return m_xTemplateToProjectCache; }; ::sfx2::IXmlIdRegistry& GetXmlIdRegistry(); ::sw::MetaFieldManager & GetMetaFieldManager(); SfxObjectShell* CreateCopy(bool bCallInitNew) const; diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx index 3dd338a5e129..8010f091d0e1 100644 --- a/sw/inc/docsh.hxx +++ b/sw/inc/docsh.hxx @@ -83,6 +83,7 @@ class SW_DLLPUBLIC SwDocShell: public SfxObjectShell, public SfxListener comphelper::EmbeddedObjectContainer* pOLEChildList; sal_Int16 nUpdateDocMode; // contains the com::sun::star::document::UpdateDocMode bool bInUpdateFontList; //prevent nested calls of UpdateFontList + bool bIsATemplate; //prevent nested calls of UpdateFontList // Methoden fuer den Zugriff aufs Doc SW_DLLPRIVATE void AddLink(); SW_DLLPRIVATE void RemoveLink(); @@ -301,6 +302,8 @@ public: GetController(); SfxInPlaceClient* GetIPClient( const ::svt::EmbeddedObjectRef& xObjRef ); + SW_DLLPRIVATE sal_Bool IsTemplate() { return bIsATemplate; } + SW_DLLPRIVATE void SetIsTemplate( bool bValue ) { bIsATemplate = bValue; } virtual const ::sfx2::IXmlIdRegistry* GetXmlIdRegistry() const; diff --git a/sw/inc/unocoll.hxx b/sw/inc/unocoll.hxx index cc65666d8fd4..a1e39cad5230 100644 --- a/sw/inc/unocoll.hxx +++ b/sw/inc/unocoll.hxx @@ -195,8 +195,12 @@ class SwUnoCollection #define SW_SERVICE_TYPE_FIELDMARK 107 #define SW_SERVICE_TYPE_FORMFIELDMARK 108 #define SW_SERVICE_TYPE_META 109 +#define SW_SERVICE_VBAOBJECTPROVIDER 110 +#define SW_SERVICE_VBACODENAMEPROVIDER 111 +#define SW_SERVICE_VBAPROJECTNAMEPROVIDER 112 +#define SW_SERVICE_VBAGLOBALS 113 -#define SW_SERVICE_LAST SW_SERVICE_TYPE_META +#define SW_SERVICE_LAST SW_SERVICE_VBAGLOBALS #define SW_SERVICE_INVALID USHRT_MAX diff --git a/sw/inc/unoprnms.hxx b/sw/inc/unoprnms.hxx index 0ea5fa9db598..53b62a024b09 100644 --- a/sw/inc/unoprnms.hxx +++ b/sw/inc/unoprnms.hxx @@ -805,8 +805,10 @@ enum SwPropNameIds /* 0737 */ UNO_NAME_DESCRIPTION, // <-- /* 0738 */ UNO_NAME_META, // #i91565# -/* 0739 */ UNO_NAME_NESTED_TEXT_CONTENT, // #i109601# -/* 0740 */ SW_PROPNAME_END +/* 0739 */ UNO_NAME_IS_TEMPLATE, +/* 0740 */ UNO_NAME_VBA_DOCOBJ, +/* 0741 */ UNO_NAME_NESTED_TEXT_CONTENT, // #i109601# +/* 0742 */ SW_PROPNAME_END }; diff --git a/sw/inc/unotbl.hxx b/sw/inc/unotbl.hxx index 372b55ca9193..25c8ad542b4a 100644 --- a/sw/inc/unotbl.hxx +++ b/sw/inc/unotbl.hxx @@ -337,7 +337,7 @@ public: SwXTextTable(SwFrmFmt& rFrmFmt); - static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId(); + SW_DLLPUBLIC static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId(); //XUnoTunnel virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException); diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx index 934909ebfd8a..713ed40d3606 100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -119,9 +119,7 @@ #include <osl/diagnose.h> #include <osl/interlck.h> -#ifdef FUTURE_VBA #include <vbahelper/vbaaccesshelper.hxx> -#endif /* @@@MAINTAINABILITY-HORROR@@@ Probably unwanted dependency on SwDocShell @@ -2732,7 +2730,6 @@ void SwDoc::ChkCondColls() } } -#ifdef FUTURE_VBA uno::Reference< script::vba::XVBAEventProcessor > SwDoc::GetVbaEventProcessor() { @@ -2751,7 +2748,6 @@ SwDoc::GetVbaEventProcessor() } return mxVbaEvents; } -#endif void SwDoc::setExternalData(::sw::tExternalDataType eType, ::sw::tExternalDataPointer pPayload) diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx index 37001380df70..06ed25fe11b7 100644 --- a/sw/source/core/unocore/unocoll.cxx +++ b/sw/source/core/unocore/unocoll.cxx @@ -79,7 +79,16 @@ #include <unorefmark.hxx> #include <unometa.hxx> #include "docsh.hxx" - +#include <com/sun/star/document/XCodeNameQuery.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/form/XFormsSupplier.hpp> +#include <com/sun/star/script/ModuleInfo.hpp> +#include <com/sun/star/script/ModuleType.hpp> +#include <com/sun/star/script/ScriptEventDescriptor.hpp> +#include <com/sun/star/script/vba/XVBAModuleInfo.hpp> +#include <vbahelper/vbaaccesshelper.hxx> +#include <basic/basmgr.hxx> +#include <comphelper/processfactory.hxx> using ::rtl::OUString; using namespace ::com::sun::star; @@ -89,6 +98,184 @@ using namespace ::com::sun::star::text; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; +class SwVbaCodeNameProvider : public ::cppu::WeakImplHelper1< document::XCodeNameQuery > +{ + SwDocShell* mpDocShell; + rtl::OUString msThisDocumentCodeName; +public: + SwVbaCodeNameProvider( SwDocShell* pDocShell ) : mpDocShell( pDocShell ) {} + // XCodeNameQuery + rtl::OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException ) + { + // Initialise the code name + if ( msThisDocumentCodeName.getLength() == 0 ) + { + try + { + uno::Reference< beans::XPropertySet > xProps( mpDocShell->GetModel(), uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xLibContainer( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BasicLibraries") ) ), uno::UNO_QUERY_THROW ); + rtl::OUString sProjectName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") ) ); + if ( mpDocShell->GetBasicManager()->GetName().Len() ) + sProjectName = mpDocShell->GetBasicManager()->GetName(); + + uno::Reference< container::XNameAccess > xLib( xLibContainer->getByName( sProjectName ), uno::UNO_QUERY_THROW ); + uno::Sequence< rtl::OUString > sModuleNames = xLib->getElementNames(); + uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY ); + + for ( sal_Int32 i=0; i < sModuleNames.getLength(); ++i ) + { + script::ModuleInfo mInfo; + + if ( xVBAModuleInfo->hasModuleInfo( sModuleNames[ i ] ) && xVBAModuleInfo->getModuleInfo( sModuleNames[ i ] ).ModuleType == script::ModuleType::DOCUMENT ) + { + msThisDocumentCodeName = sModuleNames[ i ]; + break; + } + } + } + catch( uno::Exception& ) + { + } + } + rtl::OUString sCodeName; + if ( mpDocShell ) + { + OSL_TRACE( "*** In ScVbaCodeNameProvider::getCodeNameForObject"); + // need to find the page ( and index ) for this control + uno::Reference< drawing::XDrawPageSupplier > xSupplier( mpDocShell->GetModel(), uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPage(), uno::UNO_QUERY_THROW ); + sal_Int32 nLen = xIndex->getCount(); + bool bMatched = false; + uno::Sequence< script::ScriptEventDescriptor > aFakeEvents; + try + { + uno::Reference< form::XFormsSupplier > xFormSupplier( xIndex, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW ); + // get the www-standard container + uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW ); + sal_Int32 nCntrls = xFormControls->getCount(); + for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex ) + { + uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW ); + bMatched = ( xControl == xIf ); + if ( bMatched ) + { + sCodeName = msThisDocumentCodeName; + break; + } + } + } + catch( uno::Exception& ) {} + } + // Probably should throw here ( if !bMatched ) + return sCodeName; + } +}; + +typedef std::hash_map< rtl::OUString, rtl::OUString, rtl::OUStringHash > StringHashMap; +class SwVbaProjectNameProvider : public ::cppu::WeakImplHelper1< container::XNameContainer > +{ + SwDocShell* mpDocShell; + StringHashMap mTemplateToProject; +public: + SwVbaProjectNameProvider( SwDocShell* pDocShell ) : mpDocShell( pDocShell ) + { + } + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException ) + { + return ( mTemplateToProject.find( aName ) != mTemplateToProject.end() ); + } + virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) + { + if ( !hasByName( aName ) ) + throw container::NoSuchElementException(); + return uno::makeAny( mTemplateToProject.find( aName )->second ); + } + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (::com::sun::star::uno::RuntimeException) + { + uno::Sequence< rtl::OUString > aElements( mTemplateToProject.size() ); + StringHashMap::iterator it_end = mTemplateToProject.end(); + sal_Int32 index = 0; + for ( StringHashMap::iterator it = mTemplateToProject.begin(); it != it_end; ++it, ++index ) + aElements[ index ] = it->first; + return aElements; + } + + virtual void SAL_CALL insertByName( const rtl::OUString& aName, const uno::Any& aElement ) throw ( com::sun::star::lang::IllegalArgumentException, com::sun::star::container::ElementExistException, com::sun::star::lang::WrappedTargetException ) + { + + rtl::OUString sProjectName; + aElement >>= sProjectName; + OSL_TRACE("** Template cache inserting template name %s with project %s" + , rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() + , rtl::OUStringToOString( sProjectName, RTL_TEXTENCODING_UTF8 ).getStr() ); + mTemplateToProject[ aName ] = sProjectName; + } + + virtual void SAL_CALL removeByName( const rtl::OUString& Name ) throw ( com::sun::star::container::NoSuchElementException, com::sun::star::lang::WrappedTargetException ) + { + if ( !hasByName( Name ) ) + throw container::NoSuchElementException(); + mTemplateToProject.erase( Name ); + } + virtual void SAL_CALL replaceByName( const rtl::OUString& aName, const uno::Any& aElement ) throw ( com::sun::star::lang::IllegalArgumentException, com::sun::star::container::NoSuchElementException, com::sun::star::lang::WrappedTargetException ) + { + if ( !hasByName( aName ) ) + throw container::NoSuchElementException(); + insertByName( aName, aElement ); // insert will overwrite + } + // XElemenAccess + virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException) + { + return ::getCppuType((const rtl::OUString*)0); + } + virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException ) + { + + return ( mTemplateToProject.size() > 0 ); + } + +}; + +class SwVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess > +{ + SwDocShell* mpDocShell; +public: + SwVbaObjectForCodeNameProvider( SwDocShell* pDocShell ) : mpDocShell( pDocShell ) + { + // #FIXME #TODO is the code name for ThisDocument read anywhere? + } + + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException ) + { + // #FIXME #TODO we really need to be checking against the codename for + // ThisDocument + if ( aName.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ThisDocument" ) ) ) ) + return sal_True; + return sal_False; + } + ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) + { + if ( !hasByName( aName ) ) + throw container::NoSuchElementException(); + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[0] = uno::Any( uno::Reference< uno::XInterface >() ); + aArgs[1] = uno::Any( mpDocShell->GetModel() ); + uno::Reference< uno::XInterface > xDocObj = ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.word.Document" , aArgs ); + OSL_TRACE("Creating Object ( ooo.vba.word.Document ) 0x%x", xDocObj.get() ); + return uno::makeAny( xDocObj ); + } + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (::com::sun::star::uno::RuntimeException) + { + uno::Sequence< rtl::OUString > aNames; + return aNames; + } + // XElemenAccess + virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException){ return uno::Type(); } + virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException ) { return sal_True; } + +}; + /****************************************************************************** * ******************************************************************************/ @@ -211,6 +398,10 @@ const ProvNamesId_Type __FAR_DATA aProvNamesId[] = { "com.sun.star.text.Fieldmark", SW_SERVICE_TYPE_FIELDMARK }, { "com.sun.star.text.FormFieldmark", SW_SERVICE_TYPE_FORMFIELDMARK }, { "com.sun.star.text.InContentMetadata", SW_SERVICE_TYPE_META }, + { "ooo.vba.VBAObjectModuleObjectProvider", SW_SERVICE_VBAOBJECTPROVIDER }, + { "ooo.vba.VBACodeNameProvider", SW_SERVICE_VBACODENAMEPROVIDER }, + { "ooo.vba.VBAProjectNameProvider", SW_SERVICE_VBAPROJECTNAMEPROVIDER }, + { "ooo.vba.VBAGlobals", SW_SERVICE_VBAGLOBALS }, // case-correct versions of the service names (see #i67811) { CSS_TEXT_TEXTFIELD_DATE_TIME, SW_SERVICE_FIELDTYPE_DATETIME }, @@ -391,6 +582,50 @@ uno::Reference< uno::XInterface > SwXServiceProvider::MakeInstance(sal_uInt16 xRet = (cppu::OWeakObject*)pFieldmark; } break; + case SW_SERVICE_VBAOBJECTPROVIDER : + { + SwVbaObjectForCodeNameProvider* pObjProv = new SwVbaObjectForCodeNameProvider( pDoc->GetDocShell() ); + xRet = (cppu::OWeakObject*)pObjProv; + } + break; + case SW_SERVICE_VBACODENAMEPROVIDER : + { + if ( pDoc->GetDocShell() && ooo::vba::isAlienWordDoc( *pDoc->GetDocShell() ) ) + { + SwVbaCodeNameProvider* pObjProv = new SwVbaCodeNameProvider( pDoc->GetDocShell() ); + xRet = (cppu::OWeakObject*)pObjProv; + } + } + break; + case SW_SERVICE_VBAPROJECTNAMEPROVIDER : + { + uno::Reference< container::XNameContainer > xProjProv = pDoc->GetVBATemplateToProjectCache(); + if ( !xProjProv.is() && pDoc->GetDocShell() && ooo::vba::isAlienWordDoc( *pDoc->GetDocShell() ) ) + { + xProjProv = new SwVbaProjectNameProvider( pDoc->GetDocShell() ); + pDoc->SetVBATemplateToProjectCache( xProjProv ); + } + //xRet = (cppu::OWeakObject*)xProjProv; + xRet = xProjProv; + } + break; + case SW_SERVICE_VBAGLOBALS : + { + if ( pDoc ) + { + uno::Any aGlobs; + if ( !pDoc->GetDocShell()->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aGlobs ) ) + { + uno::Sequence< uno::Any > aArgs(1); + aArgs[ 0 ] <<= pDoc->GetDocShell()->GetModel(); + aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( ::rtl::OUString::createFromAscii( "ooo.vba.word.Globals"), aArgs ); + pDoc->GetDocShell()->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", aGlobs ); + } + aGlobs >>= xRet; + } + } + break; + case SW_SERVICE_TYPE_FOOTNOTE : xRet = (cppu::OWeakObject*)new SwXFootnote(sal_False); break; diff --git a/sw/source/core/unocore/unomap.cxx b/sw/source/core/unocore/unomap.cxx index 765b1ae37485..aac97f4e31d6 100644 --- a/sw/source/core/unocore/unomap.cxx +++ b/sw/source/core/unocore/unomap.cxx @@ -1580,11 +1580,13 @@ const SfxItemPropertyMapEntry* SwUnoPropertyMapProvider::GetPropertyMapEntries(s { SW_PROP_NMID(UNO_NAME_CHAR_LOCALE), RES_CHRATR_LANGUAGE , CPPU_E2T(CPPUTYPE_LOCALE), PropertyAttribute::MAYBEVOID, MID_LANG_LOCALE }, { SW_PROP_NMID(UNO_NAME_CHARACTER_COUNT), WID_DOC_CHAR_COUNT, CPPU_E2T(CPPUTYPE_INT32), PropertyAttribute::READONLY, 0}, { SW_PROP_NMID(UNO_NAME_DIALOG_LIBRARIES), WID_DOC_DIALOG_LIBRARIES, CPPU_E2T(CPPUTYPE_REFLIBCONTAINER), PropertyAttribute::READONLY, 0}, + { SW_PROP_NMID(UNO_NAME_VBA_DOCOBJ), WID_DOC_VBA_DOCOBJ, CPPU_E2T(CPPUTYPE_PROPERTYVALUE), PropertyAttribute::READONLY, 0}, { SW_PROP_NMID(UNO_NAME_INDEX_AUTO_MARK_FILE_U_R_L), WID_DOC_AUTO_MARK_URL, CPPU_E2T(CPPUTYPE_OUSTRING), PROPERTY_NONE, 0}, { SW_PROP_NMID(UNO_NAME_PARAGRAPH_COUNT), WID_DOC_PARA_COUNT, CPPU_E2T(CPPUTYPE_INT32), PropertyAttribute::READONLY, 0}, { SW_PROP_NMID(UNO_NAME_RECORD_CHANGES), WID_DOC_CHANGES_RECORD, CPPU_E2T(CPPUTYPE_BOOLEAN), PROPERTY_NONE, 0}, { SW_PROP_NMID(UNO_NAME_SHOW_CHANGES), WID_DOC_CHANGES_SHOW, CPPU_E2T(CPPUTYPE_BOOLEAN), PROPERTY_NONE, 0}, { SW_PROP_NMID(UNO_NAME_WORD_COUNT), WID_DOC_WORD_COUNT, CPPU_E2T(CPPUTYPE_INT32), PropertyAttribute::READONLY, 0}, + { SW_PROP_NMID(UNO_NAME_IS_TEMPLATE), WID_DOC_ISTEMPLATEID, CPPU_E2T(CPPUTYPE_BOOLEAN), PropertyAttribute::READONLY, 0}, { SW_PROP_NMID(UNO_NAME_WORD_SEPARATOR), WID_DOC_WORD_SEPARATOR, CPPU_E2T(CPPUTYPE_OUSTRING), PROPERTY_NONE, 0}, { SW_PROP_NMID(UNO_NAME_HIDE_FIELD_TIPS), WID_DOC_HIDE_TIPS, CPPU_E2T(CPPUTYPE_BOOLEAN), PROPERTY_NONE, 0}, { SW_PROP_NMID(UNO_NAME_REDLINE_DISPLAY_TYPE), WID_DOC_REDLINE_DISPLAY, CPPU_E2T(CPPUTYPE_INT16), PROPERTY_NONE, 0}, diff --git a/sw/source/core/unocore/unoprnms.cxx b/sw/source/core/unocore/unoprnms.cxx index 049ccfe42ed7..5e3a38942d7f 100644 --- a/sw/source/core/unocore/unoprnms.cxx +++ b/sw/source/core/unocore/unoprnms.cxx @@ -778,7 +778,10 @@ const SwPropNameTab aPropNameTab = { /* 0736 UNO_NAME_OUTLINE_LEVEL */ {MAP_CHAR_LEN("OutlineLevel")},//#outline level,add<-zhaojianwei Outlinelevel /* 0737 UNO_NAME_DESCRIPTION */ {MAP_CHAR_LEN("Description")}, /* 0738 UNO_NAME_META */ {MAP_CHAR_LEN("InContentMetadata")}, -/* 0739 UNO_NAME_NESTED_TEXT_CONTENT */ {MAP_CHAR_LEN("NestedTextContent")}, +/* 0739 UNO_NAME_IS_TEMPLATE */ {MAP_CHAR_LEN("IsTemplate")}, +/* 0740 UNO_NAME_VBA_DOCOBJ */ {MAP_CHAR_LEN("ThisVBADocObj")}, + +/* 0741 UNO_NAME_NESTED_TEXT_CONTENT */ {MAP_CHAR_LEN("NestedTextContent")}, }; const SwPropNameLen& SwGetPropName( USHORT nId ) diff --git a/sw/source/filter/ww8/makefile.mk b/sw/source/filter/ww8/makefile.mk index 1ca992fa023d..730a67d7c126 100644 --- a/sw/source/filter/ww8/makefile.mk +++ b/sw/source/filter/ww8/makefile.mk @@ -69,6 +69,7 @@ EXCEPTIONSFILES = \ $(SLO)$/WW8TableInfo.obj \ $(SLO)$/WW8FFData.obj \ $(SLO)$/WW8Sttbf.obj \ + $(SLO)$/ww8toolbar.obj \ $(SLO)$/WW8FibData.obj \ $(SLO)$/rtfexportfilter.obj \ $(SLO)$/rtfimportfilter.obj \ @@ -106,6 +107,7 @@ SLOFILES = \ $(SLO)$/WW8TableInfo.obj \ $(SLO)$/WW8FFData.obj \ $(SLO)$/WW8Sttbf.obj \ + $(SLO)$/ww8toolbar.obj \ $(SLO)$/WW8FibData.obj \ $(SLO)$/rtfexportfilter.obj \ $(SLO)$/rtfimportfilter.obj \ diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index c8f64fb32701..194c25212003 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -128,11 +128,19 @@ #include <svl/itemiter.hxx> //SfxItemIter #include <stdio.h> +#include <comphelper/processfactory.hxx> +#include <basic/basmgr.hxx> + +#include "ww8toolbar.hxx" +#include <osl/file.hxx> +#include <com/sun/star/document/XDocumentInfoSupplier.hpp> #ifdef DEBUG #include <iostream> #include <dbgoutsw.hxx> #endif +#include <unotools/localfilehelper.hxx> +#include <comphelper/configurationhelper.hxx> #include "WW8Sttbf.hxx" #include "WW8FibData.hxx" @@ -144,6 +152,87 @@ using namespace sw::util; using namespace sw::types; using namespace nsHdFtFlags; +#include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/container/XNameReplace.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <filter/msfilter/msvbahelper.hxx> +#include <unotools/pathoptions.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> + +class Sttb : TBBase +{ +struct SBBItem +{ + sal_uInt16 cchData; + rtl::OUString data; + SBBItem() : cchData(0){} +}; + sal_uInt16 fExtend; + sal_uInt16 cData; + sal_uInt16 cbExtra; + + std::vector< SBBItem > dataItems; + + Sttb(const Sttb&); + Sttb& operator = ( const Sttb&); +public: + Sttb(); + ~Sttb(); + bool Read(SvStream *pS); + void Print( FILE* fp ); + rtl::OUString getStringAtIndex( sal_uInt32 ); +}; + +Sttb::Sttb() : fExtend( 0 ) +,cData( 0 ) +,cbExtra( 0 ) +{ +} + +Sttb::~Sttb() +{ +} + +bool Sttb::Read( SvStream* pS ) +{ + OSL_TRACE("Sttb::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + *pS >> fExtend >> cData >> cbExtra; + if ( cData ) + { + for ( sal_Int32 index = 0; index < cData; ++index ) + { + SBBItem aItem; + *pS >> aItem.cchData; + aItem.data = readUnicodeString( pS, aItem.cchData ); + dataItems.push_back( aItem ); + } + } + return true; +} + +void Sttb::Print( FILE* fp ) +{ + fprintf( fp, "[ 0x%x ] Sttb - dump\n", nOffSet); + fprintf( fp, " fExtend 0x%x [expected 0xFFFF ]\n", fExtend ); + fprintf( fp, " cData no. or string data items %d (0x%x)\n", cData, cData ); + + if ( cData ) + { + for ( sal_Int32 index = 0; index < cData; ++index ) + fprintf(fp," string dataItem[ %d(0x%x) ] has name %s\n", static_cast< int >( index ), static_cast< unsigned int >( index ), rtl::OUStringToOString( dataItems[ index ].data, RTL_TEXTENCODING_UTF8 ).getStr() ); + } + +} + +rtl::OUString +Sttb::getStringAtIndex( sal_uInt32 index ) +{ + rtl::OUString aRet; + if ( index < dataItems.size() ) + aRet = dataItems[ index ].data; + return aRet; +} SwMSDffManager::SwMSDffManager( SwWW8ImplReader& rRdr ) : SvxMSDffManager(*rRdr.pTableStream, rRdr.GetBaseURL(), rRdr.pWwFib->fcDggInfo, @@ -3787,11 +3876,168 @@ void SwWW8ImplReader::ReadDocInfo() DBG_ASSERT(xDocProps.is(), "DocumentProperties is null"); if (xDocProps.is()) { + if ( pWwFib->fDot ) + { + rtl::OUString sTemplateURL; + SfxMedium* pMedium = mpDocShell->GetMedium(); + if ( pMedium ) + { + rtl::OUString aName = pMedium->GetName(); + INetURLObject aURL( aName ); + sTemplateURL = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI); + if ( sTemplateURL.getLength() > 0 ) + xDocProps->setTemplateURL( sTemplateURL ); + } + } + else // not a template + { + long nCur = pTableStream->Tell(); + Sttb aSttb; + pTableStream->Seek( pWwFib->fcSttbfAssoc ); // point at tgc record + if (!aSttb.Read( pTableStream ) ) + OSL_TRACE("** Read of SttbAssoc data failed!!!! "); + pTableStream->Seek( nCur ); // return to previous position, is that necessary? +#if DEBUG + aSttb.Print( stderr ); +#endif + String sPath = aSttb.getStringAtIndex( 0x1 ); + String aURL; + // attempt to convert to url ( won't work for obvious reasons on linux + if ( sPath.Len() ) + ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sPath, aURL ); + if ( aURL.Len() ) + xDocProps->setTemplateURL( aURL ); + else + xDocProps->setTemplateURL( sPath ); + + } sfx2::LoadOlePropertySet(xDocProps, pStg); } } } +void lcl_createTemplateToProjectEntry( const uno::Reference< container::XNameContainer >& xPrjNameCache, const rtl::OUString& sTemplatePathOrURL, const rtl::OUString& sVBAProjName ) +{ + if ( xPrjNameCache.is() ) + { + INetURLObject aObj; + aObj.SetURL( sTemplatePathOrURL ); + bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID; + rtl::OUString aURL; + if ( bIsURL ) + aURL = sTemplatePathOrURL; + else + { + osl::FileBase::getFileURLFromSystemPath( sTemplatePathOrURL, aURL ); + aObj.SetURL( aURL ); + } + try + { + rtl::OUString templateNameWithExt = aObj.GetLastName(); + rtl::OUString templateName; + sal_Int32 nIndex = templateNameWithExt.lastIndexOf( '.' ); + //xPrjNameCache->insertByName( templateNameWithExt, uno::makeAny( sVBAProjName ) ); + if ( nIndex != -1 ) + { + templateName = templateNameWithExt.copy( 0, nIndex ); + xPrjNameCache->insertByName( templateName, uno::makeAny( sVBAProjName ) ); + } + } + catch( uno::Exception& ) + { + } + } +} + +class WW8Customizations +{ + SvStream* mpTableStream; + WW8Fib mWw8Fib; +public: + WW8Customizations( SvStream*, WW8Fib& ); + bool Import( SwDocShell* pShell ); +}; + +WW8Customizations::WW8Customizations( SvStream* pTableStream, WW8Fib& rFib ) : mpTableStream(pTableStream), mWw8Fib( rFib ) +{ +} + +bool WW8Customizations::Import( SwDocShell* pShell ) +{ + if ( mWw8Fib.lcbCmds == 0 ) + return false; + Tcg aTCG; + long nCur = mpTableStream->Tell(); + mpTableStream->Seek( mWw8Fib.fcCmds ); // point at tgc record + bool bReadResult = aTCG.Read( mpTableStream ); + mpTableStream->Seek( nCur ); // return to previous position, is that necessary? + if ( !bReadResult ) + { + OSL_TRACE("** Read of Customization data failed!!!! "); + return false; + } +#if DEBUG + aTCG.Print( stderr ); +#endif + return aTCG.ImportCustomToolBar( *pShell ); +} + +bool SwWW8ImplReader::ReadGlobalTemplateSettings( const rtl::OUString& sCreatedFrom, const uno::Reference< container::XNameContainer >& xPrjNameCache ) +{ + SvtPathOptions aPathOpt; + String aAddinPath = aPathOpt.GetAddinPath(); + uno::Sequence< rtl::OUString > sGlobalTemplates; + + // first get the autoload addins in the directory STARTUP + uno::Reference< ucb::XSimpleFileAccess > xSFA( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), uno::UNO_QUERY_THROW ); + + if( xSFA->isFolder( aAddinPath ) ) + sGlobalTemplates = xSFA->getFolderContents( aAddinPath, sal_False ); + + sal_Int32 nEntries = sGlobalTemplates.getLength(); + bool bRes = true; + const SvtFilterOptions* pVBAFlags = SvtFilterOptions::Get(); + for ( sal_Int32 i=0; i<nEntries; ++i ) + { + INetURLObject aObj; + aObj.SetURL( sGlobalTemplates[ i ] ); + bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID; + rtl::OUString aURL; + if ( bIsURL ) + aURL = sGlobalTemplates[ i ]; + else + osl::FileBase::getFileURLFromSystemPath( sGlobalTemplates[ i ], aURL ); + if ( !aURL.endsWithIgnoreAsciiCaseAsciiL( ".dot", 4 ) || ( sCreatedFrom.getLength() && sCreatedFrom.equals( aURL ) ) ) + continue; // don't try and read the same document as ourselves + + SotStorageRef rRoot = new SotStorage( aURL, STREAM_STD_READWRITE, STORAGE_TRANSACTED ); + + // Read Macro Projects + SvxImportMSVBasic aVBasic(*mpDocShell, *rRoot, + pVBAFlags->IsLoadWordBasicCode(), + pVBAFlags->IsLoadWordBasicStorage() ); + + + String s1(CREATE_CONST_ASC("Macros")); + String s2(CREATE_CONST_ASC("VBA")); + aVBasic.Import( s1, s2, !pVBAFlags->IsLoadWordBasicExecutable() ); + lcl_createTemplateToProjectEntry( xPrjNameCache, aURL, aVBasic.GetVBAProjectName() ); + // Read toolbars & menus + SvStorageStreamRef refMainStream = rRoot->OpenSotStream( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WordDocument") ) ); + refMainStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); + WW8Fib aWwFib( *refMainStream, 8 ); + SvStorageStreamRef xTableStream = rRoot->OpenSotStream(String::CreateFromAscii( aWwFib.fWhichTblStm ? SL::a1Table : SL::a0Table), STREAM_STD_READ); + + if (xTableStream.Is() && SVSTREAM_OK == xTableStream->GetError()) + { + xTableStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); + WW8Customizations aGblCustomisations( xTableStream, aWwFib ); + aGblCustomisations.Import( mpDocShell ); + } + } + return bRes; +} + ULONG SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos) { ULONG nErrRet = 0; @@ -4075,7 +4321,59 @@ ULONG SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos) } else //ordinary case { + 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 ); + + rtl::OUString sCreatedFrom = xDocProps->getTemplateURL(); + uno::Reference< container::XNameContainer > xPrjNameCache; + uno::Reference< lang::XMultiServiceFactory> xSF(mpDocShell->GetModel(), uno::UNO_QUERY); + if ( xSF.is() ) + xPrjNameCache.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAProjectNameProvider" ) ) ), uno::UNO_QUERY ); + + // Read Global templates + ReadGlobalTemplateSettings( sCreatedFrom, xPrjNameCache ); +#endif + // Create and insert Word vba Globals + uno::Any aGlobs; + uno::Sequence< uno::Any > aArgs(1); + aArgs[ 0 ] <<= mpDocShell->GetModel(); + aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( ::rtl::OUString::createFromAscii( "ooo.vba.word.Globals"), aArgs ); + mpDocShell->GetBasicManager()->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() ); + WW8Customizations aCustomisations( pTableStream, *pWwFib ); + aCustomisations.Import( mpDocShell ); +#endif + if( 2 & nRet ) + { + maTracer.Log(sw::log::eContainsVisualBasic); + rDoc.SetContainsMSVBasic(true); + } + + StoreMacroCmds(); + + maTracer.LeaveEnvironment(sw::log::eMacros); + } ReadText(0, pWwFib->ccpText, MAN_MAINTEXT); + } ::SetProgressState(nProgress, mpDocShell); // Update @@ -4149,26 +4447,6 @@ ULONG SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos) eMode |= nsRedlineMode_t::REDLINE_ON; if( pWDop->fRMView ) eMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE; - if (pStg && !pGloss) /*meaningless for a glossary, cmc*/ - { - const SvtFilterOptions* pVBAFlags = SvtFilterOptions::Get(); - maTracer.EnterEnvironment(sw::log::eMacros); - 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 ); - if( 2 & nRet ) - { - maTracer.Log(sw::log::eContainsVisualBasic); - rDoc.SetContainsMSVBasic(true); - } - - StoreMacroCmds(); - - maTracer.LeaveEnvironment(sw::log::eMacros); - } } maInsertedTables.DelAndMakeTblFrms(); diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx index beb29b02adfa..949c941ca670 100644 --- a/sw/source/filter/ww8/ww8par.hxx +++ b/sw/source/filter/ww8/ww8par.hxx @@ -1417,7 +1417,7 @@ private: // determine object attribute "Layout in Table Cell" bool IsObjectLayoutInTableCell( const UINT32 nLayoutInTableCell ) const; // <-- - + bool ReadGlobalTemplateSettings( const rtl::OUString& sCreatedFrom, const com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& xPrjNameMap ); //No copying SwWW8ImplReader(const SwWW8ImplReader &); SwWW8ImplReader& operator=(const SwWW8ImplReader&); diff --git a/sw/source/ui/app/docsh.cxx b/sw/source/ui/app/docsh.cxx index c7ee43255f3b..940f796aa1aa 100755 --- a/sw/source/ui/app/docsh.cxx +++ b/sw/source/ui/app/docsh.cxx @@ -491,16 +491,6 @@ sal_Bool SwDocShell::SaveAs( SfxMedium& rMedium ) xDocSh->DoClose(); } - if( pDoc->ContainsMSVBasic() ) - { - //TODO/MBA: it looks as that this code can be removed! - //SvxImportMSVBasic aTmp( *this, pIo->GetStorage() ); - //aTmp.SaveOrDelMSVBAStorage( FALSE, aEmptyStr ); - if( SvtFilterOptions::Get()->IsLoadWordBasicStorage() ) - nVBWarning = GetSaveWarningOfMSVBAStorage( (SfxObjectShell&) *this ); - pDoc->SetContainsMSVBasic( FALSE ); - } - // TabellenBox Edit beenden! if( pWrtShell ) pWrtShell->EndAllTblBoxEdit(); diff --git a/sw/source/ui/app/docsh2.cxx b/sw/source/ui/app/docsh2.cxx index d73316075027..ca0bdfe2f624 100644 --- a/sw/source/ui/app/docsh2.cxx +++ b/sw/source/ui/app/docsh2.cxx @@ -119,10 +119,8 @@ #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp> #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> #include "com/sun/star/ui/dialogs/TemplateDescription.hpp" -#ifdef FUTURE_VBA #include <com/sun/star/script/vba/XVBAEventProcessor.hpp> #include <com/sun/star/script/vba/VBAEventId.hpp> -#endif #include <editeng/acorrcfg.hxx> #include <SwStyleNameMapper.hxx> @@ -190,7 +188,6 @@ void SwDocShell::DoFlushDocInfo() } } -#ifdef FUTURE_VBA void lcl_processCompatibleSfxHint( const uno::Reference< script::vba::XVBAEventProcessor >& xVbaEvents, const SfxHint& rHint ) { using namespace com::sun::star::script::vba::VBAEventId; @@ -209,7 +206,6 @@ void lcl_processCompatibleSfxHint( const uno::Reference< script::vba::XVBAEventP } } } -#endif /*-------------------------------------------------------------------- Beschreibung: Benachrichtigung bei geaenderter DocInfo @@ -224,11 +220,9 @@ void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) return ; } -#ifdef FUTURE_VBA uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor(); if( xVbaEvents.is() ) lcl_processCompatibleSfxHint( xVbaEvents, rHint ); -#endif USHORT nAction = 0; if( rHint.ISA(SfxSimpleHint) ) @@ -311,7 +305,6 @@ USHORT SwDocShell::PrepareClose( BOOL bUI, BOOL bForBrowsing ) if( TRUE == nRet ) //Unbedingt auf TRUE abfragen! (RET_NEWTASK) EndListening( *this ); -#ifdef FUTURE_VBA if( pDoc && IsInPrepareClose() ) { uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor(); @@ -322,7 +315,6 @@ USHORT SwDocShell::PrepareClose( BOOL bUI, BOOL bForBrowsing ) xVbaEvents->processVbaEvent( DOCUMENT_CLOSE, aArgs ); } } -#endif return nRet; } @@ -1531,6 +1523,34 @@ void SwDocShell::Execute(SfxRequest& rReq) } } + // #FIXME - align with NEW event stuff ( if possible ) +#if 0 +void lcl_processCompatibleSfxHint( const uno::Reference< document::XVbaEventsHelper >& xVbaEventsHelper, const SfxHint& rHint ) +{ + if ( rHint.ISA( SfxEventHint ) ) + { + uno::Sequence< uno::Any > aArgs; + ULONG nEventId = ((SfxEventHint&)rHint).GetEventId(); + switch( nEventId ) + { + case SFX_EVENT_CREATEDOC: + { + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_DOCUMENT_NEW, aArgs ); + break; + } + case SFX_EVENT_OPENDOC: + { + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_DOCUMENT_OPEN, aArgs ); + break; + } + default: + { + //do nothing + } + } + } +} +#endif /*-------------------------------------------------------------------- Beschreibung: @@ -1587,6 +1607,12 @@ void SwDocShell::FillClass( SvGlobalName * pClassName, *pClipFormat = bTemplate ? SOT_FORMATSTR_ID_STARWRITER_8_TEMPLATE : SOT_FORMATSTR_ID_STARWRITER_8; *pLongUserName = SW_RESSTR(STR_WRITER_DOCUMENT_FULLTYPE); } +// #FIXME check with new Event handling +#if 0 + uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper = pDoc->GetVbaEventsHelper(); + if( xVbaEventsHelper.is() ) + lcl_processCompatibleSfxHint( xVbaEventsHelper, rHint ); +#endif *pUserName = SW_RESSTR(STR_HUMAN_SWDOC_NAME); } diff --git a/sw/source/ui/uno/unotxdoc.cxx b/sw/source/ui/uno/unotxdoc.cxx index 0579d180a04c..9f30eace31d4 100644 --- a/sw/source/ui/uno/unotxdoc.cxx +++ b/sw/source/ui/uno/unotxdoc.cxx @@ -178,6 +178,7 @@ using ::osl::FileBase; #define SW_CREATE_MARKER_TABLE 0x06 #define SW_CREATE_DRAW_DEFAULTS 0x07 +#include <comphelper/processfactory.hxx> /****************************************************************************** * @@ -256,6 +257,12 @@ sal_Int64 SAL_CALL SwXTextDocument::getSomething( const Sequence< sal_Int8 >& rI { return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this )); } + if( rId.getLength() == 16 + && 0 == rtl_compareMemory( SfxObjectShell::getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell )); + } sal_Int64 nRet = SfxBaseModel::getSomething( rId ); if ( nRet ) @@ -404,6 +411,9 @@ SwXTextDocument::SwXTextDocument(SwDocShell* pShell) : m_pPrintUIOptions( NULL ), m_pRenderData( NULL ) { + uno::Reference< document::XDocumentProperties > xWriterProps( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.writer.DocumentProperties") ), uno::UNO_QUERY_THROW); + + SfxBaseModel::setDocumentProperties( xWriterProps ); } /*-- 18.12.98 11:53:00--------------------------------------------------- @@ -2173,6 +2183,9 @@ Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName) Any aAny; switch(pEntry->nWID) { + case WID_DOC_ISTEMPLATEID : + aAny <<= pDocShell->IsTemplate(); + break; case WID_DOC_CHAR_COUNT : case WID_DOC_PARA_COUNT : case WID_DOC_WORD_COUNT : @@ -2281,6 +2294,14 @@ Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName) case WID_DOC_DIALOG_LIBRARIES: aAny <<= pDocShell->GetDialogContainer(); break; + case WID_DOC_VBA_DOCOBJ: + { + beans::PropertyValue aProp; + aProp.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ThisWordDoc") ); + aProp.Value <<= pDocShell->GetModel(); + aAny <<= aProp; + } + break; case WID_DOC_RUNTIME_UID: aAny <<= getRuntimeUID(); break; @@ -3189,6 +3210,7 @@ uno::Sequence< lang::Locale > SAL_CALL SwXTextDocument::getDocumentLanguages( { ::vos::OGuard aGuard(Application::GetSolarMutex()); + // possible canonical values for nScriptTypes // any bit wise combination is allowed const sal_Int16 nLatin = 0x001; diff --git a/sw/source/ui/vba/makefile.mk b/sw/source/ui/vba/makefile.mk index b6d0d7994295..b0fb0f406fce 100644 --- a/sw/source/ui/vba/makefile.mk +++ b/sw/source/ui/vba/makefile.mk @@ -82,6 +82,7 @@ SLOFILES= \ $(SLO)$/vbaborders.obj \ $(SLO)$/vbadocuments.obj \ $(SLO)$/vbaheaderfooter.obj \ + $(SLO)$/vbaheadersfooters.obj \ $(SLO)$/vbaheaderfooterhelper.obj \ $(SLO)$/vbaaddin.obj \ $(SLO)$/vbaaddins.obj \ @@ -91,6 +92,29 @@ SLOFILES= \ $(SLO)$/vbapagesetup.obj \ $(SLO)$/vbasection.obj \ $(SLO)$/vbasections.obj \ + $(SLO)$/vbarow.obj \ + $(SLO)$/vbarows.obj \ + $(SLO)$/vbacolumn.obj \ + $(SLO)$/vbacolumns.obj \ + $(SLO)$/vbatablehelper.obj \ + $(SLO)$/vbacell.obj \ + $(SLO)$/vbacells.obj \ + $(SLO)$/vbatabstop.obj \ + $(SLO)$/vbatabstops.obj \ + $(SLO)$/vbatableofcontents.obj \ + $(SLO)$/vbatablesofcontents.obj \ + $(SLO)$/vbalistgallery.obj \ + $(SLO)$/vbalistgalleries.obj \ + $(SLO)$/vbalisthelper.obj \ + $(SLO)$/vbalisttemplate.obj \ + $(SLO)$/vbalisttemplates.obj \ + $(SLO)$/vbalistlevel.obj \ + $(SLO)$/vbalistlevels.obj \ + $(SLO)$/vbalistformat.obj \ + $(SLO)$/vbarevision.obj \ + $(SLO)$/vbarevisions.obj \ + $(SLO)$/vbaframe.obj \ + $(SLO)$/vbaframes.obj \ $(SLO)$/vbaeventshelper.obj \ # --- Targets ------------------------------------------------------ diff --git a/sw/source/ui/vba/service.cxx b/sw/source/ui/vba/service.cxx index 9f9cbff204dd..7f1271ae16b9 100644 --- a/sw/source/ui/vba/service.cxx +++ b/sw/source/ui/vba/service.cxx @@ -57,6 +57,11 @@ namespace vbaeventshelper extern sdecl::ServiceDecl const serviceDecl; } +namespace vbaeventshelper +{ +extern sdecl::ServiceDecl const serviceDecl; +} + extern "C" { void SAL_CALL component_getImplementationEnvironment( diff --git a/sw/source/ui/vba/vbaapplication.cxx b/sw/source/ui/vba/vbaapplication.cxx index 8056f9ae3deb..ad16899c934a 100644 --- a/sw/source/ui/vba/vbaapplication.cxx +++ b/sw/source/ui/vba/vbaapplication.cxx @@ -40,6 +40,7 @@ #include <editeng/acorrcfg.hxx> #include "wordvbahelper.hxx" #include <docsh.hxx> +#include "vbalistgalleries.hxx" using namespace ::ooo; using namespace ::ooo::vba; @@ -151,6 +152,16 @@ SwVbaApplication::Dialogs( const uno::Any& index ) throw (uno::RuntimeException) return uno::makeAny( xCol ); } +uno::Any SAL_CALL +SwVbaApplication::ListGalleries( const uno::Any& index ) throw (uno::RuntimeException) +{ + uno::Reference< text::XTextDocument > xTextDoc( getCurrentDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xCol( new SwVbaListGalleries( this, mxContext, xTextDoc ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + sal_Bool SAL_CALL SwVbaApplication::getDisplayAutoCompleteTips() throw (css::uno::RuntimeException) { return SvxAutoCorrCfg::Get()->IsAutoTextTip(); diff --git a/sw/source/ui/vba/vbaapplication.hxx b/sw/source/ui/vba/vbaapplication.hxx index 1261590d7c56..65be18774330 100644 --- a/sw/source/ui/vba/vbaapplication.hxx +++ b/sw/source/ui/vba/vbaapplication.hxx @@ -60,6 +60,7 @@ public: virtual css::uno::Any SAL_CALL Documents( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL Addins( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL Dialogs( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL ListGalleries( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); virtual sal_Bool SAL_CALL getDisplayAutoCompleteTips() throw (css::uno::RuntimeException); virtual void SAL_CALL setDisplayAutoCompleteTips( sal_Bool _displayAutoCompleteTips ) throw (css::uno::RuntimeException); virtual sal_Int32 SAL_CALL getEnableCancelKey() throw (css::uno::RuntimeException); diff --git a/sw/source/ui/vba/vbaautotextentry.cxx b/sw/source/ui/vba/vbaautotextentry.cxx index d4c153913553..0a8c0925a446 100644 --- a/sw/source/ui/vba/vbaautotextentry.cxx +++ b/sw/source/ui/vba/vbaautotextentry.cxx @@ -26,7 +26,9 @@ ************************************************************************/ #include "vbaautotextentry.hxx" #include <vbahelper/vbahelper.hxx> +#include <com/sun/star/text/XParagraphCursor.hpp> #include <tools/diagnose_ex.h> +#include "wordvbahelper.hxx" #include "vbarange.hxx" using namespace ::ooo::vba; @@ -41,7 +43,7 @@ SwVbaAutoTextEntry::~SwVbaAutoTextEntry() { } -uno::Reference< word::XRange > SAL_CALL SwVbaAutoTextEntry::Insert( const uno::Reference< word::XRange >& _where, const uno::Any& /*_richtext*/ ) throw ( uno::RuntimeException ) +uno::Reference< word::XRange > SAL_CALL SwVbaAutoTextEntry::Insert( const uno::Reference< word::XRange >& _where, const uno::Any& _richtext ) throw ( uno::RuntimeException ) { SwVbaRange* pWhere = dynamic_cast<SwVbaRange*>( _where.get() ); if( pWhere ) @@ -55,8 +57,28 @@ uno::Reference< word::XRange > SAL_CALL SwVbaAutoTextEntry::Insert( const uno::R uno::Reference< text::XTextCursor > xTC = xText->createTextCursorByRange( xTextRange->getStart() ); xTC->goRight( 1, sal_True ); xTC->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("") ) ); // remove marker + // remove the blank paragraph if it is a rich text + sal_Bool bRich = sal_False; + _richtext >>= bRich; + if( bRich ) + { + // check if it is a blank paragraph + uno::Reference< text::XParagraphCursor > xParaCursor( xTC, uno::UNO_QUERY_THROW ); + if( xParaCursor->isStartOfParagraph() && xParaCursor->isEndOfParagraph() ) + { + //remove the blank paragraph + uno::Reference< frame::XModel > xModel( getCurrentWordDoc( mxContext ), uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextViewCursor > xTVCursor = word::getXTextViewCursor( xModel ); + uno::Reference< text::XTextRange > xCurrentRange( xTC->getEnd(), uno::UNO_QUERY_THROW ); + xTVCursor->gotoRange( xCurrentRange, sal_False ); + rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Delete")); + dispatchRequests( xModel,url ); + xTVCursor->gotoRange( xEndMarker->getEnd(), sal_False ); + } + } xEndMarker->setString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("") ) ); // remove marker - xTC->gotoRange( xEndMarker, sal_True ); + //xTC->gotoRange( xEndMarker, sal_True ); + xTC = xText->createTextCursorByRange( xEndMarker->getEnd() ); pWhere->setXTextCursor( xTC ); } return uno::Reference< word::XRange >( pWhere ); @@ -95,8 +117,9 @@ SwVbaAutoTextEntries::getElementType() throw (uno::RuntimeException) uno::Reference< container::XEnumeration > SwVbaAutoTextEntries::createEnumeration() throw (uno::RuntimeException) { - uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); - return xEnumerationAccess->createEnumeration(); + //uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); + //return xEnumerationAccess->createEnumeration(); + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); } uno::Any diff --git a/sw/source/ui/vba/vbabookmark.cxx b/sw/source/ui/vba/vbabookmark.cxx index a710682c5194..360a59e2b255 100644 --- a/sw/source/ui/vba/vbabookmark.cxx +++ b/sw/source/ui/vba/vbabookmark.cxx @@ -29,9 +29,12 @@ #include <tools/diagnose_ex.h> #include <com/sun/star/text/XTextDocument.hpp> #include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextRange.hpp> #include <com/sun/star/text/XTextViewCursor.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> #include "vbarange.hxx" +#include "wordvbahelper.hxx" using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -65,8 +68,8 @@ void SAL_CALL SwVbaBookmark::Delete() throw ( uno::RuntimeException ) void SAL_CALL SwVbaBookmark::Select() throw ( uno::RuntimeException ) { checkVality(); - uno::Reference< text::XTextViewCursorSupplier > xViewCursorSupplier( mxModel->getCurrentController(), uno::UNO_QUERY_THROW ); - xViewCursorSupplier->getViewCursor()->gotoRange( mxBookmark->getAnchor(),sal_False ); + uno::Reference< view::XSelectionSupplier > xSelectSupp( mxModel->getCurrentController(), uno::UNO_QUERY_THROW ); + xSelectSupp->select( uno::makeAny( mxBookmark ) ); } rtl::OUString SAL_CALL SwVbaBookmark::getName() throw ( uno::RuntimeException ) diff --git a/sw/source/ui/vba/vbabookmarks.cxx b/sw/source/ui/vba/vbabookmarks.cxx index 609b8f9df767..40943c094f6e 100644 --- a/sw/source/ui/vba/vbabookmarks.cxx +++ b/sw/source/ui/vba/vbabookmarks.cxx @@ -118,8 +118,7 @@ SwVbaBookmarks::SwVbaBookmarks( const uno::Reference< XHelperInterface >& xParen mxBookmarksSupplier.set( mxModel, uno::UNO_QUERY_THROW ); uno::Reference< text::XTextDocument > xDocument( mxModel, uno::UNO_QUERY_THROW ); // use view cursor to insert bookmark, or it will fail if insert bookmark in table - // mxText = xDocument->getText(); - mxText = word::getXTextViewCursor( mxModel )->getText(); + //mxText = word::getXTextViewCursor( mxModel )->getText(); } // XEnumerationAccess uno::Type @@ -145,16 +144,16 @@ SwVbaBookmarks::createCollectionObject( const css::uno::Any& aSource ) void SwVbaBookmarks::removeBookmarkByName( const rtl::OUString& rName ) throw (uno::RuntimeException) { uno::Reference< text::XTextContent > xBookmark( m_xNameAccess->getByName( rName ), uno::UNO_QUERY_THROW ); - mxText->removeTextContent( xBookmark ); + word::getXTextViewCursor( mxModel )->getText()->removeTextContent( xBookmark ); } -void SwVbaBookmarks::addBookmarkByName( const rtl::OUString& rName, const uno::Reference< text::XTextRange >& rTextRange ) throw (uno::RuntimeException) +void SwVbaBookmarks::addBookmarkByName( const uno::Reference< frame::XModel >& xModel, const rtl::OUString& rName, const uno::Reference< text::XTextRange >& rTextRange ) throw (uno::RuntimeException) { - uno::Reference< lang::XMultiServiceFactory > xDocMSF( mxModel, uno::UNO_QUERY_THROW ); + uno::Reference< lang::XMultiServiceFactory > xDocMSF( xModel, uno::UNO_QUERY_THROW ); uno::Reference< text::XTextContent > xBookmark( xDocMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Bookmark")) ), uno::UNO_QUERY_THROW ); uno::Reference< container::XNamed > xNamed( xBookmark, uno::UNO_QUERY_THROW ); xNamed->setName( rName ); - mxText->insertTextContent( rTextRange, xBookmark, sal_False ); + rTextRange->getText()->insertTextContent( rTextRange, xBookmark, sal_False ); } uno::Any SAL_CALL @@ -180,7 +179,7 @@ SwVbaBookmarks::Add( const rtl::OUString& rName, const uno::Any& rRange ) throw if( m_xNameAccess->hasByName( aName ) ) removeBookmarkByName( aName ); - addBookmarkByName( aName, xTextRange ); + addBookmarkByName( mxModel, aName, xTextRange ); return uno::makeAny( uno::Reference< word::XBookmark >( new SwVbaBookmark( getParent(), mxContext, mxModel, aName ) ) ); } diff --git a/sw/source/ui/vba/vbabookmarks.hxx b/sw/source/ui/vba/vbabookmarks.hxx index d9047b33d49c..511ee8639415 100644 --- a/sw/source/ui/vba/vbabookmarks.hxx +++ b/sw/source/ui/vba/vbabookmarks.hxx @@ -47,12 +47,12 @@ private: private: void removeBookmarkByName( const rtl::OUString& rName ) throw (css::uno::RuntimeException); - void addBookmarkByName( const rtl::OUString& rName, const css::uno::Reference< css::text::XTextRange >& rTextRange ) throw (css::uno::RuntimeException); public: SwVbaBookmarks( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::container::XIndexAccess >& xBookmarks, const css::uno::Reference< css::frame::XModel >& xModel ); virtual ~SwVbaBookmarks() {} + static void addBookmarkByName( const css::uno::Reference< css::frame::XModel >& xModel, const rtl::OUString& rName, const css::uno::Reference< css::text::XTextRange >& rTextRange ) throw (css::uno::RuntimeException); // XEnumerationAccess virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); diff --git a/sw/source/ui/vba/vbaborders.cxx b/sw/source/ui/vba/vbaborders.cxx index 184f406c49ac..73da177ad18a 100644 --- a/sw/source/ui/vba/vbaborders.cxx +++ b/sw/source/ui/vba/vbaborders.cxx @@ -348,14 +348,19 @@ SwVbaBorders::getItemByIntIndex( const sal_Int32 nIndex ) throw (uno::RuntimeEx sal_Bool SAL_CALL SwVbaBorders::getShadow() throw (uno::RuntimeException) { + /* table::ShadowFormat aShadowFormat; m_xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ShadowFormat") ) ) >>= aShadowFormat; return ( aShadowFormat.Location != table::ShadowLocation_NONE ); + */ + // always return False for table border in MS Word + return sal_False; } void SAL_CALL SwVbaBorders::setShadow( sal_Bool /*_shadow*/ ) throw (uno::RuntimeException) { - throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + // not support in Table border in Word + // TODO: } rtl::OUString& diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx index cef47c7e32dc..48d77006e986 100644 --- a/sw/source/ui/vba/vbadocument.cxx +++ b/sw/source/ui/vba/vbadocument.cxx @@ -38,7 +38,9 @@ #include <com/sun/star/drawing/XControlShape.hpp> #include <com/sun/star/drawing/XControlShape.hpp> #include <com/sun/star/form/XFormsSupplier.hpp> +#include <com/sun/star/document/XRedlinesSupplier.hpp> #include <ooo/vba/XControlProvider.hpp> +#include <ooo/vba/word/WdProtectionType.hpp> #include <vbahelper/helperdecl.hxx> #include <wordvbahelper.hxx> @@ -50,7 +52,14 @@ #include "vbafield.hxx" #include "vbapagesetup.hxx" #include "vbasections.hxx" +#include "vbatablesofcontents.hxx" #include <vbahelper/vbashapes.hxx> +#include <vbahelper/vbahelper.hxx> +#include "vbarevisions.hxx" +#include "vbaframes.hxx" +#include "vbaformfields.hxx" +#include <osl/file.hxx> +#include <tools/urlobj.hxx> using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -220,6 +229,31 @@ SwVbaDocument::Sections( const uno::Any& index ) throw (uno::RuntimeException) } uno::Any SAL_CALL +SwVbaDocument::TablesOfContents( const uno::Any& index ) throw (uno::RuntimeException) +{ + uno::Reference< XCollection > xCol( new SwVbaTablesOfContents( this, mxContext, mxTextDocument ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + +#ifdef FIELDPATCH +uno::Any SAL_CALL +SwVbaDocument::FormFields( const uno::Any& index ) throw (uno::RuntimeException) +{ + uno::Reference< XCollection > xCol( new SwVbaFormFields( this, mxContext, getModel() ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); +#else +uno::Any SAL_CALL +SwVbaDocument::FormFields( const uno::Any& /*index*/ ) throw (uno::RuntimeException) +{ + uno::Reference< XCollection > xCol; +#endif + return uno::makeAny( xCol ); +} + +uno::Any SAL_CALL SwVbaDocument::PageSetup( ) throw (uno::RuntimeException) { uno::Reference< beans::XPropertySet > xPageProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW ); @@ -239,16 +273,34 @@ SwVbaDocument::getAttachedTemplate() throw (uno::RuntimeException) uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( 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 ); - rtl::OUString sTemplateName = xDocProps->getTemplateName(); + rtl::OUString sTemplateUrl = xDocProps->getTemplateURL(); - xTemplate = new SwVbaTemplate( this, mxContext, getModel(), sTemplateName ); + xTemplate = new SwVbaTemplate( this, mxContext, getModel(), sTemplateUrl ); return uno::makeAny( xTemplate ); } void SAL_CALL -SwVbaDocument::setAttachedTemplate( const css::uno::Any& /*_attachedtemplate*/ ) throw (uno::RuntimeException) +SwVbaDocument::setAttachedTemplate( const css::uno::Any& _attachedtemplate ) throw (uno::RuntimeException) { - throw uno::RuntimeException(); + rtl::OUString sTemplate; + if( !( _attachedtemplate >>= sTemplate ) ) + { + throw uno::RuntimeException(); + } + rtl::OUString aURL; + INetURLObject aObj; + aObj.SetURL( sTemplate ); + bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID; + if ( bIsURL ) + aURL = sTemplate; + else + osl::FileBase::getFileURLFromSystemPath( sTemplate, aURL ); + + uno::Reference< word::XTemplate > xTemplate; + uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( 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 ); + xDocProps->setTemplateURL( aURL ); } uno::Any SAL_CALL @@ -267,6 +319,116 @@ void SAL_CALL SwVbaDocument::Activate() throw (uno::RuntimeException) VbaDocumentBase::Activate(); } +::sal_Int32 SAL_CALL SwVbaDocument::getProtectionType() throw (css::uno::RuntimeException) +{ + //TODO + return word::WdProtectionType::wdNoProtection; +} + +void SAL_CALL SwVbaDocument::setProtectionType( ::sal_Int32 /*_protectiontype*/ ) throw (css::uno::RuntimeException) +{ + //TODO +} + +::sal_Bool SAL_CALL SwVbaDocument::getUpdateStylesOnOpen() throw (css::uno::RuntimeException) +{ + //TODO + return sal_False; +} + +void SAL_CALL SwVbaDocument::setUpdateStylesOnOpen( ::sal_Bool /*_updatestylesonopen*/ ) throw (uno::RuntimeException) +{ + //TODO +} + +::sal_Bool SAL_CALL SwVbaDocument::getAutoHyphenation() throw (uno::RuntimeException) +{ + // check this property only in default paragraph style + sal_Bool IsAutoHyphenation = sal_False; + uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW ); + xParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaIsHyphenation")) ) >>= IsAutoHyphenation; + return IsAutoHyphenation; +} + +void SAL_CALL SwVbaDocument::setAutoHyphenation( ::sal_Bool _autohyphenation ) throw (uno::RuntimeException) +{ + //TODO + uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW ); + xParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaIsHyphenation")), uno::makeAny( _autohyphenation ) ); +} + +::sal_Int32 SAL_CALL SwVbaDocument::getHyphenationZone() throw (uno::RuntimeException) +{ + //TODO + return 0; +} + +void SAL_CALL SwVbaDocument::setHyphenationZone( ::sal_Int32 /*_hyphenationzone*/ ) throw (uno::RuntimeException) +{ + //TODO +} + +::sal_Int32 SAL_CALL SwVbaDocument::getConsecutiveHyphensLimit() throw (uno::RuntimeException) +{ + //TODO + sal_Int16 nHyphensLimit = 0; + uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW ); + xParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaHyphenationMaxHyphens")) ) >>= nHyphensLimit; + return nHyphensLimit; +} + +void SAL_CALL SwVbaDocument::setConsecutiveHyphensLimit( ::sal_Int32 _consecutivehyphenslimit ) throw (uno::RuntimeException) +{ + sal_Int16 nHyphensLimit = static_cast< sal_Int16 >( _consecutivehyphenslimit ); + uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW ); + xParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaHyphenationMaxHyphens")), uno::makeAny( nHyphensLimit ) ); +} + +void SAL_CALL SwVbaDocument::Protect( ::sal_Int32 /*Type*/, const uno::Any& /*NOReset*/, const uno::Any& /*Password*/, const uno::Any& /*UseIRM*/, const uno::Any& /*EnforceStyleLock*/ ) throw (uno::RuntimeException) +{ + // Seems not support in Writer + // VbaDocumentBase::Protect( Password ); +} + +void SAL_CALL SwVbaDocument::PrintOut( const uno::Any& /*Background*/, const uno::Any& /*Append*/, const uno::Any& /*Range*/, const uno::Any& /*OutputFileName*/, const uno::Any& /*From*/, const uno::Any& /*To*/, const uno::Any& /*Item*/, const uno::Any& /*Copies*/, const uno::Any& /*Pages*/, const uno::Any& /*PageType*/, const uno::Any& /*PrintToFile*/, const uno::Any& /*Collate*/, const uno::Any& /*FileName*/, const uno::Any& /*ActivePrinterMacGX*/, const uno::Any& /*ManualDuplexPrint*/, const uno::Any& /*PrintZoomColumn*/, const uno::Any& /*PrintZoomRow*/, const uno::Any& /*PrintZoomPaperWidth*/, const uno::Any& /*PrintZoomPaperHeight*/ ) throw (uno::RuntimeException) +{ + //TODO +} + +void SAL_CALL SwVbaDocument::PrintPreview( ) throw (uno::RuntimeException) +{ + rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PrintPreview")); + dispatchRequests( mxModel,url ); +} + +void SAL_CALL SwVbaDocument::ClosePrintPreview( ) throw (uno::RuntimeException) +{ + rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClosePreview")); + dispatchRequests( mxModel,url ); +} + +uno::Any SAL_CALL +SwVbaDocument::Revisions( const uno::Any& index ) throw (uno::RuntimeException) +{ + uno::Reference< document::XRedlinesSupplier > xRedlinesSupp( mxTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xCol( new SwVbaRevisions( this, mxContext, getModel(), xRedlines ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + +uno::Any SAL_CALL +SwVbaDocument::Frames( const uno::Any& index ) throw (uno::RuntimeException) +{ + uno::Reference< text::XTextFramesSupplier > xTextFramesSupp( mxTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xFrames( xTextFramesSupp->getTextFrames(), uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xCol( new SwVbaFrames( this, mxContext, xFrames, getModel() ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + uno::Any SwVbaDocument::getControlShape( const ::rtl::OUString& sName ) { diff --git a/sw/source/ui/vba/vbadocument.hxx b/sw/source/ui/vba/vbadocument.hxx index ab87798a8ded..1ffe20e46aba 100644 --- a/sw/source/ui/vba/vbadocument.hxx +++ b/sw/source/ui/vba/vbadocument.hxx @@ -65,6 +65,25 @@ public: virtual css::uno::Any SAL_CALL Sections( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); virtual void SAL_CALL Activate() throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL PageSetup() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL TablesOfContents( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL FormFields( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getProtectionType() throw (css::uno::RuntimeException); + virtual void SAL_CALL setProtectionType( ::sal_Int32 _protectiontype ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getUpdateStylesOnOpen() throw (css::uno::RuntimeException); + virtual void SAL_CALL setUpdateStylesOnOpen( ::sal_Bool _updatestylesonopen ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getAutoHyphenation() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAutoHyphenation( ::sal_Bool _autohyphenation ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getHyphenationZone() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHyphenationZone( ::sal_Int32 _hyphenationzone ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getConsecutiveHyphensLimit() throw (css::uno::RuntimeException); + virtual void SAL_CALL setConsecutiveHyphensLimit( ::sal_Int32 _consecutivehyphenslimit ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Protect( ::sal_Int32 Type, const css::uno::Any& NOReset, const css::uno::Any& Password, const css::uno::Any& UseIRM, const css::uno::Any& EnforceStyleLock ) throw (css::uno::RuntimeException); + virtual void SAL_CALL PrintOut( const css::uno::Any& Background, const css::uno::Any& Append, const css::uno::Any& Range, const css::uno::Any& OutputFileName, const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Item, const css::uno::Any& Copies, const css::uno::Any& Pages, const css::uno::Any& PageType, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& FileName, const css::uno::Any& ActivePrinterMacGX, const css::uno::Any& ManualDuplexPrint, const css::uno::Any& PrintZoomColumn, const css::uno::Any& PrintZoomRow, const css::uno::Any& PrintZoomPaperWidth, const css::uno::Any& PrintZoomPaperHeight ) throw (css::uno::RuntimeException); + virtual void SAL_CALL PrintPreview( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL ClosePrintPreview( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Revisions( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Frames( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + // XInvocation 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); diff --git a/sw/source/ui/vba/vbadocumentproperties.cxx b/sw/source/ui/vba/vbadocumentproperties.cxx index 50ab62dd904f..4c914a96ca6f 100644 --- a/sw/source/ui/vba/vbadocumentproperties.cxx +++ b/sw/source/ui/vba/vbadocumentproperties.cxx @@ -203,16 +203,16 @@ public: static DocPropInfo createDocPropInfo( const rtl::OUString& sDesc, const rtl::OUString& sPropName, boost::shared_ptr< PropertGetSetHelper >& rHelper ) { - return createDocPropInfo( rtl::OUStringToOString( sDesc, RTL_TEXTENCODING_UTF8 ).getStr(), rtl::OUStringToOString( sPropName, RTL_TEXTENCODING_UTF8 ).getStr(), rHelper ); + DocPropInfo aItem; + aItem.msMSODesc = sDesc; + aItem.msOOOPropName = sPropName; + aItem.mpPropGetSetHelper = rHelper; + return aItem; } static DocPropInfo createDocPropInfo( const sal_Char* sDesc, const sal_Char* sPropName, boost::shared_ptr< PropertGetSetHelper >& rHelper ) { - DocPropInfo aItem; - aItem.msMSODesc = rtl::OUString::createFromAscii( sDesc ); - aItem.msOOOPropName = rtl::OUString::createFromAscii( sPropName ); - aItem.mpPropGetSetHelper = rHelper; - return aItem; + return createDocPropInfo( rtl::OUString::createFromAscii( sDesc ), rtl::OUString::createFromAscii( sPropName ), rHelper ); } uno::Any getValue() { diff --git a/sw/source/ui/vba/vbafield.cxx b/sw/source/ui/vba/vbafield.cxx index a33b3c208c8f..e5b4d87a751d 100644 --- a/sw/source/ui/vba/vbafield.cxx +++ b/sw/source/ui/vba/vbafield.cxx @@ -33,6 +33,7 @@ #include <ooo/vba/word/WdFieldType.hpp> #include <com/sun/star/text/FilenameDisplayFormat.hpp> #include <com/sun/star/util/XRefreshable.hpp> +#include <com/sun/star/util/XUpdatable.hpp> #include <swtypes.hxx> using namespace ::ooo::vba; @@ -45,6 +46,17 @@ SwVbaField::SwVbaField( const uno::Reference< ooo::vba::XHelperInterface >& rPa mxTextField.set( xTextField, uno::UNO_QUERY_THROW ); } +sal_Bool SAL_CALL SwVbaField::Update() throw (uno::RuntimeException) +{ + uno::Reference< util::XUpdatable > xUpdatable( mxTextField, uno::UNO_QUERY ); + if( xUpdatable.is() ) + { + xUpdatable->update(); + return sal_True; + } + return sal_False; +} + // XHelperInterface rtl::OUString& SwVbaField::getServiceImplName() @@ -368,6 +380,7 @@ SwVbaFields::Add( const css::uno::Reference< ::ooo::vba::word::XRange >& Range, { _ReadFieldParams aReadParam(sText); sFieldName = aReadParam.GetFieldName(); + OSL_TRACE("SwVbaFields::Add, the field name is %s ",rtl::OUStringToOString( sFieldName, RTL_TEXTENCODING_UTF8 ).getStr() ); } uno::Reference< text::XTextContent > xTextField; @@ -375,6 +388,10 @@ SwVbaFields::Add( const css::uno::Reference< ::ooo::vba::word::XRange >& Range, { xTextField.set( Create_Field_FileName( sText ), uno::UNO_QUERY_THROW ); } + else if( nType == word::WdFieldType::wdFieldDocProperty || sFieldName.EqualsIgnoreCaseAscii("DOCPROPERTY") ) + { + xTextField.set( Create_Field_DocProperty( sText ), uno::UNO_QUERY_THROW ); + } else { throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); @@ -419,6 +436,104 @@ uno::Reference< text::XTextField > SwVbaFields::Create_Field_FileName( const rtl return xTextField; } +struct DocPropertyTable +{ + const char* sDocPropertyName; + const char* sFieldService; +}; + +static const DocPropertyTable aDocPropertyTables[] = +{ + { "Author", "com.sun.star.text.textfield.docinfo.CreateAuthor" }, + { "Bytes", NULL }, + { "Category", NULL }, + { "Characters",NULL }, + { "CharactersWithSpaces", NULL }, + { "Comments", "com.sun.star.text.textfield.docinfo.Description" }, + { "Company", NULL }, + { "CreateTime", "com.sun.star.text.textfield.docinfo.CreateDateTime" }, + { "HyperlinkBase", NULL }, + { "Keywords", "com.sun.star.text.textfield.docinfo.Keywords" }, + { "LastPrinted", "com.sun.star.text.textfield.docinfo.PrintDateTime" }, + { "LastSavedBy", "com.sun.star.text.textfield.docinfo.ChangeAuthor" }, + { "LastSavedTime", "com.sun.star.text.textfield.docinfo.ChangeDateTime" }, + { "Lines", NULL }, + { "Manager", NULL }, + { "NameofApplication", NULL }, + { "ODMADocID", NULL }, + { "Pages", "com.sun.star.text.textfield.PageCount" }, + { "Paragraphs", "com.sun.star.text.textfield.ParagraphCount" }, + { "RevisionNumber", "com.sun.star.text.textfield.docinfo.Revision" }, + { "Security", NULL }, + { "Subject", "com.sun.star.text.textfield.docinfo.Subject" }, + { "Template", "com.sun.star.text.textfield.TemplateName" }, + { "Title", "com.sun.star.text.textfield.docinfo.Title" }, + { "TotalEditingTime", "com.sun.star.text.textfield.docinfo.EditTime" }, + { "Words", "com.sun.star.text.textfield.WordCount" }, + { NULL, NULL } +}; + +uno::Reference< text::XTextField > SwVbaFields::Create_Field_DocProperty( const rtl::OUString _text ) throw (uno::RuntimeException) +{ + String aDocProperty; + _ReadFieldParams aReadParam( _text ); + long nRet; + while( -1 != ( nRet = aReadParam.SkipToNextToken() )) + { + switch( nRet ) + { + case -2: + if( !aDocProperty.Len() ) + aDocProperty = aReadParam.GetResult(); + break; + case '*': + //Skip over MERGEFORMAT + aReadParam.SkipToNextToken(); + break; + } + } + aDocProperty.EraseAllChars('"'); + OSL_TRACE("SwVbaFields::Create_Field_DocProperty, the document property name is %s ",rtl::OUStringToOString( aDocProperty, RTL_TEXTENCODING_UTF8 ).getStr() ); + if( aDocProperty.Len() == 0 ) + { + throw uno::RuntimeException(); + } + + sal_Bool bCustom = sal_True; + rtl::OUString sFieldService; + // find the build in document properties + for( const DocPropertyTable* pTable = aDocPropertyTables; pTable->sDocPropertyName != NULL; pTable++ ) + { + if( aDocProperty.EqualsIgnoreCaseAscii( pTable->sDocPropertyName ) ) + { + if( pTable->sFieldService != NULL ) + sFieldService = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( pTable->sFieldService ) ); + bCustom = sal_False; + break; + } + } + + if( bCustom ) + { + sFieldService = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.textfield.docinfo.Custom" ) ); + } + else if( sFieldService.getLength() == 0 ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + + uno::Reference< text::XTextField > xTextField( mxMSF->createInstance( sFieldService ), uno::UNO_QUERY_THROW ); + + if( bCustom ) + { + uno::Reference< beans::XPropertySet > xProps( xTextField, uno::UNO_QUERY_THROW ); + rtl::OUString sDocPropertyName( aDocProperty ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Name") ), uno::makeAny( sDocPropertyName ) ); + } + + return xTextField; +} + uno::Reference< container::XEnumeration > SAL_CALL SwVbaFields::createEnumeration() throw (uno::RuntimeException) { diff --git a/sw/source/ui/vba/vbafield.hxx b/sw/source/ui/vba/vbafield.hxx index 3c55acf73e9d..4f2ca4645be4 100644 --- a/sw/source/ui/vba/vbafield.hxx +++ b/sw/source/ui/vba/vbafield.hxx @@ -42,6 +42,7 @@ class SwVbaField : public SwVbaField_BASE public: SwVbaField( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextDocument >& rDocument, const css::uno::Reference< css::text::XTextField >& xTextField) throw ( css::uno::RuntimeException); + virtual sal_Bool SAL_CALL Update() throw ( css::uno::RuntimeException); // XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); @@ -57,6 +58,7 @@ class SwVbaFields : public SwVbaFields_BASE css::uno::Reference< css::lang::XMultiServiceFactory > mxMSF; private: css::uno::Reference< css::text::XTextField > Create_Field_FileName( const rtl::OUString _text ) throw (css::uno::RuntimeException); + css::uno::Reference< css::text::XTextField > Create_Field_DocProperty( const rtl::OUString _text ) throw (css::uno::RuntimeException); public: SwVbaFields( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::frame::XModel >& xModel ); diff --git a/sw/source/ui/vba/vbaglobals.cxx b/sw/source/ui/vba/vbaglobals.cxx index b95c5e5c9e3d..cd67e3019b37 100644 --- a/sw/source/ui/vba/vbaglobals.cxx +++ b/sw/source/ui/vba/vbaglobals.cxx @@ -129,6 +129,12 @@ SwVbaGlobals::Dialogs( const uno::Any& index ) throw (uno::RuntimeException) return getApplication()->Dialogs( index ); } +uno::Any SAL_CALL +SwVbaGlobals::ListGalleries( const uno::Any& index ) throw (uno::RuntimeException) +{ + return getApplication()->ListGalleries( index ); +} + uno::Reference<word::XSelection > SAL_CALL SwVbaGlobals::getSelection() throw (uno::RuntimeException) { diff --git a/sw/source/ui/vba/vbaglobals.hxx b/sw/source/ui/vba/vbaglobals.hxx index 9bb2e8fa606d..4bf3e7be033c 100644 --- a/sw/source/ui/vba/vbaglobals.hxx +++ b/sw/source/ui/vba/vbaglobals.hxx @@ -69,6 +69,7 @@ public: virtual css::uno::Any SAL_CALL Documents( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL Addins( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL Dialogs( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL ListGalleries( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); virtual float SAL_CALL CentimetersToPoints( float _Centimeters ) throw (css::uno::RuntimeException); // XMultiServiceFactory virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw (css::uno::RuntimeException); diff --git a/sw/source/ui/vba/vbaheaderfooter.cxx b/sw/source/ui/vba/vbaheaderfooter.cxx index 6fb7061c573f..6b7c131492d6 100644 --- a/sw/source/ui/vba/vbaheaderfooter.cxx +++ b/sw/source/ui/vba/vbaheaderfooter.cxx @@ -81,6 +81,7 @@ uno::Reference< word::XRange > SAL_CALL SwVbaHeaderFooter::getRange() throw (uno uno::Any SAL_CALL SwVbaHeaderFooter::Shapes( const uno::Any& index ) throw (uno::RuntimeException) { + // #FIXME: only get the shapes in the current header/footer uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxModel, uno::UNO_QUERY_THROW ); //uno::Reference< drawing::XShapes > xShapes( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW ); uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW ); diff --git a/sw/source/ui/vba/vbaheaderfooterhelper.cxx b/sw/source/ui/vba/vbaheaderfooterhelper.cxx index 604cc1e11d8c..e299c51953ae 100644 --- a/sw/source/ui/vba/vbaheaderfooterhelper.cxx +++ b/sw/source/ui/vba/vbaheaderfooterhelper.cxx @@ -29,8 +29,12 @@ #include <comphelper/processfactory.hxx> #include <com/sun/star/frame/XController.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include <com/sun/star/text/XTextRangeCompare.hpp> +#include <com/sun/star/text/XTextRange.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> using namespace ::com::sun::star; using namespace ::ooo::vba; @@ -38,41 +42,61 @@ using namespace ::ooo::vba; #define FIRST_PAGE 1; // Class HeaderFooterHelper +sal_Bool HeaderFooterHelper::isHeaderFooter( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) +{ + return isHeaderFooter( word::getCurrentXText( xModel ) ); +} -sal_Bool HeaderFooterHelper::isHeader( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XText >& xCurrentText ) throw (uno::RuntimeException) +sal_Bool HeaderFooterHelper::isHeaderFooter( const uno::Reference< text::XText >& xText ) throw (uno::RuntimeException) { - uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); - uno::Reference< beans::XPropertySet > xStyleProps( word::getCurrentPageStyle( xModel ), uno::UNO_QUERY_THROW ); + uno::Reference< lang::XServiceInfo > xServiceInfo( xText, uno::UNO_QUERY_THROW ); + rtl::OUString aImplName = xServiceInfo->getImplementationName(); + if( aImplName.equalsAscii("SwXHeadFootText") ) + return sal_True; + return sal_False; +} - sal_Bool isOn = sal_False; - xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn"))) >>= isOn; - if( !isOn ) +sal_Bool HeaderFooterHelper::isHeader( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) +{ + const uno::Reference< text::XText > xCurrentText = word::getCurrentXText( xModel ); + if( !isHeaderFooter( xCurrentText ) ) return sal_False; - sal_Bool isShared = sal_False; - xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsShared"))) >>= isShared; - + rtl::OUString aPropIsShared = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsShared") ); rtl::OUString aPropText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderText") ); + uno::Reference< style::XStyle > xPageStyle = word::getCurrentPageStyle( xModel ); + uno::Reference< beans::XPropertySet > xPageProps( xPageStyle, uno::UNO_QUERY_THROW ); + sal_Bool isShared = sal_True; + xPageProps->getPropertyValue( aPropIsShared ) >>= isShared; if( !isShared ) { + uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); if( 0 == xPageCursor->getPage() % 2 ) - { aPropText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderTextLeft") ); - } else - { aPropText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderTextRight") ); - } } - uno::Reference< text::XText > xText( xStyleProps->getPropertyValue( aPropText ), uno::UNO_QUERY_THROW ); - //FIXME: can not compare in this way? - return ( xText == xCurrentText ); + uno::Reference< text::XText > xHeaderText( xPageProps->getPropertyValue( aPropText ), uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRangeCompare > xTRC( xHeaderText, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRange > xTR1( xCurrentText, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRange > xTR2( xHeaderText, uno::UNO_QUERY_THROW ); + try + { + if( xTRC->compareRegionStarts( xTR1, xTR2 ) == 0 ) + return sal_True; + } + catch( lang::IllegalArgumentException& ) + { + return sal_False; + } + + return sal_False; } -sal_Bool HeaderFooterHelper::isFirstPageHeader( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XText >& xCurrentText ) throw (uno::RuntimeException) +sal_Bool HeaderFooterHelper::isFirstPageHeader( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) { - if( isHeader( xModel, xCurrentText ) ) + if( isHeader( xModel ) ) { uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); // FIXME: getPage allways returns 1 @@ -82,9 +106,9 @@ sal_Bool HeaderFooterHelper::isFirstPageHeader( const uno::Reference< frame::XMo return sal_False; } -sal_Bool HeaderFooterHelper::isEvenPagesHeader( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XText >& xCurrentText ) throw (uno::RuntimeException) +sal_Bool HeaderFooterHelper::isEvenPagesHeader( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) { - if( isHeader( xModel, xCurrentText ) ) + if( isHeader( xModel ) ) { uno::Reference< beans::XPropertySet > xStyleProps( word::getCurrentPageStyle( xModel ), uno::UNO_QUERY_THROW ); sal_Bool isShared = sal_False; @@ -98,40 +122,47 @@ sal_Bool HeaderFooterHelper::isEvenPagesHeader( const uno::Reference< frame::XMo return sal_False; } -sal_Bool HeaderFooterHelper::isFooter( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XText >& xCurrentText ) throw (uno::RuntimeException) +sal_Bool HeaderFooterHelper::isFooter( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) { - uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); - uno::Reference< beans::XPropertySet > xStyleProps( word::getCurrentPageStyle( xModel ), uno::UNO_QUERY_THROW ); - - sal_Bool isOn = sal_False; - xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn"))) >>= isOn; - if( !isOn ) + const uno::Reference< text::XText > xCurrentText = word::getCurrentXText( xModel ); + if( !isHeaderFooter( xCurrentText ) ) return sal_False; - sal_Bool isShared = sal_False; - xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsShared"))) >>= isShared; - + rtl::OUString aPropIsShared = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsShared") ); rtl::OUString aPropText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterText") ); + uno::Reference< style::XStyle > xPageStyle = word::getCurrentPageStyle( xModel ); + uno::Reference< beans::XPropertySet > xPageProps( xPageStyle, uno::UNO_QUERY_THROW ); + sal_Bool isShared = sal_True; + xPageProps->getPropertyValue( aPropIsShared ) >>= isShared; if( !isShared ) { + uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); if( 0 == xPageCursor->getPage() % 2 ) - { aPropText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterTextLeft") ); - } else - { aPropText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterTextRight") ); - } } - uno::Reference< text::XText > xText( xStyleProps->getPropertyValue( aPropText ), uno::UNO_QUERY_THROW ); + uno::Reference< text::XText > xFooterText( xPageProps->getPropertyValue( aPropText ), uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRangeCompare > xTRC( xFooterText, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRange > xTR1( xCurrentText, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRange > xTR2( xFooterText, uno::UNO_QUERY_THROW ); + try + { + if( xTRC->compareRegionStarts( xTR1, xTR2 ) == 0 ) + return sal_True; + } + catch( lang::IllegalArgumentException& ) + { + return sal_False; + } - return ( xText == xCurrentText ); + return sal_False; } -sal_Bool HeaderFooterHelper::isFirstPageFooter( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XText >& xCurrentText ) throw (uno::RuntimeException) +sal_Bool HeaderFooterHelper::isFirstPageFooter( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) { - if( isFooter( xModel, xCurrentText ) ) + if( isFooter( xModel ) ) { uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); sal_Int32 nPage = xPageCursor->getPage(); @@ -140,9 +171,9 @@ sal_Bool HeaderFooterHelper::isFirstPageFooter( const uno::Reference< frame::XMo return sal_False; } -sal_Bool HeaderFooterHelper::isEvenPagesFooter( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XText >& xCurrentText ) throw (uno::RuntimeException) +sal_Bool HeaderFooterHelper::isEvenPagesFooter( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) { - if( isFooter( xModel, xCurrentText ) ) + if( isFooter( xModel ) ) { uno::Reference< beans::XPropertySet > xStyleProps( word::getCurrentPageStyle( xModel ), uno::UNO_QUERY_THROW ); sal_Bool isShared = sal_False; @@ -158,18 +189,18 @@ sal_Bool HeaderFooterHelper::isEvenPagesFooter( const uno::Reference< frame::XMo #ifdef TOMORROW sal_Bool HeaderFooterHelper::isPrimaryHeader( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XText >& xCurrentText ) throw (uno::RuntimeException) { - if( isHeader( xModel, xCurrentText ) ) + if( isHeader( xModel ) ) { - return( !( isFirstPageHeader( xModel, xCurrentText ) && isEvenPagesHeader( xModel, xCurrentText ) ) ); + return( !( isFirstPageHeader( xModel ) && isEvenPagesHeader( xModel ) ) ); } return sal_False; } -sal_Bool HeaderFooterHelper::isPrimaryFooter( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XText >& xCurrentText ) throw (uno::RuntimeException) +sal_Bool HeaderFooterHelper::isPrimaryFooter( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) { - if( isHeader( xModel, xCurrentText ) ) + if( isHeader( xModel ) ) { - return( !( isFirstPageFooter( xModel, xCurrentText ) && isEvenPagesFooter( xModel, xCurrentText ) ) ); + return( !( isFirstPageFooter( xModel ) && isEvenPagesFooter( xModel ) ) ); } return sal_False; } diff --git a/sw/source/ui/vba/vbaheaderfooterhelper.hxx b/sw/source/ui/vba/vbaheaderfooterhelper.hxx index fd29a16015ab..4b620901da67 100644 --- a/sw/source/ui/vba/vbaheaderfooterhelper.hxx +++ b/sw/source/ui/vba/vbaheaderfooterhelper.hxx @@ -36,12 +36,16 @@ class HeaderFooterHelper { public: - static sal_Bool isHeader( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XText >& xCurrentText ) throw (css::uno::RuntimeException); - static sal_Bool isFirstPageHeader( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XText >& xCurrentText ) throw (css::uno::RuntimeException); - static sal_Bool isEvenPagesHeader( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XText >& xCurrentText ) throw (css::uno::RuntimeException); - static sal_Bool isFooter( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XText >& xCurrentText ) throw (css::uno::RuntimeException); - static sal_Bool isFirstPageFooter( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XText >& xCurrentText ) throw (css::uno::RuntimeException); - static sal_Bool isEvenPagesFooter( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XText >& xCurrentText ) throw (css::uno::RuntimeException); + static sal_Bool isHeaderFooter( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + static sal_Bool isHeaderFooter( const css::uno::Reference< css::text::XText >& xText ) throw (css::uno::RuntimeException); + static sal_Bool isHeader( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + static sal_Bool isFirstPageHeader( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + static sal_Bool isEvenPagesHeader( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + static sal_Bool isFooter( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + static sal_Bool isFirstPageFooter( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + static sal_Bool isEvenPagesFooter( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + static sal_Bool isPrimaryHeader( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + static sal_Bool isPrimaryFooter( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); #ifdef TOMORROW static sal_Bool isPrimaryHeader( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XText >& xCurrentText ) throw (css::uno::RuntimeException); static sal_Bool isPrimaryFooter( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XText >& xCurrentText ) throw (css::uno::RuntimeException); diff --git a/sw/source/ui/vba/vbaparagraph.cxx b/sw/source/ui/vba/vbaparagraph.cxx index 333fd4ca9a98..61b78f1a330f 100644 --- a/sw/source/ui/vba/vbaparagraph.cxx +++ b/sw/source/ui/vba/vbaparagraph.cxx @@ -48,6 +48,20 @@ SwVbaParagraph::getRange( ) throw ( uno::RuntimeException ) return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, mxTextRange->getStart(), mxTextRange->getEnd(), mxTextRange->getText(), sal_True ) ); } +uno::Any SAL_CALL +SwVbaParagraph::getStyle( ) throw ( uno::RuntimeException ) +{ + uno::Reference< word::XRange > xRange = getRange(); + return xRange->getStyle(); +} + +void SAL_CALL +SwVbaParagraph::setStyle( const uno::Any& style ) throw ( uno::RuntimeException ) +{ + uno::Reference< word::XRange > xRange = getRange(); + xRange->setStyle( style ); +} + rtl::OUString& SwVbaParagraph::getServiceImplName() { diff --git a/sw/source/ui/vba/vbaparagraph.hxx b/sw/source/ui/vba/vbaparagraph.hxx index 894ac61cc7e6..6e299c7d6f9f 100644 --- a/sw/source/ui/vba/vbaparagraph.hxx +++ b/sw/source/ui/vba/vbaparagraph.hxx @@ -50,6 +50,8 @@ public: // XParagraph virtual css::uno::Reference< ooo::vba::word::XRange > SAL_CALL getRange() throw ( css::uno::RuntimeException ); + virtual css::uno::Any SAL_CALL getStyle() throw ( css::uno::RuntimeException ); + virtual void SAL_CALL setStyle( const css::uno::Any& style ) throw ( css::uno::RuntimeException ); // XHelperInterface virtual rtl::OUString& getServiceImplName(); diff --git a/sw/source/ui/vba/vbaparagraphformat.cxx b/sw/source/ui/vba/vbaparagraphformat.cxx index 07a822ad5752..5f28bfe21938 100644 --- a/sw/source/ui/vba/vbaparagraphformat.cxx +++ b/sw/source/ui/vba/vbaparagraphformat.cxx @@ -34,6 +34,7 @@ #include <ooo/vba/word/WdOutlineLevel.hpp> #include <com/sun/star/style/ParagraphAdjust.hpp> #include <com/sun/star/style/BreakType.hpp> +#include "vbatabstops.hxx" using namespace ::ooo::vba; @@ -200,9 +201,12 @@ sal_Int32 SAL_CALL SwVbaParagraphFormat::getOutlineLevel() throw (uno::RuntimeEx return nLevel; } -void SAL_CALL SwVbaParagraphFormat::setOutlineLevel( sal_Int32 /*_outlinelevel*/ ) throw (uno::RuntimeException) +void SAL_CALL SwVbaParagraphFormat::setOutlineLevel( sal_Int32 _outlinelevel ) throw (uno::RuntimeException) { - throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + if( _outlinelevel != getOutlineLevel() ) + { + // TODO: in my test in msword, there is no effect for this function. + } } uno::Any SAL_CALL SwVbaParagraphFormat::getPageBreakBefore() throw (uno::RuntimeException) @@ -296,7 +300,7 @@ void SAL_CALL SwVbaParagraphFormat::setRightIndent( float _rightindent ) throw ( uno::Any SAL_CALL SwVbaParagraphFormat::getTabStops() throw (uno::RuntimeException) { - throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + return uno::makeAny( uno::Reference< word::XTabStops >( new SwVbaTabStops( this, mxContext, mxParaProps ) ) ); } void SAL_CALL SwVbaParagraphFormat::setTabStops( const uno::Any& /*_tabstops*/ ) throw (uno::RuntimeException) diff --git a/sw/source/ui/vba/vbarange.cxx b/sw/source/ui/vba/vbarange.cxx index 647aedb34791..9c70f6f8cf95 100644 --- a/sw/source/ui/vba/vbarange.cxx +++ b/sw/source/ui/vba/vbarange.cxx @@ -32,12 +32,21 @@ #include <com/sun/star/style/BreakType.hpp> #include <com/sun/star/text/ControlCharacter.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> -#include "wordvbahelper.hxx" +#include <com/sun/star/text/XTextRangeCompare.hpp> +#include <com/sun/star/text/XWordCursor.hpp> +#include <com/sun/star/text/XParagraphCursor.hpp> +#include <ooo/vba/word/WdUnits.hpp> +#include <ooo/vba/word/WdMovementType.hpp> #include "vbaparagraphformat.hxx" #include "vbastyle.hxx" #include "vbafont.hxx" #include "vbapalette.hxx" #include "vbapagesetup.hxx" +#include "vbalistformat.hxx" +#include "vbarevisions.hxx" +#include "vbabookmarks.hxx" +#include "vbasections.hxx" +#include "vbafield.hxx" using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -70,6 +79,8 @@ void SwVbaRange::initialize( const uno::Reference< text::XTextRange >& rStart, c } mxTextCursor = SwVbaRangeHelper::initCursor( rStart, mxText ); + if( !mxTextCursor.is() ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Fails to create text cursor") ), uno::Reference< uno::XInterface >() ); mxTextCursor->collapseToStart(); if( rEnd.is() ) @@ -90,6 +101,67 @@ void SwVbaRange::setXTextRange( const uno::Reference< text::XTextRange >& xRange mxTextCursor->gotoRange( xRange->getStart(), sal_False ); mxTextCursor->gotoRange( xRange->getEnd(), sal_True ); } + +void +SwVbaRange::Move( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend, word::E_DIRECTION eDirection ) throw ( uno::RuntimeException ) +{ + sal_Int32 nUnit = word::WdUnits::wdCharacter; + sal_Int32 nCount = 1; + sal_Int32 nExtend = word::WdMovementType::wdMove; + + if( _unit.hasValue() ) + _unit >>= nUnit; + if( _count.hasValue() ) + _count >>= nCount; + if( _extend.hasValue() ) + _extend >>= nExtend; + + if( nCount == 0 ) + return; + + sal_Bool bExpand = ( nExtend == word::WdMovementType::wdMove ) ? sal_False : sal_True; + + switch( nUnit ) + { + case word::WdUnits::wdParagraph: + { + if( eDirection == word::MOVE_LEFT || eDirection == word::MOVE_RIGHT ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + uno::Reference< text::XParagraphCursor > xParagraphCursor( mxTextCursor, uno::UNO_QUERY_THROW ); + for( sal_Int32 i=0; i<nCount; i++ ) + { + if( ( eDirection == word::MOVE_UP ) && ( xParagraphCursor->gotoPreviousParagraph( bExpand ) == sal_False ) ) + break; + else if( ( eDirection == word::MOVE_DOWN ) && ( xParagraphCursor->gotoNextParagraph( bExpand ) == sal_False ) ) + break; + } + break; + } + case word::WdUnits::wdWord: + { + if( eDirection == word::MOVE_UP || eDirection == word::MOVE_DOWN ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + uno::Reference< text::XWordCursor > xWordCursor( mxTextCursor, uno::UNO_QUERY_THROW ); + for( sal_Int32 i=0; i<nCount; i++ ) + { + if( (eDirection == word::MOVE_LEFT ) && ( xWordCursor->gotoPreviousWord( bExpand ) == sal_False ) ) + break; + else if( ( eDirection == word::MOVE_RIGHT ) && ( xWordCursor->gotoNextWord( bExpand ) == sal_False ) ) + break; + } + break; + } + default: + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + break; + } + } +} #endif /** * The complexity in this method is because we need to workaround @@ -128,17 +200,46 @@ SwVbaRange::getText() throw ( uno::RuntimeException ) void SAL_CALL SwVbaRange::setText( const rtl::OUString& rText ) throw ( uno::RuntimeException ) { + // Emulate the MSWord behavior, Don't delete the bookmark + // which contains no text string in current inserting position, + rtl::OUString sName; + uno::Reference< text::XTextRange > xRange( mxTextCursor, uno::UNO_QUERY_THROW ); + try + { + uno::Reference< text::XTextContent > xBookmark = SwVbaRangeHelper::findBookmarkByPosition( mxTextDocument, xRange->getStart() ); + if( xBookmark.is() ) + { + uno::Reference< container::XNamed > xNamed( xBookmark, uno::UNO_QUERY_THROW ); + sName = xNamed->getName(); + } + } + catch( uno::Exception& ) + { + // do nothing + } + if( rText.indexOf( '\n' ) != -1 ) { mxTextCursor->setString( rtl::OUString() ); // process CR in strings - uno::Reference< text::XTextRange > xRange( mxTextCursor, uno::UNO_QUERY_THROW ); SwVbaRangeHelper::insertString( xRange, mxText, rText, sal_True ); } else { mxTextCursor->setString( rText ); } + + // insert the bookmark if the bookmark is deleted during setting text string + if( sName.getLength() ) + { + uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( mxTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xNameAccess( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW ); + if( !xNameAccess->hasByName( sName ) ) + { + uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW ); + SwVbaBookmarks::addBookmarkByName( xModel, sName, xRange->getStart() ); + } + } } // FIXME: test is not pass @@ -229,11 +330,8 @@ SwVbaRange::setParagraphFormat( const uno::Reference< word::XParagraphFormat >& throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); } -uno::Reference< word::XStyle > SAL_CALL -SwVbaRange::getStyle() throw ( uno::RuntimeException ) +void SwVbaRange::GetStyleInfo(rtl::OUString& aStyleName, rtl::OUString& aStyleType ) throw ( uno::RuntimeException ) { - rtl::OUString aStyleName; - rtl::OUString aStyleType; uno::Reference< beans::XPropertySet > xProp( mxTextCursor, uno::UNO_QUERY_THROW ); if( ( xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharStyleName") ) ) >>= aStyleName ) && aStyleName.getLength() ) { @@ -247,14 +345,23 @@ SwVbaRange::getStyle() throw ( uno::RuntimeException ) { DebugHelper::exception( SbERR_INTERNAL_ERROR, rtl::OUString() ); } +} + +uno::Any SAL_CALL +SwVbaRange::getStyle() throw ( uno::RuntimeException ) +{ + rtl::OUString aStyleName; + rtl::OUString aStyleType; + GetStyleInfo( aStyleName, aStyleType ); uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxTextDocument, uno::UNO_QUERY_THROW); uno::Reference< container::XNameAccess > xStylesAccess( xStyleSupplier->getStyleFamilies()->getByName( aStyleType ), uno::UNO_QUERY_THROW ); uno::Reference< beans::XPropertySet > xStyleProps( xStylesAccess->getByName( aStyleName ), uno::UNO_QUERY_THROW ); - return uno::Reference< word::XStyle >( new SwVbaStyle( this, mxContext, xStyleProps ) ); + uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< word::XStyle >( new SwVbaStyle( this, mxContext, xModel, xStyleProps ) ) ); } void SAL_CALL -SwVbaRange::setStyle( const uno::Reference< word::XStyle >& rStyle ) throw ( uno::RuntimeException ) +SwVbaRange::setStyle( const uno::Any& rStyle ) throw ( uno::RuntimeException ) { uno::Reference< beans::XPropertySet > xParaProps( mxTextCursor, uno::UNO_QUERY_THROW ); SwVbaStyle::setStyle( xParaProps, rStyle ); @@ -267,6 +374,12 @@ SwVbaRange::getFont() throw ( uno::RuntimeException ) return new SwVbaFont( mxParent, mxContext, aColors.getPalette(), uno::Reference< beans::XPropertySet >( getXTextRange(), uno::UNO_QUERY_THROW ) ); } +uno::Reference< word::XListFormat > SAL_CALL +SwVbaRange::getListFormat() throw ( uno::RuntimeException ) +{ + return uno::Reference< word::XListFormat >( new SwVbaListFormat( this, mxContext, getXTextRange() ) ); +} + ::sal_Int32 SAL_CALL SwVbaRange::getLanguageID() throw (uno::RuntimeException) { uno::Reference< beans::XPropertySet > xParaProps( mxTextCursor, uno::UNO_QUERY_THROW ); @@ -324,6 +437,50 @@ void SAL_CALL SwVbaRange::setEnd( ::sal_Int32 _end ) throw (uno::RuntimeExceptio mxTextCursor->gotoRange( xEnd, sal_True ); } +::sal_Bool SAL_CALL SwVbaRange::InRange( const uno::Reference< ::ooo::vba::word::XRange >& Range ) throw (uno::RuntimeException) +{ + SwVbaRange* pRange = dynamic_cast< SwVbaRange* >( Range.get() ); + if( !pRange ) + throw uno::RuntimeException(); + uno::Reference< text::XTextRange > xTextRange = pRange->getXTextRange(); + uno::Reference< text::XTextRangeCompare > xTRC( mxTextCursor->getText(), uno::UNO_QUERY_THROW ); + if( xTRC->compareRegionStarts( xTextRange, getXTextRange() ) >= 0 && xTRC->compareRegionEnds( xTextRange, getXTextRange() ) <= 0 ) + return sal_True; + return sal_False; +} + +uno::Any SAL_CALL +SwVbaRange::Revisions( const uno::Any& index ) throw (uno::RuntimeException) +{ + uno::Reference< text::XTextRange > xTextRange = getXTextRange(); + uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xCol( new SwVbaRevisions( mxParent, mxContext, xModel, xTextRange ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + +uno::Any SAL_CALL +SwVbaRange::Sections( const uno::Any& index ) throw (uno::RuntimeException) +{ + uno::Reference< text::XTextRange > xTextRange = getXTextRange(); + uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xCol( new SwVbaSections( mxParent, mxContext, xModel, xTextRange ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + +uno::Any SAL_CALL +SwVbaRange::Fields( const uno::Any& index ) throw (uno::RuntimeException) +{ + //FIXME: should be get the field in current range + uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, xModel ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} rtl::OUString& SwVbaRange::getServiceImplName() { diff --git a/sw/source/ui/vba/vbarange.hxx b/sw/source/ui/vba/vbarange.hxx index 1f1b3a3bbc8b..c74ef3487f5a 100644 --- a/sw/source/ui/vba/vbarange.hxx +++ b/sw/source/ui/vba/vbarange.hxx @@ -35,6 +35,8 @@ #include <com/sun/star/text/XTextRange.hpp> #include <com/sun/star/text/XTextDocument.hpp> #include <ooo/vba/word/XStyle.hpp> +#include <ooo/vba/word/XListFormat.hpp> +#include "wordvbahelper.hxx" typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XRange > SwVbaRange_BASE; @@ -48,6 +50,7 @@ private: private: void initialize( const css::uno::Reference< css::text::XTextRange >& rStart, const css::uno::Reference< css::text::XTextRange >& rEnd ) throw (css::uno::RuntimeException); + void GetStyleInfo(rtl::OUString& aStyleName, rtl::OUString& aStyleType ) throw ( css::uno::RuntimeException ); public: SwVbaRange( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextDocument >& rTextDocument, const css::uno::Reference< css::text::XTextRange >& rStart, sal_Bool _bMaySpanEndOfDocument = sal_False ) throw (css::uno::RuntimeException); SwVbaRange( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextDocument >& rTextDocument, const css::uno::Reference< css::text::XTextRange >& rStart, const css::uno::Reference< css::text::XTextRange >& rEnd, sal_Bool _bMaySpanEndOfDocument = sal_False ) throw (css::uno::RuntimeException); @@ -61,16 +64,18 @@ public: #endif css::uno::Reference< css::text::XText > getXText() { return mxText; } void setXTextCursor( const css::uno::Reference< css::text::XTextCursor >& xTextCursor ) { mxTextCursor = xTextCursor; } + void Move( const css::uno::Any& _unit, const css::uno::Any& _count, const css::uno::Any& _extend, ooo::vba::word::E_DIRECTION eDirection ) throw (css::uno::RuntimeException); // Attribute virtual rtl::OUString SAL_CALL getText() throw (css::uno::RuntimeException); virtual void SAL_CALL setText( const rtl::OUString& rText ) throw (css::uno::RuntimeException); virtual css::uno::Reference< ooo::vba::word::XParagraphFormat > SAL_CALL getParagraphFormat() throw (css::uno::RuntimeException); virtual void SAL_CALL setParagraphFormat( const css::uno::Reference< ooo::vba::word::XParagraphFormat >& rParagraphFormat ) throw (css::uno::RuntimeException); - virtual css::uno::Reference< ooo::vba::word::XStyle > SAL_CALL getStyle() throw (css::uno::RuntimeException); - virtual void SAL_CALL setStyle( const css::uno::Reference< ooo::vba::word::XStyle >& _xStyle ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStyle( const css::uno::Any& _xStyle ) throw (css::uno::RuntimeException); virtual css::uno::Reference< ooo::vba::word::XFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ooo::vba::word::XListFormat > SAL_CALL getListFormat() throw (css::uno::RuntimeException); // Methods virtual void SAL_CALL InsertBreak( const css::uno::Any& _breakType ) throw (css::uno::RuntimeException); virtual void SAL_CALL Select() throw (css::uno::RuntimeException); @@ -84,6 +89,10 @@ public: virtual void SAL_CALL setStart( ::sal_Int32 _start ) throw (css::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getEnd() throw (css::uno::RuntimeException); virtual void SAL_CALL setEnd( ::sal_Int32 _end ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL InRange( const css::uno::Reference< ::ooo::vba::word::XRange >& Range ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Revisions( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Sections( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Fields( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); // XHelperInterface virtual rtl::OUString& getServiceImplName(); diff --git a/sw/source/ui/vba/vbarangehelper.cxx b/sw/source/ui/vba/vbarangehelper.cxx index 4fd9e5f143f1..d121cb483825 100644 --- a/sw/source/ui/vba/vbarangehelper.cxx +++ b/sw/source/ui/vba/vbarangehelper.cxx @@ -27,6 +27,7 @@ #include "vbarangehelper.hxx" #include <com/sun/star/text/ControlCharacter.hpp> #include <com/sun/star/text/XTextRangeCompare.hpp> +#include <com/sun/star/text/XBookmarksSupplier.hpp> using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -111,7 +112,7 @@ uno::Reference< text::XTextCursor > SwVbaRangeHelper::initCursor( const uno::Ref DebugHelper::exception(e); } - if( !bGotTextCursor ) + if( !bGotTextCursor || !xTextCursor.is() ) { try { @@ -125,7 +126,7 @@ uno::Reference< text::XTextCursor > SwVbaRangeHelper::initCursor( const uno::Ref } } - if( !bGotTextCursor ) + if( !bGotTextCursor || !xTextCursor.is() ) { try { @@ -169,3 +170,29 @@ sal_Int32 SwVbaRangeHelper::getPosition( const uno::Reference< text::XText >& rT return nPosition; } + +uno::Reference< text::XTextContent > SwVbaRangeHelper::findBookmarkByPosition( const uno::Reference< text::XTextDocument >& xTextDoc, const uno::Reference< text::XTextRange >& xTextRange ) throw ( css::uno::RuntimeException ) +{ + uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( xTextDoc, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xIndexAccess( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW ); + for( sal_Int32 index = 0; index < xIndexAccess->getCount(); index++ ) + { + uno::Reference< text::XTextContent > xBookmark( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRange > xBkAnchor = xBookmark->getAnchor(); + uno::Reference< text::XTextRangeCompare > xCompare( xBkAnchor->getText(), uno::UNO_QUERY_THROW ); + if( xCompare->compareRegionStarts( xBkAnchor->getStart(), xBkAnchor->getEnd() ) == 0 ) + { + try + { + if( xCompare->compareRegionStarts( xTextRange, xBkAnchor->getStart() ) == 0 ) + return xBookmark; + } + catch( uno::Exception& ) + { + continue; + } + } + } + return uno::Reference< text::XTextContent >(); +} + diff --git a/sw/source/ui/vba/vbarangehelper.hxx b/sw/source/ui/vba/vbarangehelper.hxx index 71bdf20f94a2..89eeb0c152fb 100644 --- a/sw/source/ui/vba/vbarangehelper.hxx +++ b/sw/source/ui/vba/vbarangehelper.hxx @@ -30,6 +30,8 @@ #include <vbahelper/vbahelperinterface.hxx> #include <com/sun/star/text/XTextViewCursor.hpp> #include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/text/XTextDocument.hpp> class SwVbaRangeHelper { @@ -38,6 +40,7 @@ public: static void insertString( css::uno::Reference< css::text::XTextRange >& rTextRange, css::uno::Reference< css::text::XText >& rText, const rtl::OUString& rStr, sal_Bool _bAbsorb ) throw ( css::uno::RuntimeException ); static css::uno::Reference< css::text::XTextCursor > initCursor( const css::uno::Reference< css::text::XTextRange >& rTextRange, const css::uno::Reference< css::text::XText >& rText ) throw ( css::uno::RuntimeException ); static sal_Int32 getPosition( const css::uno::Reference< css::text::XText >& rText, const css::uno::Reference< css::text::XTextRange >& rTextRange ) throw ( css::uno::RuntimeException ); + static css::uno::Reference< css::text::XTextContent > findBookmarkByPosition( const css::uno::Reference< css::text::XTextDocument >& xTextDoc, const css::uno::Reference< css::text::XTextRange >& xTextRange ) throw ( css::uno::RuntimeException ); }; #endif /* SW_VBA_RANGEHELPER_HXX */ diff --git a/sw/source/ui/vba/vbareplacement.cxx b/sw/source/ui/vba/vbareplacement.cxx index 81f2bb193412..226cc53c6246 100644 --- a/sw/source/ui/vba/vbareplacement.cxx +++ b/sw/source/ui/vba/vbareplacement.cxx @@ -50,6 +50,12 @@ void SAL_CALL SwVbaReplacement::setText( const ::rtl::OUString& _text ) throw (u mxPropertyReplace->setReplaceString( _text ); } +void SAL_CALL SwVbaReplacement::ClearFormatting( ) throw (uno::RuntimeException) +{ + uno::Sequence< beans::PropertyValue > aPropValues; + mxPropertyReplace->setReplaceAttributes( aPropValues ); +} + rtl::OUString& SwVbaReplacement::getServiceImplName() { diff --git a/sw/source/ui/vba/vbareplacement.hxx b/sw/source/ui/vba/vbareplacement.hxx index b257fb7a3abc..e67896f69d1f 100644 --- a/sw/source/ui/vba/vbareplacement.hxx +++ b/sw/source/ui/vba/vbareplacement.hxx @@ -47,6 +47,9 @@ public: virtual ::rtl::OUString SAL_CALL getText() throw (css::uno::RuntimeException); virtual void SAL_CALL setText( const ::rtl::OUString& _text ) throw (css::uno::RuntimeException); + //Methods + virtual void SAL_CALL ClearFormatting() throw (css::uno::RuntimeException); + // XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); diff --git a/sw/source/ui/vba/vbasection.cxx b/sw/source/ui/vba/vbasection.cxx index 2e685fbb1676..62715f2886a0 100644 --- a/sw/source/ui/vba/vbasection.cxx +++ b/sw/source/ui/vba/vbasection.cxx @@ -28,6 +28,7 @@ #include <vbahelper/vbahelper.hxx> #include <tools/diagnose_ex.h> #include "vbapagesetup.hxx" +#include "vbaheadersfooters.hxx" using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -50,14 +51,20 @@ void SAL_CALL SwVbaSection::setProtectedForForms( ::sal_Bool /*_protectedforform { } -uno::Any SAL_CALL SwVbaSection::Headers( ) throw (uno::RuntimeException) +uno::Any SAL_CALL SwVbaSection::Headers( const uno::Any& index ) throw (uno::RuntimeException) { - return uno::Any(); + uno::Reference< XCollection > xCol( new SwVbaHeadersFooters( this, mxContext, mxModel, mxPageProps, sal_True ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); } -uno::Any SAL_CALL SwVbaSection::Footers( ) throw (uno::RuntimeException) +uno::Any SAL_CALL SwVbaSection::Footers( const uno::Any& index ) throw (uno::RuntimeException) { - return uno::Any(); + uno::Reference< XCollection > xCol( new SwVbaHeadersFooters( this, mxContext, mxModel, mxPageProps, sal_False ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); } uno::Any SAL_CALL diff --git a/sw/source/ui/vba/vbasection.hxx b/sw/source/ui/vba/vbasection.hxx index 90a2972c2f52..e13af7fa0ee3 100644 --- a/sw/source/ui/vba/vbasection.hxx +++ b/sw/source/ui/vba/vbasection.hxx @@ -48,8 +48,8 @@ public: virtual void SAL_CALL setProtectedForForms( ::sal_Bool _protectedforforms ) throw (css::uno::RuntimeException); // Methods - virtual css::uno::Any SAL_CALL Headers( ) throw (css::uno::RuntimeException); - virtual css::uno::Any SAL_CALL Footers( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Headers( const css::uno::Any& index ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Footers( const css::uno::Any& index ) throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL PageSetup( ) throw (css::uno::RuntimeException); // XHelperInterface diff --git a/sw/source/ui/vba/vbasections.cxx b/sw/source/ui/vba/vbasections.cxx index c0f887f0f249..983fac9a98b9 100644 --- a/sw/source/ui/vba/vbasections.cxx +++ b/sw/source/ui/vba/vbasections.cxx @@ -87,6 +87,15 @@ public: } } + SectionCollectionHelper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ) throw (uno::RuntimeException) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel ) + { + // Hacky implementation of Range.Sections, only support 1 secction + uno::Reference< beans::XPropertySet > xRangeProps( xTextRange, uno::UNO_QUERY_THROW ); + uno::Reference< style::XStyle > xStyle = word::getCurrentPageStyle( mxModel, xRangeProps ); + uno::Reference< beans::XPropertySet > xPageProps( xStyle, uno::UNO_QUERY_THROW ); + mxSections.push_back( xPageProps ); + } + ~SectionCollectionHelper(){} // XIndexAccess @@ -134,6 +143,10 @@ SwVbaSections::SwVbaSections( const uno::Reference< XHelperInterface >& xParent, { } +SwVbaSections::SwVbaSections( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ): SwVbaSections_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new SectionCollectionHelper( xParent, xContext, xModel, xTextRange ) ) ), mxModel( xModel ) +{ +} + uno::Any SAL_CALL SwVbaSections::PageSetup( ) throw (uno::RuntimeException) { diff --git a/sw/source/ui/vba/vbasections.hxx b/sw/source/ui/vba/vbasections.hxx index 3204689af5d8..8304de445c1a 100644 --- a/sw/source/ui/vba/vbasections.hxx +++ b/sw/source/ui/vba/vbasections.hxx @@ -31,6 +31,7 @@ #include <ooo/vba/word/XSections.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> #include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/text/XTextRange.hpp> #include <vbahelper/vbahelperinterface.hxx> typedef CollTestImplHelper< ooo::vba::word::XSections > SwVbaSections_BASE; @@ -42,6 +43,7 @@ private: public: SwVbaSections( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::frame::XModel >& xModel ); + SwVbaSections( 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::text::XTextRange >& xTextRange ); virtual ~SwVbaSections() {} // XEnumerationAccess diff --git a/sw/source/ui/vba/vbaselection.cxx b/sw/source/ui/vba/vbaselection.cxx index 620e44fa413b..f393519c894a 100644 --- a/sw/source/ui/vba/vbaselection.cxx +++ b/sw/source/ui/vba/vbaselection.cxx @@ -29,7 +29,6 @@ #include <tools/diagnose_ex.h> #include "vbarange.hxx" #include "vbafind.hxx" -#include "wordvbahelper.hxx" #include <com/sun/star/text/XTextRange.hpp> #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextTableCursor.hpp> @@ -41,14 +40,19 @@ #include <ooo/vba/word/WdGoToDirection.hpp> #include <ooo/vba/word/XBookmark.hpp> #include <ooo/vba/word/XApplication.hpp> +#include <ooo/vba/word/WdCollapseDirection.hpp> #include <com/sun/star/text/XPageCursor.hpp> #include "unotbl.hxx" #include "unocoll.hxx" #include "vbatable.hxx" #include <com/sun/star/view/XSelectionSupplier.hpp> #include <com/sun/star/view/XViewCursor.hpp> +#include <com/sun/star/view/XLineCursor.hpp> +#include <com/sun/star/text/XWordCursor.hpp> +#include <com/sun/star/text/XParagraphCursor.hpp> #include <ooo/vba/word/WdInformation.hpp> #include <ooo/vba/word/WdHeaderFooterIndex.hpp> +#include <ooo/vba/word/WdSeekView.hpp> #include "vbainformationhelper.hxx" #include "vbafield.hxx" #include "vbaheaderfooter.hxx" @@ -56,6 +60,17 @@ #include <vbahelper/vbashaperange.hxx> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> #include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/text/ControlCharacter.hpp> +#include "vbarows.hxx" +#include "vbacolumns.hxx" +#include "vbatablehelper.hxx" +#include "vbacells.hxx" +#include "vbaview.hxx" +#include "vbaparagraph.hxx" +#include "vbastyle.hxx" +#include <docsh.hxx> +#include <tblenum.hxx> +#include <fesh.hxx> using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -123,23 +138,25 @@ SwVbaSelection::HomeKey( const uno::Any& _unit, const uno::Any& _extend ) throw sal_Int32 nExtend = word::WdMovementType::wdMove; _unit >>= nUnit; _extend >>= nExtend; + sal_Bool bExtend = ( nExtend == word::WdMovementType::wdExtend ) ? sal_True : sal_False; switch( nUnit ) { case word::WdUnits::wdStory: { + // go to the valid text first so that the current view cursor is valid to call gotoRange. + word::gotoSelectedObjectAnchor(mxModel); // go to the begin of the document - rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToStartOfDoc")); - dispatchRequests( mxModel,url ); - // If something is selected, it needs to go twice - dispatchRequests( mxModel,url ); + uno::Reference< text::XText > xCurrentText = word::getCurrentXText( mxModel ); + uno::Reference< text::XTextRange > xFirstRange = word::getFirstObjectPosition( xCurrentText ); + mxTextViewCursor->gotoRange( xFirstRange, bExtend ); break; } case word::WdUnits::wdLine: { // go to the begin of the Line - rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToStartOfLine")); - dispatchRequests( mxModel,url ); + uno::Reference< view::XLineCursor > xLineCursor( mxTextViewCursor, uno::UNO_QUERY_THROW ); + xLineCursor->gotoStartOfLine( bExtend ); break; } default: @@ -157,23 +174,25 @@ SwVbaSelection::EndKey( const uno::Any& _unit, const uno::Any& _extend ) throw ( sal_Int32 nExtend = word::WdMovementType::wdMove; _unit >>= nUnit; _extend >>= nExtend; + sal_Bool bExtend = ( nExtend == word::WdMovementType::wdExtend ) ? sal_True : sal_False; switch( nUnit ) { case word::WdUnits::wdStory: { + // go to the valid text first so that the current view cursor is valid to call gotoRange. + word::gotoSelectedObjectAnchor(mxModel); // go to the end of the document - rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToEndOfDoc")); - dispatchRequests( mxModel,url ); - // If something is selected, it needs to go twice - dispatchRequests( mxModel,url ); + uno::Reference< text::XText > xCurrentText = word::getCurrentXText( mxModel ); + uno::Reference< text::XTextRange > xEnd = xCurrentText->getEnd(); + mxTextViewCursor->gotoRange( xEnd, bExtend ); break; } case word::WdUnits::wdLine: { // go to the end of the Line - rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToEndOfLine")); - dispatchRequests( mxModel,url ); + uno::Reference< view::XLineCursor > xLineCursor( mxTextViewCursor, uno::UNO_QUERY_THROW ); + xLineCursor->gotoEndOfLine( bExtend ); break; } default: @@ -185,14 +204,161 @@ SwVbaSelection::EndKey( const uno::Any& _unit, const uno::Any& _extend ) throw ( } void SAL_CALL -SwVbaSelection::Delete( const uno::Any& /*_unit*/, const uno::Any& /*_count*/ ) throw ( uno::RuntimeException ) +SwVbaSelection::Delete( const uno::Any& _unit, const uno::Any& _count ) throw ( uno::RuntimeException ) { - // FIXME: handle the arguments: _unit and _count + sal_Int32 nUnit = word::WdUnits::wdLine; + sal_Int32 nCount = 0; + if( _count.hasValue() ) + _count >>= nCount; + if( _unit.hasValue() && ( nCount > 0 ) ) + { + _unit >>= nUnit; + switch( nUnit ) + { + case word::WdUnits::wdCharacter: + { + if( HasSelection() ) + nCount--; + mxTextViewCursor->goRight( nCount, sal_True ); + break; + } + default: + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + } + } rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Delete")); dispatchRequests( mxModel,url ); } -void SwVbaSelection::NextCell( sal_Int32 nCount, E_DIRECTION eDirection ) throw ( uno::RuntimeException ) +void +SwVbaSelection::Move( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend, word::E_DIRECTION eDirection ) throw ( uno::RuntimeException ) +{ + sal_Int32 nUnit = word::WdUnits::wdCharacter; + sal_Int32 nCount = 1; + sal_Int32 nExtend = word::WdMovementType::wdMove; + + if( _unit.hasValue() ) + _unit >>= nUnit; + if( _count.hasValue() ) + _count >>= nCount; + if( _extend.hasValue() ) + _extend >>= nExtend; + + if( nCount == 0 ) + return; + + sal_Bool bExpand = ( nExtend == word::WdMovementType::wdMove ) ? sal_False : sal_True; + + switch( nUnit ) + { + case word::WdUnits::wdCell: + { + if( nExtend == word::WdMovementType::wdExtend ) + { + DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString()); + return; + } + NextCell( nCount, eDirection ); + break; + } + case word::WdUnits::wdLine: + { + if( eDirection == word::MOVE_LEFT || eDirection == word::MOVE_RIGHT ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + uno::Reference< view::XViewCursor > xViewCursor( mxTextViewCursor, uno::UNO_QUERY_THROW ); + if( eDirection == word::MOVE_UP ) + xViewCursor->goUp( nCount, bExpand ); + else if( eDirection == word::MOVE_DOWN ) + xViewCursor->goDown( nCount, bExpand ); + break; + } + case word::WdUnits::wdCharacter: + { + if( eDirection == word::MOVE_UP || eDirection == word::MOVE_DOWN ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + if( word::gotoSelectedObjectAnchor( mxModel ) ) + { + nCount--; + } + uno::Reference< view::XViewCursor > xViewCursor( mxTextViewCursor, uno::UNO_QUERY_THROW ); + if( eDirection == word::MOVE_LEFT ) + { + // if current select is a cellrange or table, + // the first count of move should move to the first selected cell. + uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY ); + if ( xTextTableCursor.is() ) + { + uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextTable > xTextTable; + xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable; + if( xTextTable.is() ) + { + uno::Reference< text::XTextRange > xRange( xTextTable->getCellByName( xTextTableCursor->getRangeName()), uno::UNO_QUERY_THROW ); + mxTextViewCursor->gotoRange( xRange->getStart(), bExpand ); + nCount--; + } + } + xViewCursor->goLeft( nCount, bExpand ); + } + else if( eDirection == word::MOVE_RIGHT ) + xViewCursor->goRight( nCount, bExpand ); + break; + } + case word::WdUnits::wdWord: + case word::WdUnits::wdParagraph: + { + uno::Reference< text::XTextRange > xRange = GetSelectedRange(); + uno::Reference< text::XText > xText = xRange->getText(); + uno::Reference< text::XTextCursor > xTextCursor = xText->createTextCursorByRange( xRange ); + if( nUnit == word::WdUnits::wdParagraph ) + { + if( eDirection == word::MOVE_LEFT || eDirection == word::MOVE_RIGHT ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + uno::Reference< text::XParagraphCursor > xParagraphCursor( xTextCursor, uno::UNO_QUERY_THROW ); + for( sal_Int32 i=0; i<nCount; i++ ) + { + if( ( eDirection == word::MOVE_UP ) && ( xParagraphCursor->gotoPreviousParagraph( bExpand ) == sal_False ) ) + break; + else if( ( eDirection == word::MOVE_DOWN ) && ( xParagraphCursor->gotoNextParagraph( bExpand ) == sal_False ) ) + break; + } + } + else if( nUnit == word::WdUnits::wdWord ) + { + if( eDirection == word::MOVE_UP || eDirection == word::MOVE_DOWN ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + uno::Reference< text::XWordCursor > xWordCursor( xTextCursor, uno::UNO_QUERY_THROW ); + for( sal_Int32 i=0; i<nCount; i++ ) + { + if( (eDirection == word::MOVE_LEFT ) && ( xWordCursor->gotoPreviousWord( bExpand ) == sal_False ) ) + break; + else if( ( eDirection == word::MOVE_RIGHT ) && ( xWordCursor->gotoNextWord( bExpand ) == sal_False ) ) + break; + } + } + mxTextViewCursor->gotoRange( xTextCursor->getStart(), sal_False ); + mxTextViewCursor->gotoRange( xTextCursor->getEnd(), sal_True ); + break; + } + default: + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + break; + } + } +} + +void SwVbaSelection::NextCell( sal_Int32 nCount, word::E_DIRECTION eDirection ) throw ( uno::RuntimeException ) { uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW ); uno::Reference< text::XTextTable > xTextTable; @@ -211,22 +377,22 @@ void SwVbaSelection::NextCell( sal_Int32 nCount, E_DIRECTION eDirection ) throw // move the table cursor switch( eDirection ) { - case MOVE_LEFT: + case word::MOVE_LEFT: { xTextTableCursor->goLeft( nCount, sal_False ); break; } - case MOVE_RIGHT: + case word::MOVE_RIGHT: { xTextTableCursor->goRight( nCount, sal_False ); break; } - case MOVE_UP: + case word::MOVE_UP: { xTextTableCursor->goUp( nCount, sal_False ); break; } - case MOVE_DOWN: + case word::MOVE_DOWN: { xTextTableCursor->goDown( nCount, sal_False ); break; @@ -245,61 +411,29 @@ void SwVbaSelection::NextCell( sal_Int32 nCount, E_DIRECTION eDirection ) throw void SAL_CALL SwVbaSelection::MoveRight( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend ) throw ( uno::RuntimeException ) { - sal_Int32 nUnit = word::WdUnits::wdCharacter; sal_Int32 nCount = 1; - sal_Int32 nExtend = word::WdMovementType::wdMove; - if( _unit.hasValue() ) - _unit >>= nUnit; if( _count.hasValue() ) _count >>= nCount; - if( _extend.hasValue() ) - _extend >>= nExtend; if( nCount == 0 ) return; if( nCount < 0 ) { - // TODO: call MoveLeft; MoveLeft( _unit, uno::makeAny( -nCount ), _extend ); return; } - switch( nUnit ) - { - case word::WdUnits::wdCell: - { - if( nExtend == word::WdMovementType::wdExtend ) - { - DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString()); - return; - } - NextCell( nCount, MOVE_RIGHT ); - break; - } - default: - { - throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); - break; - } - } - + Move( _unit, _count, _extend, word::MOVE_RIGHT ); } void SAL_CALL SwVbaSelection::MoveLeft( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend ) throw ( uno::RuntimeException ) { - sal_Int32 nUnit = word::WdUnits::wdCharacter; sal_Int32 nCount = 1; - sal_Int32 nExtend = word::WdMovementType::wdMove; - - if( _unit.hasValue() ) - _unit >>= nUnit; if( _count.hasValue() ) _count >>= nCount; - if( _extend.hasValue() ) - _extend >>= nExtend; if( nCount == 0 ) return; @@ -310,67 +444,47 @@ SwVbaSelection::MoveLeft( const uno::Any& _unit, const uno::Any& _count, const u return; } - switch( nUnit ) - { - case word::WdUnits::wdCell: - { - if( nExtend == word::WdMovementType::wdExtend ) - { - DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString()); - return; - } - NextCell( nCount, MOVE_LEFT ); - break; - } - default: - { - throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); - break; - } - } - + Move( _unit, _count, _extend, word::MOVE_LEFT ); } void SAL_CALL SwVbaSelection::MoveDown( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend ) throw ( uno::RuntimeException ) { - sal_Int32 nUnit = word::WdUnits::wdCharacter; sal_Int32 nCount = 1; - sal_Int32 nExtend = word::WdMovementType::wdMove; - if( _unit.hasValue() ) - _unit >>= nUnit; if( _count.hasValue() ) _count >>= nCount; - if( _extend.hasValue() ) - _extend >>= nExtend; if( nCount == 0 ) return; if( nCount < 0 ) { - // TODO: call MoveLeft; - //MoveUp( _unit, uno::makeAny( -nCount ), _extend ); + MoveUp( _unit, uno::makeAny( -nCount ), _extend ); return; } - switch( nUnit ) + Move( _unit, _count, _extend, word::MOVE_DOWN ); +} + +void SAL_CALL +SwVbaSelection::MoveUp( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend ) throw ( uno::RuntimeException ) +{ + sal_Int32 nCount = 1; + + if( _count.hasValue() ) + _count >>= nCount; + + if( nCount == 0 ) + return; + + if( nCount < 0 ) { - case word::WdUnits::wdLine: - { - uno::Reference< view::XViewCursor > xViewCursor( mxTextViewCursor, uno::UNO_QUERY_THROW ); - sal_Bool bExpand = ( nExtend == word::WdMovementType::wdMove ) ? sal_False : sal_True; - xViewCursor->goDown( nCount, bExpand ); - break; - } - default: - { - throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); - break; - } + MoveDown( _unit, uno::makeAny( -nCount ), _extend ); + return; } + Move( _unit, _count, _extend, word::MOVE_UP ); } void SAL_CALL @@ -422,16 +536,17 @@ SwVbaSelection::getFind() throw ( uno::RuntimeException ) return uno::Reference< word::XFind >( new SwVbaFind( this, mxContext, mxModel, xTextRange ) ); } -uno::Reference< word::XStyle > SAL_CALL +uno::Any SAL_CALL SwVbaSelection::getStyle() throw ( uno::RuntimeException ) { return getRange()->getStyle(); } void SAL_CALL -SwVbaSelection::setStyle( const uno::Reference< word::XStyle >& rStyle ) throw ( uno::RuntimeException ) +SwVbaSelection::setStyle( const uno::Any& rStyle ) throw ( uno::RuntimeException ) { - return getRange()->setStyle( rStyle ); + uno::Reference< beans::XPropertySet > xParaProps( mxTextViewCursor, uno::UNO_QUERY_THROW ); + return SwVbaStyle::setStyle( xParaProps, rStyle ); } uno::Reference< word::XFont > SAL_CALL @@ -474,39 +589,79 @@ uno::Reference< word::XRange > SAL_CALL SwVbaSelection::GoTo( const uno::Any& _w sal_Int32 nWhich = 0; if( _which.hasValue() ) _which >>= nWhich; - sal_Int32 nPage = 0; - switch( nWhich ) - { - case word::WdGoToDirection::wdGoToLast: - { - nPage = nLastPage; - break; - } - case word::WdGoToDirection::wdGoToNext: - { - nPage = nCurrPage + 1; - break; - } - case word::WdGoToDirection::wdGoToPrevious: - { - nPage = nCurrPage - 1; - break; - } - default: - { - nPage = nCount; - } - } - if( nPage <= 0 ) - nPage = 1; - if( nPage > nLastPage ) - nPage = nLastPage; - xPageCursor->jumpToPage( ( sal_Int16 )( nPage ) ); - break; + sal_Int32 nPage = 0; + switch( nWhich ) + { + case word::WdGoToDirection::wdGoToLast: + { + nPage = nLastPage; + break; + } + case word::WdGoToDirection::wdGoToNext: + { + if( nCount !=0 ) + nPage = nCurrPage + nCount; + else + nPage = nCurrPage + 1; + break; + } + case word::WdGoToDirection::wdGoToPrevious: + { + if( nCount !=0 ) + nPage = nCurrPage - nCount; + else + nPage = nCurrPage - 1; + break; + } + default: + { + nPage = nCount; + } + } + if( _name.hasValue() ) + { + rtl::OUString sName; + _name >>= sName; + sal_Int32 nName = sName.toInt32(); + if( nName !=0 ) + nPage = nName; + } + if( nPage <= 0 ) + nPage = 1; + if( nPage > nLastPage ) + nPage = nLastPage; + xPageCursor->jumpToPage( ( sal_Int16 )( nPage ) ); + break; } case word::WdGoToItem::wdGoToSection: { - // TODO: implement Section object + uno::Reference< text::XPageCursor > xPageCursor( mxTextViewCursor, uno::UNO_QUERY_THROW ); + sal_Int32 nCount = 0; + if( _count.hasValue() ) + _count >>= nCount; + sal_Int32 nWhich = 0; + if( _which.hasValue() ) + _which >>= nWhich; + sal_Int32 nPage = 0; + switch( nWhich ) + { + case word::WdGoToDirection::wdGoToAbsolute: + { + // currently only support this type + if( nCount == 1 ) + nPage = 1; + break; + } + default: + { + nPage = 0; + } + } + if( nPage != 0 ) + xPageCursor->jumpToPage( ( sal_Int16 )( nPage ) ); + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + break; } default: throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); @@ -546,6 +701,82 @@ uno::Any SAL_CALL SwVbaSelection::Information( sal_Int32 _type ) throw (uno::Run result = uno::makeAny( SwVbaInformationHelper::handleWdVerticalPositionRelativeToPage( mxModel, mxTextViewCursor ) ); break; } + case word::WdInformation::wdWithInTable: + { + uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextTable > xTextTable; + xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable; + if( xTextTable.is() ) + result = uno::makeAny( sal_True ); + else + result = uno::makeAny( sal_False ); + break; + } + case word::WdInformation::wdHeaderFooterType: + { + uno::Reference< word::XView > xView( new SwVbaView( this, mxContext, mxModel ) ); + sal_Int32 nView = xView->getSeekView(); + sal_Int32 nHeaderFooterType = 0; + switch( nView ) + { + case word::WdSeekView::wdSeekMainDocument: + { + nHeaderFooterType = -1; // not in a header or footer + break; + } + case word::WdSeekView::wdSeekEvenPagesHeader: + { + nHeaderFooterType = 0; // even page header + break; + } + case word::WdSeekView::wdSeekPrimaryHeader: + { + nHeaderFooterType = 1; // odd page header + break; + } + case word::WdSeekView::wdSeekEvenPagesFooter: + { + nHeaderFooterType = 2; // even page footer + break; + } + case word::WdSeekView::wdSeekPrimaryFooter: + { + nHeaderFooterType = 3; // odd page footer + break; + } + case word::WdSeekView::wdSeekFirstPageHeader: + case word::WdSeekView::wdSeekFirstPageFooter: + { + uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW ); + rtl::OUString aPageStyleName; + xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))) >>= aPageStyleName; + sal_Bool bFirstPage = sal_False; + if( aPageStyleName.equalsAscii( "First Page" ) ) + bFirstPage = sal_True; + if( nView == word::WdSeekView::wdSeekFirstPageHeader ) + { + if( bFirstPage ) + nHeaderFooterType = 4; + else + nHeaderFooterType = 1; + } + else + { + if( bFirstPage ) + nHeaderFooterType = 5; + else + nHeaderFooterType = 3; + } + break; + } + default: + { + nHeaderFooterType = -1; + } + } + result = uno::makeAny( nHeaderFooterType ); + break; + } default: throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); } @@ -566,11 +797,6 @@ SwVbaSelection::Tables( const uno::Any& aIndex ) throw (uno::RuntimeException) // we can only support a selection that is a single table if ( !aIndex.hasValue() ) // currently we can't support multiple tables in a selection throw uno::RuntimeException(); - // if the current selection is a XTextTableCursor and the index is 1 then we can service this request, otherwise we just have to throw - uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY ); - - if ( !xTextTableCursor.is() ) - throw uno::RuntimeException(); sal_Int32 nIndex = 0; aIndex >>= nIndex; @@ -579,6 +805,24 @@ SwVbaSelection::Tables( const uno::Any& aIndex ) throw (uno::RuntimeException) if ( nIndex != 1 ) throw uno::RuntimeException(); + + uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextTable > xTextTable; + xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable; + if( xTextTable.is() ) + { + uno::Reference< css::text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW ); + uno::Reference< word::XTable > xVBATbl = new SwVbaTable( mxParent, mxContext, xTextDoc, xTextTable ); + aRet <<= xVBATbl; + return aRet; + } + + // if the current selection is a XTextTableCursor and the index is 1 then we can service this request, otherwise we just have to throw + uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY ); + + if ( !xTextTableCursor.is() ) + throw uno::RuntimeException(); + SwXTextTableCursor* pTTCursor = dynamic_cast< SwXTextTableCursor* >( xTextTableCursor.get() ); if ( pTTCursor ) { @@ -608,15 +852,14 @@ SwVbaSelection::Fields( const uno::Any& index ) throw (uno::RuntimeException) uno::Reference< word::XHeaderFooter > SAL_CALL SwVbaSelection::getHeaderFooter() throw ( uno::RuntimeException ) { - uno::Reference< text::XText > xCurrentText = word::getXTextViewCursor( mxModel )->getText(); - if( HeaderFooterHelper::isHeader( mxModel, xCurrentText ) || HeaderFooterHelper::isFooter( mxModel, xCurrentText ) ) + if( HeaderFooterHelper::isHeaderFooter( mxModel ) ) { uno::Reference< beans::XPropertySet > xPageStyleProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW ); sal_Int32 nIndex = word::WdHeaderFooterIndex::wdHeaderFooterPrimary; - sal_Bool isHeader = HeaderFooterHelper::isHeader( mxModel, xCurrentText ); - if( HeaderFooterHelper::isEvenPagesHeader( mxModel, xCurrentText ) || HeaderFooterHelper::isEvenPagesFooter( mxModel, xCurrentText ) ) + sal_Bool isHeader = HeaderFooterHelper::isHeader( mxModel ); + if( HeaderFooterHelper::isEvenPagesHeader( mxModel ) || HeaderFooterHelper::isEvenPagesFooter( mxModel ) ) nIndex = word::WdHeaderFooterIndex::wdHeaderFooterEvenPages; - else if( HeaderFooterHelper::isFirstPageHeader( mxModel, xCurrentText ) || HeaderFooterHelper::isFirstPageFooter( mxModel, xCurrentText ) ) + else if( HeaderFooterHelper::isFirstPageHeader( mxModel ) || HeaderFooterHelper::isFirstPageFooter( mxModel ) ) nIndex = word::WdHeaderFooterIndex::wdHeaderFooterFirstPage; return uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( this, mxContext, mxModel, xPageStyleProps, isHeader, nIndex ) ); @@ -629,9 +872,13 @@ uno::Any SAL_CALL SwVbaSelection::ShapeRange( ) throw (uno::RuntimeException) { uno::Reference< drawing::XShapes > xShapes( mxModel->getCurrentSelection(), uno::UNO_QUERY ); - if ( !xShapes.is() ) - throw uno::RuntimeException(); + { + uno::Reference< drawing::XShape > xShape( mxModel->getCurrentSelection(), uno::UNO_QUERY_THROW ); + uno::Reference< lang::XMultiServiceFactory > xMSF( mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); + xShapes.set( xMSF->createInstance( rtl::OUString::createFromAscii( "com.sun.star.drawing.ShapeCollection" ) ), uno::UNO_QUERY_THROW ); + xShapes->add( xShape ); + } uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxModel, uno::UNO_QUERY_THROW ); uno::Reference< drawing::XDrawPage > xDrawPage = xDrawPageSupplier->getDrawPage(); @@ -658,6 +905,281 @@ void SAL_CALL SwVbaSelection::setEnd( ::sal_Int32 _end ) throw (uno::RuntimeExce getRange()->setEnd( _end ); } +void SAL_CALL SwVbaSelection::SelectRow() throw (uno::RuntimeException) +{ + uno::Reference< word::XRows > xRows( Rows( uno::Any() ), uno::UNO_QUERY_THROW ); + xRows->Select(); +} + +void SAL_CALL SwVbaSelection::SelectColumn() throw (uno::RuntimeException) +{ + uno::Reference< word::XColumns > xColumns( Columns( uno::Any() ), uno::UNO_QUERY_THROW ); + xColumns->Select(); +} + +uno::Any SAL_CALL SwVbaSelection::Rows( const uno::Any& index ) throw (uno::RuntimeException) +{ + rtl::OUString sTLName; + rtl::OUString sBRName; + GetSelectedCellRange( sTLName, sBRName ); + + sal_Int32 nStartRow = 0; + sal_Int32 nEndRow = 0; + uno::Reference< text::XTextTable > xTextTable = GetXTextTable(); + SwVbaTableHelper aTableHelper( xTextTable ); + nStartRow = aTableHelper.getTabRowIndex( sTLName ); + if( sBRName.getLength() > 0 ) + { + nEndRow = aTableHelper.getTabRowIndex( sBRName ); + } + else + { + nEndRow = nStartRow; + } + + uno::Reference< XCollection > xCol( new SwVbaRows( this, mxContext, xTextTable, xTextTable->getRows(), nStartRow, nEndRow ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + +uno::Any SAL_CALL SwVbaSelection::Columns( const uno::Any& index ) throw (uno::RuntimeException) +{ + rtl::OUString sTLName; + rtl::OUString sBRName; + GetSelectedCellRange( sTLName, sBRName ); + sal_Int32 nStartColumn = 0; + sal_Int32 nEndColumn = 0; + + uno::Reference< text::XTextTable > xTextTable = GetXTextTable(); + SwVbaTableHelper aTableHelper( xTextTable ); + nStartColumn = aTableHelper.getTabColIndex( sTLName ); + if( sBRName.getLength() > 0 ) + { + nEndColumn = aTableHelper.getTabColIndex( sBRName ); + } + else + { + nEndColumn = nStartColumn; + } + + uno::Reference< XCollection > xCol( new SwVbaColumns( this, mxContext, xTextTable, xTextTable->getColumns(), nStartColumn, nEndColumn ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + +uno::Reference< text::XTextTable > SwVbaSelection::GetXTextTable() throw( uno::RuntimeException ) +{ + uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextTable > xTextTable; + xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable; + return xTextTable; +} + +sal_Bool SwVbaSelection::IsInTable() throw( uno::RuntimeException ) +{ + uno::Reference< text::XTextTable > xTextTable = GetXTextTable(); + if( xTextTable.is() ) + return sal_True; + return sal_False; +} + +sal_Bool SwVbaSelection::HasSelection() throw( uno::RuntimeException ) +{ + uno::Reference< text::XTextRange > xStart = mxTextViewCursor->getStart(); + uno::Reference< text::XTextRange > xEnd = mxTextViewCursor->getEnd(); + uno::Reference< text::XTextRangeCompare > xTRC( mxTextViewCursor->getText(), uno::UNO_QUERY_THROW ); + if( xTRC->compareRegionStarts( xStart, xEnd ) == 0 && xTRC->compareRegionEnds( xStart, xEnd ) == 0 ) + return sal_False; + return sal_True; +} + +void SwVbaSelection::GetSelectedCellRange( rtl::OUString& sTLName, rtl::OUString& sBRName ) throw( uno::RuntimeException ) +{ + uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextTable > xTextTable; + xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextTable; + if( !xTextTable.is() ) + throw uno::RuntimeException( ); + + uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY ); + if( xTextTableCursor.is() ) + { + String sRange( xTextTableCursor->getRangeName() ); + if( sRange.GetTokenCount(':') > 0 ) + { + sTLName = sRange.GetToken(0, ':'); + sBRName = sRange.GetToken(1, ':'); + } + } + if( !sTLName.getLength() ) + { + uno::Reference< table::XCell > xCell; + xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Cell") ) ) >>= xCell; + if( !xCell.is() ) + { + throw uno::RuntimeException( ); + } + uno::Reference< beans::XPropertySet > xCellProps( xCell, uno::UNO_QUERY_THROW ); + xCellProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CellName") ) ) >>= sTLName; + } +} + +uno::Any SAL_CALL SwVbaSelection::Cells( const uno::Any& index ) throw (uno::RuntimeException) +{ + rtl::OUString sTLName; + rtl::OUString sBRName; + GetSelectedCellRange( sTLName, sBRName ); + sal_Int32 nLeft = 0; + sal_Int32 nTop = 0; + sal_Int32 nRight = 0; + sal_Int32 nBottom = 0; + + uno::Reference< text::XTextTable > xTextTable = GetXTextTable(); + SwVbaTableHelper aTableHelper( xTextTable ); + nLeft = aTableHelper.getTabColIndex( sTLName ); + nTop = aTableHelper.getTabRowIndex( sTLName ); + if( sBRName.getLength() > 0 ) + { + nRight = aTableHelper.getTabColIndex( sBRName ); + nBottom = aTableHelper.getTabRowIndex( sBRName ); + } + else + { + nRight = nLeft; + nBottom = nTop; + } + + uno::Reference< XCollection > xCol( new SwVbaCells( this, mxContext, xTextTable, nLeft, nTop, nRight, nBottom ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + +void SAL_CALL SwVbaSelection::Copy( ) throw (uno::RuntimeException) +{ + rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Copy")); + dispatchRequests( mxModel,url ); +} + +void SAL_CALL SwVbaSelection::CopyAsPicture( ) throw (uno::RuntimeException) +{ + // seems not support in Writer + Copy(); +} + +void SAL_CALL SwVbaSelection::Paste( ) throw (uno::RuntimeException) +{ + rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Paste")); + dispatchRequests( mxModel,url ); +} + +void SAL_CALL SwVbaSelection::Collapse( const uno::Any& Direction ) throw (uno::RuntimeException) +{ + if( word::gotoSelectedObjectAnchor( mxModel ) ) + return; + + sal_Int32 nDirection = word::WdCollapseDirection::wdCollapseStart; + if( Direction.hasValue() ) + Direction >>= nDirection; + + uno::Reference< text::XTextViewCursor > xTextViewCursor = word::getXTextViewCursor( mxModel ); + if( nDirection == word::WdCollapseDirection::wdCollapseStart ) + { + // it is inaccurate if current seleciton is multipul cells, so it needs to go to start + uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getStart(); + xTextViewCursor->gotoRange( xTextRange, sal_False ); + xTextViewCursor->collapseToStart(); + } + else if( nDirection == word::WdCollapseDirection::wdCollapseEnd ) + { + uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getEnd(); + xTextViewCursor->gotoRange( xTextRange, sal_False ); + xTextViewCursor->collapseToEnd(); + } + else + { + throw uno::RuntimeException(); + } +} + +void SAL_CALL SwVbaSelection::WholeStory( ) throw (uno::RuntimeException) +{ + uno::Reference< text::XText > xText = word::getCurrentXText( mxModel ); + // FIXME: for i#7747,if the first line is a table, it fails to select all the contents in the story. + // Temporary solution, insert an empty line before the table so that it could select all the contents. + uno::Reference< container::XEnumerationAccess > xParaAccess( xText, uno::UNO_QUERY_THROW ); + uno::Reference< container::XEnumeration> xParaEnum = xParaAccess->createEnumeration(); + if( xParaEnum->hasMoreElements() ) + { + uno::Reference< text::XTextTable > xTextTable( xParaEnum->nextElement(), uno::UNO_QUERY ); + if( xTextTable.is() ) + { + // insert an empty line + uno::Reference< text::XTextRange > xFirstCellRange = word::getFirstObjectPosition( xText ); + mxTextViewCursor->gotoRange( xFirstCellRange, sal_False ); + rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:InsertPara")); + dispatchRequests( mxModel,url ); + } + } + uno::Reference< text::XTextRange > xStart = xText->getStart(); + uno::Reference< text::XTextRange > xEnd = xText->getEnd(); + mxTextViewCursor->gotoRange( xStart, sal_False ); + mxTextViewCursor->gotoRange( xEnd, sal_True ); +} + +::sal_Bool SAL_CALL SwVbaSelection::InRange( const uno::Reference< ::ooo::vba::word::XRange >& Range ) throw (uno::RuntimeException) +{ + return getRange()->InRange( Range ); +} + +void SAL_CALL SwVbaSelection::SplitTable( ) throw (uno::RuntimeException) +{ + if( !IsInTable() ) + throw uno::RuntimeException(); + + SwDocShell* pDocShell = word::getDocShell( mxModel ); + if( pDocShell ) + { + SwFEShell* pFEShell = pDocShell->GetFEShell(); + if( pFEShell ) + { + pFEShell->SplitTable( HEADLINE_CNTNTCOPY ); + } + } +} + +uno::Any SAL_CALL +SwVbaSelection::Paragraphs( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + // Hacky implementation due to missing api ( and lack of knowledge ) + // we can only support a selection that is a single paragraph + if ( !aIndex.hasValue() ) // currently we can't support multiple paragraphs in a selection + throw uno::RuntimeException(); + + sal_Int32 nIndex = 0; + aIndex >>= nIndex; + + uno::Any aRet; + + if ( nIndex != 1 ) + throw uno::RuntimeException(); + + uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getStart(); + uno::Reference< text::XText > xText = xTextRange->getText(); + uno::Reference< text::XParagraphCursor > xParaCursor( xText->createTextCursor(), uno::UNO_QUERY_THROW ); + xParaCursor->gotoStartOfParagraph( sal_False ); + xParaCursor->gotoStartOfParagraph( sal_True ); + + uno::Reference< text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRange > xParaRange( xParaCursor, uno::UNO_QUERY_THROW ); + uno::Reference< word::XParagraph > xParagraph = new SwVbaParagraph( mxParent, mxContext, xTextDoc, xParaRange ); + + aRet <<= xParagraph; + return aRet; +} + rtl::OUString& SwVbaSelection::getServiceImplName() { diff --git a/sw/source/ui/vba/vbaselection.hxx b/sw/source/ui/vba/vbaselection.hxx index a5079340ee19..10ed8a084728 100644 --- a/sw/source/ui/vba/vbaselection.hxx +++ b/sw/source/ui/vba/vbaselection.hxx @@ -31,11 +31,13 @@ #include <ooo/vba/word/XRange.hpp> #include <vbahelper/vbahelperinterface.hxx> #include <com/sun/star/text/XTextViewCursor.hpp> +#include <com/sun/star/text/XTextTable.hpp> #include <ooo/vba/word/XParagraphFormat.hpp> #include <ooo/vba/word/XFind.hpp> #include <ooo/vba/word/XStyle.hpp> #include <ooo/vba/word/XFont.hpp> #include <ooo/vba/word/XHeaderFooter.hpp> +#include "wordvbahelper.hxx" typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XSelection > SwVbaSelection_BASE; @@ -46,17 +48,14 @@ private: css::uno::Reference< css::text::XTextViewCursor > mxTextViewCursor; css::uno::Reference< ooo::vba::word::XRange > mxRange; - enum E_DIRECTION - { - MOVE_LEFT = 1, - MOVE_RIGHT, - MOVE_UP, - MOVE_DOWN - }; - private: - void NextCell( sal_Int32 nCount, E_DIRECTION eDirection ) throw ( css::uno::RuntimeException ); + void Move( const css::uno::Any& _unit, const css::uno::Any& _count, const css::uno::Any& _extend, ooo::vba::word::E_DIRECTION eDirection ) throw (css::uno::RuntimeException); + void NextCell( sal_Int32 nCount, ooo::vba::word::E_DIRECTION eDirection ) throw ( css::uno::RuntimeException ); css::uno::Reference< css::text::XTextRange > GetSelectedRange() throw ( css::uno::RuntimeException ); + void GetSelectedCellRange( rtl::OUString& sTLName, rtl::OUString& sBRName ) throw ( css::uno::RuntimeException ); + css::uno::Reference< css::text::XTextTable > GetXTextTable() throw ( css::uno::RuntimeException ); + sal_Bool IsInTable() throw ( css::uno::RuntimeException ); + sal_Bool HasSelection() throw ( css::uno::RuntimeException ); public: SwVbaSelection( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::frame::XModel >& rModel ) throw ( css::uno::RuntimeException ); @@ -73,6 +72,7 @@ public: virtual void SAL_CALL MoveRight( const css::uno::Any& _unit, const css::uno::Any& _count, const css::uno::Any& _extend ) throw (css::uno::RuntimeException); virtual void SAL_CALL MoveLeft( const css::uno::Any& _unit, const css::uno::Any& _count, const css::uno::Any& _extend ) throw (css::uno::RuntimeException); virtual void SAL_CALL MoveDown( const css::uno::Any& _unit, const css::uno::Any& _count, const css::uno::Any& _extend ) throw (css::uno::RuntimeException); + virtual void SAL_CALL MoveUp( const css::uno::Any& _unit, const css::uno::Any& _count, const css::uno::Any& _extend ) throw (css::uno::RuntimeException); virtual void SAL_CALL TypeParagraph() throw (css::uno::RuntimeException); virtual void SAL_CALL InsertParagraph() throw (css::uno::RuntimeException); virtual void SAL_CALL InsertParagraphBefore() throw (css::uno::RuntimeException); @@ -80,8 +80,8 @@ public: virtual css::uno::Reference< ooo::vba::word::XParagraphFormat > SAL_CALL getParagraphFormat() throw (css::uno::RuntimeException); virtual void SAL_CALL setParagraphFormat( const css::uno::Reference< ooo::vba::word::XParagraphFormat >& rParagraphFormat ) throw (css::uno::RuntimeException); virtual css::uno::Reference< ooo::vba::word::XFind > SAL_CALL getFind() throw (css::uno::RuntimeException); - virtual css::uno::Reference< ooo::vba::word::XStyle > SAL_CALL getStyle() throw (css::uno::RuntimeException); - virtual void SAL_CALL setStyle( const css::uno::Reference< ooo::vba::word::XStyle >& _xStyle ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStyle( const css::uno::Any& _xStyle ) throw (css::uno::RuntimeException); virtual css::uno::Reference< ooo::vba::word::XFont > SAL_CALL getFont() throw (css::uno::RuntimeException); virtual void SAL_CALL TypeBackspace() throw (css::uno::RuntimeException); virtual css::uno::Reference< ooo::vba::word::XRange > SAL_CALL GoTo( const css::uno::Any& _what, const css::uno::Any& _which, const css::uno::Any& _count, const css::uno::Any& _name ) throw (css::uno::RuntimeException); @@ -97,6 +97,19 @@ public: virtual void SAL_CALL setStart( ::sal_Int32 _start ) throw (css::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getEnd() throw (css::uno::RuntimeException); virtual void SAL_CALL setEnd( ::sal_Int32 _end ) throw (css::uno::RuntimeException); + virtual void SAL_CALL SelectRow() throw (css::uno::RuntimeException); + virtual void SAL_CALL SelectColumn() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Rows( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Columns( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Cells( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Copy( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL CopyAsPicture( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Paste( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Collapse( const css::uno::Any& Direction ) throw (css::uno::RuntimeException); + virtual void SAL_CALL WholeStory( ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL InRange( const css::uno::Reference< ::ooo::vba::word::XRange >& Range ) throw (css::uno::RuntimeException); + virtual void SAL_CALL SplitTable( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Paragraphs( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); // XHelperInterface virtual rtl::OUString& getServiceImplName(); diff --git a/sw/source/ui/vba/vbastyle.cxx b/sw/source/ui/vba/vbastyle.cxx index cf49da020284..247c6df8b9fb 100644 --- a/sw/source/ui/vba/vbastyle.cxx +++ b/sw/source/ui/vba/vbastyle.cxx @@ -28,15 +28,18 @@ #include "vbastyle.hxx" #include <ooo/vba/word/WdStyleType.hpp> #include <com/sun/star/lang/Locale.hpp> +#include <com/sun/star/text/XTextDocument.hpp> #include <i18npool/mslangid.hxx> #include "vbafont.hxx" #include "vbapalette.hxx" +#include "vbaparagraphformat.hxx" +#include "vbastyles.hxx" using namespace ::ooo::vba; using namespace ::com::sun::star; -SwVbaStyle::SwVbaStyle( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& _xPropertySet ) throw ( script::BasicErrorException, uno::RuntimeException ) : SwVbaStyle_BASE( xParent, xContext ) , mxStyleProps( _xPropertySet ) +SwVbaStyle::SwVbaStyle( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel>& xModel, const uno::Reference< beans::XPropertySet >& _xPropertySet ) throw ( script::BasicErrorException, uno::RuntimeException ) : SwVbaStyle_BASE( xParent, xContext ) , mxModel( xModel ), mxStyleProps( _xPropertySet ) { mxStyle.set( _xPropertySet, uno::UNO_QUERY_THROW ); } @@ -84,7 +87,7 @@ void SAL_CALL SwVbaStyle::setLanguageID( ::sal_Int32 _languageid ) throw (uno::R nType = word::WdStyleType::wdStyleTypeParagraph; else if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.CharacterStyle") ) ) ) nType = word::WdStyleType::wdStyleTypeCharacter; - else // if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.NumberingStyle") ) ) ) + else nType = word::WdStyleType::wdStyleTypeList; return nType; } @@ -96,10 +99,31 @@ SwVbaStyle::getFont() throw ( uno::RuntimeException ) return new SwVbaFont( mxParent, mxContext, aColors.getPalette(), mxStyleProps ); } -void SwVbaStyle::setStyle( const uno::Reference< beans::XPropertySet >& xTCProps, const uno::Reference< ooo::vba::word::XStyle >& xStyle )throw (uno::RuntimeException) + +void SAL_CALL SwVbaStyle::LinkToListTemplate( const uno::Reference< word::XListTemplate >& /*ListTemplate*/, const uno::Any& /*ListLevelNumber*/ ) throw (uno::RuntimeException) +{ +} + +void SwVbaStyle::setStyle( const uno::Reference< beans::XPropertySet >& xParaProps, const uno::Any& rStyle )throw (uno::RuntimeException) { - rtl::OUString aStyleType = getOOoStyleTypeFromMSWord( xStyle->getType() ); - xTCProps->setPropertyValue( aStyleType, uno::makeAny( xStyle->getName() ) ); + rtl::OUString sStyle; + uno::Reference< word::XStyle > xStyle; + if( rStyle >>= xStyle ) + { + sStyle = xStyle->getName(); + } + else + { + rStyle >>= sStyle; + } + + if( sStyle.getLength() ) + { + xParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaStyleName") ), uno::makeAny( sStyle ) ); + return; + } + + throw uno::RuntimeException(); } rtl::OUString SwVbaStyle::getOOoStyleTypeFromMSWord( sal_Int32 _wdStyleType ) @@ -129,6 +153,115 @@ rtl::OUString SwVbaStyle::getOOoStyleTypeFromMSWord( sal_Int32 _wdStyleType ) return aStyleType; } +::rtl::OUString SAL_CALL SwVbaStyle::getNameLocal() throw (uno::RuntimeException) +{ + rtl::OUString sNameLocal; + mxStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DisplayName") ) ) >>= sNameLocal; + return sNameLocal; +} + +void SAL_CALL SwVbaStyle::setNameLocal( const ::rtl::OUString& _namelocal ) throw (uno::RuntimeException) +{ + mxStyleProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DisplayName") ), uno::makeAny( _namelocal ) ); +} + +uno::Reference< word::XParagraphFormat > SAL_CALL SwVbaStyle::getParagraphFormat() throw (uno::RuntimeException) +{ + if( word::WdStyleType::wdStyleTypeParagraph == getType() ) + { + uno::Reference< text::XTextDocument > xTextDocument( mxModel, uno::UNO_QUERY_THROW ); + return uno::Reference< word::XParagraphFormat >( new SwVbaParagraphFormat( this, mxContext, xTextDocument, mxStyleProps ) ); + } + else + { + throw uno::RuntimeException(); + } + return uno::Reference< word::XParagraphFormat >(); +} + +::sal_Bool SAL_CALL SwVbaStyle::getAutomaticallyUpdate() throw (uno::RuntimeException) +{ + sal_Bool isAutoUpdate = sal_False; + mxStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsAutoUpdate") ) ) >>= isAutoUpdate; + return isAutoUpdate; +} + +void SAL_CALL SwVbaStyle::setAutomaticallyUpdate( ::sal_Bool _automaticallyupdate ) throw (uno::RuntimeException) +{ + mxStyleProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsAutoUpdate") ), uno::makeAny( _automaticallyupdate ) ); +} + +uno::Any SAL_CALL SwVbaStyle::getBaseStyle() throw (uno::RuntimeException) +{ + // ParentStyle + rtl::OUString sBaseStyle; + mxStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParentStyle") ) ) >>= sBaseStyle; + if( sBaseStyle.getLength() > 0 ) + { + uno::Reference< XCollection > xCol( new SwVbaStyles( this, mxContext, mxModel ) ); + return xCol->Item( uno::makeAny( sBaseStyle ), uno::Any() ); + } + else + { + throw uno::RuntimeException(); + } + return uno::Any(); +} + +void SAL_CALL SwVbaStyle::setBaseStyle( const uno::Any& _basestyle ) throw (uno::RuntimeException) +{ + uno::Reference< word::XStyle > xStyle; + _basestyle >>= xStyle; + if( xStyle.is() ) + { + rtl::OUString sBaseStyle = xStyle->getName(); + mxStyleProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParentStyle") ), uno::makeAny( sBaseStyle ) ); + } + else + { + throw uno::RuntimeException(); + } +} + +uno::Any SAL_CALL SwVbaStyle::getNextParagraphStyle() throw (uno::RuntimeException) +{ + //FollowStyle + rtl::OUString sFollowStyle; + mxStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FollowStyle") ) ) >>= sFollowStyle; + if( sFollowStyle.getLength() > 0 ) + { + uno::Reference< XCollection > xCol( new SwVbaStyles( this, mxContext, mxModel ) ); + return xCol->Item( uno::makeAny( sFollowStyle ), uno::Any() ); + } + else + { + throw uno::RuntimeException(); + } + return uno::Any(); +} + +void SAL_CALL SwVbaStyle::setNextParagraphStyle( const uno::Any& _nextparagraphstyle ) throw (uno::RuntimeException) +{ + uno::Reference< word::XStyle > xStyle; + _nextparagraphstyle >>= xStyle; + if( xStyle.is() ) + { + rtl::OUString sFollowStyle = xStyle->getName(); + mxStyleProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FollowStyle") ), uno::makeAny( sFollowStyle ) ); + } + else + { + throw uno::RuntimeException(); + } +} + +::sal_Int32 SAL_CALL SwVbaStyle::getListLevelNumber() throw (uno::RuntimeException) +{ + sal_Int16 nNumberingLevel = 0; + mxStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingLevel") ) ) >>= nNumberingLevel; + return nNumberingLevel; +} + rtl::OUString& SwVbaStyle::getServiceImplName() { diff --git a/sw/source/ui/vba/vbastyle.hxx b/sw/source/ui/vba/vbastyle.hxx index 401baa5337a1..3a31c6eca073 100644 --- a/sw/source/ui/vba/vbastyle.hxx +++ b/sw/source/ui/vba/vbastyle.hxx @@ -33,6 +33,7 @@ #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/style/XStyle.hpp> #include <ooo/vba/word/XFont.hpp> +#include <ooo/vba/word/XListTemplate.hpp> typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XStyle > SwVbaStyle_BASE; @@ -40,13 +41,14 @@ typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XStyle > SwVbaStyle_BASE; class SwVbaStyle : public SwVbaStyle_BASE { private: + css::uno::Reference< css::frame::XModel > mxModel; css::uno::Reference< css::beans::XPropertySet > mxStyleProps; css::uno::Reference< css::style::XStyle > mxStyle; public: - SwVbaStyle( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet ) throw ( css::script::BasicErrorException, css::uno::RuntimeException ); + SwVbaStyle( 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::beans::XPropertySet >& _xPropertySet ) throw ( css::script::BasicErrorException, css::uno::RuntimeException ); virtual ~SwVbaStyle(){} - static void setStyle( const css::uno::Reference< css::beans::XPropertySet >& xTCProps, const css::uno::Reference< ooo::vba::word::XStyle >& xStyle ) throw (css::uno::RuntimeException); + static void setStyle( const css::uno::Reference< css::beans::XPropertySet >& xParaProps, const css::uno::Any& xStyle ) throw (css::uno::RuntimeException); static rtl::OUString getOOoStyleTypeFromMSWord( sal_Int32 _wdStyleType ); static sal_Int32 getLanguageID( const css::uno::Reference< css::beans::XPropertySet >& xTCProps ) throw (css::uno::RuntimeException); static void setLanguageID( const css::uno::Reference< css::beans::XPropertySet >& xTCProps, sal_Int32 _languageid ) throw (css::uno::RuntimeException); @@ -58,6 +60,20 @@ public: virtual void SAL_CALL setLanguageID( ::sal_Int32 _languageid ) throw (css::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getType() throw (css::uno::RuntimeException); virtual css::uno::Reference< ooo::vba::word::XFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + virtual void SAL_CALL LinkToListTemplate( const css::uno::Reference< ooo::vba::word::XListTemplate >& ListTemplate, const css::uno::Any& ListLevelNumber ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getNameLocal() throw (css::uno::RuntimeException); + virtual void SAL_CALL setNameLocal( const ::rtl::OUString& _namelocal ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ::ooo::vba::word::XParagraphFormat > SAL_CALL getParagraphFormat() throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getAutomaticallyUpdate() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAutomaticallyUpdate( ::sal_Bool _automaticallyupdate ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getBaseStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBaseStyle( const css::uno::Any& _basestyle ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getNextParagraphStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setNextParagraphStyle( const css::uno::Any& _nextparagraphstyle ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getListLevelNumber() throw (css::uno::RuntimeException); + + //XDefaultProperty + virtual ::rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return rtl::OUString::createFromAscii("Name"); } // XHelperInterface virtual rtl::OUString& getServiceImplName(); diff --git a/sw/source/ui/vba/vbastyles.cxx b/sw/source/ui/vba/vbastyles.cxx index 371c1225cafa..68850cabf64b 100644 --- a/sw/source/ui/vba/vbastyles.cxx +++ b/sw/source/ui/vba/vbastyles.cxx @@ -44,7 +44,7 @@ struct BuiltinStyleTable sal_Int32 wdStyleType; }; -const BuiltinStyleTable aBuiltinStyleTable[] = +static const BuiltinStyleTable aBuiltinStyleTable[] = { { word::WdBuiltinStyle::wdStyleBlockQuotation, "", word::WdStyleType::wdStyleTypeParagraph }, { word::WdBuiltinStyle::wdStyleBodyText, "Text body", word::WdStyleType::wdStyleTypeParagraph }, @@ -152,7 +152,20 @@ const BuiltinStyleTable aBuiltinStyleTable[] = { 0, 0, 0 } }; +struct MSOStyleNameTable +{ + const sal_Char* pMSOStyleName; + const sal_Char* pOOoStyleName; + const sal_Char* pOOoStyleType; +}; + +static const MSOStyleNameTable aMSOStyleNameTable[] = +{ + { "Normal", "Default", "ParagraphStyles" }, + { 0, 0, 0 } +}; +#ifdef FUTURE // seems this isn't used static uno::Sequence< rtl::OUString > getStyleTypes() { uno::Sequence< rtl::OUString > aRet(3); @@ -162,41 +175,25 @@ static uno::Sequence< rtl::OUString > getStyleTypes() pArray[2] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingStyles") ); return aRet; } +#endif typedef ::cppu::WeakImplHelper1< container::XEnumeration > StyleEnumeration_BASE; typedef ::cppu::WeakImplHelper3< container::XNameAccess, container::XIndexAccess, container::XEnumerationAccess > StyleCollectionHelper_BASE; -/* -class StylesEnumeration : public StyleEnumeration_BASE -{ -public: - StylesEnumeration( const SheetMap& sMap ) : mSheetMap( sMap ), mIt( mSheetMap.begin() ) {} - virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) - { - return ( mIt != mSheetMap.end() ); - } - virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) - { - if ( !hasMoreElements() ) - throw container::NoSuchElementException(); - uno::Reference< sheet::XSpreadsheet > xSheet( *mIt++ ); - return uno::makeAny( xSheet ) ; - } -}; -*/ + class StyleCollectionHelper : public StyleCollectionHelper_BASE { private: uno::Reference< frame::XModel > mxModel; - uno::Reference< container::XNameAccess > mxStyleFamilies; - uno::Reference< container::XNameContainer > mxCurrentStyleFamily; + uno::Reference< container::XNameAccess > mxParaStyles; uno::Any cachePos; public: StyleCollectionHelper( const uno::Reference< frame::XModel >& _xModel ) : mxModel( _xModel ) { + // we only concern about the Paragraph styles uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( _xModel, uno::UNO_QUERY_THROW); - mxStyleFamilies = xStyleSupplier->getStyleFamilies(); + uno::Reference< container::XNameAccess > xStyleFamilies = xStyleSupplier->getStyleFamilies(); + mxParaStyles.set( xStyleFamilies->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParagraphStyles") ) ), uno::UNO_QUERY_THROW ); } - uno::Reference< container::XNameContainer > getCurrentStyleFamily(){ return mxCurrentStyleFamily; } // XElementAccess virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) { return style::XStyle::static_type(0); } virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) { return getCount() > 0; } @@ -209,32 +206,42 @@ public: } virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) { - uno::Sequence< rtl::OUString > sNames( getCount() ); - rtl::OUString* pString = sNames.getArray(); - uno::Sequence< rtl::OUString > aStyleTypes = getStyleTypes(); - sal_Int32 nCount = 0; - for( sal_Int32 i = 0; i < aStyleTypes.getLength(); i++ ) + return mxParaStyles->getElementNames(); + } + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException) + { + // search in the MSOStyleName table first + for( const MSOStyleNameTable* pTable = aMSOStyleNameTable; pTable->pMSOStyleName != NULL; pTable++ ) { - uno::Reference< container::XNameAccess > xNameAccess( mxStyleFamilies->getByName( aStyleTypes[i] ), uno::UNO_QUERY_THROW ); - uno::Sequence< rtl::OUString > sElementNames = xNameAccess->getElementNames(); - for( sal_Int32 j = 0; j < sElementNames.getLength(); j++ ) + if( aName.equalsIgnoreAsciiCaseAscii( pTable->pMSOStyleName ) ) { - pString[nCount++] = sElementNames[j]; + //Found it + rtl::OUString sStyleName = rtl::OUString::createFromAscii( pTable->pOOoStyleName ); + if( mxParaStyles->hasByName( sStyleName ) ) + { + cachePos = mxParaStyles->getByName( sStyleName ); + return sal_True; + } + return sal_False; } } - return sNames; - } - virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException) - { - uno::Sequence< rtl::OUString > aStyleTypes = getStyleTypes(); - for( sal_Int32 i = 0; i < aStyleTypes.getLength(); i++ ) + + if( mxParaStyles->hasByName( aName ) ) + { + cachePos = mxParaStyles->getByName( aName ); + return sal_True; + } + else { - uno::Reference< container::XNameAccess > xNameAccess( mxStyleFamilies->getByName( aStyleTypes[i] ), uno::UNO_QUERY_THROW ); - if( xNameAccess->hasByName( aName ) ) + uno::Sequence< rtl::OUString > sElementNames = mxParaStyles->getElementNames(); + for( sal_Int32 j = 0; j < sElementNames.getLength(); j++ ) { - cachePos = xNameAccess->getByName( aName ); - mxCurrentStyleFamily.set( xNameAccess, uno::UNO_QUERY_THROW ); - return sal_True; + rtl::OUString aStyleName = sElementNames[j]; + if( aStyleName.equalsIgnoreAsciiCase( aName ) ) + { + cachePos = mxParaStyles->getByName( aStyleName ); + return sal_True; + } } } return sal_False; @@ -243,44 +250,43 @@ public: // XIndexAccess virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) { - uno::Sequence< rtl::OUString > aStyleTypes = getStyleTypes(); - sal_Int32 nCount = 0; - for( sal_Int32 i = 0; i < aStyleTypes.getLength(); i++ ) - { - uno::Reference< container::XIndexAccess > xIndexAccess( mxStyleFamilies->getByName( aStyleTypes[i] ), uno::UNO_QUERY_THROW ); - nCount += xIndexAccess->getCount(); - } - return nCount; + uno::Reference< container::XIndexAccess > xIndexAccess( mxParaStyles, uno::UNO_QUERY_THROW ); + return xIndexAccess->getCount(); } virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException ) { if ( Index < 0 || Index >= getCount() ) throw lang::IndexOutOfBoundsException(); - // FIXME: need to make a alphabetically sorted list of style names - uno::Sequence< rtl::OUString > aStyleTypes = getStyleTypes(); - for( sal_Int32 i = 0; i < aStyleTypes.getLength(); i++ ) - { - uno::Reference< container::XIndexAccess > xIndexAccess( mxStyleFamilies->getByName( aStyleTypes[i] ), uno::UNO_QUERY_THROW ); - sal_Int32 nCount = xIndexAccess->getCount(); - if( Index >= nCount ) - Index -= nCount; - else - { - mxCurrentStyleFamily.set( xIndexAccess, uno::UNO_QUERY_THROW ); - return xIndexAccess->getByIndex( Index ); - } - } - throw lang::IndexOutOfBoundsException(); + uno::Reference< container::XIndexAccess > xIndexAccess( mxParaStyles, uno::UNO_QUERY_THROW ); + return xIndexAccess->getByIndex( Index ); } // XEnumerationAccess virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) { - // FIXME: throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); } }; +class StylesEnumWrapper : public EnumerationHelper_BASE +{ + SwVbaStyles* pStyles; + sal_Int32 nIndex; +public: + StylesEnumWrapper( SwVbaStyles* _pStyles ) : pStyles( _pStyles ), nIndex( 1 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex <= pStyles->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex <= pStyles->getCount() ) + return pStyles->Item( uno::makeAny( nIndex++ ), uno::Any() ); + throw container::NoSuchElementException(); + } +}; + SwVbaStyles::SwVbaStyles( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ) throw ( script::BasicErrorException ) : SwVbaStyles_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new StyleCollectionHelper( xModel ) ) ), mxModel( xModel ) { mxMSF.set( mxModel, uno::UNO_QUERY_THROW ); @@ -290,7 +296,7 @@ uno::Any SwVbaStyles::createCollectionObject(const uno::Any& aObject) { uno::Reference< beans::XPropertySet > xStyleProp( aObject, uno::UNO_QUERY_THROW ); - return uno::makeAny( uno::Reference< word::XStyle >( new SwVbaStyle( this, mxContext, xStyleProp ) ) ); + return uno::makeAny( uno::Reference< word::XStyle >( new SwVbaStyle( this, mxContext, mxModel, xStyleProp ) ) ); } uno::Type SAL_CALL @@ -302,7 +308,7 @@ SwVbaStyles::getElementType() throw (uno::RuntimeException) uno::Reference< container::XEnumeration > SAL_CALL SwVbaStyles::createEnumeration() throw (uno::RuntimeException) { - throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + return new StylesEnumWrapper( this ); } uno::Any SAL_CALL @@ -319,7 +325,8 @@ SwVbaStyles::Item( const uno::Any& Index1, const uno::Any& Index2 ) throw (uno:: rtl::OUString aStyleName = rtl::OUString::createFromAscii( pTable->pOOoStyleName ); if( aStyleName.getLength() > 0 ) { - rtl::OUString aStyleType = SwVbaStyle::getOOoStyleTypeFromMSWord( pTable->wdStyleType ); + //rtl::OUString aStyleType = SwVbaStyle::getOOoStyleTypeFromMSWord( pTable->wdStyleType ); + rtl::OUString aStyleType; switch( pTable->wdStyleType ) { case word::WdStyleType::wdStyleTypeParagraph: @@ -335,7 +342,8 @@ SwVbaStyles::Item( const uno::Any& Index1, const uno::Any& Index2 ) throw (uno:: } case word::WdStyleType::wdStyleTypeList: { - aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingStyles") ); + // should use Paragraph style and set the property "NumberingStyleName" + aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParagraphStyles") ); break; } default: @@ -344,7 +352,12 @@ SwVbaStyles::Item( const uno::Any& Index1, const uno::Any& Index2 ) throw (uno:: uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxModel, uno::UNO_QUERY_THROW); uno::Reference< container::XNameAccess > xStylesAccess( xStyleSupplier->getStyleFamilies()->getByName( aStyleType ), uno::UNO_QUERY_THROW ); uno::Reference< beans::XPropertySet > xStyleProps( xStylesAccess->getByName( aStyleName ), uno::UNO_QUERY_THROW ); - return uno::makeAny( uno::Reference< word::XStyle >( new SwVbaStyle( this, mxContext, xStyleProps ) ) ); + // set the property "NumberingStyleName" if it is a listbullet + if( pTable->wdStyleType == word::WdStyleType::wdStyleTypeList ) + { + xStyleProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingStyleName") ), uno::makeAny( aStyleName ) ); + } + return uno::makeAny( uno::Reference< word::XStyle >( new SwVbaStyle( this, mxContext, mxModel, xStyleProps ) ) ); } else { diff --git a/sw/source/ui/vba/vbasystem.cxx b/sw/source/ui/vba/vbasystem.cxx index 42d1c09ccbac..4d2d229da833 100644 --- a/sw/source/ui/vba/vbasystem.cxx +++ b/sw/source/ui/vba/vbasystem.cxx @@ -34,6 +34,13 @@ #include <tools/urlobj.hxx> #include <tools/string.hxx> +#ifdef WNT +#include <tools/prewin.h> +#include <windows.h> +#include <tools/postwin.h> +#include <tchar.h> +#endif + using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -47,13 +54,79 @@ void PrivateProfileStringListener::Initialize( const rtl::OUString& rFileName, c maGroupName = rGroupName; maKey = rKey; } +#ifdef WNT +void lcl_getRegKeyInfo( const ByteString& sKeyInfo, HKEY& hBaseKey, ByteString& sSubKey ) +{ + sal_Int32 nBaseKeyIndex = sKeyInfo.Search('\\'); + if( nBaseKeyIndex > 0 ) + { + ByteString sBaseKey = sKeyInfo.Copy( 0, nBaseKeyIndex ); + sSubKey = sKeyInfo.Copy( nBaseKeyIndex + 1 ); + if( sBaseKey.Equals("HKEY_CURRENT_USER") ) + { + hBaseKey = HKEY_CURRENT_USER; + } + else if( sBaseKey.Equals("HKEY_LOCAL_MACHINE") ) + { + hBaseKey = HKEY_LOCAL_MACHINE; + } + else if( sBaseKey.Equals("HKEY_CLASSES_ROOT") ) + { + hBaseKey = HKEY_CLASSES_ROOT; + } + else if( sBaseKey.Equals("HKEY_USERS") ) + { + hBaseKey = HKEY_USERS; + } + else if( sBaseKey.Equals("HKEY_CURRENT_CONFIG") ) + { + hBaseKey = HKEY_CURRENT_CONFIG; + } + } +} +#endif uno::Any PrivateProfileStringListener::getValueEvent() { // get the private profile string - Config aCfg( maFileName ); - aCfg.SetGroup( maGroupName ); - rtl::OUString sValue = String( aCfg.ReadKey( maKey ), RTL_TEXTENCODING_DONTKNOW ); + rtl::OUString sValue; + if(maFileName.getLength()) + { + // get key/value from a file + Config aCfg( maFileName ); + aCfg.SetGroup( maGroupName ); + sValue = String( aCfg.ReadKey( maKey ), RTL_TEXTENCODING_DONTKNOW ); + } + else + { + // get key/value from windows register +#ifdef WNT + HKEY hBaseKey = NULL; + ByteString sSubKey; + sal_Int32 nBaseKeyIndex = maGroupName.Search('\\'); + lcl_getRegKeyInfo( maGroupName, hBaseKey, sSubKey ); + if( hBaseKey != NULL ) + { + HKEY hKey = NULL; + LONG lResult; + LPCTSTR lpSubKey = TEXT( sSubKey.GetBuffer()); + TCHAR szBuffer[1024]; + DWORD cbData = sizeof( szBuffer ); + lResult = RegOpenKeyEx( hBaseKey, lpSubKey, 0, KEY_QUERY_VALUE, &hKey ); + if( ERROR_SUCCESS == lResult ) + { + LPCTSTR lpValueName = TEXT(maKey.GetBuffer()); + lResult = RegQueryValueEx( hKey, lpValueName, NULL, NULL, (LPBYTE)szBuffer, &cbData ); + RegCloseKey( hKey ); + sValue = rtl::OUString::createFromAscii(szBuffer); + } + } + + return uno::makeAny( sValue ); +#endif + throw uno::RuntimeException( rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("Only support on Windows")), uno::Reference< uno::XInterface >() ); + } return uno::makeAny( sValue ); } @@ -61,12 +134,44 @@ uno::Any PrivateProfileStringListener::getValueEvent() void PrivateProfileStringListener::setValueEvent( const css::uno::Any& value ) { // set the private profile string - Config aCfg( maFileName ); - aCfg.SetGroup( maGroupName ); - rtl::OUString aValue; value >>= aValue; - aCfg.WriteKey( maKey, ByteString( aValue.getStr(), RTL_TEXTENCODING_DONTKNOW ) ); + if(maFileName.getLength()) + { + // set value into a file + Config aCfg( maFileName ); + aCfg.SetGroup( maGroupName ); + aCfg.WriteKey( maKey, ByteString( aValue.getStr(), RTL_TEXTENCODING_DONTKNOW ) ); + } + else + { + //set value into windows register +#ifdef WNT + HKEY hBaseKey = NULL; + ByteString sSubKey; + sal_Int32 nBaseKeyIndex = maGroupName.Search('\\'); + lcl_getRegKeyInfo( maGroupName, hBaseKey, sSubKey ); + if( hBaseKey != NULL ) + { + HKEY hKey = NULL; + LONG lResult; + LPCTSTR lpSubKey = TEXT( sSubKey.GetBuffer()); + lResult = RegCreateKeyEx( hBaseKey, lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL ); + if( ERROR_SUCCESS == lResult ) + { + LPCTSTR szValue = TEXT( rtl::OUStringToOString( aValue, RTL_TEXTENCODING_UTF8 ).getStr() ); + DWORD cbData = sizeof(TCHAR) * (_tcslen(szValue) + 1); + LPCTSTR lpValueName = TEXT(maKey.GetBuffer()); + lResult = RegSetValueEx( hKey, lpValueName, NULL, REG_SZ, (LPBYTE)szValue, cbData ); + RegCloseKey( hKey ); + } + } + return; +#endif + throw uno::RuntimeException( rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("Not implemented")), uno::Reference< uno::XInterface >() ); + } + } SwVbaSystem::SwVbaSystem( uno::Reference<uno::XComponentContext >& xContext ): SwVbaSystem_BASE( uno::Reference< XHelperInterface >(), xContext ) @@ -146,19 +251,19 @@ SwVbaSystem::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException) uno::Any SAL_CALL SwVbaSystem::PrivateProfileString( const rtl::OUString& rFilename, const rtl::OUString& rSection, const rtl::OUString& rKey ) throw ( uno::RuntimeException ) { - if( rFilename.getLength() == 0 ) - throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() ); - // FIXME: need to detect whether it is a relative file path // we need to detect if this is a URL, if not then assume its a file path rtl::OUString sFileUrl; - INetURLObject aObj; - aObj.SetURL( rFilename ); - bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID; - if ( bIsURL ) - sFileUrl = rFilename; - else - osl::FileBase::getFileURLFromSystemPath( rFilename, sFileUrl); + if( rFilename.getLength() ) + { + INetURLObject aObj; + aObj.SetURL( rFilename ); + bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID; + if ( bIsURL ) + sFileUrl = rFilename; + else + osl::FileBase::getFileURLFromSystemPath( rFilename, sFileUrl); + } ByteString aGroupName = ByteString( rSection.getStr(), RTL_TEXTENCODING_DONTKNOW); ByteString aKey = ByteString( rKey.getStr(), RTL_TEXTENCODING_DONTKNOW); diff --git a/sw/source/ui/vba/vbatable.cxx b/sw/source/ui/vba/vbatable.cxx index 11969d6717a0..73d91ad492c8 100644 --- a/sw/source/ui/vba/vbatable.cxx +++ b/sw/source/ui/vba/vbatable.cxx @@ -9,11 +9,13 @@ #include <com/sun/star/container/XNamed.hpp> #include "vbaborders.hxx" #include "vbapalette.hxx" +#include "vbarows.hxx" +#include "vbacolumns.hxx" using namespace ::ooo::vba; using namespace ::com::sun::star; -SwVbaTable::SwVbaTable( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextDocument >& rDocument, const uno::Reference< css::text::XTextTable >& xTextTable) throw ( uno::RuntimeException ) : SwVbaTable_BASE( rParent, rContext ), mxTextDocument( rDocument ) +SwVbaTable::SwVbaTable( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextDocument >& rDocument, const uno::Reference< text::XTextTable >& xTextTable) throw ( uno::RuntimeException ) : SwVbaTable_BASE( rParent, rContext ), mxTextDocument( rDocument ) { mxTextTable.set( xTextTable, uno::UNO_QUERY_THROW ); } @@ -75,6 +77,26 @@ SwVbaTable::Borders( const uno::Any& index ) throw (uno::RuntimeException) return uno::makeAny( xCol ); } +uno::Any SAL_CALL +SwVbaTable::Rows( const uno::Any& index ) throw (uno::RuntimeException) +{ + uno::Reference< table::XTableRows > xTableRows( mxTextTable->getRows(), uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xCol( new SwVbaRows( this, mxContext, mxTextTable, xTableRows ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + +uno::Any SAL_CALL +SwVbaTable::Columns( const uno::Any& index ) throw (uno::RuntimeException) +{ + uno::Reference< table::XTableColumns > xTableColumns( mxTextTable->getColumns(), uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xCol( new SwVbaColumns( this, mxContext, mxTextTable, xTableColumns ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + // XHelperInterface rtl::OUString& SwVbaTable::getServiceImplName() diff --git a/sw/source/ui/vba/vbatable.hxx b/sw/source/ui/vba/vbatable.hxx index 7d913d718895..d6da8c9afec4 100644 --- a/sw/source/ui/vba/vbatable.hxx +++ b/sw/source/ui/vba/vbatable.hxx @@ -21,6 +21,9 @@ public: virtual css::uno::Reference< ::ooo::vba::word::XRange > SAL_CALL ConvertToText( const css::uno::Any& Separator, const css::uno::Any& NestedTables ) throw (css::script::BasicErrorException, css::uno::RuntimeException); virtual rtl::OUString SAL_CALL getName( ) throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL Borders( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Rows( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Columns( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + // XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); diff --git a/sw/source/ui/vba/vbatables.cxx b/sw/source/ui/vba/vbatables.cxx index 9a10622400d3..9ca798a6ce6a 100644 --- a/sw/source/ui/vba/vbatables.cxx +++ b/sw/source/ui/vba/vbatables.cxx @@ -4,6 +4,9 @@ #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextTablesSupplier.hpp> #include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/table/XCellRange.hpp> #include <comphelper/componentcontext.hxx> using namespace ::ooo::vba; @@ -26,7 +29,89 @@ uno::Any lcl_createTable( const uno::Reference< XHelperInterface >& xParent, con return uno::makeAny( xTable ); } +sal_Bool lcl_isInHeaderFooter( const uno::Reference< text::XTextTable >& xTable ) +{ + uno::Reference< text::XTextContent > xTextContent( xTable, uno::UNO_QUERY_THROW ); + uno::Reference< text::XText > xText = xTextContent->getAnchor()->getText(); + uno::Reference< lang::XServiceInfo > xServiceInfo( xText, uno::UNO_QUERY_THROW ); + rtl::OUString aImplName = xServiceInfo->getImplementationName(); + if( aImplName.equalsAscii("SwXHeadFootText") ) + return sal_True; + return sal_False; +} + typedef ::cppu::WeakImplHelper1< css::container::XEnumeration > EnumBase; +typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XNameAccess > TableCollectionHelper_Base; +typedef std::vector< uno::Reference< text::XTextTable > > XTextTableVec; + +class TableCollectionHelper : public TableCollectionHelper_Base +{ + XTextTableVec mxTables; + XTextTableVec::iterator cachePos; + +public: + TableCollectionHelper( const uno::Reference< frame::XModel >& xDocument ) + { + // only count the tables in the body text, not in the header/footer + uno::Reference< container::XIndexAccess > xTables = lcl_getTables( xDocument ); + sal_Int32 nCount = xTables->getCount(); + for( sal_Int32 i = 0; i < nCount; i++ ) + { + uno::Reference< text::XTextTable > xTable( xTables->getByIndex( i ) , uno::UNO_QUERY_THROW ); + if( !lcl_isInHeaderFooter( xTable ) ) + mxTables.push_back( xTable ); + } + cachePos = mxTables.begin(); + } + // XIndexAccess + virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) + { + return mxTables.size(); + } + virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( Index < 0 || Index >= getCount() ) + throw lang::IndexOutOfBoundsException(); + uno::Reference< text::XTextTable > xTable( mxTables[ Index ], uno::UNO_QUERY_THROW ); + return uno::makeAny( xTable ); + } + // XElementAccess + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) { return text::XTextTable::static_type(0); } + virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) { return getCount() > 0 ; } + // XNameAcess + virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasByName(aName) ) + throw container::NoSuchElementException(); + uno::Reference< text::XTextTable > xTable( *cachePos, uno::UNO_QUERY_THROW ); + return uno::makeAny( xTable ); + } + virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) + { + uno::Sequence< rtl::OUString > sNames( mxTables.size() ); + rtl::OUString* pString = sNames.getArray(); + XTextTableVec::iterator it = mxTables.begin(); + XTextTableVec::iterator it_end = mxTables.end(); + for ( ; it != it_end; ++it, ++pString ) + { + uno::Reference< container::XNamed > xName( *it, uno::UNO_QUERY_THROW ); + *pString = xName->getName(); + } + return sNames; + } + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException) + { + cachePos = mxTables.begin(); + XTextTableVec::iterator it_end = mxTables.end(); + for ( ; cachePos != it_end; ++cachePos ) + { + uno::Reference< container::XNamed > xName( *cachePos, uno::UNO_QUERY_THROW ); + if ( aName.equalsIgnoreAsciiCase( xName->getName() ) ) + break; + } + return ( cachePos != it_end ); + } +}; class TableEnumerationImpl : public EnumBase { @@ -52,7 +137,7 @@ public: }; -SwVbaTables::SwVbaTables( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xDocument ) : SwVbaTables_BASE( xParent, xContext , lcl_getTables( xDocument ) ), mxDocument( xDocument ) +SwVbaTables::SwVbaTables( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xDocument ) : SwVbaTables_BASE( xParent, xContext , uno::Reference< container::XIndexAccess >( new TableCollectionHelper( xDocument ) ) ), mxDocument( xDocument ) { } @@ -85,6 +170,12 @@ SwVbaTables::Add( const uno::Reference< word::XRange >& Range, const uno::Any& N uno::Reference< text::XTextContent > xContext( xTable, uno::UNO_QUERY_THROW ); xText->insertTextContent( xTextRange, xContext, true ); + + // move the current cursor to the first table cell + uno::Reference< table::XCellRange > xCellRange( xTable, uno::UNO_QUERY_THROW ); + uno::Reference< text::XText> xFirstCellText( xCellRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW ); + word::getXTextViewCursor( mxDocument )->gotoRange( xFirstCellText->getStart(), sal_False ); + uno::Reference< word::XTable > xVBATable( new SwVbaTable( mxParent, mxContext, pVbaRange->getDocument(), xTable ) ); return xVBATable; } diff --git a/sw/source/ui/vba/vbatemplate.cxx b/sw/source/ui/vba/vbatemplate.cxx index 68476b301a17..ae7a1fda2184 100644 --- a/sw/source/ui/vba/vbatemplate.cxx +++ b/sw/source/ui/vba/vbatemplate.cxx @@ -30,12 +30,35 @@ #include "vbaautotextentry.hxx" #include <comphelper/processfactory.hxx> #include <com/sun/star/text/XAutoTextContainer.hpp> +#include <tools/urlobj.hxx> +#include <osl/file.hxx> using namespace ::ooo::vba; using namespace ::com::sun::star; -SwVbaTemplate::SwVbaTemplate( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const css::uno::Reference< css::frame::XModel >& rModel, const rtl::OUString& rName ) - : SwVbaTemplate_BASE( rParent, rContext ), mxModel( rModel ), msName( rName ) +String lcl_CheckGroupName( const String& rGroupName ) +{ + String sRet; + //group name should contain only A-Z and a-z and spaces + for( xub_StrLen i = 0; i < rGroupName.Len(); i++ ) + { + sal_Unicode cChar = rGroupName.GetChar(i); + if( (cChar >= 'A' && cChar <= 'Z') || + (cChar >= 'a' && cChar <= 'z') || + (cChar >= '0' && cChar <= '9') || + cChar == '_' || cChar == 0x20 ) + { + sRet += cChar; + } + } + sRet.EraseLeadingChars(); + sRet.EraseTrailingChars(); + return sRet; +} + + +SwVbaTemplate::SwVbaTemplate( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const css::uno::Reference< css::frame::XModel >& rModel, const rtl::OUString& rFullUrl ) + : SwVbaTemplate_BASE( rParent, rContext ), mxModel( rModel ), msFullUrl( rFullUrl ) { } @@ -47,7 +70,27 @@ SwVbaTemplate::~SwVbaTemplate() rtl::OUString SwVbaTemplate::getName() throw ( css::uno::RuntimeException ) { - return msName; + rtl::OUString sName; + if( msFullUrl.getLength() ) + { + INetURLObject aURL( msFullUrl ); + ::osl::File::getSystemPathFromFileURL( aURL.GetLastName(), sName ); + } + return sName; +} + +rtl::OUString +SwVbaTemplate::getPath() throw ( css::uno::RuntimeException ) +{ + rtl::OUString sPath; + if( msFullUrl.getLength() ) + { + INetURLObject aURL( msFullUrl ); + rtl::OUString sURL( aURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + sURL = sURL.copy( 0, sURL.getLength() - aURL.GetLastName().getLength() - 1 ); + ::osl::File::getSystemPathFromFileURL( sURL, sPath ); + } + return sPath; } uno::Any SAL_CALL @@ -58,17 +101,18 @@ SwVbaTemplate::AutoTextEntries( const uno::Any& index ) throw (uno::RuntimeExcep // the default template is "Normal.dot" in Word. rtl::OUString sGroup( RTL_CONSTASCII_USTRINGPARAM("Normal") ); - sal_Int32 nIndex = msName.lastIndexOf( sal_Unicode('.') ); + rtl::OUString sName = getName(); + sal_Int32 nIndex = sName.lastIndexOf( sal_Unicode('.') ); if( nIndex > 0 ) { - sGroup = msName.copy( 0, msName.lastIndexOf( sal_Unicode('.') ) ); - // OSL_TRACE("SwVbaTemplate::AutoTextEntries: %s", rtl::OUStringToOString( sGroup, RTL_TEXTENCODING_UTF8 ).getStr() ); + sGroup = sName.copy( 0, sName.lastIndexOf( sal_Unicode('.') ) ); } + String sNewGroup = lcl_CheckGroupName( sGroup ); uno::Reference< container::XIndexAccess > xGroup; - if( xAutoTextContainer->hasByName( sGroup ) ) + if( xAutoTextContainer->hasByName( sNewGroup ) ) { - xGroup.set( xAutoTextContainer->getByName( sGroup ), uno::UNO_QUERY_THROW ); + xGroup.set( xAutoTextContainer->getByName( sNewGroup ), uno::UNO_QUERY_THROW ); } else { diff --git a/sw/source/ui/vba/vbatemplate.hxx b/sw/source/ui/vba/vbatemplate.hxx index 073e5cc5db1e..9d959b221bda 100644 --- a/sw/source/ui/vba/vbatemplate.hxx +++ b/sw/source/ui/vba/vbatemplate.hxx @@ -36,7 +36,7 @@ class SwVbaTemplate : public SwVbaTemplate_BASE { private: css::uno::Reference< css::frame::XModel > mxModel; - rtl::OUString msName; + rtl::OUString msFullUrl; public: SwVbaTemplate( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::frame::XModel >& rModel, const rtl::OUString& ); @@ -44,6 +44,7 @@ public: // XTemplate virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getPath() throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL AutoTextEntries( const css::uno::Any& index ) throw (css::uno::RuntimeException); // XHelperInterface virtual rtl::OUString& getServiceImplName(); diff --git a/sw/source/ui/vba/vbaview.cxx b/sw/source/ui/vba/vbaview.cxx index 9cb8bf1490ce..c1d8319de24f 100644 --- a/sw/source/ui/vba/vbaview.cxx +++ b/sw/source/ui/vba/vbaview.cxx @@ -92,20 +92,20 @@ SwVbaView::getSeekView() throw (css::uno::RuntimeException) } else if( aImplName.equalsAscii("SwXHeadFootText") ) { - if( HeaderFooterHelper::isHeader( mxModel, xCurrentText ) ) + if( HeaderFooterHelper::isHeader( mxModel ) ) { - if( HeaderFooterHelper::isFirstPageHeader( mxModel, xCurrentText ) ) + if( HeaderFooterHelper::isFirstPageHeader( mxModel ) ) return word::WdSeekView::wdSeekFirstPageHeader; - else if( HeaderFooterHelper::isEvenPagesHeader( mxModel, xCurrentText ) ) + else if( HeaderFooterHelper::isEvenPagesHeader( mxModel ) ) return word::WdSeekView::wdSeekEvenPagesHeader; else return word::WdSeekView::wdSeekPrimaryHeader; } else { - if( HeaderFooterHelper::isFirstPageFooter( mxModel, xCurrentText ) ) + if( HeaderFooterHelper::isFirstPageFooter( mxModel ) ) return word::WdSeekView::wdSeekFirstPageFooter; - else if( HeaderFooterHelper::isEvenPagesFooter( mxModel, xCurrentText ) ) + else if( HeaderFooterHelper::isEvenPagesFooter( mxModel ) ) return word::WdSeekView::wdSeekEvenPagesFooter; else return word::WdSeekView::wdSeekPrimaryFooter; @@ -132,6 +132,7 @@ SwVbaView::setSeekView( ::sal_Int32 _seekview ) throw (css::uno::RuntimeExceptio // if( _seekview == getSeekView() ) // return; + word::gotoSelectedObjectAnchor( mxModel ); switch( _seekview ) { case word::WdSeekView::wdSeekFirstPageFooter: @@ -181,7 +182,7 @@ SwVbaView::setSeekView( ::sal_Int32 _seekview ) throw (css::uno::RuntimeExceptio { uno::Reference< text::XTextDocument > xTextDocument( mxModel, uno::UNO_QUERY_THROW ); uno::Reference< text::XText > xText = xTextDocument->getText(); - mxViewCursor->gotoRange( getFirstObjectPosition( xText ), sal_False ); + mxViewCursor->gotoRange( word::getFirstObjectPosition( xText ), sal_False ); break; } } @@ -376,28 +377,7 @@ uno::Reference< text::XTextRange > SwVbaView::getHFTextRange( sal_Int32 nType ) { DebugHelper::exception( SbERR_INTERNAL_ERROR, rtl::OUString() ); } - uno::Reference< text::XTextRange > xTextRange = getFirstObjectPosition( xText ); - return xTextRange; -} - -uno::Reference< text::XTextRange > SwVbaView::getFirstObjectPosition( const uno::Reference< text::XText >& xText ) throw (uno::RuntimeException) -{ - // if the first object is table, get the position of first cell - uno::Reference< text::XTextRange > xTextRange; - uno::Reference< container::XEnumerationAccess > xParaAccess( xText, uno::UNO_QUERY_THROW ); - uno::Reference< container::XEnumeration> xParaEnum = xParaAccess->createEnumeration(); - if( xParaEnum->hasMoreElements() ) - { - uno::Reference< lang::XServiceInfo > xServiceInfo( xParaEnum->nextElement(), uno::UNO_QUERY_THROW ); - if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextTable") ) ) ) - { - uno::Reference< table::XCellRange > xCellRange( xServiceInfo, uno::UNO_QUERY_THROW ); - uno::Reference< text::XText> xFirstCellText( xCellRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW ); - xTextRange = xFirstCellText->getStart(); - } - } - if( !xTextRange.is() ) - xTextRange = xText->getStart(); + uno::Reference< text::XTextRange > xTextRange = word::getFirstObjectPosition( xText ); return xTextRange; } diff --git a/sw/source/ui/vba/vbawindow.cxx b/sw/source/ui/vba/vbawindow.cxx index e3d9bddbc7aa..a4306382372e 100644 --- a/sw/source/ui/vba/vbawindow.cxx +++ b/sw/source/ui/vba/vbawindow.cxx @@ -25,12 +25,21 @@ * ************************************************************************/ #include <vbahelper/helperdecl.hxx> +#include <ooo/vba/word/WdWindowState.hpp> +#include <vcl/wrkwin.hxx> + #include "vbawindow.hxx" #include "vbaglobals.hxx" #include "vbadocument.hxx" #include "vbaview.hxx" #include "vbapanes.hxx" #include "vbapane.hxx" +#include "wordvbahelper.hxx" +#include <view.hxx> +// #FIXME where has SfxTopViewFrame gone +#if 0 +#include <sfx2/topfrm.hxx> +#endif using namespace ::com::sun::star; using namespace ::ooo::vba; @@ -73,6 +82,44 @@ void SAL_CALL SwVbaWindow::setView( const uno::Any& _view ) throw (uno::RuntimeE } uno::Any SAL_CALL +SwVbaWindow::getWindowState() throw (uno::RuntimeException) +{ + sal_Int32 nwindowState = word::WdWindowState::wdWindowStateNormal; + SwView* pView = word::getView( m_xModel ); + SfxViewFrame* pViewFrame = pView -> GetViewFrame(); + WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow(); + if ( pWork ) + { + if ( pWork -> IsMaximized()) + nwindowState = word::WdWindowState::wdWindowStateMaximize; + else if (pWork -> IsMinimized()) + nwindowState = word::WdWindowState::wdWindowStateMinimize; + } + return uno::makeAny( nwindowState ); +} + +void SAL_CALL +SwVbaWindow::setWindowState( const uno::Any& _windowstate ) throw (uno::RuntimeException) +{ + sal_Int32 nwindowState = word::WdWindowState::wdWindowStateMaximize; + _windowstate >>= nwindowState; + SwView* pView = word::getView( m_xModel ); + SfxViewFrame* pViewFrame = pView -> GetViewFrame(); + WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow(); + if ( pWork ) + { + if ( nwindowState == word::WdWindowState::wdWindowStateMaximize ) + pWork -> Maximize(); + else if (nwindowState == word::WdWindowState::wdWindowStateMinimize) + pWork -> Minimize(); + else if (nwindowState == word::WdWindowState::wdWindowStateNormal) + pWork -> Restore(); + else + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Invalid Parameter" ) ), uno::Reference< uno::XInterface >() ); + } +} + +uno::Any SAL_CALL SwVbaWindow::Panes( const uno::Any& aIndex ) throw (uno::RuntimeException) { uno::Reference< XCollection > xPanes( new SwVbaPanes( this, mxContext, m_xModel ) ); diff --git a/sw/source/ui/vba/vbawindow.hxx b/sw/source/ui/vba/vbawindow.hxx index 0809d2b73685..c93e95fd7e55 100644 --- a/sw/source/ui/vba/vbawindow.hxx +++ b/sw/source/ui/vba/vbawindow.hxx @@ -44,6 +44,8 @@ public: // Attributes virtual css::uno::Any SAL_CALL getView() throw (css::uno::RuntimeException); virtual void SAL_CALL setView( const css::uno::Any& _view ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getWindowState() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWindowState( const css::uno::Any& _windowstate ) throw (css::uno::RuntimeException); // Methods virtual void SAL_CALL Activate( ) throw (css::uno::RuntimeException); virtual void SAL_CALL Close( const css::uno::Any& SaveChanges, const css::uno::Any& RouteDocument ) throw (css::uno::RuntimeException); diff --git a/sw/source/ui/vba/wordvbahelper.cxx b/sw/source/ui/vba/wordvbahelper.cxx index 82dfacf4f18d..c4639a0e329f 100644 --- a/sw/source/ui/vba/wordvbahelper.cxx +++ b/sw/source/ui/vba/wordvbahelper.cxx @@ -29,11 +29,16 @@ #include <comphelper/processfactory.hxx> #include <com/sun/star/frame/XController.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include <com/sun/star/text/XTextTable.hpp> +#include <com/sun/star/table/XCellRange.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> #include <unotxdoc.hxx> #include <doc.hxx> +#include <view.hxx> using namespace ::com::sun::star; using namespace ::ooo::vba; @@ -71,8 +76,13 @@ uno::Reference< text::XTextViewCursor > getXTextViewCursor( const uno::Reference uno::Reference< style::XStyle > getCurrentPageStyle( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) { uno::Reference< beans::XPropertySet > xCursorProps( getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); + return getCurrentPageStyle( xModel, xCursorProps ); +} + +uno::Reference< style::XStyle > getCurrentPageStyle( const uno::Reference< frame::XModel >& xModel, const uno::Reference< beans::XPropertySet >& xProps ) throw (uno::RuntimeException) +{ rtl::OUString aPageStyleName; - xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))) >>= aPageStyleName; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))) >>= aPageStyleName; uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( xModel, uno::UNO_QUERY_THROW ); uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_QUERY_THROW ); uno::Reference< container::XNameAccess > xPageStyles( xSytleFamNames->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyles") ) ), uno::UNO_QUERY_THROW ); @@ -87,6 +97,92 @@ sal_Int32 getPageCount( const uno::Reference< frame::XModel>& xModel ) throw (un return pDocShell ? pDocShell->GetDoc()->GetPageCount() : 0; } +uno::Reference< style::XStyle > getDefaultParagraphStyle( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) +{ + uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( xModel, uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xParaStyles( xSytleFamNames->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParagraphStyles") ) ), uno::UNO_QUERY_THROW ); + uno::Reference< style::XStyle > xStyle( xParaStyles->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") ) ), uno::UNO_QUERY_THROW ); + + return xStyle; +} + +uno::Reference< text::XTextRange > getFirstObjectPosition( const uno::Reference< text::XText >& xText ) throw (uno::RuntimeException) +{ + // if the first object is table, get the position of first cell + uno::Reference< text::XTextRange > xTextRange; + uno::Reference< container::XEnumerationAccess > xParaAccess( xText, uno::UNO_QUERY_THROW ); + uno::Reference< container::XEnumeration> xParaEnum = xParaAccess->createEnumeration(); + if( xParaEnum->hasMoreElements() ) + { + uno::Reference< lang::XServiceInfo > xServiceInfo( xParaEnum->nextElement(), uno::UNO_QUERY_THROW ); + if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextTable") ) ) ) + { + uno::Reference< table::XCellRange > xCellRange( xServiceInfo, uno::UNO_QUERY_THROW ); + uno::Reference< text::XText> xFirstCellText( xCellRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW ); + xTextRange = xFirstCellText->getStart(); + } + } + if( !xTextRange.is() ) + xTextRange = xText->getStart(); + return xTextRange; +} + +uno::Reference< text::XText > getCurrentXText( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) +{ + uno::Reference< text::XTextRange > xTextRange; + uno::Reference< text::XTextContent > xTextContent( xModel->getCurrentSelection(), uno::UNO_QUERY ); + if( !xTextContent.is() ) + { + uno::Reference< container::XIndexAccess > xIndexAccess( xModel->getCurrentSelection(), uno::UNO_QUERY ); + if( xIndexAccess.is() ) + { + xTextContent.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY ); + } + } + + if( xTextContent.is() ) + xTextRange.set( xTextContent->getAnchor(), uno::UNO_QUERY ); + + if( !xTextRange.is() ) + xTextRange.set( getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); + + uno::Reference< text::XText > xText; + try + { + xText.set( xTextRange->getText(), uno::UNO_QUERY ); + } + catch( uno::RuntimeException& ) + { + //catch exception "no text selection" + } + uno::Reference< beans::XPropertySet > xVCProps( xTextRange, uno::UNO_QUERY_THROW ); + while( xVCProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ) >>= xTextContent ) + { + xText = xTextContent->getAnchor()->getText(); + xVCProps.set( xText->createTextCursor(), uno::UNO_QUERY_THROW ); + } + + if( !xText.is() ) + throw uno::RuntimeException( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "no text selection" ) ), uno::Reference< uno::XInterface >() ); + + return xText; +} + +sal_Bool gotoSelectedObjectAnchor( const uno::Reference< frame::XModel>& xModel ) throw (uno::RuntimeException) +{ + sal_Bool isObjectSelected = sal_False; + uno::Reference< text::XTextContent > xTextContent( xModel->getCurrentSelection(), uno::UNO_QUERY ); + if( xTextContent.is() ) + { + uno::Reference< text::XTextRange > xTextRange( xTextContent->getAnchor(), uno::UNO_QUERY_THROW ); + uno::Reference< view::XSelectionSupplier > xSelectSupp( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + xSelectSupp->select( uno::makeAny( xTextRange ) ); + isObjectSelected = sal_True; + } + return isObjectSelected; +} + } // word } // } // diff --git a/sw/source/ui/vba/wordvbahelper.hxx b/sw/source/ui/vba/wordvbahelper.hxx index 0629d613a724..faf7db26d5ca 100644 --- a/sw/source/ui/vba/wordvbahelper.hxx +++ b/sw/source/ui/vba/wordvbahelper.hxx @@ -32,6 +32,8 @@ #include <com/sun/star/text/XTextViewCursor.hpp> #include <com/sun/star/text/XPageCursor.hpp> #include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/text/XTextTable.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> class SwDocShell; class SwView; @@ -46,7 +48,20 @@ namespace ooo SwView* getView( const css::uno::Reference< css::frame::XModel>& xModel ); css::uno::Reference< css::text::XTextViewCursor > getXTextViewCursor( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); css::uno::Reference< css::style::XStyle > getCurrentPageStyle( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + css::uno::Reference< css::style::XStyle > getCurrentPageStyle( const css::uno::Reference< css::frame::XModel>& xModel, const css::uno::Reference< css::beans::XPropertySet >& xProps ) throw (css::uno::RuntimeException); sal_Int32 getPageCount( const css::uno::Reference< css::frame::XModel>& xModel ) throw (css::uno::RuntimeException); + css::uno::Reference< css::style::XStyle > getDefaultParagraphStyle( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + css::uno::Reference< css::text::XTextRange > getFirstObjectPosition( const css::uno::Reference< css::text::XText >& xText ) throw (css::uno::RuntimeException); + css::uno::Reference< css::text::XText > getCurrentXText( const css::uno::Reference< css::frame::XModel>& xModel ) throw (css::uno::RuntimeException); + sal_Bool gotoSelectedObjectAnchor( const css::uno::Reference< css::frame::XModel>& xModel ) throw (css::uno::RuntimeException); + + enum E_DIRECTION + { + MOVE_LEFT = 1, + MOVE_RIGHT, + MOVE_UP, + MOVE_DOWN + }; } // word } // vba diff --git a/sw/util/makefile.mk b/sw/util/makefile.mk index 61b4a3ed5e1d..39fa183ae5e9 100644 --- a/sw/util/makefile.mk +++ b/sw/util/makefile.mk @@ -337,6 +337,7 @@ SHL4STDLIBS= \ $(SALLIB) \ $(ICUUCLIB) \ $(BASICLIB) \ + $(MSFILTERLIB) \ $(I18NUTILLIB) .IF "$(ENABLE_VBA)" == "YES" @@ -371,6 +372,10 @@ SHL5STDLIBS= \ $(SVXCORELIB) \ $(MSFILTERLIB) +.IF "$(GUI)"=="WNT" +SHL5STDLIBS+=$(SHELLLIB) +.ENDIF #WNT + SHL5DEPN=$(SHL1TARGETN) SHL5LIBS=$(SLB)$/$(TARGET_VBA).lib .ENDIF # .IF "$(ENABLE_VBA)" == "YES" |