xref: /AOO41X/main/xmloff/source/forms/elementimport_impl.hxx (revision ecfe53c5d1886e1e0d215b0d140d05282ab1c477)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // no include protection. This file is included from elementimport.hxx only.
25 
26 #ifndef _INCLUDING_FROM_ELEMENTIMPORT_HXX_
27 #error "do not include this file directly!"
28 #endif
29 
30 // no namespace. Same as above: this file is included from elementimport.hxx only,
31 // and this is done inside the namespace
32 
33 //=========================================================================
34 //= OContainerImport
35 //=========================================================================
36 //-------------------------------------------------------------------------
37 template <class BASE>
CreateChildContext(sal_uInt16 _nPrefix,const::rtl::OUString & _rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & _rxAttrList)38 inline SvXMLImportContext* OContainerImport< BASE >::CreateChildContext(
39     sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
40     const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList)
41 {
42     // maybe it's a sub control
43     if (_rLocalName == m_sWrapperElementName)
44     {
45         if (m_xMeAsContainer.is())
46             return implCreateControlWrapper(_nPrefix, _rLocalName);
47         else
48         {
49             OSL_ENSURE(sal_False, "OContainerImport::CreateChildContext: don't have an element!");
50             return NULL;
51         }
52     }
53 
54     return BASE::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
55 }
56 
57 //-------------------------------------------------------------------------
58 template <class BASE>
59 inline ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
createElement()60     OContainerImport< BASE >::createElement()
61 {
62     // let the base class create the object
63     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xReturn = BASE::createElement();
64     if (!xReturn.is())
65         return xReturn;
66 
67     // ensure that the object is a XNameContainer (we strongly need this for inserting child elements)
68     m_xMeAsContainer = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >(xReturn, ::com::sun::star::uno::UNO_QUERY);
69     if (!m_xMeAsContainer.is())
70     {
71         OSL_ENSURE(sal_False, "OContainerImport::createElement: invalid element (no XNameContainer) created!");
72         xReturn.clear();
73     }
74 
75     return xReturn;
76 }
77 
78 //-------------------------------------------------------------------------
79 template <class BASE>
EndElement()80 inline void OContainerImport< BASE >::EndElement()
81 {
82     BASE::EndElement();
83 
84     // now that we have all children, attach the events
85     ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > xIndexContainer(m_xMeAsContainer, ::com::sun::star::uno::UNO_QUERY);
86     if (xIndexContainer.is())
87         ODefaultEventAttacherManager::setEvents(xIndexContainer);
88 }
89 
90 //=========================================================================
91 //= OColumnImport
92 //=========================================================================
93 //-------------------------------------------------------------------------
94 template <class BASE>
OColumnImport(OFormLayerXMLImport_Impl & _rImport,IEventAttacherManager & _rEventManager,sal_uInt16 _nPrefix,const::rtl::OUString & _rName,const::com::sun::star::uno::Reference<::com::sun::star::container::XNameContainer> & _rxParentContainer,OControlElement::ElementType _eType)95 OColumnImport< BASE >::OColumnImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
96         const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& _rxParentContainer,
97         OControlElement::ElementType _eType)
98     :BASE(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
99     ,m_xColumnFactory(_rxParentContainer, ::com::sun::star::uno::UNO_QUERY)
100 {
101     OSL_ENSURE(m_xColumnFactory.is(), "OColumnImport::OColumnImport: invalid parent container (no factory)!");
102 }
103 
104 //-------------------------------------------------------------------------
105 // OElementImport overridables
106 template <class BASE>
createElement()107 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > OColumnImport< BASE >::createElement()
108 {
109     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xReturn;
110     // no call to the base class' method. We have to use the grid column factory
111     if (m_xColumnFactory.is())
112     {
113         // create the column
114         xReturn = m_xColumnFactory->createColumn(this->m_sServiceName);
115         OSL_ENSURE(xReturn.is(), "OColumnImport::createElement: the factory returned an invalid object!");
116     }
117     return xReturn;
118 }
119 
120