Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / docshell / editable.cxx
blob2664e9e2ae3488fd33703a558595557bca3ddbb0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "editable.hxx"
21 #include "document.hxx"
22 #include "viewfunc.hxx"
23 #include "globstr.hrc"
24 #include "markdata.hxx"
26 ScEditableTester::ScEditableTester() :
27 mbIsEditable(true),
28 mbOnlyMatrix(true)
32 ScEditableTester::ScEditableTester( ScDocument* pDoc, SCTAB nTab,
33 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) :
34 mbIsEditable(true),
35 mbOnlyMatrix(true)
37 TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
40 ScEditableTester::ScEditableTester( ScDocument* pDoc,
41 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
42 const ScMarkData& rMark ) :
43 mbIsEditable(true),
44 mbOnlyMatrix(true)
46 TestSelectedBlock( pDoc, nStartCol, nStartRow, nEndCol, nEndRow, rMark );
49 ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScRange& rRange ) :
50 mbIsEditable(true),
51 mbOnlyMatrix(true)
53 TestRange( pDoc, rRange );
56 ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScMarkData& rMark ) :
57 mbIsEditable(true),
58 mbOnlyMatrix(true)
60 TestSelection( pDoc, rMark );
63 ScEditableTester::ScEditableTester( ScViewFunc* pView ) :
64 mbIsEditable(true),
65 mbOnlyMatrix(true)
67 TestView( pView );
70 //------------------------------------------------------------------
72 void ScEditableTester::TestBlock( ScDocument* pDoc, SCTAB nTab,
73 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
75 if (mbIsEditable || mbOnlyMatrix)
77 bool bThisMatrix;
78 if ( !pDoc->IsBlockEditable( nTab, nStartCol, nStartRow, nEndCol, nEndRow, &bThisMatrix ) )
80 mbIsEditable = false;
81 if ( !bThisMatrix )
82 mbOnlyMatrix = false;
87 void ScEditableTester::TestSelectedBlock( ScDocument* pDoc,
88 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
89 const ScMarkData& rMark )
91 SCTAB nTabCount = pDoc->GetTableCount();
92 ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
93 for (; itr != itrEnd && *itr < nTabCount; ++itr)
94 TestBlock( pDoc, *itr, nStartCol, nStartRow, nEndCol, nEndRow );
97 void ScEditableTester::TestRange( ScDocument* pDoc, const ScRange& rRange )
99 SCCOL nStartCol = rRange.aStart.Col();
100 SCROW nStartRow = rRange.aStart.Row();
101 SCTAB nStartTab = rRange.aStart.Tab();
102 SCCOL nEndCol = rRange.aEnd.Col();
103 SCROW nEndRow = rRange.aEnd.Row();
104 SCTAB nEndTab = rRange.aEnd.Tab();
105 for (SCTAB nTab=nStartTab; nTab<=nEndTab; nTab++)
106 TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
109 void ScEditableTester::TestSelection( ScDocument* pDoc, const ScMarkData& rMark )
111 if (mbIsEditable || mbOnlyMatrix)
113 bool bThisMatrix;
114 if ( !pDoc->IsSelectionEditable( rMark, &bThisMatrix ) )
116 mbIsEditable = false;
117 if ( !bThisMatrix )
118 mbOnlyMatrix = false;
123 void ScEditableTester::TestView( ScViewFunc* pView )
125 if (mbIsEditable || mbOnlyMatrix)
127 bool bThisMatrix;
128 if ( !pView->SelectionEditable( &bThisMatrix ) )
130 mbIsEditable = false;
131 if ( !bThisMatrix )
132 mbOnlyMatrix = false;
137 //------------------------------------------------------------------
139 sal_uInt16 ScEditableTester::GetMessageId() const
141 if (mbIsEditable)
142 return 0;
143 else if (mbOnlyMatrix)
144 return STR_MATRIXFRAGMENTERR;
145 else
146 return STR_PROTECTIONERR;
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */