tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / dbaccess / source / core / dataaccess / ComponentDefinition.cxx
bloba36adad3f40a870df0fedbd3819b5f28767dcf49
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ComponentDefinition.hxx"
21 #include <stringconstants.hxx>
22 #include <strings.hxx>
24 #include <osl/diagnose.h>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 //#include <cppuhelper/interfacecontainer.hxx>
27 #include <comphelper/property.hxx>
28 #include <comphelper/propertysequence.hxx>
29 #include <definitioncolumn.hxx>
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::container;
35 using namespace ::cppu;
37 namespace dbaccess
40 /// helper class for column property change events which holds the OComponentDefinition weak
41 class OColumnPropertyListener:
42 public ::cppu::WeakImplHelper< XPropertyChangeListener >
44 OComponentDefinition* m_pComponent;
45 protected:
46 virtual ~OColumnPropertyListener() override {}
47 public:
48 explicit OColumnPropertyListener(OComponentDefinition* _pComponent) : m_pComponent(_pComponent){}
49 OColumnPropertyListener(const OColumnPropertyListener&) = delete;
50 const OColumnPropertyListener& operator=(const OColumnPropertyListener&) = delete;
51 // XPropertyChangeListener
52 virtual void SAL_CALL propertyChange( const PropertyChangeEvent& /*_rEvent*/ ) override
54 if ( m_pComponent )
55 m_pComponent->notifyDataSourceModified();
57 // XEventListener
58 virtual void SAL_CALL disposing( const EventObject& /*_rSource*/ ) override
61 void clear() { m_pComponent = nullptr; }
64 OComponentDefinition_Impl::OComponentDefinition_Impl()
68 OComponentDefinition_Impl::~OComponentDefinition_Impl()
72 // OComponentDefinition
75 void OComponentDefinition::initialize( const Sequence< Any >& aArguments )
77 OUString rName;
78 if( (aArguments.getLength() == 1) && (aArguments[0] >>= rName) )
80 Sequence<Any> aNewArgs(comphelper::InitAnyPropertySequence(
82 {PROPERTY_NAME, Any(rName)}
83 }));
84 OContentHelper::initialize(aNewArgs);
86 else
87 OContentHelper::initialize(aArguments);
90 void OComponentDefinition::registerProperties()
92 m_xColumnPropertyListener = new OColumnPropertyListener(this);
93 OComponentDefinition_Impl& rDefinition( getDefinition() );
94 ODataSettings::registerPropertiesFor( &rDefinition );
96 registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY|PropertyAttribute::CONSTRAINED,
97 &rDefinition.m_aProps.aTitle, cppu::UnoType<decltype(rDefinition.m_aProps.aTitle)>::get());
99 if ( m_bTable )
101 registerProperty(PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME, PropertyAttribute::BOUND,
102 &rDefinition.m_sSchemaName, cppu::UnoType<decltype(rDefinition.m_sSchemaName)>::get());
104 registerProperty(PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME, PropertyAttribute::BOUND,
105 &rDefinition.m_sCatalogName, cppu::UnoType<decltype(rDefinition.m_sCatalogName)>::get());
109 OComponentDefinition::OComponentDefinition(const Reference< XComponentContext >& _xORB
110 ,const Reference< XInterface >& _xParentContainer
111 ,const TContentPtr& _pImpl
112 ,bool _bTable)
113 :OContentHelper(_xORB,_xParentContainer,_pImpl)
114 ,ODataSettings(OContentHelper::rBHelper,!_bTable)
115 ,m_bTable(_bTable)
117 registerProperties();
120 OComponentDefinition::~OComponentDefinition()
124 OComponentDefinition::OComponentDefinition( const Reference< XInterface >& _rxContainer
125 ,const OUString& _rElementName
126 ,const Reference< XComponentContext >& _xORB
127 ,const TContentPtr& _pImpl
128 ,bool _bTable)
129 :OContentHelper(_xORB,_rxContainer,_pImpl)
130 ,ODataSettings(OContentHelper::rBHelper,!_bTable)
131 ,m_bTable(_bTable)
133 registerProperties();
135 m_pImpl->m_aProps.aTitle = _rElementName;
136 OSL_ENSURE(!m_pImpl->m_aProps.aTitle.isEmpty(), "OComponentDefinition::OComponentDefinition : invalid name !");
139 css::uno::Sequence<sal_Int8> OComponentDefinition::getImplementationId()
141 return css::uno::Sequence<sal_Int8>();
144 css::uno::Sequence< css::uno::Type > OComponentDefinition::getTypes()
146 return ::comphelper::concatSequences(
147 ODataSettings::getTypes( ),
148 OContentHelper::getTypes( ),
149 OComponentDefinition_BASE::getTypes( )
152 IMPLEMENT_FORWARD_XINTERFACE3( OComponentDefinition,OContentHelper,ODataSettings,OComponentDefinition_BASE)
154 OUString SAL_CALL OComponentDefinition::getImplementationName()
156 return u"com.sun.star.comp.dba.OComponentDefinition"_ustr;
159 Sequence< OUString > SAL_CALL OComponentDefinition::getSupportedServiceNames()
161 return { u"com.sun.star.sdb.TableDefinition"_ustr, u"com.sun.star.ucb.Content"_ustr };
164 void SAL_CALL OComponentDefinition::disposing()
166 OContentHelper::disposing();
167 if (m_pColumns)
169 m_pColumns->disposing();
171 m_xColumnPropertyListener->clear();
172 m_xColumnPropertyListener.clear();
175 IPropertyArrayHelper& OComponentDefinition::getInfoHelper()
177 return *getArrayHelper();
180 IPropertyArrayHelper* OComponentDefinition::createArrayHelper( ) const
182 Sequence< Property > aProps;
183 describeProperties(aProps);
184 return new OPropertyArrayHelper(aProps);
187 Reference< XPropertySetInfo > SAL_CALL OComponentDefinition::getPropertySetInfo( )
189 Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
190 return xInfo;
193 OUString OComponentDefinition::determineContentType() const
195 return m_bTable
196 ? u"application/vnd.org.openoffice.DatabaseTable"_ustr
197 : u"application/vnd.org.openoffice.DatabaseCommandDefinition"_ustr;
200 Reference< XNameAccess> OComponentDefinition::getColumns()
202 ::osl::MutexGuard aGuard(m_aMutex);
203 ::connectivity::checkDisposed(OContentHelper::rBHelper.bDisposed);
205 if (!m_pColumns)
207 std::vector< OUString> aNames;
209 const OComponentDefinition_Impl& rDefinition( getDefinition() );
210 aNames.reserve( rDefinition.size() );
212 for (auto const& definition : rDefinition)
213 aNames.push_back(definition.first);
215 m_pColumns.reset(new OColumns(*this, m_aMutex, true, aNames, this, nullptr, true, false, false));
216 m_pColumns->setParent(*this);
218 // see OCollection::acquire
219 return m_pColumns.get();
222 rtl::Reference<OColumn> OComponentDefinition::createColumn(const OUString& _rName) const
224 const OComponentDefinition_Impl& rDefinition( getDefinition() );
225 OComponentDefinition_Impl::const_iterator aFind = rDefinition.find( _rName );
226 if ( aFind != rDefinition.end() )
228 aFind->second->addPropertyChangeListener(OUString(),m_xColumnPropertyListener);
229 return new OTableColumnWrapper( aFind->second, aFind->second, true );
231 OSL_FAIL( "OComponentDefinition::createColumn: is this a valid case?" );
232 // This here is the last place creating a OTableColumn, and somehow /me thinks it is not needed ...
233 return new OTableColumn( _rName );
236 Reference< XPropertySet > OComponentDefinition::createColumnDescriptor()
238 return new OTableColumnDescriptor( true );
241 void OComponentDefinition::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
243 ODataSettings::setFastPropertyValue_NoBroadcast(nHandle,rValue);
244 notifyDataSourceModified();
247 void OComponentDefinition::columnDropped(const OUString& _sName)
249 getDefinition().erase( _sName );
250 notifyDataSourceModified();
253 void OComponentDefinition::columnAppended( const Reference< XPropertySet >& _rxSourceDescriptor )
255 OUString sName;
256 _rxSourceDescriptor->getPropertyValue( PROPERTY_NAME ) >>= sName;
258 Reference<XPropertySet> xColDesc = new OTableColumnDescriptor( true );
259 ::comphelper::copyProperties( _rxSourceDescriptor, xColDesc );
260 getDefinition().insert( sName, xColDesc );
262 // formerly, here was a setParent at the xColDesc. The parent used was an adapter (ChildHelper_Impl)
263 // which held another XChild weak, and forwarded all getParent requests to this other XChild.
264 // m_pColumns was used for this. This was nonsense, since m_pColumns dies when our instance dies,
265 // but xColDesc will live longer than this. So effectively, the setParent call was pretty useless.
267 // The intention for this parenting was that the column descriptor is able to find the data source,
268 // by traveling up the parent hierarchy until there's an XDataSource. This didn't work (which
269 // for instance causes #i65023#). We need another way to properly ensure this.
271 notifyDataSourceModified();
274 } // namespace dbaccess
276 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
277 com_sun_star_comp_dba_OComponentDefinition(css::uno::XComponentContext* context,
278 css::uno::Sequence<css::uno::Any> const &)
280 return cppu::acquire(new dbaccess::OComponentDefinition(
281 context, nullptr, std::make_shared<dbaccess::OComponentDefinition_Impl>()));
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */