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