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