diff options
Diffstat (limited to 'cui/source/tabpages/tpcolor.cxx')
-rw-r--r-- | cui/source/tabpages/tpcolor.cxx | 133 |
1 files changed, 81 insertions, 52 deletions
diff --git a/cui/source/tabpages/tpcolor.cxx b/cui/source/tabpages/tpcolor.cxx index 5367fc2ed271..ccfe75232bef 100644 --- a/cui/source/tabpages/tpcolor.cxx +++ b/cui/source/tabpages/tpcolor.cxx @@ -36,6 +36,7 @@ #include <officecfg/Office/Common.hxx> #include <osl/diagnose.h> #include <comphelper/dispatchcommand.hxx> +#include <comphelper/lok.hxx> #include <comphelper/propertyvalue.hxx> using namespace com::sun::star; @@ -48,7 +49,6 @@ SvxColorTabPage::SvxColorTabPage(weld::Container* pPage, weld::DialogController* , aXFillAttr( rInAttrs.GetPool() ) , rXFSet( aXFillAttr.GetItemSet() ) , eCM( ColorModel::RGB ) - , m_context(comphelper::getProcessComponentContext()) , m_xValSetColorList(new SvxColorValueSet(m_xBuilder->weld_scrolled_window("colorsetwin", true))) , m_xValSetRecentList(new SvxColorValueSet(nullptr)) , m_xSelectPalette(m_xBuilder->weld_combo_box("paletteselector")) @@ -131,7 +131,6 @@ SvxColorTabPage::SvxColorTabPage(weld::Container* pPage, weld::DialogController* m_xBtnDelete->set_sensitive(false); m_xBtnDelete->set_tooltip_text( CuiResId(RID_CUISTR_DELETEUSERCOLOR1) ); - m_xMoreColors->set_from_icon_name("cmd/sc_additionsdialog.png"); m_xMoreColors->connect_clicked(LINK(this, SvxColorTabPage, OnMoreColorsClick)); // disable preset color values @@ -150,6 +149,12 @@ SvxColorTabPage::SvxColorTabPage(weld::Container* pPage, weld::DialogController* maPaletteManager.ReloadRecentColorSet(*m_xValSetRecentList); aSize = m_xValSetRecentList->layoutAllVisible(maPaletteManager.GetRecentColorCount()); m_xValSetRecentList->set_size_request(aSize.Width(), aSize.Height()); + + // it is not possible to install color palette extensions in Online or mobile apps + if(comphelper::LibreOfficeKit::isActive()) + { + m_xMoreColors->hide(); + } } SvxColorTabPage::~SvxColorTabPage() @@ -198,14 +203,15 @@ void SvxColorTabPage::ActivatePage( const SfxItemSet& ) if( !pColorList.is() ) return; - const SfxPoolItem* pPoolItem = nullptr; - if( SfxItemState::SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), true, &pPoolItem ) ) + if( const XFillColorItem* pFillColorItem = rOutAttrs.GetItemIfSet( GetWhich( XATTR_FILLCOLOR ) ) ) { SetColorModel( ColorModel::RGB ); ChangeColorModel(); - const Color aColor = static_cast<const XFillColorItem*>(pPoolItem)->GetColorValue(); - ChangeColor( aColor ); + const Color aColor = pFillColorItem->GetColorValue(); + NamedColor aNamedColor; + aNamedColor.m_aColor = aColor; + ChangeColor(aNamedColor); sal_Int32 nPos = FindInPalette( aColor ); if ( nPos != -1 ) @@ -232,13 +238,16 @@ bool SvxColorTabPage::FillItemSet( SfxItemSet* rSet ) { Color aColor = m_xValSetColorList->GetItemColor( m_xValSetColorList->GetSelectedItemId() ); OUString sColorName; - if ( aCurrentColor == aColor ) + if (m_aCurrentColor.m_aColor == aColor) sColorName = m_xValSetColorList->GetItemText( m_xValSetColorList->GetSelectedItemId() ); else - sColorName = "#" + aCurrentColor.AsRGBHexString().toAsciiUpperCase(); - maPaletteManager.AddRecentColor( aCurrentColor, sColorName ); - rSet->Put( XFillColorItem( sColorName, aCurrentColor ) ); - rSet->Put( XFillStyleItem( drawing::FillStyle_SOLID ) ); + sColorName = "#" + m_aCurrentColor.m_aColor.AsRGBHexString().toAsciiUpperCase(); + + maPaletteManager.AddRecentColor(m_aCurrentColor.m_aColor, sColorName); + XFillColorItem aColorItem(sColorName, m_aCurrentColor.m_aColor); + aColorItem.setComplexColor(m_aCurrentColor.getComplexColor()); + rSet->Put(aColorItem); + rSet->Put(XFillStyleItem(drawing::FillStyle_SOLID)); return true; } @@ -257,7 +266,7 @@ void SvxColorTabPage::Reset( const SfxItemSet* rSet ) if ( nState >= SfxItemState::DEFAULT ) { XFillColorItem aColorItem( rSet->Get( XATTR_FILLCOLOR ) ); - aPreviousColor = aColorItem.GetColorValue(); + m_aPreviousColor = aColorItem.GetColorValue(); aNewColor = aColorItem.GetColorValue(); } @@ -267,7 +276,9 @@ void SvxColorTabPage::Reset( const SfxItemSet* rSet ) SetColorModel( eCM ); ChangeColorModel(); - ChangeColor(aNewColor); + NamedColor aColor; + aColor.m_aColor = aNewColor; + ChangeColor(aColor); UpdateModified(); } @@ -281,12 +292,12 @@ std::unique_ptr<SfxTabPage> SvxColorTabPage::Create(weld::Container* pPage, weld IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, weld::SpinButton&, void) { // read current MtrFields, if cmyk, then k-value as transparency - aCurrentColor = Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())), + m_aCurrentColor.m_aColor = Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())), static_cast<sal_uInt8>(PercentToColor_Impl(m_xGcustom->get_value())), static_cast<sal_uInt8>(PercentToColor_Impl(m_xBcustom->get_value()))); UpdateColorValues(); - rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) ); + rXFSet.Put( XFillColorItem( OUString(), m_aCurrentColor.m_aColor ) ); m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); m_aCtlPreviewNew.Invalidate(); @@ -295,13 +306,13 @@ IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, weld::SpinButton&, void) IMPL_LINK_NOARG(SvxColorTabPage, MetricSpinValueHdl_Impl, weld::MetricSpinButton&, void) { // read current MtrFields, if cmyk, then k-value as transparency - aCurrentColor = Color(ColorTransparency, static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))), + m_aCurrentColor.m_aColor = Color(ColorTransparency, static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))), static_cast<sal_uInt8>(PercentToColor_Impl(m_xCcustom->get_value(FieldUnit::NONE))), static_cast<sal_uInt8>(PercentToColor_Impl(m_xYcustom->get_value(FieldUnit::NONE))), static_cast<sal_uInt8>(PercentToColor_Impl(m_xMcustom->get_value(FieldUnit::NONE)))); - ConvertColorValues (aCurrentColor, ColorModel::RGB); + ConvertColorValues (m_aCurrentColor.m_aColor, ColorModel::RGB); - rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) ); + rXFSet.Put( XFillColorItem( OUString(), m_aCurrentColor.m_aColor ) ); m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); m_aCtlPreviewNew.Invalidate(); @@ -309,10 +320,10 @@ IMPL_LINK_NOARG(SvxColorTabPage, MetricSpinValueHdl_Impl, weld::MetricSpinButton IMPL_LINK_NOARG(SvxColorTabPage, ModifiedHdl_Impl, weld::Entry&, void) { - aCurrentColor = m_xHexcustom->GetColor(); + m_aCurrentColor.m_aColor = m_xHexcustom->GetColor(); UpdateColorValues(); - rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) ); + rXFSet.Put( XFillColorItem( OUString(), m_aCurrentColor.m_aColor ) ); m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); m_aCtlPreviewNew.Invalidate(); @@ -339,7 +350,7 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl, weld::Button&, void) while (pDlg->Execute() == RET_OK) { - pDlg->GetName( aName ); + aName = pDlg->GetName(); bValidColorName = (FindInCustomColors(aName) == -1); if (bValidColorName) @@ -360,19 +371,19 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl, weld::Button&, void) { m_xSelectPalette->set_active(0); SelectPaletteLBHdl(*m_xSelectPalette); - std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context)); + std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create()); css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get()); css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get()); sal_Int32 nSize = aCustomColorList.getLength(); aCustomColorList.realloc( nSize + 1 ); aCustomColorNameList.realloc( nSize + 1 ); - aCustomColorList.getArray()[nSize] = sal_Int32(aCurrentColor); + aCustomColorList.getArray()[nSize] = sal_Int32(m_aCurrentColor.m_aColor); aCustomColorNameList.getArray()[nSize] = aName; officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch); officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch); batch->commit(); sal_uInt16 nId = m_xValSetColorList->GetItemId(nSize - 1); - m_xValSetColorList->InsertItem( nId + 1 , aCurrentColor, aName ); + m_xValSetColorList->InsertItem( nId + 1 , m_aCurrentColor.m_aColor, aName ); m_xValSetColorList->SelectItem( nId + 1 ); m_xBtnDelete->set_sensitive(false); m_xBtnDelete->set_tooltip_text( CuiResId(RID_CUISTR_DELETEUSERCOLOR2) ); @@ -386,13 +397,13 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickWorkOnHdl_Impl, weld::Button&, void) { SvColorDialog aColorDlg; - aColorDlg.SetColor (aCurrentColor); + aColorDlg.SetColor (m_aCurrentColor.m_aColor); aColorDlg.SetMode( svtools::ColorPickerMode::Modify ); if (aColorDlg.Execute(GetFrameWeld()) == RET_OK) { Color aPreviewColor = aColorDlg.GetColor(); - aCurrentColor = aPreviewColor; + m_aCurrentColor.m_aColor = aPreviewColor; UpdateColorValues( false ); // fill ItemSet and pass it on to XOut rXFSet.Put( XFillColorItem( OUString(), aPreviewColor ) ); @@ -410,7 +421,7 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickDeleteHdl_Impl, weld::Button&, void) if (m_xSelectPalette->get_active() != 0 || nPos == VALUESET_ITEM_NOTFOUND) return; - std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context)); + std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create()); css::uno::Sequence< sal_Int32 > aCustomColorList(officecfg::Office::Common::UserColors::CustomColor::get()); auto aCustomColorListRange = asNonConstRange(aCustomColorList); css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get()); @@ -489,7 +500,22 @@ IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, ValueSet*, pValSet, void) rXFSet.Put( XFillColorItem( OUString(), aColor ) ); m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); m_aCtlPreviewNew.Invalidate(); - ChangeColor(aColor, false); + + NamedColor aNamedColor; + aNamedColor.m_aColor = aColor; + + if (pValSet == m_xValSetColorList.get() && maPaletteManager.IsThemePaletteSelected()) + { + sal_uInt16 nThemeIndex; + sal_uInt16 nEffectIndex; + if (PaletteManager::GetThemeAndEffectIndex(nPos, nThemeIndex, nEffectIndex)) + { + aNamedColor.m_nThemeIndex = nThemeIndex; + maPaletteManager.GetLumModOff(nThemeIndex, nEffectIndex, aNamedColor.m_nLumMod, aNamedColor.m_nLumOff); + } + } + + ChangeColor(aNamedColor, false); if (pValSet == m_xValSetColorList.get()) { @@ -552,13 +578,16 @@ IMPL_STATIC_LINK_NOARG(SvxColorTabPage, OnMoreColorsClick, weld::Button&, void) comphelper::dispatchCommand(".uno:AdditionsDialog", aArgs); } -void SvxColorTabPage::ChangeColor(const Color &rNewColor, bool bUpdatePreset ) +void SvxColorTabPage::ChangeColor(const NamedColor &rNewColor, bool bUpdatePreset ) { - aPreviousColor = rNewColor; - aCurrentColor = rNewColor; + m_aPreviousColor = rNewColor.m_aColor; + m_aCurrentColor = rNewColor; UpdateColorValues( bUpdatePreset ); // fill ItemSet and pass it on to XOut - rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) ); + XFillColorItem aItem(OUString(), m_aCurrentColor.m_aColor); + aItem.setComplexColor(m_aCurrentColor.getComplexColor()); + rXFSet.Put(aItem); + m_aCtlPreviewNew.SetAttributes(aXFillAttr.GetItemSet()); m_aCtlPreviewNew.Invalidate(); } @@ -599,42 +628,42 @@ void SvxColorTabPage::UpdateColorValues( bool bUpdatePreset ) { if (eCM != ColorModel::RGB) { - ConvertColorValues (aPreviousColor, eCM ); - ConvertColorValues (aCurrentColor, eCM); + ConvertColorValues (m_aPreviousColor, eCM ); + ConvertColorValues (m_aCurrentColor.m_aColor, eCM); - m_xCcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetRed() ), FieldUnit::PERCENT ); - m_xMcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetBlue() ), FieldUnit::PERCENT ); - m_xYcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetGreen() ), FieldUnit::PERCENT ); - m_xKcustom->set_value( ColorToPercent_Impl( 255 - aCurrentColor.GetAlpha() ), FieldUnit::PERCENT ); + m_xCcustom->set_value( ColorToPercent_Impl( m_aCurrentColor.m_aColor.GetRed() ), FieldUnit::PERCENT ); + m_xMcustom->set_value( ColorToPercent_Impl( m_aCurrentColor.m_aColor.GetBlue() ), FieldUnit::PERCENT ); + m_xYcustom->set_value( ColorToPercent_Impl( m_aCurrentColor.m_aColor.GetGreen() ), FieldUnit::PERCENT ); + m_xKcustom->set_value( ColorToPercent_Impl( 255 - m_aCurrentColor.m_aColor.GetAlpha() ), FieldUnit::PERCENT ); if( bUpdatePreset ) { - m_xCpreset->set_text(unicode::formatPercent(ColorToPercent_Impl(aPreviousColor.GetRed()), + m_xCpreset->set_text(unicode::formatPercent(ColorToPercent_Impl(m_aPreviousColor.GetRed()), Application::GetSettings().GetUILanguageTag())); - m_xMpreset->set_text(unicode::formatPercent(ColorToPercent_Impl(aPreviousColor.GetBlue()), + m_xMpreset->set_text(unicode::formatPercent(ColorToPercent_Impl(m_aPreviousColor.GetBlue()), Application::GetSettings().GetUILanguageTag())); - m_xYpreset->set_text(unicode::formatPercent(ColorToPercent_Impl(aPreviousColor.GetGreen()), + m_xYpreset->set_text(unicode::formatPercent(ColorToPercent_Impl(m_aPreviousColor.GetGreen()), Application::GetSettings().GetUILanguageTag())); - m_xKpreset->set_text(unicode::formatPercent(ColorToPercent_Impl(255 - aPreviousColor.GetAlpha()), + m_xKpreset->set_text(unicode::formatPercent(ColorToPercent_Impl(255 - m_aPreviousColor.GetAlpha()), Application::GetSettings().GetUILanguageTag())); } - ConvertColorValues (aPreviousColor, ColorModel::RGB); - ConvertColorValues (aCurrentColor, ColorModel::RGB); + ConvertColorValues (m_aPreviousColor, ColorModel::RGB); + ConvertColorValues (m_aCurrentColor.m_aColor, ColorModel::RGB); } else { - m_xRcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetRed() ) ); - m_xGcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetGreen() ) ); - m_xBcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetBlue() ) ); - m_xHexcustom->SetColor( aCurrentColor ); + m_xRcustom->set_value( ColorToPercent_Impl( m_aCurrentColor.m_aColor.GetRed() ) ); + m_xGcustom->set_value( ColorToPercent_Impl( m_aCurrentColor.m_aColor.GetGreen() ) ); + m_xBcustom->set_value( ColorToPercent_Impl( m_aCurrentColor.m_aColor.GetBlue() ) ); + m_xHexcustom->SetColor( m_aCurrentColor.m_aColor ); if( bUpdatePreset ) { - m_xRpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetRed()))); - m_xGpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetGreen()))); - m_xBpreset->set_text(OUString::number(ColorToPercent_Impl(aPreviousColor.GetBlue()))); - m_xHexpreset->SetColor( aPreviousColor ); + m_xRpreset->set_text(OUString::number(ColorToPercent_Impl(m_aPreviousColor.GetRed()))); + m_xGpreset->set_text(OUString::number(ColorToPercent_Impl(m_aPreviousColor.GetGreen()))); + m_xBpreset->set_text(OUString::number(ColorToPercent_Impl(m_aPreviousColor.GetBlue()))); + m_xHexpreset->SetColor( m_aPreviousColor ); } } } |