24#include <com/sun/star/container/XEnumerationAccess.hpp>
25#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
27#include <com/sun/star/style/XStyle.hpp>
28#include <ooo/vba/word/WdBuiltinStyle.hpp>
29#include <ooo/vba/word/WdStyleType.hpp>
36struct BuiltinStyleTable
38 sal_Int32 wdBuiltinStyle;
39 const char* pOOoStyleName;
40 sal_Int32 wdStyleType;
47 { word::WdBuiltinStyle::wdStyleBlockQuotation,
"", word::WdStyleType::wdStyleTypeParagraph },
48 { word::WdBuiltinStyle::wdStyleBodyText,
"Text body", word::WdStyleType::wdStyleTypeParagraph },
49 { word::WdBuiltinStyle::wdStyleBodyText2,
"", word::WdStyleType::wdStyleTypeParagraph },
50 { word::WdBuiltinStyle::wdStyleBodyText3,
"", word::WdStyleType::wdStyleTypeParagraph },
51 { word::WdBuiltinStyle::wdStyleBodyTextFirstIndent,
"First line indent", word::WdStyleType::wdStyleTypeParagraph },
52 { word::WdBuiltinStyle::wdStyleBodyTextFirstIndent2,
"", word::WdStyleType::wdStyleTypeParagraph },
53 { word::WdBuiltinStyle::wdStyleBodyTextIndent,
"Text body indent", word::WdStyleType::wdStyleTypeParagraph },
54 { word::WdBuiltinStyle::wdStyleBodyTextIndent2,
"", word::WdStyleType::wdStyleTypeParagraph },
55 { word::WdBuiltinStyle::wdStyleBodyTextIndent3,
"", word::WdStyleType::wdStyleTypeParagraph },
56 { word::WdBuiltinStyle::wdStyleCaption,
"", word::WdStyleType::wdStyleTypeParagraph },
57 { word::WdBuiltinStyle::wdStyleClosing,
"", word::WdStyleType::wdStyleTypeParagraph },
58 { word::WdBuiltinStyle::wdStyleCommentReference,
"", word::WdStyleType::wdStyleTypeParagraph },
59 { word::WdBuiltinStyle::wdStyleCommentText,
"", word::WdStyleType::wdStyleTypeParagraph },
60 { word::WdBuiltinStyle::wdStyleDate,
"", word::WdStyleType::wdStyleTypeParagraph },
61 { word::WdBuiltinStyle::wdStyleDefaultParagraphFont,
"", word::WdStyleType::wdStyleTypeParagraph },
62 { word::WdBuiltinStyle::wdStyleEmphasis,
"", word::WdStyleType::wdStyleTypeParagraph },
63 { word::WdBuiltinStyle::wdStyleEndnoteReference,
"", word::WdStyleType::wdStyleTypeParagraph },
64 { word::WdBuiltinStyle::wdStyleEndnoteText,
"Endnote", word::WdStyleType::wdStyleTypeParagraph },
65 { word::WdBuiltinStyle::wdStyleEnvelopeAddress,
"", word::WdStyleType::wdStyleTypeParagraph },
66 { word::WdBuiltinStyle::wdStyleEnvelopeReturn,
"", word::WdStyleType::wdStyleTypeParagraph },
67 { word::WdBuiltinStyle::wdStyleFooter,
"", word::WdStyleType::wdStyleTypeParagraph },
68 { word::WdBuiltinStyle::wdStyleFootnoteReference,
"", word::WdStyleType::wdStyleTypeParagraph },
69 { word::WdBuiltinStyle::wdStyleFootnoteText,
"Footnote", word::WdStyleType::wdStyleTypeParagraph },
70 { word::WdBuiltinStyle::wdStyleHeader,
"Header", word::WdStyleType::wdStyleTypeParagraph },
71 { word::WdBuiltinStyle::wdStyleHeading1,
"Heading 1", word::WdStyleType::wdStyleTypeParagraph },
72 { word::WdBuiltinStyle::wdStyleHeading2,
"Heading 2", word::WdStyleType::wdStyleTypeParagraph },
73 { word::WdBuiltinStyle::wdStyleHeading3,
"Heading 3", word::WdStyleType::wdStyleTypeParagraph },
74 { word::WdBuiltinStyle::wdStyleHeading4,
"Heading 4", word::WdStyleType::wdStyleTypeParagraph },
75 { word::WdBuiltinStyle::wdStyleHeading5,
"Heading 5", word::WdStyleType::wdStyleTypeParagraph },
76 { word::WdBuiltinStyle::wdStyleHeading6,
"Heading 6", word::WdStyleType::wdStyleTypeParagraph },
77 { word::WdBuiltinStyle::wdStyleHeading7,
"Heading 7", word::WdStyleType::wdStyleTypeParagraph },
78 { word::WdBuiltinStyle::wdStyleHeading8,
"Heading 8", word::WdStyleType::wdStyleTypeParagraph },
79 { word::WdBuiltinStyle::wdStyleHeading9,
"Heading 9", word::WdStyleType::wdStyleTypeParagraph },
80 { word::WdBuiltinStyle::wdStyleHtmlAcronym,
"", word::WdStyleType::wdStyleTypeParagraph },
81 { word::WdBuiltinStyle::wdStyleHtmlAddress,
"", word::WdStyleType::wdStyleTypeParagraph },
82 { word::WdBuiltinStyle::wdStyleHtmlCite,
"", word::WdStyleType::wdStyleTypeParagraph },
83 { word::WdBuiltinStyle::wdStyleHtmlCode,
"", word::WdStyleType::wdStyleTypeParagraph },
84 { word::WdBuiltinStyle::wdStyleHtmlDfn,
"", word::WdStyleType::wdStyleTypeParagraph },
85 { word::WdBuiltinStyle::wdStyleHtmlKbd,
"", word::WdStyleType::wdStyleTypeParagraph },
86 { word::WdBuiltinStyle::wdStyleHtmlNormal,
"", word::WdStyleType::wdStyleTypeParagraph },
87 { word::WdBuiltinStyle::wdStyleHtmlPre,
"", word::WdStyleType::wdStyleTypeParagraph },
88 { word::WdBuiltinStyle::wdStyleHtmlSamp,
"", word::WdStyleType::wdStyleTypeParagraph },
89 { word::WdBuiltinStyle::wdStyleHtmlTt,
"", word::WdStyleType::wdStyleTypeParagraph },
90 { word::WdBuiltinStyle::wdStyleHtmlVar,
"", word::WdStyleType::wdStyleTypeParagraph },
91 { word::WdBuiltinStyle::wdStyleHyperlink,
"", word::WdStyleType::wdStyleTypeParagraph },
92 { word::WdBuiltinStyle::wdStyleHyperlinkFollowed,
"", word::WdStyleType::wdStyleTypeParagraph },
93 { word::WdBuiltinStyle::wdStyleIndex1,
"Index 1", word::WdStyleType::wdStyleTypeParagraph },
94 { word::WdBuiltinStyle::wdStyleIndex2,
"Index 2", word::WdStyleType::wdStyleTypeParagraph },
95 { word::WdBuiltinStyle::wdStyleIndex3,
"Index 3", word::WdStyleType::wdStyleTypeParagraph },
96 { word::WdBuiltinStyle::wdStyleIndex4,
"", word::WdStyleType::wdStyleTypeParagraph },
97 { word::WdBuiltinStyle::wdStyleIndex5,
"", word::WdStyleType::wdStyleTypeParagraph },
98 { word::WdBuiltinStyle::wdStyleIndex6,
"", word::WdStyleType::wdStyleTypeParagraph },
99 { word::WdBuiltinStyle::wdStyleIndex7,
"", word::WdStyleType::wdStyleTypeParagraph },
100 { word::WdBuiltinStyle::wdStyleIndex8,
"", word::WdStyleType::wdStyleTypeParagraph },
101 { word::WdBuiltinStyle::wdStyleIndex9,
"", word::WdStyleType::wdStyleTypeParagraph },
102 { word::WdBuiltinStyle::wdStyleIndexHeading,
"Index Heading", word::WdStyleType::wdStyleTypeParagraph },
103 { word::WdBuiltinStyle::wdStyleLineNumber,
"", word::WdStyleType::wdStyleTypeParagraph },
104 { word::WdBuiltinStyle::wdStyleList,
"List", word::WdStyleType::wdStyleTypeParagraph },
105 { word::WdBuiltinStyle::wdStyleList2,
"List 2", word::WdStyleType::wdStyleTypeParagraph },
106 { word::WdBuiltinStyle::wdStyleList3,
"List 3", word::WdStyleType::wdStyleTypeParagraph },
107 { word::WdBuiltinStyle::wdStyleList4,
"List 4", word::WdStyleType::wdStyleTypeParagraph },
108 { word::WdBuiltinStyle::wdStyleList5,
"List 5", word::WdStyleType::wdStyleTypeParagraph },
109 { word::WdBuiltinStyle::wdStyleListBullet,
"List 1", word::WdStyleType::wdStyleTypeList },
110 { word::WdBuiltinStyle::wdStyleListBullet2,
"List 2", word::WdStyleType::wdStyleTypeList },
111 { word::WdBuiltinStyle::wdStyleListBullet3,
"List 3", word::WdStyleType::wdStyleTypeList },
112 { word::WdBuiltinStyle::wdStyleListBullet4,
"List 4", word::WdStyleType::wdStyleTypeList },
113 { word::WdBuiltinStyle::wdStyleListBullet5,
"List 5", word::WdStyleType::wdStyleTypeList },
114 { word::WdBuiltinStyle::wdStyleListContinue,
"", word::WdStyleType::wdStyleTypeParagraph },
115 { word::WdBuiltinStyle::wdStyleListContinue2,
"", word::WdStyleType::wdStyleTypeParagraph },
116 { word::WdBuiltinStyle::wdStyleListContinue3,
"", word::WdStyleType::wdStyleTypeParagraph },
117 { word::WdBuiltinStyle::wdStyleListContinue4,
"", word::WdStyleType::wdStyleTypeParagraph },
118 { word::WdBuiltinStyle::wdStyleListContinue5,
"", word::WdStyleType::wdStyleTypeParagraph },
119 { word::WdBuiltinStyle::wdStyleListNumber,
"Numbering 123", word::WdStyleType::wdStyleTypeList },
120 { word::WdBuiltinStyle::wdStyleListNumber2,
"Numbering ABC", word::WdStyleType::wdStyleTypeList },
121 { word::WdBuiltinStyle::wdStyleListNumber3,
"Numbering abc", word::WdStyleType::wdStyleTypeList },
122 { word::WdBuiltinStyle::wdStyleListNumber4,
"Numbering IVX", word::WdStyleType::wdStyleTypeList },
123 { word::WdBuiltinStyle::wdStyleListNumber5,
"Numbering ivx", word::WdStyleType::wdStyleTypeList },
124 { word::WdBuiltinStyle::wdStyleMacroText,
"", word::WdStyleType::wdStyleTypeParagraph },
125 { word::WdBuiltinStyle::wdStyleMessageHeader,
"", word::WdStyleType::wdStyleTypeParagraph },
126 { word::WdBuiltinStyle::wdStyleNavPane,
"", word::WdStyleType::wdStyleTypeParagraph },
127 { word::WdBuiltinStyle::wdStyleNormal,
"Default", word::WdStyleType::wdStyleTypeParagraph },
128 { word::WdBuiltinStyle::wdStyleNormalIndent,
"", word::WdStyleType::wdStyleTypeParagraph },
129 { word::WdBuiltinStyle::wdStyleNormalTable,
"Table", word::WdStyleType::wdStyleTypeParagraph },
130 { word::WdBuiltinStyle::wdStyleNoteHeading,
"", word::WdStyleType::wdStyleTypeParagraph },
131 { word::WdBuiltinStyle::wdStylePageNumber,
"", word::WdStyleType::wdStyleTypeParagraph },
132 { word::WdBuiltinStyle::wdStylePlainText,
"", word::WdStyleType::wdStyleTypeParagraph },
133 { word::WdBuiltinStyle::wdStyleSalutation,
"", word::WdStyleType::wdStyleTypeParagraph },
134 { word::WdBuiltinStyle::wdStyleSignature,
"", word::WdStyleType::wdStyleTypeParagraph },
135 { word::WdBuiltinStyle::wdStyleStrong,
"", word::WdStyleType::wdStyleTypeParagraph },
136 { word::WdBuiltinStyle::wdStyleSubtitle,
"", word::WdStyleType::wdStyleTypeParagraph },
137 { word::WdBuiltinStyle::wdStyleTableOfAuthorities,
"", word::WdStyleType::wdStyleTypeParagraph },
138 { word::WdBuiltinStyle::wdStyleTableOfFigures,
"", word::WdStyleType::wdStyleTypeParagraph },
139 { word::WdBuiltinStyle::wdStyleTitle,
"Title", word::WdStyleType::wdStyleTypeParagraph },
140 { word::WdBuiltinStyle::wdStyleTOAHeading,
"Contents Heading", word::WdStyleType::wdStyleTypeParagraph },
141 { word::WdBuiltinStyle::wdStyleTOC1,
"Contents 1", word::WdStyleType::wdStyleTypeParagraph },
142 { word::WdBuiltinStyle::wdStyleTOC2,
"Contents 2", word::WdStyleType::wdStyleTypeParagraph },
143 { word::WdBuiltinStyle::wdStyleTOC3,
"Contents 3", word::WdStyleType::wdStyleTypeParagraph },
144 { word::WdBuiltinStyle::wdStyleTOC4,
"Contents 4", word::WdStyleType::wdStyleTypeParagraph },
145 { word::WdBuiltinStyle::wdStyleTOC5,
"Contents 5", word::WdStyleType::wdStyleTypeParagraph },
146 { word::WdBuiltinStyle::wdStyleTOC6,
"Contents 6", word::WdStyleType::wdStyleTypeParagraph },
147 { word::WdBuiltinStyle::wdStyleTOC7,
"Contents 7", word::WdStyleType::wdStyleTypeParagraph },
148 { word::WdBuiltinStyle::wdStyleTOC8,
"Contents 8", word::WdStyleType::wdStyleTypeParagraph },
149 { word::WdBuiltinStyle::wdStyleTOC9,
"Contents 9", word::WdStyleType::wdStyleTypeParagraph },
155struct MSOStyleNameTable
157 const char* pMSOStyleName;
158 const char* pOOoStyleName;
165 {
"Normal",
"Default" },
171class StyleCollectionHelper :
public ::cppu::WeakImplHelper< container::XNameAccess,
172 container::XIndexAccess,
173 container::XEnumerationAccess >
176 uno::Reference< container::XNameAccess > mxParaStyles;
179 explicit StyleCollectionHelper(
const uno::Reference< frame::XModel >& _xModel )
182 uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( _xModel, uno::UNO_QUERY_THROW);
183 uno::Reference< container::XNameAccess > xStyleFamilies = xStyleSupplier->getStyleFamilies();
184 mxParaStyles.set( xStyleFamilies->getByName(
"ParagraphStyles"), uno::UNO_QUERY_THROW );
188 virtual sal_Bool SAL_CALL hasElements( )
override {
return getCount() > 0; }
190 virtual uno::Any SAL_CALL getByName(
const OUString& aName )
override
192 if ( !hasByName(aName) )
193 throw container::NoSuchElementException();
196 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
198 return mxParaStyles->getElementNames();
200 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override
203 for(
const MSOStyleNameTable* pTable =
aMSOStyleNameTable; pTable->pMSOStyleName !=
nullptr; pTable++ )
205 if(
aName.equalsIgnoreAsciiCaseAscii( pTable->pMSOStyleName ) )
208 OUString sStyleName = OUString::createFromAscii( pTable->pOOoStyleName );
209 if( mxParaStyles->hasByName( sStyleName ) )
211 m_cachePos = mxParaStyles->getByName( sStyleName );
218 if( mxParaStyles->hasByName( aName ) )
220 m_cachePos = mxParaStyles->getByName( aName );
225 const uno::Sequence< OUString > sElementNames = mxParaStyles->getElementNames();
226 auto pStyleName = std::find_if(sElementNames.begin(), sElementNames.end(),
227 [&aName](
const OUString& rStyleName) { return rStyleName.equalsIgnoreAsciiCase( aName ); });
228 if (pStyleName != sElementNames.end())
230 m_cachePos = mxParaStyles->getByName( *pStyleName );
238 virtual ::sal_Int32 SAL_CALL getCount( )
override
240 uno::Reference< container::XIndexAccess > xIndexAccess( mxParaStyles, uno::UNO_QUERY_THROW );
241 return xIndexAccess->getCount();
243 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
246 throw lang::IndexOutOfBoundsException();
248 uno::Reference< container::XIndexAccess > xIndexAccess( mxParaStyles, uno::UNO_QUERY_THROW );
249 return xIndexAccess->getByIndex(
Index );
252 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
254 throw uno::RuntimeException(
"Not implemented" );
263 explicit StylesEnumWrapper(
SwVbaStyles* _pStyles ) : m_pStyles( _pStyles ), m_nIndex( 1 ) {}
264 virtual sal_Bool SAL_CALL hasMoreElements( )
override
266 return ( m_nIndex <= m_pStyles->getCount() );
269 virtual uno::Any SAL_CALL nextElement( )
override
271 if ( m_nIndex <= m_pStyles->getCount() )
273 throw container::NoSuchElementException();
279SwVbaStyles::SwVbaStyles(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< css::uno::XComponentContext > & xContext,
const uno::Reference< frame::XModel >& xModel )
288 uno::Reference< beans::XPropertySet > xStyleProp( aObject, uno::UNO_QUERY_THROW );
298uno::Reference< container::XEnumeration > SAL_CALL
301 return new StylesEnumWrapper(
this );
311 for(
const BuiltinStyleTable* pTable =
aBuiltinStyleTable; pTable !=
nullptr; pTable++ )
313 if(
nIndex == pTable->wdBuiltinStyle )
315 OUString aStyleName = OUString::createFromAscii( pTable->pOOoStyleName );
316 if( !aStyleName.isEmpty() )
319 switch( pTable->wdStyleType )
321 case word::WdStyleType::wdStyleTypeParagraph:
322 case word::WdStyleType::wdStyleTypeTable:
324 aStyleType =
"ParagraphStyles";
327 case word::WdStyleType::wdStyleTypeCharacter:
329 aStyleType =
"CharacterStyles";
332 case word::WdStyleType::wdStyleTypeList:
335 aStyleType =
"ParagraphStyles";
341 uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier(
mxModel, uno::UNO_QUERY_THROW);
342 uno::Reference< container::XNameAccess > xStylesAccess( xStyleSupplier->getStyleFamilies()->getByName( aStyleType ), uno::UNO_QUERY_THROW );
343 uno::Reference< beans::XPropertySet > xStyleProps( xStylesAccess->getByName( aStyleName ), uno::UNO_QUERY_THROW );
345 if( pTable->wdStyleType == word::WdStyleType::wdStyleTypeList )
347 xStyleProps->setPropertyValue(
"NumberingStyleName",
uno::Any( aStyleName ) );
353 SAL_WARN(
"sw.vba",
"the builtin style type is not implemented");
354 throw uno::RuntimeException(
"Not implemented" );
365 return "SwVbaStyles";
368uno::Sequence< OUString >
373 "ooo.vba.word.XStyles"
css::uno::Reference< css::frame::XModel2 > mxModel
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &) override
virtual css::uno::Sequence< OUString > getServiceNames() override
SwVbaStyles(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel > &xModel)
css::uno::Reference< css::frame::XModel > mxModel
css::uno::Reference< css::lang::XMultiServiceFactory > mxMSF
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &Index2) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &) override
virtual OUString getServiceImplName() override
virtual css::uno::Type SAL_CALL getElementType() override
css::uno::Type const & get()
Sequence< OUString > aServiceNames
#define SAL_WARN(area, stream)
#define ERRCODE_BASIC_INTERNAL_ERROR
Reference< XModel > xModel
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
const BuiltinStyleTable aBuiltinStyleTable[]
const MSOStyleNameTable aMSOStyleNameTable[]