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 ColorValueSet(m_xBuilder->weld_scrolled_window("colorsetwin")))
50  , m_xValSetRecentList(new ColorValueSet(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<SvtValueSet*, 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 
129  // disable preset color values
130  m_xRGBpreset->set_sensitive(false);
131  m_xCMYKpreset->set_sensitive(false);
132 
133  // ValueSet
134  m_xValSetColorList->SetStyle(m_xValSetColorList->GetStyle() | WB_ITEMBORDER);
135  m_xValSetColorList->Show();
136 
137  m_xValSetRecentList->SetStyle(m_xValSetRecentList->GetStyle() | WB_ITEMBORDER);
138  m_xValSetRecentList->Show();
139 
141  aSize = m_xValSetRecentList->layoutAllVisible(maPaletteManager.GetRecentColorCount());
142  m_xValSetRecentList->set_size_request(aSize.Width(), aSize.Height());
143 }
144 
146 {
147  m_xValSetRecentListWin.reset();
148  m_xValSetRecentList.reset();
149  m_xValSetColorListWin.reset();
150  m_xValSetColorList.reset();
151 }
152 
154 {
155  if (!pColorList.is())
156  return;
159 }
160 
162 {
163  m_xSelectPalette->clear();
164  std::vector<OUString> aPaletteList = maPaletteManager.GetPaletteList();
165  for (auto const& palette : aPaletteList)
166  {
167  m_xSelectPalette->append_text(palette);
168  }
169  OUString aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() );
170  m_xSelectPalette->set_active_text(aPaletteName);
171  if (m_xSelectPalette->get_active() != -1)
172  {
173  SelectPaletteLBHdl(*m_xSelectPalette);
174  }
175 }
176 
178 {
179  if (pColorList.is())
180  {
181  FillPaletteLB();
183  }
184 }
185 
187 {
188  if( pColorList.is() )
189  {
190  const SfxPoolItem* pPoolItem = nullptr;
191  if( SfxItemState::SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), true, &pPoolItem ) )
192  {
195 
196  const Color aColor = static_cast<const XFillColorItem*>(pPoolItem)->GetColorValue();
197  ChangeColor( aColor );
198  sal_Int32 nPos = FindInPalette( aColor );
199 
200  if ( nPos != -1 )
201  m_xValSetColorList->SelectItem(m_xValSetColorList->GetItemId(nPos));
202  // else search in other palettes?
203 
204  }
205 
207  m_aCtlPreviewOld.Invalidate();
208 
209  SelectValSetHdl_Impl(m_xValSetColorList.get());
210  }
211 }
212 
214 {
215  if( _pSet )
216  FillItemSet( _pSet );
217 
218  return DeactivateRC::LeavePage;
219 }
220 
222 {
223  Color aColor = m_xValSetColorList->GetItemColor( m_xValSetColorList->GetSelectedItemId() );
224  OUString sColorName;
225  if ( aCurrentColor == aColor )
226  sColorName = m_xValSetColorList->GetItemText( m_xValSetColorList->GetSelectedItemId() );
227  else
228  sColorName = "#" + aCurrentColor.AsRGBHexString().toAsciiUpperCase();
230  rSet->Put( XFillColorItem( sColorName, aCurrentColor ) );
231  rSet->Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
232  return true;
233 }
234 
236 {
237  bool bEnable = pColorList.is() && pColorList->Count();
238  m_xBtnWorkOn->set_sensitive(bEnable);
239 }
240 
242 {
243  SfxItemState nState = rSet->GetItemState( XATTR_FILLCOLOR );
244 
245  Color aNewColor;
246 
247  if ( nState >= SfxItemState::DEFAULT )
248  {
249  XFillColorItem aColorItem( rSet->Get( XATTR_FILLCOLOR ) );
250  aPreviousColor = aColorItem.GetColorValue();
251  aNewColor = aColorItem.GetColorValue();
252  }
253 
254  // set color model
255  OUString aStr = GetUserData();
256  eCM = static_cast<ColorModel>(aStr.toInt32());
257  SetColorModel( eCM );
259 
260  ChangeColor(aNewColor);
261 
262  UpdateModified();
263 }
264 
265 std::unique_ptr<SfxTabPage> SvxColorTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rOutAttrs)
266 {
267  return std::make_unique<SvxColorTabPage>(pPage, pController, *rOutAttrs);
268 }
269 
270 // is called when the content of the MtrFields is changed for color values
272 {
273  // read current MtrFields, if cmyk, then k-value as transparency
274  aCurrentColor = Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())),
275  static_cast<sal_uInt8>(PercentToColor_Impl(m_xGcustom->get_value())),
276  static_cast<sal_uInt8>(PercentToColor_Impl(m_xBcustom->get_value())));
277  UpdateColorValues();
278 
279  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
280  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
281 
282  m_aCtlPreviewNew.Invalidate();
283 }
284 
285 IMPL_LINK_NOARG(SvxColorTabPage, MetricSpinValueHdl_Impl, weld::MetricSpinButton&, void)
286 {
287  // read current MtrFields, if cmyk, then k-value as transparency
288  aCurrentColor = Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))),
289  static_cast<sal_uInt8>(PercentToColor_Impl(m_xCcustom->get_value(FieldUnit::NONE))),
290  static_cast<sal_uInt8>(PercentToColor_Impl(m_xYcustom->get_value(FieldUnit::NONE))),
291  static_cast<sal_uInt8>(PercentToColor_Impl(m_xMcustom->get_value(FieldUnit::NONE))));
292  ConvertColorValues (aCurrentColor, ColorModel::RGB);
293 
294  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
295  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
296 
297  m_aCtlPreviewNew.Invalidate();
298 }
299 
300 IMPL_LINK_NOARG(SvxColorTabPage, ModifiedHdl_Impl, weld::Entry&, void)
301 {
302  aCurrentColor = m_xHexcustom->GetColor();
303  UpdateColorValues();
304 
305  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
306  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
307 
308  m_aCtlPreviewNew.Invalidate();
309 }
310 
311 IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl, weld::Button&, void)
312 {
313  OUString aNewName( SvxResId( RID_SVXSTR_COLOR ) );
314  OUString aDesc( CuiResId( RID_SVXSTR_DESC_COLOR ) );
315  OUString aName;
316 
317  long j = 1;
318  bool bValidColorName = false;
319  // check if name is already existing
320  while (!bValidColorName)
321  {
322  aName = aNewName + " " + OUString::number( j++ );
323  bValidColorName = (FindInCustomColors(aName) == LISTBOX_ENTRY_NOTFOUND);
324  }
325 
328  sal_uInt16 nError = 1;
329 
330  while (pDlg->Execute() == RET_OK)
331  {
332  pDlg->GetName( aName );
333 
334  bValidColorName = (FindInCustomColors(aName) == LISTBOX_ENTRY_NOTFOUND);
335  if (bValidColorName)
336  {
337  nError = 0;
338  break;
339  }
340 
341  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
342  std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
343  if (xWarnBox->run() != RET_OK)
344  break;
345  }
346 
347  pDlg.disposeAndClear();
348 
349  if (!nError)
350  {
351  m_xSelectPalette->set_active(0);
352  SelectPaletteLBHdl(*m_xSelectPalette);
353  std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context));
354  css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
355  css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
356  sal_Int32 nSize = aCustomColorList.getLength();
357  aCustomColorList.realloc( nSize + 1 );
358  aCustomColorNameList.realloc( nSize + 1 );
359  aCustomColorList[nSize] = sal_Int32(aCurrentColor);
360  aCustomColorNameList[nSize] = aName;
361  officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
362  officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
363  batch->commit();
364  sal_uInt16 nId = m_xValSetColorList->GetItemId(nSize - 1);
365  m_xValSetColorList->InsertItem( nId + 1 , aCurrentColor, aName );
366  m_xValSetColorList->SelectItem( nId + 1 );
367  m_xBtnDelete->set_sensitive(false);
368  ImpColorCountChanged();
369  }
370 
371  UpdateModified();
372 }
373 
374 IMPL_LINK_NOARG(SvxColorTabPage, ClickWorkOnHdl_Impl, weld::Button&, void)
375 {
376  SvColorDialog aColorDlg;
377 
378  aColorDlg.SetColor (aCurrentColor);
380 
381  if (aColorDlg.Execute(GetFrameWeld()) == RET_OK)
382  {
383  Color aPreviewColor = aColorDlg.GetColor();
384  aCurrentColor = aPreviewColor;
385  UpdateColorValues( false );
386  // fill ItemSet and pass it on to XOut
387  rXFSet.Put( XFillColorItem( OUString(), aPreviewColor ) );
388  //m_aCtlPreviewOld.SetAttributes( aXFillAttr );
389  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
390 
391  m_aCtlPreviewNew.Invalidate();
392  }
393 }
394 
395 IMPL_LINK_NOARG(SvxColorTabPage, ClickDeleteHdl_Impl, weld::Button&, void)
396 {
397  sal_uInt16 nId = m_xValSetColorList->GetSelectedItemId();
398  size_t nPos = m_xValSetColorList->GetSelectItemPos();
399  if (m_xSelectPalette->get_active() == 0 && nPos != VALUESET_ITEM_NOTFOUND )
400  {
401  std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context));
402  css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
403  css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
404  sal_Int32 nSize = aCustomColorList.getLength() - 1;
405  for(sal_Int32 nIndex = static_cast<sal_Int32>(nPos);nIndex < nSize;nIndex++)
406  {
407  aCustomColorList[nIndex] = aCustomColorList[nIndex+1];
408  aCustomColorNameList[nIndex] = aCustomColorNameList[nIndex+1];
409  }
410  aCustomColorList.realloc(nSize);
411  aCustomColorNameList.realloc(nSize);
412  officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
413  officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
414  batch->commit();
415  m_xValSetColorList->RemoveItem(nId);
416  if (m_xValSetColorList->GetItemCount() != 0)
417  {
418  nId = m_xValSetColorList->GetItemId(0);
419  m_xValSetColorList->SelectItem(nId);
420  SelectValSetHdl_Impl(m_xValSetColorList.get());
421  }
422  else
423  m_xBtnDelete->set_sensitive(false);
424  }
425 }
426 
427 IMPL_LINK_NOARG(SvxColorTabPage, SelectPaletteLBHdl, weld::ComboBox&, void)
428 {
429  m_xValSetColorList->Clear();
430  sal_Int32 nPos = m_xSelectPalette->get_active();
431  maPaletteManager.SetPalette( nPos );
432  maPaletteManager.ReloadColorSet(*m_xValSetColorList);
433 
434  if(nPos != maPaletteManager.GetPaletteCount() - 1 && nPos != 0)
435  {
438  XPropertyListType::Color, maPaletteManager.GetSelectedPalettePath()));
439  pList->SetName(maPaletteManager.GetPaletteName());
440  if(pList->Load())
441  {
442  SfxOkDialogController* pController = GetDialogController();
443  SvxAreaTabDialog* pArea = dynamic_cast<SvxAreaTabDialog*>(pController);
444  SvxLineTabDialog* pLine = dynamic_cast<SvxLineTabDialog*>(pController);
445  pColorList = pList;
446  if( pArea )
447  pArea->SetNewColorList(pList);
448  else if( pLine )
449  pLine->SetNewColorList(pList);
450  else
451  SetColorList(pList);
452  *pnColorListState |= ChangeType::CHANGED;
453  *pnColorListState &= ~ChangeType::MODIFIED;
454  }
455  }
456  if (nPos != 0)
457  m_xBtnDelete->set_sensitive(false);
458 
459  m_xValSetColorList->Resize();
460 }
461 
462 IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, SvtValueSet*, pValSet, void)
463 {
464  sal_Int32 nPos = pValSet->GetSelectedItemId();
465  if( nPos != 0 )
466  {
467  Color aColor = pValSet->GetItemColor( nPos );
468 
469  rXFSet.Put( XFillColorItem( OUString(), aColor ) );
470  m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
471  m_aCtlPreviewNew.Invalidate();
472  ChangeColor(aColor, false);
473 
474  if (pValSet == m_xValSetColorList.get())
475  {
476  m_xValSetRecentList->SetNoSelection();
477  if (m_xSelectPalette->get_active() == 0 && m_xValSetColorList->GetSelectedItemId() != 0)
478  m_xBtnDelete->set_sensitive(true);
479  else
480  m_xBtnDelete->set_sensitive(false);
481  }
482  if (pValSet == m_xValSetRecentList.get())
483  {
484  m_xValSetColorList->SetNoSelection();
485  m_xBtnDelete->set_sensitive(false);
486  }
487  }
488 }
489 
491 {
492  switch (eModell)
493  {
494  case ColorModel::RGB:
495  {
496  CmykToRgb_Impl (rColor, static_cast<sal_uInt16>(rColor.GetTransparency()) );
497  rColor.SetTransparency (sal_uInt8(0));
498  }
499  break;
500 
501  case ColorModel::CMYK:
502  {
503  sal_uInt16 nK;
504  RgbToCmyk_Impl (rColor, nK );
505  rColor.SetTransparency (static_cast<sal_uInt8>(nK));
506  }
507  break;
508  }
509 }
510 
511 IMPL_LINK_NOARG(SvxColorTabPage, SelectColorModeHdl_Impl, weld::ToggleButton&, void)
512 {
513  if (m_xRbRGB->get_active())
514  eCM = ColorModel::RGB;
515  else if (m_xRbCMYK->get_active())
516  eCM = ColorModel::CMYK;
517  ChangeColorModel();
518  UpdateColorValues();
519 }
520 
521 void SvxColorTabPage::ChangeColor(const Color &rNewColor, bool bUpdatePreset )
522 {
523  aPreviousColor = rNewColor;
524  aCurrentColor = rNewColor;
525  UpdateColorValues( bUpdatePreset );
526  // fill ItemSet and pass it on to XOut
527  rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
529  m_aCtlPreviewNew.Invalidate();
530 }
531 
533 {
534  if (eModel == ColorModel::RGB)
535  m_xRbRGB->set_active(true);
536  else if (eModel == ColorModel::CMYK)
537  m_xRbCMYK->set_active(true);
538 }
539 
541 {
542  switch( eCM )
543  {
544  case ColorModel::RGB:
545  {
546  m_xRGBcustom->show();
547  m_xRGBpreset->show();
548  m_xCMYKcustom->hide();
549  m_xCMYKpreset->hide();
550  }
551  break;
552 
553  case ColorModel::CMYK:
554  {
555  m_xCMYKcustom->show();
556  m_xCMYKpreset->show();
557  m_xRGBcustom->hide();
558  m_xRGBpreset->hide();
559  }
560  break;
561  }
562 }
563 
564 void SvxColorTabPage::UpdateColorValues( bool bUpdatePreset )
565 {
566  if (eCM != ColorModel::RGB)
567  {
570 
571  m_xCcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetRed() ), FieldUnit::PERCENT );
572  m_xMcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetBlue() ), FieldUnit::PERCENT );
573  m_xYcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetGreen() ), FieldUnit::PERCENT );
574  m_xKcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetTransparency() ), FieldUnit::PERCENT );
575 
576  if( bUpdatePreset )
577  {
586  }
587 
590  }
591  else
592  {
596  m_xHexcustom->SetColor( aCurrentColor );
597 
598  if( bUpdatePreset )
599  {
600  m_xRpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetRed())));
601  m_xGpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetGreen())));
602  m_xBpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetBlue())));
603  m_xHexpreset->SetColor( aPreviousColor );
604  }
605  }
606 }
607 
608 sal_Int32 SvxColorTabPage::FindInCustomColors(OUString const & aColorName)
609 {
610  css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
611  long nCount = aCustomColorNameList.getLength();
612  bool bValidColorName = true;
613  sal_Int32 nPos = LISTBOX_ENTRY_NOTFOUND;
614 
615  for(long i = 0;i < nCount && bValidColorName;i++)
616  {
617  if(aColorName == aCustomColorNameList[i])
618  {
619  nPos = i;
620  bValidColorName = false;
621  }
622  }
623  return nPos;
624 }
625 
626 sal_Int32 SvxColorTabPage::FindInPalette( const Color& rColor )
627 {
628  sal_Int32 nPos = pColorList->GetIndexOfColor( rColor );
629 
630  return ( nPos == -1) ? LISTBOX_ENTRY_NOTFOUND : nPos;
631 }
632 
633 // A RGB value is converted to a CMYK value - not in an ideal way as
634 // R is converted into C, G into M and B into Y. The K value is held in an
635 // extra variable. For further color models one should develop own
636 // classes which should contain the respective casts.
637 
638 void SvxColorTabPage::RgbToCmyk_Impl( Color& rColor, sal_uInt16& rK )
639 {
640  sal_uInt16 const nColor1 = 255 - rColor.GetRed();
641  sal_uInt16 const nColor2 = 255 - rColor.GetGreen();
642  sal_uInt16 const nColor3 = 255 - rColor.GetBlue();
643 
644  rK = std::min( std::min( nColor1, nColor2 ), nColor3 );
645 
646  rColor.SetRed( sal::static_int_cast< sal_uInt8 >( nColor1 - rK ) );
647  rColor.SetGreen( sal::static_int_cast< sal_uInt8 >( nColor2 - rK ) );
648  rColor.SetBlue( sal::static_int_cast< sal_uInt8 >( nColor3 - rK ) );
649 }
650 
651 
652 // reverse case to RgbToCmyk_Impl (see above)
653 
654 void SvxColorTabPage::CmykToRgb_Impl( Color& rColor, const sal_uInt16 nK )
655 {
656  long lTemp;
657 
658  lTemp = 255 - ( rColor.GetRed() + nK );
659 
660  if( lTemp < 0 )
661  lTemp = 0;
662  rColor.SetRed( static_cast<sal_uInt8>(lTemp) );
663 
664  lTemp = 255 - ( rColor.GetGreen() + nK );
665 
666  if( lTemp < 0 )
667  lTemp = 0;
668  rColor.SetGreen( static_cast<sal_uInt8>(lTemp) );
669 
670  lTemp = 255 - ( rColor.GetBlue() + nK );
671 
672  if( lTemp < 0 )
673  lTemp = 0;
674  rColor.SetBlue( static_cast<sal_uInt8>(lTemp) );
675 }
676 
677 
678 sal_uInt16 SvxColorTabPage::ColorToPercent_Impl( sal_uInt16 nColor )
679 {
680  sal_uInt16 nValue = 0;
681 
682  switch (eCM)
683  {
684  case ColorModel::RGB :
685  nValue = nColor;
686  break;
687 
688  case ColorModel::CMYK:
689  nValue = static_cast<sal_uInt16>( static_cast<double>(nColor) * 100.0 / 255.0 + 0.5 );
690  break;
691  }
692 
693  return nValue;
694 }
695 
696 
697 sal_uInt16 SvxColorTabPage::PercentToColor_Impl( sal_uInt16 nPercent )
698 {
699  sal_uInt16 nValue = 0;
700 
701  switch (eCM)
702  {
703  case ColorModel::RGB :
704  nValue = nPercent;
705  break;
706 
707  case ColorModel::CMYK:
708  nValue = static_cast<sal_uInt16>( static_cast<double>(nPercent) * 255.0 / 100.0 + 0.5 );
709  break;
710  }
711 
712  return nValue;
713 }
714 
715 
717 {
718  // the color model is saved in the Ini-file
719  SetUserData( OUString::number( static_cast<int>(eCM) ) );
720 }
721 
722 
724 {
725  OSL_ASSERT( t == XPropertyListType::Color );
726  pColorList = XColorListRef( static_cast<XColorList *>(xRef.get() ) );
727 }
728 
730 {
731  SetPropertyList( XPropertyListType::Color, XPropertyListRef( ( pColList.get() ) ) );
732 }
733 
734 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString AsRGBHexString() const
std::unique_ptr< weld::CustomWeld > m_xValSetColorListWin
Definition: cuitabarea.hxx:682
std::unique_ptr< weld::MetricSpinButton > m_xYcustom
Definition: cuitabarea.hxx:674
virtual ~SvxColorTabPage() override
Definition: tpcolor.cxx:145
std::unique_ptr< weld::Button > m_xBtnWorkOn
Definition: cuitabarea.hxx:679
FieldUnit
std::unique_ptr< weld::SpinButton > m_xRcustom
Definition: cuitabarea.hxx:662
std::unique_ptr< ColorValueSet > m_xValSetRecentList
Definition: cuitabarea.hxx:653
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
sal_uInt8 GetRed() const
void SetColorModel(ColorModel eModel)
Definition: tpcolor.cxx:532
std::unique_ptr< weld::MetricSpinButton > m_xKcustom
Definition: cuitabarea.hxx:676
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:659
IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, SvtValueSet *, pValSet, void)
Definition: tpcolor.cxx:462
const LanguageTag & GetUILanguageTag() const
#define VALUESET_ITEM_NOTFOUND
XColorListRef pColorList
Definition: cuitabarea.hxx:635
static SvxAbstractDialogFactory * Create()
sal_uInt8 GetTransparency() const
static const AllSettings & GetSettings()
std::unique_ptr< weld::MetricSpinButton > m_xMcustom
Definition: cuitabarea.hxx:675
sal_Int16 nId
std::unique_ptr< weld::Widget > m_xRGBpreset
Definition: cuitabarea.hxx:658
std::unique_ptr< weld::CustomWeld > m_xValSetRecentListWin
Definition: cuitabarea.hxx:683
SfxItemSet & rXFSet
Definition: cuitabarea.hxx:640
virtual void FillUserData() override
Definition: tpcolor.cxx:716
SvxColorTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tpcolor.cxx:40
#define LISTBOX_ENTRY_NOTFOUND
std::unique_ptr< weld::Entry > m_xGpreset
Definition: cuitabarea.hxx:660
#define XATTR_FILLCOLOR
std::unique_ptr< weld::Button > m_xBtnDelete
Definition: cuitabarea.hxx:678
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpcolor.cxx:213
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:608
PaletteManager maPaletteManager
Definition: cuitabarea.hxx:649
virtual bool FillItemSet(SfxItemSet *) override
Definition: tpcolor.cxx:221
OUString SvxResId(const char *pId)
short Execute(weld::Window *pParent)
#define WB_ITEMBORDER
void SetNewColorList(XColorListRef const &pColorList)
Definition: cuitabarea.hxx:122
void SetExchangeSupport()
const OUString & GetUserData() const
sal_uInt16 PercentToColor_Impl(sal_uInt16 nPercent)
Definition: tpcolor.cxx:697
static void CmykToRgb_Impl(Color &rColor, const sal_uInt16 nKey)
Definition: tpcolor.cxx:654
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:661
sal_uInt8 GetBlue() const
ColorModel eCM
Definition: cuitabarea.hxx:642
XFillAttrSetItem aXFillAttr
Definition: cuitabarea.hxx:639
std::unique_ptr< weld::Widget > m_xCMYKpreset
Definition: cuitabarea.hxx:668
long GetRecentColorCount() const
void SetNewColorList(XColorListRef const &pColTab)
Definition: cuitabline.hxx:76
void ChangeColor(const Color &rNewColor, bool bUpdatePreset=true)
Definition: tpcolor.cxx:521
sal_uInt16 ColorToPercent_Impl(sal_uInt16 nColor)
Definition: tpcolor.cxx:678
static XColorListRef AsColorList(rtl::Reference< XPropertyList > const &plist)
ChangeType
void SetColor(const Color &rColor)
XPropertyListType
void SetColorList(const XColorListRef &pColList)
Definition: tpcolor.cxx:729
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
std::vector< OUString > GetPaletteList()
std::unique_ptr< weld::ComboBox > m_xSelectPalette
Definition: cuitabarea.hxx:654
void UpdateModified()
Definition: tpcolor.cxx:235
void UpdateColorValues(bool bUpdatePreset=true)
Definition: tpcolor.cxx:564
virtual void Reset(const SfxItemSet *) override
Definition: tpcolor.cxx:241
int i
const SfxItemSet & rOutAttrs
Definition: cuitabarea.hxx:633
void FillPaletteLB()
Definition: tpcolor.cxx:161
void Construct()
Definition: tpcolor.cxx:177
void SetRed(sal_uInt8 nRed)
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
void ChangeColorModel()
Definition: tpcolor.cxx:540
std::unique_ptr< weld::HexColorControl > m_xHexpreset
Definition: cuitabarea.hxx:665
std::unique_ptr< weld::Widget > m_xRGBcustom
Definition: cuitabarea.hxx:657
std::unique_ptr< weld::Entry > m_xKpreset
Definition: cuitabarea.hxx:672
void ReloadRecentColorSet(SvxColorValueSet &rColorSet)
std::unique_ptr< weld::HexColorControl > m_xHexcustom
Definition: cuitabarea.hxx:666
void SetAttributes(const SfxItemSet &rItemSet)
std::unique_ptr< weld::SpinButton > m_xGcustom
Definition: cuitabarea.hxx:663
std::unique_ptr< weld::RadioButton > m_xRbCMYK
Definition: cuitabarea.hxx:656
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpcolor.cxx:265
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
std::unique_ptr< weld::Entry > m_xCpreset
Definition: cuitabarea.hxx:669
const Color & GetColor() const
std::unique_ptr< weld::Button > m_xBtnAdd
Definition: cuitabarea.hxx:677
sal_uInt8 GetGreen() const
SvxXRectPreview m_aCtlPreviewOld
Definition: cuitabarea.hxx:650
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpcolor.cxx:186
static void ConvertColorValues(Color &rColor, ColorModel eModell)
Definition: tpcolor.cxx:490
static OUString formatPercent(double dNumber, const LanguageTag &rLangTag)
SfxItemState
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
unsigned char sal_uInt8
std::unique_ptr< weld::RadioButton > m_xRbRGB
Definition: cuitabarea.hxx:655
std::unique_ptr< ColorValueSet > m_xValSetColorList
Definition: cuitabarea.hxx:652
void SetGreen(sal_uInt8 nGreen)
RET_OK
static void RgbToCmyk_Impl(Color &rColor, sal_uInt16 &rK)
Definition: tpcolor.cxx:638
void SetPropertyList(XPropertyListType t, const XPropertyListRef &xRef)
Definition: tpcolor.cxx:723
const OUString PERCENT("Percent")
Reference< XComponentContext > getProcessComponentContext()
ColorModel
sal_Int32 FindInPalette(const Color &rColor)
Definition: tpcolor.cxx:626
void ImpColorCountChanged()
Definition: tpcolor.cxx:153
DeactivateRC
OString const aName
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
std::unique_ptr< weld::Widget > m_xCMYKcustom
Definition: cuitabarea.hxx:667
IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, weld::SpinButton &, void)
Definition: tpcolor.cxx:271
void AddRecentColor(const Color &rRecentColor, const OUString &rColorName, bool bFront=true)
std::unique_ptr< weld::Entry > m_xYpreset
Definition: cuitabarea.hxx:670
std::unique_ptr< weld::MetricSpinButton > m_xCcustom
Definition: cuitabarea.hxx:673
sal_Int32 nPos
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
aStr
std::unique_ptr< weld::Entry > m_xMpreset
Definition: cuitabarea.hxx:671
SvxXRectPreview m_aCtlPreviewNew
Definition: cuitabarea.hxx:651
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
static XPropertyListRef CreatePropertyListFromURL(XPropertyListType t, const OUString &rUrl)
std::unique_ptr< weld::SpinButton > m_xBcustom
Definition: cuitabarea.hxx:664