/src/libreoffice/sc/source/ui/operation/SetValueOperation.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #include <operation/SetValueOperation.hxx> |
11 | | |
12 | | #include <docfuncutil.hxx> |
13 | | #include <docfunc.hxx> |
14 | | #include <address.hxx> |
15 | | #include <editable.hxx> |
16 | | #include <undocell.hxx> |
17 | | #include <validat.hxx> |
18 | | #include <stringutil.hxx> |
19 | | |
20 | | #include <memory> |
21 | | |
22 | | namespace sc |
23 | | { |
24 | | SetValueOperation::SetValueOperation(ScDocFunc& rDocFunc, ScDocShell& rDocShell, |
25 | | const ScAddress& rPosition, double fValue, bool bApi) |
26 | 0 | : Operation(OperationType::SetValue, true, bApi) |
27 | 0 | , mrDocFunc(rDocFunc) |
28 | 0 | , mrDocShell(rDocShell) |
29 | 0 | , mrPosition(rPosition) |
30 | 0 | , mfValue(fValue) |
31 | 0 | { |
32 | 0 | } |
33 | | |
34 | | bool SetValueOperation::runImplementation() |
35 | 0 | { |
36 | 0 | ScAddress aPosition = convertAddress(mrPosition); |
37 | |
|
38 | 0 | ScDocShellModificator aModificator(mrDocShell); |
39 | 0 | ScDocument& rDoc = mrDocShell.GetDocument(); |
40 | 0 | bool bUndo = rDoc.IsUndoEnabled(); |
41 | 0 | bool bHeight = rDoc.HasAttrib(ScRange(aPosition), HasAttrFlags::NeedHeight); |
42 | |
|
43 | 0 | ScCellValue aOldVal; |
44 | 0 | if (bUndo) |
45 | 0 | aOldVal.assign(rDoc, aPosition); |
46 | |
|
47 | 0 | rDoc.SetValue(aPosition, mfValue); |
48 | |
|
49 | 0 | ScUndoSetCell* pUndoSetCell = nullptr; |
50 | 0 | if (bUndo) |
51 | 0 | { |
52 | 0 | SfxUndoManager* pUndoMgr = mrDocShell.GetUndoManager(); |
53 | 0 | ScCellValue aNewVal; |
54 | 0 | aNewVal.assign(rDoc, aPosition); |
55 | 0 | auto pUndoAction = std::make_unique<ScUndoSetCell>(mrDocShell, aPosition, aOldVal, aNewVal); |
56 | 0 | pUndoSetCell = pUndoAction.get(); |
57 | 0 | pUndoMgr->AddUndoAction(std::move(pUndoAction)); |
58 | 0 | } |
59 | |
|
60 | 0 | syncCellToSheetViews(aPosition, pUndoSetCell); |
61 | |
|
62 | 0 | if (bHeight) |
63 | 0 | mrDocFunc.AdjustRowHeight(ScRange(aPosition), true, mbApi); |
64 | |
|
65 | 0 | mrDocShell.PostPaintCell(aPosition); |
66 | 0 | aModificator.SetDocumentModified(); |
67 | | |
68 | | // #103934#; notify editline and cell in edit mode |
69 | 0 | if (mbApi) |
70 | 0 | mrDocFunc.NotifyInputHandler(aPosition); |
71 | |
|
72 | 0 | mrDocShell.ResolveSpilledOutputs(); |
73 | |
|
74 | 0 | return true; |
75 | 0 | } |
76 | | } // end sc namespace |
77 | | |
78 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |