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 //------------------------------------------------------------------
72 void ScEditableTester::TestBlock( ScDocument
* pDoc
, SCTAB nTab
,
73 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
)
75 if (mbIsEditable
|| mbOnlyMatrix
)
78 if ( !pDoc
->IsBlockEditable( nTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
, &bThisMatrix
) )
87 void ScEditableTester::TestSelectedBlock( ScDocument
* pDoc
,
88 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
,
89 const ScMarkData
& rMark
)
91 SCTAB nTabCount
= pDoc
->GetTableCount();
92 ScMarkData::const_iterator itr
= rMark
.begin(), itrEnd
= rMark
.end();
93 for (; itr
!= itrEnd
&& *itr
< nTabCount
; ++itr
)
94 TestBlock( pDoc
, *itr
, nStartCol
, nStartRow
, nEndCol
, nEndRow
);
97 void ScEditableTester::TestRange( ScDocument
* pDoc
, const ScRange
& rRange
)
99 SCCOL nStartCol
= rRange
.aStart
.Col();
100 SCROW nStartRow
= rRange
.aStart
.Row();
101 SCTAB nStartTab
= rRange
.aStart
.Tab();
102 SCCOL nEndCol
= rRange
.aEnd
.Col();
103 SCROW nEndRow
= rRange
.aEnd
.Row();
104 SCTAB nEndTab
= rRange
.aEnd
.Tab();
105 for (SCTAB nTab
=nStartTab
; nTab
<=nEndTab
; nTab
++)
106 TestBlock( pDoc
, nTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
);
109 void ScEditableTester::TestSelection( ScDocument
* pDoc
, const ScMarkData
& rMark
)
111 if (mbIsEditable
|| mbOnlyMatrix
)
114 if ( !pDoc
->IsSelectionEditable( rMark
, &bThisMatrix
) )
116 mbIsEditable
= false;
118 mbOnlyMatrix
= false;
123 void ScEditableTester::TestView( ScViewFunc
* pView
)
125 if (mbIsEditable
|| mbOnlyMatrix
)
128 if ( !pView
->SelectionEditable( &bThisMatrix
) )
130 mbIsEditable
= false;
132 mbOnlyMatrix
= false;
137 //------------------------------------------------------------------
139 sal_uInt16
ScEditableTester::GetMessageId() const
143 else if (mbOnlyMatrix
)
144 return STR_MATRIXFRAGMENTERR
;
146 return STR_PROTECTIONERR
;
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */