1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/XMLComplexColorContext.hxx>
32 #include <xmloff/txtprmap.hxx>
33 #include <xmloff/xmltypes.hxx>
34 #include <xmloff/maptype.hxx>
35 #include <xmloff/xmlimppr.hxx>
37 #include <xmloff/XMLTextShapeStyleContext.hxx>
39 using namespace ::com::sun::star::document
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::xml::sax
;
42 using namespace ::com::sun::star::style
;
43 using namespace ::com::sun::star::beans
;
44 using namespace ::xmloff::token
;
48 class XMLTextShapePropertySetContext_Impl
: public XMLShapePropertySetContext
51 XMLTextShapePropertySetContext_Impl( SvXMLImport
& rImport
, sal_Int32 nElement
,
52 const Reference
< XFastAttributeList
>& xAttrList
,
54 ::std::vector
< XMLPropertyState
> &rProps
,
55 const rtl::Reference
< SvXMLImportPropertyMapper
> &rMap
);
57 using SvXMLPropertySetContext::createFastChildContext
;
58 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> createFastChildContext(
60 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
61 ::std::vector
< XMLPropertyState
> &rProperties
,
62 const XMLPropertyState
& rProp
) override
;
67 XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl(
68 SvXMLImport
& rImport
, sal_Int32 nElement
,
69 const Reference
< XFastAttributeList
> & xAttrList
,
71 ::std::vector
< XMLPropertyState
> &rProps
,
72 const rtl::Reference
< SvXMLImportPropertyMapper
> &rMap
) :
73 XMLShapePropertySetContext( rImport
, nElement
, xAttrList
, nFamily
,
78 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLTextShapePropertySetContext_Impl::createFastChildContext(
80 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
81 ::std::vector
< XMLPropertyState
> &rProperties
,
82 const XMLPropertyState
& rProp
)
84 switch( mxMapper
->getPropertySetMapper()
85 ->GetEntryContextId( rProp
.mnIndex
) )
88 return new XMLTextColumnsContext( GetImport(), nElement
,
93 case CTF_COMPLEX_COLOR
:
94 return new XMLPropertyComplexColorContext(GetImport(), nElement
, xAttrList
, rProp
, rProperties
);
96 case CTF_BACKGROUND_URL
:
97 DBG_ASSERT( rProp
.mnIndex
>= 3 &&
98 CTF_BACKGROUND_TRANSPARENCY
==
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!");
107 new XMLBackgroundImageContext( GetImport(), nElement
,
118 return XMLShapePropertySetContext::createFastChildContext(
119 nElement
, xAttrList
, rProperties
, rProp
);
122 void XMLTextShapeStyleContext::SetAttribute( sal_Int32 nElement
,
123 const OUString
& rValue
)
125 if( nElement
== XML_ELEMENT(STYLE
, XML_AUTO_UPDATE
) )
127 if( IsXMLToken( rValue
, XML_TRUE
) )
128 m_bAutoUpdate
= true;
132 XMLShapeStyleContext::SetAttribute( nElement
, rValue
);
137 constexpr OUString
gsIsAutoUpdate( u
"IsAutoUpdate"_ustr
);
139 XMLTextShapeStyleContext::XMLTextShapeStyleContext( SvXMLImport
& rImport
,
140 SvXMLStylesContext
& rStyles
, XmlStyleFamily nFamily
) :
141 XMLShapeStyleContext( rImport
, rStyles
, nFamily
),
142 m_bAutoUpdate( false )
146 XMLTextShapeStyleContext::~XMLTextShapeStyleContext()
150 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLTextShapeStyleContext::createFastChildContext(
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
;
167 rtl::Reference
< SvXMLImportPropertyMapper
> xImpPrMap
=
168 GetStyles()->GetImportPropertyMapper( GetFamily() );
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 m_xEventContext
= new XMLEventsImportContext( GetImport() );
182 return m_xEventContext
;
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()) )
195 Reference
< XPropertySet
> xPropSet( xStyle
, UNO_QUERY
);
196 Reference
< XPropertySetInfo
> xPropSetInfo
=
197 xPropSet
->getPropertySetInfo();
198 if( xPropSetInfo
->hasPropertyByName( gsIsAutoUpdate
) )
200 bool bTmp
= m_bAutoUpdate
;
201 xPropSet
->setPropertyValue( gsIsAutoUpdate
, Any(bTmp
) );
204 // tell the style about it's events (if applicable)
205 if( m_xEventContext
.is() )
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;
214 void XMLTextShapeStyleContext::Finish( bool bOverwrite
)
216 XMLPropStyleContext::Finish( bOverwrite
);
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */