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

Generated by: LCOV version 1.10