tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / include / connectivity / sdbcx / VCollection.hxx
blobdc1ceccb2ae2263667ea2657510d76dd801205c1
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 #ifndef INCLUDED_CONNECTIVITY_SDBCX_VCOLLECTION_HXX
21 #define INCLUDED_CONNECTIVITY_SDBCX_VCOLLECTION_HXX
23 #include <cppuhelper/implbase10.hxx>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/container/XIndexAccess.hpp>
26 #include <com/sun/star/container/XEnumerationAccess.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/util/XRefreshable.hpp>
29 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
30 #include <com/sun/star/sdbcx/XAppend.hpp>
31 #include <com/sun/star/sdbcx/XDrop.hpp>
32 #include <com/sun/star/sdbc/XColumnLocate.hpp>
33 #include <comphelper/interfacecontainer3.hxx>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <connectivity/CommonTools.hxx>
36 #include <com/sun/star/container/XContainer.hpp>
37 #include <connectivity/dbtoolsdllapi.hxx>
38 #include <memory>
40 namespace com::sun::star::container { class XEnumeration; }
43 namespace connectivity::sdbcx
46 // the class OCollection is base class for collections :-)
47 typedef ::cppu::ImplHelper10< css::container::XNameAccess,
48 css::container::XIndexAccess,
49 css::container::XEnumerationAccess,
50 css::container::XContainer,
51 css::sdbc::XColumnLocate,
52 css::util::XRefreshable,
53 css::sdbcx::XDataDescriptorFactory,
54 css::sdbcx::XAppend,
55 css::sdbcx::XDrop,
56 css::lang::XServiceInfo> OCollectionBase;
58 typedef css::uno::Reference< css::beans::XPropertySet > ObjectType;
60 class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE IObjectCollection
62 public:
63 virtual ~IObjectCollection();
64 virtual bool exists(const OUString& _sName ) = 0;
65 virtual bool empty() = 0;
66 virtual void swapAll() = 0;
67 virtual void swap() = 0;
68 virtual void clear() = 0;
69 virtual void reFill(const ::std::vector< OUString> &_rVector) = 0;
70 virtual void insert(const OUString& _sName, const ObjectType& _xObject) = 0;
71 virtual bool rename(const OUString& _sOldName, const OUString& _sNewName) = 0;
72 virtual sal_Int32 size() = 0;
73 virtual css::uno::Sequence< OUString > getElementNames() = 0;
74 virtual OUString getName(sal_Int32 _nIndex) = 0;
75 virtual void disposeAndErase(sal_Int32 _nIndex) = 0;
76 virtual void disposeElements() = 0;
77 virtual sal_Int32 findColumn( const OUString& columnName ) = 0;
78 virtual ObjectType getObject(sal_Int32 _nIndex) = 0;
79 virtual ObjectType getObject(const OUString& columnName) = 0;
80 virtual void setObject(sal_Int32 _nIndex,const ObjectType& _xObject) = 0;
81 virtual bool isCaseSensitive() const = 0;
84 // OCollection
86 class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE OCollection :
87 public OCollectionBase
89 protected:
90 ::std::unique_ptr<IObjectCollection> m_pElements;
92 ::comphelper::OInterfaceContainerHelper3<css::container::XContainerListener> m_aContainerListeners;
93 ::comphelper::OInterfaceContainerHelper3<css::util::XRefreshListener> m_aRefreshListeners;
95 protected:
96 ::cppu::OWeakObject& m_rParent; // parent of the collection
97 ::osl::Mutex& m_rMutex; // mutex of the parent
98 bool m_bUseIndexOnly; // is only TRUE when only an indexaccess is needed
100 // the implementing class should refresh their elements
101 /// @throws css::uno::RuntimeException
102 virtual void impl_refresh() = 0;
104 // will be called when an object was requested by one of the accessing methods like getByIndex
105 virtual ObjectType createObject(const OUString& _rName) = 0;
107 // will be called when a new object should be generated by a call of createDataDescriptor
108 // the returned object is empty will be filled outside and added to the collection
109 virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor();
111 /** appends an object described by a descriptor, under a given name
112 @param _rForName
113 is the name under which the object should be appended. Guaranteed to not be empty.
114 This is passed for convenience only, since it's the result of a call of
115 getNameForObject for the given descriptor
116 @param descriptor
117 describes the object to append
118 @return
119 the new object which is to be inserted into the collection. This might be the result
120 of a call of <code>createObject( _rForName )</code>, or a clone of the descriptor.
122 virtual ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor );
124 // called when XDrop was called
125 virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName);
127 /** returns the name for the object. The default implementation ask for the property NAME. If this doesn't satisfy, it has to be overridden.
128 @param _xObject The object where the name should be extracted.
129 @return The name of the object.
131 virtual OUString getNameForObject(const ObjectType& _xObject);
133 /** clones the given descriptor
135 The method calls createDescriptor to create a new, empty descriptor, and then copies all properties from
136 _descriptor to the new object, which is returned.
138 This method might come handy in derived classes for implementing appendObject, when the object
139 is not actually appended to any backend (e.g. for the columns collection of a descriptor object itself,
140 where there is not yet a database backend to append the column to).
142 ObjectType cloneDescriptor( const ObjectType& _descriptor );
144 OCollection(::cppu::OWeakObject& _rParent,
145 bool _bCase,
146 ::osl::Mutex& _rMutex,
147 const ::std::vector< OUString> &_rVector,
148 bool _bUseIndexOnly = false,
149 bool _bUseHardRef = true);
151 /** clear the name map
152 <p>Does <em>not</em> dispose the objects hold by the collection.</p>
154 void clear_NoDispose();
156 /** insert a new element into the collection
158 void insertElement(const OUString& _sElementName,const ObjectType& _xElement);
160 /** return the object, if not existent it creates it.
161 @param _nIndex
162 The index of the object to create.
163 @return ObjectType
165 ObjectType getObject(sal_Int32 _nIndex);
167 public:
168 virtual ~OCollection();
169 DECLARE_SERVICE_INFO();
171 void reFill(const ::std::vector< OUString> &_rVector);
172 bool isCaseSensitive() const { return m_pElements->isCaseSensitive(); }
173 void renameObject(const OUString& _sOldName, const OUString& _sNewName);
175 // only the name is identical to ::cppu::OComponentHelper
176 virtual void disposing();
177 // dispatch the refcounting to the parent
178 virtual void SAL_CALL acquire() noexcept override;
179 virtual void SAL_CALL release() noexcept override;
181 // XInterface
182 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
183 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
185 // css::container::XElementAccess
186 virtual css::uno::Type SAL_CALL getElementType( ) override;
187 virtual sal_Bool SAL_CALL hasElements( ) override;
188 // css::container::XIndexAccess
189 virtual sal_Int32 SAL_CALL getCount( ) override;
190 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
192 // css::container::XNameAccess
193 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
194 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
195 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
196 // XEnumerationAccess
197 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration( ) override;
198 // css::util::XRefreshable
199 virtual void SAL_CALL refresh( ) override;
200 virtual void SAL_CALL addRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
201 virtual void SAL_CALL removeRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
202 // XDataDescriptorFactory
203 virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor( ) override;
204 // XAppend
205 virtual void SAL_CALL appendByDescriptor( const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override;
206 // XDrop
207 virtual void SAL_CALL dropByName( const OUString& elementName ) override;
208 virtual void SAL_CALL dropByIndex( sal_Int32 index ) override;
209 // XColumnLocate
210 virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override;
211 // css::container::XContainer
212 virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
213 virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
214 private:
215 void notifyElementRemoved(const OUString& _sName);
216 void disposeElements();
217 void dropImpl(sal_Int32 _nIndex, bool _bReallyDrop = true);
221 #endif // INCLUDED_CONNECTIVITY_SDBCX_VCOLLECTION_HXX
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */