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 .
21 #include <tools/urlobj.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/weld.hxx>
24 #include <sfx2/dialoghelper.hxx>
26 #include <strings.hrc>
27 #include <svx/xfillit0.hxx>
28 #include <svx/xflgrit.hxx>
29 #include <svx/colorbox.hxx>
30 #include <svx/xtable.hxx>
31 #include <svx/xgrscit.hxx>
32 #include <cuitabarea.hxx>
33 #include <svx/svxdlg.hxx>
34 #include <dialmgr.hxx>
35 #include <svx/dialmgr.hxx>
36 #include <svx/strings.hrc>
37 #include <basegfx/utils/gradienttools.hxx>
38 #include <sal/log.hxx>
40 using namespace com::sun::star
;
42 SvxGradientTabPage::SvxGradientTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rInAttrs
)
43 : SfxTabPage(pPage
, pController
, u
"cui/ui/gradientpage.ui"_ustr
, u
"GradientPage"_ustr
, &rInAttrs
)
44 , m_rOutAttrs(rInAttrs
)
45 , m_pnGradientListState(nullptr)
46 , m_pnColorListState(nullptr)
47 , m_aXFillAttr(rInAttrs
.GetPool())
48 , m_rXFSet(m_aXFillAttr
.GetItemSet())
49 , m_xLbGradientType(m_xBuilder
->weld_combo_box(u
"gradienttypelb"_ustr
))
50 , m_xFtCenter(m_xBuilder
->weld_label(u
"centerft"_ustr
))
51 , m_xMtrCenterX(m_xBuilder
->weld_metric_spin_button(u
"centerxmtr"_ustr
, FieldUnit::PERCENT
))
52 , m_xMtrCenterY(m_xBuilder
->weld_metric_spin_button(u
"centerymtr"_ustr
, FieldUnit::PERCENT
))
53 , m_xFtAngle(m_xBuilder
->weld_label(u
"angleft"_ustr
))
54 , m_xMtrAngle(m_xBuilder
->weld_metric_spin_button(u
"anglemtr"_ustr
, FieldUnit::DEGREE
))
55 , m_xSliderAngle(m_xBuilder
->weld_scale(u
"angleslider"_ustr
))
56 , m_xMtrBorder(m_xBuilder
->weld_metric_spin_button(u
"bordermtr"_ustr
, FieldUnit::PERCENT
))
57 , m_xSliderBorder(m_xBuilder
->weld_scale(u
"borderslider"_ustr
))
58 , m_xLbColorFrom(new ColorListBox(m_xBuilder
->weld_menu_button(u
"colorfromlb"_ustr
),
59 [this]{ return GetDialogController()->getDialog(); }))
60 , m_xMtrColorFrom(m_xBuilder
->weld_metric_spin_button(u
"colorfrommtr"_ustr
, FieldUnit::PERCENT
))
61 , m_xLbColorTo(new ColorListBox(m_xBuilder
->weld_menu_button(u
"colortolb"_ustr
),
62 [this]{ return GetDialogController()->getDialog(); }))
63 , m_xMtrColorTo(m_xBuilder
->weld_metric_spin_button(u
"colortomtr"_ustr
, FieldUnit::PERCENT
))
64 , m_xGradientLB(new SvxPresetListBox(m_xBuilder
->weld_scrolled_window(u
"gradientpresetlistwin"_ustr
, true)))
65 , m_xMtrIncrement(m_xBuilder
->weld_spin_button(u
"incrementmtr"_ustr
))
66 , m_xCbIncrement(m_xBuilder
->weld_check_button(u
"autoincrement"_ustr
))
67 , m_xBtnAdd(m_xBuilder
->weld_button(u
"add"_ustr
))
68 , m_xBtnModify(m_xBuilder
->weld_button(u
"modify"_ustr
))
69 , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder
, u
"previewctl"_ustr
, m_aCtlPreview
))
70 , m_xGradientLBWin(new weld::CustomWeld(*m_xBuilder
, u
"gradientpresetlist"_ustr
, *m_xGradientLB
))
72 Size aSize
= getDrawPreviewOptimalSize(m_aCtlPreview
.GetDrawingArea()->get_ref_device());
73 m_xGradientLB
->set_size_request(aSize
.Width(), aSize
.Height());
74 m_xCtlPreview
->set_size_request(aSize
.Width(), aSize
.Height());
75 // this page needs ExchangeSupport
78 // as long as NOT supported by the item
80 m_xMtrColorTo
->set_value(100, FieldUnit::PERCENT
);
81 m_xMtrColorFrom
->set_value(100, FieldUnit::PERCENT
);
83 // setting the output device
84 m_rXFSet
.Put( XFillStyleItem(drawing::FillStyle_GRADIENT
) );
85 m_rXFSet
.Put( XFillGradientItem(OUString(), basegfx::BGradient()));
86 m_aCtlPreview
.SetAttributes(m_aXFillAttr
.GetItemSet());
89 m_xGradientLB
->SetSelectHdl( LINK( this, SvxGradientTabPage
, ChangeGradientHdl
) );
90 m_xGradientLB
->SetRenameHdl( LINK( this, SvxGradientTabPage
, ClickRenameHdl_Impl
) );
91 m_xGradientLB
->SetDeleteHdl( LINK( this, SvxGradientTabPage
, ClickDeleteHdl_Impl
) );
92 m_xBtnAdd
->connect_clicked(LINK(this, SvxGradientTabPage
, ClickAddHdl_Impl
));
93 m_xBtnModify
->connect_clicked(LINK(this, SvxGradientTabPage
, ClickModifyHdl_Impl
));
95 Link
<weld::MetricSpinButton
&,void> aLink
= LINK( this, SvxGradientTabPage
, ModifiedMetricHdl_Impl
);
96 Link
<weld::ComboBox
&,void> aLink2
= LINK( this, SvxGradientTabPage
, ModifiedListBoxHdl_Impl
);
97 m_xLbGradientType
->connect_changed( aLink2
);
98 m_xCbIncrement
->connect_toggled(LINK(this, SvxGradientTabPage
, ChangeAutoStepHdl_Impl
));
99 m_xMtrIncrement
->connect_value_changed(LINK(this, SvxGradientTabPage
, ModifiedEditHdl_Impl
));
100 m_xMtrCenterX
->connect_value_changed( aLink
);
101 m_xMtrCenterY
->connect_value_changed( aLink
);
102 m_xMtrAngle
->connect_value_changed( aLink
);
103 m_xSliderAngle
->connect_value_changed(LINK(this, SvxGradientTabPage
, ModifiedSliderHdl_Impl
));
104 m_xMtrBorder
->connect_value_changed( aLink
);
105 m_xSliderBorder
->connect_value_changed(LINK(this, SvxGradientTabPage
, ModifiedSliderHdl_Impl
));
106 m_xMtrColorFrom
->connect_value_changed( aLink
);
107 Link
<ColorListBox
&,void> aLink3
= LINK( this, SvxGradientTabPage
, ModifiedColorListBoxHdl_Impl
);
108 m_xLbColorFrom
->SetSelectHdl( aLink3
);
109 m_xMtrColorTo
->connect_value_changed( aLink
);
110 m_xLbColorTo
->SetSelectHdl( aLink3
);
112 m_xGradientLB
->SetStyle(WB_FLATVALUESET
| WB_NO_DIRECTSELECT
| WB_TABSTOP
);
114 // #i76307# always paint the preview in LTR, because this is what the document does
115 m_aCtlPreview
.EnableRTL(false);
118 SvxGradientTabPage::~SvxGradientTabPage()
120 m_xCtlPreview
.reset();
121 m_xGradientLBWin
.reset();
122 m_xGradientLB
.reset();
123 m_xLbColorTo
.reset();
124 m_xLbColorFrom
.reset();
127 void SvxGradientTabPage::Construct()
129 m_xGradientLB
->FillPresetListBox( *m_pGradientList
);
132 void SvxGradientTabPage::ActivatePage( const SfxItemSet
& rSet
)
134 if( !m_pColorList
.is() )
138 if( *m_pnColorListState
& ChangeType::CHANGED
||
139 *m_pnColorListState
& ChangeType::MODIFIED
)
141 SvxAreaTabDialog
* pArea
= (*m_pnColorListState
& ChangeType::CHANGED
) ?
142 dynamic_cast<SvxAreaTabDialog
*>(GetDialogController()) : nullptr;
144 m_pColorList
= pArea
->GetNewColorList();
146 ModifiedHdl_Impl( this );
149 // determining (and possibly cutting) the name and
150 // displaying it in the GroupBox
151 OUString aString
= CuiResId( RID_CUISTR_TABLE
) + ": ";
152 INetURLObject
aURL( m_pGradientList
->GetPath() );
154 aURL
.Append( m_pGradientList
->GetName() );
155 SAL_WARN_IF( aURL
.GetProtocol() == INetProtocol::NotValid
, "cui.tabpages", "invalid URL" );
157 if ( aURL
.getBase().getLength() > 18 )
159 aString
+= OUString::Concat(aURL
.getBase().subView( 0, 15 )) + "...";
162 aString
+= aURL
.getBase();
164 sal_Int32 nPos
= SearchGradientList( rSet
.Get(XATTR_FILLGRADIENT
).GetName() );
167 sal_uInt16 nId
= m_xGradientLB
->GetItemId( static_cast<size_t>( nPos
) );
168 m_xGradientLB
->SelectItem( nId
);
170 // colors could have been deleted
171 ChangeGradientHdl_Impl();
175 DeactivateRC
SvxGradientTabPage::DeactivatePage( SfxItemSet
* _pSet
)
178 FillItemSet( _pSet
);
180 return DeactivateRC::LeavePage
;
183 bool SvxGradientTabPage::FillItemSet( SfxItemSet
* rSet
)
185 std::unique_ptr
<basegfx::BGradient
> pBGradient
;
186 size_t nPos
= m_xGradientLB
->IsNoSelection() ? VALUESET_ITEM_NOTFOUND
: m_xGradientLB
->GetSelectItemPos();
188 sal_uInt16 nValue
= 0; // automatic step count
189 if (!m_xCbIncrement
->get_active())
190 nValue
= m_xMtrIncrement
->get_value();
192 if( nPos
!= VALUESET_ITEM_NOTFOUND
)
194 pBGradient
.reset(new basegfx::BGradient( m_pGradientList
->GetGradient( static_cast<sal_uInt16
>(nPos
) )->GetGradient() ));
195 OUString aString
= m_xGradientLB
->GetItemText( m_xGradientLB
->GetSelectedItemId() );
196 // update StepCount to current value to be in sync with FillGradientStepCount
197 pBGradient
->SetSteps(nValue
);
198 rSet
->Put( XFillGradientItem( aString
, *pBGradient
) );
201 // gradient was passed (unidentified)
203 pBGradient
.reset(new basegfx::BGradient(
205 static_cast<css::awt::GradientStyle
>(m_xLbGradientType
->get_active()),
206 Degree10(static_cast<sal_Int16
>(m_xMtrAngle
->get_value(FieldUnit::NONE
) * 10)), // should be changed in resource
207 static_cast<sal_uInt16
>(m_xMtrCenterX
->get_value(FieldUnit::NONE
)),
208 static_cast<sal_uInt16
>(m_xMtrCenterY
->get_value(FieldUnit::NONE
)),
209 static_cast<sal_uInt16
>(m_xMtrBorder
->get_value(FieldUnit::NONE
)),
210 static_cast<sal_uInt16
>(m_xMtrColorFrom
->get_value(FieldUnit::NONE
)),
211 static_cast<sal_uInt16
>(m_xMtrColorTo
->get_value(FieldUnit::NONE
)),
213 rSet
->Put( XFillGradientItem( OUString(), *pBGradient
) );
216 assert( pBGradient
&& "basegfx::BGradient could not be created" );
217 rSet
->Put( XFillStyleItem( drawing::FillStyle_GRADIENT
) );
218 rSet
->Put( XGradientStepCountItem( nValue
) );
222 void SvxGradientTabPage::Reset( const SfxItemSet
* )
224 ChangeGradientHdl_Impl(); // includes setting m_xCbIncrement and m_xMtrIncrement
226 // determine state of the buttons
227 if( m_pGradientList
->Count() )
228 m_xBtnModify
->set_sensitive(true);
230 m_xBtnModify
->set_sensitive(false);
233 std::unique_ptr
<SfxTabPage
> SvxGradientTabPage::Create( weld::Container
* pPage
, weld::DialogController
* pController
,
234 const SfxItemSet
* rOutAttrs
)
236 return std::make_unique
<SvxGradientTabPage
>(pPage
, pController
, *rOutAttrs
);
239 IMPL_LINK( SvxGradientTabPage
, ModifiedListBoxHdl_Impl
, weld::ComboBox
&, rListBox
, void )
241 ModifiedHdl_Impl(&rListBox
);
242 // gradient params changed, it is no longer one of the presets
243 m_xGradientLB
->SetNoSelection();
246 IMPL_LINK( SvxGradientTabPage
, ModifiedColorListBoxHdl_Impl
, ColorListBox
&, rListBox
, void )
248 ModifiedHdl_Impl(&rListBox
);
249 m_xGradientLB
->SetNoSelection();
252 IMPL_LINK( SvxGradientTabPage
, ModifiedEditHdl_Impl
, weld::SpinButton
&, rBox
, void )
254 ModifiedHdl_Impl(&rBox
);
255 m_xGradientLB
->SetNoSelection();
258 IMPL_LINK( SvxGradientTabPage
, ModifiedMetricHdl_Impl
, weld::MetricSpinButton
&, rBox
, void )
260 ModifiedHdl_Impl(&rBox
);
261 m_xGradientLB
->SetNoSelection();
264 IMPL_LINK( SvxGradientTabPage
, ModifiedSliderHdl_Impl
, weld::Scale
&, rSlider
, void )
266 ModifiedHdl_Impl(&rSlider
);
267 m_xGradientLB
->SetNoSelection();
270 IMPL_LINK_NOARG( SvxGradientTabPage
, ChangeAutoStepHdl_Impl
, weld::Toggleable
&, void )
272 if (m_xCbIncrement
->get_active())
274 m_xMtrIncrement
->set_sensitive(false);
278 m_xMtrIncrement
->set_sensitive(true);
280 ModifiedHdl_Impl(m_xMtrIncrement
.get());
283 void SvxGradientTabPage::ModifiedHdl_Impl( void const * pControl
)
285 if (pControl
== m_xMtrBorder
.get())
286 m_xSliderBorder
->set_value(m_xMtrBorder
->get_value(FieldUnit::NONE
));
287 if (pControl
== m_xSliderBorder
.get())
288 m_xMtrBorder
->set_value(m_xSliderBorder
->get_value(), FieldUnit::NONE
);
289 if (pControl
== m_xMtrAngle
.get())
290 m_xSliderAngle
->set_value(m_xMtrAngle
->get_value(FieldUnit::NONE
));
291 if (pControl
== m_xSliderAngle
.get())
292 m_xMtrAngle
->set_value(m_xSliderAngle
->get_value(), FieldUnit::NONE
);
294 css::awt::GradientStyle eXGS
= static_cast<css::awt::GradientStyle
>(m_xLbGradientType
->get_active());
296 sal_uInt16 nValue
= 0; // automatic
297 if (!m_xCbIncrement
->get_active())
298 nValue
= static_cast<sal_uInt16
>(m_xMtrIncrement
->get_value());
300 basegfx::BGradient
aBGradient(
303 Degree10(static_cast<sal_Int16
>(m_xMtrAngle
->get_value(FieldUnit::NONE
) * 10)), // should be changed in resource
304 static_cast<sal_uInt16
>(m_xMtrCenterX
->get_value(FieldUnit::NONE
)),
305 static_cast<sal_uInt16
>(m_xMtrCenterY
->get_value(FieldUnit::NONE
)),
306 static_cast<sal_uInt16
>(m_xMtrBorder
->get_value(FieldUnit::NONE
)),
307 static_cast<sal_uInt16
>(m_xMtrColorFrom
->get_value(FieldUnit::NONE
)),
308 static_cast<sal_uInt16
>(m_xMtrColorTo
->get_value(FieldUnit::NONE
)),
311 // enable/disable controls
312 if (pControl
== m_xLbGradientType
.get() || pControl
== this)
313 SetControlState_Impl( eXGS
);
315 m_rXFSet
.Put( XGradientStepCountItem( nValue
) );
317 // displaying in XOutDev
318 m_rXFSet
.Put( XFillGradientItem( OUString(), aBGradient
) );
319 m_aCtlPreview
.SetAttributes(m_aXFillAttr
.GetItemSet());
320 m_aCtlPreview
.Invalidate();
323 IMPL_LINK_NOARG(SvxGradientTabPage
, ClickAddHdl_Impl
, weld::Button
&, void)
325 OUString
aNewName( SvxResId( RID_SVXSTR_GRADIENT
) );
326 OUString
aDesc( CuiResId( RID_CUISTR_DESC_GRADIENT
) );
329 tools::Long nCount
= m_pGradientList
->Count();
331 bool bValidGradientName
= false;
333 while( !bValidGradientName
)
335 aName
= aNewName
+ " " + OUString::number( j
++ );
336 bValidGradientName
= (SearchGradientList(aName
) == -1);
339 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
340 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg(pFact
->CreateSvxNameDialog(GetFrameWeld(), aName
, aDesc
));
341 sal_uInt16 nError
= 1;
343 while (pDlg
->Execute() == RET_OK
)
345 aName
= pDlg
->GetName();
347 bValidGradientName
= (SearchGradientList(aName
) == -1);
349 if (bValidGradientName
)
355 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetFrameWeld(), u
"cui/ui/queryduplicatedialog.ui"_ustr
));
356 std::unique_ptr
<weld::MessageDialog
> xWarnBox(xBuilder
->weld_message_dialog(u
"DuplicateNameDialog"_ustr
));
357 if (xWarnBox
->run() != RET_OK
)
360 pDlg
.disposeAndClear();
364 sal_uInt16 nValue
= 0; // automatic step count
365 if (!m_xCbIncrement
->get_active())
366 nValue
= m_xMtrIncrement
->get_value();
367 basegfx::BGradient
aBGradient(
369 static_cast<css::awt::GradientStyle
>(m_xLbGradientType
->get_active()),
370 Degree10(static_cast<sal_Int16
>(m_xMtrAngle
->get_value(FieldUnit::NONE
) * 10)), // should be changed in resource
371 static_cast<sal_uInt16
>(m_xMtrCenterX
->get_value(FieldUnit::NONE
)),
372 static_cast<sal_uInt16
>(m_xMtrCenterY
->get_value(FieldUnit::NONE
)),
373 static_cast<sal_uInt16
>(m_xMtrBorder
->get_value(FieldUnit::NONE
)),
374 static_cast<sal_uInt16
>(m_xMtrColorFrom
->get_value(FieldUnit::NONE
)),
375 static_cast<sal_uInt16
>(m_xMtrColorTo
->get_value(FieldUnit::NONE
)),
378 m_pGradientList
->Insert(std::make_unique
<XGradientEntry
>(aBGradient
, aName
), nCount
);
380 sal_Int32 nId
= m_xGradientLB
->GetItemId(nCount
- 1); //calculate the last ID
381 BitmapEx aBitmap
= m_pGradientList
->GetBitmapForPreview( nCount
, m_xGradientLB
->GetIconSize() );
382 m_xGradientLB
->InsertItem( nId
+ 1, Image(aBitmap
), aName
);
383 m_xGradientLB
->SelectItem( nId
+ 1 );
384 m_xGradientLB
->Resize();
386 *m_pnGradientListState
|= ChangeType::MODIFIED
;
388 ChangeGradientHdl_Impl();
391 // determine button state
392 if (m_pGradientList
->Count())
393 m_xBtnModify
->set_sensitive(true);
397 IMPL_LINK_NOARG(SvxGradientTabPage
, ClickModifyHdl_Impl
, weld::Button
&, void)
399 sal_uInt16 nId
= m_xGradientLB
->GetSelectedItemId();
400 size_t nPos
= m_xGradientLB
->GetSelectItemPos();
402 if ( nPos
== VALUESET_ITEM_NOTFOUND
)
405 OUString
aName( m_pGradientList
->GetGradient( static_cast<sal_uInt16
>(nPos
) )->GetName() );
407 sal_uInt16 nValue
= 0; // automatic step count
408 if (!m_xCbIncrement
->get_active())
409 nValue
= m_xMtrIncrement
->get_value();
411 basegfx::BGradient
aBGradient(
413 static_cast<css::awt::GradientStyle
>(m_xLbGradientType
->get_active()),
414 Degree10(static_cast<sal_Int16
>(m_xMtrAngle
->get_value(FieldUnit::NONE
) * 10)), // should be changed in resource
415 static_cast<sal_uInt16
>(m_xMtrCenterX
->get_value(FieldUnit::NONE
)),
416 static_cast<sal_uInt16
>(m_xMtrCenterY
->get_value(FieldUnit::NONE
)),
417 static_cast<sal_uInt16
>(m_xMtrBorder
->get_value(FieldUnit::NONE
)),
418 static_cast<sal_uInt16
>(m_xMtrColorFrom
->get_value(FieldUnit::NONE
)),
419 static_cast<sal_uInt16
>(m_xMtrColorTo
->get_value(FieldUnit::NONE
)),
422 m_pGradientList
->Replace(std::make_unique
<XGradientEntry
>(aBGradient
, aName
), nPos
);
424 BitmapEx aBitmap
= m_pGradientList
->GetBitmapForPreview( static_cast<sal_uInt16
>(nPos
), m_xGradientLB
->GetIconSize() );
425 m_xGradientLB
->RemoveItem( nId
);
426 m_xGradientLB
->InsertItem( nId
, Image(aBitmap
), aName
, static_cast<sal_uInt16
>(nPos
) );
427 m_xGradientLB
->SelectItem( nId
);
429 *m_pnGradientListState
|= ChangeType::MODIFIED
;
432 IMPL_LINK_NOARG(SvxGradientTabPage
, ClickDeleteHdl_Impl
, SvxPresetListBox
*, void)
434 sal_uInt16 nId
= m_xGradientLB
->GetSelectedItemId();
435 size_t nPos
= m_xGradientLB
->GetSelectItemPos();
437 if( nPos
!= VALUESET_ITEM_NOTFOUND
)
439 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetFrameWeld(), u
"cui/ui/querydeletegradientdialog.ui"_ustr
));
440 std::unique_ptr
<weld::MessageDialog
> xQueryBox(xBuilder
->weld_message_dialog(u
"AskDelGradientDialog"_ustr
));
441 if (xQueryBox
->run() == RET_YES
)
443 m_pGradientList
->Remove(nPos
);
444 m_xGradientLB
->RemoveItem( nId
);
445 nId
= m_xGradientLB
->GetItemId( 0 );
446 m_xGradientLB
->SelectItem( nId
);
447 m_xGradientLB
->Resize();
449 m_aCtlPreview
.Invalidate();
451 ChangeGradientHdl_Impl();
453 *m_pnGradientListState
|= ChangeType::MODIFIED
;
456 // determine button state
457 if( !m_pGradientList
->Count() )
458 m_xBtnModify
->set_sensitive(false);
461 IMPL_LINK_NOARG(SvxGradientTabPage
, ClickRenameHdl_Impl
, SvxPresetListBox
*, void)
463 sal_uInt16 nId
= m_xGradientLB
->GetSelectedItemId();
464 size_t nPos
= m_xGradientLB
->GetSelectItemPos();
466 if ( nPos
== VALUESET_ITEM_NOTFOUND
)
469 OUString
aDesc( CuiResId( RID_CUISTR_DESC_GRADIENT
) );
470 OUString
aName( m_pGradientList
->GetGradient( nPos
)->GetName() );
472 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
473 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg(pFact
->CreateSvxNameDialog(GetFrameWeld(), aName
, aDesc
));
476 while( bLoop
&& pDlg
->Execute() == RET_OK
)
478 aName
= pDlg
->GetName();
479 sal_Int32 nGradientPos
= SearchGradientList(aName
);
480 bool bValidGradientName
= (nGradientPos
== static_cast<sal_Int32
>(nPos
) ) || (nGradientPos
== -1);
482 if( bValidGradientName
)
485 m_pGradientList
->GetGradient(nPos
)->SetName(aName
);
487 m_xGradientLB
->SetItemText( nId
, aName
);
488 m_xGradientLB
->SelectItem( nId
);
490 *m_pnGradientListState
|= ChangeType::MODIFIED
;
494 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetFrameWeld(), u
"cui/ui/queryduplicatedialog.ui"_ustr
));
495 std::unique_ptr
<weld::MessageDialog
> xBox(xBuilder
->weld_message_dialog(u
"DuplicateNameDialog"_ustr
));
501 IMPL_LINK_NOARG(SvxGradientTabPage
, ChangeGradientHdl
, ValueSet
*, void)
503 ChangeGradientHdl_Impl();
506 void SvxGradientTabPage::ChangeGradientHdl_Impl()
508 std::unique_ptr
<basegfx::BGradient
> pGradient
;
509 size_t nPos
= m_xGradientLB
->GetSelectItemPos();
511 if( nPos
!= VALUESET_ITEM_NOTFOUND
)
512 pGradient
.reset(new basegfx::BGradient( m_pGradientList
->GetGradient( static_cast<sal_uInt16
>( nPos
) )->GetGradient() ));
515 if( const XFillStyleItem
* pFillStyleItem
= m_rOutAttrs
.GetItemIfSet( GetWhich( XATTR_FILLSTYLE
) ) )
517 const XFillGradientItem
* pGradientItem
;
518 if( ( drawing::FillStyle_GRADIENT
== pFillStyleItem
->GetValue() ) &&
519 ( pGradientItem
= m_rOutAttrs
.GetItemIfSet( GetWhich( XATTR_FILLGRADIENT
) ) ) )
521 pGradient
.reset(new basegfx::BGradient( pGradientItem
->GetGradientValue() ));
526 sal_uInt16 nPosition
= m_xGradientLB
->GetItemId(0);
527 m_xGradientLB
->SelectItem( nPosition
);
529 pGradient
.reset(new basegfx::BGradient( m_pGradientList
->GetGradient( 0 )->GetGradient() ));
536 css::awt::GradientStyle eXGS
= pGradient
->GetGradientStyle();
537 sal_uInt16 nValue
= pGradient
->GetSteps();
538 if (const XGradientStepCountItem
* pGradientStepCountItem
= m_rOutAttrs
.GetItemIfSet(GetWhich(XATTR_GRADIENTSTEPCOUNT
)))
540 nValue
= pGradientStepCountItem
->GetValue();
544 m_xCbIncrement
->set_state(TRISTATE_TRUE
);
545 m_xMtrIncrement
->set_sensitive(false);
549 m_xCbIncrement
->set_state(TRISTATE_FALSE
);
550 m_xMtrIncrement
->set_sensitive(true);
551 m_xMtrIncrement
->set_value( nValue
);
553 m_xLbGradientType
->set_active(
554 sal::static_int_cast
< sal_Int32
>( eXGS
) );
555 // if the entry is not in the listbox,
556 // colors are added temporarily
557 m_xLbColorFrom
->SetNoSelection();
558 m_xLbColorFrom
->SelectEntry(Color(pGradient
->GetColorStops().front().getStopColor()));
560 m_xLbColorTo
->SetNoSelection();
561 m_xLbColorTo
->SelectEntry(Color(pGradient
->GetColorStops().back().getStopColor()));
563 // MCGR: preserve ColorStops if given.
564 // tdf#155901 We need offset of first and last stop, so include them.
565 if (pGradient
->GetColorStops().size() >= 2)
566 m_aColorStops
= pGradient
->GetColorStops();
568 m_aColorStops
.clear();
570 m_xMtrAngle
->set_value(pGradient
->GetAngle().get() / 10, FieldUnit::NONE
); // should be changed in resource
571 m_xSliderAngle
->set_value(pGradient
->GetAngle().get() / 10);
572 m_xMtrBorder
->set_value(pGradient
->GetBorder(), FieldUnit::NONE
);
573 m_xSliderBorder
->set_value(pGradient
->GetBorder());
574 m_xMtrCenterX
->set_value(pGradient
->GetXOffset(), FieldUnit::NONE
);
575 m_xMtrCenterY
->set_value(pGradient
->GetYOffset(), FieldUnit::NONE
);
576 m_xMtrColorFrom
->set_value(pGradient
->GetStartIntens(), FieldUnit::NONE
);
577 m_xMtrColorTo
->set_value(pGradient
->GetEndIntens(), FieldUnit::NONE
);
579 // disable/enable controls
580 SetControlState_Impl( eXGS
);
582 // fill ItemSet and pass it on to aCtlPreview
583 m_rXFSet
.Put( XFillGradientItem( OUString(), *pGradient
) );
584 m_rXFSet
.Put( XGradientStepCountItem( nValue
) );
585 m_aCtlPreview
.SetAttributes(m_aXFillAttr
.GetItemSet());
587 m_aCtlPreview
.Invalidate();
590 void SvxGradientTabPage::SetControlState_Impl( css::awt::GradientStyle eXGS
)
594 case css::awt::GradientStyle_LINEAR
:
595 case css::awt::GradientStyle_AXIAL
:
596 m_xFtCenter
->set_sensitive(false);
597 m_xMtrCenterX
->set_sensitive(false);
598 m_xMtrCenterY
->set_sensitive(false);
599 m_xFtAngle
->set_sensitive(true);
600 m_xMtrAngle
->set_sensitive(true);
601 m_xSliderAngle
->set_sensitive(true);
604 case css::awt::GradientStyle_RADIAL
:
605 m_xFtCenter
->set_sensitive(true);
606 m_xMtrCenterX
->set_sensitive(true);
607 m_xMtrCenterY
->set_sensitive(true);
608 m_xFtAngle
->set_sensitive(false);
609 m_xMtrAngle
->set_sensitive(false);
610 m_xSliderAngle
->set_sensitive(false);
613 case css::awt::GradientStyle_ELLIPTICAL
:
614 m_xFtCenter
->set_sensitive(true);
615 m_xMtrCenterX
->set_sensitive(true);
616 m_xMtrCenterY
->set_sensitive(true);
617 m_xFtAngle
->set_sensitive(true);
618 m_xMtrAngle
->set_sensitive(true);
619 m_xSliderAngle
->set_sensitive(true);
622 case css::awt::GradientStyle_SQUARE
:
623 case css::awt::GradientStyle_RECT
:
624 m_xFtCenter
->set_sensitive(true);
625 m_xMtrCenterX
->set_sensitive(true);
626 m_xMtrCenterY
->set_sensitive(true);
627 m_xFtAngle
->set_sensitive(true);
628 m_xMtrAngle
->set_sensitive(true);
629 m_xSliderAngle
->set_sensitive(true);
636 sal_Int32
SvxGradientTabPage::SearchGradientList(std::u16string_view rGradientName
)
638 tools::Long nCount
= m_pGradientList
->Count();
639 bool bValidGradientName
= true;
642 for(tools::Long i
= 0;i
< nCount
&& bValidGradientName
;i
++)
644 if(rGradientName
== m_pGradientList
->GetGradient( i
)->GetName())
647 bValidGradientName
= false;
653 basegfx::BColorStops
SvxGradientTabPage::createColorStops()
655 basegfx::BColorStops aColorStops
;
657 if(m_aColorStops
.size() >= 2)
659 aColorStops
= m_aColorStops
;
660 aColorStops
.front() = basegfx::BColorStop(m_aColorStops
.front().getStopOffset(),
661 m_xLbColorFrom
->GetSelectEntryColor().getBColor());
662 aColorStops
.back() = basegfx::BColorStop(m_aColorStops
.back().getStopOffset(),
663 m_xLbColorTo
->GetSelectEntryColor().getBColor());
667 aColorStops
.emplace_back(0.0, m_xLbColorFrom
->GetSelectEntryColor().getBColor());
668 aColorStops
.emplace_back(1.0, m_xLbColorTo
->GetSelectEntryColor().getBColor());
674 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */