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: 22 67 32.8 %
Date: 2012-12-27 Functions: 7 14 50.0 %
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           1 : ScEditableTester::ScEditableTester() :
      29             :     bIsEditable( sal_True ),
      30           1 :     bOnlyMatrix( sal_True )
      31             : {
      32           1 : }
      33             : 
      34           6 : ScEditableTester::ScEditableTester( ScDocument* pDoc, SCTAB nTab,
      35             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) :
      36             :     bIsEditable( sal_True ),
      37           6 :     bOnlyMatrix( sal_True )
      38             : {
      39           6 :     TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
      40           6 : }
      41             : 
      42           1 : ScEditableTester::ScEditableTester( ScDocument* pDoc,
      43             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
      44             :                         const ScMarkData& rMark ) :
      45             :     bIsEditable( sal_True ),
      46           1 :     bOnlyMatrix( sal_True )
      47             : {
      48           1 :     TestSelectedBlock( pDoc, nStartCol, nStartRow, nEndCol, nEndRow, rMark );
      49           1 : }
      50             : 
      51           0 : ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScRange& rRange ) :
      52             :     bIsEditable( sal_True ),
      53           0 :     bOnlyMatrix( sal_True )
      54             : {
      55           0 :     TestRange( pDoc, rRange );
      56           0 : }
      57             : 
      58           0 : ScEditableTester::ScEditableTester( ScDocument* pDoc, const ScMarkData& rMark ) :
      59             :     bIsEditable( sal_True ),
      60           0 :     bOnlyMatrix( sal_True )
      61             : {
      62           0 :     TestSelection( pDoc, rMark );
      63           0 : }
      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           8 : void ScEditableTester::TestBlock( ScDocument* pDoc, SCTAB nTab,
      75             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
      76             : {
      77           8 :     if ( bIsEditable || bOnlyMatrix )
      78             :     {
      79             :         bool bThisMatrix;
      80           8 :         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           8 : }
      88             : 
      89           1 : void ScEditableTester::TestSelectedBlock( ScDocument* pDoc,
      90             :                         SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
      91             :                         const ScMarkData& rMark )
      92             : {
      93           1 :     SCTAB nTabCount = pDoc->GetTableCount();
      94           1 :     ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
      95           2 :     for (; itr != itrEnd && *itr < nTabCount; ++itr)
      96           1 :         TestBlock( pDoc, *itr, nStartCol, nStartRow, nEndCol, nEndRow );
      97           1 : }
      98             : 
      99           0 : void ScEditableTester::TestRange( ScDocument* pDoc, const ScRange& rRange )
     100             : {
     101           0 :     SCCOL nStartCol = rRange.aStart.Col();
     102           0 :     SCROW nStartRow = rRange.aStart.Row();
     103           0 :     SCTAB nStartTab = rRange.aStart.Tab();
     104           0 :     SCCOL nEndCol = rRange.aEnd.Col();
     105           0 :     SCROW nEndRow = rRange.aEnd.Row();
     106           0 :     SCTAB nEndTab = rRange.aEnd.Tab();
     107           0 :     for (SCTAB nTab=nStartTab; nTab<=nEndTab; nTab++)
     108           0 :         TestBlock( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
     109           0 : }
     110             : 
     111           0 : void ScEditableTester::TestSelection( ScDocument* pDoc, const ScMarkData& rMark )
     112             : {
     113           0 :     if ( bIsEditable || bOnlyMatrix )
     114             :     {
     115             :         bool bThisMatrix;
     116           0 :         if ( !pDoc->IsSelectionEditable( rMark, &bThisMatrix ) )
     117             :         {
     118           0 :             bIsEditable = false;
     119           0 :             if ( !bThisMatrix )
     120           0 :                 bOnlyMatrix = false;
     121             :         }
     122             :     }
     123           0 : }
     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          15 : }
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10