1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <i18nutil/unicode.hxx>
22 #include <tools/urlobj.hxx>
23 #include <unotools/pathoptions.hxx>
24 #include <sfx2/app.hxx>
25 #include <sfx2/module.hxx>
26 #include <sfx2/objsh.hxx>
27 #include <sfx2/viewsh.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <svtools/colrdlg.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/weld.hxx>
33 #include <sfx2/filedlghelper.hxx>
34 #include <svx/ofaitem.hxx>
35 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
37 #include <strings.hrc>
38 #include <svx/xflclit.hxx>
39 #include <svx/xpool.hxx>
40 #include <svx/xtable.hxx>
41 #include <svx/drawitem.hxx>
42 #include <cuitabarea.hxx>
43 #include <defdlgname.hxx>
44 #include <dlgname.hxx>
45 #include <svx/svxdlg.hxx>
46 #include <dialmgr.hxx>
47 #include <cuitabline.hxx>
48 #include <svx/dialmgr.hxx>
49 #include <svx/dialogs.hrc>
50 #include <svx/strings.hrc>
51 #include <osl/file.hxx>
52 #include <svx/Palette.hxx>
53 #include <cppu/unotype.hxx>
54 #include <officecfg/Office/Common.hxx>
56 using namespace com::sun::star
;
58 SvxColorTabPage::SvxColorTabPage(TabPageParent pParent
, const SfxItemSet
& rInAttrs
)
59 : SfxTabPage(pParent
, "cui/ui/colorpage.ui", "ColorPage", &rInAttrs
)
60 , mpTopDlg( GetParentDialog() )
61 , rOutAttrs ( rInAttrs
)
62 // All the horrific pointers we store and should not
63 , pnColorListState( nullptr )
64 , aXFillAttr( rInAttrs
.GetPool() )
65 , rXFSet( aXFillAttr
.GetItemSet() )
66 , eCM( ColorModel::RGB
)
67 , m_context(comphelper::getProcessComponentContext())
68 , m_xValSetColorList(new ColorValueSet(m_xBuilder
->weld_scrolled_window("colorsetwin")))
69 , m_xValSetRecentList(new ColorValueSet(nullptr))
70 , m_xSelectPalette(m_xBuilder
->weld_combo_box("paletteselector"))
71 , m_xRbRGB(m_xBuilder
->weld_radio_button("RGB"))
72 , m_xRbCMYK(m_xBuilder
->weld_radio_button("CMYK"))
73 , m_xRGBcustom(m_xBuilder
->weld_widget("rgbcustom"))
74 , m_xRGBpreset(m_xBuilder
->weld_widget("rgbpreset"))
75 , m_xRpreset(m_xBuilder
->weld_entry("R_preset"))
76 , m_xGpreset(m_xBuilder
->weld_entry("G_preset"))
77 , m_xBpreset(m_xBuilder
->weld_entry("B_preset"))
78 , m_xRcustom(m_xBuilder
->weld_spin_button("R_custom"))
79 , m_xGcustom(m_xBuilder
->weld_spin_button("G_custom"))
80 , m_xBcustom(m_xBuilder
->weld_spin_button("B_custom"))
81 , m_xHexpreset(new weld::HexColorControl(m_xBuilder
->weld_entry("hex_preset")))
82 , m_xHexcustom(new weld::HexColorControl(m_xBuilder
->weld_entry("hex_custom")))
83 , m_xCMYKcustom(m_xBuilder
->weld_widget("cmykcustom"))
84 , m_xCMYKpreset(m_xBuilder
->weld_widget("cmykpreset"))
85 , m_xCpreset(m_xBuilder
->weld_entry("C_preset"))
86 , m_xYpreset(m_xBuilder
->weld_entry("Y_preset"))
87 , m_xMpreset(m_xBuilder
->weld_entry("M_preset"))
88 , m_xKpreset(m_xBuilder
->weld_entry("K_preset"))
89 , m_xCcustom(m_xBuilder
->weld_metric_spin_button("C_custom", FieldUnit::PERCENT
))
90 , m_xYcustom(m_xBuilder
->weld_metric_spin_button("Y_custom", FieldUnit::PERCENT
))
91 , m_xMcustom(m_xBuilder
->weld_metric_spin_button("M_custom", FieldUnit::PERCENT
))
92 , m_xKcustom(m_xBuilder
->weld_metric_spin_button("K_custom", FieldUnit::PERCENT
))
93 , m_xBtnAdd(m_xBuilder
->weld_button("add"))
94 , m_xBtnDelete(m_xBuilder
->weld_button("delete"))
95 , m_xBtnWorkOn(m_xBuilder
->weld_button("edit"))
96 , m_xCtlPreviewOld(new weld::CustomWeld(*m_xBuilder
, "oldpreview", m_aCtlPreviewOld
))
97 , m_xCtlPreviewNew(new weld::CustomWeld(*m_xBuilder
, "newpreview", m_aCtlPreviewNew
))
98 , m_xValSetColorListWin(new weld::CustomWeld(*m_xBuilder
, "colorset", *m_xValSetColorList
))
99 , m_xValSetRecentListWin(new weld::CustomWeld(*m_xBuilder
, "recentcolorset", *m_xValSetRecentList
))
101 Size aSize
= LogicToPixel(Size(100 , 80), MapMode(MapUnit::MapAppFont
));
102 m_xValSetColorList
->set_size_request(aSize
.Width(), aSize
.Height());
103 aSize
= LogicToPixel(Size(34 , 25), MapMode(MapUnit::MapAppFont
));
104 m_aCtlPreviewOld
.set_size_request(aSize
.Width(), aSize
.Height());
105 m_aCtlPreviewNew
.set_size_request(aSize
.Width(), aSize
.Height());
106 // this page needs ExchangeSupport
107 SetExchangeSupport();
109 // setting the output device
110 rXFSet
.Put( XFillStyleItem(drawing::FillStyle_SOLID
) );
111 rXFSet
.Put( XFillColorItem(OUString(), COL_BLACK
) );
112 m_aCtlPreviewOld
.SetAttributes( aXFillAttr
.GetItemSet() );
113 m_aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
116 m_xSelectPalette
->connect_changed(LINK(this, SvxColorTabPage
, SelectPaletteLBHdl
));
117 Link
<SvtValueSet
*, void> aValSelectLink
= LINK(this, SvxColorTabPage
, SelectValSetHdl_Impl
);
118 m_xValSetColorList
->SetSelectHdl(aValSelectLink
);
119 m_xValSetRecentList
->SetSelectHdl(aValSelectLink
);
121 Link
<weld::SpinButton
&,void> aSpinLink
= LINK(this, SvxColorTabPage
, SpinValueHdl_Impl
);
122 m_xRcustom
->connect_value_changed(aSpinLink
);
123 m_xGcustom
->connect_value_changed(aSpinLink
);
124 m_xBcustom
->connect_value_changed(aSpinLink
);
125 Link
<weld::Entry
&,void> aEntryLink
= LINK(this, SvxColorTabPage
, ModifiedHdl_Impl
);
126 m_xHexcustom
->connect_changed(aEntryLink
);
127 Link
<weld::MetricSpinButton
&,void> aMetricSpinLink
= LINK(this, SvxColorTabPage
, MetricSpinValueHdl_Impl
);
128 m_xCcustom
->connect_value_changed(aMetricSpinLink
);
129 m_xYcustom
->connect_value_changed(aMetricSpinLink
);
130 m_xMcustom
->connect_value_changed(aMetricSpinLink
);
131 m_xKcustom
->connect_value_changed(aMetricSpinLink
);
133 Link
<weld::ToggleButton
&,void> aLink2
= LINK( this, SvxColorTabPage
, SelectColorModeHdl_Impl
);
134 m_xRbRGB
->connect_toggled(aLink2
);
135 m_xRbCMYK
->connect_toggled(aLink2
);
136 SetColorModel( eCM
);
139 m_xBtnAdd
->connect_clicked( LINK( this, SvxColorTabPage
, ClickAddHdl_Impl
) );
140 m_xBtnWorkOn
->connect_clicked( LINK( this, SvxColorTabPage
, ClickWorkOnHdl_Impl
) );
141 m_xBtnDelete
->connect_clicked( LINK( this, SvxColorTabPage
, ClickDeleteHdl_Impl
) );
142 // disable modify buttons
143 // Color palettes can't be modified
144 m_xBtnDelete
->set_sensitive(false);
146 // disable preset color values
147 m_xRGBpreset
->set_sensitive(false);
148 m_xCMYKpreset
->set_sensitive(false);
151 m_xValSetColorList
->SetStyle(m_xValSetColorList
->GetStyle() | WB_ITEMBORDER
);
152 m_xValSetColorList
->Show();
154 m_xValSetRecentList
->SetStyle(m_xValSetRecentList
->GetStyle() | WB_ITEMBORDER
);
155 m_xValSetRecentList
->Show();
157 maPaletteManager
.ReloadRecentColorSet(*m_xValSetRecentList
);
158 aSize
= m_xValSetRecentList
->layoutAllVisible(maPaletteManager
.GetRecentColorCount());
159 m_xValSetRecentList
->set_size_request(aSize
.Width(), aSize
.Height());
162 SvxColorTabPage::~SvxColorTabPage()
167 void SvxColorTabPage::dispose()
170 m_xValSetRecentListWin
.reset();
171 m_xValSetRecentList
.reset();
172 m_xValSetColorListWin
.reset();
173 m_xValSetColorList
.reset();
174 SfxTabPage::dispose();
177 void SvxColorTabPage::ImpColorCountChanged()
179 if (!pColorList
.is())
181 m_xValSetColorList
->SetColCount(SvxColorValueSet::getColumnCount());
182 m_xValSetRecentList
->SetColCount(SvxColorValueSet::getColumnCount());
185 void SvxColorTabPage::FillPaletteLB()
187 m_xSelectPalette
->clear();
188 std::vector
<OUString
> aPaletteList
= maPaletteManager
.GetPaletteList();
189 for (auto const& palette
: aPaletteList
)
191 m_xSelectPalette
->append_text(palette
);
193 OUString
aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() );
194 m_xSelectPalette
->set_active_text(aPaletteName
);
195 if (m_xSelectPalette
->get_active() != -1)
197 SelectPaletteLBHdl(*m_xSelectPalette
);
201 void SvxColorTabPage::Construct()
206 ImpColorCountChanged();
210 void SvxColorTabPage::ActivatePage( const SfxItemSet
& )
212 if( pColorList
.is() )
214 const SfxPoolItem
* pPoolItem
= nullptr;
215 if( SfxItemState::SET
== rOutAttrs
.GetItemState( GetWhich( XATTR_FILLCOLOR
), true, &pPoolItem
) )
217 SetColorModel( ColorModel::RGB
);
220 const Color aColor
= static_cast<const XFillColorItem
*>(pPoolItem
)->GetColorValue();
221 ChangeColor( aColor
);
222 sal_Int32 nPos
= FindInPalette( aColor
);
225 m_xValSetColorList
->SelectItem(m_xValSetColorList
->GetItemId(nPos
));
226 // else search in other palettes?
230 m_aCtlPreviewOld
.SetAttributes(aXFillAttr
.GetItemSet());
231 m_aCtlPreviewOld
.Invalidate();
233 SelectValSetHdl_Impl(m_xValSetColorList
.get());
237 DeactivateRC
SvxColorTabPage::DeactivatePage( SfxItemSet
* _pSet
)
240 FillItemSet( _pSet
);
242 return DeactivateRC::LeavePage
;
245 bool SvxColorTabPage::FillItemSet( SfxItemSet
* rSet
)
247 Color aColor
= m_xValSetColorList
->GetItemColor( m_xValSetColorList
->GetSelectedItemId() );
249 if ( aCurrentColor
== aColor
)
250 sColorName
= m_xValSetColorList
->GetItemText( m_xValSetColorList
->GetSelectedItemId() );
252 sColorName
= "#" + aCurrentColor
.AsRGBHexString().toAsciiUpperCase();
253 maPaletteManager
.AddRecentColor( aCurrentColor
, sColorName
);
254 rSet
->Put( XFillColorItem( sColorName
, aCurrentColor
) );
255 rSet
->Put( XFillStyleItem( drawing::FillStyle_SOLID
) );
259 void SvxColorTabPage::UpdateModified()
261 bool bEnable
= pColorList
.is() && pColorList
->Count();
262 m_xBtnWorkOn
->set_sensitive(bEnable
);
265 void SvxColorTabPage::Reset( const SfxItemSet
* rSet
)
267 SfxItemState nState
= rSet
->GetItemState( XATTR_FILLCOLOR
);
271 if ( nState
>= SfxItemState::DEFAULT
)
273 XFillColorItem
aColorItem( rSet
->Get( XATTR_FILLCOLOR
) );
274 aPreviousColor
= aColorItem
.GetColorValue();
275 aNewColor
= aColorItem
.GetColorValue();
279 OUString aStr
= GetUserData();
280 eCM
= static_cast<ColorModel
>(aStr
.toInt32());
281 SetColorModel( eCM
);
284 ChangeColor(aNewColor
);
289 VclPtr
<SfxTabPage
> SvxColorTabPage::Create(TabPageParent pParent
, const SfxItemSet
* rOutAttrs
)
291 return VclPtr
<SvxColorTabPage
>::Create(pParent
, *rOutAttrs
);
294 // is called when the content of the MtrFields is changed for color values
295 IMPL_LINK_NOARG(SvxColorTabPage
, SpinValueHdl_Impl
, weld::SpinButton
&, void)
297 // read current MtrFields, if cmyk, then k-value as transparency
298 aCurrentColor
= Color(static_cast<sal_uInt8
>(PercentToColor_Impl(m_xRcustom
->get_value())),
299 static_cast<sal_uInt8
>(PercentToColor_Impl(m_xGcustom
->get_value())),
300 static_cast<sal_uInt8
>(PercentToColor_Impl(m_xBcustom
->get_value())));
303 rXFSet
.Put( XFillColorItem( OUString(), aCurrentColor
) );
304 m_aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
306 m_aCtlPreviewNew
.Invalidate();
309 IMPL_LINK_NOARG(SvxColorTabPage
, MetricSpinValueHdl_Impl
, weld::MetricSpinButton
&, void)
311 // read current MtrFields, if cmyk, then k-value as transparency
312 aCurrentColor
= Color(static_cast<sal_uInt8
>(PercentToColor_Impl(m_xKcustom
->get_value(FieldUnit::NONE
))),
313 static_cast<sal_uInt8
>(PercentToColor_Impl(m_xCcustom
->get_value(FieldUnit::NONE
))),
314 static_cast<sal_uInt8
>(PercentToColor_Impl(m_xYcustom
->get_value(FieldUnit::NONE
))),
315 static_cast<sal_uInt8
>(PercentToColor_Impl(m_xMcustom
->get_value(FieldUnit::NONE
))));
316 ConvertColorValues (aCurrentColor
, ColorModel::RGB
);
318 rXFSet
.Put( XFillColorItem( OUString(), aCurrentColor
) );
319 m_aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
321 m_aCtlPreviewNew
.Invalidate();
324 IMPL_LINK_NOARG(SvxColorTabPage
, ModifiedHdl_Impl
, weld::Entry
&, void)
326 aCurrentColor
= m_xHexcustom
->GetColor();
329 rXFSet
.Put( XFillColorItem( OUString(), aCurrentColor
) );
330 m_aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
332 m_aCtlPreviewNew
.Invalidate();
335 IMPL_LINK_NOARG(SvxColorTabPage
, ClickAddHdl_Impl
, weld::Button
&, void)
337 OUString
aNewName( SvxResId( RID_SVXSTR_COLOR
) );
338 OUString
aDesc( CuiResId( RID_SVXSTR_DESC_COLOR
) );
342 bool bValidColorName
= false;
343 // check if name is already existing
344 while (!bValidColorName
)
346 aName
= aNewName
+ " " + OUString::number( j
++ );
347 bValidColorName
= (FindInCustomColors(aName
) == LISTBOX_ENTRY_NOTFOUND
);
350 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
351 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg(pFact
->CreateSvxNameDialog(GetDialogFrameWeld(), aName
, aDesc
));
352 sal_uInt16 nError
= 1;
354 while (pDlg
->Execute() == RET_OK
)
356 pDlg
->GetName( aName
);
358 bValidColorName
= (FindInCustomColors(aName
) == LISTBOX_ENTRY_NOTFOUND
);
365 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
366 std::unique_ptr
<weld::MessageDialog
> xWarnBox(xBuilder
->weld_message_dialog("DuplicateNameDialog"));
367 if (xWarnBox
->run() != RET_OK
)
371 pDlg
.disposeAndClear();
375 m_xSelectPalette
->set_active(0);
376 SelectPaletteLBHdl(*m_xSelectPalette
);
377 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(comphelper::ConfigurationChanges::create(m_context
));
378 css::uno::Sequence
< sal_Int32
> aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
379 css::uno::Sequence
< OUString
> aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
380 sal_Int32 nSize
= aCustomColorList
.getLength();
381 aCustomColorList
.realloc( nSize
+ 1 );
382 aCustomColorNameList
.realloc( nSize
+ 1 );
383 aCustomColorList
[nSize
] = sal_Int32(aCurrentColor
);
384 aCustomColorNameList
[nSize
] = aName
;
385 officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList
, batch
);
386 officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList
, batch
);
388 sal_uInt16 nId
= m_xValSetColorList
->GetItemId(nSize
- 1);
389 m_xValSetColorList
->InsertItem( nId
+ 1 , aCurrentColor
, aName
);
390 m_xValSetColorList
->SelectItem( nId
+ 1 );
391 m_xBtnDelete
->set_sensitive(false);
392 ImpColorCountChanged();
398 IMPL_LINK_NOARG(SvxColorTabPage
, ClickWorkOnHdl_Impl
, weld::Button
&, void)
400 SvColorDialog aColorDlg
;
402 aColorDlg
.SetColor (aCurrentColor
);
403 aColorDlg
.SetMode( svtools::ColorPickerMode::Modify
);
405 if (aColorDlg
.Execute(GetDialogFrameWeld()) == RET_OK
)
407 Color aPreviewColor
= aColorDlg
.GetColor();
408 aCurrentColor
= aPreviewColor
;
409 UpdateColorValues( false );
410 // fill ItemSet and pass it on to XOut
411 rXFSet
.Put( XFillColorItem( OUString(), aPreviewColor
) );
412 //m_aCtlPreviewOld.SetAttributes( aXFillAttr );
413 m_aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
415 m_aCtlPreviewNew
.Invalidate();
419 IMPL_LINK_NOARG(SvxColorTabPage
, ClickDeleteHdl_Impl
, weld::Button
&, void)
421 sal_uInt16 nId
= m_xValSetColorList
->GetSelectedItemId();
422 size_t nPos
= m_xValSetColorList
->GetSelectItemPos();
423 if (m_xSelectPalette
->get_active() == 0 && nPos
!= VALUESET_ITEM_NOTFOUND
)
425 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(comphelper::ConfigurationChanges::create(m_context
));
426 css::uno::Sequence
< sal_Int32
> aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get());
427 css::uno::Sequence
< OUString
> aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
428 sal_Int32 nSize
= aCustomColorList
.getLength() - 1;
429 for(sal_Int32 nIndex
= static_cast<sal_Int32
>(nPos
);nIndex
< nSize
;nIndex
++)
431 aCustomColorList
[nIndex
] = aCustomColorList
[nIndex
+1];
432 aCustomColorNameList
[nIndex
] = aCustomColorNameList
[nIndex
+1];
434 aCustomColorList
.realloc(nSize
);
435 aCustomColorNameList
.realloc(nSize
);
436 officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList
, batch
);
437 officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList
, batch
);
439 m_xValSetColorList
->RemoveItem(nId
);
440 if (m_xValSetColorList
->GetItemCount() != 0)
442 nId
= m_xValSetColorList
->GetItemId(0);
443 m_xValSetColorList
->SelectItem(nId
);
444 SelectValSetHdl_Impl(m_xValSetColorList
.get());
447 m_xBtnDelete
->set_sensitive(false);
451 IMPL_LINK_NOARG(SvxColorTabPage
, SelectPaletteLBHdl
, weld::ComboBox
&, void)
453 m_xValSetColorList
->Clear();
454 sal_Int32 nPos
= m_xSelectPalette
->get_active();
455 maPaletteManager
.SetPalette( nPos
);
456 maPaletteManager
.ReloadColorSet(*m_xValSetColorList
);
458 if(nPos
!= maPaletteManager
.GetPaletteCount() - 1 && nPos
!= 0)
460 XColorListRef pList
= XPropertyList::AsColorList(
461 XPropertyList::CreatePropertyListFromURL(
462 XPropertyListType::Color
, maPaletteManager
.GetSelectedPalettePath()));
463 pList
->SetName(maPaletteManager
.GetPaletteName());
466 SvxAreaTabDialog
* pArea
= dynamic_cast< SvxAreaTabDialog
* >( mpTopDlg
.get() );
467 SvxLineTabDialog
* pLine
= dynamic_cast< SvxLineTabDialog
* >( mpTopDlg
.get() );
470 pArea
->SetNewColorList(pList
);
472 pLine
->SetNewColorList(pList
);
475 *pnColorListState
|= ChangeType::CHANGED
;
476 *pnColorListState
&= ~ChangeType::MODIFIED
;
480 m_xBtnDelete
->set_sensitive(false);
482 m_xValSetColorList
->Resize();
485 IMPL_LINK(SvxColorTabPage
, SelectValSetHdl_Impl
, SvtValueSet
*, pValSet
, void)
487 sal_Int32 nPos
= pValSet
->GetSelectedItemId();
490 Color aColor
= pValSet
->GetItemColor( nPos
);
492 rXFSet
.Put( XFillColorItem( OUString(), aColor
) );
493 m_aCtlPreviewNew
.SetAttributes( aXFillAttr
.GetItemSet() );
494 m_aCtlPreviewNew
.Invalidate();
495 ChangeColor(aColor
, false);
497 if (pValSet
== m_xValSetColorList
.get())
499 m_xValSetRecentList
->SetNoSelection();
500 if (m_xSelectPalette
->get_active() == 0 && m_xValSetColorList
->GetSelectedItemId() != 0)
501 m_xBtnDelete
->set_sensitive(true);
503 m_xBtnDelete
->set_sensitive(false);
505 if (pValSet
== m_xValSetRecentList
.get())
507 m_xValSetColorList
->SetNoSelection();
508 m_xBtnDelete
->set_sensitive(false);
513 void SvxColorTabPage::ConvertColorValues (Color
& rColor
, ColorModel eModell
)
517 case ColorModel::RGB
:
519 CmykToRgb_Impl (rColor
, static_cast<sal_uInt16
>(rColor
.GetTransparency()) );
520 rColor
.SetTransparency (sal_uInt8(0));
524 case ColorModel::CMYK
:
527 RgbToCmyk_Impl (rColor
, nK
);
528 rColor
.SetTransparency (static_cast<sal_uInt8
>(nK
));
534 IMPL_LINK_NOARG(SvxColorTabPage
, SelectColorModeHdl_Impl
, weld::ToggleButton
&, void)
536 if (m_xRbRGB
->get_active())
537 eCM
= ColorModel::RGB
;
538 else if (m_xRbCMYK
->get_active())
539 eCM
= ColorModel::CMYK
;
544 void SvxColorTabPage::ChangeColor(const Color
&rNewColor
, bool bUpdatePreset
)
546 aPreviousColor
= rNewColor
;
547 aCurrentColor
= rNewColor
;
548 UpdateColorValues( bUpdatePreset
);
549 // fill ItemSet and pass it on to XOut
550 rXFSet
.Put( XFillColorItem( OUString(), aCurrentColor
) );
551 m_aCtlPreviewNew
.SetAttributes(aXFillAttr
.GetItemSet());
552 m_aCtlPreviewNew
.Invalidate();
555 void SvxColorTabPage::SetColorModel( ColorModel eModel
)
557 if (eModel
== ColorModel::RGB
)
558 m_xRbRGB
->set_active(true);
559 else if (eModel
== ColorModel::CMYK
)
560 m_xRbCMYK
->set_active(true);
563 void SvxColorTabPage::ChangeColorModel()
567 case ColorModel::RGB
:
569 m_xRGBcustom
->show();
570 m_xRGBpreset
->show();
571 m_xCMYKcustom
->hide();
572 m_xCMYKpreset
->hide();
576 case ColorModel::CMYK
:
578 m_xCMYKcustom
->show();
579 m_xCMYKpreset
->show();
580 m_xRGBcustom
->hide();
581 m_xRGBpreset
->hide();
587 void SvxColorTabPage::UpdateColorValues( bool bUpdatePreset
)
589 if (eCM
!= ColorModel::RGB
)
591 ConvertColorValues (aPreviousColor
, eCM
);
592 ConvertColorValues (aCurrentColor
, eCM
);
594 m_xCcustom
->set_value( ColorToPercent_Impl( aCurrentColor
.GetRed() ), FieldUnit::PERCENT
);
595 m_xMcustom
->set_value( ColorToPercent_Impl( aCurrentColor
.GetBlue() ), FieldUnit::PERCENT
);
596 m_xYcustom
->set_value( ColorToPercent_Impl( aCurrentColor
.GetGreen() ), FieldUnit::PERCENT
);
597 m_xKcustom
->set_value( ColorToPercent_Impl( aCurrentColor
.GetTransparency() ), FieldUnit::PERCENT
);
601 m_xCpreset
->set_text(unicode::formatPercent(ColorToPercent_Impl(aPreviousColor
.GetRed()),
602 Application::GetSettings().GetUILanguageTag()));
603 m_xMpreset
->set_text(unicode::formatPercent(ColorToPercent_Impl(aPreviousColor
.GetBlue()),
604 Application::GetSettings().GetUILanguageTag()));
605 m_xYpreset
->set_text(unicode::formatPercent(ColorToPercent_Impl(aPreviousColor
.GetGreen()),
606 Application::GetSettings().GetUILanguageTag()));
607 m_xKpreset
->set_text(unicode::formatPercent(ColorToPercent_Impl(aPreviousColor
.GetTransparency()),
608 Application::GetSettings().GetUILanguageTag()));
611 ConvertColorValues (aPreviousColor
, ColorModel::RGB
);
612 ConvertColorValues (aCurrentColor
, ColorModel::RGB
);
616 m_xRcustom
->set_value( ColorToPercent_Impl( aCurrentColor
.GetRed() ) );
617 m_xGcustom
->set_value( ColorToPercent_Impl( aCurrentColor
.GetGreen() ) );
618 m_xBcustom
->set_value( ColorToPercent_Impl( aCurrentColor
.GetBlue() ) );
619 m_xHexcustom
->SetColor( aCurrentColor
);
623 m_xRpreset
->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor
.GetRed())));
624 m_xGpreset
->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor
.GetGreen())));
625 m_xBpreset
->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor
.GetBlue())));
626 m_xHexpreset
->SetColor( aPreviousColor
);
631 sal_Int32
SvxColorTabPage::FindInCustomColors(OUString
const & aColorName
)
633 css::uno::Sequence
< OUString
> aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get());
634 long nCount
= aCustomColorNameList
.getLength();
635 bool bValidColorName
= true;
636 sal_Int32 nPos
= LISTBOX_ENTRY_NOTFOUND
;
638 for(long i
= 0;i
< nCount
&& bValidColorName
;i
++)
640 if(aColorName
== aCustomColorNameList
[i
])
643 bValidColorName
= false;
649 sal_Int32
SvxColorTabPage::FindInPalette( const Color
& rColor
)
651 sal_Int32 nPos
= pColorList
->GetIndexOfColor( rColor
);
653 return ( nPos
== -1) ? LISTBOX_ENTRY_NOTFOUND
: nPos
;
656 // A RGB value is converted to a CMYK value - not in an ideal way as
657 // R is converted into C, G into M and B into Y. The K value is held in an
658 // extra variable. For further color models one should develop own
659 // classes which should contain the respective casts.
661 void SvxColorTabPage::RgbToCmyk_Impl( Color
& rColor
, sal_uInt16
& rK
)
663 sal_uInt16
const nColor1
= 255 - rColor
.GetRed();
664 sal_uInt16
const nColor2
= 255 - rColor
.GetGreen();
665 sal_uInt16
const nColor3
= 255 - rColor
.GetBlue();
667 rK
= std::min( std::min( nColor1
, nColor2
), nColor3
);
669 rColor
.SetRed( sal::static_int_cast
< sal_uInt8
>( nColor1
- rK
) );
670 rColor
.SetGreen( sal::static_int_cast
< sal_uInt8
>( nColor2
- rK
) );
671 rColor
.SetBlue( sal::static_int_cast
< sal_uInt8
>( nColor3
- rK
) );
675 // reverse case to RgbToCmyk_Impl (see above)
677 void SvxColorTabPage::CmykToRgb_Impl( Color
& rColor
, const sal_uInt16 nK
)
681 lTemp
= 255 - ( rColor
.GetRed() + nK
);
685 rColor
.SetRed( static_cast<sal_uInt8
>(lTemp
) );
687 lTemp
= 255 - ( rColor
.GetGreen() + nK
);
691 rColor
.SetGreen( static_cast<sal_uInt8
>(lTemp
) );
693 lTemp
= 255 - ( rColor
.GetBlue() + nK
);
697 rColor
.SetBlue( static_cast<sal_uInt8
>(lTemp
) );
701 sal_uInt16
SvxColorTabPage::ColorToPercent_Impl( sal_uInt16 nColor
)
703 sal_uInt16 nValue
= 0;
707 case ColorModel::RGB
:
711 case ColorModel::CMYK
:
712 nValue
= static_cast<sal_uInt16
>( static_cast<double>(nColor
) * 100.0 / 255.0 + 0.5 );
720 sal_uInt16
SvxColorTabPage::PercentToColor_Impl( sal_uInt16 nPercent
)
722 sal_uInt16 nValue
= 0;
726 case ColorModel::RGB
:
730 case ColorModel::CMYK
:
731 nValue
= static_cast<sal_uInt16
>( static_cast<double>(nPercent
) * 255.0 / 100.0 + 0.5 );
739 void SvxColorTabPage::FillUserData()
741 // the color model is saved in the Ini-file
742 SetUserData( OUString::number( static_cast<int>(eCM
) ) );
746 void SvxColorTabPage::SetPropertyList( XPropertyListType t
, const XPropertyListRef
&xRef
)
748 OSL_ASSERT( t
== XPropertyListType::Color
);
749 pColorList
= XColorListRef( static_cast<XColorList
*>(xRef
.get() ) );
752 void SvxColorTabPage::SetColorList( const XColorListRef
& pColList
)
754 SetPropertyList( XPropertyListType::Color
, XPropertyListRef( ( pColList
.get() ) ) );
757 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */