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>
39 
40 using namespace com::sun::star;
41 
43  : SfxTabPage(pPage, pController, "cui/ui/colorpage.ui", "ColorPage", &rInAttrs)
44  , rOutAttrs ( rInAttrs )
45  // All the horrific pointers we store and should not
46  , pnColorListState( nullptr )
47  , aXFillAttr( rInAttrs.GetPool() )
48  , rXFSet( aXFillAttr.GetItemSet() )
49  , 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( SvxResId(RID_SVXSTR_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  const SfxPoolItem* pPoolItem = nullptr;
201  if( SfxItemState::SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), true, &pPoolItem ) )
202  {
205 
206  const Color aColor = static_cast<const XFillColorItem*>(pPoolItem)->GetColorValue();
207  ChangeColor( aColor );
208  sal_Int32 nPos = FindInPalette( aColor );
209 
210  if ( nPos != -1 )
211  m_xValSetColorList->SelectItem(m_xValSetColorList->GetItemId(nPos));
212  // else search in other palettes?
213 
214  }
215 
217  m_aCtlPreviewOld.Invalidate();
218 
219  SelectValSetHdl_Impl(m_xValSetColorList.get());
220 }
221 
223 {
224  if( _pSet )
225  FillItemSet( _pSet );
226 
227  return DeactivateRC::LeavePage;
228 }
229 
231 {
232  Color aColor = m_xValSetColorList->GetItemColor( m_xValSetColorList->GetSelectedItemId() );
233  OUString sColorName;
234  if ( aCurrentColor == aColor )
235  sColorName = m_xValSetColorList->GetItemText( m_xValSetColorList->GetSelectedItemId() );
236  else
237  sColorName = "#" + aCurrentColor.AsRGBHexString().toAsciiUpperCase();
239  rSet->Put( XFillColorItem( sColorName, aCurrentColor ) );
240  rSet->Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
241  return true;
242 }
243 
245 {
246  bool bEnable = pColorList.is() && pColorList->Count();
247  m_xBtnWorkOn->set_sensitive(bEnable);
248 }
249 
251 {
253 
254  Color aNewColor;
255 
256  if ( nState >= SfxItemState::DEFAULT )
257  {
258  XFillColorItem aColorItem( rSet->Get( XATTR_FILLCOLOR ) );
259  aPreviousColor = aColorItem.GetColorValue();
260  aNewColor = aColorItem.GetColorValue();
261  }
262 
263  // set color model
264  OUString aStr = GetUserData();
265  eCM = static_cast<ColorModel>(aStr.toInt32());
266  SetColorModel( eCM );
268 
269  ChangeColor(aNewColor);
270 
271  UpdateModified();
272 }
273 
274 std::unique_ptr<SfxTabPage> SvxColorTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rOutAttrs)
275 {
276  return std::make_unique<SvxColorTabPage>(pPage, pController, *rOutAttrs);
277 }
278 
279 // is called when the content of the MtrFields is changed for color values
281 {
282  // read current MtrFields, if cmyk, then k-value as transparency
283  aCurrentColor = Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())),
284  static_cast<sal_uInt8>(PercentToColor_Impl(m_xGcustom->get_value())),
285  static_cast<sal_uInt8>(PercentToColor_Impl(m_xBcustom->get_value())));
286  UpdateColorValues();
287 
288  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
289  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
290 
291  m_aCtlPreviewNew.Invalidate();
292 }
293 
294 IMPL_LINK_NOARG(SvxColorTabPage, MetricSpinValueHdl_Impl, weld::MetricSpinButton&, void)
295 {
296  // read current MtrFields, if cmyk, then k-value as transparency
297  aCurrentColor = Color(ColorTransparency, static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))),
298  static_cast<sal_uInt8>(PercentToColor_Impl(m_xCcustom->get_value(FieldUnit::NONE))),
299  static_cast<sal_uInt8>(PercentToColor_Impl(m_xYcustom->get_value(FieldUnit::NONE))),
300  static_cast<sal_uInt8>(PercentToColor_Impl(m_xMcustom->get_value(FieldUnit::NONE))));
301  ConvertColorValues (aCurrentColor, ColorModel::RGB);
302 
303  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
304  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
305 
306  m_aCtlPreviewNew.Invalidate();
307 }
308 
309 IMPL_LINK_NOARG(SvxColorTabPage, ModifiedHdl_Impl, weld::Entry&, void)
310 {
311  aCurrentColor = m_xHexcustom->GetColor();
312  UpdateColorValues();
313 
314  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
315  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
316 
317  m_aCtlPreviewNew.Invalidate();
318 }
319 
320 IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl, weld::Button&, void)
321 {
322  OUString aNewName( SvxResId( RID_SVXSTR_COLOR ) );
323  OUString aDesc( CuiResId( RID_SVXSTR_DESC_COLOR ) );
324  OUString aName;
325 
326  tools::Long j = 1;
327  bool bValidColorName = false;
328  // check if name is already existing
329  while (!bValidColorName)
330  {
331  aName = aNewName + " " + OUString::number( j++ );
332  bValidColorName = (FindInCustomColors(aName) == -1);
333  }
334 
337  sal_uInt16 nError = 1;
338 
339  while (pDlg->Execute() == RET_OK)
340  {
341  pDlg->GetName( aName );
342 
343  bValidColorName = (FindInCustomColors(aName) == -1);
344  if (bValidColorName)
345  {
346  nError = 0;
347  break;
348  }
349 
350  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
351  std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
352  if (xWarnBox->run() != RET_OK)
353  break;
354  }
355 
356  pDlg.disposeAndClear();
357 
358  if (!nError)
359  {
360  m_xSelectPalette->set_active(0);
361  SelectPaletteLBHdl(*m_xSelectPalette);
362  std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context));
363  css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
364  css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
365  sal_Int32 nSize = aCustomColorList.getLength();
366  aCustomColorList.realloc( nSize + 1 );
367  aCustomColorNameList.realloc( nSize + 1 );
368  aCustomColorList[nSize] = sal_Int32(aCurrentColor);
369  aCustomColorNameList[nSize] = aName;
370  officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
371  officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
372  batch->commit();
373  sal_uInt16 nId = m_xValSetColorList->GetItemId(nSize - 1);
374  m_xValSetColorList->InsertItem( nId + 1 , aCurrentColor, aName );
375  m_xValSetColorList->SelectItem( nId + 1 );
376  m_xBtnDelete->set_sensitive(false);
377  m_xBtnDelete->set_tooltip_text( SvxResId(RID_SVXSTR_DELETEUSERCOLOR2) );
378  ImpColorCountChanged();
379  }
380 
381  UpdateModified();
382 }
383 
384 IMPL_LINK_NOARG(SvxColorTabPage, ClickWorkOnHdl_Impl, weld::Button&, void)
385 {
386  SvColorDialog aColorDlg;
387 
388  aColorDlg.SetColor (aCurrentColor);
390 
391  if (aColorDlg.Execute(GetFrameWeld()) == RET_OK)
392  {
393  Color aPreviewColor = aColorDlg.GetColor();
394  aCurrentColor = aPreviewColor;
395  UpdateColorValues( false );
396  // fill ItemSet and pass it on to XOut
397  rXFSet.Put( XFillColorItem( OUString(), aPreviewColor ) );
398  //m_aCtlPreviewOld.SetAttributes( aXFillAttr );
399  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
400 
401  m_aCtlPreviewNew.Invalidate();
402  }
403 }
404 
405 IMPL_LINK_NOARG(SvxColorTabPage, ClickDeleteHdl_Impl, weld::Button&, void)
406 {
407  sal_uInt16 nId = m_xValSetColorList->GetSelectedItemId();
408  size_t nPos = m_xValSetColorList->GetSelectItemPos();
409  if (m_xSelectPalette->get_active() != 0 || nPos == VALUESET_ITEM_NOTFOUND)
410  return;
411 
412  std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context));
413  css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
414  css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
415  sal_Int32 nSize = aCustomColorList.getLength() - 1;
416  for(sal_Int32 nIndex = static_cast<sal_Int32>(nPos);nIndex < nSize;nIndex++)
417  {
418  aCustomColorList[nIndex] = aCustomColorList[nIndex+1];
419  aCustomColorNameList[nIndex] = aCustomColorNameList[nIndex+1];
420  }
421  aCustomColorList.realloc(nSize);
422  aCustomColorNameList.realloc(nSize);
423  officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
424  officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
425  batch->commit();
426  m_xValSetColorList->RemoveItem(nId);
427  if (m_xValSetColorList->GetItemCount() != 0)
428  {
429  nId = m_xValSetColorList->GetItemId(0);
430  m_xValSetColorList->SelectItem(nId);
431  SelectValSetHdl_Impl(m_xValSetColorList.get());
432  }
433  else
434  {
435  m_xBtnDelete->set_sensitive(false);
436  m_xBtnDelete->set_tooltip_text( SvxResId(RID_SVXSTR_DELETEUSERCOLOR2) );
437  }
438 }
439 
440 IMPL_LINK_NOARG(SvxColorTabPage, SelectPaletteLBHdl, weld::ComboBox&, void)
441 {
442  m_xValSetColorList->Clear();
443  sal_Int32 nPos = m_xSelectPalette->get_active();
444  maPaletteManager.SetPalette( nPos );
445  maPaletteManager.ReloadColorSet(*m_xValSetColorList);
446 
447  if(nPos != maPaletteManager.GetPaletteCount() - 1 && nPos != 0)
448  {
451  XPropertyListType::Color, maPaletteManager.GetSelectedPalettePath()));
452  pList->SetName(maPaletteManager.GetPaletteName());
453  if(pList->Load())
454  {
455  SfxOkDialogController* pController = GetDialogController();
456  SvxAreaTabDialog* pArea = dynamic_cast<SvxAreaTabDialog*>(pController);
457  SvxLineTabDialog* pLine = dynamic_cast<SvxLineTabDialog*>(pController);
458  pColorList = pList;
459  if( pArea )
460  pArea->SetNewColorList(pList);
461  else if( pLine )
462  pLine->SetNewColorList(pList);
463  else
464  SetColorList(pList);
465  *pnColorListState |= ChangeType::CHANGED;
466  *pnColorListState &= ~ChangeType::MODIFIED;
467  }
468  }
469  if (nPos != 0)
470  {
471  m_xBtnDelete->set_sensitive(false);
472  m_xBtnDelete->set_tooltip_text( SvxResId(RID_SVXSTR_DELETEUSERCOLOR1) );
473  }
474 
475  m_xValSetColorList->Resize();
476 }
477 
478 IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, ValueSet*, pValSet, void)
479 {
480  sal_Int32 nPos = pValSet->GetSelectedItemId();
481  if( nPos == 0 )
482  return;
483 
484  Color aColor = pValSet->GetItemColor( nPos );
485 
486  rXFSet.Put( XFillColorItem( OUString(), aColor ) );
487  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
488  m_aCtlPreviewNew.Invalidate();
489  ChangeColor(aColor, false);
490 
491  if (pValSet == m_xValSetColorList.get())
492  {
493  m_xValSetRecentList->SetNoSelection();
494  if (m_xSelectPalette->get_active() == 0 && m_xValSetColorList->GetSelectedItemId() != 0)
495  {
496  m_xBtnDelete->set_sensitive(true);
497  m_xBtnDelete->set_tooltip_text("");
498  }
499  else
500  {
501  m_xBtnDelete->set_sensitive(false);
502  m_xBtnDelete->set_tooltip_text( SvxResId(RID_SVXSTR_DELETEUSERCOLOR1) );
503  }
504  }
505  if (pValSet == m_xValSetRecentList.get())
506  {
507  m_xValSetColorList->SetNoSelection();
508  m_xBtnDelete->set_sensitive(false);
509  m_xBtnDelete->set_tooltip_text( SvxResId(RID_SVXSTR_DELETEUSERCOLOR2) );
510  }
511 }
512 
514 {
515  switch (eModell)
516  {
517  case ColorModel::RGB:
518  {
519  CmykToRgb_Impl (rColor, static_cast<sal_uInt16>(255 - rColor.GetAlpha()) );
520  rColor.SetAlpha (255);
521  }
522  break;
523 
524  case ColorModel::CMYK:
525  {
526  sal_uInt16 nK;
527  RgbToCmyk_Impl (rColor, nK );
528  rColor.SetAlpha (255 - static_cast<sal_uInt8>(nK));
529  }
530  break;
531  }
532 }
533 
534 IMPL_LINK_NOARG(SvxColorTabPage, SelectColorModeHdl_Impl, weld::Toggleable&, void)
535 {
536  if (m_xRbRGB->get_active())
537  eCM = ColorModel::RGB;
538  else if (m_xRbCMYK->get_active())
539  eCM = ColorModel::CMYK;
540  ChangeColorModel();
541  UpdateColorValues();
542 }
543 
544 
546 {
547  css::uno::Sequence<css::beans::PropertyValue> aArgs(1);
548  aArgs[0].Name = "AdditionsTag";
549  aArgs[0].Value <<= OUString("Color Palette");
550  comphelper::dispatchCommand(".uno:AdditionsDialog", aArgs);
551 }
552 
553 void SvxColorTabPage::ChangeColor(const Color &rNewColor, bool bUpdatePreset )
554 {
555  aPreviousColor = rNewColor;
556  aCurrentColor = rNewColor;
557  UpdateColorValues( bUpdatePreset );
558  // fill ItemSet and pass it on to XOut
559  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
561  m_aCtlPreviewNew.Invalidate();
562 }
563 
565 {
566  if (eModel == ColorModel::RGB)
567  m_xRbRGB->set_active(true);
568  else if (eModel == ColorModel::CMYK)
569  m_xRbCMYK->set_active(true);
570 }
571 
573 {
574  switch( eCM )
575  {
576  case ColorModel::RGB:
577  {
578  m_xRGBcustom->show();
579  m_xRGBpreset->show();
580  m_xCMYKcustom->hide();
581  m_xCMYKpreset->hide();
582  }
583  break;
584 
585  case ColorModel::CMYK:
586  {
587  m_xCMYKcustom->show();
588  m_xCMYKpreset->show();
589  m_xRGBcustom->hide();
590  m_xRGBpreset->hide();
591  }
592  break;
593  }
594 }
595 
596 void SvxColorTabPage::UpdateColorValues( bool bUpdatePreset )
597 {
598  if (eCM != ColorModel::RGB)
599  {
602 
603  m_xCcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetRed() ), FieldUnit::PERCENT );
604  m_xMcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetBlue() ), FieldUnit::PERCENT );
605  m_xYcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetGreen() ), FieldUnit::PERCENT );
606  m_xKcustom->set_value( ColorToPercent_Impl( 255 - aCurrentColor.GetAlpha() ), FieldUnit::PERCENT );
607 
608  if( bUpdatePreset )
609  {
618  }
619 
622  }
623  else
624  {
628  m_xHexcustom->SetColor( aCurrentColor );
629 
630  if( bUpdatePreset )
631  {
632  m_xRpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetRed())));
633  m_xGpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetGreen())));
634  m_xBpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetBlue())));
635  m_xHexpreset->SetColor( aPreviousColor );
636  }
637  }
638 }
639 
640 sal_Int32 SvxColorTabPage::FindInCustomColors(std::u16string_view aColorName)
641 {
642  css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
643  tools::Long nCount = aCustomColorNameList.getLength();
644  bool bValidColorName = true;
645  sal_Int32 nPos = -1;
646 
647  for(tools::Long i = 0;i < nCount && bValidColorName;i++)
648  {
649  if(aColorName == aCustomColorNameList[i])
650  {
651  nPos = i;
652  bValidColorName = false;
653  }
654  }
655  return nPos;
656 }
657 
658 sal_Int32 SvxColorTabPage::FindInPalette( const Color& rColor )
659 {
660  return pColorList->GetIndexOfColor(rColor);
661 }
662 
663 // A RGB value is converted to a CMYK value - not in an ideal way as
664 // R is converted into C, G into M and B into Y. The K value is held in an
665 // extra variable. For further color models one should develop own
666 // classes which should contain the respective casts.
667 
668 void SvxColorTabPage::RgbToCmyk_Impl( Color& rColor, sal_uInt16& rK )
669 {
670  sal_uInt16 const nColor1 = 255 - rColor.GetRed();
671  sal_uInt16 const nColor2 = 255 - rColor.GetGreen();
672  sal_uInt16 const nColor3 = 255 - rColor.GetBlue();
673 
674  rK = std::min( std::min( nColor1, nColor2 ), nColor3 );
675 
676  rColor.SetRed( sal::static_int_cast< sal_uInt8 >( nColor1 - rK ) );
677  rColor.SetGreen( sal::static_int_cast< sal_uInt8 >( nColor2 - rK ) );
678  rColor.SetBlue( sal::static_int_cast< sal_uInt8 >( nColor3 - rK ) );
679 }
680 
681 
682 // reverse case to RgbToCmyk_Impl (see above)
683 
684 void SvxColorTabPage::CmykToRgb_Impl( Color& rColor, const sal_uInt16 nK )
685 {
686  tools::Long lTemp;
687 
688  lTemp = 255 - ( rColor.GetRed() + nK );
689 
690  if( lTemp < 0 )
691  lTemp = 0;
692  rColor.SetRed( static_cast<sal_uInt8>(lTemp) );
693 
694  lTemp = 255 - ( rColor.GetGreen() + nK );
695 
696  if( lTemp < 0 )
697  lTemp = 0;
698  rColor.SetGreen( static_cast<sal_uInt8>(lTemp) );
699 
700  lTemp = 255 - ( rColor.GetBlue() + nK );
701 
702  if( lTemp < 0 )
703  lTemp = 0;
704  rColor.SetBlue( static_cast<sal_uInt8>(lTemp) );
705 }
706 
707 
708 sal_uInt16 SvxColorTabPage::ColorToPercent_Impl( sal_uInt16 nColor )
709 {
710  sal_uInt16 nValue = 0;
711 
712  switch (eCM)
713  {
714  case ColorModel::RGB :
715  nValue = nColor;
716  break;
717 
718  case ColorModel::CMYK:
719  nValue = static_cast<sal_uInt16>( static_cast<double>(nColor) * 100.0 / 255.0 + 0.5 );
720  break;
721  }
722 
723  return nValue;
724 }
725 
726 
727 sal_uInt16 SvxColorTabPage::PercentToColor_Impl( sal_uInt16 nPercent )
728 {
729  sal_uInt16 nValue = 0;
730 
731  switch (eCM)
732  {
733  case ColorModel::RGB :
734  nValue = nPercent;
735  break;
736 
737  case ColorModel::CMYK:
738  nValue = static_cast<sal_uInt16>( static_cast<double>(nPercent) * 255.0 / 100.0 + 0.5 );
739  break;
740  }
741 
742  return nValue;
743 }
744 
745 
747 {
748  // the color model is saved in the Ini-file
749  SetUserData( OUString::number( static_cast<int>(eCM) ) );
750 }
751 
752 
754 {
755  OSL_ASSERT( t == XPropertyListType::Color );
756  pColorList = XColorListRef( static_cast<XColorList *>(xRef.get() ) );
757 }
758 
760 {
761  SetPropertyList( XPropertyListType::Color, XPropertyListRef( ( pColList.get() ) ) );
762 }
763 
764 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString AsRGBHexString() const
std::unique_ptr< weld::CustomWeld > m_xValSetColorListWin
Definition: cuitabarea.hxx:681
std::unique_ptr< weld::MetricSpinButton > m_xYcustom
Definition: cuitabarea.hxx:672
virtual ~SvxColorTabPage() override
Definition: tpcolor.cxx:154
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 GetAlpha() const
void SetAlpha(sal_uInt8 nAlpha)
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
sal_uInt8 GetRed() const
void SetColorModel(ColorModel eModel)
Definition: tpcolor.cxx:564
std::unique_ptr< weld::MetricSpinButton > m_xKcustom
Definition: cuitabarea.hxx:674
void SetBlue(sal_uInt8 nBlue)
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()
long Long
static const AllSettings & GetSettings()
std::unique_ptr< weld::MetricSpinButton > m_xMcustom
Definition: cuitabarea.hxx:673
constexpr OUStringLiteral PERCENT(u"Percent")
sal_Int16 nId
std::unique_ptr< weld::Button > m_xMoreColors
Definition: cuitabarea.hxx:678
std::unique_ptr< weld::Widget > m_xRGBpreset
Definition: cuitabarea.hxx:656
std::unique_ptr< weld::CustomWeld > m_xValSetRecentListWin
Definition: cuitabarea.hxx:682
SfxItemSet & rXFSet
Definition: cuitabarea.hxx:638
virtual void FillUserData() override
Definition: tpcolor.cxx:746
SvxColorTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tpcolor.cxx:42
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:222
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:647
virtual bool FillItemSet(SfxItemSet *) override
Definition: tpcolor.cxx:230
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:651
const OUString & GetUserData() const
sal_uInt16 PercentToColor_Impl(sal_uInt16 nPercent)
Definition: tpcolor.cxx:727
static void CmykToRgb_Impl(Color &rColor, const sal_uInt16 nKey)
Definition: tpcolor.cxx:684
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
void SetNewColorList(XColorListRef const &pColTab)
Definition: cuitabline.hxx:76
void ChangeColor(const Color &rNewColor, bool bUpdatePreset=true)
Definition: tpcolor.cxx:553
sal_uInt16 ColorToPercent_Impl(sal_uInt16 nColor)
Definition: tpcolor.cxx:708
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:759
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:244
void UpdateColorValues(bool bUpdatePreset=true)
Definition: tpcolor.cxx:596
virtual void Reset(const SfxItemSet *) override
Definition: tpcolor.cxx:250
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:640
IMPL_STATIC_LINK_NOARG(SvxColorTabPage, OnMoreColorsClick, weld::Button &, void)
Definition: tpcolor.cxx:545
void SetRed(sal_uInt8 nRed)
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
void ChangeColorModel()
Definition: tpcolor.cxx:572
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)
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
ColorTransparency
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpcolor.cxx:274
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:195
static void ConvertColorValues(Color &rColor, ColorModel eModell)
Definition: tpcolor.cxx:513
static OUString formatPercent(double dNumber, const LanguageTag &rLangTag)
SfxItemState
#define WB_NO_DIRECTSELECT
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:668
void SetPropertyList(XPropertyListType t, const XPropertyListRef &xRef)
Definition: tpcolor.cxx:753
Reference< XComponentContext > getProcessComponentContext()
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
ColorModel
IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, ValueSet *, pValSet, void)
Definition: tpcolor.cxx:478
sal_Int32 FindInPalette(const Color &rColor)
Definition: tpcolor.cxx:658
void ImpColorCountChanged()
Definition: tpcolor.cxx:162
WinBits const WB_TABSTOP
DeactivateRC
std::unique_ptr< weld::Widget > m_xCMYKcustom
Definition: cuitabarea.hxx:665
IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, weld::SpinButton &, void)
Definition: tpcolor.cxx:280
void AddRecentColor(const Color &rRecentColor, const OUString &rColorName, bool bFront=true)
#define WB_FLATVALUESET
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