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

Generated by: LCOV version 1.11