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>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlimp.hxx>
31 #include <xmloff/txtprmap.hxx>
32 #include <xmloff/xmltypes.hxx>
33 #include <xmloff/maptype.hxx>
34 #include <xmloff/xmlimppr.hxx>
35 
37 
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;
44 
45 namespace {
46 
47 class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext
48 {
49 public:
50  XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_Int32 nElement,
51  const Reference< XFastAttributeList >& xAttrList,
52  sal_uInt32 nFamily,
53  ::std::vector< XMLPropertyState > &rProps,
55 
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;
62 };
63 
64 }
65 
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,
72  XMLShapePropertySetContext( rImport, nElement, xAttrList, nFamily,
73  rProps, rMap )
74 {
75 }
76 
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 )
82 {
83  SvXMLImportContextRef xContext;
84 
85  switch( mxMapper->getPropertySetMapper()
86  ->GetEntryContextId( rProp.mnIndex ) )
87  {
88  case CTF_TEXTCOLUMNS:
89  return new XMLTextColumnsContext( GetImport(), nElement,
90  xAttrList, rProp,
91  rProperties );
92  break;
93 
94  case CTF_BACKGROUND_URL:
95  DBG_ASSERT( rProp.mnIndex >= 3 &&
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,
111  -1,
112  rProperties );
113  break;
114  }
115 
117  nElement, xAttrList, rProperties, rProp );
118 }
119 
120 void XMLTextShapeStyleContext::SetAttribute( sal_Int32 nElement,
121  const OUString& rValue )
122 {
123  if( nElement == XML_ELEMENT(STYLE, XML_AUTO_UPDATE) )
124  {
125  if( IsXMLToken( rValue, XML_TRUE ) )
126  bAutoUpdate = true;
127  }
128  else
129  {
130  XMLShapeStyleContext::SetAttribute( nElement, rValue );
131  }
132 }
133 
134 
135 constexpr OUStringLiteral gsIsAutoUpdate( u"IsAutoUpdate" );
136 
138  SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) :
139  XMLShapeStyleContext( rImport, rStyles, nFamily ),
140  bAutoUpdate( false )
141 {
142 }
143 
145 {
146 }
147 
148 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextShapeStyleContext::createFastChildContext(
149  sal_Int32 nElement,
150  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
151 {
152  if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) ||
154  {
155  sal_Int32 nLocalName = nElement & TOKEN_MASK;
156  sal_uInt32 nFamily = 0;
157  if( nLocalName == XML_TEXT_PROPERTIES )
158  nFamily = XML_TYPE_PROP_TEXT;
159  else if( nLocalName == XML_PARAGRAPH_PROPERTIES )
160  nFamily = XML_TYPE_PROP_PARAGRAPH;
161  else if( nLocalName == XML_GRAPHIC_PROPERTIES )
162  nFamily = XML_TYPE_PROP_GRAPHIC;
163  if( nFamily )
164  {
167  if( xImpPrMap.is() )
168  {
169  return new XMLTextShapePropertySetContext_Impl(
170  GetImport(), nElement, xAttrList, nFamily,
171  GetProperties(), xImpPrMap );
172  }
173  }
174  }
175  else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
176  {
177  // create and remember events import context
178  // (for delayed processing of events)
180  return xEventContext;
181  }
182 
183  return XMLShapeStyleContext::createFastChildContext( nElement, xAttrList );
184 }
185 
187 {
189  Reference < XStyle > xStyle = GetStyle();
190  if( !xStyle.is() || !(bOverwrite || IsNew()) )
191  return;
192 
193  Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
194  Reference< XPropertySetInfo > xPropSetInfo =
195  xPropSet->getPropertySetInfo();
196  if( xPropSetInfo->hasPropertyByName( gsIsAutoUpdate ) )
197  {
198  bool bTmp = bAutoUpdate;
199  xPropSet->setPropertyValue( gsIsAutoUpdate, Any(bTmp) );
200  }
201 
202  // tell the style about it's events (if applicable)
203  if( xEventContext.is() )
204  {
205  // set event supplier and release reference to context
206  Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY);
207  xEventContext->SetEvents(xEventsSupplier);
208  xEventContext = nullptr;
209  }
210 }
211 
212 void XMLTextShapeStyleContext::Finish( bool bOverwrite )
213 {
214  XMLPropStyleContext::Finish( bOverwrite );
215 }
216 
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XmlStyleFamily GetFamily() const
Definition: xmlstyle.hxx:83
constexpr OUStringLiteral gsIsAutoUpdate(u"IsAutoUpdate")
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
const css::uno::Reference< css::style::XStyle > & GetStyle() const
Definition: prstylei.hxx:106
bool IsNew() const
Definition: xmlstyle.hxx:88
virtual ~XMLTextShapeStyleContext() override
sal_Int32 mnIndex
Definition: maptype.hxx:124
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3508
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
#define CTF_BACKGROUND_POS
Definition: txtprmap.hxx:90
XmlStyleFamily
Definition: families.hxx:47
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
#define XML_TYPE_PROP_PARAGRAPH
Definition: xmltypes.hxx:99
#define CTF_BACKGROUND_TRANSPARENCY
Definition: txtprmap.hxx:143
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 ...
rtl::Reference< XMLEventsImportContext > xEventContext
virtual void Finish(bool bOverwrite) override
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:510
#define DBG_ASSERT(sCon, aError)
#define CTF_BACKGROUND_URL
Definition: txtprmap.hxx:89
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
::std::vector< XMLPropertyState > & GetProperties()
Definition: prstylei.hxx:79
virtual void CreateAndInsert(bool bOverwrite) override
Definition: prstylei.cxx:257
#define XML_TYPE_PROP_TEXT
Definition: xmltypes.hxx:98
XMLTextShapeStyleContext(SvXMLImport &rImport, SvXMLStylesContext &rStyles, XmlStyleFamily nFamily)
virtual void Finish(bool bOverwrite) override
Definition: prstylei.cxx:446
virtual void CreateAndInsert(bool bOverwrite) override
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
Definition: xmlimp.hxx:104
#define CTF_BACKGROUND_FILTER
Definition: txtprmap.hxx:91
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Handling of tokens in XML:
#define XML_TYPE_PROP_GRAPHIC
Definition: xmltypes.hxx:94
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:122
SvXMLStylesContext * GetStyles()
Definition: prstylei.hxx:78
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:94
#define CTF_TEXTCOLUMNS
Definition: txtprmap.hxx:77
constexpr sal_uInt16 XML_NAMESPACE_STYLE
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override