26 #include <strings.hrc>
35 #include <svx/strings.hrc>
36 #include <officecfg/Office/Common.hxx>
37 #include <osl/diagnose.h>
44 :
SfxTabPage(pPage, pController,
"cui/ui/colorpage.ui",
"ColorPage", &rInAttrs)
45 , rOutAttrs ( rInAttrs )
47 , pnColorListState( nullptr )
48 , aXFillAttr( rInAttrs.GetPool() )
51 , m_xValSetColorList(new
SvxColorValueSet(m_xBuilder->weld_scrolled_window(
"colorsetwin", true)))
53 , m_xSelectPalette(m_xBuilder->weld_combo_box(
"paletteselector"))
54 , m_xRbRGB(m_xBuilder->weld_radio_button(
"RGB"))
55 , m_xRbCMYK(m_xBuilder->weld_radio_button(
"CMYK"))
56 , m_xRGBcustom(m_xBuilder->weld_widget(
"rgbcustom"))
57 , m_xRGBpreset(m_xBuilder->weld_widget(
"rgbpreset"))
58 , m_xRpreset(m_xBuilder->weld_entry(
"R_preset"))
59 , m_xGpreset(m_xBuilder->weld_entry(
"G_preset"))
60 , m_xBpreset(m_xBuilder->weld_entry(
"B_preset"))
61 , m_xRcustom(m_xBuilder->weld_spin_button(
"R_custom"))
62 , m_xGcustom(m_xBuilder->weld_spin_button(
"G_custom"))
63 , m_xBcustom(m_xBuilder->weld_spin_button(
"B_custom"))
64 , m_xHexpreset(new
weld::HexColorControl(m_xBuilder->weld_entry(
"hex_preset")))
65 , m_xHexcustom(new
weld::HexColorControl(m_xBuilder->weld_entry(
"hex_custom")))
66 , m_xCMYKcustom(m_xBuilder->weld_widget(
"cmykcustom"))
67 , m_xCMYKpreset(m_xBuilder->weld_widget(
"cmykpreset"))
68 , m_xCpreset(m_xBuilder->weld_entry(
"C_preset"))
69 , m_xYpreset(m_xBuilder->weld_entry(
"Y_preset"))
70 , m_xMpreset(m_xBuilder->weld_entry(
"M_preset"))
71 , m_xKpreset(m_xBuilder->weld_entry(
"K_preset"))
72 , m_xCcustom(m_xBuilder->weld_metric_spin_button(
"C_custom",
FieldUnit::
PERCENT))
73 , m_xYcustom(m_xBuilder->weld_metric_spin_button(
"Y_custom",
FieldUnit::
PERCENT))
74 , m_xMcustom(m_xBuilder->weld_metric_spin_button(
"M_custom",
FieldUnit::
PERCENT))
75 , m_xKcustom(m_xBuilder->weld_metric_spin_button(
"K_custom",
FieldUnit::
PERCENT))
76 , m_xBtnAdd(m_xBuilder->weld_button(
"add"))
77 , m_xBtnDelete(m_xBuilder->weld_button(
"delete"))
78 , m_xBtnWorkOn(m_xBuilder->weld_button(
"edit"))
79 , m_xMoreColors(m_xBuilder->weld_button(
"btnMoreColors"))
80 , m_xCtlPreviewOld(new
weld::CustomWeld(*m_xBuilder,
"oldpreview", m_aCtlPreviewOld))
81 , m_xCtlPreviewNew(new
weld::CustomWeld(*m_xBuilder,
"newpreview", m_aCtlPreviewNew))
82 , m_xValSetColorListWin(new
weld::CustomWeld(*m_xBuilder,
"colorset", *m_xValSetColorList))
83 , m_xValSetRecentListWin(new
weld::CustomWeld(*m_xBuilder,
"recentcolorset", *m_xValSetRecentList))
114 m_xCcustom->connect_value_changed(aMetricSpinLink);
115 m_xYcustom->connect_value_changed(aMetricSpinLink);
116 m_xMcustom->connect_value_changed(aMetricSpinLink);
117 m_xKcustom->connect_value_changed(aMetricSpinLink);
133 m_xMoreColors->set_from_icon_name(
"cmd/sc_additionsdialog.png");
174 for (
auto const& palette : aPaletteList)
178 OUString aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() );
205 const Color aColor = pFillColorItem->GetColorValue();
228 return DeactivateRC::LeavePage;
245 rSet->
Put( aColorItem );
262 if ( nState >= SfxItemState::DEFAULT )
266 aNewColor = aColorItem.GetColorValue();
284 return std::make_unique<SvxColorTabPage>(pPage, pController, *
rOutAttrs);
291 aCurrentColor.m_aColor =
Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())),
292 static_cast<sal_uInt8>(PercentToColor_Impl(m_xGcustom->get_value())),
293 static_cast<sal_uInt8>(PercentToColor_Impl(m_xBcustom->get_value())));
296 rXFSet.Put(
XFillColorItem( OUString(), aCurrentColor.m_aColor ) );
297 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
299 m_aCtlPreviewNew.Invalidate();
305 aCurrentColor.m_aColor =
Color(
ColorTransparency, static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))),
306 static_cast<sal_uInt8>(PercentToColor_Impl(m_xCcustom->get_value(FieldUnit::NONE))),
307 static_cast<sal_uInt8>(PercentToColor_Impl(m_xYcustom->get_value(FieldUnit::NONE))),
308 static_cast<sal_uInt8>(PercentToColor_Impl(m_xMcustom->get_value(FieldUnit::NONE))));
311 rXFSet.Put(
XFillColorItem( OUString(), aCurrentColor.m_aColor ) );
312 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
314 m_aCtlPreviewNew.Invalidate();
319 aCurrentColor.m_aColor = m_xHexcustom->GetColor();
322 rXFSet.Put(
XFillColorItem( OUString(), aCurrentColor.m_aColor ) );
323 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
325 m_aCtlPreviewNew.Invalidate();
330 OUString aNewName(
SvxResId( RID_SVXSTR_COLOR ) );
331 OUString aDesc(
CuiResId( RID_CUISTR_DESC_COLOR ) );
335 bool bValidColorName =
false;
337 while (!bValidColorName)
339 aName = aNewName +
" " + OUString::number( j++ );
340 bValidColorName = (FindInCustomColors(aName) == -1);
345 sal_uInt16 nError = 1;
347 while (pDlg->Execute() ==
RET_OK)
349 pDlg->GetName( aName );
351 bValidColorName = (FindInCustomColors(aName) == -1);
359 std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog(
"DuplicateNameDialog"));
360 if (xWarnBox->run() !=
RET_OK)
364 pDlg.disposeAndClear();
368 m_xSelectPalette->set_active(0);
369 SelectPaletteLBHdl(*m_xSelectPalette);
371 css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
372 css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
373 sal_Int32 nSize = aCustomColorList.getLength();
374 aCustomColorList.realloc( nSize + 1 );
375 aCustomColorNameList.realloc( nSize + 1 );
376 aCustomColorList.getArray()[nSize] = sal_Int32(aCurrentColor.m_aColor);
377 aCustomColorNameList.getArray()[nSize] = aName;
378 officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
379 officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
381 sal_uInt16
nId = m_xValSetColorList->GetItemId(nSize - 1);
382 m_xValSetColorList->InsertItem( nId + 1 , aCurrentColor.m_aColor, aName );
383 m_xValSetColorList->SelectItem( nId + 1 );
384 m_xBtnDelete->set_sensitive(
false);
385 m_xBtnDelete->set_tooltip_text(
CuiResId(RID_CUISTR_DELETEUSERCOLOR2) );
386 ImpColorCountChanged();
396 aColorDlg.
SetColor (aCurrentColor.m_aColor);
402 aCurrentColor.m_aColor = aPreviewColor;
403 UpdateColorValues(
false );
407 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
409 m_aCtlPreviewNew.Invalidate();
415 sal_uInt16
nId = m_xValSetColorList->GetSelectedItemId();
416 size_t nPos = m_xValSetColorList->GetSelectItemPos();
421 css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
422 auto aCustomColorListRange = asNonConstRange(aCustomColorList);
423 css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
424 auto aCustomColorNameListRange = asNonConstRange(aCustomColorNameList);
425 sal_Int32 nSize = aCustomColorList.getLength() - 1;
428 aCustomColorListRange[
nIndex] = aCustomColorList[
nIndex+1];
429 aCustomColorNameListRange[
nIndex] = aCustomColorNameList[
nIndex+1];
431 aCustomColorList.realloc(nSize);
432 aCustomColorNameList.realloc(nSize);
433 officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
434 officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
436 m_xValSetColorList->RemoveItem(nId);
437 if (m_xValSetColorList->GetItemCount() != 0)
439 nId = m_xValSetColorList->GetItemId(0);
440 m_xValSetColorList->SelectItem(nId);
441 SelectValSetHdl_Impl(m_xValSetColorList.get());
445 m_xBtnDelete->set_sensitive(
false);
446 m_xBtnDelete->set_tooltip_text(
CuiResId(RID_CUISTR_DELETEUSERCOLOR2) );
452 m_xValSetColorList->Clear();
453 sal_Int32
nPos = m_xSelectPalette->get_active();
454 maPaletteManager.SetPalette( nPos );
455 maPaletteManager.ReloadColorSet(*m_xValSetColorList);
457 if(nPos != maPaletteManager.GetPaletteCount() - 1 && nPos != 0)
461 XPropertyListType::Color, maPaletteManager.GetSelectedPalettePath()));
462 pList->SetName(maPaletteManager.GetPaletteName());
475 *pnColorListState |= ChangeType::CHANGED;
481 m_xBtnDelete->set_sensitive(
false);
482 m_xBtnDelete->set_tooltip_text(
CuiResId(RID_CUISTR_DELETEUSERCOLOR1) );
485 m_xValSetColorList->Resize();
490 sal_Int32
nPos = pValSet->GetSelectedItemId();
494 Color aColor = pValSet->GetItemColor( nPos );
497 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
498 m_aCtlPreviewNew.Invalidate();
500 bool bThemePaletteSelected =
false;
501 if (pValSet == m_xValSetColorList.get())
503 bThemePaletteSelected = maPaletteManager.IsThemePaletteSelected();
507 if (bThemePaletteSelected)
512 ChangeColor(aThemedColor,
false);
514 if (pValSet == m_xValSetColorList.get())
516 m_xValSetRecentList->SetNoSelection();
517 if (m_xSelectPalette->get_active() == 0 && m_xValSetColorList->GetSelectedItemId() != 0)
519 m_xBtnDelete->set_sensitive(
true);
520 m_xBtnDelete->set_tooltip_text(
"");
524 m_xBtnDelete->set_sensitive(
false);
525 m_xBtnDelete->set_tooltip_text(
CuiResId(RID_CUISTR_DELETEUSERCOLOR1) );
528 if (pValSet == m_xValSetRecentList.get())
530 m_xValSetColorList->SetNoSelection();
531 m_xBtnDelete->set_sensitive(
false);
532 m_xBtnDelete->set_tooltip_text(
CuiResId(RID_CUISTR_DELETEUSERCOLOR2) );
551 rColor.
SetAlpha (255 - static_cast<sal_uInt8>(nK));
559 if (m_xRbRGB->get_active())
561 else if (m_xRbCMYK->get_active())
571 "AdditionsTag", OUString(
"Color Palette")) };
664 css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
666 bool bValidColorName =
true;
671 if(aColorName == aCustomColorNameList[
i])
674 bValidColorName =
false;
692 sal_uInt16
const nColor1 = 255 - rColor.
GetRed();
693 sal_uInt16
const nColor2 = 255 - rColor.
GetGreen();
694 sal_uInt16
const nColor3 = 255 - rColor.
GetBlue();
696 rK = std::min( std::min( nColor1, nColor2 ), nColor3 );
698 rColor.
SetRed( sal::static_int_cast< sal_uInt8 >( nColor1 - rK ) );
699 rColor.
SetGreen( sal::static_int_cast< sal_uInt8 >( nColor2 - rK ) );
700 rColor.
SetBlue( sal::static_int_cast< sal_uInt8 >( nColor3 - rK ) );
710 lTemp = 255 - ( rColor.
GetRed() + nK );
714 rColor.
SetRed( static_cast<sal_uInt8>(lTemp) );
716 lTemp = 255 - ( rColor.
GetGreen() + nK );
720 rColor.
SetGreen( static_cast<sal_uInt8>(lTemp) );
722 lTemp = 255 - ( rColor.
GetBlue() + nK );
726 rColor.
SetBlue( static_cast<sal_uInt8>(lTemp) );
741 nValue =
static_cast<sal_uInt16
>(
static_cast<double>(nColor) * 100.0 / 255.0 + 0.5 );
760 nValue =
static_cast<sal_uInt16
>(
static_cast<double>(nPercent) * 255.0 / 100.0 + 0.5 );
777 OSL_ASSERT( t == XPropertyListType::Color );
OUString AsRGBHexString() const
#define LINK(Instance, Class, Member)
std::unique_ptr< weld::CustomWeld > m_xValSetColorListWin
std::unique_ptr< weld::MetricSpinButton > m_xYcustom
virtual ~SvxColorTabPage() override
std::unique_ptr< weld::Button > m_xBtnWorkOn
std::unique_ptr< weld::SpinButton > m_xRcustom
sal_uInt8 GetAlpha() const
void SetAlpha(sal_uInt8 nAlpha)
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
void SetColorModel(ColorModel eModel)
std::unique_ptr< weld::MetricSpinButton > m_xKcustom
void SetBlue(sal_uInt8 nBlue)
void SetUserData(const OUString &rString)
std::unique_ptr< weld::Entry > m_xRpreset
void ChangeColor(const svx::NamedThemedColor &rNewColor, bool bUpdatePreset=true)
const LanguageTag & GetUILanguageTag() const
static std::shared_ptr< ConfigurationChanges > create()
#define VALUESET_ITEM_NOTFOUND
static SvxAbstractDialogFactory * Create()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
static const AllSettings & GetSettings()
std::unique_ptr< weld::MetricSpinButton > m_xMcustom
constexpr OUStringLiteral PERCENT(u"Percent")
std::unique_ptr< weld::Button > m_xMoreColors
svx::NamedThemedColor aCurrentColor
std::unique_ptr< weld::Widget > m_xRGBpreset
std::unique_ptr< weld::CustomWeld > m_xValSetRecentListWin
void SetThemeIndex(sal_Int16 nIndex)
virtual void FillUserData() override
SvxColorTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
std::unique_ptr< weld::Entry > m_xGpreset
std::unique_ptr< weld::Button > m_xBtnDelete
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
tools::Long GetRecentColorCount() const
void SetMode(svtools::ColorPickerMode eMode)
virtual VclPtr< AbstractSvxNameDialog > CreateSvxNameDialog(weld::Window *pParent, const OUString &rName, const OUString &rDesc)=0
static sal_uInt32 getColumnCount()
PaletteManager maPaletteManager
virtual bool FillItemSet(SfxItemSet *) override
SvxThemeColor & GetThemeColor()
short Execute(weld::Window *pParent)
void SetNewColorList(XColorListRef const &pColorList)
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
void SetExchangeSupport()
OUString SvxResId(TranslateId aId)
std::unique_ptr< SvxColorValueSet > m_xValSetRecentList
const OUString & GetUserData() const
sal_uInt16 PercentToColor_Impl(sal_uInt16 nPercent)
static void CmykToRgb_Impl(Color &rColor, const sal_uInt16 nKey)
static void GetThemeIndexLumModOff(sal_uInt16 nItemId, sal_Int16 &rThemeIndex, sal_Int16 &rLumMod, sal_Int16 &rLumOff)
std::unique_ptr< weld::Entry > m_xBpreset
sal_uInt8 GetBlue() const
XFillAttrSetItem aXFillAttr
std::unique_ptr< weld::Widget > m_xCMYKpreset
void SetNewColorList(XColorListRef const &pColTab)
sal_uInt16 ColorToPercent_Impl(sal_uInt16 nColor)
static XColorListRef AsColorList(rtl::Reference< XPropertyList > const &plist)
void SetColor(const Color &rColor)
OUString CuiResId(TranslateId aKey)
void SetColorList(const XColorListRef &pColList)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
std::vector< OUString > GetPaletteList()
std::unique_ptr< weld::ComboBox > m_xSelectPalette
void UpdateColorValues(bool bUpdatePreset=true)
virtual void Reset(const SfxItemSet *) override
const SfxItemSet & rOutAttrs
static sal_Int32 FindInCustomColors(std::u16string_view aColorName)
IMPL_STATIC_LINK_NOARG(SvxColorTabPage, OnMoreColorsClick, weld::Button &, void)
void SetRed(sal_uInt8 nRed)
std::unique_ptr< weld::HexColorControl > m_xHexpreset
std::unique_ptr< weld::Widget > m_xRGBcustom
std::unique_ptr< weld::Entry > m_xKpreset
void ReloadRecentColorSet(SvxColorValueSet &rColorSet)
std::unique_ptr< weld::HexColorControl > m_xHexcustom
void SetAttributes(const SfxItemSet &rItemSet)
std::unique_ptr< weld::SpinButton > m_xGcustom
std::unique_ptr< weld::RadioButton > m_xRbCMYK
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
std::unique_ptr< weld::Entry > m_xCpreset
const Color & GetColor() const
std::unique_ptr< weld::Button > m_xBtnAdd
sal_uInt8 GetGreen() const
SvxXRectPreview m_aCtlPreviewOld
constexpr TypedWhichId< XFillColorItem > XATTR_FILLCOLOR(XATTR_FILL_FIRST+1)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual void ActivatePage(const SfxItemSet &rSet) override
static void ConvertColorValues(Color &rColor, ColorModel eModell)
static OUString formatPercent(double dNumber, const LanguageTag &rLangTag)
#define WB_NO_DIRECTSELECT
std::unique_ptr< SvxColorValueSet > m_xValSetColorList
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
std::unique_ptr< weld::RadioButton > m_xRbRGB
void SetGreen(sal_uInt8 nGreen)
static XPropertyListRef CreatePropertyListFromURL(XPropertyListType t, std::u16string_view rUrl)
static void RgbToCmyk_Impl(Color &rColor, sal_uInt16 &rK)
void SetPropertyList(XPropertyListType t, const XPropertyListRef &xRef)
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, ValueSet *, pValSet, void)
sal_Int32 FindInPalette(const Color &rColor)
void ImpColorCountChanged()
std::unique_ptr< weld::Widget > m_xCMYKcustom
IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, weld::SpinButton &, void)
void AddRecentColor(const Color &rRecentColor, const OUString &rColorName, bool bFront=true)
std::unique_ptr< weld::Entry > m_xYpreset
std::unique_ptr< weld::MetricSpinButton > m_xCcustom
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
std::unique_ptr< weld::Entry > m_xMpreset
SvxXRectPreview m_aCtlPreviewNew
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
std::unique_ptr< weld::SpinButton > m_xBcustom