LCOV - code coverage report
Current view: top level - sc/source/ui/drawfunc - graphsh.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 6 121 5.0 %
Date: 2014-11-03 Functions: 5 26 19.2 %
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 <sfx2/app.hxx>
      21             : #include <sfx2/objface.hxx>
      22             : #include <sfx2/request.hxx>
      23             : #include <sfx2/sidebar/EnumContext.hxx>
      24             : #include <svl/whiter.hxx>
      25             : #include <svx/svdograf.hxx>
      26             : #include <svx/grfflt.hxx>
      27             : #include <svx/grafctrl.hxx>
      28             : #include <svx/compressgraphicdialog.hxx>
      29             : #include <vcl/msgbox.hxx>
      30             : 
      31             : #include "graphsh.hxx"
      32             : #include "sc.hrc"
      33             : #include "viewdata.hxx"
      34             : #include "drawview.hxx"
      35             : #include "scresid.hxx"
      36             : #include <svx/extedit.hxx>
      37             : 
      38             : #define ScGraphicShell
      39             : #include "scslots.hxx"
      40             : 
      41           0 : class ScExternalToolEdit : public ExternalToolEdit
      42             : {
      43             :     FmFormView* m_pView;
      44             :     SdrObject*  m_pObj;
      45             : 
      46             : public:
      47           0 :     ScExternalToolEdit ( FmFormView* pView, SdrObject* pObj ) :
      48             :         m_pView   (pView),
      49           0 :         m_pObj (pObj)
      50           0 :     {}
      51             : 
      52           0 :     virtual void Update( Graphic& aGraphic ) SAL_OVERRIDE
      53             :     {
      54           0 :         SdrPageView* pPageView = m_pView->GetSdrPageView();
      55           0 :         if( pPageView )
      56             :         {
      57           0 :             SdrGrafObj* pNewObj = static_cast<SdrGrafObj*>(m_pObj->Clone());
      58           0 :             OUString    aStr = m_pView->GetDescriptionOfMarkedObjects() + " External Edit";
      59           0 :             m_pView->BegUndo( aStr );
      60           0 :             pNewObj->SetGraphicObject( aGraphic );
      61           0 :             m_pView->ReplaceObjectAtView( m_pObj, *pPageView, pNewObj );
      62           0 :             m_pView->EndUndo();
      63             :         }
      64           0 :     }
      65             : };
      66             : 
      67         304 : SFX_IMPL_INTERFACE(ScGraphicShell, ScDrawShell, ScResId(SCSTR_GRAPHICSHELL))
      68             : 
      69          76 : void ScGraphicShell::InitInterface_Impl()
      70             : {
      71             :     GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
      72          76 :                                             ScResId(RID_GRAPHIC_OBJECTBAR));
      73             : 
      74          76 :     GetStaticInterface()->RegisterPopupMenu(ScResId(RID_POPUP_GRAPHIC));
      75          76 : }
      76             : 
      77           0 : TYPEINIT1( ScGraphicShell, ScDrawShell );
      78             : 
      79           0 : ScGraphicShell::ScGraphicShell(ScViewData* pData) :
      80           0 :     ScDrawShell(pData)
      81             : {
      82           0 :     SetHelpId(HID_SCSHELL_GRAPHIC);
      83           0 :     SetName(OUString("GraphicObject"));
      84           0 :         SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Graphic));
      85           0 : }
      86             : 
      87           0 : ScGraphicShell::~ScGraphicShell()
      88             : {
      89           0 : }
      90             : 
      91           0 : void ScGraphicShell::GetAttrState( SfxItemSet& rSet )
      92             : {
      93           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
      94             : 
      95           0 :     if( pView )
      96           0 :         SvxGrafAttrHelper::GetGrafAttrState( rSet, *pView );
      97           0 : }
      98             : 
      99           0 : void ScGraphicShell::Execute( SfxRequest& rReq )
     100             : {
     101           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     102             : 
     103           0 :     if( pView )
     104             :     {
     105           0 :         SvxGrafAttrHelper::ExecuteGrafAttr( rReq, *pView );
     106           0 :         Invalidate();
     107             :     }
     108           0 : }
     109             : 
     110           0 : void ScGraphicShell::GetFilterState( SfxItemSet& rSet )
     111             : {
     112           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     113           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     114           0 :     bool bEnable = false;
     115             : 
     116           0 :     if( rMarkList.GetMarkCount() == 1 )
     117             :     {
     118           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     119             : 
     120           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
     121           0 :             bEnable = true;
     122             :     }
     123             : 
     124           0 :     if( !bEnable )
     125           0 :         SvxGraphicFilter::DisableGraphicFilterSlots( rSet );
     126           0 : }
     127             : 
     128           0 : void ScGraphicShell::ExecuteFilter( SfxRequest& rReq )
     129             : {
     130           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     131           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     132             : 
     133           0 :     if( rMarkList.GetMarkCount() == 1 )
     134             :     {
     135           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     136             : 
     137           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
     138             :         {
     139           0 :             GraphicObject aFilterObj( static_cast<SdrGrafObj*>(pObj)->GetGraphicObject() );
     140             : 
     141           0 :             if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
     142           0 :                 SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ) )
     143             :             {
     144           0 :                 SdrPageView* pPageView = pView->GetSdrPageView();
     145             : 
     146           0 :                 if( pPageView )
     147             :                 {
     148           0 :                     SdrGrafObj* pFilteredObj = static_cast<SdrGrafObj*>(pObj->Clone());
     149           0 :                     OUString    aStr = pView->GetDescriptionOfMarkedObjects() + " " + OUString(ScResId( SCSTR_UNDO_GRAFFILTER ));
     150           0 :                     pView->BegUndo( aStr );
     151           0 :                     pFilteredObj->SetGraphicObject( aFilterObj );
     152           0 :                     pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj );
     153           0 :                     pView->EndUndo();
     154             :                 }
     155           0 :             }
     156             :         }
     157             :     }
     158             : 
     159           0 :     Invalidate();
     160           0 : }
     161             : 
     162           0 : void ScGraphicShell::GetExternalEditState( SfxItemSet& rSet )
     163             : {
     164           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     165           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     166           0 :     bool bEnable = false;
     167           0 :     if( rMarkList.GetMarkCount() == 1 )
     168             :     {
     169           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     170             : 
     171           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
     172           0 :             bEnable = true;
     173             :     }
     174             : 
     175           0 :     if( !bEnable )
     176           0 :         rSet.DisableItem( SID_EXTERNAL_EDIT );
     177           0 : }
     178             : 
     179           0 : void ScGraphicShell::ExecuteExternalEdit( SfxRequest& )
     180             : {
     181           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     182           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     183             : 
     184           0 :     if( rMarkList.GetMarkCount() == 1 )
     185             :     {
     186           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     187             : 
     188           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
     189             :         {
     190           0 :             GraphicObject aGraphicObject( static_cast<SdrGrafObj*>(pObj)->GetGraphicObject() );
     191           0 :             ScExternalToolEdit* aExternalToolEdit = new ScExternalToolEdit( pView, pObj );
     192           0 :             aExternalToolEdit->Edit( &aGraphicObject );
     193             :         }
     194             :     }
     195             : 
     196           0 :     Invalidate();
     197           0 : }
     198             : 
     199           0 : void ScGraphicShell::GetCompressGraphicState( SfxItemSet& rSet )
     200             : {
     201           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     202           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     203           0 :     bool bEnable = false;
     204           0 :     if( rMarkList.GetMarkCount() == 1 )
     205             :     {
     206           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     207             : 
     208           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
     209           0 :             bEnable = true;
     210             :     }
     211             : 
     212           0 :     if( !bEnable )
     213           0 :         rSet.DisableItem( SID_COMPRESS_GRAPHIC );
     214           0 : }
     215             : 
     216           0 : void ScGraphicShell::ExecuteCompressGraphic( SfxRequest& )
     217             : {
     218           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     219           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     220             : 
     221           0 :     if( rMarkList.GetMarkCount() == 1 )
     222             :     {
     223           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     224             : 
     225           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
     226             :         {
     227           0 :             SdrGrafObj* pGraphicObj = static_cast<SdrGrafObj*>(pObj);
     228           0 :             CompressGraphicsDialog dialog( GetViewData()->GetDialogParent(), pGraphicObj, GetViewData()->GetBindings() );
     229           0 :             if ( dialog.Execute() == RET_OK )
     230             :             {
     231           0 :                 SdrGrafObj* pNewObject = dialog.GetCompressedSdrGrafObj();
     232           0 :                 SdrPageView* pPageView = pView->GetSdrPageView();
     233           0 :                 OUString aUndoString = pView->GetDescriptionOfMarkedObjects() + " Compress";
     234           0 :                 pView->BegUndo( aUndoString );
     235           0 :                 pView->ReplaceObjectAtView( pObj, *pPageView, pNewObject );
     236           0 :                 pView->EndUndo();
     237           0 :             }
     238             :         }
     239             :     }
     240             : 
     241           0 :     Invalidate();
     242         228 : }
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10