xref: /aoo42x/main/sc/source/ui/docshell/editable.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 
29 #include "editable.hxx"
30 #include "document.hxx"
31 #include "viewfunc.hxx"
32 #include "globstr.hrc"
33 
34 //------------------------------------------------------------------
35 
ScEditableTester()36 ScEditableTester::ScEditableTester() :
37 	bIsEditable( sal_True ),
38 	bOnlyMatrix( sal_True )
39 {
40 }
41 
ScEditableTester(ScDocument * pDoc,SCTAB nTab,SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow)42 ScEditableTester::ScEditableTester( ScDocument* pDoc, SCTAB nTab,
43 						SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) :
44 	bIsEditable( sal_True ),
45 	bOnlyMatrix( sal_True )
46 {
47 	TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
48 }
49 
ScEditableTester(ScDocument * pDoc,SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow,const ScMarkData & rMark)50 ScEditableTester::ScEditableTester( ScDocument* pDoc,
51 						SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
52 						const ScMarkData& rMark ) :
53 	bIsEditable( sal_True ),
54 	bOnlyMatrix( sal_True )
55 {
56 	TestSelectedBlock( pDoc, nStartCol, nStartRow, nEndCol, nEndRow, rMark );
57 }
58 
ScEditableTester(ScDocument * pDoc,const ScRange & rRange)59 ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScRange& rRange ) :
60 	bIsEditable( sal_True ),
61 	bOnlyMatrix( sal_True )
62 {
63 	TestRange( pDoc, rRange );
64 }
65 
ScEditableTester(ScDocument * pDoc,const ScMarkData & rMark)66 ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScMarkData& rMark ) :
67 	bIsEditable( sal_True ),
68 	bOnlyMatrix( sal_True )
69 {
70 	TestSelection( pDoc, rMark );
71 }
72 
ScEditableTester(ScViewFunc * pView)73 ScEditableTester::ScEditableTester( ScViewFunc* pView ) :
74 	bIsEditable( sal_True ),
75 	bOnlyMatrix( sal_True )
76 {
77 	TestView( pView );
78 }
79 
80 //------------------------------------------------------------------
81 
TestBlock(ScDocument * pDoc,SCTAB nTab,SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow)82 void ScEditableTester::TestBlock( ScDocument* pDoc, SCTAB nTab,
83 						SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
84 {
85 	if ( bIsEditable || bOnlyMatrix )
86 	{
87 		sal_Bool bThisMatrix;
88 		if ( !pDoc->IsBlockEditable( nTab, nStartCol, nStartRow, nEndCol, nEndRow, &bThisMatrix ) )
89 		{
90 			bIsEditable = sal_False;
91 			if ( !bThisMatrix )
92 				bOnlyMatrix = sal_False;
93 		}
94 	}
95 }
96 
TestSelectedBlock(ScDocument * pDoc,SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow,const ScMarkData & rMark)97 void ScEditableTester::TestSelectedBlock( ScDocument* pDoc,
98 						SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
99 						const ScMarkData& rMark )
100 {
101 	SCTAB nTabCount = pDoc->GetTableCount();
102 	for (SCTAB nTab=0; nTab<nTabCount; nTab++)
103 		if (rMark.GetTableSelect(nTab))
104 			TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
105 }
106 
TestRange(ScDocument * pDoc,const ScRange & rRange)107 void ScEditableTester::TestRange( ScDocument* pDoc, const ScRange& rRange )
108 {
109 	SCCOL nStartCol = rRange.aStart.Col();
110 	SCROW nStartRow = rRange.aStart.Row();
111 	SCTAB nStartTab = rRange.aStart.Tab();
112 	SCCOL nEndCol = rRange.aEnd.Col();
113 	SCROW nEndRow = rRange.aEnd.Row();
114 	SCTAB nEndTab = rRange.aEnd.Tab();
115 	for (SCTAB nTab=nStartTab; nTab<=nEndTab; nTab++)
116 		TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
117 }
118 
TestSelection(ScDocument * pDoc,const ScMarkData & rMark)119 void ScEditableTester::TestSelection( ScDocument* pDoc, const ScMarkData& rMark )
120 {
121 	if ( bIsEditable || bOnlyMatrix )
122 	{
123 		sal_Bool bThisMatrix;
124 		if ( !pDoc->IsSelectionEditable( rMark, &bThisMatrix ) )
125 		{
126 			bIsEditable = sal_False;
127 			if ( !bThisMatrix )
128 				bOnlyMatrix = sal_False;
129 		}
130 	}
131 }
132 
TestView(ScViewFunc * pView)133 void ScEditableTester::TestView( ScViewFunc* pView )
134 {
135 	if ( bIsEditable || bOnlyMatrix )
136 	{
137 		sal_Bool bThisMatrix;
138 		if ( !pView->SelectionEditable( &bThisMatrix ) )
139 		{
140 			bIsEditable = sal_False;
141 			if ( !bThisMatrix )
142 				bOnlyMatrix = sal_False;
143 		}
144 	}
145 }
146 
147 //------------------------------------------------------------------
148 
GetMessageId() const149 sal_uInt16 ScEditableTester::GetMessageId() const
150 {
151 	if (bIsEditable)
152 		return 0;
153 	else if (bOnlyMatrix)
154 		return STR_MATRIXFRAGMENTERR;
155 	else
156 		return STR_PROTECTIONERR;
157 }
158 
159