xref: /aoo42x/main/sw/source/ui/vba/vbastyles.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir #include "vbastyles.hxx"
24cdf0e10cSrcweir #include "vbastyle.hxx"
25cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx>
26cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
27cdf0e10cSrcweir #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
29cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp>
30cdf0e10cSrcweir #include <ooo/vba/word/WdBuiltinStyle.hpp>
31cdf0e10cSrcweir #include <ooo/vba/word/WdStyleType.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::ooo::vba;
34cdf0e10cSrcweir using namespace ::com::sun::star;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir struct BuiltinStyleTable
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     sal_Int32 wdBuiltinStyle;
39cdf0e10cSrcweir     const sal_Char* pOOoStyleName;
40cdf0e10cSrcweir     sal_Int32 wdStyleType;
41cdf0e10cSrcweir };
42cdf0e10cSrcweir 
43cdf0e10cSrcweir const BuiltinStyleTable aBuiltinStyleTable[] =
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleBlockQuotation, "", word::WdStyleType::wdStyleTypeParagraph },
46cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleBodyText, "Text body", word::WdStyleType::wdStyleTypeParagraph },
47cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleBodyText2, "", word::WdStyleType::wdStyleTypeParagraph },
48cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleBodyText3, "", word::WdStyleType::wdStyleTypeParagraph },
49cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleBodyTextFirstIndent, "First line indent", word::WdStyleType::wdStyleTypeParagraph },
50cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleBodyTextFirstIndent2, "", word::WdStyleType::wdStyleTypeParagraph },
51cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleBodyTextIndent, "Text body indent", word::WdStyleType::wdStyleTypeParagraph },
52cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleBodyTextIndent2, "", word::WdStyleType::wdStyleTypeParagraph },
53cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleBodyTextIndent3, "", word::WdStyleType::wdStyleTypeParagraph },
54cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleCaption, "", word::WdStyleType::wdStyleTypeParagraph },
55cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleClosing, "", word::WdStyleType::wdStyleTypeParagraph },
56cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleCommentReference, "", word::WdStyleType::wdStyleTypeParagraph },
57cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleCommentText, "", word::WdStyleType::wdStyleTypeParagraph },
58cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleDate, "", word::WdStyleType::wdStyleTypeParagraph },
59cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleDefaultParagraphFont, "", word::WdStyleType::wdStyleTypeParagraph },
60cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleEmphasis, "", word::WdStyleType::wdStyleTypeParagraph },
61cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleEndnoteReference, "", word::WdStyleType::wdStyleTypeParagraph },
62cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleEndnoteText, "Endnote", word::WdStyleType::wdStyleTypeParagraph },
63cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleEnvelopeAddress, "", word::WdStyleType::wdStyleTypeParagraph },
64cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleEnvelopeReturn, "", word::WdStyleType::wdStyleTypeParagraph },
65cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleFooter, "", word::WdStyleType::wdStyleTypeParagraph },
66cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleFootnoteReference, "", word::WdStyleType::wdStyleTypeParagraph },
67cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleFootnoteText, "Footnote", word::WdStyleType::wdStyleTypeParagraph },
68cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHeader, "Header", word::WdStyleType::wdStyleTypeParagraph },
69cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHeading1, "Heading 1", word::WdStyleType::wdStyleTypeParagraph },
70cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHeading2, "Heading 2", word::WdStyleType::wdStyleTypeParagraph },
71cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHeading3, "Heading 3", word::WdStyleType::wdStyleTypeParagraph },
72cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHeading4, "Heading 4", word::WdStyleType::wdStyleTypeParagraph },
73cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHeading5, "Heading 5", word::WdStyleType::wdStyleTypeParagraph },
74cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHeading6, "Heading 6", word::WdStyleType::wdStyleTypeParagraph },
75cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHeading7, "Heading 7", word::WdStyleType::wdStyleTypeParagraph },
76cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHeading8, "Heading 8", word::WdStyleType::wdStyleTypeParagraph },
77cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHeading9, "Heading 9", word::WdStyleType::wdStyleTypeParagraph },
78cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHtmlAcronym, "", word::WdStyleType::wdStyleTypeParagraph },
79cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHtmlAddress, "", word::WdStyleType::wdStyleTypeParagraph },
80cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHtmlCite, "", word::WdStyleType::wdStyleTypeParagraph },
81cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHtmlCode, "", word::WdStyleType::wdStyleTypeParagraph },
82cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHtmlDfn, "", word::WdStyleType::wdStyleTypeParagraph },
83cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHtmlKbd, "", word::WdStyleType::wdStyleTypeParagraph },
84cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHtmlNormal, "", word::WdStyleType::wdStyleTypeParagraph },
85cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHtmlPre, "", word::WdStyleType::wdStyleTypeParagraph },
86cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHtmlSamp, "", word::WdStyleType::wdStyleTypeParagraph },
87cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHtmlTt, "", word::WdStyleType::wdStyleTypeParagraph },
88cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHtmlVar, "", word::WdStyleType::wdStyleTypeParagraph },
89cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHyperlink, "", word::WdStyleType::wdStyleTypeParagraph },
90cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleHyperlinkFollowed, "", word::WdStyleType::wdStyleTypeParagraph },
91cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleIndex1, "Index 1", word::WdStyleType::wdStyleTypeParagraph },
92cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleIndex2, "Index 2", word::WdStyleType::wdStyleTypeParagraph },
93cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleIndex3, "Index 3", word::WdStyleType::wdStyleTypeParagraph },
94cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleIndex4, "", word::WdStyleType::wdStyleTypeParagraph },
95cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleIndex5, "", word::WdStyleType::wdStyleTypeParagraph },
96cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleIndex6, "", word::WdStyleType::wdStyleTypeParagraph },
97cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleIndex7, "", word::WdStyleType::wdStyleTypeParagraph },
98cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleIndex8, "", word::WdStyleType::wdStyleTypeParagraph },
99cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleIndex9, "", word::WdStyleType::wdStyleTypeParagraph },
100cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleIndexHeading, "Index Heading", word::WdStyleType::wdStyleTypeParagraph },
101cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleLineNumber, "", word::WdStyleType::wdStyleTypeParagraph },
102cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleList, "List", word::WdStyleType::wdStyleTypeParagraph },
103cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleList2, "List 2", word::WdStyleType::wdStyleTypeParagraph },
104cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleList3, "List 3", word::WdStyleType::wdStyleTypeParagraph },
105cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleList4, "List 4", word::WdStyleType::wdStyleTypeParagraph },
106cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleList5, "List 5", word::WdStyleType::wdStyleTypeParagraph },
107cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListBullet, "List 1", word::WdStyleType::wdStyleTypeList },
108cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListBullet2, "List 2", word::WdStyleType::wdStyleTypeList },
109cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListBullet3, "List 3", word::WdStyleType::wdStyleTypeList },
110cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListBullet4, "List 4", word::WdStyleType::wdStyleTypeList },
111cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListBullet5, "List 5", word::WdStyleType::wdStyleTypeList },
112cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListContinue, "", word::WdStyleType::wdStyleTypeParagraph },
113cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListContinue2, "", word::WdStyleType::wdStyleTypeParagraph },
114cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListContinue3, "", word::WdStyleType::wdStyleTypeParagraph },
115cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListContinue4, "", word::WdStyleType::wdStyleTypeParagraph },
116cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListContinue5, "", word::WdStyleType::wdStyleTypeParagraph },
117cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListNumber, "Numbering 1", word::WdStyleType::wdStyleTypeList },
118cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListNumber2, "Numbering 2", word::WdStyleType::wdStyleTypeList },
119cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListNumber3, "Numbering 3", word::WdStyleType::wdStyleTypeList },
120cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListNumber4, "Numbering 4", word::WdStyleType::wdStyleTypeList },
121cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleListNumber5, "Numbering 5", word::WdStyleType::wdStyleTypeList },
122cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleMacroText, "", word::WdStyleType::wdStyleTypeParagraph },
123cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleMessageHeader, "", word::WdStyleType::wdStyleTypeParagraph },
124cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleNavPane, "", word::WdStyleType::wdStyleTypeParagraph },
125cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleNormal, "Default", word::WdStyleType::wdStyleTypeParagraph },
126cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleNormalIndent, "", word::WdStyleType::wdStyleTypeParagraph },
127cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleNormalTable, "Table", word::WdStyleType::wdStyleTypeParagraph },
128cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleNoteHeading, "", word::WdStyleType::wdStyleTypeParagraph },
129cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStylePageNumber, "", word::WdStyleType::wdStyleTypeParagraph },
130cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStylePlainText, "", word::WdStyleType::wdStyleTypeParagraph },
131cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleSalutation, "", word::WdStyleType::wdStyleTypeParagraph },
132cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleSignature, "", word::WdStyleType::wdStyleTypeParagraph },
133cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleStrong, "", word::WdStyleType::wdStyleTypeParagraph },
134cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleSubtitle, "", word::WdStyleType::wdStyleTypeParagraph },
135cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTableOfAuthorities, "", word::WdStyleType::wdStyleTypeParagraph },
136cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTableOfFigures, "", word::WdStyleType::wdStyleTypeParagraph },
137cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTitle, "Title", word::WdStyleType::wdStyleTypeParagraph },
138cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTOAHeading, "Contents Heading", word::WdStyleType::wdStyleTypeParagraph },
139cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTOC1, "Contents 1", word::WdStyleType::wdStyleTypeParagraph },
140cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTOC2, "Contents 2", word::WdStyleType::wdStyleTypeParagraph },
141cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTOC3, "Contents 3", word::WdStyleType::wdStyleTypeParagraph },
142cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTOC4, "Contents 4", word::WdStyleType::wdStyleTypeParagraph },
143cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTOC5, "Contents 5", word::WdStyleType::wdStyleTypeParagraph },
144cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTOC6, "Contents 6", word::WdStyleType::wdStyleTypeParagraph },
145cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTOC7, "Contents 7", word::WdStyleType::wdStyleTypeParagraph },
146cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTOC8, "Contents 8", word::WdStyleType::wdStyleTypeParagraph },
147cdf0e10cSrcweir     { word::WdBuiltinStyle::wdStyleTOC9, "Contents 9", word::WdStyleType::wdStyleTypeParagraph },
148cdf0e10cSrcweir     { 0, 0, 0 }
149cdf0e10cSrcweir };
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 
getStyleTypes()152cdf0e10cSrcweir static uno::Sequence< rtl::OUString > getStyleTypes()
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aRet(3);
155cdf0e10cSrcweir     rtl::OUString* pArray = aRet.getArray();
156cdf0e10cSrcweir     pArray[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParagraphStyles") );
157cdf0e10cSrcweir     pArray[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharacterStyles") );
158cdf0e10cSrcweir     pArray[2] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingStyles") );
159cdf0e10cSrcweir     return aRet;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1< container::XEnumeration > StyleEnumeration_BASE;
163cdf0e10cSrcweir typedef ::cppu::WeakImplHelper3< container::XNameAccess, container::XIndexAccess, container::XEnumerationAccess > StyleCollectionHelper_BASE;
164cdf0e10cSrcweir /*
165cdf0e10cSrcweir class StylesEnumeration : public StyleEnumeration_BASE
166cdf0e10cSrcweir {
167cdf0e10cSrcweir public:
168cdf0e10cSrcweir 	StylesEnumeration( const SheetMap& sMap ) : mSheetMap( sMap ), mIt( mSheetMap.begin() ) {}
169cdf0e10cSrcweir 	virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException)
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		return ( mIt != mSheetMap.end() );
172cdf0e10cSrcweir 	}
173cdf0e10cSrcweir 	virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
174cdf0e10cSrcweir 	{
175cdf0e10cSrcweir 		if ( !hasMoreElements() )
176cdf0e10cSrcweir 			throw container::NoSuchElementException();
177cdf0e10cSrcweir 		uno::Reference< sheet::XSpreadsheet > xSheet( *mIt++ );
178cdf0e10cSrcweir 		return uno::makeAny( xSheet ) ;
179cdf0e10cSrcweir 	}
180cdf0e10cSrcweir };
181cdf0e10cSrcweir */
182cdf0e10cSrcweir class StyleCollectionHelper : public StyleCollectionHelper_BASE
183cdf0e10cSrcweir {
184cdf0e10cSrcweir private:
185cdf0e10cSrcweir     uno::Reference< frame::XModel > mxModel;
186cdf0e10cSrcweir     uno::Reference< container::XNameAccess > mxStyleFamilies;
187cdf0e10cSrcweir     uno::Reference< container::XNameContainer > mxCurrentStyleFamily;
188cdf0e10cSrcweir     uno::Any cachePos;
189cdf0e10cSrcweir public:
StyleCollectionHelper(const uno::Reference<frame::XModel> & _xModel)190cdf0e10cSrcweir 	StyleCollectionHelper( const uno::Reference< frame::XModel >& _xModel ) : mxModel( _xModel )
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( _xModel, uno::UNO_QUERY_THROW);
193cdf0e10cSrcweir         mxStyleFamilies = xStyleSupplier->getStyleFamilies();
194cdf0e10cSrcweir     }
getCurrentStyleFamily()195cdf0e10cSrcweir     uno::Reference< container::XNameContainer > getCurrentStyleFamily(){ return mxCurrentStyleFamily; }
196cdf0e10cSrcweir 	// XElementAccess
getElementType()197cdf0e10cSrcweir 	virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException) { return  style::XStyle::static_type(0); }
hasElements()198cdf0e10cSrcweir 	virtual ::sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException) { return getCount() > 0; }
199cdf0e10cSrcweir 	// XNameAcess
getByName(const::rtl::OUString & aName)200cdf0e10cSrcweir 	virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
201cdf0e10cSrcweir 	{
202cdf0e10cSrcweir 		if ( !hasByName(aName) )
203cdf0e10cSrcweir 			throw container::NoSuchElementException();
204cdf0e10cSrcweir 		return cachePos;
205cdf0e10cSrcweir 	}
getElementNames()206cdf0e10cSrcweir 	virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw (uno::RuntimeException)
207cdf0e10cSrcweir 	{
208cdf0e10cSrcweir 		uno::Sequence< rtl::OUString > sNames( getCount() );
209cdf0e10cSrcweir 		rtl::OUString* pString = sNames.getArray();
210cdf0e10cSrcweir         uno::Sequence< rtl::OUString > aStyleTypes = getStyleTypes();
211cdf0e10cSrcweir         sal_Int32 nCount = 0;
212cdf0e10cSrcweir         for( sal_Int32 i = 0; i < aStyleTypes.getLength(); i++ )
213cdf0e10cSrcweir         {
214cdf0e10cSrcweir             uno::Reference< container::XNameAccess > xNameAccess( mxStyleFamilies->getByName( aStyleTypes[i] ), uno::UNO_QUERY_THROW );
215cdf0e10cSrcweir             uno::Sequence< rtl::OUString > sElementNames = xNameAccess->getElementNames();
216cdf0e10cSrcweir             for( sal_Int32 j = 0; j < sElementNames.getLength(); j++ )
217cdf0e10cSrcweir             {
218cdf0e10cSrcweir                 pString[nCount++] = sElementNames[j];
219cdf0e10cSrcweir             }
220cdf0e10cSrcweir         }
221cdf0e10cSrcweir 		return sNames;
222cdf0e10cSrcweir 	}
hasByName(const::rtl::OUString & aName)223cdf0e10cSrcweir 	virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
224cdf0e10cSrcweir 	{
225cdf0e10cSrcweir         uno::Sequence< rtl::OUString > aStyleTypes = getStyleTypes();
226cdf0e10cSrcweir         for( sal_Int32 i = 0; i < aStyleTypes.getLength(); i++ )
227cdf0e10cSrcweir         {
228cdf0e10cSrcweir             uno::Reference< container::XNameAccess > xNameAccess( mxStyleFamilies->getByName( aStyleTypes[i] ), uno::UNO_QUERY_THROW );
229cdf0e10cSrcweir             if( xNameAccess->hasByName( aName ) )
230cdf0e10cSrcweir             {
231cdf0e10cSrcweir                 cachePos = xNameAccess->getByName( aName );
232cdf0e10cSrcweir                 mxCurrentStyleFamily.set( xNameAccess, uno::UNO_QUERY_THROW );
233cdf0e10cSrcweir                 return sal_True;
234cdf0e10cSrcweir             }
235cdf0e10cSrcweir         }
236cdf0e10cSrcweir         return sal_False;
237cdf0e10cSrcweir 	}
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 	// XIndexAccess
getCount()240cdf0e10cSrcweir 	virtual ::sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException)
241cdf0e10cSrcweir     {
242cdf0e10cSrcweir         uno::Sequence< rtl::OUString > aStyleTypes = getStyleTypes();
243cdf0e10cSrcweir         sal_Int32 nCount = 0;
244cdf0e10cSrcweir         for( sal_Int32 i = 0; i < aStyleTypes.getLength(); i++ )
245cdf0e10cSrcweir         {
246cdf0e10cSrcweir             uno::Reference< container::XIndexAccess > xIndexAccess( mxStyleFamilies->getByName( aStyleTypes[i] ), uno::UNO_QUERY_THROW );
247cdf0e10cSrcweir             nCount += xIndexAccess->getCount();
248cdf0e10cSrcweir         }
249cdf0e10cSrcweir         return nCount;
250cdf0e10cSrcweir     }
getByIndex(::sal_Int32 Index)251cdf0e10cSrcweir 	virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
252cdf0e10cSrcweir 	{
253cdf0e10cSrcweir 		if ( Index < 0 || Index >= getCount() )
254cdf0e10cSrcweir 			throw lang::IndexOutOfBoundsException();
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         // FIXME: need to make a alphabetically sorted list of style names
257cdf0e10cSrcweir         uno::Sequence< rtl::OUString > aStyleTypes = getStyleTypes();
258cdf0e10cSrcweir         for( sal_Int32 i = 0; i < aStyleTypes.getLength(); i++ )
259cdf0e10cSrcweir         {
260cdf0e10cSrcweir             uno::Reference< container::XIndexAccess > xIndexAccess( mxStyleFamilies->getByName( aStyleTypes[i] ), uno::UNO_QUERY_THROW );
261cdf0e10cSrcweir             sal_Int32 nCount = xIndexAccess->getCount();
262cdf0e10cSrcweir             if( Index >= nCount )
263cdf0e10cSrcweir                 Index -= nCount;
264cdf0e10cSrcweir             else
265cdf0e10cSrcweir             {
266cdf0e10cSrcweir                 mxCurrentStyleFamily.set( xIndexAccess, uno::UNO_QUERY_THROW );
267cdf0e10cSrcweir                 return xIndexAccess->getByIndex( Index );
268cdf0e10cSrcweir             }
269cdf0e10cSrcweir         }
270cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
271cdf0e10cSrcweir 	}
272cdf0e10cSrcweir 	// XEnumerationAccess
createEnumeration()273cdf0e10cSrcweir 	virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration(  ) throw (uno::RuntimeException)
274cdf0e10cSrcweir 	{
275cdf0e10cSrcweir         // FIXME:
276cdf0e10cSrcweir         throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
277cdf0e10cSrcweir 	}
278cdf0e10cSrcweir };
279cdf0e10cSrcweir 
SwVbaStyles(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<css::uno::XComponentContext> & xContext,const uno::Reference<frame::XModel> & xModel)280cdf0e10cSrcweir SwVbaStyles::SwVbaStyles( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ) throw ( script::BasicErrorException ) : SwVbaStyles_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new StyleCollectionHelper( xModel )  ) ), mxModel( xModel )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir     mxMSF.set( mxModel, uno::UNO_QUERY_THROW );
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
285cdf0e10cSrcweir uno::Any
createCollectionObject(const uno::Any & aObject)286cdf0e10cSrcweir SwVbaStyles::createCollectionObject(const uno::Any& aObject)
287cdf0e10cSrcweir {
288cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xStyleProp( aObject, uno::UNO_QUERY_THROW );
289cdf0e10cSrcweir     return uno::makeAny( uno::Reference< word::XStyle >( new SwVbaStyle( this, mxContext, xStyleProp ) ) );
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir uno::Type SAL_CALL
getElementType()293cdf0e10cSrcweir SwVbaStyles::getElementType() throw (uno::RuntimeException)
294cdf0e10cSrcweir {
295cdf0e10cSrcweir 	return word::XStyle::static_type(0);
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir uno::Reference< container::XEnumeration > SAL_CALL
createEnumeration()299cdf0e10cSrcweir SwVbaStyles::createEnumeration() throw (uno::RuntimeException)
300cdf0e10cSrcweir {
301cdf0e10cSrcweir     throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir uno::Any SAL_CALL
Item(const uno::Any & Index1,const uno::Any & Index2)305cdf0e10cSrcweir SwVbaStyles::Item( const uno::Any& Index1, const uno::Any& Index2 ) throw (uno::RuntimeException)
306cdf0e10cSrcweir {
307cdf0e10cSrcweir     //handle WdBuiltinStyle
308cdf0e10cSrcweir     sal_Int32 nIndex = 0;
309cdf0e10cSrcweir     if( ( Index1 >>= nIndex ) && ( nIndex < 0 ) )
310cdf0e10cSrcweir     {
311cdf0e10cSrcweir         for( const BuiltinStyleTable* pTable = aBuiltinStyleTable; pTable != NULL; pTable++ )
312cdf0e10cSrcweir         {
313cdf0e10cSrcweir             if( nIndex == pTable->wdBuiltinStyle )
314cdf0e10cSrcweir             {
315cdf0e10cSrcweir                 rtl::OUString aStyleName = rtl::OUString::createFromAscii( pTable->pOOoStyleName );
316cdf0e10cSrcweir                 if( aStyleName.getLength() > 0 )
317cdf0e10cSrcweir                 {
318cdf0e10cSrcweir                     rtl::OUString aStyleType = SwVbaStyle::getOOoStyleTypeFromMSWord( pTable->wdStyleType );
319cdf0e10cSrcweir                     switch( pTable->wdStyleType )
320cdf0e10cSrcweir                     {
321cdf0e10cSrcweir                         case word::WdStyleType::wdStyleTypeParagraph:
322cdf0e10cSrcweir                         case word::WdStyleType::wdStyleTypeTable:
323cdf0e10cSrcweir                         {
324cdf0e10cSrcweir                             aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParagraphStyles") );
325cdf0e10cSrcweir                             break;
326cdf0e10cSrcweir                         }
327cdf0e10cSrcweir                         case word::WdStyleType::wdStyleTypeCharacter:
328cdf0e10cSrcweir                         {
329cdf0e10cSrcweir                             aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharacterStyles") );
330cdf0e10cSrcweir                             break;
331cdf0e10cSrcweir                         }
332cdf0e10cSrcweir                         case word::WdStyleType::wdStyleTypeList:
333cdf0e10cSrcweir                         {
334cdf0e10cSrcweir                             aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingStyles") );
335cdf0e10cSrcweir                             break;
336cdf0e10cSrcweir                         }
337cdf0e10cSrcweir                         default:
338cdf0e10cSrcweir                             DebugHelper::exception( SbERR_INTERNAL_ERROR, rtl::OUString() );
339cdf0e10cSrcweir                     }
340cdf0e10cSrcweir                     uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxModel, uno::UNO_QUERY_THROW);
341cdf0e10cSrcweir                     uno::Reference< container::XNameAccess > xStylesAccess( xStyleSupplier->getStyleFamilies()->getByName( aStyleType ), uno::UNO_QUERY_THROW );
342cdf0e10cSrcweir                     uno::Reference< beans::XPropertySet > xStyleProps( xStylesAccess->getByName( aStyleName ), uno::UNO_QUERY_THROW );
343cdf0e10cSrcweir                     return uno::makeAny( uno::Reference< word::XStyle >( new SwVbaStyle( this, mxContext, xStyleProps ) ) );
344cdf0e10cSrcweir                 }
345cdf0e10cSrcweir                 else
346cdf0e10cSrcweir                 {
347cdf0e10cSrcweir                     OSL_TRACE("SwVbaStyles::Item: the builtin style type is not implemented");
348cdf0e10cSrcweir                     throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
349cdf0e10cSrcweir                 }
350cdf0e10cSrcweir             }
351cdf0e10cSrcweir         }
352cdf0e10cSrcweir     }
353cdf0e10cSrcweir     return SwVbaStyles_BASE::Item( Index1, Index2 );
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir rtl::OUString&
getServiceImplName()357cdf0e10cSrcweir SwVbaStyles::getServiceImplName()
358cdf0e10cSrcweir {
359cdf0e10cSrcweir     static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaStyles") );
360cdf0e10cSrcweir     return sImplName;
361cdf0e10cSrcweir }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir uno::Sequence< rtl::OUString >
getServiceNames()364cdf0e10cSrcweir SwVbaStyles::getServiceNames()
365cdf0e10cSrcweir {
366cdf0e10cSrcweir     static uno::Sequence< rtl::OUString > aServiceNames;
367cdf0e10cSrcweir     if ( aServiceNames.getLength() == 0 )
368cdf0e10cSrcweir     {
369cdf0e10cSrcweir         aServiceNames.realloc( 1 );
370cdf0e10cSrcweir         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.XStyles" ) );
371cdf0e10cSrcweir     }
372cdf0e10cSrcweir     return aServiceNames;
373cdf0e10cSrcweir }
374