22 #include <com/sun/star/document/XDocumentProperties.hpp>
23 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
24 #include <com/sun/star/beans/NamedValue.hpp>
25 #include <com/sun/star/beans/XPropertyContainer.hpp>
26 #include <ooo/vba/word/WdBuiltInProperty.hpp>
27 #include <ooo/vba/office/MsoDocProperties.hpp>
39 sal_Int16 msoType = office::MsoDocProperties::msoPropertyTypeString;
41 switch ( aType.getTypeClass() )
43 case uno::TypeClass_BOOLEAN:
44 msoType = office::MsoDocProperties::msoPropertyTypeBoolean;
46 case uno::TypeClass_FLOAT:
47 msoType = office::MsoDocProperties::msoPropertyTypeFloat;
49 case uno::TypeClass_STRUCT:
50 msoType = office::MsoDocProperties::msoPropertyTypeDate;
52 case uno::TypeClass_BYTE:
53 case uno::TypeClass_SHORT:
54 case uno::TypeClass_LONG:
55 case uno::TypeClass_HYPER:
56 msoType = office::MsoDocProperties::msoPropertyTypeNumber;
59 throw lang::IllegalArgumentException();
66 class PropertGetSetHelper
69 uno::Reference< frame::XModel >
m_xModel;
70 uno::Reference<document::XDocumentProperties> m_xDocProps;
72 explicit PropertGetSetHelper(
const uno::Reference< frame::XModel >& xModel ):m_xModel( xModel )
74 uno::Reference<document::XDocumentPropertiesSupplier>
const
75 xDocPropSupp(m_xModel, uno::UNO_QUERY_THROW);
76 m_xDocProps.set(xDocPropSupp->getDocumentProperties(),
79 virtual ~PropertGetSetHelper() {}
82 uno::Reference< beans::XPropertySet > getUserDefinedProperties() {
83 return uno::Reference<beans::XPropertySet>(
84 m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
89 class BuiltinPropertyGetSetHelper :
public PropertGetSetHelper
92 explicit BuiltinPropertyGetSetHelper(
const uno::Reference< frame::XModel >& xModel ) :PropertGetSetHelper( xModel )
97 if ( rPropName ==
"EditingDuration" )
99 sal_Int32
const nSecs = m_xDocProps->getEditingDuration();
102 else if (
"Title" == rPropName)
104 return uno::Any(m_xDocProps->getTitle());
106 else if (
"Subject" == rPropName)
108 return uno::Any(m_xDocProps->getSubject());
110 else if (
"Author" == rPropName)
112 return uno::Any(m_xDocProps->getAuthor());
114 else if (
"Keywords" == rPropName)
116 return uno::Any(m_xDocProps->getKeywords());
118 else if (
"Description" == rPropName)
120 return uno::Any(m_xDocProps->getDescription());
122 else if (
"Template" == rPropName)
124 return uno::Any(m_xDocProps->getTemplateName());
126 else if (
"ModifiedBy" == rPropName)
128 return uno::Any(m_xDocProps->getModifiedBy());
130 else if (
"Generator" == rPropName)
132 return uno::Any(m_xDocProps->getGenerator());
134 else if (
"PrintDate" == rPropName)
136 return uno::Any(m_xDocProps->getPrintDate());
138 else if (
"CreationDate" == rPropName)
140 return uno::Any(m_xDocProps->getCreationDate());
142 else if (
"ModifyDate" == rPropName)
144 return uno::Any(m_xDocProps->getModificationDate());
146 else if (
"AutoloadURL" == rPropName)
148 return uno::Any(m_xDocProps->getAutoloadURL());
153 return getUserDefinedProperties()->getPropertyValue(rPropName);
158 if (
"EditingDuration" == rPropName)
161 if (aValue >>= nMins)
163 m_xDocProps->setEditingDuration(nMins * 60);
166 else if (
"Title" == rPropName)
171 m_xDocProps->setTitle(str);
174 else if (
"Subject" == rPropName)
179 m_xDocProps->setSubject(str);
182 else if (
"Author" == rPropName)
187 m_xDocProps->setAuthor(str);
190 else if (
"Keywords" == rPropName)
192 uno::Sequence<OUString> keywords;
193 if (aValue >>= keywords)
195 m_xDocProps->setKeywords(keywords);
198 else if (
"Description" == rPropName)
203 m_xDocProps->setDescription(str);
206 else if (
"Template" == rPropName)
211 m_xDocProps->setTemplateName(str);
214 else if (
"ModifiedBy" == rPropName)
219 m_xDocProps->setModifiedBy(str);
222 else if (
"Generator" == rPropName)
227 return m_xDocProps->setGenerator(str);
230 else if (
"PrintDate" == rPropName)
235 m_xDocProps->setPrintDate(dt);
238 else if (
"CreationDate" == rPropName)
243 m_xDocProps->setCreationDate(dt);
246 else if (
"ModifyDate" == rPropName)
251 m_xDocProps->setModificationDate(dt);
254 else if (
"AutoloadURL" == rPropName)
259 m_xDocProps->setAutoloadURL(str);
265 getUserDefinedProperties()->setPropertyValue(rPropName, aValue);
270 class CustomPropertyGetSetHelper :
public BuiltinPropertyGetSetHelper
273 explicit CustomPropertyGetSetHelper(
const uno::Reference< frame::XModel >& xModel ) :BuiltinPropertyGetSetHelper( xModel )
278 return getUserDefinedProperties()->getPropertyValue(rPropName);
281 const OUString& rPropName,
const uno::Any& rValue)
override
283 return getUserDefinedProperties()->setPropertyValue(rPropName, rValue);
287 class StatisticPropertyGetSetHelper :
public PropertGetSetHelper
290 uno::Reference< beans::XPropertySet > mxModelProps;
292 explicit StatisticPropertyGetSetHelper(
const uno::Reference< frame::XModel >& xModel ) :PropertGetSetHelper( xModel ) , mpDocShell( nullptr )
294 mxModelProps.set( m_xModel, uno::UNO_QUERY_THROW );
303 return mxModelProps->getPropertyValue( rPropName );
305 catch (
const uno::Exception&)
310 if ( rPropName ==
"LineCount" )
323 uno::Sequence< beans::NamedValue >
const stats(
324 m_xDocProps->getDocumentStatistics());
326 auto pStat = std::find_if(stats.begin(), stats.end(),
327 [&rPropName](
const beans::NamedValue& rStat) {
return rPropName == rStat.Name; });
328 if (pStat == stats.end())
329 throw uno::RuntimeException();
331 aReturn = pStat->
Value;
338 uno::Sequence< beans::NamedValue > stats(
339 m_xDocProps->getDocumentStatistics());
341 auto [
begin,
end] = asNonConstRange(stats);
342 auto pStat = std::find_if(begin, end,
343 [&rPropName](
const beans::NamedValue& rStat) {
return rPropName == rStat.Name; });
346 pStat->Value = aValue;
347 m_xDocProps->setDocumentStatistics(stats);
356 OUString msOOOPropName;
357 std::shared_ptr< PropertGetSetHelper > mpPropGetSetHelper;
359 static DocPropInfo createDocPropInfo(
const OUString& sDesc,
const OUString& sPropName, std::shared_ptr< PropertGetSetHelper >
const & rHelper )
362 aItem.msMSODesc = sDesc;
363 aItem.msOOOPropName = sPropName;
364 aItem.mpPropGetSetHelper = rHelper;
368 static DocPropInfo createDocPropInfo(
const char* sDesc,
const char* sPropName, std::shared_ptr< PropertGetSetHelper >
const & rHelper )
370 return createDocPropInfo( OUString::createFromAscii( sDesc ), OUString::createFromAscii( sPropName ), rHelper );
374 if ( mpPropGetSetHelper )
375 return mpPropGetSetHelper->getPropertyValue( msOOOPropName );
380 if ( mpPropGetSetHelper )
381 mpPropGetSetHelper->setPropertyValue( msOOOPropName, rValue );
383 uno::Reference< beans::XPropertySet > getUserDefinedProperties()
385 uno::Reference< beans::XPropertySet > xProps;
386 if ( mpPropGetSetHelper )
387 return mpPropGetSetHelper->getUserDefinedProperties();
398 class BuiltInIndexHelper
400 MSOIndexToOODocPropInfo m_docPropInfoMap;
403 explicit BuiltInIndexHelper(
const uno::Reference< frame::XModel >& xModel )
405 auto aStandardHelper = std::make_shared<BuiltinPropertyGetSetHelper>( xModel );
406 auto aUsingStatsHelper = std::make_shared<StatisticPropertyGetSetHelper>( xModel );
408 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTitle ] = DocPropInfo::createDocPropInfo(
"Title",
"Title", aStandardHelper );
409 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySubject ] = DocPropInfo::createDocPropInfo(
"Subject",
"Subject", aStandardHelper );
410 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyAuthor ] = DocPropInfo::createDocPropInfo(
"Author",
"Author", aStandardHelper );
411 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyKeywords ] = DocPropInfo::createDocPropInfo(
"Keywords",
"Keywords", aStandardHelper );
412 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyComments ] = DocPropInfo::createDocPropInfo(
"Comments",
"Description", aStandardHelper );
413 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTemplate ] = DocPropInfo::createDocPropInfo(
"Template",
"Template", aStandardHelper );
414 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyLastAuthor ] = DocPropInfo::createDocPropInfo(
"Last author",
"ModifiedBy", aStandardHelper );
415 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyRevision ] = DocPropInfo::createDocPropInfo(
"Revision number",
"EditingCycles", aStandardHelper );
416 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyAppName ] = DocPropInfo::createDocPropInfo(
"Application name",
"Generator", aStandardHelper );
417 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeLastPrinted ] = DocPropInfo::createDocPropInfo(
"Last print date",
"PrintDate", aStandardHelper );
418 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeCreated ] = DocPropInfo::createDocPropInfo(
"Creation date",
"CreationDate", aStandardHelper );
419 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeLastSaved ] = DocPropInfo::createDocPropInfo(
"Last save time",
"ModifyDate", aStandardHelper );
420 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyVBATotalEdit ] = DocPropInfo::createDocPropInfo(
"Total editing time",
"EditingDuration", aStandardHelper );
421 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyPages ] = DocPropInfo::createDocPropInfo(
"Number of pages",
"PageCount", aUsingStatsHelper );
422 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyWords ] = DocPropInfo::createDocPropInfo(
"Number of words",
"WordCount", aUsingStatsHelper );
423 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCharacters ] = DocPropInfo::createDocPropInfo(
"Number of characters",
"CharacterCount", aUsingStatsHelper );
424 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySecurity ] = DocPropInfo::createDocPropInfo(
"Security",
"", aStandardHelper );
425 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCategory ] = DocPropInfo::createDocPropInfo(
"Category",
"Category", aStandardHelper );
426 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyFormat ] = DocPropInfo::createDocPropInfo(
"Format",
"", aStandardHelper );
427 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyManager ] = DocPropInfo::createDocPropInfo(
"Manager",
"Manager", aStandardHelper );
428 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCompany ] = DocPropInfo::createDocPropInfo(
"Company",
"Company", aStandardHelper );
429 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyBytes ] = DocPropInfo::createDocPropInfo(
"Number of bytes",
"", aStandardHelper );
430 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyLines ] = DocPropInfo::createDocPropInfo(
"Number of lines",
"LineCount", aUsingStatsHelper );
431 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyParas ] = DocPropInfo::createDocPropInfo(
"Number of paragraphs",
"ParagraphCount", aUsingStatsHelper );
432 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySlides ] = DocPropInfo::createDocPropInfo(
"Number of slides",
"" , aStandardHelper );
433 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyNotes ] = DocPropInfo::createDocPropInfo(
"Number of notes",
"", aStandardHelper );
434 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyHiddenSlides ] = DocPropInfo::createDocPropInfo(
"Number of hidden Slides",
"", aStandardHelper );
435 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyMMClips ] = DocPropInfo::createDocPropInfo(
"Number of multimedia clips",
"", aStandardHelper );
436 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyHyperlinkBase ] = DocPropInfo::createDocPropInfo(
"Hyperlink base",
"AutoloadURL", aStandardHelper );
437 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCharsWSpaces ] = DocPropInfo::createDocPropInfo(
"Number of characters (with spaces)",
"", aStandardHelper );
440 MSOIndexToOODocPropInfo& getDocPropInfoMap() {
return m_docPropInfoMap; }
449 class SwVbaBuiltInDocumentProperty :
public SwVbaDocumentProperty_BASE
452 DocPropInfo mPropInfo;
454 SwVbaBuiltInDocumentProperty(
const uno::Reference< ov::XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const DocPropInfo& rInfo );
456 virtual void SAL_CALL
Delete( )
override;
457 virtual OUString SAL_CALL getName( )
override;
458 virtual void SAL_CALL setName(
const OUString&
Name )
override;
459 virtual ::sal_Int8 SAL_CALL
getType( )
override;
460 virtual void SAL_CALL setType( ::
sal_Int8 Type )
override;
461 virtual sal_Bool SAL_CALL getLinkToContent( )
override;
462 virtual void SAL_CALL setLinkToContent(
sal_Bool LinkToContent )
override;
465 virtual OUString SAL_CALL getLinkSource( )
override;
466 virtual void SAL_CALL setLinkSource(
const OUString& LinkSource )
override;
468 virtual OUString SAL_CALL getDefaultPropertyName( )
override {
return "Value"; }
470 virtual OUString getServiceImplName()
override;
471 virtual uno::Sequence<OUString> getServiceNames()
override;
474 class SwVbaCustomDocumentProperty :
public SwVbaBuiltInDocumentProperty
478 SwVbaCustomDocumentProperty(
const uno::Reference< ov::XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const DocPropInfo& rInfo );
480 virtual sal_Bool SAL_CALL getLinkToContent( )
override;
481 virtual void SAL_CALL setLinkToContent(
sal_Bool LinkToContent )
override;
483 virtual OUString SAL_CALL getLinkSource( )
override;
484 virtual void SAL_CALL setLinkSource(
const OUString& LinkSource )
override;
485 virtual void SAL_CALL
Delete( )
override;
486 virtual void SAL_CALL setName(
const OUString&
Name )
override;
487 virtual void SAL_CALL setType( ::
sal_Int8 Type )
override;
493 SwVbaCustomDocumentProperty::SwVbaCustomDocumentProperty(
const uno::Reference< ov::XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const DocPropInfo& rInfo ) : SwVbaBuiltInDocumentProperty( xParent, xContext, rInfo )
498 SwVbaCustomDocumentProperty::getLinkToContent( )
505 SwVbaCustomDocumentProperty::setLinkToContent(
sal_Bool )
510 SwVbaCustomDocumentProperty::getLinkSource( )
517 SwVbaCustomDocumentProperty::setLinkSource(
const OUString& )
523 SwVbaCustomDocumentProperty::setName(
const OUString& )
531 SwVbaCustomDocumentProperty::setType( ::
sal_Int8 )
538 SwVbaCustomDocumentProperty::Delete( )
540 uno::Reference< beans::XPropertyContainer > xContainer(
541 mPropInfo.getUserDefinedProperties(), uno::UNO_QUERY_THROW);
542 xContainer->removeProperty( getName() );
545 SwVbaBuiltInDocumentProperty::SwVbaBuiltInDocumentProperty(
const uno::Reference< ov::XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const DocPropInfo& rInfo ) : SwVbaDocumentProperty_BASE( xParent, xContext ), mPropInfo( rInfo )
550 SwVbaBuiltInDocumentProperty::Delete( )
553 throw uno::RuntimeException();
557 SwVbaBuiltInDocumentProperty::getName( )
559 return mPropInfo.msMSODesc;
563 SwVbaBuiltInDocumentProperty::setName(
const OUString& )
566 throw uno::RuntimeException();
570 SwVbaBuiltInDocumentProperty::getType( )
576 SwVbaBuiltInDocumentProperty::setType( ::
sal_Int8 )
579 throw uno::RuntimeException();
583 SwVbaBuiltInDocumentProperty::getLinkToContent( )
589 SwVbaBuiltInDocumentProperty::setLinkToContent(
sal_Bool )
592 throw uno::RuntimeException();
596 SwVbaBuiltInDocumentProperty::getValue( )
598 uno::Any aRet = mPropInfo.getValue();
600 throw uno::RuntimeException();
605 SwVbaBuiltInDocumentProperty::setValue(
const uno::Any& Value )
611 SwVbaBuiltInDocumentProperty::getLinkSource( )
614 throw uno::RuntimeException();
618 SwVbaBuiltInDocumentProperty::setLinkSource(
const OUString& )
621 throw uno::RuntimeException();
625 SwVbaBuiltInDocumentProperty::getServiceImplName()
627 return "SwVbaBuiltinDocumentProperty";
630 uno::Sequence<OUString>
631 SwVbaBuiltInDocumentProperty::getServiceNames()
635 "ooo.vba.word.DocumentProperty"
639 typedef ::cppu::WeakImplHelper< css::container::XIndexAccess
640 ,css::container::XNameAccess
641 ,css::container::XEnumerationAccess
644 typedef std::unordered_map< sal_Int32, uno::Reference< XDocumentProperty > >
DocProps;
648 class DocPropEnumeration :
public ::cppu::WeakImplHelper< css::container::XEnumeration >
651 DocProps::iterator mIt;
654 explicit DocPropEnumeration( DocProps&& rProps ) : mDocProps( std::move(rProps) ), mIt( mDocProps.begin() ) {}
655 virtual sal_Bool SAL_CALL hasMoreElements( )
override
657 return mIt != mDocProps.end();
659 virtual uno::Any SAL_CALL nextElement( )
override
661 if ( !hasMoreElements() )
662 throw container::NoSuchElementException();
669 typedef std::unordered_map< OUString, uno::Reference< XDocumentProperty > >
DocPropsByName;
677 uno::Reference< frame::XModel > m_xModel;
680 DocPropsByName mNamedDocProps;
683 BuiltInPropertiesImpl(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< frame::XModel >& xModel ) : m_xModel( xModel )
685 BuiltInIndexHelper builtIns( m_xModel );
686 for ( sal_Int32
index = word::WdBuiltInProperty::wdPropertyTitle;
index <= word::WdBuiltInProperty::wdPropertyCharsWSpaces; ++
index )
688 mDocProps[
index ] =
new SwVbaBuiltInDocumentProperty( xParent, xContext, builtIns.getDocPropInfoMap()[
index ] );
689 mNamedDocProps[ mDocProps[
index ]->getName() ] = mDocProps[
index ];
693 virtual ::sal_Int32 SAL_CALL getCount( )
override
695 return mDocProps.size();
697 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
700 DocProps::iterator it = mDocProps.find( ++Index );
701 if ( it == mDocProps.end() )
702 throw lang::IndexOutOfBoundsException();
705 virtual uno::Any SAL_CALL getByName(
const OUString&
aName )
override
707 if ( !hasByName( aName ) )
708 throw container::NoSuchElementException();
709 DocPropsByName::iterator it = mNamedDocProps.find( aName );
713 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
715 uno::Sequence< OUString > aNames( getCount() );
716 OUString*
pName = aNames.getArray();
717 for (
const auto& rEntry : mNamedDocProps)
719 *pName = rEntry.first;
725 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override
727 DocPropsByName::iterator it = mNamedDocProps.find( aName );
728 if ( it == mNamedDocProps.end() )
733 virtual uno::Type SAL_CALL getElementType( )
override
737 virtual sal_Bool SAL_CALL hasElements( )
override
739 return !mDocProps.empty();
741 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
743 return new DocPropEnumeration( std::unordered_map(mDocProps) );
753 uno::Reference< XDocumentProperty > SAL_CALL
756 throw uno::RuntimeException(
"not supported for Builtin properties" );
766 uno::Reference< container::XEnumeration > SAL_CALL
769 uno::Reference< container::XEnumerationAccess > xEnumAccess(
m_xIndexAccess, uno::UNO_QUERY_THROW );
770 return xEnumAccess->createEnumeration();
785 return "SwVbaBuiltinDocumentProperties";
788 uno::Sequence<OUString>
793 "ooo.vba.word.DocumentProperties"
802 uno::Reference< XHelperInterface > m_xParent;
803 uno::Reference< uno::XComponentContext >
m_xContext;
804 uno::Reference< frame::XModel > m_xModel;
805 uno::Reference< beans::XPropertySet > mxUserDefinedProp;
806 std::shared_ptr< PropertGetSetHelper > mpPropGetSetHelper;
808 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 )
811 mpPropGetSetHelper = std::make_shared<CustomPropertyGetSetHelper>( m_xModel );
812 mxUserDefinedProp.set(mpPropGetSetHelper->getUserDefinedProperties(),
816 virtual ::sal_Int32 SAL_CALL getCount( )
override
818 return mxUserDefinedProp->getPropertySetInfo()->getProperties().getLength();
821 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
823 uno::Sequence< beans::Property > aProps = mxUserDefinedProp->getPropertySetInfo()->getProperties();
824 if ( Index >= aProps.getLength() )
825 throw lang::IndexOutOfBoundsException();
827 DocPropInfo aPropInfo = DocPropInfo::createDocPropInfo( aProps[ Index ].Name, aProps[ Index ].Name, mpPropGetSetHelper );
828 return uno::Any( uno::Reference< XDocumentProperty >(
new SwVbaCustomDocumentProperty( m_xParent, m_xContext, aPropInfo ) ) );
831 virtual uno::Any SAL_CALL getByName(
const OUString& aName )
override
833 if ( !hasByName( aName ) )
834 throw container::NoSuchElementException();
836 DocPropInfo aPropInfo = DocPropInfo::createDocPropInfo( aName, aName, mpPropGetSetHelper );
837 return uno::Any( uno::Reference< XDocumentProperty >(
new SwVbaCustomDocumentProperty( m_xParent, m_xContext, aPropInfo ) ) );
840 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
842 const uno::Sequence< beans::Property > aProps = mxUserDefinedProp->getPropertySetInfo()->getProperties();
843 uno::Sequence< OUString > aNames( aProps.getLength() );
844 std::transform(aProps.begin(), aProps.end(), aNames.getArray(),
845 [](
const beans::Property& rProp) -> OUString {
return rProp.Name; });
849 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override
851 SAL_INFO(
"sw.vba",
"hasByName(" << aName <<
") returns " << mxUserDefinedProp->getPropertySetInfo()->hasPropertyByName( aName ) );
852 return mxUserDefinedProp->getPropertySetInfo()->hasPropertyByName( aName );
856 virtual uno::Type SAL_CALL getElementType( )
override
861 virtual sal_Bool SAL_CALL hasElements( )
override
863 return getCount() > 0;
866 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
869 SAL_INFO(
"sw.vba",
"Creating an enumeration");
871 sal_Int32 nElem = getCount();
872 DocProps simpleDocPropSnapShot;
873 for ( ; key < nElem; ++key )
874 simpleDocPropSnapShot[ key ].
set( getByIndex( key ), uno::UNO_QUERY_THROW );
875 SAL_INFO(
"sw.vba",
"After creating the enumeration");
876 return new DocPropEnumeration( std::move(simpleDocPropSnapShot) );
879 void addProp(
const OUString& Name,
const uno::Any& Value )
881 uno::Reference< beans::XPropertyContainer > xContainer( mxUserDefinedProp, uno::UNO_QUERY_THROW );
883 xContainer->addProperty( Name, sal_Int16(128), Value );
893 m_xIndexAccess.set(
new CustomPropertiesImpl( xParent, xContext, xModel ) );
897 uno::Reference< XDocumentProperty > SAL_CALL
900 CustomPropertiesImpl* pCustomProps =
dynamic_cast< CustomPropertiesImpl*
> (
m_xIndexAccess.get() );
901 uno::Reference< XDocumentProperty > xDocProp;
904 OUString sLinkSource;
905 pCustomProps->addProp( Name, Value );
907 xDocProp.set(
m_xNameAccess->getByName( Name ), uno::UNO_QUERY_THROW );
908 xDocProp->setLinkToContent( LinkToContent );
910 if ( LinkSource >>= sLinkSource )
911 xDocProp->setLinkSource( sLinkSource );
920 return "SwVbaCustomDocumentProperties";
std::unordered_map< OUString, uno::Reference< XDocumentProperty > > DocPropsByName
RegError REGISTRY_CALLTYPE setValue(RegKeyHandle hKey, rtl_uString *keyName, RegValueType valueType, RegValue pData, sal_uInt32 valueSize)
InheritedHelperInterfaceWeakImpl< ooo::vba::XDocumentProperty > SwVbaDocumentProperty_BASE
Reference< frame::XModel > m_xModel
virtual OUString getServiceImplName() override
sal_uInt16 GetLineCount()
static sal_Int8 lcl_toMSOPropType(const uno::Type &aType)
virtual css::uno::Reference< ::ooo::vba::XDocumentProperty > SAL_CALL Add(const OUString &Name, sal_Bool LinkToContent,::sal_Int8 Type, const css::uno::Any &Value, const css::uno::Any &LinkSource) override
bool getType(BSTR name, Type &type)
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual css::uno::Type SAL_CALL getElementType() override
SwVbaCustomDocumentProperties(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel > &xDocument)
Sequence< OUString > aServiceNames
::cppu::WeakImplHelper< css::container::XIndexAccess,css::container::XNameAccess,css::container::XEnumerationAccess > PropertiesImpl_BASE
exports com.sun.star. container
enumrange< T >::Iterator begin(enumrange< T >)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual OUString getServiceImplName() override
virtual css::uno::Reference< ::ooo::vba::XDocumentProperty > SAL_CALL Add(const OUString &Name, sal_Bool LinkToContent,::sal_Int8 Type, const css::uno::Any &Value, const css::uno::Any &LinkSource) override
#define TOOLS_WARN_EXCEPTION(area, stream)
std::unordered_map< sal_Int32, uno::Reference< XDocumentProperty > > DocProps
css::uno::Reference< css::container::XNameAccess > m_xNameAccess
css::uno::Type const & get()
void setValue(Type type, object value)
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
css::beans::Optional< css::uno::Any > getValue(std::u16string_view id)
bool setPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
std::unordered_map< sal_Int32, DocPropInfo > MSOIndexToOODocPropInfo
enumrange< T >::Iterator end(enumrange< T >)
SwDocShell * getDocShell(const uno::Reference< frame::XModel > &xModel)
SwVbaBuiltinDocumentProperties(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel > &xDocument)
#define SAL_INFO(area, stream)
SwFEShell * GetFEShell()
For Core - it knows the DocShell but not the WrtShell!
Reference< XComponentContext > m_xContext
void set(css::uno::UnoInterfaceReference const &value)