LCOV - code coverage report
Current view: top level - sw/inc - modeltoviewhelper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 6 100.0 %
Date: 2012-08-25 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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                 :            : #ifndef _MODELTOVIEWHELPER_HXX
      21                 :            : #define _MODELTOVIEWHELPER_HXX
      22                 :            : 
      23                 :            : #include <rtl/ustring.hxx>
      24                 :            : #include <sal/types.h>
      25                 :            : #include <vector>
      26                 :            : 
      27                 :            : class SwTxtNode;
      28                 :            : 
      29                 :            : /** Some helpers for converting model strings to view strings.
      30                 :            : 
      31                 :            :     A paragraph string does not have its fields expanded, i.e., they are
      32                 :            :     represented by a special character inside the string with an additional
      33                 :            :     attribute assigned to it. For some tasks (e.g., SmartTags) it is required
      34                 :            :     to expand the fields to get the string as it appears in the view. Two
      35                 :            :     helper functions are provided to convert model positions to view positions
      36                 :            :     and vice versa.
      37                 :            : 
      38                 :            :            CH_TXTATR_BREAKWORD -> SwTxtNode will have field attributes associated with these
      39                 :            :                 .       .
      40                 :            :                 .       .
      41                 :            :                 .       .
      42                 :            :     AAAAA BBBBB # CCCCC # DDDDD
      43                 :            :         | |  |    |
      44                 :            :         | |  |    |
      45                 :            :         | ---------
      46                 :            :         |    |  .
      47                 :            :         |    |  .
      48                 :            :         |    |  .......... bounds of a hidden text character attribute
      49                 :            :         ------
      50                 :            :            .
      51                 :            :            .
      52                 :            :            .............. a range of text defined in redline region as deleted
      53                 :            : 
      54                 :            :     0000: pass through gives:                                        AAAAA BBBBB # CCCCC # DDDDD
      55                 :            :     0001: only expanding fields gives:                               AAAAA BBBBB foo CCCCC foo DDDDD
      56                 :            :     0010: only hiding hiddens gives:                                 AAAAA CCCCC # DDDDD
      57                 :            :     0100: only hiding redlines gives:                                AAAABB # CCCCC # DDDDD
      58                 :            :     0011: expanding fields + hiding hiddens gives:                   AAAAA CCCC foo DDDDD
      59                 :            :     0101: expanding fields + hiding redlines gives:                  AAAA B foo CCCCC foo DDDDD
      60                 :            :     0110: hiding hiddens + hiding redlines gives:                    AAAACCCC # DDDDD
      61                 :            :     0111: expanding fields + hiding hiddens + hiding redlines gives: AAAABB foo CCCCC foo DDDDD
      62                 :            : */
      63                 :            : 
      64                 :            : #define PASSTHROUGH   0x0000
      65                 :            : #define EXPANDFIELDS  0x0001
      66                 :            : #define HIDEINVISIBLE 0x0002
      67                 :            : #define HIDEREDLINED  0x0004
      68                 :            : 
      69                 :      21980 : class ModelToViewHelper
      70                 :            : {
      71                 :            :     /** For each field in the model string, there is an entry in the conversion
      72                 :            :         map. The first value of the ConversionMapEntry points to the field
      73                 :            :         position in the model string, the second value points to the associated
      74                 :            :         position in the view string. The last entry in the conversion map
      75                 :            :         denotes the lengths of the model resp. view string.
      76                 :            :     */
      77                 :            :     typedef std::pair< sal_uInt32 , sal_uInt32 > ConversionMapEntry;
      78                 :            :     typedef std::vector< ConversionMapEntry > ConversionMap;
      79                 :            : 
      80                 :            :     ConversionMap m_aMap;
      81                 :            : 
      82                 :            :     rtl::OUString m_aRetText;
      83                 :            : 
      84                 :            : public:
      85                 :            : 
      86                 :            :     /** This struct defines a position in the model string.
      87                 :            : 
      88                 :            :         The 'main' position is given by mnPos. If there's a field located at
      89                 :            :         this position, mbIsField is set and mnSubPos denotes the position inside
      90                 :            :         that field.
      91                 :            :     */
      92                 :            :     struct ModelPosition
      93                 :            :     {
      94                 :            :         sal_uInt32 mnPos;
      95                 :            :         sal_uInt32 mnSubPos;
      96                 :            :         bool mbIsField;
      97                 :            : 
      98                 :     119393 :         ModelPosition() : mnPos(0), mnSubPos(0), mbIsField(false) {}
      99                 :            :     };
     100                 :            : 
     101                 :            :     ModelToViewHelper(const SwTxtNode &rNode, int eMode = EXPANDFIELDS);
     102                 :       5108 :     ModelToViewHelper() //pass through filter, view == model
     103                 :       5108 :     {
     104                 :       5108 :     }
     105                 :            : 
     106                 :            :     /** Converts a model position into a view position
     107                 :            : 
     108                 :            :         @param nPos
     109                 :            :             nPos denotes a position in the model string which should be
     110                 :            :             converted. Note that converting model positions inside fields is
     111                 :            :             not supported, therefore nPos is not of type ModelPosition.
     112                 :            : 
     113                 :            :         @return
     114                 :            :             the position of nPos in the view string. In case the conversion
     115                 :            :             could not be performed (e.g., because there is not ConversionMap or
     116                 :            :             nPos is behind the last entry in the conversion map) nPos will
     117                 :            :             be returned.
     118                 :            :     */
     119                 :            :     sal_uInt32 ConvertToViewPosition( sal_uInt32 nModelPos ) const;
     120                 :            : 
     121                 :            :     /** Converts a view position into a model position
     122                 :            : 
     123                 :            :         @param nPos
     124                 :            :             nPos denotes a position in the view string which should be
     125                 :            :             converted.
     126                 :            : 
     127                 :            :         @return
     128                 :            :             the position of nPos in the model string. In case the conversion
     129                 :            :             could not be performed (e.g., because there is not ConversionMap or
     130                 :            :             nPos is behind the last entry in the conversion map) a model
     131                 :            :             model position with mnPos = nPos and mnIsField = false will be
     132                 :            :             returned.
     133                 :            :     */
     134                 :            :     ModelPosition ConvertToModelPosition( sal_uInt32 nViewPos ) const;
     135                 :            : 
     136                 :       7346 :     rtl::OUString getViewText() const { return m_aRetText; }
     137                 :            : };
     138                 :            : 
     139                 :            : #endif
     140                 :            : 
     141                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10