diff options
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 34 | ||||
-rw-r--r-- | sc/source/ui/inc/docfunc.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/inc/undoconvert.hxx | 37 | ||||
-rw-r--r-- | sc/source/ui/inc/viewfunc.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/src/globstr.src | 5 | ||||
-rw-r--r-- | sc/source/ui/undo/undoconvert.cxx | 51 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh1.cxx | 5 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun2.cxx | 11 |
8 files changed, 146 insertions, 0 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index c20992abf876..f3a6245ca7d4 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -84,6 +84,8 @@ #include "cellvalue.hxx" #include "tokenarray.hxx" #include <rowheightcontext.hxx> +#include <cellvalues.hxx> +#include <undoconvert.hxx> #include <memory> #include <utility> @@ -5384,6 +5386,38 @@ void ScDocFunc::SetConditionalFormatList( ScConditionalFormatList* pList, SCTAB SfxGetpApp()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED)); } +void ScDocFunc::ConvertFormulaToValue( const ScRange& rRange, bool bRecord, bool bInteraction ) +{ + ScDocShellModificator aModificator(rDocShell); + ScDocument& rDoc = rDocShell.GetDocument(); + if (!rDoc.IsUndoEnabled()) + bRecord = false; + + ScEditableTester aTester(&rDoc, rRange); + if (!aTester.IsEditable()) + { + if (bInteraction) + rDocShell.ErrorMessage(aTester.GetMessageId()); + return; + } + + sc::TableValues aUndoVals(rRange); + sc::TableValues* pUndoVals = bRecord ? &aUndoVals : NULL; + + rDoc.ConvertFormulaToValue(rRange, pUndoVals); + + if (bRecord && pUndoVals) + { + rDocShell.GetUndoManager()->AddUndoAction( + new sc::UndoFormulaToValue(&rDocShell, *pUndoVals)); + } + + rDocShell.PostPaint(rRange, PAINT_GRID); + rDocShell.PostDataChanged(); + rDoc.BroadcastCells(rRange, SC_HINT_DATACHANGED); + aModificator.SetDocumentModified(); +} + void ScDocFunc::EnterListAction( sal_uInt16 nNameResId ) { OUString aUndo( ScGlobal::GetRscString( nNameResId ) ); diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index 37bf4aac12b7..ebd7ac371aeb 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -222,6 +222,8 @@ public: * @param nTab the tab to which the conditional format list belongs */ void SetConditionalFormatList( ScConditionalFormatList* pList, SCTAB nTab ); + + void ConvertFormulaToValue( const ScRange& rRange, bool bRecord, bool bInteraction ); }; class ScDocFuncDirect : public ScDocFunc diff --git a/sc/source/ui/inc/undoconvert.hxx b/sc/source/ui/inc/undoconvert.hxx new file mode 100644 index 000000000000..99ce97f51e7c --- /dev/null +++ b/sc/source/ui/inc/undoconvert.hxx @@ -0,0 +1,37 @@ +/* -*- 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 INCLUDED_SC_UNDOCONVERT_HXX +#define INCLUDED_SC_UNDOCONVERT_HXX + +#include <undobase.hxx> +#include <cellvalues.hxx> + +namespace sc { + +class UndoFormulaToValue : public ScSimpleUndo +{ + TableValues maUndoValues; + +public: + UndoFormulaToValue( ScDocShell* pDocSh, TableValues& rUndoValues ); + + virtual OUString GetComment() const SAL_OVERRIDE; + virtual void Undo() SAL_OVERRIDE; + virtual void Redo() SAL_OVERRIDE; + +private: + void Execute(); +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx index cd664cd5b45d..70c7e0f8df4b 100644 --- a/sc/source/ui/inc/viewfunc.hxx +++ b/sc/source/ui/inc/viewfunc.hxx @@ -240,6 +240,7 @@ public: void FillAuto( FillDir eDir, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount, bool bRecord = true ); void FillCrossDblClick(); + void ConvertFormulaToValue(); void TransliterateText( sal_Int32 nType ); diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src index 3d167fdef221..985644afec1f 100644 --- a/sc/source/ui/src/globstr.src +++ b/sc/source/ui/src/globstr.src @@ -2076,6 +2076,11 @@ Resource RID_GLOBSTR { Text [ en-US ] = "Conditional Format"; }; + + String STR_UNDO_FORMULA_TO_VALUE + { + Text [ en-US ] = "Convert Formula To Value"; + }; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/undo/undoconvert.cxx b/sc/source/ui/undo/undoconvert.cxx new file mode 100644 index 000000000000..995ab8f3e2fd --- /dev/null +++ b/sc/source/ui/undo/undoconvert.cxx @@ -0,0 +1,51 @@ +/* -*- 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 <undoconvert.hxx> +#include <globstr.hrc> +#include <undoutil.hxx> + +namespace sc { + +UndoFormulaToValue::UndoFormulaToValue( ScDocShell* pDocSh, TableValues& rUndoValues ) : + ScSimpleUndo(pDocSh) +{ + maUndoValues.swap(rUndoValues); +} + +OUString UndoFormulaToValue::GetComment() const +{ + return ScGlobal::GetRscString(STR_UNDO_FORMULA_TO_VALUE); +} + +void UndoFormulaToValue::Undo() +{ + Execute(); +} + +void UndoFormulaToValue::Redo() +{ + Execute(); +} + +void UndoFormulaToValue::Execute() +{ + ScDocument& rDoc = pDocShell->GetDocument(); + rDoc.SwapNonEmpty(maUndoValues); + + ScUndoUtil::MarkSimpleBlock(pDocShell, maUndoValues.getRange()); + + pDocShell->PostPaint(maUndoValues.getRange(), PAINT_GRID); + pDocShell->PostDataChanged(); + rDoc.BroadcastCells(maUndoValues.getRange(), SC_HINT_DATACHANGED); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index bb9ce1ad1cae..511d4b7e2e9d 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -1754,6 +1754,11 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) } break; + case SID_CONVERT_FORMULA_TO_VALUE: + { + pTabViewShell->ConvertFormulaToValue(); + } + break; case SID_THESAURUS: pTabViewShell->DoThesaurus(); break; diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index df5fb973cb6e..1f395fc4aad6 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -1414,6 +1414,17 @@ void ScViewFunc::FillCrossDblClick() } } +void ScViewFunc::ConvertFormulaToValue() +{ + ScRange aRange; + GetViewData().GetSimpleArea(aRange); + aRange.Justify(); + + ScDocShell* pDocSh = GetViewData().GetDocShell(); + pDocSh->GetDocFunc().ConvertFormulaToValue(aRange, true, true); + pDocSh->PostPaint(aRange, PAINT_GRID); +} + void ScViewFunc::TransliterateText( sal_Int32 nType ) { ScMarkData aFuncMark = GetViewData().GetMarkData(); |