Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / cui / source / tabpages / tpshadow.cxx
blob795a57f13dde42cc224cd222314e30f3983c1a08
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 WhichRangesContainer SvxShadowTabPage::pShadowRanges(svl::Items<
45 SDRATTR_SHADOWCOLOR, SDRATTR_SHADOWTRANSPARENCE,
46 SDRATTR_SHADOWBLUR, SDRATTR_SHADOWBLUR,
47 SID_ATTR_FILL_SHADOW, SID_ATTR_FILL_SHADOW,
48 SID_ATTR_SHADOW_BLUR, SID_ATTR_SHADOW_BLUR,
49 SID_ATTR_SHADOW_TRANSPARENCE, SID_ATTR_SHADOW_YDISTANCE
50 >);
52 SvxShadowTabPage::SvxShadowTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
53 : SvxTabPage(pPage, pController, "cui/ui/shadowtabpage.ui", "ShadowTabPage", rInAttrs)
54 , m_rOutAttrs(rInAttrs)
55 , m_pnColorListState(nullptr)
56 , m_nPageType(PageType::Area)
57 , m_nDlgType(0)
58 , m_aXFillAttr(rInAttrs.GetPool())
59 , m_rXFSet(m_aXFillAttr.GetItemSet())
60 , m_aCtlPosition(this)
61 , m_xTsbShowShadow(m_xBuilder->weld_check_button("TSB_SHOW_SHADOW"))
62 , m_xGridShadow(m_xBuilder->weld_widget("gridSHADOW"))
63 , m_xMtrDistance(m_xBuilder->weld_metric_spin_button("MTR_FLD_DISTANCE", FieldUnit::CM))
64 , m_xLbShadowColor(new ColorListBox(m_xBuilder->weld_menu_button("LB_SHADOW_COLOR"),
65 [this]{ return GetDialogController()->getDialog(); }))
66 , m_xMtrTransparent(m_xBuilder->weld_metric_spin_button("MTR_SHADOW_TRANSPARENT", FieldUnit::PERCENT))
67 , m_xLbShadowBlurMetric(m_xBuilder->weld_metric_spin_button("LB_SHADOW_BLUR", FieldUnit::POINT))
68 , m_xCtlPosition(new weld::CustomWeld(*m_xBuilder, "CTL_POSITION", m_aCtlPosition))
69 , m_xCtlXRectPreview(new weld::CustomWeld(*m_xBuilder, "CTL_COLOR_PREVIEW", m_aCtlXRectPreview))
71 // this page needs ExchangeSupport
72 SetExchangeSupport();
74 // adjust metric
75 FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
77 switch ( eFUnit )
79 case FieldUnit::M:
80 case FieldUnit::KM:
81 eFUnit = FieldUnit::MM;
82 break;
83 default: ;//prevent warning
85 SetFieldUnit( *m_xMtrDistance, eFUnit );
87 // determine PoolUnit
88 SfxItemPool* pPool = m_rOutAttrs.GetPool();
89 DBG_ASSERT( pPool, "Where is the pool?" );
90 m_ePoolUnit = pPool->GetMetric( SDRATTR_SHADOWXDIST );
92 // setting the output device
93 drawing::FillStyle eXFS = drawing::FillStyle_SOLID;
94 if( m_rOutAttrs.GetItemState( XATTR_FILLSTYLE ) != SfxItemState::DONTCARE )
96 eXFS = m_rOutAttrs.Get( GetWhich( XATTR_FILLSTYLE ) ).GetValue();
97 switch( eXFS )
99 case drawing::FillStyle_SOLID:
100 if( SfxItemState::DONTCARE != m_rOutAttrs.GetItemState( XATTR_FILLCOLOR ) )
102 m_rXFSet.Put( m_rOutAttrs.Get( XATTR_FILLCOLOR ) );
104 break;
106 case drawing::FillStyle_GRADIENT:
107 if( SfxItemState::DONTCARE != m_rOutAttrs.GetItemState( XATTR_FILLGRADIENT ) )
109 m_rXFSet.Put( m_rOutAttrs.Get( XATTR_FILLGRADIENT ) );
111 break;
113 case drawing::FillStyle_HATCH:
114 if( SfxItemState::DONTCARE != m_rOutAttrs.GetItemState( XATTR_FILLHATCH ) )
116 m_rXFSet.Put( m_rOutAttrs.Get( XATTR_FILLHATCH ) );
118 break;
120 case drawing::FillStyle_BITMAP:
122 if( SfxItemState::DONTCARE != m_rOutAttrs.GetItemState( XATTR_FILLBITMAP ) )
124 m_rXFSet.Put( m_rOutAttrs.Get( XATTR_FILLBITMAP ) );
127 break;
128 case drawing::FillStyle_NONE : break;
129 default: break;
132 else
134 m_rXFSet.Put( XFillColorItem( OUString(), COL_LIGHTRED ) );
137 if(drawing::FillStyle_NONE == eXFS)
139 // #i96350#
140 // fallback to solid fillmode when no fill mode is provided to have
141 // a reasonable shadow preview. The used color will be a set one or
142 // the default (currently blue8)
143 eXFS = drawing::FillStyle_SOLID;
146 m_rXFSet.Put( XFillStyleItem( eXFS ) );
147 m_aCtlXRectPreview.SetRectangleAttributes(m_aXFillAttr.GetItemSet());
149 m_xTsbShowShadow->connect_toggled(LINK( this, SvxShadowTabPage, ClickShadowHdl_Impl));
150 m_xLbShadowColor->SetSelectHdl( LINK( this, SvxShadowTabPage, SelectShadowHdl_Impl ) );
151 Link<weld::MetricSpinButton&,void> aLink = LINK( this, SvxShadowTabPage, ModifyShadowHdl_Impl );
152 m_xLbShadowBlurMetric->connect_value_changed(aLink);
153 m_xMtrTransparent->connect_value_changed(aLink);
154 m_xMtrDistance->connect_value_changed(aLink);
157 SvxShadowTabPage::~SvxShadowTabPage()
159 m_xCtlXRectPreview.reset();
160 m_xLbShadowColor.reset();
161 m_xCtlPosition.reset();
162 m_xLbShadowBlurMetric.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 )
172 return;
174 if( !m_pColorList.is() )
175 return;
177 // ColorList
178 if( *m_pnColorListState & ChangeType::CHANGED ||
179 *m_pnColorListState & ChangeType::MODIFIED )
181 if( *m_pnColorListState & ChangeType::CHANGED )
183 SvxAreaTabDialog* pArea = dynamic_cast<SvxAreaTabDialog*>(GetDialogController());
184 if( pArea )
186 m_pColorList = pArea->GetNewColorList();
188 else
190 SvxLineTabDialog* pLine = dynamic_cast<SvxLineTabDialog*>(GetDialogController());
191 if( pLine )
192 m_pColorList = pLine->GetNewColorList();
196 SfxItemSet rAttribs( rSet );
197 // rSet contains shadow attributes too, but we want
198 // to use it for updating rectangle attributes only,
199 // so set the shadow to none here
200 SdrOnOffItem aItem( makeSdrShadowItem( false ));
201 rAttribs.Put( aItem );
203 m_aCtlXRectPreview.SetRectangleAttributes( rAttribs );
204 ModifyShadowHdl_Impl( *m_xMtrTransparent );
206 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 if (m_xLbShadowBlurMetric->get_value_changed_from_saved())
320 SdrMetricItem aItem(SDRATTR_SHADOWBLUR, m_xLbShadowBlurMetric->get_value(FieldUnit::MM_100TH));
321 pOld = GetOldItem( *rAttrs, SDRATTR_SHADOWBLUR );
322 if ( !pOld || !( *static_cast<const SdrMetricItem*>(pOld) == aItem ) )
324 rAttrs->Put( aItem );
325 bModified = true;
329 rAttrs->Put (CntUInt16Item(SID_PAGE_TYPE, static_cast<sal_uInt16>(m_nPageType)));
331 return bModified;
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);
345 else
347 m_xTsbShowShadow->set_state(TRISTATE_FALSE);
350 else
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();
362 if( nX != 0 )
363 SetMetricValue( *m_xMtrDistance, nX < 0 ? -nX : nX, m_ePoolUnit );
364 else
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 );
379 else
381 // determine default-distance
382 SfxItemPool* pPool = m_rOutAttrs.GetPool();
384 sal_Int32 n = pPool->GetDefaultItem(SDRATTR_SHADOWXDIST).GetValue();
385 if (n == 0)
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() );
401 else
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);
409 else
410 m_xMtrTransparent->set_text("");
412 if( rAttrs->GetItemState( SDRATTR_SHADOWBLUR ) != SfxItemState::DONTCARE )
414 sal_uInt16 nBlur = rAttrs->Get( SDRATTR_SHADOWBLUR ).GetValue();
415 m_xLbShadowBlurMetric->set_value(nBlur, FieldUnit::MM_100TH);
417 else
418 m_xLbShadowBlurMetric->set_text("");
420 //aCtlPosition
421 m_xMtrDistance->save_value();
422 m_xLbShadowColor->SaveValue();
423 m_xTsbShowShadow->save_state();
424 m_xLbShadowBlurMetric->save_value();
426 // #66832# This field was not saved, but used to determine changes.
427 // Why? Seems to be the error.
428 // It IS the error.
429 m_xMtrTransparent->save_value();
431 ClickShadowHdl_Impl(*m_xTsbShowShadow);
432 ModifyShadowHdl_Impl(*m_xMtrTransparent);
435 std::unique_ptr<SfxTabPage> SvxShadowTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
436 const SfxItemSet* rAttrs )
438 return std::make_unique<SvxShadowTabPage>(pPage, pController, *rAttrs);
441 IMPL_LINK_NOARG(SvxShadowTabPage, ClickShadowHdl_Impl, weld::Toggleable&, void)
443 if (m_xTsbShowShadow->get_state() == TRISTATE_FALSE)
445 m_xGridShadow->set_sensitive(false);
446 m_xCtlPosition->set_sensitive(false);
448 else
450 m_xGridShadow->set_sensitive(true);
451 m_xCtlPosition->set_sensitive(true);
453 m_aCtlPosition.Invalidate();
454 ModifyShadowHdl_Impl(*m_xMtrTransparent);
457 IMPL_LINK_NOARG(SvxShadowTabPage, SelectShadowHdl_Impl, ColorListBox&, void)
459 ModifyShadowHdl_Impl(*m_xMtrTransparent);
462 IMPL_LINK_NOARG(SvxShadowTabPage, ModifyShadowHdl_Impl, weld::MetricSpinButton&, void)
464 if (m_xTsbShowShadow->get_state() == TRISTATE_TRUE)
465 m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
466 else
467 m_rXFSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) );
469 m_rXFSet.Put( XFillColorItem( OUString(), m_xLbShadowColor->GetSelectEntryColor() ) );
470 sal_uInt16 nVal = static_cast<sal_uInt16>(m_xMtrTransparent->get_value(FieldUnit::PERCENT));
471 m_rXFSet.Put( XFillTransparenceItem( nVal ) );
473 // shadow removal
474 sal_Int32 nX = 0, nY = 0;
475 sal_Int32 nXY = GetCoreValue( *m_xMtrDistance, m_ePoolUnit );
476 switch( m_aCtlPosition.GetActualRP() )
478 case RectPoint::LT: nX = nY = -nXY; break;
479 case RectPoint::MT: nY = -nXY; break;
480 case RectPoint::RT: nX = nXY; nY = -nXY; break;
481 case RectPoint::LM: nX = -nXY; break;
482 case RectPoint::RM: nX = nXY; break;
483 case RectPoint::LB: nX = -nXY; nY = nXY; break;
484 case RectPoint::MB: nY = nXY; break;
485 case RectPoint::RB: nX = nY = nXY; break;
486 case RectPoint::MM: break;
489 m_aCtlXRectPreview.SetShadowPosition(Point(nX, nY));
491 m_aCtlXRectPreview.SetShadowAttributes(m_aXFillAttr.GetItemSet());
492 m_aCtlXRectPreview.Invalidate();
495 void SvxShadowTabPage::PointChanged( weld::DrawingArea*, RectPoint )
497 // repaint shadow
498 ModifyShadowHdl_Impl( *m_xMtrTransparent );
501 void SvxShadowTabPage::PageCreated(const SfxAllItemSet& aSet)
503 const SvxColorListItem* pColorListItem = aSet.GetItem<SvxColorListItem>(SID_COLOR_TABLE, false);
504 const SfxUInt16Item* pPageTypeItem = aSet.GetItem<SfxUInt16Item>(SID_PAGE_TYPE, false);
505 const SfxUInt16Item* pDlgTypeItem = aSet.GetItem<SfxUInt16Item>(SID_DLG_TYPE, false);
507 if (pColorListItem)
508 SetColorList(pColorListItem->GetColorList());
509 if (pPageTypeItem)
510 SetPageType(static_cast<PageType>(pPageTypeItem->GetValue()));
511 if (pDlgTypeItem)
512 SetDlgType(pDlgTypeItem->GetValue());
515 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */