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