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
) :
52 TestRange( rDoc
, rRange
);
55 ScEditableTester::ScEditableTester( const ScDocument
& rDoc
, const ScMarkData
& rMark
) :
59 TestSelection( rDoc
, rMark
);
62 ScEditableTester::ScEditableTester( ScViewFunc
* pView
) :
67 if ( !pView
->SelectionEditable( &bThisMatrix
) )
75 ScEditableTester::ScEditableTester(
76 const ScDocument
& rDoc
, sc::ColRowEditAction eAction
, SCCOLROW nStart
, SCCOLROW nEnd
, const ScMarkData
& rMark
) :
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
)
88 if (!rDoc
.IsBlockEditable( nTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
, &bThisMatrix
, bNoMatrixAtAll
))
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
)
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
)
128 if ( !rDoc
.IsSelectionEditable( rMark
, &bThisMatrix
) )
130 mbIsEditable
= false;
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
)
148 mbIsEditable
= rDoc
.IsEditActionAllowed(eAction
, rTab
, nStart
, nEnd
);
152 TranslateId
ScEditableTester::GetMessageId() const
156 else if (mbOnlyMatrix
)
157 return STR_MATRIXFRAGMENTERR
;
159 return STR_PROTECTIONERR
;
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */