xref: /trunk/main/sc/source/ui/docshell/editable.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 #include "editable.hxx"
34 #include "document.hxx"
35 #include "viewfunc.hxx"
36 #include "globstr.hrc"
37 
38 //------------------------------------------------------------------
39 
40 ScEditableTester::ScEditableTester() :
41     bIsEditable( sal_True ),
42     bOnlyMatrix( sal_True )
43 {
44 }
45 
46 ScEditableTester::ScEditableTester( ScDocument* pDoc, SCTAB nTab,
47                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) :
48     bIsEditable( sal_True ),
49     bOnlyMatrix( sal_True )
50 {
51     TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
52 }
53 
54 ScEditableTester::ScEditableTester( ScDocument* pDoc,
55                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
56                         const ScMarkData& rMark ) :
57     bIsEditable( sal_True ),
58     bOnlyMatrix( sal_True )
59 {
60     TestSelectedBlock( pDoc, nStartCol, nStartRow, nEndCol, nEndRow, rMark );
61 }
62 
63 ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScRange& rRange ) :
64     bIsEditable( sal_True ),
65     bOnlyMatrix( sal_True )
66 {
67     TestRange( pDoc, rRange );
68 }
69 
70 ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScMarkData& rMark ) :
71     bIsEditable( sal_True ),
72     bOnlyMatrix( sal_True )
73 {
74     TestSelection( pDoc, rMark );
75 }
76 
77 ScEditableTester::ScEditableTester( ScViewFunc* pView ) :
78     bIsEditable( sal_True ),
79     bOnlyMatrix( sal_True )
80 {
81     TestView( pView );
82 }
83 
84 //------------------------------------------------------------------
85 
86 void ScEditableTester::TestBlock( ScDocument* pDoc, SCTAB nTab,
87                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
88 {
89     if ( bIsEditable || bOnlyMatrix )
90     {
91         sal_Bool bThisMatrix;
92         if ( !pDoc->IsBlockEditable( nTab, nStartCol, nStartRow, nEndCol, nEndRow, &bThisMatrix ) )
93         {
94             bIsEditable = sal_False;
95             if ( !bThisMatrix )
96                 bOnlyMatrix = sal_False;
97         }
98     }
99 }
100 
101 void ScEditableTester::TestSelectedBlock( ScDocument* pDoc,
102                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
103                         const ScMarkData& rMark )
104 {
105     SCTAB nTabCount = pDoc->GetTableCount();
106     for (SCTAB nTab=0; nTab<nTabCount; nTab++)
107         if (rMark.GetTableSelect(nTab))
108             TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
109 }
110 
111 void ScEditableTester::TestRange( ScDocument* pDoc, const ScRange& rRange )
112 {
113     SCCOL nStartCol = rRange.aStart.Col();
114     SCROW nStartRow = rRange.aStart.Row();
115     SCTAB nStartTab = rRange.aStart.Tab();
116     SCCOL nEndCol = rRange.aEnd.Col();
117     SCROW nEndRow = rRange.aEnd.Row();
118     SCTAB nEndTab = rRange.aEnd.Tab();
119     for (SCTAB nTab=nStartTab; nTab<=nEndTab; nTab++)
120         TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
121 }
122 
123 void ScEditableTester::TestSelection( ScDocument* pDoc, const ScMarkData& rMark )
124 {
125     if ( bIsEditable || bOnlyMatrix )
126     {
127         sal_Bool bThisMatrix;
128         if ( !pDoc->IsSelectionEditable( rMark, &bThisMatrix ) )
129         {
130             bIsEditable = sal_False;
131             if ( !bThisMatrix )
132                 bOnlyMatrix = sal_False;
133         }
134     }
135 }
136 
137 void ScEditableTester::TestView( ScViewFunc* pView )
138 {
139     if ( bIsEditable || bOnlyMatrix )
140     {
141         sal_Bool bThisMatrix;
142         if ( !pView->SelectionEditable( &bThisMatrix ) )
143         {
144             bIsEditable = sal_False;
145             if ( !bThisMatrix )
146                 bOnlyMatrix = sal_False;
147         }
148     }
149 }
150 
151 //------------------------------------------------------------------
152 
153 sal_uInt16 ScEditableTester::GetMessageId() const
154 {
155     if (bIsEditable)
156         return 0;
157     else if (bOnlyMatrix)
158         return STR_MATRIXFRAGMENTERR;
159     else
160         return STR_PROTECTIONERR;
161 }
162 
163