[PATCH] Added the Adding and removing of color charts

Rob Snelders programming at ertai.nl
Thu Mar 24 13:33:46 PDT 2011


---
 cui/source/options/cfgchart.cxx |   50 +++++++++++++++++++++++++++-----------
 cui/source/options/cfgchart.hxx |    9 +++++-
 cui/source/options/optchart.cxx |   44 +++++++++++++++++++++++++++++++++-
 cui/source/options/optchart.hrc |    3 +-
 cui/source/options/optchart.hxx |   14 +++++++----
 cui/source/options/optchart.src |   24 ++++++++++++++----
 6 files changed, 115 insertions(+), 29 deletions(-)

diff --git a/cui/source/options/cfgchart.cxx b/cui/source/options/cfgchart.cxx
index 4b449a0..0d406cd 100644
--- a/cui/source/options/cfgchart.cxx
+++ b/cui/source/options/cfgchart.cxx
@@ -43,7 +43,8 @@ SvxChartColorTable::SvxChartColorTable()
 {}
 
 SvxChartColorTable::SvxChartColorTable( const SvxChartColorTable & _rSource ) :
-        m_aColorEntries( _rSource.m_aColorEntries )
+        m_aColorEntries( _rSource.m_aColorEntries ),
+        nNextElementNumber( m_aColorEntries.size() + 1 )
 {}
 
 // accessors
@@ -79,6 +80,7 @@ ColorData SvxChartColorTable::getColorData( size_t _nIndex ) const
 void SvxChartColorTable::clear()
 {
     m_aColorEntries.clear();
+    nNextElementNumber = 1;
 }
 
 void SvxChartColorTable::append( const XColorEntry & _rEntry )
@@ -86,6 +88,12 @@ void SvxChartColorTable::append( const XColorEntry & _rEntry )
     m_aColorEntries.push_back( _rEntry );
 }
 
+void SvxChartColorTable::remove( size_t _nIndex )
+{
+    if (m_aColorEntries.size() > 0)
+        m_aColorEntries.erase( m_aColorEntries.begin() + _nIndex);
+}
+
 void SvxChartColorTable::replace( size_t _nIndex, const XColorEntry & _rEntry )
 {
     DBG_ASSERT( _nIndex <= m_aColorEntries.size(),
@@ -113,25 +121,37 @@ void SvxChartColorTable::useDefault()
 
     clear();
 
-    String aResName( CUI_RES( RID_SVXSTR_DIAGRAM_ROW ) );
-    String aPrefix, aPostfix, aName;
-    xub_StrLen nPos = aResName.SearchAscii( "$(ROW)" );
-    if( nPos != STRING_NOTFOUND )
+    for( sal_Int32 i=0; i<ROW_COLOR_COUNT; i++ )
     {
-        aPrefix = String( aResName, 0, nPos );
-        aPostfix = String( aResName, nPos + sizeof( "$(ROW)" ) - 1, STRING_LEN );
+        append( XColorEntry( aColors[ i % sizeof( aColors ) ], getNextDefaultName() ));
     }
-    else
-        aPrefix = aResName;
+}
 
-    for( sal_Int32 i=0; i<ROW_COLOR_COUNT; i++ )
-    {
-        aName = aPrefix;
-        aName.Append( String::CreateFromInt32( i + 1 ));
-        aName.Append( aPostfix );
+String SvxChartColorTable::getNextDefaultName()
+{
+    String aName;
 
-        append( XColorEntry( aColors[ i % sizeof( aColors ) ], aName ));
+    if (sDefaultNamePrefix.Len() == 0)
+    {
+        String aResName( CUI_RES( RID_SVXSTR_DIAGRAM_ROW ) );
+        xub_StrLen nPos = aResName.SearchAscii( "$(ROW)" );
+        if( nPos != STRING_NOTFOUND )
+        {
+            sDefaultNamePrefix = String( aResName, 0, nPos );
+            sDefaultNamePostfix = String( aResName, nPos + sizeof( "$(ROW)" ) - 1, STRING_LEN );
+        }
+        else
+        {
+            sDefaultNamePrefix = aResName;
+        }
     }
+
+    aName = sDefaultNamePrefix;
+    aName.Append( String::CreateFromInt32 ( nNextElementNumber ) );
+    aName.Append( sDefaultNamePostfix );
+    nNextElementNumber++;
+
+    return aName;
 }
 
 // comparison
diff --git a/cui/source/options/cfgchart.hxx b/cui/source/options/cfgchart.hxx
index b9f7ee4..918f81a 100644
--- a/cui/source/options/cfgchart.hxx
+++ b/cui/source/options/cfgchart.hxx
@@ -44,6 +44,9 @@ class SvxChartColorTable
 {
 private:
     ::std::vector< XColorEntry >     m_aColorEntries;
+    int                              nNextElementNumber;
+    String                           sDefaultNamePrefix;
+    String                           sDefaultNamePostfix;
 
 public:
     SvxChartColorTable();
@@ -57,8 +60,10 @@ public:
     // mutators
     void clear();
     void append( const XColorEntry & _rEntry );
+    void remove( size_t _nIndex );
     void replace( size_t _nIndex, const XColorEntry & _rEntry );
     void useDefault();
+    String getNextDefaultName();
 
     // comparison
     bool operator==( const SvxChartColorTable & _rOther ) const;
@@ -70,8 +75,8 @@ public:
 class SvxChartOptions : public ::utl::ConfigItem
 {
 private:
-    SvxChartColorTable		maDefColors;
-    sal_Bool					mbIsInitialized;
+    SvxChartColorTable          maDefColors;
+    sal_Bool                    mbIsInitialized;
 
     ::com::sun::star::uno::Sequence< ::rtl::OUString >
                             maPropertyNames;
diff --git a/cui/source/options/optchart.cxx b/cui/source/options/optchart.cxx
index dc3b64a..51d48d4 100644
--- a/cui/source/options/optchart.cxx
+++ b/cui/source/options/optchart.cxx
@@ -60,11 +60,15 @@ SvxDefaultColorOptPage::SvxDefaultColorOptPage( Window* pParent, const SfxItemSe
     aLbChartColors	( this, CUI_RES( LB_CHART_COLOR_LIST ) ),
     aGbColorBox		( this, CUI_RES( FL_COLOR_BOX ) ),
     aValSetColorBox	( this, CUI_RES( CT_COLOR_BOX ) ),
-    aPBDefault		( this, CUI_RES( PB_RESET_TO_DEFAULT ) )
+    aPBDefault		( this, CUI_RES( PB_RESET_TO_DEFAULT ) ),
+    aPBAdd              ( this, CUI_RES( PB_ADD_CHART_COLOR ) ),
+    aPBRemove           ( this, CUI_RES( PB_REMOVE_CHART_COLOR ) )
 {
     FreeResource();
 
     aPBDefault.SetClickHdl( LINK( this, SvxDefaultColorOptPage, ResetToDefaults ) );
+    aPBAdd.SetClickHdl( LINK( this, SvxDefaultColorOptPage, AddChartColor ) );
+    aPBRemove.SetClickHdl( LINK( this, SvxDefaultColorOptPage, RemoveChartColor ) );
     aLbChartColors.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, ListClickedHdl ) );
     aValSetColorBox.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, BoxClickedHdl ) );
 
@@ -195,6 +199,44 @@ IMPL_LINK( SvxDefaultColorOptPage, ResetToDefaults, void *, EMPTYARG )
     return 0L;
 }
 
+// AddChartColor
+// ------------
+
+IMPL_LINK( SvxDefaultColorOptPage, AddChartColor, void *, EMPTYARG )
+{
+    if( pColorConfig )
+    {
+        ColorData black = RGB_COLORDATA( 0x00, 0x00, 0x00 );
+
+        pColorConfig->GetColorTable().append (XColorEntry ( black, pColorConfig->GetColorTable().getNextDefaultName()));
+
+        aLbChartColors.Clear();
+        aLbChartColors.FillBox( pColorConfig->GetColorTable() );
+
+        aLbChartColors.GetFocus();
+    }
+
+    return 0L;
+}
+
+// RemoveChartColor
+// ----------------
+
+IMPL_LINK( SvxDefaultColorOptPage, RemoveChartColor, void *, EMPTYARG )
+{
+    if( pColorConfig )
+    {
+        pColorConfig->GetColorTable().remove( aLbChartColors.GetSelectEntryPos()  );
+
+        aLbChartColors.Clear();
+        aLbChartColors.FillBox( pColorConfig->GetColorTable() );
+
+        aLbChartColors.GetFocus();
+    }
+
+    return 0L;
+}
+
 // ListClickedHdl
 // --------------
 
diff --git a/cui/source/options/optchart.hrc b/cui/source/options/optchart.hrc
index 0fee268..dcf86df 100644
--- a/cui/source/options/optchart.hrc
+++ b/cui/source/options/optchart.hrc
@@ -34,4 +34,5 @@
 #define CT_COLOR_BOX			4
 
 #define PB_RESET_TO_DEFAULT		5
-
+#define PB_ADD_CHART_COLOR              6
+#define PB_REMOVE_CHART_COLOR           7
diff --git a/cui/source/options/optchart.hxx b/cui/source/options/optchart.hxx
index b0f61c2..71898e9 100644
--- a/cui/source/options/optchart.hxx
+++ b/cui/source/options/optchart.hxx
@@ -56,17 +56,21 @@ public:
 class SvxDefaultColorOptPage : public SfxTabPage
 {
 private:
-    FixedLine       		aGbChartColors;
-    ChartColorLB			aLbChartColors;
-    FixedLine       		aGbColorBox;
-    ValueSet				aValSetColorBox;
-    PushButton				aPBDefault;
+    FixedLine                           aGbChartColors;
+    ChartColorLB                        aLbChartColors;
+    FixedLine                           aGbColorBox;
+    ValueSet                            aValSetColorBox;
+    PushButton                          aPBDefault;
+    PushButton                          aPBAdd;
+    PushButton                          aPBRemove;
 
     SvxChartOptions*		pChartOptions;
     SvxChartColorTableItem*	pColorConfig;
     XColorTable*			pColorTab;
 
     DECL_LINK( ResetToDefaults, void * );
+    DECL_LINK( AddChartColor, void * );
+    DECL_LINK( RemoveChartColor, void * );
     DECL_LINK( ListClickedHdl, ChartColorLB * );
     DECL_LINK( BoxClickedHdl, ValueSet * );
 
diff --git a/cui/source/options/optchart.src b/cui/source/options/optchart.src
index f9ea2c6..593fafd 100644
--- a/cui/source/options/optchart.src
+++ b/cui/source/options/optchart.src
@@ -39,7 +39,7 @@ TabPage RID_OPTPAGE_CHART_DEFCOLORS
     Text [ en-US ] = "Default Colors";
     FixedLine FL_CHART_COLOR_LIST
     {
-        Pos		= MAP_APPFONT ( 6 , 3  ) ;
+        Pos	= MAP_APPFONT ( 6 , 3  ) ;
         Size    = MAP_APPFONT ( 80 , 8 ) ;
         Text [ en-US ] = "Chart colors";
         Text [ x-comment ] = " ";
@@ -48,7 +48,7 @@ TabPage RID_OPTPAGE_CHART_DEFCOLORS
     {
         HelpID = "cui:ListBox:RID_OPTPAGE_CHART_DEFCOLORS:LB_CHART_COLOR_LIST";
         Border		= TRUE;
-        Pos			= MAP_APPFONT ( 12 , 15  );
+        Pos		= MAP_APPFONT ( 12 , 15  );
         Size		= MAP_APPFONT ( 68 , 152 );
         DropDown	= FALSE;
         TabStop		= TRUE ;
@@ -56,17 +56,31 @@ TabPage RID_OPTPAGE_CHART_DEFCOLORS
     FixedLine FL_COLOR_BOX
     {
         Pos		= MAP_APPFONT ( 92 , 3  ) ;
-        Size    = MAP_APPFONT ( 106 , 8 ) ;
-        Text [ en-US ] = "Color table" ;
+        Size	        = MAP_APPFONT ( 106 , 8 ) ;
+        Text [ en-US ]  = "Color table" ;
         Text [ x-comment ] = " ";
     };
     Control CT_COLOR_BOX
     {
         Border		= TRUE;
-        Pos			= MAP_APPFONT ( 98 , 15  );
+        Pos		= MAP_APPFONT ( 98 , 15  );
         Size		= MAP_APPFONT ( 94 , 152 );
         TabStop		= TRUE ;
     };
+    PushButton PB_ADD_CHART_COLOR
+    {
+        Pos = MAP_APPFONT ( 204 , 15 ) ;
+        Size = MAP_APPFONT ( 50 , 14 ) ;
+        Text [ en-US ] = "~Add";
+        Text [ x-comment ] = " ";
+    };
+    PushButton PB_REMOVE_CHART_COLOR
+    {
+        Pos = MAP_APPFONT ( 204 , 32 ) ;
+        Size = MAP_APPFONT ( 50 , 14 ) ;
+        Text [ en-US ] = "~Remove";
+        Text [ x-comment ] = " ";
+    };
     PushButton PB_RESET_TO_DEFAULT
     {
         HelpID = "cui:PushButton:RID_OPTPAGE_CHART_DEFCOLORS:PB_RESET_TO_DEFAULT";
-- 
1.7.0.4


--------------070108020709070804090409--


More information about the LibreOffice mailing list