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