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