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