LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/docshell - editable.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 44 67 65.7 %
Date: 2013-07-09 Functions: 11 14 78.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "editable.hxx"
      21             : #include "document.hxx"
      22             : #include "viewfunc.hxx"
      23             : #include "globstr.hrc"
      24             : #include "markdata.hxx"
      25             : 
      26           7 : ScEditableTester::ScEditableTester() :
      27             :     mbIsEditable(true),
      28           7 :     mbOnlyMatrix(true)
      29             : {
      30           7 : }
      31             : 
      32        2100 : ScEditableTester::ScEditableTester( ScDocument* pDoc, SCTAB nTab,
      33             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) :
      34             :     mbIsEditable(true),
      35        2100 :     mbOnlyMatrix(true)
      36             : {
      37        2100 :     TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
      38        2100 : }
      39             : 
      40          30 : ScEditableTester::ScEditableTester( ScDocument* pDoc,
      41             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
      42             :                         const ScMarkData& rMark ) :
      43             :     mbIsEditable(true),
      44          30 :     mbOnlyMatrix(true)
      45             : {
      46          30 :     TestSelectedBlock( pDoc, nStartCol, nStartRow, nEndCol, nEndRow, rMark );
      47          30 : }
      48             : 
      49          98 : ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScRange& rRange ) :
      50             :     mbIsEditable(true),
      51          98 :     mbOnlyMatrix(true)
      52             : {
      53          98 :     TestRange( pDoc, rRange );
      54          98 : }
      55             : 
      56          82 : ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScMarkData& rMark ) :
      57             :     mbIsEditable(true),
      58          82 :     mbOnlyMatrix(true)
      59             : {
      60          82 :     TestSelection( pDoc, rMark );
      61          82 : }
      62             : 
      63           0 : ScEditableTester::ScEditableTester( ScViewFunc* pView ) :
      64             :     mbIsEditable(true),
      65           0 :     mbOnlyMatrix(true)
      66             : {
      67           0 :     TestView( pView );
      68           0 : }
      69             : 
      70             : //------------------------------------------------------------------
      71             : 
      72        2240 : void ScEditableTester::TestBlock( ScDocument* pDoc, SCTAB nTab,
      73             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
      74             : {
      75        2240 :     if (mbIsEditable || mbOnlyMatrix)
      76             :     {
      77             :         bool bThisMatrix;
      78        2240 :         if ( !pDoc->IsBlockEditable( nTab, nStartCol, nStartRow, nEndCol, nEndRow, &bThisMatrix ) )
      79             :         {
      80           0 :             mbIsEditable = false;
      81           0 :             if ( !bThisMatrix )
      82           0 :                 mbOnlyMatrix = false;
      83             :         }
      84             :     }
      85        2240 : }
      86             : 
      87          30 : void ScEditableTester::TestSelectedBlock( ScDocument* pDoc,
      88             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
      89             :                         const ScMarkData& rMark )
      90             : {
      91          30 :     SCTAB nTabCount = pDoc->GetTableCount();
      92          30 :     ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
      93          60 :     for (; itr != itrEnd && *itr < nTabCount; ++itr)
      94          30 :         TestBlock( pDoc, *itr, nStartCol, nStartRow, nEndCol, nEndRow );
      95          30 : }
      96             : 
      97          98 : void ScEditableTester::TestRange( ScDocument* pDoc, const ScRange& rRange )
      98             : {
      99          98 :     SCCOL nStartCol = rRange.aStart.Col();
     100          98 :     SCROW nStartRow = rRange.aStart.Row();
     101          98 :     SCTAB nStartTab = rRange.aStart.Tab();
     102          98 :     SCCOL nEndCol = rRange.aEnd.Col();
     103          98 :     SCROW nEndRow = rRange.aEnd.Row();
     104          98 :     SCTAB nEndTab = rRange.aEnd.Tab();
     105         196 :     for (SCTAB nTab=nStartTab; nTab<=nEndTab; nTab++)
     106          98 :         TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
     107          98 : }
     108             : 
     109          82 : void ScEditableTester::TestSelection( ScDocument* pDoc, const ScMarkData& rMark )
     110             : {
     111          82 :     if (mbIsEditable || mbOnlyMatrix)
     112             :     {
     113             :         bool bThisMatrix;
     114          82 :         if ( !pDoc->IsSelectionEditable( rMark, &bThisMatrix ) )
     115             :         {
     116           0 :             mbIsEditable = false;
     117           0 :             if ( !bThisMatrix )
     118           0 :                 mbOnlyMatrix = false;
     119             :         }
     120             :     }
     121          82 : }
     122             : 
     123           0 : void ScEditableTester::TestView( ScViewFunc* pView )
     124             : {
     125           0 :     if (mbIsEditable || mbOnlyMatrix)
     126             :     {
     127             :         bool bThisMatrix;
     128           0 :         if ( !pView->SelectionEditable( &bThisMatrix ) )
     129             :         {
     130           0 :             mbIsEditable = false;
     131           0 :             if ( !bThisMatrix )
     132           0 :                 mbOnlyMatrix = false;
     133             :         }
     134             :     }
     135           0 : }
     136             : 
     137             : //------------------------------------------------------------------
     138             : 
     139           0 : sal_uInt16 ScEditableTester::GetMessageId() const
     140             : {
     141           0 :     if (mbIsEditable)
     142           0 :         return 0;
     143           0 :     else if (mbOnlyMatrix)
     144           0 :         return STR_MATRIXFRAGMENTERR;
     145             :     else
     146           0 :         return STR_PROTECTIONERR;
     147          93 : }
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10