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