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/colorbox.hxx>
23 #include <svx/dialogs.hrc>
24 #include <svx/svxids.hrc>
25 #include <svtools/unitconv.hxx>
27 #include <svx/xflclit.hxx>
28 #include <svx/xflgrit.hxx>
29 #include <svx/xflhtit.hxx>
30 #include <svx/xbtmpit.hxx>
31 #include <svx/xpool.hxx>
32 #include <svx/sdmetitm.hxx>
33 #include <svx/sdooitm.hxx>
34 #include <svx/sdprcitm.hxx>
35 #include <svx/sdshcitm.hxx>
36 #include <svx/sdshitm.hxx>
37 #include <svx/sdshtitm.hxx>
38 #include <svx/sdsxyitm.hxx>
39 #include <svx/drawitem.hxx>
40 #include <svx/xfltrit.hxx>
41 #include <cuitabarea.hxx>
42 #include <svx/dlgutil.hxx>
43 #include <cuitabline.hxx>
44 #include <svx/xlineit0.hxx>
45 #include <sfx2/request.hxx>
47 using namespace com::sun::star
;
49 const sal_uInt16
SvxShadowTabPage::pShadowRanges
[] =
52 SDRATTR_SHADOWTRANSPARENCE
,
55 SID_ATTR_SHADOW_TRANSPARENCE
,
56 SID_ATTR_SHADOW_YDISTANCE
,
60 SvxShadowTabPage::SvxShadowTabPage(TabPageParent pParent
, const SfxItemSet
& rInAttrs
)
61 : SvxTabPage(pParent
, "cui/ui/shadowtabpage.ui", "ShadowTabPage", rInAttrs
)
62 , m_rOutAttrs(rInAttrs
)
63 , m_pnColorListState(nullptr)
64 , m_nPageType(PageType::Area
)
66 , m_aXFillAttr(rInAttrs
.GetPool())
67 , m_rXFSet(m_aXFillAttr
.GetItemSet())
68 , m_aCtlPosition(this)
69 , m_xTsbShowShadow(m_xBuilder
->weld_check_button("TSB_SHOW_SHADOW"))
70 , m_xGridShadow(m_xBuilder
->weld_widget("gridSHADOW"))
71 , m_xMtrDistance(m_xBuilder
->weld_metric_spin_button("MTR_FLD_DISTANCE", FieldUnit::CM
))
72 , m_xLbShadowColor(new ColorListBox(m_xBuilder
->weld_menu_button("LB_SHADOW_COLOR"), pParent
.GetFrameWeld()))
73 , m_xMtrTransparent(m_xBuilder
->weld_metric_spin_button("MTR_SHADOW_TRANSPARENT", FieldUnit::PERCENT
))
74 , m_xCtlPosition(new weld::CustomWeld(*m_xBuilder
, "CTL_POSITION", m_aCtlPosition
))
75 , m_xCtlXRectPreview(new weld::CustomWeld(*m_xBuilder
, "CTL_COLOR_PREVIEW", m_aCtlXRectPreview
))
77 // this page needs ExchangeSupport
81 FieldUnit eFUnit
= GetModuleFieldUnit( rInAttrs
);
87 eFUnit
= FieldUnit::MM
;
89 default: ;//prevent warning
91 SetFieldUnit( *m_xMtrDistance
, eFUnit
);
94 SfxItemPool
* pPool
= m_rOutAttrs
.GetPool();
95 DBG_ASSERT( pPool
, "Where is the pool?" );
96 m_ePoolUnit
= pPool
->GetMetric( SDRATTR_SHADOWXDIST
);
98 // setting the output device
99 drawing::FillStyle eXFS
= drawing::FillStyle_SOLID
;
100 if( m_rOutAttrs
.GetItemState( XATTR_FILLSTYLE
) != SfxItemState::DONTCARE
)
102 eXFS
= static_cast<const XFillStyleItem
&>( m_rOutAttrs
.
103 Get( GetWhich( XATTR_FILLSTYLE
) ) ).GetValue();
106 case drawing::FillStyle_SOLID
:
107 if( SfxItemState::DONTCARE
!= m_rOutAttrs
.GetItemState( XATTR_FILLCOLOR
) )
109 m_rXFSet
.Put( m_rOutAttrs
.Get( XATTR_FILLCOLOR
) );
113 case drawing::FillStyle_GRADIENT
:
114 if( SfxItemState::DONTCARE
!= m_rOutAttrs
.GetItemState( XATTR_FILLGRADIENT
) )
116 m_rXFSet
.Put( m_rOutAttrs
.Get( XATTR_FILLGRADIENT
) );
120 case drawing::FillStyle_HATCH
:
121 if( SfxItemState::DONTCARE
!= m_rOutAttrs
.GetItemState( XATTR_FILLHATCH
) )
123 m_rXFSet
.Put( m_rOutAttrs
.Get( XATTR_FILLHATCH
) );
127 case drawing::FillStyle_BITMAP
:
129 if( SfxItemState::DONTCARE
!= m_rOutAttrs
.GetItemState( XATTR_FILLBITMAP
) )
131 m_rXFSet
.Put( m_rOutAttrs
.Get( XATTR_FILLBITMAP
) );
135 case drawing::FillStyle_NONE
: break;
141 m_rXFSet
.Put( XFillColorItem( OUString(), COL_LIGHTRED
) );
144 if(drawing::FillStyle_NONE
== eXFS
)
147 // fallback to solid fillmode when no fill mode is provided to have
148 // a reasonable shadow preview. The used color will be a set one or
149 // the default (currently blue8)
150 eXFS
= drawing::FillStyle_SOLID
;
153 m_rXFSet
.Put( XFillStyleItem( eXFS
) );
154 m_aCtlXRectPreview
.SetRectangleAttributes(m_aXFillAttr
.GetItemSet());
156 m_xTsbShowShadow
->connect_toggled(LINK( this, SvxShadowTabPage
, ClickShadowHdl_Impl
));
157 m_xLbShadowColor
->SetSelectHdl( LINK( this, SvxShadowTabPage
, SelectShadowHdl_Impl
) );
158 Link
<weld::MetricSpinButton
&,void> aLink
= LINK( this, SvxShadowTabPage
, ModifyShadowHdl_Impl
);
159 m_xMtrTransparent
->connect_value_changed(aLink
);
160 m_xMtrDistance
->connect_value_changed(aLink
);
163 SvxShadowTabPage::~SvxShadowTabPage()
168 void SvxShadowTabPage::dispose()
170 m_xCtlXRectPreview
.reset();
171 m_xLbShadowColor
.reset();
172 m_xCtlPosition
.reset();
173 SvxTabPage::dispose();
176 void SvxShadowTabPage::ActivatePage( const SfxItemSet
& rSet
)
178 const SfxUInt16Item
* pPageTypeItem
= rSet
.GetItem
<SfxUInt16Item
>(SID_PAGE_TYPE
, false);
180 SetPageType(static_cast<PageType
>(pPageTypeItem
->GetValue()));
182 if( m_nDlgType
== 0 )
184 if( m_pColorList
.is() )
187 if( *m_pnColorListState
& ChangeType::CHANGED
||
188 *m_pnColorListState
& ChangeType::MODIFIED
)
190 if( *m_pnColorListState
& ChangeType::CHANGED
)
192 SvxAreaTabDialog
* pArea
= dynamic_cast< SvxAreaTabDialog
* >( GetParentDialog() );
195 m_pColorList
= pArea
->GetNewColorList();
199 SvxLineTabDialog
* pLine
= dynamic_cast< SvxLineTabDialog
* >( GetParentDialog() );
201 m_pColorList
= pLine
->GetNewColorList();
205 SfxItemSet
rAttribs( rSet
);
206 // rSet contains shadow attributes too, but we want
207 // to use it for updating rectangle attributes only,
208 // so set the shadow to none here
209 SdrOnOffItem
aItem( makeSdrShadowItem( false ));
210 rAttribs
.Put( aItem
);
212 m_aCtlXRectPreview
.SetRectangleAttributes( rAttribs
);
213 ModifyShadowHdl_Impl( *m_xMtrTransparent
);
215 m_nPageType
= PageType::Shadow
;
221 DeactivateRC
SvxShadowTabPage::DeactivatePage( SfxItemSet
* _pSet
)
224 FillItemSet( _pSet
);
226 return DeactivateRC::LeavePage
;
230 bool SvxShadowTabPage::FillItemSet( SfxItemSet
* rAttrs
)
232 bool bModified
= false;
234 const SfxPoolItem
* pOld
= nullptr;
236 if (m_xTsbShowShadow
->get_state_changed_from_saved())
238 TriState eState
= m_xTsbShowShadow
->get_state();
239 assert(eState
!= TRISTATE_INDET
);
240 // given how m_xTsbShowShadow is set up and saved in Reset(),
241 // eState == TRISTATE_INDET would imply
242 // !IsValueChangedFromSaved()
243 SdrOnOffItem
aItem( makeSdrShadowItem(eState
== TRISTATE_TRUE
) );
244 pOld
= GetOldItem( *rAttrs
, SDRATTR_SHADOW
);
245 if ( !pOld
|| !( *static_cast<const SdrOnOffItem
*>(pOld
) == aItem
) )
247 rAttrs
->Put( aItem
);
253 // a bit intricate inquiry whether there was something changed,
254 // as the items can't be displayed directly on controls
255 sal_Int32 nX
= 0, nY
= 0;
256 sal_Int32 nXY
= GetCoreValue( *m_xMtrDistance
, m_ePoolUnit
);
258 switch (m_aCtlPosition
.GetActualRP())
260 case RectPoint::LT
: nX
= nY
= -nXY
; break;
261 case RectPoint::MT
: nY
= -nXY
; break;
262 case RectPoint::RT
: nX
= nXY
; nY
= -nXY
; break;
263 case RectPoint::LM
: nX
= -nXY
; break;
264 case RectPoint::RM
: nX
= nXY
; break;
265 case RectPoint::LB
: nX
= -nXY
; nY
= nXY
; break;
266 case RectPoint::MB
: nY
= nXY
; break;
267 case RectPoint::RB
: nX
= nY
= nXY
; break;
268 case RectPoint::MM
: break;
271 // If the values of the shadow distances==SfxItemState::DONTCARE and the displayed
272 // string in the respective MetricField=="", then the comparison of the old
273 // and the new distance values would return a wrong result because in such a
274 // case the new distance values would match the default values of the MetricField !!!!
275 if ( !m_xMtrDistance
->get_text().isEmpty() ||
276 m_rOutAttrs
.GetItemState( SDRATTR_SHADOWXDIST
) != SfxItemState::DONTCARE
||
277 m_rOutAttrs
.GetItemState( SDRATTR_SHADOWYDIST
) != SfxItemState::DONTCARE
)
279 sal_Int32 nOldX
= 9876543; // impossible value, so DontCare
280 sal_Int32 nOldY
= 9876543;
281 if( m_rOutAttrs
.GetItemState( SDRATTR_SHADOWXDIST
) != SfxItemState::DONTCARE
&&
282 m_rOutAttrs
.GetItemState( SDRATTR_SHADOWYDIST
) != SfxItemState::DONTCARE
)
284 nOldX
= m_rOutAttrs
.Get( SDRATTR_SHADOWXDIST
).GetValue();
285 nOldY
= m_rOutAttrs
.Get( SDRATTR_SHADOWYDIST
).GetValue();
287 SdrMetricItem
aXItem( makeSdrShadowXDistItem(nX
) );
288 pOld
= GetOldItem( *rAttrs
, SDRATTR_SHADOWXDIST
);
290 ( !pOld
|| !( *static_cast<const SdrMetricItem
*>(pOld
) == aXItem
) ) )
292 rAttrs
->Put( aXItem
);
295 SdrMetricItem
aYItem( makeSdrShadowYDistItem(nY
) );
296 pOld
= GetOldItem( *rAttrs
, SDRATTR_SHADOWYDIST
);
298 ( !pOld
|| !( *static_cast<const SdrMetricItem
*>(pOld
) == aYItem
) ) )
300 rAttrs
->Put( aYItem
);
307 XColorItem
aItem(makeSdrShadowColorItem(m_xLbShadowColor
->GetSelectEntryColor()));
308 pOld
= GetOldItem( *rAttrs
, SDRATTR_SHADOWCOLOR
);
309 if ( !pOld
|| !( *static_cast<const XColorItem
*>(pOld
) == aItem
) )
311 rAttrs
->Put( aItem
);
317 sal_uInt16 nVal
= static_cast<sal_uInt16
>(m_xMtrTransparent
->get_value(FieldUnit::PERCENT
));
318 if (m_xMtrTransparent
->get_value_changed_from_saved())
320 SdrPercentItem
aItem( makeSdrShadowTransparenceItem(nVal
) );
321 pOld
= GetOldItem( *rAttrs
, SDRATTR_SHADOWTRANSPARENCE
);
322 if ( !pOld
|| !( *static_cast<const SdrPercentItem
*>(pOld
) == aItem
) )
324 rAttrs
->Put( aItem
);
329 rAttrs
->Put (CntUInt16Item(SID_PAGE_TYPE
, static_cast<sal_uInt16
>(m_nPageType
)));
335 void SvxShadowTabPage::Reset( const SfxItemSet
* rAttrs
)
337 // all objects can have a shadow
338 // at the moment there are only 8 possible positions where a shadow can be set
340 // has a shadow been set?
341 if( rAttrs
->GetItemState( SDRATTR_SHADOW
) != SfxItemState::DONTCARE
)
343 if( rAttrs
->Get( SDRATTR_SHADOW
).GetValue() )
344 m_xTsbShowShadow
->set_state(TRISTATE_TRUE
);
347 m_xTsbShowShadow
->set_state(TRISTATE_FALSE
);
351 m_xTsbShowShadow
->set_state(TRISTATE_INDET
);
353 // distance (only 8 possible positions),
354 // so there is only one item evaluated
356 if( rAttrs
->GetItemState( SDRATTR_SHADOWXDIST
) != SfxItemState::DONTCARE
&&
357 rAttrs
->GetItemState( SDRATTR_SHADOWYDIST
) != SfxItemState::DONTCARE
)
359 sal_Int32 nX
= rAttrs
->Get( SDRATTR_SHADOWXDIST
).GetValue();
360 sal_Int32 nY
= rAttrs
->Get( SDRATTR_SHADOWYDIST
).GetValue();
363 SetMetricValue( *m_xMtrDistance
, nX
< 0 ? -nX
: nX
, m_ePoolUnit
);
365 SetMetricValue( *m_xMtrDistance
, nY
< 0 ? -nY
: nY
, m_ePoolUnit
);
367 // setting the shadow control
368 if ( nX
< 0 && nY
< 0 ) m_aCtlPosition
.SetActualRP( RectPoint::LT
);
369 else if( nX
== 0 && nY
< 0 ) m_aCtlPosition
.SetActualRP( RectPoint::MT
);
370 else if( nX
> 0 && nY
< 0 ) m_aCtlPosition
.SetActualRP( RectPoint::RT
);
371 else if( nX
< 0 && nY
== 0 ) m_aCtlPosition
.SetActualRP( RectPoint::LM
);
372 // there's no center point anymore
373 else if( nX
== 0 && nY
== 0 ) m_aCtlPosition
.SetActualRP( RectPoint::RB
);
374 else if( nX
> 0 && nY
== 0 ) m_aCtlPosition
.SetActualRP( RectPoint::RM
);
375 else if( nX
< 0 && nY
> 0 ) m_aCtlPosition
.SetActualRP( RectPoint::LB
);
376 else if( nX
== 0 && nY
> 0 ) m_aCtlPosition
.SetActualRP( RectPoint::MB
);
377 else if( nX
> 0 && nY
> 0 ) m_aCtlPosition
.SetActualRP( RectPoint::RB
);
381 // determine default-distance
382 SfxItemPool
* pPool
= m_rOutAttrs
.GetPool();
384 sal_Int32 n
= pPool
->GetDefaultItem(SDRATTR_SHADOWXDIST
).GetValue();
386 n
= pPool
->GetDefaultItem(SDRATTR_SHADOWYDIST
).GetValue();
387 SetMetricValue(*m_xMtrDistance
, std::abs(n
), m_ePoolUnit
);
390 // Tristate, e. g. multiple objects have been marked of which some have a shadow and some don't.
391 // The text (which shall be displayed) of the MetricFields is set to "" and serves as an
392 // identification in the method FillItemSet for the fact that the distance value was NOT changed !!!!
393 m_xMtrDistance
->set_text( "" );
394 m_aCtlPosition
.SetActualRP( RectPoint::MM
);
397 if( rAttrs
->GetItemState( SDRATTR_SHADOWCOLOR
) != SfxItemState::DONTCARE
)
399 m_xLbShadowColor
->SelectEntry( rAttrs
->Get( SDRATTR_SHADOWCOLOR
).GetColorValue() );
402 m_xLbShadowColor
->SetNoSelection();
404 if( rAttrs
->GetItemState( SDRATTR_SHADOWTRANSPARENCE
) != SfxItemState::DONTCARE
)
406 sal_uInt16 nTransp
= rAttrs
->Get( SDRATTR_SHADOWTRANSPARENCE
).GetValue();
407 m_xMtrTransparent
->set_value(nTransp
, FieldUnit::PERCENT
);
410 m_xMtrTransparent
->set_text("");
413 m_xMtrDistance
->save_value();
414 m_xLbShadowColor
->SaveValue();
415 m_xTsbShowShadow
->save_state();
417 // #66832# This field was not saved, but used to determine changes.
418 // Why? Seems to be the error.
420 m_xMtrTransparent
->save_value();
422 ClickShadowHdl_Impl(*m_xTsbShowShadow
);
423 ModifyShadowHdl_Impl(*m_xMtrTransparent
);
426 VclPtr
<SfxTabPage
> SvxShadowTabPage::Create( TabPageParent pParent
,
427 const SfxItemSet
* rAttrs
)
429 return VclPtr
<SvxShadowTabPage
>::Create( pParent
, *rAttrs
);
432 IMPL_LINK_NOARG(SvxShadowTabPage
, ClickShadowHdl_Impl
, weld::ToggleButton
&, void)
434 if (m_xTsbShowShadow
->get_state() == TRISTATE_FALSE
)
436 m_xGridShadow
->set_sensitive(false);
437 m_xCtlPosition
->set_sensitive(false);
441 m_xGridShadow
->set_sensitive(true);
442 m_xCtlPosition
->set_sensitive(true);
444 m_aCtlPosition
.Invalidate();
445 ModifyShadowHdl_Impl(*m_xMtrTransparent
);
448 IMPL_LINK_NOARG(SvxShadowTabPage
, SelectShadowHdl_Impl
, ColorListBox
&, void)
450 ModifyShadowHdl_Impl(*m_xMtrTransparent
);
453 IMPL_LINK_NOARG(SvxShadowTabPage
, ModifyShadowHdl_Impl
, weld::MetricSpinButton
&, void)
455 if (m_xTsbShowShadow
->get_state() == TRISTATE_TRUE
)
456 m_rXFSet
.Put( XFillStyleItem( drawing::FillStyle_SOLID
) );
458 m_rXFSet
.Put( XFillStyleItem( drawing::FillStyle_NONE
) );
460 m_rXFSet
.Put( XFillColorItem( OUString(), m_xLbShadowColor
->GetSelectEntryColor() ) );
461 sal_uInt16 nVal
= static_cast<sal_uInt16
>(m_xMtrTransparent
->get_value(FieldUnit::PERCENT
));
462 m_rXFSet
.Put( XFillTransparenceItem( nVal
) );
465 sal_Int32 nX
= 0, nY
= 0;
466 sal_Int32 nXY
= GetCoreValue( *m_xMtrDistance
, m_ePoolUnit
);
467 switch( m_aCtlPosition
.GetActualRP() )
469 case RectPoint::LT
: nX
= nY
= -nXY
; break;
470 case RectPoint::MT
: nY
= -nXY
; break;
471 case RectPoint::RT
: nX
= nXY
; nY
= -nXY
; break;
472 case RectPoint::LM
: nX
= -nXY
; break;
473 case RectPoint::RM
: nX
= nXY
; break;
474 case RectPoint::LB
: nX
= -nXY
; nY
= nXY
; break;
475 case RectPoint::MB
: nY
= nXY
; break;
476 case RectPoint::RB
: nX
= nY
= nXY
; break;
477 case RectPoint::MM
: break;
480 m_aCtlXRectPreview
.SetShadowPosition(Point(nX
, nY
));
482 m_aCtlXRectPreview
.SetShadowAttributes(m_aXFillAttr
.GetItemSet());
483 m_aCtlXRectPreview
.Invalidate();
486 void SvxShadowTabPage::PointChanged( weld::DrawingArea
*, RectPoint
)
489 ModifyShadowHdl_Impl( *m_xMtrTransparent
);
492 void SvxShadowTabPage::PageCreated(const SfxAllItemSet
& aSet
)
494 const SvxColorListItem
* pColorListItem
= aSet
.GetItem
<SvxColorListItem
>(SID_COLOR_TABLE
, false);
495 const SfxUInt16Item
* pPageTypeItem
= aSet
.GetItem
<SfxUInt16Item
>(SID_PAGE_TYPE
, false);
496 const SfxUInt16Item
* pDlgTypeItem
= aSet
.GetItem
<SfxUInt16Item
>(SID_DLG_TYPE
, false);
499 SetColorList(pColorListItem
->GetColorList());
501 SetPageType(static_cast<PageType
>(pPageTypeItem
->GetValue()));
503 SetDlgType(pDlgTypeItem
->GetValue());
506 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */