bump product version to 6.4.0.3
[LibreOffice.git] / cui / source / tabpages / tpshadow.cxx
blob1c8c5051d0b96c874e10c94f22e6b7b8f34ffa5a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svx/colorbox.hxx>
21 #include <svx/svxids.hrc>
22 #include <svtools/unitconv.hxx>
24 #include <svx/xfillit0.hxx>
25 #include <svx/xflclit.hxx>
26 #include <svx/xflgrit.hxx>
27 #include <svx/xflhtit.hxx>
28 #include <svx/xbtmpit.hxx>
29 #include <svx/sdmetitm.hxx>
30 #include <svx/sdooitm.hxx>
31 #include <svx/sdprcitm.hxx>
32 #include <svx/sdshcitm.hxx>
33 #include <svx/sdshitm.hxx>
34 #include <svx/sdshtitm.hxx>
35 #include <svx/sdsxyitm.hxx>
36 #include <svx/drawitem.hxx>
37 #include <svx/xfltrit.hxx>
38 #include <cuitabarea.hxx>
39 #include <svx/dlgutil.hxx>
40 #include <cuitabline.hxx>
42 using namespace com::sun::star;
44 const sal_uInt16 SvxShadowTabPage::pShadowRanges[] =
46 SDRATTR_SHADOWCOLOR,
47 SDRATTR_SHADOWTRANSPARENCE,
48 SID_ATTR_FILL_SHADOW,
49 SID_ATTR_FILL_SHADOW,
50 SID_ATTR_SHADOW_TRANSPARENCE,
51 SID_ATTR_SHADOW_YDISTANCE,
55 SvxShadowTabPage::SvxShadowTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
56 : SvxTabPage(pPage, pController, "cui/ui/shadowtabpage.ui", "ShadowTabPage", rInAttrs)
57 , m_rOutAttrs(rInAttrs)
58 , m_pnColorListState(nullptr)
59 , m_nPageType(PageType::Area)
60 , m_nDlgType(0)
61 , m_aXFillAttr(rInAttrs.GetPool())
62 , m_rXFSet(m_aXFillAttr.GetItemSet())
63 , m_aCtlPosition(this)
64 , m_xTsbShowShadow(m_xBuilder->weld_check_button("TSB_SHOW_SHADOW"))
65 , m_xGridShadow(m_xBuilder->weld_widget("gridSHADOW"))
66 , m_xMtrDistance(m_xBuilder->weld_metric_spin_button("MTR_FLD_DISTANCE", FieldUnit::CM))
67 , m_xLbShadowColor(new ColorListBox(m_xBuilder->weld_menu_button("LB_SHADOW_COLOR"), pController->getDialog()))
68 , m_xMtrTransparent(m_xBuilder->weld_metric_spin_button("MTR_SHADOW_TRANSPARENT", FieldUnit::PERCENT))
69 , m_xCtlPosition(new weld::CustomWeld(*m_xBuilder, "CTL_POSITION", m_aCtlPosition))
70 , m_xCtlXRectPreview(new weld::CustomWeld(*m_xBuilder, "CTL_COLOR_PREVIEW", m_aCtlXRectPreview))
72 // this page needs ExchangeSupport
73 SetExchangeSupport();
75 // adjust metric
76 FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
78 switch ( eFUnit )
80 case FieldUnit::M:
81 case FieldUnit::KM:
82 eFUnit = FieldUnit::MM;
83 break;
84 default: ;//prevent warning
86 SetFieldUnit( *m_xMtrDistance, eFUnit );
88 // determine PoolUnit
89 SfxItemPool* pPool = m_rOutAttrs.GetPool();
90 DBG_ASSERT( pPool, "Where is the pool?" );
91 m_ePoolUnit = pPool->GetMetric( SDRATTR_SHADOWXDIST );
93 // setting the output device
94 drawing::FillStyle eXFS = drawing::FillStyle_SOLID;
95 if( m_rOutAttrs.GetItemState( XATTR_FILLSTYLE ) != SfxItemState::DONTCARE )
97 eXFS = static_cast<const XFillStyleItem&>( m_rOutAttrs.
98 Get( GetWhich( XATTR_FILLSTYLE ) ) ).GetValue();
99 switch( eXFS )
101 case drawing::FillStyle_SOLID:
102 if( SfxItemState::DONTCARE != m_rOutAttrs.GetItemState( XATTR_FILLCOLOR ) )
104 m_rXFSet.Put( m_rOutAttrs.Get( XATTR_FILLCOLOR ) );
106 break;
108 case drawing::FillStyle_GRADIENT:
109 if( SfxItemState::DONTCARE != m_rOutAttrs.GetItemState( XATTR_FILLGRADIENT ) )
111 m_rXFSet.Put( m_rOutAttrs.Get( XATTR_FILLGRADIENT ) );
113 break;
115 case drawing::FillStyle_HATCH:
116 if( SfxItemState::DONTCARE != m_rOutAttrs.GetItemState( XATTR_FILLHATCH ) )
118 m_rXFSet.Put( m_rOutAttrs.Get( XATTR_FILLHATCH ) );
120 break;
122 case drawing::FillStyle_BITMAP:
124 if( SfxItemState::DONTCARE != m_rOutAttrs.GetItemState( XATTR_FILLBITMAP ) )
126 m_rXFSet.Put( m_rOutAttrs.Get( XATTR_FILLBITMAP ) );
129 break;
130 case drawing::FillStyle_NONE : break;
131 default: break;
134 else
136 m_rXFSet.Put( XFillColorItem( OUString(), COL_LIGHTRED ) );
139 if(drawing::FillStyle_NONE == eXFS)
141 // #i96350#
142 // fallback to solid fillmode when no fill mode is provided to have
143 // a reasonable shadow preview. The used color will be a set one or
144 // the default (currently blue8)
145 eXFS = drawing::FillStyle_SOLID;
148 m_rXFSet.Put( XFillStyleItem( eXFS ) );
149 m_aCtlXRectPreview.SetRectangleAttributes(m_aXFillAttr.GetItemSet());
151 m_xTsbShowShadow->connect_toggled(LINK( this, SvxShadowTabPage, ClickShadowHdl_Impl));
152 m_xLbShadowColor->SetSelectHdl( LINK( this, SvxShadowTabPage, SelectShadowHdl_Impl ) );
153 Link<weld::MetricSpinButton&,void> aLink = LINK( this, SvxShadowTabPage, ModifyShadowHdl_Impl );
154 m_xMtrTransparent->connect_value_changed(aLink);
155 m_xMtrDistance->connect_value_changed(aLink);
158 SvxShadowTabPage::~SvxShadowTabPage()
160 m_xCtlXRectPreview.reset();
161 m_xLbShadowColor.reset();
162 m_xCtlPosition.reset();
165 void SvxShadowTabPage::ActivatePage( const SfxItemSet& rSet )
167 const SfxUInt16Item* pPageTypeItem = rSet.GetItem<SfxUInt16Item>(SID_PAGE_TYPE, false);
168 if (pPageTypeItem)
169 SetPageType(static_cast<PageType>(pPageTypeItem->GetValue()));
171 if( m_nDlgType == 0 )
173 if( m_pColorList.is() )
175 // ColorList
176 if( *m_pnColorListState & ChangeType::CHANGED ||
177 *m_pnColorListState & ChangeType::MODIFIED )
179 if( *m_pnColorListState & ChangeType::CHANGED )
181 SvxAreaTabDialog* pArea = dynamic_cast<SvxAreaTabDialog*>(GetDialogController());
182 if( pArea )
184 m_pColorList = pArea->GetNewColorList();
186 else
188 SvxLineTabDialog* pLine = dynamic_cast<SvxLineTabDialog*>(GetDialogController());
189 if( pLine )
190 m_pColorList = pLine->GetNewColorList();
194 SfxItemSet rAttribs( rSet );
195 // rSet contains shadow attributes too, but we want
196 // to use it for updating rectangle attributes only,
197 // so set the shadow to none here
198 SdrOnOffItem aItem( makeSdrShadowItem( false ));
199 rAttribs.Put( aItem );
201 m_aCtlXRectPreview.SetRectangleAttributes( rAttribs );
202 ModifyShadowHdl_Impl( *m_xMtrTransparent );
204 m_nPageType = PageType::Shadow;
210 DeactivateRC SvxShadowTabPage::DeactivatePage( SfxItemSet* _pSet )
212 if( _pSet )
213 FillItemSet( _pSet );
215 return DeactivateRC::LeavePage;
219 bool SvxShadowTabPage::FillItemSet( SfxItemSet* rAttrs )
221 bool bModified = false;
223 const SfxPoolItem* pOld = nullptr;
225 if (m_xTsbShowShadow->get_state_changed_from_saved())
227 TriState eState = m_xTsbShowShadow->get_state();
228 assert(eState != TRISTATE_INDET);
229 // given how m_xTsbShowShadow is set up and saved in Reset(),
230 // eState == TRISTATE_INDET would imply
231 // !IsValueChangedFromSaved()
232 SdrOnOffItem aItem( makeSdrShadowItem(eState == TRISTATE_TRUE) );
233 pOld = GetOldItem( *rAttrs, SDRATTR_SHADOW );
234 if ( !pOld || !( *static_cast<const SdrOnOffItem*>(pOld) == aItem ) )
236 rAttrs->Put( aItem );
237 bModified = true;
241 // shadow removal
242 // a bit intricate inquiry whether there was something changed,
243 // as the items can't be displayed directly on controls
244 sal_Int32 nX = 0, nY = 0;
245 sal_Int32 nXY = GetCoreValue( *m_xMtrDistance, m_ePoolUnit );
247 switch (m_aCtlPosition.GetActualRP())
249 case RectPoint::LT: nX = nY = -nXY; break;
250 case RectPoint::MT: nY = -nXY; break;
251 case RectPoint::RT: nX = nXY; nY = -nXY; break;
252 case RectPoint::LM: nX = -nXY; break;
253 case RectPoint::RM: nX = nXY; break;
254 case RectPoint::LB: nX = -nXY; nY = nXY; break;
255 case RectPoint::MB: nY = nXY; break;
256 case RectPoint::RB: nX = nY = nXY; break;
257 case RectPoint::MM: break;
260 // If the values of the shadow distances==SfxItemState::DONTCARE and the displayed
261 // string in the respective MetricField=="", then the comparison of the old
262 // and the new distance values would return a wrong result because in such a
263 // case the new distance values would match the default values of the MetricField !!!!
264 if ( !m_xMtrDistance->get_text().isEmpty() ||
265 m_rOutAttrs.GetItemState( SDRATTR_SHADOWXDIST ) != SfxItemState::DONTCARE ||
266 m_rOutAttrs.GetItemState( SDRATTR_SHADOWYDIST ) != SfxItemState::DONTCARE )
268 sal_Int32 nOldX = 9876543; // impossible value, so DontCare
269 sal_Int32 nOldY = 9876543;
270 if( m_rOutAttrs.GetItemState( SDRATTR_SHADOWXDIST ) != SfxItemState::DONTCARE &&
271 m_rOutAttrs.GetItemState( SDRATTR_SHADOWYDIST ) != SfxItemState::DONTCARE )
273 nOldX = m_rOutAttrs.Get( SDRATTR_SHADOWXDIST ).GetValue();
274 nOldY = m_rOutAttrs.Get( SDRATTR_SHADOWYDIST ).GetValue();
276 SdrMetricItem aXItem( makeSdrShadowXDistItem(nX) );
277 pOld = GetOldItem( *rAttrs, SDRATTR_SHADOWXDIST );
278 if ( nX != nOldX &&
279 ( !pOld || !( *static_cast<const SdrMetricItem*>(pOld) == aXItem ) ) )
281 rAttrs->Put( aXItem );
282 bModified = true;
284 SdrMetricItem aYItem( makeSdrShadowYDistItem(nY) );
285 pOld = GetOldItem( *rAttrs, SDRATTR_SHADOWYDIST );
286 if ( nY != nOldY &&
287 ( !pOld || !( *static_cast<const SdrMetricItem*>(pOld) == aYItem ) ) )
289 rAttrs->Put( aYItem );
290 bModified = true;
294 // ShadowColor
296 XColorItem aItem(makeSdrShadowColorItem(m_xLbShadowColor->GetSelectEntryColor()));
297 pOld = GetOldItem( *rAttrs, SDRATTR_SHADOWCOLOR );
298 if ( !pOld || !( *static_cast<const XColorItem*>(pOld) == aItem ) )
300 rAttrs->Put( aItem );
301 bModified = true;
305 // transparency
306 sal_uInt16 nVal = static_cast<sal_uInt16>(m_xMtrTransparent->get_value(FieldUnit::PERCENT));
307 if (m_xMtrTransparent->get_value_changed_from_saved())
309 SdrPercentItem aItem( makeSdrShadowTransparenceItem(nVal) );
310 pOld = GetOldItem( *rAttrs, SDRATTR_SHADOWTRANSPARENCE );
311 if ( !pOld || !( *static_cast<const SdrPercentItem*>(pOld) == aItem ) )
313 rAttrs->Put( aItem );
314 bModified = true;
318 rAttrs->Put (CntUInt16Item(SID_PAGE_TYPE, static_cast<sal_uInt16>(m_nPageType)));
320 return bModified;
324 void SvxShadowTabPage::Reset( const SfxItemSet* rAttrs )
326 // all objects can have a shadow
327 // at the moment there are only 8 possible positions where a shadow can be set
329 // has a shadow been set?
330 if( rAttrs->GetItemState( SDRATTR_SHADOW ) != SfxItemState::DONTCARE )
332 if( rAttrs->Get( SDRATTR_SHADOW ).GetValue() )
333 m_xTsbShowShadow->set_state(TRISTATE_TRUE);
334 else
336 m_xTsbShowShadow->set_state(TRISTATE_FALSE);
339 else
340 m_xTsbShowShadow->set_state(TRISTATE_INDET);
342 // distance (only 8 possible positions),
343 // so there is only one item evaluated
345 if( rAttrs->GetItemState( SDRATTR_SHADOWXDIST ) != SfxItemState::DONTCARE &&
346 rAttrs->GetItemState( SDRATTR_SHADOWYDIST ) != SfxItemState::DONTCARE )
348 sal_Int32 nX = rAttrs->Get( SDRATTR_SHADOWXDIST ).GetValue();
349 sal_Int32 nY = rAttrs->Get( SDRATTR_SHADOWYDIST ).GetValue();
351 if( nX != 0 )
352 SetMetricValue( *m_xMtrDistance, nX < 0 ? -nX : nX, m_ePoolUnit );
353 else
354 SetMetricValue( *m_xMtrDistance, nY < 0 ? -nY : nY, m_ePoolUnit );
356 // setting the shadow control
357 if ( nX < 0 && nY < 0 ) m_aCtlPosition.SetActualRP( RectPoint::LT );
358 else if( nX == 0 && nY < 0 ) m_aCtlPosition.SetActualRP( RectPoint::MT );
359 else if( nX > 0 && nY < 0 ) m_aCtlPosition.SetActualRP( RectPoint::RT );
360 else if( nX < 0 && nY == 0 ) m_aCtlPosition.SetActualRP( RectPoint::LM );
361 // there's no center point anymore
362 else if( nX == 0 && nY == 0 ) m_aCtlPosition.SetActualRP( RectPoint::RB );
363 else if( nX > 0 && nY == 0 ) m_aCtlPosition.SetActualRP( RectPoint::RM );
364 else if( nX < 0 && nY > 0 ) m_aCtlPosition.SetActualRP( RectPoint::LB );
365 else if( nX == 0 && nY > 0 ) m_aCtlPosition.SetActualRP( RectPoint::MB );
366 else if( nX > 0 && nY > 0 ) m_aCtlPosition.SetActualRP( RectPoint::RB );
368 else
370 // determine default-distance
371 SfxItemPool* pPool = m_rOutAttrs.GetPool();
373 sal_Int32 n = pPool->GetDefaultItem(SDRATTR_SHADOWXDIST).GetValue();
374 if (n == 0)
375 n = pPool->GetDefaultItem(SDRATTR_SHADOWYDIST).GetValue();
376 SetMetricValue(*m_xMtrDistance, std::abs(n), m_ePoolUnit);
379 // Tristate, e. g. multiple objects have been marked of which some have a shadow and some don't.
380 // The text (which shall be displayed) of the MetricFields is set to "" and serves as an
381 // identification in the method FillItemSet for the fact that the distance value was NOT changed !!!!
382 m_xMtrDistance->set_text( "" );
383 m_aCtlPosition.SetActualRP( RectPoint::MM );
386 if( rAttrs->GetItemState( SDRATTR_SHADOWCOLOR ) != SfxItemState::DONTCARE )
388 m_xLbShadowColor->SelectEntry( rAttrs->Get( SDRATTR_SHADOWCOLOR ).GetColorValue() );
390 else
391 m_xLbShadowColor->SetNoSelection();
393 if( rAttrs->GetItemState( SDRATTR_SHADOWTRANSPARENCE ) != SfxItemState::DONTCARE )
395 sal_uInt16 nTransp = rAttrs->Get( SDRATTR_SHADOWTRANSPARENCE ).GetValue();
396 m_xMtrTransparent->set_value(nTransp, FieldUnit::PERCENT);
398 else
399 m_xMtrTransparent->set_text("");
401 //aCtlPosition
402 m_xMtrDistance->save_value();
403 m_xLbShadowColor->SaveValue();
404 m_xTsbShowShadow->save_state();
406 // #66832# This field was not saved, but used to determine changes.
407 // Why? Seems to be the error.
408 // It IS the error.
409 m_xMtrTransparent->save_value();
411 ClickShadowHdl_Impl(*m_xTsbShowShadow);
412 ModifyShadowHdl_Impl(*m_xMtrTransparent);
415 std::unique_ptr<SfxTabPage> SvxShadowTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
416 const SfxItemSet* rAttrs )
418 return std::make_unique<SvxShadowTabPage>(pPage, pController, *rAttrs);
421 IMPL_LINK_NOARG(SvxShadowTabPage, ClickShadowHdl_Impl, weld::ToggleButton&, void)
423 if (m_xTsbShowShadow->get_state() == TRISTATE_FALSE)
425 m_xGridShadow->set_sensitive(false);
426 m_xCtlPosition->set_sensitive(false);
428 else
430 m_xGridShadow->set_sensitive(true);
431 m_xCtlPosition->set_sensitive(true);
433 m_aCtlPosition.Invalidate();
434 ModifyShadowHdl_Impl(*m_xMtrTransparent);
437 IMPL_LINK_NOARG(SvxShadowTabPage, SelectShadowHdl_Impl, ColorListBox&, void)
439 ModifyShadowHdl_Impl(*m_xMtrTransparent);
442 IMPL_LINK_NOARG(SvxShadowTabPage, ModifyShadowHdl_Impl, weld::MetricSpinButton&, void)
444 if (m_xTsbShowShadow->get_state() == TRISTATE_TRUE)
445 m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
446 else
447 m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) );
449 m_rXFSet.Put( XFillColorItem( OUString(), m_xLbShadowColor->GetSelectEntryColor() ) );
450 sal_uInt16 nVal = static_cast<sal_uInt16>(m_xMtrTransparent->get_value(FieldUnit::PERCENT));
451 m_rXFSet.Put( XFillTransparenceItem( nVal ) );
453 // shadow removal
454 sal_Int32 nX = 0, nY = 0;
455 sal_Int32 nXY = GetCoreValue( *m_xMtrDistance, m_ePoolUnit );
456 switch( m_aCtlPosition.GetActualRP() )
458 case RectPoint::LT: nX = nY = -nXY; break;
459 case RectPoint::MT: nY = -nXY; break;
460 case RectPoint::RT: nX = nXY; nY = -nXY; break;
461 case RectPoint::LM: nX = -nXY; break;
462 case RectPoint::RM: nX = nXY; break;
463 case RectPoint::LB: nX = -nXY; nY = nXY; break;
464 case RectPoint::MB: nY = nXY; break;
465 case RectPoint::RB: nX = nY = nXY; break;
466 case RectPoint::MM: break;
469 m_aCtlXRectPreview.SetShadowPosition(Point(nX, nY));
471 m_aCtlXRectPreview.SetShadowAttributes(m_aXFillAttr.GetItemSet());
472 m_aCtlXRectPreview.Invalidate();
475 void SvxShadowTabPage::PointChanged( weld::DrawingArea*, RectPoint )
477 // repaint shadow
478 ModifyShadowHdl_Impl( *m_xMtrTransparent );
481 void SvxShadowTabPage::PageCreated(const SfxAllItemSet& aSet)
483 const SvxColorListItem* pColorListItem = aSet.GetItem<SvxColorListItem>(SID_COLOR_TABLE, false);
484 const SfxUInt16Item* pPageTypeItem = aSet.GetItem<SfxUInt16Item>(SID_PAGE_TYPE, false);
485 const SfxUInt16Item* pDlgTypeItem = aSet.GetItem<SfxUInt16Item>(SID_DLG_TYPE, false);
487 if (pColorListItem)
488 SetColorList(pColorListItem->GetColorList());
489 if (pPageTypeItem)
490 SetPageType(static_cast<PageType>(pPageTypeItem->GetValue()));
491 if (pDlgTypeItem)
492 SetDlgType(pDlgTypeItem->GetValue());
495 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */