Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLImageMapContext.hxx"
30 : : #include <rtl/ustrbuf.hxx>
31 : : #include <com/sun/star/uno/Reference.h>
32 : : #include <com/sun/star/beans/XPropertySet.hpp>
33 : : #include <com/sun/star/beans/XPropertySetInfo.hpp>
34 : : #include <com/sun/star/xml/sax/XAttributeList.hpp>
35 : : #include <com/sun/star/container/XIndexContainer.hpp>
36 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 : : #include <com/sun/star/drawing/PointSequenceSequence.hpp>
38 : :
39 : : #include <com/sun/star/document/XEventsSupplier.hpp>
40 : : #include <com/sun/star/awt/Rectangle.hpp>
41 : : #include <xmloff/xmltoken.hxx>
42 : : #include <xmloff/xmlimp.hxx>
43 : : #include <xmloff/xmltkmap.hxx>
44 : : #include "xmloff/xmlnmspe.hxx"
45 : : #include <xmloff/nmspmap.hxx>
46 : : #include <xmloff/xmluconv.hxx>
47 : : #include "xexptran.hxx"
48 : : #include "xmloff/xmlerror.hxx"
49 : : #include <xmloff/XMLEventsImportContext.hxx>
50 : : #include "XMLStringBufferImportContext.hxx"
51 : : #include <tools/debug.hxx>
52 : :
53 : :
54 : : using namespace ::com::sun::star;
55 : : using namespace ::xmloff::token;
56 : :
57 : : using ::rtl::OUString;
58 : : using ::rtl::OUStringBuffer;
59 : : using ::com::sun::star::beans::XPropertySet;
60 : : using ::com::sun::star::beans::XPropertySetInfo;
61 : : using ::com::sun::star::container::XIndexContainer;
62 : : using ::com::sun::star::lang::XMultiServiceFactory;
63 : : using ::com::sun::star::uno::Reference;
64 : : using ::com::sun::star::uno::UNO_QUERY;
65 : : using ::com::sun::star::xml::sax::XAttributeList;
66 : : using ::com::sun::star::uno::XInterface;
67 : : using ::com::sun::star::uno::Any;
68 : : using ::com::sun::star::drawing::PointSequenceSequence;
69 : : using ::com::sun::star::document::XEventsSupplier;
70 : :
71 : :
72 : : enum XMLImageMapToken
73 : : {
74 : : XML_TOK_IMAP_URL,
75 : : XML_TOK_IMAP_X,
76 : : XML_TOK_IMAP_Y,
77 : : XML_TOK_IMAP_CENTER_X,
78 : : XML_TOK_IMAP_CENTER_Y,
79 : : XML_TOK_IMAP_WIDTH,
80 : : XML_TOK_IMAP_HEIGTH,
81 : : XML_TOK_IMAP_POINTS,
82 : : XML_TOK_IMAP_VIEWBOX,
83 : : XML_TOK_IMAP_NOHREF,
84 : : XML_TOK_IMAP_NAME,
85 : : XML_TOK_IMAP_RADIUS,
86 : : XML_TOK_IMAP_TARGET
87 : : };
88 : :
89 : : static SvXMLTokenMapEntry aImageMapObjectTokenMap[] =
90 : : {
91 : : { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAP_URL },
92 : : { XML_NAMESPACE_OFFICE, XML_NAME, XML_TOK_IMAP_NAME },
93 : : { XML_NAMESPACE_DRAW, XML_NOHREF, XML_TOK_IMAP_NOHREF },
94 : : { XML_NAMESPACE_SVG, XML_X, XML_TOK_IMAP_X },
95 : : { XML_NAMESPACE_SVG, XML_Y, XML_TOK_IMAP_Y },
96 : : { XML_NAMESPACE_SVG, XML_CX, XML_TOK_IMAP_CENTER_X },
97 : : { XML_NAMESPACE_SVG, XML_CY, XML_TOK_IMAP_CENTER_Y },
98 : : { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_IMAP_WIDTH },
99 : : { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_IMAP_HEIGTH },
100 : : { XML_NAMESPACE_SVG, XML_R, XML_TOK_IMAP_RADIUS },
101 : : { XML_NAMESPACE_SVG, XML_VIEWBOX, XML_TOK_IMAP_VIEWBOX },
102 : : { XML_NAMESPACE_DRAW, XML_POINTS, XML_TOK_IMAP_POINTS },
103 : : { XML_NAMESPACE_OFFICE, XML_TARGET_FRAME_NAME, XML_TOK_IMAP_TARGET },
104 : : XML_TOKEN_MAP_END
105 : : };
106 : :
107 : :
108 : :
109 [ # # ]: 0 : class XMLImageMapObjectContext : public SvXMLImportContext
110 : : {
111 : :
112 : : protected:
113 : :
114 : : const ::rtl::OUString sBoundary;
115 : : const ::rtl::OUString sCenter;
116 : : const ::rtl::OUString sTitle;
117 : : const ::rtl::OUString sDescription;
118 : : const ::rtl::OUString sImageMap;
119 : : const ::rtl::OUString sIsActive;
120 : : const ::rtl::OUString sName;
121 : : const ::rtl::OUString sPolygon;
122 : : const ::rtl::OUString sRadius;
123 : : const ::rtl::OUString sTarget;
124 : : const ::rtl::OUString sURL;
125 : :
126 : : Reference<XIndexContainer> xImageMap; /// the image map
127 : : Reference<XPropertySet> xMapEntry; /// one map-entry (one area)
128 : :
129 : : ::rtl::OUString sUrl;
130 : : ::rtl::OUString sTargt;
131 : : ::rtl::OUStringBuffer sDescriptionBuffer;
132 : : ::rtl::OUStringBuffer sTitleBuffer;
133 : : ::rtl::OUString sNam;
134 : : sal_Bool bIsActive;
135 : :
136 : : sal_Bool bValid;
137 : :
138 : : public:
139 : : TYPEINFO();
140 : :
141 : : XMLImageMapObjectContext(
142 : : SvXMLImport& rImport,
143 : : sal_uInt16 nPrefix,
144 : : const ::rtl::OUString& rLocalName,
145 : : ::com::sun::star::uno::Reference<
146 : : ::com::sun::star::container::XIndexContainer> xMap,
147 : : const sal_Char* pServiceName);
148 : :
149 : : void StartElement(
150 : : const ::com::sun::star::uno::Reference<
151 : : ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
152 : :
153 : : void EndElement();
154 : :
155 : : SvXMLImportContext *CreateChildContext(
156 : : sal_uInt16 nPrefix,
157 : : const ::rtl::OUString& rLocalName,
158 : : const ::com::sun::star::uno::Reference<
159 : : ::com::sun::star::xml::sax::XAttributeList> & xAttrList );
160 : :
161 : : protected:
162 : :
163 : : virtual void ProcessAttribute(
164 : : enum XMLImageMapToken eToken,
165 : : const ::rtl::OUString& rValue);
166 : :
167 : : virtual void Prepare(
168 : : ::com::sun::star::uno::Reference<
169 : : ::com::sun::star::beans::XPropertySet> & rPropertySet);
170 : : };
171 : :
172 : :
173 [ # # ][ # # ]: 0 : TYPEINIT1( XMLImageMapObjectContext, SvXMLImportContext );
174 : :
175 : 0 : XMLImageMapObjectContext::XMLImageMapObjectContext(
176 : : SvXMLImport& rImport,
177 : : sal_uInt16 nPrefix,
178 : : const OUString& rLocalName,
179 : : Reference<XIndexContainer> xMap,
180 : : const sal_Char* pServiceName) :
181 : : SvXMLImportContext(rImport, nPrefix, rLocalName),
182 : : sBoundary(RTL_CONSTASCII_USTRINGPARAM("Boundary")),
183 : : sCenter(RTL_CONSTASCII_USTRINGPARAM("Center")),
184 : : sTitle(RTL_CONSTASCII_USTRINGPARAM("Title")),
185 : : sDescription(RTL_CONSTASCII_USTRINGPARAM("Description")),
186 : : sImageMap(RTL_CONSTASCII_USTRINGPARAM("ImageMap")),
187 : : sIsActive(RTL_CONSTASCII_USTRINGPARAM("IsActive")),
188 : : sName(RTL_CONSTASCII_USTRINGPARAM("Name")),
189 : : sPolygon(RTL_CONSTASCII_USTRINGPARAM("Polygon")),
190 : : sRadius(RTL_CONSTASCII_USTRINGPARAM("Radius")),
191 : : sTarget(RTL_CONSTASCII_USTRINGPARAM("Target")),
192 : : sURL(RTL_CONSTASCII_USTRINGPARAM("URL")),
193 : : xImageMap(xMap),
194 : : bIsActive(sal_True),
195 [ # # ][ # # ]: 0 : bValid(sal_False)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
196 : : {
197 : : DBG_ASSERT(NULL != pServiceName,
198 : : "Please supply the image map object service name");
199 : :
200 [ # # ]: 0 : Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
201 [ # # ]: 0 : if( xFactory.is() )
202 : : {
203 [ # # ]: 0 : Reference<XInterface> xIfc = xFactory->createInstance(
204 [ # # ]: 0 : OUString::createFromAscii(pServiceName));
205 : : DBG_ASSERT(xIfc.is(), "can't create image map object!");
206 [ # # ]: 0 : if( xIfc.is() )
207 : : {
208 [ # # ]: 0 : Reference<XPropertySet> xPropertySet( xIfc, UNO_QUERY );
209 : :
210 [ # # ]: 0 : xMapEntry = xPropertySet;
211 : 0 : }
212 : : // else: can't create service -> ignore
213 : 0 : }
214 : : // else: can't even get factory -> ignore
215 : 0 : }
216 : :
217 : 0 : void XMLImageMapObjectContext::StartElement(
218 : : const Reference<XAttributeList >& xAttrList )
219 : : {
220 [ # # ]: 0 : SvXMLTokenMap aMap(aImageMapObjectTokenMap);
221 : :
222 [ # # ][ # # ]: 0 : sal_Int16 nLength = xAttrList->getLength();
223 [ # # ]: 0 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
224 : : {
225 : 0 : OUString sLocalName;
226 : 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
227 [ # # ]: 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
228 [ # # # # ]: 0 : &sLocalName );
229 [ # # ][ # # ]: 0 : OUString sValue = xAttrList->getValueByIndex(nAttr);
230 : :
231 : : ProcessAttribute(
232 [ # # ][ # # ]: 0 : (enum XMLImageMapToken)aMap.Get(nPrefix, sLocalName), sValue);
233 [ # # ]: 0 : }
234 : 0 : }
235 : :
236 : 0 : void XMLImageMapObjectContext::EndElement()
237 : : {
238 : : // only create and insert image map object if validity flag is set
239 : : // (and we actually have an image map)
240 [ # # ][ # # ]: 0 : if ( bValid && xImageMap.is() && xMapEntry.is() )
[ # # ][ # # ]
241 : : {
242 : : // set values
243 [ # # ]: 0 : Prepare( xMapEntry );
244 : :
245 : : // insert into image map
246 : 0 : Any aAny;
247 [ # # ]: 0 : aAny <<= xMapEntry;
248 [ # # ][ # # ]: 0 : xImageMap->insertByIndex( xImageMap->getCount(), aAny );
[ # # ][ # # ]
249 : : }
250 : : // else: not valid -> don't create and insert
251 : 0 : }
252 : :
253 : 0 : SvXMLImportContext* XMLImageMapObjectContext::CreateChildContext(
254 : : sal_uInt16 nPrefix,
255 : : const OUString& rLocalName,
256 : : const Reference<XAttributeList> & xAttrList )
257 : : {
258 [ # # # # ]: 0 : if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
[ # # ]
259 : 0 : IsXMLToken(rLocalName, XML_EVENT_LISTENERS) )
260 : : {
261 [ # # ]: 0 : Reference<XEventsSupplier> xEvents( xMapEntry, UNO_QUERY );
262 : : return new XMLEventsImportContext(
263 [ # # ][ # # ]: 0 : GetImport(), nPrefix, rLocalName, xEvents);
264 : : }
265 [ # # # # ]: 0 : else if ( (XML_NAMESPACE_SVG == nPrefix) &&
[ # # ]
266 : 0 : IsXMLToken(rLocalName, XML_TITLE) )
267 : : {
268 : : return new XMLStringBufferImportContext(
269 [ # # ]: 0 : GetImport(), nPrefix, rLocalName, sTitleBuffer);
270 : : }
271 [ # # # # ]: 0 : else if ( (XML_NAMESPACE_SVG == nPrefix) &&
[ # # ]
272 : 0 : IsXMLToken(rLocalName, XML_DESC) )
273 : : {
274 : : return new XMLStringBufferImportContext(
275 [ # # ]: 0 : GetImport(), nPrefix, rLocalName, sDescriptionBuffer);
276 : : }
277 : : else
278 : : return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
279 : 0 : xAttrList);
280 : :
281 : : }
282 : :
283 : 0 : void XMLImageMapObjectContext::ProcessAttribute(
284 : : enum XMLImageMapToken eToken,
285 : : const OUString& rValue)
286 : : {
287 [ # # # # : 0 : switch (eToken)
# ]
288 : : {
289 : : case XML_TOK_IMAP_URL:
290 : 0 : sUrl = GetImport().GetAbsoluteReference(rValue);
291 : 0 : break;
292 : :
293 : : case XML_TOK_IMAP_TARGET:
294 : 0 : sTargt = rValue;
295 : 0 : break;
296 : :
297 : : case XML_TOK_IMAP_NOHREF:
298 : 0 : bIsActive = ! IsXMLToken(rValue, XML_NOHREF);
299 : 0 : break;
300 : :
301 : : case XML_TOK_IMAP_NAME:
302 : 0 : sNam = rValue;
303 : 0 : break;
304 : : default:
305 : : // do nothing
306 : 0 : break;
307 : : }
308 : 0 : }
309 : :
310 : 0 : void XMLImageMapObjectContext::Prepare(
311 : : Reference<XPropertySet> & rPropertySet)
312 : : {
313 [ # # ]: 0 : rPropertySet->setPropertyValue( sURL, Any( sUrl ) );
314 [ # # ][ # # ]: 0 : rPropertySet->setPropertyValue( sTitle, Any( sTitleBuffer.makeStringAndClear() ) );
315 [ # # ][ # # ]: 0 : rPropertySet->setPropertyValue( sDescription, Any( sDescriptionBuffer.makeStringAndClear() ) );
316 [ # # ]: 0 : rPropertySet->setPropertyValue( sTarget, Any( sTargt ) );
317 [ # # ]: 0 : rPropertySet->setPropertyValue( sIsActive, Any( bIsActive ) );
318 [ # # ]: 0 : rPropertySet->setPropertyValue( sName, Any( sNam ) );
319 : 0 : }
320 : :
321 : :
322 : :
323 : : class XMLImageMapRectangleContext : public XMLImageMapObjectContext
324 : : {
325 : : awt::Rectangle aRectangle;
326 : :
327 : : sal_Bool bXOK;
328 : : sal_Bool bYOK;
329 : : sal_Bool bWidthOK;
330 : : sal_Bool bHeightOK;
331 : :
332 : : public:
333 : : TYPEINFO();
334 : :
335 : : XMLImageMapRectangleContext(
336 : : SvXMLImport& rImport,
337 : : sal_uInt16 nPrefix,
338 : : const ::rtl::OUString& rLocalName,
339 : : ::com::sun::star::uno::Reference<
340 : : ::com::sun::star::container::XIndexContainer> xMap);
341 : :
342 : : virtual ~XMLImageMapRectangleContext();
343 : :
344 : : protected:
345 : : virtual void ProcessAttribute(
346 : : enum XMLImageMapToken eToken,
347 : : const ::rtl::OUString& rValue);
348 : :
349 : : virtual void Prepare(
350 : : ::com::sun::star::uno::Reference<
351 : : ::com::sun::star::beans::XPropertySet> & rPropertySet);
352 : : };
353 : :
354 : :
355 : :
356 [ # # ][ # # ]: 0 : TYPEINIT1(XMLImageMapRectangleContext, XMLImageMapObjectContext);
357 : :
358 : 0 : XMLImageMapRectangleContext::XMLImageMapRectangleContext(
359 : : SvXMLImport& rImport,
360 : : sal_uInt16 nPrefix,
361 : : const OUString& rLocalName,
362 : : Reference<XIndexContainer> xMap) :
363 : : XMLImageMapObjectContext(rImport, nPrefix, rLocalName, xMap,
364 : : "com.sun.star.image.ImageMapRectangleObject"),
365 : : bXOK(sal_False),
366 : : bYOK(sal_False),
367 : : bWidthOK(sal_False),
368 [ # # ]: 0 : bHeightOK(sal_False)
369 : : {
370 : 0 : }
371 : :
372 : 0 : XMLImageMapRectangleContext::~XMLImageMapRectangleContext()
373 : : {
374 [ # # ]: 0 : }
375 : :
376 : 0 : void XMLImageMapRectangleContext::ProcessAttribute(
377 : : enum XMLImageMapToken eToken,
378 : : const OUString& rValue)
379 : : {
380 : : sal_Int32 nTmp;
381 [ # # # # : 0 : switch (eToken)
# ]
382 : : {
383 : : case XML_TOK_IMAP_X:
384 [ # # ][ # # ]: 0 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
385 : : rValue))
386 : : {
387 : 0 : aRectangle.X = nTmp;
388 : 0 : bXOK = sal_True;
389 : : }
390 : 0 : break;
391 : : case XML_TOK_IMAP_Y:
392 [ # # ][ # # ]: 0 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
393 : : rValue))
394 : : {
395 : 0 : aRectangle.Y = nTmp;
396 : 0 : bYOK = sal_True;
397 : : }
398 : 0 : break;
399 : : case XML_TOK_IMAP_WIDTH:
400 [ # # ][ # # ]: 0 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
401 : : rValue))
402 : : {
403 : 0 : aRectangle.Width = nTmp;
404 : 0 : bWidthOK = sal_True;
405 : : }
406 : 0 : break;
407 : : case XML_TOK_IMAP_HEIGTH:
408 [ # # ][ # # ]: 0 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
409 : : rValue))
410 : : {
411 : 0 : aRectangle.Height = nTmp;
412 : 0 : bHeightOK = sal_True;
413 : : }
414 : 0 : break;
415 : : default:
416 [ # # ]: 0 : XMLImageMapObjectContext::ProcessAttribute(eToken, rValue);
417 : : }
418 : :
419 [ # # ][ # # ]: 0 : bValid = bHeightOK && bXOK && bYOK && bWidthOK;
[ # # ][ # # ]
420 : 0 : }
421 : :
422 : 0 : void XMLImageMapRectangleContext::Prepare(
423 : : Reference<XPropertySet> & rPropertySet)
424 : : {
425 : 0 : Any aAny;
426 [ # # ]: 0 : aAny <<= aRectangle;
427 [ # # ][ # # ]: 0 : rPropertySet->setPropertyValue( sBoundary, aAny );
428 : :
429 : : // common properties handled by super class
430 [ # # ]: 0 : XMLImageMapObjectContext::Prepare(rPropertySet);
431 : 0 : }
432 : :
433 : :
434 : : class XMLImageMapPolygonContext : public XMLImageMapObjectContext
435 : : {
436 : : ::rtl::OUString sViewBoxString;
437 : : ::rtl::OUString sPointsString;
438 : :
439 : : sal_Bool bViewBoxOK;
440 : : sal_Bool bPointsOK;
441 : :
442 : : public:
443 : : TYPEINFO();
444 : :
445 : : XMLImageMapPolygonContext(
446 : : SvXMLImport& rImport,
447 : : sal_uInt16 nPrefix,
448 : : const ::rtl::OUString& rLocalName,
449 : : ::com::sun::star::uno::Reference<
450 : : ::com::sun::star::container::XIndexContainer> xMap);
451 : :
452 : : virtual ~XMLImageMapPolygonContext();
453 : :
454 : : protected:
455 : : virtual void ProcessAttribute(
456 : : enum XMLImageMapToken eToken,
457 : : const ::rtl::OUString& rValue);
458 : :
459 : : virtual void Prepare(
460 : : ::com::sun::star::uno::Reference<
461 : : ::com::sun::star::beans::XPropertySet> & rPropertySet);
462 : : };
463 : :
464 : :
465 : :
466 [ # # ][ # # ]: 0 : TYPEINIT1(XMLImageMapPolygonContext, XMLImageMapObjectContext);
467 : :
468 : 0 : XMLImageMapPolygonContext::XMLImageMapPolygonContext(
469 : : SvXMLImport& rImport,
470 : : sal_uInt16 nPrefix,
471 : : const OUString& rLocalName,
472 : : Reference<XIndexContainer> xMap) :
473 : : XMLImageMapObjectContext(rImport, nPrefix, rLocalName, xMap,
474 : : "com.sun.star.image.ImageMapPolygonObject"),
475 : : bViewBoxOK(sal_False),
476 [ # # ]: 0 : bPointsOK(sal_False)
477 : : {
478 : 0 : }
479 : :
480 : 0 : XMLImageMapPolygonContext::~XMLImageMapPolygonContext()
481 : : {
482 [ # # ]: 0 : }
483 : :
484 : 0 : void XMLImageMapPolygonContext::ProcessAttribute(
485 : : enum XMLImageMapToken eToken,
486 : : const OUString& rValue)
487 : : {
488 [ # # # ]: 0 : switch (eToken)
489 : : {
490 : : case XML_TOK_IMAP_POINTS:
491 : 0 : sPointsString = rValue;
492 : 0 : bPointsOK = sal_True;
493 : 0 : break;
494 : : case XML_TOK_IMAP_VIEWBOX:
495 : 0 : sViewBoxString = rValue;
496 : 0 : bViewBoxOK = sal_True;
497 : 0 : break;
498 : : default:
499 : 0 : XMLImageMapObjectContext::ProcessAttribute(eToken, rValue);
500 : 0 : break;
501 : : }
502 : :
503 [ # # ][ # # ]: 0 : bValid = bViewBoxOK && bPointsOK;
504 : 0 : }
505 : :
506 : 0 : void XMLImageMapPolygonContext::Prepare(
507 : : Reference<XPropertySet> & rPropertySet)
508 : : {
509 : : // process view box
510 : : SdXMLImExViewBox aViewBox(sViewBoxString,
511 [ # # ]: 0 : GetImport().GetMM100UnitConverter());
512 : :
513 : : // get polygon sequence
514 : 0 : awt::Point aPoint(aViewBox.GetX(), aViewBox.GetY());
515 : 0 : awt::Size aSize(aViewBox.GetWidth(), aViewBox.GetHeight());
516 : : SdXMLImExPointsElement aPoints( sPointsString, aViewBox, aPoint, aSize,
517 [ # # ]: 0 : GetImport().GetMM100UnitConverter() );
518 [ # # ]: 0 : PointSequenceSequence aPointSeqSeq = aPoints.GetPointSequenceSequence();
519 : :
520 : : // only use first element of sequence-sequence
521 [ # # ]: 0 : if (aPointSeqSeq.getLength() > 0)
522 : : {
523 : 0 : Any aAny;
524 [ # # ][ # # ]: 0 : aAny <<= aPointSeqSeq[0];
525 [ # # ][ # # ]: 0 : rPropertySet->setPropertyValue(sPolygon, aAny);
526 : : }
527 : :
528 : : // parent properties
529 [ # # ][ # # ]: 0 : XMLImageMapObjectContext::Prepare(rPropertySet);
[ # # ]
530 : 0 : }
531 : :
532 : :
533 : :
534 : : class XMLImageMapCircleContext : public XMLImageMapObjectContext
535 : : {
536 : : awt::Point aCenter;
537 : : sal_Int32 nRadius;
538 : :
539 : : sal_Bool bXOK;
540 : : sal_Bool bYOK;
541 : : sal_Bool bRadiusOK;
542 : :
543 : : public:
544 : : TYPEINFO();
545 : :
546 : : XMLImageMapCircleContext(
547 : : SvXMLImport& rImport,
548 : : sal_uInt16 nPrefix,
549 : : const ::rtl::OUString& rLocalName,
550 : : ::com::sun::star::uno::Reference<
551 : : ::com::sun::star::container::XIndexContainer> xMap);
552 : :
553 : : virtual ~XMLImageMapCircleContext();
554 : :
555 : : protected:
556 : : virtual void ProcessAttribute(
557 : : enum XMLImageMapToken eToken,
558 : : const ::rtl::OUString& rValue);
559 : :
560 : : virtual void Prepare(
561 : : ::com::sun::star::uno::Reference<
562 : : ::com::sun::star::beans::XPropertySet> & rPropertySet);
563 : : };
564 : :
565 [ # # ][ # # ]: 0 : TYPEINIT1(XMLImageMapCircleContext, XMLImageMapObjectContext);
566 : :
567 : 0 : XMLImageMapCircleContext::XMLImageMapCircleContext(
568 : : SvXMLImport& rImport,
569 : : sal_uInt16 nPrefix,
570 : : const OUString& rLocalName,
571 : : Reference<XIndexContainer> xMap) :
572 : : XMLImageMapObjectContext(rImport, nPrefix, rLocalName, xMap,
573 : : "com.sun.star.image.ImageMapCircleObject"),
574 : : bXOK(sal_False),
575 : : bYOK(sal_False),
576 [ # # ]: 0 : bRadiusOK(sal_False)
577 : : {
578 : 0 : }
579 : :
580 : 0 : XMLImageMapCircleContext::~XMLImageMapCircleContext()
581 : : {
582 [ # # ]: 0 : }
583 : :
584 : 0 : void XMLImageMapCircleContext::ProcessAttribute(
585 : : enum XMLImageMapToken eToken,
586 : : const OUString& rValue)
587 : : {
588 : : sal_Int32 nTmp;
589 [ # # # # ]: 0 : switch (eToken)
590 : : {
591 : : case XML_TOK_IMAP_CENTER_X:
592 [ # # ][ # # ]: 0 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
593 : : rValue))
594 : : {
595 : 0 : aCenter.X = nTmp;
596 : 0 : bXOK = sal_True;
597 : : }
598 : 0 : break;
599 : : case XML_TOK_IMAP_CENTER_Y:
600 [ # # ][ # # ]: 0 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
601 : : rValue))
602 : : {
603 : 0 : aCenter.Y = nTmp;
604 : 0 : bYOK = sal_True;
605 : : }
606 : 0 : break;
607 : : case XML_TOK_IMAP_RADIUS:
608 [ # # ][ # # ]: 0 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
609 : : rValue))
610 : : {
611 : 0 : nRadius = nTmp;
612 : 0 : bRadiusOK = sal_True;
613 : : }
614 : 0 : break;
615 : : default:
616 [ # # ]: 0 : XMLImageMapObjectContext::ProcessAttribute(eToken, rValue);
617 : : }
618 : :
619 [ # # ][ # # ]: 0 : bValid = bRadiusOK && bXOK && bYOK;
[ # # ]
620 : 0 : }
621 : :
622 : 0 : void XMLImageMapCircleContext::Prepare(
623 : : Reference<XPropertySet> & rPropertySet)
624 : : {
625 : : // center (x,y)
626 : 0 : Any aAny;
627 [ # # ]: 0 : aAny <<= aCenter;
628 [ # # ][ # # ]: 0 : rPropertySet->setPropertyValue( sCenter, aAny );
629 : :
630 : : // radius
631 [ # # ]: 0 : aAny <<= nRadius;
632 [ # # ][ # # ]: 0 : rPropertySet->setPropertyValue( sRadius, aAny );
633 : :
634 : : // common properties handled by super class
635 [ # # ]: 0 : XMLImageMapObjectContext::Prepare(rPropertySet);
636 : 0 : }
637 : :
638 : :
639 : :
640 : :
641 : :
642 : :
643 : :
644 : :
645 : :
646 : :
647 [ # # ][ # # ]: 0 : TYPEINIT1(XMLImageMapContext, SvXMLImportContext);
648 : :
649 : 0 : XMLImageMapContext::XMLImageMapContext(
650 : : SvXMLImport& rImport,
651 : : sal_uInt16 nPrefix,
652 : : const OUString& rLocalName,
653 : : Reference<XPropertySet> & rPropertySet) :
654 : : SvXMLImportContext(rImport, nPrefix, rLocalName),
655 : : sImageMap(RTL_CONSTASCII_USTRINGPARAM("ImageMap")),
656 [ # # ]: 0 : xPropertySet(rPropertySet)
657 : :
658 : : {
659 : : try
660 : : {
661 : : Reference < XPropertySetInfo > xInfo =
662 [ # # ][ # # ]: 0 : xPropertySet->getPropertySetInfo();
663 [ # # ][ # # ]: 0 : if( xInfo.is() && xInfo->hasPropertyByName( sImageMap ) )
[ # # ][ # # ]
[ # # ]
664 [ # # ][ # # ]: 0 : xPropertySet->getPropertyValue(sImageMap) >>= xImageMap;
[ # # ]
665 : : }
666 [ # # # # ]: 0 : catch(const com::sun::star::uno::Exception& e)
667 : : {
668 [ # # ]: 0 : uno::Sequence<OUString> aSeq(0);
669 [ # # # # : 0 : rImport.SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, aSeq, e.Message, NULL );
# # ]
670 : : }
671 : 0 : }
672 : :
673 : 0 : XMLImageMapContext::~XMLImageMapContext()
674 : : {
675 [ # # ]: 0 : }
676 : :
677 : 0 : SvXMLImportContext *XMLImageMapContext::CreateChildContext(
678 : : sal_uInt16 nPrefix,
679 : : const OUString& rLocalName,
680 : : const Reference<XAttributeList> & xAttrList )
681 : : {
682 : 0 : SvXMLImportContext* pContext = NULL;
683 : :
684 [ # # ]: 0 : if ( XML_NAMESPACE_DRAW == nPrefix )
685 : : {
686 [ # # ]: 0 : if ( IsXMLToken(rLocalName, XML_AREA_RECTANGLE) )
687 : : {
688 : : pContext = new XMLImageMapRectangleContext(
689 [ # # ][ # # ]: 0 : GetImport(), nPrefix, rLocalName, xImageMap);
690 : : }
691 [ # # ]: 0 : else if ( IsXMLToken(rLocalName, XML_AREA_POLYGON) )
692 : : {
693 : : pContext = new XMLImageMapPolygonContext(
694 [ # # ][ # # ]: 0 : GetImport(), nPrefix, rLocalName, xImageMap);
695 : : }
696 [ # # ]: 0 : else if ( IsXMLToken(rLocalName, XML_AREA_CIRCLE) )
697 : : {
698 : : pContext = new XMLImageMapCircleContext(
699 [ # # ][ # # ]: 0 : GetImport(), nPrefix, rLocalName, xImageMap);
700 : : }
701 : : }
702 : : else
703 : : pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
704 : 0 : xAttrList);
705 : :
706 : 0 : return pContext;
707 : : }
708 : :
709 : 0 : void XMLImageMapContext::EndElement()
710 : : {
711 : : Reference < XPropertySetInfo > xInfo =
712 [ # # ][ # # ]: 0 : xPropertySet->getPropertySetInfo();
713 [ # # ][ # # ]: 0 : if( xInfo.is() && xInfo->hasPropertyByName( sImageMap ) )
[ # # ][ # # ]
[ # # ]
714 [ # # ][ # # ]: 0 : xPropertySet->setPropertyValue(sImageMap, uno::makeAny( xImageMap ) );
[ # # ]
715 : 0 : }
716 : :
717 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|