LCOV - code coverage report
Current view: top level - dbaccess/source/ui/app - AppController.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 512 1443 35.5 %
Date: 2015-06-13 12:38:46 Functions: 47 96 49.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11