LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/app - client.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 113 0.9 %
Date: 2012-12-27 Functions: 2 10 20.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/XEmbeddedObject.hpp>
      21             : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
      22             : 
      23             : #include <toolkit/helper/vclunohelper.hxx>
      24             : #include <sfx2/objsh.hxx>
      25             : #include <sfx2/viewfrm.hxx>
      26             : #include <svx/svditer.hxx>
      27             : #include <svx/svdobj.hxx>
      28             : #include <svx/svdmodel.hxx>
      29             : #include <svx/svdpage.hxx>
      30             : #include <svx/svdoole2.hxx>
      31             : #include <svx/svdview.hxx>
      32             : #include <svx/svdograf.hxx>
      33             : #include <svtools/embedhlp.hxx>
      34             : 
      35             : #include "client.hxx"
      36             : #include "tabvwsh.hxx"
      37             : #include "docsh.hxx"
      38             : 
      39             : using namespace com::sun::star;
      40             : 
      41             : //------------------------------------------------------------------------
      42             : 
      43           0 : ScClient::ScClient( ScTabViewShell* pViewShell, Window* pDraw, SdrModel* pSdrModel, SdrOle2Obj* pObj ) :
      44             :     SfxInPlaceClient( pViewShell, pDraw, pObj->GetAspect() ),
      45             :     pModel( pSdrModel ),
      46           0 :     pGrafEdit( 0 )
      47             : {
      48           0 :     SetObject( pObj->GetObjRef() );
      49           0 : }
      50             : 
      51           0 : ScClient::~ScClient()
      52             : {
      53           0 : }
      54             : 
      55           0 : SdrOle2Obj* ScClient::GetDrawObj()
      56             : {
      57           0 :     uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
      58           0 :     SdrOle2Obj* pOle2Obj = NULL;
      59           0 :     String aName = GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
      60             : 
      61           0 :     sal_uInt16 nPages = pModel->GetPageCount();
      62           0 :     for (sal_uInt16 nPNr=0; nPNr<nPages && !pOle2Obj; nPNr++)
      63             :     {
      64           0 :         SdrPage* pPage = pModel->GetPage(nPNr);
      65           0 :         SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
      66           0 :         SdrObject* pObject = aIter.Next();
      67           0 :         while (pObject && !pOle2Obj)
      68             :         {
      69           0 :             if ( pObject->GetObjIdentifier() == OBJ_OLE2 )
      70             :             {
      71             :                 // name from InfoObject is PersistName
      72           0 :                 if ( ((SdrOle2Obj*)pObject)->GetPersistName() == aName )
      73           0 :                     pOle2Obj = (SdrOle2Obj*)pObject;
      74             :             }
      75           0 :             pObject = aIter.Next();
      76             :         }
      77           0 :     }
      78           0 :     return pOle2Obj;
      79             : }
      80             : 
      81           0 : void ScClient::RequestNewObjectArea( Rectangle& aLogicRect )
      82             : {
      83           0 :     SfxViewShell* pSfxViewSh = GetViewShell();
      84           0 :     ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
      85           0 :     if (!pViewSh)
      86             :     {
      87             :         OSL_FAIL("Wrong ViewShell");
      88           0 :         return;
      89             :     }
      90             : 
      91           0 :     Rectangle aOldRect = GetObjArea();
      92           0 :     SdrOle2Obj*  pDrawObj = GetDrawObj();
      93           0 :     if ( pDrawObj )
      94             :     {
      95           0 :         if ( pDrawObj->IsResizeProtect() )
      96           0 :             aLogicRect.SetSize( aOldRect.GetSize() );
      97             : 
      98           0 :         if ( pDrawObj->IsMoveProtect() )
      99           0 :             aLogicRect.SetPos( aOldRect.TopLeft() );
     100             :     }
     101             : 
     102           0 :     sal_uInt16 nTab = pViewSh->GetViewData()->GetTabNo();
     103           0 :     SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(static_cast<sal_Int16>(nTab)));
     104           0 :     if ( pPage && aLogicRect != aOldRect )
     105             :     {
     106           0 :         Point aPos;
     107           0 :         Size aSize = pPage->GetSize();
     108           0 :         if ( aSize.Width() < 0 )
     109             :         {
     110           0 :             aPos.X() = aSize.Width() + 1;       // negative
     111           0 :             aSize.Width() = -aSize.Width();     // positive
     112             :         }
     113           0 :         Rectangle aPageRect( aPos, aSize );
     114             : 
     115           0 :         if (aLogicRect.Right() > aPageRect.Right())
     116             :         {
     117           0 :             long nDiff = aLogicRect.Right() - aPageRect.Right();
     118           0 :             aLogicRect.Left() -= nDiff;
     119           0 :             aLogicRect.Right() -= nDiff;
     120             :         }
     121           0 :         if (aLogicRect.Bottom() > aPageRect.Bottom())
     122             :         {
     123           0 :             long nDiff = aLogicRect.Bottom() - aPageRect.Bottom();
     124           0 :             aLogicRect.Top() -= nDiff;
     125           0 :             aLogicRect.Bottom() -= nDiff;
     126             :         }
     127             : 
     128           0 :         if (aLogicRect.Left() < aPageRect.Left())
     129             :         {
     130           0 :             long nDiff = aLogicRect.Left() - aPageRect.Left();
     131           0 :             aLogicRect.Right() -= nDiff;
     132           0 :             aLogicRect.Left() -= nDiff;
     133             :         }
     134           0 :         if (aLogicRect.Top() < aPageRect.Top())
     135             :         {
     136           0 :             long nDiff = aLogicRect.Top() - aPageRect.Top();
     137           0 :             aLogicRect.Bottom() -= nDiff;
     138           0 :             aLogicRect.Top() -= nDiff;
     139             :         }
     140             :     }
     141             : }
     142             : 
     143           0 : void ScClient::ObjectAreaChanged()
     144             : {
     145           0 :     SfxViewShell* pSfxViewSh = GetViewShell();
     146           0 :     ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
     147           0 :     if (!pViewSh)
     148             :     {
     149             :         OSL_FAIL("Wrong ViewShell");
     150           0 :         return;
     151             :     }
     152             : 
     153             :     //  Position und Groesse ins Dokument uebernehmen
     154           0 :     SdrOle2Obj* pDrawObj = GetDrawObj();
     155           0 :     if (pDrawObj)
     156             :     {
     157           0 :         Rectangle aNewRectangle(GetScaledObjArea());
     158             : 
     159             :         // #i118524# if sheared/rotated, center to non-rotated LogicRect
     160           0 :         pDrawObj->setSuppressSetVisAreaSize(true);
     161             : 
     162           0 :         if(pDrawObj->GetGeoStat().nDrehWink || pDrawObj->GetGeoStat().nShearWink)
     163             :         {
     164           0 :             pDrawObj->SetLogicRect( aNewRectangle );
     165             : 
     166           0 :             const Rectangle& rBoundRect = pDrawObj->GetCurrentBoundRect();
     167           0 :             const Point aDelta(aNewRectangle.Center() - rBoundRect.Center());
     168             : 
     169           0 :             aNewRectangle.Move(aDelta.X(), aDelta.Y());
     170             :         }
     171             : 
     172           0 :         pDrawObj->SetLogicRect( aNewRectangle );
     173           0 :         pDrawObj->setSuppressSetVisAreaSize(false);
     174             : 
     175             :         //  set document modified (SdrModel::SetChanged is not used)
     176             :         // TODO/LATER: is there a reason that this code is not executed in Draw?
     177             : //        SfxViewShell* pSfxViewSh = GetViewShell();
     178             : //        ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
     179           0 :         if (pViewSh)
     180           0 :             pViewSh->GetViewData()->GetDocShell()->SetDrawModified();
     181             :     }
     182             : 
     183           0 :     if (pDrawObj)
     184           0 :         pViewSh->ScrollToObject( pDrawObj );
     185             : }
     186             : 
     187           0 : void ScClient::ViewChanged()
     188             : {
     189           0 :     if ( GetAspect() == embed::Aspects::MSOLE_ICON )
     190             :     {
     191             :         // the iconified object seems not to need such a scaling handling
     192             :         // since the replacement image and the size a completely controlled by the container
     193             :         // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
     194             : 
     195           0 :         return;
     196             :     }
     197             : 
     198           0 :     uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
     199             : 
     200             :     // TODO/LEAN: working with Visual Area can switch object to running state
     201           0 :     awt::Size aSz;
     202             :     try {
     203           0 :         aSz = xObj->getVisualAreaSize( GetAspect() );
     204           0 :     } catch ( embed::NoVisualAreaSizeException& )
     205             :     {
     206             :         OSL_FAIL("The visual area size must be available!\n");
     207             :     }
     208             : 
     209           0 :     MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( GetAspect() ) );
     210           0 :     Size aVisSize = OutputDevice::LogicToLogic( Size( aSz.Width, aSz.Height ), aMapUnit, MAP_100TH_MM );
     211             : 
     212             :     //  Groesse ins Dokument uebernehmen
     213           0 :     SdrOle2Obj* pDrawObj = GetDrawObj();
     214           0 :     if (pDrawObj)
     215             :     {
     216           0 :         Rectangle aLogicRect = pDrawObj->GetLogicRect();
     217           0 :         Fraction aFractX = GetScaleWidth();
     218           0 :         Fraction aFractY = GetScaleHeight();
     219           0 :         aFractX *= aVisSize.Width();
     220           0 :         aFractY *= aVisSize.Height();
     221           0 :         aVisSize = Size( (long) aFractX, (long) aFractY );      // skaliert fuer Draw-Model
     222             : 
     223             :         //  pClientData->SetObjArea vor pDrawObj->SetLogicRect, damit keine
     224             :         //  falschen Skalierungen ausgerechnet werden:
     225             :         //Rectangle aObjArea = aLogicRect;
     226             :         //aObjArea.SetSize( aVisSize );          // Dokument-Groesse vom Server
     227             :         //SetObjArea( aObjArea );
     228             : 
     229           0 :         SfxViewShell* pSfxViewSh = GetViewShell();
     230           0 :         ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
     231           0 :         if ( pViewSh )
     232             :         {
     233           0 :             Window* pWin = pViewSh->GetActiveWin();
     234           0 :             if ( pWin->LogicToPixel( aVisSize ) != pWin->LogicToPixel( aLogicRect.GetSize() ) )
     235             :             {
     236           0 :                 aLogicRect.SetSize( aVisSize );
     237           0 :                 pDrawObj->SetLogicRect( aLogicRect );
     238             : 
     239             :                 //  set document modified (SdrModel::SetChanged is not used)
     240           0 :                 pViewSh->GetViewData()->GetDocShell()->SetDrawModified();
     241             :             }
     242             :         }
     243           0 :     }
     244             : }
     245             : 
     246           0 : void ScClient::MakeVisible()
     247             : {
     248           0 :     SdrOle2Obj* pDrawObj = GetDrawObj();
     249           0 :     if (pDrawObj)
     250             :     {
     251           0 :         SfxViewShell* pSfxViewSh = GetViewShell();
     252           0 :         ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
     253           0 :         if (pViewSh)
     254           0 :             pViewSh->ScrollToObject( pDrawObj );
     255             :     }
     256          15 : }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10