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 <sal/log.hxx>
39 #define DEFAULT_GRADIENTSTEP 64
41 using namespace com::sun::star
;
43 SvxGradientTabPage::SvxGradientTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rInAttrs
)
44 : SfxTabPage(pPage
, pController
, "cui/ui/gradientpage.ui", "GradientPage", &rInAttrs
)
45 , m_rOutAttrs(rInAttrs
)
46 , m_pnGradientListState(nullptr)
47 , m_pnColorListState(nullptr)
48 , m_aXFillAttr(rInAttrs
.GetPool())
49 , m_rXFSet(m_aXFillAttr
.GetItemSet())
50 , m_xLbGradientType(m_xBuilder
->weld_combo_box("gradienttypelb"))
51 , m_xFtCenter(m_xBuilder
->weld_label("centerft"))
52 , m_xMtrCenterX(m_xBuilder
->weld_metric_spin_button("centerxmtr", FieldUnit::PERCENT
))
53 , m_xMtrCenterY(m_xBuilder
->weld_metric_spin_button("centerymtr", FieldUnit::PERCENT
))
54 , m_xFtAngle(m_xBuilder
->weld_label("angleft"))
55 , m_xMtrAngle(m_xBuilder
->weld_metric_spin_button("anglemtr", FieldUnit::DEGREE
))
56 , m_xSliderAngle(m_xBuilder
->weld_scale("angleslider"))
57 , m_xMtrBorder(m_xBuilder
->weld_metric_spin_button("bordermtr", FieldUnit::PERCENT
))
58 , m_xSliderBorder(m_xBuilder
->weld_scale("borderslider"))
59 , m_xLbColorFrom(new ColorListBox(m_xBuilder
->weld_menu_button("colorfromlb"), pController
->getDialog()))
60 , m_xMtrColorFrom(m_xBuilder
->weld_metric_spin_button("colorfrommtr", FieldUnit::PERCENT
))
61 , m_xLbColorTo(new ColorListBox(m_xBuilder
->weld_menu_button("colortolb"), pController
->getDialog()))
62 , m_xMtrColorTo(m_xBuilder
->weld_metric_spin_button("colortomtr", FieldUnit::PERCENT
))
63 , m_xGradientLB(new SvxPresetListBox(m_xBuilder
->weld_scrolled_window("gradientpresetlistwin")))
64 , m_xMtrIncrement(m_xBuilder
->weld_spin_button("incrementmtr"))
65 , m_xCbIncrement(m_xBuilder
->weld_check_button("autoincrement"))
66 , m_xBtnAdd(m_xBuilder
->weld_button("add"))
67 , m_xBtnModify(m_xBuilder
->weld_button("modify"))
68 , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder
, "previewctl", m_aCtlPreview
))
69 , m_xGradientLBWin(new weld::CustomWeld(*m_xBuilder
, "gradientpresetlist", *m_xGradientLB
))
71 Size aSize
= getPagePropertiesOptimalSize(m_xGradientLB
->GetDrawingArea()->get_ref_device());
72 m_xGradientLB
->set_size_request(aSize
.Width(), aSize
.Height());
74 aSize
= getDrawPreviewOptimalSize(m_aCtlPreview
.GetDrawingArea()->get_ref_device());
75 m_xCtlPreview
->set_size_request(aSize
.Width(), aSize
.Height());
76 // this page needs ExchangeSupport
79 // as long as NOT supported by the item
81 m_xMtrColorTo
->set_value(100, FieldUnit::PERCENT
);
82 m_xMtrColorFrom
->set_value(100, FieldUnit::PERCENT
);
84 // setting the output device
85 m_rXFSet
.Put( XFillStyleItem(drawing::FillStyle_GRADIENT
) );
86 m_rXFSet
.Put( XFillGradientItem(OUString(), XGradient( COL_BLACK
, COL_WHITE
)) );
87 m_aCtlPreview
.SetAttributes(m_aXFillAttr
.GetItemSet());
90 m_xGradientLB
->SetSelectHdl( LINK( this, SvxGradientTabPage
, ChangeGradientHdl
) );
91 m_xGradientLB
->SetRenameHdl( LINK( this, SvxGradientTabPage
, ClickRenameHdl_Impl
) );
92 m_xGradientLB
->SetDeleteHdl( LINK( this, SvxGradientTabPage
, ClickDeleteHdl_Impl
) );
93 m_xBtnAdd
->connect_clicked(LINK(this, SvxGradientTabPage
, ClickAddHdl_Impl
));
94 m_xBtnModify
->connect_clicked(LINK(this, SvxGradientTabPage
, ClickModifyHdl_Impl
));
96 Link
<weld::MetricSpinButton
&,void> aLink
= LINK( this, SvxGradientTabPage
, ModifiedMetricHdl_Impl
);
97 Link
<weld::ComboBox
&,void> aLink2
= LINK( this, SvxGradientTabPage
, ModifiedListBoxHdl_Impl
);
98 m_xLbGradientType
->connect_changed( aLink2
);
99 m_xCbIncrement
->connect_toggled(LINK(this, SvxGradientTabPage
, ChangeAutoStepHdl_Impl
));
100 m_xMtrIncrement
->connect_value_changed(LINK(this, SvxGradientTabPage
, ModifiedEditHdl_Impl
));
101 m_xMtrCenterX
->connect_value_changed( aLink
);
102 m_xMtrCenterY
->connect_value_changed( aLink
);
103 m_xMtrAngle
->connect_value_changed( aLink
);
104 m_xSliderAngle
->connect_value_changed(LINK(this, SvxGradientTabPage
, ModifiedSliderHdl_Impl
));
105 m_xMtrBorder
->connect_value_changed( aLink
);
106 m_xSliderBorder
->connect_value_changed(LINK(this, SvxGradientTabPage
, ModifiedSliderHdl_Impl
));
107 m_xMtrColorFrom
->connect_value_changed( aLink
);
108 Link
<ColorListBox
&,void> aLink3
= LINK( this, SvxGradientTabPage
, ModifiedColorListBoxHdl_Impl
);
109 m_xLbColorFrom
->SetSelectHdl( aLink3
);
110 m_xMtrColorTo
->connect_value_changed( aLink
);
111 m_xLbColorTo
->SetSelectHdl( aLink3
);
113 // #i76307# always paint the preview in LTR, because this is what the document does
114 m_aCtlPreview
.EnableRTL(false);
117 SvxGradientTabPage::~SvxGradientTabPage()
119 m_xCtlPreview
.reset();
120 m_xGradientLBWin
.reset();
121 m_xGradientLB
.reset();
122 m_xLbColorTo
.reset();
123 m_xLbColorFrom
.reset();
126 void SvxGradientTabPage::Construct()
128 m_xGradientLB
->FillPresetListBox( *m_pGradientList
);
131 void SvxGradientTabPage::ActivatePage( const SfxItemSet
& rSet
)
133 if( m_pColorList
.is() )
136 if( *m_pnColorListState
& ChangeType::CHANGED
||
137 *m_pnColorListState
& ChangeType::MODIFIED
)
139 SvxAreaTabDialog
* pArea
= (*m_pnColorListState
& ChangeType::CHANGED
) ?
140 dynamic_cast<SvxAreaTabDialog
*>(GetDialogController()) : nullptr;
142 m_pColorList
= pArea
->GetNewColorList();
144 ModifiedHdl_Impl( this );
147 // determining (and possibly cutting) the name and
148 // displaying it in the GroupBox
149 OUString aString
= CuiResId( RID_SVXSTR_TABLE
) + ": ";
150 INetURLObject
aURL( m_pGradientList
->GetPath() );
152 aURL
.Append( m_pGradientList
->GetName() );
153 SAL_WARN_IF( aURL
.GetProtocol() == INetProtocol::NotValid
, "cui.tabpages", "invalid URL" );
155 if ( aURL
.getBase().getLength() > 18 )
157 aString
+= aURL
.getBase().copy( 0, 15 ) + "...";
160 aString
+= aURL
.getBase();
162 sal_Int32 nPos
= SearchGradientList( rSet
.Get(XATTR_FILLGRADIENT
).GetName() );
163 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
165 sal_uInt16 nId
= m_xGradientLB
->GetItemId( static_cast<size_t>( nPos
) );
166 m_xGradientLB
->SelectItem( nId
);
168 // colors could have been deleted
169 ChangeGradientHdl_Impl();
174 DeactivateRC
SvxGradientTabPage::DeactivatePage( SfxItemSet
* _pSet
)
177 FillItemSet( _pSet
);
179 return DeactivateRC::LeavePage
;
182 bool SvxGradientTabPage::FillItemSet( SfxItemSet
* rSet
)
184 std::unique_ptr
<XGradient
> pXGradient
;
186 size_t nPos
= m_xGradientLB
->IsNoSelection() ? VALUESET_ITEM_NOTFOUND
: m_xGradientLB
->GetSelectItemPos();
187 if( nPos
!= VALUESET_ITEM_NOTFOUND
)
189 pXGradient
.reset(new XGradient( m_pGradientList
->GetGradient( static_cast<sal_uInt16
>(nPos
) )->GetGradient() ));
190 aString
= m_xGradientLB
->GetItemText( m_xGradientLB
->GetSelectedItemId() );
193 // gradient was passed (unidentified)
195 aString
= "gradient";
196 pXGradient
.reset(new XGradient( m_xLbColorFrom
->GetSelectEntryColor(),
197 m_xLbColorTo
->GetSelectEntryColor(),
198 static_cast<css::awt::GradientStyle
>(m_xLbGradientType
->get_active()),
199 static_cast<long>(m_xMtrAngle
->get_value(FieldUnit::NONE
) * 10), // should be changed in resource
200 static_cast<sal_uInt16
>(m_xMtrCenterX
->get_value(FieldUnit::NONE
)),
201 static_cast<sal_uInt16
>(m_xMtrCenterY
->get_value(FieldUnit::NONE
)),
202 static_cast<sal_uInt16
>(m_xMtrBorder
->get_value(FieldUnit::NONE
)),
203 static_cast<sal_uInt16
>(m_xMtrColorFrom
->get_value(FieldUnit::NONE
)),
204 static_cast<sal_uInt16
>(m_xMtrColorTo
->get_value(FieldUnit::NONE
)),
205 static_cast<sal_uInt16
>(m_xMtrIncrement
->get_value()) ));
208 sal_uInt16 nValue
= 0;
209 if (!m_xCbIncrement
->get_active())
210 nValue
= m_xMtrIncrement
->get_value();
212 assert( pXGradient
&& "XGradient could not be created" );
213 rSet
->Put( XFillStyleItem( drawing::FillStyle_GRADIENT
) );
214 rSet
->Put( XFillGradientItem( aString
, *pXGradient
) );
215 rSet
->Put( XGradientStepCountItem( nValue
) );
219 void SvxGradientTabPage::Reset( const SfxItemSet
* )
221 m_xMtrIncrement
->set_value(DEFAULT_GRADIENTSTEP
);
222 ChangeGradientHdl_Impl();
224 // determine state of the buttons
225 if( m_pGradientList
->Count() )
226 m_xBtnModify
->set_sensitive(true);
228 m_xBtnModify
->set_sensitive(false);
231 std::unique_ptr
<SfxTabPage
> SvxGradientTabPage::Create( weld::Container
* pPage
, weld::DialogController
* pController
,
232 const SfxItemSet
* rOutAttrs
)
234 return std::make_unique
<SvxGradientTabPage
>(pPage
, pController
, *rOutAttrs
);
237 IMPL_LINK( SvxGradientTabPage
, ModifiedListBoxHdl_Impl
, weld::ComboBox
&, rListBox
, void )
239 ModifiedHdl_Impl(&rListBox
);
240 // gradient params changed, it is no longer one of the presets
241 m_xGradientLB
->SetNoSelection();
244 IMPL_LINK( SvxGradientTabPage
, ModifiedColorListBoxHdl_Impl
, ColorListBox
&, rListBox
, void )
246 ModifiedHdl_Impl(&rListBox
);
247 m_xGradientLB
->SetNoSelection();
250 IMPL_LINK( SvxGradientTabPage
, ModifiedEditHdl_Impl
, weld::SpinButton
&, rBox
, void )
252 ModifiedHdl_Impl(&rBox
);
253 m_xGradientLB
->SetNoSelection();
256 IMPL_LINK( SvxGradientTabPage
, ModifiedMetricHdl_Impl
, weld::MetricSpinButton
&, rBox
, void )
258 ModifiedHdl_Impl(&rBox
);
259 m_xGradientLB
->SetNoSelection();
262 IMPL_LINK( SvxGradientTabPage
, ModifiedSliderHdl_Impl
, weld::Scale
&, rSlider
, void )
264 ModifiedHdl_Impl(&rSlider
);
265 m_xGradientLB
->SetNoSelection();
268 IMPL_LINK_NOARG( SvxGradientTabPage
, ChangeAutoStepHdl_Impl
, weld::ToggleButton
&, void )
270 if (m_xCbIncrement
->get_active())
272 m_xMtrIncrement
->set_sensitive(false);
276 m_xMtrIncrement
->set_sensitive(true);
278 ModifiedHdl_Impl(m_xMtrIncrement
.get());
281 void SvxGradientTabPage::ModifiedHdl_Impl( void const * pControl
)
283 if (pControl
== m_xMtrBorder
.get())
284 m_xSliderBorder
->set_value(m_xMtrBorder
->get_value(FieldUnit::NONE
));
285 if (pControl
== m_xSliderBorder
.get())
286 m_xMtrBorder
->set_value(m_xSliderBorder
->get_value(), FieldUnit::NONE
);
287 if (pControl
== m_xMtrAngle
.get())
288 m_xSliderAngle
->set_value(m_xMtrAngle
->get_value(FieldUnit::NONE
));
289 if (pControl
== m_xSliderAngle
.get())
290 m_xMtrAngle
->set_value(m_xSliderAngle
->get_value(), FieldUnit::NONE
);
292 css::awt::GradientStyle eXGS
= static_cast<css::awt::GradientStyle
>(m_xLbGradientType
->get_active());
294 XGradient
aXGradient( m_xLbColorFrom
->GetSelectEntryColor(),
295 m_xLbColorTo
->GetSelectEntryColor(),
297 static_cast<long>(m_xMtrAngle
->get_value(FieldUnit::NONE
) * 10), // should be changed in resource
298 static_cast<sal_uInt16
>(m_xMtrCenterX
->get_value(FieldUnit::NONE
)),
299 static_cast<sal_uInt16
>(m_xMtrCenterY
->get_value(FieldUnit::NONE
)),
300 static_cast<sal_uInt16
>(m_xMtrBorder
->get_value(FieldUnit::NONE
)),
301 static_cast<sal_uInt16
>(m_xMtrColorFrom
->get_value(FieldUnit::NONE
)),
302 static_cast<sal_uInt16
>(m_xMtrColorTo
->get_value(FieldUnit::NONE
)),
303 static_cast<sal_uInt16
>(m_xMtrIncrement
->get_value()) );
305 // enable/disable controls
306 if (pControl
== m_xLbGradientType
.get() || pControl
== this)
307 SetControlState_Impl( eXGS
);
309 sal_uInt16 nValue
= 0;
310 if (!m_xCbIncrement
->get_active())
311 nValue
= static_cast<sal_uInt16
>(m_xMtrIncrement
->get_value());
312 m_rXFSet
.Put( XGradientStepCountItem( nValue
) );
314 // displaying in XOutDev
315 m_rXFSet
.Put( XFillGradientItem( OUString(), aXGradient
) );
316 m_aCtlPreview
.SetAttributes(m_aXFillAttr
.GetItemSet());
317 m_aCtlPreview
.Invalidate();
320 IMPL_LINK_NOARG(SvxGradientTabPage
, ClickAddHdl_Impl
, weld::Button
&, void)
322 OUString
aNewName( SvxResId( RID_SVXSTR_GRADIENT
) );
323 OUString
aDesc( CuiResId( RID_SVXSTR_DESC_GRADIENT
) );
326 long nCount
= m_pGradientList
->Count();
328 bool bValidGradientName
= false;
330 while( !bValidGradientName
)
332 aName
= aNewName
+ " " + OUString::number( j
++ );
333 bValidGradientName
= (SearchGradientList(aName
) == LISTBOX_ENTRY_NOTFOUND
);
336 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
337 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg(pFact
->CreateSvxNameDialog(GetFrameWeld(), aName
, aDesc
));
338 sal_uInt16 nError
= 1;
340 while (pDlg
->Execute() == RET_OK
)
342 pDlg
->GetName( aName
);
344 bValidGradientName
= (SearchGradientList(aName
) == LISTBOX_ENTRY_NOTFOUND
);
346 if (bValidGradientName
)
352 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
353 std::unique_ptr
<weld::MessageDialog
> xWarnBox(xBuilder
->weld_message_dialog("DuplicateNameDialog"));
354 if (xWarnBox
->run() != RET_OK
)
357 pDlg
.disposeAndClear();
361 XGradient
aXGradient( m_xLbColorFrom
->GetSelectEntryColor(),
362 m_xLbColorTo
->GetSelectEntryColor(),
363 static_cast<css::awt::GradientStyle
>(m_xLbGradientType
->get_active()),
364 static_cast<long>(m_xMtrAngle
->get_value(FieldUnit::NONE
) * 10), // should be changed in resource
365 static_cast<sal_uInt16
>(m_xMtrCenterX
->get_value(FieldUnit::NONE
)),
366 static_cast<sal_uInt16
>(m_xMtrCenterY
->get_value(FieldUnit::NONE
)),
367 static_cast<sal_uInt16
>(m_xMtrBorder
->get_value(FieldUnit::NONE
)),
368 static_cast<sal_uInt16
>(m_xMtrColorFrom
->get_value(FieldUnit::NONE
)),
369 static_cast<sal_uInt16
>(m_xMtrColorTo
->get_value(FieldUnit::NONE
)),
370 static_cast<sal_uInt16
>(m_xMtrIncrement
->get_value()) );
372 m_pGradientList
->Insert(std::make_unique
<XGradientEntry
>(aXGradient
, aName
), nCount
);
374 sal_Int32 nId
= m_xGradientLB
->GetItemId(nCount
- 1); //calculate the last ID
375 BitmapEx aBitmap
= m_pGradientList
->GetBitmapForPreview( nCount
, m_xGradientLB
->GetIconSize() );
376 m_xGradientLB
->InsertItem( nId
+ 1, Image(aBitmap
), aName
);
377 m_xGradientLB
->SelectItem( nId
+ 1 );
378 m_xGradientLB
->Resize();
380 *m_pnGradientListState
|= ChangeType::MODIFIED
;
382 ChangeGradientHdl_Impl();
385 // determine button state
386 if (m_pGradientList
->Count())
387 m_xBtnModify
->set_sensitive(true);
391 IMPL_LINK_NOARG(SvxGradientTabPage
, ClickModifyHdl_Impl
, weld::Button
&, void)
393 sal_uInt16 nId
= m_xGradientLB
->GetSelectedItemId();
394 size_t nPos
= m_xGradientLB
->GetSelectItemPos();
396 if ( nPos
!= VALUESET_ITEM_NOTFOUND
)
398 OUString
aName( m_pGradientList
->GetGradient( static_cast<sal_uInt16
>(nPos
) )->GetName() );
400 XGradient
aXGradient( m_xLbColorFrom
->GetSelectEntryColor(),
401 m_xLbColorTo
->GetSelectEntryColor(),
402 static_cast<css::awt::GradientStyle
>(m_xLbGradientType
->get_active()),
403 static_cast<long>(m_xMtrAngle
->get_value(FieldUnit::NONE
) * 10), // should be changed in resource
404 static_cast<sal_uInt16
>(m_xMtrCenterX
->get_value(FieldUnit::NONE
)),
405 static_cast<sal_uInt16
>(m_xMtrCenterY
->get_value(FieldUnit::NONE
)),
406 static_cast<sal_uInt16
>(m_xMtrBorder
->get_value(FieldUnit::NONE
)),
407 static_cast<sal_uInt16
>(m_xMtrColorFrom
->get_value(FieldUnit::NONE
)),
408 static_cast<sal_uInt16
>(m_xMtrColorTo
->get_value(FieldUnit::NONE
)),
409 static_cast<sal_uInt16
>(m_xMtrIncrement
->get_value()) );
411 m_pGradientList
->Replace(std::make_unique
<XGradientEntry
>(aXGradient
, aName
), nPos
);
413 BitmapEx aBitmap
= m_pGradientList
->GetBitmapForPreview( static_cast<sal_uInt16
>(nPos
), m_xGradientLB
->GetIconSize() );
414 m_xGradientLB
->RemoveItem( nId
);
415 m_xGradientLB
->InsertItem( nId
, Image(aBitmap
), aName
, static_cast<sal_uInt16
>(nPos
) );
416 m_xGradientLB
->SelectItem( nId
);
418 *m_pnGradientListState
|= ChangeType::MODIFIED
;
422 IMPL_LINK_NOARG(SvxGradientTabPage
, ClickDeleteHdl_Impl
, SvxPresetListBox
*, void)
424 sal_uInt16 nId
= m_xGradientLB
->GetSelectedItemId();
425 size_t nPos
= m_xGradientLB
->GetSelectItemPos();
427 if( nPos
!= VALUESET_ITEM_NOTFOUND
)
429 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletegradientdialog.ui"));
430 std::unique_ptr
<weld::MessageDialog
> xQueryBox(xBuilder
->weld_message_dialog("AskDelGradientDialog"));
431 if (xQueryBox
->run() == RET_YES
)
433 m_pGradientList
->Remove(nPos
);
434 m_xGradientLB
->RemoveItem( nId
);
435 nId
= m_xGradientLB
->GetItemId( 0 );
436 m_xGradientLB
->SelectItem( nId
);
437 m_xGradientLB
->Resize();
439 m_aCtlPreview
.Invalidate();
441 ChangeGradientHdl_Impl();
443 *m_pnGradientListState
|= ChangeType::MODIFIED
;
446 // determine button state
447 if( !m_pGradientList
->Count() )
448 m_xBtnModify
->set_sensitive(false);
451 IMPL_LINK_NOARG(SvxGradientTabPage
, ClickRenameHdl_Impl
, SvxPresetListBox
*, void)
453 sal_uInt16 nId
= m_xGradientLB
->GetSelectedItemId();
454 size_t nPos
= m_xGradientLB
->GetSelectItemPos();
456 if ( nPos
!= VALUESET_ITEM_NOTFOUND
)
458 OUString
aDesc( CuiResId( RID_SVXSTR_DESC_GRADIENT
) );
459 OUString
aName( m_pGradientList
->GetGradient( nPos
)->GetName() );
461 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
462 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg(pFact
->CreateSvxNameDialog(GetFrameWeld(), aName
, aDesc
));
465 while( bLoop
&& pDlg
->Execute() == RET_OK
)
467 pDlg
->GetName( aName
);
468 sal_Int32 nGradientPos
= SearchGradientList(aName
);
469 bool bValidGradientName
= (nGradientPos
== static_cast<sal_Int32
>(nPos
) ) || (nGradientPos
== LISTBOX_ENTRY_NOTFOUND
);
471 if( bValidGradientName
)
474 m_pGradientList
->GetGradient(nPos
)->SetName(aName
);
476 m_xGradientLB
->SetItemText( nId
, aName
);
477 m_xGradientLB
->SelectItem( nId
);
479 *m_pnGradientListState
|= ChangeType::MODIFIED
;
483 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
484 std::unique_ptr
<weld::MessageDialog
> xBox(xBuilder
->weld_message_dialog("DuplicateNameDialog"));
491 IMPL_LINK_NOARG(SvxGradientTabPage
, ChangeGradientHdl
, SvtValueSet
*, void)
493 ChangeGradientHdl_Impl();
496 void SvxGradientTabPage::ChangeGradientHdl_Impl()
498 std::unique_ptr
<XGradient
> pGradient
;
499 size_t nPos
= m_xGradientLB
->GetSelectItemPos();
501 if( nPos
!= VALUESET_ITEM_NOTFOUND
)
502 pGradient
.reset(new XGradient( m_pGradientList
->GetGradient( static_cast<sal_uInt16
>( nPos
) )->GetGradient() ));
505 const SfxPoolItem
* pPoolItem
= nullptr;
506 if( SfxItemState::SET
== m_rOutAttrs
.GetItemState( GetWhich( XATTR_FILLSTYLE
), true, &pPoolItem
) )
508 if( ( drawing::FillStyle_GRADIENT
== static_cast<const XFillStyleItem
*>( pPoolItem
)->GetValue() ) &&
509 ( SfxItemState::SET
== m_rOutAttrs
.GetItemState( GetWhich( XATTR_FILLGRADIENT
), true, &pPoolItem
) ) )
511 pGradient
.reset(new XGradient( static_cast<const XFillGradientItem
*>( pPoolItem
)->GetGradientValue() ));
516 sal_uInt16 nPosition
= m_xGradientLB
->GetItemId(0);
517 m_xGradientLB
->SelectItem( nPosition
);
519 pGradient
.reset(new XGradient( m_pGradientList
->GetGradient( 0 )->GetGradient() ));
525 css::awt::GradientStyle eXGS
= pGradient
->GetGradientStyle();
526 sal_uInt16 nValue
= pGradient
->GetSteps();
529 m_xCbIncrement
->set_state(TRISTATE_TRUE
);
530 m_xMtrIncrement
->set_sensitive(false);
534 m_xCbIncrement
->set_state(TRISTATE_FALSE
);
535 m_xMtrIncrement
->set_sensitive(true);
536 m_xMtrIncrement
->set_value( nValue
);
538 m_xLbGradientType
->set_active(
539 sal::static_int_cast
< sal_Int32
>( eXGS
) );
540 // if the entry is not in the listbox,
541 // colors are added temporarily
542 m_xLbColorFrom
->SetNoSelection();
543 m_xLbColorFrom
->SelectEntry( pGradient
->GetStartColor() );
545 m_xLbColorTo
->SetNoSelection();
546 m_xLbColorTo
->SelectEntry( pGradient
->GetEndColor() );
548 m_xMtrAngle
->set_value(pGradient
->GetAngle() / 10, FieldUnit::NONE
); // should be changed in resource
549 m_xSliderAngle
->set_value(pGradient
->GetAngle() / 10);
550 m_xMtrBorder
->set_value(pGradient
->GetBorder(), FieldUnit::NONE
);
551 m_xSliderBorder
->set_value(pGradient
->GetBorder());
552 m_xMtrCenterX
->set_value(pGradient
->GetXOffset(), FieldUnit::NONE
);
553 m_xMtrCenterY
->set_value(pGradient
->GetYOffset(), FieldUnit::NONE
);
554 m_xMtrColorFrom
->set_value(pGradient
->GetStartIntens(), FieldUnit::NONE
);
555 m_xMtrColorTo
->set_value(pGradient
->GetEndIntens(), FieldUnit::NONE
);
557 // disable/enable controls
558 SetControlState_Impl( eXGS
);
560 // fill ItemSet and pass it on to aCtlPreview
561 m_rXFSet
.Put( XFillGradientItem( OUString(), *pGradient
) );
562 m_rXFSet
.Put( XGradientStepCountItem( nValue
) );
563 m_aCtlPreview
.SetAttributes(m_aXFillAttr
.GetItemSet());
565 m_aCtlPreview
.Invalidate();
569 void SvxGradientTabPage::SetControlState_Impl( css::awt::GradientStyle eXGS
)
573 case css::awt::GradientStyle_LINEAR
:
574 case css::awt::GradientStyle_AXIAL
:
575 m_xFtCenter
->set_sensitive(false);
576 m_xMtrCenterX
->set_sensitive(false);
577 m_xMtrCenterY
->set_sensitive(false);
578 m_xFtAngle
->set_sensitive(true);
579 m_xMtrAngle
->set_sensitive(true);
580 m_xSliderAngle
->set_sensitive(true);
583 case css::awt::GradientStyle_RADIAL
:
584 m_xFtCenter
->set_sensitive(true);
585 m_xMtrCenterX
->set_sensitive(true);
586 m_xMtrCenterY
->set_sensitive(true);
587 m_xFtAngle
->set_sensitive(false);
588 m_xMtrAngle
->set_sensitive(false);
589 m_xSliderAngle
->set_sensitive(false);
592 case css::awt::GradientStyle_ELLIPTICAL
:
593 m_xFtCenter
->set_sensitive(true);
594 m_xMtrCenterX
->set_sensitive(true);
595 m_xMtrCenterY
->set_sensitive(true);
596 m_xFtAngle
->set_sensitive(true);
597 m_xMtrAngle
->set_sensitive(true);
598 m_xSliderAngle
->set_sensitive(true);
601 case css::awt::GradientStyle_SQUARE
:
602 case css::awt::GradientStyle_RECT
:
603 m_xFtCenter
->set_sensitive(true);
604 m_xMtrCenterX
->set_sensitive(true);
605 m_xMtrCenterY
->set_sensitive(true);
606 m_xFtAngle
->set_sensitive(true);
607 m_xMtrAngle
->set_sensitive(true);
608 m_xSliderAngle
->set_sensitive(true);
615 sal_Int32
SvxGradientTabPage::SearchGradientList(const OUString
& rGradientName
)
617 long nCount
= m_pGradientList
->Count();
618 bool bValidGradientName
= true;
619 sal_Int32 nPos
= LISTBOX_ENTRY_NOTFOUND
;
621 for(long i
= 0;i
< nCount
&& bValidGradientName
;i
++)
623 if(rGradientName
== m_pGradientList
->GetGradient( i
)->GetName())
626 bValidGradientName
= false;
632 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */