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->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 // it is not possible to install color palette extensions in Online or mobile apps
155 {
156 m_xMoreColors->hide();
157 }
158}
159
161{
163 m_xValSetRecentList.reset();
164 m_xValSetColorListWin.reset();
165 m_xValSetColorList.reset();
166}
167
169{
170 if (!pColorList.is())
171 return;
174}
175
177{
178 m_xSelectPalette->clear();
179 std::vector<OUString> aPaletteList = maPaletteManager.GetPaletteList();
180 for (auto const& palette : aPaletteList)
181 {
182 m_xSelectPalette->append_text(palette);
183 }
184 OUString aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() );
185 m_xSelectPalette->set_active_text(aPaletteName);
186 if (m_xSelectPalette->get_active() != -1)
187 {
188 SelectPaletteLBHdl(*m_xSelectPalette);
189 }
190}
191
193{
194 if (pColorList.is())
195 {
198 }
199}
200
202{
203 if( !pColorList.is() )
204 return;
205
206 if( const XFillColorItem* pFillColorItem = rOutAttrs.GetItemIfSet( GetWhich( XATTR_FILLCOLOR ) ) )
207 {
210
211 const Color aColor = pFillColorItem->GetColorValue();
212 NamedColor aNamedColor;
213 aNamedColor.m_aColor = aColor;
214 ChangeColor(aNamedColor);
215 sal_Int32 nPos = FindInPalette( aColor );
216
217 if ( nPos != -1 )
218 m_xValSetColorList->SelectItem(m_xValSetColorList->GetItemId(nPos));
219 // else search in other palettes?
220
221 }
222
224 m_aCtlPreviewOld.Invalidate();
225
226 SelectValSetHdl_Impl(m_xValSetColorList.get());
227}
228
230{
231 if( _pSet )
232 FillItemSet( _pSet );
233
234 return DeactivateRC::LeavePage;
235}
236
238{
239 Color aColor = m_xValSetColorList->GetItemColor( m_xValSetColorList->GetSelectedItemId() );
240 OUString sColorName;
241 if (m_aCurrentColor.m_aColor == aColor)
242 sColorName = m_xValSetColorList->GetItemText( m_xValSetColorList->GetSelectedItemId() );
243 else
244 sColorName = "#" + m_aCurrentColor.m_aColor.AsRGBHexString().toAsciiUpperCase();
245
247 XFillColorItem aColorItem(sColorName, m_aCurrentColor.m_aColor);
249 rSet->Put(aColorItem);
250 rSet->Put(XFillStyleItem(drawing::FillStyle_SOLID));
251 return true;
252}
253
255{
256 bool bEnable = pColorList.is() && pColorList->Count();
257 m_xBtnWorkOn->set_sensitive(bEnable);
258}
259
261{
263
264 Color aNewColor;
265
266 if ( nState >= SfxItemState::DEFAULT )
267 {
268 XFillColorItem aColorItem( rSet->Get( XATTR_FILLCOLOR ) );
269 m_aPreviousColor = aColorItem.GetColorValue();
270 aNewColor = aColorItem.GetColorValue();
271 }
272
273 // set color model
274 OUString aStr = GetUserData();
275 eCM = static_cast<ColorModel>(aStr.toInt32());
278
279 NamedColor aColor;
280 aColor.m_aColor = aNewColor;
281 ChangeColor(aColor);
282
284}
285
286std::unique_ptr<SfxTabPage> SvxColorTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rOutAttrs)
287{
288 return std::make_unique<SvxColorTabPage>(pPage, pController, *rOutAttrs);
289}
290
291// is called when the content of the MtrFields is changed for color values
293{
294 // read current MtrFields, if cmyk, then k-value as transparency
295 m_aCurrentColor.m_aColor = Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())),
296 static_cast<sal_uInt8>(PercentToColor_Impl(m_xGcustom->get_value())),
297 static_cast<sal_uInt8>(PercentToColor_Impl(m_xBcustom->get_value())));
298 UpdateColorValues();
299
300 rXFSet.Put( XFillColorItem( OUString(), m_aCurrentColor.m_aColor ) );
301 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
302
303 m_aCtlPreviewNew.Invalidate();
304}
305
307{
308 // read current MtrFields, if cmyk, then k-value as transparency
309 m_aCurrentColor.m_aColor = Color(ColorTransparency, static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))),
310 static_cast<sal_uInt8>(PercentToColor_Impl(m_xCcustom->get_value(FieldUnit::NONE))),
311 static_cast<sal_uInt8>(PercentToColor_Impl(m_xYcustom->get_value(FieldUnit::NONE))),
312 static_cast<sal_uInt8>(PercentToColor_Impl(m_xMcustom->get_value(FieldUnit::NONE))));
313 ConvertColorValues (m_aCurrentColor.m_aColor, ColorModel::RGB);
314
315 rXFSet.Put( XFillColorItem( OUString(), m_aCurrentColor.m_aColor ) );
316 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
317
318 m_aCtlPreviewNew.Invalidate();
319}
320
322{
323 m_aCurrentColor.m_aColor = m_xHexcustom->GetColor();
324 UpdateColorValues();
325
326 rXFSet.Put( XFillColorItem( OUString(), m_aCurrentColor.m_aColor ) );
327 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
328
329 m_aCtlPreviewNew.Invalidate();
330}
331
333{
334 OUString aNewName( SvxResId( RID_SVXSTR_COLOR ) );
335 OUString aDesc( CuiResId( RID_CUISTR_DESC_COLOR ) );
336 OUString aName;
337
338 tools::Long j = 1;
339 bool bValidColorName = false;
340 // check if name is already existing
341 while (!bValidColorName)
342 {
343 aName = aNewName + " " + OUString::number( j++ );
344 bValidColorName = (FindInCustomColors(aName) == -1);
345 }
346
349 sal_uInt16 nError = 1;
350
351 while (pDlg->Execute() == RET_OK)
352 {
353 pDlg->GetName( aName );
354
355 bValidColorName = (FindInCustomColors(aName) == -1);
356 if (bValidColorName)
357 {
358 nError = 0;
359 break;
360 }
361
362 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
363 std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
364 if (xWarnBox->run() != RET_OK)
365 break;
366 }
367
368 pDlg.disposeAndClear();
369
370 if (!nError)
371 {
372 m_xSelectPalette->set_active(0);
373 SelectPaletteLBHdl(*m_xSelectPalette);
374 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
375 css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
376 css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
377 sal_Int32 nSize = aCustomColorList.getLength();
378 aCustomColorList.realloc( nSize + 1 );
379 aCustomColorNameList.realloc( nSize + 1 );
380 aCustomColorList.getArray()[nSize] = sal_Int32(m_aCurrentColor.m_aColor);
381 aCustomColorNameList.getArray()[nSize] = aName;
382 officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
383 officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
384 batch->commit();
385 sal_uInt16 nId = m_xValSetColorList->GetItemId(nSize - 1);
386 m_xValSetColorList->InsertItem( nId + 1 , m_aCurrentColor.m_aColor, aName );
387 m_xValSetColorList->SelectItem( nId + 1 );
388 m_xBtnDelete->set_sensitive(false);
389 m_xBtnDelete->set_tooltip_text( CuiResId(RID_CUISTR_DELETEUSERCOLOR2) );
390 ImpColorCountChanged();
391 }
392
393 UpdateModified();
394}
395
396IMPL_LINK_NOARG(SvxColorTabPage, ClickWorkOnHdl_Impl, weld::Button&, void)
397{
398 SvColorDialog aColorDlg;
399
400 aColorDlg.SetColor (m_aCurrentColor.m_aColor);
402
403 if (aColorDlg.Execute(GetFrameWeld()) == RET_OK)
404 {
405 Color aPreviewColor = aColorDlg.GetColor();
406 m_aCurrentColor.m_aColor = aPreviewColor;
407 UpdateColorValues( false );
408 // fill ItemSet and pass it on to XOut
409 rXFSet.Put( XFillColorItem( OUString(), aPreviewColor ) );
410 //m_aCtlPreviewOld.SetAttributes( aXFillAttr );
411 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
412
413 m_aCtlPreviewNew.Invalidate();
414 }
415}
416
417IMPL_LINK_NOARG(SvxColorTabPage, ClickDeleteHdl_Impl, weld::Button&, void)
418{
419 sal_uInt16 nId = m_xValSetColorList->GetSelectedItemId();
420 size_t nPos = m_xValSetColorList->GetSelectItemPos();
421 if (m_xSelectPalette->get_active() != 0 || nPos == VALUESET_ITEM_NOTFOUND)
422 return;
423
424 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
425 css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
426 auto aCustomColorListRange = asNonConstRange(aCustomColorList);
427 css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
428 auto aCustomColorNameListRange = asNonConstRange(aCustomColorNameList);
429 sal_Int32 nSize = aCustomColorList.getLength() - 1;
430 for(sal_Int32 nIndex = static_cast<sal_Int32>(nPos);nIndex < nSize;nIndex++)
431 {
432 aCustomColorListRange[nIndex] = aCustomColorList[nIndex+1];
433 aCustomColorNameListRange[nIndex] = aCustomColorNameList[nIndex+1];
434 }
435 aCustomColorList.realloc(nSize);
436 aCustomColorNameList.realloc(nSize);
437 officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
438 officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
439 batch->commit();
440 m_xValSetColorList->RemoveItem(nId);
441 if (m_xValSetColorList->GetItemCount() != 0)
442 {
443 nId = m_xValSetColorList->GetItemId(0);
444 m_xValSetColorList->SelectItem(nId);
445 SelectValSetHdl_Impl(m_xValSetColorList.get());
446 }
447 else
448 {
449 m_xBtnDelete->set_sensitive(false);
450 m_xBtnDelete->set_tooltip_text( CuiResId(RID_CUISTR_DELETEUSERCOLOR2) );
451 }
452}
453
455{
456 m_xValSetColorList->Clear();
457 sal_Int32 nPos = m_xSelectPalette->get_active();
458 maPaletteManager.SetPalette( nPos );
459 maPaletteManager.ReloadColorSet(*m_xValSetColorList);
460
461 if(nPos != maPaletteManager.GetPaletteCount() - 1 && nPos != 0)
462 {
465 XPropertyListType::Color, maPaletteManager.GetSelectedPalettePath()));
466 pList->SetName(maPaletteManager.GetPaletteName());
467 if(pList->Load())
468 {
469 SfxOkDialogController* pController = GetDialogController();
470 SvxAreaTabDialog* pArea = dynamic_cast<SvxAreaTabDialog*>(pController);
471 SvxLineTabDialog* pLine = dynamic_cast<SvxLineTabDialog*>(pController);
472 pColorList = pList;
473 if( pArea )
474 pArea->SetNewColorList(pList);
475 else if( pLine )
476 pLine->SetNewColorList(pList);
477 else
478 SetColorList(pList);
479 *pnColorListState |= ChangeType::CHANGED;
480 *pnColorListState &= ~ChangeType::MODIFIED;
481 }
482 }
483 if (nPos != 0)
484 {
485 m_xBtnDelete->set_sensitive(false);
486 m_xBtnDelete->set_tooltip_text( CuiResId(RID_CUISTR_DELETEUSERCOLOR1) );
487 }
488
489 m_xValSetColorList->Resize();
490}
491
492IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, ValueSet*, pValSet, void)
493{
494 sal_Int32 nPos = pValSet->GetSelectedItemId();
495 if( nPos == 0 )
496 return;
497
498 Color aColor = pValSet->GetItemColor( nPos );
499
500 rXFSet.Put( XFillColorItem( OUString(), aColor ) );
501 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
502 m_aCtlPreviewNew.Invalidate();
503
504 NamedColor aNamedColor;
505 aNamedColor.m_aColor = aColor;
506
507 if (pValSet == m_xValSetColorList.get() && maPaletteManager.IsThemePaletteSelected())
508 {
509 sal_uInt16 nThemeIndex;
510 sal_uInt16 nEffectIndex;
511 if (PaletteManager::GetThemeAndEffectIndex(nPos, nThemeIndex, nEffectIndex))
512 {
513 aNamedColor.m_nThemeIndex = nThemeIndex;
514 maPaletteManager.GetLumModOff(nThemeIndex, nEffectIndex, aNamedColor.m_nLumMod, aNamedColor.m_nLumOff);
515 }
516 }
517
518 ChangeColor(aNamedColor, false);
519
520 if (pValSet == m_xValSetColorList.get())
521 {
522 m_xValSetRecentList->SetNoSelection();
523 if (m_xSelectPalette->get_active() == 0 && m_xValSetColorList->GetSelectedItemId() != 0)
524 {
525 m_xBtnDelete->set_sensitive(true);
526 m_xBtnDelete->set_tooltip_text("");
527 }
528 else
529 {
530 m_xBtnDelete->set_sensitive(false);
531 m_xBtnDelete->set_tooltip_text( CuiResId(RID_CUISTR_DELETEUSERCOLOR1) );
532 }
533 }
534 if (pValSet == m_xValSetRecentList.get())
535 {
536 m_xValSetColorList->SetNoSelection();
537 m_xBtnDelete->set_sensitive(false);
538 m_xBtnDelete->set_tooltip_text( CuiResId(RID_CUISTR_DELETEUSERCOLOR2) );
539 }
540}
541
543{
544 switch (eModell)
545 {
546 case ColorModel::RGB:
547 {
548 CmykToRgb_Impl (rColor, static_cast<sal_uInt16>(255 - rColor.GetAlpha()) );
549 rColor.SetAlpha (255);
550 }
551 break;
552
553 case ColorModel::CMYK:
554 {
555 sal_uInt16 nK;
556 RgbToCmyk_Impl (rColor, nK );
557 rColor.SetAlpha (255 - static_cast<sal_uInt8>(nK));
558 }
559 break;
560 }
561}
562
563IMPL_LINK_NOARG(SvxColorTabPage, SelectColorModeHdl_Impl, weld::Toggleable&, void)
564{
565 if (m_xRbRGB->get_active())
566 eCM = ColorModel::RGB;
567 else if (m_xRbCMYK->get_active())
568 eCM = ColorModel::CMYK;
569 ChangeColorModel();
570 UpdateColorValues();
571}
572
573
575{
576 css::uno::Sequence<css::beans::PropertyValue> aArgs{ comphelper::makePropertyValue(
577 "AdditionsTag", OUString("Color Palette")) };
578 comphelper::dispatchCommand(".uno:AdditionsDialog", aArgs);
579}
580
581void SvxColorTabPage::ChangeColor(const NamedColor &rNewColor, bool bUpdatePreset )
582{
583 m_aPreviousColor = rNewColor.m_aColor;
584 m_aCurrentColor = rNewColor;
585 UpdateColorValues( bUpdatePreset );
586 // fill ItemSet and pass it on to XOut
587 XFillColorItem aItem(OUString(), m_aCurrentColor.m_aColor);
589 rXFSet.Put(aItem);
590
592 m_aCtlPreviewNew.Invalidate();
593}
594
596{
597 if (eModel == ColorModel::RGB)
598 m_xRbRGB->set_active(true);
599 else if (eModel == ColorModel::CMYK)
600 m_xRbCMYK->set_active(true);
601}
602
604{
605 switch( eCM )
606 {
607 case ColorModel::RGB:
608 {
609 m_xRGBcustom->show();
610 m_xRGBpreset->show();
611 m_xCMYKcustom->hide();
612 m_xCMYKpreset->hide();
613 }
614 break;
615
616 case ColorModel::CMYK:
617 {
618 m_xCMYKcustom->show();
619 m_xCMYKpreset->show();
620 m_xRGBcustom->hide();
621 m_xRGBpreset->hide();
622 }
623 break;
624 }
625}
626
627void SvxColorTabPage::UpdateColorValues( bool bUpdatePreset )
628{
629 if (eCM != ColorModel::RGB)
630 {
633
634 m_xCcustom->set_value( ColorToPercent_Impl( m_aCurrentColor.m_aColor.GetRed() ), FieldUnit::PERCENT );
635 m_xMcustom->set_value( ColorToPercent_Impl( m_aCurrentColor.m_aColor.GetBlue() ), FieldUnit::PERCENT );
636 m_xYcustom->set_value( ColorToPercent_Impl( m_aCurrentColor.m_aColor.GetGreen() ), FieldUnit::PERCENT );
637 m_xKcustom->set_value( ColorToPercent_Impl( 255 - m_aCurrentColor.m_aColor.GetAlpha() ), FieldUnit::PERCENT );
638
639 if( bUpdatePreset )
640 {
649 }
650
653 }
654 else
655 {
660
661 if( bUpdatePreset )
662 {
663 m_xRpreset->set_text(OUString::number(ColorToPercent_Impl(m_aPreviousColor.GetRed())));
664 m_xGpreset->set_text(OUString::number(ColorToPercent_Impl(m_aPreviousColor.GetGreen())));
665 m_xBpreset->set_text(OUString::number(ColorToPercent_Impl(m_aPreviousColor.GetBlue())));
666 m_xHexpreset->SetColor( m_aPreviousColor );
667 }
668 }
669}
670
671sal_Int32 SvxColorTabPage::FindInCustomColors(std::u16string_view aColorName)
672{
673 css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
674 tools::Long nCount = aCustomColorNameList.getLength();
675 bool bValidColorName = true;
676 sal_Int32 nPos = -1;
677
678 for(tools::Long i = 0;i < nCount && bValidColorName;i++)
679 {
680 if(aColorName == aCustomColorNameList[i])
681 {
682 nPos = i;
683 bValidColorName = false;
684 }
685 }
686 return nPos;
687}
688
689sal_Int32 SvxColorTabPage::FindInPalette( const Color& rColor )
690{
691 return pColorList->GetIndexOfColor(rColor);
692}
693
694// A RGB value is converted to a CMYK value - not in an ideal way as
695// R is converted into C, G into M and B into Y. The K value is held in an
696// extra variable. For further color models one should develop own
697// classes which should contain the respective casts.
698
699void SvxColorTabPage::RgbToCmyk_Impl( Color& rColor, sal_uInt16& rK )
700{
701 sal_uInt16 const nColor1 = 255 - rColor.GetRed();
702 sal_uInt16 const nColor2 = 255 - rColor.GetGreen();
703 sal_uInt16 const nColor3 = 255 - rColor.GetBlue();
704
705 rK = std::min( std::min( nColor1, nColor2 ), nColor3 );
706
707 rColor.SetRed( sal::static_int_cast< sal_uInt8 >( nColor1 - rK ) );
708 rColor.SetGreen( sal::static_int_cast< sal_uInt8 >( nColor2 - rK ) );
709 rColor.SetBlue( sal::static_int_cast< sal_uInt8 >( nColor3 - rK ) );
710}
711
712
713// reverse case to RgbToCmyk_Impl (see above)
714
715void SvxColorTabPage::CmykToRgb_Impl( Color& rColor, const sal_uInt16 nK )
716{
717 tools::Long lTemp;
718
719 lTemp = 255 - ( rColor.GetRed() + nK );
720
721 if( lTemp < 0 )
722 lTemp = 0;
723 rColor.SetRed( static_cast<sal_uInt8>(lTemp) );
724
725 lTemp = 255 - ( rColor.GetGreen() + nK );
726
727 if( lTemp < 0 )
728 lTemp = 0;
729 rColor.SetGreen( static_cast<sal_uInt8>(lTemp) );
730
731 lTemp = 255 - ( rColor.GetBlue() + nK );
732
733 if( lTemp < 0 )
734 lTemp = 0;
735 rColor.SetBlue( static_cast<sal_uInt8>(lTemp) );
736}
737
738
739sal_uInt16 SvxColorTabPage::ColorToPercent_Impl( sal_uInt16 nColor )
740{
741 sal_uInt16 nValue = 0;
742
743 switch (eCM)
744 {
745 case ColorModel::RGB :
746 nValue = nColor;
747 break;
748
749 case ColorModel::CMYK:
750 nValue = static_cast<sal_uInt16>( static_cast<double>(nColor) * 100.0 / 255.0 + 0.5 );
751 break;
752 }
753
754 return nValue;
755}
756
757
758sal_uInt16 SvxColorTabPage::PercentToColor_Impl( sal_uInt16 nPercent )
759{
760 sal_uInt16 nValue = 0;
761
762 switch (eCM)
763 {
764 case ColorModel::RGB :
765 nValue = nPercent;
766 break;
767
768 case ColorModel::CMYK:
769 nValue = static_cast<sal_uInt16>( static_cast<double>(nPercent) * 255.0 / 100.0 + 0.5 );
770 break;
771 }
772
773 return nValue;
774}
775
776
778{
779 // the color model is saved in the Ini-file
780 SetUserData( OUString::number( static_cast<int>(eCM) ) );
781}
782
783
785{
786 OSL_ASSERT( t == XPropertyListType::Color );
787 pColorList = XColorListRef( static_cast<XColorList *>(xRef.get() ) );
788}
789
791{
792 SetPropertyList( XPropertyListType::Color, XPropertyListRef( ( pColList.get() ) ) );
793}
794
795/* 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 bool GetThemeAndEffectIndex(sal_uInt16 nItemId, sal_uInt16 &rThemeIndex, sal_uInt16 &rEffectIndex)
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:715
std::unique_ptr< weld::Entry > m_xGpreset
Definition: cuitabarea.hxx:674
void ImpColorCountChanged()
Definition: tpcolor.cxx:168
static void RgbToCmyk_Impl(Color &rColor, sal_uInt16 &rK)
Definition: tpcolor.cxx:699
std::unique_ptr< weld::Entry > m_xKpreset
Definition: cuitabarea.hxx:686
const SfxItemSet & rOutAttrs
Definition: cuitabarea.hxx:649
void FillPaletteLB()
Definition: tpcolor.cxx:176
std::unique_ptr< weld::MetricSpinButton > m_xYcustom
Definition: cuitabarea.hxx:688
std::unique_ptr< weld::Widget > m_xCMYKcustom
Definition: cuitabarea.hxx:681
std::unique_ptr< weld::SpinButton > m_xGcustom
Definition: cuitabarea.hxx:677
void UpdateColorValues(bool bUpdatePreset=true)
Definition: tpcolor.cxx:627
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpcolor.cxx:229
void SetColorList(const XColorListRef &pColList)
Definition: tpcolor.cxx:790
std::unique_ptr< weld::Entry > m_xRpreset
Definition: cuitabarea.hxx:673
static sal_Int32 FindInCustomColors(std::u16string_view aColorName)
Definition: tpcolor.cxx:671
std::unique_ptr< weld::Widget > m_xCMYKpreset
Definition: cuitabarea.hxx:682
std::unique_ptr< weld::Button > m_xBtnDelete
Definition: cuitabarea.hxx:692
std::unique_ptr< weld::Widget > m_xRGBcustom
Definition: cuitabarea.hxx:671
void SetPropertyList(XPropertyListType t, const XPropertyListRef &xRef)
Definition: tpcolor.cxx:784
sal_uInt16 PercentToColor_Impl(sal_uInt16 nPercent)
Definition: tpcolor.cxx:758
XFillAttrSetItem aXFillAttr
Definition: cuitabarea.hxx:655
std::unique_ptr< weld::SpinButton > m_xBcustom
Definition: cuitabarea.hxx:678
std::unique_ptr< weld::MetricSpinButton > m_xCcustom
Definition: cuitabarea.hxx:687
std::unique_ptr< SvxColorValueSet > m_xValSetRecentList
Definition: cuitabarea.hxx:667
void ChangeColor(const NamedColor &rNewColor, bool bUpdatePreset=true)
Definition: tpcolor.cxx:581
void Construct()
Definition: tpcolor.cxx:192
NamedColor m_aCurrentColor
Definition: cuitabarea.hxx:661
static void ConvertColorValues(Color &rColor, ColorModel eModell)
Definition: tpcolor.cxx:542
ColorModel eCM
Definition: cuitabarea.hxx:658
std::unique_ptr< weld::Entry > m_xBpreset
Definition: cuitabarea.hxx:675
void ChangeColorModel()
Definition: tpcolor.cxx:603
std::unique_ptr< weld::RadioButton > m_xRbCMYK
Definition: cuitabarea.hxx:670
virtual void FillUserData() override
Definition: tpcolor.cxx:777
std::unique_ptr< weld::RadioButton > m_xRbRGB
Definition: cuitabarea.hxx:669
std::unique_ptr< weld::HexColorControl > m_xHexpreset
Definition: cuitabarea.hxx:679
Color m_aPreviousColor
Definition: cuitabarea.hxx:660
XColorListRef pColorList
Definition: cuitabarea.hxx:651
std::unique_ptr< SvxColorValueSet > m_xValSetColorList
Definition: cuitabarea.hxx:666
sal_uInt16 ColorToPercent_Impl(sal_uInt16 nColor)
Definition: tpcolor.cxx:739
sal_Int32 FindInPalette(const Color &rColor)
Definition: tpcolor.cxx:689
std::unique_ptr< weld::Button > m_xBtnWorkOn
Definition: cuitabarea.hxx:693
virtual ~SvxColorTabPage() override
Definition: tpcolor.cxx:160
std::unique_ptr< weld::ComboBox > m_xSelectPalette
Definition: cuitabarea.hxx:668
SfxItemSet & rXFSet
Definition: cuitabarea.hxx:656
std::unique_ptr< weld::MetricSpinButton > m_xMcustom
Definition: cuitabarea.hxx:689
std::unique_ptr< weld::Button > m_xBtnAdd
Definition: cuitabarea.hxx:691
SvxXRectPreview m_aCtlPreviewNew
Definition: cuitabarea.hxx:665
std::unique_ptr< weld::HexColorControl > m_xHexcustom
Definition: cuitabarea.hxx:680
std::unique_ptr< weld::SpinButton > m_xRcustom
Definition: cuitabarea.hxx:676
std::unique_ptr< weld::Entry > m_xYpreset
Definition: cuitabarea.hxx:684
std::unique_ptr< weld::Entry > m_xCpreset
Definition: cuitabarea.hxx:683
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpcolor.cxx:286
std::unique_ptr< weld::CustomWeld > m_xValSetRecentListWin
Definition: cuitabarea.hxx:698
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpcolor.cxx:201
std::unique_ptr< weld::Entry > m_xMpreset
Definition: cuitabarea.hxx:685
virtual void Reset(const SfxItemSet *) override
Definition: tpcolor.cxx:260
void SetColorModel(ColorModel eModel)
Definition: tpcolor.cxx:595
std::unique_ptr< weld::CustomWeld > m_xValSetColorListWin
Definition: cuitabarea.hxx:697
std::unique_ptr< weld::Widget > m_xRGBpreset
Definition: cuitabarea.hxx:672
virtual bool FillItemSet(SfxItemSet *) override
Definition: tpcolor.cxx:237
std::unique_ptr< weld::Button > m_xMoreColors
Definition: cuitabarea.hxx:694
SvxColorTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tpcolor.cxx:44
SvxXRectPreview m_aCtlPreviewOld
Definition: cuitabarea.hxx:664
std::unique_ptr< weld::MetricSpinButton > m_xKcustom
Definition: cuitabarea.hxx:690
PaletteManager maPaletteManager
Definition: cuitabarea.hxx:663
void UpdateModified()
Definition: tpcolor.cxx:254
static sal_uInt32 getColumnCount()
void SetNewColorList(XColorListRef const &pColTab)
Definition: cuitabline.hxx:76
void SetAttributes(const SfxItemSet &rItemSet)
void disposeAndClear()
void setComplexColor(model::ComplexColor const &rComplexColor)
const Color & GetColorValue() const
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
model::ComplexColor getComplexColor()
Color m_aColor
sal_Int16 m_nLumOff
sal_Int16 m_nLumMod
sal_Int16 m_nThemeIndex
ChangeType
DeactivateRC
IMPL_STATIC_LINK_NOARG(SvxColorTabPage, OnMoreColorsClick, weld::Button &, void)
Definition: tpcolor.cxx:574
IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, ValueSet *, pValSet, void)
Definition: tpcolor.cxx:492
IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, weld::SpinButton &, void)
Definition: tpcolor.cxx:292
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