Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <hintids.hxx>
30 : :
31 : : #include <svl/eitem.hxx>
32 : : #include <svl/stritem.hxx>
33 : : #include <svtools/imap.hxx>
34 : : #include <svtools/inetimg.hxx>
35 : : #include <svtools/transfer.hxx>
36 : : #include <sfx2/docfile.hxx>
37 : : #include <sfx2/dispatch.hxx>
38 : : #include <svx/gallery.hxx>
39 : : #include <svx/graphichelper.hxx>
40 : : #include <editeng/brshitem.hxx>
41 : :
42 : : #include <frmatr.hxx>
43 : : #include <fmturl.hxx>
44 : : #include <fmtinfmt.hxx>
45 : : #include <docsh.hxx>
46 : : #include <view.hxx>
47 : : #include <wrtsh.hxx>
48 : : #include <viewopt.hxx>
49 : : #include <swmodule.hxx>
50 : : #include <romenu.hxx>
51 : : #include <pagedesc.hxx>
52 : : #include <modcfg.hxx>
53 : :
54 : : #include <cmdid.h>
55 : : #include <helpid.h>
56 : : #include <docvw.hrc>
57 : :
58 : : using namespace ::com::sun::star::lang;
59 : : using namespace ::com::sun::star::uno;
60 : : using namespace ::com::sun::star;
61 : : using namespace ::sfx2;
62 : :
63 [ # # ][ # # ]: 0 : SwReadOnlyPopup::~SwReadOnlyPopup()
[ # # ][ # # ]
[ # # ]
64 : : {
65 [ # # ][ # # ]: 0 : delete pImageMap;
66 [ # # ][ # # ]: 0 : delete pTargetURL;
67 [ # # ]: 0 : }
68 : :
69 : 0 : void SwReadOnlyPopup::Check( sal_uInt16 nMID, sal_uInt16 nSID, SfxDispatcher &rDis )
70 : : {
71 : 0 : SfxPoolItem *_pItem = 0;
72 [ # # ][ # # ]: 0 : SfxItemState eState = rDis.GetBindings()->QueryState( nSID, _pItem );
73 [ # # ]: 0 : if (eState >= SFX_ITEM_AVAILABLE)
74 : : {
75 [ # # ]: 0 : EnableItem( nMID, sal_True );
76 [ # # ]: 0 : if (_pItem)
77 : : {
78 [ # # ][ # # ]: 0 : CheckItem ( nMID, !_pItem->ISA(SfxVoidItem) &&
79 [ # # ][ # # ]: 0 : _pItem->ISA(SfxBoolItem) &&
80 [ # # ][ # # ]: 0 : ((SfxBoolItem*)_pItem)->GetValue());
[ # # ][ # # ]
81 : : //remove full screen entry when not in full screen mode
82 [ # # ][ # # ]: 0 : if( SID_WIN_FULLSCREEN == nSID && !IsItemChecked(SID_WIN_FULLSCREEN) )
[ # # ][ # # ]
83 [ # # ]: 0 : EnableItem(nMID, sal_False);
84 : : }
85 : : }
86 : : else
87 [ # # ]: 0 : EnableItem( nMID, sal_False );
88 : :
89 [ # # ][ # # ]: 0 : delete _pItem;
90 : 0 : }
91 : :
92 : :
93 : 0 : SwReadOnlyPopup::SwReadOnlyPopup( const Point &rDPos, SwView &rV ) :
94 : : PopupMenu( SW_RES(MN_READONLY_POPUP) ),
95 : : rView ( rV ),
96 : : rDocPos( rDPos ),
97 : : pImageMap( 0 ),
98 [ # # ][ # # ]: 0 : pTargetURL( 0 )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
99 : : {
100 [ # # ]: 0 : bGrfToGalleryAsLnk = SW_MOD()->GetModuleConfig()->IsGrfToGalleryAsLnk();
101 : 0 : SwWrtShell &rSh = rView.GetWrtShell();
102 [ # # ]: 0 : rSh.IsURLGrfAtPos( rDocPos, &sURL, &sTargetFrameName, &sDescription );
103 [ # # ]: 0 : if ( !sURL.Len() )
104 : : {
105 [ # # ]: 0 : SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
106 [ # # ][ # # ]: 0 : if( rSh.GetContentAtPos( rDocPos, aCntntAtPos, sal_False))
107 : : {
108 : 0 : SwFmtINetFmt &rIItem = *(SwFmtINetFmt*)aCntntAtPos.aFnd.pAttr;
109 [ # # ]: 0 : sURL = rIItem.GetValue();
110 [ # # ]: 0 : sTargetFrameName = rIItem.GetTargetFrame();
111 [ # # ]: 0 : sDescription = aCntntAtPos.sStr;
112 [ # # ]: 0 : }
113 : : }
114 : :
115 : 0 : sal_Bool bLink = sal_False;
116 : : const Graphic *pGrf;
117 [ # # ][ # # ]: 0 : if ( 0 == (pGrf = rSh.GetGrfAtPos( rDocPos, sGrfName, bLink )) )
118 : : {
119 [ # # ]: 0 : EnableItem( MN_READONLY_SAVEGRAPHIC, sal_False );
120 [ # # ]: 0 : EnableItem( MN_READONLY_COPYGRAPHIC, sal_False );
121 : : }
122 : : else
123 : : {
124 [ # # ]: 0 : aGraphic = *pGrf;
125 [ # # ]: 0 : const SwFrmFmt* pGrfFmt = rSh.GetFmtFromObj( rDocPos );
126 : : const SfxPoolItem* pURLItem;
127 [ # # ][ # # ]: 0 : if( pGrfFmt && SFX_ITEM_SET == pGrfFmt->GetItemState(
[ # # ]
128 [ # # ]: 0 : RES_URL, sal_True, &pURLItem ))
129 : : {
130 : 0 : const SwFmtURL& rURL = *(SwFmtURL*)pURLItem;
131 [ # # ]: 0 : if( rURL.GetMap() )
132 [ # # ][ # # ]: 0 : pImageMap = new ImageMap( *rURL.GetMap() );
133 [ # # ]: 0 : else if( rURL.GetURL().Len() )
134 : : pTargetURL = new INetImage( bLink ? sGrfName : aEmptyStr,
135 : : rURL.GetURL(),
136 : : rURL.GetTargetFrameName(),
137 [ # # ][ # # ]: 0 : aEmptyStr, Size() );
[ # # ]
138 : : }
139 : : }
140 : :
141 : 0 : bool bEnableGraphicToGallery = bLink;
142 [ # # ]: 0 : if ( bEnableGraphicToGallery )
143 : : {
144 [ # # ][ # # ]: 0 : if (GalleryExplorer::FillThemeList( aThemeList ))
145 : : {
146 [ # # ]: 0 : PopupMenu *pMenu = GetPopupMenu(MN_READONLY_GRAPHICTOGALLERY);
147 [ # # ]: 0 : pMenu->CheckItem( MN_READONLY_TOGALLERYLINK, bGrfToGalleryAsLnk );
148 [ # # ]: 0 : pMenu->CheckItem( MN_READONLY_TOGALLERYCOPY, !bGrfToGalleryAsLnk );
149 : :
150 [ # # ]: 0 : for ( sal_uInt16 i=0; i < aThemeList.size(); ++i )
151 [ # # ][ # # ]: 0 : pMenu->InsertItem( MN_READONLY_GRAPHICTOGALLERY+i + 3, aThemeList[ i ] );
152 : : }
153 : : else
154 : 0 : bEnableGraphicToGallery = false;
155 : : }
156 : :
157 [ # # ]: 0 : EnableItem( MN_READONLY_GRAPHICTOGALLERY, bEnableGraphicToGallery );
158 : :
159 : 0 : SfxViewFrame * pVFrame = rV.GetViewFrame();
160 : 0 : SfxDispatcher &rDis = *pVFrame->GetDispatcher();
161 [ # # ][ # # ]: 0 : const SwPageDesc &rDesc = rSh.GetPageDesc( rSh.GetCurPageDesc() );
162 [ # # ]: 0 : pItem = &rDesc.GetMaster().GetBackground();
163 : 0 : sal_Bool bEnableBackGallery = sal_False,
164 : 0 : bEnableBack = sal_False;
165 : :
166 [ # # ]: 0 : if ( GPOS_NONE != pItem->GetGraphicPos() )
167 : : {
168 : 0 : bEnableBack = sal_True;
169 [ # # ]: 0 : if ( pItem->GetGraphicLink() )
170 : : {
171 [ # # ]: 0 : if ( aThemeList.empty() )
172 [ # # ]: 0 : GalleryExplorer::FillThemeList( aThemeList );
173 : :
174 [ # # ]: 0 : if ( !aThemeList.empty() )
175 : : {
176 [ # # ]: 0 : PopupMenu *pMenu = GetPopupMenu(MN_READONLY_BACKGROUNDTOGALLERY);
177 [ # # ]: 0 : pMenu->CheckItem( MN_READONLY_TOGALLERYLINK, bGrfToGalleryAsLnk );
178 [ # # ]: 0 : pMenu->CheckItem( MN_READONLY_TOGALLERYCOPY, !bGrfToGalleryAsLnk );
179 : 0 : bEnableBackGallery = sal_True;
180 : :
181 [ # # ]: 0 : for ( sal_uInt16 i=0; i < aThemeList.size(); ++i )
182 [ # # ][ # # ]: 0 : pMenu->InsertItem( MN_READONLY_GRAPHICTOGALLERY+i + 3, aThemeList[ i ] );
183 : : }
184 : : }
185 : : }
186 [ # # ]: 0 : EnableItem( MN_READONLY_SAVEBACKGROUND, bEnableBack );
187 [ # # ]: 0 : EnableItem( MN_READONLY_BACKGROUNDTOGALLERY, bEnableBackGallery );
188 : :
189 [ # # ]: 0 : if ( !rSh.GetViewOptions()->IsGraphic() )
190 [ # # ]: 0 : CheckItem( MN_READONLY_GRAPHICOFF );
191 : : else
192 [ # # ]: 0 : EnableItem( MN_READONLY_LOADGRAPHIC, sal_False );
193 : :
194 [ # # ]: 0 : sal_Bool bReloadFrame = 0 != rSh.GetView().GetViewFrame()->GetFrame().GetParentFrame();
195 : : EnableItem( MN_READONLY_RELOAD_FRAME,
196 [ # # ]: 0 : bReloadFrame );
197 [ # # ]: 0 : EnableItem( MN_READONLY_RELOAD, !bReloadFrame);
198 : :
199 [ # # ]: 0 : Check( MN_READONLY_EDITDOC, SID_EDITDOC, rDis );
200 [ # # ]: 0 : Check( MN_READONLY_SELECTION_MODE, FN_READONLY_SELECTION_MODE, rDis );
201 [ # # ]: 0 : Check( MN_READONLY_SOURCEVIEW, SID_SOURCEVIEW, rDis );
202 [ # # ]: 0 : Check( MN_READONLY_BROWSE_BACKWARD, SID_BROWSE_BACKWARD,rDis );
203 [ # # ]: 0 : Check( MN_READONLY_BROWSE_FORWARD, SID_BROWSE_FORWARD, rDis );
204 : : #ifdef WNT
205 : : Check( MN_READONLY_PLUGINOFF, SID_PLUGINS_ACTIVE, rDis );
206 : : #endif
207 [ # # ]: 0 : Check( MN_READONLY_OPENURL, SID_OPENDOC, rDis );
208 [ # # ]: 0 : Check( MN_READONLY_OPENURLNEW, SID_OPENDOC, rDis );
209 : :
210 : : SfxPoolItem* pState;
211 : :
212 [ # # ]: 0 : SfxItemState eState = pVFrame->GetBindings().QueryState( SID_COPY, pState );
213 [ # # ]: 0 : Check( MN_READONLY_COPY, SID_COPY, rDis );
214 [ # # ]: 0 : if(eState < SFX_ITEM_AVAILABLE)
215 [ # # ]: 0 : EnableItem( MN_READONLY_COPY, sal_False );
216 : :
217 [ # # ]: 0 : eState = pVFrame->GetBindings().QueryState( SID_EDITDOC, pState );
218 [ # # ][ # # ]: 0 : if (
[ # # ][ # # ]
219 : : eState < SFX_ITEM_DEFAULT ||
220 [ # # ][ # # ]: 0 : (rSh.IsGlobalDoc() && rView.GetDocShell()->IsReadOnlyUI())
[ # # ]
221 : : )
222 : : {
223 [ # # ]: 0 : EnableItem( MN_READONLY_EDITDOC, sal_False );
224 : : }
225 : :
226 [ # # ]: 0 : if ( !sURL.Len() )
227 : : {
228 [ # # ]: 0 : EnableItem( MN_READONLY_OPENURL, sal_False );
229 [ # # ]: 0 : EnableItem( MN_READONLY_OPENURLNEW, sal_False );
230 [ # # ]: 0 : EnableItem( MN_READONLY_COPYLINK, sal_False );
231 : : }
232 [ # # ]: 0 : Check( SID_WIN_FULLSCREEN, SID_WIN_FULLSCREEN, rDis );
233 : :
234 [ # # ]: 0 : RemoveDisabledEntries( sal_True, sal_True );
235 : 0 : }
236 : :
237 : 0 : void SwReadOnlyPopup::Execute( Window* pWin, const Point &rPixPos )
238 : : {
239 : : sal_uInt16 nId = PopupMenu::Execute(
240 : : pWin,
241 : 0 : rPixPos );
242 : 0 : Execute(pWin, nId);
243 : 0 : }
244 : :
245 : : /*-------------------------------------------------------------------------
246 : : execute the resulting ID only - necessary to support XContextMenuInterception
247 : : -----------------------------------------------------------------------*/
248 : 0 : void SwReadOnlyPopup::Execute( Window* pWin, sal_uInt16 nId )
249 : : {
250 : 0 : SwWrtShell &rSh = rView.GetWrtShell();
251 : 0 : SfxDispatcher &rDis = *rView.GetViewFrame()->GetDispatcher();
252 [ # # ]: 0 : if ( nId >= MN_READONLY_GRAPHICTOGALLERY )
253 : : {
254 [ # # ]: 0 : String sTmp;
255 : : sal_uInt16 nSaveId;
256 [ # # ]: 0 : if ( nId >= MN_READONLY_BACKGROUNDTOGALLERY )
257 : : {
258 : 0 : nId -= MN_READONLY_BACKGROUNDTOGALLERY+3;
259 : 0 : nSaveId = MN_READONLY_SAVEBACKGROUND;
260 [ # # ]: 0 : sTmp = *pItem->GetGraphicLink();
261 : : }
262 : : else
263 : : {
264 : 0 : nId -= MN_READONLY_GRAPHICTOGALLERY+3;
265 : 0 : nSaveId = MN_READONLY_SAVEGRAPHIC;
266 [ # # ]: 0 : sTmp = sGrfName;
267 : : }
268 [ # # ]: 0 : if ( !bGrfToGalleryAsLnk )
269 [ # # ][ # # ]: 0 : sTmp = SaveGraphic( nSaveId );
[ # # ]
270 : :
271 [ # # ]: 0 : if ( sTmp.Len() )
272 [ # # ][ # # ]: 0 : GalleryExplorer::InsertURL( aThemeList[nId], sTmp );
273 : :
274 [ # # ]: 0 : return;
275 : : }
276 : :
277 : 0 : TransferDataContainer* pClipCntnr = 0;
278 : :
279 : 0 : sal_uInt16 nExecId = USHRT_MAX;
280 : 0 : sal_uInt16 nFilter = USHRT_MAX;
281 [ # # # # : 0 : switch( nId )
# # # # #
# # # # #
# # # # ]
282 : : {
283 : 0 : case SID_WIN_FULLSCREEN : nExecId = SID_WIN_FULLSCREEN; break;
284 : 0 : case MN_READONLY_OPENURL: nFilter = URLLOAD_NOFILTER; break;
285 : 0 : case MN_READONLY_OPENURLNEW: nFilter = URLLOAD_NEWVIEW; break;
286 : 0 : case MN_READONLY_COPY: nExecId = SID_COPY; break;
287 : :
288 : 0 : case MN_READONLY_EDITDOC: nExecId = SID_EDITDOC; break;
289 : 0 : case MN_READONLY_SELECTION_MODE: nExecId = FN_READONLY_SELECTION_MODE; break;
290 : : case MN_READONLY_RELOAD:
291 : : case MN_READONLY_RELOAD_FRAME:
292 : 0 : rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(SID_RELOAD);
293 : 0 : break;
294 : :
295 : 0 : case MN_READONLY_BROWSE_BACKWARD: nExecId = SID_BROWSE_BACKWARD;break;
296 : 0 : case MN_READONLY_BROWSE_FORWARD: nExecId = SID_BROWSE_FORWARD; break;
297 : 0 : case MN_READONLY_SOURCEVIEW: nExecId = SID_SOURCEVIEW; break;
298 : : case MN_READONLY_SAVEGRAPHIC:
299 : : case MN_READONLY_SAVEBACKGROUND:
300 : : {
301 : 0 : SaveGraphic( nId );
302 : 0 : break;
303 : : }
304 : : case MN_READONLY_COPYLINK:
305 [ # # ]: 0 : pClipCntnr = new TransferDataContainer;
306 : 0 : pClipCntnr->CopyString( sURL );
307 : 0 : break;
308 : :
309 : : case MN_READONLY_COPYGRAPHIC:
310 [ # # ]: 0 : pClipCntnr = new TransferDataContainer;
311 : 0 : pClipCntnr->CopyGraphic( aGraphic );
312 : :
313 [ # # ]: 0 : if( pImageMap )
314 : 0 : pClipCntnr->CopyImageMap( *pImageMap );
315 [ # # ]: 0 : if( pTargetURL )
316 : 0 : pClipCntnr->CopyINetImage( *pTargetURL );
317 : 0 : break;
318 : :
319 : : case MN_READONLY_LOADGRAPHIC:
320 : : {
321 [ # # ]: 0 : sal_Bool bModified = rSh.IsModified();
322 [ # # ]: 0 : SwViewOption aOpt( *rSh.GetViewOptions() );
323 : 0 : aOpt.SetGraphic( sal_True );
324 [ # # ]: 0 : rSh.ApplyViewOptions( aOpt );
325 [ # # ]: 0 : if(!bModified)
326 [ # # ]: 0 : rSh.ResetModified();
327 [ # # ]: 0 : break;
328 : : }
329 : 0 : case MN_READONLY_GRAPHICOFF: nExecId = FN_VIEW_GRAPHIC; break;
330 : : #ifdef WNT
331 : : case MN_READONLY_PLUGINOFF: nExecId = SID_PLUGINS_ACTIVE; break;
332 : : #endif
333 : : case MN_READONLY_TOGALLERYLINK:
334 : 0 : SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( sal_True );
335 : 0 : break;
336 : : case MN_READONLY_TOGALLERYCOPY:
337 : 0 : SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( sal_False );
338 : 0 : break;
339 : :
340 : : default: //forward the id to the SfxBindings
341 : 0 : nExecId = nId;
342 : : }
343 [ # # ]: 0 : if( USHRT_MAX != nExecId )
344 : 0 : rDis.GetBindings()->Execute( nExecId );
345 [ # # ]: 0 : if( USHRT_MAX != nFilter )
346 [ # # ][ # # ]: 0 : ::LoadURL(rSh, sURL, nFilter, sTargetFrameName);
347 : :
348 [ # # ]: 0 : if( pClipCntnr )
349 : : {
350 [ # # ][ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRef( pClipCntnr );
351 [ # # ][ # # ]: 0 : if( pClipCntnr->HasAnyData() )
352 [ # # ]: 0 : pClipCntnr->CopyToClipboard( pWin );
353 : : }
354 : : }
355 : :
356 : 0 : String SwReadOnlyPopup::SaveGraphic( sal_uInt16 nId )
357 : : {
358 : :
359 : : // fish out the graphic's name
360 [ # # ]: 0 : String aName;
361 [ # # ]: 0 : if ( MN_READONLY_SAVEBACKGROUND == nId )
362 : : {
363 [ # # ]: 0 : if ( pItem->GetGraphicLink() )
364 [ # # ]: 0 : sGrfName = *pItem->GetGraphicLink();
365 [ # # ][ # # ]: 0 : ((SvxBrushItem*)pItem)->SetDoneLink( Link() );
366 [ # # ]: 0 : const Graphic *pGrf = pItem->GetGraphic();
367 [ # # ]: 0 : if ( pGrf )
368 : : {
369 [ # # ]: 0 : aGraphic = *pGrf;
370 [ # # ]: 0 : if ( pItem->GetGraphicLink() )
371 [ # # ]: 0 : sGrfName = *pItem->GetGraphicLink();
372 : : }
373 : : else
374 [ # # ]: 0 : return aEmptyStr;
375 : : }
376 [ # # ][ # # ]: 0 : return GraphicHelper::ExportGraphic( aGraphic, sGrfName );
377 : : }
378 : :
379 : :
380 : :
381 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|