lok: Hide file linking in section
[LibreOffice.git] / sw / inc / modeltoviewhelper.hxx
blob7ca5397e3e813e741ff9263552d10bca53fa9105
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SW_INC_MODELTOVIEWHELPER_HXX
21 #define INCLUDED_SW_INC_MODELTOVIEWHELPER_HXX
23 #include <rtl/ustring.hxx>
24 #include <sal/types.h>
25 #include <o3tl/typed_flags_set.hxx>
26 #include <vector>
28 class SwTextNode;
29 class SwRootFrame;
31 /** Some helpers for converting model strings to view strings.
33 A paragraph string does not have its fields expanded, i.e., they are
34 represented by a special character inside the string with an additional
35 attribute assigned to it. For some tasks (e.g., SmartTags) it is required
36 to expand the fields to get the string as it appears in the view. Two
37 helper functions are provided to convert model positions to view positions
38 and vice versa.
40 CH_TXTATR_BREAKWORD -> SwTextNode will have field attributes associated with these
41 . .
42 . .
43 . .
44 AAAAA BBBBB # CCCCC # DDDDD
45 | | | |
46 | | | |
47 | ---------
48 | | .
49 | | .
50 | | .......... bounds of a hidden text character attribute
51 ------
54 .............. a range of text defined in redline region as deleted
56 0000: pass through gives: AAAAA BBBBB # CCCCC # DDDDD
57 0001: only expanding fields gives: AAAAA BBBBB foo CCCCC foo DDDDD
58 0010: only hiding hiddens gives: AAAAA CCCCC # DDDDD
59 0100: only hiding redlines gives: AAAABB # CCCCC # DDDDD
60 0011: expanding fields + hiding hiddens gives: AAAAA CCCC foo DDDDD
61 0101: expanding fields + hiding redlines gives: AAAA B foo CCCCC foo DDDDD
62 0110: hiding hiddens + hiding redlines gives: AAAACCCC # DDDDD
63 0111: expanding fields + hiding hiddens + hiding redlines gives: AAAABB foo CCCCC foo DDDDD
66 enum class ExpandMode
68 PassThrough = 0x0000,
69 ExpandFields = 0x0001,
70 ExpandFootnote = 0x0002,
71 HideInvisible = 0x0004,
72 HideDeletions = 0x0008,
73 /// do not expand to content, but replace with zwsp
74 ReplaceMode = 0x0010,
77 namespace o3tl
79 template<> struct typed_flags<ExpandMode> : is_typed_flags<ExpandMode, 0x001f> {};
82 class ModelToViewHelper
84 /** For each expanded/hidden portion in the model string, there is an entry in
85 the conversion map. The first value of the ConversionMapEntry points to
86 the start position in the model string, the second value points to the
87 associated start position in the view string. The last entry in the
88 conversion map denotes the lengths of the model resp. view string.
90 struct ConversionMapEntry
92 ConversionMapEntry(sal_Int32 nModelPos, sal_Int32 nViewPos, bool bVisible)
93 : m_nModelPos(nModelPos)
94 , m_nViewPos(nViewPos)
95 , m_bVisible(bVisible)
98 sal_Int32 const m_nModelPos;
99 sal_Int32 const m_nViewPos;
100 bool const m_bVisible;
102 typedef std::vector< ConversionMapEntry > ConversionMap;
104 ConversionMap m_aMap;
105 /// store positions of fields and footnotes for grammar checkers
106 std::vector<sal_Int32> m_FieldPositions;
107 std::vector<sal_Int32> m_FootnotePositions;
109 OUString m_aRetText;
111 public:
113 /** This struct defines a position in the model string.
115 The 'main' position is given by mnPos. If there's a field located at
116 this position, mbIsField is set and mnSubPos denotes the position inside
117 that field.
119 struct ModelPosition
121 sal_Int32 mnPos;
122 sal_Int32 mnSubPos;
123 bool mbIsField;
125 ModelPosition() : mnPos(0), mnSubPos(0), mbIsField(false) {}
128 ModelToViewHelper(const SwTextNode &rNode, SwRootFrame const* pLayout,
129 // defaults are appropriate for spell/grammar checking
130 ExpandMode eMode = ExpandMode::ExpandFields | ExpandMode::ExpandFootnote | ExpandMode::ReplaceMode);
131 ModelToViewHelper() //pass through filter, view == model
135 /** Converts a model position into a view position
137 @param nPos
138 nPos denotes a position in the model string which should be
139 converted. Note that converting model positions inside fields is
140 not supported, therefore nPos is not of type ModelPosition.
142 @return
143 the position of nPos in the view string. In case the conversion
144 could not be performed (e.g., because there is not ConversionMap or
145 nPos is behind the last entry in the conversion map) nPos will
146 be returned.
148 sal_Int32 ConvertToViewPosition( sal_Int32 nModelPos ) const;
150 /** Converts a view position into a model position
152 @param nPos
153 nPos denotes a position in the view string which should be
154 converted.
156 @return
157 the position of nPos in the model string. In case the conversion
158 could not be performed (e.g., because there is not ConversionMap or
159 nPos is behind the last entry in the conversion map) a model
160 model position with mnPos = nPos and mnIsField = false will be
161 returned.
163 ModelPosition ConvertToModelPosition( sal_Int32 nViewPos ) const;
165 const OUString& getViewText() const { return m_aRetText; }
166 std::vector<sal_Int32> const& getFieldPositions() const { return m_FieldPositions; }
167 std::vector<sal_Int32> const& getFootnotePositions() const { return m_FootnotePositions;}
170 #endif
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */