1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tpshadow.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
38 // include ---------------------------------------------------------------
39 #include <tools/shl.hxx>
40 #include <sfx2/app.hxx>
41 #include <sfx2/module.hxx>
43 #define _SVX_TPSHADOW_CXX
46 #include <svx/xpool.hxx>
47 #include <svx/dialogs.hrc>
48 #include "tabarea.hrc"
52 #include <svx/svdattr.hxx>
54 #include "drawitem.hxx"
55 #include "cuitabarea.hxx"
56 #include <svx/dialmgr.hxx>
57 #include "dlgutil.hxx"
58 #include <cuitabline.hxx>
60 #include <svx/xlineit0.hxx>
61 #include <sfx2/request.hxx> //add CHINA001
63 #define DLGWIN this->GetParent()->GetParent()
65 // static ----------------------------------------------------------------
67 static USHORT pShadowRanges
[] =
70 SDRATTR_SHADOWTRANSPARENCE
,
76 /*************************************************************************
78 |* Dialog zum Aendern des Schattens
80 \************************************************************************/
82 SvxShadowTabPage::SvxShadowTabPage( Window
* pParent
, const SfxItemSet
& rInAttrs
) :
84 SvxTabPage ( pParent
, SVX_RES( RID_SVXPAGE_SHADOW
), rInAttrs
),
86 aFlProp ( this, SVX_RES( FL_PROP
) ),
87 aTsbShowShadow ( this, SVX_RES( TSB_SHOW_SHADOW
) ),
88 aFtPosition ( this, SVX_RES( FT_POSITION
) ),
89 aCtlPosition ( this, SVX_RES( CTL_POSITION
) ),
90 aFtDistance ( this, SVX_RES( FT_DISTANCE
) ),
91 aMtrDistance ( this, SVX_RES( MTR_FLD_DISTANCE
) ),
92 aFtShadowColor ( this, SVX_RES( FT_SHADOW_COLOR
) ),
93 aLbShadowColor ( this, SVX_RES( LB_SHADOW_COLOR
) ),
94 aFtTransparent ( this, SVX_RES( FT_TRANSPARENT
) ),
95 aMtrTransparent ( this, SVX_RES( MTR_SHADOW_TRANSPARENT
) ),
96 aCtlXRectPreview ( this, SVX_RES( CTL_COLOR_PREVIEW
) ),
97 rOutAttrs ( rInAttrs
),
100 pXPool ( (XOutdevItemPool
*) rInAttrs
.GetPool() ),
101 aXFillAttr ( pXPool
),
102 rXFSet ( aXFillAttr
.GetItemSet() )
106 // diese Page braucht ExchangeSupport
107 SetExchangeSupport();
110 FieldUnit eFUnit
= GetModuleFieldUnit( &rInAttrs
);
118 default: ;//prevent warning
120 SetFieldUnit( aMtrDistance
, eFUnit
);
122 // PoolUnit ermitteln
123 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
124 DBG_ASSERT( pPool
, "Wo ist der Pool?" );
125 ePoolUnit
= pPool
->GetMetric( SDRATTR_SHADOWXDIST
);
127 // Setzen des Output-Devices
128 XFillStyle eXFS
= XFILL_SOLID
;
129 if( rOutAttrs
.GetItemState( XATTR_FILLSTYLE
) != SFX_ITEM_DONTCARE
)
131 eXFS
= (XFillStyle
) ( ( ( const XFillStyleItem
& ) rOutAttrs
.
132 Get( GetWhich( XATTR_FILLSTYLE
) ) ).GetValue() );
135 //case XFILL_NONE: --> NICHTS
138 if( SFX_ITEM_DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLCOLOR
) )
140 XFillColorItem
aColorItem( ( const XFillColorItem
& )
141 rOutAttrs
.Get( XATTR_FILLCOLOR
) );
142 rXFSet
.Put( aColorItem
);
147 if( SFX_ITEM_DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLGRADIENT
) )
149 XFillGradientItem
aGradientItem( ( ( const XFillGradientItem
& )
150 rOutAttrs
.Get( XATTR_FILLGRADIENT
) ) );
151 rXFSet
.Put( aGradientItem
);
156 if( SFX_ITEM_DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLHATCH
) )
158 XFillHatchItem
aHatchItem( ( ( const XFillHatchItem
& )
159 rOutAttrs
.Get( XATTR_FILLHATCH
) ) );
160 rXFSet
.Put( aHatchItem
);
166 if( SFX_ITEM_DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLBITMAP
) )
168 XFillBitmapItem
aBitmapItem( ( const XFillBitmapItem
& )
169 rOutAttrs
.Get( XATTR_FILLBITMAP
) );
170 rXFSet
.Put( aBitmapItem
);
174 case XFILL_NONE
: break;
179 rXFSet
.Put( XFillColorItem( String(), COL_LIGHTRED
) );
182 if(XFILL_NONE
== eXFS
)
185 // fallback to solid fillmode when no fill mode is provided to have
186 // a reasonable shadow preview. The used color will be a set one or
187 // the default (currently blue8)
191 rXFSet
.Put( XFillStyleItem( eXFS
) );
192 aCtlXRectPreview
.SetRectangleAttributes(aXFillAttr
.GetItemSet());
193 //aCtlXRectPreview.SetFillAttr( aXFillAttr );
195 aTsbShowShadow
.SetClickHdl( LINK( this, SvxShadowTabPage
, ClickShadowHdl_Impl
) );
196 Link aLink
= LINK( this, SvxShadowTabPage
, ModifyShadowHdl_Impl
);
197 aLbShadowColor
.SetSelectHdl( aLink
);
198 aMtrTransparent
.SetModifyHdl( aLink
);
199 aMtrDistance
.SetModifyHdl( aLink
);
203 // -----------------------------------------------------------------------
205 void SvxShadowTabPage::Construct()
207 // Farbtabelle fuellen
208 aLbShadowColor
.Fill( pColorTab
);
212 aTsbShowShadow
.Disable();
213 aFtPosition
.Disable();
214 aCtlPosition
.Disable();
215 aFtDistance
.Disable();
216 aMtrDistance
.Disable();
217 aFtShadowColor
.Disable();
218 aLbShadowColor
.Disable();
219 aFtTransparent
.Disable();
220 aMtrTransparent
.Disable();
224 // -----------------------------------------------------------------------
226 void SvxShadowTabPage::ActivatePage( const SfxItemSet
& rSet
)
231 SFX_ITEMSET_ARG (&rSet
,pPageTypeItem
,SfxUInt16Item
,SID_PAGE_TYPE
,sal_False
);
233 SetPageType(pPageTypeItem
->GetValue());
235 if( nDlgType
== 0 ) //CHINA001 // Flaechen-Dialogif( *pDlgType == 0 ) // Flaechen-Dialog
240 if( *pnColorTableState
& CT_CHANGED
||
241 *pnColorTableState
& CT_MODIFIED
)
243 if( *pnColorTableState
& CT_CHANGED
)
245 SvxAreaTabDialog
* pArea
= dynamic_cast< SvxAreaTabDialog
* >( DLGWIN
);
248 pColorTab
= pArea
->GetNewColorTable();
252 SvxLineTabDialog
* pLine
= dynamic_cast< SvxLineTabDialog
* >( DLGWIN
);
254 pColorTab
= pLine
->GetNewColorTable();
259 nPos
= aLbShadowColor
.GetSelectEntryPos();
260 aLbShadowColor
.Clear();
261 aLbShadowColor
.Fill( pColorTab
);
262 nCount
= aLbShadowColor
.GetEntryCount();
264 ; // Dieser Fall sollte nicht auftreten
265 else if( nCount
<= nPos
)
266 aLbShadowColor
.SelectEntryPos( 0 );
268 aLbShadowColor
.SelectEntryPos( nPos
);
270 ModifyShadowHdl_Impl( this );
272 nPageType
= PT_SHADOW
;//CHINA001 *pPageType = PT_SHADOW;
277 // -----------------------------------------------------------------------
279 int SvxShadowTabPage::DeactivatePage( SfxItemSet
* _pSet
)
282 FillItemSet( *_pSet
);
284 return( LEAVE_PAGE
);
287 // -----------------------------------------------------------------------
289 BOOL
SvxShadowTabPage::FillItemSet( SfxItemSet
& rAttrs
)
291 const SfxPoolItem
* pOld
= NULL
;
292 BOOL bModified
= FALSE
;
297 TriState eState
= aTsbShowShadow
.GetState();
298 if( eState
!= aTsbShowShadow
.GetSavedValue() )
300 SdrShadowItem
aItem( sal::static_int_cast
< BOOL
>( eState
) );
301 pOld
= GetOldItem( rAttrs
, SDRATTR_SHADOW
);
302 if ( !pOld
|| !( *(const SdrShadowItem
*)pOld
== aItem
) )
309 // Schatten-Entfernung
310 // Etwas umstaendliche Abfrage, ob etwas geaendert wurde,
311 // da Items nicht direkt auf Controls abbildbar sind
312 INT32 nX
= 0L, nY
= 0L;
313 INT32 nXY
= GetCoreValue( aMtrDistance
, ePoolUnit
);
315 switch( aCtlPosition
.GetActualRP() )
317 case RP_LT
: nX
= nY
= -nXY
; break;
318 case RP_MT
: nY
= -nXY
; break;
319 case RP_RT
: nX
= nXY
; nY
= -nXY
; break;
320 case RP_LM
: nX
= -nXY
; break;
321 case RP_RM
: nX
= nXY
; break;
322 case RP_LB
: nX
= -nXY
; nY
= nXY
; break;
323 case RP_MB
: nY
= nXY
; break;
324 case RP_RB
: nX
= nY
= nXY
; break;
328 // Wenn die Werte des Schattenabstanden==SFX_ITEM_DONTCARE und der angezeigte
329 // String im entspr. MetricField=="", dann w�rde der Vergleich zw. alten und
330 // neuen Distance-Werte ein falsches Ergebnis liefern, da in so einem Fall die
331 // neuen Distance-Werte den Default-Werten des MetricField entspr�chen !!!!
332 if ( !aMtrDistance
.IsEmptyFieldValue() ||
333 rOutAttrs
.GetItemState( SDRATTR_SHADOWXDIST
) != SFX_ITEM_DONTCARE
||
334 rOutAttrs
.GetItemState( SDRATTR_SHADOWYDIST
) != SFX_ITEM_DONTCARE
)
336 INT32 nOldX
= 9876543; // Unmoeglicher Wert, entspr. DontCare
337 INT32 nOldY
= 9876543;
338 if( rOutAttrs
.GetItemState( SDRATTR_SHADOWXDIST
) != SFX_ITEM_DONTCARE
&&
339 rOutAttrs
.GetItemState( SDRATTR_SHADOWYDIST
) != SFX_ITEM_DONTCARE
)
341 nOldX
= ( ( const SdrShadowXDistItem
& ) rOutAttrs
.
342 Get( SDRATTR_SHADOWXDIST
) ).GetValue();
343 nOldY
= ( ( const SdrShadowYDistItem
& ) rOutAttrs
.
344 Get( SDRATTR_SHADOWYDIST
) ).GetValue();
346 SdrShadowXDistItem
aXItem( nX
);
347 pOld
= GetOldItem( rAttrs
, SDRATTR_SHADOWXDIST
);
349 ( !pOld
|| !( *(const SdrShadowXDistItem
*)pOld
== aXItem
) ) )
351 rAttrs
.Put( aXItem
);
354 SdrShadowYDistItem
aYItem( nY
);
355 pOld
= GetOldItem( rAttrs
, SDRATTR_SHADOWYDIST
);
357 ( !pOld
|| !( *(const SdrShadowYDistItem
*)pOld
== aYItem
) ) )
359 rAttrs
.Put( aYItem
);
365 USHORT nPos
= aLbShadowColor
.GetSelectEntryPos();
366 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
&&
367 nPos
!= aLbShadowColor
.GetSavedValue() )
369 SdrShadowColorItem
aItem( aLbShadowColor
.GetSelectEntry(),
370 aLbShadowColor
.GetSelectEntryColor() );
371 pOld
= GetOldItem( rAttrs
, SDRATTR_SHADOWCOLOR
);
372 if ( !pOld
|| !( *(const SdrShadowColorItem
*)pOld
== aItem
) )
380 UINT16 nVal
= (UINT16
)aMtrTransparent
.GetValue();
381 if( nVal
!= (UINT16
)aMtrTransparent
.GetSavedValue().ToInt32() )
383 SdrShadowTransparenceItem
aItem( nVal
);
384 pOld
= GetOldItem( rAttrs
, SDRATTR_SHADOWTRANSPARENCE
);
385 if ( !pOld
|| !( *(const SdrShadowTransparenceItem
*)pOld
== aItem
) )
393 rAttrs
.Put (CntUInt16Item(SID_PAGE_TYPE
,nPageType
));
398 // -----------------------------------------------------------------------
400 void SvxShadowTabPage::Reset( const SfxItemSet
& rAttrs
)
404 // Alle Objekte koennen einen Schatten besitzen
405 // z.Z. gibt es nur 8 m�gliche Positionen den Schatten zu setzen
407 // Ist Schatten gesetzt?
408 if( rAttrs
.GetItemState( SDRATTR_SHADOW
) != SFX_ITEM_DONTCARE
)
410 aTsbShowShadow
.EnableTriState( FALSE
);
412 if( ( ( const SdrShadowItem
& ) rAttrs
.Get( SDRATTR_SHADOW
) ).GetValue() )
413 aTsbShowShadow
.SetState( STATE_CHECK
);
416 aTsbShowShadow
.SetState( STATE_NOCHECK
);
420 aTsbShowShadow
.SetState( STATE_DONTKNOW
);
422 // Entfernung (nur 8 moegliche Positionen), deshalb
423 // wird nur ein Item ausgewertet
425 if( rAttrs
.GetItemState( SDRATTR_SHADOWXDIST
) != SFX_ITEM_DONTCARE
&&
426 rAttrs
.GetItemState( SDRATTR_SHADOWYDIST
) != SFX_ITEM_DONTCARE
)
428 INT32 nX
= ( ( const SdrShadowXDistItem
& ) rAttrs
.Get( SDRATTR_SHADOWXDIST
) ).GetValue();
429 INT32 nY
= ( ( const SdrShadowYDistItem
& ) rAttrs
.Get( SDRATTR_SHADOWYDIST
) ).GetValue();
432 SetMetricValue( aMtrDistance
, nX
< 0L ? -nX
: nX
, ePoolUnit
);
434 SetMetricValue( aMtrDistance
, nY
< 0L ? -nY
: nY
, ePoolUnit
);
436 // Setzen des Schatten-Controls
437 if ( nX
< 0L && nY
< 0L ) aCtlPosition
.SetActualRP( RP_LT
);
438 else if( nX
== 0L && nY
< 0L ) aCtlPosition
.SetActualRP( RP_MT
);
439 else if( nX
> 0L && nY
< 0L ) aCtlPosition
.SetActualRP( RP_RT
);
440 else if( nX
< 0L && nY
== 0L ) aCtlPosition
.SetActualRP( RP_LM
);
441 // Mittelpunkt gibt es nicht mehr
442 else if( nX
== 0L && nY
== 0L ) aCtlPosition
.SetActualRP( RP_RB
);
443 else if( nX
> 0L && nY
== 0L ) aCtlPosition
.SetActualRP( RP_RM
);
444 else if( nX
< 0L && nY
> 0L ) aCtlPosition
.SetActualRP( RP_LB
);
445 else if( nX
== 0L && nY
> 0L ) aCtlPosition
.SetActualRP( RP_MB
);
446 else if( nX
> 0L && nY
> 0L ) aCtlPosition
.SetActualRP( RP_RB
);
450 // determine default-distance
451 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
452 SdrShadowXDistItem
* pXDistItem
= (SdrShadowXDistItem
*)&pPool
->GetDefaultItem (SDRATTR_SHADOWXDIST
);
453 SdrShadowYDistItem
* pYDistItem
= (SdrShadowYDistItem
*)&pPool
->GetDefaultItem (SDRATTR_SHADOWYDIST
);
454 if (pXDistItem
&& pYDistItem
)
456 INT32 nX
= pXDistItem
->GetValue();
457 INT32 nY
= pYDistItem
->GetValue();
459 SetMetricValue( aMtrDistance
, nX
< 0L ? -nX
: nX
, ePoolUnit
);
461 SetMetricValue( aMtrDistance
, nY
< 0L ? -nY
: nY
, ePoolUnit
);
464 // Tristate, z.B. mehrer Objekte wurden markiert, wovon einige einen Schatten besitzen, einige nicht.
465 // Der anzuzeigende Text des MetricFields wird auf "" gesetzt und dient in der Methode FillItemSet
466 // als Erkennungszeichen daf�r, das der Distance-Wert NICHT ver�ndert wurde !!!!
467 aMtrDistance
.SetText( String() );
468 aCtlPosition
.SetActualRP( RP_MM
);
472 if( rAttrs
.GetItemState( SDRATTR_SHADOWCOLOR
) != SFX_ITEM_DONTCARE
)
474 aLbShadowColor
.SelectEntry( ( ( const SdrShadowColorItem
& ) rAttrs
.Get( SDRATTR_SHADOWCOLOR
) ).GetColorValue() );
477 aLbShadowColor
.SetNoSelection();
480 if( rAttrs
.GetItemState( SDRATTR_SHADOWTRANSPARENCE
) != SFX_ITEM_DONTCARE
)
482 USHORT nTransp
= ( ( const SdrShadowTransparenceItem
& ) rAttrs
.Get( SDRATTR_SHADOWTRANSPARENCE
) ).GetValue();
483 aMtrTransparent
.SetValue( nTransp
);
486 aMtrTransparent
.SetText( String() );
490 aMtrDistance
.SaveValue();
491 aLbShadowColor
.SaveValue();
492 aTsbShowShadow
.SaveValue();
494 // #66832# This field was not saved, but used to determine changes.
495 // Why? Seems to be the error.
497 aMtrTransparent
.SaveValue();
499 ClickShadowHdl_Impl( NULL
);
500 ModifyShadowHdl_Impl( NULL
);
504 // -----------------------------------------------------------------------
506 SfxTabPage
* SvxShadowTabPage::Create( Window
* pWindow
,
507 const SfxItemSet
& rAttrs
)
509 return( new SvxShadowTabPage( pWindow
, rAttrs
) );
512 //------------------------------------------------------------------------
514 USHORT
* SvxShadowTabPage::GetRanges()
516 return( pShadowRanges
);
519 //------------------------------------------------------------------------
521 IMPL_LINK( SvxShadowTabPage
, ClickShadowHdl_Impl
, void *, EMPTYARG
)
523 if( aTsbShowShadow
.GetState() == STATE_NOCHECK
)
525 aFtPosition
.Disable();
526 aCtlPosition
.Disable();
527 aFtDistance
.Disable();
528 aMtrDistance
.Disable();
529 aFtShadowColor
.Disable();
530 aLbShadowColor
.Disable();
531 aFtTransparent
.Disable();
532 aMtrTransparent
.Disable();
536 aFtPosition
.Enable();
537 aCtlPosition
.Enable();
538 aFtDistance
.Enable();
539 aMtrDistance
.Enable();
540 aFtShadowColor
.Enable();
541 aLbShadowColor
.Enable();
542 aFtTransparent
.Enable();
543 aMtrTransparent
.Enable();
545 aCtlPosition
.Invalidate();
547 ModifyShadowHdl_Impl( NULL
);
552 //------------------------------------------------------------------------
554 IMPL_LINK( SvxShadowTabPage
, ModifyShadowHdl_Impl
, void *, EMPTYARG
)
556 if( aTsbShowShadow
.GetState() == STATE_CHECK
)
557 rXFSet
.Put( XFillStyleItem( XFILL_SOLID
) );
559 rXFSet
.Put( XFillStyleItem( XFILL_NONE
) );
561 USHORT nPos
= aLbShadowColor
.GetSelectEntryPos();
562 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
564 rXFSet
.Put( XFillColorItem( String(),
565 aLbShadowColor
.GetSelectEntryColor() ) );
567 UINT16 nVal
= (UINT16
)aMtrTransparent
.GetValue();
568 XFillTransparenceItem
aItem( nVal
);
569 rXFSet
.Put( XFillTransparenceItem( aItem
) );
571 // Schatten-Entfernung
572 INT32 nX
= 0L, nY
= 0L;
573 INT32 nXY
= GetCoreValue( aMtrDistance
, ePoolUnit
);
574 switch( aCtlPosition
.GetActualRP() )
576 case RP_LT
: nX
= nY
= -nXY
; break;
577 case RP_MT
: nY
= -nXY
; break;
578 case RP_RT
: nX
= nXY
; nY
= -nXY
; break;
579 case RP_LM
: nX
= -nXY
; break;
580 case RP_RM
: nX
= nXY
; break;
581 case RP_LB
: nX
= -nXY
; nY
= nXY
; break;
582 case RP_MB
: nY
= nXY
; break;
583 case RP_RB
: nX
= nY
= nXY
; break;
587 aCtlXRectPreview
.SetShadowPosition(Point(nX
, nY
));
589 aCtlXRectPreview
.SetShadowAttributes(aXFillAttr
.GetItemSet());
590 //aCtlXRectPreview.SetFillAttr( aXFillAttr );
591 aCtlXRectPreview
.Invalidate();
596 //------------------------------------------------------------------------
598 void SvxShadowTabPage::PointChanged( Window
* pWindow
, RECT_POINT eRcPt
)
602 // Schatten neu zeichnen
603 ModifyShadowHdl_Impl( pWindow
);
606 void SvxShadowTabPage::PageCreated (SfxAllItemSet aSet
) //add CHINA001
608 SFX_ITEMSET_ARG (&aSet
,pColorTabItem
,SvxColorTableItem
,SID_COLOR_TABLE
,sal_False
);
609 SFX_ITEMSET_ARG (&aSet
,pPageTypeItem
,SfxUInt16Item
,SID_PAGE_TYPE
,sal_False
);
610 SFX_ITEMSET_ARG (&aSet
,pDlgTypeItem
,SfxUInt16Item
,SID_DLG_TYPE
,sal_False
);
614 SetColorTable(pColorTabItem
->GetColorTable());
616 SetPageType(pPageTypeItem
->GetValue());
618 SetDlgType(pDlgTypeItem
->GetValue());