/src/libreoffice/xmloff/source/text/XMLTextShapeStyleContext.cxx
Line | Count | Source |
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> |
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> |
36 | | |
37 | | #include <xmloff/XMLTextShapeStyleContext.hxx> |
38 | | |
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; |
45 | | |
46 | | namespace { |
47 | | |
48 | | class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext |
49 | | { |
50 | | public: |
51 | | XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_Int32 nElement, |
52 | | const Reference< XFastAttributeList >& xAttrList, |
53 | | sal_uInt32 nFamily, |
54 | | ::std::vector< XMLPropertyState > &rProps, |
55 | | SvXMLImportPropertyMapper* pMap ); |
56 | | |
57 | | using SvXMLPropertySetContext::createFastChildContext; |
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 | | |
67 | | XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl( |
68 | | SvXMLImport& rImport, sal_Int32 nElement, |
69 | | const Reference< XFastAttributeList > & xAttrList, |
70 | | sal_uInt32 nFamily, |
71 | | ::std::vector< XMLPropertyState > &rProps, |
72 | | SvXMLImportPropertyMapper* pMap ) : |
73 | 4.77k | XMLShapePropertySetContext( rImport, nElement, xAttrList, nFamily, |
74 | 4.77k | rProps, pMap ) |
75 | 4.77k | { |
76 | 4.77k | } |
77 | | |
78 | | css::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 | 11 | { |
84 | 11 | switch( mpMapper->getPropertySetMapper() |
85 | 11 | ->GetEntryContextId( rProp.mnIndex ) ) |
86 | 11 | { |
87 | 0 | case CTF_TEXTCOLUMNS: |
88 | 0 | return new XMLTextColumnsContext( GetImport(), nElement, |
89 | 0 | xAttrList, rProp, |
90 | 0 | rProperties ); |
91 | 0 | break; |
92 | | |
93 | 0 | case CTF_COMPLEX_COLOR: |
94 | 0 | return new XMLPropertyComplexColorContext(GetImport(), nElement, xAttrList, rProp, rProperties); |
95 | | |
96 | 11 | case CTF_BACKGROUND_URL: |
97 | 11 | DBG_ASSERT( rProp.mnIndex >= 3 && |
98 | 11 | CTF_BACKGROUND_TRANSPARENCY == |
99 | 11 | mpMapper->getPropertySetMapper() |
100 | 11 | ->GetEntryContextId( rProp.mnIndex-3 ) && |
101 | 11 | CTF_BACKGROUND_POS == mpMapper->getPropertySetMapper() |
102 | 11 | ->GetEntryContextId( rProp.mnIndex-2 ) && |
103 | 11 | CTF_BACKGROUND_FILTER == mpMapper->getPropertySetMapper() |
104 | 11 | ->GetEntryContextId( rProp.mnIndex-1 ), |
105 | 11 | "invalid property map!"); |
106 | 11 | return |
107 | 11 | new XMLBackgroundImageContext( GetImport(), nElement, |
108 | 11 | xAttrList, |
109 | 11 | rProp, |
110 | 11 | rProp.mnIndex-2, |
111 | 11 | rProp.mnIndex-1, |
112 | 11 | rProp.mnIndex-3, |
113 | 11 | -1, |
114 | 11 | rProperties ); |
115 | 0 | break; |
116 | 11 | } |
117 | | |
118 | 0 | return XMLShapePropertySetContext::createFastChildContext( |
119 | 0 | nElement, xAttrList, rProperties, rProp ); |
120 | 11 | } |
121 | | |
122 | | void XMLTextShapeStyleContext::SetAttribute( sal_Int32 nElement, |
123 | | const OUString& rValue ) |
124 | 10.9k | { |
125 | 10.9k | if( nElement == XML_ELEMENT(STYLE, XML_AUTO_UPDATE) ) |
126 | 40 | { |
127 | 40 | if( IsXMLToken( rValue, XML_TRUE ) ) |
128 | 40 | m_bAutoUpdate = true; |
129 | 40 | } |
130 | 10.9k | else |
131 | 10.9k | { |
132 | 10.9k | XMLShapeStyleContext::SetAttribute( nElement, rValue ); |
133 | 10.9k | } |
134 | 10.9k | } |
135 | | |
136 | | |
137 | | constexpr OUString gsIsAutoUpdate( u"IsAutoUpdate"_ustr ); |
138 | | |
139 | | XMLTextShapeStyleContext::XMLTextShapeStyleContext( SvXMLImport& rImport, |
140 | | SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) : |
141 | 4.94k | XMLShapeStyleContext( rImport, rStyles, nFamily ), |
142 | 4.94k | m_bAutoUpdate( false ) |
143 | 4.94k | { |
144 | 4.94k | } |
145 | | |
146 | | XMLTextShapeStyleContext::~XMLTextShapeStyleContext() |
147 | 4.94k | { |
148 | 4.94k | } |
149 | | |
150 | | css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextShapeStyleContext::createFastChildContext( |
151 | | sal_Int32 nElement, |
152 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
153 | 4.87k | { |
154 | 4.87k | if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) || |
155 | 31 | IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT) ) |
156 | 4.84k | { |
157 | 4.84k | sal_Int32 nLocalName = nElement & TOKEN_MASK; |
158 | 4.84k | sal_uInt32 nFamily = 0; |
159 | 4.84k | if( nLocalName == XML_TEXT_PROPERTIES ) |
160 | 11 | nFamily = XML_TYPE_PROP_TEXT; |
161 | 4.83k | else if( nLocalName == XML_PARAGRAPH_PROPERTIES ) |
162 | 3 | nFamily = XML_TYPE_PROP_PARAGRAPH; |
163 | 4.83k | else if( nLocalName == XML_GRAPHIC_PROPERTIES ) |
164 | 4.75k | nFamily = XML_TYPE_PROP_GRAPHIC; |
165 | 4.84k | if( nFamily ) |
166 | 4.77k | { |
167 | 4.77k | SvXMLImportPropertyMapper* pImpPrMap = |
168 | 4.77k | GetStyles()->GetImportPropertyMapper( GetFamily() ); |
169 | 4.77k | if( pImpPrMap ) |
170 | 4.77k | { |
171 | 4.77k | return new XMLTextShapePropertySetContext_Impl( |
172 | 4.77k | GetImport(), nElement, xAttrList, nFamily, |
173 | 4.77k | GetProperties(), pImpPrMap ); |
174 | 4.77k | } |
175 | 4.77k | } |
176 | 4.84k | } |
177 | 31 | else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) ) |
178 | 0 | { |
179 | | // create and remember events import context |
180 | | // (for delayed processing of events) |
181 | 0 | m_xEventContext = new XMLEventsImportContext( GetImport() ); |
182 | 0 | return m_xEventContext; |
183 | 0 | } |
184 | | |
185 | 109 | return XMLShapeStyleContext::createFastChildContext( nElement, xAttrList ); |
186 | 4.87k | } |
187 | | |
188 | | void XMLTextShapeStyleContext::CreateAndInsert( bool bOverwrite ) |
189 | 1.80k | { |
190 | 1.80k | XMLShapeStyleContext::CreateAndInsert( bOverwrite ); |
191 | 1.80k | Reference < XStyle > xStyle = GetStyle(); |
192 | 1.80k | if( !xStyle.is() || !(bOverwrite || IsNew()) ) |
193 | 13 | return; |
194 | | |
195 | 1.78k | Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY ); |
196 | 1.78k | Reference< XPropertySetInfo > xPropSetInfo = |
197 | 1.78k | xPropSet->getPropertySetInfo(); |
198 | 1.78k | if( xPropSetInfo->hasPropertyByName( gsIsAutoUpdate ) ) |
199 | 1.78k | { |
200 | 1.78k | bool bTmp = m_bAutoUpdate; |
201 | 1.78k | xPropSet->setPropertyValue( gsIsAutoUpdate, Any(bTmp) ); |
202 | 1.78k | } |
203 | | |
204 | | // tell the style about it's events (if applicable) |
205 | 1.78k | if( m_xEventContext.is() ) |
206 | 0 | { |
207 | | // set event supplier and release reference to context |
208 | 0 | Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY); |
209 | 0 | m_xEventContext->SetEvents(xEventsSupplier); |
210 | 0 | m_xEventContext = nullptr; |
211 | 0 | } |
212 | 1.78k | } |
213 | | |
214 | | void XMLTextShapeStyleContext::Finish( bool bOverwrite ) |
215 | 1.41k | { |
216 | 1.41k | XMLPropStyleContext::Finish( bOverwrite ); |
217 | 1.41k | } |
218 | | |
219 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |