summaryrefslogtreecommitdiff
path: root/sc/source/ui
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-02-27 23:22:21 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-02-27 23:23:09 -0500
commitc177e1cbec9da5c33b57b55493bbeae198051b6f (patch)
tree6ab5082d277599868657bc74a387999922cf85ed /sc/source/ui
parent10e3474d9096fa6428a6d68e6e486293c323d4a1 (diff)
Simplify ScViewFunc::DoThesaurus() with ScCellValue.
Change-Id: Ic5d31107aa7653cd8e3fae096888bd633696074f
Diffstat (limited to 'sc/source/ui')
-rw-r--r--sc/source/ui/inc/undocell.hxx17
-rw-r--r--sc/source/ui/undo/undocell.cxx76
-rw-r--r--sc/source/ui/view/viewfun4.cxx69
3 files changed, 47 insertions, 115 deletions
diff --git a/sc/source/ui/inc/undocell.hxx b/sc/source/ui/inc/undocell.hxx
index 3562983edf62..6bda9c7b8c88 100644
--- a/sc/source/ui/inc/undocell.hxx
+++ b/sc/source/ui/inc/undocell.hxx
@@ -229,10 +229,9 @@ class ScUndoThesaurus: public ScSimpleUndo
{
public:
TYPEINFO();
- ScUndoThesaurus( ScDocShell* pNewDocShell,
- SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
- const OUString& rNewUndoStr, const EditTextObject* pUndoTObj,
- const OUString& rNewRedoStr, const EditTextObject* pRedoTObj);
+ ScUndoThesaurus( ScDocShell* pNewDocShell,
+ SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
+ const ScCellValue& rOldText, const ScCellValue& rNewText );
virtual ~ScUndoThesaurus();
virtual void Undo();
@@ -246,14 +245,12 @@ private:
SCCOL nCol;
SCROW nRow;
SCTAB nTab;
- OUString aUndoStr; // Data at String cell
- EditTextObject* pUndoTObject; // at Edit cell
- OUString aRedoStr;
- EditTextObject* pRedoTObject;
sal_uLong nEndChangeAction;
- void DoChange( bool bUndo, const OUString& rStr,
- const EditTextObject* pTObj );
+ ScCellValue maOldText;
+ ScCellValue maNewText;
+
+ void DoChange( bool bUndo, const ScCellValue& rText );
void SetChangeTrack( const ScCellValue& rOldCell );
};
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index 7a6f4e1b9445..60f659458396 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -646,39 +646,20 @@ bool ScUndoPrintZoom::CanRepeat(SfxRepeatTarget& rTarget) const
return rTarget.ISA(ScTabViewTarget);
}
-ScUndoThesaurus::ScUndoThesaurus( ScDocShell* pNewDocShell,
- SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
- const OUString& rNewUndoStr, const EditTextObject* pUndoTObj,
- const OUString& rNewRedoStr, const EditTextObject* pRedoTObj) :
+ScUndoThesaurus::ScUndoThesaurus(
+ ScDocShell* pNewDocShell, SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
+ const ScCellValue& rOldText, const ScCellValue& rNewText ) :
ScSimpleUndo( pNewDocShell ),
nCol( nNewCol ),
nRow( nNewRow ),
nTab( nNewTab ),
- aUndoStr( rNewUndoStr ),
- aRedoStr( rNewRedoStr )
+ maOldText(rOldText),
+ maNewText(rNewText)
{
- pUndoTObject = (pUndoTObj) ? pUndoTObj->Clone() : NULL;
- pRedoTObject = (pRedoTObj) ? pRedoTObj->Clone() : NULL;
-
- ScCellValue aOldCell;
- if ( pUndoTObject )
- {
- aOldCell.meType = CELLTYPE_EDIT;
- aOldCell.mpEditText = pUndoTObject->Clone();
- }
- else
- {
- aOldCell.meType = CELLTYPE_STRING;
- aOldCell.mpString = new svl::SharedString(pDocShell->GetDocument()->GetSharedStringPool().intern(aUndoStr));
- }
- SetChangeTrack(aOldCell);
+ SetChangeTrack(maOldText);
}
-ScUndoThesaurus::~ScUndoThesaurus()
-{
- delete pUndoTObject;
- delete pRedoTObject;
-}
+ScUndoThesaurus::~ScUndoThesaurus() {}
OUString ScUndoThesaurus::GetComment() const
{
@@ -699,8 +680,7 @@ void ScUndoThesaurus::SetChangeTrack( const ScCellValue& rOldCell )
nEndChangeAction = 0;
}
-void ScUndoThesaurus::DoChange( bool bUndo, const OUString& rStr,
- const EditTextObject* pTObj )
+void ScUndoThesaurus::DoChange( bool bUndo, const ScCellValue& rText )
{
ScDocument* pDoc = pDocShell->GetDocument();
@@ -712,39 +692,9 @@ void ScUndoThesaurus::DoChange( bool bUndo, const OUString& rStr,
}
ScAddress aPos(nCol, nRow, nTab);
-
- if (pTObj)
- {
- // This is edit text.
- if (pDoc->GetCellType(aPos) == CELLTYPE_EDIT)
- {
- ScCellValue aOldCell;
- if (!bUndo)
- aOldCell.assign(*pDoc, aPos);
-
- // A copy of pTObj will be stored in the cell.
- pDoc->SetEditText(aPos, *pTObj, pDoc->GetEditPool());
-
- if ( !bUndo )
- SetChangeTrack(aOldCell);
- }
- else
- {
- OSL_FAIL("Not CELLTYPE_EDIT for Un/RedoThesaurus");
- }
- }
- else
- {
- // This is simple unformatted string.
- ScCellValue aOldCell;
- if (!bUndo)
- aOldCell.assign(*pDoc, aPos);
-
- pDoc->SetString( nCol, nRow, nTab, rStr );
-
- if (!bUndo)
- SetChangeTrack(aOldCell);
- }
+ rText.commit(*pDoc, aPos);
+ if (!bUndo)
+ SetChangeTrack(maOldText);
pDocShell->PostPaintCell( nCol, nRow, nTab );
}
@@ -752,7 +702,7 @@ void ScUndoThesaurus::DoChange( bool bUndo, const OUString& rStr,
void ScUndoThesaurus::Undo()
{
BeginUndo();
- DoChange( true, aUndoStr, pUndoTObject );
+ DoChange(true, maOldText);
ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
@@ -762,7 +712,7 @@ void ScUndoThesaurus::Undo()
void ScUndoThesaurus::Redo()
{
BeginRedo();
- DoChange( false, aRedoStr, pRedoTObject );
+ DoChange(false, maNewText);
EndRedo();
}
diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx
index 526160916eff..352ed4f21352 100644
--- a/sc/source/ui/view/viewfun4.cxx
+++ b/sc/source/ui/view/viewfun4.cxx
@@ -38,6 +38,7 @@
#include <svl/stritem.hxx>
#include <svtools/transfer.hxx>
#include <svl/urlbmk.hxx>
+#include <svl/sharedstringpool.hxx>
#include <vcl/msgbox.hxx>
#include <avmedia/mediawindow.hxx>
@@ -311,12 +312,9 @@ void ScViewFunc::DoThesaurus( bool bRecord )
ScMarkData& rMark = GetViewData()->GetMarkData();
ScSplitPos eWhich = GetViewData()->GetActivePart();
EESpellState eState;
- OUString sOldText, sNewString;
- EditTextObject* pOldTObj = NULL;
- const EditTextObject* pTObject = NULL;
EditView* pEditView = NULL;
boost::scoped_ptr<ESelection> pEditSel;
- ScEditEngineDefaulter* pThesaurusEngine;
+ boost::scoped_ptr<ScEditEngineDefaulter> pThesaurusEngine;
bool bIsEditMode = GetViewData()->HasEditView(eWhich);
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = false;
@@ -342,8 +340,9 @@ void ScViewFunc::DoThesaurus( bool bRecord )
return;
}
- CellType eCellType = pDoc->GetCellType(aPos);
- if (eCellType != CELLTYPE_STRING && eCellType != CELLTYPE_EDIT)
+ ScCellValue aOldText;
+ aOldText.assign(*pDoc, aPos);
+ if (aOldText.meType != CELLTYPE_STRING && aOldText.meType != CELLTYPE_EDIT)
{
ErrorMessage(STR_THESAURUS_NO_STRING);
return;
@@ -351,38 +350,26 @@ void ScViewFunc::DoThesaurus( bool bRecord )
uno::Reference<linguistic2::XSpellChecker1> xSpeller = LinguMgr::GetSpellChecker();
- pThesaurusEngine = new ScEditEngineDefaulter( pDoc->GetEnginePool() );
+ pThesaurusEngine.reset(new ScEditEngineDefaulter(pDoc->GetEnginePool()));
pThesaurusEngine->SetEditTextObjectPool( pDoc->GetEditPool() );
pThesaurusEngine->SetRefDevice(GetViewData()->GetActiveWin());
pThesaurusEngine->SetSpeller(xSpeller);
- MakeEditView(pThesaurusEngine, nCol, nRow );
+ MakeEditView(pThesaurusEngine.get(), nCol, nRow );
const ScPatternAttr* pPattern = NULL;
- SfxItemSet* pEditDefaults = new SfxItemSet(pThesaurusEngine->GetEmptyItemSet());
+ boost::scoped_ptr<SfxItemSet> pEditDefaults(
+ new SfxItemSet(pThesaurusEngine->GetEmptyItemSet()));
pPattern = pDoc->GetPattern(nCol, nRow, nTab);
if (pPattern)
{
- pPattern->FillEditItemSet( pEditDefaults );
+ pPattern->FillEditItemSet( pEditDefaults.get() );
pThesaurusEngine->SetDefaults( *pEditDefaults );
}
- if (eCellType == CELLTYPE_STRING)
- {
- sOldText = pDoc->GetString(aPos);
- pThesaurusEngine->SetText(sOldText);
- }
- else if (eCellType == CELLTYPE_EDIT)
- {
- pTObject = pDoc->GetEditText(aPos);
- if (pTObject)
- {
- pOldTObj = pTObject->Clone();
- pThesaurusEngine->SetText(*pTObject);
- }
- }
+ if (aOldText.meType == CELLTYPE_EDIT)
+ pThesaurusEngine->SetText(*aOldText.mpEditText);
else
- {
- OSL_FAIL("DoThesaurus: Keine String oder Editzelle");
- }
+ pThesaurusEngine->SetText(aOldText.getString(pDoc));
+
pEditView = GetViewData()->GetEditView(GetViewData()->GetActivePart());
if (pEditSel)
pEditView->SetSelection(*pEditSel);
@@ -407,34 +394,32 @@ void ScViewFunc::DoThesaurus( bool bRecord )
}
if (pThesaurusEngine->IsModified())
{
- EditTextObject* pNewTObj = NULL;
- if (pTObject)
+ ScCellValue aNewText;
+
+ if (aOldText.meType == CELLTYPE_EDIT)
{
// The cell will own the text object instance.
- pDoc->SetEditText(
- ScAddress(nCol,nRow,nTab), pThesaurusEngine->CreateTextObject());
+ EditTextObject* pText = pThesaurusEngine->CreateTextObject();
+ pDoc->SetEditText(ScAddress(nCol,nRow,nTab), pText);
+ aNewText.set(*pText);
}
else
{
- sNewString = pThesaurusEngine->GetText();
- pDoc->SetString(nCol, nRow, nTab, sNewString);
+ OUString aStr = pThesaurusEngine->GetText();
+ aNewText.set(pDoc->GetSharedStringPool().intern(aStr));
+ pDoc->SetString(nCol, nRow, nTab, aStr);
}
-// erack! it's broadcasted
-// pDoc->SetDirty();
+
pDocSh->SetDocumentModified();
if (bRecord)
{
GetViewData()->GetDocShell()->GetUndoManager()->AddUndoAction(
- new ScUndoThesaurus( GetViewData()->GetDocShell(),
- nCol, nRow, nTab,
- sOldText, pOldTObj, sNewString, pNewTObj));
+ new ScUndoThesaurus(
+ GetViewData()->GetDocShell(), nCol, nRow, nTab, aOldText, aNewText));
}
- delete pNewTObj;
}
+
KillEditView(true);
- delete pEditDefaults;
- delete pThesaurusEngine;
- delete pOldTObj;
pDocSh->PostPaintGridAll();
}