163bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
363bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
463bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
563bba73cSAndrew Rist * distributed with this work for additional information
663bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
763bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
863bba73cSAndrew Rist * "License"); you may not use this file except in compliance
963bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
1063bba73cSAndrew Rist *
1163bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1263bba73cSAndrew Rist *
1363bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
1463bba73cSAndrew Rist * software distributed under the License is distributed on an
1563bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1663bba73cSAndrew Rist * KIND, either express or implied. See the License for the
1763bba73cSAndrew Rist * specific language governing permissions and limitations
1863bba73cSAndrew Rist * under the License.
1963bba73cSAndrew Rist *
2063bba73cSAndrew Rist *************************************************************/
2163bba73cSAndrew Rist
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
24cdf0e10cSrcweir
25cdf0e10cSrcweir #include "XMLTextPropertySetContext.hxx"
26cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
27cdf0e10cSrcweir #include "xmloff/XMLEventsImportContext.hxx"
28cdf0e10cSrcweir #include "xmloff/attrlist.hxx"
29cdf0e10cSrcweir #include "xmloff/families.hxx"
30cdf0e10cSrcweir #include "xmloff/txtprmap.hxx"
31cdf0e10cSrcweir #include "xmloff/txtstyli.hxx"
32cdf0e10cSrcweir #include "xmloff/xmlimp.hxx"
33cdf0e10cSrcweir #include "xmloff/xmltkmap.hxx"
34cdf0e10cSrcweir #include "xmloff/xmltoken.hxx"
35cdf0e10cSrcweir #include "xmloff/xmluconv.hxx"
36cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp>
37cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
38cdf0e10cSrcweir #include <com/sun/star/document/XEventsSupplier.hpp>
39cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
40cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41cdf0e10cSrcweir #include <com/sun/star/style/ParagraphStyleCategory.hpp>
42cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp>
43cdf0e10cSrcweir #include <tools/debug.hxx>
44cdf0e10cSrcweir #include <tools/diagnose_ex.h>
45cdf0e10cSrcweir
46cdf0e10cSrcweir // STL includes
47cdf0e10cSrcweir #include <algorithm>
48cdf0e10cSrcweir #include <functional>
49cdf0e10cSrcweir #include <utility>
50cdf0e10cSrcweir #include <vector>
51cdf0e10cSrcweir
5256b35d86SArmin Le Grand //UUUU
5356b35d86SArmin Le Grand #include <xmlsdtypes.hxx>
5456b35d86SArmin Le Grand #include <xmloff/xmlerror.hxx>
5556b35d86SArmin Le Grand
56cdf0e10cSrcweir using ::rtl::OUString;
57cdf0e10cSrcweir using ::rtl::OUStringBuffer;
58cdf0e10cSrcweir
59cdf0e10cSrcweir using namespace ::std;
60cdf0e10cSrcweir using namespace ::com::sun::star;
61cdf0e10cSrcweir using namespace ::com::sun::star::uno;
62cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
63cdf0e10cSrcweir using namespace ::com::sun::star::style;
64cdf0e10cSrcweir using namespace ::com::sun::star::frame;
65cdf0e10cSrcweir using namespace ::com::sun::star::beans;
66cdf0e10cSrcweir using namespace ::com::sun::star::lang;
67cdf0e10cSrcweir using namespace ::com::sun::star::container;
68cdf0e10cSrcweir //using namespace ::com::sun::star::text;
69cdf0e10cSrcweir using namespace ::xmloff::token;
70cdf0e10cSrcweir
71cdf0e10cSrcweir static __FAR_DATA SvXMLEnumMapEntry aCategoryMap[] =
72cdf0e10cSrcweir {
73cdf0e10cSrcweir { XML_TEXT, ParagraphStyleCategory::TEXT },
74cdf0e10cSrcweir { XML_CHAPTER, ParagraphStyleCategory::CHAPTER },
75cdf0e10cSrcweir { XML_LIST, ParagraphStyleCategory::LIST },
76cdf0e10cSrcweir { XML_INDEX, ParagraphStyleCategory::INDEX },
77cdf0e10cSrcweir { XML_EXTRA, ParagraphStyleCategory::EXTRA },
78cdf0e10cSrcweir { XML_HTML, ParagraphStyleCategory::HTML },
79cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 }
80cdf0e10cSrcweir };
81cdf0e10cSrcweir
SetAttribute(sal_uInt16 nPrefixKey,const OUString & rLocalName,const OUString & rValue)82cdf0e10cSrcweir void XMLTextStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
83cdf0e10cSrcweir const OUString& rLocalName,
84cdf0e10cSrcweir const OUString& rValue )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir if( XML_NAMESPACE_STYLE == nPrefixKey )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir // TODO: use a map here
89cdf0e10cSrcweir if( IsXMLToken( rLocalName, XML_AUTO_UPDATE ) )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir if( IsXMLToken( rValue, XML_TRUE ) )
92cdf0e10cSrcweir bAutoUpdate = sal_True;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_LIST_STYLE_NAME ) )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir sListStyleName = rValue;
97cdf0e10cSrcweir // --> OD 2006-09-21 #i69523#
98cdf0e10cSrcweir mbListStyleSet = sal_True;
99cdf0e10cSrcweir // <--
100cdf0e10cSrcweir }
101cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_MASTER_PAGE_NAME ) )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir sMasterPageName = rValue;
104cdf0e10cSrcweir bHasMasterPageName = sal_True;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir sDataStyleName = rValue;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_CLASS ) )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir sCategoryVal = rValue;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_DEFAULT_OUTLINE_LEVEL ) )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir sal_Int32 nTmp;
117cdf0e10cSrcweir if( SvXMLUnitConverter::convertNumber( nTmp, rValue ) &&
118cdf0e10cSrcweir // nTmp > 0 && nTmp < 256 ) //#outline level, removed by zhaojianwei
119cdf0e10cSrcweir 0 <= nTmp && nTmp <= 10 ) //<-end,add by zhaojianwei
120cdf0e10cSrcweir nOutlineLevel = static_cast< sal_Int8 >( nTmp );
121cdf0e10cSrcweir }
122cdf0e10cSrcweir else
123cdf0e10cSrcweir {
124cdf0e10cSrcweir XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
125cdf0e10cSrcweir }
126cdf0e10cSrcweir }
127cdf0e10cSrcweir else
128cdf0e10cSrcweir {
129cdf0e10cSrcweir XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir TYPEINIT1( XMLTextStyleContext, XMLPropStyleContext );
134cdf0e10cSrcweir
XMLTextStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<XAttributeList> & xAttrList,SvXMLStylesContext & rStyles,sal_uInt16 nFamily,sal_Bool bDefaultStyle)135cdf0e10cSrcweir XMLTextStyleContext::XMLTextStyleContext( SvXMLImport& rImport,
136cdf0e10cSrcweir sal_uInt16 nPrfx, const OUString& rLName,
137cdf0e10cSrcweir const Reference< XAttributeList > & xAttrList,
138cdf0e10cSrcweir SvXMLStylesContext& rStyles, sal_uInt16 nFamily,
139cdf0e10cSrcweir sal_Bool bDefaultStyle )
140cdf0e10cSrcweir : XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle )
141cdf0e10cSrcweir , sIsAutoUpdate( RTL_CONSTASCII_USTRINGPARAM( "IsAutoUpdate" ) )
142cdf0e10cSrcweir , sCategory( RTL_CONSTASCII_USTRINGPARAM( "Category" ) )
143cdf0e10cSrcweir , sNumberingStyleName( RTL_CONSTASCII_USTRINGPARAM( "NumberingStyleName" ) )
144cdf0e10cSrcweir , sOutlineLevel(RTL_CONSTASCII_USTRINGPARAM( "OutlineLevel" ) )//#outline level,add by zhaojianwei
145cdf0e10cSrcweir , sDropCapCharStyleName( RTL_CONSTASCII_USTRINGPARAM( "DropCapCharStyleName" ) )
146cdf0e10cSrcweir , sPageDescName( RTL_CONSTASCII_USTRINGPARAM( "PageDescName" ) )
147cdf0e10cSrcweir //, nOutlineLevel( 0 ) // removed by zhaojianwei
148cdf0e10cSrcweir , nOutlineLevel( -1 ) //<-end, add by zhaojianwei
149cdf0e10cSrcweir , bAutoUpdate( sal_False )
150cdf0e10cSrcweir , bHasMasterPageName( sal_False )
151cdf0e10cSrcweir , bHasCombinedCharactersLetter( sal_False )
152cdf0e10cSrcweir // --> OD 2006-09-21 #i69523#
153cdf0e10cSrcweir , mbListStyleSet( sal_False )
154cdf0e10cSrcweir // <--
155cdf0e10cSrcweir , pEventContext( NULL )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
~XMLTextStyleContext()159cdf0e10cSrcweir XMLTextStyleContext::~XMLTextStyleContext()
160cdf0e10cSrcweir {
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)163cdf0e10cSrcweir SvXMLImportContext *XMLTextStyleContext::CreateChildContext(
164cdf0e10cSrcweir sal_uInt16 nPrefix,
165cdf0e10cSrcweir const OUString& rLocalName,
166cdf0e10cSrcweir const Reference< XAttributeList > & xAttrList )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir SvXMLImportContext *pContext = 0;
169cdf0e10cSrcweir
170cdf0e10cSrcweir if( XML_NAMESPACE_STYLE == nPrefix )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir sal_uInt32 nFamily = 0;
173cdf0e10cSrcweir if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
174cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TEXT;
175cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
176cdf0e10cSrcweir nFamily = XML_TYPE_PROP_PARAGRAPH;
177cdf0e10cSrcweir else if( IsXMLToken( rLocalName, XML_SECTION_PROPERTIES ) )
178cdf0e10cSrcweir nFamily = XML_TYPE_PROP_SECTION;
179cdf0e10cSrcweir else if( IsDefaultStyle() && IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) )
180cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TABLE;
181cdf0e10cSrcweir else if( IsDefaultStyle() && IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) )
182cdf0e10cSrcweir nFamily = XML_TYPE_PROP_TABLE_ROW;
183cdf0e10cSrcweir if( nFamily )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir UniReference < SvXMLImportPropertyMapper > xImpPrMap =
186cdf0e10cSrcweir GetStyles()->GetImportPropertyMapper( GetFamily() );
187cdf0e10cSrcweir if( xImpPrMap.is() )
188cdf0e10cSrcweir pContext = new XMLTextPropertySetContext( GetImport(), nPrefix,
189cdf0e10cSrcweir rLocalName, xAttrList,
190cdf0e10cSrcweir nFamily,
191cdf0e10cSrcweir GetProperties(),
192cdf0e10cSrcweir xImpPrMap,
193cdf0e10cSrcweir sDropCapTextStyleName );
194cdf0e10cSrcweir }
195cdf0e10cSrcweir }
196cdf0e10cSrcweir else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
197cdf0e10cSrcweir IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
198cdf0e10cSrcweir {
199cdf0e10cSrcweir // create and remember events import context
200cdf0e10cSrcweir // (for delayed processing of events)
201cdf0e10cSrcweir pEventContext = new XMLEventsImportContext( GetImport(), nPrefix,
202cdf0e10cSrcweir rLocalName);
203cdf0e10cSrcweir pEventContext->AddRef();
204cdf0e10cSrcweir pContext = pEventContext;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
207cdf0e10cSrcweir if( !pContext )
208cdf0e10cSrcweir pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
209cdf0e10cSrcweir xAttrList );
210cdf0e10cSrcweir
211cdf0e10cSrcweir return pContext;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
CreateAndInsert(sal_Bool bOverwrite)214cdf0e10cSrcweir void XMLTextStyleContext::CreateAndInsert( sal_Bool bOverwrite )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir XMLPropStyleContext::CreateAndInsert( bOverwrite );
217cdf0e10cSrcweir Reference < XStyle > xStyle = GetStyle();
218cdf0e10cSrcweir if( !xStyle.is() || !(bOverwrite || IsNew()) )
219cdf0e10cSrcweir return;
220cdf0e10cSrcweir
221cdf0e10cSrcweir Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
222cdf0e10cSrcweir Reference< XPropertySetInfo > xPropSetInfo =
223cdf0e10cSrcweir xPropSet->getPropertySetInfo();
224cdf0e10cSrcweir if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir Any aAny;
227cdf0e10cSrcweir sal_Bool bTmp = bAutoUpdate;
228cdf0e10cSrcweir aAny.setValue( &bTmp, ::getBooleanCppuType() );
229cdf0e10cSrcweir xPropSet->setPropertyValue( sIsAutoUpdate, aAny );
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
232cdf0e10cSrcweir sal_uInt16 nCategory = ParagraphStyleCategory::TEXT;
233cdf0e10cSrcweir if( XML_STYLE_FAMILY_TEXT_PARAGRAPH == GetFamily() &&
234cdf0e10cSrcweir sCategoryVal.getLength() && xStyle->isUserDefined() &&
235cdf0e10cSrcweir xPropSetInfo->hasPropertyByName( sCategory ) &&
236cdf0e10cSrcweir SvXMLUnitConverter::convertEnum( nCategory, sCategoryVal, aCategoryMap ) )
237cdf0e10cSrcweir {
238cdf0e10cSrcweir Any aAny;
239cdf0e10cSrcweir aAny <<= (sal_Int16)nCategory;
240cdf0e10cSrcweir xPropSet->setPropertyValue( sCategory, aAny );
241cdf0e10cSrcweir }
242cdf0e10cSrcweir
243cdf0e10cSrcweir // tell the style about it's events (if applicable)
244cdf0e10cSrcweir if (NULL != pEventContext)
245cdf0e10cSrcweir {
246cdf0e10cSrcweir // set event suppplier and release reference to context
247cdf0e10cSrcweir Reference<document::XEventsSupplier> xEventsSupplier(xStyle,UNO_QUERY);
248cdf0e10cSrcweir pEventContext->SetEvents(xEventsSupplier);
249cdf0e10cSrcweir pEventContext->ReleaseRef();
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
252cdf0e10cSrcweir // --> OD 2006-10-12 #i69629#
253cdf0e10cSrcweir if ( nOutlineLevel > 0 )
254cdf0e10cSrcweir {
255cdf0e10cSrcweir GetImport().GetTextImport()->AddOutlineStyleCandidate( nOutlineLevel,
256cdf0e10cSrcweir GetDisplayName() );
257cdf0e10cSrcweir }
258cdf0e10cSrcweir // <--
259cdf0e10cSrcweir }
260cdf0e10cSrcweir
SetDefaults()261cdf0e10cSrcweir void XMLTextStyleContext::SetDefaults( )
262cdf0e10cSrcweir {
263cdf0e10cSrcweir if( ( GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ) ||
264cdf0e10cSrcweir ( GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE ) ||
265cdf0e10cSrcweir ( GetFamily() == XML_STYLE_FAMILY_TABLE_ROW ) )
266cdf0e10cSrcweir {
267cdf0e10cSrcweir Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY);
268cdf0e10cSrcweir if (xFactory.is())
269cdf0e10cSrcweir {
270cdf0e10cSrcweir Reference < XInterface > xInt = xFactory->createInstance (
271cdf0e10cSrcweir OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ) );
272cdf0e10cSrcweir Reference < XPropertySet > xProperties ( xInt, UNO_QUERY );
273cdf0e10cSrcweir if ( xProperties.is() )
274cdf0e10cSrcweir FillPropertySet ( xProperties );
275cdf0e10cSrcweir }
276cdf0e10cSrcweir }
277cdf0e10cSrcweir }
278cdf0e10cSrcweir
Finish(sal_Bool bOverwrite)279cdf0e10cSrcweir void XMLTextStyleContext::Finish( sal_Bool bOverwrite )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir XMLPropStyleContext::Finish( bOverwrite );
282cdf0e10cSrcweir
283cdf0e10cSrcweir Reference < XStyle > xStyle = GetStyle();
284cdf0e10cSrcweir // --> OD 2006-09-21 #i69523#
285cdf0e10cSrcweir // consider set empty list style
286cdf0e10cSrcweir // if ( !( sListStyleName.getLength() ||
287cdf0e10cSrcweir if ( !( mbListStyleSet ||
288cdf0e10cSrcweir nOutlineLevel >= 0 || //#outline level,add by zhaojianwei
289cdf0e10cSrcweir sDropCapTextStyleName.getLength() ||
290cdf0e10cSrcweir bHasMasterPageName ) ||
291cdf0e10cSrcweir !xStyle.is() ||
292cdf0e10cSrcweir !( bOverwrite || IsNew() ) )
293cdf0e10cSrcweir return;
294cdf0e10cSrcweir // <--
295cdf0e10cSrcweir
296cdf0e10cSrcweir Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
297cdf0e10cSrcweir Reference< XPropertySetInfo > xPropSetInfo =
298cdf0e10cSrcweir xPropSet->getPropertySetInfo();
299cdf0e10cSrcweir
300cdf0e10cSrcweir //#outline level,add by zhaojianwei
301cdf0e10cSrcweir if( xPropSetInfo->hasPropertyByName( sOutlineLevel ))
302cdf0e10cSrcweir {
303cdf0e10cSrcweir Any aAny;
304cdf0e10cSrcweir if( nOutlineLevel >= 0 )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir aAny <<= nOutlineLevel;
307cdf0e10cSrcweir xPropSet->setPropertyValue( sOutlineLevel, aAny );
308cdf0e10cSrcweir }
309cdf0e10cSrcweir }
310cdf0e10cSrcweir //<-end,zhaojianwei
311cdf0e10cSrcweir
312cdf0e10cSrcweir
313cdf0e10cSrcweir // --> OD 2006-09-21 #i69523#
314cdf0e10cSrcweir // consider set empty list style
315cdf0e10cSrcweir // if( sListStyleName.getLength() )
316cdf0e10cSrcweir if ( mbListStyleSet &&
317cdf0e10cSrcweir xPropSetInfo->hasPropertyByName( sNumberingStyleName ) )
318cdf0e10cSrcweir {
319cdf0e10cSrcweir // --> OD 2006-10-12 #i70223#
320cdf0e10cSrcweir // Only for text document from version prior OOo 2.1 resp. SO 8 PU5:
321cdf0e10cSrcweir // - Do not apply list style, if paragraph style has a default outline
322cdf0e10cSrcweir // level > 0 and thus, will be assigned to the corresponding list
323cdf0e10cSrcweir // level of the outline style.
324cdf0e10cSrcweir bool bApplyListStyle( true );
325cdf0e10cSrcweir if ( nOutlineLevel > 0 )
326cdf0e10cSrcweir {
327cdf0e10cSrcweir // --> OD 2007-12-19 #152540#
328cdf0e10cSrcweir if ( GetImport().IsTextDocInOOoFileFormat() )
329cdf0e10cSrcweir {
330cdf0e10cSrcweir bApplyListStyle = false;
331cdf0e10cSrcweir }
332cdf0e10cSrcweir else
333cdf0e10cSrcweir {
334cdf0e10cSrcweir sal_Int32 nUPD( 0 );
335cdf0e10cSrcweir sal_Int32 nBuild( 0 );
336cdf0e10cSrcweir // --> OD 2008-03-19 #i86058#
337cdf0e10cSrcweir // check explicitly on certain versions
338cdf0e10cSrcweir if ( GetImport().getBuildIds( nUPD, nBuild ) &&
339cdf0e10cSrcweir ( ( nUPD == 641 ) || ( nUPD == 645 ) || // prior OOo 2.0
340cdf0e10cSrcweir ( nUPD == 680 && nBuild <= 9073 ) ) ) // OOo 2.0 - OOo 2.0.4
341cdf0e10cSrcweir {
342cdf0e10cSrcweir bApplyListStyle = false;
343cdf0e10cSrcweir }
344cdf0e10cSrcweir // <--
345cdf0e10cSrcweir }
346cdf0e10cSrcweir // <--
347cdf0e10cSrcweir }
348cdf0e10cSrcweir
349cdf0e10cSrcweir if ( bApplyListStyle )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir if ( !sListStyleName.getLength() )
352cdf0e10cSrcweir {
353cdf0e10cSrcweir Any aAny;
354cdf0e10cSrcweir aAny <<= sListStyleName /* empty string */;
355cdf0e10cSrcweir xPropSet->setPropertyValue( sNumberingStyleName, aAny );
356cdf0e10cSrcweir }
357cdf0e10cSrcweir else
358cdf0e10cSrcweir {
359cdf0e10cSrcweir // change list style name to display name
360cdf0e10cSrcweir OUString sDisplayListStyleName(
361cdf0e10cSrcweir GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST,
362cdf0e10cSrcweir sListStyleName ) );
363cdf0e10cSrcweir // The families container must exist
364cdf0e10cSrcweir const Reference < XNameContainer >& rNumStyles =
365cdf0e10cSrcweir GetImport().GetTextImport()->GetNumberingStyles();
366cdf0e10cSrcweir // if( rNumStyles.is() && rNumStyles->hasByName( sDisplayListStyleName ) &&
367cdf0e10cSrcweir // xPropSetInfo->hasPropertyByName( sNumberingStyleName ) )
368cdf0e10cSrcweir if ( rNumStyles.is() &&
369cdf0e10cSrcweir rNumStyles->hasByName( sDisplayListStyleName ) )
370cdf0e10cSrcweir {
371cdf0e10cSrcweir Any aAny;
372cdf0e10cSrcweir aAny <<= sDisplayListStyleName;
373cdf0e10cSrcweir xPropSet->setPropertyValue( sNumberingStyleName, aAny );
374cdf0e10cSrcweir }
375cdf0e10cSrcweir }
376cdf0e10cSrcweir }
377cdf0e10cSrcweir // <--
378cdf0e10cSrcweir }
379cdf0e10cSrcweir // <--
380cdf0e10cSrcweir
381cdf0e10cSrcweir if( sDropCapTextStyleName.getLength() )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir // change list style name to display name
384cdf0e10cSrcweir OUString sDisplayDropCapTextStyleName(
385cdf0e10cSrcweir GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_TEXT,
386cdf0e10cSrcweir sDropCapTextStyleName ) );
387cdf0e10cSrcweir // The families cointaner must exist
388cdf0e10cSrcweir const Reference < XNameContainer >& rTextStyles =
389cdf0e10cSrcweir GetImport().GetTextImport()->GetTextStyles();
390cdf0e10cSrcweir if( rTextStyles.is() &&
391cdf0e10cSrcweir rTextStyles->hasByName( sDisplayDropCapTextStyleName ) &&
392cdf0e10cSrcweir xPropSetInfo->hasPropertyByName( sDropCapCharStyleName ) )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir Any aAny;
395cdf0e10cSrcweir aAny <<= sDisplayDropCapTextStyleName;
396cdf0e10cSrcweir xPropSet->setPropertyValue( sDropCapCharStyleName, aAny );
397cdf0e10cSrcweir }
398cdf0e10cSrcweir }
399cdf0e10cSrcweir
400cdf0e10cSrcweir if( bHasMasterPageName )
401cdf0e10cSrcweir {
402cdf0e10cSrcweir OUString sDisplayName(
403cdf0e10cSrcweir GetImport().GetStyleDisplayName(
404cdf0e10cSrcweir XML_STYLE_FAMILY_MASTER_PAGE, sMasterPageName ) );
405cdf0e10cSrcweir // The families cointaner must exist
406cdf0e10cSrcweir const Reference < XNameContainer >& rPageStyles =
407cdf0e10cSrcweir GetImport().GetTextImport()->GetPageStyles();
408cdf0e10cSrcweir if( ( !sDisplayName.getLength() ||
409cdf0e10cSrcweir (rPageStyles.is() &&
410cdf0e10cSrcweir rPageStyles->hasByName( sDisplayName )) ) &&
411cdf0e10cSrcweir xPropSetInfo->hasPropertyByName( sPageDescName ) )
412cdf0e10cSrcweir {
413cdf0e10cSrcweir Any aAny;
414cdf0e10cSrcweir aAny <<= sDisplayName;
415cdf0e10cSrcweir xPropSet->setPropertyValue( sPageDescName, aAny );
416cdf0e10cSrcweir }
417cdf0e10cSrcweir }
418cdf0e10cSrcweir }
419cdf0e10cSrcweir
FillPropertySet(const Reference<XPropertySet> & rPropSet)420cdf0e10cSrcweir void XMLTextStyleContext::FillPropertySet(
42156b35d86SArmin Le Grand const Reference<XPropertySet > & rPropSet )
422cdf0e10cSrcweir {
42356b35d86SArmin Le Grand // imitate the FillPropertySet of the super class, so we get a chance to
42456b35d86SArmin Le Grand // catch the combined characters attribute
425cdf0e10cSrcweir
42656b35d86SArmin Le Grand // imitate XMLPropStyleContext::FillPropertySet(...)
42756b35d86SArmin Le Grand SvXMLStylesContext* pSvXMLStylesContext = static_cast< SvXMLStylesContext* >(GetStyles());
42856b35d86SArmin Le Grand UniReference < SvXMLImportPropertyMapper > xImpPrMap = pSvXMLStylesContext->GetImportPropertyMapper(GetFamily());
42956b35d86SArmin Le Grand DBG_ASSERT(xImpPrMap.is(),"Where is the import prop mapper?");
430cdf0e10cSrcweir
43156b35d86SArmin Le Grand if(xImpPrMap.is())
43256b35d86SArmin Le Grand {
43356b35d86SArmin Le Grand // imitate SvXMLImportPropertyMapper::FillPropertySet(...)
43456b35d86SArmin Le Grand // The reason for this is that we have no other way to
43556b35d86SArmin Le Grand // efficiently intercept the value of combined characters. To
43656b35d86SArmin Le Grand // get that value, we could iterate through the map once more,
43756b35d86SArmin Le Grand // but instead we chose to insert the code into this
43856b35d86SArmin Le Grand // iteration. I haven't been able to come up with a much more
43956b35d86SArmin Le Grand // intelligent solution.
440cdf0e10cSrcweir struct _ContextID_Index_Pair aContextIDs[] =
441cdf0e10cSrcweir {
442cdf0e10cSrcweir { CTF_COMBINED_CHARACTERS_FIELD, -1 },
443cdf0e10cSrcweir { CTF_KEEP_TOGETHER, -1 },
444cdf0e10cSrcweir { CTF_BORDER_MODEL, -1 },
445cdf0e10cSrcweir { CTF_TEXT_DISPLAY, -1 },
446cdf0e10cSrcweir { CTF_FONTFAMILYNAME, -1 },
447cdf0e10cSrcweir { CTF_FONTFAMILYNAME_CJK, -1 },
448cdf0e10cSrcweir { CTF_FONTFAMILYNAME_CTL, -1 },
44956b35d86SArmin Le Grand
45056b35d86SArmin Le Grand //UUU need special handling for DrawingLayer FillStyle names
45156b35d86SArmin Le Grand { CTF_FILLGRADIENTNAME, -1 },
45256b35d86SArmin Le Grand { CTF_FILLTRANSNAME, -1 },
45356b35d86SArmin Le Grand { CTF_FILLHATCHNAME, -1 },
45456b35d86SArmin Le Grand { CTF_FILLBITMAPNAME, -1 },
45556b35d86SArmin Le Grand
456cdf0e10cSrcweir { -1, -1 }
457cdf0e10cSrcweir };
458cdf0e10cSrcweir
45956b35d86SArmin Le Grand // the style families associated with the same index modulo 4
46056b35d86SArmin Le Grand static sal_uInt16 aFamilies[] =
46156b35d86SArmin Le Grand {
46256b35d86SArmin Le Grand XML_STYLE_FAMILY_SD_GRADIENT_ID,
46356b35d86SArmin Le Grand XML_STYLE_FAMILY_SD_GRADIENT_ID,
46456b35d86SArmin Le Grand XML_STYLE_FAMILY_SD_HATCH_ID,
46556b35d86SArmin Le Grand XML_STYLE_FAMILY_SD_FILL_IMAGE_ID
46656b35d86SArmin Le Grand };
467cdf0e10cSrcweir
46856b35d86SArmin Le Grand // get property set info
46956b35d86SArmin Le Grand Reference< XPropertySetInfo > xInfo;
47056b35d86SArmin Le Grand UniReference< XMLPropertySetMapper > rPropMapper;
471cdf0e10cSrcweir bool bAutomatic = false;
47256b35d86SArmin Le Grand
47356b35d86SArmin Le Grand if(pSvXMLStylesContext->IsAutomaticStyle() &&
47456b35d86SArmin Le Grand (XML_STYLE_FAMILY_TEXT_TEXT == GetFamily() || XML_STYLE_FAMILY_TEXT_PARAGRAPH == GetFamily()))
475cdf0e10cSrcweir {
476cdf0e10cSrcweir bAutomatic = true;
47756b35d86SArmin Le Grand
478cdf0e10cSrcweir if( GetAutoName().getLength() )
479cdf0e10cSrcweir {
480cdf0e10cSrcweir OUString sAutoProp = ( GetFamily() == XML_STYLE_FAMILY_TEXT_TEXT ) ?
481cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("CharAutoStyleName") ):
482cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("ParaAutoStyleName") );
48356b35d86SArmin Le Grand
484cdf0e10cSrcweir try
485cdf0e10cSrcweir {
48656b35d86SArmin Le Grand if(!xInfo.is())
48756b35d86SArmin Le Grand {
48856b35d86SArmin Le Grand xInfo = rPropSet->getPropertySetInfo();
48956b35d86SArmin Le Grand }
49056b35d86SArmin Le Grand
491cdf0e10cSrcweir if ( xInfo->hasPropertyByName( sAutoProp ) )
49256b35d86SArmin Le Grand {
493cdf0e10cSrcweir rPropSet->setPropertyValue( sAutoProp, makeAny(GetAutoName()) );
49456b35d86SArmin Le Grand }
495cdf0e10cSrcweir else
49656b35d86SArmin Le Grand {
497cdf0e10cSrcweir bAutomatic = false;
49856b35d86SArmin Le Grand }
499cdf0e10cSrcweir }
500cdf0e10cSrcweir catch( const RuntimeException& ) { throw; }
501cdf0e10cSrcweir catch( const Exception& )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
504cdf0e10cSrcweir bAutomatic = false;
505cdf0e10cSrcweir }
506cdf0e10cSrcweir }
507cdf0e10cSrcweir }
50856b35d86SArmin Le Grand
509cdf0e10cSrcweir if( bAutomatic )
51056b35d86SArmin Le Grand {
511cdf0e10cSrcweir xImpPrMap->CheckSpecialContext( GetProperties(), rPropSet, aContextIDs );
51256b35d86SArmin Le Grand }
513cdf0e10cSrcweir else
51456b35d86SArmin Le Grand {
515cdf0e10cSrcweir xImpPrMap->FillPropertySet( GetProperties(), rPropSet, aContextIDs );
51656b35d86SArmin Le Grand }
517cdf0e10cSrcweir
518cdf0e10cSrcweir sal_Int32 nIndex = aContextIDs[0].nIndex;
51956b35d86SArmin Le Grand
52056b35d86SArmin Le Grand // have we found a combined characters
521cdf0e10cSrcweir if ( nIndex != -1 )
522cdf0e10cSrcweir {
523cdf0e10cSrcweir Any& rAny = GetProperties()[nIndex].maValue;
524cdf0e10cSrcweir sal_Bool bVal = *(sal_Bool*)rAny.getValue();
525cdf0e10cSrcweir bHasCombinedCharactersLetter = bVal;
526cdf0e10cSrcweir }
527cdf0e10cSrcweir
528cdf0e10cSrcweir // keep-together: the application default is different from
529cdf0e10cSrcweir // the file format default. Hence, if we always set this
530cdf0e10cSrcweir // value; if we didn't find one, we'll set to false, the file
531cdf0e10cSrcweir // format default.
532cdf0e10cSrcweir // border-model: same
53356b35d86SArmin Le Grand if(IsDefaultStyle() && XML_STYLE_FAMILY_TABLE_ROW == GetFamily())
534cdf0e10cSrcweir {
53556b35d86SArmin Le Grand OUString sIsSplitAllowed = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsSplitAllowed" ) );
53656b35d86SArmin Le Grand DBG_ASSERT( rPropSet->getPropertySetInfo()->hasPropertyByName( sIsSplitAllowed ), "property missing?" );
53756b35d86SArmin Le Grand rPropSet->setPropertyValue(
53856b35d86SArmin Le Grand sIsSplitAllowed,
53956b35d86SArmin Le Grand (aContextIDs[1].nIndex == -1) ? makeAny( false ) : GetProperties()[aContextIDs[1].nIndex].maValue );
540cdf0e10cSrcweir }
541cdf0e10cSrcweir
542*b6ff8b28SArmin Le Grand if(IsDefaultStyle() && XML_STYLE_FAMILY_TABLE_TABLE == GetFamily())
543cdf0e10cSrcweir {
54456b35d86SArmin Le Grand OUString sCollapsingBorders(OUString( RTL_CONSTASCII_USTRINGPARAM( "CollapsingBorders" ) ) );
54556b35d86SArmin Le Grand DBG_ASSERT( rPropSet->getPropertySetInfo()->hasPropertyByName( sCollapsingBorders ), "property missing?" );
54656b35d86SArmin Le Grand rPropSet->setPropertyValue(
54756b35d86SArmin Le Grand sCollapsingBorders,
548cdf0e10cSrcweir (aContextIDs[2].nIndex == -1)
549cdf0e10cSrcweir ? makeAny( false )
550cdf0e10cSrcweir : GetProperties()[aContextIDs[2].nIndex].maValue );
551cdf0e10cSrcweir }
552cdf0e10cSrcweir
553cdf0e10cSrcweir
55456b35d86SArmin Le Grand // iterate over aContextIDs entries, start with 3, prev ones are already used above
55556b35d86SArmin Le Grand for(sal_uInt16 i(3); aContextIDs[i].nContextID != -1; i++)
556cdf0e10cSrcweir {
557cdf0e10cSrcweir nIndex = aContextIDs[i].nIndex;
55856b35d86SArmin Le Grand
559cdf0e10cSrcweir if ( nIndex != -1 )
560cdf0e10cSrcweir {
561cdf0e10cSrcweir // Found!
562cdf0e10cSrcweir struct XMLPropertyState& rState = GetProperties()[nIndex];
56356b35d86SArmin Le Grand
56456b35d86SArmin Le Grand switch(aContextIDs[i].nContextID)
565cdf0e10cSrcweir {
56656b35d86SArmin Le Grand case CTF_FILLGRADIENTNAME:
56756b35d86SArmin Le Grand case CTF_FILLTRANSNAME:
56856b35d86SArmin Le Grand case CTF_FILLHATCHNAME:
56956b35d86SArmin Le Grand case CTF_FILLBITMAPNAME:
57056b35d86SArmin Le Grand {
57156b35d86SArmin Le Grand // DrawingLayer FillStyle name�needs to be mapped to DisplayName
57256b35d86SArmin Le Grand rtl::OUString sStyleName;
57356b35d86SArmin Le Grand rState.maValue >>= sStyleName;
57456b35d86SArmin Le Grand
57556b35d86SArmin Le Grand //UUUU translate the used name from ODF intern to the name used in the Model
57656b35d86SArmin Le Grand sStyleName = GetImport().GetStyleDisplayName(aFamilies[i - 7], sStyleName);
57756b35d86SArmin Le Grand
57856b35d86SArmin Le Grand if(bAutomatic)
57956b35d86SArmin Le Grand {
58056b35d86SArmin Le Grand // in this case the rPropSet got not really filled since above the call to
58156b35d86SArmin Le Grand // CheckSpecialContext was used and not FillPropertySet, thus the below call to
58256b35d86SArmin Le Grand // setPropertyValue can fail/will not be useful (e.g. when the rPropSet
58356b35d86SArmin Le Grand // is a SwXTextCursor).
58456b35d86SArmin Le Grand // This happens for AutoStyles which are already filled in XMLPropStyleContext::CreateAndInsert,
58556b35d86SArmin Le Grand // thus the whole mechanism based on _ContextID_Index_Pair will not work
58656b35d86SArmin Le Grand // in that case. Thus the slots which need to be converted already get
58756b35d86SArmin Le Grand // converted there (its called first) and not here (see
58856b35d86SArmin Le Grand // translateNameBasedDrawingLayerFillStyleDefinitionsToStyleDisplayNames)
58956b35d86SArmin Le Grand // For convenience, still Write back the corrected value to the XMLPropertyState entry
59056b35d86SArmin Le Grand rState.maValue <<= sStyleName;
59156b35d86SArmin Le Grand break;
59256b35d86SArmin Le Grand }
59356b35d86SArmin Le Grand
59456b35d86SArmin Le Grand // Still needed if it's not an AutomaticStyle (!)
59556b35d86SArmin Le Grand try
59656b35d86SArmin Le Grand {
59756b35d86SArmin Le Grand if(!rPropMapper.is())
59856b35d86SArmin Le Grand {
59956b35d86SArmin Le Grand rPropMapper = xImpPrMap->getPropertySetMapper();
60056b35d86SArmin Le Grand }
60156b35d86SArmin Le Grand
60256b35d86SArmin Le Grand // set property
60356b35d86SArmin Le Grand const rtl::OUString& rPropertyName = rPropMapper->GetEntryAPIName(rState.mnIndex);
60456b35d86SArmin Le Grand
60556b35d86SArmin Le Grand if(!xInfo.is())
60656b35d86SArmin Le Grand {
60756b35d86SArmin Le Grand xInfo = rPropSet->getPropertySetInfo();
60856b35d86SArmin Le Grand }
60956b35d86SArmin Le Grand
61056b35d86SArmin Le Grand if(xInfo->hasPropertyByName(rPropertyName))
61156b35d86SArmin Le Grand {
61256b35d86SArmin Le Grand rPropSet->setPropertyValue(rPropertyName,Any(sStyleName));
61356b35d86SArmin Le Grand }
61456b35d86SArmin Le Grand }
61556b35d86SArmin Le Grand catch(::com::sun::star::lang::IllegalArgumentException& e)
61656b35d86SArmin Le Grand {
61756b35d86SArmin Le Grand Sequence< rtl::OUString > aSeq(1);
61856b35d86SArmin Le Grand aSeq[0] = sStyleName;
61956b35d86SArmin Le Grand GetImport().SetError(XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_WARNING, aSeq, e.Message, NULL);
62056b35d86SArmin Le Grand }
62156b35d86SArmin Le Grand break;
62256b35d86SArmin Le Grand }
62356b35d86SArmin Le Grand default:
624cdf0e10cSrcweir {
62556b35d86SArmin Le Grand // check for StarBats and StarMath fonts
62656b35d86SArmin Le Grand Any rAny = rState.maValue;
62756b35d86SArmin Le Grand sal_Int32 nMapperIndex = rState.mnIndex;
62856b35d86SArmin Le Grand
62956b35d86SArmin Le Grand // Now check for font name in rState and set corrected value,
63056b35d86SArmin Le Grand // if necessary.
63156b35d86SArmin Le Grand OUString sFontName;
63256b35d86SArmin Le Grand rAny >>= sFontName;
63356b35d86SArmin Le Grand
63456b35d86SArmin Le Grand if(sFontName.getLength() > 0)
635cdf0e10cSrcweir {
63656b35d86SArmin Le Grand OUString sStarBats(RTL_CONSTASCII_USTRINGPARAM("StarBats"));
63756b35d86SArmin Le Grand OUString sStarMath(RTL_CONSTASCII_USTRINGPARAM("StarMath"));
63856b35d86SArmin Le Grand if(sFontName.equalsIgnoreAsciiCase(sStarBats) ||
63956b35d86SArmin Le Grand sFontName.equalsIgnoreAsciiCase(sStarMath))
64056b35d86SArmin Le Grand {
64156b35d86SArmin Le Grand // construct new value
64256b35d86SArmin Le Grand sFontName = OUString(
64356b35d86SArmin Le Grand RTL_CONSTASCII_USTRINGPARAM("StarSymbol"));
64456b35d86SArmin Le Grand Any aAny(rAny);
64556b35d86SArmin Le Grand aAny <<= sFontName;
64656b35d86SArmin Le Grand
64756b35d86SArmin Le Grand if(!rPropMapper.is())
64856b35d86SArmin Le Grand {
64956b35d86SArmin Le Grand rPropMapper = xImpPrMap->getPropertySetMapper();
65056b35d86SArmin Le Grand }
65156b35d86SArmin Le Grand
65256b35d86SArmin Le Grand // set property
65356b35d86SArmin Le Grand OUString rPropertyName(rPropMapper->GetEntryAPIName(nMapperIndex));
65456b35d86SArmin Le Grand
65556b35d86SArmin Le Grand if(!xInfo.is())
65656b35d86SArmin Le Grand {
65756b35d86SArmin Le Grand xInfo = rPropSet->getPropertySetInfo();
65856b35d86SArmin Le Grand }
65956b35d86SArmin Le Grand
66056b35d86SArmin Le Grand if(xInfo->hasPropertyByName(rPropertyName))
66156b35d86SArmin Le Grand {
66256b35d86SArmin Le Grand rPropSet->setPropertyValue(rPropertyName,aAny);
66356b35d86SArmin Le Grand }
66456b35d86SArmin Le Grand }
66556b35d86SArmin Le Grand // else: "normal" style name -> no correction is necessary
666cdf0e10cSrcweir }
66756b35d86SArmin Le Grand // else: no style name found -> illegal value -> ignore
668cdf0e10cSrcweir }
669cdf0e10cSrcweir }
670cdf0e10cSrcweir }
671cdf0e10cSrcweir }
67256b35d86SArmin Le Grand }
673cdf0e10cSrcweir }
67456b35d86SArmin Le Grand
67556b35d86SArmin Le Grand //eof
676