LibreOffice Module sc (master) 1
editable.cxx
Go to the documentation of this file.
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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <editable.hxx>
21#include <document.hxx>
22#include <viewfunc.hxx>
23#include <globstr.hrc>
24
26 mbIsEditable(true),
27 mbOnlyMatrix(true)
28{
29}
30
32 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bNoMatrixAtAll ) :
33 mbIsEditable(true),
34 mbOnlyMatrix(true)
35{
36 TestBlock( rDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow, bNoMatrixAtAll );
37}
38
40 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
41 const ScMarkData& rMark ) :
42 mbIsEditable(true),
43 mbOnlyMatrix(true)
44{
45 TestSelectedBlock( rDoc, nStartCol, nStartRow, nEndCol, nEndRow, rMark );
46}
47
49 mbIsEditable(true),
50 mbOnlyMatrix(true)
51{
52 TestRange( rDoc, rRange );
53}
54
56 mbIsEditable(true),
57 mbOnlyMatrix(true)
58{
59 TestSelection( rDoc, rMark );
60}
61
63 mbIsEditable(true),
64 mbOnlyMatrix(true)
65{
66 bool bThisMatrix;
67 if ( !pView->SelectionEditable( &bThisMatrix ) )
68 {
69 mbIsEditable = false;
70 if ( !bThisMatrix )
71 mbOnlyMatrix = false;
72 }
73}
74
76 const ScDocument& rDoc, sc::ColRowEditAction eAction, SCCOLROW nStart, SCCOLROW nEnd, const ScMarkData& rMark ) :
78{
79 TestBlockForAction(rDoc, eAction, nStart, nEnd, rMark);
80}
81
83 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bNoMatrixAtAll )
84{
86 {
87 bool bThisMatrix;
88 if (!rDoc.IsBlockEditable( nTab, nStartCol, nStartRow, nEndCol, nEndRow, &bThisMatrix, bNoMatrixAtAll))
89 {
90 mbIsEditable = false;
91 if ( !bThisMatrix )
92 mbOnlyMatrix = false;
93 }
94 }
95}
96
98 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
99 const ScMarkData& rMark )
100{
101 SCTAB nTabCount = rDoc.GetTableCount();
102 for (const auto& rTab : rMark)
103 {
104 if (rTab >= nTabCount)
105 break;
106
107 TestBlock( rDoc, rTab, nStartCol, nStartRow, nEndCol, nEndRow, false );
108 }
109}
110
111void ScEditableTester::TestRange( const ScDocument& rDoc, const ScRange& rRange )
112{
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 );
121}
122
124{
126 {
127 bool bThisMatrix;
128 if ( !rDoc.IsSelectionEditable( rMark, &bThisMatrix ) )
129 {
130 mbIsEditable = false;
131 if ( !bThisMatrix )
132 mbOnlyMatrix = false;
133 }
134 }
135}
136
138 const ScDocument& rDoc, sc::ColRowEditAction eAction, SCCOLROW nStart, SCCOLROW nEnd,
139 const ScMarkData& rMark )
140{
141 mbOnlyMatrix = false;
142
143 for (const auto& rTab : rMark)
144 {
145 if (!mbIsEditable)
146 return;
147
148 mbIsEditable = rDoc.IsEditActionAllowed(eAction, rTab, nStart, nEnd);
149 }
150}
151
153{
154 if (mbIsEditable)
155 return {};
156 else if (mbOnlyMatrix)
157 return STR_MATRIXFRAGMENTERR;
158 else
159 return STR_PROTECTIONERR;
160}
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
bool IsEditActionAllowed(sc::ColRowEditAction eAction, SCTAB nTab, SCCOLROW nStart, SCCOLROW nEnd) const
Definition: document10.cxx:966
bool IsSelectionEditable(const ScMarkData &rMark, bool *pOnlyNotBecauseOfMatrix=nullptr) const
Definition: document.cxx:5340
bool IsBlockEditable(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool *pOnlyNotBecauseOfMatrix=nullptr, bool bNoMatrixAtAll=false) const
Definition: document.cxx:5317
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:297
void TestSelection(const ScDocument &rDoc, const ScMarkData &rMark)
Definition: editable.cxx:123
TranslateId GetMessageId() const
Definition: editable.cxx:152
void TestBlock(const ScDocument &rDoc, SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bNoMatrixAtAll=false)
Definition: editable.cxx:82
void TestRange(const ScDocument &rDoc, const ScRange &rRange)
Definition: editable.cxx:111
void TestBlockForAction(const ScDocument &rDoc, sc::ColRowEditAction eAction, SCCOLROW nStart, SCCOLROW nEnd, const ScMarkData &rMark)
Definition: editable.cxx:137
void TestSelectedBlock(const ScDocument &rDoc, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const ScMarkData &rMark)
Definition: editable.cxx:97
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
bool SelectionEditable(bool *pOnlyNotBecauseOfMatrix=nullptr)
Definition: viewfunc.cxx:274
ColRowEditAction
Definition: global.hxx:427
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17