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