LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/view - drawvie4.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 148 1.4 %
Date: 2012-12-27 Functions: 2 8 25.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/embed/NoVisualAreaSizeException.hpp>
      21             : 
      22             : #include <svx/svditer.hxx>
      23             : #include <svx/svdograf.hxx>
      24             : #include <svx/svdogrp.hxx>
      25             : #include <svx/svdoole2.hxx>
      26             : #include <svx/svdpage.hxx>
      27             : #include <svx/svdundo.hxx>
      28             : #include <sfx2/docfile.hxx>
      29             : #include <tools/urlobj.hxx>
      30             : #include <toolkit/helper/vclunohelper.hxx>
      31             : 
      32             : #include "drawview.hxx"
      33             : #include "global.hxx"
      34             : #include "drwlayer.hxx"
      35             : #include "viewdata.hxx"
      36             : #include "document.hxx"
      37             : #include "docsh.hxx"
      38             : #include "drwtrans.hxx"
      39             : #include "transobj.hxx"     // SetDrawClipDoc
      40             : #include "drawutil.hxx"
      41             : #include "scmod.hxx"
      42             : #include "globstr.hrc"
      43             : #include "chartarr.hxx"
      44             : 
      45             : using namespace com::sun::star;
      46             : 
      47             : // STATIC DATA -----------------------------------------------------------
      48             : 
      49           5 : Point aDragStartDiff;
      50             : 
      51             : // -----------------------------------------------------------------------
      52             : 
      53             : //! welche Funktionen aus drawview/drawvie4 muessen wirklich ohne Optimierung sein?
      54             : 
      55             : #ifdef _MSC_VER
      56             : #pragma optimize ( "", off )
      57             : #endif
      58             : 
      59             : // -----------------------------------------------------------------------
      60             : 
      61           0 : void ScDrawView::CheckOle( const SdrMarkList& rMarkList, sal_Bool& rAnyOle, sal_Bool& rOneOle )
      62             : {
      63           0 :     rAnyOle = rOneOle = false;
      64           0 :     sal_uLong nCount = rMarkList.GetMarkCount();
      65           0 :     for (sal_uLong i=0; i<nCount; i++)
      66             :     {
      67           0 :         SdrMark* pMark = rMarkList.GetMark(i);
      68           0 :         SdrObject* pObj = pMark->GetMarkedSdrObj();
      69           0 :         sal_uInt16 nSdrObjKind = pObj->GetObjIdentifier();
      70           0 :         if (nSdrObjKind == OBJ_OLE2)
      71             :         {
      72           0 :             rAnyOle = sal_True;
      73           0 :             rOneOle = (nCount == 1);
      74           0 :             break;
      75             :         }
      76           0 :         else if ( pObj->ISA(SdrObjGroup) )
      77             :         {
      78           0 :             SdrObjListIter aIter( *pObj, IM_DEEPNOGROUPS );
      79           0 :             SdrObject* pSubObj = aIter.Next();
      80           0 :             while (pSubObj)
      81             :             {
      82           0 :                 if ( pSubObj->GetObjIdentifier() == OBJ_OLE2 )
      83             :                 {
      84           0 :                     rAnyOle = sal_True;
      85             :                     // rOneOle remains sal_False - a group isn't treated like a single OLE object
      86           0 :                     return;
      87             :                 }
      88           0 :                 pSubObj = aIter.Next();
      89           0 :             }
      90             :         }
      91             :     }
      92             : }
      93             : 
      94           0 : sal_Bool ScDrawView::BeginDrag( Window* pWindow, const Point& rStartPos )
      95             : {
      96           0 :     sal_Bool bReturn = false;
      97             : 
      98           0 :     if ( AreObjectsMarked() )
      99             :     {
     100           0 :         BrkAction();
     101             : 
     102           0 :         Rectangle aMarkedRect = GetAllMarkedRect();
     103           0 :         Region aRegion( aMarkedRect );
     104             : 
     105           0 :         aDragStartDiff = rStartPos - aMarkedRect.TopLeft();
     106             : 
     107             :         sal_Bool bAnyOle, bOneOle;
     108           0 :         const SdrMarkList& rMarkList = GetMarkedObjectList();
     109           0 :         CheckOle( rMarkList, bAnyOle, bOneOle );
     110             : 
     111           0 :         ScDocShellRef aDragShellRef;
     112           0 :         if (bAnyOle)
     113             :         {
     114           0 :             aDragShellRef = new ScDocShell;     // DocShell needs a Ref immediately
     115           0 :             aDragShellRef->DoInitNew(NULL);
     116             :         }
     117           0 :         ScDrawLayer::SetGlobalDrawPersist(aDragShellRef);
     118           0 :         SdrModel* pModel = GetAllMarkedModel();
     119           0 :         ScDrawLayer::SetGlobalDrawPersist(NULL);
     120             : 
     121             :         //  Charts now always copy their data in addition to the source reference, so
     122             :         //  there's no need to call SchDLL::Update for the charts in the clipboard doc.
     123             :         //  Update with the data (including NumberFormatter) from the live document would
     124             :         //  also store the NumberFormatter in the clipboard chart (#88749#)
     125             :         // lcl_RefreshChartData( pModel, pViewData->GetDocument() );
     126             : 
     127           0 :         ScDocShell* pDocSh = pViewData->GetDocShell();
     128             : 
     129           0 :         TransferableObjectDescriptor aObjDesc;
     130           0 :         pDocSh->FillTransferableObjectDescriptor( aObjDesc );
     131           0 :         aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
     132             :         // maSize is set in ScDrawTransferObj ctor
     133             : 
     134           0 :         ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pModel, pDocSh, aObjDesc );
     135           0 :         uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
     136             : 
     137           0 :         pTransferObj->SetDrawPersist( &aDragShellRef );    // keep persist for ole objects alive
     138           0 :         pTransferObj->SetDragSource( this );            // copies selection
     139             : 
     140           0 :         SC_MOD()->SetDragObject( NULL, pTransferObj );      // for internal D&D
     141           0 :         pTransferObj->StartDrag( pWindow, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
     142             :     }
     143             : 
     144           0 :     return bReturn;
     145             : }
     146             : 
     147           0 : void ScDrawView::DoCopy()
     148             : {
     149             :     sal_Bool bAnyOle, bOneOle;
     150           0 :     const SdrMarkList& rMarkList = GetMarkedObjectList();
     151           0 :     CheckOle( rMarkList, bAnyOle, bOneOle );
     152             : 
     153             :     // update ScGlobal::pDrawClipDocShellRef
     154           0 :     ScDrawLayer::SetGlobalDrawPersist( ScTransferObj::SetDrawClipDoc( bAnyOle ) );
     155           0 :     SdrModel* pModel = GetAllMarkedModel();
     156           0 :     ScDrawLayer::SetGlobalDrawPersist(NULL);
     157             : 
     158             :     //  Charts now always copy their data in addition to the source reference, so
     159             :     //  there's no need to call SchDLL::Update for the charts in the clipboard doc.
     160             :     //  Update with the data (including NumberFormatter) from the live document would
     161             :     //  also store the NumberFormatter in the clipboard chart (#88749#)
     162             :     // lcl_RefreshChartData( pModel, pViewData->GetDocument() );
     163             : 
     164           0 :     ScDocShell* pDocSh = pViewData->GetDocShell();
     165             : 
     166           0 :     TransferableObjectDescriptor aObjDesc;
     167           0 :     pDocSh->FillTransferableObjectDescriptor( aObjDesc );
     168           0 :     aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
     169             :     // maSize is set in ScDrawTransferObj ctor
     170             : 
     171           0 :     ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pModel, pDocSh, aObjDesc );
     172           0 :     uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
     173             : 
     174           0 :     if ( ScGlobal::pDrawClipDocShellRef )
     175             :     {
     176           0 :         pTransferObj->SetDrawPersist( &(*ScGlobal::pDrawClipDocShellRef) );    // keep persist for ole objects alive
     177             :     }
     178             : 
     179           0 :     pTransferObj->CopyToClipboard( pViewData->GetActiveWin() );     // system clipboard
     180           0 :     SC_MOD()->SetClipObject( NULL, pTransferObj );                  // internal clipboard
     181           0 : }
     182             : 
     183           0 : uno::Reference<datatransfer::XTransferable> ScDrawView::CopyToTransferable()
     184             : {
     185             :     sal_Bool bAnyOle, bOneOle;
     186           0 :     const SdrMarkList& rMarkList = GetMarkedObjectList();
     187           0 :     CheckOle( rMarkList, bAnyOle, bOneOle );
     188             : 
     189             :     // update ScGlobal::pDrawClipDocShellRef
     190           0 :     ScDrawLayer::SetGlobalDrawPersist( ScTransferObj::SetDrawClipDoc( bAnyOle ) );
     191           0 :     SdrModel* pModel = GetAllMarkedModel();
     192           0 :     ScDrawLayer::SetGlobalDrawPersist(NULL);
     193             : 
     194             :     //  Charts now always copy their data in addition to the source reference, so
     195             :     //  there's no need to call SchDLL::Update for the charts in the clipboard doc.
     196             :     //  Update with the data (including NumberFormatter) from the live document would
     197             :     //  also store the NumberFormatter in the clipboard chart (#88749#)
     198             :     // lcl_RefreshChartData( pModel, pViewData->GetDocument() );
     199             : 
     200           0 :     ScDocShell* pDocSh = pViewData->GetDocShell();
     201             : 
     202           0 :     TransferableObjectDescriptor aObjDesc;
     203           0 :     pDocSh->FillTransferableObjectDescriptor( aObjDesc );
     204           0 :     aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
     205             :     // maSize is set in ScDrawTransferObj ctor
     206             : 
     207           0 :     ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pModel, pDocSh, aObjDesc );
     208           0 :     uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
     209             : 
     210           0 :     if ( ScGlobal::pDrawClipDocShellRef )
     211             :     {
     212           0 :         pTransferObj->SetDrawPersist( &(*ScGlobal::pDrawClipDocShellRef) );    // keep persist for ole objects alive
     213             :     }
     214             : 
     215           0 :     return xTransferable;
     216             : }
     217             : 
     218             : //  Korrektur fuer 100% berechnen, unabhaengig von momentanen Einstellungen
     219             : 
     220           0 : void ScDrawView::CalcNormScale( Fraction& rFractX, Fraction& rFractY ) const
     221             : {
     222           0 :     double nPPTX = ScGlobal::nScreenPPTX;
     223           0 :     double nPPTY = ScGlobal::nScreenPPTY;
     224             : 
     225           0 :     if (pViewData)
     226           0 :         nPPTX /= pViewData->GetDocShell()->GetOutputFactor();
     227             : 
     228           0 :     SCCOL nEndCol = 0;
     229           0 :     SCROW nEndRow = 0;
     230           0 :     pDoc->GetTableArea( nTab, nEndCol, nEndRow );
     231           0 :     if (nEndCol<20)
     232           0 :         nEndCol = 20;
     233           0 :     if (nEndRow<20)
     234           0 :         nEndRow = 1000;
     235             : 
     236           0 :     Fraction aZoom(1,1);
     237             :     ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, pDev, aZoom,aZoom,
     238           0 :                             nPPTX, nPPTY, rFractX,rFractY );
     239           0 : }
     240             : 
     241           0 : void ScDrawView::SetMarkedOriginalSize()
     242             : {
     243           0 :     SdrUndoGroup* pUndoGroup = new SdrUndoGroup(*GetModel());
     244             : 
     245           0 :     const SdrMarkList& rMarkList = GetMarkedObjectList();
     246           0 :     long nDone = 0;
     247           0 :     sal_uLong nCount = rMarkList.GetMarkCount();
     248           0 :     for (sal_uLong i=0; i<nCount; i++)
     249             :     {
     250           0 :         SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
     251           0 :         sal_uInt16 nIdent = pObj->GetObjIdentifier();
     252           0 :         sal_Bool bDo = false;
     253           0 :         Size aOriginalSize;
     254           0 :         if (nIdent == OBJ_OLE2)
     255             :         {
     256             :             // TODO/LEAN: working with visual area can switch object to running state
     257           0 :             uno::Reference < embed::XEmbeddedObject > xObj( ((SdrOle2Obj*)pObj)->GetObjRef(), uno::UNO_QUERY );
     258           0 :             if ( xObj.is() )    // NULL for an invalid object that couldn't be loaded
     259             :             {
     260           0 :                 sal_Int64 nAspect = ((SdrOle2Obj*)pObj)->GetAspect();
     261             : 
     262           0 :                 if ( nAspect == embed::Aspects::MSOLE_ICON )
     263             :                 {
     264           0 :                     MapMode aMapMode( MAP_100TH_MM );
     265           0 :                     aOriginalSize = ((SdrOle2Obj*)pObj)->GetOrigObjSize( &aMapMode );
     266           0 :                     bDo = sal_True;
     267             :                 }
     268             :                 else
     269             :                 {
     270           0 :                     MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( ((SdrOle2Obj*)pObj)->GetAspect() ) );
     271           0 :                     awt::Size aSz;
     272             :                     try
     273             :                     {
     274           0 :                         aSz = xObj->getVisualAreaSize( ((SdrOle2Obj*)pObj)->GetAspect() );
     275             :                         aOriginalSize = OutputDevice::LogicToLogic(
     276             :                                             Size( aSz.Width, aSz.Height ),
     277           0 :                                             aUnit, MAP_100TH_MM );
     278           0 :                         bDo = sal_True;
     279           0 :                     } catch( embed::NoVisualAreaSizeException& )
     280             :                     {
     281             :                         OSL_ENSURE( false, "Can't get the original size of the object!" );
     282             :                     }
     283             :                 }
     284           0 :             }
     285             :         }
     286           0 :         else if (nIdent == OBJ_GRAF)
     287             :         {
     288           0 :             const Graphic& rGraphic = ((SdrGrafObj*)pObj)->GetGraphic();
     289             : 
     290           0 :             MapMode aSourceMap = rGraphic.GetPrefMapMode();
     291           0 :             MapMode aDestMap( MAP_100TH_MM );
     292           0 :             if (aSourceMap.GetMapUnit() == MAP_PIXEL)
     293             :             {
     294             :                 //  Pixel-Korrektur beruecksichtigen, damit Bitmap auf dem Bildschirm stimmt
     295             : 
     296           0 :                 Fraction aNormScaleX, aNormScaleY;
     297           0 :                 CalcNormScale( aNormScaleX, aNormScaleY );
     298           0 :                 aDestMap.SetScaleX(aNormScaleX);
     299           0 :                 aDestMap.SetScaleY(aNormScaleY);
     300             :             }
     301           0 :             if (pViewData)
     302             :             {
     303           0 :                 Window* pActWin = pViewData->GetActiveWin();
     304           0 :                 if (pActWin)
     305             :                 {
     306             :                     aOriginalSize = pActWin->LogicToLogic(
     307           0 :                                     rGraphic.GetPrefSize(), &aSourceMap, &aDestMap );
     308           0 :                     bDo = sal_True;
     309             :                 }
     310           0 :             }
     311             :         }
     312             : 
     313           0 :         if ( bDo )
     314             :         {
     315           0 :             Rectangle aDrawRect = pObj->GetLogicRect();
     316             : 
     317           0 :             pUndoGroup->AddAction( new SdrUndoGeoObj( *pObj ) );
     318           0 :             pObj->Resize( aDrawRect.TopLeft(), Fraction( aOriginalSize.Width(), aDrawRect.GetWidth() ),
     319           0 :                                                  Fraction( aOriginalSize.Height(), aDrawRect.GetHeight() ) );
     320           0 :             ++nDone;
     321             :         }
     322             :     }
     323             : 
     324           0 :     if (nDone)
     325             :     {
     326           0 :         pUndoGroup->SetComment(ScGlobal::GetRscString( STR_UNDO_ORIGINALSIZE ));
     327           0 :         ScDocShell* pDocSh = pViewData->GetDocShell();
     328           0 :         pDocSh->GetUndoManager()->AddUndoAction(pUndoGroup);
     329           0 :         pDocSh->SetDrawModified();
     330             :     }
     331             :     else
     332           0 :         delete pUndoGroup;
     333          15 : }
     334             : 
     335             : 
     336             : #ifdef _MSC_VER
     337             : #pragma optimize ( "", on )
     338             : #endif
     339             : 
     340             : 
     341             : 
     342             : 
     343             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10