LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/docshell - editable.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 44 67 65.7 %
Date: 2012-12-17 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             : //------------------------------------------------------------------
      27             : 
      28           2 : ScEditableTester::ScEditableTester() :
      29             :     bIsEditable( sal_True ),
      30           2 :     bOnlyMatrix( sal_True )
      31             : {
      32           2 : }
      33             : 
      34          60 : ScEditableTester::ScEditableTester( ScDocument* pDoc, SCTAB nTab,
      35             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) :
      36             :     bIsEditable( sal_True ),
      37          60 :     bOnlyMatrix( sal_True )
      38             : {
      39          60 :     TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
      40          60 : }
      41             : 
      42           2 : ScEditableTester::ScEditableTester( ScDocument* pDoc,
      43             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
      44             :                         const ScMarkData& rMark ) :
      45             :     bIsEditable( sal_True ),
      46           2 :     bOnlyMatrix( sal_True )
      47             : {
      48           2 :     TestSelectedBlock( pDoc, nStartCol, nStartRow, nEndCol, nEndRow, rMark );
      49           2 : }
      50             : 
      51         120 : ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScRange& rRange ) :
      52             :     bIsEditable( sal_True ),
      53         120 :     bOnlyMatrix( sal_True )
      54             : {
      55         120 :     TestRange( pDoc, rRange );
      56         120 : }
      57             : 
      58           2 : ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScMarkData& rMark ) :
      59             :     bIsEditable( sal_True ),
      60           2 :     bOnlyMatrix( sal_True )
      61             : {
      62           2 :     TestSelection( pDoc, rMark );
      63           2 : }
      64             : 
      65           0 : ScEditableTester::ScEditableTester( ScViewFunc* pView ) :
      66             :     bIsEditable( sal_True ),
      67           0 :     bOnlyMatrix( sal_True )
      68             : {
      69           0 :     TestView( pView );
      70           0 : }
      71             : 
      72             : //------------------------------------------------------------------
      73             : 
      74         184 : void ScEditableTester::TestBlock( ScDocument* pDoc, SCTAB nTab,
      75             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
      76             : {
      77         184 :     if ( bIsEditable || bOnlyMatrix )
      78             :     {
      79             :         bool bThisMatrix;
      80         184 :         if ( !pDoc->IsBlockEditable( nTab, nStartCol, nStartRow, nEndCol, nEndRow, &bThisMatrix ) )
      81             :         {
      82           0 :             bIsEditable = false;
      83           0 :             if ( !bThisMatrix )
      84           0 :                 bOnlyMatrix = false;
      85             :         }
      86             :     }
      87         184 : }
      88             : 
      89           2 : void ScEditableTester::TestSelectedBlock( ScDocument* pDoc,
      90             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
      91             :                         const ScMarkData& rMark )
      92             : {
      93           2 :     SCTAB nTabCount = pDoc->GetTableCount();
      94           2 :     ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
      95           4 :     for (; itr != itrEnd && *itr < nTabCount; ++itr)
      96           2 :         TestBlock( pDoc, *itr, nStartCol, nStartRow, nEndCol, nEndRow );
      97           2 : }
      98             : 
      99         120 : void ScEditableTester::TestRange( ScDocument* pDoc, const ScRange& rRange )
     100             : {
     101         120 :     SCCOL nStartCol = rRange.aStart.Col();
     102         120 :     SCROW nStartRow = rRange.aStart.Row();
     103         120 :     SCTAB nStartTab = rRange.aStart.Tab();
     104         120 :     SCCOL nEndCol = rRange.aEnd.Col();
     105         120 :     SCROW nEndRow = rRange.aEnd.Row();
     106         120 :     SCTAB nEndTab = rRange.aEnd.Tab();
     107         240 :     for (SCTAB nTab=nStartTab; nTab<=nEndTab; nTab++)
     108         120 :         TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
     109         120 : }
     110             : 
     111           2 : void ScEditableTester::TestSelection( ScDocument* pDoc, const ScMarkData& rMark )
     112             : {
     113           2 :     if ( bIsEditable || bOnlyMatrix )
     114             :     {
     115             :         bool bThisMatrix;
     116           2 :         if ( !pDoc->IsSelectionEditable( rMark, &bThisMatrix ) )
     117             :         {
     118           0 :             bIsEditable = false;
     119           0 :             if ( !bThisMatrix )
     120           0 :                 bOnlyMatrix = false;
     121             :         }
     122             :     }
     123           2 : }
     124             : 
     125           0 : void ScEditableTester::TestView( ScViewFunc* pView )
     126             : {
     127           0 :     if ( bIsEditable || bOnlyMatrix )
     128             :     {
     129             :         bool bThisMatrix;
     130           0 :         if ( !pView->SelectionEditable( &bThisMatrix ) )
     131             :         {
     132           0 :             bIsEditable = false;
     133           0 :             if ( !bThisMatrix )
     134           0 :                 bOnlyMatrix = false;
     135             :         }
     136             :     }
     137           0 : }
     138             : 
     139             : //------------------------------------------------------------------
     140             : 
     141           0 : sal_uInt16 ScEditableTester::GetMessageId() const
     142             : {
     143           0 :     if (bIsEditable)
     144           0 :         return 0;
     145           0 :     else if (bOnlyMatrix)
     146           0 :         return STR_MATRIXFRAGMENTERR;
     147             :     else
     148           0 :         return STR_PROTECTIONERR;
     149         102 : }
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10