tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / docshell / editable.cxx
blob357897470aa1adae96fe35cb7cb37d5c7b16daa5
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, sc::EditAction eAction ) :
49 mbIsEditable(true),
50 mbOnlyMatrix(true)
52 if (eAction == sc::EditAction::Unknown)
53 TestRange(rDoc, rRange);
54 else
55 TestRangeForAction( rDoc, rRange, eAction );
58 ScEditableTester::ScEditableTester( const ScDocument& rDoc, const ScMarkData& rMark ) :
59 mbIsEditable(true),
60 mbOnlyMatrix(true)
62 TestSelection( rDoc, rMark );
65 ScEditableTester::ScEditableTester( ScViewFunc* pView ) :
66 mbIsEditable(true),
67 mbOnlyMatrix(true)
69 bool bThisMatrix;
70 if ( !pView->SelectionEditable( &bThisMatrix ) )
72 mbIsEditable = false;
73 if ( !bThisMatrix )
74 mbOnlyMatrix = false;
78 ScEditableTester::ScEditableTester(
79 const ScDocument& rDoc, sc::EditAction eAction, SCCOL nStartCol, SCROW nStartRow,
80 SCCOL nEndCol, SCROW nEndRow, const ScMarkData& rMark ) :
81 ScEditableTester()
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)
91 bool bThisMatrix;
92 if (!rDoc.IsBlockEditable( nTab, nStartCol, nStartRow, nEndCol, nEndRow, &bThisMatrix, bNoMatrixAtAll ))
94 mbIsEditable = false;
95 if ( !bThisMatrix )
96 mbOnlyMatrix = false;
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)
118 break;
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)
152 bool bThisMatrix;
153 if ( !rDoc.IsSelectionEditable( rMark, &bThisMatrix ) )
155 mbIsEditable = false;
156 if ( !bThisMatrix )
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)
170 if (!mbIsEditable)
171 return;
173 mbIsEditable = rDoc.IsEditActionAllowed(eAction, rTab, nStartCol, nStartRow, nEndCol, nEndRow);
177 TranslateId ScEditableTester::GetMessageId() const
179 if (mbIsEditable)
180 return {};
181 else if (mbOnlyMatrix)
182 return STR_MATRIXFRAGMENTERR;
183 else
184 return STR_PROTECTIONERR;
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */