Bump version to 6.4.7.2.M8
[LibreOffice.git] / cui / source / tabpages / tpgradnt.cxx
blob170d63fb96be8566ea0df1a4407aac00a6be1fe3
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 <memory>
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 = getDrawPreviewOptimalSize(m_aCtlPreview.GetDrawingArea()->get_ref_device());
72 m_xGradientLB->set_size_request(aSize.Width(), aSize.Height());
73 m_xCtlPreview->set_size_request(aSize.Width(), aSize.Height());
74 // this page needs ExchangeSupport
75 SetExchangeSupport();
77 // as long as NOT supported by the item
79 m_xMtrColorTo->set_value(100, FieldUnit::PERCENT);
80 m_xMtrColorFrom->set_value(100, FieldUnit::PERCENT);
82 // setting the output device
83 m_rXFSet.Put( XFillStyleItem(drawing::FillStyle_GRADIENT) );
84 m_rXFSet.Put( XFillGradientItem(OUString(), XGradient( COL_BLACK, COL_WHITE )) );
85 m_aCtlPreview.SetAttributes(m_aXFillAttr.GetItemSet());
87 // set handler
88 m_xGradientLB->SetSelectHdl( LINK( this, SvxGradientTabPage, ChangeGradientHdl ) );
89 m_xGradientLB->SetRenameHdl( LINK( this, SvxGradientTabPage, ClickRenameHdl_Impl ) );
90 m_xGradientLB->SetDeleteHdl( LINK( this, SvxGradientTabPage, ClickDeleteHdl_Impl ) );
91 m_xBtnAdd->connect_clicked(LINK(this, SvxGradientTabPage, ClickAddHdl_Impl));
92 m_xBtnModify->connect_clicked(LINK(this, SvxGradientTabPage, ClickModifyHdl_Impl));
94 Link<weld::MetricSpinButton&,void> aLink = LINK( this, SvxGradientTabPage, ModifiedMetricHdl_Impl );
95 Link<weld::ComboBox&,void> aLink2 = LINK( this, SvxGradientTabPage, ModifiedListBoxHdl_Impl );
96 m_xLbGradientType->connect_changed( aLink2 );
97 m_xCbIncrement->connect_toggled(LINK(this, SvxGradientTabPage, ChangeAutoStepHdl_Impl));
98 m_xMtrIncrement->connect_value_changed(LINK(this, SvxGradientTabPage, ModifiedEditHdl_Impl));
99 m_xMtrCenterX->connect_value_changed( aLink );
100 m_xMtrCenterY->connect_value_changed( aLink );
101 m_xMtrAngle->connect_value_changed( aLink );
102 m_xSliderAngle->connect_value_changed(LINK(this, SvxGradientTabPage, ModifiedSliderHdl_Impl));
103 m_xMtrBorder->connect_value_changed( aLink );
104 m_xSliderBorder->connect_value_changed(LINK(this, SvxGradientTabPage, ModifiedSliderHdl_Impl));
105 m_xMtrColorFrom->connect_value_changed( aLink );
106 Link<ColorListBox&,void> aLink3 = LINK( this, SvxGradientTabPage, ModifiedColorListBoxHdl_Impl );
107 m_xLbColorFrom->SetSelectHdl( aLink3 );
108 m_xMtrColorTo->connect_value_changed( aLink );
109 m_xLbColorTo->SetSelectHdl( aLink3 );
111 // #i76307# always paint the preview in LTR, because this is what the document does
112 m_aCtlPreview.EnableRTL(false);
115 SvxGradientTabPage::~SvxGradientTabPage()
117 m_xCtlPreview.reset();
118 m_xGradientLBWin.reset();
119 m_xGradientLB.reset();
120 m_xLbColorTo.reset();
121 m_xLbColorFrom.reset();
124 void SvxGradientTabPage::Construct()
126 m_xGradientLB->FillPresetListBox( *m_pGradientList );
129 void SvxGradientTabPage::ActivatePage( const SfxItemSet& rSet )
131 if( m_pColorList.is() )
133 // ColorList
134 if( *m_pnColorListState & ChangeType::CHANGED ||
135 *m_pnColorListState & ChangeType::MODIFIED )
137 SvxAreaTabDialog* pArea = (*m_pnColorListState & ChangeType::CHANGED) ?
138 dynamic_cast<SvxAreaTabDialog*>(GetDialogController()) : nullptr;
139 if (pArea)
140 m_pColorList = pArea->GetNewColorList();
142 ModifiedHdl_Impl( this );
145 // determining (and possibly cutting) the name and
146 // displaying it in the GroupBox
147 OUString aString = CuiResId( RID_SVXSTR_TABLE ) + ": ";
148 INetURLObject aURL( m_pGradientList->GetPath() );
150 aURL.Append( m_pGradientList->GetName() );
151 SAL_WARN_IF( aURL.GetProtocol() == INetProtocol::NotValid, "cui.tabpages", "invalid URL" );
153 if ( aURL.getBase().getLength() > 18 )
155 aString += aURL.getBase().copy( 0, 15 ) + "...";
157 else
158 aString += aURL.getBase();
160 sal_Int32 nPos = SearchGradientList( rSet.Get(XATTR_FILLGRADIENT).GetName() );
161 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
163 sal_uInt16 nId = m_xGradientLB->GetItemId( static_cast<size_t>( nPos ) );
164 m_xGradientLB->SelectItem( nId );
166 // colors could have been deleted
167 ChangeGradientHdl_Impl();
172 DeactivateRC SvxGradientTabPage::DeactivatePage( SfxItemSet* _pSet )
174 if( _pSet )
175 FillItemSet( _pSet );
177 return DeactivateRC::LeavePage;
180 bool SvxGradientTabPage::FillItemSet( SfxItemSet* rSet )
182 std::unique_ptr<XGradient> pXGradient;
183 OUString aString;
184 size_t nPos = m_xGradientLB->IsNoSelection() ? VALUESET_ITEM_NOTFOUND : m_xGradientLB->GetSelectItemPos();
185 if( nPos != VALUESET_ITEM_NOTFOUND )
187 pXGradient.reset(new XGradient( m_pGradientList->GetGradient( static_cast<sal_uInt16>(nPos) )->GetGradient() ));
188 aString = m_xGradientLB->GetItemText( m_xGradientLB->GetSelectedItemId() );
189 rSet->Put( XFillGradientItem( aString, *pXGradient ) );
191 else
192 // gradient was passed (unidentified)
194 pXGradient.reset(new XGradient( m_xLbColorFrom->GetSelectEntryColor(),
195 m_xLbColorTo->GetSelectEntryColor(),
196 static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
197 static_cast<long>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10), // should be changed in resource
198 static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
199 static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
200 static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
201 static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
202 static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
203 static_cast<sal_uInt16>(m_xMtrIncrement->get_value()) ));
204 rSet->Put( XFillGradientItem( OUString(), *pXGradient ) );
207 sal_uInt16 nValue = 0;
208 if (!m_xCbIncrement->get_active())
209 nValue = m_xMtrIncrement->get_value();
211 assert( pXGradient && "XGradient could not be created" );
212 rSet->Put( XFillStyleItem( drawing::FillStyle_GRADIENT ) );
213 rSet->Put( XGradientStepCountItem( nValue ) );
214 return true;
217 void SvxGradientTabPage::Reset( const SfxItemSet* )
219 m_xMtrIncrement->set_value(DEFAULT_GRADIENTSTEP);
220 ChangeGradientHdl_Impl();
222 // determine state of the buttons
223 if( m_pGradientList->Count() )
224 m_xBtnModify->set_sensitive(true);
225 else
226 m_xBtnModify->set_sensitive(false);
229 std::unique_ptr<SfxTabPage> SvxGradientTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
230 const SfxItemSet* rOutAttrs )
232 return std::make_unique<SvxGradientTabPage>(pPage, pController, *rOutAttrs);
235 IMPL_LINK( SvxGradientTabPage, ModifiedListBoxHdl_Impl, weld::ComboBox&, rListBox, void )
237 ModifiedHdl_Impl(&rListBox);
238 // gradient params changed, it is no longer one of the presets
239 m_xGradientLB->SetNoSelection();
242 IMPL_LINK( SvxGradientTabPage, ModifiedColorListBoxHdl_Impl, ColorListBox&, rListBox, void )
244 ModifiedHdl_Impl(&rListBox);
245 m_xGradientLB->SetNoSelection();
248 IMPL_LINK( SvxGradientTabPage, ModifiedEditHdl_Impl, weld::SpinButton&, rBox, void )
250 ModifiedHdl_Impl(&rBox);
251 m_xGradientLB->SetNoSelection();
254 IMPL_LINK( SvxGradientTabPage, ModifiedMetricHdl_Impl, weld::MetricSpinButton&, rBox, void )
256 ModifiedHdl_Impl(&rBox);
257 m_xGradientLB->SetNoSelection();
260 IMPL_LINK( SvxGradientTabPage, ModifiedSliderHdl_Impl, weld::Scale&, rSlider, void )
262 ModifiedHdl_Impl(&rSlider);
263 m_xGradientLB->SetNoSelection();
266 IMPL_LINK_NOARG( SvxGradientTabPage, ChangeAutoStepHdl_Impl, weld::ToggleButton&, void )
268 if (m_xCbIncrement->get_active())
270 m_xMtrIncrement->set_sensitive(false);
272 else
274 m_xMtrIncrement->set_sensitive(true);
276 ModifiedHdl_Impl(m_xMtrIncrement.get());
279 void SvxGradientTabPage::ModifiedHdl_Impl( void const * pControl )
281 if (pControl == m_xMtrBorder.get())
282 m_xSliderBorder->set_value(m_xMtrBorder->get_value(FieldUnit::NONE));
283 if (pControl == m_xSliderBorder.get())
284 m_xMtrBorder->set_value(m_xSliderBorder->get_value(), FieldUnit::NONE);
285 if (pControl == m_xMtrAngle.get())
286 m_xSliderAngle->set_value(m_xMtrAngle->get_value(FieldUnit::NONE));
287 if (pControl == m_xSliderAngle.get())
288 m_xMtrAngle->set_value(m_xSliderAngle->get_value(), FieldUnit::NONE);
290 css::awt::GradientStyle eXGS = static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active());
292 XGradient aXGradient( m_xLbColorFrom->GetSelectEntryColor(),
293 m_xLbColorTo->GetSelectEntryColor(),
294 eXGS,
295 static_cast<long>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10), // should be changed in resource
296 static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
297 static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
298 static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
299 static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
300 static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
301 static_cast<sal_uInt16>(m_xMtrIncrement->get_value()) );
303 // enable/disable controls
304 if (pControl == m_xLbGradientType.get() || pControl == this)
305 SetControlState_Impl( eXGS );
307 sal_uInt16 nValue = 0;
308 if (!m_xCbIncrement->get_active())
309 nValue = static_cast<sal_uInt16>(m_xMtrIncrement->get_value());
310 m_rXFSet.Put( XGradientStepCountItem( nValue ) );
312 // displaying in XOutDev
313 m_rXFSet.Put( XFillGradientItem( OUString(), aXGradient ) );
314 m_aCtlPreview.SetAttributes(m_aXFillAttr.GetItemSet());
315 m_aCtlPreview.Invalidate();
318 IMPL_LINK_NOARG(SvxGradientTabPage, ClickAddHdl_Impl, weld::Button&, void)
320 OUString aNewName( SvxResId( RID_SVXSTR_GRADIENT ) );
321 OUString aDesc( CuiResId( RID_SVXSTR_DESC_GRADIENT ) );
322 OUString aName;
324 long nCount = m_pGradientList->Count();
325 long j = 1;
326 bool bValidGradientName = false;
328 while( !bValidGradientName )
330 aName = aNewName + " " + OUString::number( j++ );
331 bValidGradientName = (SearchGradientList(aName) == LISTBOX_ENTRY_NOTFOUND);
334 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
335 ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetFrameWeld(), aName, aDesc));
336 sal_uInt16 nError = 1;
338 while (pDlg->Execute() == RET_OK)
340 pDlg->GetName( aName );
342 bValidGradientName = (SearchGradientList(aName) == LISTBOX_ENTRY_NOTFOUND);
344 if (bValidGradientName)
346 nError = 0;
347 break;
350 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
351 std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
352 if (xWarnBox->run() != RET_OK)
353 break;
355 pDlg.disposeAndClear();
357 if( !nError )
359 XGradient aXGradient( m_xLbColorFrom->GetSelectEntryColor(),
360 m_xLbColorTo->GetSelectEntryColor(),
361 static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
362 static_cast<long>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10), // should be changed in resource
363 static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
364 static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
365 static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
366 static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
367 static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
368 static_cast<sal_uInt16>(m_xMtrIncrement->get_value()) );
370 m_pGradientList->Insert(std::make_unique<XGradientEntry>(aXGradient, aName), nCount);
372 sal_Int32 nId = m_xGradientLB->GetItemId(nCount - 1); //calculate the last ID
373 BitmapEx aBitmap = m_pGradientList->GetBitmapForPreview( nCount, m_xGradientLB->GetIconSize() );
374 m_xGradientLB->InsertItem( nId + 1, Image(aBitmap), aName );
375 m_xGradientLB->SelectItem( nId + 1 );
376 m_xGradientLB->Resize();
378 *m_pnGradientListState |= ChangeType::MODIFIED;
380 ChangeGradientHdl_Impl();
383 // determine button state
384 if (m_pGradientList->Count())
385 m_xBtnModify->set_sensitive(true);
389 IMPL_LINK_NOARG(SvxGradientTabPage, ClickModifyHdl_Impl, weld::Button&, void)
391 sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
392 size_t nPos = m_xGradientLB->GetSelectItemPos();
394 if ( nPos != VALUESET_ITEM_NOTFOUND )
396 OUString aName( m_pGradientList->GetGradient( static_cast<sal_uInt16>(nPos) )->GetName() );
398 XGradient aXGradient( m_xLbColorFrom->GetSelectEntryColor(),
399 m_xLbColorTo->GetSelectEntryColor(),
400 static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
401 static_cast<long>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10), // should be changed in resource
402 static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
403 static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
404 static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
405 static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
406 static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
407 static_cast<sal_uInt16>(m_xMtrIncrement->get_value()) );
409 m_pGradientList->Replace(std::make_unique<XGradientEntry>(aXGradient, aName), nPos);
411 BitmapEx aBitmap = m_pGradientList->GetBitmapForPreview( static_cast<sal_uInt16>(nPos), m_xGradientLB->GetIconSize() );
412 m_xGradientLB->RemoveItem( nId );
413 m_xGradientLB->InsertItem( nId, Image(aBitmap), aName, static_cast<sal_uInt16>(nPos) );
414 m_xGradientLB->SelectItem( nId );
416 *m_pnGradientListState |= ChangeType::MODIFIED;
420 IMPL_LINK_NOARG(SvxGradientTabPage, ClickDeleteHdl_Impl, SvxPresetListBox*, void)
422 sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
423 size_t nPos = m_xGradientLB->GetSelectItemPos();
425 if( nPos != VALUESET_ITEM_NOTFOUND )
427 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletegradientdialog.ui"));
428 std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelGradientDialog"));
429 if (xQueryBox->run() == RET_YES)
431 m_pGradientList->Remove(nPos);
432 m_xGradientLB->RemoveItem( nId );
433 nId = m_xGradientLB->GetItemId( 0 );
434 m_xGradientLB->SelectItem( nId );
435 m_xGradientLB->Resize();
437 m_aCtlPreview.Invalidate();
439 ChangeGradientHdl_Impl();
441 *m_pnGradientListState |= ChangeType::MODIFIED;
444 // determine button state
445 if( !m_pGradientList->Count() )
446 m_xBtnModify->set_sensitive(false);
449 IMPL_LINK_NOARG(SvxGradientTabPage, ClickRenameHdl_Impl, SvxPresetListBox*, void)
451 sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
452 size_t nPos = m_xGradientLB->GetSelectItemPos();
454 if ( nPos != VALUESET_ITEM_NOTFOUND )
456 OUString aDesc( CuiResId( RID_SVXSTR_DESC_GRADIENT ) );
457 OUString aName( m_pGradientList->GetGradient( nPos )->GetName() );
459 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
460 ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetFrameWeld(), aName, aDesc));
462 bool bLoop = true;
463 while( bLoop && pDlg->Execute() == RET_OK )
465 pDlg->GetName( aName );
466 sal_Int32 nGradientPos = SearchGradientList(aName);
467 bool bValidGradientName = (nGradientPos == static_cast<sal_Int32>(nPos) ) || (nGradientPos == LISTBOX_ENTRY_NOTFOUND);
469 if( bValidGradientName )
471 bLoop = false;
472 m_pGradientList->GetGradient(nPos)->SetName(aName);
474 m_xGradientLB->SetItemText( nId, aName );
475 m_xGradientLB->SelectItem( nId );
477 *m_pnGradientListState |= ChangeType::MODIFIED;
479 else
481 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
482 std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
483 xBox->run();
489 IMPL_LINK_NOARG(SvxGradientTabPage, ChangeGradientHdl, SvtValueSet*, void)
491 ChangeGradientHdl_Impl();
494 void SvxGradientTabPage::ChangeGradientHdl_Impl()
496 std::unique_ptr<XGradient> pGradient;
497 size_t nPos = m_xGradientLB->GetSelectItemPos();
499 if( nPos != VALUESET_ITEM_NOTFOUND )
500 pGradient.reset(new XGradient( m_pGradientList->GetGradient( static_cast<sal_uInt16>( nPos ) )->GetGradient() ));
501 else
503 const SfxPoolItem* pPoolItem = nullptr;
504 if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), true, &pPoolItem ) )
506 if( ( drawing::FillStyle_GRADIENT == static_cast<const XFillStyleItem*>( pPoolItem )->GetValue() ) &&
507 ( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ), true, &pPoolItem ) ) )
509 pGradient.reset(new XGradient( static_cast<const XFillGradientItem*>( pPoolItem )->GetGradientValue() ));
512 if( !pGradient )
514 sal_uInt16 nPosition = m_xGradientLB->GetItemId(0);
515 m_xGradientLB->SelectItem( nPosition );
516 if( nPosition != 0 )
517 pGradient.reset(new XGradient( m_pGradientList->GetGradient( 0 )->GetGradient() ));
521 if( pGradient )
523 css::awt::GradientStyle eXGS = pGradient->GetGradientStyle();
524 sal_uInt16 nValue = pGradient->GetSteps();
525 if( nValue == 0 )
527 m_xCbIncrement->set_state(TRISTATE_TRUE);
528 m_xMtrIncrement->set_sensitive(false);
530 else
532 m_xCbIncrement->set_state(TRISTATE_FALSE);
533 m_xMtrIncrement->set_sensitive(true);
534 m_xMtrIncrement->set_value( nValue );
536 m_xLbGradientType->set_active(
537 sal::static_int_cast< sal_Int32 >( eXGS ) );
538 // if the entry is not in the listbox,
539 // colors are added temporarily
540 m_xLbColorFrom->SetNoSelection();
541 m_xLbColorFrom->SelectEntry( pGradient->GetStartColor() );
543 m_xLbColorTo->SetNoSelection();
544 m_xLbColorTo->SelectEntry( pGradient->GetEndColor() );
546 m_xMtrAngle->set_value(pGradient->GetAngle() / 10, FieldUnit::NONE); // should be changed in resource
547 m_xSliderAngle->set_value(pGradient->GetAngle() / 10);
548 m_xMtrBorder->set_value(pGradient->GetBorder(), FieldUnit::NONE);
549 m_xSliderBorder->set_value(pGradient->GetBorder());
550 m_xMtrCenterX->set_value(pGradient->GetXOffset(), FieldUnit::NONE);
551 m_xMtrCenterY->set_value(pGradient->GetYOffset(), FieldUnit::NONE);
552 m_xMtrColorFrom->set_value(pGradient->GetStartIntens(), FieldUnit::NONE);
553 m_xMtrColorTo->set_value(pGradient->GetEndIntens(), FieldUnit::NONE);
555 // disable/enable controls
556 SetControlState_Impl( eXGS );
558 // fill ItemSet and pass it on to aCtlPreview
559 m_rXFSet.Put( XFillGradientItem( OUString(), *pGradient ) );
560 m_rXFSet.Put( XGradientStepCountItem( nValue ) );
561 m_aCtlPreview.SetAttributes(m_aXFillAttr.GetItemSet());
563 m_aCtlPreview.Invalidate();
567 void SvxGradientTabPage::SetControlState_Impl( css::awt::GradientStyle eXGS )
569 switch( eXGS )
571 case css::awt::GradientStyle_LINEAR:
572 case css::awt::GradientStyle_AXIAL:
573 m_xFtCenter->set_sensitive(false);
574 m_xMtrCenterX->set_sensitive(false);
575 m_xMtrCenterY->set_sensitive(false);
576 m_xFtAngle->set_sensitive(true);
577 m_xMtrAngle->set_sensitive(true);
578 m_xSliderAngle->set_sensitive(true);
579 break;
581 case css::awt::GradientStyle_RADIAL:
582 m_xFtCenter->set_sensitive(true);
583 m_xMtrCenterX->set_sensitive(true);
584 m_xMtrCenterY->set_sensitive(true);
585 m_xFtAngle->set_sensitive(false);
586 m_xMtrAngle->set_sensitive(false);
587 m_xSliderAngle->set_sensitive(false);
588 break;
590 case css::awt::GradientStyle_ELLIPTICAL:
591 m_xFtCenter->set_sensitive(true);
592 m_xMtrCenterX->set_sensitive(true);
593 m_xMtrCenterY->set_sensitive(true);
594 m_xFtAngle->set_sensitive(true);
595 m_xMtrAngle->set_sensitive(true);
596 m_xSliderAngle->set_sensitive(true);
597 break;
599 case css::awt::GradientStyle_SQUARE:
600 case css::awt::GradientStyle_RECT:
601 m_xFtCenter->set_sensitive(true);
602 m_xMtrCenterX->set_sensitive(true);
603 m_xMtrCenterY->set_sensitive(true);
604 m_xFtAngle->set_sensitive(true);
605 m_xMtrAngle->set_sensitive(true);
606 m_xSliderAngle->set_sensitive(true);
607 break;
608 default:
609 break;
613 sal_Int32 SvxGradientTabPage::SearchGradientList(const OUString& rGradientName)
615 long nCount = m_pGradientList->Count();
616 bool bValidGradientName = true;
617 sal_Int32 nPos = LISTBOX_ENTRY_NOTFOUND;
619 for(long i = 0;i < nCount && bValidGradientName;i++)
621 if(rGradientName == m_pGradientList->GetGradient( i )->GetName())
623 nPos = i;
624 bValidGradientName = false;
627 return nPos;
630 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */