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/brushitem.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 0 : 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 : // execute the resulting ID only - necessary to support XContextMenuInterception
237 0 : void SwReadOnlyPopup::Execute( Window* pWin, sal_uInt16 nId )
238 : {
239 0 : SwWrtShell &rSh = rView.GetWrtShell();
240 0 : SfxDispatcher &rDis = *rView.GetViewFrame()->GetDispatcher();
241 0 : if ( nId >= MN_READONLY_GRAPHICTOGALLERY )
242 : {
243 0 : String sTmp;
244 : sal_uInt16 nSaveId;
245 0 : if ( nId >= MN_READONLY_BACKGROUNDTOGALLERY )
246 : {
247 0 : nId -= MN_READONLY_BACKGROUNDTOGALLERY+3;
248 0 : nSaveId = MN_READONLY_SAVEBACKGROUND;
249 0 : sTmp = *pItem->GetGraphicLink();
250 : }
251 : else
252 : {
253 0 : nId -= MN_READONLY_GRAPHICTOGALLERY+3;
254 0 : nSaveId = MN_READONLY_SAVEGRAPHIC;
255 0 : sTmp = sGrfName;
256 : }
257 0 : if ( !bGrfToGalleryAsLnk )
258 0 : sTmp = SaveGraphic( nSaveId );
259 :
260 0 : if ( sTmp.Len() )
261 0 : GalleryExplorer::InsertURL( aThemeList[nId], sTmp );
262 :
263 0 : return;
264 : }
265 :
266 0 : TransferDataContainer* pClipCntnr = 0;
267 :
268 0 : sal_uInt16 nExecId = USHRT_MAX;
269 0 : sal_uInt16 nFilter = USHRT_MAX;
270 0 : switch( nId )
271 : {
272 0 : case SID_WIN_FULLSCREEN : nExecId = SID_WIN_FULLSCREEN; break;
273 0 : case MN_READONLY_OPENURL: nFilter = URLLOAD_NOFILTER; break;
274 0 : case MN_READONLY_OPENURLNEW: nFilter = URLLOAD_NEWVIEW; break;
275 0 : case MN_READONLY_COPY: nExecId = SID_COPY; break;
276 :
277 0 : case MN_READONLY_EDITDOC: nExecId = SID_EDITDOC; break;
278 0 : case MN_READONLY_SELECTION_MODE: nExecId = FN_READONLY_SELECTION_MODE; break;
279 : case MN_READONLY_RELOAD:
280 : case MN_READONLY_RELOAD_FRAME:
281 0 : rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(SID_RELOAD);
282 0 : break;
283 :
284 0 : case MN_READONLY_BROWSE_BACKWARD: nExecId = SID_BROWSE_BACKWARD;break;
285 0 : case MN_READONLY_BROWSE_FORWARD: nExecId = SID_BROWSE_FORWARD; break;
286 0 : case MN_READONLY_SOURCEVIEW: nExecId = SID_SOURCEVIEW; break;
287 : case MN_READONLY_SAVEGRAPHIC:
288 : case MN_READONLY_SAVEBACKGROUND:
289 : {
290 0 : SaveGraphic( nId );
291 0 : break;
292 : }
293 : case MN_READONLY_COPYLINK:
294 0 : pClipCntnr = new TransferDataContainer;
295 0 : pClipCntnr->CopyString( sURL );
296 0 : break;
297 :
298 : case MN_READONLY_COPYGRAPHIC:
299 0 : pClipCntnr = new TransferDataContainer;
300 0 : pClipCntnr->CopyGraphic( aGraphic );
301 :
302 0 : if( pImageMap )
303 0 : pClipCntnr->CopyImageMap( *pImageMap );
304 0 : if( pTargetURL )
305 0 : pClipCntnr->CopyINetImage( *pTargetURL );
306 0 : break;
307 :
308 : case MN_READONLY_LOADGRAPHIC:
309 : {
310 0 : sal_Bool bModified = rSh.IsModified();
311 0 : SwViewOption aOpt( *rSh.GetViewOptions() );
312 0 : aOpt.SetGraphic( sal_True );
313 0 : rSh.ApplyViewOptions( aOpt );
314 0 : if(!bModified)
315 0 : rSh.ResetModified();
316 0 : break;
317 : }
318 0 : case MN_READONLY_GRAPHICOFF: nExecId = FN_VIEW_GRAPHIC; break;
319 : #ifdef WNT
320 : case MN_READONLY_PLUGINOFF: nExecId = SID_PLUGINS_ACTIVE; break;
321 : #endif
322 : case MN_READONLY_TOGALLERYLINK:
323 0 : SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( sal_True );
324 0 : break;
325 : case MN_READONLY_TOGALLERYCOPY:
326 0 : SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( sal_False );
327 0 : break;
328 :
329 : default: //forward the id to the SfxBindings
330 0 : nExecId = nId;
331 : }
332 0 : if( USHRT_MAX != nExecId )
333 0 : rDis.GetBindings()->Execute( nExecId );
334 0 : if( USHRT_MAX != nFilter )
335 0 : ::LoadURL(rSh, sURL, nFilter, sTargetFrameName);
336 :
337 0 : if( pClipCntnr )
338 : {
339 0 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRef( pClipCntnr );
340 0 : if( pClipCntnr->HasAnyData() )
341 0 : pClipCntnr->CopyToClipboard( pWin );
342 : }
343 : }
344 :
345 0 : String SwReadOnlyPopup::SaveGraphic( sal_uInt16 nId )
346 : {
347 : // fish out the graphic's name
348 0 : if ( MN_READONLY_SAVEBACKGROUND == nId )
349 : {
350 0 : if ( pItem->GetGraphicLink() )
351 0 : sGrfName = *pItem->GetGraphicLink();
352 0 : ((SvxBrushItem*)pItem)->SetDoneLink( Link() );
353 0 : const Graphic *pGrf = pItem->GetGraphic();
354 0 : if ( pGrf )
355 : {
356 0 : aGraphic = *pGrf;
357 0 : if ( pItem->GetGraphicLink() )
358 0 : sGrfName = *pItem->GetGraphicLink();
359 : }
360 : else
361 0 : return aEmptyStr;
362 : }
363 0 : return GraphicHelper::ExportGraphic( aGraphic, sGrfName );
364 99 : }
365 :
366 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|