xref: /trunk/main/xmloff/source/text/XMLTextShapeStyleContext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir #include <tools/debug.hxx>
31*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP
32*cdf0e10cSrcweir #include <com/sun/star/document/XEventsSupplier.hpp>
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
35*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
36*cdf0e10cSrcweir #include "XMLTextPropertySetContext.hxx"
37*cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
38*cdf0e10cSrcweir #include <xmloff/XMLEventsImportContext.hxx>
39*cdf0e10cSrcweir #include "XMLShapePropertySetContext.hxx"
40*cdf0e10cSrcweir #include "XMLTextColumnsContext.hxx"
41*cdf0e10cSrcweir #include "XMLBackgroundImageContext.hxx"
42*cdf0e10cSrcweir #ifndef _XMLOFF_TXTPRMAP_HXX
43*cdf0e10cSrcweir #include <xmloff/txtprmap.hxx>
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #ifndef _XMLOFF_XMLTEXTSHAPESTYLECONTEXT_HXX
47*cdf0e10cSrcweir #include <xmloff/XMLTextShapeStyleContext.hxx>
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir using ::rtl::OUString;
51*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir using namespace ::com::sun::star::document;
54*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
55*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
56*cdf0e10cSrcweir using namespace ::com::sun::star::style;
57*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
58*cdf0e10cSrcweir using namespace ::xmloff::token;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir public:
63*cdf0e10cSrcweir     XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
64*cdf0e10cSrcweir         const OUString& rLName,
65*cdf0e10cSrcweir         const Reference< XAttributeList >& xAttrList,
66*cdf0e10cSrcweir                  sal_uInt32 nFamily,
67*cdf0e10cSrcweir         ::std::vector< XMLPropertyState > &rProps,
68*cdf0e10cSrcweir         const UniReference < SvXMLImportPropertyMapper > &rMap );
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     virtual ~XMLTextShapePropertySetContext_Impl();
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir     using SvXMLPropertySetContext::CreateChildContext;
73*cdf0e10cSrcweir     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
74*cdf0e10cSrcweir         const OUString& rLocalName,
75*cdf0e10cSrcweir         const Reference< XAttributeList >& xAttrList,
76*cdf0e10cSrcweir         ::std::vector< XMLPropertyState > &rProperties,
77*cdf0e10cSrcweir         const XMLPropertyState& rProp);
78*cdf0e10cSrcweir };
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl(
81*cdf0e10cSrcweir                  SvXMLImport& rImport, sal_uInt16 nPrfx,
82*cdf0e10cSrcweir                  const OUString& rLName,
83*cdf0e10cSrcweir                  const Reference< XAttributeList > & xAttrList,
84*cdf0e10cSrcweir                  sal_uInt32 nFamily,
85*cdf0e10cSrcweir                  ::std::vector< XMLPropertyState > &rProps,
86*cdf0e10cSrcweir                  const UniReference < SvXMLImportPropertyMapper > &rMap ) :
87*cdf0e10cSrcweir     XMLShapePropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily,
88*cdf0e10cSrcweir                                 rProps, rMap )
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir XMLTextShapePropertySetContext_Impl::~XMLTextShapePropertySetContext_Impl()
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir SvXMLImportContext *XMLTextShapePropertySetContext_Impl::CreateChildContext(
97*cdf0e10cSrcweir                    sal_uInt16 nPrefix,
98*cdf0e10cSrcweir                    const OUString& rLocalName,
99*cdf0e10cSrcweir                    const Reference< XAttributeList > & xAttrList,
100*cdf0e10cSrcweir                    ::std::vector< XMLPropertyState > &rProperties,
101*cdf0e10cSrcweir                    const XMLPropertyState& rProp )
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir     SvXMLImportContext *pContext = 0;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     switch( mxMapper->getPropertySetMapper()
106*cdf0e10cSrcweir                     ->GetEntryContextId( rProp.mnIndex ) )
107*cdf0e10cSrcweir     {
108*cdf0e10cSrcweir     case CTF_TEXTCOLUMNS:
109*cdf0e10cSrcweir         pContext = new XMLTextColumnsContext( GetImport(), nPrefix,
110*cdf0e10cSrcweir                                                    rLocalName, xAttrList, rProp,
111*cdf0e10cSrcweir                                                    rProperties );
112*cdf0e10cSrcweir         break;
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     case CTF_BACKGROUND_URL:
115*cdf0e10cSrcweir         DBG_ASSERT( rProp.mnIndex >= 3 &&
116*cdf0e10cSrcweir                     CTF_BACKGROUND_TRANSPARENCY ==
117*cdf0e10cSrcweir                         mxMapper->getPropertySetMapper()
118*cdf0e10cSrcweir                         ->GetEntryContextId( rProp.mnIndex-3 ) &&
119*cdf0e10cSrcweir                     CTF_BACKGROUND_POS  == mxMapper->getPropertySetMapper()
120*cdf0e10cSrcweir                         ->GetEntryContextId( rProp.mnIndex-2 ) &&
121*cdf0e10cSrcweir                     CTF_BACKGROUND_FILTER  == mxMapper->getPropertySetMapper()
122*cdf0e10cSrcweir                         ->GetEntryContextId( rProp.mnIndex-1 ),
123*cdf0e10cSrcweir                     "invalid property map!");
124*cdf0e10cSrcweir         pContext =
125*cdf0e10cSrcweir             new XMLBackgroundImageContext( GetImport(), nPrefix,
126*cdf0e10cSrcweir                                            rLocalName, xAttrList,
127*cdf0e10cSrcweir                                            rProp,
128*cdf0e10cSrcweir                                            rProp.mnIndex-2,
129*cdf0e10cSrcweir                                            rProp.mnIndex-1,
130*cdf0e10cSrcweir                                            rProp.mnIndex-3,
131*cdf0e10cSrcweir                                            rProperties );
132*cdf0e10cSrcweir         break;
133*cdf0e10cSrcweir     }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     if( !pContext )
136*cdf0e10cSrcweir         pContext = XMLShapePropertySetContext::CreateChildContext(
137*cdf0e10cSrcweir                         nPrefix, rLocalName, xAttrList, rProperties, rProp );
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     return pContext;
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir //-----------------------------------------------------------------------------
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir void XMLTextShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
145*cdf0e10cSrcweir                                         const OUString& rLocalName,
146*cdf0e10cSrcweir                                         const OUString& rValue )
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir     if( XML_NAMESPACE_STYLE == nPrefixKey &&
149*cdf0e10cSrcweir         IsXMLToken( rLocalName, XML_AUTO_UPDATE ) )
150*cdf0e10cSrcweir     {
151*cdf0e10cSrcweir         if( IsXMLToken( rValue, XML_TRUE ) )
152*cdf0e10cSrcweir             bAutoUpdate = sal_True;
153*cdf0e10cSrcweir     }
154*cdf0e10cSrcweir     else
155*cdf0e10cSrcweir     {
156*cdf0e10cSrcweir         XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
157*cdf0e10cSrcweir     }
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir TYPEINIT1( XMLTextShapeStyleContext, XMLShapeStyleContext );
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir XMLTextShapeStyleContext::XMLTextShapeStyleContext( SvXMLImport& rImport,
163*cdf0e10cSrcweir         sal_uInt16 nPrfx, const OUString& rLName,
164*cdf0e10cSrcweir         const Reference< XAttributeList > & xAttrList,
165*cdf0e10cSrcweir         SvXMLStylesContext& rStyles, sal_uInt16 nFamily,
166*cdf0e10cSrcweir         sal_Bool /*bDefaultStyle*/ ) :
167*cdf0e10cSrcweir     XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles,
168*cdf0e10cSrcweir                           nFamily ),
169*cdf0e10cSrcweir     sIsAutoUpdate( RTL_CONSTASCII_USTRINGPARAM( "IsAutoUpdate" ) ),
170*cdf0e10cSrcweir     bAutoUpdate( sal_False )
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir XMLTextShapeStyleContext::~XMLTextShapeStyleContext()
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir SvXMLImportContext *XMLTextShapeStyleContext::CreateChildContext(
179*cdf0e10cSrcweir         sal_uInt16 nPrefix,
180*cdf0e10cSrcweir         const OUString& rLocalName,
181*cdf0e10cSrcweir         const Reference< XAttributeList > & xAttrList )
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir     SvXMLImportContext *pContext = 0;
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     if( XML_NAMESPACE_STYLE == nPrefix )
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir         sal_uInt32 nFamily = 0;
188*cdf0e10cSrcweir         if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
189*cdf0e10cSrcweir             nFamily = XML_TYPE_PROP_TEXT;
190*cdf0e10cSrcweir         else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
191*cdf0e10cSrcweir             nFamily = XML_TYPE_PROP_PARAGRAPH;
192*cdf0e10cSrcweir         else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
193*cdf0e10cSrcweir             nFamily = XML_TYPE_PROP_GRAPHIC;
194*cdf0e10cSrcweir         if( nFamily )
195*cdf0e10cSrcweir         {
196*cdf0e10cSrcweir             UniReference < SvXMLImportPropertyMapper > xImpPrMap =
197*cdf0e10cSrcweir                 GetStyles()->GetImportPropertyMapper( GetFamily() );
198*cdf0e10cSrcweir             if( xImpPrMap.is() )
199*cdf0e10cSrcweir             {
200*cdf0e10cSrcweir                 pContext = new XMLTextShapePropertySetContext_Impl(
201*cdf0e10cSrcweir                         GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
202*cdf0e10cSrcweir                         GetProperties(), xImpPrMap );
203*cdf0e10cSrcweir             }
204*cdf0e10cSrcweir         }
205*cdf0e10cSrcweir     }
206*cdf0e10cSrcweir     else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
207*cdf0e10cSrcweir               IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
208*cdf0e10cSrcweir     {
209*cdf0e10cSrcweir         // create and remember events import context
210*cdf0e10cSrcweir         // (for delayed processing of events)
211*cdf0e10cSrcweir         pContext = new XMLEventsImportContext( GetImport(), nPrefix,
212*cdf0e10cSrcweir                                                    rLocalName);
213*cdf0e10cSrcweir         xEventContext = pContext;
214*cdf0e10cSrcweir     }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir     if( !pContext )
217*cdf0e10cSrcweir         pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
218*cdf0e10cSrcweir                                                           xAttrList );
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     return pContext;
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir void XMLTextShapeStyleContext::CreateAndInsert( sal_Bool bOverwrite )
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     XMLShapeStyleContext::CreateAndInsert( bOverwrite );
226*cdf0e10cSrcweir     Reference < XStyle > xStyle = GetStyle();
227*cdf0e10cSrcweir     if( !xStyle.is() || !(bOverwrite || IsNew()) )
228*cdf0e10cSrcweir         return;
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir     Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
231*cdf0e10cSrcweir     Reference< XPropertySetInfo > xPropSetInfo =
232*cdf0e10cSrcweir                 xPropSet->getPropertySetInfo();
233*cdf0e10cSrcweir     if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) )
234*cdf0e10cSrcweir     {
235*cdf0e10cSrcweir         Any aAny;
236*cdf0e10cSrcweir         sal_Bool bTmp = bAutoUpdate;
237*cdf0e10cSrcweir         aAny.setValue( &bTmp, ::getBooleanCppuType() );
238*cdf0e10cSrcweir         xPropSet->setPropertyValue( sIsAutoUpdate, aAny );
239*cdf0e10cSrcweir     }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     // tell the style about it's events (if applicable)
242*cdf0e10cSrcweir     if( xEventContext.Is() )
243*cdf0e10cSrcweir     {
244*cdf0e10cSrcweir         // set event suppplier and release reference to context
245*cdf0e10cSrcweir         Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY);
246*cdf0e10cSrcweir         ((XMLEventsImportContext *)&xEventContext)->SetEvents(xEventsSupplier);
247*cdf0e10cSrcweir         xEventContext = 0;
248*cdf0e10cSrcweir     }
249*cdf0e10cSrcweir }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir void XMLTextShapeStyleContext::Finish( sal_Bool bOverwrite )
253*cdf0e10cSrcweir {
254*cdf0e10cSrcweir     XMLPropStyleContext::Finish( bOverwrite );
255*cdf0e10cSrcweir }
256