diff options
author | Noel Power <noel.power@novell.com> | 2010-10-13 11:12:51 +0100 |
---|---|---|
committer | Noel Power <noel.power@novell.com> | 2010-10-13 11:12:51 +0100 |
commit | 43a65612e9014e4be6ca218721d171ae51e4a6b0 (patch) | |
tree | 7ad644d2b5c55aba38a822cee70b6700b29caa9b /sw/source/ui/vba/vbafield.cxx | |
parent | abe40b170c86426a08d072e839d1ecd9cdc60796 (diff) | |
parent | 2b90812e6e7b9c4b04290138f1cb1894b9886850 (diff) |
Merge branch 'vba' fix trailing ws & tab issues
Conflicts:
sw/source/ui/app/docsh.cxx
sw/source/ui/uno/unotxdoc.cxx
Diffstat (limited to 'sw/source/ui/vba/vbafield.cxx')
-rw-r--r-- | sw/source/ui/vba/vbafield.cxx | 157 |
1 files changed, 136 insertions, 21 deletions
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; |