LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/browser - dsbrowserDnD.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 115 0.0 %
Date: 2012-12-27 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "dbexchange.hxx"
      22             : #include "dbtreelistbox.hxx"
      23             : #include "dbtreemodel.hxx"
      24             : #include "dbtreeview.hxx"
      25             : #include "dbu_brw.hrc"
      26             : #include "dbustrings.hrc"
      27             : #include "QEnumTypes.hxx"
      28             : #include "UITools.hxx"
      29             : #include "unodatbr.hxx"
      30             : 
      31             : #include <com/sun/star/frame/XStorable.hpp>
      32             : #include <com/sun/star/sdb/CommandType.hpp>
      33             : #include <com/sun/star/sdbc/XConnection.hpp>
      34             : 
      35             : #include <connectivity/dbexception.hxx>
      36             : #include <connectivity/dbtools.hxx>
      37             : #include <cppuhelper/exc_hlp.hxx>
      38             : #include <svx/dataaccessdescriptor.hxx>
      39             : #include <tools/diagnose_ex.h>
      40             : #include <osl/diagnose.h>
      41             : #include "svtools/treelistentry.hxx"
      42             : 
      43             : #include <functional>
      44             : // .........................................................................
      45             : namespace dbaui
      46             : {
      47             : // .........................................................................
      48             : 
      49             :     using namespace ::com::sun::star::uno;
      50             :     using namespace ::com::sun::star::sdb;
      51             :     using namespace ::com::sun::star::sdbc;
      52             :     using namespace ::com::sun::star::sdbcx;
      53             :     using namespace ::com::sun::star::beans;
      54             :     using namespace ::com::sun::star::util;
      55             :     using namespace ::com::sun::star::frame;
      56             :     using namespace ::com::sun::star::container;
      57             :     using namespace ::com::sun::star::lang;
      58             :     using namespace ::com::sun::star::form;
      59             :     using namespace ::com::sun::star::io;
      60             :     using namespace ::com::sun::star::i18n;
      61             :     using namespace ::com::sun::star::task;
      62             :     using namespace ::com::sun::star::datatransfer;
      63             :     using namespace ::dbtools;
      64             :     using namespace ::svx;
      65             : 
      66             :     // -----------------------------------------------------------------------------
      67           0 :     TransferableHelper* SbaTableQueryBrowser::implCopyObject( SvTreeListEntry* _pApplyTo, sal_Int32 _nCommandType, sal_Bool _bAllowConnection )
      68             :     {
      69             :         try
      70             :         {
      71           0 :             ::rtl::OUString aName = GetEntryText( _pApplyTo );
      72           0 :             ::rtl::OUString aDSName = getDataSourceAcessor( m_pTreeView->getListBox().GetRootLevelParent( _pApplyTo ) );
      73             : 
      74           0 :             ODataClipboard* pData = NULL;
      75           0 :             SharedConnection xConnection;
      76           0 :             if ( CommandType::QUERY != _nCommandType )
      77             :             {
      78           0 :                 if ( _bAllowConnection && !ensureConnection( _pApplyTo, xConnection) )
      79           0 :                     return NULL;
      80           0 :                 pData = new ODataClipboard(aDSName, _nCommandType, aName, xConnection, getNumberFormatter(), getORB());
      81             :             }
      82             :             else
      83           0 :                 pData = new ODataClipboard(aDSName, _nCommandType, aName, getNumberFormatter(), getORB());
      84             : 
      85             :             // the owner ship goes to ODataClipboards
      86           0 :             return pData;
      87             :         }
      88           0 :         catch(const SQLException& )
      89             :         {
      90           0 :             showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
      91             :         }
      92           0 :         catch( const Exception& )
      93             :         {
      94             :             DBG_UNHANDLED_EXCEPTION();
      95             :         }
      96           0 :         return NULL;
      97             :     }
      98             :     // -----------------------------------------------------------------------------
      99           0 :     sal_Int8 SbaTableQueryBrowser::queryDrop( const AcceptDropEvent& _rEvt, const DataFlavorExVector& _rFlavors )
     100             :     {
     101             :         // check if we're a table or query container
     102           0 :         SvTreeListEntry* pHitEntry = m_pTreeView->getListBox().GetEntry( _rEvt.maPosPixel );
     103             : 
     104           0 :         if ( pHitEntry ) // no drop if no entry was hit ....
     105             :         {
     106             :             // it must be a container
     107           0 :             EntryType eEntryType = getEntryType( pHitEntry );
     108           0 :             SharedConnection xConnection;
     109           0 :             if ( eEntryType == etTableContainer && ensureConnection( pHitEntry, xConnection ) && xConnection.is() )
     110             :             {
     111           0 :                 Reference<XChild> xChild(xConnection,UNO_QUERY);
     112           0 :                 Reference<XStorable> xStore;
     113           0 :                 xStore = Reference<XStorable>( xChild.is() ? getDataSourceOrModel(xChild->getParent()) : Reference<XInterface>(),UNO_QUERY );
     114             :                 // check for the concrete type
     115           0 :                 if ( xStore.is() && !xStore->isReadonly() && ::std::find_if(_rFlavors.begin(),_rFlavors.end(),TAppSupportedSotFunctor(E_TABLE,sal_True)) != _rFlavors.end())
     116           0 :                     return DND_ACTION_COPY;
     117           0 :             }
     118             :         }
     119             : 
     120           0 :         return DND_ACTION_NONE;
     121             :     }
     122             :     // -----------------------------------------------------------------------------
     123           0 :     sal_Int8 SbaTableQueryBrowser::executeDrop( const ExecuteDropEvent& _rEvt )
     124             :     {
     125           0 :         SvTreeListEntry* pHitEntry = m_pTreeView->getListBox().GetEntry( _rEvt.maPosPixel );
     126           0 :         EntryType eEntryType = getEntryType( pHitEntry );
     127           0 :         if (!isContainer(eEntryType))
     128             :         {
     129             :             OSL_FAIL("SbaTableQueryBrowser::executeDrop: what the hell did queryDrop do?");
     130             :                 // queryDrop shoud not have allowed us to reach this situation ....
     131           0 :             return DND_ACTION_NONE;
     132             :         }
     133             :         // a TransferableDataHelper for accessing the dropped data
     134           0 :         TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable);
     135             : 
     136             : 
     137             :         // reset the data of the previous async drop (if any)
     138           0 :         if ( m_nAsyncDrop )
     139           0 :             Application::RemoveUserEvent(m_nAsyncDrop);
     140             : 
     141             : 
     142           0 :         m_nAsyncDrop = 0;
     143           0 :         m_aAsyncDrop.aDroppedData.clear();
     144           0 :         m_aAsyncDrop.nType          = E_TABLE;
     145           0 :         m_aAsyncDrop.nAction        = _rEvt.mnAction;
     146           0 :         m_aAsyncDrop.bError         = sal_False;
     147           0 :         m_aAsyncDrop.bHtml          = sal_False;
     148           0 :         m_aAsyncDrop.pDroppedAt     = NULL;
     149           0 :         m_aAsyncDrop.aUrl           = ::rtl::OUString();
     150             : 
     151             : 
     152             :         // loop through the available formats and see what we can do ...
     153             :         // first we have to check if it is our own format, if not we have to copy the stream :-(
     154           0 :         if ( ODataAccessObjectTransferable::canExtractObjectDescriptor(aDroppedData.GetDataFlavorExVector()) )
     155             :         {
     156           0 :             m_aAsyncDrop.aDroppedData   = ODataAccessObjectTransferable::extractObjectDescriptor(aDroppedData);
     157           0 :             m_aAsyncDrop.pDroppedAt     = pHitEntry;
     158             : 
     159             :             // asyncron because we some dialogs and we aren't allowed to show them while in D&D
     160           0 :             m_nAsyncDrop = Application::PostUserEvent(LINK(this, SbaTableQueryBrowser, OnAsyncDrop));
     161           0 :             return DND_ACTION_COPY;
     162             :         }
     163             :         else
     164             :         {
     165           0 :             SharedConnection xDestConnection;
     166           0 :             if (  ensureConnection( pHitEntry, xDestConnection )
     167           0 :                && xDestConnection.is()
     168           0 :                && m_aTableCopyHelper.copyTagTable( aDroppedData, m_aAsyncDrop, xDestConnection )
     169             :                )
     170             :             {
     171           0 :                 m_aAsyncDrop.pDroppedAt = pHitEntry;
     172             : 
     173             :                 // asyncron because we some dialogs and we aren't allowed to show them while in D&D
     174           0 :                 m_nAsyncDrop = Application::PostUserEvent(LINK(this, SbaTableQueryBrowser, OnAsyncDrop));
     175           0 :                 return DND_ACTION_COPY;
     176           0 :             }
     177             :         }
     178             : 
     179           0 :         return DND_ACTION_NONE;
     180             :     }
     181             : 
     182             :     // -----------------------------------------------------------------------------
     183           0 :     sal_Bool SbaTableQueryBrowser::requestDrag( sal_Int8 /*_nAction*/, const Point& _rPosPixel )
     184             :     {
     185             :         // get the affected list entry
     186             :         // ensure that the entry which the user clicked at is selected
     187           0 :         SvTreeListEntry* pHitEntry = m_pTreeView->getListBox().GetEntry( _rPosPixel );
     188           0 :         if (!pHitEntry)
     189             :             // no drag of no entry was hit ....
     190           0 :             return sal_False;
     191             : 
     192             :         // it must be a query/table
     193           0 :         EntryType eEntryType = getEntryType( pHitEntry );
     194           0 :         if (!isObject(eEntryType))
     195           0 :             return DND_ACTION_NONE;
     196             : 
     197           0 :         TransferableHelper* pTransfer = implCopyObject( pHitEntry, ( etTableOrView == eEntryType ) ? CommandType::TABLE : CommandType::QUERY);
     198           0 :         Reference< XTransferable> xEnsureDelete = pTransfer;
     199             : 
     200           0 :         if (pTransfer)
     201           0 :             pTransfer->StartDrag( &m_pTreeView->getListBox(), DND_ACTION_COPY );
     202             : 
     203           0 :         return NULL != pTransfer;
     204             :     }
     205             :     // -----------------------------------------------------------------------------
     206           0 :     IMPL_LINK(SbaTableQueryBrowser, OnCopyEntry, void*, /*NOTINTERESIN*/)
     207             :     {
     208           0 :         SvTreeListEntry* pSelected = m_pTreeView->getListBox().FirstSelected();
     209           0 :         if( isEntryCopyAllowed( pSelected ) )
     210           0 :             copyEntry( pSelected );
     211           0 :         return 0;
     212             :     }
     213             :     // -----------------------------------------------------------------------------
     214           0 :     sal_Bool SbaTableQueryBrowser::isEntryCopyAllowed(SvTreeListEntry* _pEntry) const
     215             :     {
     216           0 :         EntryType eType = getEntryType(_pEntry);
     217           0 :         return  ( eType == etTableOrView || eType == etQuery );
     218             :     }
     219             :     // -----------------------------------------------------------------------------
     220           0 :     void SbaTableQueryBrowser::copyEntry(SvTreeListEntry* _pEntry)
     221             :     {
     222           0 :         TransferableHelper* pTransfer = NULL;
     223           0 :         Reference< XTransferable> aEnsureDelete;
     224           0 :         EntryType eType = getEntryType(_pEntry);
     225           0 :         pTransfer       = implCopyObject( _pEntry, eType == etQuery ? CommandType::QUERY : CommandType::TABLE);
     226           0 :         aEnsureDelete   = pTransfer;
     227           0 :         if (pTransfer)
     228           0 :             pTransfer->CopyToClipboard(getView());
     229           0 :     }
     230             :     // -----------------------------------------------------------------------------
     231           0 :     IMPL_LINK( SbaTableQueryBrowser, OnAsyncDrop, void*, /*NOTINTERESTEDIN*/ )
     232             :     {
     233           0 :         m_nAsyncDrop = 0;
     234           0 :         SolarMutexGuard aSolarGuard;
     235           0 :         ::osl::MutexGuard aGuard( getMutex() );
     236             : 
     237           0 :         if ( m_aAsyncDrop.nType == E_TABLE )
     238             :         {
     239           0 :             SharedConnection xDestConnection;
     240           0 :             if ( ensureConnection( m_aAsyncDrop.pDroppedAt, xDestConnection ) && xDestConnection.is() )
     241             :             {
     242           0 :                 SvTreeListEntry* pDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent(m_aAsyncDrop.pDroppedAt);
     243           0 :                 m_aTableCopyHelper.asyncCopyTagTable( m_aAsyncDrop, getDataSourceAcessor( pDataSourceEntry ), xDestConnection );
     244           0 :             }
     245             :         }
     246             : 
     247           0 :         m_aAsyncDrop.aDroppedData.clear();
     248             : 
     249           0 :         return 0L;
     250             :     }
     251             :     // -----------------------------------------------------------------------------
     252           0 :     void SbaTableQueryBrowser::clearTreeModel()
     253             :     {
     254           0 :         if (m_pTreeModel)
     255             :         {
     256             :             // clear the user data of the tree model
     257           0 :             SvTreeListEntry* pEntryLoop = m_pTreeModel->First();
     258           0 :             while (pEntryLoop)
     259             :             {
     260           0 :                 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pEntryLoop->GetUserData());
     261           0 :                 if(pData)
     262             :                 {
     263           0 :                     pEntryLoop->SetUserData(NULL);
     264           0 :                     Reference< XContainer > xContainer(pData->xContainer, UNO_QUERY);
     265           0 :                     if (xContainer.is())
     266           0 :                         xContainer->removeContainerListener(this);
     267             : 
     268           0 :                     if ( pData->xConnection.is() )
     269             :                     {
     270             :                         OSL_ENSURE( impl_isDataSourceEntry( pEntryLoop ), "SbaTableQueryBrowser::clearTreeModel: no data source entry, but a connection?" );
     271             :                         // connections are to be stored *only* at the data source entries
     272           0 :                         impl_releaseConnection( pData->xConnection );
     273             :                     }
     274             : 
     275           0 :                     delete pData;
     276             :                 }
     277           0 :                 pEntryLoop = m_pTreeModel->Next(pEntryLoop);
     278             :             }
     279             :         }
     280           0 :         m_pCurrentlyDisplayed = NULL;
     281           0 :     }
     282             : // .........................................................................
     283             : }   // namespace dbaui
     284             : // .........................................................................
     285             : 
     286             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10