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