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"),
60  [this]{ return GetDialogController()->getDialog(); }))
61  , m_xMtrColorFrom(m_xBuilder->weld_metric_spin_button("colorfrommtr", FieldUnit::PERCENT))
62  , m_xLbColorTo(new ColorListBox(m_xBuilder->weld_menu_button("colortolb"),
63  [this]{ return GetDialogController()->getDialog(); }))
64  , m_xMtrColorTo(m_xBuilder->weld_metric_spin_button("colortomtr", FieldUnit::PERCENT))
65  , m_xGradientLB(new SvxPresetListBox(m_xBuilder->weld_scrolled_window("gradientpresetlistwin", true)))
66  , m_xMtrIncrement(m_xBuilder->weld_spin_button("incrementmtr"))
67  , m_xCbIncrement(m_xBuilder->weld_check_button("autoincrement"))
68  , m_xBtnAdd(m_xBuilder->weld_button("add"))
69  , m_xBtnModify(m_xBuilder->weld_button("modify"))
70  , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder, "previewctl", m_aCtlPreview))
71  , m_xGradientLBWin(new weld::CustomWeld(*m_xBuilder, "gradientpresetlist", *m_xGradientLB))
72 {
73  Size aSize = getDrawPreviewOptimalSize(m_aCtlPreview.GetDrawingArea()->get_ref_device());
74  m_xGradientLB->set_size_request(aSize.Width(), aSize.Height());
75  m_xCtlPreview->set_size_request(aSize.Width(), aSize.Height());
76  // this page needs ExchangeSupport
77  SetExchangeSupport();
78 
79  // as long as NOT supported by the item
80 
81  m_xMtrColorTo->set_value(100, FieldUnit::PERCENT);
82  m_xMtrColorFrom->set_value(100, FieldUnit::PERCENT);
83 
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());
88 
89  // set handler
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));
95 
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 );
112 
113  m_xGradientLB->SetStyle(WB_FLATVALUESET | WB_NO_DIRECTSELECT | WB_TABSTOP);
114 
115  // #i76307# always paint the preview in LTR, because this is what the document does
116  m_aCtlPreview.EnableRTL(false);
117 }
118 
120 {
121  m_xCtlPreview.reset();
122  m_xGradientLBWin.reset();
123  m_xGradientLB.reset();
124  m_xLbColorTo.reset();
125  m_xLbColorFrom.reset();
126 }
127 
129 {
130  m_xGradientLB->FillPresetListBox( *m_pGradientList );
131 }
132 
134 {
135  if( !m_pColorList.is() )
136  return;
137 
138  // ColorList
139  if( *m_pnColorListState & ChangeType::CHANGED ||
140  *m_pnColorListState & ChangeType::MODIFIED )
141  {
142  SvxAreaTabDialog* pArea = (*m_pnColorListState & ChangeType::CHANGED) ?
143  dynamic_cast<SvxAreaTabDialog*>(GetDialogController()) : nullptr;
144  if (pArea)
145  m_pColorList = pArea->GetNewColorList();
146 
147  ModifiedHdl_Impl( this );
148  }
149 
150  // determining (and possibly cutting) the name and
151  // displaying it in the GroupBox
152  OUString aString = CuiResId( RID_SVXSTR_TABLE ) + ": ";
153  INetURLObject aURL( m_pGradientList->GetPath() );
154 
155  aURL.Append( m_pGradientList->GetName() );
156  SAL_WARN_IF( aURL.GetProtocol() == INetProtocol::NotValid, "cui.tabpages", "invalid URL" );
157 
158  if ( aURL.getBase().getLength() > 18 )
159  {
160  aString += OUString::Concat(aURL.getBase().subView( 0, 15 )) + "...";
161  }
162  else
163  aString += aURL.getBase();
164 
165  sal_Int32 nPos = SearchGradientList( rSet.Get(XATTR_FILLGRADIENT).GetName() );
166  if ( nPos != -1)
167  {
168  sal_uInt16 nId = m_xGradientLB->GetItemId( static_cast<size_t>( nPos ) );
169  m_xGradientLB->SelectItem( nId );
170  }
171  // colors could have been deleted
173 }
174 
175 
177 {
178  if( _pSet )
179  FillItemSet( _pSet );
180 
181  return DeactivateRC::LeavePage;
182 }
183 
185 {
186  std::unique_ptr<XGradient> pXGradient;
187  size_t nPos = m_xGradientLB->IsNoSelection() ? VALUESET_ITEM_NOTFOUND : m_xGradientLB->GetSelectItemPos();
188  if( nPos != VALUESET_ITEM_NOTFOUND )
189  {
190  pXGradient.reset(new XGradient( m_pGradientList->GetGradient( static_cast<sal_uInt16>(nPos) )->GetGradient() ));
191  OUString aString = m_xGradientLB->GetItemText( m_xGradientLB->GetSelectedItemId() );
192  rSet->Put( XFillGradientItem( aString, *pXGradient ) );
193  }
194  else
195  // gradient was passed (unidentified)
196  {
197  pXGradient.reset(new XGradient( m_xLbColorFrom->GetSelectEntryColor(),
198  m_xLbColorTo->GetSelectEntryColor(),
199  static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
200  Degree10(static_cast<sal_Int16>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10)), // should be changed in resource
201  static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
202  static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
203  static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
204  static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
205  static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
206  static_cast<sal_uInt16>(m_xMtrIncrement->get_value()) ));
207  rSet->Put( XFillGradientItem( OUString(), *pXGradient ) );
208  }
209 
210  sal_uInt16 nValue = 0;
211  if (!m_xCbIncrement->get_active())
212  nValue = m_xMtrIncrement->get_value();
213 
214  assert( pXGradient && "XGradient could not be created" );
215  rSet->Put( XFillStyleItem( drawing::FillStyle_GRADIENT ) );
216  rSet->Put( XGradientStepCountItem( nValue ) );
217  return true;
218 }
219 
221 {
224 
225  // determine state of the buttons
226  if( m_pGradientList->Count() )
227  m_xBtnModify->set_sensitive(true);
228  else
229  m_xBtnModify->set_sensitive(false);
230 }
231 
232 std::unique_ptr<SfxTabPage> SvxGradientTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
233  const SfxItemSet* rOutAttrs )
234 {
235  return std::make_unique<SvxGradientTabPage>(pPage, pController, *rOutAttrs);
236 }
237 
238 IMPL_LINK( SvxGradientTabPage, ModifiedListBoxHdl_Impl, weld::ComboBox&, rListBox, void )
239 {
240  ModifiedHdl_Impl(&rListBox);
241  // gradient params changed, it is no longer one of the presets
242  m_xGradientLB->SetNoSelection();
243 }
244 
245 IMPL_LINK( SvxGradientTabPage, ModifiedColorListBoxHdl_Impl, ColorListBox&, rListBox, void )
246 {
247  ModifiedHdl_Impl(&rListBox);
248  m_xGradientLB->SetNoSelection();
249 }
250 
251 IMPL_LINK( SvxGradientTabPage, ModifiedEditHdl_Impl, weld::SpinButton&, rBox, void )
252 {
253  ModifiedHdl_Impl(&rBox);
254  m_xGradientLB->SetNoSelection();
255 }
256 
257 IMPL_LINK( SvxGradientTabPage, ModifiedMetricHdl_Impl, weld::MetricSpinButton&, rBox, void )
258 {
259  ModifiedHdl_Impl(&rBox);
260  m_xGradientLB->SetNoSelection();
261 }
262 
263 IMPL_LINK( SvxGradientTabPage, ModifiedSliderHdl_Impl, weld::Scale&, rSlider, void )
264 {
265  ModifiedHdl_Impl(&rSlider);
266  m_xGradientLB->SetNoSelection();
267 }
268 
269 IMPL_LINK_NOARG( SvxGradientTabPage, ChangeAutoStepHdl_Impl, weld::Toggleable&, void )
270 {
271  if (m_xCbIncrement->get_active())
272  {
273  m_xMtrIncrement->set_sensitive(false);
274  }
275  else
276  {
277  m_xMtrIncrement->set_sensitive(true);
278  }
279  ModifiedHdl_Impl(m_xMtrIncrement.get());
280 }
281 
282 void SvxGradientTabPage::ModifiedHdl_Impl( void const * pControl )
283 {
284  if (pControl == m_xMtrBorder.get())
285  m_xSliderBorder->set_value(m_xMtrBorder->get_value(FieldUnit::NONE));
286  if (pControl == m_xSliderBorder.get())
287  m_xMtrBorder->set_value(m_xSliderBorder->get_value(), FieldUnit::NONE);
288  if (pControl == m_xMtrAngle.get())
289  m_xSliderAngle->set_value(m_xMtrAngle->get_value(FieldUnit::NONE));
290  if (pControl == m_xSliderAngle.get())
291  m_xMtrAngle->set_value(m_xSliderAngle->get_value(), FieldUnit::NONE);
292 
293  css::awt::GradientStyle eXGS = static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active());
294 
295  XGradient aXGradient( m_xLbColorFrom->GetSelectEntryColor(),
296  m_xLbColorTo->GetSelectEntryColor(),
297  eXGS,
298  Degree10(static_cast<sal_Int16>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10)), // should be changed in resource
299  static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
300  static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
301  static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
302  static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
303  static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
304  static_cast<sal_uInt16>(m_xMtrIncrement->get_value()) );
305 
306  // enable/disable controls
307  if (pControl == m_xLbGradientType.get() || pControl == this)
308  SetControlState_Impl( eXGS );
309 
310  sal_uInt16 nValue = 0;
311  if (!m_xCbIncrement->get_active())
312  nValue = static_cast<sal_uInt16>(m_xMtrIncrement->get_value());
313  m_rXFSet.Put( XGradientStepCountItem( nValue ) );
314 
315  // displaying in XOutDev
316  m_rXFSet.Put( XFillGradientItem( OUString(), aXGradient ) );
318  m_aCtlPreview.Invalidate();
319 }
320 
322 {
323  OUString aNewName( SvxResId( RID_SVXSTR_GRADIENT ) );
324  OUString aDesc( CuiResId( RID_SVXSTR_DESC_GRADIENT ) );
325  OUString aName;
326 
327  tools::Long nCount = m_pGradientList->Count();
328  tools::Long j = 1;
329  bool bValidGradientName = false;
330 
331  while( !bValidGradientName )
332  {
333  aName = aNewName + " " + OUString::number( j++ );
334  bValidGradientName = (SearchGradientList(aName) == -1);
335  }
336 
339  sal_uInt16 nError = 1;
340 
341  while (pDlg->Execute() == RET_OK)
342  {
343  pDlg->GetName( aName );
344 
345  bValidGradientName = (SearchGradientList(aName) == -1);
346 
347  if (bValidGradientName)
348  {
349  nError = 0;
350  break;
351  }
352 
353  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
354  std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
355  if (xWarnBox->run() != RET_OK)
356  break;
357  }
358  pDlg.disposeAndClear();
359 
360  if( !nError )
361  {
362  XGradient aXGradient( m_xLbColorFrom->GetSelectEntryColor(),
363  m_xLbColorTo->GetSelectEntryColor(),
364  static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
365  Degree10(static_cast<sal_Int16>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10)), // should be changed in resource
366  static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
367  static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
368  static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
369  static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
370  static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
371  static_cast<sal_uInt16>(m_xMtrIncrement->get_value()) );
372 
373  m_pGradientList->Insert(std::make_unique<XGradientEntry>(aXGradient, aName), nCount);
374 
375  sal_Int32 nId = m_xGradientLB->GetItemId(nCount - 1); //calculate the last ID
376  BitmapEx aBitmap = m_pGradientList->GetBitmapForPreview( nCount, m_xGradientLB->GetIconSize() );
377  m_xGradientLB->InsertItem( nId + 1, Image(aBitmap), aName );
378  m_xGradientLB->SelectItem( nId + 1 );
379  m_xGradientLB->Resize();
380 
381  *m_pnGradientListState |= ChangeType::MODIFIED;
382 
383  ChangeGradientHdl_Impl();
384  }
385 
386  // determine button state
387  if (m_pGradientList->Count())
388  m_xBtnModify->set_sensitive(true);
389 }
390 
391 
392 IMPL_LINK_NOARG(SvxGradientTabPage, ClickModifyHdl_Impl, weld::Button&, void)
393 {
394  sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
395  size_t nPos = m_xGradientLB->GetSelectItemPos();
396 
397  if ( nPos == VALUESET_ITEM_NOTFOUND )
398  return;
399 
400  OUString aName( m_pGradientList->GetGradient( static_cast<sal_uInt16>(nPos) )->GetName() );
401 
402  XGradient aXGradient( m_xLbColorFrom->GetSelectEntryColor(),
403  m_xLbColorTo->GetSelectEntryColor(),
404  static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
405  Degree10(static_cast<sal_Int16>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10)), // should be changed in resource
406  static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
407  static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
408  static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
409  static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
410  static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
411  static_cast<sal_uInt16>(m_xMtrIncrement->get_value()) );
412 
413  m_pGradientList->Replace(std::make_unique<XGradientEntry>(aXGradient, aName), nPos);
414 
415  BitmapEx aBitmap = m_pGradientList->GetBitmapForPreview( static_cast<sal_uInt16>(nPos), m_xGradientLB->GetIconSize() );
416  m_xGradientLB->RemoveItem( nId );
417  m_xGradientLB->InsertItem( nId, Image(aBitmap), aName, static_cast<sal_uInt16>(nPos) );
418  m_xGradientLB->SelectItem( nId );
419 
420  *m_pnGradientListState |= ChangeType::MODIFIED;
421 }
422 
424 {
425  sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
426  size_t nPos = m_xGradientLB->GetSelectItemPos();
427 
428  if( nPos != VALUESET_ITEM_NOTFOUND )
429  {
430  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletegradientdialog.ui"));
431  std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelGradientDialog"));
432  if (xQueryBox->run() == RET_YES)
433  {
434  m_pGradientList->Remove(nPos);
435  m_xGradientLB->RemoveItem( nId );
436  nId = m_xGradientLB->GetItemId( 0 );
437  m_xGradientLB->SelectItem( nId );
438  m_xGradientLB->Resize();
439 
440  m_aCtlPreview.Invalidate();
441 
442  ChangeGradientHdl_Impl();
443 
444  *m_pnGradientListState |= ChangeType::MODIFIED;
445  }
446  }
447  // determine button state
448  if( !m_pGradientList->Count() )
449  m_xBtnModify->set_sensitive(false);
450 }
451 
453 {
454  sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
455  size_t nPos = m_xGradientLB->GetSelectItemPos();
456 
457  if ( nPos == VALUESET_ITEM_NOTFOUND )
458  return;
459 
460  OUString aDesc( CuiResId( RID_SVXSTR_DESC_GRADIENT ) );
461  OUString aName( m_pGradientList->GetGradient( nPos )->GetName() );
462 
464  ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetFrameWeld(), aName, aDesc));
465 
466  bool bLoop = true;
467  while( bLoop && pDlg->Execute() == RET_OK )
468  {
469  pDlg->GetName( aName );
470  sal_Int32 nGradientPos = SearchGradientList(aName);
471  bool bValidGradientName = (nGradientPos == static_cast<sal_Int32>(nPos) ) || (nGradientPos == -1);
472 
473  if( bValidGradientName )
474  {
475  bLoop = false;
476  m_pGradientList->GetGradient(nPos)->SetName(aName);
477 
478  m_xGradientLB->SetItemText( nId, aName );
479  m_xGradientLB->SelectItem( nId );
480 
481  *m_pnGradientListState |= ChangeType::MODIFIED;
482  }
483  else
484  {
485  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
486  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
487  xBox->run();
488  }
489  }
490 }
491 
492 IMPL_LINK_NOARG(SvxGradientTabPage, ChangeGradientHdl, ValueSet*, void)
493 {
494  ChangeGradientHdl_Impl();
495 }
496 
498 {
499  std::unique_ptr<XGradient> pGradient;
500  size_t nPos = m_xGradientLB->GetSelectItemPos();
501 
502  if( nPos != VALUESET_ITEM_NOTFOUND )
503  pGradient.reset(new XGradient( m_pGradientList->GetGradient( static_cast<sal_uInt16>( nPos ) )->GetGradient() ));
504  else
505  {
506  const SfxPoolItem* pPoolItem = nullptr;
507  if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), true, &pPoolItem ) )
508  {
509  if( ( drawing::FillStyle_GRADIENT == static_cast<const XFillStyleItem*>( pPoolItem )->GetValue() ) &&
510  ( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ), true, &pPoolItem ) ) )
511  {
512  pGradient.reset(new XGradient( static_cast<const XFillGradientItem*>( pPoolItem )->GetGradientValue() ));
513  }
514  }
515  if( !pGradient )
516  {
517  sal_uInt16 nPosition = m_xGradientLB->GetItemId(0);
518  m_xGradientLB->SelectItem( nPosition );
519  if( nPosition != 0 )
520  pGradient.reset(new XGradient( m_pGradientList->GetGradient( 0 )->GetGradient() ));
521  }
522  }
523 
524  if( !pGradient )
525  return;
526 
527  css::awt::GradientStyle eXGS = pGradient->GetGradientStyle();
528  sal_uInt16 nValue = pGradient->GetSteps();
529  if( nValue == 0 )
530  {
531  m_xCbIncrement->set_state(TRISTATE_TRUE);
532  m_xMtrIncrement->set_sensitive(false);
533  }
534  else
535  {
536  m_xCbIncrement->set_state(TRISTATE_FALSE);
537  m_xMtrIncrement->set_sensitive(true);
538  m_xMtrIncrement->set_value( nValue );
539  }
540  m_xLbGradientType->set_active(
541  sal::static_int_cast< sal_Int32 >( eXGS ) );
542  // if the entry is not in the listbox,
543  // colors are added temporarily
544  m_xLbColorFrom->SetNoSelection();
545  m_xLbColorFrom->SelectEntry( pGradient->GetStartColor() );
546 
547  m_xLbColorTo->SetNoSelection();
548  m_xLbColorTo->SelectEntry( pGradient->GetEndColor() );
549 
550  m_xMtrAngle->set_value(pGradient->GetAngle().get() / 10, FieldUnit::NONE); // should be changed in resource
551  m_xSliderAngle->set_value(pGradient->GetAngle().get() / 10);
552  m_xMtrBorder->set_value(pGradient->GetBorder(), FieldUnit::NONE);
553  m_xSliderBorder->set_value(pGradient->GetBorder());
554  m_xMtrCenterX->set_value(pGradient->GetXOffset(), FieldUnit::NONE);
555  m_xMtrCenterY->set_value(pGradient->GetYOffset(), FieldUnit::NONE);
556  m_xMtrColorFrom->set_value(pGradient->GetStartIntens(), FieldUnit::NONE);
557  m_xMtrColorTo->set_value(pGradient->GetEndIntens(), FieldUnit::NONE);
558 
559  // disable/enable controls
560  SetControlState_Impl( eXGS );
561 
562  // fill ItemSet and pass it on to aCtlPreview
563  m_rXFSet.Put( XFillGradientItem( OUString(), *pGradient ) );
564  m_rXFSet.Put( XGradientStepCountItem( nValue ) );
566 
567  m_aCtlPreview.Invalidate();
568 }
569 
570 void SvxGradientTabPage::SetControlState_Impl( css::awt::GradientStyle eXGS )
571 {
572  switch( eXGS )
573  {
574  case css::awt::GradientStyle_LINEAR:
575  case css::awt::GradientStyle_AXIAL:
576  m_xFtCenter->set_sensitive(false);
577  m_xMtrCenterX->set_sensitive(false);
578  m_xMtrCenterY->set_sensitive(false);
579  m_xFtAngle->set_sensitive(true);
580  m_xMtrAngle->set_sensitive(true);
581  m_xSliderAngle->set_sensitive(true);
582  break;
583 
584  case css::awt::GradientStyle_RADIAL:
585  m_xFtCenter->set_sensitive(true);
586  m_xMtrCenterX->set_sensitive(true);
587  m_xMtrCenterY->set_sensitive(true);
588  m_xFtAngle->set_sensitive(false);
589  m_xMtrAngle->set_sensitive(false);
590  m_xSliderAngle->set_sensitive(false);
591  break;
592 
593  case css::awt::GradientStyle_ELLIPTICAL:
594  m_xFtCenter->set_sensitive(true);
595  m_xMtrCenterX->set_sensitive(true);
596  m_xMtrCenterY->set_sensitive(true);
597  m_xFtAngle->set_sensitive(true);
598  m_xMtrAngle->set_sensitive(true);
599  m_xSliderAngle->set_sensitive(true);
600  break;
601 
602  case css::awt::GradientStyle_SQUARE:
603  case css::awt::GradientStyle_RECT:
604  m_xFtCenter->set_sensitive(true);
605  m_xMtrCenterX->set_sensitive(true);
606  m_xMtrCenterY->set_sensitive(true);
607  m_xFtAngle->set_sensitive(true);
608  m_xMtrAngle->set_sensitive(true);
609  m_xSliderAngle->set_sensitive(true);
610  break;
611  default:
612  break;
613  }
614 }
615 
616 sal_Int32 SvxGradientTabPage::SearchGradientList(std::u16string_view rGradientName)
617 {
619  bool bValidGradientName = true;
620  sal_Int32 nPos = -1;
621 
622  for(tools::Long i = 0;i < nCount && bValidGradientName;i++)
623  {
624  if(rGradientName == m_pGradientList->GetGradient( i )->GetName())
625  {
626  nPos = i;
627  bValidGradientName = false;
628  }
629  }
630  return nPos;
631 }
632 
633 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK_NOARG(SvxGradientTabPage, ChangeAutoStepHdl_Impl, weld::Toggleable &, void)
Definition: tpgradnt.cxx:269
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:176
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
constexpr tools::Long Width() const
virtual VclPtr< AbstractSvxNameDialog > CreateSvxNameDialog(weld::Window *pParent, const OUString &rName, const OUString &rDesc)=0
virtual void Reset(const SfxItemSet *) override
Definition: tpgradnt.cxx:220
RET_YES
void ModifiedHdl_Impl(void const *)
Definition: tpgradnt.cxx:282
std::unique_ptr< weld::Scale > m_xSliderBorder
Definition: cuitabarea.hxx:367
OUString SvxResId(const char *pId)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
int nCount
std::unique_ptr< weld::CheckButton > m_xCbIncrement
Definition: cuitabarea.hxx:374
void SetControlState_Impl(css::awt::GradientStyle eXGS)
Definition: tpgradnt.cxx:570
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:616
TRISTATE_FALSE
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:238
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpgradnt.cxx:133
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:184
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define SAL_WARN_IF(condition, area, stream)
constexpr tools::Long Height() const
OUString aName
RET_OK
#define DEFAULT_GRADIENTSTEP
Definition: tpgradnt.cxx:39
SfxOkDialogController * GetDialogController() const
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
virtual ~SvxGradientTabPage() override
Definition: tpgradnt.cxx:119
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:232
void ChangeGradientHdl_Impl()
Definition: tpgradnt.cxx:497