From f35e6f2504384ad66b475d39849ed10987b2da53 Mon Sep 17 00:00:00 2001 From: Katarina Behrens Date: Thu, 16 Feb 2017 22:29:10 +0100 Subject: tdf#103224: Get the initial colour right Change-Id: I59309f5b433eb7aa92d05ce7d373d69cb413b258 Reviewed-on: https://gerrit.libreoffice.org/34383 Tested-by: Jenkins Reviewed-by: Katarina Behrens --- cui/source/inc/cuitabarea.hxx | 8 ++++--- cui/source/tabpages/tparea.cxx | 1 - cui/source/tabpages/tpcolor.cxx | 46 ++++++++++++++++++----------------------- 3 files changed, 25 insertions(+), 30 deletions(-) (limited to 'cui') diff --git a/cui/source/inc/cuitabarea.hxx b/cui/source/inc/cuitabarea.hxx index b8f7e16caaea..b419748cdab3 100644 --- a/cui/source/inc/cuitabarea.hxx +++ b/cui/source/inc/cuitabarea.hxx @@ -731,7 +731,6 @@ private: XColorListRef pColorList; ChangeType* pnColorListState; - sal_Int32* pPos; XFillStyleItem aXFStyleItem; XFillColorItem aXFillColorItem; @@ -751,6 +750,7 @@ private: void ImpColorCountChanged(); void FillPaletteLB(); + long FindColorInPalette(const OUString& rPaletteName) const; DECL_LINK( ClickAddHdl_Impl, Button*, void ); DECL_LINK( ClickWorkOnHdl_Impl, Button*, void ); @@ -763,11 +763,14 @@ private: void SetColorModel(ColorModel eModel); void ChangeColorModel(); void UpdateColorValues( bool bUpdatePreset = true ); - static sal_Int32 SearchColorList(OUString const & aColorName); DECL_LINK( ModifiedHdl_Impl, Edit&, void ); void UpdateModified(); css::uno::Reference< css::uno::XComponentContext > m_context; + + static sal_Int32 FindInCustomColors( OUString const & aColorName ); + sal_Int32 FindInPalette( const Color& rColor ); + public: SvxColorTabPage( vcl::Window* pParent, const SfxItemSet& rInAttrs ); virtual ~SvxColorTabPage() override; @@ -783,7 +786,6 @@ public: virtual DeactivateRC DeactivatePage( SfxItemSet* pSet ) override; void SetPropertyList( XPropertyListType t, const XPropertyListRef &xRef ); - void SetPos( sal_Int32* pInPos ) { pPos = pInPos; } void SetColorList( const XColorListRef& pColList ); diff --git a/cui/source/tabpages/tparea.cxx b/cui/source/tabpages/tparea.cxx index 70e7be46c9c7..9870d84c8374 100644 --- a/cui/source/tabpages/tparea.cxx +++ b/cui/source/tabpages/tparea.cxx @@ -404,7 +404,6 @@ void SvxAreaTabPage::CreatePage( sal_Int32 nId, SfxTabPage* pTab ) if(nId == SOLID ) { static_cast(pTab)->SetColorList( m_pColorList ); - static_cast(pTab)->SetPos( &m_nPos ); static_cast(pTab)->SetColorChgd( m_pnColorListState ); static_cast(pTab)->Construct(); static_cast(pTab)->ActivatePage( m_rXFSet ); diff --git a/cui/source/tabpages/tpcolor.cxx b/cui/source/tabpages/tpcolor.cxx index e4545b497d6e..62a1515d3f5d 100644 --- a/cui/source/tabpages/tpcolor.cxx +++ b/cui/source/tabpages/tpcolor.cxx @@ -59,7 +59,6 @@ SvxColorTabPage::SvxColorTabPage(vcl::Window* pParent, const SfxItemSet& rInAttr , rOutAttrs ( rInAttrs ) // All the horrific pointers we store and should not , pnColorListState( nullptr ) - , pPos( nullptr ) , aXFStyleItem( drawing::FillStyle_SOLID ) , aXFillColorItem( OUString(), Color( COL_BLACK ) ) , aXFillAttr( rInAttrs.GetPool() ) @@ -239,38 +238,26 @@ void SvxColorTabPage::ActivatePage( const SfxItemSet& ) { if( pColorList.is() ) { - if( *pPos != LISTBOX_ENTRY_NOTFOUND ) + const SfxPoolItem* pPoolItem = nullptr; + if( SfxItemState::SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), true, &pPoolItem ) ) { - m_pValSetColorList->SelectItem( m_pValSetColorList->GetItemId( static_cast(*pPos) ) ); - const XColorEntry* pEntry = pColorList->GetColor(*pPos); - aPreviousColor = pEntry->GetColor(); - ChangeColor(pEntry->GetColor()); - } - else if( *pPos == LISTBOX_ENTRY_NOTFOUND ) - { - const SfxPoolItem* pPoolItem = nullptr; - if( SfxItemState::SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), true, &pPoolItem ) ) - { - SetColorModel( ColorModel::RGB ); - ChangeColorModel(); + SetColorModel( ColorModel::RGB ); + ChangeColorModel(); - aPreviousColor = static_cast(pPoolItem)->GetColorValue(); - ChangeColor( aPreviousColor ); + const Color aColor = static_cast(pPoolItem)->GetColorValue(); + ChangeColor( aColor ); + sal_Int32 nPos = FindInPalette( aColor ); - m_pRcustom->SetValue( ColorToPercent_Impl( aCurrentColor.GetRed() ) ); - m_pGcustom->SetValue( ColorToPercent_Impl( aCurrentColor.GetGreen() ) ); - m_pBcustom->SetValue( ColorToPercent_Impl( aCurrentColor.GetBlue() ) ); - m_pHexcustom->SetColor( aCurrentColor.GetColor() ); + if ( nPos != -1 ) + m_pValSetColorList->SelectItem( m_pValSetColorList->GetItemId( nPos ) ); + // else search in other palettes? - } } m_pCtlPreviewOld->SetAttributes( aXFillAttr.GetItemSet() ); m_pCtlPreviewOld->Invalidate(); SelectValSetHdl_Impl( m_pValSetColorList ); - - *pPos = LISTBOX_ENTRY_NOTFOUND; } } @@ -374,7 +361,7 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl, Button*, void) while (!bValidColorName) { aName = aNewName + " " + OUString::number( j++ ); - bValidColorName = (SearchColorList(aName) == LISTBOX_ENTRY_NOTFOUND); + bValidColorName = (FindInCustomColors(aName) == LISTBOX_ENTRY_NOTFOUND); } SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); @@ -386,7 +373,7 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl, Button*, void) { pDlg->GetName( aName ); - bValidColorName = (SearchColorList(aName) == LISTBOX_ENTRY_NOTFOUND); + bValidColorName = (FindInCustomColors(aName) == LISTBOX_ENTRY_NOTFOUND); if (bValidColorName) { nError = 0; @@ -662,7 +649,7 @@ void SvxColorTabPage::UpdateColorValues( bool bUpdatePreset ) } } -sal_Int32 SvxColorTabPage::SearchColorList(OUString const & aColorName) +sal_Int32 SvxColorTabPage::FindInCustomColors(OUString const & aColorName) { css::uno::Sequence< OUString > aCustomColorNameList(officecfg::Office::Common::UserColors::CustomColorName::get()); long nCount = aCustomColorNameList.getLength(); @@ -680,6 +667,13 @@ sal_Int32 SvxColorTabPage::SearchColorList(OUString const & aColorName) return nPos; } +sal_Int32 SvxColorTabPage::FindInPalette( const Color& rColor ) +{ + sal_Int32 nPos = pColorList->GetIndexOfColor( rColor ); + + return ( nPos == -1) ? LISTBOX_ENTRY_NOTFOUND : nPos; +} + // A RGB value is converted to a CMYK value - not in an ideal way as // R is converted into C, G into M and B into Y. The K value is held in an // extra variable. For further color models one should develop own -- cgit