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")))
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  {
133  // ColorList
134  if( *m_pnColorListState & ChangeType::CHANGED ||
135  *m_pnColorListState & ChangeType::MODIFIED )
136  {
137  SvxAreaTabDialog* pArea = (*m_pnColorListState & ChangeType::CHANGED) ?
138  dynamic_cast<SvxAreaTabDialog*>(GetDialogController()) : nullptr;
139  if (pArea)
140  m_pColorList = pArea->GetNewColorList();
141 
142  ModifiedHdl_Impl( this );
143  }
144 
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() );
149 
150  aURL.Append( m_pGradientList->GetName() );
151  SAL_WARN_IF( aURL.GetProtocol() == INetProtocol::NotValid, "cui.tabpages", "invalid URL" );
152 
153  if ( aURL.getBase().getLength() > 18 )
154  {
155  aString += aURL.getBase().copy( 0, 15 ) + "...";
156  }
157  else
158  aString += aURL.getBase();
159 
160  sal_Int32 nPos = SearchGradientList( rSet.Get(XATTR_FILLGRADIENT).GetName() );
161  if ( nPos != LISTBOX_ENTRY_NOTFOUND )
162  {
163  sal_uInt16 nId = m_xGradientLB->GetItemId( static_cast<size_t>( nPos ) );
164  m_xGradientLB->SelectItem( nId );
165  }
166  // colors could have been deleted
168  }
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  OUString aString;
184  size_t nPos = m_xGradientLB->IsNoSelection() ? VALUESET_ITEM_NOTFOUND : m_xGradientLB->GetSelectItemPos();
185  if( nPos != VALUESET_ITEM_NOTFOUND )
186  {
187  pXGradient.reset(new XGradient( m_pGradientList->GetGradient( static_cast<sal_uInt16>(nPos) )->GetGradient() ));
188  aString = m_xGradientLB->GetItemText( m_xGradientLB->GetSelectedItemId() );
189  }
190  else
191  // gradient was passed (unidentified)
192  {
193  aString = "gradient";
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  }
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( XFillGradientItem( aString, *pXGradient ) );
213  rSet->Put( XGradientStepCountItem( nValue ) );
214  return true;
215 }
216 
218 {
221 
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);
227 }
228 
229 std::unique_ptr<SfxTabPage> SvxGradientTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
230  const SfxItemSet* rOutAttrs )
231 {
232  return std::make_unique<SvxGradientTabPage>(pPage, pController, *rOutAttrs);
233 }
234 
235 IMPL_LINK( SvxGradientTabPage, ModifiedListBoxHdl_Impl, weld::ComboBox&, rListBox, void )
236 {
237  ModifiedHdl_Impl(&rListBox);
238  // gradient params changed, it is no longer one of the presets
239  m_xGradientLB->SetNoSelection();
240 }
241 
242 IMPL_LINK( SvxGradientTabPage, ModifiedColorListBoxHdl_Impl, ColorListBox&, rListBox, void )
243 {
244  ModifiedHdl_Impl(&rListBox);
245  m_xGradientLB->SetNoSelection();
246 }
247 
248 IMPL_LINK( SvxGradientTabPage, ModifiedEditHdl_Impl, weld::SpinButton&, rBox, void )
249 {
250  ModifiedHdl_Impl(&rBox);
251  m_xGradientLB->SetNoSelection();
252 }
253 
254 IMPL_LINK( SvxGradientTabPage, ModifiedMetricHdl_Impl, weld::MetricSpinButton&, rBox, void )
255 {
256  ModifiedHdl_Impl(&rBox);
257  m_xGradientLB->SetNoSelection();
258 }
259 
260 IMPL_LINK( SvxGradientTabPage, ModifiedSliderHdl_Impl, weld::Scale&, rSlider, void )
261 {
262  ModifiedHdl_Impl(&rSlider);
263  m_xGradientLB->SetNoSelection();
264 }
265 
266 IMPL_LINK_NOARG( SvxGradientTabPage, ChangeAutoStepHdl_Impl, weld::ToggleButton&, void )
267 {
268  if (m_xCbIncrement->get_active())
269  {
270  m_xMtrIncrement->set_sensitive(false);
271  }
272  else
273  {
274  m_xMtrIncrement->set_sensitive(true);
275  }
276  ModifiedHdl_Impl(m_xMtrIncrement.get());
277 }
278 
279 void SvxGradientTabPage::ModifiedHdl_Impl( void const * pControl )
280 {
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);
289 
290  css::awt::GradientStyle eXGS = static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active());
291 
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()) );
302 
303  // enable/disable controls
304  if (pControl == m_xLbGradientType.get() || pControl == this)
305  SetControlState_Impl( eXGS );
306 
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 ) );
311 
312  // displaying in XOutDev
313  m_rXFSet.Put( XFillGradientItem( OUString(), aXGradient ) );
315  m_aCtlPreview.Invalidate();
316 }
317 
319 {
320  OUString aNewName( SvxResId( RID_SVXSTR_GRADIENT ) );
321  OUString aDesc( CuiResId( RID_SVXSTR_DESC_GRADIENT ) );
322  OUString aName;
323 
324  long nCount = m_pGradientList->Count();
325  long j = 1;
326  bool bValidGradientName = false;
327 
328  while( !bValidGradientName )
329  {
330  aName = aNewName + " " + OUString::number( j++ );
331  bValidGradientName = (SearchGradientList(aName) == LISTBOX_ENTRY_NOTFOUND);
332  }
333 
336  sal_uInt16 nError = 1;
337 
338  while (pDlg->Execute() == RET_OK)
339  {
340  pDlg->GetName( aName );
341 
342  bValidGradientName = (SearchGradientList(aName) == LISTBOX_ENTRY_NOTFOUND);
343 
344  if (bValidGradientName)
345  {
346  nError = 0;
347  break;
348  }
349 
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;
354  }
355  pDlg.disposeAndClear();
356 
357  if( !nError )
358  {
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()) );
369 
370  m_pGradientList->Insert(std::make_unique<XGradientEntry>(aXGradient, aName), nCount);
371 
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();
377 
378  *m_pnGradientListState |= ChangeType::MODIFIED;
379 
380  ChangeGradientHdl_Impl();
381  }
382 
383  // determine button state
384  if (m_pGradientList->Count())
385  m_xBtnModify->set_sensitive(true);
386 }
387 
388 
389 IMPL_LINK_NOARG(SvxGradientTabPage, ClickModifyHdl_Impl, weld::Button&, void)
390 {
391  sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
392  size_t nPos = m_xGradientLB->GetSelectItemPos();
393 
394  if ( nPos != VALUESET_ITEM_NOTFOUND )
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  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()) );
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 }
419 
421 {
422  sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
423  size_t nPos = m_xGradientLB->GetSelectItemPos();
424 
425  if( nPos != VALUESET_ITEM_NOTFOUND )
426  {
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)
430  {
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();
436 
437  m_aCtlPreview.Invalidate();
438 
439  ChangeGradientHdl_Impl();
440 
441  *m_pnGradientListState |= ChangeType::MODIFIED;
442  }
443  }
444  // determine button state
445  if( !m_pGradientList->Count() )
446  m_xBtnModify->set_sensitive(false);
447 }
448 
450 {
451  sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
452  size_t nPos = m_xGradientLB->GetSelectItemPos();
453 
454  if ( nPos != VALUESET_ITEM_NOTFOUND )
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 == LISTBOX_ENTRY_NOTFOUND);
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 
489 IMPL_LINK_NOARG(SvxGradientTabPage, ChangeGradientHdl, SvtValueSet*, void)
490 {
491  ChangeGradientHdl_Impl();
492 }
493 
495 {
496  std::unique_ptr<XGradient> pGradient;
497  size_t nPos = m_xGradientLB->GetSelectItemPos();
498 
499  if( nPos != VALUESET_ITEM_NOTFOUND )
500  pGradient.reset(new XGradient( m_pGradientList->GetGradient( static_cast<sal_uInt16>( nPos ) )->GetGradient() ));
501  else
502  {
503  const SfxPoolItem* pPoolItem = nullptr;
504  if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), true, &pPoolItem ) )
505  {
506  if( ( drawing::FillStyle_GRADIENT == static_cast<const XFillStyleItem*>( pPoolItem )->GetValue() ) &&
507  ( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ), true, &pPoolItem ) ) )
508  {
509  pGradient.reset(new XGradient( static_cast<const XFillGradientItem*>( pPoolItem )->GetGradientValue() ));
510  }
511  }
512  if( !pGradient )
513  {
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() ));
518  }
519  }
520 
521  if( pGradient )
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() / 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);
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 
567 void SvxGradientTabPage::SetControlState_Impl( css::awt::GradientStyle eXGS )
568 {
569  switch( eXGS )
570  {
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;
580 
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;
589 
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;
598 
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;
610  }
611 }
612 
613 sal_Int32 SvxGradientTabPage::SearchGradientList(const OUString& rGradientName)
614 {
615  long nCount = m_pGradientList->Count();
616  bool bValidGradientName = true;
617  sal_Int32 nPos = LISTBOX_ENTRY_NOTFOUND;
618 
619  for(long i = 0;i < nCount && bValidGradientName;i++)
620  {
621  if(rGradientName == m_pGradientList->GetGradient( i )->GetName())
622  {
623  nPos = i;
624  bValidGradientName = false;
625  }
626  }
627  return nPos;
628 }
629 
630 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Button > m_xBtnAdd
Definition: cuitabarea.hxx:376
long Width() const
FieldUnit
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
Size getDrawPreviewOptimalSize(const OutputDevice &rReference)
const XColorListRef & GetNewColorList() const
Definition: cuitabarea.hxx:124
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpgradnt.cxx:172
std::unique_ptr< weld::Scale > m_xSliderAngle
Definition: cuitabarea.hxx:366
std::unique_ptr< weld::Button > m_xBtnModify
Definition: cuitabarea.hxx:377
std::string GetValue
std::unique_ptr< weld::SpinButton > m_xMtrIncrement
Definition: cuitabarea.hxx:374
long Height() const
#define VALUESET_ITEM_NOTFOUND
XGradientListRef m_pGradientList
Definition: cuitabarea.hxx:351
static SvxAbstractDialogFactory * Create()
XColorListRef m_pColorList
Definition: cuitabarea.hxx:350
#define XATTR_FILLGRADIENT
sal_Int16 nId
TRISTATE_TRUE
std::unique_ptr< weld::MetricSpinButton > m_xMtrBorder
Definition: cuitabarea.hxx:367
#define LISTBOX_ENTRY_NOTFOUND
std::unique_ptr< ColorListBox > m_xLbColorFrom
Definition: cuitabarea.hxx:369
virtual VclPtr< AbstractSvxNameDialog > CreateSvxNameDialog(weld::Window *pParent, const OUString &rName, const OUString &rDesc)=0
virtual void Reset(const SfxItemSet *) override
Definition: tpgradnt.cxx:217
RET_YES
void ModifiedHdl_Impl(void const *)
Definition: tpgradnt.cxx:279
std::unique_ptr< weld::Scale > m_xSliderBorder
Definition: cuitabarea.hxx:368
OUString SvxResId(const char *pId)
void SetExchangeSupport()
std::unique_ptr< weld::CheckButton > m_xCbIncrement
Definition: cuitabarea.hxx:375
void SetControlState_Impl(css::awt::GradientStyle eXGS)
Definition: tpgradnt.cxx:567
ChangeType * m_pnColorListState
Definition: cuitabarea.hxx:354
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
bool Append(OUString const &rTheSegment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
std::unique_ptr< SvxPresetListBox > m_xGradientLB
Definition: cuitabarea.hxx:373
SvxGradientTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tpgradnt.cxx:43
int i
TRISTATE_FALSE
std::unique_ptr< weld::ComboBox > m_xLbGradientType
Definition: cuitabarea.hxx:360
std::unique_ptr< weld::CustomWeld > m_xGradientLBWin
Definition: cuitabarea.hxx:379
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
XFillAttrSetItem m_aXFillAttr
Definition: cuitabarea.hxx:356
const SfxItemSet & m_rOutAttrs
Definition: cuitabarea.hxx:348
void SetAttributes(const SfxItemSet &rItemSet)
std::unique_ptr< weld::MetricSpinButton > m_xMtrColorTo
Definition: cuitabarea.hxx:372
IMPL_LINK(SvxGradientTabPage, ModifiedListBoxHdl_Impl, weld::ComboBox &, rListBox, void)
Definition: tpgradnt.cxx:235
#define XATTR_FILLSTYLE
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpgradnt.cxx:129
std::unique_ptr< weld::MetricSpinButton > m_xMtrAngle
Definition: cuitabarea.hxx:365
SvxXRectPreview m_aCtlPreview
Definition: cuitabarea.hxx:359
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
std::unique_ptr< weld::MetricSpinButton > m_xMtrCenterY
Definition: cuitabarea.hxx:363
std::unique_ptr< weld::CustomWeld > m_xCtlPreview
Definition: cuitabarea.hxx:378
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
std::unique_ptr< weld::MetricSpinButton > m_xMtrCenterX
Definition: cuitabarea.hxx:362
virtual bool FillItemSet(SfxItemSet *) override
Definition: tpgradnt.cxx:180
sal_Int32 SearchGradientList(const OUString &rGradientName)
Definition: tpgradnt.cxx:613
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define SAL_WARN_IF(condition, area, stream)
RET_OK
const OUString PERCENT("Percent")
#define DEFAULT_GRADIENTSTEP
Definition: tpgradnt.cxx:39
SfxOkDialogController * GetDialogController() const
constexpr::Color COL_WHITE(0xFF, 0xFF, 0xFF)
DeactivateRC
OString const aName
std::unique_ptr< weld::Label > m_xFtAngle
Definition: cuitabarea.hxx:364
std::unique_ptr< weld::MetricSpinButton > m_xMtrColorFrom
Definition: cuitabarea.hxx:370
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
SfxItemSet & m_rXFSet
Definition: cuitabarea.hxx:357
IMPL_LINK_NOARG(SvxGradientTabPage, ChangeAutoStepHdl_Impl, weld::ToggleButton &, void)
Definition: tpgradnt.cxx:266
virtual ~SvxGradientTabPage() override
Definition: tpgradnt.cxx:115
std::unique_ptr< weld::Label > m_xFtCenter
Definition: cuitabarea.hxx:361
sal_Int32 nPos
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
std::unique_ptr< ColorListBox > m_xLbColorTo
Definition: cuitabarea.hxx:371
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpgradnt.cxx:229
void ChangeGradientHdl_Impl()
Definition: tpgradnt.cxx:494