xref: /aoo41x/main/svx/source/tbxctrls/grafctrl.cxx (revision ddde725d)
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_svx.hxx"
26 
27 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
28 
29 #ifndef _TOOLBOX_HXX //autogen
30 #include <vcl/toolbox.hxx>
31 #endif
32 #ifndef _FIELD_HXX //autogen
33 #include <vcl/field.hxx>
34 #endif
35 #include <vcl/fixed.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <svl/intitem.hxx>
38 #include <svl/eitem.hxx>
39 #include <svl/whiter.hxx>
40 #include <sfx2/app.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/objsh.hxx>
43 #include <sfx2/viewsh.hxx>
44 #include <sfx2/request.hxx>
45 #include <sfx2/basedlgs.hxx>
46 #include <tools/urlobj.hxx>
47 #include <comphelper/processfactory.hxx>
48 
49 #include <svx/svxids.hrc>
50 #include "grafctrl.hrc"
51 #include <svx/dialogs.hrc>
52 #include <editeng/brshitem.hxx>
53 #include <editeng/sizeitem.hxx>
54 #include <svx/sdgcpitm.hxx>
55 //CHINA001 #include "../dialog/grfpage.hxx"
56 #include <svx/itemwin.hxx>
57 #include <svx/dialmgr.hxx>
58 #include <svx/svdview.hxx>
59 #include <svx/svdmodel.hxx>
60 #include <svx/svdograf.hxx>
61 #include <svx/svdundo.hxx>
62 #include <svx/svdtrans.hxx>
63 #include "svx/grafctrl.hxx"
64 #include "svx/tbxcolor.hxx"
65 
66 // namespaces
67 using ::rtl::OUString;
68 using namespace ::com::sun::star::uno;
69 using namespace ::com::sun::star::frame;
70 using namespace ::com::sun::star::util;
71 using namespace ::com::sun::star::beans;
72 using namespace ::com::sun::star::lang;
73 
74 #include <svx/svxdlg.hxx> //CHINA001
75 // -----------
76 // - Defines -
77 // -----------
78 
79 #define SYMBOL_TO_FIELD_OFFSET		4
80 #define ITEMVALUE(ItemSet,Id,Cast)	((const Cast&)(ItemSet).Get(Id)).GetValue()
81 #define TOOLBOX_NAME                ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "colorbar" ) )
82 
83 // ----------------
84 // - TbxImageItem -
85 // ----------------
86 
87 TYPEINIT1_AUTOFACTORY( TbxImageItem, SfxUInt16Item );
88 
89 //---------------------------------------------------------
90 
TbxImageItem(sal_uInt16 _nWhich,sal_uInt16 nImage)91 TbxImageItem::TbxImageItem( sal_uInt16 _nWhich, sal_uInt16 nImage ) :
92 	SfxUInt16Item( _nWhich, nImage )
93 {
94 }
95 
96 //---------------------------------------------------------
97 
Clone(SfxItemPool *) const98 SfxPoolItem* TbxImageItem::Clone( SfxItemPool* ) const
99 {
100 	return new TbxImageItem( *this );
101 }
102 
103 //---------------------------------------------------------
104 
operator ==(const SfxPoolItem & rItem) const105 int TbxImageItem::operator==( const SfxPoolItem& rItem ) const
106 {
107 	return( ( (TbxImageItem&) rItem ).GetValue() == GetValue() );
108 }
109 
110 // -----------------------
111 // - ImplGrafMetricField -
112 // -----------------------
113 
114 class ImplGrafMetricField : public MetricField
115 {
116 	using Window::Update;
117 
118 private:
119 	Timer			    maTimer;
120 	OUString	        maCommand;
121     Reference< XFrame > mxFrame;
122 
123 					DECL_LINK( ImplModifyHdl, Timer* );
124 
125 protected:
126 
127 	virtual void	Modify();
128 
129 public:
130 
131                     ImplGrafMetricField( Window* pParent, const rtl::OUString& aCmd, const Reference< XFrame >& rFrame );
132 					~ImplGrafMetricField();
133 
134 	void			Update( const SfxPoolItem* pItem );
GetCommand() const135 	const OUString&	GetCommand() const { return maCommand; }
136 };
137 
138 // -----------------------------------------------------------------------------
139 
ImplGrafMetricField(Window * pParent,const rtl::OUString & rCmd,const Reference<XFrame> & rFrame)140 ImplGrafMetricField::ImplGrafMetricField( Window* pParent, const rtl::OUString& rCmd, const Reference< XFrame >& rFrame ) :
141 	MetricField( pParent, WB_BORDER | WB_SPIN | WB_REPEAT | WB_3DLOOK ),
142 	maCommand( rCmd ),
143     mxFrame( rFrame )
144 {
145 	Size aSize( GetTextWidth( String::CreateFromAscii("-100 %") ), GetTextHeight() );
146 
147 	aSize.Width() += 20, aSize.Height() += 6;
148 	SetSizePixel( aSize );
149 
150     if ( maCommand.equalsAscii( ".uno:GrafGamma" ))
151     {
152 		SetDecimalDigits( 2 );
153 
154 		SetMin( 10 );
155 		SetFirst( 10 );
156 		SetMax( 1000 );
157 		SetLast( 1000 );
158 		SetSpinSize( 10 );
159 	}
160 	else
161 	{
162         const long nMinVal = ( maCommand.equalsAscii( ".uno:GrafTransparence" )) ? 0 : -100;
163 
164 		SetUnit( FUNIT_CUSTOM );
165 		SetCustomUnitText( String::CreateFromAscii(" %") );
166 		SetDecimalDigits( 0 );
167 
168 		SetMin( nMinVal );
169 		SetFirst( nMinVal );
170 		SetMax( 100 );
171 		SetLast( 100 );
172 		SetSpinSize( 1 );
173 	}
174 
175 	maTimer.SetTimeout( 100 );
176 	maTimer.SetTimeoutHdl( LINK( this, ImplGrafMetricField, ImplModifyHdl ) );
177 }
178 
179 // -----------------------------------------------------------------------------
180 
~ImplGrafMetricField()181 ImplGrafMetricField::~ImplGrafMetricField()
182 {
183 }
184 
185 // -----------------------------------------------------------------------------
186 
Modify()187 void ImplGrafMetricField::Modify()
188 {
189 	maTimer.Start();
190 }
191 
192 // -----------------------------------------------------------------------------
193 
IMPL_LINK(ImplGrafMetricField,ImplModifyHdl,Timer *,EMPTYARG)194 IMPL_LINK( ImplGrafMetricField, ImplModifyHdl, Timer*, EMPTYARG )
195 {
196 	const sal_Int64 nVal = GetValue();
197 
198     // Convert value to an any to be usable with dispatch API
199     Any a;
200     if ( maCommand.equalsAscii( ".uno:GrafRed" ) ||
201          maCommand.equalsAscii( ".uno:GrafGreen" ) ||
202          maCommand.equalsAscii( ".uno:GrafBlue" ) ||
203          maCommand.equalsAscii( ".uno:GrafLuminance" ) ||
204          maCommand.equalsAscii( ".uno:GrafContrast" ))
205         a = makeAny( sal_Int16( nVal ));
206     else if ( maCommand.equalsAscii( ".uno:GrafGamma" ) ||
207               maCommand.equalsAscii( ".uno:GrafTransparence" ))
208         a = makeAny( sal_Int32( nVal ));
209 
210 	if ( a.hasValue() )
211 	{
212         INetURLObject aObj( maCommand );
213 
214         Sequence< PropertyValue > aArgs( 1 );
215         aArgs[0].Name = aObj.GetURLPath();
216         aArgs[0].Value = a;
217 
218         SfxToolBoxControl::Dispatch(
219             Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
220             maCommand,
221             aArgs );
222 	}
223 	return 0L;
224 }
225 
226 // -----------------------------------------------------------------------------
227 
Update(const SfxPoolItem * pItem)228 void ImplGrafMetricField::Update( const SfxPoolItem* pItem )
229 {
230 	if( pItem )
231 	{
232 		long nValue;
233 
234         if ( maCommand.equalsAscii( ".uno:GrafTransparence" ))
235 			nValue = ( (SfxUInt16Item*) pItem )->GetValue();
236         else if ( maCommand.equalsAscii( ".uno:GrafGamma" ))
237 			nValue = ( (SfxUInt32Item*) pItem )->GetValue();
238         else
239 			nValue = ( (SfxInt16Item*) pItem )->GetValue();
240 
241 		SetValue( nValue );
242 	}
243 	else
244 		SetText( String() );
245 }
246 
247 // --------------------
248 // - ImplGrafControl  -
249 // --------------------
250 
251 struct CommandToRID
252 {
253     const char* pCommand;
254     sal_uInt16      nResId;
255     sal_uInt16      nHCResId;
256 };
257 
ImplGetRID(const OUString & aCommand,bool bHighContrast)258 static sal_uInt16 ImplGetRID( const OUString& aCommand, bool bHighContrast )
259 {
260 	static const CommandToRID aImplCommandToResMap[] =
261 	{
262         { ".uno:GrafRed", RID_SVXIMG_GRAF_RED, RID_SVXIMG_GRAF_RED_H },
263         { ".uno:GrafGreen", RID_SVXIMG_GRAF_GREEN, RID_SVXIMG_GRAF_GREEN_H },
264         { ".uno:GrafBlue", RID_SVXIMG_GRAF_BLUE, RID_SVXIMG_GRAF_BLUE_H },
265         { ".uno:GrafLuminance", RID_SVXIMG_GRAF_LUMINANCE, RID_SVXIMG_GRAF_LUMINANCE_H },
266         { ".uno:GrafContrast", RID_SVXIMG_GRAF_CONTRAST, RID_SVXIMG_GRAF_CONTRAST_H },
267         { ".uno:GrafGamma", RID_SVXIMG_GRAF_GAMMA, RID_SVXIMG_GRAF_GAMMA_H },
268         { ".uno:GrafTransparence", RID_SVXIMG_GRAF_TRANSPARENCE, RID_SVXIMG_GRAF_TRANSPARENCE_H },
269         { 0, 0, 0 }
270 	};
271 
272 	sal_uInt16 nRID = 0;
273 
274     sal_Int32 i( 0 );
275     while ( aImplCommandToResMap[ i ].pCommand )
276     {
277 		if ( aCommand.equalsAscii( aImplCommandToResMap[ i ].pCommand ))
278 		{
279             if ( bHighContrast )
280                 nRID = aImplCommandToResMap[ i ].nHCResId;
281             else
282                 nRID = aImplCommandToResMap[ i ].nResId;
283 			break;
284 		}
285         ++i;
286     }
287 
288 	return nRID;
289 }
290 
291 // -----------------------------------------------------------------------------
292 
293 class ImplGrafControl : public Control
294 {
295 	using Window::Update;
296 private:
297 	FixedImage				maImage;
298 	ImplGrafMetricField		maField;
299 
300 protected:
301 
302 	virtual void			GetFocus();
303 
304 public:
305 
306                             ImplGrafControl( Window* pParent, sal_uInt16 nSlotId, const rtl::OUString& rCmd, const Reference< XFrame >& rFrame );
307 							~ImplGrafControl();
308 
Update(const SfxPoolItem * pItem)309 	void					Update( const SfxPoolItem* pItem ) { maField.Update( pItem ); }
SetText(const String & rStr)310 	void					SetText( const String& rStr ) { maField.SetText( rStr ); }
311 };
312 
313 // -----------------------------------------------------------------------------
314 
ImplGrafControl(Window * pParent,sal_uInt16,const rtl::OUString & rCmd,const Reference<XFrame> & rFrame)315 ImplGrafControl::ImplGrafControl( Window* pParent, sal_uInt16, const rtl::OUString& rCmd, const Reference< XFrame >& rFrame ) :
316 	Control( pParent, WB_TABSTOP ),
317 	maImage		( this ),
318 	maField		( this, rCmd, rFrame )
319 {
320 	ResId	aResId( ImplGetRID( rCmd, false ), DIALOG_MGR() ) ;
321 	Image	aImage( aResId );
322 
323 	ResId	aResIdHC( ImplGetRID( rCmd, true ), DIALOG_MGR() ) ;
324 	Image	aImageHC( aResIdHC );
325 
326 	Size	aImgSize( aImage.GetSizePixel() );
327 	Size	aFldSize( maField.GetSizePixel() );
328 	long	nFldY, nImgY;
329 
330 	maImage.SetImage( aImage );
331 	maImage.SetModeImage( aImageHC, BMP_COLOR_HIGHCONTRAST );
332 	maImage.SetSizePixel( aImgSize );
333 	// we want to see the backbround of the toolbox, not of the FixedImage or Control
334 	maImage.SetBackground( Wallpaper( COL_TRANSPARENT ) );
335 	SetBackground( Wallpaper( COL_TRANSPARENT ) );
336 
337 	if( aImgSize.Height() > aFldSize.Height() )
338 		nImgY = 0, nFldY = ( aImgSize.Height() - aFldSize.Height() ) >> 1;
339 	else
340 		nFldY = 0, nImgY = ( aFldSize.Height() - aImgSize.Height() ) >> 1;
341 
342 	long nOffset = SYMBOL_TO_FIELD_OFFSET / 2;
343 	maImage.SetPosPixel( Point( nOffset, nImgY ) );
344 	maField.SetPosPixel( Point( aImgSize.Width() + SYMBOL_TO_FIELD_OFFSET, nFldY ) );
345 	SetSizePixel( Size( aImgSize.Width() + aFldSize.Width() + SYMBOL_TO_FIELD_OFFSET + nOffset,
346 				  Max( aImgSize.Height(), aFldSize.Height() ) ) );
347 
348     SetBackground( Wallpaper() ); // transparent background
349 
350 	maImage.Show();
351 
352     maField.SetHelpId( rtl::OUStringToOString( rCmd, RTL_TEXTENCODING_UTF8 ) );
353 	maField.Show();
354 }
355 
356 // -----------------------------------------------------------------------------
357 
~ImplGrafControl()358 ImplGrafControl::~ImplGrafControl()
359 {
360 }
361 
362 // -----------------------------------------------------------------------------
363 
GetFocus()364 void ImplGrafControl::GetFocus()
365 {
366 	maField.GrabFocus();
367 }
368 
369 // -----------------------
370 // - ImplGrafModeControl -
371 // -----------------------
372 
373 class ImplGrafModeControl : public ListBox
374 {
375 	using Window::Update;
376 private:
377 	sal_uInt16			    mnCurPos;
378     Reference< XFrame > mxFrame;
379 
380 	virtual void 	Select();
381 	virtual long	PreNotify( NotifyEvent& rNEvt );
382 	virtual long	Notify( NotifyEvent& rNEvt );
383 	void			ImplReleaseFocus();
384 
385 public:
386 
387 					ImplGrafModeControl( Window* pParent, const Reference< XFrame >& rFrame );
388 					~ImplGrafModeControl();
389 
390 	void			Update( const SfxPoolItem* pItem );
391 };
392 
393 // -----------------------------------------------------------------------------
394 
ImplGrafModeControl(Window * pParent,const Reference<XFrame> & rFrame)395 ImplGrafModeControl::ImplGrafModeControl( Window* pParent, const Reference< XFrame >& rFrame ) :
396 	ListBox( pParent, WB_BORDER | WB_DROPDOWN | WB_AUTOHSCROLL ),
397 	mnCurPos( 0 ),
398     mxFrame( rFrame )
399 {
400 	SetSizePixel( Size( 100, 260 ) );
401 
402 	InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_STANDARD ) );
403 	InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_GREYS ) );
404 	InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_MONO ) );
405 	InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_WATERMARK ) );
406 
407 	Show();
408 }
409 
410 // -----------------------------------------------------------------------
411 
~ImplGrafModeControl()412 ImplGrafModeControl::~ImplGrafModeControl()
413 {
414 }
415 
416 // -----------------------------------------------------------------------
417 
Select()418 void ImplGrafModeControl::Select()
419 {
420 	if ( !IsTravelSelect() )
421 	{
422         Sequence< PropertyValue > aArgs( 1 );
423         aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GrafMode" ));
424         aArgs[0].Value = makeAny( sal_Int16( GetSelectEntryPos() ));
425 
426         /*  #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
427             This instance may be deleted in the meantime (i.e. when a dialog is opened
428             while in Dispatch()), accessing members will crash in this case. */
429         ImplReleaseFocus();
430 
431         SfxToolBoxControl::Dispatch(
432             Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
433             OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GrafMode" )),
434             aArgs );
435 	}
436 }
437 
438 // -----------------------------------------------------------------------
439 
PreNotify(NotifyEvent & rNEvt)440 long ImplGrafModeControl::PreNotify( NotifyEvent& rNEvt )
441 {
442 	sal_uInt16 nType = rNEvt.GetType();
443 
444 	if( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
445 		mnCurPos = GetSelectEntryPos();
446 
447 	return ListBox::PreNotify( rNEvt );
448 }
449 
450 // -----------------------------------------------------------------------
451 
Notify(NotifyEvent & rNEvt)452 long ImplGrafModeControl::Notify( NotifyEvent& rNEvt )
453 {
454 	long nHandled = ListBox::Notify( rNEvt );
455 
456 	if( rNEvt.GetType() == EVENT_KEYINPUT )
457 	{
458 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
459 
460 		switch( pKEvt->GetKeyCode().GetCode() )
461 		{
462 			case KEY_RETURN:
463 			{
464 				Select();
465 				nHandled = 1;
466 			}
467 			break;
468 
469 			case KEY_ESCAPE:
470 			{
471 				SelectEntryPos( mnCurPos );
472 				ImplReleaseFocus();
473 				nHandled = 1;
474 			}
475 			break;
476 		}
477 	}
478 
479 	return nHandled;
480 }
481 
482 // -----------------------------------------------------------------------
483 
ImplReleaseFocus()484 void ImplGrafModeControl::ImplReleaseFocus()
485 {
486 	if( SfxViewShell::Current() )
487 	{
488 		Window* pShellWnd = SfxViewShell::Current()->GetWindow();
489 
490 		if( pShellWnd )
491 			pShellWnd->GrabFocus();
492 	}
493 }
494 
495 // -----------------------------------------------------------------------
496 
Update(const SfxPoolItem * pItem)497 void ImplGrafModeControl::Update( const SfxPoolItem* pItem )
498 {
499 	if( pItem )
500 		SelectEntryPos( ((SfxUInt16Item*)pItem)->GetValue() );
501 	else
502 		SetNoSelection();
503 }
504 
505 // -----------------------
506 // - ImplGrafFilterPopup -
507 // -----------------------
508 /*
509 CD!!!
510 class ImplGrafFilterPopup : public SfxPopupWindow
511 {
512 private:
513 
514 	SvxGrafFilterToolBoxControl*	    mpParent;
515     Reference< XConfigurableUIElement > m_xToolBar;
516 //	SfxToolBoxManager				    maTbxMgr;
517 	ResId							    maResIdWin;
518 	ResId							    maResIdTbx;
519 	WindowAlign						    meTbxAlign;
520 	Link							    maSelectHdl;
521 
522 									DECL_LINK( TbxSelectHdl, void* );
523 
524 public:
525 									ImplGrafFilterPopup( sal_uInt16 nId, SvxGrafFilterToolBoxControl* pParent,
526 														 WindowAlign eAlign,
527 														 const ResId& rResIdWin, const ResId& rResIdTbx,
528 														 SfxBindings& rBindings );
529 									~ImplGrafFilterPopup();
530 
531 	virtual SfxPopupWindow*			Clone() const;
532 	virtual void					PopupModeEnd();
533 
534 	void							StartSelection() { maTbxMgr.GetToolBox().StartSelection(); }
535 	void							Update();
536 };
537 
538 // -----------------------------------------------------------------------------
539 
540 ImplGrafFilterPopup::ImplGrafFilterPopup( sal_uInt16 nId, SvxGrafFilterToolBoxControl* pParent,
541 										  WindowAlign eAlign,
542 										  const ResId& rResIdWin, const ResId& rResIdTbx ) :
543 	SfxPopupWindow	( nId, rResIdWin ),
544 	mpParent		( pParent ),
545     maTbxMgr		( this, GetBindings(), rResIdTbx ),
546     maResIdWin		( rResIdWin ),
547     maResIdTbx      ( rResIdTbx ),
548 	meTbxAlign		( eAlign )
549 {
550 	maTbxMgr.UseDefault();
551 
552 	maSelectHdl = maTbxMgr.GetToolBox().GetSelectHdl();
553 	maTbxMgr.GetToolBox().SetSelectHdl( LINK( this, ImplGrafFilterPopup, TbxSelectHdl ) );
554 
555 	FreeResource();
556 
557 	const Size aSize( maTbxMgr.CalcWindowSizePixel() );
558 	maTbxMgr.SetPosSizePixel( Point(), aSize );
559 	SetOutputSizePixel( aSize );
560 }
561 
562 // -----------------------------------------------------------------------------
563 
564 ImplGrafFilterPopup::~ImplGrafFilterPopup()
565 {
566 }
567 
568 // -----------------------------------------------------------------------------
569 
570 SfxPopupWindow* ImplGrafFilterPopup::Clone() const
571 {
572 	return( new ImplGrafFilterPopup( GetId(), mpParent, meTbxAlign,
573 									 maResIdWin, maResIdTbx,
574 									 (SfxBindings&) GetBindings() ) );
575 }
576 
577 // -----------------------------------------------------------------------------
578 
579 void ImplGrafFilterPopup::Update()
580 {
581 	ToolBox* pBox = &maTbxMgr.GetToolBox();
582 	maTbxMgr.Activate( pBox );
583 	maTbxMgr.Deactivate( pBox );
584 }
585 
586 // -----------------------------------------------------------------------------
587 
588 void ImplGrafFilterPopup::PopupModeEnd()
589 {
590 	maTbxMgr.GetToolBox().EndSelection();
591 	SfxPopupWindow::PopupModeEnd();
592 }
593 
594 // -----------------------------------------------------------------------------
595 
596 IMPL_LINK( ImplGrafFilterPopup, TbxSelectHdl, void*, EMPTYARG )
597 {
598 	const sal_uInt16 nSlotId = maTbxMgr.GetToolBox().GetCurItemId();
599 
600 	if( IsInPopupMode() )
601 		EndPopupMode();
602 
603 	GetBindings().GetDispatcher()->Execute( nSlotId, SFX_CALLMODE_ASYNCHRON );
604 
605 	return 0;
606 }
607 */
608 // -------------------------------
609 // - SvxGrafFilterToolBoxControl -
610 // -------------------------------
611 
612 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafFilterToolBoxControl, TbxImageItem );
613 
614 // -----------------------------------------------------------------------------
615 
SvxGrafFilterToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)616 SvxGrafFilterToolBoxControl::SvxGrafFilterToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
617 	SfxToolBoxControl( nSlotId, nId, rTbx )
618 {
619 	rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
620 	rTbx.Invalidate();
621 }
622 
623 // -----------------------------------------------------------------------------
624 
~SvxGrafFilterToolBoxControl()625 SvxGrafFilterToolBoxControl::~SvxGrafFilterToolBoxControl()
626 {
627 }
628 
629 // -----------------------------------------------------------------------------
630 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem *)631 void SvxGrafFilterToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* )
632 {
633 	GetToolBox().EnableItem( GetId(), ( eState != SFX_ITEM_DISABLED ) );
634 }
635 
636 // -----------------------------------------------------------------------------
637 
GetPopupWindowType() const638 SfxPopupWindowType SvxGrafFilterToolBoxControl::GetPopupWindowType() const
639 {
640 	return SFX_POPUPWINDOW_ONCLICK;
641 }
642 
643 // -----------------------------------------------------------------------------
644 
CreatePopupWindow()645 SfxPopupWindow* SvxGrafFilterToolBoxControl::CreatePopupWindow()
646 {
647     rtl::OUString aSubTbxResName(
648         RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/graffilterbar" ) );
649     createAndPositionSubToolBar( aSubTbxResName );
650 
651     return NULL;
652 }
653 
654 // -------------------------
655 // - SvxGrafToolBoxControl -
656 // -------------------------
657 
658 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafToolBoxControl, SfxVoidItem );
659 
660 // -----------------------------------------------------------------------------
661 
SvxGrafToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)662 SvxGrafToolBoxControl::SvxGrafToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx) :
663 	SfxToolBoxControl( nSlotId, nId, rTbx )
664 {
665 	rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
666 	rTbx.Invalidate();
667 }
668 
669 // -----------------------------------------------------------------------------
670 
~SvxGrafToolBoxControl()671 SvxGrafToolBoxControl::~SvxGrafToolBoxControl()
672 {
673 }
674 
675 // -----------------------------------------------------------------------------
676 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)677 void SvxGrafToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
678 
679 {
680 	ImplGrafControl* pCtrl = (ImplGrafControl*) GetToolBox().GetItemWindow( GetId() );
681 	DBG_ASSERT( pCtrl, "Control not found" );
682 
683 	if( eState == SFX_ITEM_DISABLED )
684 	{
685 		pCtrl->Disable();
686 		pCtrl->SetText( String() );
687 	}
688 	else
689 	{
690 		pCtrl->Enable();
691 
692 		if( eState == SFX_ITEM_AVAILABLE )
693 			pCtrl->Update( pState );
694 		else
695 			pCtrl->Update( NULL );
696 	}
697 }
698 
699 // -----------------------------------------------------------------------------
700 
CreateItemWindow(Window * pParent)701 Window* SvxGrafToolBoxControl::CreateItemWindow( Window *pParent )
702 {
703 	return( new ImplGrafControl( pParent, GetSlotId(), m_aCommandURL, m_xFrame ) );
704 }
705 
706 // ----------------------------
707 // - SvxGrafRedToolBoxControl -
708 // ----------------------------
709 
710 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafRedToolBoxControl, SfxInt16Item );
711 
712 // -----------------------------------------------------------------------------
713 
SvxGrafRedToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)714 SvxGrafRedToolBoxControl::SvxGrafRedToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
715 	SvxGrafToolBoxControl( nSlotId, nId, rTbx )
716 {
717 }
718 
719 // ------------------------------
720 // - SvxGrafGreenToolBoxControl -
721 // ------------------------------
722 
723 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGreenToolBoxControl, SfxInt16Item );
724 
725 // -----------------------------------------------------------------------------
726 
SvxGrafGreenToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)727 SvxGrafGreenToolBoxControl::SvxGrafGreenToolBoxControl(	sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
728 	SvxGrafToolBoxControl( nSlotId, nId, rTbx )
729 {
730 }
731 
732 // -----------------------------
733 // - SvxGrafBlueToolBoxControl -
734 // -----------------------------
735 
736 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafBlueToolBoxControl, SfxInt16Item );
737 
738 // -----------------------------------------------------------------------------
739 
SvxGrafBlueToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)740 SvxGrafBlueToolBoxControl::SvxGrafBlueToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
741 	SvxGrafToolBoxControl( nSlotId, nId, rTbx )
742 {
743 }
744 
745 // ----------------------------------
746 // - SvxGrafLuminanceToolBoxControl -
747 // ----------------------------------
748 
749 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafLuminanceToolBoxControl, SfxInt16Item );
750 
751 // -----------------------------------------------------------------------------
752 
SvxGrafLuminanceToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)753 SvxGrafLuminanceToolBoxControl::SvxGrafLuminanceToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
754 	SvxGrafToolBoxControl( nSlotId, nId, rTbx )
755 {
756 }
757 
758 // ----------------------------------
759 // - SvxGrafContrastToolBoxControl -
760 // ----------------------------------
761 
762 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafContrastToolBoxControl, SfxInt16Item );
763 
764 // -----------------------------------------------------------------------------
765 
SvxGrafContrastToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)766 SvxGrafContrastToolBoxControl::SvxGrafContrastToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
767 	SvxGrafToolBoxControl( nSlotId, nId, rTbx )
768 {
769 }
770 
771 // ------------------------------
772 // - SvxGrafGammaToolBoxControl -
773 // ------------------------------
774 
775 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGammaToolBoxControl, SfxUInt32Item );
776 
777 // -----------------------------------------------------------------------------
778 
SvxGrafGammaToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)779 SvxGrafGammaToolBoxControl::SvxGrafGammaToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
780 	SvxGrafToolBoxControl( nSlotId, nId, rTbx )
781 {
782 }
783 
784 // -------------------------------------
785 // - SvxGrafTransparenceToolBoxControl -
786 // -------------------------------------
787 
788 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafTransparenceToolBoxControl, SfxUInt16Item );
789 
790 // -----------------------------------------------------------------------------
791 
SvxGrafTransparenceToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)792 SvxGrafTransparenceToolBoxControl::SvxGrafTransparenceToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
793 	SvxGrafToolBoxControl( nSlotId, nId, rTbx )
794 {
795 }
796 
797 // -----------------------------
798 // - SvxGrafModeToolBoxControl -
799 // -----------------------------
800 
801 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafModeToolBoxControl, SfxUInt16Item );
802 
803 // -----------------------------------------------------------------------------
804 
SvxGrafModeToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)805 SvxGrafModeToolBoxControl::SvxGrafModeToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
806 	SfxToolBoxControl( nSlotId, nId, rTbx )
807 {
808 }
809 
810 // -----------------------------------------------------------------------------
811 
~SvxGrafModeToolBoxControl()812 SvxGrafModeToolBoxControl::~SvxGrafModeToolBoxControl()
813 {
814 }
815 
816 // -----------------------------------------------------------------------------
817 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)818 void SvxGrafModeToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
819 
820 {
821 	ImplGrafModeControl* pCtrl = (ImplGrafModeControl*) GetToolBox().GetItemWindow( GetId() );
822 	DBG_ASSERT( pCtrl, "Control not found" );
823 
824 	if( eState == SFX_ITEM_DISABLED )
825 	{
826 		pCtrl->Disable();
827 		pCtrl->SetText( String() );
828 	}
829 	else
830 	{
831 		pCtrl->Enable();
832 
833 		if( eState == SFX_ITEM_AVAILABLE )
834 			pCtrl->Update( pState );
835 		else
836 			pCtrl->Update( NULL );
837 	}
838 }
839 
840 // -----------------------------------------------------------------------------
841 
CreateItemWindow(Window * pParent)842 Window* SvxGrafModeToolBoxControl::CreateItemWindow( Window *pParent )
843 {
844 	return( new ImplGrafModeControl( pParent, m_xFrame ) );
845 }
846 
847 // ---------------------
848 // - SvxGrafAttrHelper -
849 // ---------------------
850 
ExecuteGrafAttr(SfxRequest & rReq,SdrView & rView)851 void SvxGrafAttrHelper::ExecuteGrafAttr( SfxRequest& rReq, SdrView& rView )
852 {
853 	SfxItemPool&	rPool = rView.GetModel()->GetItemPool();
854 	SfxItemSet		aSet( rPool, SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST );
855     String			aUndoStr;
856 	const bool      bUndo = rView.IsUndoEnabled();
857 
858 	if( bUndo )
859 	{
860 		aUndoStr = rView.GetDescriptionOfMarkedObjects();
861 		aUndoStr.Append( sal_Unicode(' ') );
862 	}
863 
864 	const SfxItemSet*	pArgs = rReq.GetArgs();
865     const SfxPoolItem*	pItem;
866     sal_uInt16				nSlot = rReq.GetSlot();
867 
868 	if( !pArgs || SFX_ITEM_SET != pArgs->GetItemState( nSlot, sal_False, &pItem ))
869 		pItem = 0;
870 
871 	switch( nSlot )
872 	{
873 		case SID_ATTR_GRAF_RED:
874 		{
875 			if( pItem )
876 			{
877 				aSet.Put( SdrGrafRedItem( ((SfxInt16Item*)pItem)->GetValue() ));
878 				if( bUndo )
879 					aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFRED ) ) );
880 			}
881 		}
882 		break;
883 
884 		case SID_ATTR_GRAF_GREEN:
885 		{
886 			if( pItem )
887 			{
888 				aSet.Put( SdrGrafGreenItem( ((SfxInt16Item*)pItem)->GetValue() ));
889 				if( bUndo )
890 					aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGREEN ) ) );
891 			}
892 		}
893 		break;
894 
895 		case SID_ATTR_GRAF_BLUE:
896 		{
897 			if( pItem )
898 			{
899 				aSet.Put( SdrGrafBlueItem( ((SfxInt16Item*)pItem)->GetValue() ));
900 				if( bUndo )
901 					aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFBLUE ) ) );
902 			}
903 		}
904 		break;
905 
906 		case SID_ATTR_GRAF_LUMINANCE:
907 		{
908 			if( pItem )
909 			{
910 				aSet.Put( SdrGrafLuminanceItem( ((SfxInt16Item*)pItem)->GetValue() ));
911 				if( bUndo )
912 					aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFLUMINANCE ) ) );
913 			}
914 		}
915 		break;
916 
917 		case SID_ATTR_GRAF_CONTRAST:
918 		{
919 			if( pItem )
920 			{
921 				aSet.Put( SdrGrafContrastItem( ((SfxInt16Item*)pItem)->GetValue() ));
922 				if( bUndo )
923 					aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCONTRAST ) ) );
924 			}
925 		}
926 		break;
927 
928 		case SID_ATTR_GRAF_GAMMA:
929 		{
930 			if( pItem )
931 			{
932 				aSet.Put( SdrGrafGamma100Item( ((SfxUInt32Item*)pItem)->GetValue() ));
933 				if( bUndo )
934 					aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGAMMA ) ) );
935 			}
936 		}
937 		break;
938 
939 		case SID_ATTR_GRAF_TRANSPARENCE:
940 		{
941 			if( pItem )
942 			{
943 				aSet.Put( SdrGrafTransparenceItem( ((SfxUInt16Item*)pItem)->GetValue() ));
944 				if( bUndo )
945 					aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFTRANSPARENCY ) ) );
946 			}
947 		}
948 		break;
949 
950 		case SID_ATTR_GRAF_MODE:
951 		{
952 			if( pItem )
953 			{
954 				aSet.Put( SdrGrafModeItem( (GraphicDrawMode) ((SfxUInt16Item*)pItem)->GetValue() ));
955 				if( bUndo )
956 					aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFMODE ) ) );
957 			}
958 		}
959 		break;
960 
961 		case( SID_ATTR_GRAF_CROP ):
962 		{
963             const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
964 
965             if( 0 < rMarkList.GetMarkCount() )
966             {
967                 SdrGrafObj* pObj = (SdrGrafObj*) rMarkList.GetMark( 0 )->GetMarkedSdrObj();
968 
969                 if( pObj && pObj->ISA( SdrGrafObj ) &&
970                     ( pObj->GetGraphicType() != GRAPHIC_NONE ) &&
971                     ( pObj->GetGraphicType() != GRAPHIC_DEFAULT ) )
972                 {
973                     SfxItemSet			aGrfAttr( rPool, SDRATTR_GRAFCROP, SDRATTR_GRAFCROP, 0 );
974                     const SfxMapUnit	eOldMetric = rPool.GetMetric( 0 );
975                     const MapMode		aMap100( MAP_100TH_MM );
976                     const MapMode		aMapTwip( MAP_TWIP );
977 
978                     aGrfAttr.Put(pObj->GetMergedItemSet());
979                     rPool.SetDefaultMetric( SFX_MAPUNIT_TWIP );
980 
981                     SfxItemSet	aCropDlgAttr( rPool,
982                                             SDRATTR_GRAFCROP, SDRATTR_GRAFCROP,
983                                             SID_ATTR_GRAF_GRAPHIC, SID_ATTR_GRAF_GRAPHIC,
984                                             SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
985                                             SID_ATTR_GRAF_FRMSIZE, SID_ATTR_GRAF_FRMSIZE,
986                                             SID_ATTR_GRAF_CROP, SID_ATTR_GRAF_CROP, 0 );
987 
988                     aCropDlgAttr.Put( SvxBrushItem( pObj->GetGraphic(), GPOS_MM, SID_ATTR_GRAF_GRAPHIC ) );
989                     aCropDlgAttr.Put( SvxSizeItem( SID_ATTR_PAGE_SIZE,
990                                                 Size( OutputDevice::LogicToLogic(
991                                                         Size( 200000, 200000 ), aMap100, aMapTwip ) ) ) );
992                     aCropDlgAttr.Put( SvxSizeItem( SID_ATTR_GRAF_FRMSIZE, OutputDevice::LogicToLogic(
993                                                 pObj->GetLogicRect().GetSize(), aMap100, aMapTwip ) ) );
994 
995                     const SdrGrafCropItem&	rCrop = (const SdrGrafCropItem&) aGrfAttr.Get( SDRATTR_GRAFCROP );
996                     Size					aLTSize( OutputDevice::LogicToLogic(
997                                                     Size( rCrop.GetLeft(), rCrop.GetTop() ), aMap100, aMapTwip ) );
998                     Size					aRBSize( OutputDevice::LogicToLogic(
999                                                     Size( rCrop.GetRight(), rCrop.GetBottom() ), aMap100, aMapTwip ) );
1000 
1001                     aCropDlgAttr.Put( SdrGrafCropItem( aLTSize.Width(), aLTSize.Height(),
1002                                                     aRBSize.Width(), aRBSize.Height() ) );
1003 
1004                     SfxSingleTabDialog	aCropDialog( SfxViewShell::Current() ? SfxViewShell::Current()->GetWindow() : NULL,
1005                                                     aCropDlgAttr, 950 );
1006                     const String		aCropStr = SVX_RESSTR( RID_SVXSTR_GRAFCROP );
1007                     //CHINA001 SfxTabPage*			pTabPage = SvxGrfCropPage::Create( &aCropDialog, aCropDlgAttr );
1008                     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1009                     DBG_ASSERT(pFact, "Dialogdiet error!");//CHINA001
1010                     ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( RID_SVXPAGE_GRFCROP );
1011                     DBG_ASSERT(fnCreatePage, "Dialogdiet error!");//CHINA001
1012                     SfxTabPage*	pTabPage = (*fnCreatePage)( &aCropDialog, aCropDlgAttr );
1013                     //CHINA001 end
1014                     pTabPage->SetText( aCropStr );
1015                     aCropDialog.SetTabPage( pTabPage );
1016 
1017                     if( aCropDialog.Execute() == RET_OK )
1018                     {
1019                         const SfxItemSet* pOutAttr = aCropDialog.GetOutputItemSet();
1020 
1021                         if( pOutAttr )
1022                         {
1023                             aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCROP ) ) );
1024 
1025                             // set crop attributes
1026                             if( SFX_ITEM_SET <= pOutAttr->GetItemState( SDRATTR_GRAFCROP ) )
1027                             {
1028                                 const SdrGrafCropItem& rNewCrop = (const SdrGrafCropItem&) pOutAttr->Get( SDRATTR_GRAFCROP );
1029 
1030                                 aLTSize = OutputDevice::LogicToLogic( Size( rNewCrop.GetLeft(), rNewCrop.GetTop() ), aMapTwip, aMap100 );
1031                                 aRBSize = OutputDevice::LogicToLogic( Size( rNewCrop.GetRight(), rNewCrop.GetBottom() ), aMapTwip, aMap100 );
1032                                 aSet.Put( SdrGrafCropItem( aLTSize.Width(), aLTSize.Height(), aRBSize.Width(), aRBSize.Height() ) );
1033                             }
1034 
1035                             // set new logic rect
1036                             if( SFX_ITEM_SET <= pOutAttr->GetItemState( SID_ATTR_GRAF_FRMSIZE ) )
1037                             {
1038                                 Point		aNewOrigin( pObj->GetLogicRect().TopLeft() );
1039                                 const Size&	rGrfSize = ( (const SvxSizeItem&) pOutAttr->Get( SID_ATTR_GRAF_FRMSIZE ) ).GetSize();
1040                                 Size		aNewGrfSize( OutputDevice::LogicToLogic( rGrfSize, aMapTwip, aMap100 ) );
1041                                 Size		aOldGrfSize( pObj->GetLogicRect().GetSize() );
1042 
1043                                 Rectangle aNewRect( aNewOrigin, aNewGrfSize );
1044                                 Point aOffset( (aNewGrfSize.Width() - aOldGrfSize.Width()) >> 1,
1045                                             (aNewGrfSize.Height() - aOldGrfSize.Height()) >> 1 );
1046 
1047                                 // #106181# rotate snap rect before setting it
1048                                 const GeoStat& aGeo = pObj->GetGeoStat();
1049 
1050                                 if (aGeo.nDrehWink!=0 || aGeo.nShearWink!=0)
1051                                 {
1052                                     Polygon aPol(aNewRect);
1053 
1054                                     // also transform origin offset
1055                                     if (aGeo.nShearWink!=0)
1056                                     {
1057                                         ShearPoly(aPol,
1058                                                 aNewRect.TopLeft(),
1059                                                 aGeo.nTan);
1060                                         ShearPoint(aOffset, Point(0,0), aGeo.nTan);
1061                                     }
1062                                     if (aGeo.nDrehWink!=0)
1063                                     {
1064                                         RotatePoly(aPol,
1065                                                 aNewRect.TopLeft(),
1066                                                 aGeo.nSin,aGeo.nCos);
1067                                         RotatePoint(aOffset, Point(0,0), aGeo.nSin,aGeo.nCos);
1068                                     }
1069 
1070                                     // apply offset
1071                                     aPol.Move( -aOffset.X(), -aOffset.Y() );
1072                                     aNewRect=aPol.GetBoundRect();
1073                                 }
1074                                 else
1075                                 {
1076                                     aNewRect.Move( -aOffset.X(), -aOffset.Y() );
1077                                 }
1078 
1079                                 if( !aSet.Count() )
1080                                     rView.SetMarkedObjRect( aNewRect );
1081                                 else
1082                                 {
1083 									if( bUndo )
1084 									{
1085 										rView.BegUndo( aUndoStr );
1086 										rView.AddUndo( rView.GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
1087 									}
1088                                     pObj->SetSnapRect( aNewRect );
1089                                     rView.SetAttributes( aSet );
1090 
1091 									if( bUndo )
1092 										rView.EndUndo();
1093                                     aSet.ClearItem();
1094                                 }
1095                             }
1096                         }
1097                     }
1098 
1099                     rPool.SetDefaultMetric( eOldMetric );
1100                 }
1101             }
1102 		}
1103 		break;
1104 
1105         case SID_COLOR_SETTINGS:
1106         {
1107             svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
1108             aToolboxAccess.toggleToolbox();
1109             rReq.Done();
1110             break;
1111         }
1112 
1113 		default:
1114 			break;
1115 	}
1116 
1117 	if( aSet.Count() )
1118 	{
1119 		if( bUndo )
1120 			rView.BegUndo( aUndoStr );
1121 
1122 		rView.SetAttributes( aSet );
1123 
1124 		if( bUndo )
1125 			rView.EndUndo();
1126 	}
1127 }
1128 
1129 // -----------------------------------------------------------------------------
1130 
GetGrafAttrState(SfxItemSet & rSet,SdrView & rView)1131 void SvxGrafAttrHelper::GetGrafAttrState( SfxItemSet& rSet, SdrView& rView )
1132 {
1133 	SfxItemPool&	rPool = rView.GetModel()->GetItemPool();
1134 	SfxItemSet		aAttrSet( rPool );
1135 	SfxWhichIter	aIter( rSet );
1136 	sal_uInt16		nWhich = aIter.FirstWhich();
1137     const           SdrMarkList& rMarkList = rView.GetMarkedObjectList();
1138     bool            bEnableColors = true;
1139     bool            bEnableTransparency = true;
1140     bool            bEnableCrop = ( 1 == rMarkList.GetMarkCount() );
1141 
1142     for( int i = 0, nCount = rMarkList.GetMarkCount(); i < nCount; ++i )
1143     {
1144         SdrGrafObj* pGrafObj = dynamic_cast< SdrGrafObj* >( rMarkList.GetMark( i )->GetMarkedSdrObj() );
1145 
1146         if( !pGrafObj ||
1147             ( pGrafObj->GetGraphicType() == GRAPHIC_NONE ) ||
1148             ( pGrafObj->GetGraphicType() == GRAPHIC_DEFAULT  ))
1149         {
1150             bEnableColors = bEnableTransparency = bEnableCrop = false;
1151             break;
1152         }
1153         else if( bEnableTransparency && ( pGrafObj->HasGDIMetaFile() || pGrafObj->IsAnimated() ) )
1154         {
1155             bEnableTransparency = false;
1156         }
1157     }
1158 
1159 	rView.GetAttributes( aAttrSet );
1160 
1161 	while( nWhich )
1162 	{
1163 		sal_uInt16 nSlotId = SfxItemPool::IsWhich( nWhich ) ? rPool.GetSlotId( nWhich ) : nWhich;
1164 
1165 		switch( nSlotId )
1166 		{
1167 			case( SID_ATTR_GRAF_MODE ):
1168 			{
1169 				if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFMODE ) )
1170 				{
1171 					if( bEnableColors )
1172                     {
1173                         rSet.Put( SfxUInt16Item( nSlotId,
1174                             sal::static_int_cast< sal_uInt16 >( ITEMVALUE( aAttrSet, SDRATTR_GRAFMODE, SdrGrafModeItem ) ) ) );
1175                     }
1176                     else
1177                     {
1178 						rSet.DisableItem( SID_ATTR_GRAF_MODE );
1179                     }
1180 				}
1181 			}
1182 			break;
1183 
1184 			case( SID_ATTR_GRAF_RED ):
1185 			{
1186 				if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFRED ) )
1187 				{
1188 					if( bEnableColors )
1189                     {
1190                         rSet.Put( SfxInt16Item( nSlotId,
1191                             ITEMVALUE( aAttrSet, SDRATTR_GRAFRED, SdrGrafRedItem ) ) );
1192                     }
1193                     else
1194                     {
1195 						rSet.DisableItem( SID_ATTR_GRAF_RED );
1196                     }
1197 				}
1198 			}
1199 			break;
1200 
1201 			case( SID_ATTR_GRAF_GREEN ):
1202 			{
1203 				if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFGREEN ) )
1204 				{
1205 					if( bEnableColors )
1206                     {
1207                         rSet.Put( SfxInt16Item( nSlotId,
1208                             ITEMVALUE( aAttrSet, SDRATTR_GRAFGREEN, SdrGrafGreenItem ) ) );
1209                     }
1210                     else
1211                     {
1212 						rSet.DisableItem( SID_ATTR_GRAF_GREEN );
1213                     }
1214 				}
1215 			}
1216 			break;
1217 
1218 			case( SID_ATTR_GRAF_BLUE ):
1219 			{
1220 				if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFBLUE ) )
1221 				{
1222 					if( bEnableColors )
1223                     {
1224                         rSet.Put( SfxInt16Item( nSlotId,
1225                             ITEMVALUE( aAttrSet, SDRATTR_GRAFBLUE, SdrGrafBlueItem ) ) );
1226                     }
1227                     else
1228                     {
1229 						rSet.DisableItem( SID_ATTR_GRAF_BLUE );
1230                     }
1231 				}
1232 			}
1233 			break;
1234 
1235 			case( SID_ATTR_GRAF_LUMINANCE ):
1236 			{
1237 				if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFLUMINANCE ) )
1238 				{
1239 					if( bEnableColors )
1240                     {
1241                         rSet.Put( SfxInt16Item( nSlotId,
1242                             ITEMVALUE( aAttrSet, SDRATTR_GRAFLUMINANCE, SdrGrafLuminanceItem ) ) );
1243                     }
1244                     else
1245                     {
1246 						rSet.DisableItem( SID_ATTR_GRAF_LUMINANCE );
1247                     }
1248 				}
1249 			}
1250 			break;
1251 
1252 			case( SID_ATTR_GRAF_CONTRAST ):
1253 			{
1254 				if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFCONTRAST ) )
1255 				{
1256 					if( bEnableColors )
1257                     {
1258                         rSet.Put( SfxInt16Item( nSlotId,
1259                             ITEMVALUE( aAttrSet, SDRATTR_GRAFCONTRAST, SdrGrafContrastItem ) ) );
1260                     }
1261                     else
1262                     {
1263 						rSet.DisableItem( SID_ATTR_GRAF_CONTRAST );
1264                     }
1265 				}
1266 			}
1267 			break;
1268 
1269 			case( SID_ATTR_GRAF_GAMMA ):
1270 			{
1271 				if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFGAMMA ) )
1272 				{
1273 					if( bEnableColors )
1274                     {
1275                         rSet.Put( SfxUInt32Item( nSlotId,
1276                             ITEMVALUE( aAttrSet, SDRATTR_GRAFGAMMA, SdrGrafGamma100Item ) ) );
1277                     }
1278                     else
1279                     {
1280 						rSet.DisableItem( SID_ATTR_GRAF_GAMMA );
1281                     }
1282 				}
1283 			}
1284 			break;
1285 
1286 			case( SID_ATTR_GRAF_TRANSPARENCE ):
1287 			{
1288 				if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFTRANSPARENCE ) )
1289 				{
1290 					if( bEnableTransparency )
1291                     {
1292 						rSet.Put( SfxUInt16Item( nSlotId,
1293 							ITEMVALUE( aAttrSet, SDRATTR_GRAFTRANSPARENCE, SdrGrafTransparenceItem ) ) );
1294                     }
1295 					else
1296                     {
1297 						rSet.DisableItem( SID_ATTR_GRAF_TRANSPARENCE );
1298                     }
1299 				}
1300 			}
1301 			break;
1302 
1303 			case( SID_ATTR_GRAF_CROP ):
1304 			{
1305                 if( !bEnableCrop )
1306                     rSet.DisableItem( nSlotId );
1307 			}
1308 			break;
1309 
1310             case SID_COLOR_SETTINGS :
1311             {
1312                 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
1313                 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
1314                 break;
1315             }
1316 
1317 			default:
1318 			break;
1319 		}
1320 
1321 		nWhich = aIter.NextWhich();
1322 	}
1323 }
1324