[Libreoffice-commits] core.git: cui/source include/svx svx/source

Katarina Behrens Katarina.Behrens at cib.de
Mon Feb 20 10:30:14 UTC 2017


 cui/source/inc/cuitabarea.hxx   |    8 ++++--
 cui/source/tabpages/tparea.cxx  |    1 
 cui/source/tabpages/tpcolor.cxx |   46 +++++++++++++++++-----------------------
 include/svx/xtable.hxx          |    1 
 svx/source/xoutdev/xtabcolr.cxx |   13 +++++++++++
 5 files changed, 39 insertions(+), 30 deletions(-)

New commits:
commit f35e6f2504384ad66b475d39849ed10987b2da53
Author: Katarina Behrens <Katarina.Behrens at cib.de>
Date:   Thu Feb 16 22:29:10 2017 +0100

    tdf#103224: Get the initial colour right
    
    Change-Id: I59309f5b433eb7aa92d05ce7d373d69cb413b258
    Reviewed-on: https://gerrit.libreoffice.org/34383
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>

diff --git a/cui/source/inc/cuitabarea.hxx b/cui/source/inc/cuitabarea.hxx
index b8f7e16..b419748 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 70e7be4..9870d84 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<SvxColorTabPage*>(pTab)->SetColorList( m_pColorList );
-        static_cast<SvxColorTabPage*>(pTab)->SetPos( &m_nPos );
         static_cast<SvxColorTabPage*>(pTab)->SetColorChgd( m_pnColorListState );
         static_cast<SvxColorTabPage*>(pTab)->Construct();
         static_cast<SvxColorTabPage*>(pTab)->ActivatePage( m_rXFSet );
diff --git a/cui/source/tabpages/tpcolor.cxx b/cui/source/tabpages/tpcolor.cxx
index e4545b4..62a1515 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<size_t>(*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<const XFillColorItem*>(pPoolItem)->GetColorValue();
-                ChangeColor( aPreviousColor );
+            const Color aColor = static_cast<const XFillColorItem*>(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
diff --git a/include/svx/xtable.hxx b/include/svx/xtable.hxx
index 1d781b9..6039e15 100644
--- a/include/svx/xtable.hxx
+++ b/include/svx/xtable.hxx
@@ -267,6 +267,7 @@ public:
 
     void Replace(long nIndex, std::unique_ptr<XColorEntry> pEntry);
     XColorEntry* GetColor(long nIndex) const;
+    long GetIndexOfColor( const Color& rColor) const;
     virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
     virtual bool Create() override;
 
diff --git a/svx/source/xoutdev/xtabcolr.cxx b/svx/source/xoutdev/xtabcolr.cxx
index 374f6fc..44f8814 100644
--- a/svx/source/xoutdev/xtabcolr.cxx
+++ b/svx/source/xoutdev/xtabcolr.cxx
@@ -157,4 +157,17 @@ Bitmap XColorList::CreateBitmapForUI( long /*nIndex*/ )
     return Bitmap();
 }
 
+long XColorList::GetIndexOfColor( const Color& rColor ) const
+{
+    for( long i = 0, n = maList.size(); i < n; ++i )
+    {
+        const Color aColor = static_cast<XColorEntry*>( maList[i].get() )->GetColor();
+
+        if (aColor == rColor )
+            return i;
+    }
+
+    return -1;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list