diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-11-21 05:09:10 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-11-23 06:25:33 +0100 |
commit | 106f128f359deb1c9553c105eff4bf829fdd9736 (patch) | |
tree | 57a563b4e8549de6c88ac5d686b17aa85c8b4361 | |
parent | 26c86c78c5eb4b15e6f4fa9074045c97fcb50173 (diff) |
ManageNames: make global undo work again with dialog
-rw-r--r-- | sc/inc/document.hxx | 1 | ||||
-rw-r--r-- | sc/inc/undorangename.hxx | 15 | ||||
-rw-r--r-- | sc/source/core/data/documen3.cxx | 28 | ||||
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 25 | ||||
-rw-r--r-- | sc/source/ui/inc/docfunc.hxx | 7 | ||||
-rw-r--r-- | sc/source/ui/inc/namedlg.hxx | 4 | ||||
-rw-r--r-- | sc/source/ui/inc/namemgrtable.hxx | 6 | ||||
-rw-r--r-- | sc/source/ui/namedlg/namedlg.cxx | 16 | ||||
-rw-r--r-- | sc/source/ui/namedlg/namemgrtable.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/undo/undorangename.cxx | 38 |
10 files changed, 103 insertions, 50 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 3095f0c6cd36..9f29bfe7a7e1 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -466,6 +466,7 @@ public: */ SC_DLLPUBLIC void GetAllTabRangeNames(ScRangeName::TabNameCopyMap& rRangeNames) const; SC_DLLPUBLIC void SetAllTabRangeNames(const ScRangeName::TabNameCopyMap& rRangeNames); + SC_DLLPUBLIC void SetAllRangeNames( const boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap); void GetTabRangeNameMap(std::map<rtl::OUString, ScRangeName*>& rRangeName); void GetRangeNameMap(std::map<rtl::OUString, ScRangeName*>& rRangeName); SC_DLLPUBLIC ScRangeName* GetRangeName(SCTAB nTab) const; diff --git a/sc/inc/undorangename.hxx b/sc/inc/undorangename.hxx index 131a404c3edd..f1c1668a7b8b 100644 --- a/sc/inc/undorangename.hxx +++ b/sc/inc/undorangename.hxx @@ -31,6 +31,7 @@ #include "undobase.hxx" #include "rangenam.hxx" +#include <boost/ptr_container/ptr_map.hpp> class ScDocShell; @@ -41,10 +42,8 @@ class ScUndoAllRangeNames : public ScSimpleUndo { public: ScUndoAllRangeNames(ScDocShell* pDocSh, - const ScRangeName* pOldGlobal, - const ScRangeName* pNewGlobal, - const ScRangeName::TabNameCopyMap& rOldLocal, - const ScRangeName::TabNameCopyMap& rNewLocal); + const std::map<rtl::OUString, ScRangeName*>& rOldNames, + const boost::ptr_map<rtl::OUString, ScRangeName>& rNewNames); virtual ~ScUndoAllRangeNames(); @@ -55,13 +54,11 @@ public: virtual String GetComment() const; private: - void DoChange(const ScRangeName& rGlobal, const ScRangeName::TabNameMap& rLocal); + void DoChange(const boost::ptr_map<rtl::OUString, ScRangeName*>& rNames); private: - ScRangeName maOldGlobalNames; - ScRangeName maNewGlobalNames; - ScRangeName::TabNameMap maOldLocalNames; - ScRangeName::TabNameMap maNewLocalNames; + boost::ptr_map<rtl::OUString, ScRangeName> maOldNames; + boost::ptr_map<rtl::OUString, ScRangeName> maNewNames; }; #endif diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index 1aabd9f7dd6a..d225f1143945 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -126,6 +126,34 @@ void ScDocument::SetAllTabRangeNames(const ScRangeName::TabNameCopyMap& rNames) SetRangeName(itr->first, new ScRangeName(*itr->second)); } +void ScDocument::SetAllRangeNames( const boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap) +{ + rtl::OUString aGlobalStr(RTL_CONSTASCII_USTRINGPARAM(STR_GLOBAL_RANGE_NAME)); + boost::ptr_map<rtl::OUString,ScRangeName>::const_iterator itr = rRangeMap.begin(), itrEnd = rRangeMap.end(); + for (; itr!=itrEnd; ++itr) + { + if (itr->first == aGlobalStr) + { + delete pRangeName; + const ScRangeName* pName = itr->second; + if (pName->empty()) + pRangeName = NULL; + else + pRangeName = new ScRangeName( *pName ); + } + else + { + const ScRangeName* pName = itr->second; + SCTAB nTab; + GetTable(itr->first, nTab); + if (pName->empty()) + SetRangeName( nTab, NULL ); + else + SetRangeName( nTab, new ScRangeName( *pName ) ); + } + } +} + void ScDocument::GetTabRangeNameMap(std::map<rtl::OUString, ScRangeName*>& aRangeNameMap) { for (SCTAB i = 0; i < static_cast<SCTAB>(maTabs.size()); ++i) diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 39600bd9ece3..739b973861c3 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -74,6 +74,7 @@ #include "drwlayer.hxx" #include "editutil.hxx" #include "globstr.hrc" +#include "globalnames.hxx" #include "olinetab.hxx" #include "patattr.hxx" #include "rangenam.hxx" @@ -4528,6 +4529,30 @@ bool ScDocFunc::SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc, SCTA return true; } +void ScDocFunc::ModifyAllRangeNames( const boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap ) +{ + ScDocShellModificator aModificator(rDocShell); + ScDocument* pDoc = rDocShell.GetDocument(); + + if (pDoc->IsUndoEnabled()) + { + std::map<rtl::OUString, ScRangeName*> aOldRangeMap; + pDoc->GetRangeNameMap(aOldRangeMap); + rDocShell.GetUndoManager()->AddUndoAction( + new ScUndoAllRangeNames(&rDocShell, aOldRangeMap, rRangeMap)); + } + + pDoc->CompileNameFormula(true); + + // set all range names + pDoc->SetAllRangeNames(rRangeMap); + + pDoc->CompileNameFormula(false); + + aModificator.SetDocumentModified(); + SFX_APP()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED)); +} + //------------------------------------------------------------------------ void ScDocFunc::CreateOneName( ScRangeName& rList, diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index 972ed945b988..a339b940d445 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -184,6 +184,13 @@ public: bool SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc = true, SCTAB nTab = -1 ); // takes ownership of pNewRanges //nTab = -1 for local range names bool ModifyRangeNames( const ScRangeName& rNewRanges, SCTAB nTab = -1 ); + /** + * Modify all range names, global scope names as well as sheet local ones, + * in one go. Note that this method will <b>not</b> destroy the instances + * passed as arguments (it creates copies); the caller is responsible for + * destroying them. + */ + void ModifyAllRangeNames( const boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap ); sal_Bool CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_Bool bApi, SCTAB nTab = -1 ); // -1 for global range names sal_Bool InsertNameList( const ScAddress& rStartPos, sal_Bool bApi ); diff --git a/sc/source/ui/inc/namedlg.hxx b/sc/source/ui/inc/namedlg.hxx index caf7d80cf979..a5b546165fcf 100644 --- a/sc/source/ui/inc/namedlg.hxx +++ b/sc/source/ui/inc/namedlg.hxx @@ -103,7 +103,9 @@ private: const ScAddress maCursorPos; Selection maCurSel; - std::map<rtl::OUString, ScRangeName*> maRangeMap; + typedef boost::ptr_map<rtl::OUString, ScRangeName> RangeNameContainer; + + RangeNameContainer maRangeMap; private: void Init(); diff --git a/sc/source/ui/inc/namemgrtable.hxx b/sc/source/ui/inc/namemgrtable.hxx index 8331a731dc80..a7beab040791 100644 --- a/sc/source/ui/inc/namemgrtable.hxx +++ b/sc/source/ui/inc/namemgrtable.hxx @@ -45,21 +45,19 @@ class SC_DLLPUBLIC ScRangeManagerTable : public SvTabListBox { private: HeaderBar maHeaderBar; - ScRangeName* mpGlobalRangeName; - std::map<rtl::OUString, ScRangeName*> maTabRangeNames; rtl::OUString maGlobalString; void GetLine(ScRangeNameLine& aLine, SvLBoxEntry* pEntry); + void Init( const boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap ); public: - ScRangeManagerTable( Window* pParent, ScRangeName* pGlobalRangeName, std::map<rtl::OUString, ScRangeName*> aTabRangeNames ); + ScRangeManagerTable( Window* pParent, boost::ptr_map<rtl::OUString, ScRangeName>& aTabRangeNames ); ~ScRangeManagerTable() {}; void addEntry( const ScRangeNameLine& rLine ); void DeleteSelectedEntries(); void GetCurrentLine(ScRangeNameLine& rLine); - void UpdateEntries(); bool IsMultiSelection(); std::vector<ScRangeNameLine> GetSelectedEntries(); }; diff --git a/sc/source/ui/namedlg/namedlg.cxx b/sc/source/ui/namedlg/namedlg.cxx index 2db86ef4fdea..c64e0349200f 100644 --- a/sc/source/ui/namedlg/namedlg.cxx +++ b/sc/source/ui/namedlg/namedlg.cxx @@ -151,8 +151,16 @@ void ScNameDlg::Init() OSL_ENSURE( mpViewData && mpDoc, "ViewData oder Document nicht gefunden!" ); //init UI - mpDoc->GetRangeNameMap(maRangeMap); - mpRangeManagerTable = new ScRangeManagerTable(&maNameMgrCtrl, mpDoc->GetRangeName(), maRangeMap); + std::map<rtl::OUString, ScRangeName*> aRangeMap; + mpDoc->GetRangeNameMap(aRangeMap); + RangeNameContainer::iterator itr = maRangeMap.begin(), itrEnd = maRangeMap.end(); + for (; itr != itrEnd; ++itr) + { + rtl::OUString aTemp(itr->first); + maRangeMap.insert(aTemp, new ScRangeName(*itr->second)); + } + + mpRangeManagerTable = new ScRangeManagerTable(&maNameMgrCtrl, maRangeMap); mpRangeManagerTable->SetSelectHdl( LINK( this, ScNameDlg, SelectionChangedHdl_Impl ) ); mpRangeManagerTable->SetDeselectHdl( LINK( this, ScNameDlg, SelectionChangedHdl_Impl ) ); @@ -229,6 +237,8 @@ void ScNameDlg::SetReference( const ScRange& rRef, ScDocument* pDocP ) sal_Bool ScNameDlg::Close() { + ScDocFunc aFunc(*mpViewData->GetDocShell()); + aFunc.ModifyAllRangeNames(maRangeMap); return DoClose( ScNameDlgWrapper::GetChildWindowId() ); } @@ -291,8 +301,6 @@ bool ScNameDlg::IsFormulaValid() //updates the table and the buttons void ScNameDlg::UpdateNames() { - mpRangeManagerTable->UpdateEntries(); - ScRangeNameLine aLine; mpRangeManagerTable->GetCurrentLine(aLine); if (aLine.aName.getLength()) diff --git a/sc/source/ui/namedlg/namemgrtable.cxx b/sc/source/ui/namedlg/namemgrtable.cxx index 5528efb2b168..70621a902572 100644 --- a/sc/source/ui/namedlg/namemgrtable.cxx +++ b/sc/source/ui/namedlg/namemgrtable.cxx @@ -55,11 +55,9 @@ String createEntryString(const ScRangeNameLine& rLine) return aRet; } -ScRangeManagerTable::ScRangeManagerTable( Window* pWindow, ScRangeName* pGlobalRangeName, std::map<rtl::OUString, ScRangeName*> aTabRangeNames ): +ScRangeManagerTable::ScRangeManagerTable( Window* pWindow, boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap ): SvTabListBox( pWindow, WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP ), maHeaderBar( pWindow, WB_BUTTONSTYLE | WB_BOTTOMBORDER ), - mpGlobalRangeName( pGlobalRangeName ), - maTabRangeNames( aTabRangeNames ), maGlobalString( ResId::toString(ScResId(STR_GLOBAL_SCOPE))) { Size aBoxSize( pWindow->GetOutputSizePixel() ); @@ -85,6 +83,7 @@ ScRangeManagerTable::ScRangeManagerTable( Window* pWindow, ScRangeName* pGlobalR Show(); maHeaderBar.Show(); SetSelectionMode(MULTIPLE_SELECTION); + Init(rRangeMap); } void ScRangeManagerTable::addEntry(const ScRangeNameLine& rLine) @@ -106,13 +105,13 @@ void ScRangeManagerTable::GetLine(ScRangeNameLine& rLine, SvLBoxEntry* pEntry) rLine.aScope = GetEntryText(pEntry, 2); } -void ScRangeManagerTable::UpdateEntries() +void ScRangeManagerTable::Init(const boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap) { Clear(); - for (std::map<rtl::OUString, ScRangeName*>::iterator itr = maTabRangeNames.begin(); - itr != maTabRangeNames.end(); ++itr) + for (boost::ptr_map<rtl::OUString, ScRangeName>::const_iterator itr = rRangeMap.begin(); + itr != rRangeMap.end(); ++itr) { - ScRangeName* pLocalRangeName = itr->second; + const ScRangeName* pLocalRangeName = itr->second; ScRangeNameLine aLine; if (itr->first == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_GLOBAL_RANGE_NAME))) aLine.aScope = maGlobalString; diff --git a/sc/source/ui/undo/undorangename.cxx b/sc/source/ui/undo/undorangename.cxx index a3ba960fb29b..b7b1e2cc6c2a 100644 --- a/sc/source/ui/undo/undorangename.cxx +++ b/sc/source/ui/undo/undorangename.cxx @@ -43,31 +43,27 @@ using ::std::auto_ptr; ScUndoAllRangeNames::ScUndoAllRangeNames( ScDocShell* pDocSh, - const ScRangeName* pOldGlobal, const ScRangeName* pNewGlobal, - const ScRangeName::TabNameCopyMap &rOldLocal, const ScRangeName::TabNameCopyMap &rNewLocal) : + const std::map<rtl::OUString, ScRangeName*>& rOldNames, + const boost::ptr_map<rtl::OUString, ScRangeName>& rNewNames) : ScSimpleUndo(pDocSh) { - if (pOldGlobal) - maOldGlobalNames = *pOldGlobal; - if (pNewGlobal) - maNewGlobalNames = *pNewGlobal; - // Copy sheet-local names. - ScRangeName::TabNameCopyMap::const_iterator itr, itrEnd; - for (itr = rOldLocal.begin(), itrEnd = rOldLocal.end(); itr != itrEnd; ++itr) + std::map<rtl::OUString, ScRangeName*>::const_iterator itr, itrEnd; + for (itr = rOldNames.begin(), itrEnd = rOldNames.end(); itr != itrEnd; ++itr) { SAL_WNODEPRECATED_DECLARATIONS_PUSH auto_ptr<ScRangeName> p(new ScRangeName(*itr->second)); SAL_WNODEPRECATED_DECLARATIONS_POP - maOldLocalNames.insert(itr->first, p); + maOldNames.insert(itr->first, p); } - for (itr = rNewLocal.begin(), itrEnd = rNewLocal.end(); itr != itrEnd; ++itr) + boost::ptr_map<rtl::OUString, ScRangeName>::const_iterator it, itEnd; + for (it = rNewNames.begin(), itEnd = rNewNames.end(); it != itEnd; ++it) { SAL_WNODEPRECATED_DECLARATIONS_PUSH - auto_ptr<ScRangeName> p(new ScRangeName(*itr->second)); + auto_ptr<ScRangeName> p(new ScRangeName(*it->second)); SAL_WNODEPRECATED_DECLARATIONS_POP - maNewLocalNames.insert(itr->first, p); + maNewNames.insert(it->first, p); } } @@ -77,12 +73,12 @@ ScUndoAllRangeNames::~ScUndoAllRangeNames() void ScUndoAllRangeNames::Undo() { - DoChange(maOldGlobalNames, maOldLocalNames); + DoChange(maOldNames); } void ScUndoAllRangeNames::Redo() { - DoChange(maNewGlobalNames, maNewLocalNames); + DoChange(maNewNames); } void ScUndoAllRangeNames::Repeat(SfxRepeatTarget& /*rTarget*/) @@ -99,21 +95,13 @@ String ScUndoAllRangeNames::GetComment() const return ScGlobal::GetRscString(STR_UNDO_RANGENAMES); } -void ScUndoAllRangeNames::DoChange(const ScRangeName& rGlobal, const ScRangeName::TabNameMap& rLocal) +void ScUndoAllRangeNames::DoChange(const boost::ptr_map<rtl::OUString, ScRangeName*>& rNames) { ScDocument& rDoc = *pDocShell->GetDocument(); rDoc.CompileNameFormula(true); - // Global names. - if (rGlobal.empty()) - rDoc.SetRangeName(NULL); - else - rDoc.SetRangeName(new ScRangeName(rGlobal)); - - ScRangeName::TabNameCopyMap aCopy; - ScRangeName::copyLocalNames(rLocal, aCopy); - rDoc.SetAllTabRangeNames(aCopy); + rDoc.SetAllRangeNames(rNames); rDoc.CompileNameFormula(true); |