LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/app - seltrans.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 198 0.5 %
Date: 2012-12-27 Functions: 2 16 12.5 %
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 <com/sun/star/beans/XPropertySet.hpp>
      21             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      22             : #include <com/sun/star/form/FormButtonType.hpp>
      23             : 
      24             : #include <tools/urlobj.hxx>
      25             : #include <sfx2/docfile.hxx>
      26             : #include <svx/fmglob.hxx>
      27             : #include <svx/svdograf.hxx>
      28             : #include <svx/svdouno.hxx>
      29             : 
      30             : #include "seltrans.hxx"
      31             : #include "transobj.hxx"
      32             : #include "drwtrans.hxx"
      33             : #include "scmod.hxx"
      34             : #include "dbfunc.hxx"   // for CopyToClip
      35             : #include "docsh.hxx"
      36             : #include "drawview.hxx"
      37             : #include "drwlayer.hxx"
      38             : #include "markdata.hxx"
      39             : 
      40             : using namespace com::sun::star;
      41             : 
      42             : // -----------------------------------------------------------------------
      43             : 
      44           0 : static sal_Bool lcl_IsURLButton( SdrObject* pObject )
      45             : {
      46           0 :     sal_Bool bRet = false;
      47             : 
      48           0 :     SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, pObject);
      49           0 :     if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
      50             :        {
      51           0 :         uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
      52             :         OSL_ENSURE( xControlModel.is(), "uno control without model" );
      53           0 :         if ( xControlModel.is() )
      54             :         {
      55           0 :             uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
      56           0 :             uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
      57             : 
      58           0 :             rtl::OUString sPropButtonType(RTL_CONSTASCII_USTRINGPARAM( "ButtonType" ));
      59           0 :             if(xInfo->hasPropertyByName( sPropButtonType ))
      60             :             {
      61           0 :                 uno::Any aAny = xPropSet->getPropertyValue( sPropButtonType );
      62             :                 form::FormButtonType eTmp;
      63           0 :                 if ( (aAny >>= eTmp) && eTmp == form::FormButtonType_URL )
      64           0 :                     bRet = sal_True;
      65           0 :             }
      66           0 :          }
      67             :     }
      68             : 
      69           0 :     return bRet;
      70             : }
      71             : 
      72             : 
      73           0 : ScSelectionTransferObj* ScSelectionTransferObj::CreateFromView( ScTabView* pView )
      74             : {
      75           0 :     ScSelectionTransferObj* pRet = NULL;
      76             : 
      77           0 :     if ( pView )
      78             :     {
      79           0 :         ScSelectionTransferMode eMode = SC_SELTRANS_INVALID;
      80             : 
      81           0 :         SdrView* pSdrView = pView->GetSdrView();
      82           0 :         if ( pSdrView )
      83             :         {
      84             :             //  handle selection on drawing layer
      85           0 :             const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
      86           0 :             sal_uLong nMarkCount = rMarkList.GetMarkCount();
      87           0 :             if ( nMarkCount )
      88             :             {
      89           0 :                 if ( nMarkCount == 1 )
      90             :                 {
      91           0 :                     SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
      92           0 :                     sal_uInt16 nSdrObjKind = pObj->GetObjIdentifier();
      93             : 
      94           0 :                     if ( nSdrObjKind == OBJ_GRAF )
      95             :                     {
      96           0 :                         if ( ((SdrGrafObj*)pObj)->GetGraphic().GetType() == GRAPHIC_BITMAP )
      97           0 :                             eMode = SC_SELTRANS_DRAW_BITMAP;
      98             :                         else
      99           0 :                             eMode = SC_SELTRANS_DRAW_GRAPHIC;
     100             :                     }
     101           0 :                     else if ( nSdrObjKind == OBJ_OLE2 )
     102           0 :                         eMode = SC_SELTRANS_DRAW_OLE;
     103           0 :                     else if ( lcl_IsURLButton( pObj ) )
     104           0 :                         eMode = SC_SELTRANS_DRAW_BOOKMARK;
     105             :                 }
     106             : 
     107           0 :                 if ( eMode == SC_SELTRANS_INVALID )
     108           0 :                     eMode = SC_SELTRANS_DRAW_OTHER;     // something selected but no special selection
     109             :             }
     110             :         }
     111           0 :         if ( eMode == SC_SELTRANS_INVALID )             // no drawing object selected
     112             :         {
     113           0 :             ScRange aRange;
     114           0 :             ScViewData* pViewData = pView->GetViewData();
     115           0 :             const ScMarkData& rMark = pViewData->GetMarkData();
     116             :             //  allow MultiMarked because GetSimpleArea may be able to merge into a simple range
     117             :             //  (GetSimpleArea modifies a local copy of MarkData)
     118             :             // Also allow simple filtered area.
     119             :             ScMarkType eMarkType;
     120           0 :             if ( ( rMark.IsMarked() || rMark.IsMultiMarked() ) &&
     121             :                     (((eMarkType = pViewData->GetSimpleArea( aRange )) == SC_MARK_SIMPLE) ||
     122             :                      (eMarkType == SC_MARK_SIMPLE_FILTERED)) )
     123             :             {
     124             :                 //  only for "real" selection, cursor alone isn't used
     125           0 :                 if ( aRange.aStart == aRange.aEnd )
     126           0 :                     eMode = SC_SELTRANS_CELL;
     127             :                 else
     128           0 :                     eMode = SC_SELTRANS_CELLS;
     129             :             }
     130             :         }
     131             : 
     132           0 :         if ( eMode != SC_SELTRANS_INVALID )
     133           0 :             pRet = new ScSelectionTransferObj( pView, eMode );
     134             :     }
     135             : 
     136           0 :     return pRet;
     137             : }
     138             : 
     139             : 
     140           0 : ScSelectionTransferObj::ScSelectionTransferObj( ScTabView* pSource, ScSelectionTransferMode eNewMode ) :
     141             :     pView( pSource ),
     142             :     eMode( eNewMode ),
     143             :     pCellData( NULL ),
     144           0 :     pDrawData( NULL )
     145             : {
     146             :     //! store range for StillValid
     147           0 : }
     148             : 
     149           0 : ScSelectionTransferObj::~ScSelectionTransferObj()
     150             : {
     151           0 :     ScModule* pScMod = SC_MOD();
     152           0 :     if ( pScMod->GetSelectionTransfer() == this )
     153             :     {
     154             :         //  this is reached when the object wasn't really copied to the selection
     155             :         //  (CopyToSelection has no effect under Windows)
     156             : 
     157           0 :         ForgetView();
     158           0 :         pScMod->SetSelectionTransfer( NULL );
     159             :     }
     160             : 
     161             :     OSL_ENSURE( !pView, "ScSelectionTransferObj dtor: ForgetView not called" );
     162           0 : }
     163             : 
     164           0 : sal_Bool ScSelectionTransferObj::StillValid()
     165             : {
     166             :     //! check if view still has same cell selection
     167             :     //! (but return sal_False if data has changed inbetween)
     168           0 :     return false;
     169             : }
     170             : 
     171           0 : void ScSelectionTransferObj::ForgetView()
     172             : {
     173           0 :     pView = NULL;
     174           0 :     eMode = SC_SELTRANS_INVALID;
     175             : 
     176           0 :     if (pCellData)
     177             :     {
     178           0 :         pCellData->release();
     179           0 :         pCellData = NULL;
     180             :     }
     181           0 :     if (pDrawData)
     182             :     {
     183           0 :         pDrawData->release();
     184           0 :         pDrawData = NULL;
     185             :     }
     186           0 : }
     187             : 
     188           0 : void ScSelectionTransferObj::AddSupportedFormats()
     189             : {
     190             :     //  AddSupportedFormats must work without actually creating the
     191             :     //  "real" transfer object
     192             : 
     193           0 :     switch (eMode)
     194             :     {
     195             :         case SC_SELTRANS_CELL:
     196             :         case SC_SELTRANS_CELLS:
     197             :             //  same formats as in ScTransferObj::AddSupportedFormats
     198           0 :             AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
     199           0 :             AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
     200           0 :             AddFormat( SOT_FORMAT_GDIMETAFILE );
     201           0 :             AddFormat( SOT_FORMAT_BITMAP );
     202           0 :             AddFormat( SOT_FORMATSTR_ID_HTML );
     203           0 :             AddFormat( SOT_FORMATSTR_ID_SYLK );
     204           0 :             AddFormat( SOT_FORMATSTR_ID_LINK );
     205           0 :             AddFormat( SOT_FORMATSTR_ID_DIF );
     206           0 :             AddFormat( SOT_FORMAT_STRING );
     207           0 :             AddFormat( SOT_FORMAT_RTF );
     208           0 :             if ( eMode == SC_SELTRANS_CELL )
     209           0 :                 AddFormat( SOT_FORMATSTR_ID_EDITENGINE );
     210           0 :             break;
     211             : 
     212             :         // different graphic formats as in ScDrawTransferObj::AddSupportedFormats:
     213             : 
     214             :         case SC_SELTRANS_DRAW_BITMAP:
     215           0 :             AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
     216           0 :             AddFormat( SOT_FORMATSTR_ID_SVXB );
     217           0 :             AddFormat( SOT_FORMAT_BITMAP );
     218           0 :             AddFormat( SOT_FORMAT_GDIMETAFILE );
     219           0 :             break;
     220             : 
     221             :         case SC_SELTRANS_DRAW_GRAPHIC:
     222           0 :             AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
     223           0 :             AddFormat( SOT_FORMATSTR_ID_SVXB );
     224           0 :             AddFormat( SOT_FORMAT_GDIMETAFILE );
     225           0 :             AddFormat( SOT_FORMAT_BITMAP );
     226           0 :              break;
     227             : 
     228             :         case SC_SELTRANS_DRAW_BOOKMARK:
     229           0 :             AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
     230           0 :             AddFormat( SOT_FORMATSTR_ID_SOLK );
     231           0 :             AddFormat( SOT_FORMAT_STRING );
     232           0 :             AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
     233           0 :             AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
     234           0 :             AddFormat( SOT_FORMATSTR_ID_DRAWING );
     235           0 :             break;
     236             : 
     237             :         case SC_SELTRANS_DRAW_OLE:
     238           0 :             AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
     239           0 :             AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
     240           0 :             AddFormat( SOT_FORMAT_GDIMETAFILE );
     241           0 :             break;
     242             : 
     243             :         case SC_SELTRANS_DRAW_OTHER:
     244             :             //  other drawing objects
     245           0 :             AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
     246           0 :             AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
     247           0 :             AddFormat( SOT_FORMATSTR_ID_DRAWING );
     248           0 :             AddFormat( SOT_FORMAT_BITMAP );
     249           0 :             AddFormat( SOT_FORMAT_GDIMETAFILE );
     250           0 :             break;
     251             : 
     252             :         default:
     253             :         {
     254             :             // added to avoid warnings
     255             :         }
     256             :     }
     257           0 : }
     258             : 
     259           0 : void ScSelectionTransferObj::CreateCellData()
     260             : {
     261             :     OSL_ENSURE( !pCellData, "CreateCellData twice" );
     262           0 :     if ( pView )
     263             :     {
     264           0 :         ScViewData* pViewData = pView->GetViewData();
     265           0 :         ScMarkData aNewMark( pViewData->GetMarkData() );    // use local copy for MarkToSimple
     266           0 :         aNewMark.MarkToSimple();
     267             : 
     268             :         //  similar to ScViewFunctionSet::BeginDrag
     269           0 :         if ( aNewMark.IsMarked() && !aNewMark.IsMultiMarked() )
     270             :         {
     271           0 :             ScDocShell* pDocSh = pViewData->GetDocShell();
     272             : 
     273           0 :             ScRange aSelRange;
     274           0 :             aNewMark.GetMarkArea( aSelRange );
     275           0 :             ScDocShellRef aDragShellRef;
     276           0 :             if ( pDocSh->GetDocument()->HasOLEObjectsInArea( aSelRange, &aNewMark ) )
     277             :             {
     278           0 :                 aDragShellRef = new ScDocShell;     // DocShell needs a Ref immediately
     279           0 :                 aDragShellRef->DoInitNew(NULL);
     280             :             }
     281           0 :             ScDrawLayer::SetGlobalDrawPersist(aDragShellRef);
     282             : 
     283           0 :             ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
     284             :             // bApi = sal_True -> no error mesages
     285             :             // #i18364# bStopEdit = sal_False -> don't end edit mode
     286             :             // (this may be called from pasting into the edit line)
     287           0 :             sal_Bool bCopied = pViewData->GetView()->CopyToClip( pClipDoc, false, sal_True, sal_True, false );
     288             : 
     289           0 :             ScDrawLayer::SetGlobalDrawPersist(NULL);
     290             : 
     291           0 :             if ( bCopied )
     292             :             {
     293           0 :                 TransferableObjectDescriptor aObjDesc;
     294           0 :                 pDocSh->FillTransferableObjectDescriptor( aObjDesc );
     295           0 :                 aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
     296             :                 // maSize is set in ScTransferObj ctor
     297             : 
     298           0 :                 ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
     299           0 :                 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
     300             : 
     301             :                 // SetDragHandlePos is not used - there is no mouse position
     302             :                 //? pTransferObj->SetVisibleTab( nTab );
     303             : 
     304           0 :                 SfxObjectShellRef aPersistRef( aDragShellRef );
     305           0 :                 pTransferObj->SetDrawPersist( aPersistRef );    // keep persist for ole objects alive
     306             : 
     307           0 :                 pTransferObj->SetDragSource( pDocSh, aNewMark );
     308             : 
     309           0 :                 pCellData = pTransferObj;
     310           0 :                 pCellData->acquire();       // keep ref count up - released in ForgetView
     311             :             }
     312             :             else
     313           0 :                 delete pClipDoc;
     314           0 :         }
     315             :     }
     316             :     OSL_ENSURE( pCellData, "can't create CellData" );
     317           0 : }
     318             : 
     319           0 : void ScSelectionTransferObj::CreateDrawData()
     320             : {
     321             :     OSL_ENSURE( !pDrawData, "CreateDrawData twice" );
     322           0 :     if ( pView )
     323             :     {
     324             :         //  similar to ScDrawView::BeginDrag
     325             : 
     326           0 :         ScDrawView* pDrawView = pView->GetScDrawView();
     327           0 :         if ( pDrawView )
     328             :         {
     329             :             sal_Bool bAnyOle, bOneOle;
     330           0 :             const SdrMarkList& rMarkList = pDrawView->GetMarkedObjectList();
     331           0 :             ScDrawView::CheckOle( rMarkList, bAnyOle, bOneOle );
     332             : 
     333             :             //---------------------------------------------------------
     334           0 :             ScDocShellRef aDragShellRef;
     335           0 :             if (bAnyOle)
     336             :             {
     337           0 :                 aDragShellRef = new ScDocShell;     // ohne Ref lebt die DocShell nicht !!!
     338           0 :                 aDragShellRef->DoInitNew(NULL);
     339             :             }
     340             :             //---------------------------------------------------------
     341             : 
     342           0 :             ScDrawLayer::SetGlobalDrawPersist(aDragShellRef);
     343           0 :             SdrModel* pModel = pDrawView->GetAllMarkedModel();
     344           0 :             ScDrawLayer::SetGlobalDrawPersist(NULL);
     345             : 
     346           0 :             ScViewData* pViewData = pView->GetViewData();
     347           0 :             ScDocShell* pDocSh = pViewData->GetDocShell();
     348             : 
     349           0 :             TransferableObjectDescriptor aObjDesc;
     350           0 :             pDocSh->FillTransferableObjectDescriptor( aObjDesc );
     351           0 :             aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
     352             :             // maSize is set in ScDrawTransferObj ctor
     353             : 
     354           0 :             ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pModel, pDocSh, aObjDesc );
     355           0 :             uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
     356             : 
     357           0 :             SfxObjectShellRef aPersistRef( aDragShellRef );
     358           0 :             pTransferObj->SetDrawPersist( aPersistRef );    // keep persist for ole objects alive
     359           0 :             pTransferObj->SetDragSource( pDrawView );       // copies selection
     360             : 
     361           0 :             pDrawData = pTransferObj;
     362           0 :             pDrawData->acquire();       // keep ref count up - released in ForgetView
     363             :         }
     364             :     }
     365             :     OSL_ENSURE( pDrawData, "can't create DrawData" );
     366           0 : }
     367             : 
     368           0 : ScTransferObj* ScSelectionTransferObj::GetCellData()
     369             : {
     370           0 :     if ( !pCellData && ( eMode == SC_SELTRANS_CELL || eMode == SC_SELTRANS_CELLS ) )
     371           0 :         CreateCellData();
     372           0 :     return pCellData;
     373             : }
     374             : 
     375           0 : ScDrawTransferObj* ScSelectionTransferObj::GetDrawData()
     376             : {
     377           0 :     if ( !pDrawData && ( eMode == SC_SELTRANS_DRAW_BITMAP || eMode == SC_SELTRANS_DRAW_GRAPHIC ||
     378             :                          eMode == SC_SELTRANS_DRAW_BOOKMARK || eMode == SC_SELTRANS_DRAW_OLE ||
     379             :                          eMode == SC_SELTRANS_DRAW_OTHER ) )
     380           0 :         CreateDrawData();
     381           0 :     return pDrawData;
     382             : }
     383             : 
     384           0 : sal_Bool ScSelectionTransferObj::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
     385             : {
     386           0 :     sal_Bool bOK = false;
     387             : 
     388           0 :     uno::Reference<datatransfer::XTransferable> xSource;
     389           0 :     switch (eMode)
     390             :     {
     391             :         case SC_SELTRANS_CELL:
     392             :         case SC_SELTRANS_CELLS:
     393           0 :             xSource = GetCellData();
     394           0 :             break;
     395             :         case SC_SELTRANS_DRAW_BITMAP:
     396             :         case SC_SELTRANS_DRAW_GRAPHIC:
     397             :         case SC_SELTRANS_DRAW_BOOKMARK:
     398             :         case SC_SELTRANS_DRAW_OLE:
     399             :         case SC_SELTRANS_DRAW_OTHER:
     400           0 :             xSource = GetDrawData();
     401           0 :             break;
     402             :         default:
     403             :         {
     404             :             // added to avoid warnings
     405             :         }
     406             :     }
     407             : 
     408           0 :     if ( xSource.is() )
     409             :     {
     410           0 :         TransferableDataHelper aHelper( xSource );
     411           0 :         uno::Any aAny = aHelper.GetAny( rFlavor );
     412           0 :         bOK = SetAny( aAny, rFlavor );
     413             :     }
     414             : 
     415           0 :     return bOK;
     416             : }
     417             : 
     418           0 : void ScSelectionTransferObj::ObjectReleased()
     419             : {
     420             :     //  called when another selection is set from outside
     421             : 
     422           0 :     ForgetView();
     423             : 
     424           0 :     ScModule* pScMod = SC_MOD();
     425           0 :     if ( pScMod->GetSelectionTransfer() == this )
     426           0 :         pScMod->SetSelectionTransfer( NULL );
     427             : 
     428           0 :     TransferableHelper::ObjectReleased();
     429          15 : }
     430             : 
     431             : 
     432             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10