35#include <svx/strings.hrc>
36#include <officecfg/Office/Common.hxx>
37#include <osl/diagnose.h>
45 :
SfxTabPage(pPage, pController,
"cui/ui/colorpage.ui",
"ColorPage", &rInAttrs)
46 , rOutAttrs ( rInAttrs )
48 , pnColorListState( nullptr )
49 , aXFillAttr( rInAttrs.GetPool() )
52 , m_xValSetColorList(new
SvxColorValueSet(m_xBuilder->weld_scrolled_window(
"colorsetwin", true)))
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))
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);
180 for (
auto const& palette : aPaletteList)
184 OUString aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() );
211 const Color aColor = pFillColorItem->GetColorValue();
234 return DeactivateRC::LeavePage;
266 if (
nState >= SfxItemState::DEFAULT )
288 return std::make_unique<SvxColorTabPage>(pPage, pController, *
rOutAttrs);
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())));
300 rXFSet.Put(
XFillColorItem( OUString(), m_aCurrentColor.m_aColor ) );
301 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
303 m_aCtlPreviewNew.Invalidate();
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))));
315 rXFSet.Put(
XFillColorItem( OUString(), m_aCurrentColor.m_aColor ) );
316 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
318 m_aCtlPreviewNew.Invalidate();
323 m_aCurrentColor.m_aColor = m_xHexcustom->GetColor();
326 rXFSet.Put(
XFillColorItem( OUString(), m_aCurrentColor.m_aColor ) );
327 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
329 m_aCtlPreviewNew.Invalidate();
334 OUString aNewName(
SvxResId( RID_SVXSTR_COLOR ) );
335 OUString aDesc(
CuiResId( RID_CUISTR_DESC_COLOR ) );
339 bool bValidColorName =
false;
341 while (!bValidColorName)
343 aName = aNewName +
" " + OUString::number( j++ );
344 bValidColorName = (FindInCustomColors(
aName) == -1);
349 sal_uInt16 nError = 1;
351 while (pDlg->Execute() ==
RET_OK)
353 pDlg->GetName(
aName );
355 bValidColorName = (FindInCustomColors(
aName) == -1);
363 std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog(
"DuplicateNameDialog"));
364 if (xWarnBox->run() !=
RET_OK)
372 m_xSelectPalette->set_active(0);
373 SelectPaletteLBHdl(*m_xSelectPalette);
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);
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();
400 aColorDlg.
SetColor (m_aCurrentColor.m_aColor);
406 m_aCurrentColor.m_aColor = aPreviewColor;
407 UpdateColorValues(
false );
411 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
413 m_aCtlPreviewNew.Invalidate();
419 sal_uInt16
nId = m_xValSetColorList->GetSelectedItemId();
420 size_t nPos = m_xValSetColorList->GetSelectItemPos();
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;
432 aCustomColorListRange[
nIndex] = aCustomColorList[
nIndex+1];
433 aCustomColorNameListRange[
nIndex] = aCustomColorNameList[
nIndex+1];
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);
440 m_xValSetColorList->RemoveItem(
nId);
441 if (m_xValSetColorList->GetItemCount() != 0)
443 nId = m_xValSetColorList->GetItemId(0);
444 m_xValSetColorList->SelectItem(
nId);
445 SelectValSetHdl_Impl(m_xValSetColorList.get());
449 m_xBtnDelete->set_sensitive(
false);
450 m_xBtnDelete->set_tooltip_text(
CuiResId(RID_CUISTR_DELETEUSERCOLOR2) );
456 m_xValSetColorList->Clear();
457 sal_Int32
nPos = m_xSelectPalette->get_active();
458 maPaletteManager.SetPalette(
nPos );
459 maPaletteManager.ReloadColorSet(*m_xValSetColorList);
461 if(
nPos != maPaletteManager.GetPaletteCount() - 1 &&
nPos != 0)
465 XPropertyListType::Color, maPaletteManager.GetSelectedPalettePath()));
466 pList->SetName(maPaletteManager.GetPaletteName());
479 *pnColorListState |= ChangeType::CHANGED;
485 m_xBtnDelete->set_sensitive(
false);
486 m_xBtnDelete->set_tooltip_text(
CuiResId(RID_CUISTR_DELETEUSERCOLOR1) );
489 m_xValSetColorList->Resize();
494 sal_Int32
nPos = pValSet->GetSelectedItemId();
498 Color aColor = pValSet->GetItemColor(
nPos );
501 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
502 m_aCtlPreviewNew.Invalidate();
507 if (pValSet == m_xValSetColorList.get() && maPaletteManager.IsThemePaletteSelected())
509 sal_uInt16 nThemeIndex;
510 sal_uInt16 nEffectIndex;
514 maPaletteManager.GetLumModOff(nThemeIndex, nEffectIndex, aNamedColor.
m_nLumMod, aNamedColor.
m_nLumOff);
518 ChangeColor(aNamedColor,
false);
520 if (pValSet == m_xValSetColorList.get())
522 m_xValSetRecentList->SetNoSelection();
523 if (m_xSelectPalette->get_active() == 0 && m_xValSetColorList->GetSelectedItemId() != 0)
525 m_xBtnDelete->set_sensitive(
true);
526 m_xBtnDelete->set_tooltip_text(
"");
530 m_xBtnDelete->set_sensitive(
false);
531 m_xBtnDelete->set_tooltip_text(
CuiResId(RID_CUISTR_DELETEUSERCOLOR1) );
534 if (pValSet == m_xValSetRecentList.get())
536 m_xValSetColorList->SetNoSelection();
537 m_xBtnDelete->set_sensitive(
false);
538 m_xBtnDelete->set_tooltip_text(
CuiResId(RID_CUISTR_DELETEUSERCOLOR2) );
565 if (m_xRbRGB->get_active())
567 else if (m_xRbCMYK->get_active())
577 "AdditionsTag", OUString(
"Color Palette")) };
673 css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
675 bool bValidColorName =
true;
680 if(aColorName == aCustomColorNameList[
i])
683 bValidColorName =
false;
701 sal_uInt16
const nColor1 = 255 - rColor.
GetRed();
702 sal_uInt16
const nColor2 = 255 - rColor.
GetGreen();
703 sal_uInt16
const nColor3 = 255 - rColor.
GetBlue();
705 rK = std::min( std::min( nColor1, nColor2 ), nColor3 );
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 ) );
719 lTemp = 255 - ( rColor.
GetRed() + nK );
725 lTemp = 255 - ( rColor.
GetGreen() + nK );
731 lTemp = 255 - ( rColor.
GetBlue() + nK );
750 nValue =
static_cast<sal_uInt16
>(
static_cast<double>(nColor) * 100.0 / 255.0 + 0.5 );
769 nValue =
static_cast<sal_uInt16
>(
static_cast<double>(nPercent) * 255.0 / 100.0 + 0.5 );
786 OSL_ASSERT(
t == XPropertyListType::Color );
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 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)
static void CmykToRgb_Impl(Color &rColor, const sal_uInt16 nKey)
std::unique_ptr< weld::Entry > m_xGpreset
void ImpColorCountChanged()
static void RgbToCmyk_Impl(Color &rColor, sal_uInt16 &rK)
std::unique_ptr< weld::Entry > m_xKpreset
const SfxItemSet & rOutAttrs
std::unique_ptr< weld::MetricSpinButton > m_xYcustom
std::unique_ptr< weld::Widget > m_xCMYKcustom
std::unique_ptr< weld::SpinButton > m_xGcustom
void UpdateColorValues(bool bUpdatePreset=true)
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
void SetColorList(const XColorListRef &pColList)
std::unique_ptr< weld::Entry > m_xRpreset
static sal_Int32 FindInCustomColors(std::u16string_view aColorName)
std::unique_ptr< weld::Widget > m_xCMYKpreset
std::unique_ptr< weld::Button > m_xBtnDelete
std::unique_ptr< weld::Widget > m_xRGBcustom
void SetPropertyList(XPropertyListType t, const XPropertyListRef &xRef)
sal_uInt16 PercentToColor_Impl(sal_uInt16 nPercent)
XFillAttrSetItem aXFillAttr
std::unique_ptr< weld::SpinButton > m_xBcustom
std::unique_ptr< weld::MetricSpinButton > m_xCcustom
std::unique_ptr< SvxColorValueSet > m_xValSetRecentList
void ChangeColor(const NamedColor &rNewColor, bool bUpdatePreset=true)
NamedColor m_aCurrentColor
static void ConvertColorValues(Color &rColor, ColorModel eModell)
std::unique_ptr< weld::Entry > m_xBpreset
std::unique_ptr< weld::RadioButton > m_xRbCMYK
virtual void FillUserData() override
std::unique_ptr< weld::RadioButton > m_xRbRGB
std::unique_ptr< weld::HexColorControl > m_xHexpreset
std::unique_ptr< SvxColorValueSet > m_xValSetColorList
sal_uInt16 ColorToPercent_Impl(sal_uInt16 nColor)
sal_Int32 FindInPalette(const Color &rColor)
std::unique_ptr< weld::Button > m_xBtnWorkOn
virtual ~SvxColorTabPage() override
std::unique_ptr< weld::ComboBox > m_xSelectPalette
std::unique_ptr< weld::MetricSpinButton > m_xMcustom
std::unique_ptr< weld::Button > m_xBtnAdd
SvxXRectPreview m_aCtlPreviewNew
std::unique_ptr< weld::HexColorControl > m_xHexcustom
std::unique_ptr< weld::SpinButton > m_xRcustom
std::unique_ptr< weld::Entry > m_xYpreset
std::unique_ptr< weld::Entry > m_xCpreset
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
std::unique_ptr< weld::CustomWeld > m_xValSetRecentListWin
virtual void ActivatePage(const SfxItemSet &rSet) override
std::unique_ptr< weld::Entry > m_xMpreset
virtual void Reset(const SfxItemSet *) override
void SetColorModel(ColorModel eModel)
std::unique_ptr< weld::CustomWeld > m_xValSetColorListWin
std::unique_ptr< weld::Widget > m_xRGBpreset
virtual bool FillItemSet(SfxItemSet *) override
std::unique_ptr< weld::Button > m_xMoreColors
SvxColorTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
SvxXRectPreview m_aCtlPreviewOld
std::unique_ptr< weld::MetricSpinButton > m_xKcustom
PaletteManager maPaletteManager
static sal_uInt32 getColumnCount()
void SetNewColorList(XColorListRef const &pColTab)
void SetAttributes(const SfxItemSet &rItemSet)
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)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
OUString CuiResId(TranslateId aKey)
SVXCORE_DLLPUBLIC OUString SvxResId(TranslateId aId)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
#define LINK(Instance, Class, Member)
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)
model::ComplexColor getComplexColor()
IMPL_STATIC_LINK_NOARG(SvxColorTabPage, OnMoreColorsClick, weld::Button &, void)
IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, ValueSet *, pValSet, void)
IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, weld::SpinButton &, void)
#define VALUESET_ITEM_NOTFOUND
#define WB_NO_DIRECTSELECT
constexpr OUStringLiteral PERCENT(u"Percent")
constexpr TypedWhichId< XFillColorItem > XATTR_FILLCOLOR(XATTR_FILL_FIRST+1)