26 #include <strings.hrc>
35 #include <svx/strings.hrc>
36 #include <officecfg/Office/Common.hxx>
41 :
SfxTabPage(pPage, pController,
"cui/ui/colorpage.ui",
"ColorPage", &rInAttrs)
42 , rOutAttrs ( rInAttrs )
44 , pnColorListState( nullptr )
45 , aXFillAttr( rInAttrs.GetPool() )
49 , m_xValSetColorList(new
SvxColorValueSet(m_xBuilder->weld_scrolled_window(
"colorsetwin", true)))
51 , m_xSelectPalette(m_xBuilder->weld_combo_box(
"paletteselector"))
52 , m_xRbRGB(m_xBuilder->weld_radio_button(
"RGB"))
53 , m_xRbCMYK(m_xBuilder->weld_radio_button(
"CMYK"))
54 , m_xRGBcustom(m_xBuilder->weld_widget(
"rgbcustom"))
55 , m_xRGBpreset(m_xBuilder->weld_widget(
"rgbpreset"))
56 , m_xRpreset(m_xBuilder->weld_entry(
"R_preset"))
57 , m_xGpreset(m_xBuilder->weld_entry(
"G_preset"))
58 , m_xBpreset(m_xBuilder->weld_entry(
"B_preset"))
59 , m_xRcustom(m_xBuilder->weld_spin_button(
"R_custom"))
60 , m_xGcustom(m_xBuilder->weld_spin_button(
"G_custom"))
61 , m_xBcustom(m_xBuilder->weld_spin_button(
"B_custom"))
62 , m_xHexpreset(new
weld::HexColorControl(m_xBuilder->weld_entry(
"hex_preset")))
63 , m_xHexcustom(new
weld::HexColorControl(m_xBuilder->weld_entry(
"hex_custom")))
64 , m_xCMYKcustom(m_xBuilder->weld_widget(
"cmykcustom"))
65 , m_xCMYKpreset(m_xBuilder->weld_widget(
"cmykpreset"))
66 , m_xCpreset(m_xBuilder->weld_entry(
"C_preset"))
67 , m_xYpreset(m_xBuilder->weld_entry(
"Y_preset"))
68 , m_xMpreset(m_xBuilder->weld_entry(
"M_preset"))
69 , m_xKpreset(m_xBuilder->weld_entry(
"K_preset"))
70 , m_xCcustom(m_xBuilder->weld_metric_spin_button(
"C_custom",
FieldUnit::
PERCENT))
71 , m_xYcustom(m_xBuilder->weld_metric_spin_button(
"Y_custom",
FieldUnit::
PERCENT))
72 , m_xMcustom(m_xBuilder->weld_metric_spin_button(
"M_custom",
FieldUnit::
PERCENT))
73 , m_xKcustom(m_xBuilder->weld_metric_spin_button(
"K_custom",
FieldUnit::
PERCENT))
74 , m_xBtnAdd(m_xBuilder->weld_button(
"add"))
75 , m_xBtnDelete(m_xBuilder->weld_button(
"delete"))
76 , m_xBtnWorkOn(m_xBuilder->weld_button(
"edit"))
77 , m_xCtlPreviewOld(new
weld::CustomWeld(*m_xBuilder,
"oldpreview", m_aCtlPreviewOld))
78 , m_xCtlPreviewNew(new
weld::CustomWeld(*m_xBuilder,
"newpreview", m_aCtlPreviewNew))
79 , m_xValSetColorListWin(new
weld::CustomWeld(*m_xBuilder,
"colorset", *m_xValSetColorList))
80 , m_xValSetRecentListWin(new
weld::CustomWeld(*m_xBuilder,
"recentcolorset", *m_xValSetRecentList))
111 m_xCcustom->connect_value_changed(aMetricSpinLink);
112 m_xYcustom->connect_value_changed(aMetricSpinLink);
113 m_xMcustom->connect_value_changed(aMetricSpinLink);
114 m_xKcustom->connect_value_changed(aMetricSpinLink);
166 for (
auto const& palette : aPaletteList)
170 OUString aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() );
219 return DeactivateRC::LeavePage;
248 if ( nState >= SfxItemState::DEFAULT )
252 aNewColor = aColorItem.GetColorValue();
268 return std::make_unique<SvxColorTabPage>(pPage, pController, *
rOutAttrs);
275 aCurrentColor =
Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())),
276 static_cast<sal_uInt8>(PercentToColor_Impl(m_xGcustom->get_value())),
277 static_cast<sal_uInt8>(PercentToColor_Impl(m_xBcustom->get_value())));
281 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
283 m_aCtlPreviewNew.Invalidate();
289 aCurrentColor =
Color(
ColorTransparency, static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))),
290 static_cast<sal_uInt8>(PercentToColor_Impl(m_xCcustom->get_value(FieldUnit::NONE))),
291 static_cast<sal_uInt8>(PercentToColor_Impl(m_xYcustom->get_value(FieldUnit::NONE))),
292 static_cast<sal_uInt8>(PercentToColor_Impl(m_xMcustom->get_value(FieldUnit::NONE))));
296 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
298 m_aCtlPreviewNew.Invalidate();
303 aCurrentColor = m_xHexcustom->GetColor();
307 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
309 m_aCtlPreviewNew.Invalidate();
314 OUString aNewName(
SvxResId( RID_SVXSTR_COLOR ) );
315 OUString aDesc(
CuiResId( RID_SVXSTR_DESC_COLOR ) );
319 bool bValidColorName =
false;
321 while (!bValidColorName)
323 aName = aNewName +
" " + OUString::number( j++ );
324 bValidColorName = (FindInCustomColors(aName) == -1);
329 sal_uInt16 nError = 1;
331 while (pDlg->Execute() ==
RET_OK)
333 pDlg->GetName( aName );
335 bValidColorName = (FindInCustomColors(aName) == -1);
343 std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog(
"DuplicateNameDialog"));
344 if (xWarnBox->run() !=
RET_OK)
348 pDlg.disposeAndClear();
352 m_xSelectPalette->set_active(0);
353 SelectPaletteLBHdl(*m_xSelectPalette);
355 css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
356 css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
357 sal_Int32 nSize = aCustomColorList.getLength();
358 aCustomColorList.realloc( nSize + 1 );
359 aCustomColorNameList.realloc( nSize + 1 );
360 aCustomColorList[nSize] = sal_Int32(aCurrentColor);
361 aCustomColorNameList[nSize] = aName;
362 officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
363 officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
365 sal_uInt16
nId = m_xValSetColorList->GetItemId(nSize - 1);
366 m_xValSetColorList->InsertItem( nId + 1 , aCurrentColor, aName );
367 m_xValSetColorList->SelectItem( nId + 1 );
368 m_xBtnDelete->set_sensitive(
false);
369 m_xBtnDelete->set_tooltip_text(
SvxResId(RID_SVXSTR_DELETEUSERCOLOR2) );
370 ImpColorCountChanged();
386 aCurrentColor = aPreviewColor;
387 UpdateColorValues(
false );
391 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
393 m_aCtlPreviewNew.Invalidate();
399 sal_uInt16
nId = m_xValSetColorList->GetSelectedItemId();
400 size_t nPos = m_xValSetColorList->GetSelectItemPos();
405 css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
406 css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
407 sal_Int32 nSize = aCustomColorList.getLength() - 1;
411 aCustomColorNameList[
nIndex] = aCustomColorNameList[
nIndex+1];
413 aCustomColorList.realloc(nSize);
414 aCustomColorNameList.realloc(nSize);
415 officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch);
416 officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch);
418 m_xValSetColorList->RemoveItem(nId);
419 if (m_xValSetColorList->GetItemCount() != 0)
421 nId = m_xValSetColorList->GetItemId(0);
422 m_xValSetColorList->SelectItem(nId);
423 SelectValSetHdl_Impl(m_xValSetColorList.get());
427 m_xBtnDelete->set_sensitive(
false);
428 m_xBtnDelete->set_tooltip_text(
SvxResId(RID_SVXSTR_DELETEUSERCOLOR2) );
434 m_xValSetColorList->Clear();
435 sal_Int32
nPos = m_xSelectPalette->get_active();
436 maPaletteManager.SetPalette( nPos );
437 maPaletteManager.ReloadColorSet(*m_xValSetColorList);
439 if(nPos != maPaletteManager.GetPaletteCount() - 1 && nPos != 0)
443 XPropertyListType::Color, maPaletteManager.GetSelectedPalettePath()));
444 pList->SetName(maPaletteManager.GetPaletteName());
457 *pnColorListState |= ChangeType::CHANGED;
463 m_xBtnDelete->set_sensitive(
false);
464 m_xBtnDelete->set_tooltip_text(
SvxResId(RID_SVXSTR_DELETEUSERCOLOR1) );
467 m_xValSetColorList->Resize();
472 sal_Int32
nPos = pValSet->GetSelectedItemId();
476 Color aColor = pValSet->GetItemColor( nPos );
479 m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
480 m_aCtlPreviewNew.Invalidate();
481 ChangeColor(aColor,
false);
483 if (pValSet == m_xValSetColorList.get())
485 m_xValSetRecentList->SetNoSelection();
486 if (m_xSelectPalette->get_active() == 0 && m_xValSetColorList->GetSelectedItemId() != 0)
488 m_xBtnDelete->set_sensitive(
true);
489 m_xBtnDelete->set_tooltip_text(
"");
493 m_xBtnDelete->set_sensitive(
false);
494 m_xBtnDelete->set_tooltip_text(
SvxResId(RID_SVXSTR_DELETEUSERCOLOR1) );
497 if (pValSet == m_xValSetRecentList.get())
499 m_xValSetColorList->SetNoSelection();
500 m_xBtnDelete->set_sensitive(
false);
501 m_xBtnDelete->set_tooltip_text(
SvxResId(RID_SVXSTR_DELETEUSERCOLOR2) );
520 rColor.
SetAlpha (255 - static_cast<sal_uInt8>(nK));
528 if (m_xRbRGB->get_active())
530 else if (m_xRbCMYK->get_active())
625 css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
627 bool bValidColorName =
true;
632 if(aColorName == aCustomColorNameList[
i])
635 bValidColorName =
false;
653 sal_uInt16
const nColor1 = 255 - rColor.
GetRed();
654 sal_uInt16
const nColor2 = 255 - rColor.
GetGreen();
655 sal_uInt16
const nColor3 = 255 - rColor.
GetBlue();
657 rK = std::min( std::min( nColor1, nColor2 ), nColor3 );
659 rColor.
SetRed( sal::static_int_cast< sal_uInt8 >( nColor1 - rK ) );
660 rColor.
SetGreen( sal::static_int_cast< sal_uInt8 >( nColor2 - rK ) );
661 rColor.
SetBlue( sal::static_int_cast< sal_uInt8 >( nColor3 - rK ) );
671 lTemp = 255 - ( rColor.
GetRed() + nK );
675 rColor.
SetRed( static_cast<sal_uInt8>(lTemp) );
677 lTemp = 255 - ( rColor.
GetGreen() + nK );
681 rColor.
SetGreen( static_cast<sal_uInt8>(lTemp) );
683 lTemp = 255 - ( rColor.
GetBlue() + nK );
687 rColor.
SetBlue( static_cast<sal_uInt8>(lTemp) );
702 nValue =
static_cast<sal_uInt16
>(
static_cast<double>(nColor) * 100.0 / 255.0 + 0.5 );
721 nValue =
static_cast<sal_uInt16
>(
static_cast<double>(nPercent) * 255.0 / 100.0 + 0.5 );
738 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)
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
const LanguageTag & GetUILanguageTag() const
#define VALUESET_ITEM_NOTFOUND
static SvxAbstractDialogFactory * Create()
static const AllSettings & GetSettings()
std::unique_ptr< weld::MetricSpinButton > m_xMcustom
constexpr OUStringLiteral PERCENT(u"Percent")
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false)
std::unique_ptr< weld::Widget > m_xRGBpreset
std::unique_ptr< weld::CustomWeld > m_xValSetRecentListWin
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
OUString SvxResId(const char *pId)
short Execute(weld::Window *pParent)
void SetNewColorList(XColorListRef const &pColorList)
void SetExchangeSupport()
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 std::shared_ptr< ConfigurationChanges > create(css::uno::Reference< css::uno::XComponentContext > const &context=comphelper::getProcessComponentContext())
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)
void ChangeColor(const Color &rNewColor, bool bUpdatePreset=true)
sal_uInt16 ColorToPercent_Impl(sal_uInt16 nColor)
static XColorListRef AsColorList(rtl::Reference< XPropertyList > const &plist)
void SetColor(const Color &rColor)
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)
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 *)
OUString CuiResId(const char *pKey)
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)
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 void RgbToCmyk_Impl(Color &rColor, sal_uInt16 &rK)
void SetPropertyList(XPropertyListType t, const XPropertyListRef &xRef)
Reference< XComponentContext > getProcessComponentContext()
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 XPropertyListRef CreatePropertyListFromURL(XPropertyListType t, const OUString &rUrl)
std::unique_ptr< weld::SpinButton > m_xBcustom