1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sfx2/app.hxx>
21 #include <sfx2/module.hxx>
22 #include <svx/dialogs.hrc>
24 #include "svx/xattr.hxx"
25 #include <svx/xpool.hxx>
27 #include <svx/svdattr.hxx>
28 #include "svx/drawitem.hxx"
29 #include "cuitabarea.hxx"
30 #include <dialmgr.hxx>
31 #include "svx/dlgutil.hxx"
32 #include <cuitabline.hxx>
33 #include "paragrph.hrc"
34 #include <svx/xlineit0.hxx>
35 #include <sfx2/request.hxx>
37 using namespace com::sun::star
;
39 const sal_uInt16
SvxShadowTabPage::pShadowRanges
[] =
42 SDRATTR_SHADOWTRANSPARENCE
,
48 SvxShadowTabPage::SvxShadowTabPage( vcl::Window
* pParent
, const SfxItemSet
& rInAttrs
) :
52 "cui/ui/shadowtabpage.ui",
54 rOutAttrs ( rInAttrs
),
56 pnColorListState ( 0 ),
61 pXPool ( static_cast<XOutdevItemPool
*>(rInAttrs
.GetPool()) ),
62 aXFillAttr ( pXPool
),
63 rXFSet ( aXFillAttr
.GetItemSet() )
65 get(m_pTsbShowShadow
,"TSB_SHOW_SHADOW");
66 get(m_pGridShadow
,"gridSHADOW");
67 get(m_pCtlPosition
,"CTL_POSITION");
68 get(m_pMtrDistance
,"MTR_FLD_DISTANCE");
69 get(m_pLbShadowColor
,"LB_SHADOW_COLOR");
70 get(m_pMtrTransparent
,"MTR_SHADOW_TRANSPARENT");
71 get(m_pCtlXRectPreview
,"CTL_COLOR_PREVIEW");
73 // this page needs ExchangeSupport
77 FieldUnit eFUnit
= GetModuleFieldUnit( rInAttrs
);
85 default: ;//prevent warning
87 SetFieldUnit( *m_pMtrDistance
, eFUnit
);
90 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
91 DBG_ASSERT( pPool
, "Wo ist der Pool?" );
92 ePoolUnit
= pPool
->GetMetric( SDRATTR_SHADOWXDIST
);
94 // setting the output device
95 drawing::FillStyle eXFS
= drawing::FillStyle_SOLID
;
96 if( rOutAttrs
.GetItemState( XATTR_FILLSTYLE
) != SfxItemState::DONTCARE
)
98 eXFS
= (drawing::FillStyle
) ( static_cast<const XFillStyleItem
&>( rOutAttrs
.
99 Get( GetWhich( XATTR_FILLSTYLE
) ) ).GetValue() );
102 case drawing::FillStyle_SOLID
:
103 if( SfxItemState::DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLCOLOR
) )
105 XFillColorItem
aColorItem( static_cast<const XFillColorItem
&>(
106 rOutAttrs
.Get( XATTR_FILLCOLOR
) ) );
107 rXFSet
.Put( aColorItem
);
111 case drawing::FillStyle_GRADIENT
:
112 if( SfxItemState::DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLGRADIENT
) )
114 XFillGradientItem
aGradientItem( static_cast<const XFillGradientItem
&>(
115 rOutAttrs
.Get( XATTR_FILLGRADIENT
) ) );
116 rXFSet
.Put( aGradientItem
);
120 case drawing::FillStyle_HATCH
:
121 if( SfxItemState::DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLHATCH
) )
123 XFillHatchItem
aHatchItem( static_cast<const XFillHatchItem
& >(
124 rOutAttrs
.Get( XATTR_FILLHATCH
) ) );
125 rXFSet
.Put( aHatchItem
);
129 case drawing::FillStyle_BITMAP
:
131 if( SfxItemState::DONTCARE
!= rOutAttrs
.GetItemState( XATTR_FILLBITMAP
) )
133 XFillBitmapItem
aBitmapItem( static_cast<const XFillBitmapItem
& >(
134 rOutAttrs
.Get( XATTR_FILLBITMAP
) ) );
135 rXFSet
.Put( aBitmapItem
);
139 case drawing::FillStyle_NONE
: break;
145 rXFSet
.Put( XFillColorItem( OUString(), COL_LIGHTRED
) );
148 if(drawing::FillStyle_NONE
== eXFS
)
151 // fallback to solid fillmode when no fill mode is provided to have
152 // a reasonable shadow preview. The used color will be a set one or
153 // the default (currently blue8)
154 eXFS
= drawing::FillStyle_SOLID
;
157 rXFSet
.Put( XFillStyleItem( eXFS
) );
158 m_pCtlXRectPreview
->SetRectangleAttributes(aXFillAttr
.GetItemSet());
159 //aCtlXRectPreview.SetFillAttr( aXFillAttr );
161 m_pTsbShowShadow
->SetClickHdl( LINK( this, SvxShadowTabPage
, ClickShadowHdl_Impl
) );
162 Link
<> aLink
= LINK( this, SvxShadowTabPage
, ModifyShadowHdl_Impl
);
163 m_pLbShadowColor
->SetSelectHdl( aLink
);
164 m_pMtrTransparent
->SetModifyHdl( aLink
);
165 m_pMtrDistance
->SetModifyHdl( aLink
);
168 SvxShadowTabPage::~SvxShadowTabPage()
173 void SvxShadowTabPage::dispose()
175 m_pTsbShowShadow
.clear();
176 m_pGridShadow
.clear();
177 m_pCtlPosition
.clear();
178 m_pMtrDistance
.clear();
179 m_pLbShadowColor
.clear();
180 m_pMtrTransparent
.clear();
181 m_pCtlXRectPreview
.clear();
182 SvxTabPage::dispose();
185 void SvxShadowTabPage::Construct()
187 m_pLbShadowColor
->Fill( pColorList
);
191 m_pTsbShowShadow
->Disable();
192 m_pGridShadow
->Disable();
198 void SvxShadowTabPage::ActivatePage( const SfxItemSet
& rSet
)
203 SFX_ITEMSET_ARG (&rSet
,pPageTypeItem
,SfxUInt16Item
,SID_PAGE_TYPE
,false);
205 SetPageType(pPageTypeItem
->GetValue());
209 if( pColorList
.is() )
212 if( *pnColorListState
& ChangeType::CHANGED
||
213 *pnColorListState
& ChangeType::MODIFIED
)
215 if( *pnColorListState
& ChangeType::CHANGED
)
217 SvxAreaTabDialog
* pArea
= dynamic_cast< SvxAreaTabDialog
* >( GetParentDialog() );
220 pColorList
= pArea
->GetNewColorList();
224 SvxLineTabDialog
* pLine
= dynamic_cast< SvxLineTabDialog
* >( GetParentDialog() );
226 pColorList
= pLine
->GetNewColorList();
231 nPos
= m_pLbShadowColor
->GetSelectEntryPos();
232 m_pLbShadowColor
->Clear();
233 m_pLbShadowColor
->Fill( pColorList
);
234 nCount
= m_pLbShadowColor
->GetEntryCount();
236 ; // this case should not occur
237 else if( nCount
<= nPos
)
238 m_pLbShadowColor
->SelectEntryPos( 0 );
240 m_pLbShadowColor
->SelectEntryPos( nPos
);
242 SfxItemSet
rAttribs( rSet
);
243 // rSet contains shadow attributes too, but we want
244 // to use it for updating rectangle attributes only,
245 // so set the shadow to none here
246 SdrOnOffItem
aItem( makeSdrShadowItem( false ));
247 rAttribs
.Put( aItem
);
249 m_pCtlXRectPreview
->SetRectangleAttributes( rAttribs
);
250 ModifyShadowHdl_Impl( this );
252 nPageType
= PT_SHADOW
;
259 SfxTabPage::sfxpg
SvxShadowTabPage::DeactivatePage( SfxItemSet
* _pSet
)
262 FillItemSet( _pSet
);
269 bool SvxShadowTabPage::FillItemSet( SfxItemSet
* rAttrs
)
271 bool bModified
= false;
275 const SfxPoolItem
* pOld
= NULL
;
277 if( m_pTsbShowShadow
->IsValueChangedFromSaved() )
279 TriState eState
= m_pTsbShowShadow
->GetState();
280 assert(eState
!= TRISTATE_INDET
);
281 // given how m_pTsbShowShadow is set up and saved in Reset(),
282 // eState == TRISTATE_INDET would imply
283 // !IsValueChangedFromSaved()
284 SdrOnOffItem
aItem( makeSdrShadowItem(eState
== TRISTATE_TRUE
) );
285 pOld
= GetOldItem( *rAttrs
, SDRATTR_SHADOW
);
286 if ( !pOld
|| !( *static_cast<const SdrOnOffItem
*>(pOld
) == aItem
) )
288 rAttrs
->Put( aItem
);
294 // a bit intricate inquiry whether there was something changed,
295 // as the items can't be displayed directly on controls
296 sal_Int32 nX
= 0L, nY
= 0L;
297 sal_Int32 nXY
= GetCoreValue( *m_pMtrDistance
, ePoolUnit
);
299 switch( m_pCtlPosition
->GetActualRP() )
301 case RP_LT
: nX
= nY
= -nXY
; break;
302 case RP_MT
: nY
= -nXY
; break;
303 case RP_RT
: nX
= nXY
; nY
= -nXY
; break;
304 case RP_LM
: nX
= -nXY
; break;
305 case RP_RM
: nX
= nXY
; break;
306 case RP_LB
: nX
= -nXY
; nY
= nXY
; break;
307 case RP_MB
: nY
= nXY
; break;
308 case RP_RB
: nX
= nY
= nXY
; break;
312 // If the values of the shadow distances==SfxItemState::DONTCARE and the displayed
313 // string in the respective MetricField=="", then the comparison of the old
314 // and the new distance values would return a wrong result because in such a
315 // case the new distance values would matche the default values of the MetricField !!!!
316 if ( !m_pMtrDistance
->IsEmptyFieldValue() ||
317 rOutAttrs
.GetItemState( SDRATTR_SHADOWXDIST
) != SfxItemState::DONTCARE
||
318 rOutAttrs
.GetItemState( SDRATTR_SHADOWYDIST
) != SfxItemState::DONTCARE
)
320 sal_Int32 nOldX
= 9876543; // impossible value, so DontCare
321 sal_Int32 nOldY
= 9876543;
322 if( rOutAttrs
.GetItemState( SDRATTR_SHADOWXDIST
) != SfxItemState::DONTCARE
&&
323 rOutAttrs
.GetItemState( SDRATTR_SHADOWYDIST
) != SfxItemState::DONTCARE
)
325 nOldX
= static_cast<const SdrMetricItem
&>( rOutAttrs
.
326 Get( SDRATTR_SHADOWXDIST
) ).GetValue();
327 nOldY
= static_cast<const SdrMetricItem
&>( rOutAttrs
.
328 Get( SDRATTR_SHADOWYDIST
) ).GetValue();
330 SdrMetricItem
aXItem( makeSdrShadowXDistItem(nX
) );
331 pOld
= GetOldItem( *rAttrs
, SDRATTR_SHADOWXDIST
);
333 ( !pOld
|| !( *static_cast<const SdrMetricItem
*>(pOld
) == aXItem
) ) )
335 rAttrs
->Put( aXItem
);
338 SdrMetricItem
aYItem( makeSdrShadowYDistItem(nY
) );
339 pOld
= GetOldItem( *rAttrs
, SDRATTR_SHADOWYDIST
);
341 ( !pOld
|| !( *static_cast<const SdrMetricItem
*>(pOld
) == aYItem
) ) )
343 rAttrs
->Put( aYItem
);
349 sal_Int32 nPos
= m_pLbShadowColor
->GetSelectEntryPos();
350 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
&&
351 m_pLbShadowColor
->IsValueChangedFromSaved() )
353 XColorItem
aItem(makeSdrShadowColorItem(m_pLbShadowColor
->GetSelectEntryColor()));
354 pOld
= GetOldItem( *rAttrs
, SDRATTR_SHADOWCOLOR
);
355 if ( !pOld
|| !( *static_cast<const XColorItem
*>(pOld
) == aItem
) )
357 rAttrs
->Put( aItem
);
363 sal_uInt16 nVal
= (sal_uInt16
)m_pMtrTransparent
->GetValue();
364 if( m_pMtrTransparent
->IsValueChangedFromSaved() )
366 SdrPercentItem
aItem( makeSdrShadowTransparenceItem(nVal
) );
367 pOld
= GetOldItem( *rAttrs
, SDRATTR_SHADOWTRANSPARENCE
);
368 if ( !pOld
|| !( *static_cast<const SdrPercentItem
*>(pOld
) == aItem
) )
370 rAttrs
->Put( aItem
);
376 rAttrs
->Put (CntUInt16Item(SID_PAGE_TYPE
,nPageType
));
383 void SvxShadowTabPage::Reset( const SfxItemSet
* rAttrs
)
387 // all objects can have a shadow
388 // at the moment there are only 8 possible positions where a shadow can be set
390 // has a shadow been set?
391 if( rAttrs
->GetItemState( SDRATTR_SHADOW
) != SfxItemState::DONTCARE
)
393 m_pTsbShowShadow
->EnableTriState( false );
395 if( static_cast<const SdrOnOffItem
&>( rAttrs
->Get( SDRATTR_SHADOW
) ).GetValue() )
396 m_pTsbShowShadow
->SetState( TRISTATE_TRUE
);
399 m_pTsbShowShadow
->SetState( TRISTATE_FALSE
);
403 m_pTsbShowShadow
->SetState( TRISTATE_INDET
);
405 // distance (only 8 possible positions),
406 // so there is only one item evaluated
408 if( rAttrs
->GetItemState( SDRATTR_SHADOWXDIST
) != SfxItemState::DONTCARE
&&
409 rAttrs
->GetItemState( SDRATTR_SHADOWYDIST
) != SfxItemState::DONTCARE
)
411 sal_Int32 nX
= static_cast<const SdrMetricItem
&>( rAttrs
->Get( SDRATTR_SHADOWXDIST
) ).GetValue();
412 sal_Int32 nY
= static_cast<const SdrMetricItem
&>( rAttrs
->Get( SDRATTR_SHADOWYDIST
) ).GetValue();
415 SetMetricValue( *m_pMtrDistance
, nX
< 0L ? -nX
: nX
, ePoolUnit
);
417 SetMetricValue( *m_pMtrDistance
, nY
< 0L ? -nY
: nY
, ePoolUnit
);
419 // setting the shadow control
420 if ( nX
< 0L && nY
< 0L ) m_pCtlPosition
->SetActualRP( RP_LT
);
421 else if( nX
== 0L && nY
< 0L ) m_pCtlPosition
->SetActualRP( RP_MT
);
422 else if( nX
> 0L && nY
< 0L ) m_pCtlPosition
->SetActualRP( RP_RT
);
423 else if( nX
< 0L && nY
== 0L ) m_pCtlPosition
->SetActualRP( RP_LM
);
424 // there's no center point anymore
425 else if( nX
== 0L && nY
== 0L ) m_pCtlPosition
->SetActualRP( RP_RB
);
426 else if( nX
> 0L && nY
== 0L ) m_pCtlPosition
->SetActualRP( RP_RM
);
427 else if( nX
< 0L && nY
> 0L ) m_pCtlPosition
->SetActualRP( RP_LB
);
428 else if( nX
== 0L && nY
> 0L ) m_pCtlPosition
->SetActualRP( RP_MB
);
429 else if( nX
> 0L && nY
> 0L ) m_pCtlPosition
->SetActualRP( RP_RB
);
433 // determine default-distance
434 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
435 const SdrMetricItem
* pXDistItem
= static_cast<const SdrMetricItem
*>(&pPool
->GetDefaultItem(SDRATTR_SHADOWXDIST
));
436 const SdrMetricItem
* pYDistItem
= static_cast<const SdrMetricItem
*>(&pPool
->GetDefaultItem(SDRATTR_SHADOWYDIST
));
437 if (pXDistItem
&& pYDistItem
)
439 sal_Int32 nX
= pXDistItem
->GetValue();
440 sal_Int32 nY
= pYDistItem
->GetValue();
442 SetMetricValue( *m_pMtrDistance
, nX
< 0L ? -nX
: nX
, ePoolUnit
);
444 SetMetricValue( *m_pMtrDistance
, nY
< 0L ? -nY
: nY
, ePoolUnit
);
447 // Tristate, e. g. multiple objects have been marked of which some have a shadow and some don't.
448 // The text (which shall be displayed) of the MetricFields is set to "" and serves as an
449 // identification in the method FillItemSet for the fact that the distance value was NOT changed !!!!
450 m_pMtrDistance
->SetText( "" );
451 m_pCtlPosition
->SetActualRP( RP_MM
);
454 if( rAttrs
->GetItemState( SDRATTR_SHADOWCOLOR
) != SfxItemState::DONTCARE
)
456 m_pLbShadowColor
->SelectEntry( static_cast<const XColorItem
&>( rAttrs
->Get( SDRATTR_SHADOWCOLOR
) ).GetColorValue() );
459 m_pLbShadowColor
->SetNoSelection();
461 if( rAttrs
->GetItemState( SDRATTR_SHADOWTRANSPARENCE
) != SfxItemState::DONTCARE
)
463 sal_uInt16 nTransp
= static_cast<const SdrPercentItem
&>( rAttrs
->Get( SDRATTR_SHADOWTRANSPARENCE
) ).GetValue();
464 m_pMtrTransparent
->SetValue( nTransp
);
467 m_pMtrTransparent
->SetText( "" );
470 m_pMtrDistance
->SaveValue();
471 m_pLbShadowColor
->SaveValue();
472 m_pTsbShowShadow
->SaveValue();
474 // #66832# This field was not saved, but used to determine changes.
475 // Why? Seems to be the error.
477 m_pMtrTransparent
->SaveValue();
479 ClickShadowHdl_Impl( NULL
);
480 ModifyShadowHdl_Impl( NULL
);
486 VclPtr
<SfxTabPage
> SvxShadowTabPage::Create( vcl::Window
* pWindow
,
487 const SfxItemSet
* rAttrs
)
489 return VclPtr
<SvxShadowTabPage
>::Create( pWindow
, *rAttrs
);
494 IMPL_LINK_NOARG(SvxShadowTabPage
, ClickShadowHdl_Impl
)
496 if( m_pTsbShowShadow
->GetState() == TRISTATE_FALSE
)
498 m_pGridShadow
->Disable();
502 m_pGridShadow
->Enable();
504 m_pCtlPosition
->Invalidate();
506 ModifyShadowHdl_Impl( NULL
);
513 IMPL_LINK_NOARG(SvxShadowTabPage
, ModifyShadowHdl_Impl
)
515 if( m_pTsbShowShadow
->GetState() == TRISTATE_TRUE
)
516 rXFSet
.Put( XFillStyleItem( drawing::FillStyle_SOLID
) );
518 rXFSet
.Put( XFillStyleItem( drawing::FillStyle_NONE
) );
520 sal_Int32 nPos
= m_pLbShadowColor
->GetSelectEntryPos();
521 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
523 rXFSet
.Put( XFillColorItem( OUString(), m_pLbShadowColor
->GetSelectEntryColor() ) );
525 sal_uInt16 nVal
= (sal_uInt16
)m_pMtrTransparent
->GetValue();
526 XFillTransparenceItem
aItem( nVal
);
527 rXFSet
.Put( XFillTransparenceItem( aItem
) );
530 sal_Int32 nX
= 0L, nY
= 0L;
531 sal_Int32 nXY
= GetCoreValue( *m_pMtrDistance
, ePoolUnit
);
532 switch( m_pCtlPosition
->GetActualRP() )
534 case RP_LT
: nX
= nY
= -nXY
; break;
535 case RP_MT
: nY
= -nXY
; break;
536 case RP_RT
: nX
= nXY
; nY
= -nXY
; break;
537 case RP_LM
: nX
= -nXY
; break;
538 case RP_RM
: nX
= nXY
; break;
539 case RP_LB
: nX
= -nXY
; nY
= nXY
; break;
540 case RP_MB
: nY
= nXY
; break;
541 case RP_RB
: nX
= nY
= nXY
; break;
545 m_pCtlXRectPreview
->SetShadowPosition(Point(nX
, nY
));
547 m_pCtlXRectPreview
->SetShadowAttributes(aXFillAttr
.GetItemSet());
548 //aCtlXRectPreview.SetFillAttr( aXFillAttr );
549 m_pCtlXRectPreview
->Invalidate();
556 void SvxShadowTabPage::PointChanged( vcl::Window
* pWindow
, RECT_POINT eRcPt
)
561 ModifyShadowHdl_Impl( pWindow
);
564 void SvxShadowTabPage::PageCreated(const SfxAllItemSet
& aSet
)
566 SFX_ITEMSET_ARG (&aSet
,pColorListItem
,SvxColorListItem
,SID_COLOR_TABLE
,false);
567 SFX_ITEMSET_ARG (&aSet
,pPageTypeItem
,SfxUInt16Item
,SID_PAGE_TYPE
,false);
568 SFX_ITEMSET_ARG (&aSet
,pDlgTypeItem
,SfxUInt16Item
,SID_DLG_TYPE
,false);
571 SetColorList(pColorListItem
->GetColorList());
573 SetPageType(pPageTypeItem
->GetValue());
575 SetDlgType(pDlgTypeItem
->GetValue());
579 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */