LibreOffice Module sw (master)  1
romenu.cxx
Go to the documentation of this file.
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 <memory>
21 #include <hintids.hxx>
22 
23 #include <svl/eitem.hxx>
24 #include <svl/stritem.hxx>
25 #include <vcl/imap.hxx>
26 #include <vcl/inetimg.hxx>
27 #include <vcl/transfer.hxx>
28 #include <sfx2/docfile.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <svx/gallery.hxx>
32 #include <svx/graphichelper.hxx>
33 #include <editeng/brushitem.hxx>
34 
35 #include <frmatr.hxx>
36 #include <fmturl.hxx>
37 #include <fmtinfmt.hxx>
38 #include <docsh.hxx>
39 #include <view.hxx>
40 #include <wrtsh.hxx>
41 #include <viewopt.hxx>
42 #include <swmodule.hxx>
43 #include "romenu.hxx"
44 #include <pagedesc.hxx>
45 #include <modcfg.hxx>
46 
47 #include <cmdid.h>
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 
55 {
57 }
58 
59 void SwReadOnlyPopup::Check( sal_uInt16 nMID, sal_uInt16 nSID, SfxDispatcher const &rDis )
60 {
61  std::unique_ptr<SfxPoolItem> _pItem;
62  SfxItemState eState = rDis.GetBindings()->QueryState( nSID, _pItem );
63  if (eState >= SfxItemState::DEFAULT)
64  {
65  m_xMenu->EnableItem(nMID);
66  if (_pItem)
67  {
68  m_xMenu->CheckItem(nMID, !_pItem->IsVoidItem() &&
69  dynamic_cast< const SfxBoolItem *>( _pItem.get() ) != nullptr &&
70  static_cast<SfxBoolItem*>(_pItem.get())->GetValue());
71  //remove full screen entry when not in full screen mode
72  if (SID_WIN_FULLSCREEN == nSID && !m_xMenu->IsItemChecked(m_nReadonlyFullscreen))
73  m_xMenu->EnableItem(nMID, false);
74  }
75  }
76  else
77  m_xMenu->EnableItem(nMID, false);
78 }
79 
80 #define MN_READONLY_GRAPHICTOGALLERY 1000
81 #define MN_READONLY_BACKGROUNDTOGALLERY 2000
82 
84  : m_aBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "modules/swriter/ui/readonlymenu.ui", "")
85  , m_xMenu(m_aBuilder.get_menu("menu"))
86  , m_nReadonlyOpenurl(m_xMenu->GetItemId("openurl"))
87  , m_nReadonlyOpendoc(m_xMenu->GetItemId("opendoc"))
88  , m_nReadonlyEditdoc(m_xMenu->GetItemId("edit"))
89  , m_nReadonlySelectionMode(m_xMenu->GetItemId("selection"))
90  , m_nReadonlyReload(m_xMenu->GetItemId("reload"))
91  , m_nReadonlyReloadFrame(m_xMenu->GetItemId("reloadframe"))
92  , m_nReadonlySourceview(m_xMenu->GetItemId("html"))
93  , m_nReadonlyBrowseBackward(m_xMenu->GetItemId("backward"))
94  , m_nReadonlyBrowseForward(m_xMenu->GetItemId("forward"))
95  , m_nReadonlySaveGraphic(m_xMenu->GetItemId("savegraphic"))
96  , m_nReadonlyGraphictogallery(m_xMenu->GetItemId("graphictogallery"))
97  , m_nReadonlyTogallerylink(m_xMenu->GetItemId("graphicaslink"))
98  , m_nReadonlyTogallerycopy(m_xMenu->GetItemId("graphicascopy"))
99  , m_nReadonlySaveBackground(m_xMenu->GetItemId("savebackground"))
100  , m_nReadonlyBackgroundtogallery(m_xMenu->GetItemId("backgroundtogallery"))
101  , m_nReadonlyBackgroundTogallerylink(m_xMenu->GetItemId("backaslink"))
102  , m_nReadonlyBackgroundTogallerycopy(m_xMenu->GetItemId("backascopy"))
103  , m_nReadonlyCopylink(m_xMenu->GetItemId("copylink"))
104  , m_nReadonlyLoadGraphic(m_xMenu->GetItemId("loadgraphic"))
105  , m_nReadonlyGraphicoff(m_xMenu->GetItemId("imagesoff"))
106  , m_nReadonlyFullscreen(m_xMenu->GetItemId("fullscreen"))
107  , m_nReadonlyCopy(m_xMenu->GetItemId("copy"))
108  , m_rView(rV)
109  , m_aBrushItem(std::make_shared<SvxBrushItem>(RES_BACKGROUND))
110 {
111  m_bGrfToGalleryAsLnk = SW_MOD()->GetModuleConfig()->IsGrfToGalleryAsLnk();
112  SwWrtShell &rSh = m_rView.GetWrtShell();
113  OUString sDescription;
114  rSh.IsURLGrfAtPos( rDPos, &m_sURL, &m_sTargetFrameName, &sDescription );
115  if ( m_sURL.isEmpty() )
116  {
117  SwContentAtPos aContentAtPos( IsAttrAtPos::InetAttr );
118  if( rSh.GetContentAtPos( rDPos, aContentAtPos))
119  {
120  const SwFormatINetFormat &rIItem = *static_cast<const SwFormatINetFormat*>(aContentAtPos.aFnd.pAttr);
121  m_sURL = rIItem.GetValue();
123  }
124  }
125 
126  bool bLink = false;
127  const Graphic *pGrf;
128  if ( nullptr == (pGrf = rSh.GetGrfAtPos( rDPos, m_sGrfName, bLink )) )
129  {
130  m_xMenu->EnableItem(m_nReadonlySaveGraphic, false);
131  }
132  else
133  {
134  m_aGraphic = *pGrf;
135  }
136 
137  bool bEnableGraphicToGallery = bLink;
138  if ( bEnableGraphicToGallery )
139  {
141  {
142  PopupMenu *pMenu = m_xMenu->GetPopupMenu(m_nReadonlyGraphictogallery);
145 
146  for ( size_t i=0; i < m_aThemeList.size(); ++i )
148  }
149  else
150  bEnableGraphicToGallery = false;
151  }
152 
153  m_xMenu->EnableItem(m_nReadonlyGraphictogallery, bEnableGraphicToGallery);
154 
155  SfxViewFrame * pVFrame = rV.GetViewFrame();
156  SfxDispatcher &rDis = *pVFrame->GetDispatcher();
157  const SwPageDesc &rDesc = rSh.GetPageDesc( rSh.GetCurPageDesc() );
159  bool bEnableBackGallery = false,
160  bEnableBack = false;
161 
162  if ( m_aBrushItem && GPOS_NONE != m_aBrushItem->GetGraphicPos() )
163  {
164  bEnableBack = true;
165  if ( !m_aBrushItem->GetGraphicLink().isEmpty() )
166  {
167  if ( m_aThemeList.empty() )
169 
170  if ( !m_aThemeList.empty() )
171  {
172  PopupMenu *pMenu = m_xMenu->GetPopupMenu(m_nReadonlyBackgroundtogallery);
175  bEnableBackGallery = true;
176 
177  for ( size_t i=0; i < m_aThemeList.size(); ++i )
179  }
180  }
181  }
182  m_xMenu->EnableItem(m_nReadonlySaveBackground, bEnableBack);
183  m_xMenu->EnableItem(m_nReadonlyBackgroundtogallery, bEnableBackGallery);
184 
185  if ( !rSh.GetViewOptions()->IsGraphic() )
186  m_xMenu->CheckItem(m_nReadonlyGraphicoff);
187  else
188  m_xMenu->EnableItem(m_nReadonlyLoadGraphic, false);
189 
190  m_xMenu->EnableItem(m_nReadonlyReloadFrame, false);
191  m_xMenu->EnableItem(m_nReadonlyReload);
192 
193  Check(m_nReadonlyEditdoc, SID_EDITDOC, rDis);
195  Check(m_nReadonlySourceview, SID_SOURCEVIEW, rDis);
196  Check(m_nReadonlyBrowseBackward, SID_BROWSE_BACKWARD, rDis);
197  Check(m_nReadonlyBrowseForward,SID_BROWSE_FORWARD, rDis);
198  Check(m_nReadonlyOpenurl, SID_OPENDOC, rDis);
199  Check(m_nReadonlyOpendoc, SID_OPENDOC, rDis);
200 
201  std::unique_ptr<SfxPoolItem> pState;
202 
203  SfxItemState eState = pVFrame->GetBindings().QueryState( SID_COPY, pState );
204  Check(m_nReadonlyCopy, SID_COPY, rDis);
205  if (eState < SfxItemState::DEFAULT)
206  m_xMenu->EnableItem(m_nReadonlyCopy, false);
207 
208  eState = pVFrame->GetBindings().QueryState( SID_EDITDOC, pState );
209  if (
210  eState < SfxItemState::DEFAULT ||
212  )
213  {
214  m_xMenu->EnableItem(m_nReadonlyEditdoc, false);
215  }
216 
217  if ( m_sURL.isEmpty() )
218  {
219  m_xMenu->EnableItem(m_nReadonlyOpenurl, false);
220  m_xMenu->EnableItem(m_nReadonlyOpendoc, false);
221  m_xMenu->EnableItem(m_nReadonlyCopylink, false);
222  }
223  Check(m_nReadonlyFullscreen, SID_WIN_FULLSCREEN, rDis);
224 
225  m_xMenu->RemoveDisabledEntries( true, true );
226 }
227 
228 void SwReadOnlyPopup::Execute( vcl::Window* pWin, const Point &rPixPos )
229 {
230  sal_uInt16 nId = m_xMenu->Execute(pWin, rPixPos);
231  Execute(pWin, nId);
232 }
233 
234 // execute the resulting ID only - necessary to support XContextMenuInterception
235 void SwReadOnlyPopup::Execute( vcl::Window* pWin, sal_uInt16 nId )
236 {
237  SwWrtShell &rSh = m_rView.GetWrtShell();
239  if (nId >= MN_READONLY_GRAPHICTOGALLERY)
240  {
241  OUString sTmp;
242  sal_uInt16 nSaveId;
244  {
246  nSaveId = m_nReadonlySaveBackground;
247  sTmp = m_aBrushItem->GetGraphicLink();
248  }
249  else
250  {
252  nSaveId = m_nReadonlySaveGraphic;
253  sTmp = m_sGrfName;
254  }
255  if ( !m_bGrfToGalleryAsLnk )
256  sTmp = SaveGraphic(nSaveId);
257 
258  if ( !sTmp.isEmpty() )
260 
261  return;
262  }
263 
265 
266  sal_uInt16 nExecId = USHRT_MAX;
267  bool bFilterSet = false;
269  if (nId == m_nReadonlyFullscreen)
270  nExecId = SID_WIN_FULLSCREEN;
271  else if (nId == m_nReadonlyOpenurl)
272  {
273  nFilter = LoadUrlFlags::NONE;
274  bFilterSet = true;
275  }
276  else if (nId == m_nReadonlyOpendoc)
277  {
278  nFilter = LoadUrlFlags::NewView;
279  bFilterSet = true;
280  }
281  else if (nId == m_nReadonlyCopy)
282  nExecId = SID_COPY;
283  else if (nId == m_nReadonlyEditdoc)
284  nExecId = SID_EDITDOC;
285  else if (nId == m_nReadonlySelectionMode)
286  nExecId = FN_READONLY_SELECTION_MODE;
287  else if (nId == m_nReadonlyReload || nId == m_nReadonlyReloadFrame)
288  rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(SID_RELOAD);
289  else if (nId == m_nReadonlyBrowseBackward)
290  nExecId = SID_BROWSE_BACKWARD;
291  else if (nId == m_nReadonlyBrowseForward)
292  nExecId = SID_BROWSE_FORWARD;
293  else if (nId == m_nReadonlySourceview)
294  nExecId = SID_SOURCEVIEW;
295  else if (nId == m_nReadonlySaveGraphic || nId == m_nReadonlySaveBackground)
296  SaveGraphic(nId);
297  else if (nId == m_nReadonlyCopylink)
298  {
299  pClipCntnr = new TransferDataContainer;
300  pClipCntnr->CopyString( m_sURL );
301  }
302  else if (nId == m_nReadonlyLoadGraphic)
303  {
304  bool bModified = rSh.IsModified();
305  SwViewOption aOpt( *rSh.GetViewOptions() );
306  aOpt.SetGraphic( true );
307  rSh.ApplyViewOptions( aOpt );
308  if(!bModified)
309  rSh.ResetModified();
310  }
311  else if (nId == m_nReadonlyGraphicoff)
312  nExecId = FN_VIEW_GRAPHIC;
314  SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk(true);
316  SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk(false);
317 
318  if( USHRT_MAX != nExecId )
319  rDis.GetBindings()->Execute( nExecId );
320  if( bFilterSet )
321  ::LoadURL(rSh, m_sURL, nFilter, m_sTargetFrameName);
322 
323  if( pClipCntnr && pClipCntnr->HasAnyData() )
324  {
325  pClipCntnr->CopyToClipboard( pWin );
326  }
327 }
328 
329 OUString SwReadOnlyPopup::SaveGraphic(sal_uInt16 nId)
330 {
331  // fish out the graphic's name
332  if (nId == m_nReadonlySaveBackground)
333  {
334  if ( m_aBrushItem && !m_aBrushItem->GetGraphicLink().isEmpty() )
335  m_sGrfName = m_aBrushItem->GetGraphicLink();
336  const Graphic *pGrf = m_aBrushItem ? m_aBrushItem->GetGraphic() : nullptr;
337  if ( pGrf )
338  {
339  m_aGraphic = *pGrf;
340  if ( !m_aBrushItem->GetGraphicLink().isEmpty() )
341  m_sGrfName = m_aBrushItem->GetGraphicLink();
342  }
343  else
344  return OUString();
345  }
347 }
348 
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define MN_READONLY_GRAPHICTOGALLERY
Definition: romenu.cxx:80
SfxViewFrame * GetViewFrame() const
#define FN_VIEW_GRAPHIC
Definition: cmdid.h:153
#define FN_READONLY_SELECTION_MODE
Definition: cmdid.h:704
const SwFrameFormat * IsURLGrfAtPos(const Point &rPt, OUString *pURL=nullptr, OUString *pTargetFrameName=nullptr, OUString *pURLDescription=nullptr) const
Position is a graphic with URL?
Definition: fefly1.cxx:1472
sal_uInt16 const m_nReadonlyCopylink
Definition: romenu.hxx:53
sal_uInt16 const m_nReadonlyBrowseForward
Definition: romenu.hxx:44
LoadUrlFlags
Definition: swurl.hxx:27
std::string GetValue
SwReadOnlyPopup(const Point &rDPos, SwView &rV)
Definition: romenu.cxx:83
bool IsGraphic() const
Definition: viewopt.hxx:294
const Graphic * GetGrfAtPos(const Point &rDocPos, OUString &rName, bool &rbLink) const
Deliver graphic in rName besides graphic name.
Definition: fefly1.cxx:1545
sal_uInt16 const m_nReadonlyOpendoc
Definition: romenu.hxx:37
GPOS_NONE
SfxDispatcher * GetDispatcher()
void disposeAndClear()
const SfxPoolItem * pAttr
Definition: crsrsh.hxx:100
bool IsModified() const
Changes in document?
Definition: edws.cxx:64
sal_Int16 nId
OUString m_sURL
Definition: romenu.hxx:62
#define MN_READONLY_BACKGROUNDTOGALLERY
Definition: romenu.cxx:81
sal_uInt16 const m_nReadonlyOpenurl
Definition: romenu.hxx:36
bool IsReadOnlyUI() const
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
void LoadURL(SwViewShell &rVSh, const OUString &rURL, LoadUrlFlags nFilter, const OUString &rTargetFrameName)
Definition: wrtsh2.cxx:491
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
const SwView & GetView() const
Definition: wrtsh.hxx:428
sal_uInt16 const m_nReadonlyBackgroundTogallerylink
Definition: romenu.hxx:51
sal_uInt16 const m_nReadonlyFullscreen
Definition: romenu.hxx:56
sal_uInt16 const m_nReadonlyEditdoc
Definition: romenu.hxx:38
sal_uInt16 const m_nReadonlySourceview
Definition: romenu.hxx:42
sal_uInt16 const m_nReadonlySelectionMode
Definition: romenu.hxx:39
bool Execute(sal_uInt16 nSlot, const SfxPoolItem **pArgs=nullptr, SfxCallMode nCall=SfxCallMode::SLOT)
sal_uInt16 const m_nReadonlyTogallerycopy
Definition: romenu.hxx:48
#define RES_BACKGROUND
Definition: hintids.hxx:212
OUString m_sGrfName
Definition: romenu.hxx:64
#define SW_MOD()
Definition: swmodule.hxx:256
SfxBindings * GetBindings() const
ScopedVclPtr< PopupMenu > m_xMenu
Definition: romenu.hxx:35
OUString SaveGraphic(sal_uInt16 nId)
Definition: romenu.cxx:329
sal_uInt16 const m_nReadonlyLoadGraphic
Definition: romenu.hxx:54
static bool InsertURL(const OUString &rThemeName, const OUString &rURL)
SfxBindings & GetBindings()
int i
const SwPageDesc & GetPageDesc(size_t i) const
Definition: fedesc.cxx:127
std::shared_ptr< SvxBrushItem > makeBackgroundBrushItem(bool=true) const
Definition: format.cxx:782
static bool FillThemeList(std::vector< OUString > &rThemeList)
std::shared_ptr< SvxBrushItem > m_aBrushItem
Definition: romenu.hxx:60
SfxItemState QueryState(sal_uInt16 nSID, std::unique_ptr< SfxPoolItem > &rpState)
void SetGraphic(bool b)
Definition: viewopt.hxx:296
Graphic m_aGraphic
Definition: romenu.hxx:61
SwDocShell * GetDocShell()
Definition: view.cxx:1127
void CheckItem(sal_uInt16 nItemId, bool bCheck=true)
SwFrameFormat & GetMaster()
Definition: pagedesc.hxx:217
void InsertItem(sal_uInt16 nItemId, const OUString &rStr, MenuItemBits nItemBits=MenuItemBits::NONE, const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
void Check(sal_uInt16 nMID, sal_uInt16 nSID, SfxDispatcher const &rDis)
Definition: romenu.cxx:59
static OUString ExportGraphic(weld::Window *pWin, const Graphic &rGraphic, const OUString &rGraphicName)
SfxItemState
weld::Window * GetFrameWeld() const
sal_uInt16 const m_nReadonlySaveBackground
Definition: romenu.hxx:49
const OUString & GetTargetFrame() const
Definition: fmtinfmt.hxx:89
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:426
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
void ResetModified()
Definition: edws.cxx:74
bool m_bGrfToGalleryAsLnk
Definition: romenu.hxx:66
std::vector< OUString > m_aThemeList
Definition: romenu.hxx:65
sal_uInt16 const m_nReadonlyGraphictogallery
Definition: romenu.hxx:46
sal_uInt16 const m_nReadonlyGraphicoff
Definition: romenu.hxx:55
sal_uInt16 const m_nReadonlyReloadFrame
Definition: romenu.hxx:41
sal_uInt16 const m_nReadonlySaveGraphic
Definition: romenu.hxx:45
sal_uInt16 const m_nReadonlyTogallerylink
Definition: romenu.hxx:47
sal_uInt16 const m_nReadonlyBrowseBackward
Definition: romenu.hxx:43
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
bool GetContentAtPos(const Point &rPt, SwContentAtPos &rContentAtPos, bool bSetCursor=false, SwRect *pFieldRect=nullptr)
Definition: crstrvl.cxx:1268
OUString m_sTargetFrameName
Definition: romenu.hxx:62
virtual void ApplyViewOptions(const SwViewOption &rOpt) override
Apply ViewOptions with Start-/EndAction.
Definition: wrtsh1.cxx:1801
sal_uInt16 const m_nReadonlyBackgroundtogallery
Definition: romenu.hxx:50
size_t GetCurPageDesc(const bool bCalcFrame=true) const
Definition: fedesc.cxx:168
SwView & m_rView
Definition: romenu.hxx:59
Definition: view.hxx:146
sal_uInt16 const m_nReadonlyBackgroundTogallerycopy
Definition: romenu.hxx:52
void Execute(vcl::Window *pWin, const Point &rPPos)
Definition: romenu.cxx:228
bool IsGlobalDoc() const
Interfaces for GlobalDocument.
Definition: edglbldc.cxx:35
sal_uInt16 const m_nReadonlyReload
Definition: romenu.hxx:40
union SwContentAtPos::@25 aFnd
sal_uInt16 const m_nReadonlyCopy
Definition: romenu.hxx:57