LCOV - code coverage report
Current view: top level - sw/source/uibase/uiview - swcli.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 29 64 45.3 %
Date: 2014-11-03 Functions: 5 8 62.5 %
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             : #include <wrtsh.hxx>
      22             : #include <doc.hxx>
      23             : #include <IDocumentSettingAccess.hxx>
      24             : #include <swtypes.hxx>
      25             : #include <view.hxx>
      26             : #include <edtwin.hxx>
      27             : #include <swcli.hxx>
      28             : #include <cmdid.h>
      29             : #include <cfgitems.hxx>
      30             : 
      31             : #include <toolkit/helper/vclunohelper.hxx>
      32             : 
      33             : using namespace com::sun::star;
      34             : 
      35          20 : SwOleClient::SwOleClient( SwView *pView, SwEditWin *pWin, const svt::EmbeddedObjectRef& xObj ) :
      36             :     SfxInPlaceClient( pView, pWin, xObj.GetViewAspect() ), bInDoVerb( false ),
      37          20 :     bOldCheckForOLEInCaption( pView->GetWrtShell().IsCheckForOLEInCaption() )
      38             : {
      39          20 :     SetObject( xObj.GetObject() );
      40          20 : }
      41             : 
      42           0 : void SwOleClient::RequestNewObjectArea( Rectangle& aLogRect )
      43             : {
      44             :     // The server wants to change the client size.
      45             :     // We put the desired size in the core. The attributes of the frame
      46             :     // are set to the desired value. This value will be passed on to the
      47             :     // InPlaceClient.
      48             :     // The core accepts or formats the adjusted values not necessarily.
      49             :     // If the Ole-Frm is formatted, then the CalcAndSetScale() of the WrtShell
      50             :     // will be called. There the scaling of the SwOleClient is set if necessary.
      51             : 
      52           0 :     SwWrtShell &rSh  = ((SwView*)GetViewShell())->GetWrtShell();
      53             : 
      54           0 :     rSh.StartAllAction();
      55             : 
      56             :     // the aLogRect will get the preliminary size now
      57           0 :     aLogRect.SetSize( rSh.RequestObjectResize( SwRect( aLogRect ), GetObject() ) );
      58             : 
      59             :     // the EndAllAction() call will trigger CalcAndSetScale() call,
      60             :     // so the embedded object must get the correct size before
      61           0 :     if ( aLogRect.GetSize() != GetScaledObjArea().GetSize() )
      62             :     {
      63             :         // size has changed, so first change visual area of the object before we resize its view
      64             :         // without this the object always would be scaled - now it has the choice
      65             : 
      66             :         // TODO/LEAN: getMapUnit can switch object to running state
      67           0 :         MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
      68           0 :         MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
      69             : 
      70           0 :         Size aNewObjSize( Fraction( aLogRect.GetWidth() ) / GetScaleWidth(),
      71           0 :                           Fraction( aLogRect.GetHeight() ) / GetScaleHeight() );
      72             : 
      73             :         // convert to logical coordinates of the embedded object
      74           0 :         Size aNewSize = GetEditWin()->LogicToLogic( aNewObjSize, &aClientMap, &aObjectMap );
      75           0 :         GetObject()->setVisualAreaSize( GetAspect(), awt::Size( aNewSize.Width(), aNewSize.Height() ) );
      76             :     }
      77             : 
      78           0 :     rSh.EndAllAction();
      79             : 
      80           0 :     SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED,     0, GetObject() )),
      81           0 :            aPrt( rSh.GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, GetObject() ));
      82           0 :     aLogRect.SetPos( aPrt.Pos() + aFrm.Pos() );
      83           0 :     aLogRect.SetSize( aPrt.SSize() );
      84           0 : }
      85             : 
      86           0 : void SwOleClient::ObjectAreaChanged()
      87             : {
      88           0 :     SwWrtShell &rSh  = ((SwView*)GetViewShell())->GetWrtShell();
      89           0 :     SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED,     0, GetObject() ));
      90           0 :     if ( !aFrm.IsOver( rSh.VisArea() ) )
      91           0 :         rSh.MakeVisible( aFrm );
      92           0 : }
      93             : 
      94          62 : void SwOleClient::ViewChanged()
      95             : {
      96          62 :     if ( bInDoVerb )
      97           0 :         return;
      98             : 
      99          62 :     if ( GetAspect() == embed::Aspects::MSOLE_ICON )
     100             :     {
     101             :         // the iconified object seems not to need such a scaling handling
     102             :         // since the replacement image and the size a completely controlled by the container
     103             :         // TODO/LATER: when the icon exchange is implemented the scaling handling
     104             :         //             might be required again here
     105           0 :         return;
     106             :     }
     107             : 
     108          62 :     SwWrtShell &rSh  = ((SwView*)GetViewShell())->GetWrtShell();
     109             : 
     110             :     // Adjust the size of the object in the core. The Scaling must
     111             :     // be considered. Repercussions on the object are considered by
     112             :     // CalcAndSetScale() of the WrtShell if the size / position of
     113             :     // the frame in the core changes.
     114             : 
     115             :     // TODO/LEAN: getMapUnit can switch object to running state
     116          62 :     awt::Size aSz;
     117             :     try
     118             :     {
     119          62 :         aSz = GetObject()->getVisualAreaSize( GetAspect() );
     120             :     }
     121           0 :     catch (const embed::NoVisualAreaSizeException&)
     122             :     {
     123             :         // Nothing will be done
     124             :     }
     125           0 :     catch (const uno::Exception&)
     126             :     {
     127             :         OSL_FAIL( "Something goes wrong on requesting object size!\n" );
     128             :     }
     129             : 
     130          62 :     Size aVisSize( aSz.Width, aSz.Height );
     131             : 
     132             :     // As long as from the object comes no reasonable size
     133             :     // nothing can be scaled.
     134          62 :     if( !aVisSize.Width() || !aVisSize.Height() )
     135           0 :         return;
     136             : 
     137             :     // first convert to TWIPS before scaling, because scaling factors are calculated for
     138             :     // the TWIPS mapping and so they will produce the best results if applied to TWIPS based
     139             :     // coordinates
     140          62 :     const MapMode aMyMap ( MAP_TWIP );
     141         124 :     const MapMode aObjMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
     142          62 :     aVisSize = OutputDevice::LogicToLogic( aVisSize, aObjMap, aMyMap );
     143             : 
     144          62 :     aVisSize.Width() = Fraction( aVisSize.Width()  ) * GetScaleWidth();
     145          62 :     aVisSize.Height()= Fraction( aVisSize.Height() ) * GetScaleHeight();
     146             : 
     147          62 :     SwRect aRect( Point( LONG_MIN, LONG_MIN ), aVisSize );
     148          62 :     rSh.LockView( true );   // Prevent scrolling in the EndAction
     149          62 :     rSh.StartAllAction();
     150          62 :     rSh.RequestObjectResize( aRect, GetObject() );
     151          62 :     rSh.EndAllAction();
     152         124 :     rSh.LockView( false );
     153             : }
     154             : 
     155           0 : void SwOleClient::MakeVisible()
     156             : {
     157           0 :     const SwWrtShell &rSh  = ((SwView*)GetViewShell())->GetWrtShell();
     158           0 :     rSh.MakeObjVisible( GetObject() );
     159           0 : }
     160             : 
     161          20 : void SwOleClient::FormatChanged()
     162             : {
     163          20 :     const uno::Reference < embed::XEmbeddedObject >& xObj( GetObject() );
     164          20 :     SwView * pView = dynamic_cast< SwView * >( GetViewShell() );
     165          20 :     if ( pView && xObj.is() && SotExchange::IsMath( xObj->getClassID() ) )
     166             :     {
     167           0 :         SwWrtShell & rWrtSh = pView->GetWrtShell();
     168           0 :         if (rWrtSh.GetDoc()->getIDocumentSettingAccess().get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT ))
     169           0 :             rWrtSh.AlignFormulaToBaseline( xObj );
     170          20 :     }
     171         290 : }
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10