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"
24 #include "markdata.hxx"
26 ScEditableTester::ScEditableTester() :
32 ScEditableTester::ScEditableTester( ScDocument
* pDoc
, SCTAB nTab
,
33 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
) :
37 TestBlock( pDoc
, nTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
);
40 ScEditableTester::ScEditableTester( ScDocument
* pDoc
,
41 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
,
42 const ScMarkData
& rMark
) :
46 TestSelectedBlock( pDoc
, nStartCol
, nStartRow
, nEndCol
, nEndRow
, rMark
);
49 ScEditableTester::ScEditableTester( ScDocument
* pDoc
, const ScRange
& rRange
) :
53 TestRange( pDoc
, rRange
);
56 ScEditableTester::ScEditableTester( ScDocument
* pDoc
, const ScMarkData
& rMark
) :
60 TestSelection( pDoc
, rMark
);
63 ScEditableTester::ScEditableTester( ScViewFunc
* pView
) :
70 void ScEditableTester::TestBlock( ScDocument
* pDoc
, SCTAB nTab
,
71 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
)
73 if (mbIsEditable
|| mbOnlyMatrix
)
76 if ( !pDoc
->IsBlockEditable( nTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
, &bThisMatrix
) )
85 void ScEditableTester::TestSelectedBlock( ScDocument
* pDoc
,
86 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
,
87 const ScMarkData
& rMark
)
89 SCTAB nTabCount
= pDoc
->GetTableCount();
90 ScMarkData::const_iterator itr
= rMark
.begin(), itrEnd
= rMark
.end();
91 for (; itr
!= itrEnd
&& *itr
< nTabCount
; ++itr
)
92 TestBlock( pDoc
, *itr
, nStartCol
, nStartRow
, nEndCol
, nEndRow
);
95 void ScEditableTester::TestRange( ScDocument
* pDoc
, const ScRange
& rRange
)
97 SCCOL nStartCol
= rRange
.aStart
.Col();
98 SCROW nStartRow
= rRange
.aStart
.Row();
99 SCTAB nStartTab
= rRange
.aStart
.Tab();
100 SCCOL nEndCol
= rRange
.aEnd
.Col();
101 SCROW nEndRow
= rRange
.aEnd
.Row();
102 SCTAB nEndTab
= rRange
.aEnd
.Tab();
103 for (SCTAB nTab
=nStartTab
; nTab
<=nEndTab
; nTab
++)
104 TestBlock( pDoc
, nTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
);
107 void ScEditableTester::TestSelection( ScDocument
* pDoc
, const ScMarkData
& rMark
)
109 if (mbIsEditable
|| mbOnlyMatrix
)
112 if ( !pDoc
->IsSelectionEditable( rMark
, &bThisMatrix
) )
114 mbIsEditable
= false;
116 mbOnlyMatrix
= false;
121 void ScEditableTester::TestView( ScViewFunc
* pView
)
123 if (mbIsEditable
|| mbOnlyMatrix
)
126 if ( !pView
->SelectionEditable( &bThisMatrix
) )
128 mbIsEditable
= false;
130 mbOnlyMatrix
= false;
135 sal_uInt16
ScEditableTester::GetMessageId() const
139 else if (mbOnlyMatrix
)
140 return STR_MATRIXFRAGMENTERR
;
142 return STR_PROTECTIONERR
;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */