xref: /trunk/main/sw/source/ui/shells/grfsh.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 
33 
34 #ifndef _CMDID_H
35 #include <cmdid.h>
36 #endif
37 #include <hintids.hxx>
38 #include <tools/urlobj.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <svl/stritem.hxx>
41 #include <svl/whiter.hxx>
42 #include <svl/urihelper.hxx>
43 #include <sfx2/docfile.hxx>
44 #include <sfx2/dispatch.hxx>
45 
46 #include <sfx2/objface.hxx>
47 #include <editeng/sizeitem.hxx>
48 #include <editeng/protitem.hxx>
49 #include <sfx2/request.hxx>
50 #include <svl/srchitem.hxx>
51 #include <svx/htmlmode.hxx>
52 #include <svx/sdgluitm.hxx>
53 #include <svx/sdgcoitm.hxx>
54 #include <svx/sdggaitm.hxx>
55 #include <svx/sdgtritm.hxx>
56 #include <svx/sdginitm.hxx>
57 #include <svx/sdgmoitm.hxx>
58 #include <editeng/brshitem.hxx>
59 #include <svx/grfflt.hxx>
60 #include <svx/tbxcolor.hxx>
61 #include <fmturl.hxx>
62 #include <view.hxx>
63 #include <wrtsh.hxx>
64 #include <viewopt.hxx>
65 #include <swmodule.hxx>
66 #include <frmatr.hxx>
67 #include <swundo.hxx>
68 #include <uitool.hxx>
69 #include <docsh.hxx>
70 #include <grfsh.hxx>
71 #include <frmmgr.hxx>
72 #include <frmdlg.hxx>
73 #include <frmfmt.hxx>
74 #include <grfatr.hxx>
75 #include <usrpref.hxx>
76 #include <edtwin.hxx>
77 #include <swwait.hxx>
78 #include <shells.hrc>
79 #include <popup.hrc>
80 
81 #define SwGrfShell
82 #include <sfx2/msg.hxx>
83 #include "swslots.hxx"
84 
85 #include "swabstdlg.hxx"
86 
87 #define TOOLBOX_NAME    ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "colorbar" ) )
88 
89 SFX_IMPL_INTERFACE(SwGrfShell, SwBaseShell, SW_RES(STR_SHELLNAME_GRAPHIC))
90 {
91 	SFX_POPUPMENU_REGISTRATION(SW_RES(MN_GRF_POPUPMENU));
92 	SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_GRAFIK_TOOLBOX));
93 }
94 
95 void SwGrfShell::Execute(SfxRequest &rReq)
96 {
97 	SwWrtShell &rSh = GetShell();
98 
99 	sal_uInt16 nSlot = rReq.GetSlot();
100 	switch(nSlot)
101 	{
102 		case SID_TWAIN_TRANSFER:
103 		{
104             GetView().ExecuteScan( rReq );
105 			break;
106 		}
107         case FN_SAVE_GRAPHIC:
108         {
109             const Graphic *pGraphic;
110             if(0 != (pGraphic = rSh.GetGraphic()))
111             {
112 			    String sGrfNm, sFilterNm;
113 			    rSh.GetGrfNms( &sGrfNm, &sFilterNm );
114                 ExportGraphic( *pGraphic, sGrfNm );
115             }
116         }
117         break;
118 		case SID_INSERT_GRAPHIC:
119 		case FN_FORMAT_GRAFIC_DLG:
120 		{
121 			SwFlyFrmAttrMgr aMgr( sal_False, &rSh, rSh.IsFrmSelected() ?
122 											   FRMMGR_TYPE_NONE : FRMMGR_TYPE_GRF);
123 			const SwViewOption* pVOpt = rSh.GetViewOptions();
124 			SwViewOption aUsrPref( *pVOpt );
125 
126 			SfxItemSet aSet(GetPool(), RES_FRMATR_BEGIN, RES_FRMATR_END-1,
127 							RES_GRFATR_MIRRORGRF, 	RES_GRFATR_CROPGRF,
128 							SID_ATTR_BORDER_INNER, 	SID_ATTR_BORDER_INNER,
129 							SID_ATTR_GRAF_KEEP_ZOOM, SID_ATTR_GRAF_KEEP_ZOOM,
130 							SID_ATTR_GRAF_FRMSIZE, SID_ATTR_GRAF_FRMSIZE,
131 							SID_ATTR_GRAF_FRMSIZE_PERCENT, SID_ATTR_GRAF_FRMSIZE_PERCENT,
132 							SID_ATTR_GRAF_GRAPHIC, SID_ATTR_GRAF_GRAPHIC,
133 							FN_PARAM_GRF_CONNECT, 	FN_PARAM_GRF_CONNECT,
134 							SID_ATTR_PAGE_SIZE, 	SID_ATTR_PAGE_SIZE,
135 							FN_GET_PRINT_AREA, 		FN_GET_PRINT_AREA,
136 							FN_SET_FRM_NAME, 		FN_KEEP_ASPECT_RATIO,
137 							FN_PARAM_GRF_DIALOG, 	FN_PARAM_GRF_DIALOG,
138 							SID_DOCFRAME, 			SID_DOCFRAME,
139 							SID_HTML_MODE, 			SID_HTML_MODE,
140 							FN_SET_FRM_ALT_NAME,	FN_SET_FRM_ALT_NAME,
141 							0);
142 
143 			sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
144 			aSet.Put(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
145 			FieldUnit eMetric = ::GetDfltMetric((0 != (nHtmlMode&HTMLMODE_ON)));
146             SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
147 
148 			const SwRect* pRect = &rSh.GetAnyCurRect(RECT_PAGE);
149 			SwFmtFrmSize aFrmSize( ATT_VAR_SIZE, pRect->Width(), pRect->Height());
150 			aFrmSize.SetWhich( GetPool().GetWhich( SID_ATTR_PAGE_SIZE ) );
151 			aSet.Put( aFrmSize );
152 
153 			aSet.Put(SfxStringItem(FN_SET_FRM_NAME, rSh.GetFlyName()));
154             if ( nSlot == FN_FORMAT_GRAFIC_DLG )
155             {
156                 // --> OD 2009-07-13 #i73249#
157 //                aSet.Put(SfxStringItem(FN_SET_FRM_ALT_NAME, rSh.GetAlternateText()));
158                 aSet.Put( SfxStringItem( FN_SET_FRM_ALT_NAME, rSh.GetObjTitle() ) );
159                 // <--
160             }
161 
162 			pRect = &rSh.GetAnyCurRect(RECT_PAGE_PRT);
163 			aFrmSize.SetWidth( pRect->Width() );
164 			aFrmSize.SetHeight( pRect->Height() );
165 			aFrmSize.SetWhich( GetPool().GetWhich(FN_GET_PRINT_AREA) );
166 			aSet.Put( aFrmSize );
167 
168 			aSet.Put( aMgr.GetAttrSet() );
169 			aSet.SetParent( aMgr.GetAttrSet().GetParent() );
170 
171 			// Bei %-Werten Groesse initialisieren
172 			SwFmtFrmSize aSizeCopy = (const SwFmtFrmSize&)aSet.Get(RES_FRM_SIZE);
173 			if (aSizeCopy.GetWidthPercent() && aSizeCopy.GetWidthPercent() != 0xff)
174 				aSizeCopy.SetWidth(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Width());
175 			if (aSizeCopy.GetHeightPercent() && aSizeCopy.GetHeightPercent() != 0xff)
176 				aSizeCopy.SetHeight(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Height());
177 
178 			// and now set the size for "external" tabpages
179 			{
180 				SvxSizeItem aSzItm( SID_ATTR_GRAF_FRMSIZE, aSizeCopy.GetSize() );
181 				aSet.Put( aSzItm );
182 
183 				Size aSz( aSizeCopy.GetWidthPercent(), aSizeCopy.GetHeightPercent() );
184 				if( 0xff == aSz.Width() ) 	aSz.Width() = 0;
185 				if( 0xff == aSz.Height() )  aSz.Height() = 0;
186 
187 				aSzItm.SetSize( aSz );
188 				aSzItm.SetWhich( SID_ATTR_GRAF_FRMSIZE_PERCENT );
189 				aSet.Put( aSzItm );
190 			}
191 
192 			String sGrfNm, sFilterNm;
193 			rSh.GetGrfNms( &sGrfNm, &sFilterNm );
194 			if( sGrfNm.Len() )
195 			{
196 				aSet.Put( SvxBrushItem( INetURLObject::decode( sGrfNm,
197 										INET_HEX_ESCAPE,
198 						   				INetURLObject::DECODE_UNAMBIGUOUS,
199 										RTL_TEXTENCODING_UTF8 ),
200 										sFilterNm, GPOS_LT,
201 										SID_ATTR_GRAF_GRAPHIC ));
202 			}
203 			else
204 			{
205                 // --> OD 2005-02-09 #119353# - robust
206                 const GraphicObject* pGrfObj = rSh.GetGraphicObj();
207                 if ( pGrfObj )
208                 {
209                     aSet.Put( SvxBrushItem( *pGrfObj, GPOS_LT,
210                                             SID_ATTR_GRAF_GRAPHIC ) );
211                 }
212                 // <--
213 			}
214             aSet.Put( SfxBoolItem( FN_PARAM_GRF_CONNECT, sGrfNm.Len() > 0 ) );
215 
216 			// get Mirror and Crop
217 			{
218 				SfxItemSet aTmpSet( rSh.GetAttrPool(),
219 								RES_GRFATR_MIRRORGRF, RES_GRFATR_CROPGRF );
220 
221                 rSh.GetCurAttr( aTmpSet );
222 				aSet.Put( aTmpSet );
223 			}
224 
225 			aSet.Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO, aUsrPref.IsKeepRatio()));
226 			aSet.Put(SfxBoolItem( SID_ATTR_GRAF_KEEP_ZOOM, aUsrPref.IsGrfKeepZoom()));
227 
228 			aSet.Put(SfxFrameItem( SID_DOCFRAME, &GetView().GetViewFrame()->GetTopFrame()));
229 
230 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
231             DBG_ASSERT(pFact, "Dialogdiet fail!");
232             SfxAbstractTabDialog* pDlg = pFact->CreateFrmTabDialog( DLG_FRM_GRF,
233 													GetView().GetViewFrame(),
234 													GetView().GetWindow(),
235 													aSet, sal_False, DLG_FRM_GRF);
236             DBG_ASSERT(pDlg, "Dialogdiet fail!");
237 			if( pDlg->Execute() )
238 			{
239 				rSh.StartAllAction();
240 				rSh.StartUndo(UNDO_START);
241 				const SfxPoolItem* pItem;
242 				SfxItemSet* pSet = (SfxItemSet*)pDlg->GetOutputItemSet();
243                 rReq.Done(*pSet);
244 				// change the 2 frmsize SizeItems to the correct SwFrmSizeItem
245 				if( SFX_ITEM_SET == pSet->GetItemState(
246 								SID_ATTR_GRAF_FRMSIZE, sal_False, &pItem ))
247 				{
248 					SwFmtFrmSize aSize;
249 					const Size& rSz = ((SvxSizeItem*)pItem)->GetSize();
250 					aSize.SetWidth( rSz.Width() );
251 					aSize.SetHeight( rSz.Height() );
252 
253 					if( SFX_ITEM_SET == pSet->GetItemState(
254 							SID_ATTR_GRAF_FRMSIZE_PERCENT, sal_False, &pItem ))
255 					{
256                         const Size& rRelativeSize = ((SvxSizeItem*)pItem)->GetSize();
257                         aSize.SetWidthPercent( static_cast< sal_uInt8 >( rRelativeSize.Width() ) );
258                         aSize.SetHeightPercent( static_cast< sal_uInt8 >( rRelativeSize.Height() ) );
259 					}
260 					pSet->Put( aSize );
261 				}
262 
263 				// Vorlagen-AutoUpdate
264 				SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
265 				if(pFmt && pFmt->IsAutoUpdateFmt())
266 				{
267                     pFmt->SetFmtAttr(*pSet);
268 					SfxItemSet aShellSet(GetPool(), RES_FRM_SIZE,	RES_FRM_SIZE,
269 													RES_SURROUND, 	RES_SURROUND,
270 													RES_ANCHOR,		RES_ANCHOR,
271 													RES_VERT_ORIENT,RES_HORI_ORIENT,
272 													0);
273 					aShellSet.Put(*pSet);
274 					aMgr.SetAttrSet(aShellSet);
275 				}
276 				else
277 				{
278 					aMgr.SetAttrSet(*pSet);
279 				}
280 				aMgr.UpdateFlyFrm();
281 
282 				sal_Bool bApplyUsrPref = sal_False;
283 				if (SFX_ITEM_SET == pSet->GetItemState(
284 					FN_KEEP_ASPECT_RATIO, sal_True, &pItem ))
285 				{
286 					aUsrPref.SetKeepRatio(
287 									((const SfxBoolItem*)pItem)->GetValue() );
288 					bApplyUsrPref = sal_True;
289 				}
290 				if( SFX_ITEM_SET == pSet->GetItemState(
291 					SID_ATTR_GRAF_KEEP_ZOOM, sal_True, &pItem ))
292 				{
293 					aUsrPref.SetGrfKeepZoom(
294 									((const SfxBoolItem*)pItem)->GetValue() );
295 					bApplyUsrPref = sal_True;
296 				}
297 
298 				if( bApplyUsrPref )
299 					SW_MOD()->ApplyUsrPref(aUsrPref, &GetView());
300 
301 				// and now set all the graphic attributes and other stuff
302 				if( SFX_ITEM_SET == pSet->GetItemState(
303 										SID_ATTR_GRAF_GRAPHIC, sal_True, &pItem ))
304 				{
305 					if( ((SvxBrushItem*)pItem)->GetGraphicLink() )
306 						sGrfNm = *((SvxBrushItem*)pItem)->GetGraphicLink();
307 					else
308 						sGrfNm.Erase();
309 
310 					if( ((SvxBrushItem*)pItem)->GetGraphicFilter() )
311 						sFilterNm = *((SvxBrushItem*)pItem)->GetGraphicFilter();
312 					else
313 						sFilterNm.Erase();
314 
315 					if( sGrfNm.Len() )
316 					{
317                         SwDocShell* pDocSh = GetView().GetDocShell();
318                         SwWait aWait( *pDocSh, sal_True );
319                         SfxMedium* pMedium = pDocSh->GetMedium();
320                         INetURLObject aAbs;
321                         if( pMedium )
322                             aAbs = pMedium->GetURLObject();
323                         rSh.ReRead( URIHelper::SmartRel2Abs(
324                                         aAbs, sGrfNm,
325                                         URIHelper::GetMaybeFileHdl() ),
326 								 	sFilterNm, 0 );
327 					}
328 				}
329                 if ( SFX_ITEM_SET == pSet->GetItemState(
330 										FN_SET_FRM_ALT_NAME, sal_True, &pItem ))
331                 {
332                     // --> OD 2009-07-13 #i73249#
333 //                    rSh.SetAlternateText(
334 //                                ((const SfxStringItem*)pItem)->GetValue() );
335                     rSh.SetObjTitle( ((const SfxStringItem*)pItem)->GetValue() );
336                     // <--
337                 }
338 
339 				SfxItemSet aGrfSet( rSh.GetAttrPool(), RES_GRFATR_BEGIN,
340 													   RES_GRFATR_END-1 );
341 				aGrfSet.Put( *pSet );
342 				if( aGrfSet.Count() )
343 					rSh.SetAttr( aGrfSet );
344 
345 				rSh.EndUndo(UNDO_END);
346 				rSh.EndAllAction();
347 			}
348 			delete pDlg;
349 		}
350 		break;
351 
352 		case FN_GRAPHIC_MIRROR_ON_EVEN_PAGES:
353 		{
354 			SfxItemSet aSet(rSh.GetAttrPool(), RES_GRFATR_MIRRORGRF, RES_GRFATR_MIRRORGRF);
355             rSh.GetCurAttr( aSet );
356 			SwMirrorGrf aGrf((const SwMirrorGrf &)aSet.Get(RES_GRFATR_MIRRORGRF));
357 			aGrf.SetGrfToggle(!aGrf.IsGrfToggle());
358 			rSh.SetAttr(aGrf);
359 		}
360 		break;
361 
362 		default:
363 			ASSERT(!this, falscher Dispatcher);
364 			return;
365 	}
366 }
367 
368 
369 void SwGrfShell::ExecAttr( SfxRequest &rReq )
370 {
371 	sal_uInt16 nGrfType;
372 	if( CNT_GRF == GetShell().GetCntType() &&
373 		( GRAPHIC_BITMAP == ( nGrfType = GetShell().GetGraphicType()) ||
374 		  GRAPHIC_GDIMETAFILE == nGrfType ))
375 	{
376 		SfxItemSet aGrfSet( GetShell().GetAttrPool(), RES_GRFATR_BEGIN,
377 													  RES_GRFATR_END -1 );
378     	const SfxItemSet *pArgs = rReq.GetArgs();
379     	const SfxPoolItem* pItem;
380     	sal_uInt16 nSlot = rReq.GetSlot();
381 	    if( !pArgs || SFX_ITEM_SET != pArgs->GetItemState( nSlot, sal_False, &pItem ))
382 			pItem = 0;
383 
384 		switch( nSlot )
385 		{
386 			case FN_FLIP_VERT_GRAFIC:
387 			case FN_FLIP_HORZ_GRAFIC:
388 			{
389                 GetShell().GetCurAttr( aGrfSet );
390 				SwMirrorGrf aMirror( (SwMirrorGrf&)aGrfSet.Get(
391 													RES_GRFATR_MIRRORGRF ) );
392 				sal_uInt16 nMirror = aMirror.GetValue();
393 				if( FN_FLIP_VERT_GRAFIC == nSlot )
394 					switch( nMirror )
395 					{
396                     case RES_MIRROR_GRAPH_DONT: nMirror = RES_MIRROR_GRAPH_VERT;
397 												break;
398                     case RES_MIRROR_GRAPH_HOR:  nMirror = RES_MIRROR_GRAPH_BOTH;
399 												break;
400                     case RES_MIRROR_GRAPH_VERT:   nMirror = RES_MIRROR_GRAPH_DONT;
401 												break;
402                     case RES_MIRROR_GRAPH_BOTH: nMirror = RES_MIRROR_GRAPH_HOR;
403 												break;
404 					}
405 				else
406 					switch( nMirror )
407 					{
408                     case RES_MIRROR_GRAPH_DONT: nMirror = RES_MIRROR_GRAPH_HOR;
409 												break;
410                     case RES_MIRROR_GRAPH_VERT: nMirror = RES_MIRROR_GRAPH_BOTH;
411 												break;
412                     case RES_MIRROR_GRAPH_HOR:    nMirror = RES_MIRROR_GRAPH_DONT;
413 												break;
414                     case RES_MIRROR_GRAPH_BOTH: nMirror = RES_MIRROR_GRAPH_VERT;
415 												break;
416 					}
417 				aMirror.SetValue( nMirror );
418 				aGrfSet.ClearItem();
419 				aGrfSet.Put( aMirror );
420 			}
421 			break;
422 
423 		case SID_ATTR_GRAF_LUMINANCE:
424 			if( pItem )
425 				aGrfSet.Put( SwLuminanceGrf(
426 							((SfxInt16Item*)pItem)->GetValue() ));
427 			break;
428 		case SID_ATTR_GRAF_CONTRAST:
429 			if( pItem )
430 				aGrfSet.Put( SwContrastGrf(
431 							((SfxInt16Item*)pItem)->GetValue() ));
432 			break;
433 		case SID_ATTR_GRAF_RED:
434 			if( pItem )
435 				aGrfSet.Put( SwChannelRGrf(
436 							((SfxInt16Item*)pItem)->GetValue() ));
437 			break;
438 		case SID_ATTR_GRAF_GREEN:
439 			if( pItem )
440 				aGrfSet.Put( SwChannelGGrf(
441 							((SfxInt16Item*)pItem)->GetValue() ));
442 			break;
443 		case SID_ATTR_GRAF_BLUE:
444 			if( pItem )
445 				aGrfSet.Put( SwChannelBGrf(
446 							((SfxInt16Item*)pItem)->GetValue() ));
447 			break;
448 		case SID_ATTR_GRAF_GAMMA:
449 			if( pItem )
450 			{
451 				double fVal = ((SfxUInt32Item*)pItem)->GetValue();
452 				aGrfSet.Put( SwGammaGrf(fVal/100. ));
453 			}
454 			break;
455 		case SID_ATTR_GRAF_TRANSPARENCE:
456 			if( pItem )
457                 aGrfSet.Put( SwTransparencyGrf(
458                     static_cast< sal_Int8 >( ( (SfxUInt16Item*)pItem )->GetValue() ) ) );
459 			break;
460 		case SID_ATTR_GRAF_INVERT:
461 			if( pItem )
462 				aGrfSet.Put( SwInvertGrf(
463 							((SfxBoolItem*)pItem)->GetValue() ));
464 			break;
465 
466 		case SID_ATTR_GRAF_MODE:
467 			if( pItem )
468 				aGrfSet.Put( SwDrawModeGrf(
469 							((SfxUInt16Item*)pItem)->GetValue() ));
470 			break;
471 
472         case SID_COLOR_SETTINGS:
473         {
474             svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
475             aToolboxAccess.toggleToolbox();
476             break;
477         }
478         case SID_GRFFILTER:
479         case SID_GRFFILTER_INVERT:
480 		case SID_GRFFILTER_SMOOTH:
481 		case SID_GRFFILTER_SHARPEN:
482 		case SID_GRFFILTER_REMOVENOISE:
483 		case SID_GRFFILTER_SOBEL:
484 		case SID_GRFFILTER_MOSAIC:
485 		case SID_GRFFILTER_EMBOSS:
486 		case SID_GRFFILTER_POSTER:
487 		case SID_GRFFILTER_POPART:
488 		case SID_GRFFILTER_SEPIA:
489 		case SID_GRFFILTER_SOLARIZE:
490 			if( GRAPHIC_BITMAP == nGrfType )
491 			{
492                 // --> OD 2005-02-09 #119353# - robust
493                 const GraphicObject* pFilterObj( GetShell().GetGraphicObj() );
494                 if ( pFilterObj )
495                 {
496                     GraphicObject aFilterObj( *pFilterObj );
497                     if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
498                         SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ))
499                         GetShell().ReRead( aEmptyStr, aEmptyStr,
500                                            &aFilterObj.GetGraphic() );
501                 }
502                 // <--
503 			}
504 			break;
505 
506 		default:
507 			ASSERT(!this, falscher Dispatcher);
508 		}
509 		if( aGrfSet.Count() )
510 			GetShell().SetAttr( aGrfSet );
511 	}
512 	GetView().GetViewFrame()->GetBindings().Invalidate(rReq.GetSlot());
513 }
514 
515 void SwGrfShell::GetAttrState(SfxItemSet &rSet)
516 {
517 	SwWrtShell &rSh = GetShell();
518 	SfxItemSet aCoreSet( GetPool(), aNoTxtNodeSetRange );
519     rSh.GetCurAttr( aCoreSet );
520 	sal_Bool bParentCntProt = 0 != rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT );
521 	sal_Bool bIsGrfCntnt = CNT_GRF == GetShell().GetCntType();
522 //    const GraphicObject* pGrfObj = ( bIsGrfCntnt ? rSh.GetGraphicObj() : NULL );
523 //    sal_Bool bIsRenderGraphicGrfCntnt = ( pGrfObj && pGrfObj->IsRenderGraphic() );
524 
525     // --> OD 2006-11-03 #i59688#
526 //    sal_Bool bSwappedOut = rSh.IsGrfSwapOut( sal_True );
527 //    sal_Bool bBitmapType = !bSwappedOut && GRAPHIC_BITMAP == rSh.GetGraphicType();
528     // <--
529 
530     SetGetStateSet( &rSet );
531 
532 	SfxWhichIter aIter( rSet );
533 	sal_uInt16 nWhich = aIter.FirstWhich();
534 	while( nWhich )
535 	{
536 		sal_Bool bDisable = bParentCntProt;
537 		switch( nWhich )
538 		{
539 		case SID_INSERT_GRAPHIC:
540         case FN_FORMAT_GRAFIC_DLG:
541 		case SID_TWAIN_TRANSFER:
542 			if( bParentCntProt || !bIsGrfCntnt )
543 				bDisable = sal_True;
544 			break;
545         case FN_SAVE_GRAPHIC:
546 			if( rSh.GetGraphicType() == GRAPHIC_NONE )
547 			    bDisable = sal_True;
548         break;
549         case SID_COLOR_SETTINGS:
550         {
551             if ( bParentCntProt || !bIsGrfCntnt )
552                 bDisable = sal_True;
553             else
554             {
555                 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
556                 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
557             }
558             break;
559         }
560 
561         case FN_FLIP_VERT_GRAFIC:
562 			if( !bParentCntProt )
563 			{
564                 MirrorGraph nState = static_cast< MirrorGraph >(((const SwMirrorGrf &) aCoreSet.Get(
565                                         RES_GRFATR_MIRRORGRF )).GetValue());
566 
567                 rSet.Put(SfxBoolItem( nWhich, nState == RES_MIRROR_GRAPH_VERT ||
568                                               nState == RES_MIRROR_GRAPH_BOTH));
569 			}
570 			break;
571 
572 		case FN_FLIP_HORZ_GRAFIC:
573 			if( !bParentCntProt )
574 			{
575                 MirrorGraph nState = static_cast< MirrorGraph >(((const SwMirrorGrf &) aCoreSet.Get(
576                                         RES_GRFATR_MIRRORGRF )).GetValue());
577 
578                 rSet.Put(SfxBoolItem( nWhich, nState == RES_MIRROR_GRAPH_HOR ||
579                                               nState == RES_MIRROR_GRAPH_BOTH));
580 			}
581 			break;
582 
583 
584 		case SID_ATTR_GRAF_LUMINANCE:
585 			if( !bParentCntProt )
586 				rSet.Put( SfxInt16Item( nWhich, ((SwLuminanceGrf&)
587 						aCoreSet.Get(RES_GRFATR_LUMINANCE)).GetValue() ));
588 			break;
589 		case SID_ATTR_GRAF_CONTRAST:
590 			if( !bParentCntProt )
591 				rSet.Put( SfxInt16Item( nWhich, ((SwContrastGrf&)
592 						aCoreSet.Get(RES_GRFATR_CONTRAST)).GetValue() ));
593 			break;
594 		case SID_ATTR_GRAF_RED:
595 			if( !bParentCntProt )
596 				rSet.Put( SfxInt16Item( nWhich, ((SwChannelRGrf&)
597 						aCoreSet.Get(RES_GRFATR_CHANNELR)).GetValue() ));
598 			break;
599 		case SID_ATTR_GRAF_GREEN:
600 			if( !bParentCntProt )
601 				rSet.Put( SfxInt16Item( nWhich, ((SwChannelGGrf&)
602 						aCoreSet.Get(RES_GRFATR_CHANNELG)).GetValue() ));
603 			break;
604 		case SID_ATTR_GRAF_BLUE:
605 			if( !bParentCntProt )
606 				rSet.Put( SfxInt16Item( nWhich, ((SwChannelBGrf&)
607 						aCoreSet.Get(RES_GRFATR_CHANNELB)).GetValue() ));
608 			break;
609 
610 		case SID_ATTR_GRAF_GAMMA:
611 			if( !bParentCntProt )
612                 rSet.Put( SfxUInt32Item( nWhich, static_cast< sal_uInt32 >(
613                     ( (SwGammaGrf&)aCoreSet.Get( RES_GRFATR_GAMMA ) ).GetValue() * 100 ) ) );
614 			break;
615 		case SID_ATTR_GRAF_TRANSPARENCE:
616 			if( !bParentCntProt )
617 			{
618                 // --> OD 2005-02-09 #119353# - robust
619                 const GraphicObject* pGrafObj = rSh.GetGraphicObj();
620                 if ( pGrafObj )
621                 {
622                     if( pGrafObj->IsAnimated() ||
623                         GRAPHIC_GDIMETAFILE == pGrafObj->GetType() )
624                         bDisable = sal_True;
625                     else
626                         rSet.Put( SfxUInt16Item( nWhich, ((SwTransparencyGrf&)
627                             aCoreSet.Get(RES_GRFATR_TRANSPARENCY)).GetValue() ));
628                 }
629 			}
630 			break;
631 		case SID_ATTR_GRAF_INVERT:
632 			if( !bParentCntProt )
633 				rSet.Put( SfxBoolItem( nWhich, ((SwInvertGrf&)
634 						aCoreSet.Get(RES_GRFATR_INVERT)).GetValue() ));
635 			break;
636 
637 		case SID_ATTR_GRAF_MODE:
638 			if( !bParentCntProt )
639                 rSet.Put( SfxUInt16Item( nWhich, ((SwDrawModeGrf&)
640 						aCoreSet.Get(RES_GRFATR_DRAWMODE)).GetValue() ));
641 			break;
642 
643 		case SID_GRFFILTER:
644 		case SID_GRFFILTER_INVERT:
645 		case SID_GRFFILTER_SMOOTH:
646 		case SID_GRFFILTER_SHARPEN:
647 		case SID_GRFFILTER_REMOVENOISE:
648 		case SID_GRFFILTER_SOBEL:
649 		case SID_GRFFILTER_MOSAIC:
650 		case SID_GRFFILTER_EMBOSS:
651 		case SID_GRFFILTER_POSTER:
652 		case SID_GRFFILTER_POPART:
653 		case SID_GRFFILTER_SEPIA:
654 		case SID_GRFFILTER_SOLARIZE:
655             {
656                 if( bParentCntProt || !bIsGrfCntnt )
657                     bDisable = sal_True;
658                 // --> OD 2006-11-03 #i59688#
659                 // load graphic only if type is unknown
660 //                else if( bSwappedOut )
661 //                {
662 //                    rSet.DisableItem( nWhich );
663 //                    if( AddGrfUpdateSlot( nWhich ))
664 //                        rSh.GetGraphic(sal_False);  // start the loading
665 //                }
666 //                else
667 //                    bDisable = !bBitmapType;
668                 else
669                 {
670                     const sal_uInt16 eGraphicType( rSh.GetGraphicType() );
671                     if ( ( eGraphicType == GRAPHIC_NONE ||
672                            eGraphicType == GRAPHIC_DEFAULT ) &&
673                          rSh.IsGrfSwapOut( sal_True ) )
674                     {
675                         rSet.DisableItem( nWhich );
676                         if( AddGrfUpdateSlot( nWhich ))
677                             rSh.GetGraphic(sal_False);  // start the loading
678                     }
679                     else
680                     {
681                         bDisable = eGraphicType != GRAPHIC_BITMAP;
682                     }
683                 }
684                 // <--
685             }
686 			break;
687 
688 		default:
689 			bDisable = sal_False;
690 		}
691 
692 		if( bDisable )
693 			rSet.DisableItem( nWhich );
694 		nWhich = aIter.NextWhich();
695 	}
696 	SetGetStateSet( 0 );
697 }
698 
699 
700 SwGrfShell::SwGrfShell(SwView &_rView) :
701     SwBaseShell(_rView)
702 
703 {
704 	SetName(String::CreateFromAscii("Graphic"));
705 	SetHelpId(SW_GRFSHELL);
706 }
707