Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <tools/debug.hxx>
21 : #include <xmloff/XMLShapeStyleContext.hxx>
22 : #include "XMLShapePropertySetContext.hxx"
23 : #include <xmloff/contextid.hxx>
24 : #include <com/sun/star/drawing/XControlShape.hpp>
25 : #include <com/sun/star/beans/XPropertySetInfo.hpp>
26 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 : #include <xmloff/xmlimp.hxx>
28 : #include <xmloff/xmlnumi.hxx>
29 : #include <xmloff/xmlnmspe.hxx>
30 : #include <xmloff/xmltoken.hxx>
31 : #include <xmloff/xmlerror.hxx>
32 : #include <xmloff/maptype.hxx>
33 :
34 : #include "sdpropls.hxx"
35 :
36 : using namespace ::com::sun::star;
37 : using namespace ::com::sun::star::uno;
38 : using namespace ::com::sun::star::beans;
39 : using ::xmloff::token::IsXMLToken;
40 : using ::xmloff::token::XML_TEXT_PROPERTIES;
41 : using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
42 : using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
43 :
44 6815 : TYPEINIT1( XMLShapeStyleContext, XMLPropStyleContext );
45 :
46 1994 : XMLShapeStyleContext::XMLShapeStyleContext(
47 : SvXMLImport& rImport,
48 : sal_uInt16 nPrfx,
49 : const OUString& rLName,
50 : const uno::Reference< xml::sax::XAttributeList >& xAttrList,
51 : SvXMLStylesContext& rStyles,
52 : sal_uInt16 nFamily)
53 : : XMLPropStyleContext(rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
54 1994 : m_bIsNumRuleAlreadyConverted( false )
55 : {
56 1994 : }
57 :
58 2581 : XMLShapeStyleContext::~XMLShapeStyleContext()
59 : {
60 2581 : }
61 :
62 4692 : void XMLShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName, const OUString& rValue )
63 : {
64 4692 : if (m_sControlDataStyleName.isEmpty() && (::xmloff::token::GetXMLToken(::xmloff::token::XML_DATA_STYLE_NAME) == rLocalName))
65 : {
66 0 : m_sControlDataStyleName = rValue;
67 : }
68 4692 : else if( (XML_NAMESPACE_STYLE == nPrefixKey) && IsXMLToken( rLocalName, ::xmloff::token::XML_LIST_STYLE_NAME ) )
69 : {
70 4 : m_sListStyleName = rValue;
71 : }
72 : else
73 : {
74 4688 : XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
75 :
76 11409 : if( (XML_NAMESPACE_STYLE == nPrefixKey) &&
77 7382 : ( IsXMLToken( rLocalName, ::xmloff::token::XML_NAME ) || IsXMLToken( rLocalName, ::xmloff::token::XML_DISPLAY_NAME ) ) )
78 : {
79 2033 : if( !GetName().isEmpty() && !GetDisplayName().isEmpty() && GetName() != GetDisplayName() )
80 : {
81 39 : const_cast< SvXMLImport&>( GetImport() ).
82 78 : AddStyleDisplayName( GetFamily(), GetName(), GetDisplayName() );
83 : }
84 : }
85 : }
86 4692 : }
87 :
88 1070 : SvXMLImportContext *XMLShapeStyleContext::CreateChildContext(
89 : sal_uInt16 nPrefix,
90 : const OUString& rLocalName,
91 : const Reference< xml::sax::XAttributeList > & xAttrList )
92 : {
93 1070 : SvXMLImportContext *pContext = 0;
94 :
95 1070 : if( XML_NAMESPACE_STYLE == nPrefix )
96 : {
97 1070 : sal_uInt32 nFamily = 0;
98 1070 : if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
99 295 : nFamily = XML_TYPE_PROP_TEXT;
100 775 : else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
101 261 : nFamily = XML_TYPE_PROP_PARAGRAPH;
102 514 : else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
103 504 : nFamily = XML_TYPE_PROP_GRAPHIC;
104 1070 : if( nFamily )
105 : {
106 : UniReference < SvXMLImportPropertyMapper > xImpPrMap =
107 1060 : GetStyles()->GetImportPropertyMapper( GetFamily() );
108 1060 : if( xImpPrMap.is() )
109 1060 : pContext = new XMLShapePropertySetContext( GetImport(), nPrefix,
110 : rLocalName, xAttrList,
111 : nFamily,
112 1060 : GetProperties(),
113 2120 : xImpPrMap );
114 : }
115 : }
116 :
117 1070 : if( !pContext )
118 : pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
119 10 : xAttrList );
120 :
121 1070 : return pContext;
122 : }
123 :
124 2268 : void XMLShapeStyleContext::FillPropertySet( const Reference< beans::XPropertySet > & rPropSet )
125 : {
126 2268 : if( !m_bIsNumRuleAlreadyConverted )
127 : {
128 1972 : m_bIsNumRuleAlreadyConverted = true;
129 :
130 : // for compatibility to beta files, search for CTF_SD_NUMBERINGRULES_NAME to
131 : // import numbering rules from the style:properties element
132 1972 : const UniReference< XMLPropertySetMapper >&rMapper = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper();
133 :
134 1972 : ::std::vector< XMLPropertyState > &rProperties = GetProperties();
135 1972 : ::std::vector< XMLPropertyState >::iterator end( rProperties.end() );
136 1972 : ::std::vector< XMLPropertyState >::iterator property;
137 :
138 : // first, look for the old format, where we had a text:list-style-name
139 : // attribute in the style:properties element
140 22733 : for( property = rProperties.begin(); property != end; ++property )
141 : {
142 : // find properties with context
143 20761 : if( (property->mnIndex != -1) && (rMapper->GetEntryContextId( property->mnIndex ) == CTF_SD_NUMBERINGRULES_NAME) )
144 0 : break;
145 : }
146 :
147 : // if we did not find an old list-style-name in the properties, and we need one
148 : // because we got a style:list-style attribute in the style-style element
149 : // we generate one
150 1972 : if( (property == end) && ( !m_sListStyleName.isEmpty() ) )
151 : {
152 4 : sal_Int32 nIndex = rMapper->FindEntryIndex( CTF_SD_NUMBERINGRULES_NAME );
153 : DBG_ASSERT( -1 != nIndex, "can't find numbering rules property entry, can't set numbering rule!" );
154 :
155 4 : XMLPropertyState aNewState( nIndex );
156 4 : rProperties.push_back( aNewState );
157 4 : end = rProperties.end();
158 4 : property = end - 1;
159 : }
160 :
161 : // so, if we have an old or a new list style name, we set its value to
162 : // a numbering rule
163 1972 : if( property != end )
164 : {
165 4 : if( m_sListStyleName.isEmpty() )
166 : {
167 0 : property->maValue >>= m_sListStyleName;
168 : }
169 :
170 4 : const SvxXMLListStyleContext *pListStyle = GetImport().GetTextImport()->FindAutoListStyle( m_sListStyleName );
171 :
172 : DBG_ASSERT( pListStyle, "list-style not found for shape style" );
173 4 : if( pListStyle )
174 : {
175 4 : uno::Reference< container::XIndexReplace > xNumRule( pListStyle->CreateNumRule( GetImport().GetModel() ) );
176 4 : pListStyle->FillUnoNumRule(xNumRule, NULL /* const SvI18NMap * ??? */ );
177 4 : property->maValue <<= xNumRule;
178 : }
179 : else
180 : {
181 0 : property->mnIndex = -1;
182 : }
183 : }
184 : }
185 :
186 : struct _ContextID_Index_Pair aContextIDs[] =
187 : {
188 : { CTF_DASHNAME , -1 },
189 : { CTF_LINESTARTNAME , -1 },
190 : { CTF_LINEENDNAME , -1 },
191 : { CTF_FILLGRADIENTNAME, -1 },
192 : { CTF_FILLTRANSNAME , -1 },
193 : { CTF_FILLHATCHNAME , -1 },
194 : { CTF_FILLBITMAPNAME , -1 },
195 : { CTF_SD_OLE_VIS_AREA_IMPORT_LEFT, -1 },
196 : { CTF_SD_OLE_VIS_AREA_IMPORT_TOP, -1 },
197 : { CTF_SD_OLE_VIS_AREA_IMPORT_WIDTH, -1 },
198 : { CTF_SD_OLE_VIS_AREA_IMPORT_HEIGHT, -1 },
199 : { -1, -1 }
200 2268 : };
201 : static const sal_uInt16 aFamilies[] =
202 : {
203 : XML_STYLE_FAMILY_SD_STROKE_DASH_ID,
204 : XML_STYLE_FAMILY_SD_MARKER_ID,
205 : XML_STYLE_FAMILY_SD_MARKER_ID,
206 : XML_STYLE_FAMILY_SD_GRADIENT_ID,
207 : XML_STYLE_FAMILY_SD_GRADIENT_ID,
208 : XML_STYLE_FAMILY_SD_HATCH_ID,
209 : XML_STYLE_FAMILY_SD_FILL_IMAGE_ID
210 : };
211 :
212 : UniReference < SvXMLImportPropertyMapper > xImpPrMap =
213 2268 : GetStyles()->GetImportPropertyMapper( GetFamily() );
214 : DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
215 2268 : if( xImpPrMap.is() )
216 2271 : xImpPrMap->FillPropertySet( GetProperties(), rPropSet, aContextIDs );
217 :
218 4530 : Reference< XPropertySetInfo > xInfo;
219 : // get property set mapper
220 4530 : UniReference<XMLPropertySetMapper> xPropMapper( xImpPrMap->getPropertySetMapper() );
221 :
222 27180 : for( sal_uInt16 i=0; aContextIDs[i].nContextID != -1; i++ )
223 : {
224 24915 : sal_Int32 nIndex = aContextIDs[i].nIndex;
225 24915 : if( nIndex != -1 ) switch( aContextIDs[i].nContextID )
226 : {
227 : case CTF_DASHNAME:
228 : case CTF_LINESTARTNAME:
229 : case CTF_LINEENDNAME:
230 : case CTF_FILLGRADIENTNAME:
231 : case CTF_FILLTRANSNAME:
232 : case CTF_FILLHATCHNAME:
233 : case CTF_FILLBITMAPNAME:
234 : {
235 118 : struct XMLPropertyState& rState = GetProperties()[nIndex];
236 118 : OUString sStyleName;
237 118 : rState.maValue >>= sStyleName;
238 118 : sStyleName = GetImport().GetStyleDisplayName( aFamilies[i], sStyleName );
239 : try
240 : {
241 :
242 : // set property
243 118 : const OUString& rPropertyName = xPropMapper->GetEntryAPIName(rState.mnIndex);
244 118 : if( !xInfo.is() )
245 83 : xInfo = rPropSet->getPropertySetInfo();
246 118 : if ( xInfo->hasPropertyByName( rPropertyName ) )
247 : {
248 118 : rPropSet->setPropertyValue( rPropertyName, Any( sStyleName ) );
249 : }
250 : }
251 0 : catch ( const ::com::sun::star::lang::IllegalArgumentException& e )
252 : {
253 0 : Sequence<OUString> aSeq(1);
254 0 : aSeq[0] = sStyleName;
255 0 : GetImport().SetError(
256 : XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_WARNING,
257 0 : aSeq, e.Message, NULL );
258 : }
259 118 : break;
260 : }
261 : case CTF_SD_OLE_VIS_AREA_IMPORT_LEFT:
262 : case CTF_SD_OLE_VIS_AREA_IMPORT_TOP:
263 : case CTF_SD_OLE_VIS_AREA_IMPORT_WIDTH:
264 : case CTF_SD_OLE_VIS_AREA_IMPORT_HEIGHT:
265 : {
266 3 : struct XMLPropertyState& rState = GetProperties()[nIndex];
267 3 : const OUString& rPropertyName = xPropMapper->GetEntryAPIName(rState.mnIndex);
268 : try
269 : {
270 3 : if( !xInfo.is() )
271 3 : xInfo = rPropSet->getPropertySetInfo();
272 3 : if ( xInfo->hasPropertyByName( rPropertyName ) )
273 : {
274 0 : rPropSet->setPropertyValue( rPropertyName, rState.maValue );
275 : }
276 : }
277 0 : catch ( const ::com::sun::star::lang::IllegalArgumentException& e )
278 : {
279 0 : Sequence<OUString> aSeq;
280 0 : GetImport().SetError(
281 : XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_WARNING,
282 0 : aSeq, e.Message, NULL );
283 : }
284 3 : break;
285 : }
286 : }
287 : }
288 :
289 2265 : if (!m_sControlDataStyleName.isEmpty())
290 : { // we had a data-style-name attribute
291 :
292 : // set the formatting on the control model of the control shape
293 0 : uno::Reference< drawing::XControlShape > xControlShape(rPropSet, uno::UNO_QUERY);
294 : DBG_ASSERT(xControlShape.is(), "XMLShapeStyleContext::FillPropertySet: data style for a non-control shape!");
295 0 : if (xControlShape.is())
296 : {
297 0 : uno::Reference< beans::XPropertySet > xControlModel(xControlShape->getControl(), uno::UNO_QUERY);
298 : DBG_ASSERT(xControlModel.is(), "XMLShapeStyleContext::FillPropertySet: no control model for the shape!");
299 0 : if (xControlModel.is())
300 : {
301 0 : GetImport().GetFormImport()->applyControlNumberStyle(xControlModel, m_sControlDataStyleName);
302 0 : }
303 0 : }
304 2268 : }
305 2265 : }
306 :
307 170 : void XMLShapeStyleContext::Finish( bool /*bOverwrite*/ )
308 : {
309 170 : }
310 :
311 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|