LCOV - code coverage report
Current view: top level - sw/inc - modeltoviewhelper.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 8 0.0 %
Date: 2014-04-14 Functions: 0 7 0.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             : #ifndef INCLUDED_SW_INC_MODELTOVIEWHELPER_HXX
      21             : #define INCLUDED_SW_INC_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 EXPANDFOOTNOTE 0x0002
      67             : #define HIDEINVISIBLE  0x0004
      68             : #define HIDEREDLINED   0x0008
      69             : /// do not expand to content, but replace with ZWSP
      70             : #define REPLACEMODE    0x0010
      71             : 
      72           0 : class ModelToViewHelper
      73             : {
      74             :     /** For each field in the model string, there is an entry in the conversion
      75             :         map. The first value of the ConversionMapEntry points to the field
      76             :         position in the model string, the second value points to the associated
      77             :         position in the view string. The last entry in the conversion map
      78             :         denotes the lengths of the model resp. view string.
      79             :     */
      80             :     typedef std::pair< sal_Int32 , sal_Int32 > ConversionMapEntry;
      81             :     typedef std::vector< ConversionMapEntry > ConversionMap;
      82             :     typedef std::vector<sal_Int32> Positions;
      83             : 
      84             :     ConversionMap m_aMap;
      85             :     /// store positions of fields and footnotes for grammar checkers
      86             :     Positions m_FieldPositions;
      87             :     Positions m_FootnotePositions;
      88             : 
      89             :     OUString m_aRetText;
      90             : 
      91             : public:
      92             : 
      93             :     /** This struct defines a position in the model string.
      94             : 
      95             :         The 'main' position is given by mnPos. If there's a field located at
      96             :         this position, mbIsField is set and mnSubPos denotes the position inside
      97             :         that field.
      98             :     */
      99             :     struct ModelPosition
     100             :     {
     101             :         sal_Int32 mnPos;
     102             :         sal_Int32 mnSubPos;
     103             :         bool mbIsField;
     104             : 
     105           0 :         ModelPosition() : mnPos(0), mnSubPos(0), mbIsField(false) {}
     106             :     };
     107             : 
     108             :     ModelToViewHelper(const SwTxtNode &rNode,
     109             :             // defaults are appropriate for spell/grammar checking
     110             :             sal_uInt16 eMode = EXPANDFIELDS | EXPANDFOOTNOTE | REPLACEMODE);
     111           0 :     ModelToViewHelper() //pass through filter, view == model
     112           0 :     {
     113           0 :     }
     114             : 
     115             :     /** Converts a model position into a view position
     116             : 
     117             :         @param nPos
     118             :             nPos denotes a position in the model string which should be
     119             :             converted. Note that converting model positions inside fields is
     120             :             not supported, therefore nPos is not of type ModelPosition.
     121             : 
     122             :         @return
     123             :             the position of nPos in the view string. In case the conversion
     124             :             could not be performed (e.g., because there is not ConversionMap or
     125             :             nPos is behind the last entry in the conversion map) nPos will
     126             :             be returned.
     127             :     */
     128             :     sal_Int32 ConvertToViewPosition( sal_Int32 nModelPos ) const;
     129             : 
     130             :     /** Converts a view position into a model position
     131             : 
     132             :         @param nPos
     133             :             nPos denotes a position in the view string which should be
     134             :             converted.
     135             : 
     136             :         @return
     137             :             the position of nPos in the model string. In case the conversion
     138             :             could not be performed (e.g., because there is not ConversionMap or
     139             :             nPos is behind the last entry in the conversion map) a model
     140             :             model position with mnPos = nPos and mnIsField = false will be
     141             :             returned.
     142             :     */
     143             :     ModelPosition ConvertToModelPosition( sal_Int32 nViewPos ) const;
     144             : 
     145           0 :     OUString getViewText() const { return m_aRetText; }
     146           0 :     Positions const& getFieldPositions() const { return m_FieldPositions; }
     147           0 :     Positions const& getFootnotePositions() const { return m_FootnotePositions;}
     148             : };
     149             : 
     150             : #endif
     151             : 
     152             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10