LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/drawinglayer - DrawViewWrapper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 179 0.0 %
Date: 2012-12-27 Functions: 0 22 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 "DrawViewWrapper.hxx"
      21             : #include "chartview/DrawModelWrapper.hxx"
      22             : #include "ConfigurationAccess.hxx"
      23             : #include "macros.hxx"
      24             : 
      25             : #include <unotools/lingucfg.hxx>
      26             : #include <editeng/langitem.hxx>
      27             : // header for class SdrPage
      28             : #include <svx/svdpage.hxx>
      29             : //header for class SdrPageView
      30             : #include <svx/svdpagv.hxx>
      31             : // header for class SdrModel
      32             : #include <svx/svdmodel.hxx>
      33             : // header for class E3dScene
      34             : #include <svx/scene3d.hxx>
      35             : #include <svx/svdetc.hxx>
      36             : #include <svx/svdoutl.hxx>
      37             : 
      38             : // header for class SvxForbiddenCharactersTable
      39             : #include <editeng/forbiddencharacterstable.hxx>
      40             : 
      41             : #include <svx/svxids.hrc>
      42             : 
      43             : // header for class SvxShape
      44             : #include <svx/unoshape.hxx>
      45             : #include <editeng/fhgtitem.hxx>
      46             : 
      47             : #include <com/sun/star/container/XChild.hpp>
      48             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      49             : 
      50             : #include <sfx2/objsh.hxx>
      51             : #include <svx/helperhittest3d.hxx>
      52             : 
      53             : using namespace ::com::sun::star;
      54             : 
      55             : //.............................................................................
      56             : namespace chart
      57             : {
      58             : //.............................................................................
      59             : 
      60             : namespace
      61             : {
      62           0 :     short lcl_getHitTolerance( OutputDevice* pOutDev )
      63             :     {
      64           0 :         const short HITPIX=2; //hit-tolerance in pixel
      65           0 :         short nHitTolerance = 50;
      66           0 :         if(pOutDev)
      67           0 :             nHitTolerance = static_cast<short>(pOutDev->PixelToLogic(Size(HITPIX,0)).Width());
      68           0 :         return nHitTolerance;
      69             :     }
      70             : 
      71             : // this code is copied from sfx2/source/doc/objembed.cxx
      72           0 : SfxObjectShell * lcl_GetParentObjectShell( const uno::Reference< frame::XModel > & xModel )
      73             : {
      74           0 :     SfxObjectShell* pResult = NULL;
      75             : 
      76             :     try
      77             :     {
      78           0 :         uno::Reference< container::XChild > xChildModel( xModel, uno::UNO_QUERY );
      79           0 :         if ( xChildModel.is() )
      80             :         {
      81           0 :             uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
      82           0 :             if ( xParentTunnel.is() )
      83             :             {
      84           0 :                 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
      85             :                 pResult = reinterpret_cast< SfxObjectShell * >(
      86           0 :                     xParentTunnel->getSomething( uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
      87           0 :             }
      88           0 :         }
      89             :     }
      90           0 :     catch( const uno::Exception& )
      91             :     {
      92             :         // TODO: error handling
      93             :     }
      94             : 
      95           0 :     return pResult;
      96             : }
      97             : 
      98             : // this code is copied from sfx2/source/doc/objembed.cxx.  It is a workaround to
      99             : // get the reference device (e.g. printer) fromthe parent document
     100           0 : OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel )
     101             : {
     102           0 :     SfxObjectShell * pParent = lcl_GetParentObjectShell( xModel );
     103           0 :     if ( pParent )
     104           0 :         return pParent->GetDocumentRefDev();
     105           0 :     return NULL;
     106             : }
     107             : 
     108             : }
     109             : 
     110           0 : DrawViewWrapper::DrawViewWrapper( SdrModel* pSdrModel, OutputDevice* pOut, bool bPaintPageForEditMode)
     111             :             : E3dView(pSdrModel, pOut)
     112             :             , m_pMarkHandleProvider(NULL)
     113             :             , m_apOutliner( SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT, pSdrModel ) )
     114           0 :             , m_bRestoreMapMode( false )
     115             : {
     116           0 :     SetBufferedOutputAllowed(true);
     117           0 :     SetBufferedOverlayAllowed(true);
     118             : 
     119           0 :     SetPagePaintingAllowed(bPaintPageForEditMode);
     120             : 
     121             :     // #i12587# support for shapes in chart
     122           0 :     SdrOutliner* pOutliner = getOutliner();
     123           0 :     SfxItemPool* pOutlinerPool = ( pOutliner ? pOutliner->GetEditTextObjectPool() : NULL );
     124           0 :     if ( pOutlinerPool )
     125             :     {
     126           0 :         SvtLinguConfig aLinguConfig;
     127           0 :         SvtLinguOptions aLinguOptions;
     128           0 :         if ( aLinguConfig.GetOptions( aLinguOptions ) )
     129             :         {
     130           0 :             pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
     131           0 :             pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
     132           0 :             pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
     133             :         }
     134             : 
     135             :         // set font height without changing SdrEngineDefaults
     136           0 :         pOutlinerPool->SetPoolDefaultItem( SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT ) );  // 12pt
     137             :     }
     138             : 
     139           0 :     ReInit();
     140           0 : }
     141             : 
     142           0 : void DrawViewWrapper::ReInit()
     143             : {
     144           0 :     OutputDevice* pOutDev = this->GetFirstOutputDevice();
     145           0 :     Size aOutputSize(100,100);
     146           0 :     if(pOutDev)
     147           0 :         aOutputSize = pOutDev->GetOutputSize();
     148             : 
     149           0 :     bPageVisible = false;
     150           0 :     bPageBorderVisible = false;
     151           0 :     bBordVisible = false;
     152           0 :     bGridVisible = false;
     153           0 :     bHlplVisible = false;
     154             : 
     155           0 :     this->SetNoDragXorPolys(true);//for interactive 3D resize-dragging: paint only a single rectangle (not a simulated 3D object)
     156             : 
     157             :     //a correct work area is at least necessary for correct values in the position and  size dialog
     158           0 :     Rectangle aRect(Point(0,0), aOutputSize);
     159           0 :     this->SetWorkArea(aRect);
     160             : 
     161           0 :     this->ShowSdrPage(this->GetModel()->GetPage(0));
     162           0 : }
     163             : 
     164           0 : DrawViewWrapper::~DrawViewWrapper()
     165             : {
     166           0 :     aComeBackTimer.Stop();//@todo this should be done in destructor of base class
     167           0 :     UnmarkAllObj();//necessary to aavoid a paint call during the destructor hierarchy
     168           0 : }
     169             : 
     170           0 : SdrPageView* DrawViewWrapper::GetPageView() const
     171             : {
     172           0 :     SdrPageView* pSdrPageView = this->GetSdrPageView();
     173           0 :     return pSdrPageView;
     174             : };
     175             : 
     176           0 : void DrawViewWrapper::SetMarkHandles()
     177             : {
     178           0 :     if( m_pMarkHandleProvider && m_pMarkHandleProvider->getMarkHandles( aHdl ) )
     179           0 :         return;
     180             :     else
     181           0 :         SdrView::SetMarkHandles();
     182             : }
     183             : 
     184           0 : SdrObject* DrawViewWrapper::getHitObject( const Point& rPnt ) const
     185             : {
     186           0 :     SdrObject* pRet = NULL;
     187           0 :     sal_uLong nOptions = SDRSEARCH_DEEP | SDRSEARCH_TESTMARKABLE;
     188             : 
     189           0 :     SdrPageView* pSdrPageView = this->GetPageView();
     190           0 :     this->SdrView::PickObj(rPnt, lcl_getHitTolerance( this->GetFirstOutputDevice() ), pRet, pSdrPageView, nOptions);
     191             : 
     192           0 :     if( pRet )
     193             :     {
     194             :         //ignore some special shapes
     195           0 :         OUString aShapeName = pRet->GetName();
     196           0 :         if( aShapeName.match("PlotAreaIncludingAxes") || aShapeName.match("PlotAreaExcludingAxes") )
     197             :         {
     198           0 :             pRet->SetMarkProtect( true );
     199           0 :             return getHitObject( rPnt );
     200             :         }
     201             : 
     202             :         //3d objects need a special treatment
     203             :         //because the simple PickObj method is not accurate in this case for performance reasons
     204           0 :         E3dObject* pE3d = dynamic_cast< E3dObject* >(pRet);
     205           0 :         if( pE3d )
     206             :         {
     207           0 :             E3dScene* pScene = pE3d->GetScene();
     208           0 :             if( pScene )
     209             :             {
     210             :                 // prepare result vector and call helper
     211           0 :                 ::std::vector< const E3dCompoundObject* > aHitList;
     212           0 :                 const basegfx::B2DPoint aHitPoint(rPnt.X(), rPnt.Y());
     213           0 :                 getAllHit3DObjectsSortedFrontToBack(aHitPoint, *pScene, aHitList);
     214             : 
     215           0 :                 if(!aHitList.empty())
     216             :                 {
     217             :                     // choose the frontmost hit 3D object of the scene
     218           0 :                     pRet = const_cast< E3dCompoundObject* >(aHitList[0]);
     219           0 :                 }
     220             :             }
     221           0 :         }
     222             :     }
     223           0 :     return pRet;
     224             : }
     225             : 
     226           0 : void DrawViewWrapper::MarkObject( SdrObject* pObj )
     227             : {
     228           0 :     bool bFrameDragSingles = true;//true == green == surrounding handles
     229           0 :     if(pObj)
     230           0 :         pObj->SetMarkProtect(false);
     231           0 :     if( m_pMarkHandleProvider )
     232           0 :         bFrameDragSingles = m_pMarkHandleProvider->getFrameDragSingles();
     233             : 
     234           0 :     this->SetFrameDragSingles(bFrameDragSingles);//decide whether each single object should get handles
     235           0 :     this->SdrView::MarkObj( pObj, this->GetPageView() );
     236           0 :     this->showMarkHandles();
     237           0 : }
     238             : 
     239             : 
     240           0 : void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider* pMarkHandleProvider )
     241             : {
     242           0 :     m_pMarkHandleProvider = pMarkHandleProvider;
     243           0 : }
     244             : 
     245           0 : void DrawViewWrapper::CompleteRedraw(OutputDevice* pOut, const Region& rReg, sdr::contact::ViewObjectContactRedirector* /* pRedirector */)
     246             : {
     247           0 :     svtools::ColorConfig aColorConfig;
     248           0 :     Color aFillColor = Color( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
     249           0 :     this->SetApplicationBackgroundColor(aFillColor);
     250           0 :     this->E3dView::CompleteRedraw( pOut, rReg );
     251           0 : }
     252             : 
     253           0 : SdrObject* DrawViewWrapper::getSelectedObject() const
     254             : {
     255           0 :     SdrObject* pObj(NULL);
     256           0 :     const SdrMarkList& rMarkList = this->GetMarkedObjectList();
     257           0 :     if(rMarkList.GetMarkCount() == 1)
     258             :     {
     259           0 :         SdrMark* pMark = rMarkList.GetMark(0);
     260           0 :         pObj = pMark->GetMarkedSdrObj();
     261             :     }
     262           0 :     return pObj;
     263             : }
     264             : 
     265           0 : SdrObject* DrawViewWrapper::getTextEditObject() const
     266             : {
     267           0 :     SdrObject* pObj = this->getSelectedObject();
     268           0 :     SdrObject* pTextObj = NULL;
     269           0 :     if( pObj && pObj->HasTextEdit())
     270           0 :         pTextObj = (SdrTextObj*)pObj;
     271           0 :     return pTextObj;
     272             : }
     273             : 
     274           0 : void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference< frame::XModel > & xChartModel )
     275             : {
     276           0 :     OutputDevice * pParentRefDev( lcl_GetParentRefDevice( xChartModel ));
     277           0 :     SdrOutliner * pOutliner( getOutliner());
     278           0 :     if( pParentRefDev && pOutliner )
     279             :     {
     280           0 :         pOutliner->SetRefDevice( pParentRefDev );
     281             :     }
     282           0 : }
     283             : 
     284           0 : SdrOutliner* DrawViewWrapper::getOutliner() const
     285             : {
     286           0 :     return m_apOutliner.get();
     287             : }
     288             : 
     289           0 : SfxItemSet DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const
     290             : {
     291           0 :     SfxItemSet aFullSet( GetModel()->GetItemPool(),
     292             :                     SID_ATTR_TRANSFORM_POS_X,SID_ATTR_TRANSFORM_ANGLE,
     293             :                     SID_ATTR_TRANSFORM_PROTECT_POS,SID_ATTR_TRANSFORM_AUTOHEIGHT,
     294             :                     SDRATTR_ECKENRADIUS,SDRATTR_ECKENRADIUS,
     295             :                     SID_ATTR_METRIC,SID_ATTR_METRIC,
     296           0 :                     0);
     297           0 :     SfxItemSet aGeoSet( E3dView::GetGeoAttrFromMarked() );
     298           0 :     aFullSet.Put( aGeoSet );
     299           0 :     aFullSet.Put( SfxUInt16Item(SID_ATTR_METRIC,static_cast< sal_uInt16 >( ConfigurationAccess::getFieldUnit())));
     300           0 :     return aFullSet;
     301             : }
     302             : 
     303           0 : SdrObject* DrawViewWrapper::getNamedSdrObject( const OUString& rName ) const
     304             : {
     305           0 :     if(rName.isEmpty())
     306           0 :         return 0;
     307           0 :     SdrPageView* pSdrPageView = this->GetPageView();
     308           0 :     if( pSdrPageView )
     309             :     {
     310           0 :         return DrawModelWrapper::getNamedSdrObject( rName, pSdrPageView->GetObjList() );
     311             :     }
     312           0 :     return 0;
     313             : }
     314             : 
     315           0 : bool DrawViewWrapper::IsObjectHit( SdrObject* pObj, const Point& rPnt ) const
     316             : {
     317           0 :     if(pObj)
     318             :     {
     319           0 :         Rectangle aRect(pObj->GetCurrentBoundRect());
     320           0 :         return aRect.IsInside(rPnt);
     321             :     }
     322           0 :     return false;
     323             : }
     324             : 
     325           0 : void DrawViewWrapper::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
     326             : {
     327             :     //prevent wrong reselection of objects
     328           0 :     SdrModel* pSdrModel( this->GetModel() );
     329           0 :     if( pSdrModel && pSdrModel->isLocked() )
     330           0 :         return;
     331             : 
     332           0 :     const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
     333             : 
     334             :     //#i76053# do nothing when only changes on the hidden draw page were made ( e.g. when the symbols for the dialogs are created )
     335           0 :     SdrPageView* pSdrPageView = this->GetPageView();
     336           0 :     if( pSdrHint && pSdrPageView )
     337             :     {
     338           0 :         if( pSdrPageView->GetPage() != pSdrHint->GetPage() )
     339           0 :             return;
     340             :     }
     341             : 
     342           0 :     E3dView::Notify(rBC, rHint);
     343             : 
     344           0 :     if( pSdrHint != 0 )
     345             :     {
     346           0 :         SdrHintKind eKind = pSdrHint->GetKind();
     347           0 :         if( eKind == HINT_BEGEDIT )
     348             :         {
     349             :             // #i79965# remember map mode
     350             :             OSL_ASSERT( ! m_bRestoreMapMode );
     351           0 :             OutputDevice* pOutDev = this->GetFirstOutputDevice();
     352           0 :             if( pOutDev )
     353             :             {
     354           0 :                 m_aMapModeToRestore = pOutDev->GetMapMode();
     355           0 :                 m_bRestoreMapMode = true;
     356             :             }
     357             :         }
     358           0 :         else if( eKind == HINT_ENDEDIT )
     359             :         {
     360             :             // #i79965# scroll back view when ending text edit
     361             :             OSL_ASSERT( m_bRestoreMapMode );
     362           0 :             if( m_bRestoreMapMode )
     363             :             {
     364           0 :                 OutputDevice* pOutDev = this->GetFirstOutputDevice();
     365           0 :                 if( pOutDev )
     366             :                 {
     367           0 :                     pOutDev->SetMapMode( m_aMapModeToRestore );
     368           0 :                     m_bRestoreMapMode = false;
     369             :                 }
     370             :             }
     371             :         }
     372             :     }
     373             : }
     374             : 
     375           0 : SdrObject* DrawViewWrapper::getSdrObject( const uno::Reference<
     376             :                     drawing::XShape >& xShape )
     377             : {
     378           0 :     SdrObject* pRet = 0;
     379           0 :     uno::Reference< lang::XUnoTunnel > xUnoTunnel( xShape, uno::UNO_QUERY );
     380           0 :     uno::Reference< lang::XTypeProvider > xTypeProvider( xShape, uno::UNO_QUERY );
     381           0 :     if(xUnoTunnel.is()&&xTypeProvider.is())
     382             :     {
     383           0 :         SvxShape* pSvxShape = reinterpret_cast<SvxShape*>(xUnoTunnel->getSomething( SvxShape::getUnoTunnelId() ));
     384           0 :         if(pSvxShape)
     385           0 :             pRet = pSvxShape->GetSdrObject();
     386             :     }
     387           0 :     return pRet;
     388             : }
     389             : 
     390             : //.............................................................................
     391             : } //namespace chart
     392             : //.............................................................................
     393             : 
     394             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10