LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/txtnode - modeltoviewhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 36 100.0 %
Date: 2013-07-09 Functions: 2 2 100.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 <modeltoviewhelper.hxx>
      21             : 
      22             : /** Converts a model position into a view position
      23             : */
      24        1864 : sal_uInt32 ModelToViewHelper::ConvertToViewPosition( sal_uInt32 nModelPos ) const
      25             : {
      26        1864 :     sal_uInt32 nRet = nModelPos;
      27             : 
      28             :     // Search for entry after nPos:
      29        1864 :     ConversionMap::const_iterator aIter;
      30        2656 :     for ( aIter = m_aMap.begin(); aIter != m_aMap.end(); ++aIter )
      31             :     {
      32        1724 :         if ( (*aIter).first >= nModelPos )
      33             :         {
      34         932 :             const sal_uInt32 nPosModel  = (*aIter).first;
      35         932 :             const sal_uInt32 nPosExpand = (*aIter).second;
      36             : 
      37         932 :             const sal_uInt32 nDistToNextModel  = nPosModel - nModelPos;
      38         932 :             nRet = nPosExpand - nDistToNextModel;
      39         932 :             break;
      40             :         }
      41             :     }
      42             : 
      43        1864 :     return nRet;
      44             : }
      45             : 
      46             : 
      47             : /** Converts a view position into a model position
      48             : */
      49       22030 : ModelToViewHelper::ModelPosition ModelToViewHelper::ConvertToModelPosition( sal_uInt32 nViewPos ) const
      50             : {
      51       22030 :     ModelPosition aRet;
      52       22030 :     aRet.mnPos = nViewPos;
      53             : 
      54             :     // Search for entry after nPos:
      55       22030 :     ConversionMap::const_iterator aIter;
      56       22108 :     for ( aIter = m_aMap.begin(); aIter != m_aMap.end(); ++aIter )
      57             :     {
      58         205 :         if ( (*aIter).second > nViewPos )
      59             :         {
      60         127 :             const sal_uInt32 nPosModel  = (*aIter).first;
      61         127 :             const sal_uInt32 nPosExpand = (*aIter).second;
      62             : 
      63             :             // If nViewPos is in front of first field, we are finished.
      64         127 :             if ( aIter == m_aMap.begin() )
      65          82 :                 break;
      66             : 
      67          45 :             --aIter;
      68             : 
      69             :             // nPrevPosModel is the field position
      70          45 :             const sal_uInt32 nPrevPosModel  = (*aIter).first;
      71          45 :             const sal_uInt32 nPrevPosExpand = (*aIter).second;
      72             : 
      73          45 :             const sal_uInt32 nLengthModel  = nPosModel - nPrevPosModel;
      74          45 :             const sal_uInt32 nLengthExpand = nPosExpand - nPrevPosExpand;
      75             : 
      76          45 :             const sal_uInt32 nFieldLengthExpand = nLengthExpand - nLengthModel + 1;
      77          45 :             const sal_uInt32 nFieldEndExpand = nPrevPosExpand + nFieldLengthExpand;
      78             : 
      79             :             // Check if nPos is outside of field:
      80          45 :             if ( nFieldEndExpand <= nViewPos )
      81             :             {
      82             :                 // nPos is outside of field:
      83          13 :                 const sal_uInt32 nDistToField = nViewPos - nFieldEndExpand + 1;
      84          13 :                 aRet.mnPos  = nPrevPosModel + nDistToField;
      85             :             }
      86             :             else
      87             :             {
      88             :                 // nViewPos is inside a field:
      89          32 :                 aRet.mnPos = nPrevPosModel;
      90          32 :                 aRet.mnSubPos = nViewPos - nPrevPosExpand;
      91          32 :                 aRet.mbIsField = true;
      92             :             }
      93             : 
      94          45 :             break;
      95             :         }
      96             :     }
      97             : 
      98       22030 :     return aRet;
      99             : }
     100             : 
     101             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10