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