File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 113, column 13 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /* | |||
3 | * This file is part of the LibreOffice project. | |||
4 | * | |||
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/. | |||
8 | * | |||
9 | * This file incorporates work covered by the following license notice: | |||
10 | * | |||
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 . | |||
18 | */ | |||
19 | ||||
20 | #include <memory> | |||
21 | #include "AppController.hxx" | |||
22 | #include <core_resource.hxx> | |||
23 | #include <strings.hxx> | |||
24 | #include <advancedsettingsdlg.hxx> | |||
25 | #include "subcomponentmanager.hxx" | |||
26 | ||||
27 | #include <com/sun/star/beans/NamedValue.hpp> | |||
28 | #include <com/sun/star/container/XChild.hpp> | |||
29 | #include <com/sun/star/container/XContainer.hpp> | |||
30 | #include <com/sun/star/container/XContentEnumerationAccess.hpp> | |||
31 | #include <com/sun/star/container/XHierarchicalNameAccess.hpp> | |||
32 | #include <com/sun/star/container/XHierarchicalNameContainer.hpp> | |||
33 | #include <com/sun/star/frame/XStorable.hpp> | |||
34 | #include <com/sun/star/sdb/CommandType.hpp> | |||
35 | #include <com/sun/star/sdb/ErrorMessageDialog.hpp> | |||
36 | #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> | |||
37 | #include <com/sun/star/sdbc/SQLException.hpp> | |||
38 | #include <com/sun/star/sdbc/SQLWarning.hpp> | |||
39 | #include <com/sun/star/sdbc/XDataSource.hpp> | |||
40 | #include <com/sun/star/sdbcx/XAlterView.hpp> | |||
41 | #include <com/sun/star/sdbcx/XAppend.hpp> | |||
42 | #include <com/sun/star/sdbcx/XRename.hpp> | |||
43 | #include <com/sun/star/sdbcx/XTablesSupplier.hpp> | |||
44 | #include <com/sun/star/sdbcx/XViewsSupplier.hpp> | |||
45 | #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> | |||
46 | #include <com/sun/star/util/XFlushable.hpp> | |||
47 | #include <com/sun/star/util/XModifiable.hpp> | |||
48 | #include <com/sun/star/util/XModifyBroadcaster.hpp> | |||
49 | #include <com/sun/star/util/XURLTransformer.hpp> | |||
50 | #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> | |||
51 | #include <com/sun/star/document/XEmbeddedScripts.hpp> | |||
52 | #include <com/sun/star/frame/XModel2.hpp> | |||
53 | #include <com/sun/star/task/XInteractionHandler.hpp> | |||
54 | #include <com/sun/star/sdb/application/DatabaseObject.hpp> | |||
55 | #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp> | |||
56 | #include <com/sun/star/document/XDocumentEventBroadcaster.hpp> | |||
57 | #include <tools/diagnose_ex.h> | |||
58 | #include <tools/urlobj.hxx> | |||
59 | #include <osl/diagnose.h> | |||
60 | ||||
61 | #include <svl/filenotation.hxx> | |||
62 | #include <vcl/transfer.hxx> | |||
63 | #include <svtools/cliplistener.hxx> | |||
64 | ||||
65 | #include <comphelper/sequence.hxx> | |||
66 | #include <comphelper/uno3.hxx> | |||
67 | #include <comphelper/types.hxx> | |||
68 | #include <comphelper/interaction.hxx> | |||
69 | #include <comphelper/processfactory.hxx> | |||
70 | ||||
71 | #include <vcl/svapp.hxx> | |||
72 | #include <vcl/weld.hxx> | |||
73 | ||||
74 | #include <unotools/closeveto.hxx> | |||
75 | #include <unotools/pathoptions.hxx> | |||
76 | #include <unotools/moduleoptions.hxx> | |||
77 | #include <unotools/historyoptions.hxx> | |||
78 | ||||
79 | #include <sfx2/mailmodelapi.hxx> | |||
80 | #include <sfx2/filedlghelper.hxx> | |||
81 | #include <sfx2/docfilt.hxx> | |||
82 | #include <sfx2/QuerySaveDocument.hxx> | |||
83 | ||||
84 | #include <cppuhelper/exc_hlp.hxx> | |||
85 | ||||
86 | #include <connectivity/dbtools.hxx> | |||
87 | #include <connectivity/dbexception.hxx> | |||
88 | ||||
89 | #include <svx/dbaexchange.hxx> | |||
90 | #include <svx/dbaobjectex.hxx> | |||
91 | #include <svx/svxdlg.hxx> | |||
92 | ||||
93 | #include <osl/mutex.hxx> | |||
94 | #include "AppView.hxx" | |||
95 | #include <browserids.hxx> | |||
96 | #include <strings.hrc> | |||
97 | #include <defaultobjectnamecheck.hxx> | |||
98 | #include <databaseobjectview.hxx> | |||
99 | #include <dbtreelistbox.hxx> | |||
100 | #include "AppDetailView.hxx" | |||
101 | #include <linkeddocuments.hxx> | |||
102 | #include <UITools.hxx> | |||
103 | #include <dsntypes.hxx> | |||
104 | #include <dlgsave.hxx> | |||
105 | #include <dbaccess_slotid.hrc> | |||
106 | ||||
107 | extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface* | |||
108 | org_openoffice_comp_dbu_OApplicationController_get_implementation( | |||
109 | css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& ) | |||
110 | { | |||
111 | return cppu::acquire(new ::dbaui::OApplicationController(context)); | |||
112 | } | |||
113 | ||||
114 | namespace dbaui | |||
115 | { | |||
116 | using namespace ::dbtools; | |||
117 | using namespace ::svx; | |||
118 | using namespace ::com::sun::star; | |||
119 | using namespace ::com::sun::star::uno; | |||
120 | using namespace ::com::sun::star::ucb; | |||
121 | using namespace ::com::sun::star::view; | |||
122 | using namespace ::com::sun::star::util; | |||
123 | using namespace ::com::sun::star::beans; | |||
124 | using namespace ::com::sun::star::lang; | |||
125 | using namespace ::com::sun::star::frame; | |||
126 | using namespace ::com::sun::star::container; | |||
127 | using namespace ::com::sun::star::sdb; | |||
128 | using namespace ::com::sun::star::sdbc; | |||
129 | using namespace ::com::sun::star::sdbcx; | |||
130 | using namespace ::com::sun::star::datatransfer; | |||
131 | using namespace ::com::sun::star::ui::dialogs; | |||
132 | using namespace ::com::sun::star::task; | |||
133 | using ::com::sun::star::document::XEmbeddedScripts; | |||
134 | using ::com::sun::star::document::XDocumentEventBroadcaster; | |||
135 | using ::com::sun::star::sdb::application::NamedDatabaseObject; | |||
136 | ||||
137 | namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; | |||
138 | namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer; | |||
139 | ||||
140 | OUString SAL_CALL OApplicationController::getImplementationName() | |||
141 | { | |||
142 | return SERVICE_SDB_APPLICATIONCONTROLLER"org.openoffice.comp.dbu.OApplicationController"; | |||
143 | } | |||
144 | ||||
145 | Sequence< OUString> SAL_CALL OApplicationController::getSupportedServiceNames() | |||
146 | { | |||
147 | return { "com.sun.star.sdb.application.DefaultViewController" }; | |||
148 | } | |||
149 | ||||
150 | namespace { | |||
151 | ||||
152 | class SelectionGuard; | |||
153 | ||||
154 | } | |||
155 | ||||
156 | // OApplicationController | |||
157 | class SelectionNotifier | |||
158 | { | |||
159 | private: | |||
160 | ::comphelper::OInterfaceContainerHelper2 m_aSelectionListeners; | |||
161 | ::cppu::OWeakObject& m_rContext; | |||
162 | sal_Int32 m_nSelectionNestingLevel; | |||
163 | ||||
164 | public: | |||
165 | SelectionNotifier( ::osl::Mutex& _rMutex, ::cppu::OWeakObject& _rContext ) | |||
166 | :m_aSelectionListeners( _rMutex ) | |||
167 | ,m_rContext( _rContext ) | |||
168 | ,m_nSelectionNestingLevel( 0 ) | |||
169 | { | |||
170 | } | |||
171 | ||||
172 | SelectionNotifier(const SelectionNotifier&) = delete; | |||
173 | const SelectionNotifier& operator=(const SelectionNotifier&) = delete; | |||
174 | ||||
175 | void addListener( const Reference< XSelectionChangeListener >& Listener ) | |||
176 | { | |||
177 | m_aSelectionListeners.addInterface( Listener ); | |||
178 | } | |||
179 | ||||
180 | void removeListener( const Reference< XSelectionChangeListener >& Listener ) | |||
181 | { | |||
182 | m_aSelectionListeners.removeInterface( Listener ); | |||
183 | } | |||
184 | ||||
185 | void disposing() | |||
186 | { | |||
187 | EventObject aEvent( m_rContext ); | |||
188 | m_aSelectionListeners.disposeAndClear( aEvent ); | |||
189 | } | |||
190 | ||||
191 | struct SelectionGuardAccess { friend SelectionGuard; private: SelectionGuardAccess() { } }; | |||
192 | ||||
193 | /** enters a block which modifies the selection of our owner. | |||
194 | ||||
195 | Can be called multiple times, the only important thing is to call leaveSelection | |||
196 | equally often. | |||
197 | */ | |||
198 | void enterSelection( SelectionGuardAccess ) | |||
199 | { | |||
200 | ++m_nSelectionNestingLevel; | |||
201 | } | |||
202 | ||||
203 | /** leaves a block which modifies the selection of our owner | |||
204 | ||||
205 | Must be paired with enterSelection calls. | |||
206 | ||||
207 | When the last block is left, i.e. the last leaveSelection call is made on the current stack, | |||
208 | then our SelectionChangeListeners are notified | |||
209 | */ | |||
210 | void leaveSelection( SelectionGuardAccess ) | |||
211 | { | |||
212 | if ( --m_nSelectionNestingLevel == 0 ) | |||
213 | { | |||
214 | EventObject aEvent( m_rContext ); | |||
215 | m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aEvent ); | |||
216 | } | |||
217 | } | |||
218 | }; | |||
219 | ||||
220 | namespace { | |||
221 | ||||
222 | class SelectionGuard | |||
223 | { | |||
224 | public: | |||
225 | explicit SelectionGuard( SelectionNotifier& _rNotifier ) | |||
226 | :m_rNotifier( _rNotifier ) | |||
227 | { | |||
228 | m_rNotifier.enterSelection( SelectionNotifier::SelectionGuardAccess() ); | |||
229 | } | |||
230 | ||||
231 | ~SelectionGuard() | |||
232 | { | |||
233 | m_rNotifier.leaveSelection( SelectionNotifier::SelectionGuardAccess() ); | |||
234 | } | |||
235 | ||||
236 | SelectionGuard(const SelectionGuard&) = delete; | |||
237 | const SelectionGuard& operator=(const SelectionGuard&) = delete; | |||
238 | ||||
239 | private: | |||
240 | SelectionNotifier& m_rNotifier; | |||
241 | }; | |||
242 | ||||
243 | } | |||
244 | ||||
245 | // OApplicationController | |||
246 | OApplicationController::OApplicationController(const Reference< XComponentContext >& _rxORB) | |||
247 | :OGenericUnoController( _rxORB ) | |||
248 | ,m_aContextMenuInterceptors( getMutex() ) | |||
249 | ,m_pSubComponentManager( new SubComponentManager( *this, getSharedMutex() ) ) | |||
250 | ,m_aTypeCollection( _rxORB ) | |||
251 | ,m_aTableCopyHelper(this) | |||
252 | ,m_nAsyncDrop(nullptr) | |||
253 | ,m_aSelectContainerEvent( LINK( this, OApplicationController, OnSelectContainer )::tools::detail::makeLink( ::tools::detail::castTo<OApplicationController *>(this), &OApplicationController::LinkStubOnSelectContainer ) ) | |||
254 | ,m_ePreviewMode(E_PREVIEWNONE) | |||
255 | ,m_eCurrentType(E_NONE) | |||
256 | ,m_bNeedToReconnect(false) | |||
257 | ,m_bSuspended( false ) | |||
258 | ,m_pSelectionNotifier( new SelectionNotifier( getMutex(), *this ) ) | |||
259 | { | |||
260 | } | |||
261 | ||||
262 | OApplicationController::~OApplicationController() | |||
263 | { | |||
264 | if ( !rBHelper.bDisposed && !rBHelper.bInDispose ) | |||
265 | { | |||
266 | OSL_FAIL("Please check who doesn't dispose this component!")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "266" ": "), "%s", "Please check who doesn't dispose this component!" ); } } while (false); | |||
267 | // increment ref count to prevent double call of Dtor | |||
268 | osl_atomic_increment( &m_refCount )__sync_add_and_fetch((&m_refCount), 1); | |||
269 | dispose(); | |||
270 | } | |||
271 | clearView(); | |||
272 | } | |||
273 | ||||
274 | IMPLEMENT_FORWARD_XTYPEPROVIDER2(OApplicationController,OGenericUnoController,OApplicationController_Base)css::uno::Sequence< css::uno::Type > OApplicationController ::getTypes( ) { return ::comphelper::concatSequences( OGenericUnoController ::getTypes(), OApplicationController_Base::getTypes() ); } css ::uno::Sequence< sal_Int8 > OApplicationController::getImplementationId ( ) { return css::uno::Sequence<sal_Int8>(); } | |||
275 | IMPLEMENT_FORWARD_XINTERFACE2(OApplicationController,OGenericUnoController,OApplicationController_Base)void OApplicationController::acquire() throw() { OGenericUnoController ::acquire(); } void OApplicationController::release() throw() { OGenericUnoController::release(); } css::uno::Any OApplicationController ::queryInterface( const css::uno::Type& _rType ) { css::uno ::Any aReturn = OGenericUnoController::queryInterface( _rType ); if ( !aReturn.hasValue() ) aReturn = OApplicationController_Base ::queryInterface( _rType ); return aReturn; } | |||
276 | void OApplicationController::disconnect() | |||
277 | { | |||
278 | if ( m_xDataSourceConnection.is() ) | |||
279 | stopConnectionListening( m_xDataSourceConnection ); | |||
280 | ||||
281 | try | |||
282 | { | |||
283 | // temporary (hopefully!) hack for #i55274# | |||
284 | Reference< XFlushable > xFlush( m_xDataSourceConnection, UNO_QUERY ); | |||
285 | if ( xFlush.is() && m_xMetaData.is() && !m_xMetaData->isReadOnly() ) | |||
286 | xFlush->flush(); | |||
287 | } | |||
288 | catch( const Exception& ) | |||
289 | { | |||
290 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "290" ": ", "dbaccess" );; | |||
291 | } | |||
292 | ||||
293 | m_xDataSourceConnection.clear(); | |||
294 | m_xMetaData.clear(); | |||
295 | ||||
296 | InvalidateAll(); | |||
297 | } | |||
298 | ||||
299 | void SAL_CALL OApplicationController::disposing() | |||
300 | { | |||
301 | for( const auto& rContainerListener : m_aCurrentContainers ) | |||
302 | { | |||
303 | if( rContainerListener.is() ) | |||
304 | { | |||
305 | rContainerListener->removeContainerListener( this ); | |||
306 | } | |||
307 | } | |||
308 | ||||
309 | m_aCurrentContainers.clear(); | |||
310 | m_pSubComponentManager->disposing(); | |||
311 | m_pSelectionNotifier->disposing(); | |||
312 | ||||
313 | if ( getView() ) | |||
314 | { | |||
315 | getContainer()->showPreview(nullptr); | |||
316 | m_pClipboardNotifier->ClearCallbackLink(); | |||
317 | m_pClipboardNotifier->RemoveListener( getView() ); | |||
318 | m_pClipboardNotifier.clear(); | |||
319 | } | |||
320 | ||||
321 | disconnect(); | |||
322 | try | |||
323 | { | |||
324 | Reference < XFrame > xFrame; | |||
325 | attachFrame( xFrame ); | |||
326 | ||||
327 | if ( m_xDataSource.is() ) | |||
328 | { | |||
329 | m_xDataSource->removePropertyChangeListener(OUString(), this); | |||
330 | m_xDataSource->removePropertyChangeListener(PROPERTY_INFO"Info", this); | |||
331 | m_xDataSource->removePropertyChangeListener(PROPERTY_URL"URL", this); | |||
332 | m_xDataSource->removePropertyChangeListener(PROPERTY_ISPASSWORDREQUIRED"IsPasswordRequired", this); | |||
333 | m_xDataSource->removePropertyChangeListener(PROPERTY_LAYOUTINFORMATION"LayoutInformation", this); | |||
334 | m_xDataSource->removePropertyChangeListener(PROPERTY_SUPPRESSVERSIONCL"SuppressVersionColumns", this); | |||
335 | m_xDataSource->removePropertyChangeListener(PROPERTY_TABLEFILTER"TableFilter", this); | |||
336 | m_xDataSource->removePropertyChangeListener(PROPERTY_TABLETYPEFILTER"TableTypeFilter", this); | |||
337 | m_xDataSource->removePropertyChangeListener(PROPERTY_USER"User", this); | |||
338 | m_xDataSource = nullptr; | |||
339 | } | |||
340 | ||||
341 | Reference< XModifyBroadcaster > xBroadcaster( m_xModel, UNO_QUERY ); | |||
342 | if ( xBroadcaster.is() ) | |||
343 | xBroadcaster->removeModifyListener(static_cast<XModifyListener*>(this)); | |||
344 | ||||
345 | if ( m_xModel.is() ) | |||
346 | { | |||
347 | OUString sUrl = m_xModel->getURL(); | |||
348 | if ( !sUrl.isEmpty() ) | |||
349 | { | |||
350 | ::comphelper::NamedValueCollection aArgs( m_xModel->getArgs() ); | |||
351 | if ( aArgs.getOrDefault( "PickListEntry", true ) ) | |||
352 | { | |||
353 | OUString aFilter; | |||
354 | INetURLObject aURL( m_xModel->getURL() ); | |||
355 | std::shared_ptr<const SfxFilter> pFilter = getStandardDatabaseFilter(); | |||
356 | if ( pFilter ) | |||
357 | aFilter = pFilter->GetFilterName(); | |||
358 | ||||
359 | // add to svtool history options | |||
360 | SvtHistoryOptions().AppendItem( ePICKLIST, | |||
361 | aURL.GetURLNoPass( INetURLObject::DecodeMechanism::NONE ), | |||
362 | aFilter, | |||
363 | getStrippedDatabaseName(), | |||
364 | std::nullopt); | |||
365 | ||||
366 | // add to recent document list | |||
367 | if ( aURL.GetProtocol() == INetProtocol::File ) | |||
368 | Application::AddToRecentDocumentList( aURL.GetURLNoPass( INetURLObject::DecodeMechanism::NONE ), | |||
369 | pFilter ? pFilter->GetMimeType() : OUString(), | |||
370 | pFilter ? pFilter->GetServiceName() : OUString() ); | |||
371 | } | |||
372 | } | |||
373 | ||||
374 | m_xModel->disconnectController( this ); | |||
375 | ||||
376 | m_xModel.clear(); | |||
377 | } | |||
378 | } | |||
379 | catch(const Exception&) | |||
380 | { | |||
381 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "381" ": ", "dbaccess" );; | |||
382 | } | |||
383 | ||||
384 | clearView(); | |||
385 | OGenericUnoController::disposing(); // here the m_refCount must be equal 5 | |||
386 | } | |||
387 | ||||
388 | bool OApplicationController::Construct(vcl::Window* _pParent) | |||
389 | { | |||
390 | setView( VclPtr<OApplicationView>::Create( _pParent, getORB(), *this, m_ePreviewMode ) ); | |||
| ||||
391 | ||||
392 | // late construction | |||
393 | bool bSuccess = false; | |||
394 | try | |||
395 | { | |||
396 | getContainer()->Construct(); | |||
397 | bSuccess = true; | |||
398 | } | |||
399 | catch(const SQLException&) | |||
400 | { | |||
401 | } | |||
402 | catch(const Exception&) | |||
403 | { | |||
404 | OSL_FAIL("OApplicationController::Construct : the construction of UnoDataBrowserView failed !")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "404" ": "), "%s", "OApplicationController::Construct : the construction of UnoDataBrowserView failed !" ); } } while (false); | |||
405 | } | |||
406 | ||||
407 | if ( !bSuccess ) | |||
408 | { | |||
409 | clearView(); | |||
410 | return false; | |||
411 | } | |||
412 | ||||
413 | // now that we have a view we can create the clipboard listener | |||
414 | m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() ); | |||
415 | m_aSystemClipboard.StartClipboardListening( ); | |||
416 | ||||
417 | m_pClipboardNotifier = new TransferableClipboardListener( LINK( this, OApplicationController, OnClipboardChanged )::tools::detail::makeLink( ::tools::detail::castTo<OApplicationController *>(this), &OApplicationController::LinkStubOnClipboardChanged ) ); | |||
418 | m_pClipboardNotifier->AddListener( getView() ); | |||
419 | ||||
420 | OGenericUnoController::Construct( _pParent ); | |||
421 | getView()->Show(); | |||
422 | ||||
423 | return true; | |||
424 | } | |||
425 | ||||
426 | void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) | |||
427 | { | |||
428 | ::osl::MutexGuard aGuard( getMutex() ); | |||
429 | Reference<XConnection> xCon(_rSource.Source, UNO_QUERY); | |||
430 | if ( xCon.is() ) | |||
431 | { | |||
432 | OSL_ENSURE( m_xDataSourceConnection == xCon,do { if (true && (!(m_xDataSourceConnection == xCon)) ) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "433" ": "), "%s", "OApplicationController::disposing: which connection does this come from?" ); } } while (false) | |||
433 | "OApplicationController::disposing: which connection does this come from?" )do { if (true && (!(m_xDataSourceConnection == xCon)) ) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "433" ": "), "%s", "OApplicationController::disposing: which connection does this come from?" ); } } while (false); | |||
434 | ||||
435 | if ( getContainer() && getContainer()->getElementType() == E_TABLE ) | |||
436 | getContainer()->clearPages(); | |||
437 | if ( m_xDataSourceConnection == xCon ) | |||
438 | { | |||
439 | m_xMetaData.clear(); | |||
440 | m_xDataSourceConnection.clear(); | |||
441 | } | |||
442 | } | |||
443 | else if ( _rSource.Source == m_xModel ) | |||
444 | { | |||
445 | m_xModel.clear(); | |||
446 | } | |||
447 | else if ( _rSource.Source == m_xDataSource ) | |||
448 | { | |||
449 | m_xDataSource = nullptr; | |||
450 | } | |||
451 | else | |||
452 | { | |||
453 | Reference<XContainer> xContainer( _rSource.Source, UNO_QUERY ); | |||
454 | if ( xContainer.is() ) | |||
455 | { | |||
456 | TContainerVector::iterator aFind = std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer); | |||
457 | if ( aFind != m_aCurrentContainers.end() ) | |||
458 | m_aCurrentContainers.erase(aFind); | |||
459 | } | |||
460 | OGenericUnoController::disposing( _rSource ); | |||
461 | } | |||
462 | } | |||
463 | ||||
464 | sal_Bool SAL_CALL OApplicationController::suspend(sal_Bool bSuspend) | |||
465 | { | |||
466 | // notify the OnPrepareViewClosing event (before locking any mutex) | |||
467 | Reference< XDocumentEventBroadcaster > xBroadcaster( m_xModel, UNO_QUERY ); | |||
468 | if ( xBroadcaster.is() ) | |||
469 | { | |||
470 | xBroadcaster->notifyDocumentEvent( | |||
471 | "OnPrepareViewClosing", | |||
472 | this, | |||
473 | Any() | |||
474 | ); | |||
475 | } | |||
476 | ||||
477 | SolarMutexGuard aSolarGuard; | |||
478 | ::osl::MutexGuard aGuard( getMutex() ); | |||
479 | ||||
480 | if ( getView() && getView()->IsInModalMode() ) | |||
481 | return false; | |||
482 | ||||
483 | bool bCanSuspend = true; | |||
484 | ||||
485 | if ( m_bSuspended != bool(bSuspend) ) | |||
486 | { | |||
487 | if ( bSuspend && !closeSubComponents() ) | |||
488 | return false; | |||
489 | ||||
490 | Reference<XModifiable> xModi(m_xModel,UNO_QUERY); | |||
491 | Reference<XStorable> xStor(getModel(),UNO_QUERY); | |||
492 | ||||
493 | if ( bSuspend | |||
494 | && xStor.is() | |||
495 | && !xStor->isReadonly() | |||
496 | && ( xModi.is() | |||
497 | && xModi->isModified() | |||
498 | ) | |||
499 | ) | |||
500 | { | |||
501 | switch (ExecuteQuerySaveDocument(getFrameWeld(), getStrippedDatabaseName())) | |||
502 | { | |||
503 | case RET_YES: | |||
504 | Execute(ID_BROWSER_SAVEDOC(5000 + 505),Sequence<PropertyValue>()); | |||
505 | bCanSuspend = !xModi->isModified(); | |||
506 | // when we save the document this must be false else some press cancel | |||
507 | break; | |||
508 | case RET_CANCEL: | |||
509 | bCanSuspend = false; | |||
510 | break; | |||
511 | default: | |||
512 | break; | |||
513 | } | |||
514 | } | |||
515 | } | |||
516 | ||||
517 | if ( bCanSuspend ) | |||
518 | m_bSuspended = bSuspend; | |||
519 | ||||
520 | return bCanSuspend; | |||
521 | } | |||
522 | ||||
523 | FeatureState OApplicationController::GetState(sal_uInt16 _nId) const | |||
524 | { | |||
525 | FeatureState aReturn; | |||
526 | aReturn.bEnabled = false; | |||
527 | // check this first | |||
528 | if ( !getContainer() || m_bReadOnly ) | |||
529 | return aReturn; | |||
530 | ||||
531 | try | |||
532 | { | |||
533 | switch (_nId) | |||
534 | { | |||
535 | case SID_NEWDOCDIRECT(5000 + 537): | |||
536 | aReturn.bEnabled = true; | |||
537 | aReturn.sTitle = "private:factory/sdatabase"; | |||
538 | break; | |||
539 | case SID_OPENURL(5000 + 596): | |||
540 | aReturn.bEnabled = true; | |||
541 | if ( m_xModel.is() ) | |||
542 | aReturn.sTitle = m_xModel->getURL(); | |||
543 | break; | |||
544 | case ID_BROWSER_COPY(5000 + 711): | |||
545 | { | |||
546 | sal_Int32 nCount = getContainer()->getSelectionCount(); | |||
547 | aReturn.bEnabled = nCount >= 1; | |||
548 | if ( aReturn.bEnabled && nCount == 1 && getContainer()->getElementType() == E_TABLE ) | |||
549 | aReturn.bEnabled = getContainer()->isALeafSelected(); | |||
550 | } | |||
551 | break; | |||
552 | case ID_BROWSER_CUT(5000 + 710): | |||
553 | aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() >= 1; | |||
554 | aReturn.bEnabled = aReturn.bEnabled && (getContainer()->getElementType() != E_TABLE || getContainer()->isCutAllowed()); | |||
555 | break; | |||
556 | case ID_BROWSER_PASTE(5000 + 712): | |||
557 | switch( getContainer()->getElementType() ) | |||
558 | { | |||
559 | case E_TABLE: | |||
560 | aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat(); | |||
561 | break; | |||
562 | case E_QUERY: | |||
563 | aReturn.bEnabled = !isDataSourceReadOnly() && getViewClipboard().HasFormat(SotClipboardFormatId::DBACCESS_QUERY); | |||
564 | break; | |||
565 | default: | |||
566 | aReturn.bEnabled = !isDataSourceReadOnly() && OComponentTransferable::canExtractComponentDescriptor(getViewClipboard().GetDataFlavorExVector(),getContainer()->getElementType() == E_FORM); | |||
567 | } | |||
568 | break; | |||
569 | case SID_DB_APP_PASTE_SPECIAL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 55 ): | |||
570 | aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat(); | |||
571 | break; | |||
572 | case SID_OPENDOC(5000 + 501): | |||
573 | aReturn.bEnabled = true; | |||
574 | break; | |||
575 | case ID_BROWSER_SAVEDOC(5000 + 505): | |||
576 | aReturn.bEnabled = !isDataSourceReadOnly(); | |||
577 | break; | |||
578 | case ID_BROWSER_SAVEASDOC(5000 + 502): | |||
579 | aReturn.bEnabled = true; | |||
580 | break; | |||
581 | case ID_BROWSER_SORTUP( 10000 + 712 ): | |||
582 | aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount(); | |||
583 | aReturn.bChecked = aReturn.bEnabled && getContainer()->isSortUp(); | |||
584 | break; | |||
585 | case ID_BROWSER_SORTDOWN( 10000 + 713 ): | |||
586 | aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount(); | |||
587 | aReturn.bChecked = aReturn.bEnabled && !getContainer()->isSortUp(); | |||
588 | break; | |||
589 | ||||
590 | case SID_NEWDOC(5000 + 500): | |||
591 | case SID_APP_NEW_FORM( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 54 ): | |||
592 | case ID_DOCUMENT_CREATE_REPWIZ41: | |||
593 | aReturn.bEnabled = !isDataSourceReadOnly() && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::WRITER); | |||
594 | break; | |||
595 | case SID_APP_NEW_REPORT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 65 ): | |||
596 | aReturn.bEnabled = !isDataSourceReadOnly() | |||
597 | && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::WRITER); | |||
598 | if ( aReturn.bEnabled ) | |||
599 | { | |||
600 | Reference< XContentEnumerationAccess > xEnumAccess(m_xContext->getServiceManager(), UNO_QUERY); | |||
601 | aReturn.bEnabled = xEnumAccess.is(); | |||
602 | if ( aReturn.bEnabled ) | |||
603 | { | |||
604 | const OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_xContext); | |||
605 | aReturn.bEnabled = !sReportEngineServiceName.isEmpty(); | |||
606 | if ( aReturn.bEnabled ) | |||
607 | { | |||
608 | const Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName); | |||
609 | aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements(); | |||
610 | } | |||
611 | } | |||
612 | } | |||
613 | break; | |||
614 | case SID_DB_APP_VIEW_TABLES( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 9 ): | |||
615 | aReturn.bEnabled = true; | |||
616 | aReturn.bChecked = getContainer()->getElementType() == E_TABLE; | |||
617 | break; | |||
618 | case SID_DB_APP_VIEW_QUERIES( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 10 ): | |||
619 | aReturn.bEnabled = true; | |||
620 | aReturn.bChecked = getContainer()->getElementType() == E_QUERY; | |||
621 | break; | |||
622 | case SID_DB_APP_VIEW_FORMS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 12 ): | |||
623 | aReturn.bEnabled = true; | |||
624 | aReturn.bChecked = getContainer()->getElementType() == E_FORM; | |||
625 | break; | |||
626 | case SID_DB_APP_VIEW_REPORTS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 22 ): | |||
627 | aReturn.bEnabled = true; | |||
628 | aReturn.bChecked = getContainer()->getElementType() == E_REPORT; | |||
629 | break; | |||
630 | case ID_NEW_QUERY_DESIGN20: | |||
631 | case ID_NEW_QUERY_SQL22: | |||
632 | case ID_APP_NEW_QUERY_AUTO_PILOT44: | |||
633 | case SID_DB_FORM_NEW_PILOT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 63 ): | |||
634 | aReturn.bEnabled = !isDataSourceReadOnly(); | |||
635 | break; | |||
636 | case ID_NEW_VIEW_DESIGN28: | |||
637 | case SID_DB_NEW_VIEW_SQL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 64 ): | |||
638 | case ID_NEW_VIEW_DESIGN_AUTO_PILOT46: | |||
639 | aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly(); | |||
640 | if ( aReturn.bEnabled ) | |||
641 | { | |||
642 | Reference<XViewsSupplier> xViewsSup( getConnection(), UNO_QUERY ); | |||
643 | aReturn.bEnabled = xViewsSup.is(); | |||
644 | } | |||
645 | break; | |||
646 | case ID_NEW_TABLE_DESIGN25: | |||
647 | case ID_NEW_TABLE_DESIGN_AUTO_PILOT45: | |||
648 | aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly(); | |||
649 | break; | |||
650 | case ID_DIRECT_SQL32: | |||
651 | aReturn.bEnabled = true; | |||
652 | break; | |||
653 | case SID_APP_NEW_FOLDER( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 53 ): | |||
654 | aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() <= 1; | |||
655 | if ( aReturn.bEnabled ) | |||
656 | { | |||
657 | const ElementType eType = getContainer()->getElementType(); | |||
658 | aReturn.bEnabled = eType == E_REPORT || eType == E_FORM; | |||
659 | } | |||
660 | break; | |||
661 | case SID_FORM_CREATE_REPWIZ_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 50 ): | |||
662 | case SID_REPORT_CREATE_REPWIZ_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 51 ): | |||
663 | case SID_APP_NEW_REPORT_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 19 ): | |||
664 | aReturn.bEnabled = !isDataSourceReadOnly() | |||
665 | && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::WRITER) | |||
666 | && getContainer()->isALeafSelected(); | |||
667 | if ( aReturn.bEnabled ) | |||
668 | { | |||
669 | ElementType eType = getContainer()->getElementType(); | |||
670 | aReturn.bEnabled = eType == E_QUERY || eType == E_TABLE; | |||
671 | if ( aReturn.bEnabled && SID_APP_NEW_REPORT_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 19 ) == _nId ) | |||
672 | { | |||
673 | Reference< XContentEnumerationAccess > xEnumAccess(m_xContext->getServiceManager(), UNO_QUERY); | |||
674 | aReturn.bEnabled = xEnumAccess.is(); | |||
675 | if ( aReturn.bEnabled ) | |||
676 | { | |||
677 | static const char s_sReportDesign[] = "org.libreoffice.report.pentaho.SOReportJobFactory"; | |||
678 | Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(s_sReportDesign); | |||
679 | aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements(); | |||
680 | } | |||
681 | } | |||
682 | } | |||
683 | break; | |||
684 | case SID_DB_APP_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 40 ): | |||
685 | case SID_DB_APP_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 41 ): | |||
686 | aReturn.bEnabled = isRenameDeleteAllowed(getContainer()->getElementType(), _nId == SID_DB_APP_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 40 )); | |||
687 | break; | |||
688 | case SID_DB_APP_TABLE_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 24 ): | |||
689 | case SID_DB_APP_TABLE_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 25 ): | |||
690 | aReturn.bEnabled = isRenameDeleteAllowed(E_TABLE, _nId == SID_DB_APP_TABLE_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 24 )); | |||
691 | break; | |||
692 | case SID_DB_APP_QUERY_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 28 ): | |||
693 | case SID_DB_APP_QUERY_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 29 ): | |||
694 | aReturn.bEnabled = isRenameDeleteAllowed(E_QUERY, _nId == SID_DB_APP_QUERY_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 28 )); | |||
695 | break; | |||
696 | case SID_DB_APP_FORM_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 32 ): | |||
697 | case SID_DB_APP_FORM_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 33 ): | |||
698 | aReturn.bEnabled = isRenameDeleteAllowed(E_FORM, _nId == SID_DB_APP_FORM_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 32 )); | |||
699 | break; | |||
700 | case SID_DB_APP_REPORT_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 36 ): | |||
701 | case SID_DB_APP_REPORT_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 37 ): | |||
702 | aReturn.bEnabled = isRenameDeleteAllowed(E_REPORT, _nId == SID_DB_APP_REPORT_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 36 )); | |||
703 | break; | |||
704 | ||||
705 | case SID_SELECTALL(5000 + 723): | |||
706 | aReturn.bEnabled = getContainer()->getElementCount() > 0 && getContainer()->getSelectionCount() != getContainer()->getElementCount(); | |||
707 | break; | |||
708 | case SID_DB_APP_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 42 ): | |||
709 | case SID_DB_APP_TABLE_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 26 ): | |||
710 | case SID_DB_APP_QUERY_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 30 ): | |||
711 | case SID_DB_APP_FORM_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 34 ): | |||
712 | case SID_DB_APP_REPORT_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 38 ): | |||
713 | aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() > 0 | |||
714 | && getContainer()->isALeafSelected(); | |||
715 | break; | |||
716 | case SID_DB_APP_EDIT_SQL_VIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 66 ): | |||
717 | if ( isDataSourceReadOnly() ) | |||
718 | aReturn.bEnabled = false; | |||
719 | else | |||
720 | { | |||
721 | switch ( getContainer()->getElementType() ) | |||
722 | { | |||
723 | case E_QUERY: | |||
724 | aReturn.bEnabled = ( getContainer()->getSelectionCount() > 0 ) | |||
725 | && ( getContainer()->isALeafSelected() ); | |||
726 | break; | |||
727 | case E_TABLE: | |||
728 | aReturn.bEnabled = false; | |||
729 | // there's one exception: views which support altering their underlying | |||
730 | // command can be edited in SQL view, too | |||
731 | if ( ( getContainer()->getSelectionCount() > 0 ) | |||
732 | && ( getContainer()->isALeafSelected() ) | |||
733 | ) | |||
734 | { | |||
735 | std::vector< OUString > aSelected; | |||
736 | getSelectionElementNames( aSelected ); | |||
737 | bool bAlterableViews = true; | |||
738 | for (auto const& selectedName : aSelected) | |||
739 | { | |||
740 | bAlterableViews &= impl_isAlterableView_nothrow(selectedName); | |||
741 | if (!bAlterableViews) | |||
742 | break; | |||
743 | } | |||
744 | aReturn.bEnabled = bAlterableViews; | |||
745 | } | |||
746 | break; | |||
747 | default: | |||
748 | break; | |||
749 | } | |||
750 | } | |||
751 | break; | |||
752 | case SID_DB_APP_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 43 ): | |||
753 | case SID_DB_APP_TABLE_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 27 ): | |||
754 | case SID_DB_APP_QUERY_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 31 ): | |||
755 | case SID_DB_APP_FORM_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 35 ): | |||
756 | case SID_DB_APP_REPORT_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 39 ): | |||
757 | aReturn.bEnabled = getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected(); | |||
758 | break; | |||
759 | case SID_DB_APP_DSUSERADMIN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 14 ): | |||
760 | aReturn.bEnabled = !dbaccess::ODsnTypeCollection::isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL"URL"))); | |||
761 | break; | |||
762 | case SID_DB_APP_DSRELDESIGN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 13 ): | |||
763 | aReturn.bEnabled = true; | |||
764 | break; | |||
765 | case SID_DB_APP_TABLEFILTER( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 15 ): | |||
766 | aReturn.bEnabled = !isDataSourceReadOnly(); | |||
767 | break; | |||
768 | case SID_DB_APP_REFRESH_TABLES( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 21 ): | |||
769 | aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && isConnected(); | |||
770 | break; | |||
771 | case SID_DB_APP_DSPROPS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 17 ): | |||
772 | aReturn.bEnabled = m_xDataSource.is() && dbaccess::ODsnTypeCollection::isShowPropertiesEnabled(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL"URL"))); | |||
773 | break; | |||
774 | case SID_DB_APP_DSCONNECTION_TYPE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 4 ): | |||
775 | aReturn.bEnabled = !isDataSourceReadOnly() && m_xDataSource.is() && !dbaccess::ODsnTypeCollection::isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL"URL"))); | |||
776 | break; | |||
777 | case SID_DB_APP_DSADVANCED_SETTINGS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 5 ): | |||
778 | aReturn.bEnabled = m_xDataSource.is() && AdvancedSettingsDialog::doesHaveAnyAdvancedSettings( m_aTypeCollection.getType(::comphelper::getString( m_xDataSource->getPropertyValue( PROPERTY_URL"URL" ) )) ); | |||
779 | break; | |||
780 | case SID_DB_APP_CONVERTTOVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 20 ): | |||
781 | aReturn.bEnabled = !isDataSourceReadOnly(); | |||
782 | if ( aReturn.bEnabled ) | |||
783 | { | |||
784 | ElementType eType = getContainer()->getElementType(); | |||
785 | aReturn.bEnabled = eType == E_QUERY && getContainer()->getSelectionCount() > 0; | |||
786 | if ( aReturn.bEnabled ) | |||
787 | { | |||
788 | Reference<XViewsSupplier> xViewSup( getConnection(), UNO_QUERY ); | |||
789 | aReturn.bEnabled = xViewSup.is() && Reference<XAppend>(xViewSup->getViews(),UNO_QUERY).is(); | |||
790 | } | |||
791 | } | |||
792 | break; | |||
793 | case SID_DB_APP_DISABLE_PREVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 3 ): | |||
794 | aReturn.bEnabled = true; | |||
795 | aReturn.bChecked = getContainer()->getPreviewMode() == E_PREVIEWNONE; | |||
796 | break; | |||
797 | case SID_DB_APP_VIEW_DOCINFO_PREVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 7 ): | |||
798 | { | |||
799 | ElementType eType = getContainer()->getElementType(); | |||
800 | aReturn.bEnabled = (E_REPORT == eType || E_FORM == eType); | |||
801 | aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENTINFO; | |||
802 | } | |||
803 | break; | |||
804 | case SID_DB_APP_VIEW_DOC_PREVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 8 ): | |||
805 | aReturn.bEnabled = true; | |||
806 | aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENT; | |||
807 | break; | |||
808 | case ID_BROWSER_UNDO(5000 + 701): | |||
809 | aReturn.bEnabled = false; | |||
810 | break; | |||
811 | case SID_MAIL_SENDDOC(5000 + 331): | |||
812 | aReturn.bEnabled = true; | |||
813 | break; | |||
814 | case SID_DB_APP_SENDREPORTASMAIL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 61 ): | |||
815 | { | |||
816 | ElementType eType = getContainer()->getElementType(); | |||
817 | aReturn.bEnabled = E_REPORT == eType && getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected(); | |||
818 | } | |||
819 | break; | |||
820 | case SID_DB_APP_SENDREPORTTOWRITER( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 62 ): | |||
821 | case SID_DB_APP_DBADMIN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 18 ): | |||
822 | aReturn.bEnabled = false; | |||
823 | break; | |||
824 | case SID_DB_APP_STATUS_TYPE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 57 ): | |||
825 | aReturn.bEnabled = m_xDataSource.is(); | |||
826 | if ( aReturn.bEnabled ) | |||
827 | { | |||
828 | OUString sURL; | |||
829 | m_xDataSource->getPropertyValue(PROPERTY_URL"URL") >>= sURL; | |||
830 | OUString sDSTypeName; | |||
831 | if ( dbaccess::ODsnTypeCollection::isEmbeddedDatabase( sURL ) ) | |||
832 | { | |||
833 | sDSTypeName = DBA_RES(RID_STR_EMBEDDED_DATABASE)::dbaccess::ResourceManager::loadString( reinterpret_cast< char const *>("RID_STR_EMBEDDED_DATABASE" "\004" u8"Embedded database" ) ); | |||
834 | } | |||
835 | else | |||
836 | { | |||
837 | sDSTypeName = m_aTypeCollection.getTypeDisplayName(sURL); | |||
838 | } | |||
839 | aReturn.sTitle = sDSTypeName; | |||
840 | } | |||
841 | break; | |||
842 | case SID_DB_APP_STATUS_DBNAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 58 ): | |||
843 | aReturn.bEnabled = m_xDataSource.is(); | |||
844 | if ( aReturn.bEnabled ) | |||
845 | { | |||
846 | OUString sURL; | |||
847 | m_xDataSource->getPropertyValue(PROPERTY_URL"URL") >>= sURL; | |||
848 | OUString sDatabaseName; | |||
849 | OUString sHostName; | |||
850 | sal_Int32 nPortNumber( -1 ); | |||
851 | ||||
852 | m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber ); | |||
853 | ||||
854 | if ( sDatabaseName.isEmpty() ) | |||
855 | sDatabaseName = m_aTypeCollection.cutPrefix( sURL ); | |||
856 | if ( m_aTypeCollection.isFileSystemBased(sURL) ) | |||
857 | { | |||
858 | sDatabaseName = SvtPathOptions().SubstituteVariable( sDatabaseName ); | |||
859 | if ( !sDatabaseName.isEmpty() ) | |||
860 | { | |||
861 | ::svt::OFileNotation aFileNotation(sDatabaseName); | |||
862 | // set this decoded URL as text | |||
863 | sDatabaseName = aFileNotation.get(::svt::OFileNotation::N_SYSTEM); | |||
864 | } | |||
865 | } | |||
866 | ||||
867 | if ( sDatabaseName.isEmpty() ) | |||
868 | sDatabaseName = m_aTypeCollection.getTypeDisplayName( sURL ); | |||
869 | ||||
870 | aReturn.sTitle = sDatabaseName; | |||
871 | } | |||
872 | break; | |||
873 | case SID_DB_APP_STATUS_USERNAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 59 ): | |||
874 | aReturn.bEnabled = m_xDataSource.is(); | |||
875 | if ( aReturn.bEnabled ) | |||
876 | m_xDataSource->getPropertyValue( PROPERTY_USER"User" ) >>= aReturn.sTitle; | |||
877 | break; | |||
878 | case SID_DB_APP_STATUS_HOSTNAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 60 ): | |||
879 | aReturn.bEnabled = m_xDataSource.is(); | |||
880 | if ( aReturn.bEnabled ) | |||
881 | { | |||
882 | OUString sURL; | |||
883 | m_xDataSource->getPropertyValue( PROPERTY_URL"URL" ) >>= sURL; | |||
884 | ||||
885 | OUString sHostName, sDatabaseName; | |||
886 | sal_Int32 nPortNumber = -1; | |||
887 | m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber ); | |||
888 | aReturn.sTitle = sHostName; | |||
889 | } | |||
890 | break; | |||
891 | default: | |||
892 | aReturn = OGenericUnoController::GetState(_nId); | |||
893 | } | |||
894 | } | |||
895 | catch(const Exception& ) | |||
896 | { | |||
897 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "897" ": ", "dbaccess" );; | |||
898 | } | |||
899 | return aReturn; | |||
900 | } | |||
901 | ||||
902 | namespace | |||
903 | { | |||
904 | bool lcl_handleException_nothrow( const Reference< XModel >& _rxDocument, const Any& _rException ) | |||
905 | { | |||
906 | bool bHandled = false; | |||
907 | ||||
908 | // try handling the error with an interaction handler | |||
909 | ::comphelper::NamedValueCollection aArgs( _rxDocument->getArgs() ); | |||
910 | Reference< XInteractionHandler > xHandler( aArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) ); | |||
911 | if ( xHandler.is() ) | |||
912 | { | |||
913 | rtl::Reference pRequest( new ::comphelper::OInteractionRequest( _rException ) ); | |||
914 | rtl::Reference pApprove( new ::comphelper::OInteractionApprove ); | |||
915 | pRequest->addContinuation( pApprove.get() ); | |||
916 | ||||
917 | try | |||
918 | { | |||
919 | xHandler->handle( pRequest.get() ); | |||
920 | } | |||
921 | catch( const Exception& ) | |||
922 | { | |||
923 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "923" ": ", "dbaccess" );; | |||
924 | } | |||
925 | ||||
926 | bHandled = pApprove->wasSelected(); | |||
927 | } | |||
928 | return bHandled; | |||
929 | } | |||
930 | } | |||
931 | ||||
932 | void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs) | |||
933 | { | |||
934 | SolarMutexGuard aSolarGuard; | |||
935 | ::osl::MutexGuard aGuard( getMutex() ); | |||
936 | ||||
937 | if ( isUserDefinedFeature( _nId ) ) | |||
938 | { | |||
939 | OGenericUnoController::Execute( _nId, aArgs ); | |||
940 | return; | |||
941 | } | |||
942 | ||||
943 | if ( !getContainer() || m_bReadOnly ) | |||
944 | return; // return without execution | |||
945 | ||||
946 | try | |||
947 | { | |||
948 | switch(_nId) | |||
949 | { | |||
950 | case ID_BROWSER_CUT(5000 + 710): | |||
951 | getContainer()->cut(); | |||
952 | break; | |||
953 | case ID_BROWSER_COPY(5000 + 711): | |||
954 | { | |||
955 | rtl::Reference<TransferableHelper> pTransfer = copyObject(); | |||
956 | if ( pTransfer ) | |||
957 | pTransfer->CopyToClipboard(getView()); | |||
958 | } | |||
959 | break; | |||
960 | case ID_BROWSER_PASTE(5000 + 712): | |||
961 | { | |||
962 | const TransferableDataHelper& rTransferData( getViewClipboard() ); | |||
963 | ElementType eType = getContainer()->getElementType(); | |||
964 | ||||
965 | switch( eType ) | |||
966 | { | |||
967 | case E_TABLE: | |||
968 | { | |||
969 | // get the selected tablename | |||
970 | std::vector< OUString > aList; | |||
971 | getSelectionElementNames( aList ); | |||
972 | if ( !aList.empty() ) | |||
973 | m_aTableCopyHelper.SetTableNameForAppend( *aList.begin() ); | |||
974 | else | |||
975 | m_aTableCopyHelper.ResetTableNameForAppend(); | |||
976 | ||||
977 | m_aTableCopyHelper.pasteTable( rTransferData , getDatabaseName(), ensureConnection() ); | |||
978 | } | |||
979 | break; | |||
980 | ||||
981 | case E_QUERY: | |||
982 | if ( rTransferData.HasFormat(SotClipboardFormatId::DBACCESS_QUERY) ) | |||
983 | paste( E_QUERY, ODataAccessObjectTransferable::extractObjectDescriptor( rTransferData ) ); | |||
984 | break; | |||
985 | default: | |||
986 | { | |||
987 | std::vector< OUString> aList; | |||
988 | getSelectionElementNames(aList); | |||
989 | OUString sFolderNameToInsertInto; | |||
990 | if ( !aList.empty() ) | |||
991 | { | |||
992 | Reference< XHierarchicalNameAccess > xContainer(getElements(eType),UNO_QUERY); | |||
993 | if ( xContainer.is() | |||
994 | && xContainer->hasByHierarchicalName(*aList.begin()) | |||
995 | && (xContainer->getByHierarchicalName(*aList.begin()) >>= xContainer) | |||
996 | && xContainer.is() | |||
997 | ) | |||
998 | sFolderNameToInsertInto = *aList.begin(); | |||
999 | } | |||
1000 | paste( eType, OComponentTransferable::extractComponentDescriptor( rTransferData ), | |||
1001 | sFolderNameToInsertInto ); | |||
1002 | } | |||
1003 | break; | |||
1004 | } | |||
1005 | } | |||
1006 | break; | |||
1007 | case SID_DB_APP_PASTE_SPECIAL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 55 ): | |||
1008 | { | |||
1009 | if ( !aArgs.hasElements() ) | |||
1010 | { | |||
1011 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); | |||
1012 | ScopedVclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog(getFrameWeld())); | |||
1013 | std::vector<SotClipboardFormatId> aFormatIds; | |||
1014 | getSupportedFormats(getContainer()->getElementType(),aFormatIds); | |||
1015 | for (auto const& formatId : aFormatIds) | |||
1016 | pDlg->Insert(formatId,""); | |||
1017 | ||||
1018 | const TransferableDataHelper& rClipboard = getViewClipboard(); | |||
1019 | pasteFormat(pDlg->GetFormat(rClipboard.GetTransferable())); | |||
1020 | } | |||
1021 | else | |||
1022 | { | |||
1023 | const PropertyValue* pIter = aArgs.getConstArray(); | |||
1024 | const PropertyValue* pEnd = pIter + aArgs.getLength(); | |||
1025 | for( ; pIter != pEnd ; ++pIter) | |||
1026 | { | |||
1027 | if ( pIter->Name == "FormatStringId" ) | |||
1028 | { | |||
1029 | sal_uLong nTmp; | |||
1030 | if ( pIter->Value >>= nTmp ) | |||
1031 | pasteFormat(static_cast<SotClipboardFormatId>(nTmp)); | |||
1032 | break; | |||
1033 | } | |||
1034 | } | |||
1035 | } | |||
1036 | } | |||
1037 | break; | |||
1038 | case SID_NEWDOCDIRECT(5000 + 537): | |||
1039 | case SID_OPENDOC(5000 + 501): | |||
1040 | { | |||
1041 | Reference < XDispatchProvider > xProv( getFrame(), UNO_QUERY ); | |||
1042 | if ( xProv.is() ) | |||
1043 | { | |||
1044 | URL aURL; | |||
1045 | OUString aTarget; | |||
1046 | if ( _nId == SID_NEWDOCDIRECT(5000 + 537) ) | |||
1047 | { | |||
1048 | aURL.Complete = "private:factory/sdatabase?Interactive"; | |||
1049 | aTarget = "_default"; | |||
1050 | } | |||
1051 | else | |||
1052 | aURL.Complete = ".uno:Open"; | |||
1053 | ||||
1054 | if ( m_xUrlTransformer.is() ) | |||
1055 | m_xUrlTransformer->parseStrict( aURL ); | |||
1056 | Reference < XDispatch > xDisp = xProv->queryDispatch( aURL, aTarget, 0 ); | |||
1057 | if ( xDisp.is() ) | |||
1058 | xDisp->dispatch( aURL, Sequence < PropertyValue >() ); | |||
1059 | } | |||
1060 | } | |||
1061 | break; | |||
1062 | case ID_BROWSER_SAVEDOC(5000 + 505): | |||
1063 | { | |||
1064 | Reference< XStorable > xStore( m_xModel, UNO_QUERY_THROW ); | |||
1065 | try | |||
1066 | { | |||
1067 | xStore->store(); | |||
1068 | } | |||
1069 | catch( const Exception& ) | |||
1070 | { | |||
1071 | lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() ); | |||
1072 | } | |||
1073 | } | |||
1074 | break; | |||
1075 | ||||
1076 | case ID_BROWSER_SAVEASDOC(5000 + 502): | |||
1077 | { | |||
1078 | OUString sUrl; | |||
1079 | if ( m_xModel.is() ) | |||
1080 | sUrl = m_xModel->getURL(); | |||
1081 | if ( sUrl.isEmpty() ) | |||
1082 | sUrl = SvtPathOptions().GetWorkPath(); | |||
1083 | ||||
1084 | ::sfx2::FileDialogHelper aFileDlg( | |||
1085 | ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION, | |||
1086 | FileDialogFlags::NONE, getFrameWeld()); | |||
1087 | aFileDlg.SetDisplayDirectory( sUrl ); | |||
1088 | ||||
1089 | std::shared_ptr<const SfxFilter> pFilter = getStandardDatabaseFilter(); | |||
1090 | if ( pFilter ) | |||
1091 | { | |||
1092 | aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension()); | |||
1093 | aFileDlg.SetCurrentFilter(pFilter->GetUIName()); | |||
1094 | } | |||
1095 | ||||
1096 | if ( aFileDlg.Execute() != ERRCODE_NONEErrCode(0) ) | |||
1097 | break; | |||
1098 | ||||
1099 | Reference<XStorable> xStore( m_xModel, UNO_QUERY_THROW ); | |||
1100 | INetURLObject aURL( aFileDlg.GetPath() ); | |||
1101 | try | |||
1102 | { | |||
1103 | xStore->storeAsURL( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), Sequence< PropertyValue >() ); | |||
1104 | } | |||
1105 | catch( const Exception& ) | |||
1106 | { | |||
1107 | lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() ); | |||
1108 | } | |||
1109 | ||||
1110 | /*updateTitle();*/ | |||
1111 | m_bCurrentlyModified = false; | |||
1112 | InvalidateFeature(ID_BROWSER_SAVEDOC(5000 + 505)); | |||
1113 | if ( getContainer()->getElementType() == E_NONE ) | |||
1114 | { | |||
1115 | getContainer()->selectContainer(E_NONE); | |||
1116 | getContainer()->selectContainer(E_TABLE); | |||
1117 | // #i95524# | |||
1118 | getContainer()->Invalidate(); | |||
1119 | refreshTables(); | |||
1120 | } | |||
1121 | ||||
1122 | } | |||
1123 | break; | |||
1124 | case ID_BROWSER_SORTUP( 10000 + 712 ): | |||
1125 | getContainer()->sortUp(); | |||
1126 | InvalidateFeature(ID_BROWSER_SORTDOWN( 10000 + 713 )); | |||
1127 | break; | |||
1128 | case ID_BROWSER_SORTDOWN( 10000 + 713 ): | |||
1129 | getContainer()->sortDown(); | |||
1130 | InvalidateFeature(ID_BROWSER_SORTUP( 10000 + 712 )); | |||
1131 | break; | |||
1132 | ||||
1133 | case ID_NEW_TABLE_DESIGN_AUTO_PILOT45: | |||
1134 | case ID_NEW_VIEW_DESIGN_AUTO_PILOT46: | |||
1135 | case ID_APP_NEW_QUERY_AUTO_PILOT44: | |||
1136 | case SID_DB_FORM_NEW_PILOT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 63 ): | |||
1137 | case SID_REPORT_CREATE_REPWIZ_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 51 ): | |||
1138 | case SID_APP_NEW_REPORT_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 19 ): | |||
1139 | case SID_FORM_CREATE_REPWIZ_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 50 ): | |||
1140 | case ID_DOCUMENT_CREATE_REPWIZ41: | |||
1141 | case SID_APP_NEW_FORM( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 54 ): | |||
1142 | case SID_APP_NEW_REPORT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 65 ): | |||
1143 | case ID_NEW_QUERY_SQL22: | |||
1144 | case ID_NEW_QUERY_DESIGN20: | |||
1145 | case ID_NEW_TABLE_DESIGN25: | |||
1146 | { | |||
1147 | ElementType eType = E_TABLE; | |||
1148 | bool bAutoPilot = false; | |||
1149 | ::comphelper::NamedValueCollection aCreationArgs; | |||
1150 | ||||
1151 | switch( _nId ) | |||
1152 | { | |||
1153 | case SID_DB_FORM_NEW_PILOT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 63 ): | |||
1154 | case SID_FORM_CREATE_REPWIZ_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 50 ): | |||
1155 | bAutoPilot = true; | |||
1156 | [[fallthrough]]; | |||
1157 | case SID_APP_NEW_FORM( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 54 ): | |||
1158 | eType = E_FORM; | |||
1159 | break; | |||
1160 | case ID_DOCUMENT_CREATE_REPWIZ41: | |||
1161 | case SID_REPORT_CREATE_REPWIZ_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 51 ): | |||
1162 | bAutoPilot = true; | |||
1163 | [[fallthrough]]; | |||
1164 | case SID_APP_NEW_REPORT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 65 ): | |||
1165 | case SID_APP_NEW_REPORT_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 19 ): | |||
1166 | eType = E_REPORT; | |||
1167 | break; | |||
1168 | case ID_APP_NEW_QUERY_AUTO_PILOT44: | |||
1169 | bAutoPilot = true; | |||
1170 | eType = E_QUERY; | |||
1171 | break; | |||
1172 | case ID_NEW_QUERY_DESIGN20: | |||
1173 | aCreationArgs.put( OUString(PROPERTY_GRAPHICAL_DESIGN"GraphicalDesign"), true ); | |||
1174 | [[fallthrough]]; | |||
1175 | case ID_NEW_QUERY_SQL22: | |||
1176 | eType = E_QUERY; | |||
1177 | break; | |||
1178 | case ID_NEW_TABLE_DESIGN_AUTO_PILOT45: | |||
1179 | bAutoPilot = true; | |||
1180 | [[fallthrough]]; | |||
1181 | case ID_NEW_TABLE_DESIGN25: | |||
1182 | break; | |||
1183 | default: | |||
1184 | OSL_FAIL("illegal switch call!")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1184" ": "), "%s", "illegal switch call!"); } } while ( false); | |||
1185 | } | |||
1186 | if ( bAutoPilot ) | |||
1187 | getContainer()->PostUserEvent( LINK( this, OApplicationController, OnCreateWithPilot )::tools::detail::makeLink( ::tools::detail::castTo<OApplicationController *>(this), &OApplicationController::LinkStubOnCreateWithPilot ), reinterpret_cast< void* >( eType ) ); | |||
1188 | else | |||
1189 | { | |||
1190 | Reference< XComponent > xDocDefinition; | |||
1191 | newElement( eType, aCreationArgs, xDocDefinition ); | |||
1192 | } | |||
1193 | } | |||
1194 | break; | |||
1195 | case SID_APP_NEW_FOLDER( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 53 ): | |||
1196 | { | |||
1197 | ElementType eType = getContainer()->getElementType(); | |||
1198 | OUString sName = getContainer()->getQualifiedName( nullptr ); | |||
1199 | insertHierachyElement(eType,sName); | |||
1200 | } | |||
1201 | break; | |||
1202 | case ID_NEW_VIEW_DESIGN28: | |||
1203 | case SID_DB_NEW_VIEW_SQL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 64 ): | |||
1204 | { | |||
1205 | SharedConnection xConnection( ensureConnection() ); | |||
1206 | if ( xConnection.is() ) | |||
1207 | { | |||
1208 | QueryDesigner aDesigner( getORB(), this, getFrame(), true ); | |||
1209 | ||||
1210 | ::comphelper::NamedValueCollection aCreationArgs; | |||
1211 | aCreationArgs.put( OUString(PROPERTY_GRAPHICAL_DESIGN"GraphicalDesign"), ID_NEW_VIEW_DESIGN28 == _nId ); | |||
1212 | ||||
1213 | const Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); | |||
1214 | const Reference< XComponent > xComponent = aDesigner.createNew( xDataSource, aCreationArgs ); | |||
1215 | onDocumentOpened( OUString(), E_QUERY, E_OPEN_DESIGN, xComponent, nullptr ); | |||
1216 | } | |||
1217 | } | |||
1218 | break; | |||
1219 | case SID_DB_APP_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 40 ): | |||
1220 | case SID_DB_APP_TABLE_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 24 ): | |||
1221 | case SID_DB_APP_QUERY_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 28 ): | |||
1222 | case SID_DB_APP_FORM_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 32 ): | |||
1223 | case SID_DB_APP_REPORT_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 36 ): | |||
1224 | deleteEntries(); | |||
1225 | break; | |||
1226 | case SID_DB_APP_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 41 ): | |||
1227 | case SID_DB_APP_TABLE_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 25 ): | |||
1228 | case SID_DB_APP_QUERY_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 29 ): | |||
1229 | case SID_DB_APP_FORM_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 33 ): | |||
1230 | case SID_DB_APP_REPORT_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 37 ): | |||
1231 | renameEntry(); | |||
1232 | break; | |||
1233 | case SID_DB_APP_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 42 ): | |||
1234 | case SID_DB_APP_EDIT_SQL_VIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 66 ): | |||
1235 | case SID_DB_APP_TABLE_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 26 ): | |||
1236 | case SID_DB_APP_QUERY_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 30 ): | |||
1237 | case SID_DB_APP_FORM_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 34 ): | |||
1238 | case SID_DB_APP_REPORT_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 38 ): | |||
1239 | doAction( _nId, E_OPEN_DESIGN ); | |||
1240 | break; | |||
1241 | case SID_DB_APP_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 43 ): | |||
1242 | case SID_DB_APP_TABLE_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 27 ): | |||
1243 | case SID_DB_APP_QUERY_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 31 ): | |||
1244 | case SID_DB_APP_FORM_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 35 ): | |||
1245 | case SID_DB_APP_REPORT_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 39 ): | |||
1246 | doAction( _nId, E_OPEN_NORMAL ); | |||
1247 | break; | |||
1248 | case SID_DB_APP_CONVERTTOVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 20 ): | |||
1249 | doAction( _nId, E_OPEN_NORMAL ); | |||
1250 | break; | |||
1251 | case SID_SELECTALL(5000 + 723): | |||
1252 | getContainer()->selectAll(); | |||
1253 | InvalidateAll(); | |||
1254 | break; | |||
1255 | case SID_DB_APP_DSRELDESIGN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 13 ): | |||
1256 | { | |||
1257 | Reference< XComponent > xRelationDesigner; | |||
1258 | if ( !m_pSubComponentManager->activateSubFrame( OUString(), SID_DB_APP_DSRELDESIGN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 13 ), E_OPEN_DESIGN, xRelationDesigner ) ) | |||
1259 | { | |||
1260 | SharedConnection xConnection( ensureConnection() ); | |||
1261 | if ( xConnection.is() ) | |||
1262 | { | |||
1263 | RelationDesigner aDesigner( getORB(), this, m_aCurrentFrame.getFrame() ); | |||
1264 | ||||
1265 | const Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); | |||
1266 | const Reference< XComponent > xComponent = aDesigner.createNew( xDataSource ); | |||
1267 | onDocumentOpened( OUString(), SID_DB_APP_DSRELDESIGN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 13 ), E_OPEN_DESIGN, xComponent, nullptr ); | |||
1268 | } | |||
1269 | } | |||
1270 | } | |||
1271 | break; | |||
1272 | case SID_DB_APP_DSUSERADMIN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 14 ): | |||
1273 | { | |||
1274 | SharedConnection xConnection( ensureConnection() ); | |||
1275 | if ( xConnection.is() ) | |||
1276 | openDialog("com.sun.star.sdb.UserAdministrationDialog"); | |||
1277 | } | |||
1278 | break; | |||
1279 | case SID_DB_APP_TABLEFILTER( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 15 ): | |||
1280 | // opens the table filter dialog for the selected data source | |||
1281 | openDialog( "com.sun.star.sdb.TableFilterDialog" ); | |||
1282 | askToReconnect(); | |||
1283 | break; | |||
1284 | case SID_DB_APP_REFRESH_TABLES( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 21 ): | |||
1285 | refreshTables(); | |||
1286 | break; | |||
1287 | case SID_DB_APP_DSPROPS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 17 ): | |||
1288 | // opens the administration dialog for the selected data source | |||
1289 | openDialog( "com.sun.star.sdb.DatasourceAdministrationDialog" ); | |||
1290 | askToReconnect(); | |||
1291 | break; | |||
1292 | case SID_DB_APP_DSADVANCED_SETTINGS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 5 ): | |||
1293 | openDialog("com.sun.star.sdb.AdvancedDatabaseSettingsDialog"); | |||
1294 | askToReconnect(); | |||
1295 | break; | |||
1296 | case SID_DB_APP_DSCONNECTION_TYPE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 4 ): | |||
1297 | openDialog("com.sun.star.sdb.DataSourceTypeChangeDialog"); | |||
1298 | askToReconnect(); | |||
1299 | break; | |||
1300 | case ID_DIRECT_SQL32: | |||
1301 | { | |||
1302 | SharedConnection xConnection( ensureConnection() ); | |||
1303 | if ( xConnection.is() ) | |||
1304 | // opens the DirectSQLDialog to execute hand made sql statements. | |||
1305 | openDialog( SERVICE_SDB_DIRECTSQLDIALOG"org.openoffice.comp.dbu.DirectSqlDialog" ); | |||
1306 | } | |||
1307 | break; | |||
1308 | case SID_DB_APP_VIEW_TABLES( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 9 ): | |||
1309 | m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_TABLE ) ); | |||
1310 | break; | |||
1311 | case SID_DB_APP_VIEW_QUERIES( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 10 ): | |||
1312 | m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_QUERY ) ); | |||
1313 | break; | |||
1314 | case SID_DB_APP_VIEW_FORMS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 12 ): | |||
1315 | m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_FORM ) ); | |||
1316 | break; | |||
1317 | case SID_DB_APP_VIEW_REPORTS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 22 ): | |||
1318 | m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_REPORT ) ); | |||
1319 | break; | |||
1320 | case SID_DB_APP_DISABLE_PREVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 3 ): | |||
1321 | m_ePreviewMode = E_PREVIEWNONE; | |||
1322 | getContainer()->switchPreview(m_ePreviewMode); | |||
1323 | break; | |||
1324 | case SID_DB_APP_VIEW_DOCINFO_PREVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 7 ): | |||
1325 | m_ePreviewMode = E_DOCUMENTINFO; | |||
1326 | getContainer()->switchPreview(m_ePreviewMode); | |||
1327 | break; | |||
1328 | case SID_DB_APP_VIEW_DOC_PREVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 8 ): | |||
1329 | m_ePreviewMode = E_DOCUMENT; | |||
1330 | getContainer()->switchPreview(m_ePreviewMode); | |||
1331 | break; | |||
1332 | case SID_MAIL_SENDDOC(5000 + 331): | |||
1333 | { | |||
1334 | SfxMailModel aSendMail; | |||
1335 | if ( aSendMail.AttachDocument(getModel(), OUString()) == SfxMailModel::SEND_MAIL_OK ) | |||
1336 | aSendMail.Send( getFrame() ); | |||
1337 | } | |||
1338 | break; | |||
1339 | case SID_DB_APP_SENDREPORTASMAIL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 61 ): | |||
1340 | doAction( _nId, E_OPEN_FOR_MAIL ); | |||
1341 | break; | |||
1342 | } | |||
1343 | } | |||
1344 | catch( const Exception& ) | |||
1345 | { | |||
1346 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1346" ": ", "dbaccess" );; | |||
1347 | } | |||
1348 | InvalidateFeature(_nId); | |||
1349 | } | |||
1350 | ||||
1351 | void OApplicationController::describeSupportedFeatures() | |||
1352 | { | |||
1353 | OGenericUnoController::describeSupportedFeatures(); | |||
1354 | ||||
1355 | implDescribeSupportedFeature( ".uno:AddDirect", SID_NEWDOCDIRECT(5000 + 537), CommandGroup::APPLICATION ); | |||
1356 | implDescribeSupportedFeature( ".uno:Save", ID_BROWSER_SAVEDOC(5000 + 505), CommandGroup::DOCUMENT ); | |||
1357 | implDescribeSupportedFeature( ".uno:SaveAs", ID_BROWSER_SAVEASDOC(5000 + 502), CommandGroup::DOCUMENT ); | |||
1358 | implDescribeSupportedFeature( ".uno:SendMail", SID_MAIL_SENDDOC(5000 + 331), CommandGroup::DOCUMENT ); | |||
1359 | implDescribeSupportedFeature( ".uno:DBSendReportAsMail",SID_DB_APP_SENDREPORTASMAIL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 61 ), | |||
1360 | CommandGroup::DOCUMENT ); | |||
1361 | implDescribeSupportedFeature( ".uno:DBSendReportToWriter",SID_DB_APP_SENDREPORTTOWRITER( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 62 ), | |||
1362 | CommandGroup::DOCUMENT ); | |||
1363 | implDescribeSupportedFeature( ".uno:DBNewForm", SID_APP_NEW_FORM( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 54 ), CommandGroup::INSERT ); | |||
1364 | implDescribeSupportedFeature( ".uno:DBNewFolder", SID_APP_NEW_FOLDER( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 53 ), CommandGroup::INSERT ); | |||
1365 | implDescribeSupportedFeature( ".uno:DBNewFormAutoPilot", SID_DB_FORM_NEW_PILOT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 63 ), CommandGroup::INSERT ); | |||
1366 | implDescribeSupportedFeature( ".uno:DBNewFormAutoPilotWithPreSelection", | |||
1367 | SID_FORM_CREATE_REPWIZ_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 50 ), | |||
1368 | CommandGroup::APPLICATION ); | |||
1369 | ||||
1370 | implDescribeSupportedFeature( ".uno:DBNewReport", SID_APP_NEW_REPORT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 65 ), CommandGroup::INSERT ); | |||
1371 | implDescribeSupportedFeature( ".uno:DBNewReportAutoPilot", | |||
1372 | ID_DOCUMENT_CREATE_REPWIZ41, CommandGroup::INSERT ); | |||
1373 | implDescribeSupportedFeature( ".uno:DBNewReportAutoPilotWithPreSelection", | |||
1374 | SID_REPORT_CREATE_REPWIZ_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 51 ), | |||
1375 | CommandGroup::APPLICATION ); | |||
1376 | implDescribeSupportedFeature( ".uno:DBNewQuery", ID_NEW_QUERY_DESIGN20, CommandGroup::INSERT ); | |||
1377 | implDescribeSupportedFeature( ".uno:DBNewQuerySql", ID_NEW_QUERY_SQL22, CommandGroup::INSERT ); | |||
1378 | implDescribeSupportedFeature( ".uno:DBNewQueryAutoPilot",ID_APP_NEW_QUERY_AUTO_PILOT44, | |||
1379 | CommandGroup::INSERT ); | |||
1380 | implDescribeSupportedFeature( ".uno:DBNewTable", ID_NEW_TABLE_DESIGN25, CommandGroup::INSERT ); | |||
1381 | implDescribeSupportedFeature( ".uno:DBNewTableAutoPilot",ID_NEW_TABLE_DESIGN_AUTO_PILOT45, | |||
1382 | CommandGroup::INSERT ); | |||
1383 | implDescribeSupportedFeature( ".uno:DBNewView", ID_NEW_VIEW_DESIGN28, CommandGroup::INSERT ); | |||
1384 | implDescribeSupportedFeature( ".uno:DBNewViewSQL", SID_DB_NEW_VIEW_SQL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 64 ), CommandGroup::INSERT ); | |||
1385 | ||||
1386 | implDescribeSupportedFeature( ".uno:DBDelete", SID_DB_APP_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 40 ), CommandGroup::EDIT ); | |||
1387 | implDescribeSupportedFeature( ".uno:Delete", SID_DB_APP_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 40 ), CommandGroup::EDIT ); | |||
1388 | implDescribeSupportedFeature( ".uno:DBRename", SID_DB_APP_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 41 ), CommandGroup::EDIT ); | |||
1389 | implDescribeSupportedFeature( ".uno:DBEdit", SID_DB_APP_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 42 ), CommandGroup::EDIT ); | |||
1390 | implDescribeSupportedFeature( ".uno:DBEditSqlView", SID_DB_APP_EDIT_SQL_VIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 66 ), CommandGroup::EDIT ); | |||
1391 | implDescribeSupportedFeature( ".uno:DBOpen", SID_DB_APP_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 43 ), CommandGroup::EDIT ); | |||
1392 | ||||
1393 | implDescribeSupportedFeature( ".uno:DBTableDelete", SID_DB_APP_TABLE_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 24 ), CommandGroup::EDIT ); | |||
1394 | implDescribeSupportedFeature( ".uno:DBTableRename", SID_DB_APP_TABLE_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 25 ), CommandGroup::EDIT ); | |||
1395 | implDescribeSupportedFeature( ".uno:DBTableEdit", SID_DB_APP_TABLE_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 26 ), CommandGroup::EDIT ); | |||
1396 | implDescribeSupportedFeature( ".uno:DBTableOpen", SID_DB_APP_TABLE_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 27 ), CommandGroup::EDIT ); | |||
1397 | ||||
1398 | implDescribeSupportedFeature( ".uno:DBQueryDelete", SID_DB_APP_QUERY_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 28 ), CommandGroup::EDIT ); | |||
1399 | implDescribeSupportedFeature( ".uno:DBQueryRename", SID_DB_APP_QUERY_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 29 ), CommandGroup::EDIT ); | |||
1400 | implDescribeSupportedFeature( ".uno:DBQueryEdit", SID_DB_APP_QUERY_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 30 ), CommandGroup::EDIT ); | |||
1401 | implDescribeSupportedFeature( ".uno:DBQueryOpen", SID_DB_APP_QUERY_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 31 ), CommandGroup::EDIT ); | |||
1402 | ||||
1403 | implDescribeSupportedFeature( ".uno:DBFormDelete", SID_DB_APP_FORM_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 32 ), CommandGroup::EDIT ); | |||
1404 | implDescribeSupportedFeature( ".uno:DBFormRename", SID_DB_APP_FORM_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 33 ), CommandGroup::EDIT ); | |||
1405 | implDescribeSupportedFeature( ".uno:DBFormEdit", SID_DB_APP_FORM_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 34 ), CommandGroup::EDIT ); | |||
1406 | implDescribeSupportedFeature( ".uno:DBFormOpen", SID_DB_APP_FORM_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 35 ), CommandGroup::EDIT ); | |||
1407 | ||||
1408 | implDescribeSupportedFeature( ".uno:DBReportDelete", SID_DB_APP_REPORT_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 36 ), CommandGroup::EDIT ); | |||
1409 | implDescribeSupportedFeature( ".uno:DBReportRename", SID_DB_APP_REPORT_RENAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 37 ), CommandGroup::EDIT ); | |||
1410 | implDescribeSupportedFeature( ".uno:DBReportEdit", SID_DB_APP_REPORT_EDIT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 38 ), CommandGroup::EDIT ); | |||
1411 | implDescribeSupportedFeature( ".uno:DBReportOpen", SID_DB_APP_REPORT_OPEN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 39 ), CommandGroup::EDIT ); | |||
1412 | ||||
1413 | implDescribeSupportedFeature( ".uno:SelectAll", SID_SELECTALL(5000 + 723), CommandGroup::EDIT ); | |||
1414 | implDescribeSupportedFeature( ".uno:Undo", ID_BROWSER_UNDO(5000 + 701), CommandGroup::EDIT ); | |||
1415 | ||||
1416 | implDescribeSupportedFeature( ".uno:Sortup", ID_BROWSER_SORTUP( 10000 + 712 ), CommandGroup::VIEW ); | |||
1417 | implDescribeSupportedFeature( ".uno:SortDown", ID_BROWSER_SORTDOWN( 10000 + 713 ), CommandGroup::VIEW ); | |||
1418 | implDescribeSupportedFeature( ".uno:DBRelationDesign", SID_DB_APP_DSRELDESIGN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 13 ), CommandGroup::APPLICATION ); | |||
1419 | implDescribeSupportedFeature( ".uno:DBUserAdmin", SID_DB_APP_DSUSERADMIN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 14 ), CommandGroup::APPLICATION ); | |||
1420 | implDescribeSupportedFeature( ".uno:DBTableFilter", SID_DB_APP_TABLEFILTER( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 15 ), CommandGroup::APPLICATION ); | |||
1421 | implDescribeSupportedFeature( ".uno:DBDSProperties", SID_DB_APP_DSPROPS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 17 ), CommandGroup::EDIT ); | |||
1422 | implDescribeSupportedFeature( ".uno:DBDSConnectionType", SID_DB_APP_DSCONNECTION_TYPE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 4 ), | |||
1423 | CommandGroup::EDIT ); | |||
1424 | implDescribeSupportedFeature( ".uno:DBDSAdvancedSettings", | |||
1425 | SID_DB_APP_DSADVANCED_SETTINGS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 5 ), | |||
1426 | CommandGroup::EDIT ); | |||
1427 | implDescribeSupportedFeature( ".uno:PasteSpecial", SID_DB_APP_PASTE_SPECIAL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 55 ), CommandGroup::EDIT ); | |||
1428 | implDescribeSupportedFeature( ".uno:DBConvertToView", SID_DB_APP_CONVERTTOVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 20 ), CommandGroup::EDIT ); | |||
1429 | implDescribeSupportedFeature( ".uno:DBRefreshTables", SID_DB_APP_REFRESH_TABLES( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 21 ), CommandGroup::APPLICATION ); | |||
1430 | implDescribeSupportedFeature( ".uno:DBDirectSQL", ID_DIRECT_SQL32, CommandGroup::APPLICATION ); | |||
1431 | implDescribeSupportedFeature( ".uno:DBViewTables", SID_DB_APP_VIEW_TABLES( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 9 ), CommandGroup::VIEW ); | |||
1432 | implDescribeSupportedFeature( ".uno:DBViewQueries", SID_DB_APP_VIEW_QUERIES( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 10 ), CommandGroup::VIEW ); | |||
1433 | implDescribeSupportedFeature( ".uno:DBViewForms", SID_DB_APP_VIEW_FORMS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 12 ), CommandGroup::VIEW ); | |||
1434 | implDescribeSupportedFeature( ".uno:DBViewReports", SID_DB_APP_VIEW_REPORTS( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 22 ), CommandGroup::VIEW ); | |||
1435 | implDescribeSupportedFeature( ".uno:DBDisablePreview", SID_DB_APP_DISABLE_PREVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 3 ),CommandGroup::VIEW ); | |||
1436 | implDescribeSupportedFeature( ".uno:DBShowDocInfoPreview", | |||
1437 | SID_DB_APP_VIEW_DOCINFO_PREVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 7 ), | |||
1438 | CommandGroup::VIEW ); | |||
1439 | implDescribeSupportedFeature( ".uno:DBShowDocPreview", SID_DB_APP_VIEW_DOC_PREVIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 8 ), | |||
1440 | CommandGroup::VIEW ); | |||
1441 | ||||
1442 | implDescribeSupportedFeature( ".uno:OpenUrl", SID_OPENURL(5000 + 596), CommandGroup::APPLICATION ); | |||
1443 | ||||
1444 | // this one should not appear under Tools->Customize->Keyboard | |||
1445 | implDescribeSupportedFeature( ".uno:DBNewReportWithPreSelection", | |||
1446 | SID_APP_NEW_REPORT_PRE_SEL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 19 ) ); | |||
1447 | implDescribeSupportedFeature( ".uno:DBDSImport", SID_DB_APP_DSIMPORT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 11 )); | |||
1448 | implDescribeSupportedFeature( ".uno:DBDSExport", SID_DB_APP_DSEXPORT( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 23 )); | |||
1449 | implDescribeSupportedFeature( ".uno:DBDBAdmin", SID_DB_APP_DBADMIN( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 18 )); | |||
1450 | ||||
1451 | // status info | |||
1452 | implDescribeSupportedFeature( ".uno:DBStatusType", SID_DB_APP_STATUS_TYPE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 57 )); | |||
1453 | implDescribeSupportedFeature( ".uno:DBStatusDBName", SID_DB_APP_STATUS_DBNAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 58 )); | |||
1454 | implDescribeSupportedFeature( ".uno:DBStatusUserName", SID_DB_APP_STATUS_USERNAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 59 )); | |||
1455 | implDescribeSupportedFeature( ".uno:DBStatusHostName", SID_DB_APP_STATUS_HOSTNAME( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 60 )); | |||
1456 | } | |||
1457 | ||||
1458 | OApplicationView* OApplicationController::getContainer() const | |||
1459 | { | |||
1460 | return static_cast< OApplicationView* >( getView() ); | |||
1461 | } | |||
1462 | ||||
1463 | // css::container::XContainerListener | |||
1464 | void SAL_CALL OApplicationController::elementInserted( const ContainerEvent& _rEvent ) | |||
1465 | { | |||
1466 | SolarMutexGuard aSolarGuard; | |||
1467 | ::osl::MutexGuard aGuard( getMutex() ); | |||
1468 | ||||
1469 | Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY); | |||
1470 | if ( std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) == m_aCurrentContainers.end() ) | |||
1471 | return; | |||
1472 | ||||
1473 | OSL_ENSURE(getContainer(),"View is NULL! -> GPF")do { if (true && (!(getContainer()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1473" ": "), "%s", "View is NULL! -> GPF"); } } while (false); | |||
1474 | if ( !getContainer() ) | |||
1475 | return; | |||
1476 | ||||
1477 | OUString sName; | |||
1478 | _rEvent.Accessor >>= sName; | |||
1479 | ElementType eType = getElementType(xContainer); | |||
1480 | ||||
1481 | switch( eType ) | |||
1482 | { | |||
1483 | case E_TABLE: | |||
1484 | ensureConnection(); | |||
1485 | break; | |||
1486 | case E_FORM: | |||
1487 | case E_REPORT: | |||
1488 | { | |||
1489 | Reference< XContainer > xSubContainer(_rEvent.Element,UNO_QUERY); | |||
1490 | if ( xSubContainer.is() ) | |||
1491 | containerFound(xSubContainer); | |||
1492 | } | |||
1493 | break; | |||
1494 | default: | |||
1495 | break; | |||
1496 | } | |||
1497 | getContainer()->elementAdded(eType,sName,_rEvent.Element); | |||
1498 | } | |||
1499 | ||||
1500 | void SAL_CALL OApplicationController::elementRemoved( const ContainerEvent& _rEvent ) | |||
1501 | { | |||
1502 | SolarMutexGuard aSolarGuard; | |||
1503 | ::osl::MutexGuard aGuard( getMutex() ); | |||
1504 | ||||
1505 | Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY); | |||
1506 | if ( std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) == m_aCurrentContainers.end() ) | |||
1507 | return; | |||
1508 | ||||
1509 | OSL_ENSURE(getContainer(),"View is NULL! -> GPF")do { if (true && (!(getContainer()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1509" ": "), "%s", "View is NULL! -> GPF"); } } while (false); | |||
1510 | OUString sName; | |||
1511 | _rEvent.Accessor >>= sName; | |||
1512 | ElementType eType = getElementType(xContainer); | |||
1513 | switch( eType ) | |||
1514 | { | |||
1515 | case E_TABLE: | |||
1516 | ensureConnection(); | |||
1517 | break; | |||
1518 | case E_FORM: | |||
1519 | case E_REPORT: | |||
1520 | { | |||
1521 | Reference<XContent> xContent(xContainer,UNO_QUERY); | |||
1522 | if ( xContent.is() ) | |||
1523 | { | |||
1524 | sName = xContent->getIdentifier()->getContentIdentifier() + "/" + sName; | |||
1525 | } | |||
1526 | } | |||
1527 | break; | |||
1528 | default: | |||
1529 | break; | |||
1530 | } | |||
1531 | getContainer()->elementRemoved(eType,sName); | |||
1532 | } | |||
1533 | ||||
1534 | void SAL_CALL OApplicationController::elementReplaced( const ContainerEvent& _rEvent ) | |||
1535 | { | |||
1536 | SolarMutexGuard aSolarGuard; | |||
1537 | ::osl::MutexGuard aGuard( getMutex() ); | |||
1538 | ||||
1539 | Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY); | |||
1540 | if ( std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) == m_aCurrentContainers.end() ) | |||
1541 | return; | |||
1542 | ||||
1543 | OSL_ENSURE(getContainer(),"View is NULL! -> GPF")do { if (true && (!(getContainer()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1543" ": "), "%s", "View is NULL! -> GPF"); } } while (false); | |||
1544 | OUString sName; | |||
1545 | try | |||
1546 | { | |||
1547 | _rEvent.Accessor >>= sName; | |||
1548 | Reference<XPropertySet> xProp(_rEvent.Element,UNO_QUERY); | |||
1549 | ||||
1550 | ElementType eType = getElementType(xContainer); | |||
1551 | switch( eType ) | |||
1552 | { | |||
1553 | case E_TABLE: | |||
1554 | { | |||
1555 | ensureConnection(); | |||
1556 | if ( xProp.is() && m_xMetaData.is() ) | |||
1557 | //TODO: tdf#133497 "OApplicationController::elementReplaced effectively does | |||
1558 | // nothing": | |||
1559 | (void) ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::EComposeRule::InDataManipulation, false ); | |||
1560 | } | |||
1561 | break; | |||
1562 | case E_FORM: | |||
1563 | case E_REPORT: | |||
1564 | { | |||
1565 | Reference<XContent> xContent(xContainer,UNO_QUERY); | |||
1566 | if ( xContent.is() ) | |||
1567 | { | |||
1568 | sName = xContent->getIdentifier()->getContentIdentifier() + "/" + sName; | |||
1569 | } | |||
1570 | } | |||
1571 | break; | |||
1572 | default: | |||
1573 | break; | |||
1574 | } | |||
1575 | // getContainer()->elementReplaced(getContainer()->getElementType(),sName,sNewName); | |||
1576 | } | |||
1577 | catch( Exception& ) | |||
1578 | { | |||
1579 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1579" ": ", "dbaccess" );; | |||
1580 | } | |||
1581 | } | |||
1582 | ||||
1583 | namespace | |||
1584 | { | |||
1585 | OUString lcl_getToolBarResource(ElementType _eType) | |||
1586 | { | |||
1587 | OUString sToolbar; | |||
1588 | switch(_eType) | |||
1589 | { | |||
1590 | case E_TABLE: | |||
1591 | sToolbar = "private:resource/toolbar/tableobjectbar"; | |||
1592 | break; | |||
1593 | case E_QUERY: | |||
1594 | sToolbar = "private:resource/toolbar/queryobjectbar"; | |||
1595 | break; | |||
1596 | case E_FORM: | |||
1597 | sToolbar = "private:resource/toolbar/formobjectbar"; | |||
1598 | break; | |||
1599 | case E_REPORT: | |||
1600 | sToolbar = "private:resource/toolbar/reportobjectbar"; | |||
1601 | break; | |||
1602 | case E_NONE: | |||
1603 | break; | |||
1604 | default: | |||
1605 | OSL_FAIL("Invalid ElementType!")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1605" ": "), "%s", "Invalid ElementType!"); } } while ( false); | |||
1606 | break; | |||
1607 | } | |||
1608 | return sToolbar; | |||
1609 | } | |||
1610 | } | |||
1611 | ||||
1612 | bool OApplicationController::onContainerSelect(ElementType _eType) | |||
1613 | { | |||
1614 | OSL_ENSURE(getContainer(),"View is NULL! -> GPF")do { if (true && (!(getContainer()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1614" ": "), "%s", "View is NULL! -> GPF"); } } while (false); | |||
1615 | ||||
1616 | if ( m_eCurrentType != _eType && _eType != E_NONE ) | |||
1617 | { | |||
1618 | SelectionGuard aSelGuard( *m_pSelectionNotifier ); | |||
1619 | ||||
1620 | if ( _eType == E_TABLE ) | |||
1621 | { | |||
1622 | try | |||
1623 | { | |||
1624 | SharedConnection xConnection( ensureConnection() ); | |||
1625 | if ( xConnection.is() && getContainer()->getDetailView() ) | |||
1626 | { | |||
1627 | getContainer()->getDetailView()->createTablesPage(xConnection); | |||
1628 | Reference<XTablesSupplier> xTabSup(xConnection,UNO_QUERY); | |||
1629 | if ( xTabSup.is() ) | |||
1630 | addContainerListener(xTabSup->getTables()); | |||
1631 | } | |||
1632 | else | |||
1633 | { | |||
1634 | return false; | |||
1635 | } | |||
1636 | } | |||
1637 | catch( const Exception& ) | |||
1638 | { | |||
1639 | return false; | |||
1640 | } | |||
1641 | } | |||
1642 | else if ( _eType == E_QUERY ) | |||
1643 | { | |||
1644 | // tdf#126578: retrieve connection to be able to call "Create as View" | |||
1645 | ensureConnection(); | |||
1646 | } | |||
1647 | Reference< XLayoutManager > xLayoutManager = getLayoutManager( getFrame() ); | |||
1648 | if ( xLayoutManager.is() ) | |||
1649 | { | |||
1650 | OUString sToolbar = lcl_getToolBarResource(_eType); | |||
1651 | OUString sDestroyToolbar = lcl_getToolBarResource(m_eCurrentType); | |||
1652 | ||||
1653 | xLayoutManager->lock(); | |||
1654 | xLayoutManager->destroyElement( sDestroyToolbar ); | |||
1655 | if ( !sToolbar.isEmpty() ) | |||
1656 | { | |||
1657 | xLayoutManager->createElement( sToolbar ); | |||
1658 | xLayoutManager->requestElement( sToolbar ); | |||
1659 | } | |||
1660 | xLayoutManager->unlock(); | |||
1661 | xLayoutManager->doLayout(); | |||
1662 | } | |||
1663 | ||||
1664 | if ( _eType != E_TABLE && getContainer()->getDetailView() ) | |||
1665 | { | |||
1666 | Reference< XNameAccess > xContainer = getElements(_eType); | |||
1667 | addContainerListener(xContainer); | |||
1668 | getContainer()->getDetailView()->createPage(_eType,xContainer); | |||
1669 | } | |||
1670 | ||||
1671 | SelectionByElementType::const_iterator pendingSelection = m_aPendingSelection.find( _eType ); | |||
1672 | if ( pendingSelection != m_aPendingSelection.end() ) | |||
1673 | { | |||
1674 | getContainer()->selectElements( comphelper::containerToSequence(pendingSelection->second) ); | |||
1675 | ||||
1676 | m_aPendingSelection.erase( pendingSelection ); | |||
1677 | } | |||
1678 | ||||
1679 | InvalidateAll(); | |||
1680 | } | |||
1681 | m_eCurrentType = _eType; | |||
1682 | ||||
1683 | return true; | |||
1684 | } | |||
1685 | ||||
1686 | bool OApplicationController::onEntryDoubleClick(const weld::TreeView& rTreeView) | |||
1687 | { | |||
1688 | OApplicationView* pContainer = getContainer(); | |||
1689 | if (!pContainer) | |||
1690 | return false; // not handled | |||
1691 | ||||
1692 | std::unique_ptr<weld::TreeIter> xHdlEntry = rTreeView.make_iterator(); | |||
1693 | if (!rTreeView.get_cursor(xHdlEntry.get())) | |||
1694 | return false; | |||
1695 | ||||
1696 | if (pContainer->isLeaf(rTreeView, *xHdlEntry)) | |||
1697 | { | |||
1698 | try | |||
1699 | { | |||
1700 | // opens a new frame with either the table or the query or report or form or view | |||
1701 | openElementWithArguments( | |||
1702 | getContainer()->getQualifiedName(xHdlEntry.get()), | |||
1703 | getContainer()->getElementType(), | |||
1704 | E_OPEN_NORMAL, | |||
1705 | 0, | |||
1706 | ::comphelper::NamedValueCollection() ); | |||
1707 | return true; // handled | |||
1708 | } | |||
1709 | catch(const Exception&) | |||
1710 | { | |||
1711 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1711" ": ", "dbaccess" );; | |||
1712 | } | |||
1713 | } | |||
1714 | ||||
1715 | return false; // not handled | |||
1716 | } | |||
1717 | ||||
1718 | bool OApplicationController::impl_isAlterableView_nothrow( const OUString& _rTableOrViewName ) const | |||
1719 | { | |||
1720 | OSL_PRECOND( m_xDataSourceConnection.is(), "OApplicationController::impl_isAlterableView_nothrow: no connection!" )do { if (true && (!(m_xDataSourceConnection.is()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1720" ": "), "%s", "OApplicationController::impl_isAlterableView_nothrow: no connection!" ); } } while (false); | |||
1721 | ||||
1722 | bool bIsAlterableView( false ); | |||
1723 | try | |||
1724 | { | |||
1725 | Reference< XViewsSupplier > xViewsSupp( m_xDataSourceConnection, UNO_QUERY ); | |||
1726 | Reference< XNameAccess > xViews; | |||
1727 | if ( xViewsSupp.is() ) | |||
1728 | xViews = xViewsSupp->getViews(); | |||
1729 | ||||
1730 | Reference< XAlterView > xAsAlterableView; | |||
1731 | if ( xViews.is() && xViews->hasByName( _rTableOrViewName ) ) | |||
1732 | xAsAlterableView.set( xViews->getByName( _rTableOrViewName ), UNO_QUERY ); | |||
1733 | ||||
1734 | bIsAlterableView = xAsAlterableView.is(); | |||
1735 | } | |||
1736 | catch( const Exception& ) | |||
1737 | { | |||
1738 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1738" ": ", "dbaccess" );; | |||
1739 | } | |||
1740 | return bIsAlterableView; | |||
1741 | } | |||
1742 | ||||
1743 | Reference< XComponent > OApplicationController::openElementWithArguments( const OUString& _sName, ElementType _eType, | |||
1744 | ElementOpenMode _eOpenMode, sal_uInt16 _nInstigatorCommand, const ::comphelper::NamedValueCollection& _rAdditionalArguments ) | |||
1745 | { | |||
1746 | OSL_PRECOND( getContainer(), "OApplicationController::openElementWithArguments: no view!" )do { if (true && (!(getContainer()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1746" ": "), "%s", "OApplicationController::openElementWithArguments: no view!" ); } } while (false); | |||
1747 | if ( !getContainer() ) | |||
1748 | return nullptr; | |||
1749 | ||||
1750 | Reference< XComponent > xRet; | |||
1751 | if ( _eOpenMode == E_OPEN_DESIGN ) | |||
1752 | { | |||
1753 | // https://bz.apache.org/ooo/show_bug.cgi?id=30382 | |||
1754 | getContainer()->showPreview(nullptr); | |||
1755 | } | |||
1756 | ||||
1757 | bool isStandaloneDocument = false; | |||
1758 | switch ( _eType ) | |||
1759 | { | |||
1760 | case E_REPORT: | |||
1761 | if ( _eOpenMode != E_OPEN_DESIGN ) | |||
1762 | { | |||
1763 | // reports which are opened in a mode other than design are no sub components of our application | |||
1764 | // component, but standalone documents. | |||
1765 | isStandaloneDocument = true; | |||
1766 | } | |||
1767 | [[fallthrough]]; | |||
1768 | case E_FORM: | |||
1769 | { | |||
1770 | if ( isStandaloneDocument || !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode, xRet ) ) | |||
1771 | { | |||
1772 | std::unique_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType ); | |||
1773 | if ( !aHelper->isConnected() ) | |||
1774 | break; | |||
1775 | ||||
1776 | Reference< XComponent > xDefinition; | |||
1777 | xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments ); | |||
1778 | ||||
1779 | if ( !isStandaloneDocument ) | |||
1780 | onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition ); | |||
1781 | } | |||
1782 | } | |||
1783 | break; | |||
1784 | ||||
1785 | case E_QUERY: | |||
1786 | case E_TABLE: | |||
1787 | { | |||
1788 | if ( !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode, xRet ) ) | |||
1789 | { | |||
1790 | SharedConnection xConnection( ensureConnection() ); | |||
1791 | if ( !xConnection.is() ) | |||
1792 | break; | |||
1793 | ||||
1794 | std::unique_ptr< DatabaseObjectView > pDesigner; | |||
1795 | ::comphelper::NamedValueCollection aArguments( _rAdditionalArguments ); | |||
1796 | ||||
1797 | Any aDataSource; | |||
1798 | if ( _eOpenMode == E_OPEN_DESIGN ) | |||
1799 | { | |||
1800 | bool bAddViewTypeArg = false; | |||
1801 | ||||
1802 | if ( _eType == E_TABLE ) | |||
1803 | { | |||
1804 | if ( impl_isAlterableView_nothrow( _sName ) ) | |||
1805 | { | |||
1806 | pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true ) ); | |||
1807 | bAddViewTypeArg = true; | |||
1808 | } | |||
1809 | else | |||
1810 | { | |||
1811 | pDesigner.reset( new TableDesigner( getORB(), this, m_aCurrentFrame.getFrame() ) ); | |||
1812 | } | |||
1813 | } | |||
1814 | else if ( _eType == E_QUERY ) | |||
1815 | { | |||
1816 | pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false ) ); | |||
1817 | bAddViewTypeArg = true; | |||
1818 | } | |||
1819 | aDataSource <<= m_xDataSource; | |||
1820 | ||||
1821 | if ( bAddViewTypeArg ) | |||
1822 | { | |||
1823 | const bool bQueryGraphicalMode =( _nInstigatorCommand != SID_DB_APP_EDIT_SQL_VIEW( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 66 ) ); | |||
1824 | aArguments.put( OUString(PROPERTY_GRAPHICAL_DESIGN"GraphicalDesign"), bQueryGraphicalMode ); | |||
1825 | } | |||
1826 | ||||
1827 | } | |||
1828 | else | |||
1829 | { | |||
1830 | pDesigner.reset( new ResultSetBrowser( getORB(), this, m_aCurrentFrame.getFrame(), _eType == E_TABLE ) ); | |||
1831 | ||||
1832 | if ( !aArguments.has( OUString(PROPERTY_SHOWMENU"ShowMenu") ) ) | |||
1833 | aArguments.put( OUString(PROPERTY_SHOWMENU"ShowMenu"), makeAny( true ) ); | |||
1834 | ||||
1835 | aDataSource <<= getDatabaseName(); | |||
1836 | } | |||
1837 | ||||
1838 | xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments ) ); | |||
1839 | onDocumentOpened( _sName, _eType, _eOpenMode, xRet, nullptr ); | |||
1840 | } | |||
1841 | } | |||
1842 | break; | |||
1843 | ||||
1844 | default: | |||
1845 | OSL_FAIL( "OApplicationController::openElement: illegal object type!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1845" ": "), "%s", "OApplicationController::openElement: illegal object type!" ); } } while (false); | |||
1846 | break; | |||
1847 | } | |||
1848 | return xRet; | |||
1849 | } | |||
1850 | ||||
1851 | IMPL_LINK( OApplicationController, OnSelectContainer, void*, _pType, void )void OApplicationController::LinkStubOnSelectContainer(void * instance, void* data) { return static_cast<OApplicationController *>(instance)->OnSelectContainer(data); } void OApplicationController ::OnSelectContainer(void* _pType) | |||
1852 | { | |||
1853 | ElementType eType = static_cast<ElementType>(reinterpret_cast< sal_IntPtr >( _pType )); | |||
1854 | if (getContainer()) | |||
1855 | getContainer()->selectContainer(eType); | |||
1856 | } | |||
1857 | ||||
1858 | IMPL_LINK( OApplicationController, OnCreateWithPilot, void*, _pType, void )void OApplicationController::LinkStubOnCreateWithPilot(void * instance, void* data) { return static_cast<OApplicationController *>(instance)->OnCreateWithPilot(data); } void OApplicationController ::OnCreateWithPilot(void* _pType) | |||
1859 | { | |||
1860 | ElementType eType = static_cast<ElementType>(reinterpret_cast< sal_IntPtr >( _pType )); | |||
1861 | newElementWithPilot( eType ); | |||
1862 | } | |||
1863 | ||||
1864 | void OApplicationController::newElementWithPilot( ElementType _eType ) | |||
1865 | { | |||
1866 | utl::CloseVeto aKeepDoc( getFrame() ); | |||
1867 | // prevent the document being closed while the wizard is open | |||
1868 | ||||
1869 | OSL_ENSURE( getContainer(), "OApplicationController::newElementWithPilot: without a view?" )do { if (true && (!(getContainer()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1869" ": "), "%s", "OApplicationController::newElementWithPilot: without a view?" ); } } while (false); | |||
1870 | ||||
1871 | switch ( _eType ) | |||
1872 | { | |||
1873 | case E_REPORT: | |||
1874 | case E_FORM: | |||
1875 | { | |||
1876 | std::unique_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType); | |||
1877 | if ( aHelper->isConnected() ) | |||
1878 | { | |||
1879 | sal_Int32 nCommandType = -1; | |||
1880 | const OUString sCurrentSelected( getCurrentlySelectedName( nCommandType ) ); | |||
1881 | if ( E_REPORT == _eType ) | |||
1882 | aHelper->newReportWithPilot( nCommandType, sCurrentSelected ); | |||
1883 | else | |||
1884 | aHelper->newFormWithPilot( nCommandType, sCurrentSelected ); | |||
1885 | } | |||
1886 | } | |||
1887 | break; | |||
1888 | case E_QUERY: | |||
1889 | case E_TABLE: | |||
1890 | { | |||
1891 | std::unique_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType); | |||
1892 | if ( aHelper->isConnected() ) | |||
1893 | { | |||
1894 | if ( E_QUERY == _eType ) | |||
1895 | aHelper->newQueryWithPilot(); | |||
1896 | else | |||
1897 | aHelper->newTableWithPilot(); | |||
1898 | } | |||
1899 | } | |||
1900 | break; | |||
1901 | case E_NONE: | |||
1902 | break; | |||
1903 | } | |||
1904 | ||||
1905 | // no need for onDocumentOpened, the table wizard opens the created table by using | |||
1906 | // XDatabaseDocumentUI::loadComponent method. | |||
1907 | } | |||
1908 | ||||
1909 | Reference< XComponent > OApplicationController::newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments, | |||
1910 | Reference< XComponent >& o_rDocumentDefinition ) | |||
1911 | { | |||
1912 | OSL_ENSURE(getContainer(),"View is NULL! -> GPF")do { if (true && (!(getContainer()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1912" ": "), "%s", "View is NULL! -> GPF"); } } while (false); | |||
1913 | ||||
1914 | Reference< XComponent > xComponent; | |||
1915 | o_rDocumentDefinition.clear(); | |||
1916 | ||||
1917 | switch ( _eType ) | |||
1918 | { | |||
1919 | case E_FORM: | |||
1920 | case E_REPORT: | |||
1921 | { | |||
1922 | std::unique_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess( _eType ); | |||
1923 | if ( !aHelper->isConnected() ) | |||
1924 | break; | |||
1925 | ||||
1926 | xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT15 : ID_REPORT_NEW_TEXT14, i_rAdditionalArguments, o_rDocumentDefinition ); | |||
1927 | } | |||
1928 | break; | |||
1929 | ||||
1930 | case E_QUERY: | |||
1931 | case E_TABLE: | |||
1932 | { | |||
1933 | std::unique_ptr< DatabaseObjectView > pDesigner; | |||
1934 | SharedConnection xConnection( ensureConnection() ); | |||
1935 | if ( !xConnection.is() ) | |||
1936 | break; | |||
1937 | ||||
1938 | if ( _eType == E_TABLE ) | |||
1939 | { | |||
1940 | pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) ); | |||
1941 | } | |||
1942 | else if ( _eType == E_QUERY ) | |||
1943 | { | |||
1944 | pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false ) ); | |||
1945 | } | |||
1946 | ||||
1947 | Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); | |||
1948 | xComponent = pDesigner->createNew( xDataSource, i_rAdditionalArguments ); | |||
1949 | } | |||
1950 | break; | |||
1951 | ||||
1952 | default: | |||
1953 | OSL_FAIL( "OApplicationController::newElement: illegal type!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1953" ": "), "%s", "OApplicationController::newElement: illegal type!" ); } } while (false); | |||
1954 | break; | |||
1955 | } | |||
1956 | ||||
1957 | if ( xComponent.is() ) | |||
1958 | onDocumentOpened( OUString(), _eType, E_OPEN_DESIGN, xComponent, o_rDocumentDefinition ); | |||
1959 | ||||
1960 | return xComponent; | |||
1961 | } | |||
1962 | ||||
1963 | void OApplicationController::addContainerListener(const Reference<XNameAccess>& _xCollection) | |||
1964 | { | |||
1965 | try | |||
1966 | { | |||
1967 | Reference< XContainer > xCont(_xCollection, UNO_QUERY); | |||
1968 | if ( xCont.is() ) | |||
1969 | { | |||
1970 | // add as listener to get notified if elements are inserted or removed | |||
1971 | TContainerVector::const_iterator aFind = std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xCont); | |||
1972 | if ( aFind == m_aCurrentContainers.end() ) | |||
1973 | { | |||
1974 | xCont->addContainerListener(this); | |||
1975 | m_aCurrentContainers.push_back(xCont); | |||
1976 | } | |||
1977 | } | |||
1978 | } | |||
1979 | catch( const Exception& ) | |||
1980 | { | |||
1981 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1981" ": ", "dbaccess" );; | |||
1982 | } | |||
1983 | } | |||
1984 | ||||
1985 | void OApplicationController::renameEntry() | |||
1986 | { | |||
1987 | SolarMutexGuard aSolarGuard; | |||
1988 | ::osl::MutexGuard aGuard( getMutex() ); | |||
1989 | ||||
1990 | OSL_ENSURE(getContainer(),"View is NULL! -> GPF")do { if (true && (!(getContainer()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1990" ": "), "%s", "View is NULL! -> GPF"); } } while (false); | |||
1991 | std::vector< OUString> aList; | |||
1992 | getSelectionElementNames(aList); | |||
1993 | ||||
1994 | Reference< XNameAccess > xContainer = getElements(getContainer()->getElementType()); | |||
1995 | OSL_ENSURE(aList.size() == 1,"Invalid rename call here. More than one element!")do { if (true && (!(aList.size() == 1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "1995" ": "), "%s", "Invalid rename call here. More than one element!" ); } } while (false); | |||
1996 | if ( aList.empty() ) | |||
1997 | return; | |||
1998 | ||||
1999 | try | |||
2000 | { | |||
2001 | if ( xContainer.is() ) | |||
2002 | { | |||
2003 | std::unique_ptr< IObjectNameCheck > pNameChecker; | |||
2004 | std::unique_ptr<OSaveAsDlg> xDialog; | |||
2005 | ||||
2006 | Reference<XRename> xRename; | |||
2007 | const ElementType eType = getContainer()->getElementType(); | |||
2008 | switch( eType ) | |||
2009 | { | |||
2010 | case E_FORM: | |||
2011 | case E_REPORT: | |||
2012 | { | |||
2013 | Reference<XHierarchicalNameContainer> xHNames(xContainer, UNO_QUERY); | |||
2014 | if ( xHNames.is() ) | |||
2015 | { | |||
2016 | OUString sLabel; | |||
2017 | if ( eType == E_FORM ) | |||
2018 | sLabel = DBA_RES(STR_FRM_LABEL)::dbaccess::ResourceManager::loadString( reinterpret_cast< char const *>("STR_FRM_LABEL" "\004" u8"F~orm name") ); | |||
2019 | else | |||
2020 | sLabel = DBA_RES(STR_RPT_LABEL)::dbaccess::ResourceManager::loadString( reinterpret_cast< char const *>("STR_RPT_LABEL" "\004" u8"~Report name") ); | |||
2021 | ||||
2022 | OUString sName = *aList.begin(); | |||
2023 | if ( xHNames->hasByHierarchicalName(sName) ) | |||
2024 | { | |||
2025 | xRename.set(xHNames->getByHierarchicalName(sName),UNO_QUERY); | |||
2026 | Reference<XChild> xChild(xRename,UNO_QUERY); | |||
2027 | if ( xChild.is() ) | |||
2028 | { | |||
2029 | Reference<XHierarchicalNameContainer> xParent(xChild->getParent(),UNO_QUERY); | |||
2030 | if ( xParent.is() ) | |||
2031 | { | |||
2032 | xHNames = xParent; | |||
2033 | Reference<XPropertySet>(xRename,UNO_QUERY_THROW)->getPropertyValue(PROPERTY_NAME"Name") >>= sName; | |||
2034 | } | |||
2035 | } | |||
2036 | pNameChecker.reset( new HierarchicalNameCheck( xHNames.get(), OUString() ) ); | |||
2037 | xDialog.reset(new OSaveAsDlg( | |||
2038 | getFrameWeld(), getORB(), sName, sLabel, *pNameChecker, SADFlags::TitleRename)); | |||
2039 | } | |||
2040 | } | |||
2041 | } | |||
2042 | break; | |||
2043 | case E_TABLE: | |||
2044 | ensureConnection(); | |||
2045 | if ( !getConnection().is() ) | |||
2046 | break; | |||
2047 | [[fallthrough]]; | |||
2048 | case E_QUERY: | |||
2049 | if ( xContainer->hasByName(*aList.begin()) ) | |||
2050 | { | |||
2051 | xRename.set(xContainer->getByName(*aList.begin()),UNO_QUERY); | |||
2052 | sal_Int32 nCommandType = eType == E_QUERY ? CommandType::QUERY : CommandType::TABLE; | |||
2053 | ||||
2054 | ensureConnection(); | |||
2055 | pNameChecker.reset( new DynamicTableOrQueryNameCheck( getConnection(), nCommandType ) ); | |||
2056 | xDialog.reset(new OSaveAsDlg(getFrameWeld(), nCommandType, getORB(), getConnection(), | |||
2057 | *aList.begin(), *pNameChecker, SADFlags::TitleRename)); | |||
2058 | } | |||
2059 | break; | |||
2060 | default: | |||
2061 | break; | |||
2062 | } | |||
2063 | ||||
2064 | if (xRename.is() && xDialog) | |||
2065 | { | |||
2066 | ||||
2067 | bool bTryAgain = true; | |||
2068 | while( bTryAgain ) | |||
2069 | { | |||
2070 | if (xDialog->run() == RET_OK) | |||
2071 | { | |||
2072 | try | |||
2073 | { | |||
2074 | OUString sNewName; | |||
2075 | if ( eType == E_TABLE ) | |||
2076 | { | |||
2077 | OUString sName = xDialog->getName(); | |||
2078 | OUString sCatalog = xDialog->getCatalog(); | |||
2079 | OUString sSchema = xDialog->getSchema(); | |||
2080 | ||||
2081 | sNewName = ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sName, false, ::dbtools::EComposeRule::InDataManipulation ); | |||
2082 | } | |||
2083 | else | |||
2084 | sNewName = xDialog->getName(); | |||
2085 | ||||
2086 | OUString sOldName = *aList.begin(); | |||
2087 | if ( eType == E_FORM || eType == E_REPORT ) | |||
2088 | { | |||
2089 | Reference<XContent> xContent(xRename,UNO_QUERY); | |||
2090 | if ( xContent.is() ) | |||
2091 | { | |||
2092 | sOldName = xContent->getIdentifier()->getContentIdentifier(); | |||
2093 | } | |||
2094 | } | |||
2095 | ||||
2096 | xRename->rename(sNewName); | |||
2097 | ||||
2098 | if ( eType == E_TABLE ) | |||
2099 | { | |||
2100 | Reference<XPropertySet> xProp(xRename,UNO_QUERY); | |||
2101 | sNewName = ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::EComposeRule::InDataManipulation, false ); | |||
2102 | } | |||
2103 | getContainer()->elementReplaced( eType , sOldName, sNewName ); | |||
2104 | ||||
2105 | bTryAgain = false; | |||
2106 | } | |||
2107 | catch(const SQLException& ) | |||
2108 | { | |||
2109 | showError( SQLExceptionInfo( ::cppu::getCaughtException() ) ); | |||
2110 | ||||
2111 | } | |||
2112 | catch(const ElementExistException& e) | |||
2113 | { | |||
2114 | OUString sMsg(DBA_RES(STR_NAME_ALREADY_EXISTS)::dbaccess::ResourceManager::loadString( reinterpret_cast< char const *>("STR_NAME_ALREADY_EXISTS" "\004" u8"The name \"#\" already exists." ) )); | |||
2115 | showError(SQLExceptionInfo(SQLException(sMsg.replaceAll("#", e.Message), e.Context, "S1000", 0, Any()))); | |||
2116 | } | |||
2117 | catch(const Exception& ) | |||
2118 | { | |||
2119 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2119" ": ", "dbaccess" );; | |||
2120 | } | |||
2121 | } | |||
2122 | else | |||
2123 | bTryAgain = false; | |||
2124 | } | |||
2125 | } | |||
2126 | } | |||
2127 | } | |||
2128 | catch(const Exception& ) | |||
2129 | { | |||
2130 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2130" ": ", "dbaccess" );; | |||
2131 | } | |||
2132 | } | |||
2133 | ||||
2134 | void OApplicationController::onSelectionChanged() | |||
2135 | { | |||
2136 | InvalidateAll(); | |||
2137 | ||||
2138 | SelectionGuard aSelGuard( *m_pSelectionNotifier ); | |||
2139 | ||||
2140 | OApplicationView* pView = getContainer(); | |||
2141 | if ( !pView ) | |||
2142 | return; | |||
2143 | ||||
2144 | if ( pView->getSelectionCount() == 1 ) | |||
2145 | { | |||
2146 | const ElementType eType = pView->getElementType(); | |||
2147 | if ( pView->isALeafSelected() ) | |||
2148 | { | |||
2149 | const OUString sName = pView->getQualifiedName( nullptr /* means 'first selected' */ ); | |||
2150 | showPreviewFor( eType, sName ); | |||
2151 | } | |||
2152 | } | |||
2153 | } | |||
2154 | ||||
2155 | void OApplicationController::showPreviewFor(const ElementType _eType,const OUString& _sName) | |||
2156 | { | |||
2157 | if ( m_ePreviewMode == E_PREVIEWNONE ) | |||
2158 | return; | |||
2159 | ||||
2160 | OApplicationView* pView = getContainer(); | |||
2161 | if ( !pView ) | |||
2162 | return; | |||
2163 | ||||
2164 | try | |||
2165 | { | |||
2166 | switch( _eType ) | |||
2167 | { | |||
2168 | case E_FORM: | |||
2169 | case E_REPORT: | |||
2170 | { | |||
2171 | Reference< XHierarchicalNameAccess > xContainer( getElements( _eType ), UNO_QUERY_THROW ); | |||
2172 | Reference< XContent> xContent( xContainer->getByHierarchicalName( _sName ), UNO_QUERY_THROW ); | |||
2173 | pView->showPreview( xContent ); | |||
2174 | } | |||
2175 | break; | |||
2176 | ||||
2177 | case E_TABLE: | |||
2178 | case E_QUERY: | |||
2179 | { | |||
2180 | SharedConnection xConnection( ensureConnection() ); | |||
2181 | if ( xConnection.is() ) | |||
2182 | pView->showPreview( getDatabaseName(), xConnection, _sName, _eType == E_TABLE ); | |||
2183 | } | |||
2184 | return; | |||
2185 | ||||
2186 | default: | |||
2187 | OSL_FAIL( "OApplicationController::showPreviewFor: unexpected element type!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2187" ": "), "%s", "OApplicationController::showPreviewFor: unexpected element type!" ); } } while (false); | |||
2188 | break; | |||
2189 | } | |||
2190 | } | |||
2191 | catch( const SQLException& ) | |||
2192 | { | |||
2193 | showError( SQLExceptionInfo( ::cppu::getCaughtException() ) ); | |||
2194 | } | |||
2195 | catch(const Exception& ) | |||
2196 | { | |||
2197 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2197" ": ", "dbaccess" );; | |||
2198 | } | |||
2199 | } | |||
2200 | ||||
2201 | IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper*, void)void OApplicationController::LinkStubOnClipboardChanged(void * instance, TransferableDataHelper* data) { return static_cast <OApplicationController *>(instance)->OnClipboardChanged (data); } void OApplicationController::OnClipboardChanged(__attribute__ ((unused)) TransferableDataHelper*) | |||
2202 | { | |||
2203 | OnInvalidateClipboard(); | |||
2204 | } | |||
2205 | ||||
2206 | void OApplicationController::OnInvalidateClipboard() | |||
2207 | { | |||
2208 | InvalidateFeature(ID_BROWSER_CUT(5000 + 710)); | |||
2209 | InvalidateFeature(ID_BROWSER_COPY(5000 + 711)); | |||
2210 | InvalidateFeature(ID_BROWSER_PASTE(5000 + 712)); | |||
2211 | InvalidateFeature(SID_DB_APP_PASTE_SPECIAL( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 55 )); | |||
2212 | } | |||
2213 | ||||
2214 | void OApplicationController::onCopyEntry() | |||
2215 | { | |||
2216 | Execute(ID_BROWSER_COPY(5000 + 711),Sequence<PropertyValue>()); | |||
2217 | } | |||
2218 | ||||
2219 | void OApplicationController::onPasteEntry() | |||
2220 | { | |||
2221 | Execute(ID_BROWSER_PASTE(5000 + 712),Sequence<PropertyValue>()); | |||
2222 | } | |||
2223 | ||||
2224 | void OApplicationController::onDeleteEntry() | |||
2225 | { | |||
2226 | ElementType eType = getContainer()->getElementType(); | |||
2227 | sal_uInt16 nId = 0; | |||
2228 | switch(eType) | |||
2229 | { | |||
2230 | case E_TABLE: | |||
2231 | nId = SID_DB_APP_TABLE_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 24 ); | |||
2232 | break; | |||
2233 | case E_QUERY: | |||
2234 | nId = SID_DB_APP_QUERY_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 28 ); | |||
2235 | break; | |||
2236 | case E_FORM: | |||
2237 | nId = SID_DB_APP_FORM_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 32 ); | |||
2238 | break; | |||
2239 | case E_REPORT: | |||
2240 | nId = SID_DB_APP_REPORT_DELETE( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 36 ); | |||
2241 | break; | |||
2242 | default: | |||
2243 | OSL_FAIL("Invalid ElementType!")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2243" ": "), "%s", "Invalid ElementType!"); } } while ( false); | |||
2244 | break; | |||
2245 | } | |||
2246 | executeChecked(nId,Sequence<PropertyValue>()); | |||
2247 | } | |||
2248 | ||||
2249 | OUString OApplicationController::getContextMenuResourceName() const | |||
2250 | { | |||
2251 | return "edit"; | |||
2252 | } | |||
2253 | ||||
2254 | IController& OApplicationController::getCommandController() | |||
2255 | { | |||
2256 | return *this; | |||
2257 | } | |||
2258 | ||||
2259 | ::comphelper::OInterfaceContainerHelper2* OApplicationController::getContextMenuInterceptors() | |||
2260 | { | |||
2261 | return &m_aContextMenuInterceptors; | |||
2262 | } | |||
2263 | ||||
2264 | Any OApplicationController::getCurrentSelection(weld::TreeView& rControl) const | |||
2265 | { | |||
2266 | Sequence< NamedDatabaseObject > aSelection; | |||
2267 | getContainer()->describeCurrentSelectionForControl(rControl, aSelection); | |||
2268 | return makeAny( aSelection ); | |||
2269 | } | |||
2270 | ||||
2271 | vcl::Window* OApplicationController::getMenuParent() const | |||
2272 | { | |||
2273 | return getContainer()->getMenuParent(); | |||
2274 | } | |||
2275 | ||||
2276 | void OApplicationController::adjustMenuPosition(const weld::TreeView& rControl, ::Point& rPos) const | |||
2277 | { | |||
2278 | getContainer()->adjustMenuPosition(rControl, rPos); | |||
2279 | } | |||
2280 | ||||
2281 | bool OApplicationController::requestQuickHelp(const void* /*pUserData*/, OUString& /*rText*/) const | |||
2282 | { | |||
2283 | return false; | |||
2284 | } | |||
2285 | ||||
2286 | bool OApplicationController::requestDrag(const weld::TreeIter& /*rEntry*/) | |||
2287 | { | |||
2288 | bool bSuccess = false; | |||
2289 | rtl::Reference<TransferableHelper> pTransfer; | |||
2290 | ||||
2291 | OApplicationView* pContainer = getContainer(); | |||
2292 | if (pContainer && pContainer->getSelectionCount()) | |||
2293 | { | |||
2294 | try | |||
2295 | { | |||
2296 | if (getContainer()->getDetailView()) | |||
2297 | { | |||
2298 | TreeListBox* pTreeListBox = getContainer()->getDetailView()->getTreeWindow(); | |||
2299 | ||||
2300 | ElementType eType = getContainer()->getElementType(); | |||
2301 | if (eType == E_TABLE || eType == E_QUERY) | |||
2302 | { | |||
2303 | ODataClipboard& rExchange = static_cast<ODataClipboard&>(pTreeListBox->GetDataTransfer()); | |||
2304 | bSuccess = copySQLObject(rExchange); | |||
2305 | } | |||
2306 | else | |||
2307 | { | |||
2308 | svx::OComponentTransferable& rExchange = static_cast<svx::OComponentTransferable&>(pTreeListBox->GetDataTransfer()); | |||
2309 | bSuccess = copyDocObject(rExchange); | |||
2310 | } | |||
2311 | } | |||
2312 | } | |||
2313 | catch(const Exception& ) | |||
2314 | { | |||
2315 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2315" ": ", "dbaccess" );; | |||
2316 | } | |||
2317 | } | |||
2318 | ||||
2319 | return bSuccess; | |||
2320 | } | |||
2321 | ||||
2322 | sal_Int8 OApplicationController::queryDrop( const AcceptDropEvent& _rEvt, const DataFlavorExVector& _rFlavors ) | |||
2323 | { | |||
2324 | sal_Int8 nActionAskedFor = _rEvt.mnAction; | |||
2325 | // check if we're a table or query container | |||
2326 | OApplicationView* pView = getContainer(); | |||
2327 | if ( pView && !isDataSourceReadOnly() ) | |||
2328 | { | |||
2329 | ElementType eType = pView->getElementType(); | |||
2330 | if ( eType != E_NONE && (eType != E_TABLE || !isConnectionReadOnly()) ) | |||
2331 | { | |||
2332 | // check for the concrete type | |||
2333 | if(std::any_of(_rFlavors.begin(),_rFlavors.end(),TAppSupportedSotFunctor(eType))) | |||
2334 | return DND_ACTION_COPYcss::datatransfer::dnd::DNDConstants::ACTION_COPY; | |||
2335 | if ( eType == E_FORM || eType == E_REPORT ) | |||
2336 | { | |||
2337 | sal_Int8 nAction = OComponentTransferable::canExtractComponentDescriptor(_rFlavors,eType == E_FORM) ? DND_ACTION_COPYcss::datatransfer::dnd::DNDConstants::ACTION_COPY : DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE; | |||
2338 | if ( nAction != DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE ) | |||
2339 | { | |||
2340 | auto xHitEntry = pView->getEntry(_rEvt.maPosPixel); | |||
2341 | if (xHitEntry) | |||
2342 | { | |||
2343 | OUString sName = pView->getQualifiedName(xHitEntry.get()); | |||
2344 | if ( !sName.isEmpty() ) | |||
2345 | { | |||
2346 | Reference< XHierarchicalNameAccess > xContainer(getElements(pView->getElementType()),UNO_QUERY); | |||
2347 | if ( xContainer.is() && xContainer->hasByHierarchicalName(sName) ) | |||
2348 | { | |||
2349 | Reference< XHierarchicalNameAccess > xHitObject(xContainer->getByHierarchicalName(sName),UNO_QUERY); | |||
2350 | if ( xHitObject.is() ) | |||
2351 | nAction = nActionAskedFor & DND_ACTION_COPYMOVEcss::datatransfer::dnd::DNDConstants::ACTION_COPY_OR_MOVE; | |||
2352 | } | |||
2353 | else | |||
2354 | nAction = DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE; | |||
2355 | } | |||
2356 | } | |||
2357 | } | |||
2358 | return nAction; | |||
2359 | } | |||
2360 | } | |||
2361 | } | |||
2362 | ||||
2363 | return DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE; | |||
2364 | } | |||
2365 | ||||
2366 | sal_Int8 OApplicationController::executeDrop( const ExecuteDropEvent& _rEvt ) | |||
2367 | { | |||
2368 | OApplicationView* pView = getContainer(); | |||
2369 | if ( !pView || pView->getElementType() == E_NONE ) | |||
2370 | { | |||
2371 | OSL_FAIL("OApplicationController::executeDrop: what the hell did queryDrop do?")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2371" ": "), "%s", "OApplicationController::executeDrop: what the hell did queryDrop do?" ); } } while (false); | |||
2372 | // queryDrop should not have allowed us to reach this situation... | |||
2373 | return DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE; | |||
2374 | } | |||
2375 | ||||
2376 | // a TransferableDataHelper for accessing the dropped data | |||
2377 | TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable); | |||
2378 | ||||
2379 | // reset the data of the previous async drop (if any) | |||
2380 | if ( m_nAsyncDrop ) | |||
2381 | Application::RemoveUserEvent(m_nAsyncDrop); | |||
2382 | ||||
2383 | m_nAsyncDrop = nullptr; | |||
2384 | m_aAsyncDrop.aDroppedData.clear(); | |||
2385 | m_aAsyncDrop.nType = pView->getElementType(); | |||
2386 | m_aAsyncDrop.nAction = _rEvt.mnAction; | |||
2387 | m_aAsyncDrop.bError = false; | |||
2388 | m_aAsyncDrop.bHtml = false; | |||
2389 | m_aAsyncDrop.aUrl.clear(); | |||
2390 | ||||
2391 | // loop through the available formats and see what we can do... | |||
2392 | // first we have to check if it is our own format, if not we have to copy the stream :-( | |||
2393 | if ( ODataAccessObjectTransferable::canExtractObjectDescriptor(aDroppedData.GetDataFlavorExVector()) ) | |||
2394 | { | |||
2395 | m_aAsyncDrop.aDroppedData = ODataAccessObjectTransferable::extractObjectDescriptor(aDroppedData); | |||
2396 | ||||
2397 | // asynchron because we some dialogs and we aren't allowed to show them while in D&D | |||
2398 | m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop)::tools::detail::makeLink( ::tools::detail::castTo<OApplicationController *>(this), &OApplicationController::LinkStubOnAsyncDrop )); | |||
2399 | return DND_ACTION_COPYcss::datatransfer::dnd::DNDConstants::ACTION_COPY; | |||
2400 | } | |||
2401 | else if ( OComponentTransferable::canExtractComponentDescriptor(aDroppedData.GetDataFlavorExVector(),m_aAsyncDrop.nType == E_FORM) ) | |||
2402 | { | |||
2403 | m_aAsyncDrop.aDroppedData = OComponentTransferable::extractComponentDescriptor(aDroppedData); | |||
2404 | auto xHitEntry = pView->getEntry(_rEvt.maPosPixel); | |||
2405 | if ( xHitEntry ) | |||
2406 | m_aAsyncDrop.aUrl = pView->getQualifiedName(xHitEntry.get()); | |||
2407 | ||||
2408 | sal_Int8 nAction = _rEvt.mnAction; | |||
2409 | Reference<XContent> xContent; | |||
2410 | m_aAsyncDrop.aDroppedData[DataAccessDescriptorProperty::Component] >>= xContent; | |||
2411 | if ( xContent.is() ) | |||
2412 | { | |||
2413 | OUString sName = xContent->getIdentifier()->getContentIdentifier(); | |||
2414 | sName = sName.copy(sName.indexOf('/') + 1); | |||
2415 | if ( m_aAsyncDrop.aUrl.getLength() >= sName.getLength() && m_aAsyncDrop.aUrl.startsWith(sName) ) | |||
2416 | { | |||
2417 | m_aAsyncDrop.aDroppedData.clear(); | |||
2418 | return DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE; | |||
2419 | } | |||
2420 | ||||
2421 | // check if move is allowed, if another object with the same name exists only copy is allowed | |||
2422 | Reference< XHierarchicalNameAccess > xContainer(getElements(m_aAsyncDrop.nType),UNO_QUERY); | |||
2423 | Reference<XNameAccess> xNameAccess(xContainer,UNO_QUERY); | |||
2424 | ||||
2425 | if ( !m_aAsyncDrop.aUrl.isEmpty() && xContainer.is() && xContainer->hasByHierarchicalName(m_aAsyncDrop.aUrl) ) | |||
2426 | xNameAccess.set(xContainer->getByHierarchicalName(m_aAsyncDrop.aUrl),UNO_QUERY); | |||
2427 | ||||
2428 | if ( xNameAccess.is() ) | |||
2429 | { | |||
2430 | Reference<XPropertySet> xProp(xContent,UNO_QUERY); | |||
2431 | if ( xProp.is() ) | |||
2432 | { | |||
2433 | xProp->getPropertyValue(PROPERTY_NAME"Name") >>= sName; | |||
2434 | if ( xNameAccess.is() && xNameAccess->hasByName(sName) ) | |||
2435 | nAction &= ~DND_ACTION_MOVEcss::datatransfer::dnd::DNDConstants::ACTION_MOVE; | |||
2436 | } | |||
2437 | else | |||
2438 | nAction &= ~DND_ACTION_MOVEcss::datatransfer::dnd::DNDConstants::ACTION_MOVE; | |||
2439 | } | |||
2440 | } | |||
2441 | if ( nAction != DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE ) | |||
2442 | { | |||
2443 | m_aAsyncDrop.nAction = nAction; | |||
2444 | // asynchron because we some dialogs and we aren't allowed to show them while in D&D | |||
2445 | m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop)::tools::detail::makeLink( ::tools::detail::castTo<OApplicationController *>(this), &OApplicationController::LinkStubOnAsyncDrop )); | |||
2446 | } | |||
2447 | else | |||
2448 | m_aAsyncDrop.aDroppedData.clear(); | |||
2449 | return nAction; | |||
2450 | } | |||
2451 | else | |||
2452 | { | |||
2453 | SharedConnection xConnection( ensureConnection() ); | |||
2454 | if ( xConnection.is() && m_aTableCopyHelper.copyTagTable( aDroppedData, m_aAsyncDrop, xConnection ) ) | |||
2455 | { | |||
2456 | // asynchron because we some dialogs and we aren't allowed to show them while in D&D | |||
2457 | m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop)::tools::detail::makeLink( ::tools::detail::castTo<OApplicationController *>(this), &OApplicationController::LinkStubOnAsyncDrop )); | |||
2458 | return DND_ACTION_COPYcss::datatransfer::dnd::DNDConstants::ACTION_COPY; | |||
2459 | } | |||
2460 | } | |||
2461 | ||||
2462 | return DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE; | |||
2463 | } | |||
2464 | ||||
2465 | Reference< XModel > SAL_CALL OApplicationController::getModel() | |||
2466 | { | |||
2467 | return m_xModel; | |||
2468 | } | |||
2469 | ||||
2470 | void OApplicationController::onAttachedFrame() | |||
2471 | { | |||
2472 | sal_Int32 nConnectedControllers( 0 ); | |||
2473 | try | |||
2474 | { | |||
2475 | Reference< XModel2 > xModel( m_xModel, UNO_QUERY_THROW ); | |||
2476 | Reference< XEnumeration > xEnumControllers( xModel->getControllers(), UNO_SET_THROW ); | |||
2477 | while ( xEnumControllers->hasMoreElements() ) | |||
2478 | { | |||
2479 | Reference< XController > xController( xEnumControllers->nextElement(), UNO_QUERY_THROW ); | |||
2480 | ++nConnectedControllers; | |||
2481 | } | |||
2482 | } | |||
2483 | catch( const Exception& ) | |||
2484 | { | |||
2485 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2485" ": ", "dbaccess" );; | |||
2486 | } | |||
2487 | ||||
2488 | if ( nConnectedControllers > 1 ) | |||
2489 | { // we are not the first connected controller, there were already others | |||
2490 | return; | |||
2491 | } | |||
2492 | ||||
2493 | OnFirstControllerConnected(); | |||
2494 | } | |||
2495 | ||||
2496 | void OApplicationController::OnFirstControllerConnected() | |||
2497 | { | |||
2498 | if ( !m_xModel.is() ) | |||
2499 | { | |||
2500 | OSL_FAIL( "OApplicationController::OnFirstControllerConnected: too late!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2500" ": "), "%s", "OApplicationController::OnFirstControllerConnected: too late!" ); } } while (false); | |||
2501 | } | |||
2502 | ||||
2503 | // if we have forms or reports which contain macros/scripts, then show a warning | |||
2504 | // which suggests the user to migrate them to the database document | |||
2505 | Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY ); | |||
2506 | if ( xDocumentScripts.is() ) | |||
2507 | { | |||
2508 | // no need to show this warning, obviously the document supports embedding scripts | |||
2509 | // into itself, so there are no "old-style" forms/reports which have macros/scripts | |||
2510 | // themselves | |||
2511 | return; | |||
2512 | } | |||
2513 | ||||
2514 | try | |||
2515 | { | |||
2516 | // If the migration just happened, but was not successful, the document is reloaded. | |||
2517 | // In this case, we should not show the warning, again. | |||
2518 | ::comphelper::NamedValueCollection aModelArgs( m_xModel->getArgs() ); | |||
2519 | if ( aModelArgs.getOrDefault( "SuppressMigrationWarning", false ) ) | |||
2520 | return; | |||
2521 | ||||
2522 | // also, if the document is read-only, then no migration is possible, and the | |||
2523 | // respective menu entry is hidden. So, don't show the warning in this case, too. | |||
2524 | if ( Reference< XStorable >( m_xModel, UNO_QUERY_THROW )->isReadonly() ) | |||
2525 | return; | |||
2526 | ||||
2527 | SQLWarning aWarning; | |||
2528 | aWarning.Message = DBA_RES(STR_SUB_DOCS_WITH_SCRIPTS)::dbaccess::ResourceManager::loadString( reinterpret_cast< char const *>("STR_SUB_DOCS_WITH_SCRIPTS" "\004" u8"The document contains forms or reports with embedded macros." ) ); | |||
2529 | SQLException aDetail; | |||
2530 | aDetail.Message = DBA_RES(STR_SUB_DOCS_WITH_SCRIPTS_DETAIL)::dbaccess::ResourceManager::loadString( reinterpret_cast< char const *>("STR_SUB_DOCS_WITH_SCRIPTS_DETAIL" "\004" u8"Macros should be embedded into the database document itself.\n\n" "You can continue to use your document as before, however, you are encouraged to migrate " "your macros. The menu item 'Tools / Migrate Macros ...' will assist you with this.\n\n" "Note that you won't be able to embed macros into the database document itself until " "this migration is done. ") ); | |||
2531 | aWarning.NextException <<= aDetail; | |||
2532 | ||||
2533 | Reference< XExecutableDialog > xDialog = ErrorMessageDialog::create( getORB(), "", nullptr, makeAny( aWarning ) ); | |||
2534 | xDialog->execute(); | |||
2535 | } | |||
2536 | catch( const Exception& ) | |||
2537 | { | |||
2538 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2538" ": ", "dbaccess" );; | |||
2539 | } | |||
2540 | } | |||
2541 | ||||
2542 | void SAL_CALL OApplicationController::attachFrame( const Reference< XFrame > & i_rxFrame ) | |||
2543 | { | |||
2544 | SolarMutexGuard aSolarGuard; // avoid deadlock in XModel calls | |||
2545 | ::osl::MutexGuard aGuard( getMutex() ); | |||
2546 | ||||
2547 | OGenericUnoController::attachFrame( i_rxFrame ); | |||
2548 | if ( getFrame().is() ) | |||
2549 | onAttachedFrame(); | |||
2550 | } | |||
2551 | ||||
2552 | sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > & _rxModel) | |||
2553 | { | |||
2554 | ::osl::MutexGuard aGuard( getMutex() ); | |||
2555 | const Reference< XOfficeDatabaseDocument > xOfficeDoc( _rxModel, UNO_QUERY ); | |||
2556 | const Reference< XModifiable > xDocModify( _rxModel, UNO_QUERY ); | |||
2557 | if ( ( !xOfficeDoc.is() || !xDocModify.is() ) && _rxModel.is() ) | |||
2558 | { | |||
2559 | OSL_FAIL( "OApplicationController::attachModel: invalid model!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2559" ": "), "%s", "OApplicationController::attachModel: invalid model!" ); } } while (false); | |||
2560 | return false; | |||
2561 | } | |||
2562 | ||||
2563 | if ( m_xModel.is() && ( m_xModel != _rxModel ) && ( _rxModel.is() ) ) | |||
2564 | { | |||
2565 | OSL_ENSURE( false, "OApplicationController::attachModel: missing implementation: setting a new model while we have another one!" )do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2565" ": "), "%s", "OApplicationController::attachModel: missing implementation: setting a new model while we have another one!" ); } } while (false); | |||
2566 | // we'd need to completely update our view here, close sub components, and the like | |||
2567 | return false; | |||
2568 | } | |||
2569 | ||||
2570 | const OUString aPropertyNames[] = | |||
2571 | { | |||
2572 | OUString(PROPERTY_URL"URL"), OUString(PROPERTY_USER"User") | |||
2573 | }; | |||
2574 | ||||
2575 | // disconnect from old model | |||
2576 | try | |||
2577 | { | |||
2578 | if ( m_xDataSource.is() ) | |||
2579 | { | |||
2580 | for (const auto & aPropertyName : aPropertyNames) | |||
2581 | { | |||
2582 | m_xDataSource->removePropertyChangeListener( aPropertyName, this ); | |||
2583 | } | |||
2584 | } | |||
2585 | ||||
2586 | Reference< XModifyBroadcaster > xBroadcaster( m_xModel, UNO_QUERY ); | |||
2587 | if ( xBroadcaster.is() ) | |||
2588 | xBroadcaster->removeModifyListener( this ); | |||
2589 | } | |||
2590 | catch( const Exception& ) | |||
2591 | { | |||
2592 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2592" ": ", "dbaccess" );; | |||
2593 | } | |||
2594 | ||||
2595 | m_xModel = _rxModel; | |||
2596 | m_xDataSource.set( xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference< XDataSource >(), UNO_QUERY ); | |||
2597 | ||||
2598 | // connect to new model | |||
2599 | try | |||
2600 | { | |||
2601 | if ( m_xDataSource.is() ) | |||
2602 | { | |||
2603 | for (const auto & aPropertyName : aPropertyNames) | |||
2604 | { | |||
2605 | m_xDataSource->addPropertyChangeListener( aPropertyName, this ); | |||
2606 | } | |||
2607 | } | |||
2608 | ||||
2609 | Reference< XModifyBroadcaster > xBroadcaster( m_xModel, UNO_QUERY_THROW ); | |||
2610 | xBroadcaster->addModifyListener( this ); | |||
2611 | ||||
2612 | } | |||
2613 | catch( const Exception& ) | |||
2614 | { | |||
2615 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2615" ": ", "dbaccess" );; | |||
2616 | } | |||
2617 | ||||
2618 | // initial preview mode | |||
2619 | if ( m_xDataSource.is() ) | |||
2620 | { | |||
2621 | try | |||
2622 | { | |||
2623 | // to get the 'modified' for the data source | |||
2624 | ::comphelper::NamedValueCollection aLayoutInfo( m_xDataSource->getPropertyValue( PROPERTY_LAYOUTINFORMATION"LayoutInformation" ) ); | |||
2625 | if ( aLayoutInfo.has( OUString(INFO_PREVIEW"Preview") ) ) | |||
2626 | { | |||
2627 | const sal_Int32 nPreviewMode( aLayoutInfo.getOrDefault( INFO_PREVIEW"Preview", sal_Int32(0) ) ); | |||
2628 | m_ePreviewMode = static_cast< PreviewMode >( nPreviewMode ); | |||
2629 | if ( getView() ) | |||
2630 | getContainer()->switchPreview( m_ePreviewMode ); | |||
2631 | } | |||
2632 | } | |||
2633 | catch( const Exception& ) | |||
2634 | { | |||
2635 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2635" ": ", "dbaccess" );; | |||
2636 | } | |||
2637 | } | |||
2638 | ||||
2639 | return true; | |||
2640 | } | |||
2641 | ||||
2642 | void OApplicationController::containerFound( const Reference< XContainer >& _xContainer) | |||
2643 | { | |||
2644 | try | |||
2645 | { | |||
2646 | if ( _xContainer.is() ) | |||
2647 | { | |||
2648 | m_aCurrentContainers.push_back(_xContainer); | |||
2649 | _xContainer->addContainerListener(this); | |||
2650 | } | |||
2651 | } | |||
2652 | catch(const Exception&) | |||
2653 | { | |||
2654 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2654" ": ", "dbaccess" );; | |||
2655 | } | |||
2656 | } | |||
2657 | ||||
2658 | OUString OApplicationController::getCurrentlySelectedName(sal_Int32& _rnCommandType) const | |||
2659 | { | |||
2660 | _rnCommandType = ( (getContainer()->getElementType() == E_QUERY) | |||
2661 | ? CommandType::QUERY : ( (getContainer()->getElementType() == E_TABLE) ? CommandType::TABLE : -1 )); | |||
2662 | ||||
2663 | OUString sName; | |||
2664 | if ( _rnCommandType != -1 ) | |||
2665 | { | |||
2666 | try | |||
2667 | { | |||
2668 | sName = getContainer()->getQualifiedName( nullptr ); | |||
2669 | OSL_ENSURE( !sName.isEmpty(), "OApplicationController::getCurrentlySelectedName: no name given!" )do { if (true && (!(!sName.isEmpty()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2669" ": "), "%s", "OApplicationController::getCurrentlySelectedName: no name given!" ); } } while (false); | |||
2670 | } | |||
2671 | catch( const Exception& ) | |||
2672 | { | |||
2673 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2673" ": ", "dbaccess" );; | |||
2674 | } | |||
2675 | } | |||
2676 | return sName; | |||
2677 | } | |||
2678 | ||||
2679 | void SAL_CALL OApplicationController::addSelectionChangeListener( const Reference< view::XSelectionChangeListener >& Listener ) | |||
2680 | { | |||
2681 | m_pSelectionNotifier->addListener( Listener ); | |||
2682 | } | |||
2683 | ||||
2684 | void SAL_CALL OApplicationController::removeSelectionChangeListener( const Reference< view::XSelectionChangeListener >& Listener ) | |||
2685 | { | |||
2686 | m_pSelectionNotifier->removeListener( Listener ); | |||
2687 | } | |||
2688 | ||||
2689 | sal_Bool SAL_CALL OApplicationController::select( const Any& _aSelection ) | |||
2690 | { | |||
2691 | SolarMutexGuard aSolarGuard; | |||
2692 | ::osl::MutexGuard aGuard( getMutex() ); | |||
2693 | Sequence< OUString> aSelection; | |||
2694 | if ( !_aSelection.hasValue() || !getView() ) | |||
2695 | { | |||
2696 | getContainer()->selectElements(aSelection); | |||
2697 | return true; | |||
2698 | } | |||
2699 | ||||
2700 | // BEGIN compatibility | |||
2701 | Sequence< NamedValue > aCurrentSelection; | |||
2702 | if ( (_aSelection >>= aCurrentSelection) && aCurrentSelection.hasElements() ) | |||
2703 | { | |||
2704 | ElementType eType = E_NONE; | |||
2705 | const NamedValue* pIter = aCurrentSelection.getConstArray(); | |||
2706 | const NamedValue* pEnd = pIter + aCurrentSelection.getLength(); | |||
2707 | for(;pIter != pEnd;++pIter) | |||
2708 | { | |||
2709 | if ( pIter->Name == "Type" ) | |||
2710 | { | |||
2711 | sal_Int32 nType = 0; | |||
2712 | pIter->Value >>= nType; | |||
2713 | if ( nType < DatabaseObject::TABLE || nType > DatabaseObject::REPORT ) | |||
2714 | throw IllegalArgumentException(); | |||
2715 | eType = static_cast< ElementType >( nType ); | |||
2716 | } | |||
2717 | else if ( pIter->Name == "Selection" ) | |||
2718 | pIter->Value >>= aSelection; | |||
2719 | } | |||
2720 | ||||
2721 | m_aSelectContainerEvent.CancelCall(); // just in case the async select request was running | |||
2722 | getContainer()->selectContainer(eType); | |||
2723 | getContainer()->selectElements(aSelection); | |||
2724 | return true; | |||
2725 | } | |||
2726 | // END compatibility | |||
2727 | ||||
2728 | Sequence< NamedDatabaseObject > aSelectedObjects; | |||
2729 | if ( !( _aSelection >>= aSelectedObjects ) ) | |||
2730 | { | |||
2731 | aSelectedObjects.realloc( 1 ); | |||
2732 | if ( !( _aSelection >>= aSelectedObjects[0] ) ) | |||
2733 | throw IllegalArgumentException(); | |||
2734 | } | |||
2735 | ||||
2736 | SelectionByElementType aSelectedElements; | |||
2737 | ElementType eSelectedCategory = E_NONE; | |||
2738 | for ( const NamedDatabaseObject* pObject = aSelectedObjects.getConstArray(); | |||
2739 | pObject != aSelectedObjects.getConstArray() + aSelectedObjects.getLength(); | |||
2740 | ++pObject | |||
2741 | ) | |||
2742 | { | |||
2743 | switch ( pObject->Type ) | |||
2744 | { | |||
2745 | case DatabaseObject::TABLE: | |||
2746 | case DatabaseObjectContainer::SCHEMA: | |||
2747 | case DatabaseObjectContainer::CATALOG: | |||
2748 | aSelectedElements[ E_TABLE ].push_back( pObject->Name ); | |||
2749 | break; | |||
2750 | case DatabaseObject::QUERY: | |||
2751 | aSelectedElements[ E_QUERY ].push_back( pObject->Name ); | |||
2752 | break; | |||
2753 | case DatabaseObject::FORM: | |||
2754 | case DatabaseObjectContainer::FORMS_FOLDER: | |||
2755 | aSelectedElements[ E_FORM ].push_back( pObject->Name ); | |||
2756 | break; | |||
2757 | case DatabaseObject::REPORT: | |||
2758 | case DatabaseObjectContainer::REPORTS_FOLDER: | |||
2759 | aSelectedElements[ E_REPORT ].push_back( pObject->Name ); | |||
2760 | break; | |||
2761 | case DatabaseObjectContainer::TABLES: | |||
2762 | case DatabaseObjectContainer::QUERIES: | |||
2763 | case DatabaseObjectContainer::FORMS: | |||
2764 | case DatabaseObjectContainer::REPORTS: | |||
2765 | if ( eSelectedCategory != E_NONE ) | |||
2766 | throw IllegalArgumentException( | |||
2767 | DBA_RES(RID_STR_NO_DIFF_CAT)::dbaccess::ResourceManager::loadString( reinterpret_cast< char const *>("RID_STR_NO_DIFF_CAT" "\004" u8"You cannot select different categories." ) ), | |||
2768 | *this, sal_Int16( pObject - aSelectedObjects.getConstArray() ) ); | |||
2769 | eSelectedCategory = | |||
2770 | ( pObject->Type == DatabaseObjectContainer::TABLES ) ? E_TABLE | |||
2771 | : ( pObject->Type == DatabaseObjectContainer::QUERIES ) ? E_QUERY | |||
2772 | : ( pObject->Type == DatabaseObjectContainer::FORMS ) ? E_FORM | |||
2773 | : ( pObject->Type == DatabaseObjectContainer::REPORTS ) ? E_REPORT | |||
2774 | : E_NONE; | |||
2775 | break; | |||
2776 | ||||
2777 | default: | |||
2778 | case DatabaseObjectContainer::DATA_SOURCE: | |||
2779 | { | |||
2780 | OUString sMessage( | |||
2781 | DBA_RES(RID_STR_UNSUPPORTED_OBJECT_TYPE)::dbaccess::ResourceManager::loadString( reinterpret_cast< char const *>("RID_STR_UNSUPPORTED_OBJECT_TYPE" "\004" u8"Unsupported object type found ($type$)." ) ). | |||
2782 | replaceFirst("$type$", OUString::number(pObject->Type))); | |||
2783 | throw IllegalArgumentException(sMessage, *this, sal_Int16( pObject - aSelectedObjects.getConstArray() )); | |||
2784 | } | |||
2785 | } | |||
2786 | } | |||
2787 | for (auto const& selectedElement : aSelectedElements) | |||
2788 | { | |||
2789 | if ( selectedElement.first == m_eCurrentType ) | |||
2790 | { | |||
2791 | getContainer()->selectElements( comphelper::containerToSequence(selectedElement.second) ); | |||
2792 | } | |||
2793 | else | |||
2794 | { | |||
2795 | m_aPendingSelection[ selectedElement.first ] = selectedElement.second; | |||
2796 | } | |||
2797 | } | |||
2798 | ||||
2799 | m_aSelectContainerEvent.CancelCall(); // just in case the async select request was running | |||
2800 | getContainer()->selectContainer( eSelectedCategory ); | |||
2801 | ||||
2802 | return true; | |||
2803 | } | |||
2804 | ||||
2805 | Any SAL_CALL OApplicationController::getSelection( ) | |||
2806 | { | |||
2807 | SolarMutexGuard aSolarGuard; | |||
2808 | ::osl::MutexGuard aGuard( getMutex() ); | |||
2809 | ||||
2810 | Sequence< NamedDatabaseObject > aCurrentSelection; | |||
2811 | const ElementType eType( getContainer()->getElementType() ); | |||
2812 | if ( eType != E_NONE ) | |||
2813 | { | |||
2814 | getContainer()->describeCurrentSelectionForType( eType, aCurrentSelection ); | |||
2815 | if ( !aCurrentSelection.hasElements() ) | |||
2816 | { // if no objects are selected, add an entry to the sequence which describes the overall category | |||
2817 | // which is selected currently | |||
2818 | aCurrentSelection.realloc(1); | |||
2819 | aCurrentSelection[0].Name = getDatabaseName(); | |||
2820 | switch ( eType ) | |||
2821 | { | |||
2822 | case E_TABLE: aCurrentSelection[0].Type = DatabaseObjectContainer::TABLES; break; | |||
2823 | case E_QUERY: aCurrentSelection[0].Type = DatabaseObjectContainer::QUERIES; break; | |||
2824 | case E_FORM: aCurrentSelection[0].Type = DatabaseObjectContainer::FORMS; break; | |||
2825 | case E_REPORT: aCurrentSelection[0].Type = DatabaseObjectContainer::REPORTS; break; | |||
2826 | default: | |||
2827 | OSL_FAIL( "OApplicationController::getSelection: unexpected current element type!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/app/AppController.cxx" ":" "2827" ": "), "%s", "OApplicationController::getSelection: unexpected current element type!" ); } } while (false); | |||
2828 | break; | |||
2829 | } | |||
2830 | } | |||
2831 | } | |||
2832 | return makeAny( aCurrentSelection ); | |||
2833 | } | |||
2834 | ||||
2835 | } // namespace dbaui | |||
2836 | ||||
2837 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
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/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
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 . |
18 | */ |
19 | |
20 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||||||||||||||||
2 | /* | ||||||||||||||||
3 | * This file is part of the LibreOffice project. | ||||||||||||||||
4 | * | ||||||||||||||||
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/. | ||||||||||||||||
8 | * | ||||||||||||||||
9 | * This file incorporates work covered by the following license notice: | ||||||||||||||||
10 | * | ||||||||||||||||
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 . | ||||||||||||||||
18 | */ | ||||||||||||||||
19 | |||||||||||||||||
20 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||||||||||
22 | |||||||||||||||||
23 | #include "sal/config.h" | ||||||||||||||||
24 | |||||||||||||||||
25 | #include <cassert> | ||||||||||||||||
26 | #include <cstddef> | ||||||||||||||||
27 | #include <functional> | ||||||||||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||
29 | #include <type_traits> | ||||||||||||||||
30 | #endif | ||||||||||||||||
31 | |||||||||||||||||
32 | #include "sal/types.h" | ||||||||||||||||
33 | |||||||||||||||||
34 | namespace rtl | ||||||||||||||||
35 | { | ||||||||||||||||
36 | |||||||||||||||||
37 | /** Template reference class for reference type. | ||||||||||||||||
38 | */ | ||||||||||||||||
39 | template <class reference_type> | ||||||||||||||||
40 | class Reference | ||||||||||||||||
41 | { | ||||||||||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||||||||||
43 | */ | ||||||||||||||||
44 | reference_type * m_pBody; | ||||||||||||||||
45 | |||||||||||||||||
46 | |||||||||||||||||
47 | public: | ||||||||||||||||
48 | /** Constructor... | ||||||||||||||||
49 | */ | ||||||||||||||||
50 | Reference() | ||||||||||||||||
51 | : m_pBody (NULL__null) | ||||||||||||||||
52 | {} | ||||||||||||||||
53 | |||||||||||||||||
54 | |||||||||||||||||
55 | /** Constructor... | ||||||||||||||||
56 | */ | ||||||||||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||||||||||
58 | : m_pBody (pBody) | ||||||||||||||||
59 | { | ||||||||||||||||
60 | } | ||||||||||||||||
61 | |||||||||||||||||
62 | /** Constructor... | ||||||||||||||||
63 | */ | ||||||||||||||||
64 | Reference (reference_type * pBody) | ||||||||||||||||
65 | : m_pBody (pBody) | ||||||||||||||||
66 | { | ||||||||||||||||
67 | if (m_pBody) | ||||||||||||||||
68 | m_pBody->acquire(); | ||||||||||||||||
69 | } | ||||||||||||||||
70 | |||||||||||||||||
71 | /** Copy constructor... | ||||||||||||||||
72 | */ | ||||||||||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||||||||||
75 | { | ||||||||||||||||
76 | if (m_pBody) | ||||||||||||||||
77 | m_pBody->acquire(); | ||||||||||||||||
78 | } | ||||||||||||||||
79 | |||||||||||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||
81 | /** Move constructor... | ||||||||||||||||
82 | */ | ||||||||||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||||||||||
85 | { | ||||||||||||||||
86 | handle.m_pBody = nullptr; | ||||||||||||||||
87 | } | ||||||||||||||||
88 | #endif | ||||||||||||||||
89 | |||||||||||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||||||||||
92 | |||||||||||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||||||||||
94 | |||||||||||||||||
95 | @param rRef another reference | ||||||||||||||||
96 | */ | ||||||||||||||||
97 | template< class derived_type > | ||||||||||||||||
98 | inline Reference( | ||||||||||||||||
99 | const Reference< derived_type > & rRef, | ||||||||||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||||||||||
101 | : m_pBody (rRef.get()) | ||||||||||||||||
102 | { | ||||||||||||||||
103 | if (m_pBody) | ||||||||||||||||
104 | m_pBody->acquire(); | ||||||||||||||||
105 | } | ||||||||||||||||
106 | #endif | ||||||||||||||||
107 | |||||||||||||||||
108 | /** Destructor... | ||||||||||||||||
109 | */ | ||||||||||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||||||||||
111 | { | ||||||||||||||||
112 | if (m_pBody
| ||||||||||||||||
113 | m_pBody->release(); | ||||||||||||||||
| |||||||||||||||||
114 | } | ||||||||||||||||
115 | |||||||||||||||||
116 | /** Set... | ||||||||||||||||
117 | Similar to assignment. | ||||||||||||||||
118 | */ | ||||||||||||||||
119 | Reference<reference_type> & | ||||||||||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||||||||||
121 | { | ||||||||||||||||
122 | if (pBody) | ||||||||||||||||
123 | pBody->acquire(); | ||||||||||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||||||||||
125 | m_pBody = pBody; | ||||||||||||||||
126 | if (pOld) | ||||||||||||||||
127 | pOld->release(); | ||||||||||||||||
128 | return *this; | ||||||||||||||||
129 | } | ||||||||||||||||
130 | |||||||||||||||||
131 | /** Assignment. | ||||||||||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||||||||||
133 | bind it to the body represented by the handle. | ||||||||||||||||
134 | */ | ||||||||||||||||
135 | Reference<reference_type> & | ||||||||||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||||||||||
137 | { | ||||||||||||||||
138 | return set( handle.m_pBody ); | ||||||||||||||||
139 | } | ||||||||||||||||
140 | |||||||||||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||
142 | /** Assignment. | ||||||||||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||||||||||
144 | * bind it to the body represented by the handle, and | ||||||||||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||||||||||
146 | */ | ||||||||||||||||
147 | Reference<reference_type> & | ||||||||||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||||||||||
149 | { | ||||||||||||||||
150 | // self-movement guts ourself | ||||||||||||||||
151 | if (m_pBody) | ||||||||||||||||
152 | m_pBody->release(); | ||||||||||||||||
153 | m_pBody = handle.m_pBody; | ||||||||||||||||
154 | handle.m_pBody = nullptr; | ||||||||||||||||
155 | return *this; | ||||||||||||||||
156 | } | ||||||||||||||||
157 | #endif | ||||||||||||||||
158 | |||||||||||||||||
159 | /** Assignment... | ||||||||||||||||
160 | */ | ||||||||||||||||
161 | Reference<reference_type> & | ||||||||||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||||||||||
163 | { | ||||||||||||||||
164 | return set( pBody ); | ||||||||||||||||
165 | } | ||||||||||||||||
166 | |||||||||||||||||
167 | /** Unbind the body from this handle. | ||||||||||||||||
168 | Note that for a handle representing a large body, | ||||||||||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||||||||||
171 | since in the second case two large objects exist in memory | ||||||||||||||||
172 | (the old body and the new body). | ||||||||||||||||
173 | */ | ||||||||||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||||||||||
175 | { | ||||||||||||||||
176 | if (m_pBody) | ||||||||||||||||
177 | { | ||||||||||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||||||||||
179 | m_pBody = NULL__null; | ||||||||||||||||
180 | pOld->release(); | ||||||||||||||||
181 | } | ||||||||||||||||
182 | return *this; | ||||||||||||||||
183 | } | ||||||||||||||||
184 | |||||||||||||||||
185 | |||||||||||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||||||||||
188 | are the same. | ||||||||||||||||
189 | */ | ||||||||||||||||
190 | reference_type * SAL_CALL get() const | ||||||||||||||||
191 | { | ||||||||||||||||
192 | return m_pBody; | ||||||||||||||||
193 | } | ||||||||||||||||
194 | |||||||||||||||||
195 | |||||||||||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||||||||||
197 | */ | ||||||||||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||||||||||
199 | { | ||||||||||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||||||||||
201 | return m_pBody; | ||||||||||||||||
202 | } | ||||||||||||||||
203 | |||||||||||||||||
204 | |||||||||||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||||||||||
206 | */ | ||||||||||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||||||||||
208 | { | ||||||||||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||||||||||
210 | return *m_pBody; | ||||||||||||||||
211 | } | ||||||||||||||||
212 | |||||||||||||||||
213 | |||||||||||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||||||||||
215 | */ | ||||||||||||||||
216 | bool SAL_CALL is() const | ||||||||||||||||
217 | { | ||||||||||||||||
218 | return (m_pBody != NULL__null); | ||||||||||||||||
219 | } | ||||||||||||||||
220 | |||||||||||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||||||||||
223 | */ | ||||||||||||||||
224 | explicit operator bool() const | ||||||||||||||||
225 | { | ||||||||||||||||
226 | return is(); | ||||||||||||||||
227 | } | ||||||||||||||||
228 | #endif | ||||||||||||||||
229 | |||||||||||||||||
230 | /** Returns True if this points to pBody. | ||||||||||||||||
231 | */ | ||||||||||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||||||||||
233 | { | ||||||||||||||||
234 | return (m_pBody == pBody); | ||||||||||||||||
235 | } | ||||||||||||||||
236 | |||||||||||||||||
237 | |||||||||||||||||
238 | /** Returns True if handle points to the same body. | ||||||||||||||||
239 | */ | ||||||||||||||||
240 | bool | ||||||||||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||||||||||
242 | { | ||||||||||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||||||||||
244 | } | ||||||||||||||||
245 | |||||||||||||||||
246 | |||||||||||||||||
247 | /** Needed to place References into STL collection. | ||||||||||||||||
248 | */ | ||||||||||||||||
249 | bool | ||||||||||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||||||||||
251 | { | ||||||||||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||||||||||
253 | } | ||||||||||||||||
254 | |||||||||||||||||
255 | |||||||||||||||||
256 | /** Needed to place References into STL collection. | ||||||||||||||||
257 | */ | ||||||||||||||||
258 | bool | ||||||||||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||||||||||
260 | { | ||||||||||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||||||||||
262 | } | ||||||||||||||||
263 | |||||||||||||||||
264 | |||||||||||||||||
265 | /** Needed to place References into STL collection. | ||||||||||||||||
266 | */ | ||||||||||||||||
267 | bool | ||||||||||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||||||||||
269 | { | ||||||||||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||||||||||
271 | } | ||||||||||||||||
272 | }; | ||||||||||||||||
273 | |||||||||||||||||
274 | } // namespace rtl | ||||||||||||||||
275 | |||||||||||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||
277 | namespace std | ||||||||||||||||
278 | { | ||||||||||||||||
279 | |||||||||||||||||
280 | /// @cond INTERNAL | ||||||||||||||||
281 | /** | ||||||||||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||||||||||
283 | |||||||||||||||||
284 | @since LibreOffice 6.3 | ||||||||||||||||
285 | */ | ||||||||||||||||
286 | template<typename T> | ||||||||||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||||||||||
288 | { | ||||||||||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||||||||||
290 | { return std::size_t(s.get()); } | ||||||||||||||||
291 | }; | ||||||||||||||||
292 | /// @endcond | ||||||||||||||||
293 | |||||||||||||||||
294 | } | ||||||||||||||||
295 | |||||||||||||||||
296 | #endif | ||||||||||||||||
297 | |||||||||||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||||||||||
299 | |||||||||||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
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/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
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 . |
18 | */ |
19 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |