diff options
119 files changed, 11345 insertions, 628 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index ba52f459f2..dc9bf196ff 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -80,9 +80,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> @@ -409,9 +407,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 @@ -2137,9 +2134,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 9abc65e2ac..7a47dc2ea9 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(); @@ -303,6 +304,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 bf6ba2852c..805b68c472 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 374753ba22..2dfc961cc6 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 d0b4f3043d..86804ef25d 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 e2c101bdd8..d1a29eb6b2 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 @@ -2738,7 +2736,6 @@ void SwDoc::ChkCondColls() } } -#ifdef FUTURE_VBA uno::Reference< script::vba::XVBAEventProcessor > SwDoc::GetVbaEventProcessor() { @@ -2757,7 +2754,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 bbabfa96b5..42f3c13a73 100644 --- a/sw/source/core/unocore/unocoll.cxx +++ b/sw/source/core/unocore/unocoll.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -77,7 +77,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; @@ -87,6 +96,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; } + +}; + /****************************************************************************** * ******************************************************************************/ @@ -209,6 +396,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 }, @@ -389,6 +580,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 f5aee26ca4..a7e10a77c0 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 228b489557..6a98b9756c 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 1ca992fa02..730a67d7c1 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 6bf1b0bbb2..47d4836bd1 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, @@ -587,10 +676,10 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt, { pObj->SetMergedItemSet(aSet); pObj->SetModel(pSdrModel); - + if (bVerticalText && dynamic_cast< SdrTextObj* >( pObj ) ) dynamic_cast< SdrTextObj* >( pObj )->SetVerticalWriting(sal_True); - + if ( bIsSimpleDrawingTextBox ) { if ( nTextRotationAngle ) @@ -609,7 +698,7 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt, if ( ( ( rObjData.nSpFlags & SP_FFLIPV ) || mnFix16Angle || nTextRotationAngle ) && dynamic_cast< SdrObjCustomShape* >( pObj ) ) { SdrObjCustomShape* pCustomShape = dynamic_cast< SdrObjCustomShape* >( pObj ); - + double fExtraTextRotation = 0.0; if ( mnFix16Angle && !( GetPropertyValue( DFF_Prop_FitTextToShape ) & 4 ) ) { // text is already rotated, we have to take back the object rotation if DFF_Prop_RotateText is false @@ -861,13 +950,13 @@ long lcl_GetTrueMargin(const SvxLRSpaceItem &rLR, const SwNumFmt &rFmt, // --> OD 2010-05-06 #i103711# // --> OD 2010-05-11 #i105414# -void SyncIndentWithList( SvxLRSpaceItem &rLR, +void SyncIndentWithList( SvxLRSpaceItem &rLR, const SwNumFmt &rFmt, const bool bFirstLineOfstSet, const bool bLeftIndentSet ) { if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION ) - { + { long nWantedFirstLinePos; long nExtraListIndent = lcl_GetTrueMargin(rLR, rFmt, nWantedFirstLinePos); rLR.SetTxtLeft(nWantedFirstLinePos - nExtraListIndent); @@ -875,7 +964,7 @@ void SyncIndentWithList( SvxLRSpaceItem &rLR, } else if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT ) { - if ( !bFirstLineOfstSet && bLeftIndentSet && + if ( !bFirstLineOfstSet && bLeftIndentSet && rFmt.GetFirstLineIndent() != 0 ) { rLR.SetTxtFirstLineOfst( rFmt.GetFirstLineIndent() ); @@ -944,7 +1033,7 @@ void SwWW8FltControlStack::SetAttrInDoc(const SwPosition& rTmpPos, pNum = GetNumFmtFromStack(*aRegion.GetPoint(), *pTxtNode); if (!pNum) - { + { pNum = GetNumFmtFromTxtNode(*pTxtNode); } @@ -3799,11 +3888,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; @@ -4087,7 +4333,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 @@ -4161,26 +4459,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 a61dec4315..1f9a90ed0b 100644 --- a/sw/source/filter/ww8/ww8par.hxx +++ b/sw/source/filter/ww8/ww8par.hxx @@ -1421,7 +1421,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/filter/ww8/ww8toolbar.cxx b/sw/source/filter/ww8/ww8toolbar.cxx new file mode 100644 index 0000000000..d0d5a0f49a --- /dev/null +++ b/sw/source/filter/ww8/ww8toolbar.cxx @@ -0,0 +1,1301 @@ +#include "ww8toolbar.hxx" +#include <rtl/ustrbuf.hxx> +#include <stdarg.h> +#include <com/sun/star/ui/XUIConfigurationPersistence.hpp> +#include <com/sun/star/ui/XUIConfigurationPersistence.hpp> +#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XSingleComponentFactory.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/ui/XImageManager.hpp> +#include <com/sun/star/ui/ItemType.hpp> +#include <fstream> +#include <comphelper/processfactory.hxx> +#include <vcl/graph.hxx> +#include <map> +using namespace com::sun::star; + +// no. of visual data elements in a CTB ( fixed ) +const short nVisualData = 5; + +typedef std::map< sal_Int16, rtl::OUString > IdToString; + +class MSOWordCommandConvertor : public MSOCommandConvertor +{ + IdToString msoToOOcmd; + IdToString tcidToOOcmd; +public: + MSOWordCommandConvertor(); + virtual rtl::OUString MSOCommandToOOCommand( sal_Int16 msoCmd ); + virtual rtl::OUString MSOTCIDToOOCommand( sal_Int16 key ); +}; + +MSOWordCommandConvertor::MSOWordCommandConvertor() +{ + // mso command id to ooo command string + // #FIXME and *HUNDREDS* of id's to added here + msoToOOcmd[ 0x20b ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:CloseDoc") ); + msoToOOcmd[ 0x50 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:Open") ); + + // mso tcid to ooo command string + // #FIXME and *HUNDREDS* of id's to added here + tcidToOOcmd[ 0x9d9 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:Print") ); +} + +rtl::OUString MSOWordCommandConvertor::MSOCommandToOOCommand( sal_Int16 key ) +{ + rtl::OUString sResult; + IdToString::iterator it = msoToOOcmd.find( key ); + if ( it != msoToOOcmd.end() ) + sResult = it->second; + return sResult; +} + +rtl::OUString MSOWordCommandConvertor::MSOTCIDToOOCommand( sal_Int16 key ) +{ + rtl::OUString sResult; + IdToString::iterator it = tcidToOOcmd.find( key ); + if ( it != tcidToOOcmd.end() ) + sResult = it->second; + return sResult; +} + + +CTBWrapper::CTBWrapper( bool bReadId ) : Tcg255SubStruct( bReadId ) +,reserved2(0) +,reserved3(0) +,reserved4(0) +,reserved5(0) +,cbTBD(0) +,cCust(0) +,cbDTBC(0) +,rtbdc(0) +{ +} + +CTBWrapper::~CTBWrapper() +{ +} + +Customization* CTBWrapper::GetCustomizaton( sal_Int16 index ) +{ + if ( index < 0 || index >= static_cast<sal_Int16>( rCustomizations.size() ) ) + return NULL; + return &rCustomizations[ index ]; +} + +CTB* CTBWrapper::GetCustomizationData( const rtl::OUString& sTBName ) +{ + CTB* pCTB = NULL; + for ( std::vector< Customization >::iterator it = rCustomizations.begin(); it != rCustomizations.end(); ++it ) + { + if ( it->GetCustomizationData() && it->GetCustomizationData()->GetName().equals( sTBName ) ) + { + pCTB = it->GetCustomizationData(); + break; + } + } + return pCTB; +} + +bool CTBWrapper::Read( SvStream* pS ) +{ + OSL_TRACE("CTBWrapper::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + Tcg255SubStruct::Read( pS ); + *pS >> reserved2 >> reserved3 >> reserved4 >> reserved5; + *pS >> cbTBD >> cCust >> cbDTBC; + long nExpectedPos = pS->Tell() + cbDTBC; + if ( cbDTBC ) + { + // cbDTBC is the size in bytes of the TBC array + // but the size of a TBC element is dynamic ( and this relates to TBDelta's + int nStart = pS->Tell(); + + int bytesRead = 0; + int bytesToRead = cbDTBC - bytesRead; + // cbDTBC specifies the size ( in bytes ) taken by an array ( of unspecified size ) + // of TBC records ( TBC records have dynamic length, so we need to check our position + // after each read ) + do + { + TBC aTBC; + if ( !aTBC.Read( pS ) ) + return false; + rtbdc.push_back( aTBC ); + bytesToRead = cbDTBC - ( pS->Tell() - nStart ); + } while ( bytesToRead > 0 ); + } + if ( static_cast< long >( pS->Tell() ) != nExpectedPos ) + { + // Strange error condition, shouldn't happen ( but does in at least + // one test document ) In the case where it happens the TBC & + // TBCHeader records seem blank??? ( and incorrect ) + OSL_ENSURE( pS->Tell() == nExpectedPos, "### Error: Expected pos not equal to actual pos after reading rtbdc"); + OSL_TRACE("\tPos now is 0x%x should be 0x%x", pS->Tell(), nExpectedPos ); + // seek to correct position after rtbdc + pS->Seek( nExpectedPos ); + } + if ( cCust ) + { + for ( sal_Int32 index = 0; index < cCust; ++index ) + { + Customization aCust( this ); + if ( !aCust.Read( pS ) ) + return false; + rCustomizations.push_back( aCust ); + } + } + std::vector< sal_Int16 >::iterator it_end = dropDownMenuIndices.end(); + for ( std::vector< sal_Int16 >::iterator it = dropDownMenuIndices.begin(); it != it_end; ++it ) + { + rCustomizations[ *it ].bIsDroppedMenuTB = true; + } + return true; +} + +TBC* CTBWrapper::GetTBCAtOffset( sal_uInt32 nStreamOffset ) +{ + for ( std::vector< TBC >::iterator it = rtbdc.begin(); it != rtbdc.end(); ++it ) + { + if ( (*it).GetOffset() == nStreamOffset ) + return &(*it); + } + return NULL; +} + +void CTBWrapper::Print( FILE* fp ) +{ + Indent a; + indent_printf(fp,"[ 0x%x ] CTBWrapper - dump\n", nOffSet ); + bool bRes = ( ch == 0x12 && reserved2 == 0x0 && reserved3 == 0x7 && reserved4 == 0x6 && reserved5 == 0xC ); + if ( bRes ) + indent_printf(fp," sanity check ( first 8 bytes conform )\n"); + else + { + indent_printf(fp," reserved1(0x%x)\n",ch); + indent_printf(fp," reserved2(0x%x)\n",reserved2); + indent_printf(fp," reserved3(0x%x)\n",reserved3); + indent_printf(fp," reserved4(0x%x)\n",reserved4); + indent_printf(fp," reserved5(0x%x)\n",reserved5); + indent_printf(fp,"Quiting dump"); + return; + } + indent_printf(fp," size of TBDelta structures 0x%x\n", cbTBD ); + indent_printf(fp," cCust: no. of cCust structures 0x%x\n",cCust); + indent_printf(fp," cbDTBC: no. of bytes in rtbdc array 0x%x\n", static_cast< unsigned int >( cbDTBC )); + + sal_Int32 index = 0; + + for ( std::vector< TBC >::iterator it = rtbdc.begin(); it != rtbdc.end(); ++it, ++index ) + { + indent_printf(fp," Dumping rtbdc[%d]\n", static_cast< int >( index )); + Indent b; + it->Print( fp ); + } + + index = 0; + + for ( std::vector< Customization >::iterator it = rCustomizations.begin(); it != rCustomizations.end(); ++it, ++index ) + { + indent_printf(fp," Dumping custimization [%d]\n", static_cast< int >( index )); + Indent c; + it->Print(fp); + } +} + +bool CTBWrapper::ImportCustomToolBar( SfxObjectShell& rDocSh ) +{ + for ( std::vector< Customization >::iterator it = rCustomizations.begin(); it != rCustomizations.end(); ++it ) + { + uno::Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + uno::Reference< ui::XModuleUIConfigurationManagerSupplier > xAppCfgSupp( xMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ) ) ), uno::UNO_QUERY_THROW ); + CustomToolBarImportHelper helper( rDocSh, xAppCfgSupp->getUIConfigurationManager( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument" ) ) ) ); + helper.setMSOCommandMap( new MSOWordCommandConvertor() ); + + if ( !(*it).ImportCustomToolBar( *this, helper ) ) + return false; + } + return false; +} + +Customization::Customization( CTBWrapper* wrapper ) : tbidForTBD( 0 ) +,reserved1( 0 ) +, ctbds( 0 ) +, pWrapper( wrapper ) +, bIsDroppedMenuTB( false ) +{ +} + +Customization::~Customization() +{ +} + +bool Customization::Read( SvStream *pS) +{ + OSL_TRACE("Custimization::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + *pS >> tbidForTBD >> reserved1 >> ctbds; + if ( tbidForTBD ) + { + for ( sal_Int32 index = 0; index < ctbds; ++index ) + { + TBDelta aTBDelta; + if (!aTBDelta.Read( pS ) ) + return false; + customizationDataTBDelta.push_back( aTBDelta ); + // Only set the drop down for menu's associated with standard toolbar + if ( aTBDelta.ControlDropsToolBar() && tbidForTBD == 0x25 ) + pWrapper->InsertDropIndex( aTBDelta.CustomizationIndex() ); + } + } + else + { + customizationDataCTB.reset( new CTB() ); + if ( !customizationDataCTB->Read( pS ) ) + return false; + } + return true; +} + +void Customization::Print( FILE* fp ) +{ + Indent a; + indent_printf( fp,"[ 0x%x ] Customization -- dump \n", nOffSet ); + indent_printf( fp," tbidForTBD 0x%x ( should be 0 for CTBs )\n", static_cast< unsigned int >( tbidForTBD )); + indent_printf( fp," reserved1 0x%x \n", reserved1); + indent_printf( fp," ctbds - number of customisations %d(0x%x) \n", ctbds, ctbds ); + if ( !tbidForTBD && !ctbds ) + customizationDataCTB->Print( fp ); + else + { + const char* pToolBar = NULL; + switch ( tbidForTBD ) + { + case 0x9: + pToolBar = "Standard"; + break; + case 0x25: + pToolBar = "Builtin-Menu"; + break; + default: + pToolBar = "Unknown toolbar"; + break; + } + + indent_printf( fp," TBDelta(s) are associated with %s toolbar.\n", pToolBar); + std::vector< TBDelta >::iterator it = customizationDataTBDelta.begin(); + for ( sal_Int32 index = 0; index < ctbds; ++it,++index ) + it->Print( fp ); + } + +} + +bool Customization::ImportMenu( CTBWrapper& rWrapper, CustomToolBarImportHelper& helper ) +{ + if ( tbidForTBD == 0x25 ) // we can handle in a limited way additions the built-in menu bar + { + for ( std::vector< TBDelta >::iterator it = customizationDataTBDelta.begin(); it != customizationDataTBDelta.end(); ++it ) + { + // for each new menu ( control that drops a toolbar ) + // import a toolbar + if ( it->ControlIsInserted() && it->ControlDropsToolBar() ) + { + Customization* pCust = pWrapper->GetCustomizaton( it->CustomizationIndex() ); + if ( pCust ) + { + // currently only support built-in menu + rtl::OUString sMenuBar( RTL_CONSTASCII_USTRINGPARAM("private:resource/menubar/") ); + + sMenuBar = sMenuBar.concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("menubar") ) ); + // Get menu name + TBC* pTBC = pWrapper->GetTBCAtOffset( it->TBCStreamOffset() ); + if ( !pTBC ) + return false; + rtl::OUString sMenuName = pTBC->GetCustomText(); + sMenuName = sMenuName.replace('&','~'); + + // see if the document has already setting for the menubar + + uno::Reference< container::XIndexContainer > xIndexContainer; + bool bHasSettings = false; + if ( helper.getCfgManager()->hasSettings( sMenuBar ) ) + { + xIndexContainer.set( helper.getCfgManager()->getSettings( sMenuBar, sal_True ), uno::UNO_QUERY_THROW ); + bHasSettings = true; + } + else + { + if ( helper.getAppCfgManager()->hasSettings( sMenuBar ) ) + xIndexContainer.set( helper.getAppCfgManager()->getSettings( sMenuBar, sal_True ), uno::UNO_QUERY_THROW ); + else + xIndexContainer.set( helper.getAppCfgManager()->createSettings(), uno::UNO_QUERY_THROW ); + } + + uno::Reference< lang::XSingleComponentFactory > xSCF( xIndexContainer, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + uno::Reference< uno::XComponentContext > xContext( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW ); + // create the popup menu + uno::Sequence< beans::PropertyValue > aPopupMenu( 4 ); + aPopupMenu[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CommandURL") ); + aPopupMenu[0].Value = uno::makeAny( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("vnd.openoffice.org:") ) + sMenuName ); + aPopupMenu[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Label") ); + aPopupMenu[1].Value <<= sMenuName; + aPopupMenu[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Type" ) ); + aPopupMenu[2].Value <<= sal_Int32( 0 ); + aPopupMenu[3].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ItemDescriptorContainer") ); + uno::Reference< container::XIndexContainer > xMenuContainer( xSCF->createInstanceWithContext( xContext ), uno::UNO_QUERY_THROW ); + aPopupMenu[3].Value <<= xMenuContainer; + if ( pCust->customizationDataCTB.get() && !pCust->customizationDataCTB->ImportMenuTB( rWrapper, xMenuContainer, helper ) ) + return false; + OSL_TRACE("** there are %d menu items on the bar, inserting after that", xIndexContainer->getCount() ); + xIndexContainer->insertByIndex( xIndexContainer->getCount(), uno::makeAny( aPopupMenu ) ); + + if ( bHasSettings ) + helper.getCfgManager()->replaceSettings( sMenuBar, uno::Reference< container::XIndexAccess >( xIndexContainer, uno::UNO_QUERY_THROW ) ); + else + helper.getCfgManager()->insertSettings( sMenuBar, uno::Reference< container::XIndexAccess >( xIndexContainer, uno::UNO_QUERY_THROW ) ); + uno::Reference< ui::XUIConfigurationPersistence > xPersistence( helper.getCfgManager(), uno::UNO_QUERY_THROW ); + xPersistence->store(); + } + } + } + return true; + } + return true; +} + +bool Customization::ImportCustomToolBar( CTBWrapper& rWrapper, CustomToolBarImportHelper& helper ) +{ + if ( GetTBIDForTB() == 0x25 ) + return ImportMenu( rWrapper, helper ); + if ( !customizationDataCTB.get() ) + return false; + if ( !customizationDataCTB->IsMenuToolbar() ) + { + if ( !customizationDataCTB->ImportCustomToolBar( rWrapper, helper ) ) + return false; + } + return true; +} + +TBDelta::TBDelta() : doprfatendFlags(0) +,ibts(0) +,cidNext(0) +,cid(0) +,fc(0) +,cbTBC(0) +{ +} + +bool TBDelta::ControlIsModified() +{ + return ( ( doprfatendFlags & 0x3 ) == 0x2 ); +} + +bool TBDelta::ControlIsInserted() +{ + return ( ( doprfatendFlags & 0x3 ) == 0x1 ); +} + +bool TBDelta::ControlIsChanged() +{ + return ( ( doprfatendFlags & 0x3 ) == 0x1 ); +} + +bool TBDelta::ControlDropsToolBar() +{ + return !( CiTBDE & 0x8000 ); +} + +sal_Int32 TBDelta::TBCStreamOffset() +{ + return fc; +} + +sal_Int16 TBDelta::CustomizationIndex() +{ + sal_Int16 nIndex = CiTBDE; + nIndex = nIndex >> 1; + nIndex &= 0x1ff; // only 13 bits are relevant + return nIndex; +} + +bool TBDelta::Read(SvStream *pS) +{ + OSL_TRACE("TBDelta::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + *pS >> doprfatendFlags >> ibts >> cidNext >> cid >> fc ; + *pS >> CiTBDE >> cbTBC; + return true; +} + +void TBDelta::Print( FILE* fp ) +{ + // Like most of the debug output, it's raw and little ( no ) + // interpretation of the data is output ( e.g. flag values etc. ) + indent_printf( fp, "[ 0x%x ] TBDelta -- dump\n", nOffSet ); + indent_printf( fp, " doprfatendFlags 0x%x\n",doprfatendFlags ); + + indent_printf( fp, " ibts 0x%x\n",ibts ); + indent_printf( fp, " cidNext 0x%x\n", static_cast< unsigned int >( cidNext ) ); + indent_printf( fp, " cid 0x%x\n", static_cast< unsigned int >( cid ) ); + indent_printf( fp, " fc 0x%x\n", static_cast< unsigned int >( fc ) ); + indent_printf( fp, " CiTBDE 0x%x\n",CiTBDE ); + indent_printf( fp, " cbTBC 0x%x\n", cbTBC ); + if ( ControlDropsToolBar() ) + { + indent_printf( fp, " this delta is associated with a control that drops a menu toolbar\n", cbTBC ); + indent_printf( fp, " the menu toolbar drops the toolbar defined at index[%d] in the rCustomizations array of the CTBWRAPPER that contains this TBDelta\n", CustomizationIndex() ); + } +} + +CTB::CTB() : cbTBData( 0 ) +,iWCTBl( 0 ) +,reserved( 0 ) +,unused( 0 ) +,cCtls( 0 ) +{ +} + +CTB::~CTB() +{ +} + +bool CTB::IsMenuToolbar() +{ + return tb.IsMenuToolbar(); +} + + +bool CTB::Read( SvStream *pS) +{ + OSL_TRACE("CTB::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + if ( !name.Read( pS ) ) + return false; + *pS >> cbTBData; + if ( !tb.Read( pS ) ) + return false; + for ( short index = 0; index < nVisualData; ++index ) + { + TBVisualData aVisData; + aVisData.Read( pS ); + rVisualData.push_back( aVisData ); + } + + *pS >> iWCTBl >> reserved >> unused >> cCtls; + + if ( cCtls ) + { + for ( sal_Int32 index = 0; index < cCtls; ++index ) + { + TBC aTBC; + if ( !aTBC.Read( pS ) ) + return false; + rTBC.push_back( aTBC ); + } + } + return true; +} + +void +CTB::Print( FILE* fp ) +{ + Indent a; + indent_printf(fp, "[ 0x%x ] CTB - dump\n", nOffSet ); + indent_printf(fp, " name %s\n", rtl::OUStringToOString( name.getString(), RTL_TEXTENCODING_UTF8 ).getStr() ); + indent_printf(fp, " cbTBData size, in bytes, of this structure excluding the name, cCtls, and rTBC fields. %x\n", static_cast< unsigned int >( cbTBData ) ); + + tb.Print(fp); + for ( short counter = 0; counter < nVisualData; ++counter ) + { + indent_printf( fp, " TBVisualData [%d]\n", counter); + Indent b; + rVisualData[ counter ].Print( fp ); + } + indent_printf(fp, " iWCTBl 0x%x reserved 0x%x unused 0x%x cCtls( toolbar controls ) 0x%x \n", static_cast< unsigned int >( iWCTBl ), reserved, unused, static_cast< unsigned int >( cCtls ) ); + if ( cCtls ) + { + for ( sal_Int32 index = 0; index < cCtls; ++index ) + { + + indent_printf(fp, " dumping toolbar control 0x%x\n", static_cast< unsigned int >( index ) ); + rTBC[ index ].Print( fp ); + } + } +} + +bool CTB::ImportCustomToolBar( CTBWrapper& rWrapper, CustomToolBarImportHelper& helper ) +{ + static rtl::OUString sToolbarPrefix( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/custom_" ) ); + bool bRes = false; + try + { + if ( !tb.IsEnabled() ) + return true; // didn't fail, just ignoring + // Create default setting + uno::Reference< container::XIndexContainer > xIndexContainer( helper.getCfgManager()->createSettings(), uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xIndexAccess( xIndexContainer, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( xIndexContainer, uno::UNO_QUERY_THROW ); + + // set UI name for toolbar + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UIName") ), uno::makeAny( name.getString() ) ); + + rtl::OUString sToolBarName = sToolbarPrefix.concat( name.getString() ); + for ( std::vector< TBC >::iterator it = rTBC.begin(); it != rTBC.end(); ++it ) + { + // createToolBar item for control + if ( !it->ImportToolBarControl( rWrapper, xIndexContainer, helper, IsMenuToolbar() ) ) + return false; + } + + OSL_TRACE("Name of toolbar :-/ %s", rtl::OUStringToOString( sToolBarName, RTL_TEXTENCODING_UTF8 ).getStr() ); + + helper.getCfgManager()->insertSettings( sToolBarName, xIndexAccess ); + helper.applyIcons(); +#if 1 // don't think this is necessary + uno::Reference< ui::XUIConfigurationPersistence > xPersistence( helper.getCfgManager()->getImageManager(), uno::UNO_QUERY_THROW ); + xPersistence->store(); + + xPersistence.set( helper.getCfgManager(), uno::UNO_QUERY_THROW ); + xPersistence->store(); +#endif + bRes = true; + } + catch( uno::Exception& e ) + { + OSL_TRACE("***** For some reason we have an exception %s", rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); + bRes = false; + } + return bRes; +} + +bool CTB::ImportMenuTB( CTBWrapper& rWrapper, const css::uno::Reference< css::container::XIndexContainer >& xIndexContainer, CustomToolBarImportHelper& rHelper ) +{ + for ( std::vector< TBC >::iterator it = rTBC.begin(); it != rTBC.end(); ++it ) + { + // createToolBar item for control + if ( !it->ImportToolBarControl( rWrapper, xIndexContainer, rHelper, true ) ) + return false; + } + return true; +} + +TBC::TBC() +{ +} + +TBC::~TBC() +{ +} + +bool TBC::Read( SvStream *pS ) +{ + OSL_TRACE("TBC::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + if ( !tbch.Read( pS ) ) + return false; + if ( tbch.getTcID() != 0x1 && tbch.getTcID() != 0x1051 ) + { + cid.reset( new sal_uInt32 ); + *pS >> *cid; + } + // MUST exist if tbch.tct is not equal to 0x16 + if ( tbch.getTct() != 0x16 ) + { + tbcd.reset( new TBCData( tbch ) ); + if ( !tbcd->Read( pS ) ) + return false; + } + return true; +} + +void TBC::Print( FILE* fp ) +{ + Indent a; + indent_printf(fp,"[ 0x%x ] TBC -- dump\n", nOffSet ); + indent_printf(fp," dumping header ( TBCHeader )\n"); + tbch.Print( fp ); + if ( cid.get() ) + indent_printf(fp," cid = 0x%x\n", static_cast< unsigned int >( *cid ) ); + if ( tbcd.get() ) + { + indent_printf(fp," dumping toolbar data TBCData \n"); + tbcd->Print(fp); + } +} + +bool +TBC::ImportToolBarControl( CTBWrapper& rWrapper, const css::uno::Reference< css::container::XIndexContainer >& toolbarcontainer, CustomToolBarImportHelper& helper, bool bIsMenuBar ) +{ + // cmtFci 0x1 Command based on a built-in command. See CidFci. + // cmtMacro 0x2 Macro command. See CidMacro. + // cmtAllocated 0x3 Allocated command. See CidAllocated. + // cmtNil 0x7 No command. See Cid. + bool bBuiltin = false; + sal_uInt16 cmdId = 0; + if ( cid.get() ) + { + sal_uInt16 arg2 = ( *( cid.get() ) & 0xFFFF ); + + sal_uInt8 cmt = ( arg2 & 0x7 ); + arg2 = ( arg2 >> 3 ); + + switch ( cmt ) + { + case 1: + OSL_TRACE("cmt is cmtFci builtin command 0x%x", arg2); + bBuiltin = true; + cmdId = arg2; + break; + case 2: + OSL_TRACE("cmt is cmtMacro macro 0x%x", arg2); + break; + case 3: + OSL_TRACE("cmt is cmtAllocated [???] 0x%x", arg2); + break; + case 7: + OSL_TRACE("cmt is cmNill no-phing 0x%x", arg2); + break; + default: + OSL_TRACE("illegal 0x%x", cmt); + break; + } + } + + if ( tbcd.get() ) + { + std::vector< css::beans::PropertyValue > props; + if ( bBuiltin ) + { + rtl::OUString sCommand = helper.MSOCommandToOOCommand( cmdId ); + if ( sCommand.getLength() > 0 ) + { + beans::PropertyValue aProp; + + aProp.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CommandURL") ); + aProp.Value <<= sCommand; + props.push_back( aProp ); + } + } + bool bBeginGroup = false; + if ( ! tbcd->ImportToolBarControl( helper, props, bBeginGroup, bIsMenuBar ) ) + return false; + + TBCMenuSpecific* pMenu = tbcd->getMenuSpecific(); + if ( pMenu ) + { + OSL_TRACE("** control has a menu, name of toolbar with menu items is %s", rtl::OUStringToOString( pMenu->Name(), RTL_TEXTENCODING_UTF8 ).getStr() ); + // search for CTB with the appropriate name ( it contains the + // menu items, although we cannot import ( or create ) a menu on + // a custom toolbar we can import the menu items in a separate + // toolbar ( better than nothing ) + CTB* pCustTB = rWrapper.GetCustomizationData( pMenu->Name() ); + if ( pCustTB ) + { + uno::Reference< container::XIndexContainer > xMenuDesc; + uno::Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + xMenuDesc.set( xMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) ) ), uno::UNO_QUERY_THROW ); + if ( !pCustTB->ImportMenuTB( rWrapper,xMenuDesc, helper ) ) + return false; + if ( !bIsMenuBar ) + { + if ( !helper.createMenu( pMenu->Name(), uno::Reference< container::XIndexAccess >( xMenuDesc, uno::UNO_QUERY ), true ) ) + return false; + } + else + { + beans::PropertyValue aProp; + aProp.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ItemDescriptorContainer") ); + aProp.Value <<= xMenuDesc; + props.push_back( aProp ); + } + } + } + + if ( bBeginGroup ) + { + // insert spacer + uno::Sequence< beans::PropertyValue > sProps( 1 ); + sProps[ 0 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Type") ); + sProps[ 0 ].Value = uno::makeAny( ui::ItemType::SEPARATOR_LINE ); + toolbarcontainer->insertByIndex( toolbarcontainer->getCount(), uno::makeAny( sProps ) ); + } + + uno::Sequence< beans::PropertyValue > sProps( props.size() ); + beans::PropertyValue* pProp = sProps.getArray(); + + for ( std::vector< css::beans::PropertyValue >::iterator it = props.begin(); it != props.end(); ++it, ++pProp ) + *pProp = *it; + + toolbarcontainer->insertByIndex( toolbarcontainer->getCount(), uno::makeAny( sProps ) ); + } + return true; +} + +rtl::OUString +TBC::GetCustomText() +{ + rtl::OUString sCustomText; + if ( tbcd.get() ) + sCustomText = tbcd->getGeneralInfo().CustomText(); + return sCustomText; + + +} + +bool +Xst::Read( SvStream* pS ) +{ + OSL_TRACE("Xst::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + sal_Int16 nChars = 0; + *pS >> nChars; + sString = readUnicodeString( pS, static_cast< sal_Int32 >( nChars ) ); + return true; +} + +void +Xst::Print( FILE* fp ) +{ + Indent a; + indent_printf( fp, "[ 0x%x ] Xst -- dump\n", nOffSet ); + indent_printf( fp, " %s", rtl::OUStringToOString( sString, RTL_TEXTENCODING_UTF8 ).getStr() ); +} + +Tcg::Tcg() : nTcgVer( 255 ) +{ +} + +bool Tcg::Read(SvStream *pS) +{ + OSL_TRACE("Tcg::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + *pS >> nTcgVer; + if ( nTcgVer != (sal_Int8)255 ) + return false; + tcg.reset( new Tcg255() ); + return tcg->Read( pS ); +} + +void Tcg::Print( FILE* fp ) +{ + Indent a(true); + indent_printf(fp, "[ 0x%x ] Tcg - dump %d\n", nOffSet, nTcgVer); + indent_printf(fp," nTcgVer %d\n", nTcgVer); + if ( tcg.get() ) + tcg->Print( fp ); +} + +bool Tcg::ImportCustomToolBar( SfxObjectShell& rDocSh ) +{ + if ( tcg.get() ) + return tcg->ImportCustomToolBar( rDocSh ); + return false; +} + +Tcg255::Tcg255() +{ +} + +Tcg255::~Tcg255() +{ + std::vector< Tcg255SubStruct* >::iterator it = rgtcgData.begin(); + for ( ; it != rgtcgData.end(); ++it ) + delete *it; +} + +bool Tcg255::processSubStruct( sal_uInt8 nId, SvStream *pS ) +{ + Tcg255SubStruct* pSubStruct = NULL; + switch ( nId ) + { + case 0x1: + { + pSubStruct = new PlfMcd( false ); // don't read the id + break; + } + case 0x2: + { + pSubStruct = new PlfAcd( false ); + break; + } + case 0x3: + case 0x4: + { + pSubStruct = new PlfKme( false ); + break; + } + case 0x10: + { + pSubStruct = new TcgSttbf( false ); + break; + } + case 0x11: + { + pSubStruct = new MacroNames( false ); + break; + } + case 0x12: + { + pSubStruct = new CTBWrapper( false ); + break; + } + default: + OSL_TRACE("Unknown id 0x%x",nId); + return false; + } + pSubStruct->ch = nId; + if ( !pSubStruct->Read( pS ) ) + return false; + rgtcgData.push_back( pSubStruct ); + return true; +} + +bool Tcg255::ImportCustomToolBar( SfxObjectShell& rDocSh ) +{ + // Find the CTBWrapper + for ( std::vector< Tcg255SubStruct* >::const_iterator it = rgtcgData.begin(); it != rgtcgData.end(); ++it ) + { + if ( (*it)->id() == 0x12 ) + { + // not so great, shouldn't really have to do a horror casting + CTBWrapper* pCTBWrapper = dynamic_cast< CTBWrapper* > ( *it ); + if ( pCTBWrapper ) + { + if ( !pCTBWrapper->ImportCustomToolBar( rDocSh ) ) + return false; + } + } + } + return true; +} + + +bool Tcg255::Read(SvStream *pS) +{ + OSL_TRACE("Tcg255::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + sal_uInt8 nId = 0; // + *pS >> nId; + while ( nId != 0x40 ) + { + if ( !processSubStruct( nId, pS ) ) + return false; + *pS >> nId; + } + return true; + // Peek at +} + +void Tcg255::Print( FILE* fp) +{ + Indent a; + indent_printf(fp, "[ 0x%x ] Tcg255 - dump\n", nOffSet ); + indent_printf(fp, " contains %d sub records\n", rgtcgData.size() ); + std::vector< Tcg255SubStruct* >::iterator it = rgtcgData.begin(); + std::vector< Tcg255SubStruct* >::iterator it_end = rgtcgData.end(); + + for( sal_Int32 count = 1; it != it_end ; ++it, ++count ) + { + Indent b; + indent_printf(fp, " [%d] Tcg255SubStruct \n", static_cast< unsigned int >( count ) ); + (*it)->Print(fp); + } +} + + +Tcg255SubStruct::Tcg255SubStruct( bool bReadId ) : mbReadId( bReadId ), ch(0) +{ +} + +bool Tcg255SubStruct::Read(SvStream *pS) +{ + OSL_TRACE("Tcg255SubStruct::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + if ( mbReadId ) + *pS >> ch; + return true; +} + +PlfMcd::PlfMcd( bool bReadId ): Tcg255SubStruct( bReadId ), rgmcd( NULL ) +{ +} +PlfMcd::~PlfMcd() +{ + if ( rgmcd ) + delete[] rgmcd; +} + +bool PlfMcd::Read(SvStream *pS) +{ + OSL_TRACE("PffMcd::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + Tcg255SubStruct::Read( pS ); + *pS >> iMac; + if ( iMac ) + { + rgmcd = new MCD[ iMac ]; + for ( sal_Int32 index = 0; index < iMac; ++index ) + { + if ( !rgmcd[ index ].Read( pS ) ) + return false; + } + } + return true; +} + +void PlfMcd::Print( FILE* fp ) +{ + Indent a; + indent_printf(fp, "[ 0x%x ] PlfMcd ( Tcg255SubStruct ) - dump\n", nOffSet ); + indent_printf(fp, " contains %d MCD records\n", static_cast<int>( iMac ) ); + for ( sal_Int32 count=0; count < iMac; ++count ) + { + Indent b; + indent_printf(fp, "[%d] MCD\n", static_cast< int >( count ) ); + rgmcd[ count ].Print( fp ); + } + +} + +PlfAcd::PlfAcd( bool bReadId ) : Tcg255SubStruct( bReadId ) +,iMac(0) +,rgacd(NULL) +{ +} + + +PlfAcd::~PlfAcd() +{ + if ( rgacd ) + delete[] rgacd; +} + +bool PlfAcd::Read( SvStream *pS) +{ + OSL_TRACE("PffAcd::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + Tcg255SubStruct::Read( pS ); + *pS >> iMac; + if ( iMac ) + { + rgacd = new Acd[ iMac ]; + for ( sal_Int32 index = 0; index < iMac; ++index ) + { + if ( !rgacd[ index ].Read( pS ) ) + return false; + } + } + return true; +} +void PlfAcd::Print( FILE* fp ) +{ + Indent a; + indent_printf(fp, "[ 0x%x ] PlfAcd ( Tcg255SubStruct ) - dump\n", nOffSet ); + indent_printf(fp, " contains %d ACD records\n", static_cast< int >( iMac ) ); + for ( sal_Int32 count=0; count < iMac; ++count ) + { + Indent b; + indent_printf(fp, "[%d] ACD\n", static_cast< int >( count ) ); + rgacd[ count ].Print( fp ); + } + +} + +PlfKme::PlfKme( bool bReadId ) : Tcg255SubStruct( bReadId ) +,iMac( 0 ) +,rgkme( NULL ) +{ +} + +PlfKme::~PlfKme() +{ + if ( rgkme ) + delete[] rgkme; +} + +bool PlfKme::Read(SvStream *pS) +{ + OSL_TRACE("PlfKme::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + Tcg255SubStruct::Read( pS ); + *pS >> iMac; + if ( iMac ) + { + rgkme = new Kme[ iMac ]; + for( sal_Int32 index=0; index<iMac; ++index ) + { + if ( !rgkme[ index ].Read( pS ) ) + return false; + } + } + return true; +} + +void PlfKme::Print( FILE* fp ) +{ + Indent a; + indent_printf(fp, "[ 0x%x ] PlfKme ( Tcg255SubStruct ) - dump\n", nOffSet ); + indent_printf(fp, " contains %d Kme records\n", static_cast< int >( iMac ) ); + for ( sal_Int32 count=0; count < iMac; ++count ) + { + Indent b; + indent_printf(fp, "[%d] Kme\n", static_cast< int >( count ) ); + rgkme[ count ].Print( fp ); + } + +} + +TcgSttbf::TcgSttbf( bool bReadId ) : Tcg255SubStruct( bReadId ) +{ +} + +bool TcgSttbf::Read( SvStream *pS) +{ + OSL_TRACE("TcgSttbf::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + Tcg255SubStruct::Read( pS ); + return sttbf.Read( pS ); +} + +void TcgSttbf::Print( FILE* fp ) +{ + Indent a; + indent_printf(fp,"[ 0x%x ] TcgSttbf - dump\n", nOffSet ); + sttbf.Print( fp ); +} + +TcgSttbfCore::TcgSttbfCore() : fExtend( 0 ) +,cData( 0 ) +,cbExtra( 0 ) +,dataItems( NULL ) +{ +} + +TcgSttbfCore::~TcgSttbfCore() +{ + if ( dataItems ) + delete[] dataItems; +} + +bool TcgSttbfCore::Read( SvStream* pS ) +{ + OSL_TRACE("TcgSttbfCore::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + *pS >> fExtend >> cData >> cbExtra; + if ( cData ) + { + dataItems = new SBBItem[ cData ]; + for ( sal_Int32 index = 0; index < cData; ++index ) + { + *pS >> dataItems[ index ].cchData; + dataItems[ index ].data = readUnicodeString( pS, dataItems[ index ].cchData ); + *pS >> dataItems[ index ].extraData; + } + } + return true; +} + +void TcgSttbfCore::Print( FILE* fp ) +{ + Indent a; + indent_printf( fp, "[ 0x%x ] TcgSttbfCore - dump\n"); + indent_printf( fp, " fExtend 0x%x [expected 0xFFFF ]\n", fExtend ); + indent_printf( fp, " cbExtra 0x%x [expected 0x02 ]\n", cbExtra ); + indent_printf( fp, " cData no. or string data items %d (0x%x)\n", cData, cData ); + + if ( cData ) + { + for ( sal_Int32 index = 0; index < cData; ++index ) + indent_printf(fp," string dataItem[ %d(0x%x) ] has name %s and if referenced %d times.\n", static_cast< int >( index ), static_cast< unsigned int >( index ), rtl::OUStringToOString( dataItems[ index ].data, RTL_TEXTENCODING_UTF8 ).getStr(), dataItems[ index ].extraData ); + } + +} +MacroNames::MacroNames( bool bReadId ) : Tcg255SubStruct( bReadId ) +,iMac( 0 ) +,rgNames( NULL ) +{ +} + +MacroNames::~MacroNames() +{ + if ( rgNames ) + delete[] rgNames; +} + +bool MacroNames::Read( SvStream *pS) +{ + OSL_TRACE("MacroNames::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + Tcg255SubStruct::Read( pS ); + *pS >> iMac; + if ( iMac ) + { + rgNames = new MacroName[ iMac ]; + for ( sal_Int32 index = 0; index < iMac; ++index ) + { + if ( !rgNames[ index ].Read( pS ) ) + return false; + } + } + return true; +} + +void MacroNames::Print( FILE* fp ) +{ + Indent a; + indent_printf(fp, "[ 0x%x ] MacroNames ( Tcg255SubStruct ) - dump\n"); + indent_printf(fp, " contains %d MacroName records\n", iMac ); + for ( sal_Int32 count=0; count < iMac; ++count ) + { + Indent b; + indent_printf(fp, "[%d] MacroName\n", static_cast<int>( count ) ); + rgNames[ count ].Print( fp ); + } + +} + +MacroName::MacroName():ibst(0) +{ +} + + +bool MacroName::Read(SvStream *pS) +{ + OSL_TRACE("MacroName::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + *pS >> ibst; + return xstz.Read( pS ); +} + +void MacroName::Print( FILE* fp ) +{ + Indent a; + indent_printf( fp, "[ 0x%x ] MacroName - dump"); + indent_printf( fp," index - 0x%x has associated following record\n", ibst ); + xstz.Print( fp ); +} + + + +Xstz::Xstz():chTerm(0) +{ +} + +bool +Xstz::Read(SvStream *pS) +{ + OSL_TRACE("Xstz::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + if ( !xst.Read( pS ) ) + return false; + *pS >> chTerm; + if ( chTerm != 0 ) // should be an assert + return false; + return true; +} + +void Xstz::Print( FILE* fp ) +{ + Indent a; + indent_printf(fp,"[ 0x%x ] Xstz -- dump\n", nOffSet ); + indent_printf(fp," Xst\n"); + xst.Print( fp ); + indent_printf(fp," chterm 0x%x ( should be zero )\n", chTerm); +} + +Kme::Kme() : reserved1(0) +,reserved2(0) +,kcm1(0) +,kcm2(0) +,kt(0) +,param(0) +{ +} + +Kme::~Kme() +{ +} + +bool +Kme::Read(SvStream *pS) +{ + OSL_TRACE("Kme::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + *pS >> reserved1 >> reserved2 >> kcm1 >> kcm2 >> kt >> param; + return true; +} + +void Kme::Print( FILE* fp ) +{ + Indent a; + + indent_printf( fp, "[ 0x%x ] Kme - dump\n", nOffSet ); + indent_printf( fp, " reserved1 0x%x [expected 0x0 ]\n", reserved1 ); + indent_printf( fp, " reserved2 0x%x [expected 0x0 ]\n", reserved2 ); + indent_printf( fp, " kcm1 0x%x [shortcut key]\n", kcm1 ); + indent_printf( fp, " kcm2 0x%x [shortcut key]\n", kcm2 ); + indent_printf( fp, " kt 0x%x \n", kt ); + indent_printf( fp, " param 0x%x \n", static_cast< unsigned int >( param ) ); +} + +Acd::Acd() : ibst( 0 ) +, fciBasedOnABC( 0 ) +{ +} + +bool Acd::Read(SvStream *pS) +{ + OSL_TRACE("Acd::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + *pS >> ibst >> fciBasedOnABC; + return true; +} + +void Acd::Print( FILE* fp ) +{ + Indent a; + indent_printf( fp,"[ 0x%x ] ACD - dump\n", nOffSet ); + // #TODO flesh out interpretation of these values + indent_printf( fp," ibst 0x%x\n", ibst); + indent_printf( fp," fciBaseObABC 0x%x\n", fciBasedOnABC); +} + +MCD::MCD() : reserved1(0x56) +,reserved2( 0 ) +,ibst( 0 ) +,ibstName( 0 ) +,reserved3( 0xFFFF ) +,reserved4( 0 ) +,reserved5( 0 ) +,reserved6( 0 ) +,reserved7( 0 ) +{ +} + +bool MCD::Read(SvStream *pS) +{ + OSL_TRACE("MCD::Read() stream pos 0x%x", pS->Tell() ); + nOffSet = pS->Tell(); + *pS >> reserved1 >> reserved2 >> ibst >> ibstName >> reserved3; + *pS >> reserved4 >> reserved5 >> reserved6 >> reserved7; + return true; +} + +void MCD::Print( FILE* fp ) +{ + Indent a; + indent_printf( fp, "[ 0x%x ] MCD - dump\n", nOffSet ); + indent_printf( fp, " reserved1 0x%x [expected 0x56 ]\n", reserved1 ); + indent_printf( fp, " reserved2 0x%x [expected 0x0 ]\n", reserved2 ); + indent_printf( fp, " ibst 0x%x specifies macro with MacroName.xstz = 0x%x\n", ibst, ibst ); + indent_printf( fp, " ibstName 0x%x index into command string table ( TcgSttbf.sttbf )\n", ibstName ); + + indent_printf( fp, " reserved3 0x%x [expected 0xFFFF ]\n", reserved3 ); + indent_printf( fp, " reserved4 0x%x\n", static_cast< unsigned int >( reserved4 ) ); + indent_printf( fp, " reserved5 0x%x [expected 0x0 ]\n", static_cast< unsigned int >( reserved5 ) ); + indent_printf( fp, " reserved6 0x%x\n", static_cast< unsigned int >( reserved6 ) ); + indent_printf( fp, " reserved7 0x%x\n", static_cast< unsigned int >( reserved7 ) ); +} diff --git a/sw/source/filter/ww8/ww8toolbar.hxx b/sw/source/filter/ww8/ww8toolbar.hxx new file mode 100644 index 0000000000..d89789b65d --- /dev/null +++ b/sw/source/filter/ww8/ww8toolbar.hxx @@ -0,0 +1,347 @@ +#ifndef _WW8TOOLBAR_HXX +#define _WW8TOOLBAR_HXX + +#include <filter/msfilter/mstoolbar.hxx> + +namespace css = ::com::sun::star; + +class Xst : public TBBase +{ + rtl::OUString sString; +public: + Xst(){} + bool Read(SvStream *pS); + rtl::OUString getString() { return sString; } + void Print( FILE* fp ); +}; + +class CTBWrapper; +class TBC : public TBBase +{ + TBCHeader tbch; + boost::shared_ptr< sal_uInt32 > cid; // optional + boost::shared_ptr<TBCData> tbcd; +public: + TBC(); + ~TBC(); + bool Read(SvStream *pS); + void Print( FILE* ); + bool ImportToolBarControl( CTBWrapper&, const css::uno::Reference< css::container::XIndexContainer >&, CustomToolBarImportHelper&, bool ); + rtl::OUString GetCustomText(); +}; + +class CTB : public TBBase +{ + Xst name; + sal_Int32 cbTBData; + TB tb; + std::vector<TBVisualData> rVisualData; + sal_Int32 iWCTBl; + sal_uInt16 reserved; + sal_uInt16 unused; + sal_Int32 cCtls; + std::vector< TBC > rTBC; + + CTB(const CTB&); + CTB& operator = ( const CTB&); +public: + CTB(); + ~CTB(); + bool Read(SvStream *pS); + void Print( FILE* fp ); + bool IsMenuToolbar(); + bool ImportCustomToolBar( CTBWrapper&, CustomToolBarImportHelper& ); + bool ImportMenuTB( CTBWrapper&, const css::uno::Reference< css::container::XIndexContainer >&, CustomToolBarImportHelper& ); + rtl::OUString GetName() { return tb.getName().getString(); } +}; + +class TBDelta : public TBBase +{ + sal_uInt8 doprfatendFlags; + + sal_uInt8 ibts; + sal_Int32 cidNext; + sal_Int32 cid; + sal_Int32 fc; + sal_uInt16 CiTBDE; // careful of this ( endian matters etc. ) + sal_uInt16 cbTBC; +public: + TBDelta(); + ~TBDelta(){} + bool Read(SvStream *pS); + void Print( FILE* ); + bool ControlIsModified(); + bool ControlIsInserted(); + bool ControlIsChanged(); + bool ControlDropsToolBar(); + sal_Int32 TBCStreamOffset(); + sal_Int16 CustomizationIndex(); + +}; + +class Tcg255SubStruct : public TBBase +{ +friend class Tcg255; + bool mbReadId; + Tcg255SubStruct(const Tcg255SubStruct&); + Tcg255SubStruct& operator = ( const Tcg255SubStruct&); +protected: + sal_uInt8 ch; +public: + Tcg255SubStruct( bool bReadId ); + ~Tcg255SubStruct(){} + virtual sal_uInt8 id() const { return ch; } + bool Read(SvStream *pS); +}; + +class CTBWrapper; +class Customization : public TBBase +{ +friend class CTBWrapper; + sal_Int32 tbidForTBD; + sal_uInt16 reserved1; + sal_Int16 ctbds; + CTBWrapper* pWrapper; + boost::shared_ptr< CTB > customizationDataCTB; + std::vector< TBDelta > customizationDataTBDelta; + bool bIsDroppedMenuTB; + bool ImportMenu( CTBWrapper&, const css::uno::Reference< css::container::XIndexContainer >&, CustomToolBarImportHelper& ); +public: + Customization( CTBWrapper* rapper ); + ~Customization(); + bool Read(SvStream *pS); + bool ImportCustomToolBar( CTBWrapper&, CustomToolBarImportHelper& ); + bool ImportMenu( CTBWrapper&, CustomToolBarImportHelper& ); + void Print( FILE* ); + sal_Int32 GetTBIDForTB(){ return tbidForTBD; } + CTB* GetCustomizationData() { return customizationDataCTB.get(); }; +}; + +class SfxObjectShell; + +class CTBWrapper : public Tcg255SubStruct +{ + // reserved1 is the ch field of Tcg255SubStruct + sal_uInt16 reserved2; + sal_uInt8 reserved3; + sal_uInt16 reserved4; + sal_uInt16 reserved5; + + sal_Int16 cbTBD; + sal_Int16 cCust; + + sal_Int32 cbDTBC; + + std::vector< TBC > rtbdc; // + std::vector< Customization > rCustomizations; // array of Customizations + std::vector< sal_Int16 > dropDownMenuIndices; // array of indexes of Customization toolbars that are dropped by a menu + CTBWrapper(const CTBWrapper&); + CTBWrapper& operator = ( const CTBWrapper&); +public: + CTBWrapper( bool bReadId = true ); + ~CTBWrapper(); + void InsertDropIndex( sal_Int32 aIndex ) { dropDownMenuIndices.push_back( aIndex ); } + TBC* GetTBCAtOffset( sal_uInt32 nStreamOffset ); + bool Read(SvStream *pS); + bool ImportCustomToolBar( SfxObjectShell& rDocSh ); + + Customization* GetCustomizaton( sal_Int16 index ); + CTB* GetCustomizationData( const rtl::OUString& name ); + void Print( FILE* ); +}; + +class MCD : public TBBase +{ + sal_Int8 reserved1; // A signed integer that MUST be 0x56. + sal_uInt8 reserved2; // MUST be 0. + sal_uInt16 ibst; // Unsigned integer that specifies the name of the macro. Macro name is specified by MacroName.xstz of the MacroName entry in the MacroNames such that MacroName.ibst equals ibst. MacroNames MUST contain such an entry. + sal_uInt16 ibstName; // An unsigned integer that specifies the index into the Command String Table (TcgSttbf.sttbf) where the macro‘s name and arguments are specified. + sal_uInt16 reserved3; // An unsigned integer that MUST be 0xFFFF. + sal_uInt32 reserved4; //MUST be ignored. + sal_uInt32 reserved5; //MUST be 0. + sal_uInt32 reserved6; //MUST be ignored. + sal_uInt32 reserved7; //MUST be ignored + + MCD(const MCD&); + MCD& operator = ( const MCD&); +public: + MCD(); + ~MCD(){} + bool Read(SvStream *pS); + void Print( FILE* ); +}; + +class PlfMcd : public Tcg255SubStruct +{ + sal_Int32 iMac; + MCD* rgmcd; // array of MCD's + PlfMcd(const PlfMcd&); + PlfMcd& operator = ( const PlfMcd&); +public: + PlfMcd( bool bReadId = true ); + ~PlfMcd(); + bool Read(SvStream *pS); + void Print( FILE* ); +}; + +class Acd : public TBBase +{ + sal_Int16 ibst; + sal_uInt16 fciBasedOnABC; // fciBasedOn(13 bits) A(1bit)B(1bit)C(1Bit) + Acd(const Acd&); + Acd& operator = ( const Acd&); +public: + Acd(); + ~Acd(){} + bool Read(SvStream *pS); + void Print( FILE* ); +}; + +class PlfAcd: public Tcg255SubStruct +{ + sal_Int32 iMac; + Acd* rgacd; + PlfAcd(const PlfAcd&); + PlfAcd& operator = ( const PlfAcd&); +public: + PlfAcd( bool bReadId = true ); + ~PlfAcd(); + bool Read(SvStream *pS); + void Print(FILE*); +}; + +class Kme : public TBBase +{ + sal_Int16 reserved1; //MUST be zero. + sal_Int16 reserved2; //MUST be zero. + sal_uInt16 kcm1; //A Kcm that specifies the primary shortcut key. + sal_uInt16 kcm2; //A Kcm that specifies the secondary shortcut key, or 0x00FF if there is no secondary shortcut key. + sal_uInt16 kt; //A Kt that specifies the type of action to be taken when the key combination is pressed. + sal_uInt32 param; //The meaning of this field depends on the value of kt + + Kme(const Kme&); + Kme& operator = ( const Kme&); +public: + Kme(); + ~Kme(); + bool Read(SvStream *pS); + void Print( FILE* ); +}; + +class PlfKme : public Tcg255SubStruct +{ + sal_Int32 iMac; + Kme* rgkme; + PlfKme(const PlfKme&); + PlfKme& operator = ( const PlfKme&); +public: + PlfKme( bool bReadId = true ); + ~PlfKme(); + bool Read(SvStream *pS); + void Print( FILE* ); +}; + +class TcgSttbfCore : public TBBase +{ +struct SBBItem +{ + sal_uInt16 cchData; + rtl::OUString data; + sal_uInt16 extraData; + SBBItem() : cchData(0), extraData(0){} +}; + sal_uInt16 fExtend; + sal_uInt16 cData; + sal_uInt16 cbExtra; + SBBItem* dataItems; + TcgSttbfCore(const TcgSttbfCore&); + TcgSttbfCore& operator = ( const TcgSttbfCore&); +public: + TcgSttbfCore(); + ~TcgSttbfCore(); + bool Read(SvStream *pS); + void Print( FILE* fp ); +}; + +class TcgSttbf : public Tcg255SubStruct +{ + TcgSttbfCore sttbf; + TcgSttbf(const TcgSttbf&); + TcgSttbf& operator = ( const TcgSttbf&); +public: + TcgSttbf( bool bReadId = true ); + ~TcgSttbf(){} + bool Read(SvStream *pS); + void Print( FILE* fp ); +}; + +class Xstz : public TBBase +{ + Xst xst; //An Xst specifying the string with its pre-pended length. + sal_uInt16 chTerm; + + Xstz(const Xstz&); + Xstz& operator = ( const Xstz&); +public: + Xstz(); + ~Xstz(){} + bool Read(SvStream *pS); + void Print( FILE* fp ); +}; + +class MacroName : public TBBase +{ + sal_uInt16 ibst; //An unsigned integer that specifies the index of the current entry in the macro name table. MUST NOT be the same as the index of any other entry. + Xstz xstz; + MacroName(const MacroName&); + MacroName& operator = ( const MacroName&); +public: + MacroName(); + ~MacroName(){} + bool Read(SvStream *pS); + void Print( FILE* ); +}; + +class MacroNames : public Tcg255SubStruct +{ + sal_uInt16 iMac; //An unsigned integer that specifies the number of MacroName structures in rgNames. + MacroName* rgNames; + + MacroNames(const MacroNames&); + MacroNames& operator = ( const MacroNames&); +public: + MacroNames( bool bReadId = true ); + ~MacroNames(); + bool Read(SvStream *pS); + void Print( FILE* ); +}; + +class Tcg255 : public TBBase +{ + std::vector< Tcg255SubStruct* > rgtcgData; // array of sub structures + Tcg255(const Tcg255&); + Tcg255& operator = ( const Tcg255&); + bool processSubStruct( sal_uInt8 nId, SvStream* ); +public: + Tcg255(); + ~Tcg255(); + bool Read(SvStream *pS); + void Print( FILE* ); + bool ImportCustomToolBar( SfxObjectShell& rDocSh ); +}; + +class Tcg: public TBBase +{ + sal_Int8 nTcgVer; + std::auto_ptr< Tcg255 > tcg; + Tcg(const Tcg&); + Tcg& operator = ( const Tcg&); +public: + Tcg(); + ~Tcg(){} + bool Read(SvStream *pS); + bool ImportCustomToolBar( SfxObjectShell& rDocSh ); + void Print( FILE* ); +}; + +#endif diff --git a/sw/source/ui/app/docsh2.cxx b/sw/source/ui/app/docsh2.cxx index e84e78ee30..e988220962 100644 --- a/sw/source/ui/app/docsh2.cxx +++ b/sw/source/ui/app/docsh2.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -110,10 +110,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> @@ -181,7 +179,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; @@ -200,7 +197,6 @@ void lcl_processCompatibleSfxHint( const uno::Reference< script::vba::XVBAEventP } } } -#endif /*-------------------------------------------------------------------- Beschreibung: Benachrichtigung bei geaenderter DocInfo @@ -213,11 +209,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) ) @@ -298,7 +292,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(); @@ -307,9 +300,8 @@ USHORT SwDocShell::PrepareClose( BOOL bUI, BOOL bForBrowsing ) using namespace com::sun::star::script::vba::VBAEventId; uno::Sequence< uno::Any > aArgs; xVbaEvents->processVbaEvent( DOCUMENT_CLOSE, aArgs ); - } - } -#endif + } + } return nRet; } @@ -1440,6 +1432,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: @@ -1502,6 +1522,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 4577cabdb7..6082257e10 100644 --- a/sw/source/ui/uno/unotxdoc.cxx +++ b/sw/source/ui/uno/unotxdoc.cxx @@ -1,7 +1,7 @@ /************************************************************************* - * + * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -174,6 +174,12 @@ using ::osl::FileBase; #define SW_CREATE_MARKER_TABLE 0x06 #define SW_CREATE_DRAW_DEFAULTS 0x07 +#include <comphelper/processfactory.hxx> + +/****************************************************************************** + * + ******************************************************************************/ + extern bool lcl_GetPostIts( IDocumentFieldsAccess* pIDFA, _SetGetExpFlds * pSrtLst ); SwPrintUIOptions * lcl_GetPrintUIOptions( @@ -188,11 +194,11 @@ SwPrintUIOptions * lcl_GetPrintUIOptions( const SwView * pSwView = dynamic_cast< const SwView * >(pView); const bool bHasSelection = pSwView ? pSwView->HasSelection( sal_False ) : false; // check for any selection, not just text selection const bool bHasPostIts = lcl_GetPostIts( pDocShell->GetDoc(), 0 ); - + // get default values to use in dialog from documents SwPrintData const SwPrintData *pPrintData = pDocShell->GetDoc()->getPrintData(); DBG_ASSERT( pPrintData, "failed to get SwPrintData from document" ); - + return new SwPrintUIOptions( bWebDoc, bSwSrcView, bHasSelection, bHasPostIts, *pPrintData ); } @@ -241,6 +247,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 ) @@ -270,7 +282,7 @@ Any SAL_CALL SwXTextDocument::queryInterface( const uno::Type& rType ) throw(Run aRet <<= xTmp; } - if ( !aRet.hasValue() + if ( !aRet.hasValue() && rType != ::getCppuType((Reference< com::sun::star::document::XDocumentEventBroadcaster>*)0) && rType != ::getCppuType((Reference< com::sun::star::frame::XController>*)0) && rType != ::getCppuType((Reference< com::sun::star::frame::XFrame>*)0) @@ -377,6 +389,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 ); } SwXTextDocument::~SwXTextDocument() @@ -877,7 +892,7 @@ SwUnoCrsr* SwXTextDocument::FindAny(const Reference< util::XSearchDescriptor > (FindRanges)eRanges, pReplaceColl ); } else - { + { //todo/mba: assuming that notes should be omitted BOOL bSearchInNotes = FALSE; BOOL bCancel; @@ -2011,6 +2026,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 : @@ -2119,6 +2137,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; @@ -2307,7 +2333,7 @@ Any SAL_CALL SwXTextDocument::getPropertyDefault( const OUString& rPropertyName static OutputDevice * lcl_GetOutputDevice( const SwPrintUIOptions &rPrintUIOptions ) { OutputDevice *pOut = 0; - + uno::Any aAny( rPrintUIOptions.getValue( C2U( "RenderDevice" ) )); uno::Reference< awt::XDevice > xRenderDevice; aAny >>= xRenderDevice; @@ -2318,9 +2344,9 @@ static OutputDevice * lcl_GetOutputDevice( const SwPrintUIOptions &rPrintUIOptio } return pOut; -} +} -static bool lcl_SeqHasProperty( +static bool lcl_SeqHasProperty( const uno::Sequence< beans::PropertyValue >& rOptions, const sal_Char *pPropName ) { @@ -2331,13 +2357,13 @@ static bool lcl_SeqHasProperty( { if (pProps[i].Name.equalsAscii( pPropName )) bRes = true; - } + } return bRes; -} +} -SfxViewShell * SwXTextDocument::GetRenderView( - bool &rbIsSwSrcView, - const uno::Sequence< beans::PropertyValue >& rOptions, +SfxViewShell * SwXTextDocument::GetRenderView( + bool &rbIsSwSrcView, + const uno::Sequence< beans::PropertyValue >& rOptions, bool bIsPDFExport ) { // get view shell to use @@ -2352,11 +2378,11 @@ SfxViewShell * SwXTextDocument::GetRenderView( for (sal_Int32 i = 0; i < nLen; ++i) { if (pProps[i].Name.equalsAscii( "View" )) - { + { aTmp = pProps[i].Value; break; } - } + } uno::Reference< frame::XController > xController; if (aTmp >>= xController) @@ -2366,7 +2392,7 @@ SfxViewShell * SwXTextDocument::GetRenderView( } } return pView; -} +} /* * GetRenderDoc: @@ -2376,9 +2402,9 @@ SfxViewShell * SwXTextDocument::GetRenderView( * The rpView variable will be set (if not already done) to the used * SfxViewShell. */ -SwDoc * SwXTextDocument::GetRenderDoc( - SfxViewShell *&rpView, - const uno::Any& rSelection, +SwDoc * SwXTextDocument::GetRenderDoc( + SfxViewShell *&rpView, + const uno::Any& rSelection, bool bIsPDFExport ) { SwDoc *pDoc = 0; @@ -2428,8 +2454,8 @@ SwDoc * SwXTextDocument::GetRenderDoc( return pDoc; } -static void lcl_SavePrintUIOptionsToDocumentPrintData( - SwDoc &rDoc, +static void lcl_SavePrintUIOptionsToDocumentPrintData( + SwDoc &rDoc, const SwPrintUIOptions &rPrintUIOptions, bool bIsPDFEXport ) { @@ -2439,9 +2465,9 @@ static void lcl_SavePrintUIOptionsToDocumentPrintData( rDoc.setPrintData ( *pTmpData ); delete pTmpData; // setPrintData does make its own copy! } - + SwPrintData *pDocPrintData = rDoc.getPrintData(); - + pDocPrintData->SetPrintGraphic( rPrintUIOptions.IsPrintGraphics() ); pDocPrintData->SetPrintTable( rPrintUIOptions.IsPrintTables() ); pDocPrintData->SetPrintDraw( rPrintUIOptions.IsPrintDrawings() ); @@ -2461,7 +2487,7 @@ static void lcl_SavePrintUIOptionsToDocumentPrintData( pDocPrintData->SetPrintHiddenText( rPrintUIOptions.IsPrintHiddenText() ); pDocPrintData->SetPrintTextPlaceholder( rPrintUIOptions.IsPrintTextPlaceholders() ); } - + sal_Int32 SAL_CALL SwXTextDocument::getRendererCount( const uno::Any& rSelection, const uno::Sequence< beans::PropertyValue >& rxOptions ) @@ -2474,14 +2500,14 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount( const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" ); bool bIsSwSrcView = false; SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport ); - + if (!bIsSwSrcView && !m_pRenderData) m_pRenderData = new SwRenderData; if (!m_pPrintUIOptions) m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView ); bool bFormat = m_pPrintUIOptions->processPropertiesAndCheckFormat( rxOptions ); // const bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport ); - + SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport ); DBG_ASSERT( pDoc && pView, "doc or view shell missing!" ); if (!pDoc || !pView) @@ -2519,7 +2545,7 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount( // reformating the document for printing will show the changes in the view // which is likely to produce many unwanted and not nice to view actions. - // We don't want that! Thus we disable updating of the view. + // We don't want that! Thus we disable updating of the view. pWrtShell->StartAction(); const TypeId aSwViewTypeId = TYPE(SwView); @@ -2534,7 +2560,7 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount( m_pRenderData->SetSwPrtOptions( new SwPrtOptions( C2U( bIsPDFExport ? "PDF export" : "Printing" ) ) ); m_pRenderData->MakeSwPrtOptions( m_pRenderData->GetSwPrtOptionsRef(), pRenderDocShell, m_pPrintUIOptions, m_pRenderData, bIsPDFExport ); - + if (pView->IsA(aSwViewTypeId)) { // PDF export should not make use of the SwPrtOptions @@ -2550,10 +2576,10 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount( bool bStateChanged = false; if ( bOrigStatus && !SvtPrintWarningOptions().IsModifyDocumentOnPrintingAllowed() ) { - pRenderDocShell->EnableSetModified( sal_False ); + pRenderDocShell->EnableSetModified( sal_False ); bStateChanged = true; } - + // --> FME 2005-05-23 #122919# Force field update before PDF export: pWrtShell->ViewShell::UpdateFlds(TRUE); @@ -2566,10 +2592,10 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount( //TODO: check what exatly needs to be done and make just one function for that pWrtShell->CalcLayout(); pWrtShell->CalcPagesForPrint( pDoc->GetPageCount() ); - + pWrtShell->SetPDFExportOption( sal_False ); - + // enable view again pWrtShell->EndAction(); } @@ -2608,7 +2634,7 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount( } } DBG_ASSERT( nRet >= 0, "negative number of pages???" ); - + return nRet; } @@ -2625,7 +2651,7 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer( const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" ); bool bIsSwSrcView = false; SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport ); - + // m_pRenderData should NOT be created here! // That should only be done in getRendererCount. If this function is called before // getRendererCount was called then the caller will probably just retrieve the extra UI options @@ -2670,8 +2696,8 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer( // determine the correct page number from the renderer index const USHORT nPage = m_pRenderData->GetPagesToPrint()[ nRenderer ]; // <-- - - // get paper tray to use ... + + // get paper tray to use ... sal_Int32 nPrinterPaperTray = -1; if (! bPrintPaperFromSetup) { @@ -2688,7 +2714,7 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer( if (bIsSwSrcView || bPrintProspect) { // for printing of HTML source code and prospect printing we should use - // the printers paper size since + // the printers paper size since // a) HTML source view has no page size // b) prospect printing has a different page size from the documents page // since two document pages will get rendered on one printer page @@ -2743,11 +2769,11 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer( aRenderer.realloc( nLen ); aRenderer[ nLen - 1 ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "PrinterPaperTray" ) ); aRenderer[ nLen - 1 ].Value <<= nPrinterPaperTray; - } + } } m_pPrintUIOptions->appendPrintUIOptions( aRenderer ); - + return aRenderer; } @@ -2788,7 +2814,7 @@ SfxViewShell * SwXTextDocument::GuessViewShell( if (pView) rbIsSwSrcView = pSwSrcView != 0; return pView; -// return pSwView ? dynamic_cast< SfxViewShell * >(pSwView) : +// return pSwView ? dynamic_cast< SfxViewShell * >(pSwView) : // (pSwSrcView ? dynamic_cast< SfxViewShell * >(pSwSrcView) : // dynamic_cast< SfxViewShell * >(pSwPagePreView) ); } @@ -2812,7 +2838,7 @@ void SAL_CALL SwXTextDocument::render( const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" ); bool bIsSwSrcView = false; SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport ); - + DBG_ASSERT( m_pRenderData, "data should have been created already in getRendererCount..." ); DBG_ASSERT( m_pPrintUIOptions, "data should have been created already in getRendererCount..." ); if (!bIsSwSrcView && !m_pRenderData) @@ -2859,24 +2885,24 @@ void SAL_CALL SwXTextDocument::render( ((SwView*)pView)->GetWrtShellPtr() : ((SwPagePreView*)pView)->GetViewShell(); } - + // get output device to use OutputDevice * pOut = lcl_GetOutputDevice( *m_pPrintUIOptions ); - + if(pVwSh && pOut && m_pRenderData->HasSwPrtOptions()) { const rtl::OUString aPageRange = m_pPrintUIOptions->getStringValue( "PageRange", OUString() ); const bool bFirstPage = m_pPrintUIOptions->getBoolValue( "IsFirstPage", sal_False ); bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport ); - + DBG_ASSERT(( pView->IsA(aSwViewTypeId) && m_pRenderData->IsViewOptionAdjust()) - || (!pView->IsA(aSwViewTypeId) && !m_pRenderData->IsViewOptionAdjust()), + || (!pView->IsA(aSwViewTypeId) && !m_pRenderData->IsViewOptionAdjust()), "SwView / SwViewOptionAdjust_Impl availability mismatch" ); - + // since printing now also use the API for PDF export this option // should be set for printing as well ... pVwSh->SetPDFExportOption( sal_True ); - + // --> FME 2004-06-08 #i12836# enhanced pdf export // // First, we have to export hyperlinks, notes, and outline to pdf. @@ -2886,19 +2912,19 @@ void SAL_CALL SwXTextDocument::render( SwWrtShell* pWrtShell = pView->IsA(aSwViewTypeId) ? ((SwView*)pView)->GetWrtShellPtr() : 0; - + if (bIsPDFExport && bFirstPage && pWrtShell) { SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, sal_False ); } // <-- - + const SwPrtOptions &rSwPrtOptions = *m_pRenderData->GetSwPrtOptions(); if (bPrintProspect) pVwSh->PrintProspect( pOut, rSwPrtOptions, nRenderer ); else // normal printing and PDF export pVwSh->PrintOrPDFExport( pOut, rSwPrtOptions, nRenderer ); - + // --> FME 2004-10-08 #i35176# // // After printing the last page, we take care for the links coming @@ -2910,18 +2936,18 @@ void SAL_CALL SwXTextDocument::render( SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, sal_True ); } // <-- - + pVwSh->SetPDFExportOption( sal_False ); - + // last page to be rendered? (not necessarily the last page of the document) // -> do clean-up of data - if (bLastPage) + if (bLastPage) { // #i96167# haggai: delete ViewOptionsAdjust here because it makes use // of the shell, which might get destroyed in lcl_DisposeView! if (m_pRenderData && m_pRenderData->IsViewOptionAdjust()) m_pRenderData->ViewOptionAdjustStop(); - + if (m_pRenderData && m_pRenderData->HasPostItData()) m_pRenderData->DeletePostItData(); if (m_pHiddenViewFrame) @@ -2999,6 +3025,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; @@ -3802,7 +3829,7 @@ SwViewOptionAdjust_Impl::~SwViewOptionAdjust_Impl() m_rShell.ApplyViewOptions( m_aOldViewOptions ); } -void SwViewOptionAdjust_Impl::AdjustViewOptions( +void SwViewOptionAdjust_Impl::AdjustViewOptions( const SwPrtOptions *pPrtOptions ) { // to avoid unnecessary reformatting the view options related to the content @@ -3819,7 +3846,7 @@ void SwViewOptionAdjust_Impl::AdjustViewOptions( SwViewOption aRenderViewOptions( m_aOldViewOptions ); // disable anything in the view that should not be printed (or exported to PDF) by default - // (see also dialog "Tools/Options - StarOffice Writer - Formatting Aids" + // (see also dialog "Tools/Options - StarOffice Writer - Formatting Aids" // in section "Display of ...") aRenderViewOptions.SetParagraph( FALSE ); // paragraph end aRenderViewOptions.SetSoftHyph( FALSE ); // aka custom hyphens @@ -3836,17 +3863,17 @@ void SwViewOptionAdjust_Impl::AdjustViewOptions( aRenderViewOptions.SetShowHiddenField( bVal ); if (bContainsHiddenParagraphs) aRenderViewOptions.SetShowHiddenPara( bVal ); - + if (bContainsPlaceHolders) { // should always be printed in PDF export! bVal = pPrtOptions ? pPrtOptions->bPrintTextPlaceholder : TRUE; aRenderViewOptions.SetShowPlaceHolderFields( bVal ); } - + if (bContainsFields) aRenderViewOptions.SetFldName( FALSE ); - + // we need to set this flag in order to get to see the visible effect of // some of the above settings (needed for correct rendering) aRenderViewOptions.SetViewMetaChars( TRUE ); diff --git a/sw/source/ui/vba/makefile.mk b/sw/source/ui/vba/makefile.mk index b6d0d79942..2cd777b282 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 8200e323b8..a80a69a85f 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 fd815b2b04..4ce05bcfa8 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 66f9bca50b..65be187743 100644 --- a/sw/source/ui/vba/vbaapplication.hxx +++ b/sw/source/ui/vba/vbaapplication.hxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -56,10 +56,11 @@ public: virtual css::uno::Reference< ov::word::XWindow > SAL_CALL getActiveWindow() throw (css::uno::RuntimeException); virtual css::uno::Reference< ooo::vba::word::XOptions > SAL_CALL getOptions() throw (css::uno::RuntimeException); virtual css::uno::Reference< ooo::vba::word::XSelection > SAL_CALL getSelection() throw (css::uno::RuntimeException); - virtual css::uno::Any SAL_CALL CommandBars( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); - 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 CommandBars( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + 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 5d098a2992..8c92627617 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 bb67fac461..f5ff0fe6e6 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 bccfeeff0e..841b7e7bdd 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 5efef7a31a..29e26b9478 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 634ab630cd..73da177ad1 100644 --- a/sw/source/ui/vba/vbaborders.cxx +++ b/sw/source/ui/vba/vbaborders.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -58,7 +58,7 @@ class SwVbaBorder : public SwVbaBorder_Base { private: uno::Reference< beans::XPropertySet > m_xProps; - sal_Int32 m_LineType; + sal_Int32 m_LineType; VbaPalette m_Palette; bool setBorderLine( table::BorderLine& rBorderLine ) { @@ -75,7 +75,7 @@ private: aTableBorder.IsTopLineValid = sal_True; aTableBorder.TopLine = rBorderLine; break; - + case word::WdBorderType::wdBorderBottom: aTableBorder.IsBottomLineValid = sal_True; aTableBorder.BottomLine = rBorderLine; @@ -96,13 +96,13 @@ private: case word::WdBorderType::wdBorderDiagonalUp: // #TODO have to ignore at the momement, would be // nice to investigate what we can do here - break; + break; default: return false; } m_xProps->setPropertyValue( sTableBorder, uno::makeAny(aTableBorder) ); return true; - } + } bool getBorderLine( table::BorderLine& rBorderLine ) { @@ -139,18 +139,18 @@ private: case word::WdBorderType::wdBorderDiagonalUp: // #TODO have to ignore at the momement, would be // nice to investigate what we can do here - break; + break; default: return false; } return true; - } + } SwVbaBorder(); // no impl -protected: +protected: virtual rtl::OUString& getServiceImplName() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaBorder") ); - return sImplName; + return sImplName; } virtual css::uno::Sequence<rtl::OUString> getServiceNames() { @@ -160,10 +160,10 @@ protected: aServiceNames.realloc( 1 ); aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Border" ) ); } - return aServiceNames; + return aServiceNames; } public: - SwVbaBorder( const uno::Reference< beans::XPropertySet > & xProps, const uno::Reference< uno::XComponentContext >& xContext, sal_Int32 lineType, VbaPalette& rPalette) : SwVbaBorder_Base( uno::Reference< XHelperInterface >( xProps, uno::UNO_QUERY ), xContext ), m_xProps( xProps ), m_LineType( lineType ), m_Palette( rPalette ) {} + SwVbaBorder( const uno::Reference< beans::XPropertySet > & xProps, const uno::Reference< uno::XComponentContext >& xContext, sal_Int32 lineType, VbaPalette& rPalette) : SwVbaBorder_Base( uno::Reference< XHelperInterface >( xProps, uno::UNO_QUERY ), xContext ), m_xProps( xProps ), m_LineType( lineType ), m_Palette( rPalette ) {} uno::Any SAL_CALL getLineStyle() throw (uno::RuntimeException) { @@ -186,7 +186,7 @@ public: } return uno::makeAny( nLineStyle ); } - void SAL_CALL setLineStyle( const uno::Any& _linestyle ) throw (uno::RuntimeException) + void SAL_CALL setLineStyle( const uno::Any& _linestyle ) throw (uno::RuntimeException) { // Urk no choice but to silently ignore we don't support this attribute // #TODO would be nice to support the word line styles @@ -265,14 +265,14 @@ public: RangeBorders( const uno::Reference< table::XCellRange >& xRange, const uno::Reference< uno::XComponentContext > & xContext, VbaPalette& rPalette ) : m_xRange( xRange ), m_xContext( xContext ), m_Palette( rPalette ) { } - // XIndexAccess + // XIndexAccess virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) { return sizeof( supportedIndexTable ) / sizeof( supportedIndexTable[0] ); } - virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) { - + sal_Int32 nIndex = getTableIndex( Index ); if ( nIndex >= 0 && nIndex < getCount() ) { @@ -291,7 +291,7 @@ public: } }; -uno::Reference< container::XIndexAccess > +uno::Reference< container::XIndexAccess > rangeToBorderIndexAccess( const uno::Reference< table::XCellRange >& xRange, const uno::Reference< uno::XComponentContext > & xContext, VbaPalette& rPalette ) { return new RangeBorders( xRange, xContext, rPalette ); @@ -334,7 +334,7 @@ SwVbaBorders::createCollectionObject( const css::uno::Any& aSource ) return aSource; // its already a Border object } -uno::Type +uno::Type SwVbaBorders::getElementType() throw (uno::RuntimeException) { return word::XBorders::static_type(0); @@ -348,24 +348,29 @@ 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& +rtl::OUString& SwVbaBorders::getServiceImplName() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaBorders") ); return sImplName; } -uno::Sequence< rtl::OUString > +uno::Sequence< rtl::OUString > SwVbaBorders::getServiceNames() { static uno::Sequence< rtl::OUString > aServiceNames; diff --git a/sw/source/ui/vba/vbacell.cxx b/sw/source/ui/vba/vbacell.cxx new file mode 100644 index 0000000000..8d7bf9e420 --- /dev/null +++ b/sw/source/ui/vba/vbacell.cxx @@ -0,0 +1,119 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacell.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include "vbatable.hxx" +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <rtl/ustrbuf.hxx> +#include "wordvbahelper.hxx" +#include "vbatablehelper.hxx" +#include "vbarow.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaCell::SwVbaCell( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextTable >& xTextTable, sal_Int32 nColumn, sal_Int32 nRow ) throw ( uno::RuntimeException ) : + SwVbaCell_BASE( rParent, rContext ), mxTextTable( xTextTable ), mnColumn( nColumn ), mnRow( nRow ) +{ +} + +SwVbaCell::~SwVbaCell() +{ +} + +::sal_Int32 SAL_CALL SwVbaCell::getWidth() throw (css::uno::RuntimeException) +{ + SwVbaTableHelper aTableHelper( mxTextTable ); + return aTableHelper.GetColWidth( mnColumn, mnRow, sal_True ); +} + +void SAL_CALL SwVbaCell::setWidth( ::sal_Int32 _width ) throw (css::uno::RuntimeException) +{ + SwVbaTableHelper aTableHelper( mxTextTable ); + aTableHelper.SetColWidth( _width, mnColumn, mnRow, sal_True ); +} + +uno::Any SAL_CALL SwVbaCell::getHeight() throw (css::uno::RuntimeException) +{ + uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnRow ) ); + return xRow->getHeight(); +} + +void SAL_CALL SwVbaCell::setHeight( const uno::Any& _height ) throw (css::uno::RuntimeException) +{ + uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnRow ) ); + xRow->setHeight( _height ); +} + +::sal_Int32 SAL_CALL SwVbaCell::getHeightRule() throw (css::uno::RuntimeException) +{ + uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnRow ) ); + return xRow->getHeightRule(); +} + +void SAL_CALL SwVbaCell::setHeightRule( ::sal_Int32 _heightrule ) throw (css::uno::RuntimeException) +{ + uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnRow ) ); + xRow->setHeightRule( _heightrule ); +} + +void SAL_CALL SwVbaCell::SetWidth( float width, sal_Int32 /*rulestyle*/ ) throw (css::uno::RuntimeException) +{ + // FIXME: handle the argument: rulestyle + setWidth( width ); +} + +void SAL_CALL SwVbaCell::SetHeight( float height, sal_Int32 heightrule ) throw (css::uno::RuntimeException) +{ + // FIXME: handle the argument: heightrule + setHeightRule( heightrule ); + setHeight( uno::makeAny( height ) ); +} + +rtl::OUString& +SwVbaCell::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaCell") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaCell::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Cell" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbacell.hxx b/sw/source/ui/vba/vbacell.hxx new file mode 100644 index 0000000000..4ce550793b --- /dev/null +++ b/sw/source/ui/vba/vbacell.hxx @@ -0,0 +1,67 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_CELL_HXX +#define SW_VBA_CELL_HXX + +#include <ooo/vba/word/XCell.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/text/XTextTable.hpp> + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XCell > SwVbaCell_BASE; + +class SwVbaCell : public SwVbaCell_BASE +{ +private: + css::uno::Reference< css::text::XTextTable > mxTextTable; + sal_Int32 mnColumn; + sal_Int32 mnRow; + +public: + SwVbaCell( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextTable >& xTextTable, sal_Int32 nColumn, sal_Int32 nRow ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaCell(); + + // Attributes + virtual ::sal_Int32 SAL_CALL getWidth() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWidth( ::sal_Int32 _width ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getHeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeight( const css::uno::Any& _height ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getHeightRule() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeightRule( ::sal_Int32 _heightrule ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL SetWidth( float width, sal_Int32 rulestyle ) throw (css::uno::RuntimeException); + virtual void SAL_CALL SetHeight( float height, sal_Int32 heightrule ) throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_CELL_HXX */ diff --git a/sw/source/ui/vba/vbacells.cxx b/sw/source/ui/vba/vbacells.cxx new file mode 100644 index 0000000000..d8d6b04ab3 --- /dev/null +++ b/sw/source/ui/vba/vbacells.cxx @@ -0,0 +1,223 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacells.hxx" +#include "vbacell.hxx" +#include "wordvbahelper.hxx" +#include "vbatablehelper.hxx" +#include "vbarow.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > CellCollectionHelper_Base; + +class CellsEnumWrapper : public EnumerationHelper_BASE +{ + uno::Reference< container::XIndexAccess > mxIndexAccess; + sal_Int32 nIndex; + +public: + CellsEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : mxIndexAccess( xIndexAccess ), nIndex( 0 ) + { + } + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < mxIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if( nIndex < mxIndexAccess->getCount() ) + { + return mxIndexAccess->getByIndex( nIndex++ ); + } + throw container::NoSuchElementException(); + } +}; + +class CellCollectionHelper : public CellCollectionHelper_Base +{ +private: + uno::Reference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< css::text::XTextTable > mxTextTable; + sal_Int32 mnLeft; + sal_Int32 mnTop; + sal_Int32 mnRight; + sal_Int32 mnBottom; + +public: + CellCollectionHelper( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::text::XTextTable >& xTextTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw ( css::uno::RuntimeException ): mxParent( xParent ), mxContext( xContext ), mxTextTable( xTextTable ), mnLeft( nLeft ), mnTop( nTop ), mnRight( nRight ), mnBottom( nBottom ) + { + } + virtual ~CellCollectionHelper() {} + + virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) + { + return ( mnRight - mnLeft + 1 ) * ( mnBottom - mnTop + 1 ); + } + virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( Index < 0 || Index >= getCount() ) + throw css::lang::IndexOutOfBoundsException(); + + for( sal_Int32 row = mnTop; row <= mnBottom; row++ ) + { + for( sal_Int32 col = mnLeft; col <= mnRight; col++ ) + { + if( Index == ( ( row - mnTop ) * ( mnRight - mnLeft + 1 ) + ( col - mnLeft ) ) ) + return uno::makeAny( uno::Reference< word::XCell >( new SwVbaCell( mxParent, mxContext, mxTextTable, col, row ) ) ); + } + } + throw css::lang::IndexOutOfBoundsException(); + + } + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) + { + return word::XCell::static_type(0); + } + virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return sal_True; + } + // XEnumerationAccess + virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) + { + return new CellsEnumWrapper( this ); + } +}; + +SwVbaCells::SwVbaCells( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextTable >& xTextTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (uno::RuntimeException) : SwVbaCells_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new CellCollectionHelper( xParent, xContext, xTextTable, nLeft, nTop, nRight, nBottom ) ) ), mxTextTable( xTextTable ), mnLeft( nLeft ), mnTop( nTop ), mnRight( nRight ), mnBottom( nBottom ) +{ +} + +::sal_Int32 SAL_CALL SwVbaCells::getWidth() throw (css::uno::RuntimeException) +{ + uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( 0 ), uno::UNO_QUERY_THROW ); + return xCell->getWidth(); +} + +void SAL_CALL SwVbaCells::setWidth( ::sal_Int32 _width ) throw (css::uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + while( nIndex < m_xIndexAccess->getCount() ) + { + uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW ); + xCell->setWidth( _width ); + } +} + +uno::Any SAL_CALL SwVbaCells::getHeight() throw (css::uno::RuntimeException) +{ + uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnTop ) ); + return xRow->getHeight(); +} + +void SAL_CALL SwVbaCells::setHeight( const uno::Any& _height ) throw (css::uno::RuntimeException) +{ + for( sal_Int32 row = mnTop; row <= mnBottom; row++ ) + { + uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) ); + xRow->setHeight( _height ); + } +} + +::sal_Int32 SAL_CALL SwVbaCells::getHeightRule() throw (css::uno::RuntimeException) +{ + uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnTop ) ); + return xRow->getHeightRule(); +} + +void SAL_CALL SwVbaCells::setHeightRule( ::sal_Int32 _heightrule ) throw (css::uno::RuntimeException) +{ + for( sal_Int32 row = mnTop; row <= mnBottom; row++ ) + { + uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) ); + xRow->setHeightRule( _heightrule ); + } +} + +void SAL_CALL SwVbaCells::SetWidth( float width, sal_Int32 rulestyle ) throw (css::uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + while( nIndex < m_xIndexAccess->getCount() ) + { + uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW ); + xCell->SetWidth( width, rulestyle ); + } +} + +void SAL_CALL SwVbaCells::SetHeight( float height, sal_Int32 heightrule ) throw (css::uno::RuntimeException) +{ + for( sal_Int32 row = mnTop; row <= mnBottom; row++ ) + { + uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) ); + xRow->SetHeight( height, heightrule ); + } +} + +// XEnumerationAccess +uno::Type +SwVbaCells::getElementType() throw (uno::RuntimeException) +{ + return word::XCell::static_type(0); +} + +uno::Reference< container::XEnumeration > +SwVbaCells::createEnumeration() throw (uno::RuntimeException) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); + return xEnumAccess->createEnumeration(); +} + +uno::Any +SwVbaCells::createCollectionObject( const uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString& +SwVbaCells::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaCells") ); + return sImplName; +} + +uno::Sequence<rtl::OUString> +SwVbaCells::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Cells") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbacells.hxx b/sw/source/ui/vba/vbacells.hxx new file mode 100644 index 0000000000..5d4fa8ad44 --- /dev/null +++ b/sw/source/ui/vba/vbacells.hxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_CELLS_HXX +#define SW_VBA_CELLS_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XCells.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/text/XTextTable.hpp> + +typedef CollTestImplHelper< ooo::vba::word::XCells > SwVbaCells_BASE; + +class SwVbaCells : public SwVbaCells_BASE +{ +private: + css::uno::Reference< css::text::XTextTable > mxTextTable; + sal_Int32 mnLeft; + sal_Int32 mnTop; + sal_Int32 mnRight; + sal_Int32 mnBottom; + +public: + SwVbaCells( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::text::XTextTable >& xTextTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaCells() {} + + // Attributes + virtual ::sal_Int32 SAL_CALL getWidth() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWidth( ::sal_Int32 _width ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getHeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeight( const css::uno::Any& _height ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getHeightRule() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeightRule( ::sal_Int32 _heightrule ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL SetWidth( float width, sal_Int32 rulestyle ) throw (css::uno::RuntimeException); + virtual void SAL_CALL SetHeight( float height, sal_Int32 heightrule ) 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); + + // SwVbaCells_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SW_VBA_CELLS_HXX */ diff --git a/sw/source/ui/vba/vbacheckbox.cxx b/sw/source/ui/vba/vbacheckbox.cxx new file mode 100644 index 0000000000..49620b6f36 --- /dev/null +++ b/sw/source/ui/vba/vbacheckbox.cxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacheckbox.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextViewCursor.hpp> +#include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include <ecmaflds.hxx> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaCheckBox::SwVbaCheckBox( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< frame::XModel >& rModel, const uno::Reference< text::XFormField >& xFormField ) throw ( uno::RuntimeException ) : SwVbaCheckBox_BASE( rParent, rContext ), mxModel( rModel ), mxFormField( xFormField ) +{ + rtl::OUString sType = mxFormField->getFieldType(); + if( !sType.equalsIgnoreAsciiCaseAscii( ECMA_FORMCHECKBOX ) ) + { + throw uno::RuntimeException( rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("It is not a CheckBox")), uno::Reference< uno::XInterface >() ); + } +} + +SwVbaCheckBox::~SwVbaCheckBox() +{ +} + +sal_Bool SAL_CALL SwVbaCheckBox::getValue() throw ( uno::RuntimeException ) +{ + sal_Bool bValue = sal_False; + sal_Int32 nCount = mxFormField->getParamCount(); + for( sal_Int32 i = 0; i < nCount; i++ ) + { + if( mxFormField->getParamName(i).equalsIgnoreAsciiCaseAscii( ECMA_FORMCHECKBOX_CHECKED ) ) + { + if( mxFormField->getParamValue(i).equalsIgnoreAsciiCaseAscii("on") ) + bValue = sal_True; + else + bValue = sal_False; + break; + } + } + return bValue; +} + +void SAL_CALL SwVbaCheckBox::setValue( sal_Bool value ) throw ( uno::RuntimeException ) +{ + rtl::OUString sValue = rtl::OUString::createFromAscii( value ? "on" : "off" ); + mxFormField->addParam( rtl::OUString::createFromAscii( ECMA_FORMCHECKBOX_CHECKED ), sValue, sal_True ); +} + +rtl::OUString& +SwVbaCheckBox::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaCheckBox") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaCheckBox::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.CheckBox" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbacheckbox.hxx b/sw/source/ui/vba/vbacheckbox.hxx new file mode 100644 index 0000000000..91367c3195 --- /dev/null +++ b/sw/source/ui/vba/vbacheckbox.hxx @@ -0,0 +1,58 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_CHECKBOX_HXX +#define SW_VBA_CHECKBOX_HXX + +#include <ooo/vba/word/XCheckBox.hpp> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/text/XFormField.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XCheckBox > SwVbaCheckBox_BASE; + +class SwVbaCheckBox : public SwVbaCheckBox_BASE +{ +private: + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::text::XFormField > mxFormField; + +public: + SwVbaCheckBox( 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 css::uno::Reference< css::text::XFormField >& xFormField ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaCheckBox(); + + // Methods + sal_Bool SAL_CALL getValue() throw ( css::uno::RuntimeException ); + void SAL_CALL setValue( sal_Bool value ) throw ( css::uno::RuntimeException ); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_CHECKBOX_HXX */ diff --git a/sw/source/ui/vba/vbacolumn.cxx b/sw/source/ui/vba/vbacolumn.cxx new file mode 100644 index 0000000000..b99d85551e --- /dev/null +++ b/sw/source/ui/vba/vbacolumn.cxx @@ -0,0 +1,200 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacolumn.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include "vbatable.hxx" +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <rtl/ustrbuf.hxx> +#include "wordvbahelper.hxx" +#include "vbatablehelper.hxx" + +#define RELATIVE_TABLE_WIDTH 10000 + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaColumn::SwVbaColumn( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextTable >& xTextTable, sal_Int32 nIndex ) throw ( uno::RuntimeException ) : + SwVbaColumn_BASE( rParent, rContext ), mxTextTable( xTextTable ), mnIndex( nIndex ) +{ + mxTableColumns = mxTextTable->getColumns(); +} + +SwVbaColumn::~SwVbaColumn() +{ +} + +void SwVbaColumn::calculateAbsoluteColumnWidth( sal_Int32 nTableWidth, const css::uno::Sequence< css::text::TableColumnSeparator >& aSeparators, double* pAbsWidth ) +{ + const text::TableColumnSeparator* pArray = aSeparators.getConstArray(); + sal_Int32 nSepCount = aSeparators.getLength(); + for( sal_Int32 i = 0; i <= nSepCount; i++ ) + { + sal_Int32 nRelColWidth = 0; + if( i == 0 ) + { + if( nSepCount != 0 ) + { + nRelColWidth = pArray[0].Position; + } + else + { + nRelColWidth = RELATIVE_TABLE_WIDTH; + } + } + else + { + if( i == nSepCount ) + { + nRelColWidth = RELATIVE_TABLE_WIDTH - pArray[i-1].Position; + } + else + { + nRelColWidth = pArray[i].Position - pArray[i-1].Position; + } + } + pAbsWidth[i] = ( (double)nRelColWidth / RELATIVE_TABLE_WIDTH ) * (double) nTableWidth; + } +} + +void SwVbaColumn::calculateRelativeColumnWidth( const double* pAbsWidth, double* pRelWidth, sal_Int32 nCount ) +{ + double tableWidth = 0.0; + for( sal_Int32 i = 0; i < nCount; i++ ) + { + tableWidth += pAbsWidth[i]; + } + + pRelWidth[ nCount - 1 ] = tableWidth; + for( sal_Int32 i = 0; i < nCount - 1; i++ ) + { + if( i == 0 ) + { + pRelWidth[i] = ( pAbsWidth[i] * RELATIVE_TABLE_WIDTH ) / tableWidth; + } + else + { + pRelWidth[i] = pRelWidth[i-1] + ( pAbsWidth[i] * RELATIVE_TABLE_WIDTH ) / tableWidth; + } + } +} + +sal_Int32 SAL_CALL +SwVbaColumn::getWidth( ) throw ( css::uno::RuntimeException ) +{ + /* uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW ); + uno::Sequence< text::TableColumnSeparator > aSeparators; + xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TableColumnSeparators") ) ) >>= aSeparators; + sal_Int32 nTableWidth = SwVbaTable::getTableWidth( xTableProps ); + sal_Int32 nColCont = aSeparators.getLength() + 1; + double dAbsColWidth[ nColCont ]; + calculateAbsoluteColumnWidth( nTableWidth, aSeparators, dAbsColWidth ); + return Millimeter::getInPoints( (sal_Int32)( dAbsColWidth[ mnIndex ] ) ); + */ + SwVbaTableHelper aTableHelper( mxTextTable ); + return aTableHelper.GetColWidth( mnIndex ); +} + +void SAL_CALL +SwVbaColumn::setWidth( sal_Int32 _width ) throw ( css::uno::RuntimeException ) +{ +/* uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW ); + uno::Sequence< text::TableColumnSeparator > aSeparators; + xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TableColumnSeparators") ) ) >>= aSeparators; + sal_Int32 nTableWidth = SwVbaTable::getTableWidth( xTableProps ); + sal_Int32 nColCont = aSeparators.getLength() + 1; + double dAbsColWidth[ nColCont ]; + calculateAbsoluteColumnWidth( nTableWidth, aSeparators, dAbsColWidth ); + dAbsColWidth[ mnIndex ] = Millimeter::getInHundredthsOfOneMillimeter( _width ); + double tableWidth = 0.0; + for( sal_Int32 i = 0; i < nColCont; i++ ) + { + tableWidth += dAbsColWidth[i]; + } + + double dRelColWidth[ nColCont ]; + calculateRelativeColumnWidth( dAbsColWidth, dRelColWidth, nColCont); + + text::TableColumnSeparator* pArray = aSeparators.getArray(); + for( sal_Int32 i = 0; i < nColCont - 1; i++ ) + { + pArray[i].Position = (sal_Int16)(dRelColWidth[i]); + } + + xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TableColumnSeparators") ), uno::makeAny( aSeparators ) ); + SwVbaTable::setTableWidth( xTableProps, (sal_Int32)( tableWidth ) ); + */ + + SwVbaTableHelper aTableHelper( mxTextTable ); + aTableHelper.SetColWidth( _width, mnIndex ); +} + +void SAL_CALL +SwVbaColumn::Select( ) throw ( uno::RuntimeException ) +{ + SelectColumn( getCurrentWordDoc(mxContext), mxTextTable, mnIndex, mnIndex ); +} + +void SwVbaColumn::SelectColumn( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextTable >& xTextTable, sal_Int32 nStartColumn, sal_Int32 nEndColumn ) throw ( uno::RuntimeException ) +{ + rtl::OUStringBuffer aRangeName; + rtl::OUString sStartCol = SwVbaTableHelper::getColumnStr( nStartColumn ); + aRangeName.append(sStartCol).append(sal_Int32( 1 ) ); + rtl::OUString sEndCol = SwVbaTableHelper::getColumnStr( nEndColumn ); + sal_Int32 nRowCount = xTextTable->getRows()->getCount(); + aRangeName.appendAscii(":").append( sEndCol ).append( sal_Int32( nRowCount ) ); + + uno::Reference< table::XCellRange > xCellRange( xTextTable, uno::UNO_QUERY_THROW ); + rtl::OUString sSelRange = aRangeName.makeStringAndClear(); + uno::Reference< table::XCellRange > xSelRange = xCellRange->getCellRangeByName( sSelRange ); + + uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + xSelection->select( uno::makeAny( xSelRange ) ); +} + +rtl::OUString& +SwVbaColumn::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaColumn") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaColumn::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Column" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbacolumn.hxx b/sw/source/ui/vba/vbacolumn.hxx new file mode 100644 index 0000000000..fe4a81fc21 --- /dev/null +++ b/sw/source/ui/vba/vbacolumn.hxx @@ -0,0 +1,68 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_COLUMN_HXX +#define SW_VBA_COLUMN_HXX + +#include <ooo/vba/word/XColumn.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/table/XTableColumns.hpp> +#include <com/sun/star/text/XTextTable.hpp> +#include <com/sun/star/text/TableColumnSeparator.hpp> + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XColumn > SwVbaColumn_BASE; + +class SwVbaColumn : public SwVbaColumn_BASE +{ +private: + css::uno::Reference< css::text::XTextTable > mxTextTable; + css::uno::Reference< css::table::XTableColumns > mxTableColumns; + sal_Int32 mnIndex; + +private: + void calculateAbsoluteColumnWidth( sal_Int32 nTableWidth, const css::uno::Sequence< css::text::TableColumnSeparator >& aSeparators, double* pAbsWidth ); + void calculateRelativeColumnWidth( const double* pAbsWidth, double* pRelWidth, sal_Int32 nCount ); + +public: + SwVbaColumn( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextTable >& xTextTable, sal_Int32 nIndex ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaColumn(); + + // Methods + virtual sal_Int32 SAL_CALL getWidth() throw ( css::uno::RuntimeException ); + virtual void SAL_CALL setWidth( sal_Int32 _width ) throw ( css::uno::RuntimeException ); + virtual void SAL_CALL Select( ) throw (css::uno::RuntimeException); + + static void SelectColumn( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XTextTable >& xTextTable, sal_Int32 nStartColumn, sal_Int32 nEndColumn ) throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_COLUMN_HXX */ diff --git a/sw/source/ui/vba/vbacolumns.cxx b/sw/source/ui/vba/vbacolumns.cxx new file mode 100644 index 0000000000..0abd73d997 --- /dev/null +++ b/sw/source/ui/vba/vbacolumns.cxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacolumns.hxx" +#include "vbacolumn.hxx" +#include <com/sun/star/text/HoriOrientation.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <ooo/vba/word/WdConstants.hpp> +#include <ooo/vba/word/WdRulerStyle.hpp> +#include "wordvbahelper.hxx" +#include "vbatablehelper.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +class ColumnsEnumWrapper : public EnumerationHelper_BASE +{ + uno::WeakReference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< text::XTextTable > mxTextTable; + uno::Reference< container::XIndexAccess > mxIndexAccess; + sal_Int32 nIndex; + +public: + ColumnsEnumWrapper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< text::XTextTable >& xTextTable ) : mxParent( xParent ), mxContext( xContext ), mxTextTable( xTextTable ), nIndex( 0 ) + { + mxIndexAccess.set( mxTextTable->getColumns(), uno::UNO_QUERY ); + } + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < mxIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if( nIndex < mxIndexAccess->getCount() ) + { + return uno::makeAny( uno::Reference< word::XColumn > ( new SwVbaColumn( mxParent, mxContext, mxTextTable, nIndex++ ) ) ); + } + throw container::NoSuchElementException(); + } +}; + +SwVbaColumns::SwVbaColumns( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextTable >& xTextTable, const uno::Reference< table::XTableColumns >& xTableColumns ) throw (uno::RuntimeException) : SwVbaColumns_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( xTableColumns, uno::UNO_QUERY_THROW ) ), mxTextTable( xTextTable ), mxTableColumns( xTableColumns ) +{ + mnStartColumnIndex = 0; + SwVbaTableHelper aTableHelper( mxTextTable ); + mnEndColumnIndex = aTableHelper.getTabColumnsMaxCount( ) - 1; +} + +SwVbaColumns::SwVbaColumns( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextTable >& xTextTable, const uno::Reference< table::XTableColumns >& xTableColumns, sal_Int32 nStartCol, sal_Int32 nEndCol ) throw (uno::RuntimeException) : SwVbaColumns_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( xTableColumns, uno::UNO_QUERY_THROW ) ), mxTextTable( xTextTable ), mxTableColumns( xTableColumns ), mnStartColumnIndex( nStartCol ), mnEndColumnIndex( nEndCol ) +{ + if( mnEndColumnIndex < mnStartColumnIndex ) + throw uno::RuntimeException(); +} + +uno::Reference< word::XColumn > SwVbaColumns::getColumnAtIndex( sal_Int32 index ) throw (uno::RuntimeException) +{ + return uno::Reference< word::XColumn >( new SwVbaColumn( this, mxContext, mxTextTable, index ) ); +} + +::sal_Int32 SAL_CALL SwVbaColumns::getWidth() throw (uno::RuntimeException) +{ + return getColumnAtIndex( mnStartColumnIndex )->getWidth(); +} + +void SAL_CALL SwVbaColumns::setWidth( ::sal_Int32 _width ) throw (uno::RuntimeException) +{ + for( sal_Int32 index = mnStartColumnIndex; index <= mnEndColumnIndex; index++ ) + { + getColumnAtIndex( index )->setWidth( _width ); + } +} + +void SAL_CALL SwVbaColumns::Select( ) throw (uno::RuntimeException) +{ + SwVbaColumn::SelectColumn( getCurrentWordDoc(mxContext), mxTextTable, mnStartColumnIndex, mnEndColumnIndex ); +} + +::sal_Int32 SAL_CALL SwVbaColumns::getCount() throw (uno::RuntimeException) +{ + return ( mnEndColumnIndex - mnStartColumnIndex + 1 ); +} + +uno::Any SAL_CALL SwVbaColumns::Item( const uno::Any& Index1, const uno::Any& /*not processed in this base class*/ ) throw (uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + if( ( Index1 >>= nIndex ) == sal_True ) + { + if( nIndex <= 0 || nIndex > getCount() ) + { + throw lang::IndexOutOfBoundsException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Index out of bounds") ), uno::Reference< uno::XInterface >() ); + } + return uno::makeAny( uno::Reference< word::XColumn >( new SwVbaColumn( this, mxContext, mxTextTable, nIndex - 1 ) ) ); + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Index out of bounds") ), uno::Reference< uno::XInterface >() ); +} + +// XEnumerationAccess +uno::Type +SwVbaColumns::getElementType() throw (uno::RuntimeException) +{ + return word::XColumn::static_type(0); +} +uno::Reference< container::XEnumeration > +SwVbaColumns::createEnumeration() throw (uno::RuntimeException) +{ + return new ColumnsEnumWrapper( this, mxContext, mxTextTable ); +} + +uno::Any +SwVbaColumns::createCollectionObject( const uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString& +SwVbaColumns::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaColumns") ); + return sImplName; +} + +uno::Sequence<rtl::OUString> +SwVbaColumns::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Columns") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbacolumns.hxx b/sw/source/ui/vba/vbacolumns.hxx new file mode 100644 index 0000000000..a8f4dc2a3c --- /dev/null +++ b/sw/source/ui/vba/vbacolumns.hxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_COLUMNS_HXX +#define SW_VBA_COLUMNS_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XColumns.hpp> +#include <ooo/vba/word/XColumn.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/table/XTableColumns.hpp> +#include <com/sun/star/text/XTextTable.hpp> + +typedef CollTestImplHelper< ooo::vba::word::XColumns > SwVbaColumns_BASE; + +class SwVbaColumns : public SwVbaColumns_BASE +{ +private: + css::uno::Reference< css::text::XTextTable > mxTextTable; + css::uno::Reference< css::table::XTableColumns > mxTableColumns; + sal_Int32 mnStartColumnIndex; + sal_Int32 mnEndColumnIndex; + +private: + css::uno::Reference< ooo::vba::word::XColumn > getColumnAtIndex( sal_Int32 index ) throw (css::uno::RuntimeException); + +public: + SwVbaColumns( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::text::XTextTable >& xTextTable, const css::uno::Reference< css::table::XTableColumns >& xTableColumns ) throw ( css::uno::RuntimeException ); + SwVbaColumns( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::text::XTextTable >& xTextTable, const css::uno::Reference< css::table::XTableColumns >& xTableColumns, sal_Int32 nStartCol, sal_Int32 nEndCol ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaColumns() {} + + virtual sal_Int32 SAL_CALL getWidth( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL setWidth( sal_Int32 _width ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Select( ) throw (css::uno::RuntimeException); + + //XCollection + virtual ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& /*not processed in this base class*/ ) 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); + + // SwVbaColumns_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SW_VBA_COLUMNS_HXX */ diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx index 98692d56ca..71641e1dd6 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 4602e9ab08..4ca68013b3 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 475ca93751..0a3270c000 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 8e9661d0af..e5b4d87a75 100644 --- a/sw/source/ui/vba/vbafield.cxx +++ b/sw/source/ui/vba/vbafield.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -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,15 +46,26 @@ 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& +rtl::OUString& SwVbaField::getServiceImplName() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaField") ); - return sImplName; + return sImplName; } -uno::Sequence<rtl::OUString> +uno::Sequence<rtl::OUString> SwVbaField::getServiceNames() { static uno::Sequence< rtl::OUString > aServiceNames; @@ -276,7 +288,7 @@ uno::Any lcl_createField( const uno::Reference< XHelperInterface >& xParent, con typedef ::cppu::WeakImplHelper1< css::container::XEnumeration > FieldEnumeration_BASE; typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > FieldCollectionHelper_BASE; -class FieldEnumeration : public FieldEnumeration_BASE +class FieldEnumeration : public FieldEnumeration_BASE { uno::Reference< XHelperInterface > mxParent; uno::Reference< uno::XComponentContext > mxContext; @@ -286,8 +298,8 @@ public: FieldEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< container::XEnumeration >& xEnumeration ) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel ), mxEnumeration( xEnumeration ) { } - virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) - { + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { return mxEnumeration->hasMoreElements(); } virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) @@ -315,15 +327,15 @@ public: virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) { return mxEnumerationAccess->hasElements(); } // XIndexAccess virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) - { + { uno::Reference< container::XEnumeration > xEnumeration = mxEnumerationAccess->createEnumeration(); sal_Int32 nCount = 0; while( xEnumeration->hasMoreElements() ) { ++nCount; xEnumeration->nextElement(); - } - return nCount; + } + return nCount; } virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException ) { @@ -349,13 +361,13 @@ public: return uno::Reference< container::XEnumeration >( new FieldEnumeration( mxParent, mxContext, mxModel, xEnumeration ) ); } }; - + SwVbaFields::SwVbaFields( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ) : SwVbaFields_BASE( xParent, xContext , uno::Reference< container::XIndexAccess >( new FieldCollectionHelper( xParent, xContext, xModel ) ) ), mxModel( xModel ) { mxMSF.set( mxModel, uno::UNO_QUERY_THROW ); } -uno::Reference< word::XField > SAL_CALL +uno::Reference< word::XField > SAL_CALL SwVbaFields::Add( const css::uno::Reference< ::ooo::vba::word::XRange >& Range, const css::uno::Any& Type, const css::uno::Any& Text, const css::uno::Any& /*PreserveFormatting*/ ) throw (css::uno::RuntimeException) { sal_Int32 nType = word::WdFieldType::wdFieldEmpty; @@ -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,19 +436,117 @@ uno::Reference< text::XTextField > SwVbaFields::Create_Field_FileName( const rtl return xTextField; } -uno::Reference< container::XEnumeration > SAL_CALL +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) { uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); return xEnumerationAccess->createEnumeration(); } -// ScVbaCollectionBaseImpl -uno::Any +// ScVbaCollectionBaseImpl +uno::Any SwVbaFields::createCollectionObject( const uno::Any& aSource ) { return lcl_createField( mxParent, mxContext, mxModel, aSource ); -} +} sal_Int32 SAL_CALL SwVbaFields::Update() throw (uno::RuntimeException) { @@ -450,21 +565,21 @@ sal_Int32 SAL_CALL SwVbaFields::Update() throw (uno::RuntimeException) } // XHelperInterface -rtl::OUString& +rtl::OUString& SwVbaFields::getServiceImplName() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaFields") ); - return sImplName; + return sImplName; } // XEnumerationAccess -uno::Type SAL_CALL +uno::Type SAL_CALL SwVbaFields::getElementType() throw (uno::RuntimeException) { - return word::XField::static_type(0); + return word::XField::static_type(0); } -uno::Sequence<rtl::OUString> +uno::Sequence<rtl::OUString> SwVbaFields::getServiceNames() { static uno::Sequence< rtl::OUString > aServiceNames; diff --git a/sw/source/ui/vba/vbafield.hxx b/sw/source/ui/vba/vbafield.hxx index f421179d35..4f2ca4645b 100644 --- a/sw/source/ui/vba/vbafield.hxx +++ b/sw/source/ui/vba/vbafield.hxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -42,9 +42,10 @@ 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(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); }; // *** SwVbaFields *********************************************** @@ -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 ); @@ -66,12 +68,12 @@ public: // 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); - // ScVbaCollectionBaseImpl + // ScVbaCollectionBaseImpl virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); // XHelperInterface virtual rtl::OUString& getServiceImplName(); - virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); }; #endif diff --git a/sw/source/ui/vba/vbaformfield.cxx b/sw/source/ui/vba/vbaformfield.cxx new file mode 100644 index 0000000000..5988015be3 --- /dev/null +++ b/sw/source/ui/vba/vbaformfield.cxx @@ -0,0 +1,138 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaformfield.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextViewCursor.hpp> +#include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include <ecmaflds.hxx> +#include "vbacheckbox.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaFormField::SwVbaFormField( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< frame::XModel >& rModel, const uno::Reference< text::XFormField >& xFormField ) throw ( uno::RuntimeException ) : SwVbaFormField_BASE( rParent, rContext ), mxModel( rModel ), mxFormField( xFormField ) +{ +} + +SwVbaFormField::~SwVbaFormField() +{ +} + +rtl::OUString SAL_CALL SwVbaFormField::getResult() throw ( uno::RuntimeException ) +{ + rtl::OUString sResult; + rtl::OUString sType = mxFormField->getFieldType(); + if( sType.equalsIgnoreAsciiCaseAscii( ECMA_FORMTEXT ) ) + { + uno::Reference< text::XTextContent > xTextContent( mxFormField, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRange > xTextRange = xTextContent->getAnchor(); + sResult = xTextRange->getString(); + } + else if( sType.equalsIgnoreAsciiCaseAscii( ECMA_FORMCHECKBOX ) ) + { + sal_Int32 nValue = 0; + sal_Int32 nCount = mxFormField->getParamCount(); + for( sal_Int32 i = 0; i < nCount; i++ ) + { + if( mxFormField->getParamName(i).equalsIgnoreAsciiCaseAscii( ECMA_FORMCHECKBOX_CHECKED ) ) + { + if( mxFormField->getParamValue(i).equalsIgnoreAsciiCaseAscii("on") ) + nValue = 1; + else + nValue = 0; + break; + } + + } + sResult = rtl::OUString::valueOf( nValue ); + } + else + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + return sResult; +} + +void SAL_CALL SwVbaFormField::setResult( const rtl::OUString& result ) throw ( uno::RuntimeException ) +{ + rtl::OUString sType = mxFormField->getFieldType(); + if( sType.equalsIgnoreAsciiCaseAscii( ECMA_FORMTEXT ) ) + { + uno::Reference< text::XTextContent > xTextContent( mxFormField, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRange > xTextRange = xTextContent->getAnchor(); + xTextRange->setString( result ); + } + else if( sType.equalsIgnoreAsciiCaseAscii( ECMA_FORMCHECKBOX ) ) + { + // do nothing + } + else + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } +} + +sal_Bool SAL_CALL SwVbaFormField::getEnabled() throw ( uno::RuntimeException ) +{ + //allways return true + return sal_True; +} + +void SAL_CALL SwVbaFormField::setEnabled( sal_Bool/* enabled */ ) throw ( uno::RuntimeException ) +{ + // not support in Writer +} + +uno::Any SAL_CALL SwVbaFormField::CheckBox() throw ( uno::RuntimeException ) +{ + return uno::makeAny( uno::Reference< word::XCheckBox >( new SwVbaCheckBox( this, mxContext, mxModel, mxFormField ) ) ); +} + +rtl::OUString& +SwVbaFormField::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaFormField") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaFormField::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.FormField" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbaformfield.hxx b/sw/source/ui/vba/vbaformfield.hxx new file mode 100644 index 0000000000..6a90269d47 --- /dev/null +++ b/sw/source/ui/vba/vbaformfield.hxx @@ -0,0 +1,61 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_FORMFIELD_HXX +#define SW_VBA_FORMFIELD_HXX + +#include <ooo/vba/word/XFormField.hpp> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/text/XFormField.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XFormField > SwVbaFormField_BASE; + +class SwVbaFormField : public SwVbaFormField_BASE +{ +private: + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::text::XFormField > mxFormField; + +public: + SwVbaFormField( 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 css::uno::Reference< css::text::XFormField >& xFormField ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaFormField(); + + // Methods + rtl::OUString SAL_CALL getResult() throw ( css::uno::RuntimeException ); + void SAL_CALL setResult( const rtl::OUString& result ) throw ( css::uno::RuntimeException ); + sal_Bool SAL_CALL getEnabled() throw ( css::uno::RuntimeException ); + void SAL_CALL setEnabled( sal_Bool enabled ) throw ( css::uno::RuntimeException ); + css::uno::Any SAL_CALL CheckBox() throw ( css::uno::RuntimeException ); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_FORMFIELD_HXX */ diff --git a/sw/source/ui/vba/vbaformfields.cxx b/sw/source/ui/vba/vbaformfields.cxx new file mode 100644 index 0000000000..293f2f90ae --- /dev/null +++ b/sw/source/ui/vba/vbaformfields.cxx @@ -0,0 +1,205 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaformfields.hxx" +#include "vbaformfield.hxx" +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextViewCursor.hpp> +#include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include "wordvbahelper.hxx" +#include <cppuhelper/implbase3.hxx> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +typedef std::vector< uno::Reference< text::XFormField > > XFormFieldVec; +typedef ::cppu::WeakImplHelper1< container::XEnumeration > FormFiledEnumeration_BASE; +typedef ::cppu::WeakImplHelper3< container::XNameAccess, container::XIndexAccess, container::XEnumerationAccess > FormFieldCollectionHelper_BASE; + +rtl::OUString lcl_getFormFieldName( const uno::Reference< text::XFormField >& xFormField ) +{ + rtl::OUString sName; + sal_Int32 nCount = xFormField->getParamCount(); + for( sal_Int32 i = 0; i < nCount; i++ ) + { + if( xFormField->getParamName(i).equalsIgnoreAsciiCaseAscii( "Name" ) ) + { + sName = xFormField->getParamValue(i); + OSL_TRACE("lcl_getFormFieldName: %s", rtl::OUStringToOString( sName, RTL_TEXTENCODING_UTF8 ).getStr() ); + break; + } + } + return sName; +} + +class FormFieldsEnumeration : public FormFiledEnumeration_BASE +{ +private: + uno::Reference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< frame::XModel > mxModel; + XFormFieldVec mxFormFields; + XFormFieldVec::iterator cachePos; +public: + FormFieldsEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const XFormFieldVec& xFormFiels ) throw (uno::RuntimeException) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel ), mxFormFields( xFormFiels ), cachePos( mxFormFields.begin() ) + { + } + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( cachePos != mxFormFields.end() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasMoreElements() ) + throw container::NoSuchElementException(); + uno::Reference< text::XFormField > xFormField( *cachePos++ ); + return uno::makeAny( uno::Reference< word::XFormField > ( new SwVbaFormField( mxParent, mxContext, mxModel, xFormField ) ) ); + } + +}; + +class FormFieldCollectionHelper : public FormFieldCollectionHelper_BASE +{ +private: + uno::Reference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< frame::XModel > mxModel; + XFormFieldVec mxFormFields; + XFormFieldVec::iterator cachePos; +public: + FormFieldCollectionHelper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel ) + { + uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( xModel,uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xIndexAccess( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW ); + sal_Int32 nCount = xIndexAccess->getCount(); + for( sal_Int32 i = 0; i < nCount; i++ ) + { + uno::Reference< text::XFormField > xFormField( xIndexAccess->getByIndex( i ), uno::UNO_QUERY ); + if( xFormField.is() ) + mxFormFields.push_back( xFormField ); + } + cachePos = mxFormFields.begin(); + } + // XElementAccess + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) { return word::XFormField::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::XFormField > xFormField( *cachePos, uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< word::XFormField >( new SwVbaFormField( mxParent, mxContext, mxModel, xFormField ) ) ); + } + virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) + { + uno::Sequence< rtl::OUString > sNames( mxFormFields.size() ); + rtl::OUString* pString = sNames.getArray(); + XFormFieldVec::iterator it = mxFormFields.begin(); + XFormFieldVec::iterator it_end = mxFormFields.end(); + for ( ; it != it_end; ++it, ++pString ) + { + uno::Reference< text::XFormField > xFormField( *cachePos, uno::UNO_QUERY_THROW ); + *pString = lcl_getFormFieldName( xFormField ); + } + return sNames; + } + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException) + { + cachePos = mxFormFields.begin(); + XFormFieldVec::iterator it_end = mxFormFields.end(); + for ( ; cachePos != it_end; ++cachePos ) + { + //uno::Reference< container::XNamed > xName( *cachePos, uno::UNO_QUERY_THROW ); + uno::Reference< text::XFormField > xFormField( *cachePos, uno::UNO_QUERY_THROW ); + if ( aName.equalsIgnoreAsciiCase( lcl_getFormFieldName( xFormField )) ) + break; + } + return ( cachePos != it_end ); + } + // XIndexAccess + virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) + { + return mxFormFields.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(); + return uno::makeAny( uno::Reference< word::XFormField >( new SwVbaFormField( mxParent, mxContext, mxModel, mxFormFields[ Index ] ) ) ); + } + // XEnumerationAccess + virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) + { + return new FormFieldsEnumeration( mxParent, mxContext, mxModel, mxFormFields ); + } +}; + +SwVbaFormFields::SwVbaFormFields( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ): SwVbaFormFields_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new FormFieldCollectionHelper( xParent, xContext, xModel ) ) ), mxModel( xModel ) +{ +} +// XEnumerationAccess +uno::Type +SwVbaFormFields::getElementType() throw (uno::RuntimeException) +{ + return word::XFormField::static_type(0); +} +uno::Reference< container::XEnumeration > +SwVbaFormFields::createEnumeration() throw (uno::RuntimeException) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); + return xEnumAccess->createEnumeration(); +} + +uno::Any +SwVbaFormFields::createCollectionObject( const css::uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString& +SwVbaFormFields::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaFormFields") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +SwVbaFormFields::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.FormFields") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbaformfields.hxx b/sw/source/ui/vba/vbaformfields.hxx new file mode 100644 index 0000000000..338b01cb84 --- /dev/null +++ b/sw/source/ui/vba/vbaformfields.hxx @@ -0,0 +1,60 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_FORMFIELDS_HXX +#define SW_VBA_FORMFIELDS_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XFormFields.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/text/XBookmarksSupplier.hpp> +#include <com/sun/star/text/XTextRange.hpp> + +typedef CollTestImplHelper< ooo::vba::word::XFormFields > SwVbaFormFields_BASE; + +class SwVbaFormFields : public SwVbaFormFields_BASE +{ +private: + css::uno::Reference< css::frame::XModel > mxModel; + +public: + SwVbaFormFields( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::frame::XModel >& xModel ); + virtual ~SwVbaFormFields() {} + + // 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); + + // SwVbaFormFields_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SW_VBA_FORMFIELDS_HXX */ diff --git a/sw/source/ui/vba/vbaframe.cxx b/sw/source/ui/vba/vbaframe.cxx new file mode 100644 index 0000000000..f7fbb249a0 --- /dev/null +++ b/sw/source/ui/vba/vbaframe.cxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaframe.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextViewCursor.hpp> +#include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaFrame::SwVbaFrame( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const css::uno::Reference< frame::XModel >& rModel, const css::uno::Reference< text::XTextFrame >& xTextFrame ) throw ( css::uno::RuntimeException ) : + SwVbaFrame_BASE( rParent, rContext ), mxModel( rModel ), mxTextFrame( xTextFrame ) +{ +} + +SwVbaFrame::~SwVbaFrame() +{ +} + +void SAL_CALL SwVbaFrame::Select() throw ( uno::RuntimeException ) +{ + uno::Reference< view::XSelectionSupplier > xSelectSupp( mxModel->getCurrentController(), uno::UNO_QUERY_THROW ); + xSelectSupp->select( uno::makeAny( mxTextFrame ) ); +} + +rtl::OUString& +SwVbaFrame::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaFrame") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaFrame::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Frame" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbaframe.hxx b/sw/source/ui/vba/vbaframe.hxx new file mode 100644 index 0000000000..6584bcf94f --- /dev/null +++ b/sw/source/ui/vba/vbaframe.hxx @@ -0,0 +1,57 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_FRAME_HXX +#define SW_VBA_FRAME_HXX + +#include <ooo/vba/word/XFrame.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/text/XTextFrame.hpp> + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XFrame > SwVbaFrame_BASE; + +class SwVbaFrame : public SwVbaFrame_BASE +{ +private: + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::text::XTextFrame > mxTextFrame; + +public: + SwVbaFrame( 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 css::uno::Reference< css::text::XTextFrame >& xTextFrame ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaFrame(); + + // Methods + virtual void SAL_CALL Select() throw ( css::uno::RuntimeException ); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_FRAME_HXX */ diff --git a/sw/source/ui/vba/vbaframes.cxx b/sw/source/ui/vba/vbaframes.cxx new file mode 100644 index 0000000000..0c2a4f36f1 --- /dev/null +++ b/sw/source/ui/vba/vbaframes.cxx @@ -0,0 +1,109 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaframes.hxx" +#include "vbaframe.hxx" +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextViewCursor.hpp> +#include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include "wordvbahelper.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +typedef ::cppu::WeakImplHelper1< container::XEnumeration > FramesEnumeration_Base; +class FramesEnumeration : public FramesEnumeration_Base +{ +private: + uno::Reference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< container::XIndexAccess> mxIndexAccess; + uno::Reference< frame::XModel > mxModel; + sal_Int32 nCurrentPos; +public: + FramesEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess, const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : mxParent( xParent ), mxContext( xContext), mxIndexAccess( xIndexAccess ), mxModel( xModel ), nCurrentPos(0) + { + } + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nCurrentPos < mxIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasMoreElements() ) + throw container::NoSuchElementException(); + uno::Reference< text::XTextFrame > xTextFrame( mxIndexAccess->getByIndex( nCurrentPos++ ), uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< word::XFrame > ( new SwVbaFrame( mxParent, mxContext, mxModel, xTextFrame ) ) ); + } + +}; + +SwVbaFrames::SwVbaFrames( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xFrames, const uno::Reference< frame::XModel >& xModel ): SwVbaFrames_BASE( xParent, xContext, xFrames ), mxModel( xModel ) +{ + mxFramesSupplier.set( mxModel, uno::UNO_QUERY_THROW ); +} +// XEnumerationAccess +uno::Type +SwVbaFrames::getElementType() throw (uno::RuntimeException) +{ + return word::XFrame::static_type(0); +} + +uno::Reference< container::XEnumeration > +SwVbaFrames::createEnumeration() throw (uno::RuntimeException) +{ + return new FramesEnumeration( this, mxContext,m_xIndexAccess, mxModel ); +} + +uno::Any +SwVbaFrames::createCollectionObject( const css::uno::Any& aSource ) +{ + uno::Reference< text::XTextFrame > xTextFrame( aSource, uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< word::XFrame > ( new SwVbaFrame( this, mxContext, mxModel, xTextFrame ) ) ); +} + +rtl::OUString& +SwVbaFrames::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaFrames") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +SwVbaFrames::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Frames") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbaframes.hxx b/sw/source/ui/vba/vbaframes.hxx new file mode 100644 index 0000000000..7a7a1c3d15 --- /dev/null +++ b/sw/source/ui/vba/vbaframes.hxx @@ -0,0 +1,61 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_FRAMES_HXX +#define SW_VBA_FRAMES_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XFrames.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/text/XTextFramesSupplier.hpp> + +typedef CollTestImplHelper< ooo::vba::word::XFrames > SwVbaFrames_BASE; + +class SwVbaFrames : public SwVbaFrames_BASE +{ +private: + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::text::XTextFramesSupplier > mxFramesSupplier; + +public: + SwVbaFrames( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::container::XIndexAccess >& xFrames, const css::uno::Reference< css::frame::XModel >& xModel ); + virtual ~SwVbaFrames() {} + + // 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); + + // SwVbaFrames_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +}; + +#endif /* SW_VBA_FRAMES_HXX */ diff --git a/sw/source/ui/vba/vbaglobals.cxx b/sw/source/ui/vba/vbaglobals.cxx index 0770ea3196..c8012944c2 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 ad6ce95bce..4bf3e7be03 100644 --- a/sw/source/ui/vba/vbaglobals.hxx +++ b/sw/source/ui/vba/vbaglobals.hxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -46,7 +46,7 @@ typedef ::cppu::ImplInheritanceHelper1< VbaGlobalsBase, ov::word::XGlobals > SwVbaGlobals_BASE; -class SwVbaGlobals : public SwVbaGlobals_BASE +class SwVbaGlobals : public SwVbaGlobals_BASE { private: css::uno::Reference< ooo::vba::word::XApplication > mxApplication; @@ -54,7 +54,7 @@ private: virtual css::uno::Reference< ooo::vba::word::XApplication > getApplication() throw (css::uno::RuntimeException); public: - + SwVbaGlobals( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& rxContext ); virtual ~SwVbaGlobals(); @@ -65,10 +65,11 @@ public: virtual css::uno::Reference< ov::word::XWindow > SAL_CALL getActiveWindow() throw (css::uno::RuntimeException); virtual css::uno::Reference< ooo::vba::word::XOptions > SAL_CALL getOptions() throw (css::uno::RuntimeException); virtual css::uno::Reference< ooo::vba::word::XSelection > SAL_CALL getSelection() throw (css::uno::RuntimeException); - virtual css::uno::Any SAL_CALL CommandBars( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); - 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 CommandBars( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + 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); @@ -77,4 +78,4 @@ public: virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); }; -#endif /* SW_VBA_GLOBALS_HXX */ +#endif /* SW_VBA_GLOBALS_HXX */ diff --git a/sw/source/ui/vba/vbaheaderfooter.cxx b/sw/source/ui/vba/vbaheaderfooter.cxx index ec3b0cef27..6b7c131492 100644 --- a/sw/source/ui/vba/vbaheaderfooter.cxx +++ b/sw/source/ui/vba/vbaheaderfooter.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -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 ); @@ -90,14 +91,14 @@ SwVbaHeaderFooter::Shapes( const uno::Any& index ) throw (uno::RuntimeException) return uno::makeAny( xCol ); } -rtl::OUString& +rtl::OUString& SwVbaHeaderFooter::getServiceImplName() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaHeaderFooter") ); return sImplName; } -uno::Sequence< rtl::OUString > +uno::Sequence< rtl::OUString > SwVbaHeaderFooter::getServiceNames() { static uno::Sequence< rtl::OUString > aServiceNames; diff --git a/sw/source/ui/vba/vbaheaderfooterhelper.cxx b/sw/source/ui/vba/vbaheaderfooterhelper.cxx index d91f37a20d..e299c51953 100644 --- a/sw/source/ui/vba/vbaheaderfooterhelper.cxx +++ b/sw/source/ui/vba/vbaheaderfooterhelper.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -29,50 +29,74 @@ #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; #define FIRST_PAGE 1; -// Class HeaderFooterHelper +// 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 ); - - sal_Bool isOn = sal_False; - xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn"))) >>= isOn; - if( !isOn ) - return sal_False; + 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 isShared = sal_False; - xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsShared"))) >>= isShared; +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; + 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; @@ -93,45 +117,52 @@ sal_Bool HeaderFooterHelper::isEvenPagesHeader( const uno::Reference< frame::XMo { uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); return ( 0 == xPageCursor->getPage() % 2 ); - } + } } 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 ); - return ( xText == xCurrentText ); + 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 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; @@ -151,25 +182,25 @@ sal_Bool HeaderFooterHelper::isEvenPagesFooter( const uno::Reference< frame::XMo { uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW ); return ( 0 == xPageCursor->getPage() % 2 ); - } + } } return sal_False; } #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 0e5fd4c450..dbcd53d84a 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/vbaheadersfooters.cxx b/sw/source/ui/vba/vbaheadersfooters.cxx new file mode 100644 index 0000000000..197e64e692 --- /dev/null +++ b/sw/source/ui/vba/vbaheadersfooters.cxx @@ -0,0 +1,150 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaheadersfooters.hxx" +#include "vbaheaderfooter.hxx" +#include <ooo/vba/word/WdHeaderFooterIndex.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +// I assume there is only one headersfooters in Writer +typedef ::cppu::WeakImplHelper1<container::XIndexAccess > HeadersFootersIndexAccess_Base; +class HeadersFootersIndexAccess : public HeadersFootersIndexAccess_Base +{ +private: + uno::Reference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< frame::XModel > mxModel; + uno::Reference< beans::XPropertySet > mxPageStyleProps; + sal_Bool mbHeader; + +public: + HeadersFootersIndexAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< beans::XPropertySet >& xPageStyleProps, sal_Bool bHeader ) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel ), mxPageStyleProps( xPageStyleProps ), mbHeader( bHeader ) {} + ~HeadersFootersIndexAccess(){} + + // XIndexAccess + virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) + { + // first page, evenpages and primary page + return 3; + } + virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { + if( Index < 1 || Index > 3 ) + throw container::NoSuchElementException(); + return uno::makeAny( uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( mxParent, mxContext, mxModel, mxPageStyleProps, mbHeader, Index ) ) ); + } + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) + { + return word::XHeaderFooter::static_type(0); + } + virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return sal_True; + } +}; + +class HeadersFootersEnumWrapper : public EnumerationHelper_BASE +{ + SwVbaHeadersFooters* pHeadersFooters; + sal_Int32 nIndex; +public: + HeadersFootersEnumWrapper( SwVbaHeadersFooters* _pHeadersFooters ) : pHeadersFooters( _pHeadersFooters ), nIndex( 0 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < pHeadersFooters->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex < pHeadersFooters->getCount() ) + return pHeadersFooters->Item( uno::makeAny( ++nIndex ), uno::Any() ); + throw container::NoSuchElementException(); + } +}; + +SwVbaHeadersFooters::SwVbaHeadersFooters( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< beans::XPropertySet >& xPageStyleProps, sal_Bool isHeader ): SwVbaHeadersFooters_BASE( xParent, xContext, new HeadersFootersIndexAccess( xParent, xContext, xModel, xPageStyleProps, isHeader ) ), mxModel( xModel ), mxPageStyleProps( xPageStyleProps ), mbHeader( isHeader ) +{ +} + +::sal_Int32 SAL_CALL SwVbaHeadersFooters::getCount() throw (uno::RuntimeException) +{ + // wdHeaderFooterFirstPage, wdHeaderFooterPrimary and wdHeaderFooterEvenPages + return 3; +} + +uno::Any SAL_CALL SwVbaHeadersFooters::Item( const uno::Any& Index1, const uno::Any& ) throw (uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + Index1 >>= nIndex; + if( ( nIndex < 1 ) || ( nIndex > 3 ) ) + { + throw container::NoSuchElementException(); + } + return uno::makeAny( uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( this, mxContext, mxModel, mxPageStyleProps, mbHeader, nIndex ) ) ); +} + +// XEnumerationAccess +uno::Type +SwVbaHeadersFooters::getElementType() throw (uno::RuntimeException) +{ + return word::XHeaderFooter::static_type(0); +} +uno::Reference< container::XEnumeration > + +SwVbaHeadersFooters::createEnumeration() throw (uno::RuntimeException) +{ + return new HeadersFootersEnumWrapper( this ); +} + +uno::Any +SwVbaHeadersFooters::createCollectionObject( const uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString& +SwVbaHeadersFooters::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaHeadersFooters") ); + return sImplName; +} + +uno::Sequence<rtl::OUString> +SwVbaHeadersFooters::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.HeadersFooters") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbaheadersfooters.hxx b/sw/source/ui/vba/vbaheadersfooters.hxx new file mode 100644 index 0000000000..f7d2ce4517 --- /dev/null +++ b/sw/source/ui/vba/vbaheadersfooters.hxx @@ -0,0 +1,62 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_HEADERSFOOTERS_HXX +#define SW_VBA_HEADERSFOOTERS_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XHeadersFooters.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef CollTestImplHelper< ooo::vba::word::XHeadersFooters > SwVbaHeadersFooters_BASE; + +class SwVbaHeadersFooters : public SwVbaHeadersFooters_BASE +{ +private: + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::beans::XPropertySet > mxPageStyleProps; + sal_Bool mbHeader; + +public: + SwVbaHeadersFooters( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::beans::XPropertySet >& xProps, sal_Bool isHeader ); + virtual ~SwVbaHeadersFooters() {} + + virtual ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& )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); + + // SwVbaHeadersFooters_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SW_VBA_HEADERSFOOTERS_HXX */ diff --git a/sw/source/ui/vba/vbalistformat.cxx b/sw/source/ui/vba/vbalistformat.cxx new file mode 100644 index 0000000000..2f2fde8a3e --- /dev/null +++ b/sw/source/ui/vba/vbalistformat.cxx @@ -0,0 +1,120 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbalistformat.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include <ooo/vba/word/WdListApplyTo.hpp> +#include <ooo/vba/word/WdDefaultListBehavior.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include "vbalisttemplate.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaListFormat::SwVbaListFormat( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextRange >& xTextRange ) throw ( uno::RuntimeException ) : SwVbaListFormat_BASE( rParent, rContext ), mxTextRange( xTextRange ) +{ +} + +SwVbaListFormat::~SwVbaListFormat() +{ +} + +void SAL_CALL SwVbaListFormat::ApplyListTemplate( const css::uno::Reference< word::XListTemplate >& ListTemplate, const css::uno::Any& ContinuePreviousList, const css::uno::Any& ApplyTo, const css::uno::Any& DefaultListBehavior ) throw (css::uno::RuntimeException) +{ + sal_Bool bContinuePreviousList = sal_True; + if( ContinuePreviousList.hasValue() ) + ContinuePreviousList >>= bContinuePreviousList; + + // "applyto" must be current selection + sal_Int32 bApplyTo = word::WdListApplyTo::wdListApplyToSelection; + if( ApplyTo.hasValue() ) + ApplyTo >>= bApplyTo; + if( bApplyTo != word::WdListApplyTo::wdListApplyToSelection ) + throw uno::RuntimeException(); + + // default behaviour must be wdWord8ListBehavior + sal_Int32 nDefaultListBehavior = word::WdDefaultListBehavior::wdWord8ListBehavior; + if( DefaultListBehavior.hasValue() ) + DefaultListBehavior >>= nDefaultListBehavior; + if( nDefaultListBehavior != word::WdDefaultListBehavior::wdWord8ListBehavior ) + throw uno::RuntimeException(); + + SwVbaListTemplate* pListTemplate = dynamic_cast< SwVbaListTemplate* >( ListTemplate.get() ); + + uno::Reference< container::XEnumerationAccess > xEnumAccess( mxTextRange, uno::UNO_QUERY_THROW ); + uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration(); + sal_Bool isFirstElement = sal_True; + while( xEnum->hasMoreElements() ) + { + uno::Reference< beans::XPropertySet > xProps( xEnum->nextElement(), uno::UNO_QUERY_THROW ); + if( isFirstElement ) + { + sal_Bool isNumberingRestart = !bContinuePreviousList; + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart") ), uno::makeAny( isNumberingRestart ) ); + if( isNumberingRestart ) + { + sal_Int16 nStartValue = 1; + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue") ), uno::makeAny( nStartValue ) ); + } + isFirstElement = sal_False; + } + else + { + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart") ), uno::makeAny( sal_False ) ); + } + pListTemplate->applyListTemplate( xProps ); + } +} + +void SAL_CALL SwVbaListFormat::ConvertNumbersToText( ) throw (css::uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); +} + +rtl::OUString& +SwVbaListFormat::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaListFormat") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaListFormat::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.ListFormat" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbalistformat.hxx b/sw/source/ui/vba/vbalistformat.hxx new file mode 100644 index 0000000000..966870c63f --- /dev/null +++ b/sw/source/ui/vba/vbalistformat.hxx @@ -0,0 +1,60 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_LISTFORMAT_HXX +#define SW_VBA_LISTFORMAT_HXX + +#include <ooo/vba/word/XListFormat.hpp> +#include <ooo/vba/word/XListTemplate.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/text/XTextRange.hpp> +#include "vbalisthelper.hxx" + + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XListFormat > SwVbaListFormat_BASE; + +class SwVbaListFormat : public SwVbaListFormat_BASE +{ +private: + css::uno::Reference< css::text::XTextRange > mxTextRange; + +public: + SwVbaListFormat( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextRange >& xTextRange ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaListFormat(); + + // Methods + virtual void SAL_CALL ApplyListTemplate( const css::uno::Reference< ::ooo::vba::word::XListTemplate >& ListTemplate, const css::uno::Any& ContinuePreviousList, const css::uno::Any& ApplyTo, const css::uno::Any& DefaultListBehavior ) throw (css::uno::RuntimeException); + virtual void SAL_CALL ConvertNumbersToText( ) throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_LISTFORMAT_HXX */ diff --git a/sw/source/ui/vba/vbalistgalleries.cxx b/sw/source/ui/vba/vbalistgalleries.cxx new file mode 100644 index 0000000000..e46b531ff8 --- /dev/null +++ b/sw/source/ui/vba/vbalistgalleries.cxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbalistgalleries.hxx" +#include "vbalistgallery.hxx" +#include <ooo/vba/word/WdListGalleryType.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +class ListGalleriesEnumWrapper : public EnumerationHelper_BASE +{ + SwVbaListGalleries* pListGalleries; + sal_Int32 nIndex; +public: + ListGalleriesEnumWrapper( SwVbaListGalleries* pGalleries ) : pListGalleries( pGalleries ), nIndex( 1 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex <= pListGalleries->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex <= pListGalleries->getCount() ) + return pListGalleries->Item( uno::makeAny( nIndex++ ), uno::Any() ); + throw container::NoSuchElementException(); + } +}; + +SwVbaListGalleries::SwVbaListGalleries( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextDocument >& xTextDoc ) throw (uno::RuntimeException) : SwVbaListGalleries_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >() ), mxTextDocument( xTextDoc ) +{ +} + +::sal_Int32 SAL_CALL SwVbaListGalleries::getCount() throw (uno::RuntimeException) +{ + // 3 types of list( bullet, numbered and outline ) + return 3; +} + +uno::Any SAL_CALL SwVbaListGalleries::Item( const uno::Any& Index1, const uno::Any& /*not processed in this base class*/ ) throw (uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + if( ( Index1 >>= nIndex ) == sal_True ) + { + if( nIndex == word::WdListGalleryType::wdBulletGallery + || nIndex == word::WdListGalleryType::wdNumberGallery + || nIndex == word::WdListGalleryType::wdOutlineNumberGallery ) + return uno::makeAny( uno::Reference< word::XListGallery >( new SwVbaListGallery( this, mxContext, mxTextDocument, nIndex ) ) ); + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Index out of bounds") ), uno::Reference< uno::XInterface >() ); +} + +// XEnumerationAccess +uno::Type +SwVbaListGalleries::getElementType() throw (uno::RuntimeException) +{ + return word::XListGallery::static_type(0); +} + +uno::Reference< container::XEnumeration > +SwVbaListGalleries::createEnumeration() throw (uno::RuntimeException) +{ + return new ListGalleriesEnumWrapper( this ); +} + +uno::Any +SwVbaListGalleries::createCollectionObject( const css::uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString& +SwVbaListGalleries::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaListGalleries") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +SwVbaListGalleries::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.ListGalleries") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbalistgalleries.hxx b/sw/source/ui/vba/vbalistgalleries.hxx new file mode 100644 index 0000000000..c1a1566bd1 --- /dev/null +++ b/sw/source/ui/vba/vbalistgalleries.hxx @@ -0,0 +1,61 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_LISTGALLERIES_HXX +#define SW_VBA_LISTGALLERIES_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XListGalleries.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/text/XTextDocument.hpp> + +typedef CollTestImplHelper< ooo::vba::word::XListGalleries > SwVbaListGalleries_BASE; + +class SwVbaListGalleries : public SwVbaListGalleries_BASE +{ +private: + css::uno::Reference< css::text::XTextDocument > mxTextDocument; + +public: + SwVbaListGalleries( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::text::XTextDocument >& xTextDoc ) throw (css::uno::RuntimeException); + virtual ~SwVbaListGalleries() {} + + virtual ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& /*not processed in this base class*/ ) 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); + + // SwVbaListGalleries_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SW_VBA_LISTGALLERIES_HXX */ diff --git a/sw/source/ui/vba/vbalistgallery.cxx b/sw/source/ui/vba/vbalistgallery.cxx new file mode 100644 index 0000000000..909036c040 --- /dev/null +++ b/sw/source/ui/vba/vbalistgallery.cxx @@ -0,0 +1,72 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbalistgallery.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include "vbalisttemplates.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaListGallery::SwVbaListGallery( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextDocument >& xTextDoc, sal_Int32 nType ) throw ( uno::RuntimeException ) : SwVbaListGallery_BASE( rParent, rContext ), mxTextDocument( xTextDoc ), mnType( nType ) +{ +} + +SwVbaListGallery::~SwVbaListGallery() +{ +} + +uno::Any SAL_CALL +SwVbaListGallery::ListTemplates( const uno::Any& index ) throw (uno::RuntimeException) +{ + uno::Reference< XCollection > xCol( new SwVbaListTemplates( mxParent, mxContext, mxTextDocument, mnType ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + +rtl::OUString& +SwVbaListGallery::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaListGallery") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaListGallery::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.ListGallery" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbalistgallery.hxx b/sw/source/ui/vba/vbalistgallery.hxx new file mode 100644 index 0000000000..dfb6fcd9ae --- /dev/null +++ b/sw/source/ui/vba/vbalistgallery.hxx @@ -0,0 +1,58 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_LISTGALLERY_HXX +#define SW_VBA_LISTGALLERY_HXX + +#include <ooo/vba/word/XListGallery.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/text/XTextDocument.hpp> + + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XListGallery > SwVbaListGallery_BASE; + +class SwVbaListGallery : public SwVbaListGallery_BASE +{ +private: + css::uno::Reference< css::text::XTextDocument > mxTextDocument; + sal_Int32 mnType; + +public: + SwVbaListGallery( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextDocument >& xTextDoc, sal_Int32 nType ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaListGallery(); + + // Methods + virtual css::uno::Any SAL_CALL ListTemplates( const css::uno::Any& index ) throw ( css::uno::RuntimeException ); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_LISTGALLERY_HXX */ diff --git a/sw/source/ui/vba/vbalisthelper.cxx b/sw/source/ui/vba/vbalisthelper.cxx new file mode 100644 index 0000000000..7cb29fa28c --- /dev/null +++ b/sw/source/ui/vba/vbalisthelper.cxx @@ -0,0 +1,706 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbalisthelper.hxx" +#include <tools/diagnose_ex.h> +#include <ooo/vba/word/WdListGalleryType.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/style/NumberingType.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +static const sal_Int32 LIST_LEVEL_COUNT = 9; + +static const char WORD_BULLET_GALLERY[] = "WdBullet"; +static const char WORD_NUMBER_GALLERY[] = "WdNumber"; +static const char WORD_OUTLINE_NUMBER_GALLERY[] = "WdOutlineNumber"; + +static const char UNO_NAME_ADJUST[] = "Adjust"; +static const char UNO_NAME_PARENT_NUMBERING[] = "ParentNumbering"; +static const char UNO_NAME_PREFIX[] = "Prefix"; +static const char UNO_NAME_SUFFIX[] = "Suffix"; +static const char UNO_NAME_CHAR_STYLE_NAME[] = "CharStyleName"; +static const char UNO_NAME_START_WITH[] = "StartWith"; +static const char UNO_NAME_POSITION_AND_SPACE_MODE[] = "PositionAndSpaceMode"; +static const char UNO_NAME_LABEL_FOLLOWED_BY[] = "LabelFollowedBy"; +static const char UNO_NAME_LIST_TAB_STOP_POSITION[] = "ListtabStopPosition"; +static const char UNO_NAME_FIRST_LINE_INDENT[] = "FirstLineIndent"; +static const char UNO_NAME_INDENT_AT[] = "IndentAt"; +static const char UNO_NAME_NUMBERING_TYPE[] = "NumberingType"; +static const char UNO_NAME_BULLET_ID[] = "BulletId"; +static const char UNO_NAME_BULLET_CHAR[] = "BulletChar"; +static const char UNO_NAME_BULLET_FONT_NAME[] = "BulletFontName"; +static const char UNO_NAME_BULLET_FONT[] = "BulletFont"; + +static const sal_Int16 CHAR_CLOSED_DOT = 8226; +static const sal_Int16 CHAR_EMPTY_DOT = 111; +static const sal_Int16 CHAR_SQUARE = 9632; +static const sal_Int16 CHAR_STAR_SYMBOL = 10026; +static const sal_Int16 CHAR_FOUR_DIAMONDS = 10070; +static const sal_Int16 CHAR_DIAMOND = 10022; +static const sal_Int16 CHAR_ARROW = 10146; +static const sal_Int16 CHAR_CHECK_MARK = 10003; + +SwVbaListHelper::SwVbaListHelper( const css::uno::Reference< css::text::XTextDocument >& xTextDoc, sal_Int32 nGalleryType, sal_Int32 nTemplateType ) throw( css::uno::RuntimeException ) : mxTextDocument( xTextDoc ), mnGalleryType( nGalleryType ), mnTemplateType( nTemplateType ) +{ + Init(); +} + +void SwVbaListHelper::Init() throw( css::uno::RuntimeException ) +{ + // set the numbering style name + switch( mnGalleryType ) + { + case word::WdListGalleryType::wdBulletGallery: + { + msStyleName = rtl::OUString::createFromAscii( WORD_BULLET_GALLERY ); + break; + } + case word::WdListGalleryType::wdNumberGallery: + { + msStyleName = rtl::OUString::createFromAscii( WORD_NUMBER_GALLERY ); + break; + } + case word::WdListGalleryType::wdOutlineNumberGallery: + { + msStyleName = rtl::OUString::createFromAscii( WORD_OUTLINE_NUMBER_GALLERY ); + break; + } + default: + { + throw uno::RuntimeException(); + } + } + msStyleName += rtl::OUString::valueOf( mnTemplateType ); + + // get the numbering style + uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxTextDocument, uno::UNO_QUERY_THROW ); + mxStyleFamily.set( xStyleSupplier->getStyleFamilies()->getByName(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingStyles") ) ), uno::UNO_QUERY_THROW ); + OSL_TRACE("SwVbaListHelper::Init: numbering style name: %s", rtl::OUStringToOString( msStyleName, RTL_TEXTENCODING_UTF8 ).getStr() ); + if( mxStyleFamily->hasByName( msStyleName ) ) + { + mxStyleProps.set( mxStyleFamily->getByName( msStyleName ), uno::UNO_QUERY_THROW ); + mxNumberingRules.set( mxStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingRules") ) ), uno::UNO_QUERY_THROW ); + } + else + { + // create new numbering style + uno::Reference< lang::XMultiServiceFactory > xDocMSF( mxTextDocument, uno::UNO_QUERY_THROW ); + mxStyleProps.set( xDocMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.NumberingStyle") ) ), uno::UNO_QUERY_THROW ); + // insert this style into style family, or the property NumberingRules doesn't exist. + mxStyleFamily->insertByName( msStyleName, uno::makeAny( mxStyleProps ) ); + mxStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingRules") ) ) >>= mxNumberingRules; + //mxNumberingRules.set( xDocMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.NumberingRules") ) ), uno::UNO_QUERY_THROW ); + + CreateListTemplate(); + + mxStyleProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingRules") ) , uno::makeAny( mxNumberingRules ) ); + } +} + +void SwVbaListHelper::CreateListTemplate() throw( css::uno::RuntimeException ) +{ + switch( mnGalleryType ) + { + case word::WdListGalleryType::wdBulletGallery: + { + CreateBulletListTemplate(); + break; + } + case word::WdListGalleryType::wdNumberGallery: + { + CreateNumberListTemplate(); + break; + } + case word::WdListGalleryType::wdOutlineNumberGallery: + { + CreateOutlineNumberListTemplate(); + break; + } + default: + { + throw uno::RuntimeException(); + } + } +} + +void SwVbaListHelper::CreateBulletListTemplate() throw( css::uno::RuntimeException ) +{ + // there is only 1 level for each bullet list in MSWord + sal_Int32 nLevel = 0; + uno::Sequence< beans::PropertyValue > aPropertyValues; + mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues; + rtl::OUString sCharStyleName( RTL_CONSTASCII_USTRINGPARAM("Bullet Symbols") ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_CHAR_STYLE_NAME ), uno::makeAny( sCharStyleName ) ); + sal_Int16 nNumberingType = style::NumberingType::CHAR_SPECIAL; + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_NUMBERING_TYPE ), uno::makeAny( nNumberingType ) ); + + rtl::OUString aBulletChar; + switch( mnTemplateType ) + { + case 1: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_CLOSED_DOT ) ); + break; + } + case 2: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_EMPTY_DOT ) ); + break; + } + case 3: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_SQUARE ) ); + break; + } + case 4: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_STAR_SYMBOL ) ); + break; + } + case 5: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_FOUR_DIAMONDS ) ); + break; + } + case 6: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_ARROW ) ); + break; + } + case 7: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_CHECK_MARK ) ); + break; + } + default: + { + // we only support 7 types template now + throw css::uno::RuntimeException(); + } + } + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_BULLET_CHAR ), uno::makeAny( aBulletChar ) ); + + mxNumberingRules->replaceByIndex( nLevel, uno::makeAny( aPropertyValues ) ); +} + +void SwVbaListHelper::CreateNumberListTemplate() throw( css::uno::RuntimeException ) +{ + // there is only 1 level for each bullet list in MSWord + sal_Int32 nLevel = 0; + uno::Sequence< beans::PropertyValue > aPropertyValues; + mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues; + + sal_Int16 nNumberingType = 0; + rtl::OUString sSuffix; + switch( mnTemplateType ) + { + case 1: + { + nNumberingType = style::NumberingType::ARABIC; + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + case 2: + { + nNumberingType = style::NumberingType::ARABIC; + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 3: + { + nNumberingType = style::NumberingType::ROMAN_UPPER; + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + case 4: + { + nNumberingType = style::NumberingType::CHARS_UPPER_LETTER; + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + case 5: + { + nNumberingType = style::NumberingType::CHARS_LOWER_LETTER; + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 6: + { + nNumberingType = style::NumberingType::CHARS_LOWER_LETTER; + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + case 7: + { + nNumberingType = style::NumberingType::ROMAN_LOWER; + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + default: + { + // we only support 7 types template now + throw css::uno::RuntimeException(); + } + } + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_NUMBERING_TYPE ), uno::makeAny( nNumberingType ) ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_SUFFIX ), uno::makeAny( sSuffix ) ); + + mxNumberingRules->replaceByIndex( nLevel, uno::makeAny( aPropertyValues ) ); +} + +void SwVbaListHelper::CreateOutlineNumberListTemplate() throw( css::uno::RuntimeException ) +{ + switch( mnTemplateType ) + { + case 1: + { + CreateOutlineNumberForType1(); + break; + } + case 2: + { + CreateOutlineNumberForType2(); + break; + } + case 3: + { + CreateOutlineNumberForType3(); + break; + } + case 4: + { + CreateOutlineNumberForType4(); + break; + } + case 5: + { + CreateOutlineNumberForType5(); + break; + } + case 6: + { + CreateOutlineNumberForType6(); + break; + } + case 7: + { + CreateOutlineNumberForType7(); + break; + } + default: + { + // we only support 7 types template now + throw css::uno::RuntimeException(); + } + } +} + +void SwVbaListHelper::CreateOutlineNumberForType1() throw( css::uno::RuntimeException ) +{ + sal_Int16 nNumberingType = 0; + rtl::OUString sPrefix; + rtl::OUString sSuffix; + uno::Sequence< beans::PropertyValue > aPropertyValues; + + for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ ) + { + mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues; + switch( nLevel ) + { + case 0: + case 1: + { + nNumberingType = style::NumberingType::ARABIC; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 2: + { + nNumberingType = style::NumberingType::ROMAN_LOWER; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 3: + { + nNumberingType = style::NumberingType::ARABIC; + sPrefix = rtl::OUString::valueOf( sal_Unicode('(') ); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 4: + { + nNumberingType = style::NumberingType::CHARS_LOWER_LETTER; + sPrefix = rtl::OUString::valueOf( sal_Unicode('(') ); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 5: + { + nNumberingType = style::NumberingType::ROMAN_LOWER; + sPrefix = rtl::OUString::valueOf( sal_Unicode('(') ); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 6: + { + nNumberingType = style::NumberingType::ARABIC; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + case 7: + { + nNumberingType = style::NumberingType::CHARS_LOWER_LETTER; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + case 8: + { + nNumberingType = style::NumberingType::ROMAN_LOWER; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + default: + { + throw uno::RuntimeException(); + } + } + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_NUMBERING_TYPE ), uno::makeAny( nNumberingType ) ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_PREFIX ), uno::makeAny( sPrefix ) ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_SUFFIX ), uno::makeAny( sSuffix ) ); + mxNumberingRules->replaceByIndex( nLevel, uno::makeAny( aPropertyValues ) ); + } +} + +void SwVbaListHelper::CreateOutlineNumberForType2() throw( css::uno::RuntimeException ) +{ + sal_Int16 nNumberingType = style::NumberingType::ARABIC; + sal_Int16 nParentNumbering = 0; + rtl::OUString sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + uno::Sequence< beans::PropertyValue > aPropertyValues; + + for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ ) + { + mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues; + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_NUMBERING_TYPE ), uno::makeAny( nNumberingType ) ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_SUFFIX ), uno::makeAny( sSuffix ) ); + if( nLevel != 0 ) + { + nParentNumbering = sal_Int16( nLevel - 1 ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_PARENT_NUMBERING ), uno::makeAny( nParentNumbering ) ); + } + mxNumberingRules->replaceByIndex( nLevel, uno::makeAny( aPropertyValues ) ); + } +} + +void SwVbaListHelper::CreateOutlineNumberForType3() throw( css::uno::RuntimeException ) +{ + sal_Int16 nNumberingType = style::NumberingType::CHAR_SPECIAL; + rtl::OUString sCharStyleName( RTL_CONSTASCII_USTRINGPARAM("Bullet Symbols") ); + rtl::OUString aBulletChar; + uno::Sequence< beans::PropertyValue > aPropertyValues; + + for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ ) + { + mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues; + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_NUMBERING_TYPE ), uno::makeAny( nNumberingType ) ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_CHAR_STYLE_NAME ), uno::makeAny( sCharStyleName ) ); + switch( nLevel ) + { + case 0: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_FOUR_DIAMONDS ) ); + break; + } + case 1: + case 5: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_ARROW ) ); + break; + } + case 2: + case 6: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_SQUARE ) ); + break; + } + case 3: + case 7: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_CLOSED_DOT ) ); + break; + } + case 4: + case 8: + { + aBulletChar = rtl::OUString( sal_Unicode( CHAR_DIAMOND ) ); + break; + } + default: + { + throw uno::RuntimeException(); + } + } + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_BULLET_CHAR ), uno::makeAny( aBulletChar ) ); + mxNumberingRules->replaceByIndex( nLevel, uno::makeAny( aPropertyValues ) ); + } +} + +void SwVbaListHelper::CreateOutlineNumberForType4() throw( css::uno::RuntimeException ) +{ + sal_Int16 nNumberingType = 0; + rtl::OUString sPrefix; + rtl::OUString sSuffix; + uno::Sequence< beans::PropertyValue > aPropertyValues; + + for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ ) + { + mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues; + switch( nLevel ) + { + case 0: + { + nNumberingType = style::NumberingType::ROMAN_UPPER; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + case 1: + { + nNumberingType = style::NumberingType::ARABIC; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + sal_Int16 nParentNumbering = 0; + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_PARENT_NUMBERING ), uno::makeAny( nParentNumbering ) ); + break; + } + case 2: + { + nNumberingType = style::NumberingType::CHARS_LOWER_LETTER; + sPrefix = rtl::OUString::valueOf( sal_Unicode('(') ); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 3: + { + nNumberingType = style::NumberingType::ROMAN_LOWER; + sPrefix = rtl::OUString::valueOf( sal_Unicode('(') ); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 4: + { + nNumberingType = style::NumberingType::ARABIC; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 5: + { + nNumberingType = style::NumberingType::CHARS_LOWER_LETTER; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 6: + { + nNumberingType = style::NumberingType::ROMAN_LOWER; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 7: + { + nNumberingType = style::NumberingType::CHARS_LOWER_LETTER; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + case 8: + { + nNumberingType = style::NumberingType::ROMAN_LOWER; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + default: + { + throw uno::RuntimeException(); + } + } + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_NUMBERING_TYPE ), uno::makeAny( nNumberingType ) ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_PREFIX ), uno::makeAny( sPrefix ) ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_SUFFIX ), uno::makeAny( sSuffix ) ); + mxNumberingRules->replaceByIndex( nLevel, uno::makeAny( aPropertyValues ) ); + } +} + +void SwVbaListHelper::CreateOutlineNumberForType5() throw( css::uno::RuntimeException ) +{ + sal_Int16 nNumberingType = style::NumberingType::ARABIC; + sal_Int16 nParentNumbering = 0; + uno::Sequence< beans::PropertyValue > aPropertyValues; + + for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ ) + { + mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues; + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_NUMBERING_TYPE ), uno::makeAny( nNumberingType ) ); + if( nLevel != 0 ) + { + nParentNumbering = sal_Int16( nLevel - 1 ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_PARENT_NUMBERING ), uno::makeAny( nParentNumbering ) ); + } + mxNumberingRules->replaceByIndex( nLevel, uno::makeAny( aPropertyValues ) ); + } +} + +void SwVbaListHelper::CreateOutlineNumberForType6() throw( css::uno::RuntimeException ) +{ + sal_Int16 nNumberingType = 0; + rtl::OUString sPrefix; + rtl::OUString sSuffix; + uno::Sequence< beans::PropertyValue > aPropertyValues; + + for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ ) + { + mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues; + switch( nLevel ) + { + case 0: + { + nNumberingType = style::NumberingType::ROMAN_UPPER; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + case 1: + { + nNumberingType = style::NumberingType::CHARS_UPPER_LETTER; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + case 2: + { + nNumberingType = style::NumberingType::ARABIC; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 3: + { + nNumberingType = style::NumberingType::CHARS_LOWER_LETTER; + sPrefix = rtl::OUString(); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 4: + { + nNumberingType = style::NumberingType::ARABIC; + sPrefix = rtl::OUString::valueOf( sal_Unicode('(') ); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 5: + { + nNumberingType = style::NumberingType::CHARS_LOWER_LETTER; + sPrefix = rtl::OUString::valueOf( sal_Unicode('(') ); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 6: + { + nNumberingType = style::NumberingType::ROMAN_LOWER; + sPrefix = rtl::OUString::valueOf( sal_Unicode('(') ); + sSuffix = rtl::OUString::valueOf( sal_Unicode(')') ); + break; + } + case 7: + { + nNumberingType = style::NumberingType::CHARS_LOWER_LETTER; + sPrefix = rtl::OUString::valueOf( sal_Unicode('(') ); + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + case 8: + { + nNumberingType = style::NumberingType::ROMAN_LOWER; + sPrefix = rtl::OUString::valueOf( sal_Unicode('(') ); + sSuffix = rtl::OUString::valueOf( sal_Unicode('.') ); + break; + } + default: + { + throw uno::RuntimeException(); + } + } + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_NUMBERING_TYPE ), uno::makeAny( nNumberingType ) ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_PREFIX ), uno::makeAny( sPrefix ) ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_SUFFIX ), uno::makeAny( sSuffix ) ); + mxNumberingRules->replaceByIndex( nLevel, uno::makeAny( aPropertyValues ) ); + } +} + +void SwVbaListHelper::CreateOutlineNumberForType7() throw( css::uno::RuntimeException ) +{ + sal_Int16 nNumberingType = style::NumberingType::ARABIC; + uno::Sequence< beans::PropertyValue > aPropertyValues; + rtl::OUString sPrefix = rtl::OUString::createFromAscii("Chapter "); + + for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ ) + { + mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues; + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_NUMBERING_TYPE ), uno::makeAny( nNumberingType ) ); + setOrAppendPropertyValue( aPropertyValues, rtl::OUString::createFromAscii( UNO_NAME_PREFIX ), uno::makeAny( sPrefix ) ); + mxNumberingRules->replaceByIndex( nLevel, uno::makeAny( aPropertyValues ) ); + } +} + +uno::Any SwVbaListHelper::getPropertyValueWithNameAndLevel( sal_Int32 nLevel, const rtl::OUString& sName ) throw( css::uno::RuntimeException ) +{ + uno::Sequence< beans::PropertyValue > aPropertyValues; + mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues; + return getPropertyValue( aPropertyValues, sName ); +} + +void SwVbaListHelper::setPropertyValueWithNameAndLevel( sal_Int32 nLevel, const rtl::OUString& sName, const css::uno::Any& aValue ) throw( css::uno::RuntimeException ) +{ + uno::Sequence< beans::PropertyValue > aPropertyValues; + mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues; + setOrAppendPropertyValue( aPropertyValues, sName, aValue ); + mxNumberingRules->replaceByIndex( nLevel, uno::makeAny( aPropertyValues ) ); + mxStyleProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingRules") ) , uno::makeAny( mxNumberingRules ) ); +} diff --git a/sw/source/ui/vba/vbalisthelper.hxx b/sw/source/ui/vba/vbalisthelper.hxx new file mode 100644 index 0000000000..1f6b2dc146 --- /dev/null +++ b/sw/source/ui/vba/vbalisthelper.hxx @@ -0,0 +1,74 @@ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#ifndef SW_VBA_LISTHELPER_HXX +#define SW_VBA_LISTHELPER_HXX + +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/container/XIndexReplace.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <boost/shared_ptr.hpp> + + +class SwVbaListHelper; +typedef ::boost::shared_ptr< SwVbaListHelper > SwVbaListHelperRef; + +class SwVbaListHelper +{ +private: + css::uno::Reference< css::text::XTextDocument > mxTextDocument; + css::uno::Reference< css::container::XIndexReplace > mxNumberingRules; + css::uno::Reference< css::container::XNameContainer > mxStyleFamily; + css::uno::Reference< css::beans::XPropertySet > mxStyleProps; + sal_Int32 mnGalleryType; + sal_Int32 mnTemplateType; + rtl::OUString msStyleName; + + void Init() throw( css::uno::RuntimeException ); + void CreateListTemplate() throw( css::uno::RuntimeException ); + void CreateBulletListTemplate() throw( css::uno::RuntimeException ); + void CreateNumberListTemplate() throw( css::uno::RuntimeException ); + void CreateOutlineNumberListTemplate() throw( css::uno::RuntimeException ); + void CreateOutlineNumberForType1() throw( css::uno::RuntimeException ); + void CreateOutlineNumberForType2() throw( css::uno::RuntimeException ); + void CreateOutlineNumberForType3() throw( css::uno::RuntimeException ); + void CreateOutlineNumberForType4() throw( css::uno::RuntimeException ); + void CreateOutlineNumberForType5() throw( css::uno::RuntimeException ); + void CreateOutlineNumberForType6() throw( css::uno::RuntimeException ); + void CreateOutlineNumberForType7() throw( css::uno::RuntimeException ); + +public: + SwVbaListHelper( const css::uno::Reference< css::text::XTextDocument >& xTextDoc, sal_Int32 nGalleryType, sal_Int32 nTemplateType ) throw( css::uno::RuntimeException ); + + sal_Int32 getGalleryType() { return mnGalleryType; } + css::uno::Reference< css::container::XIndexReplace > getNumberingRules() { return mxNumberingRules; } + css::uno::Any getPropertyValueWithNameAndLevel( sal_Int32 nLevel, const rtl::OUString& sName ) throw( css::uno::RuntimeException ); + void setPropertyValueWithNameAndLevel( sal_Int32 nLevel, const rtl::OUString& sName, const css::uno::Any& aValue ) throw( css::uno::RuntimeException ); + +}; + +#endif//SW_VBA_LISTHELPER_HXX diff --git a/sw/source/ui/vba/vbalistlevel.cxx b/sw/source/ui/vba/vbalistlevel.cxx new file mode 100644 index 0000000000..ba85610c8d --- /dev/null +++ b/sw/source/ui/vba/vbalistlevel.cxx @@ -0,0 +1,400 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbalistlevel.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include <com/sun/star/style/NumberingType.hpp> +#include <ooo/vba/word/WdListNumberStyle.hpp> +#include <ooo/vba/word/WdTrailingCharacter.hpp> +#include <com/sun/star/text/HoriOrientation.hpp> +#include <ooo/vba/word/WdListLevelAlignment.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaListLevel::SwVbaListLevel( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, SwVbaListHelperRef pHelper, sal_Int32 nLevel ) throw ( uno::RuntimeException ) : SwVbaListLevel_BASE( rParent, rContext ), pListHelper( pHelper ), mnLevel( nLevel ) +{ +} + +SwVbaListLevel::~SwVbaListLevel() +{ +} + +::sal_Int32 SAL_CALL SwVbaListLevel::getAlignment() throw (uno::RuntimeException) +{ + sal_Int16 nAlignment = 0; + pListHelper->getPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Adjust") ) ) >>= nAlignment; + switch( nAlignment ) + { + case text::HoriOrientation::LEFT: + { + nAlignment = word::WdListLevelAlignment::wdListLevelAlignLeft; + break; + } + case text::HoriOrientation::RIGHT: + { + nAlignment = word::WdListLevelAlignment::wdListLevelAlignRight; + break; + } + case text::HoriOrientation::CENTER: + { + nAlignment = word::WdListLevelAlignment::wdListLevelAlignCenter; + break; + } + default: + { + throw uno::RuntimeException(); + } + } + return nAlignment; +} + +void SAL_CALL SwVbaListLevel::setAlignment( ::sal_Int32 _alignment ) throw (uno::RuntimeException) +{ + sal_Int16 nAlignment = text::HoriOrientation::LEFT; + switch( _alignment ) + { + case word::WdListLevelAlignment::wdListLevelAlignLeft: + { + nAlignment = text::HoriOrientation::LEFT; + break; + } + case word::WdListLevelAlignment::wdListLevelAlignRight: + { + nAlignment = text::HoriOrientation::RIGHT; + break; + } + case word::WdListLevelAlignment::wdListLevelAlignCenter: + { + nAlignment = text::HoriOrientation::CENTER; + break; + } + default: + { + throw uno::RuntimeException(); + } + } + pListHelper->setPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Adjust") ), uno::makeAny( nAlignment ) ); +} + +uno::Reference< ::ooo::vba::word::XFont > SAL_CALL SwVbaListLevel::getFont() throw (uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + return uno::Reference< word::XFont >(); +} + +void SAL_CALL SwVbaListLevel::setFont( const uno::Reference< ::ooo::vba::word::XFont >& /*_font*/ ) throw (uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); +} + +::sal_Int32 SAL_CALL SwVbaListLevel::getIndex() throw (uno::RuntimeException) +{ + return mnLevel + 1; +} + +::rtl::OUString SAL_CALL SwVbaListLevel::getLinkedStyle() throw (uno::RuntimeException) +{ + // TODO: + return rtl::OUString(); +} + +void SAL_CALL SwVbaListLevel::setLinkedStyle( const ::rtl::OUString& /*_linkedstyle*/ ) throw (uno::RuntimeException) +{ + // TODO: +} + +::rtl::OUString SAL_CALL SwVbaListLevel::getNumberFormat() throw (uno::RuntimeException) +{ + // TODO:: + return rtl::OUString(); +} + +void SAL_CALL SwVbaListLevel::setNumberFormat( const ::rtl::OUString& /*_numberformat*/ ) throw (uno::RuntimeException) +{ + // TODO:: +} + +float SAL_CALL SwVbaListLevel::getNumberPosition() throw (uno::RuntimeException) +{ + // indentAt + firstlineindent + sal_Int32 nIndentAt = 0; + sal_Int32 nFirstLineIndent = 0; + pListHelper->getPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IndentAt") ) ) >>= nIndentAt; + pListHelper->getPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FirstLineIndent") ) ) >>= nFirstLineIndent; + + sal_Int32 nResult = nIndentAt + nFirstLineIndent; + + return static_cast< float >( Millimeter::getInPoints( nResult ) ); +} + +void SAL_CALL SwVbaListLevel::setNumberPosition( float _numberposition ) throw (uno::RuntimeException) +{ + sal_Int32 nNumberPosition = Millimeter::getInHundredthsOfOneMillimeter( _numberposition ); + + sal_Int32 nIndentAt = 0; + pListHelper->getPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IndentAt") ) ) >>= nIndentAt; + + sal_Int32 nFirstLineIndent = nNumberPosition - nIndentAt; + pListHelper->setPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FirstLineIndent") ), uno::makeAny( nFirstLineIndent ) ); +} + +::sal_Int32 SAL_CALL SwVbaListLevel::getNumberStyle() throw (uno::RuntimeException) +{ + sal_Int16 nNumberingType = 0; + pListHelper->getPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingType") ) ) >>= nNumberingType; + switch( nNumberingType ) + { + case style::NumberingType::CHAR_SPECIAL: + { + nNumberingType = word::WdListNumberStyle::wdListNumberStyleBullet; + break; + } + case style::NumberingType::CHARS_UPPER_LETTER: + { + nNumberingType = word::WdListNumberStyle::wdListNumberStyleUppercaseLetter; + break; + } + case style::NumberingType::CHARS_LOWER_LETTER: + { + nNumberingType = word::WdListNumberStyle::wdListNumberStyleLowercaseLetter; + break; + } + case style::NumberingType::ROMAN_UPPER: + { + nNumberingType = word::WdListNumberStyle::wdListNumberStyleUppercaseRoman; + break; + } + case style::NumberingType::ROMAN_LOWER: + { + nNumberingType = word::WdListNumberStyle::wdListNumberStyleLowercaseRoman; + break; + } + case style::NumberingType::ARABIC: + { + nNumberingType = word::WdListNumberStyle::wdListNumberStyleArabic; + break; + } + case style::NumberingType::NUMBER_NONE: + { + nNumberingType = word::WdListNumberStyle::wdListNumberStyleNone; + break; + } + case style::NumberingType::FULLWIDTH_ARABIC: + { + nNumberingType = word::WdListNumberStyle::wdListNumberStyleArabicFullWidth; + break; + } + case style::NumberingType::CIRCLE_NUMBER: + { + nNumberingType = word::WdListNumberStyle::wdListNumberStyleNumberInCircle; + break; + } + case style::NumberingType::CHARS_ARABIC: + { + nNumberingType = word::WdListNumberStyle::wdListNumberStyleCardinalText; + break; + } + default: + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + } + return nNumberingType; +} + +void SAL_CALL SwVbaListLevel::setNumberStyle( ::sal_Int32 _numberstyle ) throw (uno::RuntimeException) +{ + sal_Int16 nNumberingType = 0; + switch( _numberstyle ) + { + case word::WdListNumberStyle::wdListNumberStyleBullet: + { + nNumberingType = style::NumberingType::CHAR_SPECIAL; + break; + } + case word::WdListNumberStyle::wdListNumberStyleUppercaseLetter: + { + nNumberingType = style::NumberingType::CHARS_UPPER_LETTER_N; + break; + } + case word::WdListNumberStyle::wdListNumberStyleLowercaseLetter: + { + nNumberingType = style::NumberingType::CHARS_LOWER_LETTER_N; + break; + } + case word::WdListNumberStyle::wdListNumberStyleUppercaseRoman: + { + nNumberingType = style::NumberingType::ROMAN_UPPER; + break; + } + case word::WdListNumberStyle::wdListNumberStyleLowercaseRoman: + { + nNumberingType = style::NumberingType::ROMAN_LOWER; + break; + } + case word::WdListNumberStyle::wdListNumberStyleArabic: + { + nNumberingType = style::NumberingType::ARABIC; + break; + } + case word::WdListNumberStyle::wdListNumberStyleNone: + { + nNumberingType = style::NumberingType::NUMBER_NONE; + break; + } + case word::WdListNumberStyle::wdListNumberStyleArabicFullWidth: + { + nNumberingType = style::NumberingType::FULLWIDTH_ARABIC; + break; + } + case word::WdListNumberStyle::wdListNumberStyleNumberInCircle: + { + nNumberingType = style::NumberingType::CIRCLE_NUMBER; + break; + } + case word::WdListNumberStyle::wdListNumberStyleCardinalText: + { + nNumberingType = style::NumberingType::CHARS_ARABIC; + break; + } + case word::WdListNumberStyle::wdListNumberStyleOrdinal: + case word::WdListNumberStyle::wdListNumberStyleOrdinalText: + case word::WdListNumberStyle::wdListNumberStyleKanji: + case word::WdListNumberStyle::wdListNumberStyleKanjiDigit: + case word::WdListNumberStyle::wdListNumberStyleAiueoHalfWidth: + case word::WdListNumberStyle::wdListNumberStyleIrohaHalfWidth: + { + nNumberingType = style::NumberingType::ARABIC; + break; + } + default: + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + } + + pListHelper->setPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingType") ), uno::makeAny( nNumberingType ) ); +} + +::sal_Int32 SAL_CALL SwVbaListLevel::getResetOnHigher() throw (uno::RuntimeException) +{ + //seems not support? + return 0; +} + +void SAL_CALL SwVbaListLevel::setResetOnHigher( ::sal_Int32 /*_resetonhigher*/ ) throw (uno::RuntimeException) +{ + //seems not support? +} + +::sal_Int32 SAL_CALL SwVbaListLevel::getStartAt() throw (uno::RuntimeException) +{ + sal_Int16 nStartWith = 0; + pListHelper->getPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StartWith") ) ) >>= nStartWith; + return nStartWith; +} + +void SAL_CALL SwVbaListLevel::setStartAt( ::sal_Int32 _startat ) throw (uno::RuntimeException) +{ + sal_Int16 nStartWith = (sal_Int16)_startat; + pListHelper->setPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StartWith") ), uno::makeAny( nStartWith ) ); +} + +float SAL_CALL SwVbaListLevel::getTabPosition() throw (uno::RuntimeException) +{ + sal_Int32 nTabPosition = 0; + pListHelper->getPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ListtabStopPosition") ) ) >>= nTabPosition; + + return static_cast< float >( Millimeter::getInPoints( nTabPosition ) ); +} + +void SAL_CALL SwVbaListLevel::setTabPosition( float _tabposition ) throw (uno::RuntimeException) +{ + sal_Int32 nTabPosition = Millimeter::getInHundredthsOfOneMillimeter( _tabposition ); + pListHelper->setPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ListtabStopPosition") ), uno::makeAny( nTabPosition ) ); +} + +float SAL_CALL SwVbaListLevel::getTextPosition() throw (uno::RuntimeException) +{ + // indentAt + sal_Int32 nIndentAt = 0; + pListHelper->getPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IndentAt") ) ) >>= nIndentAt; + + return static_cast< float >( Millimeter::getInPoints( nIndentAt ) ); +} + +void SAL_CALL SwVbaListLevel::setTextPosition( float _textposition ) throw (uno::RuntimeException) +{ + sal_Int32 nIndentAt = 0; + sal_Int32 nFirstLineIndent = 0; + pListHelper->getPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IndentAt") ) ) >>= nIndentAt; + pListHelper->getPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FirstLineIndent") ) ) >>= nFirstLineIndent; + + sal_Int32 nAlignedAt = nIndentAt + nFirstLineIndent; + + nIndentAt = Millimeter::getInHundredthsOfOneMillimeter( _textposition ); + nFirstLineIndent = nAlignedAt - nIndentAt; + pListHelper->setPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IndentAt") ), uno::makeAny( nIndentAt ) ); + pListHelper->setPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FirstLineIndent") ), uno::makeAny( nFirstLineIndent ) ); +} + +::sal_Int32 SAL_CALL SwVbaListLevel::getTrailingCharacter() throw (uno::RuntimeException) +{ + sal_Int16 nLabelFollowedBy= 0; + pListHelper->getPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LabelFollowedBy") ) ) >>= nLabelFollowedBy; + + return nLabelFollowedBy; +} + +void SAL_CALL SwVbaListLevel::setTrailingCharacter( ::sal_Int32 _trailingcharacter ) throw (uno::RuntimeException) +{ + sal_Int16 nLabelFollowedBy = (sal_Int16)_trailingcharacter; + pListHelper->setPropertyValueWithNameAndLevel( mnLevel, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LabelFollowedBy") ), uno::makeAny( nLabelFollowedBy ) ); +} + +rtl::OUString& +SwVbaListLevel::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaListLevel") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaListLevel::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.ListLevel" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbalistlevel.hxx b/sw/source/ui/vba/vbalistlevel.hxx new file mode 100644 index 0000000000..9f9d1b1055 --- /dev/null +++ b/sw/source/ui/vba/vbalistlevel.hxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_LISTLEVEL_HXX +#define SW_VBA_LISTLEVEL_HXX + +#include <ooo/vba/word/XListLevel.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/text/XTextDocument.hpp> +#include "vbalisthelper.hxx" + + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XListLevel > SwVbaListLevel_BASE; + +class SwVbaListLevel : public SwVbaListLevel_BASE +{ +private: + SwVbaListHelperRef pListHelper; + sal_Int32 mnLevel; + +public: + SwVbaListLevel( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, SwVbaListHelperRef pHelper, sal_Int32 nLevel ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaListLevel(); + + // Attributes + virtual ::sal_Int32 SAL_CALL getAlignment() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAlignment( ::sal_Int32 _alignment ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ::ooo::vba::word::XFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFont( const css::uno::Reference< ::ooo::vba::word::XFont >& _font ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getIndex() throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getLinkedStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLinkedStyle( const ::rtl::OUString& _linkedstyle ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getNumberFormat() throw (css::uno::RuntimeException); + virtual void SAL_CALL setNumberFormat( const ::rtl::OUString& _numberformat ) throw (css::uno::RuntimeException); + virtual float SAL_CALL getNumberPosition() throw (css::uno::RuntimeException); + virtual void SAL_CALL setNumberPosition( float _numberposition ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getNumberStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setNumberStyle( ::sal_Int32 _numberstyle ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getResetOnHigher() throw (css::uno::RuntimeException); + virtual void SAL_CALL setResetOnHigher( ::sal_Int32 _resetonhigher ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getStartAt() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStartAt( ::sal_Int32 _startat ) throw (css::uno::RuntimeException); + virtual float SAL_CALL getTabPosition() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTabPosition( float _tabposition ) throw (css::uno::RuntimeException); + virtual float SAL_CALL getTextPosition() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTextPosition( float _textposition ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getTrailingCharacter() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTrailingCharacter( ::sal_Int32 _trailingcharacter ) throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_LISTLEVEL_HXX */ diff --git a/sw/source/ui/vba/vbalistlevels.cxx b/sw/source/ui/vba/vbalistlevels.cxx new file mode 100644 index 0000000000..0d3604a06b --- /dev/null +++ b/sw/source/ui/vba/vbalistlevels.cxx @@ -0,0 +1,118 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbalistlevels.hxx" +#include "vbalistlevel.hxx" +#include <ooo/vba/word/WdListGalleryType.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +class ListLevelsEnumWrapper : public EnumerationHelper_BASE +{ + SwVbaListLevels* pListLevels; + sal_Int32 nIndex; +public: + ListLevelsEnumWrapper( SwVbaListLevels* pLevels ) : pListLevels( pLevels ), nIndex( 1 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex <= pListLevels->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex <= pListLevels->getCount() ) + return pListLevels->Item( uno::makeAny( nIndex++ ), uno::Any() ); + throw container::NoSuchElementException(); + } +}; + +SwVbaListLevels::SwVbaListLevels( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, SwVbaListHelperRef pHelper ) throw (uno::RuntimeException) : SwVbaListLevels_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >() ), pListHelper( pHelper ) +{ +} + +::sal_Int32 SAL_CALL SwVbaListLevels::getCount() throw (uno::RuntimeException) +{ + sal_Int32 nGalleryType = pListHelper->getGalleryType(); + if( nGalleryType == word::WdListGalleryType::wdBulletGallery + || nGalleryType == word::WdListGalleryType::wdNumberGallery ) + return 1; + else if( nGalleryType == word::WdListGalleryType::wdOutlineNumberGallery ) + return 9; + return 0; +} + +uno::Any SAL_CALL SwVbaListLevels::Item( const uno::Any& Index1, const uno::Any& /*not processed in this base class*/ ) throw (uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + if( ( Index1 >>= nIndex ) == sal_False ) + throw uno::RuntimeException(); + if( nIndex <=0 || nIndex > getCount() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Index out of bounds") ), uno::Reference< uno::XInterface >() ); + + return uno::makeAny( uno::Reference< word::XListLevel >( new SwVbaListLevel( this, mxContext, pListHelper, nIndex - 1 ) ) ); +} + +// XEnumerationAccess +uno::Type +SwVbaListLevels::getElementType() throw (uno::RuntimeException) +{ + return word::XListLevel::static_type(0); +} + +uno::Reference< container::XEnumeration > +SwVbaListLevels::createEnumeration() throw (uno::RuntimeException) +{ + return new ListLevelsEnumWrapper( this ); +} + +uno::Any +SwVbaListLevels::createCollectionObject( const css::uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString& +SwVbaListLevels::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaListLevels") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +SwVbaListLevels::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.ListLevels") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbalistlevels.hxx b/sw/source/ui/vba/vbalistlevels.hxx new file mode 100644 index 0000000000..70774bdb6b --- /dev/null +++ b/sw/source/ui/vba/vbalistlevels.hxx @@ -0,0 +1,62 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_LISTLEVELS_HXX +#define SW_VBA_LISTLEVELS_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XListLevels.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include "vbalisthelper.hxx" + + +typedef CollTestImplHelper< ooo::vba::word::XListLevels > SwVbaListLevels_BASE; + +class SwVbaListLevels : public SwVbaListLevels_BASE +{ +private: + SwVbaListHelperRef pListHelper; + +public: + SwVbaListLevels( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, SwVbaListHelperRef pHelper ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaListLevels() {} + + virtual ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& /*not processed in this base class*/ ) 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); + + // SwVbaListLevels_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SW_VBA_LISTLEVELS_HXX */ diff --git a/sw/source/ui/vba/vbalisttemplate.cxx b/sw/source/ui/vba/vbalisttemplate.cxx new file mode 100644 index 0000000000..dc71f4c664 --- /dev/null +++ b/sw/source/ui/vba/vbalisttemplate.cxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbalisttemplate.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include "vbalistlevels.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaListTemplate::SwVbaListTemplate( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextDocument >& xTextDoc, sal_Int32 nGalleryType, sal_Int32 nTemplateType ) throw ( uno::RuntimeException ) : SwVbaListTemplate_BASE( rParent, rContext ) +{ + pListHelper.reset( new SwVbaListHelper( xTextDoc, nGalleryType, nTemplateType ) ); +} + +SwVbaListTemplate::~SwVbaListTemplate() +{ +} + +uno::Any SAL_CALL +SwVbaListTemplate::ListLevels( const uno::Any& index ) throw (uno::RuntimeException) +{ + uno::Reference< XCollection > xCol( new SwVbaListLevels( mxParent, mxContext, pListHelper ) ); + if ( index.hasValue() ) + return xCol->Item( index, uno::Any() ); + return uno::makeAny( xCol ); +} + +void SwVbaListTemplate::applyListTemplate( uno::Reference< beans::XPropertySet >& xProps ) throw (uno::RuntimeException) +{ + uno::Reference< container::XIndexReplace > xNumberingRules = pListHelper->getNumberingRules(); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingRules") ) , uno::makeAny( xNumberingRules ) ); +} + +rtl::OUString& +SwVbaListTemplate::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaListTemplate") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaListTemplate::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.ListTemplate" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbalisttemplate.hxx b/sw/source/ui/vba/vbalisttemplate.hxx new file mode 100644 index 0000000000..408f6b8fa6 --- /dev/null +++ b/sw/source/ui/vba/vbalisttemplate.hxx @@ -0,0 +1,60 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_LISTTEMPLATE_HXX +#define SW_VBA_LISTTEMPLATE_HXX + +#include <ooo/vba/word/XListTemplate.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/text/XTextDocument.hpp> +#include "vbalisthelper.hxx" + + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XListTemplate > SwVbaListTemplate_BASE; + +class SwVbaListTemplate : public SwVbaListTemplate_BASE +{ +private: + SwVbaListHelperRef pListHelper; + +public: + SwVbaListTemplate( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextDocument >& xTextDoc, sal_Int32 nGalleryType, sal_Int32 nTemplateType ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaListTemplate(); + + void applyListTemplate( css::uno::Reference< css::beans::XPropertySet >& xProps ) throw ( css::uno::RuntimeException ); + + // Methods + virtual css::uno::Any SAL_CALL ListLevels( const css::uno::Any& index ) throw ( css::uno::RuntimeException ); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_LISTTEMPLATE_HXX */ diff --git a/sw/source/ui/vba/vbalisttemplates.cxx b/sw/source/ui/vba/vbalisttemplates.cxx new file mode 100644 index 0000000000..6fd3c4811e --- /dev/null +++ b/sw/source/ui/vba/vbalisttemplates.cxx @@ -0,0 +1,112 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbalisttemplates.hxx" +#include "vbalisttemplate.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +class ListTemplatesEnumWrapper : public EnumerationHelper_BASE +{ + SwVbaListTemplates* pListTemplates; + sal_Int32 nIndex; +public: + ListTemplatesEnumWrapper( SwVbaListTemplates* pTemplates ) : pListTemplates( pTemplates ), nIndex( 1 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex <= pListTemplates->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex <= pListTemplates->getCount() ) + return pListTemplates->Item( uno::makeAny( nIndex++ ), uno::Any() ); + throw container::NoSuchElementException(); + } +}; + +SwVbaListTemplates::SwVbaListTemplates( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextDocument >& xTextDoc, sal_Int32 nType ) throw (uno::RuntimeException) : SwVbaListTemplates_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >() ), mxTextDocument( xTextDoc ), mnGalleryType( nType ) +{ +} + +::sal_Int32 SAL_CALL SwVbaListTemplates::getCount() throw (uno::RuntimeException) +{ + // 3 types of list( bullet, numbered and outline ) + return 7; +} + +uno::Any SAL_CALL SwVbaListTemplates::Item( const uno::Any& Index1, const uno::Any& /*not processed in this base class*/ ) throw (uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + if( ( Index1 >>= nIndex ) == sal_False ) + throw uno::RuntimeException(); + if( nIndex <=0 || nIndex > getCount() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Index out of bounds") ), uno::Reference< uno::XInterface >() ); + + return uno::makeAny( uno::Reference< word::XListTemplate >( new SwVbaListTemplate( this, mxContext, mxTextDocument, mnGalleryType, nIndex ) ) ); +} + +// XEnumerationAccess +uno::Type +SwVbaListTemplates::getElementType() throw (uno::RuntimeException) +{ + return word::XListTemplate::static_type(0); +} + +uno::Reference< container::XEnumeration > +SwVbaListTemplates::createEnumeration() throw (uno::RuntimeException) +{ + return new ListTemplatesEnumWrapper( this ); +} + +uno::Any +SwVbaListTemplates::createCollectionObject( const css::uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString& +SwVbaListTemplates::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaListTemplates") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +SwVbaListTemplates::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.ListTemplates") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbalisttemplates.hxx b/sw/source/ui/vba/vbalisttemplates.hxx new file mode 100644 index 0000000000..431f891839 --- /dev/null +++ b/sw/source/ui/vba/vbalisttemplates.hxx @@ -0,0 +1,62 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_LISTTEMPLATES_HXX +#define SW_VBA_LISTTEMPLATES_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XListTemplates.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/text/XTextDocument.hpp> + +typedef CollTestImplHelper< ooo::vba::word::XListTemplates > SwVbaListTemplates_BASE; + +class SwVbaListTemplates : public SwVbaListTemplates_BASE +{ +private: + css::uno::Reference< css::text::XTextDocument > mxTextDocument; + sal_Int32 mnGalleryType; + +public: + SwVbaListTemplates( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::text::XTextDocument >& xTextDoc, sal_Int32 nType ) throw (css::uno::RuntimeException); + virtual ~SwVbaListTemplates() {} + + virtual ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& /*not processed in this base class*/ ) 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); + + // SwVbaListTemplates_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SW_VBA_LISTTEMPLATES_HXX */ diff --git a/sw/source/ui/vba/vbaparagraph.cxx b/sw/source/ui/vba/vbaparagraph.cxx index 075ea6f107..4e088a6bdf 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 4c2cc448e5..ea994f9567 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 dbcadac1e3..1285ca7fd2 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 d6f719dd0b..9c70f6f8cf 100644 --- a/sw/source/ui/vba/vbarange.cxx +++ b/sw/source/ui/vba/vbarange.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -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; @@ -67,9 +76,11 @@ void SwVbaRange::initialize( const uno::Reference< text::XTextRange >& rStart, c if( !mxText.is() ) { mxText = mxTextDocument->getText(); - } - + } + 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,14 +437,58 @@ void SAL_CALL SwVbaRange::setEnd( ::sal_Int32 _end ) throw (uno::RuntimeExceptio mxTextCursor->gotoRange( xEnd, sal_True ); } -rtl::OUString& +::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() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaRange") ); return sImplName; } -uno::Sequence< rtl::OUString > +uno::Sequence< rtl::OUString > SwVbaRange::getServiceNames() { static uno::Sequence< rtl::OUString > aServiceNames; diff --git a/sw/source/ui/vba/vbarange.hxx b/sw/source/ui/vba/vbarange.hxx index ca3a4ea21b..a23bf2d9a1 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 337fd9d6ae..c5be3cb8ae 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,28 @@ 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 530c7e1fa1..bf274802d3 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 2bd7dcfa58..097699b06a 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 c0f66af45f..62e114342f 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/vbarevision.cxx b/sw/source/ui/vba/vbarevision.cxx new file mode 100644 index 0000000000..7c50d62242 --- /dev/null +++ b/sw/source/ui/vba/vbarevision.cxx @@ -0,0 +1,104 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbarevision.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include <com/sun/star/document/XRedlinesSupplier.hpp> +#include "wordvbahelper.hxx" +#include <docsh.hxx> +#include <doc.hxx> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaRevision::SwVbaRevision( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< beans::XPropertySet >& xRedlineProps ) throw ( uno::RuntimeException ) : SwVbaRevision_BASE( rParent, rContext ), mxModel( xModel ), mxRedlineProps( xRedlineProps ) +{ +} + +SwVbaRevision::~SwVbaRevision() +{ +} + +sal_Int32 SwVbaRevision::GetPosition() throw (css::uno::RuntimeException) +{ + sal_Int32 nPos = -1; + uno::Reference< document::XRedlinesSupplier > xRedlinesSupp( mxModel, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW ); + sal_Int32 nCount = xRedlines->getCount(); + for( sal_Int32 i = 0; i < nCount; i++ ) + { + uno::Reference< beans::XPropertySet > xProps( xRedlines->getByIndex( i ), uno::UNO_QUERY_THROW ); + if( xProps == mxRedlineProps ) + { + nPos = i; + OSL_TRACE(" SwVbaRevision::SwVbaRevision, the redline position is %d, ", nPos ); + break; + } + } + if( nPos == -1 ) + throw uno::RuntimeException(); + + return nPos; +} + +void SAL_CALL +SwVbaRevision::Accept() throw ( css::uno::RuntimeException ) +{ + SwDoc* pDoc = word::getDocShell( mxModel )->GetDoc(); + if( pDoc ) + pDoc->AcceptRedline( GetPosition(), sal_True ); +} + +void SAL_CALL +SwVbaRevision::Reject( ) throw ( css::uno::RuntimeException ) +{ + SwDoc* pDoc = word::getDocShell( mxModel )->GetDoc(); + if( pDoc ) + pDoc->RejectRedline( GetPosition(), sal_True ); +} + +rtl::OUString& +SwVbaRevision::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaRevision") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaRevision::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Revision" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbarevision.hxx b/sw/source/ui/vba/vbarevision.hxx new file mode 100644 index 0000000000..7f8adbe1b4 --- /dev/null +++ b/sw/source/ui/vba/vbarevision.hxx @@ -0,0 +1,60 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_REVISION_HXX +#define SW_VBA_REVISION_HXX + +#include <ooo/vba/word/XRevision.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <cppuhelper/implbase1.hxx> + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XRevision > SwVbaRevision_BASE; + +class SwVbaRevision : public SwVbaRevision_BASE +{ +private: + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::beans::XPropertySet > mxRedlineProps; + +private: + sal_Int32 GetPosition() throw (css::uno::RuntimeException); + +public: + SwVbaRevision( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::beans::XPropertySet >& xRedlineProps ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaRevision(); + + // Methods + virtual void SAL_CALL Accept( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Reject( ) throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_REVISION_HXX */ diff --git a/sw/source/ui/vba/vbarevisions.cxx b/sw/source/ui/vba/vbarevisions.cxx new file mode 100644 index 0000000000..be7120063d --- /dev/null +++ b/sw/source/ui/vba/vbarevisions.cxx @@ -0,0 +1,188 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbarevisions.hxx" +#include "vbarevision.hxx" +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/document/XRedlinesSupplier.hpp> +#include <com/sun/star/text/XTextRangeCompare.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +typedef ::cppu::WeakImplHelper1< container::XEnumeration > RevisionEnumeration_BASE; +typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > RevisionCollectionHelper_BASE; +typedef std::vector< uno::Reference< beans::XPropertySet > > RevisionMap; + +class RedlinesEnumeration : public RevisionEnumeration_BASE +{ + RevisionMap mRevisionMap; + RevisionMap::iterator mIt; +public: + RedlinesEnumeration( const RevisionMap& sMap ) : mRevisionMap( sMap ), mIt( mRevisionMap.begin() ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( mIt != mRevisionMap.end() ); + } + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasMoreElements() ) + throw container::NoSuchElementException(); + uno::Reference< beans::XPropertySet > xRevision( *mIt++ ); + return uno::makeAny( xRevision ) ; + } +}; + +class RevisionCollectionHelper : public RevisionCollectionHelper_BASE +{ + RevisionMap mRevisionMap; +public: +RevisionCollectionHelper( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ) throw (uno::RuntimeException); + + // XElementAccess + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) { return beans::XPropertySet::static_type(0); } + virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) { return ( mRevisionMap.size() > 0 ); } + // XIndexAccess + virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) { return mRevisionMap.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(); + + return uno::makeAny( mRevisionMap[ Index ] ); + + } + // XEnumerationAccess + virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) + { + return new RedlinesEnumeration( mRevisionMap ); + } +}; + +RevisionCollectionHelper::RevisionCollectionHelper( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ) throw (uno::RuntimeException) + { + uno::Reference< text::XTextRangeCompare > xTRC( xTextRange->getText(), uno::UNO_QUERY_THROW ); + uno::Reference< document::XRedlinesSupplier > xRedlinesSupp( xModel, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW ); + sal_Int32 nCount = xRedlines->getCount(); + for( sal_Int32 index = 0; index < nCount; index++ ) + { + uno::Reference< text::XTextRange > xRedlineRange( xRedlines->getByIndex( index ), uno::UNO_QUERY_THROW ); + if( xTRC->compareRegionStarts( xTextRange, xRedlineRange ) >= 0 && xTRC->compareRegionEnds( xTextRange, xRedlineRange ) <= 0 ) + { + uno::Reference< beans::XPropertySet > xRedlineProps( xRedlineRange, uno::UNO_QUERY_THROW ); + mRevisionMap.push_back( xRedlineProps ); + } + } + } +class RevisionsEnumeration : public EnumerationHelperImpl +{ + uno::Reference< frame::XModel > m_xModel; +public: + RevisionsEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), m_xModel( xModel ) {} + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + uno::Reference< beans::XPropertySet > xRevision( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< word::XRevision > ( new SwVbaRevision( m_xParent, m_xContext, m_xModel, xRevision ) ) ); + } + +}; + +SwVbaRevisions::SwVbaRevisions( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ): SwVbaRevisions_BASE( xParent, xContext, new RevisionCollectionHelper( xModel, xTextRange ) ), mxModel( xModel ) +{ +} + +SwVbaRevisions::SwVbaRevisions( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< container::XIndexAccess >& xIndexAccess ): SwVbaRevisions_BASE( xParent, xContext, xIndexAccess ), mxModel( xModel ) +{ +} + +// XEnumerationAccess +uno::Type +SwVbaRevisions::getElementType() throw (uno::RuntimeException) +{ + return word::XRevision::static_type(0); +} +uno::Reference< container::XEnumeration > +SwVbaRevisions::createEnumeration() throw (uno::RuntimeException) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); + return new RevisionsEnumeration( this, mxContext, xEnumAccess->createEnumeration(), mxModel ); +} + +uno::Any +SwVbaRevisions::createCollectionObject( const css::uno::Any& aSource ) +{ + uno::Reference< beans::XPropertySet > xRevision( aSource, uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< word::XRevision > ( new SwVbaRevision( this, mxContext, mxModel, xRevision ) ) ); +} + +void SAL_CALL SwVbaRevisions::AcceptAll( ) throw (css::uno::RuntimeException) +{ + // First we need to put all the redline into a vector, because if the redline is accepted, + // it will auto delete in the document. + std::vector< uno::Reference< word::XRevision > > aRevisions; + uno::Reference< container::XEnumeration > xEnumeration = createEnumeration(); + while( xEnumeration->hasMoreElements() ) + { + uno::Reference< word::XRevision > xRevision( xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); + aRevisions.push_back( xRevision ); + } + + std::vector< uno::Reference< word::XRevision > >::iterator it = aRevisions.begin(); + for( ; it != aRevisions.end(); it++ ) + { + uno::Reference< word::XRevision > xRevision( *it ); + xRevision->Accept(); + } +} + +void SAL_CALL SwVbaRevisions::RejectAll( ) throw (css::uno::RuntimeException) +{ + throw uno::RuntimeException(); +} + +rtl::OUString& +SwVbaRevisions::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaRevisions") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +SwVbaRevisions::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Revisions") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbarevisions.hxx b/sw/source/ui/vba/vbarevisions.hxx new file mode 100644 index 0000000000..b299e713ea --- /dev/null +++ b/sw/source/ui/vba/vbarevisions.hxx @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_PANES_HXX +#define SW_VBA_PANES_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XRevisions.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/text/XTextRange.hpp> + + +typedef CollTestImplHelper< ooo::vba::word::XRevisions > SwVbaRevisions_BASE; + +class SwVbaRevisions : public SwVbaRevisions_BASE +{ +private: + css::uno::Reference< css::frame::XModel > mxModel; + +public: + SwVbaRevisions( 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 ); + + SwVbaRevisions( 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::container::XIndexAccess >& xIndexAccess ); + virtual ~SwVbaRevisions() {} + + // Methods + virtual void SAL_CALL AcceptAll( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL RejectAll( ) 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); + + // SwVbaRevisions_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SW_VBA_PANES_HXX */ diff --git a/sw/source/ui/vba/vbarow.cxx b/sw/source/ui/vba/vbarow.cxx new file mode 100644 index 0000000000..8846723ca9 --- /dev/null +++ b/sw/source/ui/vba/vbarow.cxx @@ -0,0 +1,135 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbarow.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <ooo/vba/word/WdRowHeightRule.hpp> +#include <ooo/vba/word/WdConstants.hpp> +#include <rtl/ustrbuf.hxx> +#include "wordvbahelper.hxx" +#include "vbatablehelper.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaRow::SwVbaRow( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext,const uno::Reference< text::XTextTable >& xTextTable, sal_Int32 nIndex ) throw ( uno::RuntimeException ) : + SwVbaRow_BASE( rParent, rContext ), mxTextTable( xTextTable ), mnIndex( nIndex ) +{ + mxTableRows = mxTextTable->getRows(); + mxRowProps.set( mxTableRows->getByIndex( mnIndex ), uno::UNO_QUERY_THROW ); +} + +SwVbaRow::~SwVbaRow() +{ +} + +uno::Any SAL_CALL SwVbaRow::getHeight() throw (css::uno::RuntimeException) +{ + if( getHeightRule() == word::WdRowHeightRule::wdRowHeightAuto ) + return uno::makeAny( sal_Int32( word::WdConstants::wdUndefined ) ); + + sal_Int32 nHeight = 0; + mxRowProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ) ) >>= nHeight; + return uno::makeAny( (float)Millimeter::getInPoints( nHeight ) ); +} + +void SAL_CALL SwVbaRow::setHeight( const uno::Any& _height ) throw (css::uno::RuntimeException) +{ + float height = 0; + _height >>= height; + + sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( height ); + mxRowProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ), uno::makeAny( nHeight ) ); +} + +::sal_Int32 SAL_CALL SwVbaRow::getHeightRule() throw (css::uno::RuntimeException) +{ + sal_Bool isAutoHeight = sal_False; + mxRowProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsAutoHeight") ) ) >>= isAutoHeight; + return isAutoHeight ? word::WdRowHeightRule::wdRowHeightAuto : word::WdRowHeightRule::wdRowHeightExactly; +} + +void SAL_CALL SwVbaRow::setHeightRule( ::sal_Int32 _heightrule ) throw (css::uno::RuntimeException) +{ + sal_Bool isAutoHeight = ( _heightrule == word::WdRowHeightRule::wdRowHeightAuto ); + mxRowProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsAutoHeight") ), uno::makeAny( isAutoHeight ) ); +} + +void SAL_CALL +SwVbaRow::Select( ) throw ( uno::RuntimeException ) +{ + SelectRow( getCurrentWordDoc(mxContext), mxTextTable, mnIndex, mnIndex ); +} + +void SwVbaRow::SelectRow( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextTable >& xTextTable, sal_Int32 nStartRow, sal_Int32 nEndRow ) throw ( uno::RuntimeException ) +{ + rtl::OUStringBuffer aRangeName; + aRangeName.appendAscii("A").append(sal_Int32( nStartRow + 1 ) ); + SwVbaTableHelper aTableHelper( xTextTable ); + sal_Int32 nColCount = aTableHelper.getTabColumnsCount( nEndRow ); + // FIXME: the column count > 26 + //sal_Char cCol = 'A' + nColCount - 1; + rtl::OUString sCol = aTableHelper.getColumnStr( nColCount - 1); + aRangeName.appendAscii(":").append( sCol ).append( sal_Int32( nEndRow + 1 ) ); + + uno::Reference< table::XCellRange > xCellRange( xTextTable, uno::UNO_QUERY_THROW ); + rtl::OUString sSelRange = aRangeName.makeStringAndClear(); + uno::Reference< table::XCellRange > xSelRange = xCellRange->getCellRangeByName( sSelRange ); + + uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + xSelection->select( uno::makeAny( xSelRange ) ); +} + +void SAL_CALL SwVbaRow::SetHeight( float height, sal_Int32 heightrule ) throw (css::uno::RuntimeException) +{ + setHeightRule( heightrule ); + setHeight( uno::makeAny( height ) ); +} + +rtl::OUString& +SwVbaRow::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaRow") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaRow::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Row" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbarow.hxx b/sw/source/ui/vba/vbarow.hxx new file mode 100644 index 0000000000..218ea996a6 --- /dev/null +++ b/sw/source/ui/vba/vbarow.hxx @@ -0,0 +1,69 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_ROW_HXX +#define SW_VBA_ROW_HXX + +#include <ooo/vba/word/XRow.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/text/XTextTable.hpp> + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XRow > SwVbaRow_BASE; + +class SwVbaRow : public SwVbaRow_BASE +{ +private: + css::uno::Reference< css::text::XTextTable > mxTextTable; + css::uno::Reference< css::table::XTableRows > mxTableRows; + css::uno::Reference< css::beans::XPropertySet > mxRowProps; + sal_Int32 mnIndex; + +public: + SwVbaRow( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextTable >& xTextTable, sal_Int32 nIndex ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaRow(); + + // Attributes + virtual css::uno::Any SAL_CALL getHeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeight( const css::uno::Any& _height ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getHeightRule() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeightRule( ::sal_Int32 _heightrule ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL Select( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL SetHeight( float height, sal_Int32 heightrule ) throw (css::uno::RuntimeException); + + static void SelectRow( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XTextTable >& xTextTable, sal_Int32 nStartRow, sal_Int32 nEndRow ) throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_ROW_HXX */ diff --git a/sw/source/ui/vba/vbarows.cxx b/sw/source/ui/vba/vbarows.cxx new file mode 100644 index 0000000000..c5a04fb29a --- /dev/null +++ b/sw/source/ui/vba/vbarows.cxx @@ -0,0 +1,368 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbarows.hxx" +#include "vbarow.hxx" +#include <com/sun/star/text/HoriOrientation.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <ooo/vba/word/WdRowAlignment.hpp> +#include <ooo/vba/word/WdConstants.hpp> +#include <ooo/vba/word/WdRulerStyle.hpp> +#include "wordvbahelper.hxx" +#include "vbacolumns.hxx" +#include "vbatablehelper.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +class RowsEnumWrapper : public EnumerationHelper_BASE +{ + uno::WeakReference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< text::XTextTable > mxTextTable; + uno::Reference< container::XIndexAccess > mxIndexAccess; + sal_Int32 nIndex; + +public: + RowsEnumWrapper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< text::XTextTable >& xTextTable ) : mxParent( xParent ), mxContext( xContext ), mxTextTable( xTextTable ), nIndex( 0 ) + { + mxIndexAccess.set( mxTextTable->getRows(), uno::UNO_QUERY ); + } + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < mxIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if( nIndex < mxIndexAccess->getCount() ) + { + return uno::makeAny( uno::Reference< word::XRow > ( new SwVbaRow( mxParent, mxContext, mxTextTable, nIndex++ ) ) ); + } + throw container::NoSuchElementException(); + } +}; + +SwVbaRows::SwVbaRows( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextTable >& xTextTable, const uno::Reference< table::XTableRows >& xTableRows ) throw (uno::RuntimeException) : SwVbaRows_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( xTableRows, uno::UNO_QUERY_THROW ) ), mxTextTable( xTextTable ), mxTableRows( xTableRows ) +{ + mnStartRowIndex = 0; + mnEndRowIndex = m_xIndexAccess->getCount() - 1; +} + +SwVbaRows::SwVbaRows( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextTable >& xTextTable, const uno::Reference< table::XTableRows >& xTableRows, sal_Int32 nStarIndex, sal_Int32 nEndIndex ) throw (uno::RuntimeException) : SwVbaRows_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( xTableRows, uno::UNO_QUERY_THROW ) ), mxTextTable( xTextTable ), mxTableRows( xTableRows ), mnStartRowIndex( nStarIndex ), mnEndRowIndex( nEndIndex ) +{ + if( mnEndRowIndex < mnStartRowIndex ) + throw uno::RuntimeException(); +} + +/** + * get the alignment of the rows: SO format com.sun.star.text.HoriOrientation + * is mapped to WdRowAlignment in Word + * @return the alignment + */ +::sal_Int32 SAL_CALL SwVbaRows::getAlignment() throw (uno::RuntimeException) +{ + sal_Int16 nAlignment = text::HoriOrientation::LEFT; + uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW ); + xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HoriOrient") ) ) >>= nAlignment; + sal_Int32 nRet = 0; + switch( nAlignment ) + { + case text::HoriOrientation::CENTER: + { + nRet = word::WdRowAlignment::wdAlignRowCenter; + break; + } + case text::HoriOrientation::RIGHT: + { + nRet = word::WdRowAlignment::wdAlignRowRight; + break; + } + default: + { + nRet = word::WdRowAlignment::wdAlignRowLeft; + } + } + return nRet; +} + +void SAL_CALL SwVbaRows::setAlignment( ::sal_Int32 _alignment ) throw (uno::RuntimeException) +{ + sal_Int16 nAlignment = text::HoriOrientation::LEFT; + switch( _alignment ) + { + case word::WdRowAlignment::wdAlignRowCenter: + { + nAlignment = text::HoriOrientation::CENTER; + break; + } + case word::WdRowAlignment::wdAlignRowRight: + { + nAlignment = text::HoriOrientation::RIGHT; + break; + } + default: + { + nAlignment = text::HoriOrientation::LEFT; + } + } + uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW ); + xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HoriOrient") ), uno::makeAny( nAlignment ) ); +} + +uno::Any SAL_CALL SwVbaRows::getAllowBreakAcrossPages() throw (uno::RuntimeException) +{ + sal_Bool bAllowBreak = sal_False; + uno::Reference< container::XIndexAccess > xRowsAccess( mxTableRows, uno::UNO_QUERY_THROW ); + for( sal_Int32 index = mnStartRowIndex; index <= mnEndRowIndex; ++index ) + { + uno::Reference< beans::XPropertySet > xRowProps( xRowsAccess->getByIndex( index ), uno::UNO_QUERY_THROW ); + sal_Bool bSplit = sal_False; + xRowProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsSplitAllowed") ) ) >>= bSplit; + if( index == 0 ) + { + bAllowBreak = bSplit; + } + if( bSplit != bAllowBreak ) + { + sal_Int32 nRet = word::WdConstants::wdUndefined; + return uno::makeAny( nRet ); + } + } + return uno::makeAny( bAllowBreak ); +} + +void SAL_CALL SwVbaRows::setAllowBreakAcrossPages( const uno::Any& _allowbreakacrosspages ) throw (uno::RuntimeException) +{ + sal_Bool bAllowBreak = sal_False; + _allowbreakacrosspages >>= bAllowBreak; + uno::Reference< container::XIndexAccess > xRowsAccess( mxTableRows, uno::UNO_QUERY_THROW ); + for( sal_Int32 index = mnStartRowIndex; index <= mnEndRowIndex; ++index ) + { + uno::Reference< beans::XPropertySet > xRowProps( xRowsAccess->getByIndex( index ), uno::UNO_QUERY_THROW ); + xRowProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsSplitAllowed") ), uno::makeAny( bAllowBreak ) ); + } +} + +float SAL_CALL SwVbaRows::getSpaceBetweenColumns() throw (uno::RuntimeException) +{ + // just get the first spacing of the first cell + uno::Reference< table::XCellRange > xCellRange( mxTextTable, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xCellProps( xCellRange->getCellByPosition( 0, mnStartRowIndex ), uno::UNO_QUERY_THROW ); + sal_Int32 nLeftBorderDistance = 0; + sal_Int32 nRightBorderDistance = 0; + xCellProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftBorderDistance") ) ) >>= nLeftBorderDistance; + xCellProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightBorderDistance") ) ) >>= nRightBorderDistance; + return static_cast< float >( Millimeter::getInPoints( nLeftBorderDistance + nRightBorderDistance ) ); +} + +void SAL_CALL SwVbaRows::setSpaceBetweenColumns( float _spacebetweencolumns ) throw (uno::RuntimeException) +{ + sal_Int32 nSpace = Millimeter::getInHundredthsOfOneMillimeter( _spacebetweencolumns ) / 2; + uno::Reference< container::XIndexAccess > xColumnAccess( mxTextTable->getColumns(), uno::UNO_QUERY_THROW ); + uno::Reference< table::XCellRange > xCellRange( mxTextTable, uno::UNO_QUERY_THROW ); + SwVbaTableHelper aTableHelper( mxTextTable ); + for( sal_Int32 row = mnStartRowIndex; row <= mnEndRowIndex; ++row ) + { + sal_Int32 nColumns = aTableHelper.getTabColumnsCount( row ); + for( sal_Int32 column = 0; column < nColumns; ++column ) + { + uno::Reference< beans::XPropertySet > xCellProps( xCellRange->getCellByPosition( column, row ), uno::UNO_QUERY_THROW ); + xCellProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftBorderDistance") ), uno::makeAny( nSpace ) ); + xCellProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightBorderDistance") ), uno::makeAny( nSpace ) ); + } + } +} + +void SAL_CALL SwVbaRows::Delete( ) throw (uno::RuntimeException) +{ + mxTableRows->removeByIndex( mnStartRowIndex, getCount() ); +} + +void SAL_CALL SwVbaRows::SetLeftIndent( float LeftIndent, ::sal_Int32 RulerStyle ) throw (uno::RuntimeException) +{ + uno::Reference< word::XColumns > xColumns( new SwVbaColumns( getParent(), mxContext, mxTextTable, mxTextTable->getColumns() ) ); + sal_Int32 nIndent = (sal_Int32)( LeftIndent ); + switch( RulerStyle ) + { + case word::WdRulerStyle::wdAdjustFirstColumn: + { + setIndentWithAdjustFirstColumn( xColumns, nIndent ); + break; + } + case word::WdRulerStyle::wdAdjustNone: + { + setIndentWithAdjustNone( nIndent ); + break; + } + case word::WdRulerStyle::wdAdjustProportional: + { + setIndentWithAdjustProportional( xColumns, nIndent ); + break; + } + case word::WdRulerStyle::wdAdjustSameWidth: + { + setIndentWithAdjustSameWidth( xColumns, nIndent ); + break; + } + default: + { + DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString()); + } + } +} + +void SwVbaRows::setIndentWithAdjustNone( sal_Int32 indent ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW ); + sal_Int32 nMargin = 0; + xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ) ) >>= nMargin; + nMargin += indent; + xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ), uno::makeAny( nMargin ) ); +} + + void SwVbaRows::setIndentWithAdjustFirstColumn( const uno::Reference< word::XColumns >& xColumns, sal_Int32 indent ) throw (uno::RuntimeException) + { + sal_Int32 nIndex = 1; + uno::Reference< XCollection > xCol( xColumns, uno::UNO_QUERY_THROW ); + uno::Reference< word::XColumn > xColumn( xCol->Item( uno::makeAny( nIndex ), uno::Any() ), uno::UNO_QUERY_THROW ); + sal_Int32 nWidth = xColumn->getWidth(); + nWidth -= indent; + xColumn->setWidth( nWidth ); + setIndentWithAdjustNone( indent ); + } + + void SwVbaRows::setIndentWithAdjustProportional( const uno::Reference< word::XColumns >& xColumns, sal_Int32 indent ) throw (uno::RuntimeException) + { + // calculate the new width and get the proportion between old and new + uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW ); + sal_Int32 nWidth = 0; + xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= nWidth; + sal_Int32 nNewWidth = nWidth - indent; + double propFactor = (double)nNewWidth/(double)nWidth; + + // get all columns, calculate and set the new width of the columns + uno::Reference< XCollection > xCol( xColumns, uno::UNO_QUERY_THROW ); + sal_Int32 nColCount = xCol->getCount(); + for( sal_Int32 i = 0; i < nColCount; i++ ) + { + uno::Reference< word::XColumn > xColumn( xCol->Item( uno::makeAny( i ), uno::Any() ), uno::UNO_QUERY_THROW ); + sal_Int32 nColWidth = xColumn->getWidth(); + sal_Int32 nNewColWidth = ( sal_Int32 )( propFactor * nColWidth ); + xColumn->setWidth( nNewColWidth ); + } + + // set the width and position of the table + setIndentWithAdjustNone( indent ); + xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ), uno::makeAny( nNewWidth ) ); + } + + void SwVbaRows::setIndentWithAdjustSameWidth( const uno::Reference< word::XColumns >& xColumns, sal_Int32 indent ) throw (uno::RuntimeException) + { + // calculate the new width and get the width of all columns + uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW ); + sal_Int32 nWidth = 0; + xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= nWidth; + sal_Int32 nNewWidth = nWidth - indent; + + // get all columns, calculate and set the new width of the columns + uno::Reference< XCollection > xCol( xColumns, uno::UNO_QUERY_THROW ); + sal_Int32 nColCount = xCol->getCount(); + sal_Int32 nNewColWidth = (sal_Int32)( double( nNewWidth )/nColCount ); + for( sal_Int32 i = 0; i < nColCount; i++ ) + { + uno::Reference< word::XColumn > xColumn( xCol->Item( uno::makeAny( i ), uno::Any() ), uno::UNO_QUERY_THROW ); + xColumn->setWidth( nNewColWidth ); + } + + // set the width and position of the table + setIndentWithAdjustNone( indent ); + xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ), uno::makeAny( nNewWidth ) ); + } + +void SAL_CALL SwVbaRows::Select( ) throw (uno::RuntimeException) +{ + SwVbaRow::SelectRow( getCurrentWordDoc(mxContext), mxTextTable, mnStartRowIndex, mnEndRowIndex ); +} + +::sal_Int32 SAL_CALL SwVbaRows::getCount() throw (uno::RuntimeException) +{ + return ( mnEndRowIndex - mnStartRowIndex + 1 ); +} + +uno::Any SAL_CALL SwVbaRows::Item( const uno::Any& Index1, const uno::Any& /*not processed in this base class*/ ) throw (uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + if( ( Index1 >>= nIndex ) == sal_True ) + { + if( nIndex <= 0 || nIndex > getCount() ) + { + throw lang::IndexOutOfBoundsException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Index out of bounds") ), uno::Reference< uno::XInterface >() ); + } + return uno::makeAny( uno::Reference< word::XRow >( new SwVbaRow( this, mxContext, mxTextTable, nIndex - 1 ) ) ); + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Index out of bounds") ), uno::Reference< uno::XInterface >() ); +} + +// XEnumerationAccess +uno::Type +SwVbaRows::getElementType() throw (uno::RuntimeException) +{ + return word::XRow::static_type(0); +} +uno::Reference< container::XEnumeration > +SwVbaRows::createEnumeration() throw (uno::RuntimeException) +{ + return new RowsEnumWrapper( this, mxContext, mxTextTable ); +} + +uno::Any +SwVbaRows::createCollectionObject( const uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString& +SwVbaRows::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaRows") ); + return sImplName; +} + +uno::Sequence<rtl::OUString> +SwVbaRows::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Rows") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbarows.hxx b/sw/source/ui/vba/vbarows.hxx new file mode 100644 index 0000000000..0c2380d9fe --- /dev/null +++ b/sw/source/ui/vba/vbarows.hxx @@ -0,0 +1,87 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_ROWS_HXX +#define SW_VBA_ROWS_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XRows.hpp> +#include <ooo/vba/word/XColumns.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/text/XTextTable.hpp> + +typedef CollTestImplHelper< ooo::vba::word::XRows > SwVbaRows_BASE; + +class SwVbaRows : public SwVbaRows_BASE +{ +private: + css::uno::Reference< css::text::XTextTable > mxTextTable; + css::uno::Reference< css::table::XTableRows > mxTableRows; + sal_Int32 mnStartRowIndex; + sal_Int32 mnEndRowIndex; + +private: + void setIndentWithAdjustNone( sal_Int32 indent ) throw (css::uno::RuntimeException); + void setIndentWithAdjustFirstColumn( const css::uno::Reference< ooo::vba::word::XColumns >& xColumns, sal_Int32 indent ) throw (css::uno::RuntimeException); + void setIndentWithAdjustProportional( const css::uno::Reference< ooo::vba::word::XColumns >& xColumns, sal_Int32 indent ) throw (css::uno::RuntimeException); + void setIndentWithAdjustSameWidth( const css::uno::Reference< ooo::vba::word::XColumns >& xColumns, sal_Int32 indent ) throw (css::uno::RuntimeException); + +public: + SwVbaRows( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::text::XTextTable >& xTextTable, const css::uno::Reference< css::table::XTableRows >& xTableRows ) throw ( css::uno::RuntimeException ); + SwVbaRows( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::text::XTextTable >& xTextTable, const css::uno::Reference< css::table::XTableRows >& xTableRows, sal_Int32 nStarIndex, sal_Int32 nEndIndex ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaRows() {} + + // Attributes + virtual ::sal_Int32 SAL_CALL getAlignment() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAlignment( ::sal_Int32 _alignment ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getAllowBreakAcrossPages() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAllowBreakAcrossPages( const css::uno::Any& _allowbreakacrosspages ) throw (css::uno::RuntimeException); + virtual float SAL_CALL getSpaceBetweenColumns() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSpaceBetweenColumns( float _spacebetweencolumns ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL Delete( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL SetLeftIndent( float LeftIndent, ::sal_Int32 RulerStyle ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Select( ) throw (css::uno::RuntimeException); + + //XCollection + virtual ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& /*not processed in this base class*/ ) 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); + + // SwVbaRows_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SW_VBA_ROWS_HXX */ diff --git a/sw/source/ui/vba/vbasection.cxx b/sw/source/ui/vba/vbasection.cxx index 4df6f0b5b3..fd747b3f11 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 9dd4058699..dc1984f319 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 6a4ae0e45e..6e6ee9baeb 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 9cb35cf74e..ef533e4f8a 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 17d4e2f5a3..f393519c89 100644 --- a/sw/source/ui/vba/vbaselection.cxx +++ b/sw/source/ui/vba/vbaselection.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -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; @@ -73,7 +88,7 @@ uno::Reference< text::XTextRange > SwVbaSelection::GetSelectedRange() throw ( un { uno::Reference< text::XTextRange > xTextRange; uno::Reference< lang::XServiceInfo > xServiceInfo( mxModel->getCurrentSelection(), uno::UNO_QUERY_THROW ); - if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextRanges") ) ) ) + if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextRanges") ) ) ) { uno::Reference< container::XIndexAccess > xTextRanges( xServiceInfo, uno::UNO_QUERY_THROW ); if( xTextRanges->getCount() > 0 ) @@ -89,7 +104,7 @@ uno::Reference< text::XTextRange > SwVbaSelection::GetSelectedRange() throw ( un return xTextRange; } -uno::Reference< word::XRange > SAL_CALL +uno::Reference< word::XRange > SAL_CALL SwVbaSelection::getRange() throw ( uno::RuntimeException ) { uno::Reference< text::XTextRange > xTextRange = GetSelectedRange(); @@ -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; @@ -208,25 +374,25 @@ void SwVbaSelection::NextCell( sal_Int32 nCount, E_DIRECTION eDirection ) throw rtl::OUString aCellName; xCellProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CellName") ) ) >>= aCellName; uno::Reference< text::XTextTableCursor > xTextTableCursor = xTextTable->createCursorByCellName( aCellName ); - // move the table cursor + // 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,138 +411,86 @@ 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; - + if( nCount < 0 ) { MoveRight( _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_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 SwVbaSelection::TypeParagraph() throw ( uno::RuntimeException ) { - // #FIXME: if the selection is an entire paragraph, it's replaced + // #FIXME: if the selection is an entire paragraph, it's replaced // by the new paragraph sal_Bool isCollapsed = mxTextViewCursor->isCollapsed(); InsertParagraph(); @@ -415,23 +529,24 @@ SwVbaSelection::setParagraphFormat( const uno::Reference< word::XParagraphFormat return getRange()->setParagraphFormat( rParagraphFormat ); } -uno::Reference< word::XFind > SAL_CALL +uno::Reference< word::XFind > SAL_CALL SwVbaSelection::getFind() throw ( uno::RuntimeException ) { uno::Reference< text::XTextRange > xTextRange = GetSelectedRange(); 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 >() ); } @@ -565,12 +796,7 @@ SwVbaSelection::Tables( 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 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(); + throw uno::RuntimeException(); sal_Int32 nIndex = 0; aIndex >>= nIndex; @@ -578,7 +804,25 @@ SwVbaSelection::Tables( const uno::Any& aIndex ) throw (uno::RuntimeException) uno::Any aRet; if ( nIndex != 1 ) - throw uno::RuntimeException(); + 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 ) { @@ -588,12 +832,12 @@ SwVbaSelection::Tables( const uno::Any& aIndex ) throw (uno::RuntimeException) { uno::Reference< text::XTextTable > xTbl = SwXTextTables::GetObject(*pFmt); uno::Reference< css::text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW ); - uno::Reference< word::XTable > xVBATbl = new SwVbaTable( mxParent, mxContext, xTextDoc, xTbl ); + uno::Reference< word::XTable > xVBATbl = new SwVbaTable( mxParent, mxContext, xTextDoc, xTbl ); aRet <<= xVBATbl; } } return aRet; - + } uno::Any SAL_CALL @@ -608,17 +852,16 @@ 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,14 +905,289 @@ void SAL_CALL SwVbaSelection::setEnd( ::sal_Int32 _end ) throw (uno::RuntimeExce getRange()->setEnd( _end ); } -rtl::OUString& +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() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaSelection") ); return sImplName; } -uno::Sequence< rtl::OUString > +uno::Sequence< rtl::OUString > SwVbaSelection::getServiceNames() { static uno::Sequence< rtl::OUString > aServiceNames; diff --git a/sw/source/ui/vba/vbaselection.hxx b/sw/source/ui/vba/vbaselection.hxx index afbf79a6c3..0b398cd484 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 a8bb6bee9c..984dbae3b4 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 bfa12e0caa..2dd6a2d703 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 58a88e2e79..8a835f180b 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 66e5d1fd4c..4d2d229da8 100644 --- a/sw/source/ui/vba/vbasystem.cxx +++ b/sw/source/ui/vba/vbasystem.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -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 ) @@ -97,7 +202,7 @@ SwVbaSystem::getCursor() throw (uno::RuntimeException) } } -void SAL_CALL +void SAL_CALL SwVbaSystem::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException) { try @@ -131,11 +236,11 @@ SwVbaSystem::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException) break; } default: - throw uno::RuntimeException( rtl::OUString( + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown value for Cursor pointer")), uno::Reference< uno::XInterface >() ); // TODO: isn't this a flaw in the API? It should be allowed to throw an // IllegalArgumentException, or so - } + } } catch( const uno::Exception& ) { @@ -143,22 +248,22 @@ SwVbaSystem::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException) } } -uno::Any SAL_CALL +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); @@ -167,14 +272,14 @@ SwVbaSystem::PrivateProfileString( const rtl::OUString& rFilename, const rtl::OU return uno::makeAny( uno::Reference< XPropValue > ( new ScVbaPropValue( &maPrivateProfileStringListener ) ) ); } -rtl::OUString& +rtl::OUString& SwVbaSystem::getServiceImplName() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaSystem") ); return sImplName; } -uno::Sequence< rtl::OUString > +uno::Sequence< rtl::OUString > SwVbaSystem::getServiceNames() { static uno::Sequence< rtl::OUString > aServiceNames; diff --git a/sw/source/ui/vba/vbatable.cxx b/sw/source/ui/vba/vbatable.cxx index 7598dfc6cf..1ff9294a42 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 c28a3cdaf3..1348c603f6 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/vbatablehelper.cxx b/sw/source/ui/vba/vbatablehelper.cxx new file mode 100644 index 0000000000..bf87b6b248 --- /dev/null +++ b/sw/source/ui/vba/vbatablehelper.cxx @@ -0,0 +1,306 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbatablehelper.hxx" +#include <swtable.hxx> +#include <unotbl.hxx> +#include <docsh.hxx> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +#define UNO_TABLE_COLUMN_SUM 10000 + +SwVbaTableHelper::SwVbaTableHelper( const uno::Reference< text::XTextTable >& xTextTable ) throw (uno::RuntimeException) : mxTextTable( xTextTable ), pDoc( NULL ) +{ + pTable = GetSwTable( mxTextTable ); +} + +SwTable* SwVbaTableHelper::GetSwTable( const uno::Reference< text::XTextTable >& xTextTable ) throw (uno::RuntimeException) +{ + uno::Reference< lang::XUnoTunnel > xTunnel( xTextTable, uno::UNO_QUERY_THROW ); + SwXTextTable* pXTextTable = reinterpret_cast< SwXTextTable * >( sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextTable::getUnoTunnelId()))); + if( !pXTextTable ) + throw uno::RuntimeException(); + + SwFrmFmt* pFrmFmt = pXTextTable->GetFrmFmt(); + if( !pFrmFmt ) + throw uno::RuntimeException(); + + SwTable* pTable = SwTable::FindTable( pFrmFmt ); + return pTable; +} + +sal_Int32 SwVbaTableHelper::getTabColumnsCount( sal_Int32 nRowIndex ) throw (uno::RuntimeException) +{ + sal_Int32 nRet = 0; + if(!pTable->IsTblComplex()) + { + SwTableLines& rLines = pTable->GetTabLines(); + SwTableLine* pLine = rLines.GetObject( nRowIndex ); + nRet = pLine->GetTabBoxes().Count(); + } + return nRet; +} + +sal_Int32 SwVbaTableHelper::getTabColumnsMaxCount( ) throw (uno::RuntimeException) +{ + sal_Int32 nRet = 0; + //sal_Int32 nRowCount = mxTextTable->getRows()->getCount(); + sal_Int32 nRowCount = pTable->GetTabLines().Count(); + for( sal_Int32 index = 0; index < nRowCount; index++ ) + { + sal_Int32 nColCount = getTabColumnsCount( index ); + if( nRet < nColCount ) + nRet = nColCount; + } + return nRet; +} + +sal_Int32 SwVbaTableHelper::getTabRowIndex( const rtl::OUString& CellName ) throw (uno::RuntimeException) +{ + sal_Int32 nRet = 0; + String sCellName(CellName); + SwTableBox* pBox = (SwTableBox*)pTable->GetTblBox( sCellName ); + if( !pBox ) + throw uno::RuntimeException(); + + const SwTableLine* pLine = pBox->GetUpper(); + const SwTableLines* pLines = pLine->GetUpper() + ? &pLine->GetUpper()->GetTabLines() : &pTable->GetTabLines(); + nRet = pLines->GetPos( pLine ); + return nRet; +} + +sal_Int32 SwVbaTableHelper::getTabColIndex( const rtl::OUString& CellName ) throw (uno::RuntimeException) +{ + sal_Int32 nRet = 0; + String sCellName(CellName); + const SwTableBox* pBox = (SwTableBox*)pTable->GetTblBox( sCellName ); + if( !pBox ) + throw uno::RuntimeException(); + const SwTableBoxes* pBoxes = &pBox->GetUpper()->GetTabBoxes(); + nRet = pBoxes->GetPos( pBox ); + return nRet; +} + +rtl::OUString SwVbaTableHelper::getColumnStr( sal_Int32 nCol ) +{ + const sal_Int32 coDiff = 52; // 'A'-'Z' 'a' - 'z' + sal_Int32 nCalc = 0; + + String sRet; + do{ + nCalc = nCol % coDiff; + if( nCalc >= 26 ) + sRet.Insert( sal_Unicode('a' - 26 + nCalc ), 0 ); + else + sRet.Insert( sal_Unicode('A' + nCalc ), 0 ); + + if( 0 == ( nCol = nCol - nCalc ) ) + break; + nCol /= coDiff; + --nCol; + }while(1); + return sRet; +} + +sal_Int32 SwVbaTableHelper::getTableWidth( ) throw (uno::RuntimeException) +{ + sal_Int32 nWidth = 0; + sal_Bool isWidthRelatvie = sal_False; + uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW ); + xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsWidthRelative") ) ) >>= isWidthRelatvie; + if( isWidthRelatvie ) + { + xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RelativeWidth") ) ) >>= nWidth; + } + else + { + xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) ) >>= nWidth; + } + return nWidth; +} + +void SwVbaTableHelper::setTableWidth( sal_Int32 _width ) throw (uno::RuntimeException) +{ + sal_Bool isWidthRelatvie = sal_False; + uno::Reference< beans::XPropertySet > xTableProps( mxTextTable, uno::UNO_QUERY_THROW ); + xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsWidthRelative") ) ) >>= isWidthRelatvie; + if( isWidthRelatvie ) + { + xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RelativeWidth") ), uno::makeAny( _width )); + } + else + { + xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ), uno::makeAny( _width ) ); + } +} + +SwTableBox* SwVbaTableHelper::GetTabBox( sal_Int32 nCol, sal_Int32 nRow ) throw (css::uno::RuntimeException) +{ + SwTableLines& rLines = pTable->GetTabLines(); + sal_Int32 nRowCount = rLines.Count(); + if( nRowCount < nRow ) + throw uno::RuntimeException(); + + SwTableBox* pStart = NULL; + SwTableLine* pLine = rLines.GetObject( nRow ); + if( pLine->GetTabBoxes().Count() < nCol ) + throw uno::RuntimeException(); + + pStart = pLine->GetTabBoxes()[ nCol ]; + + if( !pStart ) + throw uno::RuntimeException(); + + return pStart; +} + +void SwVbaTableHelper::InitTabCols( SwTabCols& rCols, const SwTableBox *pStart, BOOL /*bCurRowOnly*/ ) +{ + rCols.SetLeftMin ( 0 ); + rCols.SetLeft ( 0 ); + rCols.SetRight ( UNO_TABLE_COLUMN_SUM ); + rCols.SetRightMax( UNO_TABLE_COLUMN_SUM ); + + //if( !pDoc ) + // { + // pDoc = word::getDocShell( getCurrentDocument() )->GetDoc(); + // } + pTable->GetTabCols( rCols, pStart, sal_False, sal_False ); +} + +sal_Int32 SwVbaTableHelper::GetColCount( SwTabCols& rCols ) const +{ + sal_Int32 nCount = 0; + for(sal_Int32 i = 0; i < rCols.Count(); i++ ) + if(rCols.IsHidden(i)) + nCount ++; + return rCols.Count() - nCount; +} + +sal_Int32 SwVbaTableHelper::GetRightSeparator( SwTabCols& rCols, sal_Int32 nNum) const +{ + DBG_ASSERT( nNum < (sal_Int32)GetColCount( rCols ) ,"Index out of range"); + sal_Int32 i = 0; + while( nNum >= 0 ) + { + if( !rCols.IsHidden( static_cast< USHORT >(i)) ) + nNum--; + i++; + } + return i - 1; +} + +sal_Int32 SwVbaTableHelper::GetColWidth( sal_Int32 nCol, sal_Int32 nRow, sal_Bool bCurRowOnly ) throw (uno::RuntimeException) +{ + SwTableBox* pStart = GetTabBox( nCol, nRow ); + SwTabCols aCols; + InitTabCols( aCols, pStart, bCurRowOnly ); + sal_Int32 nWidth = GetColWidth( aCols, nCol ); + + sal_Int32 nTableWidth = getTableWidth( ); + double dAbsWidth = ( (double)nWidth / UNO_TABLE_COLUMN_SUM ) * (double) nTableWidth; + return ( sal_Int32 )Millimeter::getInPoints( dAbsWidth ); +} + +sal_Int32 SwVbaTableHelper::GetColWidth( SwTabCols& rCols, sal_Int32 nNum ) throw (uno::RuntimeException) +{ + SwTwips nWidth = 0; + + if( rCols.Count() > 0 ) + { + if(rCols.Count() == GetColCount( rCols )) + { + nWidth = (SwTwips)((nNum == rCols.Count()) ? + rCols.GetRight() - rCols[nNum-1] : + nNum == 0 ? rCols[nNum] - rCols.GetLeft() : + rCols[nNum] - rCols[nNum-1]); + } + else + { + SwTwips nRValid = nNum < GetColCount( rCols ) ? + rCols[(USHORT)GetRightSeparator( rCols, nNum)]: + rCols.GetRight(); + SwTwips nLValid = nNum ? + rCols[(USHORT)GetRightSeparator( rCols, nNum - 1)]: + rCols.GetLeft(); + nWidth = nRValid - nLValid; + } + } + else + nWidth = rCols.GetRight(); + + return nWidth; +} + +void SwVbaTableHelper::SetColWidth( sal_Int32 _width, sal_Int32 nCol, sal_Int32 nRow, sal_Bool bCurRowOnly ) throw (css::uno::RuntimeException) +{ + double dAbsWidth = Millimeter::getInHundredthsOfOneMillimeter( _width ); + sal_Int32 nTableWidth = getTableWidth( ); + sal_Int32 nNewWidth = (sal_Int32)( dAbsWidth/nTableWidth * UNO_TABLE_COLUMN_SUM ); + + SwTableBox* pStart = GetTabBox( nCol, nRow ); + SwTabCols aOldCols; + InitTabCols( aOldCols, pStart, bCurRowOnly ); + + //BOOL bCurRowOnly = FALSE; + SwTwips nWidth = 0; + + SwTabCols aCols( aOldCols ); + if ( aCols.Count() > 0 ) + { + // if(aCols.Count() != GetColCount( aCols )) + // bCurRowOnly = TRUE; + nWidth = GetColWidth( aCols, nCol); + + int nDiff = (int)(nNewWidth - nWidth); + if( !nCol ) + aCols[ static_cast< USHORT >(GetRightSeparator(aCols, 0)) ] += nDiff; + else if( nCol < GetColCount( aCols ) ) + { + if(nDiff < GetColWidth( aCols, nCol + 1) - MINLAY) + aCols[ static_cast< USHORT >(GetRightSeparator( aCols, nCol)) ] += nDiff; + else + { + int nDiffLeft = nDiff - (int)GetColWidth( aCols, nCol + 1) + (int)MINLAY; + aCols[ static_cast< USHORT >(GetRightSeparator( aCols, nCol)) ] += (nDiff - nDiffLeft); + aCols[ static_cast< USHORT >(GetRightSeparator( aCols, nCol - 1)) ] -= nDiffLeft; + } + } + else + aCols[ static_cast< USHORT >(GetRightSeparator( aCols, nCol-1)) ] -= nDiff; + } + else + aCols.SetRight( Min( (long)nNewWidth, aCols.GetRightMax()) ); + + //pDoc->SetTabCols(*pTable, aCols, aOldCols, pStartBox, bCurRowOnly ); + pTable->SetTabCols(aCols, aOldCols, pStart, bCurRowOnly ); +} diff --git a/sw/source/ui/vba/vbatablehelper.hxx b/sw/source/ui/vba/vbatablehelper.hxx new file mode 100644 index 0000000000..62677cc6e9 --- /dev/null +++ b/sw/source/ui/vba/vbatablehelper.hxx @@ -0,0 +1,70 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: vbahelper.hxx,v $ + * $Revision: 1.5.32.1 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_WORD_VBA_TABLEHELPER_HXX +#define SW_WORD_VBA_TABLEHELPER_HXX + +#include <com/sun/star/text/XTextTable.hpp> +#include "wordvbahelper.hxx" +#include <swtable.hxx> +#include <tabcol.hxx> +#include <doc.hxx> + +class SwVbaTableHelper +{ +private: + css::uno::Reference< css::text::XTextTable > mxTextTable; + SwTable* pTable; + SwDoc* pDoc; + +private: + SwTableBox* GetTabBox( sal_Int32 nCol, sal_Int32 nRow ) throw (css::uno::RuntimeException); + void InitTabCols( SwTabCols& rCols, const SwTableBox *pStart, sal_Bool bCurRowOnly = FALSE ); + sal_Int32 GetRightSeparator( SwTabCols& rCols, sal_Int32 nNum) const; + sal_Int32 GetColCount( SwTabCols& rCols ) const; + sal_Int32 GetColWidth( SwTabCols& rCols, sal_Int32 nNum ) throw (css::uno::RuntimeException); + +public: + SwVbaTableHelper( const css::uno::Reference< css::text::XTextTable >& xTextTable ) throw (css::uno::RuntimeException); + ~SwVbaTableHelper() {} + sal_Int32 getTabColumnsCount( sal_Int32 nRowIndex ) throw (css::uno::RuntimeException); + sal_Int32 getTabColumnsMaxCount( ) throw (css::uno::RuntimeException); + sal_Int32 getTabRowIndex( const rtl::OUString& sCellName ) throw (css::uno::RuntimeException); + sal_Int32 getTabColIndex( const rtl::OUString& sCellName ) throw (css::uno::RuntimeException); + sal_Int32 getTableWidth( ) throw (css::uno::RuntimeException); + void setTableWidth( sal_Int32 _width ) throw (css::uno::RuntimeException); + + sal_Int32 GetColWidth( sal_Int32 nCol, sal_Int32 nRow = 0, sal_Bool bCurRowOnly = FALSE ) throw (css::uno::RuntimeException); + void SetColWidth( sal_Int32 _width, sal_Int32 nCol, sal_Int32 nRow = 0, sal_Bool bCurRowOnly = FALSE ) throw (css::uno::RuntimeException); + + static SwTable* GetSwTable( const css::uno::Reference< css::text::XTextTable >& xTextTable ) throw (css::uno::RuntimeException); + static rtl::OUString getColumnStr( sal_Int32 nCol ); +}; + +#endif diff --git a/sw/source/ui/vba/vbatableofcontents.cxx b/sw/source/ui/vba/vbatableofcontents.cxx new file mode 100644 index 0000000000..d7e5663813 --- /dev/null +++ b/sw/source/ui/vba/vbatableofcontents.cxx @@ -0,0 +1,124 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbatableofcontents.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> +#include <ooo/vba/word/WdTabLeader.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaTableOfContents::SwVbaTableOfContents( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextDocument >& xDoc, const uno::Reference< text::XDocumentIndex >& xDocumentIndex ) throw ( uno::RuntimeException ) : + SwVbaTableOfContents_BASE( rParent, rContext ), mxTextDocument( xDoc ), mxDocumentIndex( xDocumentIndex ) +{ + mxTocProps.set( mxDocumentIndex, uno::UNO_QUERY_THROW ); +} + + +SwVbaTableOfContents::~SwVbaTableOfContents() +{ +} + +::sal_Int32 SAL_CALL SwVbaTableOfContents::getLowerHeadingLevel() throw (uno::RuntimeException) +{ + sal_Int16 nLevel = 0; + mxTocProps->getPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Level") ) ) >>= nLevel; + return nLevel; +} + +void SAL_CALL SwVbaTableOfContents::setLowerHeadingLevel( ::sal_Int32 _lowerheadinglevel ) throw (uno::RuntimeException) +{ + mxTocProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Level") ), uno::makeAny( sal_Int8( _lowerheadinglevel ) ) ); +} + +::sal_Int32 SAL_CALL SwVbaTableOfContents::getTabLeader() throw (uno::RuntimeException) +{ + // not support in Writer + return word::WdTabLeader::wdTabLeaderDots; +} + +void SAL_CALL SwVbaTableOfContents::setTabLeader( ::sal_Int32 /*_tableader*/ ) throw (uno::RuntimeException) +{ + // not support in Writer +} + +::sal_Bool SAL_CALL SwVbaTableOfContents::getUseFields() throw (css::uno::RuntimeException) +{ + sal_Bool bUseFields = sal_False; + mxTocProps->getPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CreateFromMarks") ) ) >>= bUseFields; + return bUseFields; +} + +void SAL_CALL SwVbaTableOfContents::setUseFields( ::sal_Bool _useFields ) throw (css::uno::RuntimeException) +{ + mxTocProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CreateFromMarks") ), uno::makeAny( _useFields ) ); +} + +::sal_Bool SAL_CALL SwVbaTableOfContents::getUseOutlineLevels() throw (css::uno::RuntimeException) +{ + sal_Bool bUseOutlineLevels = sal_False; + mxTocProps->getPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CreateFromOutline") ) ) >>= bUseOutlineLevels; + return bUseOutlineLevels; +} + +void SAL_CALL SwVbaTableOfContents::setUseOutlineLevels( ::sal_Bool _useOutlineLevels ) throw (css::uno::RuntimeException) +{ + mxTocProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CreateFromOutline") ), uno::makeAny( _useOutlineLevels ) ); +} + +void SAL_CALL SwVbaTableOfContents::Delete( ) throw (uno::RuntimeException) +{ + uno::Reference< text::XTextContent > xTextContent( mxDocumentIndex, uno::UNO_QUERY_THROW ); + mxTextDocument->getText()->removeTextContent( xTextContent ); +} + +void SAL_CALL SwVbaTableOfContents::Update( ) throw (uno::RuntimeException) +{ + mxDocumentIndex->update(); +} + +rtl::OUString& +SwVbaTableOfContents::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaTableOfContents") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaTableOfContents::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.TableOfContents" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbatableofcontents.hxx b/sw/source/ui/vba/vbatableofcontents.hxx new file mode 100644 index 0000000000..73abc8f4a7 --- /dev/null +++ b/sw/source/ui/vba/vbatableofcontents.hxx @@ -0,0 +1,70 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_TABLEOFCONTENTS_HXX +#define SW_VBA_TABLEOFCONTENTS_HXX + +#include <ooo/vba/word/XTableOfContents.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XDocumentIndex.hpp> + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XTableOfContents > SwVbaTableOfContents_BASE; + +class SwVbaTableOfContents : public SwVbaTableOfContents_BASE +{ +private: + css::uno::Reference< css::text::XTextDocument > mxTextDocument; + css::uno::Reference< css::text::XDocumentIndex > mxDocumentIndex; + css::uno::Reference< css::beans::XPropertySet > mxTocProps; + +public: + SwVbaTableOfContents( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextDocument >& xDoc, const css::uno::Reference< css::text::XDocumentIndex >& xDocumentIndex ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaTableOfContents(); + + // Attributes + virtual ::sal_Int32 SAL_CALL getLowerHeadingLevel() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLowerHeadingLevel( ::sal_Int32 _lowerheadinglevel ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getTabLeader() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTabLeader( ::sal_Int32 _tableader ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getUseFields() throw (css::uno::RuntimeException); + virtual void SAL_CALL setUseFields( ::sal_Bool _useFields ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getUseOutlineLevels() throw (css::uno::RuntimeException); + virtual void SAL_CALL setUseOutlineLevels( ::sal_Bool _useOutlineLevels ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL Delete( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Update( ) throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_TABLEOFCONTENTS_HXX */ diff --git a/sw/source/ui/vba/vbatables.cxx b/sw/source/ui/vba/vbatables.cxx index 53178d1c79..9ca798a6ce 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 { @@ -39,8 +124,8 @@ public: TableEnumerationImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xDocument, const uno::Reference< container::XIndexAccess >& xIndexAccess ) : mxParent( xParent ), mxContext( xContext ), mxDocument( xDocument ), mxIndexAccess( xIndexAccess ), mnCurIndex(0) { } - virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) - { + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { return ( mnCurIndex < mxIndexAccess->getCount() ); } virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) @@ -49,15 +134,15 @@ public: throw container::NoSuchElementException(); return lcl_createTable( mxParent, mxContext, mxDocument, mxIndexAccess->getByIndex( mnCurIndex++ ) ); } - + }; - -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 ) { } -uno::Reference< word::XTable > SAL_CALL +uno::Reference< word::XTable > SAL_CALL SwVbaTables::Add( const uno::Reference< word::XRange >& Range, const uno::Any& NumRows, const uno::Any& NumColumns, const uno::Any& /*DefaultTableBehavior*/, const uno::Any& /*AutoFitBehavior*/ ) throw (script::BasicErrorException, uno::RuntimeException) { sal_Int32 nCols = 0; @@ -66,7 +151,7 @@ SwVbaTables::Add( const uno::Reference< word::XRange >& Range, const uno::Any& N // Preconditions if ( !( pVbaRange && ( NumRows >>= nRows ) && ( NumColumns >>= nCols ) ) ) throw uno::RuntimeException(); // #FIXME better exception?? - if ( nCols <= 0 || nRows <= 0 ) + if ( nCols <= 0 || nRows <= 0 ) throw uno::RuntimeException(); // #FIXME better exception?? uno::Reference< frame::XModel > xModel( pVbaRange->getDocument(), uno::UNO_QUERY_THROW ); @@ -82,42 +167,48 @@ SwVbaTables::Add( const uno::Reference< word::XRange >& Range, const uno::Any& N */ xTable->initialize( nRows, nCols ); uno::Reference< text::XText > xText = xTextRange->getText(); - uno::Reference< text::XTextContent > xContext( xTable, uno::UNO_QUERY_THROW ); - + 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; } -uno::Reference< container::XEnumeration > SAL_CALL +uno::Reference< container::XEnumeration > SAL_CALL SwVbaTables::createEnumeration() throw (uno::RuntimeException) { return new TableEnumerationImpl( mxParent, mxContext, mxDocument, m_xIndexAccess ); } -// ScVbaCollectionBaseImpl -uno::Any +// ScVbaCollectionBaseImpl +uno::Any SwVbaTables::createCollectionObject( const uno::Any& aSource ) { return lcl_createTable( mxParent, mxContext, mxDocument, aSource ); -} +} // XHelperInterface -rtl::OUString& +rtl::OUString& SwVbaTables::getServiceImplName() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaTables") ); - return sImplName; + return sImplName; } // XEnumerationAccess -uno::Type SAL_CALL +uno::Type SAL_CALL SwVbaTables::getElementType() throw (uno::RuntimeException) { - return word::XTable::static_type(0); + return word::XTable::static_type(0); } -uno::Sequence<rtl::OUString> +uno::Sequence<rtl::OUString> SwVbaTables::getServiceNames() { static uno::Sequence< rtl::OUString > aServiceNames; diff --git a/sw/source/ui/vba/vbatablesofcontents.cxx b/sw/source/ui/vba/vbatablesofcontents.cxx new file mode 100644 index 0000000000..f7a84a9c65 --- /dev/null +++ b/sw/source/ui/vba/vbatablesofcontents.cxx @@ -0,0 +1,197 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbatablesofcontents.hxx" +#include "vbatableofcontents.hxx" +#include "vbarange.hxx" +#include <com/sun/star/text/XDocumentIndexesSupplier.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > TableOfContentsCollectionHelper_Base; +typedef std::vector< uno::Reference< text::XDocumentIndex > > XTocVec; + +class TablesOfContentsEnumWrapper : public EnumerationHelper_BASE +{ + uno::Reference< container::XIndexAccess > mxIndexAccess; + sal_Int32 nIndex; + +public: + TablesOfContentsEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : mxIndexAccess( xIndexAccess ), nIndex( 0 ) + { + } + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < mxIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if( nIndex < mxIndexAccess->getCount() ) + { + return mxIndexAccess->getByIndex( nIndex++ ); + } + throw container::NoSuchElementException(); + } +}; + +class TableOfContentsCollectionHelper : public TableOfContentsCollectionHelper_Base +{ +private: + uno::Reference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< text::XTextDocument > mxTextDocument; + XTocVec maToc; + +public: + TableOfContentsCollectionHelper( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextDocument >& xDoc ) throw ( uno::RuntimeException ): mxParent( xParent ), mxContext( xContext ), mxTextDocument( xDoc ) + { + uno::Reference< text::XDocumentIndexesSupplier > xDocIndexSupp( mxTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xDocIndexes = xDocIndexSupp->getDocumentIndexes(); + sal_Int32 nCount = xDocIndexes->getCount(); + for( sal_Int32 i = 0; i < nCount; i++ ) + { + uno::Reference< text::XDocumentIndex > xToc( xDocIndexes->getByIndex(i), uno::UNO_QUERY_THROW ); + if( xToc->getServiceName().equalsAscii("com.sun.star.text.ContentIndex") ) + { + maToc.push_back( xToc ); + } + } + } + + virtual ~TableOfContentsCollectionHelper() {} + + virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) + { + return maToc.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::XDocumentIndex > xToc( maToc[Index], uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< word::XTableOfContents >( new SwVbaTableOfContents( mxParent, mxContext, mxTextDocument, xToc ) ) ); + } + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) + { + return word::XTableOfContents::static_type(0); + } + virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return sal_True; + } + // XEnumerationAccess + virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) + { + return new TablesOfContentsEnumWrapper( this ); + } +}; + +SwVbaTablesOfContents::SwVbaTablesOfContents( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextDocument >& xDoc ) throw (uno::RuntimeException) : SwVbaTablesOfContents_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new TableOfContentsCollectionHelper( xParent, xContext, xDoc ) ) ), mxTextDocument( xDoc ) +{ +} + +uno::Reference< word::XTableOfContents > SAL_CALL +SwVbaTablesOfContents::Add( const uno::Reference< word::XRange >& Range, const uno::Any& /*UseHeadingStyles*/, const uno::Any& /*UpperHeadingLevel*/, const uno::Any& LowerHeadingLevel, const uno::Any& UseFields, const uno::Any& /*TableID*/, const uno::Any& /*RightAlignPageNumbers*/, const uno::Any& /*IncludePageNumbers*/, const uno::Any& /*AddedStyles*/, const uno::Any& /*UseHyperlinks*/, const uno::Any& /*HidePageNumbersInWeb*/, const uno::Any& /*UseOutlineLevels*/ ) throw (uno::RuntimeException) +{ + uno::Reference< lang::XMultiServiceFactory > xDocMSF( mxTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< text::XDocumentIndex > xDocumentIndex( xDocMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.ContentIndex")) ), uno::UNO_QUERY_THROW ); + + uno::Reference< beans::XPropertySet > xTocProps( xDocumentIndex, uno::UNO_QUERY_THROW ); + sal_Bool isProtected = sal_False; + xTocProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsProtected") ), uno::makeAny( isProtected ) ); + + uno::Reference< word::XTableOfContents > xToc( new SwVbaTableOfContents( this, mxContext, mxTextDocument, xDocumentIndex ) ); + + sal_Int32 nLowerHeadingLevel = 9; + if( LowerHeadingLevel.hasValue() ) + LowerHeadingLevel >>= nLowerHeadingLevel; + xToc->setLowerHeadingLevel( nLowerHeadingLevel ); + + sal_Bool bUseFields = sal_False; + if( UseFields.hasValue() ) + UseFields >>= bUseFields; + xToc->setUseFields( bUseFields ); + + sal_Bool bUseOutlineLevels = sal_True; + //if( UseOutlineLevels.hasValue() ) + // UseOutlineLevels >>= bUseOutlineLevels; + xToc->setUseOutlineLevels( bUseOutlineLevels ); + + SwVbaRange* pVbaRange = dynamic_cast<SwVbaRange*>( Range.get() ); + if( !pVbaRange ) + throw uno::RuntimeException(); + + uno::Reference< text::XTextRange > xTextRange = pVbaRange->getXTextRange(); + uno::Reference< text::XText > xText = pVbaRange->getXText(); + uno::Reference< text::XTextContent > xTextContent( xDocumentIndex, uno::UNO_QUERY_THROW ); + xText->insertTextContent( xTextRange, xTextContent, sal_False ); + xToc->Update(); + + return xToc; +} + +// XEnumerationAccess +uno::Type +SwVbaTablesOfContents::getElementType() throw (uno::RuntimeException) +{ + return word::XTableOfContents::static_type(0); +} +uno::Reference< container::XEnumeration > +SwVbaTablesOfContents::createEnumeration() throw (uno::RuntimeException) +{ + return new TablesOfContentsEnumWrapper( m_xIndexAccess ); +} + +uno::Any +SwVbaTablesOfContents::createCollectionObject( const uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString& +SwVbaTablesOfContents::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaTablesOfContents") ); + return sImplName; +} + +uno::Sequence<rtl::OUString> +SwVbaTablesOfContents::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.TablesOfContents") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbatablesofcontents.hxx b/sw/source/ui/vba/vbatablesofcontents.hxx new file mode 100644 index 0000000000..5a6f0a0c76 --- /dev/null +++ b/sw/source/ui/vba/vbatablesofcontents.hxx @@ -0,0 +1,64 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_TABLESOFCONTENTS_HXX +#define SW_VBA_TABLESOFCONTENTS_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XTablesOfContents.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/text/XTextDocument.hpp> +#include <ooo/vba/word/XTableOfContents.hpp> +#include <ooo/vba/word/XRange.hpp> + +typedef CollTestImplHelper< ooo::vba::word::XTablesOfContents > SwVbaTablesOfContents_BASE; + +class SwVbaTablesOfContents : public SwVbaTablesOfContents_BASE +{ +private: + css::uno::Reference< css::text::XTextDocument > mxTextDocument; + +public: + SwVbaTablesOfContents( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::text::XTextDocument >& xDoc ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaTablesOfContents() {} + + // Methods + virtual css::uno::Reference< ::ooo::vba::word::XTableOfContents > SAL_CALL Add( const css::uno::Reference< ::ooo::vba::word::XRange >& Range, const css::uno::Any& UseHeadingStyles, const css::uno::Any& UpperHeadingLevel, const css::uno::Any& LowerHeadingLevel, const css::uno::Any& UseFields, const css::uno::Any& TableID, const css::uno::Any& RightAlignPageNumbers, const css::uno::Any& IncludePageNumbers, const css::uno::Any& AddedStyles, const css::uno::Any& UseHyperlinks, const css::uno::Any& HidePageNumbersInWeb, const css::uno::Any& UseOutlineLevels ) 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); + + // SwVbaTablesOfContents_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SW_VBA_TABLESOFCONTENTS_HXX */ diff --git a/sw/source/ui/vba/vbatabstop.cxx b/sw/source/ui/vba/vbatabstop.cxx new file mode 100644 index 0000000000..8ac6535d48 --- /dev/null +++ b/sw/source/ui/vba/vbatabstop.cxx @@ -0,0 +1,62 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbatabstop.hxx" +#include <vbahelper/vbahelper.hxx> +#include <tools/diagnose_ex.h> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +SwVbaTabStop::SwVbaTabStop( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< beans::XPropertySet >& xParaProps, const style::TabStop& aTabStop ) throw ( uno::RuntimeException ) : SwVbaTabStop_BASE( rParent, rContext ), mxParaProps( xParaProps ), maTabStop( aTabStop ) +{ +} + +SwVbaTabStop::~SwVbaTabStop() +{ +} + +rtl::OUString& +SwVbaTabStop::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaTabStop") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +SwVbaTabStop::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.TabStop" ) ); + } + return aServiceNames; +} diff --git a/sw/source/ui/vba/vbatabstop.hxx b/sw/source/ui/vba/vbatabstop.hxx new file mode 100644 index 0000000000..d5fd9c412f --- /dev/null +++ b/sw/source/ui/vba/vbatabstop.hxx @@ -0,0 +1,54 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_TABSTOP_HXX +#define SW_VBA_TABSTOP_HXX + +#include <ooo/vba/word/XTabStop.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/style/TabStop.hpp> + +typedef InheritedHelperInterfaceImpl1< ooo::vba::word::XTabStop > SwVbaTabStop_BASE; + +class SwVbaTabStop : public SwVbaTabStop_BASE +{ +private: + css::uno::Reference< css::beans::XPropertySet > mxParaProps; + css::style::TabStop maTabStop; + +public: + SwVbaTabStop( const css::uno::Reference< ooo::vba::XHelperInterface >& rParent, const css::uno::Reference< css::uno::XComponentContext >& rContext, const css::uno::Reference< css::beans::XPropertySet >& xParaProps, const css::style::TabStop& aTabStop ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaTabStop(); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SW_VBA_TABSTOP_HXX */ diff --git a/sw/source/ui/vba/vbatabstops.cxx b/sw/source/ui/vba/vbatabstops.cxx new file mode 100644 index 0000000000..d2b0663046 --- /dev/null +++ b/sw/source/ui/vba/vbatabstops.cxx @@ -0,0 +1,280 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbatabstops.hxx" +#include "vbatabstop.hxx" +#include <com/sun/star/style/TabAlign.hpp> +#include <ooo/vba/word/WdTabLeader.hpp> +#include <ooo/vba/word/WdTabAlignment.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +uno::Sequence< style::TabStop > lcl_getTabStops( const uno::Reference< beans::XPropertySet >& xParaProps ) throw (uno::RuntimeException) +{ + uno::Sequence< style::TabStop > aSeq; + xParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaTabStops") ) ) >>= aSeq; + return aSeq; +} + +void lcl_setTabStops( const uno::Reference< beans::XPropertySet >& xParaProps, const uno::Sequence< style::TabStop >& aSeq ) throw (uno::RuntimeException) +{ + xParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaTabStops") ), uno::makeAny( aSeq ) ); +} + +typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > TabStopCollectionHelper_Base; + +class TabStopsEnumWrapper : public EnumerationHelper_BASE +{ + uno::Reference< container::XIndexAccess > mxIndexAccess; + sal_Int32 nIndex; + +public: + TabStopsEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : mxIndexAccess( xIndexAccess ), nIndex( 0 ) + { + } + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < mxIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if( nIndex < mxIndexAccess->getCount() ) + { + return mxIndexAccess->getByIndex( nIndex++ ); + } + throw container::NoSuchElementException(); + } +}; + +class TabStopCollectionHelper : public TabStopCollectionHelper_Base +{ +private: + uno::Reference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< beans::XPropertySet > mxParaProps; + uno::Sequence< style::TabStop > maTabStops; + +public: + TabStopCollectionHelper( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& xParaProps ) throw ( css::uno::RuntimeException ): mxParent( xParent ), mxContext( xContext ), mxParaProps( xParaProps ) + { + maTabStops = lcl_getTabStops( xParaProps ); + } + + virtual ~TabStopCollectionHelper() {} + + virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) + { + return maTabStops.getLength(); + } + virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( Index < 0 || Index >= getCount() ) + throw css::lang::IndexOutOfBoundsException(); + + const style::TabStop* pTabs = maTabStops.getConstArray(); + return uno::makeAny( uno::Reference< word::XTabStop >( new SwVbaTabStop( mxParent, mxContext, mxParaProps, pTabs[ Index ] ) ) ); + } + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) + { + return word::XTabStop::static_type(0); + } + virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return sal_True; + } + // XEnumerationAccess + virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) + { + return new TabStopsEnumWrapper( this ); + } +}; + +SwVbaTabStops::SwVbaTabStops( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& xParaProps ) throw (uno::RuntimeException) : SwVbaTabStops_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new TabStopCollectionHelper( xParent, xContext, xParaProps ) ) ), mxParaProps( xParaProps ) +{ +} + +uno::Reference< word::XTabStop > SAL_CALL SwVbaTabStops::Add( float Position, const uno::Any& Alignment, const uno::Any& Leader ) throw (uno::RuntimeException) +{ + sal_Int32 nPosition = Millimeter::getInHundredthsOfOneMillimeter( Position ); + + style::TabAlign nAlign = style::TabAlign_LEFT; + if( Alignment.hasValue() ) + { + sal_Int32 wdAlign = word::WdTabAlignment::wdAlignTabLeft; + Alignment >>= wdAlign; + switch( wdAlign ) + { + case word::WdTabAlignment::wdAlignTabLeft: + { + nAlign = style::TabAlign_LEFT; + break; + } + case word::WdTabAlignment::wdAlignTabRight: + { + nAlign = style::TabAlign_RIGHT; + break; + } + case word::WdTabAlignment::wdAlignTabCenter: + { + nAlign = style::TabAlign_CENTER; + break; + } + case word::WdTabAlignment::wdAlignTabDecimal: + { + nAlign = style::TabAlign_DECIMAL; + break; + } + case word::WdTabAlignment::wdAlignTabBar: + case word::WdTabAlignment::wdAlignTabList: + { + DebugHelper::exception( SbERR_NOT_IMPLEMENTED, rtl::OUString() ); + break; + } + default: + { + //left + } + } + } + + sal_Char cLeader = ' '; // default is space + if( Leader.hasValue() ) + { + sal_Int32 wdLeader = word::WdTabLeader::wdTabLeaderSpaces; + Leader >>= wdLeader; + switch( wdLeader ) + { + case word::WdTabLeader::wdTabLeaderSpaces: + { + cLeader = ' '; + break; + } + case word::WdTabLeader::wdTabLeaderMiddleDot: + { + cLeader = 183; + break; + } + case word::WdTabLeader::wdTabLeaderDots: + { + cLeader = '.'; + break; + } + case word::WdTabLeader::wdTabLeaderDashes: + case word::WdTabLeader::wdTabLeaderHeavy: + case word::WdTabLeader::wdTabLeaderLines: + { + cLeader = '_'; + break; + } + default: + { + //left + } + } + } + + sal_Char cDecimal = '.'; // default value + + style::TabStop aTab; + aTab.Position = nPosition; + aTab.Alignment = nAlign; + aTab.DecimalChar = cDecimal; + aTab.FillChar = cLeader; + + uno::Sequence< style::TabStop > aOldTabs = lcl_getTabStops( mxParaProps ); + sal_Bool bOverWriter = sal_False; + + sal_Int32 nTabs = aOldTabs.getLength(); + uno::Sequence< style::TabStop > aNewTabs( nTabs + 1 ); + + style::TabStop* pOldTab = aOldTabs.getArray(); + style::TabStop* pNewTab = aNewTabs.getArray(); + pNewTab[0] = aTab; + for( sal_Int32 nIndex = 0; nIndex < nTabs && !bOverWriter; nIndex++ ) + { + if( pOldTab[nIndex].Position == nPosition ) + { + bOverWriter = sal_True; + pOldTab[nIndex] = aTab; + break; + } + pNewTab[ nIndex+1 ] = pOldTab[ nIndex ]; + } + if( bOverWriter ) + lcl_setTabStops( mxParaProps, aOldTabs ); + else + lcl_setTabStops( mxParaProps, aNewTabs ); + + return uno::Reference< word::XTabStop >( new SwVbaTabStop( this, mxContext, mxParaProps, aTab ) ); +} + +void SAL_CALL SwVbaTabStops::ClearAll() throw (uno::RuntimeException) +{ + uno::Sequence< style::TabStop > aSeq; + lcl_setTabStops( mxParaProps, aSeq ); +} + +// XEnumerationAccess +uno::Type +SwVbaTabStops::getElementType() throw (uno::RuntimeException) +{ + return word::XTabStop::static_type(0); +} +uno::Reference< container::XEnumeration > +SwVbaTabStops::createEnumeration() throw (uno::RuntimeException) +{ + return new TabStopsEnumWrapper( m_xIndexAccess ); +} + +uno::Any +SwVbaTabStops::createCollectionObject( const css::uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString& +SwVbaTabStops::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaTabStops") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +SwVbaTabStops::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.TabStops") ); + } + return sNames; +} diff --git a/sw/source/ui/vba/vbatabstops.hxx b/sw/source/ui/vba/vbatabstops.hxx new file mode 100644 index 0000000000..1c6ae34476 --- /dev/null +++ b/sw/source/ui/vba/vbatabstops.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: + * $Revision: + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SW_VBA_TABSTOPS_HXX +#define SW_VBA_TABSTOPS_HXX + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/word/XTabStops.hpp> +#include <ooo/vba/word/XTabStop.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef CollTestImplHelper< ooo::vba::word::XTabStops > SwVbaTabStops_BASE; + +class SwVbaTabStops : public SwVbaTabStops_BASE +{ +private: + css::uno::Reference< css::beans::XPropertySet > mxParaProps; + +public: + SwVbaTabStops( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& xParaProps ) throw ( css::uno::RuntimeException ); + virtual ~SwVbaTabStops() {} + + // Methods + virtual css::uno::Reference< ::ooo::vba::word::XTabStop > SAL_CALL Add( float Position, const css::uno::Any& Alignment, const css::uno::Any& Leader ) throw (css::uno::RuntimeException); + virtual void SAL_CALL ClearAll( ) 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); + + // SwVbaTabStops_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SW_VBA_TABSTOPS_HXX */ diff --git a/sw/source/ui/vba/vbatemplate.cxx b/sw/source/ui/vba/vbatemplate.cxx index 71dc7acd85..05987b1051 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 4e33599604..0abbc36204 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 2cf6194454..3dba711fe6 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 dc5913aaa1..a430638237 100644 --- a/sw/source/ui/vba/vbawindow.cxx +++ b/sw/source/ui/vba/vbawindow.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -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; @@ -56,10 +65,10 @@ SwVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& RouteDocument ) document.Close(SaveChanges, FileName, RouteDocument ); } -uno::Any SAL_CALL +uno::Any SAL_CALL SwVbaWindow::getView() throw (uno::RuntimeException) { - return uno::makeAny( uno::Reference< word::XView >( new SwVbaView( this, mxContext, m_xModel ) ) ); + return uno::makeAny( uno::Reference< word::XView >( new SwVbaView( this, mxContext, m_xModel ) ) ); } void SAL_CALL SwVbaWindow::setView( const uno::Any& _view ) throw (uno::RuntimeException) @@ -69,33 +78,71 @@ void SAL_CALL SwVbaWindow::setView( const uno::Any& _view ) throw (uno::RuntimeE { SwVbaView view( this, mxContext, m_xModel ); view.setType( nType ); - } + } +} + +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 +uno::Any SAL_CALL SwVbaWindow::Panes( const uno::Any& aIndex ) throw (uno::RuntimeException) { uno::Reference< XCollection > xPanes( new SwVbaPanes( this, mxContext, m_xModel ) ); if( aIndex.getValueTypeClass() == uno::TypeClass_VOID ) return uno::makeAny( xPanes ); - return uno::Any( xPanes->Item( aIndex, uno::Any() ) ); + return uno::Any( xPanes->Item( aIndex, uno::Any() ) ); } -uno::Any SAL_CALL +uno::Any SAL_CALL SwVbaWindow::ActivePane() throw (uno::RuntimeException) { - return uno::makeAny( uno::Reference< word::XPane >( new SwVbaPane( this, mxContext, m_xModel ) ) ); + return uno::makeAny( uno::Reference< word::XPane >( new SwVbaPane( this, mxContext, m_xModel ) ) ); } -rtl::OUString& +rtl::OUString& SwVbaWindow::getServiceImplName() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaWindow") ); return sImplName; } -uno::Sequence< rtl::OUString > +uno::Sequence< rtl::OUString > SwVbaWindow::getServiceNames() { static uno::Sequence< rtl::OUString > aServiceNames; diff --git a/sw/source/ui/vba/vbawindow.hxx b/sw/source/ui/vba/vbawindow.hxx index 1ef1ff9141..a5e03e9456 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 e489b0b69d..c4639a0e32 100644 --- a/sw/source/ui/vba/wordvbahelper.cxx +++ b/sw/source/ui/vba/wordvbahelper.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -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; @@ -47,7 +52,7 @@ namespace vba namespace word { -SwDocShell* getDocShell( const uno::Reference< frame::XModel>& xModel ) +SwDocShell* getDocShell( const uno::Reference< frame::XModel>& xModel ) { uno::Reference< lang::XUnoTunnel > xTunnel( xModel, uno::UNO_QUERY_THROW ); SwXTextDocument* pXDoc = reinterpret_cast< SwXTextDocument * >( sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextDocument::getUnoTunnelId()))); @@ -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 489cf25ea3..47d718eef9 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 61b4a3ed5e..39fa183ae5 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" |