diff -uPr old/sc/source/ui/inc/undoblk.hxx new/sc/source/ui/inc/undoblk.hxx --- old/sc/source/ui/inc/undoblk.hxx 2009-04-16 13:06:06.000000000 +0800 +++ new/sc/source/ui/inc/undoblk.hxx 2009-06-09 10:25:18.000000000 +0800 @@ -36,6 +36,7 @@ #include "spellparam.hxx" class ScDocShell; +class ScBaseCell; class ScDocument; class ScOutlineTable; class ScRangeName; @@ -592,6 +593,35 @@ void SetChangeTrack(); }; +class ScUndoRefConversion: public ScSimpleUndo +{ +public: + TYPEINFO(); + ScUndoRefConversion( ScDocShell* pNewDocShell, + const ScRange& aMarkRange, const ScMarkData& rMark, + ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc, BOOL bNewMulti, USHORT nNewFlag); + virtual ~ScUndoRefConversion(); + + virtual void Undo(); + virtual void Redo(); + virtual void Repeat(SfxRepeatTarget& rTarget); + virtual BOOL CanRepeat(SfxRepeatTarget& rTarget) const; + + virtual String GetComment() const; + +private: + ScMarkData aMarkData; + ScDocument* pUndoDoc; + ScDocument* pRedoDoc; + ScRange aRange; + BOOL bMulti; + USHORT nFlags; + ULONG nStartChangeAction; + ULONG nEndChangeAction; + + void DoChange( ScDocument* pRefDoc); + void SetChangeTrack(); +}; class ScUndoListNames: public ScBlockUndo { diff -uPr old/sc/source/ui/inc/viewfunc.hxx new/sc/source/ui/inc/viewfunc.hxx --- old/sc/source/ui/inc/viewfunc.hxx 2009-04-16 13:06:06.000000000 +0800 +++ new/sc/source/ui/inc/viewfunc.hxx 2009-06-05 12:09:06.000000000 +0800 @@ -300,6 +300,7 @@ void SetNoteText( const ScAddress& rPos, const String& rNoteText ); void ReplaceNote( const ScAddress& rPos, const String& rNoteText, const String* pAuthor, const String* pDate ); + void DoRefConversion( BOOL bRecord = TRUE ); //UNUSED2008-05 void DoSpellingChecker( BOOL bRecord = TRUE ); void DoHangulHanjaConversion( BOOL bRecord = TRUE ); diff -uPr old/sc/source/ui/undo/undoblk3.cxx new/sc/source/ui/undo/undoblk3.cxx --- old/sc/source/ui/undo/undoblk3.cxx 2009-04-16 13:03:34.000000000 +0800 +++ new/sc/source/ui/undo/undoblk3.cxx 2009-06-09 10:30:10.000000000 +0800 @@ -74,6 +74,7 @@ TYPEINIT1(ScUndoReplace, SfxUndoAction); TYPEINIT1(ScUndoTabOp, SfxUndoAction); TYPEINIT1(ScUndoConversion, SfxUndoAction); +TYPEINIT1(ScUndoRefConversion, SfxUndoAction); TYPEINIT1(ScUndoRefreshLink, SfxUndoAction); TYPEINIT1(ScUndoInsertAreaLink, SfxUndoAction); TYPEINIT1(ScUndoRemoveAreaLink, SfxUndoAction); @@ -1531,6 +1532,98 @@ //============================================================================ +// class ScUndoRefConversion +// +// cell reference conversion + +//---------------------------------------------------------------------------- + +ScUndoRefConversion::ScUndoRefConversion( ScDocShell* pNewDocShell, + const ScRange& aMarkRange, const ScMarkData& rMark, + ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc, BOOL bNewMulti, USHORT nNewFlag) : +ScSimpleUndo( pNewDocShell ), +aRange ( aMarkRange ), +aMarkData ( rMark ), +pUndoDoc ( pNewUndoDoc ), +pRedoDoc ( pNewRedoDoc ), +bMulti ( bNewMulti ), +nFlags ( nNewFlag ) +{ + SetChangeTrack(); +} + +__EXPORT ScUndoRefConversion::~ScUndoRefConversion() +{ + delete pUndoDoc; + delete pRedoDoc; +} + +String __EXPORT ScUndoRefConversion::GetComment() const +{ + return ScGlobal::GetRscString( STR_UNDO_ENTERDATA ); // "Eingabe" +} + +void ScUndoRefConversion::SetChangeTrack() +{ + ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack(); + if ( pChangeTrack && (nFlags & IDF_FORMULA) ) + pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc, + nStartChangeAction, nEndChangeAction ); + else + nStartChangeAction = nEndChangeAction = 0; +} + +void ScUndoRefConversion::DoChange( ScDocument* pRefDoc) +{ + ScDocument* pDoc = pDocShell->GetDocument(); + + ShowTable(aRange); + + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (pViewShell) + pViewShell->SetMarkData( aMarkData ); + + ScRange aCopyRange = aRange; + SCTAB nTabCount = pDoc->GetTableCount(); + aCopyRange.aStart.SetTab(0); + aCopyRange.aEnd.SetTab(nTabCount-1); + pRefDoc->CopyToDocument( aCopyRange, nFlags, bMulti, pDoc, &aMarkData ); + pDocShell->PostPaint( aRange, PAINT_GRID); + pDocShell->PostDataChanged(); + if (pViewShell) + pViewShell->CellContentChanged(); +} +void __EXPORT ScUndoRefConversion::Undo() +{ + BeginUndo(); + if (pUndoDoc) + DoChange(pUndoDoc); + ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack(); + if ( pChangeTrack ) + pChangeTrack->Undo( nStartChangeAction, nEndChangeAction ); + EndUndo(); +} + +void __EXPORT ScUndoRefConversion::Redo() +{ + BeginRedo(); + if (pRedoDoc) + DoChange(pRedoDoc); + SetChangeTrack(); + EndRedo(); +} + +void __EXPORT ScUndoRefConversion::Repeat(SfxRepeatTarget& rTarget) +{ + if (rTarget.ISA(ScTabViewTarget)) + ((ScTabViewTarget&)rTarget).GetViewShell()->DoRefConversion(); +} + +BOOL __EXPORT ScUndoRefConversion::CanRepeat(SfxRepeatTarget& rTarget) const +{ + return (rTarget.ISA(ScTabViewTarget)); +} +//============================================================================ // class ScUndoRefreshLink // // Link aktualisieren / aendern diff -uPr old/sc/source/ui/view/cellsh1.cxx new/sc/source/ui/view/cellsh1.cxx --- old/sc/source/ui/view/cellsh1.cxx 2009-04-16 13:06:50.000000000 +0800 +++ new/sc/source/ui/view/cellsh1.cxx 2009-06-03 14:04:40.000000000 +0800 @@ -1709,32 +1709,7 @@ break; case SID_TOGGLE_REL: - { - BOOL bOk = FALSE; - SCCOL nCol = GetViewData()->GetCurX(); - SCROW nRow = GetViewData()->GetCurY(); - SCTAB nTab = GetViewData()->GetTabNo(); - ScDocument* pDoc = GetViewData()->GetDocument(); - CellType eType; - pDoc->GetCellType( nCol, nRow, nTab, eType ); - if (eType == CELLTYPE_FORMULA) - { - String aOld; - pDoc->GetFormula( nCol, nRow, nTab, aOld ); - xub_StrLen nLen = aOld.Len(); - ScRefFinder aFinder( aOld, pDoc ); - aFinder.ToggleRel( 0, nLen ); - if (aFinder.GetFound()) - { - String aNew = aFinder.GetText(); - pTabViewShell->EnterData( nCol, nRow, nTab, aNew ); - pTabViewShell->UpdateInputHandler(); - bOk = TRUE; - } - } - if (!bOk) - pTabViewShell->ErrorMessage(STR_ERR_NOREF); - } + pTabViewShell->DoRefConversion(); break; case SID_DEC_INDENT: diff -uPr old/sc/source/ui/view/viewfun4.cxx new/sc/source/ui/view/viewfun4.cxx --- old/sc/source/ui/view/viewfun4.cxx 2009-04-16 13:06:48.000000000 +0800 +++ new/sc/source/ui/view/viewfun4.cxx 2009-06-09 09:18:40.000000000 +0800 @@ -81,6 +81,9 @@ #include "impex.hxx" #include "editutil.hxx" #include "editable.hxx" +#include "dociter.hxx" +#include "reffind.hxx" +#include "compiler.hxx" using namespace com::sun::star; @@ -187,7 +190,131 @@ ShowAllCursors(); } } +void ScViewFunc::DoRefConversion( BOOL bRecord ) +{ + ScDocument* pDoc = GetViewData()->GetDocument(); + ScMarkData& rMark = GetViewData()->GetMarkData(); + SCTAB nTabCount = pDoc->GetTableCount(); + SCTAB nSelCount = rMark.GetSelectCount(); + if (bRecord && !pDoc->IsUndoEnabled()) + bRecord = FALSE; + + ScRange aMarkRange; + rMark.MarkToSimple(); + BOOL bMulti = rMark.IsMultiMarked(); + if (bMulti) + rMark.GetMultiMarkArea( aMarkRange ); + else if (rMark.IsMarked()) + rMark.GetMarkArea( aMarkRange ); + else + { + aMarkRange = ScRange( GetViewData()->GetCurX(), + GetViewData()->GetCurY(), GetViewData()->GetTabNo() ); + } + ScEditableTester aTester( pDoc, aMarkRange.aStart.Col(), aMarkRange.aStart.Row(), + aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(),rMark ); + if (!aTester.IsEditable()) + { + ErrorMessage(aTester.GetMessageId()); + return; + } + + ScDocShell* pDocSh = GetViewData()->GetDocShell(); + BOOL bOk = FALSE; + + ScDocument* pUndoDoc = NULL; + if (bRecord) + { + pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); + SCTAB nTab = aMarkRange.aStart.Tab(); + pUndoDoc->InitUndo( pDoc, nTab, nTab ); + SCTAB nTabCount = pDoc->GetTableCount(); + if ( rMark.GetSelectCount() > 1 ) + { + for (SCTAB i=0; iAddUndoTab( i, i ); + } + ScRange aCopyRange = aMarkRange; + aCopyRange.aStart.SetTab(0); + aCopyRange.aEnd.SetTab(nTabCount-1); + pDoc->CopyToDocument( aCopyRange, IDF_ALL, bMulti, pUndoDoc, &rMark ); + } + + ScRangeListRef xRanges; + GetViewData()->GetMultiArea( xRanges ); + ULONG nCount = xRanges->Count(); + + for (SCTAB i=0; iGetObject(j); + aRange.aStart.SetTab(i); + aRange.aEnd.SetTab(i); + ScCellIterator aIter( pDoc, aRange ); + ScBaseCell* pCell = aIter.GetFirst(); + while ( pCell ) + { + if (pCell->GetCellType() == CELLTYPE_FORMULA) + { + String aOld; + ((ScFormulaCell*)pCell)->GetFormula(aOld); + xub_StrLen nLen = aOld.Len(); + ScRefFinder aFinder( aOld, pDoc ); + aFinder.ToggleRel( 0, nLen ); + if (aFinder.GetFound()) + { + ScAddress aPos = ((ScFormulaCell*)pCell)->aPos; + String aNew = aFinder.GetText(); + ScCompiler aComp( pDoc, aPos); + aComp.SetGrammar(pDoc->GetGrammar()); + ScTokenArray* pArr = aComp.CompileString( aNew ); + ScFormulaCell* pNewCell = new ScFormulaCell( pDoc, aPos, + pArr,formula::FormulaGrammar::GRAM_DEFAULT, MM_NONE ); + pDoc->PutCell( aPos, pNewCell ); + bOk = TRUE; + } + } + pCell = aIter.GetNext(); + } + } + } + } + if (bRecord) + { + ScDocument* pRedoDoc = new ScDocument( SCDOCMODE_UNDO ); + SCTAB nTab = aMarkRange.aStart.Tab(); + pRedoDoc->InitUndo( pDoc, nTab, nTab ); + + SCTAB nTabCount = pDoc->GetTableCount(); + if ( rMark.GetSelectCount() > 1 ) + { + for (SCTAB i=0; iAddUndoTab( i, i ); + } + ScRange aCopyRange = aMarkRange; + aCopyRange.aStart.SetTab(0); + aCopyRange.aEnd.SetTab(nTabCount-1); + pDoc->CopyToDocument( aCopyRange, IDF_ALL, bMulti, pRedoDoc, &rMark ); + + pDocSh->GetUndoManager()->AddUndoAction( + new ScUndoRefConversion( pDocSh, + aMarkRange, rMark, pUndoDoc, pRedoDoc, bMulti, IDF_ALL) ); + } + + pDocSh->PostPaint( aMarkRange, PAINT_GRID ); + pDocSh->UpdateOle(GetViewData()); + pDocSh->SetDocumentModified(); + CellContentChanged(); + + if (!bOk) + ErrorMessage(STR_ERR_NOREF); +} // Thesaurus - Undo ok void ScViewFunc::DoThesaurus( BOOL bRecord ) {