LibreOffice Module cui (master)  1
tpgradnt.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <memory>
21 #include <tools/urlobj.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/weld.hxx>
24 #include <sfx2/dialoghelper.hxx>
25 
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>
38 
39 #define DEFAULT_GRADIENTSTEP 64
40 
41 using namespace com::sun::star;
42 
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", true)))
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))
70 {
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
76 
77  // as long as NOT supported by the item
78 
79  m_xMtrColorTo->set_value(100, FieldUnit::PERCENT);
80  m_xMtrColorFrom->set_value(100, FieldUnit::PERCENT);
81 
82  // setting the output device
83  m_rXFSet.Put( XFillStyleItem(drawing::FillStyle_GRADIENT) );
86 
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));
93 
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 );
110 
111  // #i76307# always paint the preview in LTR, because this is what the document does
112  m_aCtlPreview.EnableRTL(false);
113 }
114 
116 {
117  m_xCtlPreview.reset();
118  m_xGradientLBWin.reset();
119  m_xGradientLB.reset();
120  m_xLbColorTo.reset();
121  m_xLbColorFrom.reset();
122 }
123 
125 {
126  m_xGradientLB->FillPresetListBox( *m_pGradientList );
127 }
128 
130 {
131  if( !m_pColorList.is() )
132  return;
133 
134  // ColorList
135  if( *m_pnColorListState & ChangeType::CHANGED ||
136  *m_pnColorListState & ChangeType::MODIFIED )
137  {
138  SvxAreaTabDialog* pArea = (*m_pnColorListState & ChangeType::CHANGED) ?
139  dynamic_cast<SvxAreaTabDialog*>(GetDialogController()) : nullptr;
140  if (pArea)
141  m_pColorList = pArea->GetNewColorList();
142 
143  ModifiedHdl_Impl( this );
144  }
145 
146  // determining (and possibly cutting) the name and
147  // displaying it in the GroupBox
148  OUString aString = CuiResId( RID_SVXSTR_TABLE ) + ": ";
149  INetURLObject aURL( m_pGradientList->GetPath() );
150 
151  aURL.Append( m_pGradientList->GetName() );
152  SAL_WARN_IF( aURL.GetProtocol() == INetProtocol::NotValid, "cui.tabpages", "invalid URL" );
153 
154  if ( aURL.getBase().getLength() > 18 )
155  {
156  aString += OUString::Concat(aURL.getBase().subView( 0, 15 )) + "...";
157  }
158  else
159  aString += aURL.getBase();
160 
161  sal_Int32 nPos = SearchGradientList( rSet.Get(XATTR_FILLGRADIENT).GetName() );
162  if ( nPos != -1)
163  {
164  sal_uInt16 nId = m_xGradientLB->GetItemId( static_cast<size_t>( nPos ) );
165  m_xGradientLB->SelectItem( nId );
166  }
167  // colors could have been deleted
169 }
170 
171 
173 {
174  if( _pSet )
175  FillItemSet( _pSet );
176 
177  return DeactivateRC::LeavePage;
178 }
179 
181 {
182  std::unique_ptr<XGradient> pXGradient;
183  size_t nPos = m_xGradientLB->IsNoSelection() ? VALUESET_ITEM_NOTFOUND : m_xGradientLB->GetSelectItemPos();
184  if( nPos != VALUESET_ITEM_NOTFOUND )
185  {
186  pXGradient.reset(new XGradient( m_pGradientList->GetGradient( static_cast<sal_uInt16>(nPos) )->GetGradient() ));
187  OUString aString = m_xGradientLB->GetItemText( m_xGradientLB->GetSelectedItemId() );
188  rSet->Put( XFillGradientItem( aString, *pXGradient ) );
189  }
190  else
191  // gradient was passed (unidentified)
192  {
193  pXGradient.reset(new XGradient( m_xLbColorFrom->GetSelectEntryColor(),
194  m_xLbColorTo->GetSelectEntryColor(),
195  static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
196  Degree10(static_cast<sal_Int16>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10)), // should be changed in resource
197  static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
198  static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
199  static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
200  static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
201  static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
202  static_cast<sal_uInt16>(m_xMtrIncrement->get_value()) ));
203  rSet->Put( XFillGradientItem( OUString(), *pXGradient ) );
204  }
205 
206  sal_uInt16 nValue = 0;
207  if (!m_xCbIncrement->get_active())
208  nValue = m_xMtrIncrement->get_value();
209 
210  assert( pXGradient && "XGradient could not be created" );
211  rSet->Put( XFillStyleItem( drawing::FillStyle_GRADIENT ) );
212  rSet->Put( XGradientStepCountItem( nValue ) );
213  return true;
214 }
215 
217 {
220 
221  // determine state of the buttons
222  if( m_pGradientList->Count() )
223  m_xBtnModify->set_sensitive(true);
224  else
225  m_xBtnModify->set_sensitive(false);
226 }
227 
228 std::unique_ptr<SfxTabPage> SvxGradientTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
229  const SfxItemSet* rOutAttrs )
230 {
231  return std::make_unique<SvxGradientTabPage>(pPage, pController, *rOutAttrs);
232 }
233 
234 IMPL_LINK( SvxGradientTabPage, ModifiedListBoxHdl_Impl, weld::ComboBox&, rListBox, void )
235 {
236  ModifiedHdl_Impl(&rListBox);
237  // gradient params changed, it is no longer one of the presets
238  m_xGradientLB->SetNoSelection();
239 }
240 
241 IMPL_LINK( SvxGradientTabPage, ModifiedColorListBoxHdl_Impl, ColorListBox&, rListBox, void )
242 {
243  ModifiedHdl_Impl(&rListBox);
244  m_xGradientLB->SetNoSelection();
245 }
246 
247 IMPL_LINK( SvxGradientTabPage, ModifiedEditHdl_Impl, weld::SpinButton&, rBox, void )
248 {
249  ModifiedHdl_Impl(&rBox);
250  m_xGradientLB->SetNoSelection();
251 }
252 
253 IMPL_LINK( SvxGradientTabPage, ModifiedMetricHdl_Impl, weld::MetricSpinButton&, rBox, void )
254 {
255  ModifiedHdl_Impl(&rBox);
256  m_xGradientLB->SetNoSelection();
257 }
258 
259 IMPL_LINK( SvxGradientTabPage, ModifiedSliderHdl_Impl, weld::Scale&, rSlider, void )
260 {
261  ModifiedHdl_Impl(&rSlider);
262  m_xGradientLB->SetNoSelection();
263 }
264 
265 IMPL_LINK_NOARG( SvxGradientTabPage, ChangeAutoStepHdl_Impl, weld::ToggleButton&, void )
266 {
267  if (m_xCbIncrement->get_active())
268  {
269  m_xMtrIncrement->set_sensitive(false);
270  }
271  else
272  {
273  m_xMtrIncrement->set_sensitive(true);
274  }
275  ModifiedHdl_Impl(m_xMtrIncrement.get());
276 }
277 
278 void SvxGradientTabPage::ModifiedHdl_Impl( void const * pControl )
279 {
280  if (pControl == m_xMtrBorder.get())
281  m_xSliderBorder->set_value(m_xMtrBorder->get_value(FieldUnit::NONE));
282  if (pControl == m_xSliderBorder.get())
283  m_xMtrBorder->set_value(m_xSliderBorder->get_value(), FieldUnit::NONE);
284  if (pControl == m_xMtrAngle.get())
285  m_xSliderAngle->set_value(m_xMtrAngle->get_value(FieldUnit::NONE));
286  if (pControl == m_xSliderAngle.get())
287  m_xMtrAngle->set_value(m_xSliderAngle->get_value(), FieldUnit::NONE);
288 
289  css::awt::GradientStyle eXGS = static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active());
290 
291  XGradient aXGradient( m_xLbColorFrom->GetSelectEntryColor(),
292  m_xLbColorTo->GetSelectEntryColor(),
293  eXGS,
294  Degree10(static_cast<sal_Int16>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10)), // should be changed in resource
295  static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
296  static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
297  static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
298  static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
299  static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
300  static_cast<sal_uInt16>(m_xMtrIncrement->get_value()) );
301 
302  // enable/disable controls
303  if (pControl == m_xLbGradientType.get() || pControl == this)
304  SetControlState_Impl( eXGS );
305 
306  sal_uInt16 nValue = 0;
307  if (!m_xCbIncrement->get_active())
308  nValue = static_cast<sal_uInt16>(m_xMtrIncrement->get_value());
309  m_rXFSet.Put( XGradientStepCountItem( nValue ) );
310 
311  // displaying in XOutDev
312  m_rXFSet.Put( XFillGradientItem( OUString(), aXGradient ) );
314  m_aCtlPreview.Invalidate();
315 }
316 
318 {
319  OUString aNewName( SvxResId( RID_SVXSTR_GRADIENT ) );
320  OUString aDesc( CuiResId( RID_SVXSTR_DESC_GRADIENT ) );
321  OUString aName;
322 
323  tools::Long nCount = m_pGradientList->Count();
324  tools::Long j = 1;
325  bool bValidGradientName = false;
326 
327  while( !bValidGradientName )
328  {
329  aName = aNewName + " " + OUString::number( j++ );
330  bValidGradientName = (SearchGradientList(aName) == -1);
331  }
332 
335  sal_uInt16 nError = 1;
336 
337  while (pDlg->Execute() == RET_OK)
338  {
339  pDlg->GetName( aName );
340 
341  bValidGradientName = (SearchGradientList(aName) == -1);
342 
343  if (bValidGradientName)
344  {
345  nError = 0;
346  break;
347  }
348 
349  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
350  std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
351  if (xWarnBox->run() != RET_OK)
352  break;
353  }
354  pDlg.disposeAndClear();
355 
356  if( !nError )
357  {
358  XGradient aXGradient( m_xLbColorFrom->GetSelectEntryColor(),
359  m_xLbColorTo->GetSelectEntryColor(),
360  static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
361  Degree10(static_cast<sal_Int16>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10)), // should be changed in resource
362  static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
363  static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
364  static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
365  static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
366  static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
367  static_cast<sal_uInt16>(m_xMtrIncrement->get_value()) );
368 
369  m_pGradientList->Insert(std::make_unique<XGradientEntry>(aXGradient, aName), nCount);
370 
371  sal_Int32 nId = m_xGradientLB->GetItemId(nCount - 1); //calculate the last ID
372  BitmapEx aBitmap = m_pGradientList->GetBitmapForPreview( nCount, m_xGradientLB->GetIconSize() );
373  m_xGradientLB->InsertItem( nId + 1, Image(aBitmap), aName );
374  m_xGradientLB->SelectItem( nId + 1 );
375  m_xGradientLB->Resize();
376 
377  *m_pnGradientListState |= ChangeType::MODIFIED;
378 
379  ChangeGradientHdl_Impl();
380  }
381 
382  // determine button state
383  if (m_pGradientList->Count())
384  m_xBtnModify->set_sensitive(true);
385 }
386 
387 
388 IMPL_LINK_NOARG(SvxGradientTabPage, ClickModifyHdl_Impl, weld::Button&, void)
389 {
390  sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
391  size_t nPos = m_xGradientLB->GetSelectItemPos();
392 
393  if ( nPos == VALUESET_ITEM_NOTFOUND )
394  return;
395 
396  OUString aName( m_pGradientList->GetGradient( static_cast<sal_uInt16>(nPos) )->GetName() );
397 
398  XGradient aXGradient( m_xLbColorFrom->GetSelectEntryColor(),
399  m_xLbColorTo->GetSelectEntryColor(),
400  static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
401  Degree10(static_cast<sal_Int16>(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()) );
408 
409  m_pGradientList->Replace(std::make_unique<XGradientEntry>(aXGradient, aName), nPos);
410 
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 );
415 
416  *m_pnGradientListState |= ChangeType::MODIFIED;
417 }
418 
420 {
421  sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
422  size_t nPos = m_xGradientLB->GetSelectItemPos();
423 
424  if( nPos != VALUESET_ITEM_NOTFOUND )
425  {
426  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletegradientdialog.ui"));
427  std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelGradientDialog"));
428  if (xQueryBox->run() == RET_YES)
429  {
430  m_pGradientList->Remove(nPos);
431  m_xGradientLB->RemoveItem( nId );
432  nId = m_xGradientLB->GetItemId( 0 );
433  m_xGradientLB->SelectItem( nId );
434  m_xGradientLB->Resize();
435 
436  m_aCtlPreview.Invalidate();
437 
438  ChangeGradientHdl_Impl();
439 
440  *m_pnGradientListState |= ChangeType::MODIFIED;
441  }
442  }
443  // determine button state
444  if( !m_pGradientList->Count() )
445  m_xBtnModify->set_sensitive(false);
446 }
447 
449 {
450  sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
451  size_t nPos = m_xGradientLB->GetSelectItemPos();
452 
453  if ( nPos == VALUESET_ITEM_NOTFOUND )
454  return;
455 
456  OUString aDesc( CuiResId( RID_SVXSTR_DESC_GRADIENT ) );
457  OUString aName( m_pGradientList->GetGradient( nPos )->GetName() );
458 
460  ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetFrameWeld(), aName, aDesc));
461 
462  bool bLoop = true;
463  while( bLoop && pDlg->Execute() == RET_OK )
464  {
465  pDlg->GetName( aName );
466  sal_Int32 nGradientPos = SearchGradientList(aName);
467  bool bValidGradientName = (nGradientPos == static_cast<sal_Int32>(nPos) ) || (nGradientPos == -1);
468 
469  if( bValidGradientName )
470  {
471  bLoop = false;
472  m_pGradientList->GetGradient(nPos)->SetName(aName);
473 
474  m_xGradientLB->SetItemText( nId, aName );
475  m_xGradientLB->SelectItem( nId );
476 
477  *m_pnGradientListState |= ChangeType::MODIFIED;
478  }
479  else
480  {
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();
484  }
485  }
486 }
487 
488 IMPL_LINK_NOARG(SvxGradientTabPage, ChangeGradientHdl, ValueSet*, void)
489 {
490  ChangeGradientHdl_Impl();
491 }
492 
494 {
495  std::unique_ptr<XGradient> pGradient;
496  size_t nPos = m_xGradientLB->GetSelectItemPos();
497 
498  if( nPos != VALUESET_ITEM_NOTFOUND )
499  pGradient.reset(new XGradient( m_pGradientList->GetGradient( static_cast<sal_uInt16>( nPos ) )->GetGradient() ));
500  else
501  {
502  const SfxPoolItem* pPoolItem = nullptr;
503  if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), true, &pPoolItem ) )
504  {
505  if( ( drawing::FillStyle_GRADIENT == static_cast<const XFillStyleItem*>( pPoolItem )->GetValue() ) &&
506  ( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ), true, &pPoolItem ) ) )
507  {
508  pGradient.reset(new XGradient( static_cast<const XFillGradientItem*>( pPoolItem )->GetGradientValue() ));
509  }
510  }
511  if( !pGradient )
512  {
513  sal_uInt16 nPosition = m_xGradientLB->GetItemId(0);
514  m_xGradientLB->SelectItem( nPosition );
515  if( nPosition != 0 )
516  pGradient.reset(new XGradient( m_pGradientList->GetGradient( 0 )->GetGradient() ));
517  }
518  }
519 
520  if( !pGradient )
521  return;
522 
523  css::awt::GradientStyle eXGS = pGradient->GetGradientStyle();
524  sal_uInt16 nValue = pGradient->GetSteps();
525  if( nValue == 0 )
526  {
527  m_xCbIncrement->set_state(TRISTATE_TRUE);
528  m_xMtrIncrement->set_sensitive(false);
529  }
530  else
531  {
532  m_xCbIncrement->set_state(TRISTATE_FALSE);
533  m_xMtrIncrement->set_sensitive(true);
534  m_xMtrIncrement->set_value( nValue );
535  }
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() );
542 
543  m_xLbColorTo->SetNoSelection();
544  m_xLbColorTo->SelectEntry( pGradient->GetEndColor() );
545 
546  m_xMtrAngle->set_value(pGradient->GetAngle().get() / 10, FieldUnit::NONE); // should be changed in resource
547  m_xSliderAngle->set_value(pGradient->GetAngle().get() / 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);
554 
555  // disable/enable controls
556  SetControlState_Impl( eXGS );
557 
558  // fill ItemSet and pass it on to aCtlPreview
559  m_rXFSet.Put( XFillGradientItem( OUString(), *pGradient ) );
560  m_rXFSet.Put( XGradientStepCountItem( nValue ) );
562 
563  m_aCtlPreview.Invalidate();
564 }
565 
566 void SvxGradientTabPage::SetControlState_Impl( css::awt::GradientStyle eXGS )
567 {
568  switch( eXGS )
569  {
570  case css::awt::GradientStyle_LINEAR:
571  case css::awt::GradientStyle_AXIAL:
572  m_xFtCenter->set_sensitive(false);
573  m_xMtrCenterX->set_sensitive(false);
574  m_xMtrCenterY->set_sensitive(false);
575  m_xFtAngle->set_sensitive(true);
576  m_xMtrAngle->set_sensitive(true);
577  m_xSliderAngle->set_sensitive(true);
578  break;
579 
580  case css::awt::GradientStyle_RADIAL:
581  m_xFtCenter->set_sensitive(true);
582  m_xMtrCenterX->set_sensitive(true);
583  m_xMtrCenterY->set_sensitive(true);
584  m_xFtAngle->set_sensitive(false);
585  m_xMtrAngle->set_sensitive(false);
586  m_xSliderAngle->set_sensitive(false);
587  break;
588 
589  case css::awt::GradientStyle_ELLIPTICAL:
590  m_xFtCenter->set_sensitive(true);
591  m_xMtrCenterX->set_sensitive(true);
592  m_xMtrCenterY->set_sensitive(true);
593  m_xFtAngle->set_sensitive(true);
594  m_xMtrAngle->set_sensitive(true);
595  m_xSliderAngle->set_sensitive(true);
596  break;
597 
598  case css::awt::GradientStyle_SQUARE:
599  case css::awt::GradientStyle_RECT:
600  m_xFtCenter->set_sensitive(true);
601  m_xMtrCenterX->set_sensitive(true);
602  m_xMtrCenterY->set_sensitive(true);
603  m_xFtAngle->set_sensitive(true);
604  m_xMtrAngle->set_sensitive(true);
605  m_xSliderAngle->set_sensitive(true);
606  break;
607  default:
608  break;
609  }
610 }
611 
612 sal_Int32 SvxGradientTabPage::SearchGradientList(std::u16string_view rGradientName)
613 {
615  bool bValidGradientName = true;
616  sal_Int32 nPos = -1;
617 
618  for(tools::Long i = 0;i < nCount && bValidGradientName;i++)
619  {
620  if(rGradientName == m_pGradientList->GetGradient( i )->GetName())
621  {
622  nPos = i;
623  bValidGradientName = false;
624  }
625  }
626  return nPos;
627 }
628 
629 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Button > m_xBtnAdd
Definition: cuitabarea.hxx:375
URL aURL
FieldUnit
Size getDrawPreviewOptimalSize(const OutputDevice &rReference)
const XColorListRef & GetNewColorList() const
Definition: cuitabarea.hxx:122
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpgradnt.cxx:172
std::unique_ptr< weld::Scale > m_xSliderAngle
Definition: cuitabarea.hxx:365
std::unique_ptr< weld::Button > m_xBtnModify
Definition: cuitabarea.hxx:376
std::string GetValue
std::unique_ptr< weld::SpinButton > m_xMtrIncrement
Definition: cuitabarea.hxx:373
#define VALUESET_ITEM_NOTFOUND
XGradientListRef m_pGradientList
Definition: cuitabarea.hxx:350
static SvxAbstractDialogFactory * Create()
long Long
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
XColorListRef m_pColorList
Definition: cuitabarea.hxx:349
constexpr OUStringLiteral PERCENT(u"Percent")
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false)
sal_Int16 nId
TRISTATE_TRUE
std::unique_ptr< weld::MetricSpinButton > m_xMtrBorder
Definition: cuitabarea.hxx:366
std::unique_ptr< ColorListBox > m_xLbColorFrom
Definition: cuitabarea.hxx:368
virtual VclPtr< AbstractSvxNameDialog > CreateSvxNameDialog(weld::Window *pParent, const OUString &rName, const OUString &rDesc)=0
virtual void Reset(const SfxItemSet *) override
Definition: tpgradnt.cxx:216
RET_YES
void ModifiedHdl_Impl(void const *)
Definition: tpgradnt.cxx:278
std::unique_ptr< weld::Scale > m_xSliderBorder
Definition: cuitabarea.hxx:367
OUString SvxResId(const char *pId)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void SetExchangeSupport()
int nCount
std::unique_ptr< weld::CheckButton > m_xCbIncrement
Definition: cuitabarea.hxx:374
void SetControlState_Impl(css::awt::GradientStyle eXGS)
Definition: tpgradnt.cxx:566
ChangeType * m_pnColorListState
Definition: cuitabarea.hxx:353
constexpr TypedWhichId< XFillGradientItem > XATTR_FILLGRADIENT(XATTR_FILL_FIRST+2)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
int i
std::unique_ptr< SvxPresetListBox > m_xGradientLB
Definition: cuitabarea.hxx:372
SvxGradientTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tpgradnt.cxx:43
sal_Int32 SearchGradientList(std::u16string_view rGradientName)
Definition: tpgradnt.cxx:612
TRISTATE_FALSE
tools::Long Width() const
std::unique_ptr< weld::ComboBox > m_xLbGradientType
Definition: cuitabarea.hxx:359
std::unique_ptr< weld::CustomWeld > m_xGradientLBWin
Definition: cuitabarea.hxx:378
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
XFillAttrSetItem m_aXFillAttr
Definition: cuitabarea.hxx:355
const SfxItemSet & m_rOutAttrs
Definition: cuitabarea.hxx:347
void SetAttributes(const SfxItemSet &rItemSet)
std::unique_ptr< weld::MetricSpinButton > m_xMtrColorTo
Definition: cuitabarea.hxx:371
IMPL_LINK(SvxGradientTabPage, ModifiedListBoxHdl_Impl, weld::ComboBox &, rListBox, void)
Definition: tpgradnt.cxx:234
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpgradnt.cxx:129
std::unique_ptr< weld::MetricSpinButton > m_xMtrAngle
Definition: cuitabarea.hxx:364
SvxXRectPreview m_aCtlPreview
Definition: cuitabarea.hxx:358
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
std::unique_ptr< weld::MetricSpinButton > m_xMtrCenterY
Definition: cuitabarea.hxx:362
std::unique_ptr< weld::CustomWeld > m_xCtlPreview
Definition: cuitabarea.hxx:377
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
std::unique_ptr< weld::MetricSpinButton > m_xMtrCenterX
Definition: cuitabarea.hxx:361
virtual bool FillItemSet(SfxItemSet *) override
Definition: tpgradnt.cxx:180
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define SAL_WARN_IF(condition, area, stream)
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
OUString aName
RET_OK
tools::Long Height() const
#define DEFAULT_GRADIENTSTEP
Definition: tpgradnt.cxx:39
SfxOkDialogController * GetDialogController() const
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
DeactivateRC
std::unique_ptr< weld::Label > m_xFtAngle
Definition: cuitabarea.hxx:363
std::unique_ptr< weld::MetricSpinButton > m_xMtrColorFrom
Definition: cuitabarea.hxx:369
SfxItemSet & m_rXFSet
Definition: cuitabarea.hxx:356
IMPL_LINK_NOARG(SvxGradientTabPage, ChangeAutoStepHdl_Impl, weld::ToggleButton &, void)
Definition: tpgradnt.cxx:265
virtual ~SvxGradientTabPage() override
Definition: tpgradnt.cxx:115
std::unique_ptr< weld::Label > m_xFtCenter
Definition: cuitabarea.hxx:360
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
std::unique_ptr< ColorListBox > m_xLbColorTo
Definition: cuitabarea.hxx:370
sal_uInt16 nPos
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
sal_Int16 nValue
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpgradnt.cxx:228
void ChangeGradientHdl_Impl()
Definition: tpgradnt.cxx:493