nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / text / XMLTextShapeStyleContext.cxx
blob27accc1ed1c244e76a7a160fbc48ea24d5b24dd7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/debug.hxx>
21 #include <com/sun/star/document/XEventsSupplier.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/style/XStyle.hpp>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/XMLEventsImportContext.hxx>
28 #include <XMLShapePropertySetContext.hxx>
29 #include <XMLTextColumnsContext.hxx>
30 #include <XMLBackgroundImageContext.hxx>
31 #include <xmloff/txtprmap.hxx>
32 #include <xmloff/xmltypes.hxx>
33 #include <xmloff/maptype.hxx>
34 #include <xmloff/xmlimppr.hxx>
36 #include <xmloff/XMLTextShapeStyleContext.hxx>
38 using namespace ::com::sun::star::document;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::xml::sax;
41 using namespace ::com::sun::star::style;
42 using namespace ::com::sun::star::beans;
43 using namespace ::xmloff::token;
45 namespace {
47 class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext
49 public:
50 XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_Int32 nElement,
51 const Reference< XFastAttributeList >& xAttrList,
52 sal_uInt32 nFamily,
53 ::std::vector< XMLPropertyState > &rProps,
54 const rtl::Reference < SvXMLImportPropertyMapper > &rMap );
56 using SvXMLPropertySetContext::createFastChildContext;
57 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > createFastChildContext(
58 sal_Int32 nElement,
59 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
60 ::std::vector< XMLPropertyState > &rProperties,
61 const XMLPropertyState& rProp ) override;
66 XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl(
67 SvXMLImport& rImport, sal_Int32 nElement,
68 const Reference< XFastAttributeList > & xAttrList,
69 sal_uInt32 nFamily,
70 ::std::vector< XMLPropertyState > &rProps,
71 const rtl::Reference < SvXMLImportPropertyMapper > &rMap ) :
72 XMLShapePropertySetContext( rImport, nElement, xAttrList, nFamily,
73 rProps, rMap )
77 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextShapePropertySetContext_Impl::createFastChildContext(
78 sal_Int32 nElement,
79 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
80 ::std::vector< XMLPropertyState > &rProperties,
81 const XMLPropertyState& rProp )
83 SvXMLImportContextRef xContext;
85 switch( mxMapper->getPropertySetMapper()
86 ->GetEntryContextId( rProp.mnIndex ) )
88 case CTF_TEXTCOLUMNS:
89 return new XMLTextColumnsContext( GetImport(), nElement,
90 xAttrList, rProp,
91 rProperties );
92 break;
94 case CTF_BACKGROUND_URL:
95 DBG_ASSERT( rProp.mnIndex >= 3 &&
96 CTF_BACKGROUND_TRANSPARENCY ==
97 mxMapper->getPropertySetMapper()
98 ->GetEntryContextId( rProp.mnIndex-3 ) &&
99 CTF_BACKGROUND_POS == mxMapper->getPropertySetMapper()
100 ->GetEntryContextId( rProp.mnIndex-2 ) &&
101 CTF_BACKGROUND_FILTER == mxMapper->getPropertySetMapper()
102 ->GetEntryContextId( rProp.mnIndex-1 ),
103 "invalid property map!");
104 return
105 new XMLBackgroundImageContext( GetImport(), nElement,
106 xAttrList,
107 rProp,
108 rProp.mnIndex-2,
109 rProp.mnIndex-1,
110 rProp.mnIndex-3,
112 rProperties );
113 break;
116 return XMLShapePropertySetContext::createFastChildContext(
117 nElement, xAttrList, rProperties, rProp );
120 void XMLTextShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
121 const OUString& rLocalName,
122 const OUString& rValue )
124 if( XML_NAMESPACE_STYLE == nPrefixKey &&
125 IsXMLToken( rLocalName, XML_AUTO_UPDATE ) )
127 if( IsXMLToken( rValue, XML_TRUE ) )
128 bAutoUpdate = true;
130 else
132 XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
137 constexpr OUStringLiteral gsIsAutoUpdate( u"IsAutoUpdate" );
139 XMLTextShapeStyleContext::XMLTextShapeStyleContext( SvXMLImport& rImport,
140 SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) :
141 XMLShapeStyleContext( rImport, rStyles, nFamily ),
142 bAutoUpdate( false )
146 XMLTextShapeStyleContext::~XMLTextShapeStyleContext()
150 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextShapeStyleContext::createFastChildContext(
151 sal_Int32 nElement,
152 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
154 if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) ||
155 IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT) )
157 sal_Int32 nLocalName = nElement & TOKEN_MASK;
158 sal_uInt32 nFamily = 0;
159 if( nLocalName == XML_TEXT_PROPERTIES )
160 nFamily = XML_TYPE_PROP_TEXT;
161 else if( nLocalName == XML_PARAGRAPH_PROPERTIES )
162 nFamily = XML_TYPE_PROP_PARAGRAPH;
163 else if( nLocalName == XML_GRAPHIC_PROPERTIES )
164 nFamily = XML_TYPE_PROP_GRAPHIC;
165 if( nFamily )
167 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
168 GetStyles()->GetImportPropertyMapper( GetFamily() );
169 if( xImpPrMap.is() )
171 return new XMLTextShapePropertySetContext_Impl(
172 GetImport(), nElement, xAttrList, nFamily,
173 GetProperties(), xImpPrMap );
177 else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
179 // create and remember events import context
180 // (for delayed processing of events)
181 xEventContext = new XMLEventsImportContext( GetImport() );
182 return xEventContext.get();
185 return XMLShapeStyleContext::createFastChildContext( nElement, xAttrList );
188 void XMLTextShapeStyleContext::CreateAndInsert( bool bOverwrite )
190 XMLShapeStyleContext::CreateAndInsert( bOverwrite );
191 Reference < XStyle > xStyle = GetStyle();
192 if( !xStyle.is() || !(bOverwrite || IsNew()) )
193 return;
195 Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
196 Reference< XPropertySetInfo > xPropSetInfo =
197 xPropSet->getPropertySetInfo();
198 if( xPropSetInfo->hasPropertyByName( gsIsAutoUpdate ) )
200 bool bTmp = bAutoUpdate;
201 xPropSet->setPropertyValue( gsIsAutoUpdate, Any(bTmp) );
204 // tell the style about it's events (if applicable)
205 if( xEventContext.is() )
207 // set event supplier and release reference to context
208 Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY);
209 xEventContext->SetEvents(xEventsSupplier);
210 xEventContext = nullptr;
214 void XMLTextShapeStyleContext::Finish( bool bOverwrite )
216 XMLPropStyleContext::Finish( bOverwrite );
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */