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 44 : ScEditableTester::ScEditableTester() :
27 : mbIsEditable(true),
28 44 : mbOnlyMatrix(true)
29 : {
30 44 : }
31 :
32 2460 : ScEditableTester::ScEditableTester( ScDocument* pDoc, SCTAB nTab,
33 : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) :
34 : mbIsEditable(true),
35 2460 : mbOnlyMatrix(true)
36 : {
37 2460 : TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
38 2460 : }
39 :
40 122 : ScEditableTester::ScEditableTester( ScDocument* pDoc,
41 : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
42 : const ScMarkData& rMark ) :
43 : mbIsEditable(true),
44 122 : mbOnlyMatrix(true)
45 : {
46 122 : TestSelectedBlock( pDoc, nStartCol, nStartRow, nEndCol, nEndRow, rMark );
47 122 : }
48 :
49 218 : ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScRange& rRange ) :
50 : mbIsEditable(true),
51 218 : mbOnlyMatrix(true)
52 : {
53 218 : TestRange( pDoc, rRange );
54 218 : }
55 :
56 178 : ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScMarkData& rMark ) :
57 : mbIsEditable(true),
58 178 : mbOnlyMatrix(true)
59 : {
60 178 : TestSelection( pDoc, rMark );
61 178 : }
62 :
63 0 : ScEditableTester::ScEditableTester( ScViewFunc* pView ) :
64 : mbIsEditable(true),
65 0 : mbOnlyMatrix(true)
66 : {
67 0 : TestView( pView );
68 0 : }
69 :
70 2876 : void ScEditableTester::TestBlock( ScDocument* pDoc, SCTAB nTab,
71 : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
72 : {
73 2876 : if (mbIsEditable || mbOnlyMatrix)
74 : {
75 : bool bThisMatrix;
76 2876 : 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 2876 : }
84 :
85 122 : void ScEditableTester::TestSelectedBlock( ScDocument* pDoc,
86 : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
87 : const ScMarkData& rMark )
88 : {
89 122 : SCTAB nTabCount = pDoc->GetTableCount();
90 122 : ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
91 244 : for (; itr != itrEnd && *itr < nTabCount; ++itr)
92 122 : TestBlock( pDoc, *itr, nStartCol, nStartRow, nEndCol, nEndRow );
93 122 : }
94 :
95 218 : void ScEditableTester::TestRange( ScDocument* pDoc, const ScRange& rRange )
96 : {
97 218 : SCCOL nStartCol = rRange.aStart.Col();
98 218 : SCROW nStartRow = rRange.aStart.Row();
99 218 : SCTAB nStartTab = rRange.aStart.Tab();
100 218 : SCCOL nEndCol = rRange.aEnd.Col();
101 218 : SCROW nEndRow = rRange.aEnd.Row();
102 218 : SCTAB nEndTab = rRange.aEnd.Tab();
103 436 : for (SCTAB nTab=nStartTab; nTab<=nEndTab; nTab++)
104 218 : TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
105 218 : }
106 :
107 180 : void ScEditableTester::TestSelection( ScDocument* pDoc, const ScMarkData& rMark )
108 : {
109 180 : if (mbIsEditable || mbOnlyMatrix)
110 : {
111 : bool bThisMatrix;
112 180 : if ( !pDoc->IsSelectionEditable( rMark, &bThisMatrix ) )
113 : {
114 0 : mbIsEditable = false;
115 0 : if ( !bThisMatrix )
116 0 : mbOnlyMatrix = false;
117 : }
118 : }
119 180 : }
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 228 : }
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|