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

Generated by: LCOV version 1.10