[Libreoffice-commits] core.git: sc/inc sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Thu Feb 27 20:24:49 PST 2014
sc/inc/cellvalue.hxx | 2 +
sc/source/core/data/cellvalue.cxx | 43 +++++++++++++--------
sc/source/ui/inc/undocell.hxx | 17 +++-----
sc/source/ui/undo/undocell.cxx | 76 ++++++--------------------------------
sc/source/ui/view/viewfun4.cxx | 69 +++++++++++++---------------------
5 files changed, 76 insertions(+), 131 deletions(-)
New commits:
commit c177e1cbec9da5c33b57b55493bbeae198051b6f
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Thu Feb 27 23:22:21 2014 -0500
Simplify ScViewFunc::DoThesaurus() with ScCellValue.
Change-Id: Ic5d31107aa7653cd8e3fae096888bd633696074f
diff --git a/sc/inc/cellvalue.hxx b/sc/inc/cellvalue.hxx
index dd07d1c..08cd8ce 100644
--- a/sc/inc/cellvalue.hxx
+++ b/sc/inc/cellvalue.hxx
@@ -77,6 +77,8 @@ struct SC_DLLPUBLIC ScCellValue
void release( ScColumn& rColumn, SCROW nRow );
+ OUString getString( const ScDocument* pDoc );
+
bool isEmpty() const;
bool equalsWithoutFormat( const ScCellValue& r ) const;
diff --git a/sc/source/core/data/cellvalue.cxx b/sc/source/core/data/cellvalue.cxx
index 0a9d53d..3155f98 100644
--- a/sc/source/core/data/cellvalue.cxx
+++ b/sc/source/core/data/cellvalue.cxx
@@ -154,6 +154,27 @@ bool hasNumericImpl( CellType eType, ScFormulaCell* pFormula )
}
}
+template<typename _CellT>
+OUString getStringImpl( const _CellT& rCell, const ScDocument* pDoc )
+{
+ switch (rCell.meType)
+ {
+ case CELLTYPE_VALUE:
+ return OUString::number(rCell.mfValue);
+ case CELLTYPE_STRING:
+ return rCell.mpString->getString();
+ case CELLTYPE_EDIT:
+ if (rCell.mpEditText)
+ return ScEditUtil::GetString(*rCell.mpEditText, pDoc);
+ break;
+ case CELLTYPE_FORMULA:
+ return rCell.mpFormula->GetString().getString();
+ default:
+ ;
+ }
+ return EMPTY_OUSTRING;
+}
+
}
ScCellValue::ScCellValue() : meType(CELLTYPE_NONE), mfValue(0.0) {}
@@ -442,6 +463,11 @@ void ScCellValue::release( ScColumn& rColumn, SCROW nRow )
mfValue = 0.0;
}
+OUString ScCellValue::getString( const ScDocument* pDoc )
+{
+ return getStringImpl(*this, pDoc);
+}
+
bool ScCellValue::isEmpty() const
{
return meType == CELLTYPE_NONE;
@@ -553,22 +579,7 @@ double ScRefCellValue::getValue()
OUString ScRefCellValue::getString( const ScDocument* pDoc )
{
- switch (meType)
- {
- case CELLTYPE_VALUE:
- return OUString::number(mfValue);
- case CELLTYPE_STRING:
- return mpString->getString();
- case CELLTYPE_EDIT:
- if (mpEditText)
- return ScEditUtil::GetString(*mpEditText, pDoc);
- break;
- case CELLTYPE_FORMULA:
- return mpFormula->GetString().getString();
- default:
- ;
- }
- return EMPTY_OUSTRING;
+ return getStringImpl(*this, pDoc);
}
bool ScRefCellValue::isEmpty() const
diff --git a/sc/source/ui/inc/undocell.hxx b/sc/source/ui/inc/undocell.hxx
index 3562983..6bda9c7 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 7a6f4e1..60f6594 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 5261609..352ed4f 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();
}
More information about the Libreoffice-commits
mailing list