LibreOffice Module cui (master)  1
tpcolor.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 <i18nutil/unicode.hxx>
22 #include <svtools/colrdlg.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/weld.hxx>
25 
26 #include <strings.hrc>
27 #include <svx/xfillit0.hxx>
28 #include <svx/xflclit.hxx>
29 #include <svx/xtable.hxx>
30 #include <cuitabarea.hxx>
31 #include <svx/svxdlg.hxx>
32 #include <dialmgr.hxx>
33 #include <cuitabline.hxx>
34 #include <svx/dialmgr.hxx>
35 #include <svx/strings.hrc>
36 #include <officecfg/Office/Common.hxx>
37 
38 using namespace com::sun::star;
39 
41  : SfxTabPage(pPage, pController, "cui/ui/colorpage.ui", "ColorPage", &rInAttrs)
42  , rOutAttrs ( rInAttrs )
43  // All the horrific pointers we store and should not
44  , pnColorListState( nullptr )
45  , aXFillAttr( rInAttrs.GetPool() )
46  , rXFSet( aXFillAttr.GetItemSet() )
47  , eCM( ColorModel::RGB )
49  , m_xValSetColorList(new SvxColorValueSet(m_xBuilder->weld_scrolled_window("colorsetwin")))
50  , m_xValSetRecentList(new SvxColorValueSet(nullptr))
51  , m_xSelectPalette(m_xBuilder->weld_combo_box("paletteselector"))
52  , m_xRbRGB(m_xBuilder->weld_radio_button("RGB"))
53  , m_xRbCMYK(m_xBuilder->weld_radio_button("CMYK"))
54  , m_xRGBcustom(m_xBuilder->weld_widget("rgbcustom"))
55  , m_xRGBpreset(m_xBuilder->weld_widget("rgbpreset"))
56  , m_xRpreset(m_xBuilder->weld_entry("R_preset"))
57  , m_xGpreset(m_xBuilder->weld_entry("G_preset"))
58  , m_xBpreset(m_xBuilder->weld_entry("B_preset"))
59  , m_xRcustom(m_xBuilder->weld_spin_button("R_custom"))
60  , m_xGcustom(m_xBuilder->weld_spin_button("G_custom"))
61  , m_xBcustom(m_xBuilder->weld_spin_button("B_custom"))
62  , m_xHexpreset(new weld::HexColorControl(m_xBuilder->weld_entry("hex_preset")))
63  , m_xHexcustom(new weld::HexColorControl(m_xBuilder->weld_entry("hex_custom")))
64  , m_xCMYKcustom(m_xBuilder->weld_widget("cmykcustom"))
65  , m_xCMYKpreset(m_xBuilder->weld_widget("cmykpreset"))
66  , m_xCpreset(m_xBuilder->weld_entry("C_preset"))
67  , m_xYpreset(m_xBuilder->weld_entry("Y_preset"))
68  , m_xMpreset(m_xBuilder->weld_entry("M_preset"))
69  , m_xKpreset(m_xBuilder->weld_entry("K_preset"))
70  , m_xCcustom(m_xBuilder->weld_metric_spin_button("C_custom", FieldUnit::PERCENT))
71  , m_xYcustom(m_xBuilder->weld_metric_spin_button("Y_custom", FieldUnit::PERCENT))
72  , m_xMcustom(m_xBuilder->weld_metric_spin_button("M_custom", FieldUnit::PERCENT))
73  , m_xKcustom(m_xBuilder->weld_metric_spin_button("K_custom", FieldUnit::PERCENT))
74  , m_xBtnAdd(m_xBuilder->weld_button("add"))
75  , m_xBtnDelete(m_xBuilder->weld_button("delete"))
76  , m_xBtnWorkOn(m_xBuilder->weld_button("edit"))
77  , m_xCtlPreviewOld(new weld::CustomWeld(*m_xBuilder, "oldpreview", m_aCtlPreviewOld))
78  , m_xCtlPreviewNew(new weld::CustomWeld(*m_xBuilder, "newpreview", m_aCtlPreviewNew))
79  , m_xValSetColorListWin(new weld::CustomWeld(*m_xBuilder, "colorset", *m_xValSetColorList))
80  , m_xValSetRecentListWin(new weld::CustomWeld(*m_xBuilder, "recentcolorset", *m_xValSetRecentList))
81 {
82  Size aSize(m_xBtnWorkOn->get_approximate_digit_width() * 25,
83  m_xBtnWorkOn->get_text_height() * 10);
84  m_xValSetColorList->set_size_request(aSize.Width(), aSize.Height());
85  aSize = Size(m_xBtnWorkOn->get_approximate_digit_width() * 8,
86  m_xBtnWorkOn->get_text_height() * 3);
87  m_aCtlPreviewOld.set_size_request(aSize.Width(), aSize.Height());
88  m_aCtlPreviewNew.set_size_request(aSize.Width(), aSize.Height());
89  // this page needs ExchangeSupport
91 
92  // setting the output device
93  rXFSet.Put( XFillStyleItem(drawing::FillStyle_SOLID) );
94  rXFSet.Put( XFillColorItem(OUString(), COL_BLACK) );
97 
98  // set handler
99  m_xSelectPalette->connect_changed(LINK(this, SvxColorTabPage, SelectPaletteLBHdl));
100  Link<ValueSet*, void> aValSelectLink = LINK(this, SvxColorTabPage, SelectValSetHdl_Impl);
101  m_xValSetColorList->SetSelectHdl(aValSelectLink);
102  m_xValSetRecentList->SetSelectHdl(aValSelectLink);
103 
104  Link<weld::SpinButton&,void> aSpinLink = LINK(this, SvxColorTabPage, SpinValueHdl_Impl);
105  m_xRcustom->connect_value_changed(aSpinLink);
106  m_xGcustom->connect_value_changed(aSpinLink);
107  m_xBcustom->connect_value_changed(aSpinLink);
108  Link<weld::Entry&,void> aEntryLink = LINK(this, SvxColorTabPage, ModifiedHdl_Impl);
109  m_xHexcustom->connect_changed(aEntryLink);
110  Link<weld::MetricSpinButton&,void> aMetricSpinLink = LINK(this, SvxColorTabPage, MetricSpinValueHdl_Impl);
111  m_xCcustom->connect_value_changed(aMetricSpinLink);
112  m_xYcustom->connect_value_changed(aMetricSpinLink);
113  m_xMcustom->connect_value_changed(aMetricSpinLink);
114  m_xKcustom->connect_value_changed(aMetricSpinLink);
115 
116  Link<weld::ToggleButton&,void> aLink2 = LINK( this, SvxColorTabPage, SelectColorModeHdl_Impl );
117  m_xRbRGB->connect_toggled(aLink2);
118  m_xRbCMYK->connect_toggled(aLink2);
119  SetColorModel( eCM );
121 
122  m_xBtnAdd->connect_clicked( LINK( this, SvxColorTabPage, ClickAddHdl_Impl ) );
123  m_xBtnWorkOn->connect_clicked( LINK( this, SvxColorTabPage, ClickWorkOnHdl_Impl ) );
124  m_xBtnDelete->connect_clicked( LINK( this, SvxColorTabPage, ClickDeleteHdl_Impl ) );
125  // disable modify buttons
126  // Color palettes can't be modified
127  m_xBtnDelete->set_sensitive(false);
128  m_xBtnDelete->set_tooltip_text( SvxResId(RID_SVXSTR_DELETEUSERCOLOR1) );
129 
130  // disable preset color values
131  m_xRGBpreset->set_sensitive(false);
132  m_xCMYKpreset->set_sensitive(false);
133 
134  // ValueSet
135  m_xValSetColorList->SetStyle(m_xValSetColorList->GetStyle() | WB_ITEMBORDER);
136  m_xValSetColorList->Show();
137 
138  m_xValSetRecentList->SetStyle(m_xValSetRecentList->GetStyle() | WB_ITEMBORDER);
139  m_xValSetRecentList->Show();
140 
142  aSize = m_xValSetRecentList->layoutAllVisible(maPaletteManager.GetRecentColorCount());
143  m_xValSetRecentList->set_size_request(aSize.Width(), aSize.Height());
144 }
145 
147 {
148  m_xValSetRecentListWin.reset();
149  m_xValSetRecentList.reset();
150  m_xValSetColorListWin.reset();
151  m_xValSetColorList.reset();
152 }
153 
155 {
156  if (!pColorList.is())
157  return;
160 }
161 
163 {
164  m_xSelectPalette->clear();
165  std::vector<OUString> aPaletteList = maPaletteManager.GetPaletteList();
166  for (auto const& palette : aPaletteList)
167  {
168  m_xSelectPalette->append_text(palette);
169  }
170  OUString aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() );
171  m_xSelectPalette->set_active_text(aPaletteName);
172  if (m_xSelectPalette->get_active() != -1)
173  {
174  SelectPaletteLBHdl(*m_xSelectPalette);
175  }
176 }
177 
179 {
180  if (pColorList.is())
181  {
182  FillPaletteLB();
184  }
185 }
186 
188 {
189  if( !pColorList.is() )
190  return;
191 
192  const SfxPoolItem* pPoolItem = nullptr;
193  if( SfxItemState::SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), true, &pPoolItem ) )
194  {
197 
198  const Color aColor = static_cast<const XFillColorItem*>(pPoolItem)->GetColorValue();
199  ChangeColor( aColor );
200  sal_Int32 nPos = FindInPalette( aColor );
201 
202  if ( nPos != -1 )
203  m_xValSetColorList->SelectItem(m_xValSetColorList->GetItemId(nPos));
204  // else search in other palettes?
205 
206  }
207 
209  m_aCtlPreviewOld.Invalidate();
210 
211  SelectValSetHdl_Impl(m_xValSetColorList.get());
212 }
213 
215 {
216  if( _pSet )
217  FillItemSet( _pSet );
218 
219  return DeactivateRC::LeavePage;
220 }
221 
223 {
224  Color aColor = m_xValSetColorList->GetItemColor( m_xValSetColorList->GetSelectedItemId() );
225  OUString sColorName;
226  if ( aCurrentColor == aColor )
227  sColorName = m_xValSetColorList->GetItemText( m_xValSetColorList->GetSelectedItemId() );
228  else
229  sColorName = "#" + aCurrentColor.AsRGBHexString().toAsciiUpperCase();
231  rSet->Put( XFillColorItem( sColorName, aCurrentColor ) );
232  rSet->Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
233  return true;
234 }
235 
237 {
238  bool bEnable = pColorList.is() && pColorList->Count();
239  m_xBtnWorkOn->set_sensitive(bEnable);
240 }
241 
243 {
245 
246  Color aNewColor;
247 
248  if ( nState >= SfxItemState::DEFAULT )
249  {
250  XFillColorItem aColorItem( rSet->Get( XATTR_FILLCOLOR ) );
251  aPreviousColor = aColorItem.GetColorValue();
252  aNewColor = aColorItem.GetColorValue();
253  }
254 
255  // set color model
256  OUString aStr = GetUserData();
257  eCM = static_cast<ColorModel>(aStr.toInt32());
258  SetColorModel( eCM );
260 
261  ChangeColor(aNewColor);
262 
263  UpdateModified();
264 }
265 
266 std::unique_ptr<SfxTabPage> SvxColorTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rOutAttrs)
267 {
268  return std::make_unique<SvxColorTabPage>(pPage, pController, *rOutAttrs);
269 }
270 
271 // is called when the content of the MtrFields is changed for color values
273 {
274  // read current MtrFields, if cmyk, then k-value as transparency
275  aCurrentColor = Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())),
276  static_cast<sal_uInt8>(PercentToColor_Impl(m_xGcustom->get_value())),
277  static_cast<sal_uInt8>(PercentToColor_Impl(m_xBcustom->get_value())));
278  UpdateColorValues();
279 
280  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
281  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
282 
283  m_aCtlPreviewNew.Invalidate();
284 }
285 
286 IMPL_LINK_NOARG(SvxColorTabPage, MetricSpinValueHdl_Impl, weld::MetricSpinButton&, void)
287 {
288  // read current MtrFields, if cmyk, then k-value as transparency
289  aCurrentColor = Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))),
290  static_cast<sal_uInt8>(PercentToColor_Impl(m_xCcustom->get_value(FieldUnit::NONE))),
291  static_cast<sal_uInt8>(PercentToColor_Impl(m_xYcustom->get_value(FieldUnit::NONE))),
292  static_cast<sal_uInt8>(PercentToColor_Impl(m_xMcustom->get_value(FieldUnit::NONE))));
293  ConvertColorValues (aCurrentColor, ColorModel::RGB);
294 
295  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
296  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
297 
298  m_aCtlPreviewNew.Invalidate();
299 }
300 
301 IMPL_LINK_NOARG(SvxColorTabPage, ModifiedHdl_Impl, weld::Entry&, void)
302 {
303  aCurrentColor = m_xHexcustom->GetColor();
304  UpdateColorValues();
305 
306  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
307  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
308 
309  m_aCtlPreviewNew.Invalidate();
310 }
311 
312 IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl, weld::Button&, void)
313 {
314  OUString aNewName( SvxResId( RID_SVXSTR_COLOR ) );
315  OUString aDesc( CuiResId( RID_SVXSTR_DESC_COLOR ) );
316  OUString aName;
317 
318  long j = 1;
319  bool bValidColorName = false;
320  // check if name is already existing
321  while (!bValidColorName)
322  {
323  aName = aNewName + " " + OUString::number( j++ );
324  bValidColorName = (FindInCustomColors(aName) == -1);
325  }
326 
329  sal_uInt16 nError = 1;
330 
331  while (pDlg->Execute() == RET_OK)
332  {
333  pDlg->GetName( aName );
334 
335  bValidColorName = (FindInCustomColors(aName) == -1);
336  if (bValidColorName)
337  {
338  nError = 0;
339  break;
340  }
341 
342  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
343  std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
344  if (xWarnBox->run() != RET_OK)
345  break;
346  }
347 
348  pDlg.disposeAndClear();
349 
350  if (!nError)
351  {
352  m_xSelectPalette->set_active(0);
353  SelectPaletteLBHdl(*m_xSelectPalette);
354  std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context));
355  css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
356  css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
357  sal_Int32 nSize = aCustomColorList.getLength();
358  aCustomColorList.realloc( nSize + 1 );
359  aCustomColorNameList.realloc( nSize + 1 );
360  aCustomColorList[nSize] = sal_Int32(aCurrentColor);
361  aCustomColorNameList[nSize] = aName;
362  officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
363  officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
364  batch->commit();
365  sal_uInt16 nId = m_xValSetColorList->GetItemId(nSize - 1);
366  m_xValSetColorList->InsertItem( nId + 1 , aCurrentColor, aName );
367  m_xValSetColorList->SelectItem( nId + 1 );
368  m_xBtnDelete->set_sensitive(false);
369  m_xBtnDelete->set_tooltip_text( SvxResId(RID_SVXSTR_DELETEUSERCOLOR2) );
370  ImpColorCountChanged();
371  }
372 
373  UpdateModified();
374 }
375 
376 IMPL_LINK_NOARG(SvxColorTabPage, ClickWorkOnHdl_Impl, weld::Button&, void)
377 {
378  SvColorDialog aColorDlg;
379 
380  aColorDlg.SetColor (aCurrentColor);
382 
383  if (aColorDlg.Execute(GetFrameWeld()) == RET_OK)
384  {
385  Color aPreviewColor = aColorDlg.GetColor();
386  aCurrentColor = aPreviewColor;
387  UpdateColorValues( false );
388  // fill ItemSet and pass it on to XOut
389  rXFSet.Put( XFillColorItem( OUString(), aPreviewColor ) );
390  //m_aCtlPreviewOld.SetAttributes( aXFillAttr );
391  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
392 
393  m_aCtlPreviewNew.Invalidate();
394  }
395 }
396 
397 IMPL_LINK_NOARG(SvxColorTabPage, ClickDeleteHdl_Impl, weld::Button&, void)
398 {
399  sal_uInt16 nId = m_xValSetColorList->GetSelectedItemId();
400  size_t nPos = m_xValSetColorList->GetSelectItemPos();
401  if (m_xSelectPalette->get_active() != 0 || nPos == VALUESET_ITEM_NOTFOUND)
402  return;
403 
404  std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context));
405  css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
406  css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
407  sal_Int32 nSize = aCustomColorList.getLength() - 1;
408  for(sal_Int32 nIndex = static_cast<sal_Int32>(nPos);nIndex < nSize;nIndex++)
409  {
410  aCustomColorList[nIndex] = aCustomColorList[nIndex+1];
411  aCustomColorNameList[nIndex] = aCustomColorNameList[nIndex+1];
412  }
413  aCustomColorList.realloc(nSize);
414  aCustomColorNameList.realloc(nSize);
415  officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
416  officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
417  batch->commit();
418  m_xValSetColorList->RemoveItem(nId);
419  if (m_xValSetColorList->GetItemCount() != 0)
420  {
421  nId = m_xValSetColorList->GetItemId(0);
422  m_xValSetColorList->SelectItem(nId);
423  SelectValSetHdl_Impl(m_xValSetColorList.get());
424  }
425  else
426  {
427  m_xBtnDelete->set_sensitive(false);
428  m_xBtnDelete->set_tooltip_text( SvxResId(RID_SVXSTR_DELETEUSERCOLOR2) );
429  }
430 }
431 
432 IMPL_LINK_NOARG(SvxColorTabPage, SelectPaletteLBHdl, weld::ComboBox&, void)
433 {
434  m_xValSetColorList->Clear();
435  sal_Int32 nPos = m_xSelectPalette->get_active();
436  maPaletteManager.SetPalette( nPos );
437  maPaletteManager.ReloadColorSet(*m_xValSetColorList);
438 
439  if(nPos != maPaletteManager.GetPaletteCount() - 1 && nPos != 0)
440  {
443  XPropertyListType::Color, maPaletteManager.GetSelectedPalettePath()));
444  pList->SetName(maPaletteManager.GetPaletteName());
445  if(pList->Load())
446  {
447  SfxOkDialogController* pController = GetDialogController();
448  SvxAreaTabDialog* pArea = dynamic_cast<SvxAreaTabDialog*>(pController);
449  SvxLineTabDialog* pLine = dynamic_cast<SvxLineTabDialog*>(pController);
450  pColorList = pList;
451  if( pArea )
452  pArea->SetNewColorList(pList);
453  else if( pLine )
454  pLine->SetNewColorList(pList);
455  else
456  SetColorList(pList);
457  *pnColorListState |= ChangeType::CHANGED;
458  *pnColorListState &= ~ChangeType::MODIFIED;
459  }
460  }
461  if (nPos != 0)
462  {
463  m_xBtnDelete->set_sensitive(false);
464  m_xBtnDelete->set_tooltip_text( SvxResId(RID_SVXSTR_DELETEUSERCOLOR1) );
465  }
466 
467  m_xValSetColorList->Resize();
468 }
469 
470 IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, ValueSet*, pValSet, void)
471 {
472  sal_Int32 nPos = pValSet->GetSelectedItemId();
473  if( nPos == 0 )
474  return;
475 
476  Color aColor = pValSet->GetItemColor( nPos );
477 
478  rXFSet.Put( XFillColorItem( OUString(), aColor ) );
479  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
480  m_aCtlPreviewNew.Invalidate();
481  ChangeColor(aColor, false);
482 
483  if (pValSet == m_xValSetColorList.get())
484  {
485  m_xValSetRecentList->SetNoSelection();
486  if (m_xSelectPalette->get_active() == 0 && m_xValSetColorList->GetSelectedItemId() != 0)
487  {
488  m_xBtnDelete->set_sensitive(true);
489  m_xBtnDelete->set_tooltip_text("");
490  }
491  else
492  {
493  m_xBtnDelete->set_sensitive(false);
494  m_xBtnDelete->set_tooltip_text( SvxResId(RID_SVXSTR_DELETEUSERCOLOR1) );
495  }
496  }
497  if (pValSet == m_xValSetRecentList.get())
498  {
499  m_xValSetColorList->SetNoSelection();
500  m_xBtnDelete->set_sensitive(false);
501  m_xBtnDelete->set_tooltip_text( SvxResId(RID_SVXSTR_DELETEUSERCOLOR2) );
502  }
503 }
504 
506 {
507  switch (eModell)
508  {
509  case ColorModel::RGB:
510  {
511  CmykToRgb_Impl (rColor, static_cast<sal_uInt16>(rColor.GetTransparency()) );
512  rColor.SetTransparency (sal_uInt8(0));
513  }
514  break;
515 
516  case ColorModel::CMYK:
517  {
518  sal_uInt16 nK;
519  RgbToCmyk_Impl (rColor, nK );
520  rColor.SetTransparency (static_cast<sal_uInt8>(nK));
521  }
522  break;
523  }
524 }
525 
526 IMPL_LINK_NOARG(SvxColorTabPage, SelectColorModeHdl_Impl, weld::ToggleButton&, void)
527 {
528  if (m_xRbRGB->get_active())
529  eCM = ColorModel::RGB;
530  else if (m_xRbCMYK->get_active())
531  eCM = ColorModel::CMYK;
532  ChangeColorModel();
533  UpdateColorValues();
534 }
535 
536 void SvxColorTabPage::ChangeColor(const Color &rNewColor, bool bUpdatePreset )
537 {
538  aPreviousColor = rNewColor;
539  aCurrentColor = rNewColor;
540  UpdateColorValues( bUpdatePreset );
541  // fill ItemSet and pass it on to XOut
542  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
544  m_aCtlPreviewNew.Invalidate();
545 }
546 
548 {
549  if (eModel == ColorModel::RGB)
550  m_xRbRGB->set_active(true);
551  else if (eModel == ColorModel::CMYK)
552  m_xRbCMYK->set_active(true);
553 }
554 
556 {
557  switch( eCM )
558  {
559  case ColorModel::RGB:
560  {
561  m_xRGBcustom->show();
562  m_xRGBpreset->show();
563  m_xCMYKcustom->hide();
564  m_xCMYKpreset->hide();
565  }
566  break;
567 
568  case ColorModel::CMYK:
569  {
570  m_xCMYKcustom->show();
571  m_xCMYKpreset->show();
572  m_xRGBcustom->hide();
573  m_xRGBpreset->hide();
574  }
575  break;
576  }
577 }
578 
579 void SvxColorTabPage::UpdateColorValues( bool bUpdatePreset )
580 {
581  if (eCM != ColorModel::RGB)
582  {
585 
586  m_xCcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetRed() ), FieldUnit::PERCENT );
587  m_xMcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetBlue() ), FieldUnit::PERCENT );
588  m_xYcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetGreen() ), FieldUnit::PERCENT );
589  m_xKcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetTransparency() ), FieldUnit::PERCENT );
590 
591  if( bUpdatePreset )
592  {
601  }
602 
605  }
606  else
607  {
611  m_xHexcustom->SetColor( aCurrentColor );
612 
613  if( bUpdatePreset )
614  {
615  m_xRpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetRed())));
616  m_xGpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetGreen())));
617  m_xBpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetBlue())));
618  m_xHexpreset->SetColor( aPreviousColor );
619  }
620  }
621 }
622 
623 sal_Int32 SvxColorTabPage::FindInCustomColors(OUString const & aColorName)
624 {
625  css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
626  long nCount = aCustomColorNameList.getLength();
627  bool bValidColorName = true;
628  sal_Int32 nPos = -1;
629 
630  for(long i = 0;i < nCount && bValidColorName;i++)
631  {
632  if(aColorName == aCustomColorNameList[i])
633  {
634  nPos = i;
635  bValidColorName = false;
636  }
637  }
638  return nPos;
639 }
640 
641 sal_Int32 SvxColorTabPage::FindInPalette( const Color& rColor )
642 {
643  return pColorList->GetIndexOfColor(rColor);
644 }
645 
646 // A RGB value is converted to a CMYK value - not in an ideal way as
647 // R is converted into C, G into M and B into Y. The K value is held in an
648 // extra variable. For further color models one should develop own
649 // classes which should contain the respective casts.
650 
651 void SvxColorTabPage::RgbToCmyk_Impl( Color& rColor, sal_uInt16& rK )
652 {
653  sal_uInt16 const nColor1 = 255 - rColor.GetRed();
654  sal_uInt16 const nColor2 = 255 - rColor.GetGreen();
655  sal_uInt16 const nColor3 = 255 - rColor.GetBlue();
656 
657  rK = std::min( std::min( nColor1, nColor2 ), nColor3 );
658 
659  rColor.SetRed( sal::static_int_cast< sal_uInt8 >( nColor1 - rK ) );
660  rColor.SetGreen( sal::static_int_cast< sal_uInt8 >( nColor2 - rK ) );
661  rColor.SetBlue( sal::static_int_cast< sal_uInt8 >( nColor3 - rK ) );
662 }
663 
664 
665 // reverse case to RgbToCmyk_Impl (see above)
666 
667 void SvxColorTabPage::CmykToRgb_Impl( Color& rColor, const sal_uInt16 nK )
668 {
669  long lTemp;
670 
671  lTemp = 255 - ( rColor.GetRed() + nK );
672 
673  if( lTemp < 0 )
674  lTemp = 0;
675  rColor.SetRed( static_cast<sal_uInt8>(lTemp) );
676 
677  lTemp = 255 - ( rColor.GetGreen() + nK );
678 
679  if( lTemp < 0 )
680  lTemp = 0;
681  rColor.SetGreen( static_cast<sal_uInt8>(lTemp) );
682 
683  lTemp = 255 - ( rColor.GetBlue() + nK );
684 
685  if( lTemp < 0 )
686  lTemp = 0;
687  rColor.SetBlue( static_cast<sal_uInt8>(lTemp) );
688 }
689 
690 
691 sal_uInt16 SvxColorTabPage::ColorToPercent_Impl( sal_uInt16 nColor )
692 {
693  sal_uInt16 nValue = 0;
694 
695  switch (eCM)
696  {
697  case ColorModel::RGB :
698  nValue = nColor;
699  break;
700 
701  case ColorModel::CMYK:
702  nValue = static_cast<sal_uInt16>( static_cast<double>(nColor) * 100.0 / 255.0 + 0.5 );
703  break;
704  }
705 
706  return nValue;
707 }
708 
709 
710 sal_uInt16 SvxColorTabPage::PercentToColor_Impl( sal_uInt16 nPercent )
711 {
712  sal_uInt16 nValue = 0;
713 
714  switch (eCM)
715  {
716  case ColorModel::RGB :
717  nValue = nPercent;
718  break;
719 
720  case ColorModel::CMYK:
721  nValue = static_cast<sal_uInt16>( static_cast<double>(nPercent) * 255.0 / 100.0 + 0.5 );
722  break;
723  }
724 
725  return nValue;
726 }
727 
728 
730 {
731  // the color model is saved in the Ini-file
732  SetUserData( OUString::number( static_cast<int>(eCM) ) );
733 }
734 
735 
737 {
738  OSL_ASSERT( t == XPropertyListType::Color );
739  pColorList = XColorListRef( static_cast<XColorList *>(xRef.get() ) );
740 }
741 
743 {
744  SetPropertyList( XPropertyListType::Color, XPropertyListRef( ( pColList.get() ) ) );
745 }
746 
747 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString AsRGBHexString() const
std::unique_ptr< weld::CustomWeld > m_xValSetColorListWin
Definition: cuitabarea.hxx:680
std::unique_ptr< weld::MetricSpinButton > m_xYcustom
Definition: cuitabarea.hxx:672
virtual ~SvxColorTabPage() override
Definition: tpcolor.cxx:146
std::unique_ptr< weld::Button > m_xBtnWorkOn
Definition: cuitabarea.hxx:677
FieldUnit
sal_Int32 nIndex
std::unique_ptr< weld::SpinButton > m_xRcustom
Definition: cuitabarea.hxx:660
sal_uInt8 GetRed() const
void SetColorModel(ColorModel eModel)
Definition: tpcolor.cxx:547
std::unique_ptr< weld::MetricSpinButton > m_xKcustom
Definition: cuitabarea.hxx:674
void SetBlue(sal_uInt8 nBlue)
void SetTransparency(sal_uInt8 nTransparency)
void SetUserData(const OUString &rString)
std::unique_ptr< weld::Entry > m_xRpreset
Definition: cuitabarea.hxx:657
const LanguageTag & GetUILanguageTag() const
#define VALUESET_ITEM_NOTFOUND
XColorListRef pColorList
Definition: cuitabarea.hxx:633
static SvxAbstractDialogFactory * Create()
sal_uInt8 GetTransparency() const
static const AllSettings & GetSettings()
std::unique_ptr< weld::MetricSpinButton > m_xMcustom
Definition: cuitabarea.hxx:673
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false)
sal_Int16 nId
std::unique_ptr< weld::Widget > m_xRGBpreset
Definition: cuitabarea.hxx:656
std::unique_ptr< weld::CustomWeld > m_xValSetRecentListWin
Definition: cuitabarea.hxx:681
SfxItemSet & rXFSet
Definition: cuitabarea.hxx:638
virtual void FillUserData() override
Definition: tpcolor.cxx:729
SvxColorTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tpcolor.cxx:40
std::unique_ptr< weld::Entry > m_xGpreset
Definition: cuitabarea.hxx:658
std::unique_ptr< weld::Button > m_xBtnDelete
Definition: cuitabarea.hxx:676
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpcolor.cxx:214
void SetMode(svtools::ColorPickerMode eMode)
virtual VclPtr< AbstractSvxNameDialog > CreateSvxNameDialog(weld::Window *pParent, const OUString &rName, const OUString &rDesc)=0
static sal_uInt32 getColumnCount()
static sal_Int32 FindInCustomColors(OUString const &aColorName)
Definition: tpcolor.cxx:623
PaletteManager maPaletteManager
Definition: cuitabarea.hxx:647
virtual bool FillItemSet(SfxItemSet *) override
Definition: tpcolor.cxx:222
OUString SvxResId(const char *pId)
short Execute(weld::Window *pParent)
#define WB_ITEMBORDER
void SetNewColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:120
void SetExchangeSupport()
int nCount
std::unique_ptr< SvxColorValueSet > m_xValSetRecentList
Definition: cuitabarea.hxx:651
const OUString & GetUserData() const
sal_uInt16 PercentToColor_Impl(sal_uInt16 nPercent)
Definition: tpcolor.cxx:710
static void CmykToRgb_Impl(Color &rColor, const sal_uInt16 nKey)
Definition: tpcolor.cxx:667
static std::shared_ptr< ConfigurationChanges > create(css::uno::Reference< css::uno::XComponentContext > const &context=comphelper::getProcessComponentContext())
std::unique_ptr< weld::Entry > m_xBpreset
Definition: cuitabarea.hxx:659
sal_uInt8 GetBlue() const
ColorModel eCM
Definition: cuitabarea.hxx:640
XFillAttrSetItem aXFillAttr
Definition: cuitabarea.hxx:637
std::unique_ptr< weld::Widget > m_xCMYKpreset
Definition: cuitabarea.hxx:666
long GetRecentColorCount() const
void SetNewColorList(XColorListRef const &pColTab)
Definition: cuitabline.hxx:75
void ChangeColor(const Color &rNewColor, bool bUpdatePreset=true)
Definition: tpcolor.cxx:536
sal_uInt16 ColorToPercent_Impl(sal_uInt16 nColor)
Definition: tpcolor.cxx:691
static XColorListRef AsColorList(rtl::Reference< XPropertyList > const &plist)
ChangeType
void SetColor(const Color &rColor)
XPropertyListType
void SetColorList(const XColorListRef &pColList)
Definition: tpcolor.cxx:742
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
int i
std::vector< OUString > GetPaletteList()
std::unique_ptr< weld::ComboBox > m_xSelectPalette
Definition: cuitabarea.hxx:652
void UpdateModified()
Definition: tpcolor.cxx:236
void UpdateColorValues(bool bUpdatePreset=true)
Definition: tpcolor.cxx:579
virtual void Reset(const SfxItemSet *) override
Definition: tpcolor.cxx:242
const SfxItemSet & rOutAttrs
Definition: cuitabarea.hxx:631
void FillPaletteLB()
Definition: tpcolor.cxx:162
void Construct()
Definition: tpcolor.cxx:178
void SetRed(sal_uInt8 nRed)
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
void ChangeColorModel()
Definition: tpcolor.cxx:555
std::unique_ptr< weld::HexColorControl > m_xHexpreset
Definition: cuitabarea.hxx:663
std::unique_ptr< weld::Widget > m_xRGBcustom
Definition: cuitabarea.hxx:655
std::unique_ptr< weld::Entry > m_xKpreset
Definition: cuitabarea.hxx:670
void ReloadRecentColorSet(SvxColorValueSet &rColorSet)
const OUStringLiteral PERCENT(u"Percent")
std::unique_ptr< weld::HexColorControl > m_xHexcustom
Definition: cuitabarea.hxx:664
void SetAttributes(const SfxItemSet &rItemSet)
std::unique_ptr< weld::SpinButton > m_xGcustom
Definition: cuitabarea.hxx:661
std::unique_ptr< weld::RadioButton > m_xRbCMYK
Definition: cuitabarea.hxx:654
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpcolor.cxx:266
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
std::unique_ptr< weld::Entry > m_xCpreset
Definition: cuitabarea.hxx:667
const Color & GetColor() const
std::unique_ptr< weld::Button > m_xBtnAdd
Definition: cuitabarea.hxx:675
sal_uInt8 GetGreen() const
SvxXRectPreview m_aCtlPreviewOld
Definition: cuitabarea.hxx:648
constexpr TypedWhichId< XFillColorItem > XATTR_FILLCOLOR(XATTR_FILL_FIRST+1)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpcolor.cxx:187
static void ConvertColorValues(Color &rColor, ColorModel eModell)
Definition: tpcolor.cxx:505
static OUString formatPercent(double dNumber, const LanguageTag &rLangTag)
SfxItemState
std::unique_ptr< SvxColorValueSet > m_xValSetColorList
Definition: cuitabarea.hxx:650
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
unsigned char sal_uInt8
std::unique_ptr< weld::RadioButton > m_xRbRGB
Definition: cuitabarea.hxx:653
void SetGreen(sal_uInt8 nGreen)
OUString aName
RET_OK
static void RgbToCmyk_Impl(Color &rColor, sal_uInt16 &rK)
Definition: tpcolor.cxx:651
void SetPropertyList(XPropertyListType t, const XPropertyListRef &xRef)
Definition: tpcolor.cxx:736
Reference< XComponentContext > getProcessComponentContext()
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
ColorModel
IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, ValueSet *, pValSet, void)
Definition: tpcolor.cxx:470
sal_Int32 FindInPalette(const Color &rColor)
Definition: tpcolor.cxx:641
void ImpColorCountChanged()
Definition: tpcolor.cxx:154
DeactivateRC
std::unique_ptr< weld::Widget > m_xCMYKcustom
Definition: cuitabarea.hxx:665
IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, weld::SpinButton &, void)
Definition: tpcolor.cxx:272
void AddRecentColor(const Color &rRecentColor, const OUString &rColorName, bool bFront=true)
std::unique_ptr< weld::Entry > m_xYpreset
Definition: cuitabarea.hxx:668
std::unique_ptr< weld::MetricSpinButton > m_xCcustom
Definition: cuitabarea.hxx:671
sal_Int32 nState
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
aStr
std::unique_ptr< weld::Entry > m_xMpreset
Definition: cuitabarea.hxx:669
sal_uInt16 nPos
SvxXRectPreview m_aCtlPreviewNew
Definition: cuitabarea.hxx:649
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
sal_Int16 nValue
static XPropertyListRef CreatePropertyListFromURL(XPropertyListType t, const OUString &rUrl)
std::unique_ptr< weld::SpinButton > m_xBcustom
Definition: cuitabarea.hxx:662