merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / docshell / editable.cxx
blob21d6c2cd60e85bdf33022b304622f64b418d58d7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editable.cxx,v $
10 * $Revision: 1.5.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include "editable.hxx"
37 #include "document.hxx"
38 #include "viewfunc.hxx"
39 #include "globstr.hrc"
41 //------------------------------------------------------------------
43 ScEditableTester::ScEditableTester() :
44 bIsEditable( TRUE ),
45 bOnlyMatrix( TRUE )
49 ScEditableTester::ScEditableTester( ScDocument* pDoc, SCTAB nTab,
50 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) :
51 bIsEditable( TRUE ),
52 bOnlyMatrix( TRUE )
54 TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
57 ScEditableTester::ScEditableTester( ScDocument* pDoc,
58 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
59 const ScMarkData& rMark ) :
60 bIsEditable( TRUE ),
61 bOnlyMatrix( TRUE )
63 TestSelectedBlock( pDoc, nStartCol, nStartRow, nEndCol, nEndRow, rMark );
66 ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScRange& rRange ) :
67 bIsEditable( TRUE ),
68 bOnlyMatrix( TRUE )
70 TestRange( pDoc, rRange );
73 ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScMarkData& rMark ) :
74 bIsEditable( TRUE ),
75 bOnlyMatrix( TRUE )
77 TestSelection( pDoc, rMark );
80 ScEditableTester::ScEditableTester( ScViewFunc* pView ) :
81 bIsEditable( TRUE ),
82 bOnlyMatrix( TRUE )
84 TestView( pView );
87 //------------------------------------------------------------------
89 void ScEditableTester::TestBlock( ScDocument* pDoc, SCTAB nTab,
90 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
92 if ( bIsEditable || bOnlyMatrix )
94 BOOL bThisMatrix;
95 if ( !pDoc->IsBlockEditable( nTab, nStartCol, nStartRow, nEndCol, nEndRow, &bThisMatrix ) )
97 bIsEditable = FALSE;
98 if ( !bThisMatrix )
99 bOnlyMatrix = FALSE;
104 void ScEditableTester::TestSelectedBlock( ScDocument* pDoc,
105 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
106 const ScMarkData& rMark )
108 SCTAB nTabCount = pDoc->GetTableCount();
109 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
110 if (rMark.GetTableSelect(nTab))
111 TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
114 void ScEditableTester::TestRange( ScDocument* pDoc, const ScRange& rRange )
116 SCCOL nStartCol = rRange.aStart.Col();
117 SCROW nStartRow = rRange.aStart.Row();
118 SCTAB nStartTab = rRange.aStart.Tab();
119 SCCOL nEndCol = rRange.aEnd.Col();
120 SCROW nEndRow = rRange.aEnd.Row();
121 SCTAB nEndTab = rRange.aEnd.Tab();
122 for (SCTAB nTab=nStartTab; nTab<=nEndTab; nTab++)
123 TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
126 void ScEditableTester::TestSelection( ScDocument* pDoc, const ScMarkData& rMark )
128 if ( bIsEditable || bOnlyMatrix )
130 BOOL bThisMatrix;
131 if ( !pDoc->IsSelectionEditable( rMark, &bThisMatrix ) )
133 bIsEditable = FALSE;
134 if ( !bThisMatrix )
135 bOnlyMatrix = FALSE;
140 void ScEditableTester::TestView( ScViewFunc* pView )
142 if ( bIsEditable || bOnlyMatrix )
144 BOOL bThisMatrix;
145 if ( !pView->SelectionEditable( &bThisMatrix ) )
147 bIsEditable = FALSE;
148 if ( !bThisMatrix )
149 bOnlyMatrix = FALSE;
154 //------------------------------------------------------------------
156 USHORT ScEditableTester::GetMessageId() const
158 if (bIsEditable)
159 return 0;
160 else if (bOnlyMatrix)
161 return STR_MATRIXFRAGMENTERR;
162 else
163 return STR_PROTECTIONERR;