LCOV - code coverage report
Current view: top level - sc/source/ui/drawfunc - graphsh.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 12 184 6.5 %
Date: 2015-06-13 12:38:46 Functions: 7 28 25.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 <sfx2/app.hxx>
      21             : #include <sfx2/objface.hxx>
      22             : #include <sfx2/request.hxx>
      23             : #include <sfx2/sidebar/EnumContext.hxx>
      24             : #include <sfx2/opengrf.hxx>
      25             : #include <svl/whiter.hxx>
      26             : #include <svx/svdograf.hxx>
      27             : #include <svx/grfflt.hxx>
      28             : #include <svx/grafctrl.hxx>
      29             : #include <svx/compressgraphicdialog.hxx>
      30             : #include <svx/graphichelper.hxx>
      31             : #include <vcl/msgbox.hxx>
      32             : 
      33             : #include "graphsh.hxx"
      34             : #include "sc.hrc"
      35             : #include "viewdata.hxx"
      36             : #include "drawview.hxx"
      37             : #include "scresid.hxx"
      38             : #include <svx/extedit.hxx>
      39             : #include "tabvwsh.hxx"
      40             : 
      41             : #define ScGraphicShell
      42             : #include "scslots.hxx"
      43             : 
      44         212 : SFX_IMPL_INTERFACE(ScGraphicShell, ScDrawShell)
      45             : 
      46          52 : void ScGraphicShell::InitInterface_Impl()
      47             : {
      48             :     GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
      49          52 :                                             RID_GRAPHIC_OBJECTBAR);
      50             : 
      51          52 :     GetStaticInterface()->RegisterPopupMenu(ScResId(RID_POPUP_GRAPHIC));
      52          52 : }
      53             : 
      54           0 : TYPEINIT1( ScGraphicShell, ScDrawShell );
      55             : 
      56           1 : ScGraphicShell::ScGraphicShell(ScViewData* pData) :
      57           1 :     ScDrawShell(pData)
      58             : {
      59           1 :     SetHelpId(HID_SCSHELL_GRAPHIC);
      60           1 :     SetName(OUString("GraphicObject"));
      61           1 :         SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Graphic));
      62           1 : }
      63             : 
      64           0 : ScGraphicShell::~ScGraphicShell()
      65             : {
      66           0 : }
      67             : 
      68           0 : void ScGraphicShell::GetAttrState( SfxItemSet& rSet )
      69             : {
      70           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
      71             : 
      72           0 :     if( pView )
      73           0 :         SvxGrafAttrHelper::GetGrafAttrState( rSet, *pView );
      74           0 : }
      75             : 
      76           0 : void ScGraphicShell::Execute( SfxRequest& rReq )
      77             : {
      78           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
      79             : 
      80           0 :     if( pView )
      81             :     {
      82           0 :         SvxGrafAttrHelper::ExecuteGrafAttr( rReq, *pView );
      83           0 :         Invalidate();
      84             :     }
      85           0 : }
      86             : 
      87           0 : void ScGraphicShell::GetFilterState( SfxItemSet& rSet )
      88             : {
      89           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
      90           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
      91           0 :     bool bEnable = false;
      92             : 
      93           0 :     if( rMarkList.GetMarkCount() == 1 )
      94             :     {
      95           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
      96             : 
      97           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
      98           0 :             bEnable = true;
      99             :     }
     100             : 
     101           0 :     if( !bEnable )
     102           0 :         SvxGraphicFilter::DisableGraphicFilterSlots( rSet );
     103           0 : }
     104             : 
     105           0 : void ScGraphicShell::ExecuteFilter( SfxRequest& rReq )
     106             : {
     107           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     108           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     109             : 
     110           0 :     if( rMarkList.GetMarkCount() == 1 )
     111             :     {
     112           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     113             : 
     114           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
     115             :         {
     116           0 :             GraphicObject aFilterObj( static_cast<SdrGrafObj*>(pObj)->GetGraphicObject() );
     117             : 
     118           0 :             if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
     119           0 :                 SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ) )
     120             :             {
     121           0 :                 SdrPageView* pPageView = pView->GetSdrPageView();
     122             : 
     123           0 :                 if( pPageView )
     124             :                 {
     125           0 :                     SdrGrafObj* pFilteredObj = static_cast<SdrGrafObj*>(pObj->Clone());
     126           0 :                     OUString    aStr = pView->GetDescriptionOfMarkedObjects() + " " + OUString(ScResId( SCSTR_UNDO_GRAFFILTER ));
     127           0 :                     pView->BegUndo( aStr );
     128           0 :                     pFilteredObj->SetGraphicObject( aFilterObj );
     129           0 :                     pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj );
     130           0 :                     pView->EndUndo();
     131             :                 }
     132           0 :             }
     133             :         }
     134             :     }
     135             : 
     136           0 :     Invalidate();
     137           0 : }
     138             : 
     139           0 : void ScGraphicShell::GetExternalEditState( SfxItemSet& rSet )
     140             : {
     141           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     142           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     143           0 :     bool bEnable = false;
     144           0 :     if( rMarkList.GetMarkCount() == 1 )
     145             :     {
     146           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     147             : 
     148           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
     149           0 :             bEnable = true;
     150             :     }
     151             : 
     152           0 :     if( !bEnable )
     153           0 :         rSet.DisableItem( SID_EXTERNAL_EDIT );
     154           0 : }
     155             : 
     156           0 : void ScGraphicShell::ExecuteExternalEdit( SfxRequest& )
     157             : {
     158           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     159           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     160             : 
     161           0 :     if( rMarkList.GetMarkCount() == 1 )
     162             :     {
     163           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     164             : 
     165           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
     166             :         {
     167           0 :             GraphicObject aGraphicObject( static_cast<SdrGrafObj*>(pObj)->GetGraphicObject() );
     168             :             m_ExternalEdits.push_back( std::unique_ptr<SdrExternalToolEdit>(
     169           0 :                         new SdrExternalToolEdit(pView, pObj)));
     170           0 :             m_ExternalEdits.back()->Edit( &aGraphicObject );
     171             :         }
     172             :     }
     173             : 
     174           0 :     Invalidate();
     175           0 : }
     176             : 
     177           0 : void ScGraphicShell::GetCompressGraphicState( SfxItemSet& rSet )
     178             : {
     179           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     180           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     181           0 :     bool bEnable = false;
     182           0 :     if( rMarkList.GetMarkCount() == 1 )
     183             :     {
     184           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     185             : 
     186           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
     187           0 :             bEnable = true;
     188             :     }
     189             : 
     190           0 :     if( !bEnable )
     191           0 :         rSet.DisableItem( SID_COMPRESS_GRAPHIC );
     192           0 : }
     193             : 
     194           0 : void ScGraphicShell::ExecuteCompressGraphic( SfxRequest& )
     195             : {
     196           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     197           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     198             : 
     199           0 :     if( rMarkList.GetMarkCount() == 1 )
     200             :     {
     201           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     202             : 
     203           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
     204             :         {
     205           0 :             SdrGrafObj* pGraphicObj = static_cast<SdrGrafObj*>(pObj);
     206           0 :             ScopedVclPtrInstance< CompressGraphicsDialog > dialog( GetViewData()->GetDialogParent(), pGraphicObj, GetViewData()->GetBindings() );
     207           0 :             if ( dialog->Execute() == RET_OK )
     208             :             {
     209           0 :                 SdrGrafObj* pNewObject = dialog->GetCompressedSdrGrafObj();
     210           0 :                 SdrPageView* pPageView = pView->GetSdrPageView();
     211           0 :                 OUString aUndoString = pView->GetDescriptionOfMarkedObjects() + " Compress";
     212           0 :                 pView->BegUndo( aUndoString );
     213           0 :                 pView->ReplaceObjectAtView( pObj, *pPageView, pNewObject );
     214           0 :                 pView->EndUndo();
     215           0 :             }
     216             :         }
     217             :     }
     218             : 
     219           0 :     Invalidate();
     220           0 : }
     221             : 
     222           0 : void ScGraphicShell::GetCropGraphicState( SfxItemSet& rSet )
     223             : {
     224           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     225           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     226           0 :     bool bEnable = false;
     227           0 :     if( rMarkList.GetMarkCount() == 1 )
     228             :     {
     229           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     230             : 
     231           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
     232           0 :             bEnable = true;
     233             :     }
     234             : 
     235           0 :     if( !bEnable )
     236           0 :         rSet.DisableItem( SID_OBJECT_CROP );
     237           0 : }
     238             : 
     239           0 : void ScGraphicShell::ExecuteCropGraphic( SfxRequest& )
     240             : {
     241           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     242           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     243             : 
     244           0 :     if( rMarkList.GetMarkCount() == 1 )
     245             :     {
     246           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     247             : 
     248           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
     249             :         {
     250           0 :             pView->SetEditMode(SDREDITMODE_EDIT);
     251           0 :             pView->SetDragMode(SDRDRAG_CROP);
     252             :         }
     253             :     }
     254             : 
     255           0 :     Invalidate();
     256           0 : }
     257             : 
     258           0 : void ScGraphicShell::ExecuteSaveGraphic(SfxRequest& /*rReq*/)
     259             : {
     260           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     261           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     262           0 :     if( rMarkList.GetMarkCount() == 1 )
     263             :     {
     264           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     265           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
     266             :         {
     267           0 :             GraphicObject aGraphicObject( static_cast<SdrGrafObj*>( pObj )->GetGraphicObject() );
     268             :             {
     269           0 :                 GraphicHelper::ExportGraphic( aGraphicObject.GetGraphic(), "" );
     270           0 :             }
     271             :         }
     272             :     }
     273             : 
     274           0 :     Invalidate();
     275           0 : }
     276             : 
     277           0 : void ScGraphicShell::GetSaveGraphicState(SfxItemSet &rSet)
     278             : {
     279           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     280           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     281           0 :     bool bEnable = false;
     282           0 :     if( rMarkList.GetMarkCount() == 1 )
     283             :     {
     284           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     285             : 
     286           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
     287           0 :             bEnable = true;
     288             :     }
     289             : 
     290           0 :     if( !bEnable )
     291           0 :         rSet.DisableItem( SID_SAVE_GRAPHIC );
     292           0 : }
     293             : 
     294           0 : void ScGraphicShell::ExecuteChangePicture(SfxRequest& /*rReq*/)
     295             : {
     296           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     297           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     298             : 
     299           0 :     if( rMarkList.GetMarkCount() == 1 )
     300             :     {
     301           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     302             : 
     303           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
     304             :         {
     305           0 :             SdrGrafObj* pGraphicObj = static_cast<SdrGrafObj*>(pObj);
     306           0 :             SvxOpenGraphicDialog aDlg(ScResId(STR_INSERTGRAPHIC));
     307             : 
     308           0 :             if( aDlg.Execute() == GRFILTER_OK )
     309             :             {
     310           0 :                 Graphic aGraphic;
     311           0 :                 int nError = aDlg.GetGraphic(aGraphic);
     312           0 :                 if( nError == GRFILTER_OK )
     313             :                 {
     314           0 :                     SdrGrafObj* pNewObject = pGraphicObj->Clone();
     315           0 :                     pNewObject->SetGraphic( aGraphic );
     316           0 :                     SdrPageView* pPageView = pView->GetSdrPageView();
     317           0 :                     OUString aUndoString = pView->GetDescriptionOfMarkedObjects() + " Change";
     318           0 :                     pView->BegUndo( aUndoString );
     319           0 :                     pView->ReplaceObjectAtView( pObj, *pPageView, pNewObject );
     320           0 :                     pView->EndUndo();
     321           0 :                 }
     322           0 :             }
     323             :         }
     324             :     }
     325             : 
     326           0 :     Invalidate();
     327           0 : }
     328             : 
     329           0 : void ScGraphicShell::GetChangePictureState(SfxItemSet &rSet)
     330             : {
     331           0 :     ScDrawView* pView = GetViewData()->GetScDrawView();
     332           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     333           0 :     bool bEnable = false;
     334           0 :     if( rMarkList.GetMarkCount() == 1 )
     335             :     {
     336           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     337             : 
     338           0 :         if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
     339           0 :             bEnable = true;
     340             :     }
     341             : 
     342           0 :     if( !bEnable )
     343           0 :         rSet.DisableItem( SID_CHANGE_PICTURE );
     344         156 : }
     345             : 
     346             : 
     347             : 
     348             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11