Branch data Line data Source code
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 "xmloff/xmlnmspe.hxx"
23 : : #include <xmloff/xmltoken.hxx>
24 : : #include "XMLTextPropertySetContext.hxx"
25 : : #include <xmloff/xmlimp.hxx>
26 : : #include <xmloff/XMLEventsImportContext.hxx>
27 : : #include "XMLShapePropertySetContext.hxx"
28 : : #include "XMLTextColumnsContext.hxx"
29 : : #include "XMLBackgroundImageContext.hxx"
30 : : #include <xmloff/txtprmap.hxx>
31 : :
32 : : #include <xmloff/XMLTextShapeStyleContext.hxx>
33 : :
34 : : using ::rtl::OUString;
35 : : using ::rtl::OUStringBuffer;
36 : :
37 : : using namespace ::com::sun::star::document;
38 : : using namespace ::com::sun::star::uno;
39 : : using namespace ::com::sun::star::xml::sax;
40 : : using namespace ::com::sun::star::style;
41 : : using namespace ::com::sun::star::beans;
42 : : using namespace ::xmloff::token;
43 : :
44 : : class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext
45 : : {
46 : : public:
47 : : XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
48 : : const OUString& rLName,
49 : : const Reference< XAttributeList >& xAttrList,
50 : : sal_uInt32 nFamily,
51 : : ::std::vector< XMLPropertyState > &rProps,
52 : : const UniReference < SvXMLImportPropertyMapper > &rMap );
53 : :
54 : : virtual ~XMLTextShapePropertySetContext_Impl();
55 : :
56 : : using SvXMLPropertySetContext::CreateChildContext;
57 : : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
58 : : const OUString& rLocalName,
59 : : const Reference< XAttributeList >& xAttrList,
60 : : ::std::vector< XMLPropertyState > &rProperties,
61 : : const XMLPropertyState& rProp);
62 : : };
63 : :
64 : 40 : XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl(
65 : : SvXMLImport& rImport, sal_uInt16 nPrfx,
66 : : const OUString& rLName,
67 : : const Reference< XAttributeList > & xAttrList,
68 : : sal_uInt32 nFamily,
69 : : ::std::vector< XMLPropertyState > &rProps,
70 : : const UniReference < SvXMLImportPropertyMapper > &rMap ) :
71 : : XMLShapePropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily,
72 : 40 : rProps, rMap )
73 : : {
74 : 40 : }
75 : :
76 : 40 : XMLTextShapePropertySetContext_Impl::~XMLTextShapePropertySetContext_Impl()
77 : : {
78 [ - + ]: 80 : }
79 : :
80 : 0 : SvXMLImportContext *XMLTextShapePropertySetContext_Impl::CreateChildContext(
81 : : sal_uInt16 nPrefix,
82 : : const OUString& rLocalName,
83 : : const Reference< XAttributeList > & xAttrList,
84 : : ::std::vector< XMLPropertyState > &rProperties,
85 : : const XMLPropertyState& rProp )
86 : : {
87 : 0 : SvXMLImportContext *pContext = 0;
88 : :
89 [ # # # ]: 0 : switch( mxMapper->getPropertySetMapper()
90 : 0 : ->GetEntryContextId( rProp.mnIndex ) )
91 : : {
92 : : case CTF_TEXTCOLUMNS:
93 : 0 : pContext = new XMLTextColumnsContext( GetImport(), nPrefix,
94 : : rLocalName, xAttrList, rProp,
95 [ # # ]: 0 : rProperties );
96 : 0 : break;
97 : :
98 : : case CTF_BACKGROUND_URL:
99 : : DBG_ASSERT( rProp.mnIndex >= 3 &&
100 : : CTF_BACKGROUND_TRANSPARENCY ==
101 : : mxMapper->getPropertySetMapper()
102 : : ->GetEntryContextId( rProp.mnIndex-3 ) &&
103 : : CTF_BACKGROUND_POS == mxMapper->getPropertySetMapper()
104 : : ->GetEntryContextId( rProp.mnIndex-2 ) &&
105 : : CTF_BACKGROUND_FILTER == mxMapper->getPropertySetMapper()
106 : : ->GetEntryContextId( rProp.mnIndex-1 ),
107 : : "invalid property map!");
108 : : pContext =
109 : 0 : new XMLBackgroundImageContext( GetImport(), nPrefix,
110 : : rLocalName, xAttrList,
111 : : rProp,
112 : : rProp.mnIndex-2,
113 : : rProp.mnIndex-1,
114 : : rProp.mnIndex-3,
115 [ # # ]: 0 : rProperties );
116 : 0 : break;
117 : : }
118 : :
119 [ # # ]: 0 : if( !pContext )
120 : : pContext = XMLShapePropertySetContext::CreateChildContext(
121 : 0 : nPrefix, rLocalName, xAttrList, rProperties, rProp );
122 : :
123 : 0 : return pContext;
124 : : }
125 : :
126 : : //-----------------------------------------------------------------------------
127 : :
128 : 90 : void XMLTextShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
129 : : const OUString& rLocalName,
130 : : const OUString& rValue )
131 : : {
132 [ + - - + ]: 180 : if( XML_NAMESPACE_STYLE == nPrefixKey &&
[ - + ]
133 : 90 : IsXMLToken( rLocalName, XML_AUTO_UPDATE ) )
134 : : {
135 [ # # ]: 0 : if( IsXMLToken( rValue, XML_TRUE ) )
136 : 0 : bAutoUpdate = sal_True;
137 : : }
138 : : else
139 : : {
140 : 90 : XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
141 : : }
142 : 90 : }
143 : :
144 [ - + ][ + - ]: 174 : TYPEINIT1( XMLTextShapeStyleContext, XMLShapeStyleContext );
145 : :
146 : 40 : XMLTextShapeStyleContext::XMLTextShapeStyleContext( SvXMLImport& rImport,
147 : : sal_uInt16 nPrfx, const OUString& rLName,
148 : : const Reference< XAttributeList > & xAttrList,
149 : : SvXMLStylesContext& rStyles, sal_uInt16 nFamily,
150 : : sal_Bool /*bDefaultStyle*/ ) :
151 : : XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles,
152 : : nFamily ),
153 : : sIsAutoUpdate( "IsAutoUpdate" ),
154 : 40 : bAutoUpdate( sal_False )
155 : : {
156 : 40 : }
157 : :
158 [ + - ]: 40 : XMLTextShapeStyleContext::~XMLTextShapeStyleContext()
159 : : {
160 [ - + ]: 80 : }
161 : :
162 : 40 : SvXMLImportContext *XMLTextShapeStyleContext::CreateChildContext(
163 : : sal_uInt16 nPrefix,
164 : : const OUString& rLocalName,
165 : : const Reference< XAttributeList > & xAttrList )
166 : : {
167 : 40 : SvXMLImportContext *pContext = 0;
168 : :
169 [ + - ]: 40 : if( XML_NAMESPACE_STYLE == nPrefix )
170 : : {
171 : 40 : sal_uInt32 nFamily = 0;
172 [ - + ]: 40 : if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
173 : 0 : nFamily = XML_TYPE_PROP_TEXT;
174 [ - + ]: 40 : else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
175 : 0 : nFamily = XML_TYPE_PROP_PARAGRAPH;
176 [ + - ]: 40 : else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
177 : 40 : nFamily = XML_TYPE_PROP_GRAPHIC;
178 [ + - ]: 40 : if( nFamily )
179 : : {
180 : : UniReference < SvXMLImportPropertyMapper > xImpPrMap =
181 [ + - ]: 40 : GetStyles()->GetImportPropertyMapper( GetFamily() );
182 [ + - ]: 40 : if( xImpPrMap.is() )
183 : : {
184 : : pContext = new XMLTextShapePropertySetContext_Impl(
185 : 40 : GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
186 [ + - ][ + - ]: 40 : GetProperties(), xImpPrMap );
187 [ + - ]: 40 : }
188 : : }
189 : : }
190 [ # # # # ]: 0 : else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
[ # # ]
191 : 0 : IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
192 : : {
193 : : // create and remember events import context
194 : : // (for delayed processing of events)
195 : 0 : pContext = new XMLEventsImportContext( GetImport(), nPrefix,
196 [ # # ]: 0 : rLocalName);
197 : 0 : xEventContext = pContext;
198 : : }
199 : :
200 [ - + ]: 40 : if( !pContext )
201 : : pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
202 : 0 : xAttrList );
203 : :
204 : 40 : return pContext;
205 : : }
206 : :
207 : 20 : void XMLTextShapeStyleContext::CreateAndInsert( sal_Bool bOverwrite )
208 : : {
209 [ + - ]: 20 : XMLShapeStyleContext::CreateAndInsert( bOverwrite );
210 : 20 : Reference < XStyle > xStyle = GetStyle();
211 [ - + ][ # # ]: 20 : if( !xStyle.is() || !(bOverwrite || IsNew()) )
[ - + ][ + - ]
212 : 20 : return;
213 : :
214 [ + - ]: 20 : Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
215 : : Reference< XPropertySetInfo > xPropSetInfo =
216 [ + - ][ + - ]: 20 : xPropSet->getPropertySetInfo();
217 [ + - ][ + - ]: 20 : if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) )
[ + - ]
218 : : {
219 : 20 : Any aAny;
220 : 20 : sal_Bool bTmp = bAutoUpdate;
221 [ + - ]: 20 : aAny.setValue( &bTmp, ::getBooleanCppuType() );
222 [ + - ][ + - ]: 20 : xPropSet->setPropertyValue( sIsAutoUpdate, aAny );
223 : : }
224 : :
225 : : // tell the style about it's events (if applicable)
226 [ - + ]: 20 : if( xEventContext.Is() )
227 : : {
228 : : // set event suppplier and release reference to context
229 [ # # ]: 0 : Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY);
230 [ # # ]: 0 : ((XMLEventsImportContext *)&xEventContext)->SetEvents(xEventsSupplier);
231 [ # # ]: 0 : xEventContext = 0;
232 [ + - ]: 20 : }
233 : : }
234 : :
235 : :
236 : 20 : void XMLTextShapeStyleContext::Finish( sal_Bool bOverwrite )
237 : : {
238 : 20 : XMLPropStyleContext::Finish( bOverwrite );
239 : 20 : }
240 : :
241 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|