1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: romenu.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <hintids.hxx>
36 #include <tools/urlobj.hxx>
37 #include <vcl/graph.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <sot/formats.hxx>
40 #include <svtools/eitem.hxx>
41 #include <svtools/stritem.hxx>
42 #include <svtools/pathoptions.hxx>
43 #include <svtools/filter.hxx>
44 #include <svtools/imap.hxx>
45 #include <svtools/inetimg.hxx>
46 #include <svtools/transfer.hxx>
47 #include <sfx2/docfile.hxx>
48 #include <sfx2/dispatch.hxx>
49 #include <svx/xoutbmp.hxx>
50 #include <svx/impgrf.hxx>
51 #include <svx/gallery.hxx>
52 #include <svx/brshitem.hxx>
55 #include <swunodef.hxx>
58 #include <fmtinfmt.hxx>
62 #include <viewopt.hxx>
63 #include <swmodule.hxx>
65 #include <pagedesc.hxx>
72 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
73 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
74 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
75 #include <sfx2/filedlghelper.hxx>
77 using namespace ::com::sun::star::lang
;
78 using namespace ::com::sun::star::uno
;
79 using namespace ::com::sun::star
;
80 using namespace ::com::sun::star::ui::dialogs
;
81 using namespace ::sfx2
;
83 SwReadOnlyPopup::~SwReadOnlyPopup()
85 String
*pDel
= (String
*)aThemeList
.First();
89 pDel
= (String
*)aThemeList
.Next();
97 void SwReadOnlyPopup::Check( USHORT nMID
, USHORT nSID
, SfxDispatcher
&rDis
)
99 SfxPoolItem
*_pItem
= 0;
100 SfxItemState eState
= rDis
.GetBindings()->QueryState( nSID
, _pItem
);
101 if (eState
>= SFX_ITEM_AVAILABLE
)
103 EnableItem( nMID
, TRUE
);
106 CheckItem ( nMID
, !_pItem
->ISA(SfxVoidItem
) &&
107 _pItem
->ISA(SfxBoolItem
) &&
108 ((SfxBoolItem
*)_pItem
)->GetValue());
109 //remove full screen entry when not in full screen mode
110 if(SID_WIN_FULLSCREEN
== nSID
&& !IsItemChecked(SID_WIN_FULLSCREEN
) )
111 EnableItem(nMID
, FALSE
);
115 EnableItem( nMID
, FALSE
);
121 SwReadOnlyPopup::SwReadOnlyPopup( const Point
&rDPos
, SwView
&rV
) :
122 PopupMenu( SW_RES(MN_READONLY_POPUP
) ),
128 bGrfToGalleryAsLnk
= SW_MOD()->GetModuleConfig()->IsGrfToGalleryAsLnk();
129 SwWrtShell
&rSh
= rView
.GetWrtShell();
130 rSh
.IsURLGrfAtPos( rDocPos
, &sURL
, &sTargetFrameName
, &sDescription
);
133 SwContentAtPos
aCntntAtPos( SwContentAtPos::SW_INETATTR
);
134 if( rSh
.GetContentAtPos( rDocPos
, aCntntAtPos
, FALSE
))
136 SwFmtINetFmt
&rIItem
= *(SwFmtINetFmt
*)aCntntAtPos
.aFnd
.pAttr
;
137 sURL
= rIItem
.GetValue();
138 sTargetFrameName
= rIItem
.GetTargetFrame();
139 sDescription
= aCntntAtPos
.sStr
;
145 if ( 0 == (pGrf
= rSh
.GetGrfAtPos( rDocPos
, sGrfName
, bLink
)) )
147 EnableItem( MN_READONLY_SAVEGRAPHIC
, FALSE
);
148 EnableItem( MN_READONLY_COPYGRAPHIC
, FALSE
);
153 const SwFrmFmt
* pGrfFmt
= rSh
.GetFmtFromObj( rDocPos
);
154 const SfxPoolItem
* pURLItem
;
155 if( pGrfFmt
&& SFX_ITEM_SET
== pGrfFmt
->GetItemState(
156 RES_URL
, TRUE
, &pURLItem
))
158 const SwFmtURL
& rURL
= *(SwFmtURL
*)pURLItem
;
160 pImageMap
= new ImageMap( *rURL
.GetMap() );
161 else if( rURL
.GetURL().Len() )
162 pTargetURL
= new INetImage( bLink
? sGrfName
: aEmptyStr
,
164 rURL
.GetTargetFrameName(),
169 BOOL bEnableGraphicToGallery
;
170 if ( TRUE
== (bEnableGraphicToGallery
= bLink
) )
172 GalleryExplorer::FillThemeList( aThemeList
);
173 if ( aThemeList
.Count() )
175 PopupMenu
*pMenu
= GetPopupMenu(MN_READONLY_GRAPHICTOGALLERY
);
176 pMenu
->CheckItem( MN_READONLY_TOGALLERYLINK
, bGrfToGalleryAsLnk
);
177 pMenu
->CheckItem( MN_READONLY_TOGALLERYCOPY
, !bGrfToGalleryAsLnk
);
178 for ( USHORT i
=0; i
< aThemeList
.Count(); ++i
)
179 pMenu
->InsertItem( MN_READONLY_GRAPHICTOGALLERY
+i
+ 3,
180 *(String
*)aThemeList
.GetObject( i
) );
183 bEnableGraphicToGallery
= FALSE
;
185 EnableItem( MN_READONLY_GRAPHICTOGALLERY
, bEnableGraphicToGallery
);
187 SfxViewFrame
* pVFrame
= rV
.GetViewFrame();
188 SfxDispatcher
&rDis
= *pVFrame
->GetDispatcher();
189 const SwPageDesc
&rDesc
= rSh
.GetPageDesc( rSh
.GetCurPageDesc() );
190 pItem
= &rDesc
.GetMaster().GetBackground();
191 BOOL bEnableBackGallery
= FALSE
,
194 if ( GPOS_NONE
!= pItem
->GetGraphicPos() )
197 if ( pItem
->GetGraphicLink() )
199 if ( !aThemeList
.Count() )
200 GalleryExplorer::FillThemeList( aThemeList
);
201 if ( aThemeList
.Count() )
203 PopupMenu
*pMenu
= GetPopupMenu(MN_READONLY_BACKGROUNDTOGALLERY
);
204 pMenu
->CheckItem( MN_READONLY_TOGALLERYLINK
, bGrfToGalleryAsLnk
);
205 pMenu
->CheckItem( MN_READONLY_TOGALLERYCOPY
, !bGrfToGalleryAsLnk
);
206 bEnableBackGallery
= TRUE
;
207 for ( USHORT i
=0; i
< aThemeList
.Count(); ++i
)
208 pMenu
->InsertItem( MN_READONLY_BACKGROUNDTOGALLERY
+i
+ 3,
209 *(String
*)aThemeList
.GetObject( i
) );
213 EnableItem( MN_READONLY_SAVEBACKGROUND
, bEnableBack
);
214 EnableItem( MN_READONLY_BACKGROUNDTOGALLERY
, bEnableBackGallery
);
216 if ( !rSh
.GetViewOptions()->IsGraphic() )
217 CheckItem( MN_READONLY_GRAPHICOFF
);
219 EnableItem( MN_READONLY_LOADGRAPHIC
, FALSE
);
221 BOOL bReloadFrame
= 0 != rSh
.GetView().GetViewFrame()->GetFrame()->GetParentFrame();
222 EnableItem( MN_READONLY_RELOAD_FRAME
,
224 EnableItem( MN_READONLY_RELOAD
, !bReloadFrame
);
226 Check( MN_READONLY_EDITDOC
, SID_EDITDOC
, rDis
);
227 Check( MN_READONLY_SELECTION_MODE
, FN_READONLY_SELECTION_MODE
, rDis
);
228 Check( MN_READONLY_SOURCEVIEW
, SID_SOURCEVIEW
, rDis
);
229 Check( MN_READONLY_BROWSE_STOP
, SID_BROWSE_STOP
, rDis
);
230 Check( MN_READONLY_BROWSE_BACKWARD
, SID_BROWSE_BACKWARD
,rDis
);
231 Check( MN_READONLY_BROWSE_FORWARD
, SID_BROWSE_FORWARD
, rDis
);
233 Check( MN_READONLY_PLUGINOFF
, SID_PLUGINS_ACTIVE
, rDis
);
235 Check( MN_READONLY_OPENURL
, SID_OPENDOC
, rDis
);
236 Check( MN_READONLY_OPENURLNEW
, SID_OPENDOC
, rDis
);
240 SfxItemState eState
= pVFrame
->GetBindings().QueryState( SID_COPY
, pState
);
241 Check( MN_READONLY_COPY
, SID_COPY
, rDis
);
242 if(eState
< SFX_ITEM_AVAILABLE
)
243 EnableItem( MN_READONLY_COPY
, FALSE
);
245 eState
= pVFrame
->GetBindings().QueryState( SID_EDITDOC
, pState
);
246 if(eState
< SFX_ITEM_DEFAULT
||
247 rSh
.IsGlobalDoc() && rView
.GetDocShell()->IsReadOnlyUI())
248 EnableItem( MN_READONLY_EDITDOC
, FALSE
);
252 EnableItem( MN_READONLY_OPENURL
, FALSE
);
253 EnableItem( MN_READONLY_OPENURLNEW
, FALSE
);
254 EnableItem( MN_READONLY_COPYLINK
, FALSE
);
256 Check( SID_WIN_FULLSCREEN
, SID_WIN_FULLSCREEN
, rDis
);
258 RemoveDisabledEntries( TRUE
, TRUE
);
261 void SwReadOnlyPopup::Execute( Window
* pWin
, const Point
&rPixPos
)
263 USHORT nId
= PopupMenu::Execute(
269 /*-- 17.03.2004 13:06:18---------------------------------------------------
270 execute the resulting ID only - necessary to support XContextMenuInterception
271 -----------------------------------------------------------------------*/
272 void SwReadOnlyPopup::Execute( Window
* pWin
, USHORT nId
)
274 SwWrtShell
&rSh
= rView
.GetWrtShell();
275 SfxDispatcher
&rDis
= *rView
.GetViewFrame()->GetDispatcher();
276 if ( nId
>= MN_READONLY_GRAPHICTOGALLERY
)
280 if ( nId
>= MN_READONLY_BACKGROUNDTOGALLERY
)
282 nId
-= MN_READONLY_BACKGROUNDTOGALLERY
+3;
283 nSaveId
= MN_READONLY_SAVEBACKGROUND
;
284 sTmp
= *pItem
->GetGraphicLink();
288 nId
-= MN_READONLY_GRAPHICTOGALLERY
+3;
289 nSaveId
= MN_READONLY_SAVEGRAPHIC
;
292 if ( !bGrfToGalleryAsLnk
)
293 sTmp
= SaveGraphic( nSaveId
);
297 String
sThemeName( *(String
*)aThemeList
.GetObject( nId
));
298 GalleryExplorer::InsertURL( sThemeName
, sTmp
);
303 TransferDataContainer
* pClipCntnr
= 0;
305 USHORT nExecId
= USHRT_MAX
;
306 USHORT nFilter
= USHRT_MAX
;
309 case SID_WIN_FULLSCREEN
: nExecId
= SID_WIN_FULLSCREEN
; break;
310 case MN_READONLY_OPENURL
: nFilter
= URLLOAD_NOFILTER
; break;
311 case MN_READONLY_OPENURLNEW
: nFilter
= URLLOAD_NEWVIEW
; break;
312 case MN_READONLY_COPY
: nExecId
= SID_COPY
; break;
314 case MN_READONLY_EDITDOC
: nExecId
= SID_EDITDOC
; break;
315 case MN_READONLY_SELECTION_MODE
: nExecId
= FN_READONLY_SELECTION_MODE
; break;
316 case MN_READONLY_RELOAD
:
317 case MN_READONLY_RELOAD_FRAME
:
318 rSh
.GetView().GetViewFrame()->GetDispatcher()->Execute(SID_RELOAD
);
321 case MN_READONLY_BROWSE_STOP
: nExecId
= SID_BROWSE_STOP
; break;
322 case MN_READONLY_BROWSE_BACKWARD
: nExecId
= SID_BROWSE_BACKWARD
;break;
323 case MN_READONLY_BROWSE_FORWARD
: nExecId
= SID_BROWSE_FORWARD
; break;
324 case MN_READONLY_SOURCEVIEW
: nExecId
= SID_SOURCEVIEW
; break;
325 case MN_READONLY_SAVEGRAPHIC
:
326 case MN_READONLY_SAVEBACKGROUND
:
331 case MN_READONLY_COPYLINK
:
332 pClipCntnr
= new TransferDataContainer
;
333 pClipCntnr
->CopyString( sURL
);
336 case MN_READONLY_COPYGRAPHIC
:
337 pClipCntnr
= new TransferDataContainer
;
338 pClipCntnr
->CopyGraphic( aGraphic
);
341 pClipCntnr
->CopyImageMap( *pImageMap
);
343 pClipCntnr
->CopyINetImage( *pTargetURL
);
346 case MN_READONLY_LOADGRAPHIC
:
348 BOOL bModified
= rSh
.IsModified();
349 SwViewOption
aOpt( *rSh
.GetViewOptions() );
350 aOpt
.SetGraphic( TRUE
);
351 rSh
.ApplyViewOptions( aOpt
);
356 case MN_READONLY_GRAPHICOFF
: nExecId
= FN_VIEW_GRAPHIC
; break;
358 case MN_READONLY_PLUGINOFF
: nExecId
= SID_PLUGINS_ACTIVE
; break;
360 case MN_READONLY_TOGALLERYLINK
:
361 SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( TRUE
);
363 case MN_READONLY_TOGALLERYCOPY
:
364 SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( FALSE
);
367 default: //forward the id to the SfxBindings
370 if( USHRT_MAX
!= nExecId
)
371 rDis
.GetBindings()->Execute( nExecId
);
372 if( USHRT_MAX
!= nFilter
)
373 ::LoadURL( sURL
, &rSh
, nFilter
, &sTargetFrameName
);
377 STAR_REFERENCE( datatransfer::XTransferable
) xRef( pClipCntnr
);
378 if( pClipCntnr
->HasAnyData() )
379 pClipCntnr
->CopyToClipboard( pWin
);
382 static void lcl_GetPreferedExtension( String
&rExt
, const Graphic
&rGrf
)
384 // dann ggfs. ueber die native-Info der Grafik den "besten"
385 // Filter vorschlagen
386 const sal_Char
* pExt
= "png";
387 switch( const_cast<Graphic
&>(rGrf
).GetLink().GetType() )
389 case GFX_LINK_TYPE_NATIVE_GIF
: pExt
= "gif"; break;
390 case GFX_LINK_TYPE_NATIVE_TIF
: pExt
= "tif"; break;
391 case GFX_LINK_TYPE_NATIVE_WMF
: pExt
= "wmf"; break;
392 case GFX_LINK_TYPE_NATIVE_MET
: pExt
= "met"; break;
393 case GFX_LINK_TYPE_NATIVE_PCT
: pExt
= "pct"; break;
394 case GFX_LINK_TYPE_NATIVE_JPG
: pExt
= "jpg"; break;
395 default:; //prevent warning
397 rExt
.AssignAscii( pExt
);
401 String
SwReadOnlyPopup::SaveGraphic( USHORT nId
)
404 //Namen der Grafik herausfischen.
406 if ( MN_READONLY_SAVEBACKGROUND
== nId
)
408 if ( pItem
->GetGraphicLink() )
409 sGrfName
= *pItem
->GetGraphicLink();
410 ((SvxBrushItem
*)pItem
)->SetDoneLink( Link() );
411 const Graphic
*pGrf
= pItem
->GetGraphic( rView
.GetDocShell() );
415 if ( pItem
->GetGraphicLink() )
416 sGrfName
= *pItem
->GetGraphicLink();
421 return ExportGraphic( aGraphic
, sGrfName
);
424 String
ExportGraphic( const Graphic
&rGraphic
, const String
&rGrfName
)
426 SvtPathOptions aPathOpt
;
427 String
sGrfPath( aPathOpt
.GetGraphicPath() );
429 FileDialogHelper
aDlgHelper( TemplateDescription::FILESAVE_SIMPLE
, 0 );
430 Reference
< XFilePicker
> xFP
= aDlgHelper
.GetFilePicker();
432 // aExpDlg.SetHelpId(HID_FILEDLG_ROMENU);
434 aPath
.SetSmartURL( sGrfPath
);
436 //Namen der Grafik herausfischen.
437 String aName
= rGrfName
;
439 aDlgHelper
.SetTitle( SW_RESSTR(STR_EXPORT_GRAFIK_TITLE
));
440 aDlgHelper
.SetDisplayDirectory( aPath
.GetMainURL(INetURLObject::DECODE_TO_IURI
) );
442 aURL
.SetSmartURL( aName
);
443 aDlgHelper
.SetFileName( aURL
.GetName() );
445 GraphicFilter
& rGF
= *GetGrfFilter();
446 const USHORT nCount
= rGF
.GetExportFormatCount();
448 String
aExt( aURL
.GetExtension() );
450 lcl_GetPreferedExtension( aExt
, rGraphic
);
453 USHORT nDfltFilter
= USHRT_MAX
;
455 Reference
<XFilterManager
> xFltMgr(xFP
, UNO_QUERY
);
457 for ( USHORT i
= 0; i
< nCount
; i
++ )
459 xFltMgr
->appendFilter( rGF
.GetExportFormatName( i
), rGF
.GetExportWildcard( i
) );
460 if ( COMPARE_EQUAL
== aExt
.CompareIgnoreCaseToAscii(rGF
.GetExportFormatShortName( i
).ToLowerAscii() ))
463 if ( USHRT_MAX
== nDfltFilter
)
465 //"falsche" Extension?
466 lcl_GetPreferedExtension( aExt
, rGraphic
);
467 for ( USHORT i
= 0; i
< nCount
; ++i
)
468 if ( aExt
== rGF
.GetExportFormatShortName( i
).ToLowerAscii() )
475 if( USHRT_MAX
!= nDfltFilter
)
477 xFltMgr
->setCurrentFilter( rGF
.GetExportFormatName( nDfltFilter
) ) ;
479 if( aDlgHelper
.Execute() == ERRCODE_NONE
)
481 String
sPath( xFP
->getFiles().getConstArray()[0] );
482 //verwendeten Pfad merken - bitte nicht wieder wegoptimieren!
483 aPath
.SetSmartURL( sPath
);
484 sGrfPath
= aPath
.GetPath();
486 if( rGrfName
.Len() &&
487 nDfltFilter
== rGF
.GetExportFormatNumber( xFltMgr
->getCurrentFilter()))
489 //Versuchen die Originalgrafik zu speichern.
490 SfxMedium
aIn( rGrfName
, STREAM_READ
| STREAM_NOCREATE
,
492 if( aIn
.GetInStream() && !aIn
.GetInStream()->GetError() )
494 SfxMedium
aOut( sPath
, STREAM_WRITE
| STREAM_SHARE_DENYNONE
,
496 if( aOut
.GetOutStream() && !aOut
.GetOutStream()->GetError())
498 *aOut
.GetOutStream() << *aIn
.GetInStream();
499 if ( 0 == aIn
.GetError() )
503 if ( 0 == aOut
.GetError() )
511 if ( xFltMgr
->getCurrentFilter().getLength() && rGF
.GetExportFormatCount() )
512 nFilter
= rGF
.GetExportFormatNumber( xFltMgr
->getCurrentFilter() );
514 nFilter
= GRFILTER_FORMAT_DONTKNOW
;
515 String
aFilter( rGF
.GetExportFormatShortName( nFilter
) );
516 XOutBitmap::WriteGraphic( rGraphic
, sPath
, aFilter
,
517 XOUTBMP_DONT_EXPAND_FILENAME
);