1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 // include ---------------------------------------------------------------
32 #include <tools/shl.hxx>
33 #include <sfx2/app.hxx>
34 #include <sfx2/module.hxx>
35 #include <svx/dialogs.hrc>
37 #define _SVX_TPSHADOW_CXX
39 #include "svx/xattr.hxx"
40 #include <svx/xpool.hxx>
42 #include "tabarea.hrc"
43 #include <svx/svdattr.hxx>
44 #include "svx/drawitem.hxx"
45 #include "cuitabarea.hxx"
46 #include <dialmgr.hxx>
47 #include "svx/dlgutil.hxx"
48 #include <cuitabline.hxx>
49 #include "paragrph.hrc"
50 #include <svx/xlineit0.hxx>
51 #include <sfx2/request.hxx> //add CHINA001
53 #define DLGWIN this->GetParent()->GetParent()
55 // static ----------------------------------------------------------------
57 static sal_uInt16 pShadowRanges
[] =
60 SDRATTR_SHADOWTRANSPARENCE
,
66 /*************************************************************************
68 |* Dialog zum Aendern des Schattens
70 \************************************************************************/
72 SvxShadowTabPage::SvxShadowTabPage( Window
* pParent
, const SfxItemSet
& rInAttrs
) :
74 SvxTabPage ( pParent
, CUI_RES( RID_SVXPAGE_SHADOW
), rInAttrs
),
76 aFlProp ( this, CUI_RES( FL_PROP
) ),
77 aTsbShowShadow ( this, CUI_RES( TSB_SHOW_SHADOW
) ),
78 aFtPosition ( this, CUI_RES( FT_POSITION
) ),
79 aCtlPosition ( this, CUI_RES( CTL_POSITION
) ),
80 aFtDistance ( this, CUI_RES( FT_DISTANCE
) ),
81 aMtrDistance ( this, CUI_RES( MTR_FLD_DISTANCE
) ),
82 aFtShadowColor ( this, CUI_RES( FT_SHADOW_COLOR
) ),
83 aLbShadowColor ( this, CUI_RES( LB_SHADOW_COLOR
) ),
84 aFtTransparent ( this, CUI_RES( FT_TRANSPARENT
) ),
85 aMtrTransparent ( this, CUI_RES( MTR_SHADOW_TRANSPARENT
) ),
86 aCtlXRectPreview ( this, CUI_RES( CTL_COLOR_PREVIEW
) ),
87 rOutAttrs ( rInAttrs
),
89 bDisable ( sal_False
),
90 pXPool ( (XOutdevItemPool
*) rInAttrs
.GetPool() ),
91 aXFillAttr ( pXPool
),
92 rXFSet ( aXFillAttr
.GetItemSet() )
96 // diese Page braucht ExchangeSupport
100 FieldUnit eFUnit
= GetModuleFieldUnit( rInAttrs
);
108 default: ;//prevent warning
110 SetFieldUnit( aMtrDistance
, eFUnit
);
112 // PoolUnit ermitteln
113 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
114 DBG_ASSERT( pPool
, "Wo ist der Pool?" );
115 ePoolUnit
= pPool
->GetMetric( SDRATTR_SHADOWXDIST
);
117 // Setzen des Output-Devices
118 XFillStyle eXFS
= XFILL_SOLID
;
119 if( rOutAttrs
.GetItemState( XATTR_FILLSTYLE
) != SFX_ITEM_DONTCARE
)
121 eXFS
= (XFillStyle
) ( ( ( const XFillStyleItem
& ) rOutAttrs
.
122 Get( GetWhich( XATTR_FILLSTYLE
) ) ).GetValue() );
125 //case XFILL_NONE: --> NICHTS
128 if( SFX_ITEM_DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLCOLOR
) )
130 XFillColorItem
aColorItem( ( const XFillColorItem
& )
131 rOutAttrs
.Get( XATTR_FILLCOLOR
) );
132 rXFSet
.Put( aColorItem
);
137 if( SFX_ITEM_DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLGRADIENT
) )
139 XFillGradientItem
aGradientItem( ( ( const XFillGradientItem
& )
140 rOutAttrs
.Get( XATTR_FILLGRADIENT
) ) );
141 rXFSet
.Put( aGradientItem
);
146 if( SFX_ITEM_DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLHATCH
) )
148 XFillHatchItem
aHatchItem( ( ( const XFillHatchItem
& )
149 rOutAttrs
.Get( XATTR_FILLHATCH
) ) );
150 rXFSet
.Put( aHatchItem
);
156 if( SFX_ITEM_DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLBITMAP
) )
158 XFillBitmapItem
aBitmapItem( ( const XFillBitmapItem
& )
159 rOutAttrs
.Get( XATTR_FILLBITMAP
) );
160 rXFSet
.Put( aBitmapItem
);
164 case XFILL_NONE
: break;
169 rXFSet
.Put( XFillColorItem( String(), COL_LIGHTRED
) );
172 if(XFILL_NONE
== eXFS
)
175 // fallback to solid fillmode when no fill mode is provided to have
176 // a reasonable shadow preview. The used color will be a set one or
177 // the default (currently blue8)
181 rXFSet
.Put( XFillStyleItem( eXFS
) );
182 aCtlXRectPreview
.SetRectangleAttributes(aXFillAttr
.GetItemSet());
183 //aCtlXRectPreview.SetFillAttr( aXFillAttr );
185 aTsbShowShadow
.SetClickHdl( LINK( this, SvxShadowTabPage
, ClickShadowHdl_Impl
) );
186 Link aLink
= LINK( this, SvxShadowTabPage
, ModifyShadowHdl_Impl
);
187 aLbShadowColor
.SetSelectHdl( aLink
);
188 aMtrTransparent
.SetModifyHdl( aLink
);
189 aMtrDistance
.SetModifyHdl( aLink
);
191 aCtlXRectPreview
.SetAccessibleName(String(CUI_RES(STR_EXAMPLE
)));
192 aCtlPosition
.SetAccessibleRelationMemberOf( &aFlProp
);
195 // -----------------------------------------------------------------------
197 void SvxShadowTabPage::Construct()
199 // Farbtabelle fuellen
200 aLbShadowColor
.Fill( pColorTab
);
204 aTsbShowShadow
.Disable();
205 aFtPosition
.Disable();
206 aCtlPosition
.Disable();
207 aFtDistance
.Disable();
208 aMtrDistance
.Disable();
209 aFtShadowColor
.Disable();
210 aLbShadowColor
.Disable();
211 aFtTransparent
.Disable();
212 aMtrTransparent
.Disable();
216 // -----------------------------------------------------------------------
218 void SvxShadowTabPage::ActivatePage( const SfxItemSet
& rSet
)
223 SFX_ITEMSET_ARG (&rSet
,pPageTypeItem
,SfxUInt16Item
,SID_PAGE_TYPE
,sal_False
);
225 SetPageType(pPageTypeItem
->GetValue());
227 if( nDlgType
== 0 ) //CHINA001 // Flaechen-Dialogif( *pDlgType == 0 ) // Flaechen-Dialog
232 if( *pnColorTableState
& CT_CHANGED
||
233 *pnColorTableState
& CT_MODIFIED
)
235 if( *pnColorTableState
& CT_CHANGED
)
237 SvxAreaTabDialog
* pArea
= dynamic_cast< SvxAreaTabDialog
* >( DLGWIN
);
240 pColorTab
= pArea
->GetNewColorTable();
244 SvxLineTabDialog
* pLine
= dynamic_cast< SvxLineTabDialog
* >( DLGWIN
);
246 pColorTab
= pLine
->GetNewColorTable();
251 nPos
= aLbShadowColor
.GetSelectEntryPos();
252 aLbShadowColor
.Clear();
253 aLbShadowColor
.Fill( pColorTab
);
254 nCount
= aLbShadowColor
.GetEntryCount();
256 ; // Dieser Fall sollte nicht auftreten
257 else if( nCount
<= nPos
)
258 aLbShadowColor
.SelectEntryPos( 0 );
260 aLbShadowColor
.SelectEntryPos( nPos
);
262 ModifyShadowHdl_Impl( this );
264 nPageType
= PT_SHADOW
;//CHINA001 *pPageType = PT_SHADOW;
269 // -----------------------------------------------------------------------
271 int SvxShadowTabPage::DeactivatePage( SfxItemSet
* _pSet
)
274 FillItemSet( *_pSet
);
276 return( LEAVE_PAGE
);
279 // -----------------------------------------------------------------------
281 sal_Bool
SvxShadowTabPage::FillItemSet( SfxItemSet
& rAttrs
)
283 const SfxPoolItem
* pOld
= NULL
;
284 sal_Bool bModified
= sal_False
;
289 TriState eState
= aTsbShowShadow
.GetState();
290 if( eState
!= aTsbShowShadow
.GetSavedValue() )
292 SdrShadowItem
aItem( sal::static_int_cast
< sal_Bool
>( eState
) );
293 pOld
= GetOldItem( rAttrs
, SDRATTR_SHADOW
);
294 if ( !pOld
|| !( *(const SdrShadowItem
*)pOld
== aItem
) )
297 bModified
= sal_True
;
301 // Schatten-Entfernung
302 // Etwas umstaendliche Abfrage, ob etwas geaendert wurde,
303 // da Items nicht direkt auf Controls abbildbar sind
304 sal_Int32 nX
= 0L, nY
= 0L;
305 sal_Int32 nXY
= GetCoreValue( aMtrDistance
, ePoolUnit
);
307 switch( aCtlPosition
.GetActualRP() )
309 case RP_LT
: nX
= nY
= -nXY
; break;
310 case RP_MT
: nY
= -nXY
; break;
311 case RP_RT
: nX
= nXY
; nY
= -nXY
; break;
312 case RP_LM
: nX
= -nXY
; break;
313 case RP_RM
: nX
= nXY
; break;
314 case RP_LB
: nX
= -nXY
; nY
= nXY
; break;
315 case RP_MB
: nY
= nXY
; break;
316 case RP_RB
: nX
= nY
= nXY
; break;
320 // Wenn die Werte des Schattenabstanden==SFX_ITEM_DONTCARE und der angezeigte
321 // String im entspr. MetricField=="", dann w�rde der Vergleich zw. alten und
322 // neuen Distance-Werte ein falsches Ergebnis liefern, da in so einem Fall die
323 // neuen Distance-Werte den Default-Werten des MetricField entspr�chen !!!!
324 if ( !aMtrDistance
.IsEmptyFieldValue() ||
325 rOutAttrs
.GetItemState( SDRATTR_SHADOWXDIST
) != SFX_ITEM_DONTCARE
||
326 rOutAttrs
.GetItemState( SDRATTR_SHADOWYDIST
) != SFX_ITEM_DONTCARE
)
328 sal_Int32 nOldX
= 9876543; // Unmoeglicher Wert, entspr. DontCare
329 sal_Int32 nOldY
= 9876543;
330 if( rOutAttrs
.GetItemState( SDRATTR_SHADOWXDIST
) != SFX_ITEM_DONTCARE
&&
331 rOutAttrs
.GetItemState( SDRATTR_SHADOWYDIST
) != SFX_ITEM_DONTCARE
)
333 nOldX
= ( ( const SdrShadowXDistItem
& ) rOutAttrs
.
334 Get( SDRATTR_SHADOWXDIST
) ).GetValue();
335 nOldY
= ( ( const SdrShadowYDistItem
& ) rOutAttrs
.
336 Get( SDRATTR_SHADOWYDIST
) ).GetValue();
338 SdrShadowXDistItem
aXItem( nX
);
339 pOld
= GetOldItem( rAttrs
, SDRATTR_SHADOWXDIST
);
341 ( !pOld
|| !( *(const SdrShadowXDistItem
*)pOld
== aXItem
) ) )
343 rAttrs
.Put( aXItem
);
344 bModified
= sal_True
;
346 SdrShadowYDistItem
aYItem( nY
);
347 pOld
= GetOldItem( rAttrs
, SDRATTR_SHADOWYDIST
);
349 ( !pOld
|| !( *(const SdrShadowYDistItem
*)pOld
== aYItem
) ) )
351 rAttrs
.Put( aYItem
);
352 bModified
= sal_True
;
357 sal_uInt16 nPos
= aLbShadowColor
.GetSelectEntryPos();
358 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
&&
359 nPos
!= aLbShadowColor
.GetSavedValue() )
361 SdrShadowColorItem
aItem( aLbShadowColor
.GetSelectEntry(),
362 aLbShadowColor
.GetSelectEntryColor() );
363 pOld
= GetOldItem( rAttrs
, SDRATTR_SHADOWCOLOR
);
364 if ( !pOld
|| !( *(const SdrShadowColorItem
*)pOld
== aItem
) )
367 bModified
= sal_True
;
372 sal_uInt16 nVal
= (sal_uInt16
)aMtrTransparent
.GetValue();
373 if( nVal
!= (sal_uInt16
)aMtrTransparent
.GetSavedValue().ToInt32() )
375 SdrShadowTransparenceItem
aItem( nVal
);
376 pOld
= GetOldItem( rAttrs
, SDRATTR_SHADOWTRANSPARENCE
);
377 if ( !pOld
|| !( *(const SdrShadowTransparenceItem
*)pOld
== aItem
) )
380 bModified
= sal_True
;
385 rAttrs
.Put (CntUInt16Item(SID_PAGE_TYPE
,nPageType
));
390 // -----------------------------------------------------------------------
392 void SvxShadowTabPage::Reset( const SfxItemSet
& rAttrs
)
396 // Alle Objekte koennen einen Schatten besitzen
397 // z.Z. gibt es nur 8 m�gliche Positionen den Schatten zu setzen
399 // Ist Schatten gesetzt?
400 if( rAttrs
.GetItemState( SDRATTR_SHADOW
) != SFX_ITEM_DONTCARE
)
402 aTsbShowShadow
.EnableTriState( sal_False
);
404 if( ( ( const SdrShadowItem
& ) rAttrs
.Get( SDRATTR_SHADOW
) ).GetValue() )
405 aTsbShowShadow
.SetState( STATE_CHECK
);
408 aTsbShowShadow
.SetState( STATE_NOCHECK
);
412 aTsbShowShadow
.SetState( STATE_DONTKNOW
);
414 // Entfernung (nur 8 moegliche Positionen), deshalb
415 // wird nur ein Item ausgewertet
417 if( rAttrs
.GetItemState( SDRATTR_SHADOWXDIST
) != SFX_ITEM_DONTCARE
&&
418 rAttrs
.GetItemState( SDRATTR_SHADOWYDIST
) != SFX_ITEM_DONTCARE
)
420 sal_Int32 nX
= ( ( const SdrShadowXDistItem
& ) rAttrs
.Get( SDRATTR_SHADOWXDIST
) ).GetValue();
421 sal_Int32 nY
= ( ( const SdrShadowYDistItem
& ) rAttrs
.Get( SDRATTR_SHADOWYDIST
) ).GetValue();
424 SetMetricValue( aMtrDistance
, nX
< 0L ? -nX
: nX
, ePoolUnit
);
426 SetMetricValue( aMtrDistance
, nY
< 0L ? -nY
: nY
, ePoolUnit
);
428 // Setzen des Schatten-Controls
429 if ( nX
< 0L && nY
< 0L ) aCtlPosition
.SetActualRP( RP_LT
);
430 else if( nX
== 0L && nY
< 0L ) aCtlPosition
.SetActualRP( RP_MT
);
431 else if( nX
> 0L && nY
< 0L ) aCtlPosition
.SetActualRP( RP_RT
);
432 else if( nX
< 0L && nY
== 0L ) aCtlPosition
.SetActualRP( RP_LM
);
433 // Mittelpunkt gibt es nicht mehr
434 else if( nX
== 0L && nY
== 0L ) aCtlPosition
.SetActualRP( RP_RB
);
435 else if( nX
> 0L && nY
== 0L ) aCtlPosition
.SetActualRP( RP_RM
);
436 else if( nX
< 0L && nY
> 0L ) aCtlPosition
.SetActualRP( RP_LB
);
437 else if( nX
== 0L && nY
> 0L ) aCtlPosition
.SetActualRP( RP_MB
);
438 else if( nX
> 0L && nY
> 0L ) aCtlPosition
.SetActualRP( RP_RB
);
442 // determine default-distance
443 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
444 SdrShadowXDistItem
* pXDistItem
= (SdrShadowXDistItem
*)&pPool
->GetDefaultItem (SDRATTR_SHADOWXDIST
);
445 SdrShadowYDistItem
* pYDistItem
= (SdrShadowYDistItem
*)&pPool
->GetDefaultItem (SDRATTR_SHADOWYDIST
);
446 if (pXDistItem
&& pYDistItem
)
448 sal_Int32 nX
= pXDistItem
->GetValue();
449 sal_Int32 nY
= pYDistItem
->GetValue();
451 SetMetricValue( aMtrDistance
, nX
< 0L ? -nX
: nX
, ePoolUnit
);
453 SetMetricValue( aMtrDistance
, nY
< 0L ? -nY
: nY
, ePoolUnit
);
456 // Tristate, z.B. mehrer Objekte wurden markiert, wovon einige einen Schatten besitzen, einige nicht.
457 // Der anzuzeigende Text des MetricFields wird auf "" gesetzt und dient in der Methode FillItemSet
458 // als Erkennungszeichen daf�r, das der Distance-Wert NICHT ver�ndert wurde !!!!
459 aMtrDistance
.SetText( String() );
460 aCtlPosition
.SetActualRP( RP_MM
);
464 if( rAttrs
.GetItemState( SDRATTR_SHADOWCOLOR
) != SFX_ITEM_DONTCARE
)
466 aLbShadowColor
.SelectEntry( ( ( const SdrShadowColorItem
& ) rAttrs
.Get( SDRATTR_SHADOWCOLOR
) ).GetColorValue() );
469 aLbShadowColor
.SetNoSelection();
472 if( rAttrs
.GetItemState( SDRATTR_SHADOWTRANSPARENCE
) != SFX_ITEM_DONTCARE
)
474 sal_uInt16 nTransp
= ( ( const SdrShadowTransparenceItem
& ) rAttrs
.Get( SDRATTR_SHADOWTRANSPARENCE
) ).GetValue();
475 aMtrTransparent
.SetValue( nTransp
);
478 aMtrTransparent
.SetText( String() );
482 aMtrDistance
.SaveValue();
483 aLbShadowColor
.SaveValue();
484 aTsbShowShadow
.SaveValue();
486 // #66832# This field was not saved, but used to determine changes.
487 // Why? Seems to be the error.
489 aMtrTransparent
.SaveValue();
491 ClickShadowHdl_Impl( NULL
);
492 ModifyShadowHdl_Impl( NULL
);
496 // -----------------------------------------------------------------------
498 SfxTabPage
* SvxShadowTabPage::Create( Window
* pWindow
,
499 const SfxItemSet
& rAttrs
)
501 return( new SvxShadowTabPage( pWindow
, rAttrs
) );
504 //------------------------------------------------------------------------
506 sal_uInt16
* SvxShadowTabPage::GetRanges()
508 return( pShadowRanges
);
511 //------------------------------------------------------------------------
513 IMPL_LINK( SvxShadowTabPage
, ClickShadowHdl_Impl
, void *, EMPTYARG
)
515 if( aTsbShowShadow
.GetState() == STATE_NOCHECK
)
517 aFtPosition
.Disable();
518 aCtlPosition
.Disable();
519 aFtDistance
.Disable();
520 aMtrDistance
.Disable();
521 aFtShadowColor
.Disable();
522 aLbShadowColor
.Disable();
523 aFtTransparent
.Disable();
524 aMtrTransparent
.Disable();
528 aFtPosition
.Enable();
529 aCtlPosition
.Enable();
530 aFtDistance
.Enable();
531 aMtrDistance
.Enable();
532 aFtShadowColor
.Enable();
533 aLbShadowColor
.Enable();
534 aFtTransparent
.Enable();
535 aMtrTransparent
.Enable();
537 aCtlPosition
.Invalidate();
539 ModifyShadowHdl_Impl( NULL
);
544 //------------------------------------------------------------------------
546 IMPL_LINK( SvxShadowTabPage
, ModifyShadowHdl_Impl
, void *, EMPTYARG
)
548 if( aTsbShowShadow
.GetState() == STATE_CHECK
)
549 rXFSet
.Put( XFillStyleItem( XFILL_SOLID
) );
551 rXFSet
.Put( XFillStyleItem( XFILL_NONE
) );
553 sal_uInt16 nPos
= aLbShadowColor
.GetSelectEntryPos();
554 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
556 rXFSet
.Put( XFillColorItem( String(),
557 aLbShadowColor
.GetSelectEntryColor() ) );
559 sal_uInt16 nVal
= (sal_uInt16
)aMtrTransparent
.GetValue();
560 XFillTransparenceItem
aItem( nVal
);
561 rXFSet
.Put( XFillTransparenceItem( aItem
) );
563 // Schatten-Entfernung
564 sal_Int32 nX
= 0L, nY
= 0L;
565 sal_Int32 nXY
= GetCoreValue( aMtrDistance
, ePoolUnit
);
566 switch( aCtlPosition
.GetActualRP() )
568 case RP_LT
: nX
= nY
= -nXY
; break;
569 case RP_MT
: nY
= -nXY
; break;
570 case RP_RT
: nX
= nXY
; nY
= -nXY
; break;
571 case RP_LM
: nX
= -nXY
; break;
572 case RP_RM
: nX
= nXY
; break;
573 case RP_LB
: nX
= -nXY
; nY
= nXY
; break;
574 case RP_MB
: nY
= nXY
; break;
575 case RP_RB
: nX
= nY
= nXY
; break;
579 aCtlXRectPreview
.SetShadowPosition(Point(nX
, nY
));
581 aCtlXRectPreview
.SetShadowAttributes(aXFillAttr
.GetItemSet());
582 //aCtlXRectPreview.SetFillAttr( aXFillAttr );
583 aCtlXRectPreview
.Invalidate();
588 //------------------------------------------------------------------------
590 void SvxShadowTabPage::PointChanged( Window
* pWindow
, RECT_POINT eRcPt
)
594 // Schatten neu zeichnen
595 ModifyShadowHdl_Impl( pWindow
);
598 void SvxShadowTabPage::PageCreated (SfxAllItemSet aSet
) //add CHINA001
600 SFX_ITEMSET_ARG (&aSet
,pColorTabItem
,SvxColorTableItem
,SID_COLOR_TABLE
,sal_False
);
601 SFX_ITEMSET_ARG (&aSet
,pPageTypeItem
,SfxUInt16Item
,SID_PAGE_TYPE
,sal_False
);
602 SFX_ITEMSET_ARG (&aSet
,pDlgTypeItem
,SfxUInt16Item
,SID_DLG_TYPE
,sal_False
);
606 SetColorTable(pColorTabItem
->GetColorTable());
608 SetPageType(pPageTypeItem
->GetValue());
610 SetDlgType(pDlgTypeItem
->GetValue());