1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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() :
31 ScEditableTester::ScEditableTester( const ScDocument
& rDoc
, SCTAB nTab
,
32 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
, bool bNoMatrixAtAll
) :
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
) :
45 TestSelectedBlock( rDoc
, nStartCol
, nStartRow
, nEndCol
, nEndRow
, rMark
);
48 ScEditableTester::ScEditableTester( const ScDocument
& rDoc
, const ScRange
& rRange
, sc::EditAction eAction
) :
52 if (eAction
== sc::EditAction::Unknown
)
53 TestRange(rDoc
, rRange
);
55 TestRangeForAction( rDoc
, rRange
, eAction
);
58 ScEditableTester::ScEditableTester( const ScDocument
& rDoc
, const ScMarkData
& rMark
) :
62 TestSelection( rDoc
, rMark
);
65 ScEditableTester::ScEditableTester( ScViewFunc
* pView
) :
70 if ( !pView
->SelectionEditable( &bThisMatrix
) )
78 ScEditableTester::ScEditableTester(
79 const ScDocument
& rDoc
, sc::EditAction eAction
, SCCOL nStartCol
, SCROW nStartRow
,
80 SCCOL nEndCol
, SCROW nEndRow
, const ScMarkData
& rMark
) :
83 TestBlockForAction(rDoc
, eAction
, nStartCol
, nStartRow
, nEndCol
, nEndRow
, rMark
);
86 void ScEditableTester::TestBlock( const ScDocument
& rDoc
, SCTAB nTab
,
87 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
, bool bNoMatrixAtAll
)
89 if (mbIsEditable
|| mbOnlyMatrix
)
92 if (!rDoc
.IsBlockEditable( nTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
, &bThisMatrix
, bNoMatrixAtAll
))
101 void ScEditableTester::TestBlockForAction( const ScDocument
& rDoc
, SCTAB nTab
,
102 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
, sc::EditAction eAction
)
104 if (mbIsEditable
|| mbOnlyMatrix
)
106 mbIsEditable
= rDoc
.IsEditActionAllowed(eAction
, nTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
);
110 void ScEditableTester::TestSelectedBlock( const ScDocument
& rDoc
,
111 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
,
112 const ScMarkData
& rMark
)
114 SCTAB nTabCount
= rDoc
.GetTableCount();
115 for (const auto& rTab
: rMark
)
117 if (rTab
>= nTabCount
)
120 TestBlock( rDoc
, rTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
, false );
124 void ScEditableTester::TestRange( const ScDocument
& rDoc
, const ScRange
& rRange
)
126 SCCOL nStartCol
= rRange
.aStart
.Col();
127 SCROW nStartRow
= rRange
.aStart
.Row();
128 SCTAB nStartTab
= rRange
.aStart
.Tab();
129 SCCOL nEndCol
= rRange
.aEnd
.Col();
130 SCROW nEndRow
= rRange
.aEnd
.Row();
131 SCTAB nEndTab
= rRange
.aEnd
.Tab();
132 for (SCTAB nTab
=nStartTab
; nTab
<=nEndTab
; nTab
++)
133 TestBlock( rDoc
, nTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
, false );
136 void ScEditableTester::TestRangeForAction(const ScDocument
& rDoc
, const ScRange
& rRange
, sc::EditAction eAction
)
138 SCCOL nStartCol
= rRange
.aStart
.Col();
139 SCROW nStartRow
= rRange
.aStart
.Row();
140 SCTAB nStartTab
= rRange
.aStart
.Tab();
141 SCCOL nEndCol
= rRange
.aEnd
.Col();
142 SCROW nEndRow
= rRange
.aEnd
.Row();
143 SCTAB nEndTab
= rRange
.aEnd
.Tab();
144 for (SCTAB nTab
= nStartTab
; nTab
<= nEndTab
; nTab
++)
145 TestBlockForAction(rDoc
, nTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
, eAction
);
148 void ScEditableTester::TestSelection( const ScDocument
& rDoc
, const ScMarkData
& rMark
)
150 if (mbIsEditable
|| mbOnlyMatrix
)
153 if ( !rDoc
.IsSelectionEditable( rMark
, &bThisMatrix
) )
155 mbIsEditable
= false;
157 mbOnlyMatrix
= false;
162 void ScEditableTester::TestBlockForAction(
163 const ScDocument
& rDoc
, sc::EditAction eAction
, SCCOL nStartCol
, SCROW nStartRow
,
164 SCCOL nEndCol
, SCROW nEndRow
, const ScMarkData
& rMark
)
166 mbOnlyMatrix
= false;
168 for (const auto& rTab
: rMark
)
173 mbIsEditable
= rDoc
.IsEditActionAllowed(eAction
, rTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
);
177 TranslateId
ScEditableTester::GetMessageId() const
181 else if (mbOnlyMatrix
)
182 return STR_MATRIXFRAGMENTERR
;
184 return STR_PROTECTIONERR
;
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */