LCOV - code coverage report
Current view: top level - sc/source/ui/view - drawvie4.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 148 1.4 %
Date: 2012-08-25 Functions: 2 8 25.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 284 0.7 %

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

Generated by: LCOV version 1.10