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