LibreOffice Module xmloff (master) 1
XMLTextShapeStyleContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
25#include <xmloff/xmltoken.hxx>
26#include <xmloff/xmlimp.hxx>
32#include <xmloff/txtprmap.hxx>
33#include <xmloff/xmltypes.hxx>
34#include <xmloff/maptype.hxx>
35#include <xmloff/xmlimppr.hxx>
36
38
39using namespace ::com::sun::star::document;
40using namespace ::com::sun::star::uno;
41using namespace ::com::sun::star::xml::sax;
42using namespace ::com::sun::star::style;
43using namespace ::com::sun::star::beans;
44using namespace ::xmloff::token;
45
46namespace {
47
48class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext
49{
50public:
51 XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_Int32 nElement,
52 const Reference< XFastAttributeList >& xAttrList,
53 sal_uInt32 nFamily,
54 ::std::vector< XMLPropertyState > &rProps,
56
58 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > createFastChildContext(
59 sal_Int32 nElement,
60 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
61 ::std::vector< XMLPropertyState > &rProperties,
62 const XMLPropertyState& rProp ) override;
63};
64
65}
66
67XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl(
68 SvXMLImport& rImport, sal_Int32 nElement,
69 const Reference< XFastAttributeList > & xAttrList,
70 sal_uInt32 nFamily,
71 ::std::vector< XMLPropertyState > &rProps,
73 XMLShapePropertySetContext( rImport, nElement, xAttrList, nFamily,
74 rProps, rMap )
75{
76}
77
78css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextShapePropertySetContext_Impl::createFastChildContext(
79 sal_Int32 nElement,
80 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
81 ::std::vector< XMLPropertyState > &rProperties,
82 const XMLPropertyState& rProp )
83{
84 switch( mxMapper->getPropertySetMapper()
85 ->GetEntryContextId( rProp.mnIndex ) )
86 {
87 case CTF_TEXTCOLUMNS:
88 return new XMLTextColumnsContext( GetImport(), nElement,
89 xAttrList, rProp,
90 rProperties );
91 break;
92
94 return new XMLComplexColorContext(GetImport(), nElement, xAttrList, rProp, rProperties);
95
97 DBG_ASSERT( rProp.mnIndex >= 3 &&
99 mxMapper->getPropertySetMapper()
100 ->GetEntryContextId( rProp.mnIndex-3 ) &&
101 CTF_BACKGROUND_POS == mxMapper->getPropertySetMapper()
102 ->GetEntryContextId( rProp.mnIndex-2 ) &&
103 CTF_BACKGROUND_FILTER == mxMapper->getPropertySetMapper()
104 ->GetEntryContextId( rProp.mnIndex-1 ),
105 "invalid property map!");
106 return
107 new XMLBackgroundImageContext( GetImport(), nElement,
108 xAttrList,
109 rProp,
110 rProp.mnIndex-2,
111 rProp.mnIndex-1,
112 rProp.mnIndex-3,
113 -1,
114 rProperties );
115 break;
116 }
117
119 nElement, xAttrList, rProperties, rProp );
120}
121
123 const OUString& rValue )
124{
125 if( nElement == XML_ELEMENT(STYLE, XML_AUTO_UPDATE) )
126 {
127 if( IsXMLToken( rValue, XML_TRUE ) )
128 m_bAutoUpdate = true;
129 }
130 else
131 {
132 XMLShapeStyleContext::SetAttribute( nElement, rValue );
133 }
134}
135
136
137constexpr OUStringLiteral gsIsAutoUpdate( u"IsAutoUpdate" );
138
140 SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) :
141 XMLShapeStyleContext( rImport, rStyles, nFamily ),
142 m_bAutoUpdate( false )
143{
144}
145
147{
148}
149
150css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextShapeStyleContext::createFastChildContext(
151 sal_Int32 nElement,
152 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
153{
156 {
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 )
166 {
169 if( xImpPrMap.is() )
170 {
171 return new XMLTextShapePropertySetContext_Impl(
172 GetImport(), nElement, xAttrList, nFamily,
173 GetProperties(), xImpPrMap );
174 }
175 }
176 }
177 else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
178 {
179 // create and remember events import context
180 // (for delayed processing of events)
182 return m_xEventContext;
183 }
184
185 return XMLShapeStyleContext::createFastChildContext( nElement, xAttrList );
186}
187
189{
191 Reference < XStyle > xStyle = GetStyle();
192 if( !xStyle.is() || !(bOverwrite || IsNew()) )
193 return;
194
195 Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
196 Reference< XPropertySetInfo > xPropSetInfo =
197 xPropSet->getPropertySetInfo();
198 if( xPropSetInfo->hasPropertyByName( gsIsAutoUpdate ) )
199 {
200 bool bTmp = m_bAutoUpdate;
201 xPropSet->setPropertyValue( gsIsAutoUpdate, Any(bTmp) );
202 }
203
204 // tell the style about it's events (if applicable)
205 if( m_xEventContext.is() )
206 {
207 // set event supplier and release reference to context
208 Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY);
209 m_xEventContext->SetEvents(xEventsSupplier);
210 m_xEventContext = nullptr;
211 }
212}
213
214void XMLTextShapeStyleContext::Finish( bool bOverwrite )
215{
216 XMLPropStyleContext::Finish( bOverwrite );
217}
218
219/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral gsIsAutoUpdate(u"IsAutoUpdate")
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: xmlprcon.cxx:55
XmlStyleFamily GetFamily() const
Definition: xmlstyle.hxx:85
bool IsNew() const
Definition: xmlstyle.hxx:90
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:522
Import <script:events> element.
const css::uno::Reference< css::style::XStyle > & GetStyle() const
Definition: prstylei.hxx:106
::std::vector< XMLPropertyState > & GetProperties()
Definition: prstylei.hxx:79
virtual void CreateAndInsert(bool bOverwrite) override
Definition: prstylei.cxx:257
SvXMLStylesContext * GetStyles()
Definition: prstylei.hxx:78
virtual void Finish(bool bOverwrite) override
Definition: prstylei.cxx:446
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, ::std::vector< XMLPropertyState > &rProperties, const XMLPropertyState &rProp) override
This method is called from this instance implementation of CreateChildContext if the element matches ...
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
virtual ~XMLTextShapeStyleContext() override
virtual void CreateAndInsert(bool bOverwrite) override
XMLTextShapeStyleContext(SvXMLImport &rImport, SvXMLStylesContext &rStyles, XmlStyleFamily nFamily)
rtl::Reference< XMLEventsImportContext > m_xEventContext
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
virtual void Finish(bool bOverwrite) override
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
#define DBG_ASSERT(sCon, aError)
XmlStyleFamily
Definition: families.hxx:50
Handling of tokens in XML:
@ XML_PARAGRAPH_PROPERTIES
Definition: xmltoken.hxx:2634
@ XML_GRAPHIC_PROPERTIES
Definition: xmltoken.hxx:2629
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:140
sal_Int32 mnIndex
Definition: maptype.hxx:141
#define CTF_BACKGROUND_POS
Definition: txtprmap.hxx:90
#define CTF_BACKGROUND_FILTER
Definition: txtprmap.hxx:91
#define CTF_COMPLEX_COLOR
Definition: txtprmap.hxx:205
#define CTF_BACKGROUND_URL
Definition: txtprmap.hxx:89
#define CTF_TEXTCOLUMNS
Definition: txtprmap.hxx:77
#define CTF_BACKGROUND_TRANSPARENCY
Definition: txtprmap.hxx:143
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
Definition: xmlimp.hxx:104
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:94
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
constexpr sal_uInt16 XML_NAMESPACE_STYLE
#define XML_TYPE_PROP_GRAPHIC
Definition: xmltypes.hxx:94
#define XML_TYPE_PROP_PARAGRAPH
Definition: xmltypes.hxx:99
#define XML_TYPE_PROP_TEXT
Definition: xmltypes.hxx:98