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

Generated by: LCOV version 1.10