diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2010-02-23 19:04:41 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2010-02-23 19:04:41 -0500 |
commit | 2ab03deceb3343ca85fe0d87d952329d6ec3dde5 (patch) | |
tree | dea8f29baa9429d17a60f98f86b4bea6ec74b5d3 | |
parent | b8cdea71ab986882c8590d1531a0e2ede4c51cb2 (diff) |
calctabcolor: Use STL's container instead of using an internal List. We should avoid using List at all cost!
-rw-r--r-- | sc/inc/tabbgcolor.hxx | 17 | ||||
-rw-r--r-- | sc/source/core/data/makefile.mk | 2 | ||||
-rw-r--r-- | sc/source/core/data/tabbgcolor.cxx | 52 | ||||
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 27 | ||||
-rw-r--r-- | sc/source/ui/inc/docfunc.hxx | 3 | ||||
-rw-r--r-- | sc/source/ui/inc/undotab.hxx | 6 | ||||
-rw-r--r-- | sc/source/ui/inc/viewfunc.hxx | 4 | ||||
-rw-r--r-- | sc/source/ui/undo/undotab.cxx | 25 | ||||
-rw-r--r-- | sc/source/ui/view/tabvwshf.cxx | 33 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun2.cxx | 8 |
10 files changed, 119 insertions, 58 deletions
diff --git a/sc/inc/tabbgcolor.hxx b/sc/inc/tabbgcolor.hxx index 83b694af6219..9c0ad6bf207d 100644 --- a/sc/inc/tabbgcolor.hxx +++ b/sc/inc/tabbgcolor.hxx @@ -30,8 +30,10 @@ #ifndef SC_TABBGCOLOR_HXX #define SC_TABBGCOLOR_HXX -#include <tools/color.hxx> -#include <tools/list.hxx> +#include "tools/color.hxx" +#include "address.hxx" + +#include <vector> struct ScUndoSetTabBgColorInfo { @@ -39,8 +41,13 @@ public: SCTAB nTabId; Color aOldTabBgColor; Color aNewTabBgColor; - BOOL IsDefaultOldTabBgColor() const {return aOldTabBgColor == Color( COL_AUTO ) ? TRUE : FALSE ;}; - BOOL IsDefaultNewTabBgColor() const {return aOldTabBgColor == Color( COL_AUTO ) ? TRUE : FALSE ;}; + bool IsDefaultOldTabBgColor() const { return aOldTabBgColor == Color(COL_AUTO) ? true : false; } + bool IsDefaultNewTabBgColor() const { return aOldTabBgColor == Color(COL_AUTO) ? true : false; } + + explicit ScUndoSetTabBgColorInfo(SCTAB nTab); + ScUndoSetTabBgColorInfo(const ScUndoSetTabBgColorInfo& r); }; -DECLARE_LIST( ScUndoSetTabBgColorInfoList, ScUndoSetTabBgColorInfo* ) + +typedef ::std::vector<ScUndoSetTabBgColorInfo> ScUndoSetTabBgColorInfoList; + #endif diff --git a/sc/source/core/data/makefile.mk b/sc/source/core/data/makefile.mk index ecd3aad07c0b..4d86f148390d 100644 --- a/sc/source/core/data/makefile.mk +++ b/sc/source/core/data/makefile.mk @@ -104,6 +104,7 @@ SLOFILES = \ $(SLO)$/sortparam.obj \ $(SLO)$/stlpool.obj \ $(SLO)$/stlsheet.obj \ + $(SLO)$/tabbgcolor.obj \ $(SLO)$/table1.obj \ $(SLO)$/table2.obj \ $(SLO)$/table3.obj \ @@ -130,6 +131,7 @@ EXCEPTIONSFILES= \ $(SLO)$/dptabres.obj \ $(SLO)$/dptabdat.obj \ $(SLO)$/global2.obj \ + $(SLO)$/tabbgcolor.obj \ $(SLO)$/table1.obj \ $(SLO)$/table2.obj \ $(SLO)$/table3.obj \ diff --git a/sc/source/core/data/tabbgcolor.cxx b/sc/source/core/data/tabbgcolor.cxx new file mode 100644 index 000000000000..d80c7509a19d --- /dev/null +++ b/sc/source/core/data/tabbgcolor.cxx @@ -0,0 +1,52 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: tabbgcolor.hxx,v $ + * $Revision: 1.00 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sc.hxx" + + + +// INCLUDE --------------------------------------------------------------- + +#include "tabbgcolor.hxx" + +ScUndoSetTabBgColorInfo::ScUndoSetTabBgColorInfo(SCTAB nTab) : + nTabId(nTab), + aOldTabBgColor(COL_AUTO), + aNewTabBgColor(COL_AUTO) +{ +} + +ScUndoSetTabBgColorInfo::ScUndoSetTabBgColorInfo(const ScUndoSetTabBgColorInfo& r) : + nTabId(r.nTabId), + aOldTabBgColor(r.aOldTabBgColor), + aNewTabBgColor(r.aNewTabBgColor) +{ +} diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index f54e4c17bcdf..308f45e4de98 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -2892,11 +2892,13 @@ bool ScDocFunc::SetTabBgColor( SCTAB nTab, const Color& rColor, bool bRecord, bo return bSuccess; } -bool ScDocFunc::SetTabBgColor( ScUndoSetTabBgColorInfoList* rUndoSetTabBgColorInfoList, bool bRecord, bool bApi ) +bool ScDocFunc::SetTabBgColor( + ScUndoSetTabBgColorInfoList& rUndoTabColorList, bool bRecord, bool bApi ) { ScDocument* pDoc = rDocShell.GetDocument(); if (bRecord && !pDoc->IsUndoEnabled()) bRecord = false; + if ( !pDoc->IsDocEditable() ) { if (!bApi) @@ -2904,20 +2906,19 @@ bool ScDocFunc::SetTabBgColor( ScUndoSetTabBgColorInfoList* rUndoSetTabBgColorIn return false; } - ScViewData* pViewData = rDocShell.GetViewData(); USHORT nTab; Color aNewTabBgColor; - ScUndoSetTabBgColorInfo* rUndoSetTabBgColorInfo; bool bSuccess = true; - USHORT nTabProtectCount = 0; - for ( USHORT i=0; i < rUndoSetTabBgColorInfoList->Count(); i++ ) + size_t nTabProtectCount = 0; + size_t nTabListCount = rUndoTabColorList.size(); + for ( size_t i = 0; i < nTabListCount; ++i ) { - rUndoSetTabBgColorInfo = rUndoSetTabBgColorInfoList->GetObject(i); - nTab = rUndoSetTabBgColorInfo->nTabId; + ScUndoSetTabBgColorInfo& rInfo = rUndoTabColorList[i]; + nTab = rInfo.nTabId; if ( !pDoc->IsTabProtected(nTab) ) { - aNewTabBgColor = rUndoSetTabBgColorInfo->aNewTabBgColor; - rUndoSetTabBgColorInfo->aOldTabBgColor = pDoc->GetTabBgColor(nTab); + aNewTabBgColor = rInfo.aNewTabBgColor; + rInfo.aOldTabBgColor = pDoc->GetTabBgColor(nTab); pDoc->SetTabBgColor(nTab, aNewTabBgColor); if ( pDoc->GetTabBgColor(nTab) != aNewTabBgColor) { @@ -2930,18 +2931,20 @@ bool ScDocFunc::SetTabBgColor( ScUndoSetTabBgColorInfoList* rUndoSetTabBgColorIn nTabProtectCount++; } } - if ( nTabProtectCount == rUndoSetTabBgColorInfoList->Count() ) + + if ( nTabProtectCount == nTabListCount ) { if (!bApi) rDocShell.ErrorMessage(STR_PROTECTIONERR); //TODO Get a better String Error... - return FALSE; + return false; } + if (bSuccess) { if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoSetTabBgColor( &rDocShell, rUndoSetTabBgColorInfoList)); + new ScUndoSetTabBgColor( &rDocShell, rUndoTabColorList)); } rDocShell.PostPaintExtras(); ScDocShellModificator aModificator( rDocShell ); diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index 11e8914dd14e..a186ebabdae5 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -122,8 +122,7 @@ public: BOOL DeleteTable( SCTAB nTab, BOOL bRecord, BOOL bApi ); bool SetTabBgColor( SCTAB nTab, const Color& rColor, bool bRecord, bool bApi ); - bool SetTabBgColor( ScUndoSetTabBgColorInfoList* rUndoSetTabBgColorInfoList, - bool bRecord, bool bApi ); + bool SetTabBgColor( ScUndoSetTabBgColorInfoList& rUndoTabColorList, bool bRecord, bool bApi ); BOOL SetTableVisible( SCTAB nTab, BOOL bVisible, BOOL bApi ); diff --git a/sc/source/ui/inc/undotab.hxx b/sc/source/ui/inc/undotab.hxx index c158c9747da7..b7d095ea8732 100644 --- a/sc/source/ui/inc/undotab.hxx +++ b/sc/source/ui/inc/undotab.hxx @@ -238,7 +238,7 @@ public: const Color& aNTabBgColor); ScUndoSetTabBgColor( ScDocShell* pNewDocShell, - ScUndoSetTabBgColorInfoList* pUndoSetTabBgColorInfoList); + const ScUndoSetTabBgColorInfoList& rUndoTabColorList); virtual ~ScUndoSetTabBgColor(); virtual void Undo(); @@ -249,11 +249,11 @@ public: virtual String GetComment() const; private: - ScUndoSetTabBgColorInfoList* aUndoSetTabBgColorInfoList; + ScUndoSetTabBgColorInfoList aTabColorList; SCTAB nTab; Color aOldTabBgColor; Color aNewTabBgColor; - BOOL bIsMultipleUndo; + bool bIsMultipleUndo; void DoChange( SCTAB nTab, const Color& rTabBgColor ) const; void DoChange( BOOL bUndoType ) const; diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx index b727d96f944b..7bb3be9d43be 100644 --- a/sc/source/ui/inc/viewfunc.hxx +++ b/sc/source/ui/inc/viewfunc.hxx @@ -278,8 +278,8 @@ public: SCTAB nCount, const SCTAB* pSrcTabs, BOOL bLink,SCTAB nTab); - BOOL SetTabBgColor( const Color& rColor, SCTAB nTabNr ); - BOOL SetTabBgColor( ScUndoSetTabBgColorInfoList* rUndoSetTabBgColorInfoList ); + bool SetTabBgColor( const Color& rColor, SCTAB nTabNr ); + bool SetTabBgColor( ScUndoSetTabBgColorInfoList& rUndoSetTabBgColorInfoList ); void InsertTableLink( const String& rFile, const String& rFilter, const String& rOptions, diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx index 0793607fc728..d5c301648d76 100644 --- a/sc/source/ui/undo/undotab.cxx +++ b/sc/source/ui/undo/undotab.cxx @@ -793,7 +793,6 @@ ScUndoSetTabBgColor::ScUndoSetTabBgColor( ScDocShell* pNewDocShell, const Color& aOTabBgColor, const Color& aNTabBgColor) : ScSimpleUndo( pNewDocShell ), - aUndoSetTabBgColorInfoList ( NULL ), nTab ( nT ), aOldTabBgColor( aOTabBgColor ), aNewTabBgColor( aNTabBgColor ), @@ -801,12 +800,13 @@ ScUndoSetTabBgColor::ScUndoSetTabBgColor( ScDocShell* pNewDocShell, { } -ScUndoSetTabBgColor::ScUndoSetTabBgColor( ScDocShell* pNewDocShell, - ScUndoSetTabBgColorInfoList* pUndoSetTabBgColorInfoList) : - ScSimpleUndo( pNewDocShell ), - bIsMultipleUndo ( TRUE ) +ScUndoSetTabBgColor::ScUndoSetTabBgColor( + ScDocShell* pNewDocShell, + const ScUndoSetTabBgColorInfoList& rUndoTabColorList) : + ScSimpleUndo(pNewDocShell), + aTabColorList(rUndoTabColorList), + bIsMultipleUndo (true) { - aUndoSetTabBgColorInfoList = pUndoSetTabBgColorInfoList; } ScUndoSetTabBgColor::~ScUndoSetTabBgColor() @@ -815,7 +815,7 @@ ScUndoSetTabBgColor::~ScUndoSetTabBgColor() String ScUndoSetTabBgColor::GetComment() const { - if (bIsMultipleUndo && aUndoSetTabBgColorInfoList && aUndoSetTabBgColorInfoList->Count() > 1) + if (bIsMultipleUndo && aTabColorList.size() > 1) return ScGlobal::GetRscString( STR_UNDO_SET_MULTI_TAB_BG_COLOR ); return ScGlobal::GetRscString( STR_UNDO_SET_TAB_BG_COLOR ); } @@ -847,13 +847,12 @@ void ScUndoSetTabBgColor::DoChange(BOOL bUndoType) const if (!pDoc) return; - ScUndoSetTabBgColorInfo* aUndoSetTabBgColorInfo = NULL; - for (USHORT i=0; i < aUndoSetTabBgColorInfoList->Count(); ++i) + size_t nTabColorCount = aTabColorList.size(); + for (size_t i=0; i < nTabColorCount; ++i) { - aUndoSetTabBgColorInfo = aUndoSetTabBgColorInfoList->GetObject(i); - pDoc->SetTabBgColor( - aUndoSetTabBgColorInfo->nTabId, - bUndoType ? aUndoSetTabBgColorInfo->aOldTabBgColor : aUndoSetTabBgColorInfo->aNewTabBgColor); + const ScUndoSetTabBgColorInfo& rTabColor = aTabColorList[i]; + pDoc->SetTabBgColor(rTabColor.nTabId, + bUndoType ? rTabColor.aOldTabBgColor : rTabColor.aNewTabBgColor); } pDocShell->PostPaintExtras(); pDocShell->PostDataChanged(); diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx index 54f9cab2f693..0c5b3bc3f213 100644 --- a/sc/source/ui/view/tabvwshf.cxx +++ b/sc/source/ui/view/tabvwshf.cxx @@ -58,9 +58,11 @@ #include "scabstdlg.hxx" //CHINA001 -#include "tabbgcolor.hxx" //DBW -#include "tabbgcolordlg.hxx" //DBW -#include <svx/colritem.hxx> //DBW +#include "tabbgcolor.hxx" +#include "tabbgcolordlg.hxx" +#include "svx/colritem.hxx" + +#include <boost/scoped_ptr.hpp> #define IS_AVAILABLE(WhichId,ppItem) \ (pReqArgs->GetItemState((WhichId), TRUE, ppItem ) == SFX_ITEM_SET) @@ -700,8 +702,7 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) ScMarkData& rMark = pViewData->GetMarkData(); SCTAB nTabSelCount = rMark.GetSelectCount(); - ScUndoSetTabBgColorInfo* aTabBgColorUndoInfo=NULL; - ScUndoSetTabBgColorInfoList* aTabBgColorUndoInfoList =NULL; + ::boost::scoped_ptr<ScUndoSetTabBgColorInfoList> pTabColorList; if ( !pDoc->IsDocEditable() ) break; @@ -722,18 +723,17 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) if ( nTabSelCount > 1 ) { - aTabBgColorUndoInfoList = new ScUndoSetTabBgColorInfoList(); + pTabColorList.reset(new ScUndoSetTabBgColorInfoList); for (SCTAB nTab=0; nTab<nTabCount; nTab++) { if ( rMark.GetTableSelect(nTab) && !pDoc->IsTabProtected(nTab) ) { - aTabBgColorUndoInfo = new ScUndoSetTabBgColorInfo(); - aTabBgColorUndoInfo->nTabId = nTab; - aTabBgColorUndoInfo->aNewTabBgColor = aColor; - aTabBgColorUndoInfoList->Insert(aTabBgColorUndoInfo); + ScUndoSetTabBgColorInfo aTabColorInfo(nTab); + aTabColorInfo.aNewTabBgColor = aColor; + pTabColorList->push_back(aTabColorInfo); } } - bDone = SetTabBgColor( aTabBgColorUndoInfoList ); + bDone = SetTabBgColor( *pTabColorList ); } else { @@ -767,20 +767,19 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) { Color aSelectedColor; pDlg->GetSelectedColor(aSelectedColor); - aTabBgColorUndoInfoList = new ScUndoSetTabBgColorInfoList(); + pTabColorList.reset(new ScUndoSetTabBgColorInfoList); if ( nTabSelCount > 1 ) { for (SCTAB nTab=0; nTab<nTabCount; nTab++) { if ( rMark.GetTableSelect(nTab) && !pDoc->IsTabProtected(nTab) ) { - aTabBgColorUndoInfo = new ScUndoSetTabBgColorInfo(); - aTabBgColorUndoInfo->nTabId = nTab; - aTabBgColorUndoInfo->aNewTabBgColor = aSelectedColor; - aTabBgColorUndoInfoList->Insert(aTabBgColorUndoInfo); + ScUndoSetTabBgColorInfo aTabColorInfo(nTab); + aTabColorInfo.aNewTabBgColor = aSelectedColor; + pTabColorList->push_back(aTabColorInfo); } } - bDone = SetTabBgColor( aTabBgColorUndoInfoList ); + bDone = SetTabBgColor( *pTabColorList ); } else { diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 68ce5049217b..5e5c0318fa34 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -2277,9 +2277,9 @@ BOOL ScViewFunc::RenameTable( const String& rName, SCTAB nTab ) //---------------------------------------------------------------------------- -BOOL ScViewFunc::SetTabBgColor( const Color& rColor, SCTAB nTab ) +bool ScViewFunc::SetTabBgColor( const Color& rColor, SCTAB nTab ) { - BOOL bSuccess = GetViewData()->GetDocShell()->GetDocFunc().SetTabBgColor( nTab, rColor, TRUE, FALSE ); + bool bSuccess = GetViewData()->GetDocShell()->GetDocFunc().SetTabBgColor( nTab, rColor, TRUE, FALSE ); if (bSuccess) { GetViewData()->GetViewShell()->UpdateInputHandler(); @@ -2287,9 +2287,9 @@ BOOL ScViewFunc::SetTabBgColor( const Color& rColor, SCTAB nTab ) return bSuccess; } -BOOL ScViewFunc::SetTabBgColor( ScUndoSetTabBgColorInfoList* rUndoSetTabBgColorInfoList ) +bool ScViewFunc::SetTabBgColor( ScUndoSetTabBgColorInfoList& rUndoSetTabBgColorInfoList ) { - BOOL bSuccess = GetViewData()->GetDocShell()->GetDocFunc().SetTabBgColor( rUndoSetTabBgColorInfoList, TRUE, FALSE ); + bool bSuccess = GetViewData()->GetDocShell()->GetDocFunc().SetTabBgColor( rUndoSetTabBgColorInfoList, TRUE, FALSE ); if (bSuccess) { GetViewData()->GetViewShell()->UpdateInputHandler(); |