1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #include "vbadocumentproperties.hxx" 28*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 29*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 30*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentInfoSupplier.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyContainer.hpp> 34*cdf0e10cSrcweir #include <ooo/vba/word/WdBuiltInProperty.hpp> 35*cdf0e10cSrcweir #include <ooo/vba/office/MsoDocProperties.hpp> 36*cdf0e10cSrcweir #include <memory> 37*cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 38*cdf0e10cSrcweir #include "wordvbahelper.hxx" 39*cdf0e10cSrcweir #include "fesh.hxx" 40*cdf0e10cSrcweir #include "docsh.hxx" 41*cdf0e10cSrcweir using namespace ::ooo::vba; 42*cdf0e10cSrcweir using namespace css; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir sal_Int8 lcl_toMSOPropType( const uno::Type& aType ) throw ( lang::IllegalArgumentException ) 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir sal_Int16 msoType = office::MsoDocProperties::msoPropertyTypeString; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir switch ( aType.getTypeClass() ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir case uno::TypeClass_BOOLEAN: 51*cdf0e10cSrcweir msoType = office::MsoDocProperties::msoPropertyTypeBoolean; 52*cdf0e10cSrcweir break; 53*cdf0e10cSrcweir case uno::TypeClass_FLOAT: 54*cdf0e10cSrcweir msoType = office::MsoDocProperties::msoPropertyTypeFloat; 55*cdf0e10cSrcweir break; 56*cdf0e10cSrcweir case uno::TypeClass_STRUCT: // Assume date 57*cdf0e10cSrcweir msoType = office::MsoDocProperties::msoPropertyTypeDate; 58*cdf0e10cSrcweir break; 59*cdf0e10cSrcweir case uno::TypeClass_BYTE: 60*cdf0e10cSrcweir case uno::TypeClass_SHORT: 61*cdf0e10cSrcweir case uno::TypeClass_LONG: 62*cdf0e10cSrcweir case uno::TypeClass_HYPER: 63*cdf0e10cSrcweir msoType = office::MsoDocProperties::msoPropertyTypeNumber; 64*cdf0e10cSrcweir break; 65*cdf0e10cSrcweir default: 66*cdf0e10cSrcweir throw lang::IllegalArgumentException(); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir return msoType; 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir class PropertGetSetHelper 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir protected: 74*cdf0e10cSrcweir uno::Reference< frame::XModel > m_xModel; 75*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > mxProps; 76*cdf0e10cSrcweir public: 77*cdf0e10cSrcweir PropertGetSetHelper( const uno::Reference< frame::XModel >& xModel ):m_xModel( xModel ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( m_xModel, uno::UNO_QUERY_THROW ); 80*cdf0e10cSrcweir mxProps.set( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW ); 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir virtual ~PropertGetSetHelper() {} 83*cdf0e10cSrcweir virtual uno::Any getPropertyValue( const rtl::OUString& rPropName ) = 0; 84*cdf0e10cSrcweir virtual void setPropertyValue( const rtl::OUString& rPropName, const uno::Any& aValue ) = 0; 85*cdf0e10cSrcweir virtual uno::Reference< beans::XPropertySet > getUnoProperties() { return mxProps; } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir }; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir class BuiltinPropertyGetSetHelper : public PropertGetSetHelper 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir public: 92*cdf0e10cSrcweir BuiltinPropertyGetSetHelper( const uno::Reference< frame::XModel >& xModel ) :PropertGetSetHelper( xModel ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir virtual uno::Any getPropertyValue( const rtl::OUString& rPropName ) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir if ( rPropName.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("EditingDuration" ) ) ) ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir sal_Int32 nSecs = 0; 100*cdf0e10cSrcweir mxProps->getPropertyValue( rPropName ) >>= nSecs; 101*cdf0e10cSrcweir return uno::makeAny( nSecs/60 ); // minutes 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir return mxProps->getPropertyValue( rPropName ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir virtual void setPropertyValue( const rtl::OUString& rPropName, const uno::Any& aValue ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir mxProps->setPropertyValue( rPropName, aValue ); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir }; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir class CustomPropertyGetSetHelper : public BuiltinPropertyGetSetHelper 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir public: 114*cdf0e10cSrcweir CustomPropertyGetSetHelper( const uno::Reference< frame::XModel >& xModel ) :BuiltinPropertyGetSetHelper( xModel ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( mxProps, uno::UNO_QUERY_THROW ); 117*cdf0e10cSrcweir uno::Reference< document::XDocumentProperties > xDocProp( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW ); 118*cdf0e10cSrcweir mxProps.set( xDocProp->getUserDefinedProperties(), uno::UNO_QUERY_THROW ); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir }; 121*cdf0e10cSrcweir class StatisticPropertyGetSetHelper : public PropertGetSetHelper 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir SwDocShell* mpDocShell; 124*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > mxModelProps; 125*cdf0e10cSrcweir public: 126*cdf0e10cSrcweir StatisticPropertyGetSetHelper( const uno::Reference< frame::XModel >& xModel ) :PropertGetSetHelper( xModel ) , mpDocShell( NULL ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir mxModelProps.set( m_xModel, uno::UNO_QUERY_THROW ); 129*cdf0e10cSrcweir mpDocShell = word::getDocShell( xModel ); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir virtual uno::Any getPropertyValue( const rtl::OUString& rPropName ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > stats; 134*cdf0e10cSrcweir try 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir // Characters, ParagraphCount & WordCount are available from 137*cdf0e10cSrcweir // the model ( and addtionally these also update the statics object ) 138*cdf0e10cSrcweir //return mxProps->getPropertyValue( rPropName ); 139*cdf0e10cSrcweir return mxModelProps->getPropertyValue( rPropName ); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir catch( uno::Exception& ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir OSL_TRACE("Got exception"); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir uno::Any aReturn; 146*cdf0e10cSrcweir if ( rPropName.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LineCount")) ) ) // special processing needed 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir if ( mpDocShell ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir SwFEShell* pFEShell = mpDocShell->GetFEShell(); 151*cdf0e10cSrcweir if(pFEShell) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir aReturn <<= pFEShell->GetLineCount(sal_False); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir else 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir mxModelProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParagraphCount") ) ) >>= stats; 160*cdf0e10cSrcweir mxProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DocumentStatistic") ) ) >>= stats; 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir sal_Int32 nLen = stats.getLength(); 163*cdf0e10cSrcweir bool bFound = false; 164*cdf0e10cSrcweir for ( sal_Int32 index = 0; index < nLen && !bFound ; ++index ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir if ( rPropName.equals( stats[ index ].Name ) ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir aReturn = stats[ index ].Value; 169*cdf0e10cSrcweir bFound = true; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir if ( !bFound ) 173*cdf0e10cSrcweir throw uno::RuntimeException(); // bad Property 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir return aReturn; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir virtual void setPropertyValue( const rtl::OUString& rPropName, const uno::Any& aValue ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > stats; 182*cdf0e10cSrcweir mxProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DocumentStatistic") ) ) >>= stats; 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir sal_Int32 nLen = stats.getLength(); 185*cdf0e10cSrcweir for ( sal_Int32 index = 0; index < nLen; ++index ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir if ( rPropName.equals( stats[ index ].Name ) ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir stats[ index ].Value = aValue; 190*cdf0e10cSrcweir mxProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DocumentStatistic") ), uno::makeAny( stats ) ); 191*cdf0e10cSrcweir break; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir }; 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir class DocPropInfo 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir public: 200*cdf0e10cSrcweir rtl::OUString msMSODesc; 201*cdf0e10cSrcweir rtl::OUString msOOOPropName; 202*cdf0e10cSrcweir boost::shared_ptr< PropertGetSetHelper > mpPropGetSetHelper; 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir static DocPropInfo createDocPropInfo( const rtl::OUString& sDesc, const rtl::OUString& sPropName, boost::shared_ptr< PropertGetSetHelper >& rHelper ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir return createDocPropInfo( rtl::OUStringToOString( sDesc, RTL_TEXTENCODING_UTF8 ).getStr(), rtl::OUStringToOString( sPropName, RTL_TEXTENCODING_UTF8 ).getStr(), rHelper ); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir static DocPropInfo createDocPropInfo( const sal_Char* sDesc, const sal_Char* sPropName, boost::shared_ptr< PropertGetSetHelper >& rHelper ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir DocPropInfo aItem; 212*cdf0e10cSrcweir aItem.msMSODesc = rtl::OUString::createFromAscii( sDesc ); 213*cdf0e10cSrcweir aItem.msOOOPropName = rtl::OUString::createFromAscii( sPropName ); 214*cdf0e10cSrcweir aItem.mpPropGetSetHelper = rHelper; 215*cdf0e10cSrcweir return aItem; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir uno::Any getValue() 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir if ( mpPropGetSetHelper.get() ) 220*cdf0e10cSrcweir return mpPropGetSetHelper->getPropertyValue( msOOOPropName ); 221*cdf0e10cSrcweir return uno::Any(); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir void setValue( const uno::Any& rValue ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir if ( mpPropGetSetHelper.get() ) 226*cdf0e10cSrcweir mpPropGetSetHelper->setPropertyValue( msOOOPropName, rValue ); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > getUnoProperties() 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps; 232*cdf0e10cSrcweir if ( mpPropGetSetHelper.get() ) 233*cdf0e10cSrcweir return mpPropGetSetHelper->getUnoProperties(); 234*cdf0e10cSrcweir return xProps; 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir }; 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir typedef std::hash_map< sal_Int32, DocPropInfo > MSOIndexToOODocPropInfo; 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir class BuiltInIndexHelper 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir MSOIndexToOODocPropInfo m_docPropInfoMap; 244*cdf0e10cSrcweir BuiltInIndexHelper(); 245*cdf0e10cSrcweir public: 246*cdf0e10cSrcweir BuiltInIndexHelper( const uno::Reference< frame::XModel >& xModel ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir boost::shared_ptr< PropertGetSetHelper > aStandardHelper( new BuiltinPropertyGetSetHelper( xModel ) ); 249*cdf0e10cSrcweir boost::shared_ptr< PropertGetSetHelper > aUsingStatsHelper( new StatisticPropertyGetSetHelper( xModel ) ); 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTitle ] = DocPropInfo::createDocPropInfo( "Title", "Title", aStandardHelper ); 252*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySubject ] = DocPropInfo::createDocPropInfo( "Subject", "Subject", aStandardHelper ); 253*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyAuthor ] = DocPropInfo::createDocPropInfo( "Author", "Author", aStandardHelper ); 254*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyKeywords ] = DocPropInfo::createDocPropInfo( "Keywords", "Keywords", aStandardHelper ); 255*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyComments ] = DocPropInfo::createDocPropInfo( "Comments", "Description", aStandardHelper ); 256*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTemplate ] = DocPropInfo::createDocPropInfo( "Template", "Template", aStandardHelper ); 257*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyLastAuthor ] = DocPropInfo::createDocPropInfo( "Last author", "ModifiedBy", aStandardHelper ); // doesn't seem to exist - throw or return nothing ? 258*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyRevision ] = DocPropInfo::createDocPropInfo( "Revision number", "EditingCycles", aStandardHelper ); // doesn't seem to exist - throw or return nothing ? 259*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyAppName ] = DocPropInfo::createDocPropInfo( "Application name", "Generator", aStandardHelper ); // doesn't seem to exist - throw or return nothing ? 260*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeLastPrinted ] = DocPropInfo::createDocPropInfo( "Last print date", "PrintDate", aStandardHelper ); // doesn't seem to exist - throw or return nothing ? 261*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeCreated ] = DocPropInfo::createDocPropInfo( "Creation date", "CreationDate", aStandardHelper ); 262*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeLastSaved ] = DocPropInfo::createDocPropInfo( "Last save time", "ModifyDate", aStandardHelper ); 263*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyVBATotalEdit ] = DocPropInfo::createDocPropInfo( "Total editing time", "EditingDuration", aStandardHelper ); // Not sure if this is correct 264*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyPages ] = DocPropInfo::createDocPropInfo( "Number of pages", "PageCount", aUsingStatsHelper ); // special handling required ? 265*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyWords ] = DocPropInfo::createDocPropInfo( "Number of words", "WordCount", aUsingStatsHelper ); // special handling require ? 266*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCharacters ] = DocPropInfo::createDocPropInfo( "Number of characters", "CharacterCount", aUsingStatsHelper ); // special handling required ? 267*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySecurity ] = DocPropInfo::createDocPropInfo( "Security", "", aStandardHelper ); // doesn't seem to exist 268*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCategory ] = DocPropInfo::createDocPropInfo( "Category", "Category", aStandardHelper ); // hacked in 269*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyFormat ] = DocPropInfo::createDocPropInfo( "Format", "", aStandardHelper ); // doesn't seem to exist 270*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyManager ] = DocPropInfo::createDocPropInfo( "Manager", "Manager", aStandardHelper ); // hacked in 271*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCompany ] = DocPropInfo::createDocPropInfo( "Company", "Company", aStandardHelper ); // hacked in 272*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyBytes ] = DocPropInfo::createDocPropInfo( "Number of bytes", "", aStandardHelper ); // doesn't seem to exist - size on disk exists ( for an already saved document ) perhaps it will do ( or we need something else ) 273*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyLines ] = DocPropInfo::createDocPropInfo( "Number of lines", "LineCount", aUsingStatsHelper ); // special handling 274*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyParas ] = DocPropInfo::createDocPropInfo( "Number of paragraphs", "ParagraphCount", aUsingStatsHelper ); // special handling 275*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySlides ] = DocPropInfo::createDocPropInfo( "Number of slides", "" , aStandardHelper ); // doesn't seem to exist 276*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyNotes ] = DocPropInfo::createDocPropInfo( "Number of notes", "", aStandardHelper ); // doesn't seem to exist 277*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyHiddenSlides ] = DocPropInfo::createDocPropInfo("Number of hidden Slides", "", aStandardHelper ); // doesn't seem to exist 278*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyMMClips ] = DocPropInfo::createDocPropInfo( "Number of multimedia clips", "", aStandardHelper ); // doesn't seem to exist 279*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyHyperlinkBase ] = DocPropInfo::createDocPropInfo( "Hyperlink base", "AutoloadURL", aStandardHelper ); 280*cdf0e10cSrcweir m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCharsWSpaces ] = DocPropInfo::createDocPropInfo( "Number of characters (with spaces)", "", aStandardHelper ); // doesn't seem to be supported 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir MSOIndexToOODocPropInfo& getDocPropInfoMap() { return m_docPropInfoMap; } 284*cdf0e10cSrcweir }; 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir typedef InheritedHelperInterfaceImpl1< ooo::vba::XDocumentProperty > SwVbaDocumentProperty_BASE; 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir class SwVbaBuiltInDocumentProperty : public SwVbaDocumentProperty_BASE 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir protected: 292*cdf0e10cSrcweir DocPropInfo mPropInfo; 293*cdf0e10cSrcweir public: 294*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const DocPropInfo& rInfo ); 295*cdf0e10cSrcweir // XDocumentProperty 296*cdf0e10cSrcweir virtual void SAL_CALL Delete( ) throw (script::BasicErrorException, uno::RuntimeException); 297*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getName( ) throw (script::BasicErrorException, uno::RuntimeException); 298*cdf0e10cSrcweir virtual void SAL_CALL setName( const ::rtl::OUString& Name ) throw (script::BasicErrorException, uno::RuntimeException); 299*cdf0e10cSrcweir virtual ::sal_Int8 SAL_CALL getType( ) throw (script::BasicErrorException, uno::RuntimeException); 300*cdf0e10cSrcweir virtual void SAL_CALL setType( ::sal_Int8 Type ) throw (script::BasicErrorException, uno::RuntimeException); 301*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL getLinkToContent( ) throw (script::BasicErrorException, uno::RuntimeException); 302*cdf0e10cSrcweir virtual void SAL_CALL setLinkToContent( ::sal_Bool LinkToContent ) throw (script::BasicErrorException, uno::RuntimeException); 303*cdf0e10cSrcweir virtual uno::Any SAL_CALL getValue( ) throw (script::BasicErrorException, uno::RuntimeException); 304*cdf0e10cSrcweir virtual void SAL_CALL setValue( const uno::Any& Value ) throw (script::BasicErrorException, uno::RuntimeException); 305*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getLinkSource( ) throw (script::BasicErrorException, uno::RuntimeException); 306*cdf0e10cSrcweir virtual void SAL_CALL setLinkSource( const rtl::OUString& LinkSource ) throw (script::BasicErrorException, uno::RuntimeException); 307*cdf0e10cSrcweir //XDefaultProperty 308*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (uno::RuntimeException) { return rtl::OUString::createFromAscii("Value"); } 309*cdf0e10cSrcweir // XHelperInterface 310*cdf0e10cSrcweir virtual rtl::OUString& getServiceImplName(); 311*cdf0e10cSrcweir virtual uno::Sequence<rtl::OUString> getServiceNames(); 312*cdf0e10cSrcweir }; 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir class SwVbaCustomDocumentProperty : public SwVbaBuiltInDocumentProperty 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir public: 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir SwVbaCustomDocumentProperty( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const DocPropInfo& rInfo ); 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL getLinkToContent( ) throw (script::BasicErrorException, uno::RuntimeException); 321*cdf0e10cSrcweir virtual void SAL_CALL setLinkToContent( ::sal_Bool LinkToContent ) throw (script::BasicErrorException, uno::RuntimeException); 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getLinkSource( ) throw (script::BasicErrorException, uno::RuntimeException); 324*cdf0e10cSrcweir virtual void SAL_CALL setLinkSource( const rtl::OUString& LinkSource ) throw (script::BasicErrorException, uno::RuntimeException); 325*cdf0e10cSrcweir virtual void SAL_CALL Delete( ) throw (script::BasicErrorException, uno::RuntimeException); 326*cdf0e10cSrcweir virtual void SAL_CALL setName( const ::rtl::OUString& Name ) throw (script::BasicErrorException, uno::RuntimeException); 327*cdf0e10cSrcweir virtual void SAL_CALL setType( ::sal_Int8 Type ) throw (script::BasicErrorException, uno::RuntimeException); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir }; 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir SwVbaCustomDocumentProperty::SwVbaCustomDocumentProperty( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const DocPropInfo& rInfo ) : SwVbaBuiltInDocumentProperty( xParent, xContext, rInfo ) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir sal_Bool 337*cdf0e10cSrcweir SwVbaCustomDocumentProperty::getLinkToContent( ) throw (script::BasicErrorException, uno::RuntimeException) 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir // #FIXME we need to store the link content somewhere 340*cdf0e10cSrcweir return sal_False; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir void 344*cdf0e10cSrcweir SwVbaCustomDocumentProperty::setLinkToContent( sal_Bool /*bLinkContent*/ ) throw (script::BasicErrorException, uno::RuntimeException) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir rtl::OUString 349*cdf0e10cSrcweir SwVbaCustomDocumentProperty::getLinkSource( ) throw (script::BasicErrorException, uno::RuntimeException) 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir // #FIXME we need to store the link content somewhere 352*cdf0e10cSrcweir return rtl::OUString();; 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir void 356*cdf0e10cSrcweir SwVbaCustomDocumentProperty::setLinkSource( const rtl::OUString& /*rsLinkContent*/ ) throw (script::BasicErrorException, uno::RuntimeException) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir // #FIXME we need to store the link source somewhere 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir void SAL_CALL 362*cdf0e10cSrcweir SwVbaCustomDocumentProperty::setName( const ::rtl::OUString& /*Name*/ ) throw (script::BasicErrorException, uno::RuntimeException) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir // setName on existing property ? 365*cdf0e10cSrcweir // #FIXME 366*cdf0e10cSrcweir // do we need to delete existing property and create a new one? 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir void SAL_CALL 370*cdf0e10cSrcweir SwVbaCustomDocumentProperty::setType( ::sal_Int8 /*Type*/ ) throw (script::BasicErrorException, uno::RuntimeException) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir // setType, do we need to do a conversion? 373*cdf0e10cSrcweir // #FIXME the underlying value needs to be changed to the new type 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir void SAL_CALL 377*cdf0e10cSrcweir SwVbaCustomDocumentProperty::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir uno::Reference< beans::XPropertyContainer > xContainer( mPropInfo.getUnoProperties(), uno::UNO_QUERY_THROW ); 380*cdf0e10cSrcweir xContainer->removeProperty( getName() ); 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::SwVbaBuiltInDocumentProperty( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const DocPropInfo& rInfo ) : SwVbaDocumentProperty_BASE( xParent, xContext ), mPropInfo( rInfo ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir void SAL_CALL 388*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir // not valid for Builtin 391*cdf0e10cSrcweir throw uno::RuntimeException(); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir ::rtl::OUString SAL_CALL 395*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::getName( ) throw (script::BasicErrorException, uno::RuntimeException) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir return mPropInfo.msMSODesc; 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir void SAL_CALL 401*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::setName( const rtl::OUString& ) throw (script::BasicErrorException, uno::RuntimeException) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir // not valid for Builtin 404*cdf0e10cSrcweir throw uno::RuntimeException(); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir ::sal_Int8 SAL_CALL 408*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::getType( ) throw (script::BasicErrorException, uno::RuntimeException) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir return lcl_toMSOPropType( getValue().getValueType() ); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir void SAL_CALL 414*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::setType( ::sal_Int8 /*Type*/ ) throw (script::BasicErrorException, uno::RuntimeException) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir // not valid for Builtin 417*cdf0e10cSrcweir throw uno::RuntimeException(); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir ::sal_Bool SAL_CALL 421*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::getLinkToContent( ) throw (script::BasicErrorException, uno::RuntimeException) 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir return sal_False; // built-in always false 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir void SAL_CALL 427*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::setLinkToContent( ::sal_Bool /*LinkToContent*/ ) throw (script::BasicErrorException, uno::RuntimeException) 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir // not valid for Builtin 430*cdf0e10cSrcweir throw uno::RuntimeException(); 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir uno::Any SAL_CALL 434*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::getValue( ) throw (script::BasicErrorException, uno::RuntimeException) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir uno::Any aRet = mPropInfo.getValue(); 437*cdf0e10cSrcweir if ( !aRet.hasValue() ) 438*cdf0e10cSrcweir throw uno::RuntimeException(); 439*cdf0e10cSrcweir return aRet; 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir void SAL_CALL 443*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::setValue( const uno::Any& Value ) throw (script::BasicErrorException, uno::RuntimeException) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir mPropInfo.setValue( Value ); 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir rtl::OUString SAL_CALL 449*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::getLinkSource( ) throw (script::BasicErrorException, uno::RuntimeException) 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir // not valid for Builtin 452*cdf0e10cSrcweir throw uno::RuntimeException(); 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir void SAL_CALL 456*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::setLinkSource( const rtl::OUString& /*LinkSource*/ ) throw (script::BasicErrorException, uno::RuntimeException) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir // not valid for Builtin 459*cdf0e10cSrcweir throw uno::RuntimeException(); 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir rtl::OUString& 463*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::getServiceImplName() 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaBuiltinDocumentProperty") ); 466*cdf0e10cSrcweir return sImplName; 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir uno::Sequence<rtl::OUString> 470*cdf0e10cSrcweir SwVbaBuiltInDocumentProperty::getServiceNames() 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 473*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 476*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.DocumentProperty" ) ); 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir return aServiceNames; 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper3< com::sun::star::container::XIndexAccess 481*cdf0e10cSrcweir ,com::sun::star::container::XNameAccess 482*cdf0e10cSrcweir ,com::sun::star::container::XEnumerationAccess 483*cdf0e10cSrcweir > PropertiesImpl_BASE; 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir typedef std::hash_map< sal_Int32, uno::Reference< XDocumentProperty > > DocProps; 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1< com::sun::star::container::XEnumeration > DocPropEnumeration_BASE; 488*cdf0e10cSrcweir class DocPropEnumeration : public DocPropEnumeration_BASE 489*cdf0e10cSrcweir { 490*cdf0e10cSrcweir DocProps mDocProps; 491*cdf0e10cSrcweir DocProps::iterator mIt; 492*cdf0e10cSrcweir public: 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir DocPropEnumeration( const DocProps& rProps ) : mDocProps( rProps ), mIt( mDocProps.begin() ) {} 495*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) 496*cdf0e10cSrcweir { 497*cdf0e10cSrcweir return mIt != mDocProps.end(); 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir if ( !hasMoreElements() ) 502*cdf0e10cSrcweir throw container::NoSuchElementException(); 503*cdf0e10cSrcweir return uno::makeAny( mIt++->second ); 504*cdf0e10cSrcweir } 505*cdf0e10cSrcweir }; 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir typedef std::hash_map< rtl::OUString, uno::Reference< XDocumentProperty >, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > DocPropsByName; 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir class BuiltInPropertiesImpl : public PropertiesImpl_BASE 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir protected: 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir uno::Reference< XHelperInterface > m_xParent; 514*cdf0e10cSrcweir uno::Reference< uno::XComponentContext > m_xContext; 515*cdf0e10cSrcweir uno::Reference< frame::XModel > m_xModel; 516*cdf0e10cSrcweir uno::Reference< document::XDocumentInfo > m_xOOOBuiltIns; 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir DocProps mDocProps; 519*cdf0e10cSrcweir DocPropsByName mNamedDocProps; 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir public: 522*cdf0e10cSrcweir BuiltInPropertiesImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : m_xParent( xParent ), m_xContext( xContext ), m_xModel( xModel ) 523*cdf0e10cSrcweir { 524*cdf0e10cSrcweir BuiltInIndexHelper builtIns( m_xModel ); 525*cdf0e10cSrcweir for ( sal_Int32 index = word::WdBuiltInProperty::wdPropertyTitle; index <= word::WdBuiltInProperty::wdPropertyCharsWSpaces; ++index ) 526*cdf0e10cSrcweir { 527*cdf0e10cSrcweir mDocProps[ index ] = new SwVbaBuiltInDocumentProperty( xParent, xContext, builtIns.getDocPropInfoMap()[ index ] ); 528*cdf0e10cSrcweir mNamedDocProps[ mDocProps[ index ]->getName() ] = mDocProps[ index ]; 529*cdf0e10cSrcweir } 530*cdf0e10cSrcweir } 531*cdf0e10cSrcweir // XIndexAccess 532*cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) 533*cdf0e10cSrcweir { 534*cdf0e10cSrcweir return mDocProps.size(); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException ) 537*cdf0e10cSrcweir { 538*cdf0e10cSrcweir // correct the correct by the base class for 1 based indices 539*cdf0e10cSrcweir DocProps::iterator it = mDocProps.find( ++Index ); 540*cdf0e10cSrcweir if ( it == mDocProps.end() ) 541*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 542*cdf0e10cSrcweir return uno::makeAny( it->second ); 543*cdf0e10cSrcweir } 544*cdf0e10cSrcweir virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir if ( !hasByName( aName ) ) 547*cdf0e10cSrcweir throw container::NoSuchElementException(); 548*cdf0e10cSrcweir DocPropsByName::iterator it = mNamedDocProps.find( aName ); 549*cdf0e10cSrcweir return uno::Any( it->second ); 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir uno::Sequence< rtl::OUString > aNames( getCount() ); 555*cdf0e10cSrcweir rtl::OUString* pName = aNames.getArray(); 556*cdf0e10cSrcweir DocPropsByName::iterator it_end = mNamedDocProps.end(); 557*cdf0e10cSrcweir for( DocPropsByName::iterator it = mNamedDocProps.begin(); it != it_end; ++it, ++pName ) 558*cdf0e10cSrcweir *pName = it->first; 559*cdf0e10cSrcweir return aNames; 560*cdf0e10cSrcweir } 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException) 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir DocPropsByName::iterator it = mNamedDocProps.find( aName ); 565*cdf0e10cSrcweir if ( it == mNamedDocProps.end() ) 566*cdf0e10cSrcweir return sal_False; 567*cdf0e10cSrcweir return sal_True; 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir // XElementAccess 570*cdf0e10cSrcweir virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) 571*cdf0e10cSrcweir { 572*cdf0e10cSrcweir return XDocumentProperty::static_type(0); 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir return mDocProps.size() > 0; 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) 579*cdf0e10cSrcweir { 580*cdf0e10cSrcweir return new DocPropEnumeration( mDocProps ); 581*cdf0e10cSrcweir } 582*cdf0e10cSrcweir }; 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir SwVbaBuiltinDocumentProperties::SwVbaBuiltinDocumentProperties( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : SwVbaDocumentproperties_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new BuiltInPropertiesImpl( xParent, xContext, xModel ) ) ), m_xModel( xModel ) 585*cdf0e10cSrcweir { 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir 588*cdf0e10cSrcweir uno::Reference< XDocumentProperty > SAL_CALL 589*cdf0e10cSrcweir SwVbaBuiltinDocumentProperties::Add( const ::rtl::OUString& /*Name*/, ::sal_Bool /*LinkToContent*/, ::sal_Int8 /*Type*/, const uno::Any& /*value*/, const uno::Any& /*LinkSource*/ ) throw (script::BasicErrorException, uno::RuntimeException) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir throw uno::RuntimeException( 592*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("not supported for Builtin properties") ), uno::Reference< uno::XInterface >() ); 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir // XEnumerationAccess 596*cdf0e10cSrcweir uno::Type SAL_CALL 597*cdf0e10cSrcweir SwVbaBuiltinDocumentProperties::getElementType() throw (uno::RuntimeException) 598*cdf0e10cSrcweir { 599*cdf0e10cSrcweir return XDocumentProperty::static_type(0); 600*cdf0e10cSrcweir } 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir uno::Reference< container::XEnumeration > SAL_CALL 603*cdf0e10cSrcweir SwVbaBuiltinDocumentProperties::createEnumeration() throw (uno::RuntimeException) 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); 606*cdf0e10cSrcweir return xEnumAccess->createEnumeration(); 607*cdf0e10cSrcweir } 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir // ScVbaCollectionBaseImpl 610*cdf0e10cSrcweir uno::Any 611*cdf0e10cSrcweir SwVbaBuiltinDocumentProperties::createCollectionObject( const uno::Any& aSource ) 612*cdf0e10cSrcweir { 613*cdf0e10cSrcweir // pass through 614*cdf0e10cSrcweir return aSource; 615*cdf0e10cSrcweir } 616*cdf0e10cSrcweir 617*cdf0e10cSrcweir // XHelperInterface 618*cdf0e10cSrcweir rtl::OUString& 619*cdf0e10cSrcweir SwVbaBuiltinDocumentProperties::getServiceImplName() 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaBuiltinDocumentProperties") ); 622*cdf0e10cSrcweir return sImplName; 623*cdf0e10cSrcweir } 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir uno::Sequence<rtl::OUString> 626*cdf0e10cSrcweir SwVbaBuiltinDocumentProperties::getServiceNames() 627*cdf0e10cSrcweir { 628*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 629*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 632*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.DocumentProperties" ) ); 633*cdf0e10cSrcweir } 634*cdf0e10cSrcweir return aServiceNames; 635*cdf0e10cSrcweir } 636*cdf0e10cSrcweir 637*cdf0e10cSrcweir class CustomPropertiesImpl : public PropertiesImpl_BASE 638*cdf0e10cSrcweir { 639*cdf0e10cSrcweir uno::Reference< XHelperInterface > m_xParent; 640*cdf0e10cSrcweir uno::Reference< uno::XComponentContext > m_xContext; 641*cdf0e10cSrcweir uno::Reference< frame::XModel > m_xModel; 642*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > mxUserDefinedProp; 643*cdf0e10cSrcweir boost::shared_ptr< PropertGetSetHelper > mpPropGetSetHelper; 644*cdf0e10cSrcweir public: 645*cdf0e10cSrcweir CustomPropertiesImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : m_xParent( xParent ), m_xContext( xContext ), m_xModel( xModel ) 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir // suck in the document( custom ) properties 648*cdf0e10cSrcweir uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( m_xModel, uno::UNO_QUERY_THROW ); 649*cdf0e10cSrcweir uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW ); 650*cdf0e10cSrcweir uno::Reference< document::XDocumentProperties > xDocProp( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW ); 651*cdf0e10cSrcweir mxUserDefinedProp.set( xDocProp->getUserDefinedProperties(), uno::UNO_QUERY_THROW ); 652*cdf0e10cSrcweir mpPropGetSetHelper.reset( new CustomPropertyGetSetHelper( m_xModel ) ); 653*cdf0e10cSrcweir }; 654*cdf0e10cSrcweir // XIndexAccess 655*cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) 656*cdf0e10cSrcweir { 657*cdf0e10cSrcweir return mxUserDefinedProp->getPropertySetInfo()->getProperties().getLength(); 658*cdf0e10cSrcweir } 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException ) 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir uno::Sequence< beans::Property > aProps = mxUserDefinedProp->getPropertySetInfo()->getProperties(); 663*cdf0e10cSrcweir if ( Index >= aProps.getLength() ) 664*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 665*cdf0e10cSrcweir // How to determine type e.g Date? ( com.sun.star.util.DateTime ) 666*cdf0e10cSrcweir DocPropInfo aPropInfo = DocPropInfo::createDocPropInfo( aProps[ Index ].Name, aProps[ Index ].Name, mpPropGetSetHelper ); 667*cdf0e10cSrcweir return uno::makeAny( uno::Reference< XDocumentProperty >( new SwVbaCustomDocumentProperty( m_xParent, m_xContext, aPropInfo ) ) ); 668*cdf0e10cSrcweir } 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir if ( !hasByName( aName ) ) 673*cdf0e10cSrcweir throw container::NoSuchElementException(); 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir DocPropInfo aPropInfo = DocPropInfo::createDocPropInfo( aName, aName, mpPropGetSetHelper ); 676*cdf0e10cSrcweir return uno::makeAny( uno::Reference< XDocumentProperty >( new SwVbaCustomDocumentProperty( m_xParent, m_xContext, aPropInfo ) ) ); 677*cdf0e10cSrcweir } 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) 680*cdf0e10cSrcweir { 681*cdf0e10cSrcweir uno::Sequence< beans::Property > aProps = mxUserDefinedProp->getPropertySetInfo()->getProperties(); 682*cdf0e10cSrcweir uno::Sequence< rtl::OUString > aNames( aProps.getLength() ); 683*cdf0e10cSrcweir rtl::OUString* pString = aNames.getArray(); 684*cdf0e10cSrcweir rtl::OUString* pEnd = ( pString + aNames.getLength() ); 685*cdf0e10cSrcweir beans::Property* pProp = aProps.getArray(); 686*cdf0e10cSrcweir for ( ; pString != pEnd; ++pString, ++pProp ) 687*cdf0e10cSrcweir *pString = pProp->Name; 688*cdf0e10cSrcweir return aNames; 689*cdf0e10cSrcweir } 690*cdf0e10cSrcweir 691*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException) 692*cdf0e10cSrcweir { 693*cdf0e10cSrcweir OSL_TRACE("hasByName(%s) returns %d", rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr(), mxUserDefinedProp->getPropertySetInfo()->hasPropertyByName( aName ) ); 694*cdf0e10cSrcweir return mxUserDefinedProp->getPropertySetInfo()->hasPropertyByName( aName ); 695*cdf0e10cSrcweir } 696*cdf0e10cSrcweir 697*cdf0e10cSrcweir // XElementAccess 698*cdf0e10cSrcweir virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) 699*cdf0e10cSrcweir { 700*cdf0e10cSrcweir return XDocumentProperty::static_type(0); 701*cdf0e10cSrcweir } 702*cdf0e10cSrcweir 703*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) 704*cdf0e10cSrcweir { 705*cdf0e10cSrcweir return getCount() > 0; 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) 709*cdf0e10cSrcweir { 710*cdf0e10cSrcweir // create a map of properties ( the key doesn't matter ) 711*cdf0e10cSrcweir OSL_TRACE("Creating an enumeration"); 712*cdf0e10cSrcweir sal_Int32 key = 0; 713*cdf0e10cSrcweir sal_Int32 nElem = getCount(); 714*cdf0e10cSrcweir DocProps simpleDocPropSnapShot; 715*cdf0e10cSrcweir for ( ; key < nElem; ++key ) 716*cdf0e10cSrcweir simpleDocPropSnapShot[ key ].set( getByIndex( key ), uno::UNO_QUERY_THROW ); 717*cdf0e10cSrcweir OSL_TRACE("After creating the enumeration"); 718*cdf0e10cSrcweir return new DocPropEnumeration( simpleDocPropSnapShot ); 719*cdf0e10cSrcweir } 720*cdf0e10cSrcweir 721*cdf0e10cSrcweir void addProp( const ::rtl::OUString& Name, ::sal_Int8 /*Type*/, const uno::Any& Value ) 722*cdf0e10cSrcweir { 723*cdf0e10cSrcweir sal_Int16 attributes = 128; 724*cdf0e10cSrcweir uno::Reference< beans::XPropertyContainer > xContainer( mxUserDefinedProp, uno::UNO_QUERY_THROW ); 725*cdf0e10cSrcweir // TODO fixme, perform the necessary Type Value conversions 726*cdf0e10cSrcweir xContainer->addProperty( Name, attributes, Value ); 727*cdf0e10cSrcweir } 728*cdf0e10cSrcweir 729*cdf0e10cSrcweir }; 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir SwVbaCustomDocumentProperties::SwVbaCustomDocumentProperties( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : SwVbaBuiltinDocumentProperties( xParent, xContext, xModel ) 733*cdf0e10cSrcweir { 734*cdf0e10cSrcweir // replace the m_xIndexAccess implementation ( we need a virtual init ) 735*cdf0e10cSrcweir m_xIndexAccess.set( new CustomPropertiesImpl( xParent, xContext, xModel ) ); 736*cdf0e10cSrcweir m_xNameAccess.set( m_xIndexAccess, uno::UNO_QUERY_THROW ); 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir uno::Reference< XDocumentProperty > SAL_CALL 740*cdf0e10cSrcweir SwVbaCustomDocumentProperties::Add( const ::rtl::OUString& Name, ::sal_Bool LinkToContent, ::sal_Int8 Type, const uno::Any& Value, const uno::Any& LinkSource ) throw (script::BasicErrorException, uno::RuntimeException) 741*cdf0e10cSrcweir { 742*cdf0e10cSrcweir CustomPropertiesImpl* pCustomProps = dynamic_cast< CustomPropertiesImpl* > ( m_xIndexAccess.get() ); 743*cdf0e10cSrcweir uno::Reference< XDocumentProperty > xDocProp; 744*cdf0e10cSrcweir if ( pCustomProps ) 745*cdf0e10cSrcweir { 746*cdf0e10cSrcweir rtl::OUString sLinkSource; 747*cdf0e10cSrcweir pCustomProps->addProp( Name, Type, Value ); 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir xDocProp.set( m_xNameAccess->getByName( Name ), uno::UNO_QUERY_THROW ); 750*cdf0e10cSrcweir xDocProp->setLinkToContent( LinkToContent ); 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir if ( LinkSource >>= sLinkSource ) 753*cdf0e10cSrcweir xDocProp->setLinkSource( sLinkSource ); 754*cdf0e10cSrcweir } 755*cdf0e10cSrcweir return xDocProp; 756*cdf0e10cSrcweir } 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir // XHelperInterface 759*cdf0e10cSrcweir rtl::OUString& 760*cdf0e10cSrcweir SwVbaCustomDocumentProperties::getServiceImplName() 761*cdf0e10cSrcweir { 762*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaCustomDocumentProperties") ); 763*cdf0e10cSrcweir return sImplName; 764*cdf0e10cSrcweir } 765