LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/docvw - romenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 183 0.0 %
Date: 2012-12-17 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/brshitem.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, sal_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, sal_False);
      75             :         }
      76             :     }
      77             :     else
      78           0 :         EnableItem( nMID, sal_False );
      79             : 
      80           0 :     delete _pItem;
      81           0 : }
      82             : 
      83             : 
      84           0 : SwReadOnlyPopup::SwReadOnlyPopup( const Point &rDPos, SwView &rV ) :
      85             :     PopupMenu( SW_RES(MN_READONLY_POPUP) ),
      86             :     rView  ( rV ),
      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.Len() )
      95             :     {
      96           0 :         SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
      97           0 :         if( rSh.GetContentAtPos( rDocPos, aCntntAtPos, sal_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 :     sal_Bool bLink = sal_False;
     107             :     const Graphic *pGrf;
     108           0 :     if ( 0 == (pGrf = rSh.GetGrfAtPos( rDocPos, sGrfName, bLink )) )
     109             :     {
     110           0 :         EnableItem( MN_READONLY_SAVEGRAPHIC, sal_False );
     111           0 :         EnableItem( MN_READONLY_COPYGRAPHIC, sal_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 && SFX_ITEM_SET == pGrfFmt->GetItemState(
     119           0 :             RES_URL, sal_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().Len() )
     125             :                 pTargetURL = new INetImage( bLink ? sGrfName : aEmptyStr,
     126             :                                             rURL.GetURL(),
     127             :                                             rURL.GetTargetFrameName(),
     128           0 :                                             aEmptyStr, 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 :     pItem = &rDesc.GetMaster().GetBackground();
     154           0 :     sal_Bool bEnableBackGallery = sal_False,
     155           0 :          bEnableBack = sal_False;
     156             : 
     157           0 :     if ( GPOS_NONE != pItem->GetGraphicPos() )
     158             :     {
     159           0 :         bEnableBack = sal_True;
     160           0 :         if ( pItem->GetGraphicLink() )
     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 = sal_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, sal_False );
     184             : 
     185           0 :     sal_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             :     SfxPoolItem* pState;
     202             : 
     203           0 :     SfxItemState eState = pVFrame->GetBindings().QueryState( SID_COPY, pState );
     204           0 :     Check( MN_READONLY_COPY,            SID_COPY,           rDis );
     205           0 :     if(eState < SFX_ITEM_AVAILABLE)
     206           0 :         EnableItem( MN_READONLY_COPY, sal_False );
     207             : 
     208           0 :     eState = pVFrame->GetBindings().QueryState( SID_EDITDOC, pState );
     209           0 :     if (
     210             :         eState < SFX_ITEM_DEFAULT ||
     211           0 :         (rSh.IsGlobalDoc() && rView.GetDocShell()->IsReadOnlyUI())
     212             :        )
     213             :     {
     214           0 :         EnableItem( MN_READONLY_EDITDOC, sal_False );
     215             :     }
     216             : 
     217           0 :     if ( !sURL.Len() )
     218             :     {
     219           0 :         EnableItem( MN_READONLY_OPENURL, sal_False );
     220           0 :         EnableItem( MN_READONLY_OPENURLNEW, sal_False );
     221           0 :         EnableItem( MN_READONLY_COPYLINK, sal_False );
     222             :     }
     223           0 :     Check( SID_WIN_FULLSCREEN,         SID_WIN_FULLSCREEN,        rDis );
     224             : 
     225           0 :     RemoveDisabledEntries( sal_True, sal_True );
     226           0 : }
     227             : 
     228           0 : void SwReadOnlyPopup::Execute( Window* pWin, const Point &rPixPos )
     229             : {
     230             :     sal_uInt16 nId     = PopupMenu::Execute(
     231             :     pWin,
     232           0 :     rPixPos );
     233           0 :     Execute(pWin, nId);
     234           0 : }
     235             : 
     236             : /*-------------------------------------------------------------------------
     237             :     execute the resulting ID only - necessary to support XContextMenuInterception
     238             :   -----------------------------------------------------------------------*/
     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 :         String 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.Len() )
     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 : String 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() )
     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() )
     360           0 :                 sGrfName = *pItem->GetGraphicLink();
     361             :         }
     362             :         else
     363           0 :             return aEmptyStr;
     364             :     }
     365           0 :     return GraphicHelper::ExportGraphic( aGraphic, sGrfName );
     366             : }
     367             : 
     368             : 
     369             : 
     370             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10