LCOV - code coverage report
Current view: top level - sw/source/core/uibase/shells - grfsh.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 5 421 1.2 %
Date: 2014-04-11 Functions: 5 16 31.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 <cmdid.h>
      21             : #include <hintids.hxx>
      22             : #include <tools/urlobj.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : #include <svl/stritem.hxx>
      25             : #include <svl/whiter.hxx>
      26             : #include <svl/urihelper.hxx>
      27             : #include <sfx2/docfile.hxx>
      28             : #include <sfx2/dispatch.hxx>
      29             : 
      30             : #include <sfx2/objface.hxx>
      31             : #include <editeng/sizeitem.hxx>
      32             : #include <editeng/protitem.hxx>
      33             : #include <sfx2/request.hxx>
      34             : #include <sfx2/sidebar/EnumContext.hxx>
      35             : #include <svl/srchitem.hxx>
      36             : #include <sfx2/htmlmode.hxx>
      37             : #include <svx/sdgluitm.hxx>
      38             : #include <svx/sdgcoitm.hxx>
      39             : #include <svx/sdggaitm.hxx>
      40             : #include <svx/sdgtritm.hxx>
      41             : #include <svx/sdginitm.hxx>
      42             : #include <svx/sdgmoitm.hxx>
      43             : #include <editeng/brushitem.hxx>
      44             : #include <svx/grfflt.hxx>
      45             : #include <svx/compressgraphicdialog.hxx>
      46             : #include <vcl/GraphicNativeTransform.hxx>
      47             : #include <svx/tbxcolor.hxx>
      48             : #include <fmturl.hxx>
      49             : #include <view.hxx>
      50             : #include <wrtsh.hxx>
      51             : #include <viewopt.hxx>
      52             : #include <swmodule.hxx>
      53             : #include <frmatr.hxx>
      54             : #include <swundo.hxx>
      55             : #include <uitool.hxx>
      56             : #include <docsh.hxx>
      57             : #include <grfsh.hxx>
      58             : #include <frmmgr.hxx>
      59             : #include <frmdlg.hxx>
      60             : #include <frmfmt.hxx>
      61             : #include <grfatr.hxx>
      62             : #include <usrpref.hxx>
      63             : #include <edtwin.hxx>
      64             : #include <swwait.hxx>
      65             : #include <shells.hrc>
      66             : #include <popup.hrc>
      67             : #include <svx/extedit.hxx>
      68             : #include <svx/graphichelper.hxx>
      69             : #include <doc.hxx>
      70             : 
      71             : #define SwGrfShell
      72             : 
      73             : #include <sfx2/msg.hxx>
      74             : #include "swslots.hxx"
      75             : 
      76             : #include "swabstdlg.hxx"
      77             : 
      78             : #define TOOLBOX_NAME "colorbar"
      79             : 
      80             : namespace
      81             : {
      82           0 :     class SwExternalToolEdit : public ExternalToolEdit
      83             :     {
      84             :         SwWrtShell*  m_pShell;
      85             : 
      86             :     public:
      87           0 :         SwExternalToolEdit ( SwWrtShell* pShell ) :
      88           0 :             m_pShell  (pShell)
      89           0 :         {}
      90             : 
      91           0 :         virtual void Update( Graphic& aGraphic ) SAL_OVERRIDE
      92             :         {
      93           0 :             m_pShell->ReRead(OUString(), OUString(), (const Graphic*) &aGraphic);
      94           0 :         }
      95             :     };
      96             : }
      97             : 
      98         222 : SFX_IMPL_INTERFACE(SwGrfShell, SwBaseShell, SW_RES(STR_SHELLNAME_GRAPHIC))
      99             : {
     100          37 :     SFX_POPUPMENU_REGISTRATION(SW_RES(MN_GRF_POPUPMENU));
     101          37 :     SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_GRAFIK_TOOLBOX));
     102          37 : }
     103             : 
     104           0 : void SwGrfShell::Execute(SfxRequest &rReq)
     105             : {
     106           0 :     SwWrtShell &rSh = GetShell();
     107             : 
     108           0 :     sal_uInt16 nSlot = rReq.GetSlot();
     109           0 :     switch(nSlot)
     110             :     {
     111             :         case SID_TWAIN_TRANSFER:
     112             :         {
     113           0 :             GetView().ExecuteScan( rReq );
     114           0 :             break;
     115             :         }
     116             : 
     117             :         case SID_SAVE_GRAPHIC:
     118             :         {
     119             :             const Graphic *pGraphic;
     120           0 :             if(0 != (pGraphic = rSh.GetGraphic()))
     121             :             {
     122           0 :                 OUString sGrfNm;
     123           0 :                 OUString sFilterNm;
     124           0 :                 rSh.GetGrfNms( &sGrfNm, &sFilterNm );
     125           0 :                 GraphicHelper::ExportGraphic( *pGraphic, sGrfNm );
     126             :             }
     127             :         }
     128           0 :         break;
     129             : 
     130             :         case SID_COMPRESS_GRAPHIC:
     131             :         {
     132           0 :             const Graphic* pGraphic = rSh.GetGraphic();
     133           0 :             if( pGraphic )
     134             :             {
     135             :                 Size aSize (
     136           0 :                     TWIP_TO_MM100(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Width()),
     137           0 :                     TWIP_TO_MM100(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Height()));
     138             : 
     139           0 :                 SfxItemSet aSet( rSh.GetAttrPool(), RES_GRFATR_CROPGRF, RES_GRFATR_CROPGRF );
     140           0 :                 rSh.GetCurAttr( aSet );
     141           0 :                 SwCropGrf aCrop( (const SwCropGrf&) aSet.Get(RES_GRFATR_CROPGRF) );
     142             : 
     143             :                 Rectangle aCropRectangle(
     144           0 :                     TWIP_TO_MM100(aCrop.GetLeft()),
     145           0 :                     TWIP_TO_MM100(aCrop.GetTop()),
     146           0 :                     TWIP_TO_MM100(aCrop.GetRight()),
     147           0 :                     TWIP_TO_MM100(aCrop.GetBottom()) );
     148             : 
     149           0 :                 Graphic aGraphic = Graphic( *pGraphic );
     150             : 
     151           0 :                 CompressGraphicsDialog aDialog( GetView().GetWindow(), aGraphic, aSize, aCropRectangle, GetView().GetViewFrame()->GetBindings() );
     152           0 :                 if( aDialog.Execute() == RET_OK )
     153             :                 {
     154           0 :                     rSh.StartAllAction();
     155           0 :                     rSh.StartUndo(UNDO_START);
     156           0 :                     Rectangle aScaledCropedRectangle = aDialog.GetScaledCropRectangle();
     157             : 
     158           0 :                     aCrop.SetLeft(   MM100_TO_TWIP( aScaledCropedRectangle.Left() ));
     159           0 :                     aCrop.SetTop(    MM100_TO_TWIP( aScaledCropedRectangle.Top() ));
     160           0 :                     aCrop.SetRight(  MM100_TO_TWIP( aScaledCropedRectangle.Right() ));
     161           0 :                     aCrop.SetBottom( MM100_TO_TWIP( aScaledCropedRectangle.Bottom() ));
     162             : 
     163           0 :                     Graphic aCompressedGraphic( aDialog.GetCompressedGraphic() );
     164           0 :                     rSh.ReRead(OUString(), OUString(), (const Graphic*) &aCompressedGraphic);
     165             : 
     166           0 :                     rSh.SetAttrItem(aCrop);
     167             : 
     168           0 :                     rSh.EndUndo(UNDO_END);
     169           0 :                     rSh.EndAllAction();
     170           0 :                 }
     171             :             }
     172             :         }
     173           0 :         break;
     174             : 
     175             :         case SID_EXTERNAL_EDIT:
     176             :         {
     177             :             // When the graphic is selected to be opened via some external tool
     178             :             // for advanced editing
     179           0 :             GraphicObject *pGraphicObject = (GraphicObject *) rSh.GetGraphicObj();
     180           0 :             if(0 != pGraphicObject)
     181             :             {
     182           0 :                 SwExternalToolEdit* externalToolEdit = new SwExternalToolEdit( &rSh );
     183           0 :                 externalToolEdit->Edit ( pGraphicObject );
     184             :             }
     185             :         }
     186           0 :         break;
     187             : 
     188             :         case SID_INSERT_GRAPHIC:
     189             :         {
     190             :             // #i123922# implement slot independent from the two below to
     191             :             // bring up the insert graphic dialog and associated actions
     192           0 :             SwView& rLclView = GetView();
     193           0 :             rReq.SetReturnValue(SfxBoolItem(nSlot, rLclView.InsertGraphicDlg( rReq )));
     194           0 :             break;
     195             :         }
     196             :         case FN_FORMAT_GRAFIC_DLG:
     197             :         case FN_DRAW_WRAP_DLG:
     198             :         {
     199           0 :             SwFlyFrmAttrMgr aMgr( sal_False, &rSh, rSh.IsFrmSelected() ?
     200           0 :                                                FRMMGR_TYPE_NONE : FRMMGR_TYPE_GRF);
     201           0 :             const SwViewOption* pVOpt = rSh.GetViewOptions();
     202           0 :             SwViewOption aUsrPref( *pVOpt );
     203             : 
     204           0 :             SfxItemSet aSet(GetPool(), RES_FRMATR_BEGIN, RES_FRMATR_END-1,
     205             :                             RES_GRFATR_MIRRORGRF,   RES_GRFATR_CROPGRF,
     206             :                             SID_ATTR_BORDER_INNER,  SID_ATTR_BORDER_INNER,
     207             :                             SID_ATTR_GRAF_KEEP_ZOOM, SID_ATTR_GRAF_KEEP_ZOOM,
     208             :                             SID_ATTR_GRAF_FRMSIZE, SID_ATTR_GRAF_FRMSIZE,
     209             :                             SID_ATTR_GRAF_FRMSIZE_PERCENT, SID_ATTR_GRAF_FRMSIZE_PERCENT,
     210             :                             SID_ATTR_GRAF_GRAPHIC, SID_ATTR_GRAF_GRAPHIC,
     211             :                             FN_PARAM_GRF_CONNECT,   FN_PARAM_GRF_CONNECT,
     212             :                             SID_ATTR_PAGE_SIZE,     SID_ATTR_PAGE_SIZE,
     213             :                             FN_GET_PRINT_AREA,      FN_GET_PRINT_AREA,
     214             :                             FN_SET_FRM_NAME,        FN_KEEP_ASPECT_RATIO,
     215             :                             FN_PARAM_GRF_DIALOG,    FN_PARAM_GRF_DIALOG,
     216             :                             SID_DOCFRAME,           SID_DOCFRAME,
     217             :                             SID_HTML_MODE,          SID_HTML_MODE,
     218             :                             FN_SET_FRM_ALT_NAME,    FN_SET_FRM_ALT_NAME,
     219             :                             SID_REFERER,            SID_REFERER,
     220           0 :                             0);
     221             : 
     222           0 :             sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
     223           0 :             aSet.Put(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
     224           0 :             FieldUnit eMetric = ::GetDfltMetric((0 != (nHtmlMode&HTMLMODE_ON)));
     225           0 :             SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
     226             : 
     227           0 :             const SwRect* pRect = &rSh.GetAnyCurRect(RECT_PAGE);
     228           0 :             SwFmtFrmSize aFrmSize( ATT_VAR_SIZE, pRect->Width(), pRect->Height());
     229           0 :             aFrmSize.SetWhich( GetPool().GetWhich( SID_ATTR_PAGE_SIZE ) );
     230           0 :             aSet.Put( aFrmSize );
     231             : 
     232           0 :             aSet.Put(SfxStringItem(FN_SET_FRM_NAME, rSh.GetFlyName()));
     233           0 :             if ( nSlot == FN_FORMAT_GRAFIC_DLG )
     234             :             {
     235             :                 // #i73249#
     236           0 :                 aSet.Put( SfxStringItem( FN_SET_FRM_ALT_NAME, rSh.GetObjTitle() ) );
     237             :             }
     238             : 
     239           0 :             pRect = &rSh.GetAnyCurRect(RECT_PAGE_PRT);
     240           0 :             aFrmSize.SetWidth( pRect->Width() );
     241           0 :             aFrmSize.SetHeight( pRect->Height() );
     242           0 :             aFrmSize.SetWhich( GetPool().GetWhich(FN_GET_PRINT_AREA) );
     243           0 :             aSet.Put( aFrmSize );
     244             : 
     245           0 :             aSet.Put( aMgr.GetAttrSet() );
     246           0 :             aSet.SetParent( aMgr.GetAttrSet().GetParent() );
     247             : 
     248             :             // At percentage values initialize size
     249           0 :             SwFmtFrmSize aSizeCopy = (const SwFmtFrmSize&)aSet.Get(RES_FRM_SIZE);
     250           0 :             if (aSizeCopy.GetWidthPercent() && aSizeCopy.GetWidthPercent() != 0xff)
     251           0 :                 aSizeCopy.SetWidth(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Width());
     252           0 :             if (aSizeCopy.GetHeightPercent() && aSizeCopy.GetHeightPercent() != 0xff)
     253           0 :                 aSizeCopy.SetHeight(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Height());
     254             :             // and now set the size for "external" tabpages
     255             :             {
     256           0 :                 SvxSizeItem aSzItm( SID_ATTR_GRAF_FRMSIZE, aSizeCopy.GetSize() );
     257           0 :                 aSet.Put( aSzItm );
     258             : 
     259           0 :                 Size aSz( aSizeCopy.GetWidthPercent(), aSizeCopy.GetHeightPercent() );
     260           0 :                 if( 0xff == aSz.Width() )   aSz.Width() = 0;
     261           0 :                 if( 0xff == aSz.Height() )  aSz.Height() = 0;
     262             : 
     263           0 :                 aSzItm.SetSize( aSz );
     264           0 :                 aSzItm.SetWhich( SID_ATTR_GRAF_FRMSIZE_PERCENT );
     265           0 :                 aSet.Put( aSzItm );
     266             :             }
     267             : 
     268           0 :             OUString sGrfNm;
     269           0 :             OUString sFilterNm;
     270           0 :             rSh.GetGrfNms( &sGrfNm, &sFilterNm );
     271           0 :             if( !sGrfNm.isEmpty() )
     272             :             {
     273             :                 aSet.Put( SvxBrushItem( INetURLObject::decode( sGrfNm,
     274             :                                         '%',
     275             :                                            INetURLObject::DECODE_UNAMBIGUOUS,
     276             :                                         RTL_TEXTENCODING_UTF8 ),
     277             :                                         sFilterNm, GPOS_LT,
     278           0 :                                         SID_ATTR_GRAF_GRAPHIC ));
     279             :             }
     280             :             else
     281             :             {
     282             :                 // #119353# - robust
     283           0 :                 const GraphicObject* pGrfObj = rSh.GetGraphicObj();
     284           0 :                 if ( pGrfObj )
     285             :                 {
     286             :                     aSet.Put( SvxBrushItem( *pGrfObj, GPOS_LT,
     287           0 :                                             SID_ATTR_GRAF_GRAPHIC ) );
     288             :                 }
     289             :             }
     290           0 :             aSet.Put( SfxBoolItem( FN_PARAM_GRF_CONNECT, !sGrfNm.isEmpty() ) );
     291             : 
     292             :             // get Mirror and Crop
     293             :             {
     294           0 :                 SfxItemSet aTmpSet( rSh.GetAttrPool(),
     295           0 :                                 RES_GRFATR_MIRRORGRF, RES_GRFATR_CROPGRF );
     296             : 
     297           0 :                 rSh.GetCurAttr( aTmpSet );
     298           0 :                 aSet.Put( aTmpSet );
     299             :             }
     300             : 
     301           0 :             aSet.Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO, aUsrPref.IsKeepRatio()));
     302           0 :             aSet.Put(SfxBoolItem( SID_ATTR_GRAF_KEEP_ZOOM, aUsrPref.IsGrfKeepZoom()));
     303             : 
     304           0 :             aSet.Put(SfxFrameItem( SID_DOCFRAME, &GetView().GetViewFrame()->GetTopFrame()));
     305             : 
     306           0 :             SfxObjectShell * sh = rSh.GetDoc()->GetPersist();
     307           0 :             if (sh != 0 && sh->HasName())
     308             :             {
     309             :                 aSet.Put(
     310           0 :                     SfxStringItem(SID_REFERER, sh->GetMedium()->GetName()));
     311             :             }
     312             : 
     313           0 :             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     314             :             OSL_ENSURE(pFact, "no dialog factory!");
     315             :             SfxAbstractTabDialog* pDlg = pFact->CreateFrmTabDialog("PictureDialog",
     316           0 :                                                     GetView().GetViewFrame(),
     317           0 :                                                     GetView().GetWindow(),
     318           0 :                                                     aSet, false);
     319             :             OSL_ENSURE(pDlg, "no tab dialog!");
     320             : 
     321           0 :             if (nSlot == FN_DRAW_WRAP_DLG)
     322           0 :                 pDlg->SetCurPageId("wrap");
     323             : 
     324           0 :             if( pDlg->Execute() )
     325             :             {
     326           0 :                 rSh.StartAllAction();
     327           0 :                 rSh.StartUndo(UNDO_START);
     328             :                 const SfxPoolItem* pItem;
     329           0 :                 SfxItemSet* pSet = (SfxItemSet*)pDlg->GetOutputItemSet();
     330           0 :                 rReq.Done(*pSet);
     331             :                 // change the 2 frmsize SizeItems to the correct SwFrmSizeItem
     332           0 :                 if( SFX_ITEM_SET == pSet->GetItemState(
     333           0 :                                 SID_ATTR_GRAF_FRMSIZE, false, &pItem ))
     334             :                 {
     335           0 :                     SwFmtFrmSize aSize;
     336           0 :                     const Size& rSz = ((SvxSizeItem*)pItem)->GetSize();
     337           0 :                     aSize.SetWidth( rSz.Width() );
     338           0 :                     aSize.SetHeight( rSz.Height() );
     339             : 
     340           0 :                     if( SFX_ITEM_SET == pSet->GetItemState(
     341           0 :                             SID_ATTR_GRAF_FRMSIZE_PERCENT, false, &pItem ))
     342             :                     {
     343           0 :                         const Size& rRelativeSize = ((SvxSizeItem*)pItem)->GetSize();
     344           0 :                         aSize.SetWidthPercent( static_cast< sal_uInt8 >( rRelativeSize.Width() ) );
     345           0 :                         aSize.SetHeightPercent( static_cast< sal_uInt8 >( rRelativeSize.Height() ) );
     346             :                     }
     347           0 :                     pSet->Put( aSize );
     348             :                 }
     349             : 
     350             :                 // Templates AutoUpdate
     351           0 :                 SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
     352           0 :                 if(pFmt && pFmt->IsAutoUpdateFmt())
     353             :                 {
     354           0 :                     pFmt->SetFmtAttr(*pSet);
     355           0 :                     SfxItemSet aShellSet(GetPool(), RES_FRM_SIZE,   RES_FRM_SIZE,
     356             :                                                     RES_SURROUND,   RES_SURROUND,
     357             :                                                     RES_ANCHOR,     RES_ANCHOR,
     358             :                                                     RES_VERT_ORIENT,RES_HORI_ORIENT,
     359           0 :                                                     0);
     360           0 :                     aShellSet.Put(*pSet);
     361           0 :                     aMgr.SetAttrSet(aShellSet);
     362             :                 }
     363             :                 else
     364             :                 {
     365           0 :                     aMgr.SetAttrSet(*pSet);
     366             :                 }
     367           0 :                 aMgr.UpdateFlyFrm();
     368             : 
     369           0 :                 bool bApplyUsrPref = false;
     370           0 :                 if (SFX_ITEM_SET == pSet->GetItemState(
     371           0 :                     FN_KEEP_ASPECT_RATIO, true, &pItem ))
     372             :                 {
     373             :                     aUsrPref.SetKeepRatio(
     374           0 :                                     ((const SfxBoolItem*)pItem)->GetValue() );
     375           0 :                     bApplyUsrPref = true;
     376             :                 }
     377           0 :                 if( SFX_ITEM_SET == pSet->GetItemState(
     378           0 :                     SID_ATTR_GRAF_KEEP_ZOOM, true, &pItem ))
     379             :                 {
     380             :                     aUsrPref.SetGrfKeepZoom(
     381           0 :                                     ((const SfxBoolItem*)pItem)->GetValue() );
     382           0 :                     bApplyUsrPref = true;
     383             :                 }
     384             : 
     385           0 :                 if( bApplyUsrPref )
     386           0 :                     SW_MOD()->ApplyUsrPref(aUsrPref, &GetView());
     387             : 
     388             :                 // and now set all the graphic attributes and other stuff
     389           0 :                 if( SFX_ITEM_SET == pSet->GetItemState(
     390           0 :                                         SID_ATTR_GRAF_GRAPHIC, true, &pItem ))
     391             :                 {
     392           0 :                     if( !((SvxBrushItem*)pItem)->GetGraphicLink().isEmpty() )
     393           0 :                         sGrfNm = ((SvxBrushItem*)pItem)->GetGraphicLink();
     394             :                     else
     395           0 :                         sGrfNm = "";
     396             : 
     397           0 :                     if( !((SvxBrushItem*)pItem)->GetGraphicFilter().isEmpty() )
     398           0 :                         sFilterNm = ((SvxBrushItem*)pItem)->GetGraphicFilter();
     399             :                     else
     400           0 :                         sFilterNm = "";
     401             : 
     402           0 :                     if( !sGrfNm.isEmpty() )
     403             :                     {
     404           0 :                         SwDocShell* pDocSh = GetView().GetDocShell();
     405           0 :                         SwWait aWait( *pDocSh, true );
     406           0 :                         SfxMedium* pMedium = pDocSh->GetMedium();
     407           0 :                         INetURLObject aAbs;
     408           0 :                         if( pMedium )
     409           0 :                             aAbs = pMedium->GetURLObject();
     410             :                         rSh.ReRead( URIHelper::SmartRel2Abs(
     411             :                                         aAbs, sGrfNm,
     412             :                                         URIHelper::GetMaybeFileHdl() ),
     413           0 :                                      sFilterNm, 0 );
     414             :                     }
     415             :                 }
     416           0 :                 if ( SFX_ITEM_SET == pSet->GetItemState(
     417           0 :                                         FN_SET_FRM_ALT_NAME, true, &pItem ))
     418             :                 {
     419             :                     // #i73249#
     420           0 :                     rSh.SetObjTitle( ((const SfxStringItem*)pItem)->GetValue() );
     421             :                 }
     422             : 
     423           0 :                 SfxItemSet aGrfSet( rSh.GetAttrPool(), RES_GRFATR_BEGIN,
     424           0 :                                                        RES_GRFATR_END-1 );
     425           0 :                 aGrfSet.Put( *pSet );
     426           0 :                 if( aGrfSet.Count() )
     427           0 :                     rSh.SetAttrSet( aGrfSet );
     428             : 
     429           0 :                 rSh.EndUndo(UNDO_END);
     430           0 :                 rSh.EndAllAction();
     431             :             }
     432           0 :             delete pDlg;
     433             :         }
     434           0 :         break;
     435             : 
     436             :         case FN_GRAPHIC_MIRROR_ON_EVEN_PAGES:
     437             :         {
     438           0 :             SfxItemSet aSet(rSh.GetAttrPool(), RES_GRFATR_MIRRORGRF, RES_GRFATR_MIRRORGRF);
     439           0 :             rSh.GetCurAttr( aSet );
     440           0 :             SwMirrorGrf aGrf((const SwMirrorGrf &)aSet.Get(RES_GRFATR_MIRRORGRF));
     441           0 :             aGrf.SetGrfToggle(!aGrf.IsGrfToggle());
     442           0 :             rSh.SetAttrItem(aGrf);
     443             :         }
     444           0 :         break;
     445             : 
     446             :         default:
     447             :             OSL_ENSURE(!this, "wrong dispatcher");
     448           0 :             return;
     449             :     }
     450             : }
     451             : 
     452           0 : void SwGrfShell::ExecAttr( SfxRequest &rReq )
     453             : {
     454             :     sal_uInt16 nGrfType;
     455           0 :     if( CNT_GRF == GetShell().GetCntType() &&
     456           0 :         ( GRAPHIC_BITMAP == ( nGrfType = GetShell().GetGraphicType()) ||
     457             :           GRAPHIC_GDIMETAFILE == nGrfType ))
     458             :     {
     459           0 :         SfxItemSet aGrfSet( GetShell().GetAttrPool(), RES_GRFATR_BEGIN,
     460           0 :                                                       RES_GRFATR_END -1 );
     461           0 :         const SfxItemSet *pArgs = rReq.GetArgs();
     462             :         const SfxPoolItem* pItem;
     463           0 :         sal_uInt16 nSlot = rReq.GetSlot();
     464           0 :         if( !pArgs || SFX_ITEM_SET != pArgs->GetItemState( nSlot, false, &pItem ))
     465           0 :             pItem = 0;
     466             : 
     467           0 :         switch( nSlot )
     468             :         {
     469             :             case SID_FLIP_VERTICAL:
     470             :             case SID_FLIP_HORIZONTAL:
     471             :             {
     472           0 :                 GetShell().GetCurAttr( aGrfSet );
     473           0 :                 SwMirrorGrf aMirror( (SwMirrorGrf&)aGrfSet.Get( RES_GRFATR_MIRRORGRF ) );
     474           0 :                 sal_uInt16 nMirror = aMirror.GetValue();
     475           0 :                 if ( nSlot==SID_FLIP_HORIZONTAL )
     476           0 :                     switch( nMirror )
     477             :                     {
     478           0 :                     case RES_MIRROR_GRAPH_DONT: nMirror = RES_MIRROR_GRAPH_VERT;
     479           0 :                                                 break;
     480           0 :                     case RES_MIRROR_GRAPH_HOR:  nMirror = RES_MIRROR_GRAPH_BOTH;
     481           0 :                                                 break;
     482           0 :                     case RES_MIRROR_GRAPH_VERT:   nMirror = RES_MIRROR_GRAPH_DONT;
     483           0 :                                                 break;
     484           0 :                     case RES_MIRROR_GRAPH_BOTH: nMirror = RES_MIRROR_GRAPH_HOR;
     485           0 :                                                 break;
     486             :                     }
     487             :                 else
     488           0 :                     switch( nMirror )
     489             :                     {
     490           0 :                     case RES_MIRROR_GRAPH_DONT: nMirror = RES_MIRROR_GRAPH_HOR;
     491           0 :                                                 break;
     492           0 :                     case RES_MIRROR_GRAPH_VERT: nMirror = RES_MIRROR_GRAPH_BOTH;
     493           0 :                                                 break;
     494           0 :                     case RES_MIRROR_GRAPH_HOR:    nMirror = RES_MIRROR_GRAPH_DONT;
     495           0 :                                                 break;
     496           0 :                     case RES_MIRROR_GRAPH_BOTH: nMirror = RES_MIRROR_GRAPH_VERT;
     497           0 :                                                 break;
     498             :                     }
     499           0 :                 aMirror.SetValue( nMirror );
     500           0 :                 aGrfSet.ClearItem();
     501           0 :                 aGrfSet.Put( aMirror );
     502             :             }
     503           0 :             break;
     504             : 
     505             :         case SID_ATTR_GRAF_LUMINANCE:
     506           0 :             if( pItem )
     507             :                 aGrfSet.Put( SwLuminanceGrf(
     508           0 :                             ((SfxInt16Item*)pItem)->GetValue() ));
     509           0 :             break;
     510             : 
     511             :         case SID_ATTR_GRAF_CONTRAST:
     512           0 :             if( pItem )
     513             :                 aGrfSet.Put( SwContrastGrf(
     514           0 :                             ((SfxInt16Item*)pItem)->GetValue() ));
     515           0 :             break;
     516             : 
     517             :         case SID_ATTR_GRAF_RED:
     518           0 :             if( pItem )
     519             :                 aGrfSet.Put( SwChannelRGrf(
     520           0 :                             ((SfxInt16Item*)pItem)->GetValue() ));
     521           0 :             break;
     522             : 
     523             :         case SID_ATTR_GRAF_GREEN:
     524           0 :             if( pItem )
     525             :                 aGrfSet.Put( SwChannelGGrf(
     526           0 :                             ((SfxInt16Item*)pItem)->GetValue() ));
     527           0 :             break;
     528             : 
     529             :         case SID_ATTR_GRAF_BLUE:
     530           0 :             if( pItem )
     531             :                 aGrfSet.Put( SwChannelBGrf(
     532           0 :                             ((SfxInt16Item*)pItem)->GetValue() ));
     533           0 :             break;
     534             : 
     535             :         case SID_ATTR_GRAF_GAMMA:
     536           0 :             if( pItem )
     537             :             {
     538           0 :                 double fVal = ((SfxUInt32Item*)pItem)->GetValue();
     539           0 :                 aGrfSet.Put( SwGammaGrf(fVal/100. ));
     540             :             }
     541           0 :             break;
     542             : 
     543             :         case SID_ATTR_GRAF_TRANSPARENCE:
     544           0 :             if( pItem )
     545             :                 aGrfSet.Put( SwTransparencyGrf(
     546           0 :                     static_cast< sal_Int8 >( ( (SfxUInt16Item*)pItem )->GetValue() ) ) );
     547           0 :             break;
     548             : 
     549             :         case SID_ATTR_GRAF_INVERT:
     550           0 :             if( pItem )
     551             :                 aGrfSet.Put( SwInvertGrf(
     552           0 :                             ((SfxBoolItem*)pItem)->GetValue() ));
     553           0 :             break;
     554             : 
     555             :         case SID_ATTR_GRAF_MODE:
     556           0 :             if( pItem )
     557             :                 aGrfSet.Put( SwDrawModeGrf(
     558           0 :                             ((SfxUInt16Item*)pItem)->GetValue() ));
     559           0 :             break;
     560             : 
     561             :         case SID_COLOR_SETTINGS:
     562             :         {
     563           0 :             svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
     564           0 :             aToolboxAccess.toggleToolbox();
     565           0 :             break;
     566             :         }
     567             : 
     568             :         case SID_GRFFILTER:
     569             :         case SID_GRFFILTER_INVERT:
     570             :         case SID_GRFFILTER_SMOOTH:
     571             :         case SID_GRFFILTER_SHARPEN:
     572             :         case SID_GRFFILTER_REMOVENOISE:
     573             :         case SID_GRFFILTER_SOBEL:
     574             :         case SID_GRFFILTER_MOSAIC:
     575             :         case SID_GRFFILTER_EMBOSS:
     576             :         case SID_GRFFILTER_POSTER:
     577             :         case SID_GRFFILTER_POPART:
     578             :         case SID_GRFFILTER_SEPIA:
     579             :         case SID_GRFFILTER_SOLARIZE:
     580           0 :             if( GRAPHIC_BITMAP == nGrfType )
     581             :             {
     582             :                 // #119353# - robust
     583           0 :                 const GraphicObject* pFilterObj( GetShell().GetGraphicObj() );
     584           0 :                 if ( pFilterObj )
     585             :                 {
     586           0 :                     GraphicObject aFilterObj( *pFilterObj );
     587           0 :                     if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
     588           0 :                         SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ))
     589           0 :                         GetShell().ReRead( OUString(), OUString(),
     590           0 :                                            &aFilterObj.GetGraphic() );
     591             :                 }
     592             :             }
     593           0 :             break;
     594             : 
     595             :         default:
     596             :             OSL_ENSURE(!this, "wrong dispatcher");
     597             :         }
     598             : 
     599           0 :         if( aGrfSet.Count() )
     600           0 :             GetShell().SetAttrSet( aGrfSet );
     601             :     }
     602           0 :     GetView().GetViewFrame()->GetBindings().Invalidate(rReq.GetSlot());
     603           0 : }
     604             : 
     605           0 : void SwGrfShell::GetAttrState(SfxItemSet &rSet)
     606             : {
     607           0 :     SwWrtShell &rSh = GetShell();
     608           0 :     SfxItemSet aCoreSet( GetPool(), aNoTxtNodeSetRange );
     609           0 :     rSh.GetCurAttr( aCoreSet );
     610           0 :     bool bParentCntProt = 0 != rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT );
     611           0 :     bool bIsGrfCntnt = CNT_GRF == GetShell().GetCntType();
     612             : 
     613           0 :     SetGetStateSet( &rSet );
     614             : 
     615           0 :     SfxWhichIter aIter( rSet );
     616           0 :     sal_uInt16 nWhich = aIter.FirstWhich();
     617           0 :     while( nWhich )
     618             :     {
     619           0 :         bool bDisable = bParentCntProt;
     620           0 :         switch( nWhich )
     621             :         {
     622             :         case SID_INSERT_GRAPHIC:
     623             :         case FN_FORMAT_GRAFIC_DLG:
     624             :         case SID_TWAIN_TRANSFER:
     625           0 :             if( bParentCntProt || !bIsGrfCntnt )
     626           0 :                 bDisable = true;
     627           0 :             else if ( nWhich == SID_INSERT_GRAPHIC
     628           0 :                       && rSh.CrsrInsideInputFld() )
     629             :             {
     630           0 :                 bDisable = true;
     631             :             }
     632           0 :             break;
     633             : 
     634             :         case SID_SAVE_GRAPHIC:
     635             :         case SID_EXTERNAL_EDIT:
     636           0 :             if( rSh.GetGraphicType() == GRAPHIC_NONE )
     637           0 :                 bDisable = true;
     638           0 :             break;
     639             : 
     640             :         case SID_COLOR_SETTINGS:
     641             :         {
     642           0 :             if ( bParentCntProt || !bIsGrfCntnt )
     643           0 :                 bDisable = true;
     644             :             else
     645             :             {
     646           0 :                 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
     647           0 :                 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
     648             :             }
     649           0 :             break;
     650             :         }
     651             : 
     652             :         case SID_FLIP_HORIZONTAL:
     653           0 :             if( !bParentCntProt )
     654             :             {
     655             :                 MirrorGraph nState = static_cast< MirrorGraph >(((const SwMirrorGrf &) aCoreSet.Get(
     656           0 :                                         RES_GRFATR_MIRRORGRF )).GetValue());
     657             : 
     658           0 :                 rSet.Put(SfxBoolItem( nWhich, nState == RES_MIRROR_GRAPH_VERT ||
     659           0 :                                               nState == RES_MIRROR_GRAPH_BOTH));
     660             :             }
     661           0 :             break;
     662             : 
     663             :         case SID_FLIP_VERTICAL:
     664           0 :             if( !bParentCntProt )
     665             :             {
     666             :                 MirrorGraph nState = static_cast< MirrorGraph >(((const SwMirrorGrf &) aCoreSet.Get(
     667           0 :                                         RES_GRFATR_MIRRORGRF )).GetValue());
     668             : 
     669           0 :                 rSet.Put(SfxBoolItem( nWhich, nState == RES_MIRROR_GRAPH_HOR ||
     670           0 :                                               nState == RES_MIRROR_GRAPH_BOTH));
     671             :             }
     672           0 :             break;
     673             : 
     674             :         case SID_ATTR_GRAF_LUMINANCE:
     675           0 :             if( !bParentCntProt )
     676             :                 rSet.Put( SfxInt16Item( nWhich, ((SwLuminanceGrf&)
     677           0 :                         aCoreSet.Get(RES_GRFATR_LUMINANCE)).GetValue() ));
     678           0 :             break;
     679             : 
     680             :         case SID_ATTR_GRAF_CONTRAST:
     681           0 :             if( !bParentCntProt )
     682             :                 rSet.Put( SfxInt16Item( nWhich, ((SwContrastGrf&)
     683           0 :                         aCoreSet.Get(RES_GRFATR_CONTRAST)).GetValue() ));
     684           0 :             break;
     685             : 
     686             :         case SID_ATTR_GRAF_RED:
     687           0 :             if( !bParentCntProt )
     688             :                 rSet.Put( SfxInt16Item( nWhich, ((SwChannelRGrf&)
     689           0 :                         aCoreSet.Get(RES_GRFATR_CHANNELR)).GetValue() ));
     690           0 :             break;
     691             : 
     692             :         case SID_ATTR_GRAF_GREEN:
     693           0 :             if( !bParentCntProt )
     694             :                 rSet.Put( SfxInt16Item( nWhich, ((SwChannelGGrf&)
     695           0 :                         aCoreSet.Get(RES_GRFATR_CHANNELG)).GetValue() ));
     696           0 :             break;
     697             : 
     698             :         case SID_ATTR_GRAF_BLUE:
     699           0 :             if( !bParentCntProt )
     700             :                 rSet.Put( SfxInt16Item( nWhich, ((SwChannelBGrf&)
     701           0 :                         aCoreSet.Get(RES_GRFATR_CHANNELB)).GetValue() ));
     702           0 :             break;
     703             : 
     704             :         case SID_ATTR_GRAF_GAMMA:
     705           0 :             if( !bParentCntProt )
     706             :                 rSet.Put( SfxUInt32Item( nWhich, static_cast< sal_uInt32 >(
     707           0 :                     ( (SwGammaGrf&)aCoreSet.Get( RES_GRFATR_GAMMA ) ).GetValue() * 100 ) ) );
     708           0 :             break;
     709             : 
     710             :         case SID_ATTR_GRAF_TRANSPARENCE:
     711           0 :             if( !bParentCntProt )
     712             :             {
     713             :                 // #119353# - robust
     714           0 :                 const GraphicObject* pGrafObj = rSh.GetGraphicObj();
     715           0 :                 if ( pGrafObj )
     716             :                 {
     717           0 :                     if( pGrafObj->IsAnimated() ||
     718           0 :                         GRAPHIC_GDIMETAFILE == pGrafObj->GetType() )
     719           0 :                         bDisable = true;
     720             :                     else
     721             :                         rSet.Put( SfxUInt16Item( nWhich, ((SwTransparencyGrf&)
     722           0 :                             aCoreSet.Get(RES_GRFATR_TRANSPARENCY)).GetValue() ));
     723             :                 }
     724             :             }
     725           0 :             break;
     726             : 
     727             :         case SID_ATTR_GRAF_INVERT:
     728           0 :             if( !bParentCntProt )
     729             :                 rSet.Put( SfxBoolItem( nWhich, ((SwInvertGrf&)
     730           0 :                         aCoreSet.Get(RES_GRFATR_INVERT)).GetValue() ));
     731           0 :             break;
     732             : 
     733             :         case SID_ATTR_GRAF_MODE:
     734           0 :             if( !bParentCntProt )
     735             :                 rSet.Put( SfxUInt16Item( nWhich, ((SwDrawModeGrf&)
     736           0 :                         aCoreSet.Get(RES_GRFATR_DRAWMODE)).GetValue() ));
     737           0 :             break;
     738             : 
     739             :         case SID_GRFFILTER:
     740             :         case SID_GRFFILTER_INVERT:
     741             :         case SID_GRFFILTER_SMOOTH:
     742             :         case SID_GRFFILTER_SHARPEN:
     743             :         case SID_GRFFILTER_REMOVENOISE:
     744             :         case SID_GRFFILTER_SOBEL:
     745             :         case SID_GRFFILTER_MOSAIC:
     746             :         case SID_GRFFILTER_EMBOSS:
     747             :         case SID_GRFFILTER_POSTER:
     748             :         case SID_GRFFILTER_POPART:
     749             :         case SID_GRFFILTER_SEPIA:
     750             :         case SID_GRFFILTER_SOLARIZE:
     751             :             {
     752           0 :                 if( bParentCntProt || !bIsGrfCntnt )
     753           0 :                     bDisable = true;
     754             :                 // #i59688# load graphic only if type is unknown
     755             :                 else
     756             :                 {
     757           0 :                     const sal_uInt16 eGraphicType( rSh.GetGraphicType() );
     758           0 :                     if ( ( eGraphicType == GRAPHIC_NONE ||
     759           0 :                            eGraphicType == GRAPHIC_DEFAULT ) &&
     760           0 :                          rSh.IsGrfSwapOut( sal_True ) )
     761             :                     {
     762           0 :                         rSet.DisableItem( nWhich );
     763           0 :                         if( AddGrfUpdateSlot( nWhich ))
     764           0 :                             rSh.GetGraphic(sal_False);  // start the loading
     765             :                     }
     766             :                     else
     767             :                     {
     768           0 :                         bDisable = eGraphicType != GRAPHIC_BITMAP;
     769             :                     }
     770             :                 }
     771             :             }
     772           0 :             break;
     773             : 
     774             :         default:
     775           0 :             bDisable = false;
     776             :         }
     777             : 
     778           0 :         if( bDisable )
     779           0 :             rSet.DisableItem( nWhich );
     780           0 :         nWhich = aIter.NextWhich();
     781             :     }
     782           0 :     SetGetStateSet( 0 );
     783           0 : }
     784             : 
     785           0 : void SwGrfShell::ExecuteRotation(SfxRequest &rReq)
     786             : {
     787             :     sal_uInt16 aRotation;
     788             : 
     789           0 :     SwWrtShell& rShell = GetShell();
     790             : 
     791           0 :     if (rReq.GetSlot() == SID_ROTATE_GRAPHIC_LEFT)
     792             :     {
     793           0 :         aRotation = 900;
     794             :     }
     795           0 :     else if (rReq.GetSlot() == SID_ROTATE_GRAPHIC_RIGHT)
     796             :     {
     797           0 :         aRotation = 2700;
     798             :     }
     799             :     else
     800             :     {
     801           0 :         return;
     802             :     }
     803             : 
     804           0 :     rShell.StartAllAction();
     805           0 :     rShell.StartUndo(UNDO_START);
     806             : 
     807           0 :     Graphic aGraphic = *rShell.GetGraphic();
     808           0 :     GraphicNativeTransform aTransform(aGraphic);
     809           0 :     aTransform.rotate(aRotation);
     810           0 :     rShell.ReRead(OUString(), OUString(), (const Graphic*) &aGraphic);
     811             : 
     812           0 :     SwFlyFrmAttrMgr aManager(false, &rShell, rShell.IsFrmSelected() ? FRMMGR_TYPE_NONE : FRMMGR_TYPE_GRF);
     813           0 :     Size aSize(aManager.GetSize().Height(), aManager.GetSize().Width());
     814           0 :     aManager.SetSize(aSize);
     815           0 :     aManager.UpdateFlyFrm();
     816             : 
     817           0 :     SfxItemSet aSet( rShell.GetAttrPool(), RES_GRFATR_CROPGRF, RES_GRFATR_CROPGRF );
     818           0 :     rShell.GetCurAttr( aSet );
     819           0 :     SwCropGrf aCrop( (const SwCropGrf&) aSet.Get(RES_GRFATR_CROPGRF) );
     820           0 :     Rectangle aCropRectangle(aCrop.GetLeft(),  aCrop.GetTop(), aCrop.GetRight(), aCrop.GetBottom());
     821             : 
     822           0 :     if (rReq.GetSlot() == SID_ROTATE_GRAPHIC_LEFT)
     823             :     {
     824           0 :         aCrop.SetLeft(   aCropRectangle.Top()    );
     825           0 :         aCrop.SetTop(    aCropRectangle.Right()  );
     826           0 :         aCrop.SetRight(  aCropRectangle.Bottom() );
     827           0 :         aCrop.SetBottom( aCropRectangle.Left()   );
     828             :     }
     829           0 :     else if (rReq.GetSlot() == SID_ROTATE_GRAPHIC_RIGHT)
     830             :     {
     831           0 :         aCrop.SetLeft(   aCropRectangle.Bottom() );
     832           0 :         aCrop.SetTop(    aCropRectangle.Left()   );
     833           0 :         aCrop.SetRight(  aCropRectangle.Top()    );
     834           0 :         aCrop.SetBottom( aCropRectangle.Right()  );
     835             :     }
     836             : 
     837           0 :     rShell.SetAttrItem(aCrop);
     838             : 
     839           0 :     rShell.EndUndo(UNDO_END);
     840           0 :     rShell.EndAllAction();
     841             : }
     842             : 
     843           0 : void SwGrfShell::GetAttrStateForRotation(SfxItemSet &rSet)
     844             : {
     845           0 :     SwWrtShell& rShell = GetShell();
     846           0 :     bool bIsParentContentProtected = 0 != rShell.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT );
     847             : 
     848           0 :     SetGetStateSet( &rSet );
     849             : 
     850           0 :     SfxWhichIter aIterator( rSet );
     851           0 :     sal_uInt16 nWhich = aIterator.FirstWhich();
     852           0 :     while( nWhich )
     853             :     {
     854           0 :         bool bDisable = bIsParentContentProtected;
     855           0 :         switch( nWhich )
     856             :         {
     857             :         case SID_ROTATE_GRAPHIC_LEFT:
     858             :         case SID_ROTATE_GRAPHIC_RIGHT:
     859           0 :             if( rShell.GetGraphicType() == GRAPHIC_NONE )
     860             :             {
     861           0 :                 bDisable = true;
     862             :             }
     863             :             else
     864             :             {
     865           0 :                 Graphic aGraphic = *rShell.GetGraphic();
     866           0 :                 GraphicNativeTransform aTransform(aGraphic);
     867           0 :                 if (!aTransform.canBeRotated())
     868             :                 {
     869           0 :                     bDisable = true;
     870           0 :                 }
     871             :             }
     872           0 :             break;
     873             :         default:
     874           0 :             bDisable = false;
     875             :         }
     876             : 
     877           0 :         if( bDisable )
     878           0 :             rSet.DisableItem( nWhich );
     879           0 :         nWhich = aIterator.NextWhich();
     880             :     }
     881           0 :     SetGetStateSet( 0 );
     882           0 : }
     883             : 
     884           0 : SwGrfShell::SwGrfShell(SwView &_rView) :
     885           0 :     SwBaseShell(_rView)
     886             : {
     887           0 :     SetName(OUString("Graphic"));
     888           0 :     SetHelpId(SW_GRFSHELL);
     889           0 :     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Graphic));
     890         111 : }
     891             : 
     892             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10