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