LCOV - code coverage report
Current view: top level - sw/source/uibase/docvw - romenu.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 189 0.5 %
Date: 2014-11-03 Functions: 2 9 22.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 <hintids.hxx>
      21             : 
      22             : #include <svl/eitem.hxx>
      23             : #include <svl/stritem.hxx>
      24             : #include <svtools/imap.hxx>
      25             : #include <svtools/inetimg.hxx>
      26             : #include <svtools/transfer.hxx>
      27             : #include <sfx2/docfile.hxx>
      28             : #include <sfx2/dispatch.hxx>
      29             : #include <svx/gallery.hxx>
      30             : #include <svx/graphichelper.hxx>
      31             : #include <editeng/brushitem.hxx>
      32             : 
      33             : #include <frmatr.hxx>
      34             : #include <fmturl.hxx>
      35             : #include <fmtinfmt.hxx>
      36             : #include <docsh.hxx>
      37             : #include <view.hxx>
      38             : #include <wrtsh.hxx>
      39             : #include <viewopt.hxx>
      40             : #include <swmodule.hxx>
      41             : #include <romenu.hxx>
      42             : #include <pagedesc.hxx>
      43             : #include <modcfg.hxx>
      44             : 
      45             : #include <cmdid.h>
      46             : #include <helpid.h>
      47             : #include <docvw.hrc>
      48             : 
      49             : using namespace ::com::sun::star::lang;
      50             : using namespace ::com::sun::star::uno;
      51             : using namespace ::com::sun::star;
      52             : using namespace ::sfx2;
      53             : 
      54           0 : SwReadOnlyPopup::~SwReadOnlyPopup()
      55             : {
      56           0 :     delete pImageMap;
      57           0 :     delete pTargetURL;
      58           0 : }
      59             : 
      60           0 : void SwReadOnlyPopup::Check( sal_uInt16 nMID, sal_uInt16 nSID, SfxDispatcher &rDis )
      61             : {
      62           0 :     SfxPoolItem *_pItem = 0;
      63           0 :     SfxItemState eState = rDis.GetBindings()->QueryState( nSID, _pItem );
      64           0 :     if (eState >= SfxItemState::DEFAULT)
      65             :     {
      66           0 :         EnableItem( nMID, true );
      67           0 :         if (_pItem)
      68             :         {
      69           0 :             CheckItem ( nMID, !_pItem->ISA(SfxVoidItem) &&
      70           0 :                             _pItem->ISA(SfxBoolItem) &&
      71           0 :                             ((SfxBoolItem*)_pItem)->GetValue());
      72             :             //remove full screen entry when not in full screen mode
      73           0 :             if( SID_WIN_FULLSCREEN == nSID && !IsItemChecked(SID_WIN_FULLSCREEN) )
      74           0 :                 EnableItem(nMID, false);
      75             :         }
      76             :     }
      77             :     else
      78           0 :         EnableItem( nMID, false );
      79             : 
      80           0 :     delete _pItem;
      81           0 : }
      82             : 
      83           0 : SwReadOnlyPopup::SwReadOnlyPopup( const Point &rDPos, SwView &rV ) :
      84             :     PopupMenu( SW_RES(MN_READONLY_POPUP) ),
      85             :     rView  ( rV ),
      86             :     aBrushItem(RES_BACKGROUND),
      87             :     rDocPos( rDPos ),
      88             :     pImageMap( 0 ),
      89           0 :     pTargetURL( 0 )
      90             : {
      91           0 :     bGrfToGalleryAsLnk = SW_MOD()->GetModuleConfig()->IsGrfToGalleryAsLnk();
      92           0 :     SwWrtShell &rSh = rView.GetWrtShell();
      93           0 :     rSh.IsURLGrfAtPos( rDocPos, &sURL, &sTargetFrameName, &sDescription );
      94           0 :     if ( sURL.isEmpty() )
      95             :     {
      96           0 :         SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
      97           0 :         if( rSh.GetContentAtPos( rDocPos, aCntntAtPos, false))
      98             :         {
      99           0 :             SwFmtINetFmt &rIItem = *(SwFmtINetFmt*)aCntntAtPos.aFnd.pAttr;
     100           0 :             sURL = rIItem.GetValue();
     101           0 :             sTargetFrameName = rIItem.GetTargetFrame();
     102           0 :             sDescription = aCntntAtPos.sStr;
     103           0 :         }
     104             :     }
     105             : 
     106           0 :     bool bLink = false;
     107             :     const Graphic *pGrf;
     108           0 :     if ( 0 == (pGrf = rSh.GetGrfAtPos( rDocPos, sGrfName, bLink )) )
     109             :     {
     110           0 :         EnableItem( MN_READONLY_SAVEGRAPHIC, false );
     111           0 :         EnableItem( MN_READONLY_COPYGRAPHIC, false );
     112             :     }
     113             :     else
     114             :     {
     115           0 :         aGraphic = *pGrf;
     116           0 :         const SwFrmFmt* pGrfFmt = rSh.GetFmtFromObj( rDocPos );
     117             :         const SfxPoolItem* pURLItem;
     118           0 :         if( pGrfFmt && SfxItemState::SET == pGrfFmt->GetItemState(
     119           0 :             RES_URL, true, &pURLItem ))
     120             :         {
     121           0 :             const SwFmtURL& rURL = *(SwFmtURL*)pURLItem;
     122           0 :             if( rURL.GetMap() )
     123           0 :                 pImageMap = new ImageMap( *rURL.GetMap() );
     124           0 :             else if( !rURL.GetURL().isEmpty() )
     125             :                 pTargetURL = new INetImage( bLink ? sGrfName : OUString(),
     126             :                                             rURL.GetURL(),
     127             :                                             rURL.GetTargetFrameName(),
     128           0 :                                             OUString(), Size() );
     129             :         }
     130             :     }
     131             : 
     132           0 :     bool bEnableGraphicToGallery = bLink;
     133           0 :     if ( bEnableGraphicToGallery )
     134             :     {
     135           0 :         if (GalleryExplorer::FillThemeList( aThemeList ))
     136             :         {
     137           0 :             PopupMenu *pMenu = GetPopupMenu(MN_READONLY_GRAPHICTOGALLERY);
     138           0 :             pMenu->CheckItem( MN_READONLY_TOGALLERYLINK,  bGrfToGalleryAsLnk );
     139           0 :             pMenu->CheckItem( MN_READONLY_TOGALLERYCOPY, !bGrfToGalleryAsLnk );
     140             : 
     141           0 :             for ( sal_uInt16 i=0; i < aThemeList.size(); ++i )
     142           0 :                 pMenu->InsertItem( MN_READONLY_GRAPHICTOGALLERY+i + 3, aThemeList[ i ] );
     143             :         }
     144             :         else
     145           0 :             bEnableGraphicToGallery = false;
     146             :     }
     147             : 
     148           0 :     EnableItem( MN_READONLY_GRAPHICTOGALLERY, bEnableGraphicToGallery );
     149             : 
     150           0 :     SfxViewFrame * pVFrame = rV.GetViewFrame();
     151           0 :     SfxDispatcher &rDis = *pVFrame->GetDispatcher();
     152           0 :     const SwPageDesc &rDesc = rSh.GetPageDesc( rSh.GetCurPageDesc() );
     153           0 :     aBrushItem = rDesc.GetMaster().makeBackgroundBrushItem();
     154           0 :     bool bEnableBackGallery = false,
     155           0 :          bEnableBack = false;
     156             : 
     157           0 :     if ( GPOS_NONE != aBrushItem.GetGraphicPos() )
     158             :     {
     159           0 :         bEnableBack = true;
     160           0 :         if ( !aBrushItem.GetGraphicLink().isEmpty() )
     161             :         {
     162           0 :             if ( aThemeList.empty() )
     163           0 :                 GalleryExplorer::FillThemeList( aThemeList );
     164             : 
     165           0 :             if ( !aThemeList.empty() )
     166             :             {
     167           0 :                 PopupMenu *pMenu = GetPopupMenu(MN_READONLY_BACKGROUNDTOGALLERY);
     168           0 :                 pMenu->CheckItem( MN_READONLY_TOGALLERYLINK,  bGrfToGalleryAsLnk );
     169           0 :                 pMenu->CheckItem( MN_READONLY_TOGALLERYCOPY, !bGrfToGalleryAsLnk );
     170           0 :                 bEnableBackGallery = true;
     171             : 
     172           0 :                 for ( sal_uInt16 i=0; i < aThemeList.size(); ++i )
     173           0 :                     pMenu->InsertItem( MN_READONLY_GRAPHICTOGALLERY+i + 3, aThemeList[ i ] );
     174             :             }
     175             :         }
     176             :     }
     177           0 :     EnableItem( MN_READONLY_SAVEBACKGROUND, bEnableBack );
     178           0 :     EnableItem( MN_READONLY_BACKGROUNDTOGALLERY, bEnableBackGallery );
     179             : 
     180           0 :     if ( !rSh.GetViewOptions()->IsGraphic() )
     181           0 :         CheckItem( MN_READONLY_GRAPHICOFF );
     182             :     else
     183           0 :         EnableItem( MN_READONLY_LOADGRAPHIC, false );
     184             : 
     185           0 :     bool bReloadFrame = 0 != rSh.GetView().GetViewFrame()->GetFrame().GetParentFrame();
     186             :     EnableItem( MN_READONLY_RELOAD_FRAME,
     187           0 :             bReloadFrame );
     188           0 :     EnableItem( MN_READONLY_RELOAD, !bReloadFrame);
     189             : 
     190           0 :     Check( MN_READONLY_EDITDOC,         SID_EDITDOC,        rDis );
     191           0 :     Check( MN_READONLY_SELECTION_MODE,  FN_READONLY_SELECTION_MODE,    rDis );
     192           0 :     Check( MN_READONLY_SOURCEVIEW,      SID_SOURCEVIEW,     rDis );
     193           0 :     Check( MN_READONLY_BROWSE_BACKWARD, SID_BROWSE_BACKWARD,rDis );
     194           0 :     Check( MN_READONLY_BROWSE_FORWARD,  SID_BROWSE_FORWARD, rDis );
     195             : #ifdef WNT
     196             :     Check( MN_READONLY_PLUGINOFF,       SID_PLUGINS_ACTIVE, rDis );
     197             : #endif
     198           0 :     Check( MN_READONLY_OPENURL,         SID_OPENDOC,        rDis );
     199           0 :     Check( MN_READONLY_OPENURLNEW,      SID_OPENDOC,        rDis );
     200             : 
     201           0 :     SfxPoolItem* pState = NULL;
     202             : 
     203           0 :     SfxItemState eState = pVFrame->GetBindings().QueryState( SID_COPY, pState );
     204           0 :     Check( MN_READONLY_COPY,            SID_COPY,           rDis );
     205           0 :     if(eState < SfxItemState::DEFAULT)
     206           0 :         EnableItem( MN_READONLY_COPY, false );
     207           0 :     delete pState;
     208           0 :     pState = NULL;
     209             : 
     210           0 :     eState = pVFrame->GetBindings().QueryState( SID_EDITDOC, pState );
     211           0 :     if (
     212           0 :         eState < SfxItemState::DEFAULT ||
     213           0 :         (rSh.IsGlobalDoc() && rView.GetDocShell()->IsReadOnlyUI())
     214             :        )
     215             :     {
     216           0 :         EnableItem( MN_READONLY_EDITDOC, false );
     217             :     }
     218           0 :     delete pState;
     219             : 
     220           0 :     if ( sURL.isEmpty() )
     221             :     {
     222           0 :         EnableItem( MN_READONLY_OPENURL, false );
     223           0 :         EnableItem( MN_READONLY_OPENURLNEW, false );
     224           0 :         EnableItem( MN_READONLY_COPYLINK, false );
     225             :     }
     226           0 :     Check( SID_WIN_FULLSCREEN,         SID_WIN_FULLSCREEN,        rDis );
     227             : 
     228           0 :     RemoveDisabledEntries( true, true );
     229           0 : }
     230             : 
     231           0 : void SwReadOnlyPopup::Execute( vcl::Window* pWin, const Point &rPixPos )
     232             : {
     233             :     sal_uInt16 nId     = PopupMenu::Execute(
     234             :     pWin,
     235           0 :     rPixPos );
     236           0 :     Execute(pWin, nId);
     237           0 : }
     238             : 
     239             : // execute the resulting ID only - necessary to support XContextMenuInterception
     240           0 : void SwReadOnlyPopup::Execute( vcl::Window* pWin, sal_uInt16 nId )
     241             : {
     242           0 :     SwWrtShell &rSh = rView.GetWrtShell();
     243           0 :     SfxDispatcher &rDis = *rView.GetViewFrame()->GetDispatcher();
     244           0 :     if ( nId >= MN_READONLY_GRAPHICTOGALLERY )
     245             :     {
     246           0 :         OUString sTmp;
     247             :         sal_uInt16 nSaveId;
     248           0 :         if ( nId >= MN_READONLY_BACKGROUNDTOGALLERY )
     249             :         {
     250           0 :             nId -= MN_READONLY_BACKGROUNDTOGALLERY+3;
     251           0 :             nSaveId = MN_READONLY_SAVEBACKGROUND;
     252           0 :             sTmp = aBrushItem.GetGraphicLink();
     253             :         }
     254             :         else
     255             :         {
     256           0 :             nId -= MN_READONLY_GRAPHICTOGALLERY+3;
     257           0 :             nSaveId = MN_READONLY_SAVEGRAPHIC;
     258           0 :             sTmp = sGrfName;
     259             :         }
     260           0 :         if ( !bGrfToGalleryAsLnk )
     261           0 :             sTmp = SaveGraphic( nSaveId );
     262             : 
     263           0 :         if ( !sTmp.isEmpty() )
     264           0 :             GalleryExplorer::InsertURL( aThemeList[nId], sTmp );
     265             : 
     266           0 :         return;
     267             :     }
     268             : 
     269           0 :     TransferDataContainer* pClipCntnr = 0;
     270             : 
     271           0 :     sal_uInt16 nExecId = USHRT_MAX;
     272           0 :     sal_uInt16 nFilter = USHRT_MAX;
     273           0 :     switch( nId )
     274             :     {
     275           0 :         case SID_WIN_FULLSCREEN :           nExecId = SID_WIN_FULLSCREEN; break;
     276           0 :         case MN_READONLY_OPENURL:           nFilter = URLLOAD_NOFILTER;   break;
     277           0 :         case MN_READONLY_OPENURLNEW:        nFilter = URLLOAD_NEWVIEW;    break;
     278           0 :         case MN_READONLY_COPY:              nExecId = SID_COPY;           break;
     279             : 
     280           0 :         case MN_READONLY_EDITDOC:           nExecId = SID_EDITDOC;        break;
     281           0 :         case MN_READONLY_SELECTION_MODE:    nExecId = FN_READONLY_SELECTION_MODE; break;
     282             :         case MN_READONLY_RELOAD:
     283             :         case MN_READONLY_RELOAD_FRAME:
     284           0 :             rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(SID_RELOAD);
     285           0 :         break;
     286             : 
     287           0 :         case MN_READONLY_BROWSE_BACKWARD:   nExecId = SID_BROWSE_BACKWARD;break;
     288           0 :         case MN_READONLY_BROWSE_FORWARD:    nExecId = SID_BROWSE_FORWARD; break;
     289           0 :         case MN_READONLY_SOURCEVIEW:        nExecId = SID_SOURCEVIEW;     break;
     290             :         case MN_READONLY_SAVEGRAPHIC:
     291             :         case MN_READONLY_SAVEBACKGROUND:
     292             :             {
     293           0 :                 SaveGraphic( nId );
     294           0 :                 break;
     295             :             }
     296             :         case MN_READONLY_COPYLINK:
     297           0 :             pClipCntnr = new TransferDataContainer;
     298           0 :             pClipCntnr->CopyString( sURL );
     299           0 :             break;
     300             : 
     301             :         case MN_READONLY_COPYGRAPHIC:
     302           0 :             pClipCntnr = new TransferDataContainer;
     303           0 :             pClipCntnr->CopyGraphic( aGraphic );
     304             : 
     305           0 :             if( pImageMap )
     306           0 :                 pClipCntnr->CopyImageMap( *pImageMap );
     307           0 :             if( pTargetURL )
     308           0 :                 pClipCntnr->CopyINetImage( *pTargetURL );
     309           0 :             break;
     310             : 
     311             :         case MN_READONLY_LOADGRAPHIC:
     312             :             {
     313           0 :                 bool bModified = rSh.IsModified();
     314           0 :                 SwViewOption aOpt( *rSh.GetViewOptions() );
     315           0 :                 aOpt.SetGraphic( true );
     316           0 :                 rSh.ApplyViewOptions( aOpt );
     317           0 :                 if(!bModified)
     318           0 :                     rSh.ResetModified();
     319           0 :                 break;
     320             :             }
     321           0 :         case MN_READONLY_GRAPHICOFF:        nExecId = FN_VIEW_GRAPHIC;    break;
     322             : #ifdef WNT
     323             :         case MN_READONLY_PLUGINOFF:         nExecId = SID_PLUGINS_ACTIVE; break;
     324             : #endif
     325             :         case MN_READONLY_TOGALLERYLINK:
     326           0 :             SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( true );
     327           0 :             break;
     328             :         case MN_READONLY_TOGALLERYCOPY:
     329           0 :             SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( false );
     330           0 :             break;
     331             : 
     332             :         default: //forward the id to the SfxBindings
     333           0 :             nExecId = nId;
     334             :     }
     335           0 :     if( USHRT_MAX != nExecId )
     336           0 :         rDis.GetBindings()->Execute( nExecId );
     337           0 :     if( USHRT_MAX != nFilter )
     338           0 :         ::LoadURL(rSh, sURL, nFilter, sTargetFrameName);
     339             : 
     340           0 :     if( pClipCntnr )
     341             :     {
     342           0 :         ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRef( pClipCntnr );
     343           0 :         if( pClipCntnr->HasAnyData() )
     344           0 :             pClipCntnr->CopyToClipboard( pWin );
     345             :     }
     346             : }
     347             : 
     348           0 : OUString SwReadOnlyPopup::SaveGraphic( sal_uInt16 nId )
     349             : {
     350             :     // fish out the graphic's name
     351           0 :     if ( MN_READONLY_SAVEBACKGROUND == nId )
     352             :     {
     353           0 :         if ( !aBrushItem.GetGraphicLink().isEmpty() )
     354           0 :             sGrfName = aBrushItem.GetGraphicLink();
     355           0 :         aBrushItem.SetDoneLink( Link() );
     356           0 :         const Graphic *pGrf = aBrushItem.GetGraphic();
     357           0 :         if ( pGrf )
     358             :         {
     359           0 :             aGraphic = *pGrf;
     360           0 :             if ( !aBrushItem.GetGraphicLink().isEmpty() )
     361           0 :                 sGrfName = aBrushItem.GetGraphicLink();
     362             :         }
     363             :         else
     364           0 :             return OUString();
     365             :     }
     366           0 :     return GraphicHelper::ExportGraphic( aGraphic, sGrfName );
     367         270 : }
     368             : 
     369             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10