1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmloff.hxx" 26 #include <tools/debug.hxx> 27 #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP 28 #include <com/sun/star/document/XEventsSupplier.hpp> 29 #endif 30 #include "xmloff/xmlnmspe.hxx" 31 #include <xmloff/xmltoken.hxx> 32 #include "XMLTextPropertySetContext.hxx" 33 #include <xmloff/xmlimp.hxx> 34 #include <xmloff/XMLEventsImportContext.hxx> 35 #include "XMLShapePropertySetContext.hxx" 36 #include "XMLTextColumnsContext.hxx" 37 #include "XMLBackgroundImageContext.hxx" 38 #ifndef _XMLOFF_TXTPRMAP_HXX 39 #include <xmloff/txtprmap.hxx> 40 #endif 41 42 #ifndef _XMLOFF_XMLTEXTSHAPESTYLECONTEXT_HXX 43 #include <xmloff/XMLTextShapeStyleContext.hxx> 44 #endif 45 46 using ::rtl::OUString; 47 using ::rtl::OUStringBuffer; 48 49 using namespace ::com::sun::star::document; 50 using namespace ::com::sun::star::uno; 51 using namespace ::com::sun::star::xml::sax; 52 using namespace ::com::sun::star::style; 53 using namespace ::com::sun::star::beans; 54 using namespace ::xmloff::token; 55 56 class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext 57 { 58 public: 59 XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx, 60 const OUString& rLName, 61 const Reference< XAttributeList >& xAttrList, 62 sal_uInt32 nFamily, 63 ::std::vector< XMLPropertyState > &rProps, 64 const UniReference < SvXMLImportPropertyMapper > &rMap ); 65 66 virtual ~XMLTextShapePropertySetContext_Impl(); 67 68 using SvXMLPropertySetContext::CreateChildContext; 69 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, 70 const OUString& rLocalName, 71 const Reference< XAttributeList >& xAttrList, 72 ::std::vector< XMLPropertyState > &rProperties, 73 const XMLPropertyState& rProp); 74 }; 75 76 XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl( 77 SvXMLImport& rImport, sal_uInt16 nPrfx, 78 const OUString& rLName, 79 const Reference< XAttributeList > & xAttrList, 80 sal_uInt32 nFamily, 81 ::std::vector< XMLPropertyState > &rProps, 82 const UniReference < SvXMLImportPropertyMapper > &rMap ) : 83 XMLShapePropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily, 84 rProps, rMap ) 85 { 86 } 87 88 XMLTextShapePropertySetContext_Impl::~XMLTextShapePropertySetContext_Impl() 89 { 90 } 91 92 SvXMLImportContext *XMLTextShapePropertySetContext_Impl::CreateChildContext( 93 sal_uInt16 nPrefix, 94 const OUString& rLocalName, 95 const Reference< XAttributeList > & xAttrList, 96 ::std::vector< XMLPropertyState > &rProperties, 97 const XMLPropertyState& rProp ) 98 { 99 SvXMLImportContext *pContext = 0; 100 101 switch( mxMapper->getPropertySetMapper() 102 ->GetEntryContextId( rProp.mnIndex ) ) 103 { 104 case CTF_TEXTCOLUMNS: 105 pContext = new XMLTextColumnsContext( GetImport(), nPrefix, 106 rLocalName, xAttrList, rProp, 107 rProperties ); 108 break; 109 110 case CTF_BACKGROUND_URL: 111 DBG_ASSERT( rProp.mnIndex >= 3 && 112 CTF_BACKGROUND_TRANSPARENCY == 113 mxMapper->getPropertySetMapper() 114 ->GetEntryContextId( rProp.mnIndex-3 ) && 115 CTF_BACKGROUND_POS == mxMapper->getPropertySetMapper() 116 ->GetEntryContextId( rProp.mnIndex-2 ) && 117 CTF_BACKGROUND_FILTER == mxMapper->getPropertySetMapper() 118 ->GetEntryContextId( rProp.mnIndex-1 ), 119 "invalid property map!"); 120 pContext = 121 new XMLBackgroundImageContext( GetImport(), nPrefix, 122 rLocalName, xAttrList, 123 rProp, 124 rProp.mnIndex-2, 125 rProp.mnIndex-1, 126 rProp.mnIndex-3, 127 rProperties ); 128 break; 129 } 130 131 if( !pContext ) 132 pContext = XMLShapePropertySetContext::CreateChildContext( 133 nPrefix, rLocalName, xAttrList, rProperties, rProp ); 134 135 return pContext; 136 } 137 138 //----------------------------------------------------------------------------- 139 140 void XMLTextShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey, 141 const OUString& rLocalName, 142 const OUString& rValue ) 143 { 144 if( XML_NAMESPACE_STYLE == nPrefixKey && 145 IsXMLToken( rLocalName, XML_AUTO_UPDATE ) ) 146 { 147 if( IsXMLToken( rValue, XML_TRUE ) ) 148 bAutoUpdate = sal_True; 149 } 150 else 151 { 152 XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue ); 153 } 154 } 155 156 TYPEINIT1( XMLTextShapeStyleContext, XMLShapeStyleContext ); 157 158 XMLTextShapeStyleContext::XMLTextShapeStyleContext( SvXMLImport& rImport, 159 sal_uInt16 nPrfx, const OUString& rLName, 160 const Reference< XAttributeList > & xAttrList, 161 SvXMLStylesContext& rStyles, sal_uInt16 nFamily, 162 sal_Bool /*bDefaultStyle*/ ) : 163 XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, 164 nFamily ), 165 sIsAutoUpdate( RTL_CONSTASCII_USTRINGPARAM( "IsAutoUpdate" ) ), 166 bAutoUpdate( sal_False ) 167 { 168 } 169 170 XMLTextShapeStyleContext::~XMLTextShapeStyleContext() 171 { 172 } 173 174 SvXMLImportContext *XMLTextShapeStyleContext::CreateChildContext( 175 sal_uInt16 nPrefix, 176 const OUString& rLocalName, 177 const Reference< XAttributeList > & xAttrList ) 178 { 179 SvXMLImportContext *pContext = 0; 180 181 if( XML_NAMESPACE_STYLE == nPrefix ) 182 { 183 sal_uInt32 nFamily = 0; 184 if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) 185 nFamily = XML_TYPE_PROP_TEXT; 186 else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) ) 187 nFamily = XML_TYPE_PROP_PARAGRAPH; 188 else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) ) 189 nFamily = XML_TYPE_PROP_GRAPHIC; 190 if( nFamily ) 191 { 192 UniReference < SvXMLImportPropertyMapper > xImpPrMap = 193 GetStyles()->GetImportPropertyMapper( GetFamily() ); 194 if( xImpPrMap.is() ) 195 { 196 pContext = new XMLTextShapePropertySetContext_Impl( 197 GetImport(), nPrefix, rLocalName, xAttrList, nFamily, 198 GetProperties(), xImpPrMap ); 199 } 200 } 201 } 202 else if ( (XML_NAMESPACE_OFFICE == nPrefix) && 203 IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) 204 { 205 // create and remember events import context 206 // (for delayed processing of events) 207 pContext = new XMLEventsImportContext( GetImport(), nPrefix, 208 rLocalName); 209 xEventContext = pContext; 210 } 211 212 if( !pContext ) 213 pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName, 214 xAttrList ); 215 216 return pContext; 217 } 218 219 void XMLTextShapeStyleContext::CreateAndInsert( sal_Bool bOverwrite ) 220 { 221 XMLShapeStyleContext::CreateAndInsert( bOverwrite ); 222 Reference < XStyle > xStyle = GetStyle(); 223 if( !xStyle.is() || !(bOverwrite || IsNew()) ) 224 return; 225 226 Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY ); 227 Reference< XPropertySetInfo > xPropSetInfo = 228 xPropSet->getPropertySetInfo(); 229 if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) ) 230 { 231 Any aAny; 232 sal_Bool bTmp = bAutoUpdate; 233 aAny.setValue( &bTmp, ::getBooleanCppuType() ); 234 xPropSet->setPropertyValue( sIsAutoUpdate, aAny ); 235 } 236 237 // tell the style about it's events (if applicable) 238 if( xEventContext.Is() ) 239 { 240 // set event suppplier and release reference to context 241 Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY); 242 ((XMLEventsImportContext *)&xEventContext)->SetEvents(xEventsSupplier); 243 xEventContext = 0; 244 } 245 } 246 247 248 void XMLTextShapeStyleContext::Finish( sal_Bool bOverwrite ) 249 { 250 XMLPropStyleContext::Finish( bOverwrite ); 251 } 252