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