1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: XMLShapeStyleContext.cxx,v $
*
* $Revision: 1.14 $
*
* last change: $Author: hr $ $Date: 2006-06-19 18:08:55 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
#include <tools/debug.hxx>
#ifndef _XMLOFF_XMLSHAPESTYLECONTEXT_HXX
#include "XMLShapeStyleContext.hxx"
#endif
#ifndef _XMLOFF_XMLSHAPEPROPERTYSETCONTEXT_HXX
#include "XMLShapePropertySetContext.hxx"
#endif
#ifndef _XMLOFF_CONTEXTID_HXX_
#include "contextid.hxx"
#endif
#ifndef _COM_SUN_STAR_DRAWING_XCONTROLSHAPE_HPP_
#include <com/sun/star/drawing/XControlShape.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_
#include "com/sun/star/beans/XPropertySetInfo.hpp"
#endif
#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#endif
#ifndef _XMLOFF_XMLIMP_HXX
#include "xmlimp.hxx"
#endif
#ifndef _XMLOFF_XMLNUMI_HXX
#include "xmlnumi.hxx"
#endif
#ifndef _XMLOFF_XMLNMSPE_HXX
#include <xmlnmspe.hxx>
#endif
#ifndef _XMLOFF_XMLTOKEN_HXX
#include "xmltoken.hxx"
#endif
#ifndef _XMLOFF_XMLERROR_HXX
#include "xmlerror.hxx"
#endif
#ifndef _XMLOFF_PROPMAPPINGTYPES_HXX
#include "maptype.hxx"
#endif
#include "sdpropls.hxx"
using namespace ::rtl;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using ::xmloff::token::IsXMLToken;
using ::xmloff::token::XML_TEXT_PROPERTIES;
using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
//////////////////////////////////////////////////////////////////////////////
TYPEINIT1( XMLShapeStyleContext, XMLPropStyleContext );
XMLShapeStyleContext::XMLShapeStyleContext(
SvXMLImport& rImport,
sal_uInt16 nPrfx,
const OUString& rLName,
const uno::Reference< xml::sax::XAttributeList >& xAttrList,
SvXMLStylesContext& rStyles,
sal_uInt16 nFamily)
: XMLPropStyleContext(rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
m_bIsNumRuleAlreadyConverted( sal_False )
{
}
XMLShapeStyleContext::~XMLShapeStyleContext()
{
}
void XMLShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
{
if ((0 == m_sControlDataStyleName.getLength()) && (::xmloff::token::GetXMLToken(::xmloff::token::XML_DATA_STYLE_NAME) == rLocalName))
{
m_sControlDataStyleName = rValue;
}
else if( (XML_NAMESPACE_STYLE == nPrefixKey) && IsXMLToken( rLocalName, ::xmloff::token::XML_LIST_STYLE_NAME ) )
{
m_sListStyleName = rValue;
}
else
{
XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
if( (XML_NAMESPACE_STYLE == nPrefixKey) &&
( IsXMLToken( rLocalName, ::xmloff::token::XML_NAME ) || IsXMLToken( rLocalName, ::xmloff::token::XML_DISPLAY_NAME ) ) )
{
if( GetName().getLength() && GetDisplayName().getLength() && GetName() != GetDisplayName() )
{
const_cast< SvXMLImport&>( GetImport() ).
AddStyleDisplayName( GetFamily(), GetName(), GetDisplayName() );
}
}
}
}
SvXMLImportContext *XMLShapeStyleContext::CreateChildContext(
sal_uInt16 nPrefix,
const OUString& rLocalName,
const Reference< xml::sax::XAttributeList > & xAttrList )
{
SvXMLImportContext *pContext = 0;
if( XML_NAMESPACE_STYLE == nPrefix )
{
sal_uInt32 nFamily = 0;
if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
nFamily = XML_TYPE_PROP_TEXT;
else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
nFamily = XML_TYPE_PROP_PARAGRAPH;
else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
nFamily = XML_TYPE_PROP_GRAPHIC;
if( nFamily )
{
UniReference < SvXMLImportPropertyMapper > xImpPrMap =
GetStyles()->GetImportPropertyMapper( GetFamily() );
if( xImpPrMap.is() )
pContext = new XMLShapePropertySetContext( GetImport(), nPrefix,
rLocalName, xAttrList,
nFamily,
GetProperties(),
xImpPrMap );
}
}
if( !pContext )
pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
xAttrList );
return pContext;
}
void XMLShapeStyleContext::FillPropertySet( const Reference< beans::XPropertySet > & rPropSet )
{
if( !m_bIsNumRuleAlreadyConverted )
{
m_bIsNumRuleAlreadyConverted = sal_True;
// for compatibility to beta files, search for CTF_SD_NUMBERINGRULES_NAME to
// import numbering rules from the style:properties element
const UniReference< XMLPropertySetMapper >&rMapper = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper();
::std::vector< XMLPropertyState > &rProperties = GetProperties();
::std::vector< XMLPropertyState >::iterator end( rProperties.end() );
::std::vector< XMLPropertyState >::iterator property;
// first, look for the old format, where we had a text:list-style-name
// attribute in the style:properties element
for( property = rProperties.begin(); property != end; property++ )
{
// find properties with context
if( (property->mnIndex != -1) && (rMapper->GetEntryContextId( property->mnIndex ) == CTF_SD_NUMBERINGRULES_NAME) )
break;
}
// if we did not find an old list-style-name in the properties, and we need one
// because we got a style:list-style attribute in the style-style element
// we generate one
if( (property == end) && ( 0 != m_sListStyleName.getLength() ) )
{
sal_Int32 nIndex = rMapper->FindEntryIndex( CTF_SD_NUMBERINGRULES_NAME );
DBG_ASSERT( -1 != nIndex, "can't find numbering rules property entry, can't set numbering rule!" );
XMLPropertyState aNewState( nIndex );
rProperties.push_back( aNewState );
end = rProperties.end();
property = end - 1;
}
// so, if we have an old or a new list style name, we set its value to
// a numbering rule
if( property != end )
{
if( 0 == m_sListStyleName.getLength() )
{
property->maValue >>= m_sListStyleName;
}
const SvxXMLListStyleContext *pListStyle = GetImport().GetTextImport()->FindAutoListStyle( m_sListStyleName );
DBG_ASSERT( pListStyle, "list-style not found for shape style" );
if( pListStyle )
{
uno::Reference< container::XIndexReplace > xNumRule( pListStyle->CreateNumRule( GetImport().GetModel() ) );
pListStyle->FillUnoNumRule(xNumRule, NULL /* const SvI18NMap * ??? */ );
property->maValue <<= xNumRule;
}
else
{
property->mnIndex = -1;
}
}
}
const sal_uInt16 MAX_SPECIAL_DRAW_STYLES = 7;
struct _ContextID_Index_Pair aContextIDs[MAX_SPECIAL_DRAW_STYLES+1] =
{
{ CTF_DASHNAME , -1 },
{ CTF_LINESTARTNAME , -1 },
{ CTF_LINEENDNAME , -1 },
{ CTF_FILLGRADIENTNAME, -1 },
{ CTF_FILLTRANSNAME , -1 },
{ CTF_FILLHATCHNAME , -1 },
{ CTF_FILLBITMAPNAME , -1 },
{ -1, -1 }
};
static sal_uInt16 aFamilies[MAX_SPECIAL_DRAW_STYLES] =
{
XML_STYLE_FAMILY_SD_STROKE_DASH_ID,
XML_STYLE_FAMILY_SD_MARKER_ID,
XML_STYLE_FAMILY_SD_MARKER_ID,
XML_STYLE_FAMILY_SD_GRADIENT_ID,
XML_STYLE_FAMILY_SD_GRADIENT_ID,
XML_STYLE_FAMILY_SD_HATCH_ID,
XML_STYLE_FAMILY_SD_FILL_IMAGE_ID
};
UniReference < SvXMLImportPropertyMapper > xImpPrMap =
GetStyles()->GetImportPropertyMapper( GetFamily() );
DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
if( xImpPrMap.is() )
xImpPrMap->FillPropertySet( GetProperties(), rPropSet, aContextIDs );
Reference< XPropertySetInfo > xInfo;
for( sal_uInt16 i=0; i<MAX_SPECIAL_DRAW_STYLES; i++ )
{
sal_Int32 nIndex = aContextIDs[i].nIndex;
if( nIndex != -1 )
{
struct XMLPropertyState& rState = GetProperties()[nIndex];
OUString sStyleName;
rState.maValue >>= sStyleName;
sStyleName = GetImport().GetStyleDisplayName( aFamilies[i],
sStyleName );
// get property set mapper
UniReference<XMLPropertySetMapper> rPropMapper =
xImpPrMap->getPropertySetMapper();
// set property
const OUString& rPropertyName =
rPropMapper->GetEntryAPIName(rState.mnIndex);
if( !xInfo.is() )
xInfo = rPropSet->getPropertySetInfo();
if ( xInfo->hasPropertyByName( rPropertyName ) )
{
Any aAny;
aAny <<= sStyleName;
try
{
rPropSet->setPropertyValue( rPropertyName, aAny );
}
catch ( ::com::sun::star::lang::IllegalArgumentException& e )
{
Sequence<OUString> aSeq(1);
aSeq[0] = sStyleName;
GetImport().SetError(
XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_ERROR,
aSeq, e.Message, NULL );
}
}
}
}
if (m_sControlDataStyleName.getLength())
{ // we had a data-style-name attribute
// set the formatting on the control model of the control shape
uno::Reference< drawing::XControlShape > xControlShape(rPropSet, uno::UNO_QUERY);
DBG_ASSERT(xControlShape.is(), "XMLShapeStyleContext::FillPropertySet: data style for a non-control shape!");
if (xControlShape.is())
{
uno::Reference< beans::XPropertySet > xControlModel(xControlShape->getControl(), uno::UNO_QUERY);
DBG_ASSERT(xControlModel.is(), "XMLShapeStyleContext::FillPropertySet: no control model for the shape!");
if (xControlModel.is())
{
GetImport().GetFormImport()->applyControlNumberStyle(xControlModel, m_sControlDataStyleName);
}
}
}
}
void XMLShapeStyleContext::Finish( sal_Bool /*bOverwrite*/ )
{
}
|