LCOV - code coverage report
Current view: top level - svx/source/form - fmexch.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 182 0.5 %
Date: 2014-11-03 Functions: 2 34 5.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 "fmexch.hxx"
      21             : 
      22             : #include <sot/storage.hxx>
      23             : #include <svl/itempool.hxx>
      24             : 
      25             : #include <sot/formats.hxx>
      26             : #include <svtools/treelistbox.hxx>
      27             : #include "svtools/treelistentry.hxx"
      28             : #include <tools/diagnose_ex.h>
      29             : 
      30             : 
      31             : 
      32             : namespace svxform
      33             : {
      34             : 
      35             : 
      36             :     using namespace ::com::sun::star::uno;
      37             :     using namespace ::com::sun::star::datatransfer;
      38             : 
      39           0 :     OLocalExchange::OLocalExchange( )
      40             :         :m_bDragging( false )
      41           0 :         ,m_bClipboardOwner( false )
      42             :     {
      43           0 :     }
      44             : 
      45             : 
      46           0 :     void OLocalExchange::copyToClipboard( vcl::Window* _pWindow, const GrantAccess& )
      47             :     {
      48           0 :         if ( m_bClipboardOwner )
      49             :         {   // simulate a lostOwnership to notify parties interested in
      50           0 :             if ( m_aClipboardListener.IsSet() )
      51           0 :                 m_aClipboardListener.Call( this );
      52             :         }
      53             : 
      54           0 :         m_bClipboardOwner = true;
      55           0 :         CopyToClipboard( _pWindow );
      56           0 :     }
      57             : 
      58             : 
      59           0 :     void OLocalExchange::clear()
      60             :     {
      61           0 :         if ( isClipboardOwner() )
      62             :         {
      63             :             try
      64             :             {
      65           0 :                 Reference< clipboard::XClipboard > xClipBoard( getOwnClipboard() );
      66           0 :                 if ( xClipBoard.is() )
      67           0 :                     xClipBoard->setContents( NULL, NULL );
      68             :             }
      69           0 :             catch( const Exception& )
      70             :             {
      71             :                 DBG_UNHANDLED_EXCEPTION();
      72             :             }
      73           0 :             m_bClipboardOwner = false;
      74             :         }
      75           0 :     }
      76             : 
      77             : 
      78           0 :     void SAL_CALL OLocalExchange::lostOwnership( const Reference< clipboard::XClipboard >& _rxClipboard, const Reference< XTransferable >& _rxTrans ) throw(RuntimeException, std::exception)
      79             :     {
      80           0 :         TransferableHelper::implCallOwnLostOwnership( _rxClipboard, _rxTrans );
      81           0 :         m_bClipboardOwner = false;
      82             : 
      83           0 :         if ( m_aClipboardListener.IsSet() )
      84           0 :             m_aClipboardListener.Call( this );
      85           0 :     }
      86             : 
      87             : 
      88           0 :     void OLocalExchange::startDrag( vcl::Window* _pWindow, sal_Int8 _nDragSourceActions, const GrantAccess& )
      89             :     {
      90           0 :         m_bDragging = true;
      91           0 :         StartDrag( _pWindow, _nDragSourceActions );
      92           0 :     }
      93             : 
      94             : 
      95           0 :     void OLocalExchange::DragFinished( sal_Int8 nDropAction )
      96             :     {
      97           0 :         TransferableHelper::DragFinished( nDropAction );
      98           0 :         m_bDragging = false;
      99           0 :     }
     100             : 
     101             : 
     102           0 :     bool OLocalExchange::hasFormat( const DataFlavorExVector& _rFormats, sal_uInt32 _nFormatId )
     103             :     {
     104           0 :         DataFlavorExVector::const_iterator aSearch;
     105             : 
     106           0 :         for ( aSearch = _rFormats.begin(); aSearch != _rFormats.end(); ++aSearch )
     107           0 :             if ( aSearch->mnSotId == _nFormatId )
     108           0 :                 break;
     109             : 
     110           0 :         return aSearch != _rFormats.end();
     111             :     }
     112             : 
     113             : 
     114           0 :     bool OLocalExchange::GetData( const css::datatransfer::DataFlavor& /*_rFlavor*/, const OUString& /*rDestDoc*/ )
     115             :     {
     116           0 :         return false;   // do not have any formats by default
     117             :     }
     118             : 
     119           0 :     OControlTransferData::OControlTransferData( )
     120           0 :         :m_pFocusEntry( NULL )
     121             :     {
     122           0 :     }
     123             : 
     124             : 
     125           0 :     OControlTransferData::OControlTransferData( const Reference< XTransferable >& _rxTransferable )
     126           0 :         :m_pFocusEntry( NULL )
     127             :     {
     128           0 :         TransferableDataHelper aExchangedData( _rxTransferable );
     129             : 
     130             :         // try the formats we know
     131           0 :         if ( OControlExchange::hasControlPathFormat( aExchangedData.GetDataFlavorExVector() ) )
     132             :         {   // paths to the controls, relative to a root
     133           0 :             Sequence< Any > aControlPathData;
     134           0 :             if ( aExchangedData.GetAny(OControlExchange::getControlPathFormatId(), OUString()) >>= aControlPathData )
     135             :             {
     136             :                 DBG_ASSERT( aControlPathData.getLength() >= 2, "OControlTransferData::OControlTransferData: invalid data for the control path format!" );
     137           0 :                 if ( aControlPathData.getLength() >= 2 )
     138             :                 {
     139           0 :                     aControlPathData[0] >>= m_xFormsRoot;
     140           0 :                     aControlPathData[1] >>= m_aControlPaths;
     141             :                 }
     142             :             }
     143             :             else
     144             :             {
     145             :                 OSL_FAIL( "OControlTransferData::OControlTransferData: invalid data for the control path format (2)!" );
     146           0 :             }
     147             :         }
     148           0 :         if ( OControlExchange::hasHiddenControlModelsFormat( aExchangedData.GetDataFlavorExVector() ) )
     149             :         {   // sequence of models of hidden controls
     150           0 :             aExchangedData.GetAny(OControlExchange::getHiddenControlModelsFormatId(), OUString()) >>= m_aHiddenControlModels;
     151             :         }
     152             : 
     153           0 :         updateFormats( );
     154           0 :     }
     155             : 
     156             : 
     157           0 :     static bool lcl_fillDataFlavorEx( SotFormatStringId nId, DataFlavorEx& _rFlavor )
     158             :     {
     159           0 :         _rFlavor.mnSotId = nId;
     160           0 :         return SotExchange::GetFormatDataFlavor( _rFlavor.mnSotId, _rFlavor );
     161             :     }
     162             : 
     163             : 
     164           0 :     void OControlTransferData::updateFormats( )
     165             :     {
     166           0 :         m_aCurrentFormats.clear();
     167           0 :         m_aCurrentFormats.reserve( 3 );
     168             : 
     169           0 :         DataFlavorEx aFlavor;
     170             : 
     171           0 :         if ( m_aHiddenControlModels.getLength() )
     172             :         {
     173           0 :             if ( lcl_fillDataFlavorEx( OControlExchange::getHiddenControlModelsFormatId(), aFlavor ) )
     174           0 :                 m_aCurrentFormats.push_back( aFlavor );
     175             :         }
     176             : 
     177           0 :         if ( m_xFormsRoot.is() && m_aControlPaths.getLength() )
     178             :         {
     179           0 :             if ( lcl_fillDataFlavorEx( OControlExchange::getControlPathFormatId(), aFlavor ) )
     180           0 :                 m_aCurrentFormats.push_back( aFlavor );
     181             :         }
     182             : 
     183           0 :         if ( !m_aSelectedEntries.empty() )
     184             :         {
     185           0 :             if ( lcl_fillDataFlavorEx( OControlExchange::getFieldExchangeFormatId(), aFlavor ) )
     186           0 :                 m_aCurrentFormats.push_back( aFlavor );
     187           0 :         }
     188           0 :     }
     189             : 
     190             : 
     191           0 :     size_t OControlTransferData::onEntryRemoved( SvTreeListEntry* _pEntry )
     192             :     {
     193           0 :         m_aSelectedEntries.erase( _pEntry );
     194           0 :         return m_aSelectedEntries.size();
     195             :     }
     196             : 
     197             : 
     198           0 :     void OControlTransferData::addSelectedEntry( SvTreeListEntry* _pEntry )
     199             :     {
     200           0 :         m_aSelectedEntries.insert( _pEntry );
     201           0 :     }
     202             : 
     203             : 
     204           0 :     void OControlTransferData::setFocusEntry( SvTreeListEntry* _pFocusEntry )
     205             :     {
     206           0 :         m_pFocusEntry = _pFocusEntry;
     207           0 :     }
     208             : 
     209             : 
     210           0 :     void OControlTransferData::addHiddenControlsFormat(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >& seqInterfaces)
     211             :     {
     212           0 :         m_aHiddenControlModels = seqInterfaces;
     213           0 :     }
     214             : 
     215             : 
     216           0 :     void OControlTransferData::buildPathFormat(SvTreeListBox* pTreeBox, SvTreeListEntry* pRoot)
     217             :     {
     218           0 :         m_aControlPaths.realloc(0);
     219             : 
     220           0 :         sal_Int32 nEntryCount = m_aSelectedEntries.size();
     221           0 :         if (nEntryCount == 0)
     222           0 :             return;
     223             : 
     224           0 :         m_aControlPaths.realloc(nEntryCount);
     225           0 :         ::com::sun::star::uno::Sequence<sal_uInt32>* pAllPaths = m_aControlPaths.getArray();
     226           0 :         for (   ListBoxEntrySet::const_iterator loop = m_aSelectedEntries.begin();
     227           0 :                 loop != m_aSelectedEntries.end();
     228             :                 ++loop, ++pAllPaths
     229             :             )
     230             :         {
     231             :             // erst mal sammeln wir den Pfad in einem Array ein
     232           0 :             ::std::vector< sal_uInt32 > aCurrentPath;
     233           0 :             SvTreeListEntry* pCurrentEntry = *loop;
     234             : 
     235           0 :             SvTreeListEntry* pLoop = pCurrentEntry;
     236           0 :             while (pLoop != pRoot)
     237             :             {
     238           0 :                 aCurrentPath.push_back(pLoop->GetChildListPos());
     239           0 :                 pLoop = pTreeBox->GetParent(pLoop);
     240             :                 DBG_ASSERT((pLoop != NULL) || (pRoot == 0), "OControlTransferData::buildPathFormat: invalid root or entry !");
     241             :                     // pLoop == NULL heisst, dass ich am oberen Ende angelangt bin, dann sollte das Ganze abbrechen, was nur bei pRoot == NULL der Fall sein wird
     242             :             }
     243             : 
     244             :             // dann koennen wir ihn in die ::com::sun::star::uno::Sequence uebertragen
     245           0 :             Sequence<sal_uInt32>& rCurrentPath = *pAllPaths;
     246           0 :             sal_Int32 nDepth = aCurrentPath.size();
     247             : 
     248           0 :             rCurrentPath.realloc(nDepth);
     249           0 :             sal_uInt32* pSeq = rCurrentPath.getArray();
     250             :             sal_Int32 j,k;
     251           0 :             for (j = nDepth - 1, k = 0; k<nDepth; --j, ++k)
     252           0 :                 pSeq[j] = aCurrentPath[k];
     253           0 :         }
     254             :     }
     255             : 
     256             : 
     257           0 :     void OControlTransferData::buildListFromPath(SvTreeListBox* pTreeBox, SvTreeListEntry* pRoot)
     258             :     {
     259           0 :         ListBoxEntrySet aEmpty;
     260           0 :         m_aSelectedEntries.swap( aEmpty );
     261             : 
     262           0 :         sal_Int32 nControls = m_aControlPaths.getLength();
     263           0 :         const ::com::sun::star::uno::Sequence<sal_uInt32>* pPaths = m_aControlPaths.getConstArray();
     264           0 :         for (sal_Int32 i=0; i<nControls; ++i)
     265             :         {
     266           0 :             sal_Int32 nThisPatLength = pPaths[i].getLength();
     267           0 :             const sal_uInt32* pThisPath = pPaths[i].getConstArray();
     268           0 :             SvTreeListEntry* pSearch = pRoot;
     269           0 :             for (sal_Int32 j=0; j<nThisPatLength; ++j)
     270           0 :                 pSearch = pTreeBox->GetEntry(pSearch, pThisPath[j]);
     271             : 
     272           0 :             m_aSelectedEntries.insert( pSearch );
     273           0 :         }
     274           0 :     }
     275             : 
     276           0 :     OControlExchange::OControlExchange( )
     277             :     {
     278           0 :     }
     279             : 
     280             : 
     281           0 :     bool OControlExchange::GetData( const DataFlavor& _rFlavor, const OUString& rDestDoc )
     282             :     {
     283           0 :         const sal_uInt32 nFormatId = SotExchange::GetFormat( _rFlavor );
     284             : 
     285           0 :         if ( getControlPathFormatId( ) == nFormatId )
     286             :         {
     287             :             // ugly. We have to pack all the info into one object
     288           0 :             Sequence< Any > aCompleteInfo( 2 );
     289             :             OSL_ENSURE( m_xFormsRoot.is(), "OLocalExchange::GetData: invalid forms root for this format!" );
     290           0 :             aCompleteInfo.getArray()[ 0 ] <<= m_xFormsRoot;
     291           0 :             aCompleteInfo.getArray()[ 1 ] <<= m_aControlPaths;
     292             : 
     293           0 :             SetAny( makeAny( aCompleteInfo ), _rFlavor );
     294             :         }
     295           0 :         else if ( getHiddenControlModelsFormatId() == nFormatId )
     296             :         {
     297             :             // just need to transfer the models
     298           0 :             SetAny( makeAny( m_aHiddenControlModels ), _rFlavor );
     299             :         }
     300             :         else
     301           0 :             return OLocalExchange::GetData(_rFlavor, rDestDoc);
     302             : 
     303           0 :         return true;
     304             :     }
     305             : 
     306             : 
     307           0 :     void OControlExchange::AddSupportedFormats()
     308             :     {
     309           0 :         if (m_pFocusEntry && !m_aSelectedEntries.empty())
     310           0 :             AddFormat(getFieldExchangeFormatId());
     311             : 
     312           0 :         if (m_aControlPaths.getLength())
     313           0 :             AddFormat(getControlPathFormatId());
     314             : 
     315           0 :         if (m_aHiddenControlModels.getLength())
     316           0 :             AddFormat(getHiddenControlModelsFormatId());
     317           0 :     }
     318             : 
     319             : 
     320           0 :     sal_uInt32 OControlExchange::getControlPathFormatId()
     321             :     {
     322             :         static sal_uInt32 s_nFormat = (sal_uInt32)-1;
     323           0 :         if ((sal_uInt32)-1 == s_nFormat)
     324             :         {
     325           0 :             s_nFormat = SotExchange::RegisterFormatName(OUString("application/x-openoffice;windows_formatname=\"svxform.ControlPathExchange\""));
     326             :             DBG_ASSERT((sal_uInt32)-1 != s_nFormat, "OControlExchange::getControlPathFormatId: bad exchange id!");
     327             :         }
     328           0 :         return s_nFormat;
     329             :     }
     330             : 
     331             : 
     332           0 :     sal_uInt32 OControlExchange::getHiddenControlModelsFormatId()
     333             :     {
     334             :         static sal_uInt32 s_nFormat = (sal_uInt32)-1;
     335           0 :         if ((sal_uInt32)-1 == s_nFormat)
     336             :         {
     337           0 :             s_nFormat = SotExchange::RegisterFormatName(OUString("application/x-openoffice;windows_formatname=\"svxform.HiddenControlModelsExchange\""));
     338             :             DBG_ASSERT((sal_uInt32)-1 != s_nFormat, "OControlExchange::getHiddenControlModelsFormatId: bad exchange id!");
     339             :         }
     340           0 :         return s_nFormat;
     341             :     }
     342             : 
     343             : 
     344           0 :     sal_uInt32 OControlExchange::getFieldExchangeFormatId()
     345             :     {
     346             :         static sal_uInt32 s_nFormat = (sal_uInt32)-1;
     347           0 :         if ((sal_uInt32)-1 == s_nFormat)
     348             :         {
     349           0 :             s_nFormat = SotExchange::RegisterFormatName(OUString("application/x-openoffice;windows_formatname=\"svxform.FieldNameExchange\""));
     350             :             DBG_ASSERT((sal_uInt32)-1 != s_nFormat, "OControlExchange::getFieldExchangeFormatId: bad exchange id!");
     351             :         }
     352           0 :         return s_nFormat;
     353             :     }
     354             : 
     355             : 
     356             :     //= OControlExchangeHelper
     357             : 
     358           0 :     OLocalExchange* OControlExchangeHelper::createExchange() const
     359             :     {
     360           0 :         return new OControlExchange;
     361             :     }
     362             : 
     363           0 :     OLocalExchangeHelper::OLocalExchangeHelper(vcl::Window* _pDragSource)
     364             :         :m_pDragSource(_pDragSource)
     365           0 :         ,m_pTransferable(NULL)
     366             :     {
     367           0 :     }
     368             : 
     369             : 
     370           0 :     OLocalExchangeHelper::~OLocalExchangeHelper()
     371             :     {
     372           0 :         implReset();
     373           0 :     }
     374             : 
     375             : 
     376           0 :     void OLocalExchangeHelper::startDrag( sal_Int8 nDragSourceActions )
     377             :     {
     378             :         DBG_ASSERT(m_pTransferable, "OLocalExchangeHelper::startDrag: not prepared!");
     379           0 :         m_pTransferable->startDrag( m_pDragSource, nDragSourceActions, OLocalExchange::GrantAccess() );
     380           0 :     }
     381             : 
     382             : 
     383           0 :     void OLocalExchangeHelper::copyToClipboard( ) const
     384             :     {
     385             :         DBG_ASSERT( m_pTransferable, "OLocalExchangeHelper::copyToClipboard: not prepared!" );
     386           0 :         m_pTransferable->copyToClipboard( m_pDragSource, OLocalExchange::GrantAccess() );
     387           0 :     }
     388             : 
     389             : 
     390           0 :     void OLocalExchangeHelper::implReset()
     391             :     {
     392           0 :         if (m_pTransferable)
     393             :         {
     394           0 :             m_pTransferable->setClipboardListener( Link() );
     395           0 :             m_pTransferable->release();
     396           0 :             m_pTransferable = NULL;
     397             :         }
     398           0 :     }
     399             : 
     400             : 
     401           0 :     void OLocalExchangeHelper::prepareDrag( )
     402             :     {
     403             :         DBG_ASSERT(!m_pTransferable || !m_pTransferable->isDragging(), "OLocalExchangeHelper::prepareDrag: recursive DnD?");
     404             : 
     405           0 :         implReset();
     406           0 :         m_pTransferable = createExchange();
     407           0 :         m_pTransferable->acquire();
     408           0 :     }
     409             : 
     410             : 
     411         651 : }
     412             : 
     413             : 
     414             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10