1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLShapeStyleContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include <tools/debug.hxx>
35 #include <xmloff/XMLShapeStyleContext.hxx>
36 #include "XMLShapePropertySetContext.hxx"
37 #include <xmloff/contextid.hxx>
38 #include <com/sun/star/drawing/XControlShape.hpp>
39 #include "com/sun/star/beans/XPropertySetInfo.hpp"
40 #include <com/sun/star/lang/IllegalArgumentException.hpp>
41 #include <xmloff/xmlimp.hxx>
42 #include <xmloff/xmlnumi.hxx>
43 #include <xmlnmspe.hxx>
44 #include <xmloff/xmltoken.hxx>
45 #include "xmlerror.hxx"
46 #include <xmloff/maptype.hxx>
48 #include "sdpropls.hxx"
50 using ::rtl::OUString
;
51 using ::rtl::OUStringBuffer
;
53 using namespace ::com::sun::star
;
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::beans
;
56 using ::xmloff::token::IsXMLToken
;
57 using ::xmloff::token::XML_TEXT_PROPERTIES
;
58 using ::xmloff::token::XML_GRAPHIC_PROPERTIES
;
59 using ::xmloff::token::XML_PARAGRAPH_PROPERTIES
;
61 //////////////////////////////////////////////////////////////////////////////
63 TYPEINIT1( XMLShapeStyleContext
, XMLPropStyleContext
);
65 XMLShapeStyleContext::XMLShapeStyleContext(
68 const OUString
& rLName
,
69 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
70 SvXMLStylesContext
& rStyles
,
72 : XMLPropStyleContext(rImport
, nPrfx
, rLName
, xAttrList
, rStyles
, nFamily
),
73 m_bIsNumRuleAlreadyConverted( sal_False
)
77 XMLShapeStyleContext::~XMLShapeStyleContext()
81 void XMLShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey
, const ::rtl::OUString
& rLocalName
, const ::rtl::OUString
& rValue
)
83 if ((0 == m_sControlDataStyleName
.getLength()) && (::xmloff::token::GetXMLToken(::xmloff::token::XML_DATA_STYLE_NAME
) == rLocalName
))
85 m_sControlDataStyleName
= rValue
;
87 else if( (XML_NAMESPACE_STYLE
== nPrefixKey
) && IsXMLToken( rLocalName
, ::xmloff::token::XML_LIST_STYLE_NAME
) )
89 m_sListStyleName
= rValue
;
93 XMLPropStyleContext::SetAttribute( nPrefixKey
, rLocalName
, rValue
);
95 if( (XML_NAMESPACE_STYLE
== nPrefixKey
) &&
96 ( IsXMLToken( rLocalName
, ::xmloff::token::XML_NAME
) || IsXMLToken( rLocalName
, ::xmloff::token::XML_DISPLAY_NAME
) ) )
98 if( GetName().getLength() && GetDisplayName().getLength() && GetName() != GetDisplayName() )
100 const_cast< SvXMLImport
&>( GetImport() ).
101 AddStyleDisplayName( GetFamily(), GetName(), GetDisplayName() );
107 SvXMLImportContext
*XMLShapeStyleContext::CreateChildContext(
109 const OUString
& rLocalName
,
110 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
112 SvXMLImportContext
*pContext
= 0;
114 if( XML_NAMESPACE_STYLE
== nPrefix
)
116 sal_uInt32 nFamily
= 0;
117 if( IsXMLToken( rLocalName
, XML_TEXT_PROPERTIES
) )
118 nFamily
= XML_TYPE_PROP_TEXT
;
119 else if( IsXMLToken( rLocalName
, XML_PARAGRAPH_PROPERTIES
) )
120 nFamily
= XML_TYPE_PROP_PARAGRAPH
;
121 else if( IsXMLToken( rLocalName
, XML_GRAPHIC_PROPERTIES
) )
122 nFamily
= XML_TYPE_PROP_GRAPHIC
;
125 UniReference
< SvXMLImportPropertyMapper
> xImpPrMap
=
126 GetStyles()->GetImportPropertyMapper( GetFamily() );
128 pContext
= new XMLShapePropertySetContext( GetImport(), nPrefix
,
129 rLocalName
, xAttrList
,
137 pContext
= XMLPropStyleContext::CreateChildContext( nPrefix
, rLocalName
,
143 void XMLShapeStyleContext::FillPropertySet( const Reference
< beans::XPropertySet
> & rPropSet
)
145 if( !m_bIsNumRuleAlreadyConverted
)
147 m_bIsNumRuleAlreadyConverted
= sal_True
;
149 // for compatibility to beta files, search for CTF_SD_NUMBERINGRULES_NAME to
150 // import numbering rules from the style:properties element
151 const UniReference
< XMLPropertySetMapper
>&rMapper
= GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper();
153 ::std::vector
< XMLPropertyState
> &rProperties
= GetProperties();
154 ::std::vector
< XMLPropertyState
>::iterator
end( rProperties
.end() );
155 ::std::vector
< XMLPropertyState
>::iterator property
;
157 // first, look for the old format, where we had a text:list-style-name
158 // attribute in the style:properties element
159 for( property
= rProperties
.begin(); property
!= end
; property
++ )
161 // find properties with context
162 if( (property
->mnIndex
!= -1) && (rMapper
->GetEntryContextId( property
->mnIndex
) == CTF_SD_NUMBERINGRULES_NAME
) )
166 // if we did not find an old list-style-name in the properties, and we need one
167 // because we got a style:list-style attribute in the style-style element
169 if( (property
== end
) && ( 0 != m_sListStyleName
.getLength() ) )
171 sal_Int32 nIndex
= rMapper
->FindEntryIndex( CTF_SD_NUMBERINGRULES_NAME
);
172 DBG_ASSERT( -1 != nIndex
, "can't find numbering rules property entry, can't set numbering rule!" );
174 XMLPropertyState
aNewState( nIndex
);
175 rProperties
.push_back( aNewState
);
176 end
= rProperties
.end();
180 // so, if we have an old or a new list style name, we set its value to
182 if( property
!= end
)
184 if( 0 == m_sListStyleName
.getLength() )
186 property
->maValue
>>= m_sListStyleName
;
189 const SvxXMLListStyleContext
*pListStyle
= GetImport().GetTextImport()->FindAutoListStyle( m_sListStyleName
);
191 DBG_ASSERT( pListStyle
, "list-style not found for shape style" );
194 uno::Reference
< container::XIndexReplace
> xNumRule( pListStyle
->CreateNumRule( GetImport().GetModel() ) );
195 pListStyle
->FillUnoNumRule(xNumRule
, NULL
/* const SvI18NMap * ??? */ );
196 property
->maValue
<<= xNumRule
;
200 property
->mnIndex
= -1;
205 struct _ContextID_Index_Pair aContextIDs
[] =
207 { CTF_DASHNAME
, -1 },
208 { CTF_LINESTARTNAME
, -1 },
209 { CTF_LINEENDNAME
, -1 },
210 { CTF_FILLGRADIENTNAME
, -1 },
211 { CTF_FILLTRANSNAME
, -1 },
212 { CTF_FILLHATCHNAME
, -1 },
213 { CTF_FILLBITMAPNAME
, -1 },
214 { CTF_SD_OLE_VIS_AREA_IMPORT_LEFT
, -1 },
215 { CTF_SD_OLE_VIS_AREA_IMPORT_TOP
, -1 },
216 { CTF_SD_OLE_VIS_AREA_IMPORT_WIDTH
, -1 },
217 { CTF_SD_OLE_VIS_AREA_IMPORT_HEIGHT
, -1 },
220 static sal_uInt16 aFamilies
[] =
222 XML_STYLE_FAMILY_SD_STROKE_DASH_ID
,
223 XML_STYLE_FAMILY_SD_MARKER_ID
,
224 XML_STYLE_FAMILY_SD_MARKER_ID
,
225 XML_STYLE_FAMILY_SD_GRADIENT_ID
,
226 XML_STYLE_FAMILY_SD_GRADIENT_ID
,
227 XML_STYLE_FAMILY_SD_HATCH_ID
,
228 XML_STYLE_FAMILY_SD_FILL_IMAGE_ID
231 UniReference
< SvXMLImportPropertyMapper
> xImpPrMap
=
232 GetStyles()->GetImportPropertyMapper( GetFamily() );
233 DBG_ASSERT( xImpPrMap
.is(), "There is the import prop mapper" );
235 xImpPrMap
->FillPropertySet( GetProperties(), rPropSet
, aContextIDs
);
237 Reference
< XPropertySetInfo
> xInfo
;
238 // get property set mapper
239 UniReference
<XMLPropertySetMapper
> xPropMapper( xImpPrMap
->getPropertySetMapper() );
241 for( sal_uInt16 i
=0; aContextIDs
[i
].nContextID
!= -1; i
++ )
243 sal_Int32 nIndex
= aContextIDs
[i
].nIndex
;
244 if( nIndex
!= -1 ) switch( aContextIDs
[i
].nContextID
)
247 case CTF_LINESTARTNAME
:
248 case CTF_LINEENDNAME
:
249 case CTF_FILLGRADIENTNAME
:
250 case CTF_FILLTRANSNAME
:
251 case CTF_FILLHATCHNAME
:
252 case CTF_FILLBITMAPNAME
:
254 struct XMLPropertyState
& rState
= GetProperties()[nIndex
];
256 rState
.maValue
>>= sStyleName
;
257 sStyleName
= GetImport().GetStyleDisplayName( aFamilies
[i
], sStyleName
);
262 const OUString
& rPropertyName
= xPropMapper
->GetEntryAPIName(rState
.mnIndex
);
264 xInfo
= rPropSet
->getPropertySetInfo();
265 if ( xInfo
->hasPropertyByName( rPropertyName
) )
267 rPropSet
->setPropertyValue( rPropertyName
, Any( sStyleName
) );
270 catch ( ::com::sun::star::lang::IllegalArgumentException
& e
)
272 Sequence
<OUString
> aSeq(1);
273 aSeq
[0] = sStyleName
;
274 GetImport().SetError(
275 XMLERROR_STYLE_PROP_VALUE
| XMLERROR_FLAG_WARNING
,
276 aSeq
, e
.Message
, NULL
);
280 case CTF_SD_OLE_VIS_AREA_IMPORT_LEFT
:
281 case CTF_SD_OLE_VIS_AREA_IMPORT_TOP
:
282 case CTF_SD_OLE_VIS_AREA_IMPORT_WIDTH
:
283 case CTF_SD_OLE_VIS_AREA_IMPORT_HEIGHT
:
285 struct XMLPropertyState
& rState
= GetProperties()[nIndex
];
286 const OUString
& rPropertyName
= xPropMapper
->GetEntryAPIName(rState
.mnIndex
);
290 xInfo
= rPropSet
->getPropertySetInfo();
291 if ( xInfo
->hasPropertyByName( rPropertyName
) )
293 rPropSet
->setPropertyValue( rPropertyName
, rState
.maValue
);
296 catch ( ::com::sun::star::lang::IllegalArgumentException
& e
)
298 Sequence
<OUString
> aSeq
;
299 GetImport().SetError(
300 XMLERROR_STYLE_PROP_VALUE
| XMLERROR_FLAG_WARNING
,
301 aSeq
, e
.Message
, NULL
);
308 if (m_sControlDataStyleName
.getLength())
309 { // we had a data-style-name attribute
311 // set the formatting on the control model of the control shape
312 uno::Reference
< drawing::XControlShape
> xControlShape(rPropSet
, uno::UNO_QUERY
);
313 DBG_ASSERT(xControlShape
.is(), "XMLShapeStyleContext::FillPropertySet: data style for a non-control shape!");
314 if (xControlShape
.is())
316 uno::Reference
< beans::XPropertySet
> xControlModel(xControlShape
->getControl(), uno::UNO_QUERY
);
317 DBG_ASSERT(xControlModel
.is(), "XMLShapeStyleContext::FillPropertySet: no control model for the shape!");
318 if (xControlModel
.is())
320 GetImport().GetFormImport()->applyControlNumberStyle(xControlModel
, m_sControlDataStyleName
);
326 void XMLShapeStyleContext::Finish( sal_Bool
/*bOverwrite*/ )