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

Generated by: LCOV version 1.10