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