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