xref: /aoo41x/main/sw/source/ui/docvw/romenu.cxx (revision 270a30df)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir #include <hintids.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/urlobj.hxx>
30cdf0e10cSrcweir #include <vcl/graph.hxx>
31cdf0e10cSrcweir #include <vcl/msgbox.hxx>
32cdf0e10cSrcweir #include <sot/formats.hxx>
33cdf0e10cSrcweir #include <svl/eitem.hxx>
34cdf0e10cSrcweir #include <svl/stritem.hxx>
35cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
36cdf0e10cSrcweir #include <svtools/filter.hxx>
37cdf0e10cSrcweir #include <svtools/imap.hxx>
38cdf0e10cSrcweir #include <svtools/inetimg.hxx>
39cdf0e10cSrcweir #include <svtools/transfer.hxx>
40cdf0e10cSrcweir #include <sfx2/docfile.hxx>
41cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
42cdf0e10cSrcweir #include <svx/xoutbmp.hxx>
43cdf0e10cSrcweir #include <svx/gallery.hxx>
44cdf0e10cSrcweir #include <editeng/brshitem.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include <swunodef.hxx>
48cdf0e10cSrcweir #include <frmatr.hxx>
49cdf0e10cSrcweir #include <fmturl.hxx>
50cdf0e10cSrcweir #include <fmtinfmt.hxx>
51cdf0e10cSrcweir #include <docsh.hxx>
52cdf0e10cSrcweir #include <view.hxx>
53cdf0e10cSrcweir #include <wrtsh.hxx>
54cdf0e10cSrcweir #include <viewopt.hxx>
55cdf0e10cSrcweir #include <swmodule.hxx>
56cdf0e10cSrcweir #include <romenu.hxx>
57cdf0e10cSrcweir #include <pagedesc.hxx>
58cdf0e10cSrcweir #include <modcfg.hxx>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir #include <cmdid.h>
61cdf0e10cSrcweir #include <helpid.h>
62cdf0e10cSrcweir #include <docvw.hrc>
63cdf0e10cSrcweir #include <docvw.hrc>
64cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
65cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
66cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
67cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
68cdf0e10cSrcweir 
69cdf0e10cSrcweir using namespace ::com::sun::star::lang;
70cdf0e10cSrcweir using namespace ::com::sun::star::uno;
71cdf0e10cSrcweir using namespace ::com::sun::star;
72cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
73cdf0e10cSrcweir using namespace ::sfx2;
74cdf0e10cSrcweir 
~SwReadOnlyPopup()75cdf0e10cSrcweir SwReadOnlyPopup::~SwReadOnlyPopup()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	String *pDel = (String*)aThemeList.First();
78cdf0e10cSrcweir 	while ( pDel )
79cdf0e10cSrcweir 	{
80cdf0e10cSrcweir 		delete pDel;
81cdf0e10cSrcweir 		pDel = (String*)aThemeList.Next();
82cdf0e10cSrcweir 	}
83cdf0e10cSrcweir 	delete pImageMap;
84cdf0e10cSrcweir 	delete pTargetURL;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 
Check(sal_uInt16 nMID,sal_uInt16 nSID,SfxDispatcher & rDis)89cdf0e10cSrcweir void SwReadOnlyPopup::Check( sal_uInt16 nMID, sal_uInt16 nSID, SfxDispatcher &rDis )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     SfxPoolItem *_pItem = 0;
92cdf0e10cSrcweir     SfxItemState eState = rDis.GetBindings()->QueryState( nSID, _pItem );
93cdf0e10cSrcweir 	if (eState >= SFX_ITEM_AVAILABLE)
94cdf0e10cSrcweir 	{
95cdf0e10cSrcweir 		EnableItem( nMID, sal_True );
96cdf0e10cSrcweir         if (_pItem)
97cdf0e10cSrcweir 		{
98cdf0e10cSrcweir             CheckItem ( nMID, !_pItem->ISA(SfxVoidItem) &&
99cdf0e10cSrcweir                             _pItem->ISA(SfxBoolItem) &&
100cdf0e10cSrcweir                             ((SfxBoolItem*)_pItem)->GetValue());
101cdf0e10cSrcweir             //remove full screen entry when not in full screen mode
102cdf0e10cSrcweir             if(SID_WIN_FULLSCREEN == nSID && !IsItemChecked(SID_WIN_FULLSCREEN) )
103cdf0e10cSrcweir                 EnableItem(nMID, sal_False);
104cdf0e10cSrcweir 		}
105cdf0e10cSrcweir 	}
106cdf0e10cSrcweir 	else
107cdf0e10cSrcweir 		EnableItem( nMID, sal_False );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     delete _pItem;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
SwReadOnlyPopup(const Point & rDPos,SwView & rV)113cdf0e10cSrcweir SwReadOnlyPopup::SwReadOnlyPopup( const Point &rDPos, SwView &rV ) :
114cdf0e10cSrcweir 	PopupMenu( SW_RES(MN_READONLY_POPUP) ),
115cdf0e10cSrcweir     rView  ( rV ),
116cdf0e10cSrcweir 	rDocPos( rDPos ),
117cdf0e10cSrcweir 	pImageMap( 0 ),
118cdf0e10cSrcweir 	pTargetURL( 0 )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir 	bGrfToGalleryAsLnk = SW_MOD()->GetModuleConfig()->IsGrfToGalleryAsLnk();
121cdf0e10cSrcweir 	SwWrtShell &rSh = rView.GetWrtShell();
122cdf0e10cSrcweir 	rSh.IsURLGrfAtPos( rDocPos, &sURL, &sTargetFrameName, &sDescription );
123cdf0e10cSrcweir 	if ( !sURL.Len() )
124cdf0e10cSrcweir 	{
125cdf0e10cSrcweir 		SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
126cdf0e10cSrcweir 		if( rSh.GetContentAtPos( rDocPos, aCntntAtPos, sal_False))
127cdf0e10cSrcweir 		{
128cdf0e10cSrcweir 			SwFmtINetFmt &rIItem = *(SwFmtINetFmt*)aCntntAtPos.aFnd.pAttr;
129cdf0e10cSrcweir 			sURL = rIItem.GetValue();
130cdf0e10cSrcweir 			sTargetFrameName = rIItem.GetTargetFrame();
131cdf0e10cSrcweir 			sDescription = aCntntAtPos.sStr;
132cdf0e10cSrcweir 		}
133cdf0e10cSrcweir 	}
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	sal_Bool bLink = sal_False;
136cdf0e10cSrcweir 	const Graphic *pGrf;
137cdf0e10cSrcweir 	if ( 0 == (pGrf = rSh.GetGrfAtPos( rDocPos, sGrfName, bLink )) )
138cdf0e10cSrcweir 	{
139cdf0e10cSrcweir 		EnableItem( MN_READONLY_SAVEGRAPHIC, sal_False );
140cdf0e10cSrcweir 		EnableItem( MN_READONLY_COPYGRAPHIC, sal_False );
141cdf0e10cSrcweir 	}
142cdf0e10cSrcweir 	else
143cdf0e10cSrcweir 	{
144cdf0e10cSrcweir 		aGraphic = *pGrf;
145cdf0e10cSrcweir 		const SwFrmFmt* pGrfFmt = rSh.GetFmtFromObj( rDocPos );
146cdf0e10cSrcweir         const SfxPoolItem* pURLItem;
147cdf0e10cSrcweir 		if( pGrfFmt && SFX_ITEM_SET == pGrfFmt->GetItemState(
148cdf0e10cSrcweir             RES_URL, sal_True, &pURLItem ))
149cdf0e10cSrcweir 		{
150cdf0e10cSrcweir             const SwFmtURL& rURL = *(SwFmtURL*)pURLItem;
151cdf0e10cSrcweir 			if( rURL.GetMap() )
152cdf0e10cSrcweir 				pImageMap = new ImageMap( *rURL.GetMap() );
153cdf0e10cSrcweir 			else if( rURL.GetURL().Len() )
154cdf0e10cSrcweir 				pTargetURL = new INetImage( bLink ? sGrfName : aEmptyStr,
155cdf0e10cSrcweir 											rURL.GetURL(),
156cdf0e10cSrcweir 											rURL.GetTargetFrameName(),
157cdf0e10cSrcweir 											aEmptyStr, Size() );
158cdf0e10cSrcweir 		}
159cdf0e10cSrcweir 	}
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	sal_Bool bEnableGraphicToGallery;
162cdf0e10cSrcweir 	if ( sal_True == (bEnableGraphicToGallery = bLink) )
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		GalleryExplorer::FillThemeList( aThemeList );
165cdf0e10cSrcweir 		if ( aThemeList.Count() )
166cdf0e10cSrcweir 		{
167cdf0e10cSrcweir 			PopupMenu *pMenu = GetPopupMenu(MN_READONLY_GRAPHICTOGALLERY);
168cdf0e10cSrcweir 			pMenu->CheckItem( MN_READONLY_TOGALLERYLINK,  bGrfToGalleryAsLnk );
169cdf0e10cSrcweir 			pMenu->CheckItem( MN_READONLY_TOGALLERYCOPY, !bGrfToGalleryAsLnk );
170cdf0e10cSrcweir 			for ( sal_uInt16 i=0; i < aThemeList.Count(); ++i )
171cdf0e10cSrcweir 				pMenu->InsertItem( MN_READONLY_GRAPHICTOGALLERY+i + 3,
172cdf0e10cSrcweir 								   *(String*)aThemeList.GetObject( i ) );
173cdf0e10cSrcweir 		}
174cdf0e10cSrcweir 		else
175cdf0e10cSrcweir 			bEnableGraphicToGallery = sal_False;
176cdf0e10cSrcweir 	}
177cdf0e10cSrcweir 	EnableItem( MN_READONLY_GRAPHICTOGALLERY, bEnableGraphicToGallery );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 	SfxViewFrame * pVFrame = rV.GetViewFrame();
180cdf0e10cSrcweir 	SfxDispatcher &rDis = *pVFrame->GetDispatcher();
181cdf0e10cSrcweir     const SwPageDesc &rDesc = rSh.GetPageDesc( rSh.GetCurPageDesc() );
182cdf0e10cSrcweir 	pItem = &rDesc.GetMaster().GetBackground();
183cdf0e10cSrcweir 	sal_Bool bEnableBackGallery = sal_False,
184cdf0e10cSrcweir 		 bEnableBack = sal_False;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 	if ( GPOS_NONE != pItem->GetGraphicPos() )
187cdf0e10cSrcweir 	{
188cdf0e10cSrcweir 		bEnableBack = sal_True;
189cdf0e10cSrcweir 		if ( pItem->GetGraphicLink() )
190cdf0e10cSrcweir 		{
191cdf0e10cSrcweir 			if ( !aThemeList.Count() )
192cdf0e10cSrcweir 				GalleryExplorer::FillThemeList( aThemeList );
193cdf0e10cSrcweir 			if ( aThemeList.Count() )
194cdf0e10cSrcweir 			{
195cdf0e10cSrcweir 				PopupMenu *pMenu = GetPopupMenu(MN_READONLY_BACKGROUNDTOGALLERY);
196cdf0e10cSrcweir 				pMenu->CheckItem( MN_READONLY_TOGALLERYLINK,  bGrfToGalleryAsLnk );
197cdf0e10cSrcweir 				pMenu->CheckItem( MN_READONLY_TOGALLERYCOPY, !bGrfToGalleryAsLnk );
198cdf0e10cSrcweir 				bEnableBackGallery = sal_True;
199cdf0e10cSrcweir 				for ( sal_uInt16 i=0; i < aThemeList.Count(); ++i )
200cdf0e10cSrcweir 					pMenu->InsertItem( MN_READONLY_BACKGROUNDTOGALLERY+i + 3,
201cdf0e10cSrcweir 									   *(String*)aThemeList.GetObject( i ) );
202cdf0e10cSrcweir 			}
203cdf0e10cSrcweir 		}
204cdf0e10cSrcweir 	}
205cdf0e10cSrcweir 	EnableItem( MN_READONLY_SAVEBACKGROUND, bEnableBack );
206cdf0e10cSrcweir 	EnableItem( MN_READONLY_BACKGROUNDTOGALLERY, bEnableBackGallery );
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	if ( !rSh.GetViewOptions()->IsGraphic() )
209cdf0e10cSrcweir 		CheckItem( MN_READONLY_GRAPHICOFF );
210cdf0e10cSrcweir 	else
211cdf0e10cSrcweir 		EnableItem( MN_READONLY_LOADGRAPHIC, sal_False );
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 	sal_Bool bReloadFrame = 0 != rSh.GetView().GetViewFrame()->GetFrame().GetParentFrame();
214cdf0e10cSrcweir 	EnableItem( MN_READONLY_RELOAD_FRAME,
215cdf0e10cSrcweir 			bReloadFrame );
216cdf0e10cSrcweir 	EnableItem( MN_READONLY_RELOAD, !bReloadFrame);
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 	Check( MN_READONLY_EDITDOC, 		SID_EDITDOC, 		rDis );
219cdf0e10cSrcweir     Check( MN_READONLY_SELECTION_MODE,  FN_READONLY_SELECTION_MODE,    rDis );
220cdf0e10cSrcweir     Check( MN_READONLY_SOURCEVIEW,      SID_SOURCEVIEW,     rDis );
221cdf0e10cSrcweir 	Check( MN_READONLY_BROWSE_BACKWARD,	SID_BROWSE_BACKWARD,rDis );
222cdf0e10cSrcweir 	Check( MN_READONLY_BROWSE_FORWARD,	SID_BROWSE_FORWARD,	rDis );
223cdf0e10cSrcweir #ifdef WNT
224cdf0e10cSrcweir 	Check( MN_READONLY_PLUGINOFF,		SID_PLUGINS_ACTIVE,	rDis );
225cdf0e10cSrcweir #endif
226cdf0e10cSrcweir 	Check( MN_READONLY_OPENURL,			SID_OPENDOC,		rDis );
227cdf0e10cSrcweir 	Check( MN_READONLY_OPENURLNEW,		SID_OPENDOC,		rDis );
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	SfxPoolItem* pState;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     SfxItemState eState = pVFrame->GetBindings().QueryState( SID_COPY, pState );
232cdf0e10cSrcweir     Check( MN_READONLY_COPY,            SID_COPY,           rDis );
233cdf0e10cSrcweir     if(eState < SFX_ITEM_AVAILABLE)
234cdf0e10cSrcweir         EnableItem( MN_READONLY_COPY, sal_False );
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     eState = pVFrame->GetBindings().QueryState( SID_EDITDOC, pState );
237cdf0e10cSrcweir     if (
238cdf0e10cSrcweir         eState < SFX_ITEM_DEFAULT ||
239cdf0e10cSrcweir         (rSh.IsGlobalDoc() && rView.GetDocShell()->IsReadOnlyUI())
240cdf0e10cSrcweir        )
241cdf0e10cSrcweir     {
242cdf0e10cSrcweir         EnableItem( MN_READONLY_EDITDOC, sal_False );
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 	if ( !sURL.Len() )
246cdf0e10cSrcweir 	{
247cdf0e10cSrcweir 		EnableItem( MN_READONLY_OPENURL, sal_False );
248cdf0e10cSrcweir 		EnableItem( MN_READONLY_OPENURLNEW, sal_False );
249cdf0e10cSrcweir 		EnableItem( MN_READONLY_COPYLINK, sal_False );
250cdf0e10cSrcweir 	}
251cdf0e10cSrcweir     Check( SID_WIN_FULLSCREEN,         SID_WIN_FULLSCREEN,        rDis );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 	RemoveDisabledEntries( sal_True, sal_True );
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
Execute(Window * pWin,const Point & rPixPos)256cdf0e10cSrcweir void SwReadOnlyPopup::Execute( Window* pWin, const Point &rPixPos )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir     sal_uInt16 nId     = PopupMenu::Execute(
259cdf0e10cSrcweir 	pWin,
260cdf0e10cSrcweir 	rPixPos );
261cdf0e10cSrcweir     Execute(pWin, nId);
262cdf0e10cSrcweir }
263cdf0e10cSrcweir 
264cdf0e10cSrcweir /*-- 17.03.2004 13:06:18---------------------------------------------------
265cdf0e10cSrcweir     execute the resulting ID only - necessary to support XContextMenuInterception
266cdf0e10cSrcweir   -----------------------------------------------------------------------*/
Execute(Window * pWin,sal_uInt16 nId)267cdf0e10cSrcweir void SwReadOnlyPopup::Execute( Window* pWin, sal_uInt16 nId )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir     SwWrtShell &rSh = rView.GetWrtShell();
270cdf0e10cSrcweir     SfxDispatcher &rDis = *rView.GetViewFrame()->GetDispatcher();
271cdf0e10cSrcweir     if ( nId >= MN_READONLY_GRAPHICTOGALLERY )
272cdf0e10cSrcweir 	{
273cdf0e10cSrcweir 		String sTmp;
274cdf0e10cSrcweir 		sal_uInt16 nSaveId;
275cdf0e10cSrcweir         if ( nId >= MN_READONLY_BACKGROUNDTOGALLERY )
276cdf0e10cSrcweir 		{
277cdf0e10cSrcweir 			nId -= MN_READONLY_BACKGROUNDTOGALLERY+3;
278cdf0e10cSrcweir 			nSaveId = MN_READONLY_SAVEBACKGROUND;
279cdf0e10cSrcweir 			sTmp = *pItem->GetGraphicLink();
280cdf0e10cSrcweir 		}
281cdf0e10cSrcweir 		else
282cdf0e10cSrcweir 		{
283cdf0e10cSrcweir 			nId -= MN_READONLY_GRAPHICTOGALLERY+3;
284cdf0e10cSrcweir 			nSaveId = MN_READONLY_SAVEGRAPHIC;
285cdf0e10cSrcweir 			sTmp = sGrfName;
286cdf0e10cSrcweir 		}
287cdf0e10cSrcweir 		if ( !bGrfToGalleryAsLnk )
288cdf0e10cSrcweir 			sTmp = SaveGraphic( nSaveId );
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 		if ( sTmp.Len() )
291cdf0e10cSrcweir 		{
292cdf0e10cSrcweir 			String sThemeName( *(String*)aThemeList.GetObject( nId ));
293cdf0e10cSrcweir 			GalleryExplorer::InsertURL( sThemeName, sTmp );
294cdf0e10cSrcweir 		}
295cdf0e10cSrcweir 		return;
296cdf0e10cSrcweir 	}
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 	TransferDataContainer* pClipCntnr = 0;
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 	sal_uInt16 nExecId = USHRT_MAX;
301cdf0e10cSrcweir 	sal_uInt16 nFilter = USHRT_MAX;
302cdf0e10cSrcweir 	switch( nId )
303cdf0e10cSrcweir 	{
304cdf0e10cSrcweir         case SID_WIN_FULLSCREEN :           nExecId = SID_WIN_FULLSCREEN; break;
305cdf0e10cSrcweir         case MN_READONLY_OPENURL:           nFilter = URLLOAD_NOFILTER;   break;
306cdf0e10cSrcweir 		case MN_READONLY_OPENURLNEW:		nFilter = URLLOAD_NEWVIEW;	  break;
307cdf0e10cSrcweir         case MN_READONLY_COPY:              nExecId = SID_COPY;           break;
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 		case MN_READONLY_EDITDOC:			nExecId = SID_EDITDOC;		  break;
310cdf0e10cSrcweir         case MN_READONLY_SELECTION_MODE:    nExecId = FN_READONLY_SELECTION_MODE; break;
311cdf0e10cSrcweir 		case MN_READONLY_RELOAD:
312cdf0e10cSrcweir 		case MN_READONLY_RELOAD_FRAME:
313cdf0e10cSrcweir 			rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(SID_RELOAD);
314cdf0e10cSrcweir 		break;
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 		case MN_READONLY_BROWSE_BACKWARD:	nExecId = SID_BROWSE_BACKWARD;break;
317cdf0e10cSrcweir 		case MN_READONLY_BROWSE_FORWARD:	nExecId = SID_BROWSE_FORWARD; break;
318cdf0e10cSrcweir 		case MN_READONLY_SOURCEVIEW:		nExecId = SID_SOURCEVIEW;	  break;
319cdf0e10cSrcweir         case MN_READONLY_SAVEGRAPHIC:
320cdf0e10cSrcweir 		case MN_READONLY_SAVEBACKGROUND:
321cdf0e10cSrcweir 			{
322cdf0e10cSrcweir 				SaveGraphic( nId );
323cdf0e10cSrcweir 				break;
324cdf0e10cSrcweir 			}
325cdf0e10cSrcweir 		case MN_READONLY_COPYLINK:
326cdf0e10cSrcweir 			pClipCntnr = new TransferDataContainer;
327cdf0e10cSrcweir 			pClipCntnr->CopyString( sURL );
328cdf0e10cSrcweir 			break;
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 		case MN_READONLY_COPYGRAPHIC:
331cdf0e10cSrcweir 			pClipCntnr = new TransferDataContainer;
332cdf0e10cSrcweir 			pClipCntnr->CopyGraphic( aGraphic );
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 			if( pImageMap )
335cdf0e10cSrcweir 				pClipCntnr->CopyImageMap( *pImageMap );
336cdf0e10cSrcweir 			if( pTargetURL )
337cdf0e10cSrcweir 				pClipCntnr->CopyINetImage( *pTargetURL );
338cdf0e10cSrcweir 			break;
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 		case MN_READONLY_LOADGRAPHIC:
341cdf0e10cSrcweir 			{
342cdf0e10cSrcweir 				sal_Bool bModified = rSh.IsModified();
343cdf0e10cSrcweir 				SwViewOption aOpt( *rSh.GetViewOptions() );
344cdf0e10cSrcweir 				aOpt.SetGraphic( sal_True );
345cdf0e10cSrcweir 				rSh.ApplyViewOptions( aOpt );
346cdf0e10cSrcweir 				if(!bModified)
347cdf0e10cSrcweir 					rSh.ResetModified();
348cdf0e10cSrcweir 				break;
349cdf0e10cSrcweir 			}
350cdf0e10cSrcweir 		case MN_READONLY_GRAPHICOFF:		nExecId = FN_VIEW_GRAPHIC;	  break;
351cdf0e10cSrcweir #ifdef WNT
352cdf0e10cSrcweir 		case MN_READONLY_PLUGINOFF:			nExecId = SID_PLUGINS_ACTIVE; break;
353cdf0e10cSrcweir #endif
354cdf0e10cSrcweir 		case MN_READONLY_TOGALLERYLINK:
355cdf0e10cSrcweir 			SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( sal_True );
356cdf0e10cSrcweir 			break;
357cdf0e10cSrcweir 		case MN_READONLY_TOGALLERYCOPY:
358cdf0e10cSrcweir 			SW_MOD()->GetModuleConfig()->SetGrfToGalleryAsLnk( sal_False );
359cdf0e10cSrcweir 			break;
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 		default: //forward the id to the SfxBindings
362cdf0e10cSrcweir             nExecId = nId;
363cdf0e10cSrcweir 	}
364cdf0e10cSrcweir 	if( USHRT_MAX != nExecId )
365cdf0e10cSrcweir 		rDis.GetBindings()->Execute( nExecId );
366cdf0e10cSrcweir 	if( USHRT_MAX != nFilter )
367cdf0e10cSrcweir 		::LoadURL( sURL, &rSh, nFilter, &sTargetFrameName);
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 	if( pClipCntnr )
370cdf0e10cSrcweir 	{
371cdf0e10cSrcweir 		STAR_REFERENCE( datatransfer::XTransferable ) xRef( pClipCntnr );
372cdf0e10cSrcweir 		if( pClipCntnr->HasAnyData() )
373cdf0e10cSrcweir 			pClipCntnr->CopyToClipboard( pWin );
374cdf0e10cSrcweir 	}
375cdf0e10cSrcweir }
lcl_GetPreferedExtension(String & rExt,const Graphic & rGrf)376cdf0e10cSrcweir static void lcl_GetPreferedExtension( String &rExt, const Graphic &rGrf )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir 	// dann ggfs. ueber die native-Info der Grafik den "besten"
379cdf0e10cSrcweir 	// Filter vorschlagen
380cdf0e10cSrcweir 	const sal_Char* pExt = "png";
381cdf0e10cSrcweir 	switch( const_cast<Graphic&>(rGrf).GetLink().GetType() )
382cdf0e10cSrcweir 	{
383cdf0e10cSrcweir 		case GFX_LINK_TYPE_NATIVE_GIF:      pExt = "gif"; break;
384*270a30dfSArmin Le Grand 
385*270a30dfSArmin Le Grand         // #15508# added BMP type for better exports (writer export graphic - checked, works)
386*270a30dfSArmin Le Grand         case GFX_LINK_TYPE_NATIVE_BMP:      pExt = "bmp"; break;
387*270a30dfSArmin Le Grand 
388cdf0e10cSrcweir 		case GFX_LINK_TYPE_NATIVE_TIF:      pExt = "tif"; break;
389cdf0e10cSrcweir 		case GFX_LINK_TYPE_NATIVE_WMF:      pExt = "wmf"; break;
390cdf0e10cSrcweir 		case GFX_LINK_TYPE_NATIVE_MET:      pExt = "met"; break;
391cdf0e10cSrcweir 		case GFX_LINK_TYPE_NATIVE_PCT:		pExt = "pct"; break;
392cdf0e10cSrcweir 		case GFX_LINK_TYPE_NATIVE_JPG:		pExt = "jpg"; break;
393cdf0e10cSrcweir         default:; //prevent warning
394cdf0e10cSrcweir 	}
395cdf0e10cSrcweir 	rExt.AssignAscii( pExt );
396cdf0e10cSrcweir }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 
SaveGraphic(sal_uInt16 nId)399cdf0e10cSrcweir String SwReadOnlyPopup::SaveGraphic( sal_uInt16 nId )
400cdf0e10cSrcweir {
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 	//Namen der Grafik herausfischen.
403cdf0e10cSrcweir 	String aName;
404cdf0e10cSrcweir 	if ( MN_READONLY_SAVEBACKGROUND == nId )
405cdf0e10cSrcweir 	{
406cdf0e10cSrcweir 		if ( pItem->GetGraphicLink() )
407cdf0e10cSrcweir             sGrfName = *pItem->GetGraphicLink();
408cdf0e10cSrcweir 		((SvxBrushItem*)pItem)->SetDoneLink( Link() );
409cdf0e10cSrcweir 		const Graphic *pGrf = pItem->GetGraphic();
410cdf0e10cSrcweir 		if ( pGrf )
411cdf0e10cSrcweir 		{
412cdf0e10cSrcweir 			aGraphic = *pGrf;
413cdf0e10cSrcweir 			if ( pItem->GetGraphicLink() )
414cdf0e10cSrcweir 				sGrfName = *pItem->GetGraphicLink();
415cdf0e10cSrcweir 		}
416cdf0e10cSrcweir 		else
417cdf0e10cSrcweir 			return aEmptyStr;
418cdf0e10cSrcweir 	}
419cdf0e10cSrcweir     return ExportGraphic( aGraphic, sGrfName );
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
ExportGraphic(const Graphic & rGraphic,const String & rGrfName)422cdf0e10cSrcweir String ExportGraphic( const Graphic &rGraphic, const String &rGrfName )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir 	SvtPathOptions aPathOpt;
425cdf0e10cSrcweir 	String sGrfPath( aPathOpt.GetGraphicPath() );
426cdf0e10cSrcweir 
427cdf0e10cSrcweir     FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION, 0 );
428cdf0e10cSrcweir     Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
429cdf0e10cSrcweir 
430cdf0e10cSrcweir //    aExpDlg.SetHelpId(HID_FILEDLG_ROMENU);
431cdf0e10cSrcweir 	INetURLObject aPath;
432cdf0e10cSrcweir 	aPath.SetSmartURL( sGrfPath );
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 	//Namen der Grafik herausfischen.
435cdf0e10cSrcweir 	String aName = rGrfName;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 	aDlgHelper.SetTitle( SW_RESSTR(STR_EXPORT_GRAFIK_TITLE));
438cdf0e10cSrcweir 	aDlgHelper.SetDisplayDirectory( aPath.GetMainURL(INetURLObject::DECODE_TO_IURI) );
439cdf0e10cSrcweir     INetURLObject aURL;
440cdf0e10cSrcweir     aURL.SetSmartURL( aName );
441cdf0e10cSrcweir     aDlgHelper.SetFileName( aURL.GetName() );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 	GraphicFilter& rGF = *GraphicFilter::GetGraphicFilter();
444cdf0e10cSrcweir 	const sal_uInt16 nCount = rGF.GetExportFormatCount();
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 	String aExt( aURL.GetExtension() );
447cdf0e10cSrcweir 	if( !aExt.Len() )
448cdf0e10cSrcweir 		lcl_GetPreferedExtension( aExt, rGraphic );
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 	aExt.ToLowerAscii();
451cdf0e10cSrcweir     sal_uInt16 nDfltFilter = USHRT_MAX;
452cdf0e10cSrcweir 
453cdf0e10cSrcweir     Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     for ( sal_uInt16 i = 0; i < nCount; i++ )
456cdf0e10cSrcweir 	{
457cdf0e10cSrcweir         xFltMgr->appendFilter( rGF.GetExportFormatName( i ), rGF.GetExportWildcard( i ) );
458cdf0e10cSrcweir 		if ( COMPARE_EQUAL == aExt.CompareIgnoreCaseToAscii(rGF.GetExportFormatShortName( i ).ToLowerAscii() ))
459cdf0e10cSrcweir 			nDfltFilter = i;
460cdf0e10cSrcweir 	}
461cdf0e10cSrcweir     if ( USHRT_MAX == nDfltFilter )
462cdf0e10cSrcweir 	{
463cdf0e10cSrcweir 		//"falsche" Extension?
464cdf0e10cSrcweir 		lcl_GetPreferedExtension( aExt, rGraphic );
465cdf0e10cSrcweir         for ( sal_uInt16 i = 0; i < nCount; ++i )
466cdf0e10cSrcweir 			if ( aExt == rGF.GetExportFormatShortName( i ).ToLowerAscii() )
467cdf0e10cSrcweir 			{
468cdf0e10cSrcweir 				nDfltFilter =  i;
469cdf0e10cSrcweir 				break;
470cdf0e10cSrcweir 			}
471cdf0e10cSrcweir 	}
472cdf0e10cSrcweir 
473cdf0e10cSrcweir     if( USHRT_MAX != nDfltFilter )
474cdf0e10cSrcweir 	{
475cdf0e10cSrcweir         xFltMgr->setCurrentFilter( rGF.GetExportFormatName( nDfltFilter ) ) ;
476cdf0e10cSrcweir 
477cdf0e10cSrcweir         if( aDlgHelper.Execute() == ERRCODE_NONE )
478cdf0e10cSrcweir 		{
479cdf0e10cSrcweir             String sPath( xFP->getFiles().getConstArray()[0] );
480cdf0e10cSrcweir 			//verwendeten Pfad merken - bitte nicht wieder wegoptimieren!
481cdf0e10cSrcweir 			aPath.SetSmartURL( sPath);
482cdf0e10cSrcweir 			sGrfPath = aPath.GetPath();
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 			if( rGrfName.Len() &&
485cdf0e10cSrcweir                  nDfltFilter == rGF.GetExportFormatNumber( xFltMgr->getCurrentFilter()))
486cdf0e10cSrcweir 			{
487cdf0e10cSrcweir 				//Versuchen die Originalgrafik zu speichern.
488cdf0e10cSrcweir 				SfxMedium aIn( rGrfName, STREAM_READ | STREAM_NOCREATE,
489cdf0e10cSrcweir 								sal_True );
490cdf0e10cSrcweir 				if( aIn.GetInStream() && !aIn.GetInStream()->GetError() )
491cdf0e10cSrcweir 				{
492cdf0e10cSrcweir 					SfxMedium aOut( sPath, STREAM_WRITE | STREAM_SHARE_DENYNONE,
493cdf0e10cSrcweir 											sal_False);
494cdf0e10cSrcweir 					if( aOut.GetOutStream() && !aOut.GetOutStream()->GetError())
495cdf0e10cSrcweir 					{
496cdf0e10cSrcweir 						*aOut.GetOutStream() << *aIn.GetInStream();
497cdf0e10cSrcweir 						if ( 0 == aIn.GetError() )
498cdf0e10cSrcweir 						{
499cdf0e10cSrcweir 							aOut.Close();
500cdf0e10cSrcweir 							aOut.Commit();
501cdf0e10cSrcweir 							if ( 0 == aOut.GetError() )
502cdf0e10cSrcweir 								return sPath;
503cdf0e10cSrcweir 						}
504cdf0e10cSrcweir 					}
505cdf0e10cSrcweir 				}
506cdf0e10cSrcweir 			}
507cdf0e10cSrcweir 
508cdf0e10cSrcweir             sal_uInt16 nFilter;
509cdf0e10cSrcweir             if ( xFltMgr->getCurrentFilter().getLength() && rGF.GetExportFormatCount() )
510cdf0e10cSrcweir                 nFilter = rGF.GetExportFormatNumber( xFltMgr->getCurrentFilter() );
511cdf0e10cSrcweir 			else
512cdf0e10cSrcweir 				nFilter = GRFILTER_FORMAT_DONTKNOW;
513cdf0e10cSrcweir 			String aFilter( rGF.GetExportFormatShortName( nFilter ) );
514cdf0e10cSrcweir 			XOutBitmap::WriteGraphic( rGraphic, sPath, aFilter,
515cdf0e10cSrcweir                                         XOUTBMP_DONT_EXPAND_FILENAME|XOUTBMP_DONT_ADD_EXTENSION );
516cdf0e10cSrcweir 			return sPath;
517cdf0e10cSrcweir 		}
518cdf0e10cSrcweir 	}
519cdf0e10cSrcweir 	return aEmptyStr;
520cdf0e10cSrcweir }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 
523cdf0e10cSrcweir 
524