Line data Source code
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 : #include "markdata.hxx"
25 :
26 22 : ScEditableTester::ScEditableTester() :
27 : mbIsEditable(true),
28 22 : mbOnlyMatrix(true)
29 : {
30 22 : }
31 :
32 1239 : ScEditableTester::ScEditableTester( ScDocument* pDoc, SCTAB nTab,
33 : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) :
34 : mbIsEditable(true),
35 1239 : mbOnlyMatrix(true)
36 : {
37 1239 : TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
38 1239 : }
39 :
40 66 : ScEditableTester::ScEditableTester( ScDocument* pDoc,
41 : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
42 : const ScMarkData& rMark ) :
43 : mbIsEditable(true),
44 66 : mbOnlyMatrix(true)
45 : {
46 66 : TestSelectedBlock( pDoc, nStartCol, nStartRow, nEndCol, nEndRow, rMark );
47 66 : }
48 :
49 109 : ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScRange& rRange ) :
50 : mbIsEditable(true),
51 109 : mbOnlyMatrix(true)
52 : {
53 109 : TestRange( pDoc, rRange );
54 109 : }
55 :
56 89 : ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScMarkData& rMark ) :
57 : mbIsEditable(true),
58 89 : mbOnlyMatrix(true)
59 : {
60 89 : TestSelection( pDoc, rMark );
61 89 : }
62 :
63 0 : ScEditableTester::ScEditableTester( ScViewFunc* pView ) :
64 : mbIsEditable(true),
65 0 : mbOnlyMatrix(true)
66 : {
67 0 : TestView( pView );
68 0 : }
69 :
70 1452 : void ScEditableTester::TestBlock( ScDocument* pDoc, SCTAB nTab,
71 : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
72 : {
73 1452 : if (mbIsEditable || mbOnlyMatrix)
74 : {
75 : bool bThisMatrix;
76 1452 : if ( !pDoc->IsBlockEditable( nTab, nStartCol, nStartRow, nEndCol, nEndRow, &bThisMatrix ) )
77 : {
78 0 : mbIsEditable = false;
79 0 : if ( !bThisMatrix )
80 0 : mbOnlyMatrix = false;
81 : }
82 : }
83 1452 : }
84 :
85 66 : void ScEditableTester::TestSelectedBlock( ScDocument* pDoc,
86 : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
87 : const ScMarkData& rMark )
88 : {
89 66 : SCTAB nTabCount = pDoc->GetTableCount();
90 66 : ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
91 132 : for (; itr != itrEnd && *itr < nTabCount; ++itr)
92 66 : TestBlock( pDoc, *itr, nStartCol, nStartRow, nEndCol, nEndRow );
93 66 : }
94 :
95 109 : void ScEditableTester::TestRange( ScDocument* pDoc, const ScRange& rRange )
96 : {
97 109 : SCCOL nStartCol = rRange.aStart.Col();
98 109 : SCROW nStartRow = rRange.aStart.Row();
99 109 : SCTAB nStartTab = rRange.aStart.Tab();
100 109 : SCCOL nEndCol = rRange.aEnd.Col();
101 109 : SCROW nEndRow = rRange.aEnd.Row();
102 109 : SCTAB nEndTab = rRange.aEnd.Tab();
103 218 : for (SCTAB nTab=nStartTab; nTab<=nEndTab; nTab++)
104 109 : TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
105 109 : }
106 :
107 90 : void ScEditableTester::TestSelection( ScDocument* pDoc, const ScMarkData& rMark )
108 : {
109 90 : if (mbIsEditable || mbOnlyMatrix)
110 : {
111 : bool bThisMatrix;
112 90 : if ( !pDoc->IsSelectionEditable( rMark, &bThisMatrix ) )
113 : {
114 0 : mbIsEditable = false;
115 0 : if ( !bThisMatrix )
116 0 : mbOnlyMatrix = false;
117 : }
118 : }
119 90 : }
120 :
121 0 : void ScEditableTester::TestView( ScViewFunc* pView )
122 : {
123 0 : if (mbIsEditable || mbOnlyMatrix)
124 : {
125 : bool bThisMatrix;
126 0 : if ( !pView->SelectionEditable( &bThisMatrix ) )
127 : {
128 0 : mbIsEditable = false;
129 0 : if ( !bThisMatrix )
130 0 : mbOnlyMatrix = false;
131 : }
132 : }
133 0 : }
134 :
135 0 : sal_uInt16 ScEditableTester::GetMessageId() const
136 : {
137 0 : if (mbIsEditable)
138 0 : return 0;
139 0 : else if (mbOnlyMatrix)
140 0 : return STR_MATRIXFRAGMENTERR;
141 : else
142 0 : return STR_PROTECTIONERR;
143 156 : }
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|