LCOV - code coverage report
Current view: top level - sw/source/core/uibase/docvw - romenu.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 188 0.0 %
Date: 2014-04-14 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <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 >= SFX_ITEM_AVAILABLE)
      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             :     rDocPos( rDPos ),
      87             :     pImageMap( 0 ),
      88           0 :     pTargetURL( 0 )
      89             : {
      90           0 :     bGrfToGalleryAsLnk = SW_MOD()->GetModuleConfig()->IsGrfToGalleryAsLnk();
      91           0 :     SwWrtShell &rSh = rView.GetWrtShell();
      92           0 :     rSh.IsURLGrfAtPos( rDocPos, &sURL, &sTargetFrameName, &sDescription );
      93           0 :     if ( sURL.isEmpty() )
      94             :     {
      95           0 :         SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
      96           0 :         if( rSh.GetContentAtPos( rDocPos, aCntntAtPos, sal_False))
      97             :         {
      98           0 :             SwFmtINetFmt &rIItem = *(SwFmtINetFmt*)aCntntAtPos.aFnd.pAttr;
      99           0 :             sURL = rIItem.GetValue();
     100           0 :             sTargetFrameName = rIItem.GetTargetFrame();
     101           0 :             sDescription = aCntntAtPos.sStr;
     102           0 :         }
     103             :     }
     104             : 
     105           0 :     sal_Bool bLink = sal_False;
     106             :     const Graphic *pGrf;
     107           0 :     if ( 0 == (pGrf = rSh.GetGrfAtPos( rDocPos, sGrfName, bLink )) )
     108             :     {
     109           0 :         EnableItem( MN_READONLY_SAVEGRAPHIC, false );
     110           0 :         EnableItem( MN_READONLY_COPYGRAPHIC, false );
     111             :     }
     112             :     else
     113             :     {
     114           0 :         aGraphic = *pGrf;
     115           0 :         const SwFrmFmt* pGrfFmt = rSh.GetFmtFromObj( rDocPos );
     116             :         const SfxPoolItem* pURLItem;
     117           0 :         if( pGrfFmt && SFX_ITEM_SET == pGrfFmt->GetItemState(
     118           0 :             RES_URL, sal_True, &pURLItem ))
     119             :         {
     120           0 :             const SwFmtURL& rURL = *(SwFmtURL*)pURLItem;
     121           0 :             if( rURL.GetMap() )
     122           0 :                 pImageMap = new ImageMap( *rURL.GetMap() );
     123           0 :             else if( !rURL.GetURL().isEmpty() )
     124             :                 pTargetURL = new INetImage( bLink ? sGrfName : OUString(),
     125             :                                             rURL.GetURL(),
     126             :                                             rURL.GetTargetFrameName(),
     127           0 :                                             OUString(), Size() );
     128             :         }
     129             :     }
     130             : 
     131           0 :     bool bEnableGraphicToGallery = bLink;
     132           0 :     if ( bEnableGraphicToGallery )
     133             :     {
     134           0 :         if (GalleryExplorer::FillThemeList( aThemeList ))
     135             :         {
     136           0 :             PopupMenu *pMenu = GetPopupMenu(MN_READONLY_GRAPHICTOGALLERY);
     137           0 :             pMenu->CheckItem( MN_READONLY_TOGALLERYLINK,  bGrfToGalleryAsLnk );
     138           0 :             pMenu->CheckItem( MN_READONLY_TOGALLERYCOPY, !bGrfToGalleryAsLnk );
     139             : 
     140           0 :             for ( sal_uInt16 i=0; i < aThemeList.size(); ++i )
     141           0 :                 pMenu->InsertItem( MN_READONLY_GRAPHICTOGALLERY+i + 3, aThemeList[ i ] );
     142             :         }
     143             :         else
     144           0 :             bEnableGraphicToGallery = false;
     145             :     }
     146             : 
     147           0 :     EnableItem( MN_READONLY_GRAPHICTOGALLERY, bEnableGraphicToGallery );
     148             : 
     149           0 :     SfxViewFrame * pVFrame = rV.GetViewFrame();
     150           0 :     SfxDispatcher &rDis = *pVFrame->GetDispatcher();
     151           0 :     const SwPageDesc &rDesc = rSh.GetPageDesc( rSh.GetCurPageDesc() );
     152           0 :     pItem = &rDesc.GetMaster().GetBackground();
     153           0 :     sal_Bool bEnableBackGallery = sal_False,
     154           0 :          bEnableBack = sal_False;
     155             : 
     156           0 :     if ( GPOS_NONE != pItem->GetGraphicPos() )
     157             :     {
     158           0 :         bEnableBack = sal_True;
     159           0 :         if ( !pItem->GetGraphicLink().isEmpty() )
     160             :         {
     161           0 :             if ( aThemeList.empty() )
     162           0 :                 GalleryExplorer::FillThemeList( aThemeList );
     163             : 
     164           0 :             if ( !aThemeList.empty() )
     165             :             {
     166           0 :                 PopupMenu *pMenu = GetPopupMenu(MN_READONLY_BACKGROUNDTOGALLERY);
     167           0 :                 pMenu->CheckItem( MN_READONLY_TOGALLERYLINK,  bGrfToGalleryAsLnk );
     168           0 :                 pMenu->CheckItem( MN_READONLY_TOGALLERYCOPY, !bGrfToGalleryAsLnk );
     169           0 :                 bEnableBackGallery = sal_True;
     170             : 
     171           0 :                 for ( sal_uInt16 i=0; i < aThemeList.size(); ++i )
     172           0 :                     pMenu->InsertItem( MN_READONLY_GRAPHICTOGALLERY+i + 3, aThemeList[ i ] );
     173             :             }
     174             :         }
     175             :     }
     176           0 :     EnableItem( MN_READONLY_SAVEBACKGROUND, bEnableBack );
     177           0 :     EnableItem( MN_READONLY_BACKGROUNDTOGALLERY, bEnableBackGallery );
     178             : 
     179           0 :     if ( !rSh.GetViewOptions()->IsGraphic() )
     180           0 :         CheckItem( MN_READONLY_GRAPHICOFF );
     181             :     else
     182           0 :         EnableItem( MN_READONLY_LOADGRAPHIC, false );
     183             : 
     184           0 :     sal_Bool bReloadFrame = 0 != rSh.GetView().GetViewFrame()->GetFrame().GetParentFrame();
     185             :     EnableItem( MN_READONLY_RELOAD_FRAME,
     186           0 :             bReloadFrame );
     187           0 :     EnableItem( MN_READONLY_RELOAD, !bReloadFrame);
     188             : 
     189           0 :     Check( MN_READONLY_EDITDOC,         SID_EDITDOC,        rDis );
     190           0 :     Check( MN_READONLY_SELECTION_MODE,  FN_READONLY_SELECTION_MODE,    rDis );
     191           0 :     Check( MN_READONLY_SOURCEVIEW,      SID_SOURCEVIEW,     rDis );
     192           0 :     Check( MN_READONLY_BROWSE_BACKWARD, SID_BROWSE_BACKWARD,rDis );
     193           0 :     Check( MN_READONLY_BROWSE_FORWARD,  SID_BROWSE_FORWARD, rDis );
     194             : #ifdef WNT
     195             :     Check( MN_READONLY_PLUGINOFF,       SID_PLUGINS_ACTIVE, rDis );
     196             : #endif
     197           0 :     Check( MN_READONLY_OPENURL,         SID_OPENDOC,        rDis );
     198           0 :     Check( MN_READONLY_OPENURLNEW,      SID_OPENDOC,        rDis );
     199             : 
     200           0 :     SfxPoolItem* pState = NULL;
     201             : 
     202           0 :     SfxItemState eState = pVFrame->GetBindings().QueryState( SID_COPY, pState );
     203           0 :     Check( MN_READONLY_COPY,            SID_COPY,           rDis );
     204           0 :     if(eState < SFX_ITEM_AVAILABLE)
     205           0 :         EnableItem( MN_READONLY_COPY, false );
     206           0 :     delete pState;
     207           0 :     pState = NULL;
     208             : 
     209           0 :     eState = pVFrame->GetBindings().QueryState( SID_EDITDOC, pState );
     210           0 :     if (
     211           0 :         eState < SFX_ITEM_DEFAULT ||
     212           0 :         (rSh.IsGlobalDoc() && rView.GetDocShell()->IsReadOnlyUI())
     213             :        )
     214             :     {
     215           0 :         EnableItem( MN_READONLY_EDITDOC, false );
     216             :     }
     217           0 :     delete pState;
     218             : 
     219           0 :     if ( sURL.isEmpty() )
     220             :     {
     221           0 :         EnableItem( MN_READONLY_OPENURL, false );
     222           0 :         EnableItem( MN_READONLY_OPENURLNEW, false );
     223           0 :         EnableItem( MN_READONLY_COPYLINK, false );
     224             :     }
     225           0 :     Check( SID_WIN_FULLSCREEN,         SID_WIN_FULLSCREEN,        rDis );
     226             : 
     227           0 :     RemoveDisabledEntries( true, true );
     228           0 : }
     229             : 
     230           0 : void SwReadOnlyPopup::Execute( Window* pWin, const Point &rPixPos )
     231             : {
     232             :     sal_uInt16 nId     = PopupMenu::Execute(
     233             :     pWin,
     234           0 :     rPixPos );
     235           0 :     Execute(pWin, nId);
     236           0 : }
     237             : 
     238             : // execute the resulting ID only - necessary to support XContextMenuInterception
     239           0 : void SwReadOnlyPopup::Execute( Window* pWin, sal_uInt16 nId )
     240             : {
     241           0 :     SwWrtShell &rSh = rView.GetWrtShell();
     242           0 :     SfxDispatcher &rDis = *rView.GetViewFrame()->GetDispatcher();
     243           0 :     if ( nId >= MN_READONLY_GRAPHICTOGALLERY )
     244             :     {
     245           0 :         OUString sTmp;
     246             :         sal_uInt16 nSaveId;
     247           0 :         if ( nId >= MN_READONLY_BACKGROUNDTOGALLERY )
     248             :         {
     249           0 :             nId -= MN_READONLY_BACKGROUNDTOGALLERY+3;
     250           0 :             nSaveId = MN_READONLY_SAVEBACKGROUND;
     251           0 :             sTmp = pItem->GetGraphicLink();
     252             :         }
     253             :         else
     254             :         {
     255           0 :             nId -= MN_READONLY_GRAPHICTOGALLERY+3;
     256           0 :             nSaveId = MN_READONLY_SAVEGRAPHIC;
     257           0 :             sTmp = sGrfName;
     258             :         }
     259           0 :         if ( !bGrfToGalleryAsLnk )
     260           0 :             sTmp = SaveGraphic( nSaveId );
     261             : 
     262           0 :         if ( !sTmp.isEmpty() )
     263           0 :             GalleryExplorer::InsertURL( aThemeList[nId], sTmp );
     264             : 
     265           0 :         return;
     266             :     }
     267             : 
     268           0 :     TransferDataContainer* pClipCntnr = 0;
     269             : 
     270           0 :     sal_uInt16 nExecId = USHRT_MAX;
     271           0 :     sal_uInt16 nFilter = USHRT_MAX;
     272           0 :     switch( nId )
     273             :     {
     274           0 :         case SID_WIN_FULLSCREEN :           nExecId = SID_WIN_FULLSCREEN; break;
     275           0 :         case MN_READONLY_OPENURL:           nFilter = URLLOAD_NOFILTER;   break;
     276           0 :         case MN_READONLY_OPENURLNEW:        nFilter = URLLOAD_NEWVIEW;    break;
     277           0 :         case MN_READONLY_COPY:              nExecId = SID_COPY;           break;
     278             : 
     279           0 :         case MN_READONLY_EDITDOC:           nExecId = SID_EDITDOC;        break;
     280           0 :         case MN_READONLY_SELECTION_MODE:    nExecId = FN_READONLY_SELECTION_MODE; break;
     281             :         case MN_READONLY_RELOAD:
     282             :         case MN_READONLY_RELOAD_FRAME:
     283           0 :             rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(SID_RELOAD);
     284           0 :         break;
     285             : 
     286           0 :         case MN_READONLY_BROWSE_BACKWARD:   nExecId = SID_BROWSE_BACKWARD;break;
     287           0 :         case MN_READONLY_BROWSE_FORWARD:    nExecId = SID_BROWSE_FORWARD; break;
     288           0 :         case MN_READONLY_SOURCEVIEW:        nExecId = SID_SOURCEVIEW;     break;
     289             :         case MN_READONLY_SAVEGRAPHIC:
     290             :         case MN_READONLY_SAVEBACKGROUND:
     291             :             {
     292           0 :                 SaveGraphic( nId );
     293           0 :                 break;
     294             :             }
     295             :         case MN_READONLY_COPYLINK:
     296           0 :             pClipCntnr = new TransferDataContainer;
     297           0 :             pClipCntnr->CopyString( sURL );
     298           0 :             break;
     299             : 
     300             :         case MN_READONLY_COPYGRAPHIC:
     301           0 :             pClipCntnr = new TransferDataContainer;
     302           0 :             pClipCntnr->CopyGraphic( aGraphic );
     303             : 
     304           0 :             if( pImageMap )
     305           0 :                 pClipCntnr->CopyImageMap( *pImageMap );
     306           0 :             if( pTargetURL )
     307           0 :                 pClipCntnr->CopyINetImage( *pTargetURL );
     308           0 :             break;
     309             : 
     310             :         case MN_READONLY_LOADGRAPHIC:
     311             :             {
     312           0 :                 sal_Bool bModified = rSh.IsModified();
     313           0 :                 SwViewOption aOpt( *rSh.GetViewOptions() );
     314           0 :                 aOpt.SetGraphic( sal_True );
     315           0 :                 rSh.ApplyViewOptions( aOpt );
     316           0 :                 if(!bModified)
     317           0 :                     rSh.ResetModified();
     318           0 :                 break;
     319             :             }
     320           0 :         case MN_READONLY_GRAPHICOFF:        nExecId = FN_VIEW_GRAPHIC;    break;
     321             : #ifdef WNT
     322             :         case MN_READONLY_PLUGINOFF:         nExecId = SID_PLUGINS_ACTIVE; break;
     323             : #endif
     324             :         case MN_READONLY_TOGALLERYLINK:
     325           0 :             SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( sal_True );
     326           0 :             break;
     327             :         case MN_READONLY_TOGALLERYCOPY:
     328           0 :             SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( sal_False );
     329           0 :             break;
     330             : 
     331             :         default: //forward the id to the SfxBindings
     332           0 :             nExecId = nId;
     333             :     }
     334           0 :     if( USHRT_MAX != nExecId )
     335           0 :         rDis.GetBindings()->Execute( nExecId );
     336           0 :     if( USHRT_MAX != nFilter )
     337           0 :         ::LoadURL(rSh, sURL, nFilter, sTargetFrameName);
     338             : 
     339           0 :     if( pClipCntnr )
     340             :     {
     341           0 :         ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRef( pClipCntnr );
     342           0 :         if( pClipCntnr->HasAnyData() )
     343           0 :             pClipCntnr->CopyToClipboard( pWin );
     344             :     }
     345             : }
     346             : 
     347           0 : OUString SwReadOnlyPopup::SaveGraphic( sal_uInt16 nId )
     348             : {
     349             :     // fish out the graphic's name
     350           0 :     if ( MN_READONLY_SAVEBACKGROUND == nId )
     351             :     {
     352           0 :         if ( !pItem->GetGraphicLink().isEmpty() )
     353           0 :             sGrfName = pItem->GetGraphicLink();
     354           0 :         ((SvxBrushItem*)pItem)->SetDoneLink( Link() );
     355           0 :         const Graphic *pGrf = pItem->GetGraphic();
     356           0 :         if ( pGrf )
     357             :         {
     358           0 :             aGraphic = *pGrf;
     359           0 :             if ( !pItem->GetGraphicLink().isEmpty() )
     360           0 :                 sGrfName = pItem->GetGraphicLink();
     361             :         }
     362             :         else
     363           0 :             return OUString();
     364             :     }
     365           0 :     return GraphicHelper::ExportGraphic( aGraphic, sGrfName );
     366             : }
     367             : 
     368             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10