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