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();
100 return uno::makeAny( nSecs/60 );
102 else if (
"Title" == rPropName)
104 return uno::makeAny(m_xDocProps->getTitle());
106 else if (
"Subject" == rPropName)
108 return uno::makeAny(m_xDocProps->getSubject());
110 else if (
"Author" == rPropName)
112 return uno::makeAny(m_xDocProps->getAuthor());
114 else if (
"Keywords" == rPropName)
116 return uno::makeAny(m_xDocProps->getKeywords());
118 else if (
"Description" == rPropName)
120 return uno::makeAny(m_xDocProps->getDescription());
122 else if (
"Template" == rPropName)
124 return uno::makeAny(m_xDocProps->getTemplateName());
126 else if (
"ModifiedBy" == rPropName)
128 return uno::makeAny(m_xDocProps->getModifiedBy());
130 else if (
"Generator" == rPropName)
132 return uno::makeAny(m_xDocProps->getGenerator());
134 else if (
"PrintDate" == rPropName)
136 return uno::makeAny(m_xDocProps->getPrintDate());
138 else if (
"CreationDate" == rPropName)
140 return uno::makeAny(m_xDocProps->getCreationDate());
142 else if (
"ModifyDate" == rPropName)
144 return uno::makeAny(m_xDocProps->getModificationDate());
146 else if (
"AutoloadURL" == rPropName)
148 return uno::makeAny(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 pStat = std::find_if(stats.begin(), stats.end(),
342 [&rPropName](
const beans::NamedValue& rStat) {
return rPropName == rStat.Name; });
343 if (pStat != stats.end())
345 pStat->Value = aValue;
346 m_xDocProps->setDocumentStatistics(stats);
355 OUString msOOOPropName;
356 std::shared_ptr< PropertGetSetHelper > mpPropGetSetHelper;
358 static DocPropInfo createDocPropInfo(
const OUString& sDesc,
const OUString& sPropName, std::shared_ptr< PropertGetSetHelper >
const & rHelper )
361 aItem.msMSODesc = sDesc;
362 aItem.msOOOPropName = sPropName;
363 aItem.mpPropGetSetHelper = rHelper;
367 static DocPropInfo createDocPropInfo(
const char* sDesc,
const char* sPropName, std::shared_ptr< PropertGetSetHelper >
const & rHelper )
369 return createDocPropInfo( OUString::createFromAscii( sDesc ), OUString::createFromAscii( sPropName ), rHelper );
373 if ( mpPropGetSetHelper )
374 return mpPropGetSetHelper->getPropertyValue( msOOOPropName );
379 if ( mpPropGetSetHelper )
380 mpPropGetSetHelper->setPropertyValue( msOOOPropName, rValue );
382 uno::Reference< beans::XPropertySet > getUserDefinedProperties()
384 uno::Reference< beans::XPropertySet > xProps;
385 if ( mpPropGetSetHelper )
386 return mpPropGetSetHelper->getUserDefinedProperties();
397 class BuiltInIndexHelper
399 MSOIndexToOODocPropInfo m_docPropInfoMap;
402 explicit BuiltInIndexHelper(
const uno::Reference< frame::XModel >& xModel )
404 auto aStandardHelper = std::make_shared<BuiltinPropertyGetSetHelper>( xModel );
405 auto aUsingStatsHelper = std::make_shared<StatisticPropertyGetSetHelper>( xModel );
407 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTitle ] = DocPropInfo::createDocPropInfo(
"Title",
"Title", aStandardHelper );
408 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySubject ] = DocPropInfo::createDocPropInfo(
"Subject",
"Subject", aStandardHelper );
409 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyAuthor ] = DocPropInfo::createDocPropInfo(
"Author",
"Author", aStandardHelper );
410 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyKeywords ] = DocPropInfo::createDocPropInfo(
"Keywords",
"Keywords", aStandardHelper );
411 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyComments ] = DocPropInfo::createDocPropInfo(
"Comments",
"Description", aStandardHelper );
412 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTemplate ] = DocPropInfo::createDocPropInfo(
"Template",
"Template", aStandardHelper );
413 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyLastAuthor ] = DocPropInfo::createDocPropInfo(
"Last author",
"ModifiedBy", aStandardHelper );
414 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyRevision ] = DocPropInfo::createDocPropInfo(
"Revision number",
"EditingCycles", aStandardHelper );
415 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyAppName ] = DocPropInfo::createDocPropInfo(
"Application name",
"Generator", aStandardHelper );
416 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeLastPrinted ] = DocPropInfo::createDocPropInfo(
"Last print date",
"PrintDate", aStandardHelper );
417 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeCreated ] = DocPropInfo::createDocPropInfo(
"Creation date",
"CreationDate", aStandardHelper );
418 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyTimeLastSaved ] = DocPropInfo::createDocPropInfo(
"Last save time",
"ModifyDate", aStandardHelper );
419 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyVBATotalEdit ] = DocPropInfo::createDocPropInfo(
"Total editing time",
"EditingDuration", aStandardHelper );
420 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyPages ] = DocPropInfo::createDocPropInfo(
"Number of pages",
"PageCount", aUsingStatsHelper );
421 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyWords ] = DocPropInfo::createDocPropInfo(
"Number of words",
"WordCount", aUsingStatsHelper );
422 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCharacters ] = DocPropInfo::createDocPropInfo(
"Number of characters",
"CharacterCount", aUsingStatsHelper );
423 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySecurity ] = DocPropInfo::createDocPropInfo(
"Security",
"", aStandardHelper );
424 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCategory ] = DocPropInfo::createDocPropInfo(
"Category",
"Category", aStandardHelper );
425 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyFormat ] = DocPropInfo::createDocPropInfo(
"Format",
"", aStandardHelper );
426 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyManager ] = DocPropInfo::createDocPropInfo(
"Manager",
"Manager", aStandardHelper );
427 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCompany ] = DocPropInfo::createDocPropInfo(
"Company",
"Company", aStandardHelper );
428 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyBytes ] = DocPropInfo::createDocPropInfo(
"Number of bytes",
"", aStandardHelper );
429 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyLines ] = DocPropInfo::createDocPropInfo(
"Number of lines",
"LineCount", aUsingStatsHelper );
430 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyParas ] = DocPropInfo::createDocPropInfo(
"Number of paragraphs",
"ParagraphCount", aUsingStatsHelper );
431 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertySlides ] = DocPropInfo::createDocPropInfo(
"Number of slides",
"" , aStandardHelper );
432 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyNotes ] = DocPropInfo::createDocPropInfo(
"Number of notes",
"", aStandardHelper );
433 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyHiddenSlides ] = DocPropInfo::createDocPropInfo(
"Number of hidden Slides",
"", aStandardHelper );
434 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyMMClips ] = DocPropInfo::createDocPropInfo(
"Number of multimedia clips",
"", aStandardHelper );
435 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyHyperlinkBase ] = DocPropInfo::createDocPropInfo(
"Hyperlink base",
"AutoloadURL", aStandardHelper );
436 m_docPropInfoMap[ word::WdBuiltInProperty::wdPropertyCharsWSpaces ] = DocPropInfo::createDocPropInfo(
"Number of characters (with spaces)",
"", aStandardHelper );
439 MSOIndexToOODocPropInfo& getDocPropInfoMap() {
return m_docPropInfoMap; }
448 class SwVbaBuiltInDocumentProperty :
public SwVbaDocumentProperty_BASE
451 DocPropInfo mPropInfo;
453 SwVbaBuiltInDocumentProperty(
const uno::Reference< ov::XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const DocPropInfo& rInfo );
455 virtual void SAL_CALL
Delete( )
override;
456 virtual OUString SAL_CALL getName( )
override;
457 virtual void SAL_CALL setName(
const OUString&
Name )
override;
458 virtual ::sal_Int8 SAL_CALL
getType( )
override;
459 virtual void SAL_CALL setType( ::
sal_Int8 Type )
override;
460 virtual sal_Bool SAL_CALL getLinkToContent( )
override;
461 virtual void SAL_CALL setLinkToContent(
sal_Bool LinkToContent )
override;
464 virtual OUString SAL_CALL getLinkSource( )
override;
465 virtual void SAL_CALL setLinkSource(
const OUString& LinkSource )
override;
467 virtual OUString SAL_CALL getDefaultPropertyName( )
override {
return "Value"; }
469 virtual OUString getServiceImplName()
override;
470 virtual uno::Sequence<OUString> getServiceNames()
override;
473 class SwVbaCustomDocumentProperty :
public SwVbaBuiltInDocumentProperty
477 SwVbaCustomDocumentProperty(
const uno::Reference< ov::XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const DocPropInfo& rInfo );
479 virtual sal_Bool SAL_CALL getLinkToContent( )
override;
480 virtual void SAL_CALL setLinkToContent(
sal_Bool LinkToContent )
override;
482 virtual OUString SAL_CALL getLinkSource( )
override;
483 virtual void SAL_CALL setLinkSource(
const OUString& LinkSource )
override;
484 virtual void SAL_CALL
Delete( )
override;
485 virtual void SAL_CALL setName(
const OUString&
Name )
override;
486 virtual void SAL_CALL setType( ::
sal_Int8 Type )
override;
492 SwVbaCustomDocumentProperty::SwVbaCustomDocumentProperty(
const uno::Reference< ov::XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const DocPropInfo& rInfo ) : SwVbaBuiltInDocumentProperty( xParent, xContext, rInfo )
497 SwVbaCustomDocumentProperty::getLinkToContent( )
504 SwVbaCustomDocumentProperty::setLinkToContent(
sal_Bool )
509 SwVbaCustomDocumentProperty::getLinkSource( )
516 SwVbaCustomDocumentProperty::setLinkSource(
const OUString& )
522 SwVbaCustomDocumentProperty::setName(
const OUString& )
530 SwVbaCustomDocumentProperty::setType( ::
sal_Int8 )
537 SwVbaCustomDocumentProperty::Delete( )
539 uno::Reference< beans::XPropertyContainer > xContainer(
540 mPropInfo.getUserDefinedProperties(), uno::UNO_QUERY_THROW);
541 xContainer->removeProperty( getName() );
544 SwVbaBuiltInDocumentProperty::SwVbaBuiltInDocumentProperty(
const uno::Reference< ov::XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const DocPropInfo& rInfo ) : SwVbaDocumentProperty_BASE( xParent, xContext ), mPropInfo( rInfo )
549 SwVbaBuiltInDocumentProperty::Delete( )
552 throw uno::RuntimeException();
556 SwVbaBuiltInDocumentProperty::getName( )
558 return mPropInfo.msMSODesc;
562 SwVbaBuiltInDocumentProperty::setName(
const OUString& )
565 throw uno::RuntimeException();
569 SwVbaBuiltInDocumentProperty::getType( )
575 SwVbaBuiltInDocumentProperty::setType( ::
sal_Int8 )
578 throw uno::RuntimeException();
582 SwVbaBuiltInDocumentProperty::getLinkToContent( )
588 SwVbaBuiltInDocumentProperty::setLinkToContent(
sal_Bool )
591 throw uno::RuntimeException();
595 SwVbaBuiltInDocumentProperty::getValue( )
597 uno::Any aRet = mPropInfo.getValue();
599 throw uno::RuntimeException();
604 SwVbaBuiltInDocumentProperty::setValue(
const uno::Any& Value )
610 SwVbaBuiltInDocumentProperty::getLinkSource( )
613 throw uno::RuntimeException();
617 SwVbaBuiltInDocumentProperty::setLinkSource(
const OUString& )
620 throw uno::RuntimeException();
624 SwVbaBuiltInDocumentProperty::getServiceImplName()
626 return "SwVbaBuiltinDocumentProperty";
629 uno::Sequence<OUString>
630 SwVbaBuiltInDocumentProperty::getServiceNames()
634 "ooo.vba.word.DocumentProperty"
638 typedef ::cppu::WeakImplHelper< css::container::XIndexAccess
639 ,css::container::XNameAccess
640 ,css::container::XEnumerationAccess
643 typedef std::unordered_map< sal_Int32, uno::Reference< XDocumentProperty > >
DocProps;
647 class DocPropEnumeration :
public ::cppu::WeakImplHelper< css::container::XEnumeration >
650 DocProps::iterator mIt;
653 explicit DocPropEnumeration(
const DocProps& rProps ) : mDocProps( rProps ), mIt( mDocProps.begin() ) {}
654 virtual sal_Bool SAL_CALL hasMoreElements( )
override
656 return mIt != mDocProps.end();
658 virtual uno::Any SAL_CALL nextElement( )
override
660 if ( !hasMoreElements() )
661 throw container::NoSuchElementException();
662 return uno::makeAny( mIt++->second );
668 typedef std::unordered_map< OUString, uno::Reference< XDocumentProperty > >
DocPropsByName;
676 uno::Reference< frame::XModel > m_xModel;
679 DocPropsByName mNamedDocProps;
682 BuiltInPropertiesImpl(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< frame::XModel >& xModel ) : m_xModel( xModel )
684 BuiltInIndexHelper builtIns( m_xModel );
685 for ( sal_Int32
index = word::WdBuiltInProperty::wdPropertyTitle;
index <= word::WdBuiltInProperty::wdPropertyCharsWSpaces; ++
index )
687 mDocProps[
index ] =
new SwVbaBuiltInDocumentProperty( xParent, xContext, builtIns.getDocPropInfoMap()[
index ] );
688 mNamedDocProps[ mDocProps[
index ]->getName() ] = mDocProps[
index ];
692 virtual ::sal_Int32 SAL_CALL getCount( )
override
694 return mDocProps.size();
696 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
699 DocProps::iterator it = mDocProps.find( ++Index );
700 if ( it == mDocProps.end() )
701 throw lang::IndexOutOfBoundsException();
702 return uno::makeAny( it->second );
704 virtual uno::Any SAL_CALL getByName(
const OUString&
aName )
override
706 if ( !hasByName( aName ) )
707 throw container::NoSuchElementException();
708 DocPropsByName::iterator it = mNamedDocProps.find( aName );
712 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
714 uno::Sequence< OUString > aNames( getCount() );
715 OUString*
pName = aNames.getArray();
716 for (
const auto& rEntry : mNamedDocProps)
718 *pName = rEntry.first;
724 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override
726 DocPropsByName::iterator it = mNamedDocProps.find( aName );
727 if ( it == mNamedDocProps.end() )
732 virtual uno::Type SAL_CALL getElementType( )
override
736 virtual sal_Bool SAL_CALL hasElements( )
override
738 return !mDocProps.empty();
740 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
742 return new DocPropEnumeration( mDocProps );
752 uno::Reference< XDocumentProperty > SAL_CALL
755 throw uno::RuntimeException(
"not supported for Builtin properties" );
765 uno::Reference< container::XEnumeration > SAL_CALL
768 uno::Reference< container::XEnumerationAccess > xEnumAccess(
m_xIndexAccess, uno::UNO_QUERY_THROW );
769 return xEnumAccess->createEnumeration();
784 return "SwVbaBuiltinDocumentProperties";
787 uno::Sequence<OUString>
792 "ooo.vba.word.DocumentProperties"
801 uno::Reference< XHelperInterface > m_xParent;
802 uno::Reference< uno::XComponentContext >
m_xContext;
803 uno::Reference< frame::XModel > m_xModel;
804 uno::Reference< beans::XPropertySet > mxUserDefinedProp;
805 std::shared_ptr< PropertGetSetHelper > mpPropGetSetHelper;
807 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 )
810 mpPropGetSetHelper = std::make_shared<CustomPropertyGetSetHelper>( m_xModel );
811 mxUserDefinedProp.set(mpPropGetSetHelper->getUserDefinedProperties(),
815 virtual ::sal_Int32 SAL_CALL getCount( )
override
817 return mxUserDefinedProp->getPropertySetInfo()->getProperties().getLength();
820 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
822 uno::Sequence< beans::Property > aProps = mxUserDefinedProp->getPropertySetInfo()->getProperties();
823 if ( Index >= aProps.getLength() )
824 throw lang::IndexOutOfBoundsException();
826 DocPropInfo aPropInfo = DocPropInfo::createDocPropInfo( aProps[ Index ].Name, aProps[ Index ].Name, mpPropGetSetHelper );
827 return uno::makeAny( uno::Reference< XDocumentProperty >(
new SwVbaCustomDocumentProperty( m_xParent, m_xContext, aPropInfo ) ) );
830 virtual uno::Any SAL_CALL getByName(
const OUString& aName )
override
832 if ( !hasByName( aName ) )
833 throw container::NoSuchElementException();
835 DocPropInfo aPropInfo = DocPropInfo::createDocPropInfo( aName, aName, mpPropGetSetHelper );
836 return uno::makeAny( uno::Reference< XDocumentProperty >(
new SwVbaCustomDocumentProperty( m_xParent, m_xContext, aPropInfo ) ) );
839 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
841 uno::Sequence< beans::Property > aProps = mxUserDefinedProp->getPropertySetInfo()->getProperties();
842 uno::Sequence< OUString > aNames( aProps.getLength() );
843 std::transform(aProps.begin(), aProps.end(), aNames.begin(),
844 [](
const beans::Property& rProp) -> OUString {
return rProp.Name; });
848 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override
850 SAL_INFO(
"sw.vba",
"hasByName(" << aName <<
") returns " << mxUserDefinedProp->getPropertySetInfo()->hasPropertyByName( aName ) );
851 return mxUserDefinedProp->getPropertySetInfo()->hasPropertyByName( aName );
855 virtual uno::Type SAL_CALL getElementType( )
override
860 virtual sal_Bool SAL_CALL hasElements( )
override
862 return getCount() > 0;
865 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
868 SAL_INFO(
"sw.vba",
"Creating an enumeration");
870 sal_Int32 nElem = getCount();
871 DocProps simpleDocPropSnapShot;
872 for ( ; key < nElem; ++key )
873 simpleDocPropSnapShot[ key ].
set( getByIndex( key ), uno::UNO_QUERY_THROW );
874 SAL_INFO(
"sw.vba",
"After creating the enumeration");
875 return new DocPropEnumeration( simpleDocPropSnapShot );
878 void addProp(
const OUString& Name,
const uno::Any& Value )
880 uno::Reference< beans::XPropertyContainer > xContainer( mxUserDefinedProp, uno::UNO_QUERY_THROW );
882 xContainer->addProperty( Name, sal_Int16(128), Value );
892 m_xIndexAccess.set(
new CustomPropertiesImpl( xParent, xContext, xModel ) );
896 uno::Reference< XDocumentProperty > SAL_CALL
899 CustomPropertiesImpl* pCustomProps =
dynamic_cast< CustomPropertiesImpl*
> (
m_xIndexAccess.get() );
900 uno::Reference< XDocumentProperty > xDocProp;
903 OUString sLinkSource;
904 pCustomProps->addProp( Name, Value );
906 xDocProp.set(
m_xNameAccess->getByName( Name ), uno::UNO_QUERY_THROW );
907 xDocProp->setLinkToContent( LinkToContent );
909 if ( LinkSource >>= sLinkSource )
910 xDocProp->setLinkSource( sLinkSource );
919 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
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
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)