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