diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-03-21 19:50:03 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-03-22 21:49:22 -0400 |
commit | 14afe7b9b057e5bbd68d41573884c8a85761712d (patch) | |
tree | 97758b002922bc7095e2dc2f9b32943fa127d139 | |
parent | 07bd80e7d94d90be0bc8059e98eade6b3ca2b6c6 (diff) |
Move ScCellValue into its own header/source files.
This can be used outside the undo code, like change tracking code.
Change-Id: Iad936acef0dacbd19d8c179da4713b1cdc7f9c84
-rw-r--r-- | sc/Library_sc.mk | 1 | ||||
-rw-r--r-- | sc/inc/cellvalue.hxx | 56 | ||||
-rw-r--r-- | sc/source/core/data/cellvalue.cxx | 116 | ||||
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 3 | ||||
-rw-r--r-- | sc/source/ui/inc/undocell.hxx | 45 | ||||
-rw-r--r-- | sc/source/ui/undo/undocell.cxx | 106 |
6 files changed, 184 insertions, 143 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index 48ebfd23d954..1935b7afb528 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -101,6 +101,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/core/data/bigrange \ sc/source/core/data/cell \ sc/source/core/data/cell2 \ + sc/source/core/data/cellvalue \ sc/source/core/data/clipparam \ sc/source/core/data/column \ sc/source/core/data/column2 \ diff --git a/sc/inc/cellvalue.hxx b/sc/inc/cellvalue.hxx new file mode 100644 index 000000000000..409e17853c3d --- /dev/null +++ b/sc/inc/cellvalue.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef __SC_CELLVALUE_HXX__ +#define __SC_CELLVALUE_HXX__ + +#include "global.hxx" + +class ScDocument; +class ScFormulaCell; +class EditTextObject; + +/** + * Store arbitrary cell value of any kind. It only stores cell value and + * nothing else. + */ +struct ScCellValue +{ + CellType meType; + union { + double mfValue; + OUString* mpString; + EditTextObject* mpEditText; + ScFormulaCell* mpFormula; + }; + + ScCellValue(); + ScCellValue( double fValue ); + ScCellValue( const OUString& rString ); + ScCellValue( const EditTextObject& rEditText ); + ScCellValue( const ScFormulaCell& rFormula ); + ScCellValue( const ScCellValue& r ); + ~ScCellValue(); + + void clear(); + + /** + * Take cell value from specified position in specified document. + */ + void assign( const ScDocument& rDoc, const ScAddress& rPos ); + + /** + * Set cell value at specified position in specified document. + */ + void commit( ScDocument& rDoc, const ScAddress& rPos ); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/cellvalue.cxx b/sc/source/core/data/cellvalue.cxx new file mode 100644 index 000000000000..fe038ced4393 --- /dev/null +++ b/sc/source/core/data/cellvalue.cxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "cellvalue.hxx" +#include "document.hxx" +#include "cell.hxx" +#include "editeng/editobj.hxx" +#include "stringutil.hxx" + +ScCellValue::ScCellValue() : meType(CELLTYPE_NONE), mfValue(0.0) {} +ScCellValue::ScCellValue( double fValue ) : meType(CELLTYPE_VALUE), mfValue(fValue) {} +ScCellValue::ScCellValue( const OUString& rString ) : meType(CELLTYPE_STRING), mpString(new OUString(rString)) {} +ScCellValue::ScCellValue( const EditTextObject& rEditText ) : meType(CELLTYPE_EDIT), mpEditText(rEditText.Clone()) {} +ScCellValue::ScCellValue( const ScFormulaCell& rFormula ) : meType(CELLTYPE_FORMULA), mpFormula(rFormula.Clone()) {} + +ScCellValue::ScCellValue( const ScCellValue& r ) : meType(r.meType), mfValue(r.mfValue) +{ + switch (r.meType) + { + case CELLTYPE_STRING: + mpString = new OUString(*r.mpString); + break; + case CELLTYPE_EDIT: + mpEditText = r.mpEditText->Clone(); + break; + case CELLTYPE_FORMULA: + mpFormula = r.mpFormula->Clone(); + break; + default: + ; + } +} + +ScCellValue::~ScCellValue() +{ + clear(); +} + +void ScCellValue::clear() +{ + switch (meType) + { + case CELLTYPE_STRING: + delete mpString; + break; + case CELLTYPE_EDIT: + delete mpEditText; + break; + case CELLTYPE_FORMULA: + mpFormula->Delete(); + break; + default: + ; + } + + // Reset to empty value. + meType = CELLTYPE_NONE; + mfValue = 0.0; +} + +void ScCellValue::assign( const ScDocument& rDoc, const ScAddress& rPos ) +{ + clear(); + + meType = rDoc.GetCellType(rPos); + switch (meType) + { + case CELLTYPE_STRING: + mpString = new OUString(rDoc.GetString(rPos)); + break; + case CELLTYPE_EDIT: + mpEditText = rDoc.GetEditText(rPos)->Clone(); + break; + case CELLTYPE_VALUE: + mfValue = rDoc.GetValue(rPos); + break; + case CELLTYPE_FORMULA: + mpFormula = rDoc.GetFormulaCell(rPos)->Clone(); + break; + default: + meType = CELLTYPE_NONE; // reset to empty. + } +} + +void ScCellValue::commit( ScDocument& rDoc, const ScAddress& rPos ) +{ + switch (meType) + { + case CELLTYPE_STRING: + { + ScSetStringParam aParam; + aParam.setTextInput(); + rDoc.SetString(rPos, *mpString, &aParam); + } + break; + case CELLTYPE_EDIT: + rDoc.SetEditText(rPos, mpEditText->Clone()); + break; + case CELLTYPE_VALUE: + rDoc.SetValue(rPos, mfValue); + break; + case CELLTYPE_FORMULA: + rDoc.SetFormulaCell(rPos, mpFormula->Clone()); + break; + default: + rDoc.SetEmptyCell(rPos); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index d3061e1a84c6..70ca4c353db8 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -81,6 +81,7 @@ #include "progress.hxx" #include "dpobject.hxx" #include "stringutil.hxx" +#include "cellvalue.hxx" #include <memory> #include <basic/basmgr.hxx> @@ -809,7 +810,7 @@ sal_Bool ScDocFunc::SetNormalString( bool& o_rbNumFmtSet, const ScAddress& rPos, namespace { -void pushUndoSetCell( ScDocShell& rDocShell, ScDocument* pDoc, const ScAddress& rPos, const ScUndoCellValue& rNewVal ) +void pushUndoSetCell( ScDocShell& rDocShell, ScDocument* pDoc, const ScAddress& rPos, const ScCellValue& rNewVal ) { svl::IUndoManager* pUndoMgr = rDocShell.GetUndoManager(); switch (pDoc->GetCellType(rPos)) diff --git a/sc/source/ui/inc/undocell.hxx b/sc/source/ui/inc/undocell.hxx index a9ff3f1c32e1..e550cc07cc21 100644 --- a/sc/source/ui/inc/undocell.hxx +++ b/sc/source/ui/inc/undocell.hxx @@ -22,6 +22,7 @@ #include "undobase.hxx" #include "postit.hxx" +#include "cellvalue.hxx" #include <boost/shared_ptr.hpp> #include <boost/scoped_ptr.hpp> @@ -36,40 +37,6 @@ class ScDetOpData; class ScRangeName; class ScDocument; -/** - * Store arbitrary cell value of any kind for undo objects. - */ -struct ScUndoCellValue -{ - CellType meType; - union { - double mfValue; - OUString* mpString; - EditTextObject* mpEditText; - ScFormulaCell* mpFormula; - }; - - ScUndoCellValue(); - ScUndoCellValue( double fValue ); - ScUndoCellValue( const OUString& rString ); - ScUndoCellValue( const EditTextObject& rEditText ); - ScUndoCellValue( const ScFormulaCell& rFormula ); - ScUndoCellValue( const ScUndoCellValue& r ); - ~ScUndoCellValue(); - - void clear(); - - /** - * Take cell value from specified position in specified document. - */ - void assign( const ScDocument& rDoc, const ScAddress& rPos ); - - /** - * Set cell value at specified position in specified document. - */ - void commit( ScDocument& rDoc, const ScAddress& rPos ); -}; - class ScUndoCursorAttr: public ScSimpleUndo { public: @@ -179,8 +146,8 @@ class ScUndoSetCell : public ScSimpleUndo { public: TYPEINFO(); - ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScUndoCellValue& rNewVal ); - ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScUndoCellValue& rOldVal, const ScUndoCellValue& rNewVal ); + ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScCellValue& rNewVal ); + ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScCellValue& rOldVal, const ScCellValue& rNewVal ); virtual ~ScUndoSetCell(); @@ -191,12 +158,12 @@ public: virtual OUString GetComment() const; private: - void SetValue( const ScUndoCellValue& rVal ); + void SetValue( const ScCellValue& rVal ); private: ScAddress maPos; - ScUndoCellValue maOldValue; - ScUndoCellValue maNewValue; + ScCellValue maOldValue; + ScCellValue maNewValue; }; class ScUndoPageBreak: public ScSimpleUndo diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx index 171a7587f0a7..574ddba62cc4 100644 --- a/sc/source/ui/undo/undocell.cxx +++ b/sc/source/ui/undo/undocell.cxx @@ -45,106 +45,6 @@ using ::boost::shared_ptr; -ScUndoCellValue::ScUndoCellValue() : meType(CELLTYPE_NONE), mfValue(0.0) {} -ScUndoCellValue::ScUndoCellValue( double fValue ) : meType(CELLTYPE_VALUE), mfValue(fValue) {} -ScUndoCellValue::ScUndoCellValue( const OUString& rString ) : meType(CELLTYPE_STRING), mpString(new OUString(rString)) {} -ScUndoCellValue::ScUndoCellValue( const EditTextObject& rEditText ) : meType(CELLTYPE_EDIT), mpEditText(rEditText.Clone()) {} -ScUndoCellValue::ScUndoCellValue( const ScFormulaCell& rFormula ) : meType(CELLTYPE_FORMULA), mpFormula(rFormula.Clone()) {} - -ScUndoCellValue::ScUndoCellValue( const ScUndoCellValue& r ) : meType(r.meType), mfValue(r.mfValue) -{ - switch (r.meType) - { - case CELLTYPE_STRING: - mpString = new OUString(*r.mpString); - break; - case CELLTYPE_EDIT: - mpEditText = r.mpEditText->Clone(); - break; - case CELLTYPE_FORMULA: - mpFormula = r.mpFormula->Clone(); - break; - default: - ; - } -} - -ScUndoCellValue::~ScUndoCellValue() -{ - clear(); -} - -void ScUndoCellValue::clear() -{ - switch (meType) - { - case CELLTYPE_STRING: - delete mpString; - break; - case CELLTYPE_EDIT: - delete mpEditText; - break; - case CELLTYPE_FORMULA: - mpFormula->Delete(); - break; - default: - ; - } - - // Reset to empty value. - meType = CELLTYPE_NONE; - mfValue = 0.0; -} - -void ScUndoCellValue::assign( const ScDocument& rDoc, const ScAddress& rPos ) -{ - clear(); - - meType = rDoc.GetCellType(rPos); - switch (meType) - { - case CELLTYPE_STRING: - mpString = new OUString(rDoc.GetString(rPos)); - break; - case CELLTYPE_EDIT: - mpEditText = rDoc.GetEditText(rPos)->Clone(); - break; - case CELLTYPE_VALUE: - mfValue = rDoc.GetValue(rPos); - break; - case CELLTYPE_FORMULA: - mpFormula = rDoc.GetFormulaCell(rPos)->Clone(); - break; - default: - meType = CELLTYPE_NONE; // reset to empty. - } -} - -void ScUndoCellValue::commit( ScDocument& rDoc, const ScAddress& rPos ) -{ - switch (meType) - { - case CELLTYPE_STRING: - { - ScSetStringParam aParam; - aParam.setTextInput(); - rDoc.SetString(rPos, *mpString, &aParam); - } - break; - case CELLTYPE_EDIT: - rDoc.SetEditText(rPos, mpEditText->Clone()); - break; - case CELLTYPE_VALUE: - rDoc.SetValue(rPos, mfValue); - break; - case CELLTYPE_FORMULA: - rDoc.SetFormulaCell(rPos, mpFormula->Clone()); - break; - default: - rDoc.SetEmptyCell(rPos); - } -} - TYPEINIT1(ScUndoCursorAttr, ScSimpleUndo); TYPEINIT1(ScUndoEnterData, ScSimpleUndo); TYPEINIT1(ScUndoEnterValue, ScSimpleUndo); @@ -515,10 +415,10 @@ sal_Bool ScUndoEnterValue::CanRepeat(SfxRepeatTarget& /* rTarget */) const return false; } -ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScUndoCellValue& rNewVal ) : +ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScCellValue& rNewVal ) : ScSimpleUndo(pDocSh), maPos(rPos), maNewValue(rNewVal) {} -ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScUndoCellValue& rOldVal, const ScUndoCellValue& rNewVal ) : +ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScCellValue& rOldVal, const ScCellValue& rNewVal ) : ScSimpleUndo(pDocSh), maPos(rPos), maOldValue(rOldVal), maNewValue(rNewVal) {} ScUndoSetCell::~ScUndoSetCell() {} @@ -554,7 +454,7 @@ OUString ScUndoSetCell::GetComment() const return ScGlobal::GetRscString(STR_UNDO_ENTERDATA); // "Input" } -void ScUndoSetCell::SetValue( const ScUndoCellValue& rVal ) +void ScUndoSetCell::SetValue( const ScCellValue& rVal ) { ScDocument* pDoc = pDocShell->GetDocument(); |