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/xmlnmspe.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_uInt16 nPrfx,
51  const OUString& rLName,
52  const Reference< XAttributeList >& xAttrList,
53  sal_uInt32 nFamily,
54  ::std::vector< XMLPropertyState > &rProps,
56 
58  virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
59  const OUString& rLocalName,
60  const Reference< XAttributeList >& xAttrList,
61  ::std::vector< XMLPropertyState > &rProperties,
62  const XMLPropertyState& rProp) override;
63 };
64 
65 }
66 
67 XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl(
68  SvXMLImport& rImport, sal_uInt16 nPrfx,
69  const OUString& rLName,
70  const Reference< XAttributeList > & xAttrList,
71  sal_uInt32 nFamily,
72  ::std::vector< XMLPropertyState > &rProps,
74  XMLShapePropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily,
75  rProps, rMap )
76 {
77 }
78 
79 SvXMLImportContextRef XMLTextShapePropertySetContext_Impl::CreateChildContext(
80  sal_uInt16 nPrefix,
81  const OUString& rLocalName,
82  const Reference< XAttributeList > & xAttrList,
83  ::std::vector< XMLPropertyState > &rProperties,
84  const XMLPropertyState& rProp )
85 {
86  SvXMLImportContextRef xContext;
87 
88  switch( mxMapper->getPropertySetMapper()
89  ->GetEntryContextId( rProp.mnIndex ) )
90  {
91  case CTF_TEXTCOLUMNS:
92  xContext = new XMLTextColumnsContext( GetImport(), nPrefix,
93  rLocalName, xAttrList, rProp,
94  rProperties );
95  break;
96 
97  case CTF_BACKGROUND_URL:
98  DBG_ASSERT( rProp.mnIndex >= 3 &&
100  mxMapper->getPropertySetMapper()
101  ->GetEntryContextId( rProp.mnIndex-3 ) &&
102  CTF_BACKGROUND_POS == mxMapper->getPropertySetMapper()
103  ->GetEntryContextId( rProp.mnIndex-2 ) &&
104  CTF_BACKGROUND_FILTER == mxMapper->getPropertySetMapper()
105  ->GetEntryContextId( rProp.mnIndex-1 ),
106  "invalid property map!");
107  xContext =
108  new XMLBackgroundImageContext( GetImport(), nPrefix,
109  rLocalName, xAttrList,
110  rProp,
111  rProp.mnIndex-2,
112  rProp.mnIndex-1,
113  rProp.mnIndex-3,
114  -1,
115  rProperties );
116  break;
117  }
118 
119  if (!xContext)
121  nPrefix, rLocalName, xAttrList, rProperties, rProp );
122 
123  return xContext;
124 }
125 
126 void XMLTextShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
127  const OUString& rLocalName,
128  const OUString& rValue )
129 {
130  if( XML_NAMESPACE_STYLE == nPrefixKey &&
131  IsXMLToken( rLocalName, XML_AUTO_UPDATE ) )
132  {
133  if( IsXMLToken( rValue, XML_TRUE ) )
134  bAutoUpdate = true;
135  }
136  else
137  {
138  XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
139  }
140 }
141 
142 
143 static const OUStringLiteral gsIsAutoUpdate( "IsAutoUpdate" );
144 
146  sal_uInt16 nPrfx, const OUString& rLName,
147  const Reference< XAttributeList > & xAttrList,
148  SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) :
149  XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles,
150  nFamily ),
151  bAutoUpdate( false )
152 {
153 }
154 
156 {
157 }
158 
160  sal_uInt16 nPrefix,
161  const OUString& rLocalName,
162  const Reference< XAttributeList > & xAttrList )
163 {
164  SvXMLImportContextRef xContext;
165 
166  if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix )
167  {
168  sal_uInt32 nFamily = 0;
169  if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
170  nFamily = XML_TYPE_PROP_TEXT;
171  else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
172  nFamily = XML_TYPE_PROP_PARAGRAPH;
173  else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
174  nFamily = XML_TYPE_PROP_GRAPHIC;
175  if( nFamily )
176  {
179  if( xImpPrMap.is() )
180  {
181  xContext = new XMLTextShapePropertySetContext_Impl(
182  GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
183  GetProperties(), xImpPrMap );
184  }
185  }
186  }
187  else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
188  IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
189  {
190  // create and remember events import context
191  // (for delayed processing of events)
192  xContext = new XMLEventsImportContext( GetImport(), nPrefix,
193  rLocalName);
194  xEventContext = xContext;
195  }
196 
197  if (!xContext)
198  xContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
199  xAttrList );
200 
201  return xContext;
202 }
203 
205 {
207  Reference < XStyle > xStyle = GetStyle();
208  if( !xStyle.is() || !(bOverwrite || IsNew()) )
209  return;
210 
211  Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
212  Reference< XPropertySetInfo > xPropSetInfo =
213  xPropSet->getPropertySetInfo();
214  if( xPropSetInfo->hasPropertyByName( gsIsAutoUpdate ) )
215  {
216  bool bTmp = bAutoUpdate;
217  xPropSet->setPropertyValue( gsIsAutoUpdate, Any(bTmp) );
218  }
219 
220  // tell the style about it's events (if applicable)
221  if( xEventContext.is() )
222  {
223  // set event supplier and release reference to context
224  Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY);
225  static_cast<XMLEventsImportContext *>(xEventContext.get())->SetEvents(xEventsSupplier);
226  xEventContext = nullptr;
227  }
228 }
229 
230 void XMLTextShapeStyleContext::Finish( bool bOverwrite )
231 {
232  XMLPropStyleContext::Finish( bOverwrite );
233 }
234 
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
Definition: xmlnmspe.hxx:80
XmlStyleFamily GetFamily() const
Definition: xmlstyle.hxx:112
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
constexpr sal_uInt16 XML_NAMESPACE_STYLE
Definition: xmlnmspe.hxx:30
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
const css::uno::Reference< css::style::XStyle > & GetStyle() const
Definition: prstylei.hxx:110
bool IsNew() const
Definition: xmlstyle.hxx:117
virtual ~XMLTextShapeStyleContext() override
sal_Int32 mnIndex
Definition: maptype.hxx:106
SvXMLImportContextRef xEventContext
#define CTF_BACKGROUND_POS
Definition: txtprmap.hxx:90
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
XmlStyleFamily
Definition: families.hxx:47
#define XML_TYPE_PROP_PARAGRAPH
Definition: xmltypes.hxx:99
#define CTF_BACKGROUND_TRANSPARENCY
Definition: txtprmap.hxx:143
virtual void Finish(bool bOverwrite) override
static const OUStringLiteral gsIsAutoUpdate("IsAutoUpdate")
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:580
#define DBG_ASSERT(sCon, aError)
#define CTF_BACKGROUND_URL
Definition: txtprmap.hxx:89
::std::vector< XMLPropertyState > & GetProperties()
Definition: prstylei.hxx:79
virtual void CreateAndInsert(bool bOverwrite) override
Definition: prstylei.cxx:268
#define XML_TYPE_PROP_TEXT
Definition: xmltypes.hxx:98
SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
virtual void Finish(bool bOverwrite) override
Definition: prstylei.cxx:457
virtual void SetAttribute(sal_uInt16 nPrefixKey, const OUString &rLocalName, const OUString &rValue) override
virtual void CreateAndInsert(bool bOverwrite) override
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
#define CTF_BACKGROUND_FILTER
Definition: txtprmap.hxx:91
Handling of tokens in XML:
#define XML_TYPE_PROP_GRAPHIC
Definition: xmltypes.hxx:94
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:104
SvXMLStylesContext * GetStyles()
Definition: prstylei.hxx:78
virtual void SetAttribute(sal_uInt16 nPrefixKey, const OUString &rLocalName, const OUString &rValue) override
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList,::std::vector< XMLPropertyState > &rProperties, const XMLPropertyState &rProp) override
XMLTextShapeStyleContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, SvXMLStylesContext &rStyles, XmlStyleFamily nFamily)
#define CTF_TEXTCOLUMNS
Definition: txtprmap.hxx:77
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
Definition: xmlnmspe.hxx:29