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