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