calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / sc / source / ui / docshell / editable.cxx
blob86bbb9f2e004b49f843ccd454561630507cf8b97
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <editable.hxx>
21 #include <document.hxx>
22 #include <viewfunc.hxx>
23 #include <globstr.hrc>
25 ScEditableTester::ScEditableTester() :
26 mbIsEditable(true),
27 mbOnlyMatrix(true)
31 ScEditableTester::ScEditableTester( const ScDocument& rDoc, SCTAB nTab,
32 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bNoMatrixAtAll ) :
33 mbIsEditable(true),
34 mbOnlyMatrix(true)
36 TestBlock( rDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow, bNoMatrixAtAll );
39 ScEditableTester::ScEditableTester( const ScDocument& rDoc,
40 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
41 const ScMarkData& rMark ) :
42 mbIsEditable(true),
43 mbOnlyMatrix(true)
45 TestSelectedBlock( rDoc, nStartCol, nStartRow, nEndCol, nEndRow, rMark );
48 ScEditableTester::ScEditableTester( const ScDocument& rDoc, const ScRange& rRange ) :
49 mbIsEditable(true),
50 mbOnlyMatrix(true)
52 TestRange( rDoc, rRange );
55 ScEditableTester::ScEditableTester( const ScDocument& rDoc, const ScMarkData& rMark ) :
56 mbIsEditable(true),
57 mbOnlyMatrix(true)
59 TestSelection( rDoc, rMark );
62 ScEditableTester::ScEditableTester( ScViewFunc* pView ) :
63 mbIsEditable(true),
64 mbOnlyMatrix(true)
66 bool bThisMatrix;
67 if ( !pView->SelectionEditable( &bThisMatrix ) )
69 mbIsEditable = false;
70 if ( !bThisMatrix )
71 mbOnlyMatrix = false;
75 ScEditableTester::ScEditableTester(
76 const ScDocument& rDoc, sc::ColRowEditAction eAction, SCCOLROW nStart, SCCOLROW nEnd, const ScMarkData& rMark ) :
77 ScEditableTester()
79 TestBlockForAction(rDoc, eAction, nStart, nEnd, rMark);
82 void ScEditableTester::TestBlock( const ScDocument& rDoc, SCTAB nTab,
83 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bNoMatrixAtAll )
85 if (mbIsEditable || mbOnlyMatrix)
87 bool bThisMatrix;
88 if (!rDoc.IsBlockEditable( nTab, nStartCol, nStartRow, nEndCol, nEndRow, &bThisMatrix, bNoMatrixAtAll))
90 mbIsEditable = false;
91 if ( !bThisMatrix )
92 mbOnlyMatrix = false;
97 void ScEditableTester::TestSelectedBlock( const ScDocument& rDoc,
98 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
99 const ScMarkData& rMark )
101 SCTAB nTabCount = rDoc.GetTableCount();
102 for (const auto& rTab : rMark)
104 if (rTab >= nTabCount)
105 break;
107 TestBlock( rDoc, rTab, nStartCol, nStartRow, nEndCol, nEndRow, false );
111 void ScEditableTester::TestRange( const ScDocument& rDoc, const ScRange& rRange )
113 SCCOL nStartCol = rRange.aStart.Col();
114 SCROW nStartRow = rRange.aStart.Row();
115 SCTAB nStartTab = rRange.aStart.Tab();
116 SCCOL nEndCol = rRange.aEnd.Col();
117 SCROW nEndRow = rRange.aEnd.Row();
118 SCTAB nEndTab = rRange.aEnd.Tab();
119 for (SCTAB nTab=nStartTab; nTab<=nEndTab; nTab++)
120 TestBlock( rDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow, false );
123 void ScEditableTester::TestSelection( const ScDocument& rDoc, const ScMarkData& rMark )
125 if (mbIsEditable || mbOnlyMatrix)
127 bool bThisMatrix;
128 if ( !rDoc.IsSelectionEditable( rMark, &bThisMatrix ) )
130 mbIsEditable = false;
131 if ( !bThisMatrix )
132 mbOnlyMatrix = false;
137 void ScEditableTester::TestBlockForAction(
138 const ScDocument& rDoc, sc::ColRowEditAction eAction, SCCOLROW nStart, SCCOLROW nEnd,
139 const ScMarkData& rMark )
141 mbOnlyMatrix = false;
143 for (const auto& rTab : rMark)
145 if (!mbIsEditable)
146 return;
148 mbIsEditable = rDoc.IsEditActionAllowed(eAction, rTab, nStart, nEnd);
152 TranslateId ScEditableTester::GetMessageId() const
154 if (mbIsEditable)
155 return {};
156 else if (mbOnlyMatrix)
157 return STR_MATRIXFRAGMENTERR;
158 else
159 return STR_PROTECTIONERR;
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */