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 25 : 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 25 : rProps, rMap )
73 : {
74 25 : }
75 :
76 50 : XMLTextShapePropertySetContext_Impl::~XMLTextShapePropertySetContext_Impl()
77 : {
78 50 : }
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 58 : void XMLTextShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
129 : const OUString& rLocalName,
130 : const OUString& rValue )
131 : {
132 116 : if( XML_NAMESPACE_STYLE == nPrefixKey &&
133 58 : IsXMLToken( rLocalName, XML_AUTO_UPDATE ) )
134 : {
135 0 : if( IsXMLToken( rValue, XML_TRUE ) )
136 0 : bAutoUpdate = sal_True;
137 : }
138 : else
139 : {
140 58 : XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
141 : }
142 58 : }
143 :
144 102 : TYPEINIT1( XMLTextShapeStyleContext, XMLShapeStyleContext );
145 :
146 25 : 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 25 : bAutoUpdate( sal_False )
155 : {
156 25 : }
157 :
158 50 : XMLTextShapeStyleContext::~XMLTextShapeStyleContext()
159 : {
160 50 : }
161 :
162 25 : SvXMLImportContext *XMLTextShapeStyleContext::CreateChildContext(
163 : sal_uInt16 nPrefix,
164 : const OUString& rLocalName,
165 : const Reference< XAttributeList > & xAttrList )
166 : {
167 25 : SvXMLImportContext *pContext = 0;
168 :
169 25 : if( XML_NAMESPACE_STYLE == nPrefix )
170 : {
171 25 : sal_uInt32 nFamily = 0;
172 25 : if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
173 0 : nFamily = XML_TYPE_PROP_TEXT;
174 25 : else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
175 0 : nFamily = XML_TYPE_PROP_PARAGRAPH;
176 25 : else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
177 25 : nFamily = XML_TYPE_PROP_GRAPHIC;
178 25 : if( nFamily )
179 : {
180 : UniReference < SvXMLImportPropertyMapper > xImpPrMap =
181 25 : GetStyles()->GetImportPropertyMapper( GetFamily() );
182 25 : if( xImpPrMap.is() )
183 : {
184 : pContext = new XMLTextShapePropertySetContext_Impl(
185 25 : GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
186 25 : GetProperties(), xImpPrMap );
187 25 : }
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 25 : if( !pContext )
201 : pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
202 0 : xAttrList );
203 :
204 25 : return pContext;
205 : }
206 :
207 12 : void XMLTextShapeStyleContext::CreateAndInsert( sal_Bool bOverwrite )
208 : {
209 12 : XMLShapeStyleContext::CreateAndInsert( bOverwrite );
210 12 : Reference < XStyle > xStyle = GetStyle();
211 12 : if( !xStyle.is() || !(bOverwrite || IsNew()) )
212 12 : return;
213 :
214 12 : Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
215 : Reference< XPropertySetInfo > xPropSetInfo =
216 12 : xPropSet->getPropertySetInfo();
217 12 : if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) )
218 : {
219 12 : Any aAny;
220 12 : sal_Bool bTmp = bAutoUpdate;
221 12 : aAny.setValue( &bTmp, ::getBooleanCppuType() );
222 12 : xPropSet->setPropertyValue( sIsAutoUpdate, aAny );
223 : }
224 :
225 : // tell the style about it's events (if applicable)
226 12 : 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 12 : }
233 : }
234 :
235 :
236 12 : void XMLTextShapeStyleContext::Finish( sal_Bool bOverwrite )
237 : {
238 12 : XMLPropStyleContext::Finish( bOverwrite );
239 12 : }
240 :
241 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|