android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / inc / modeltoviewhelper.hxx
blobc045c283718484a16090a6730a408b9525a85e4b
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,
75 HideFieldmarkCommands = 0x0020,
78 namespace o3tl
80 template<> struct typed_flags<ExpandMode> : is_typed_flags<ExpandMode, 0x003f> {};
83 class ModelToViewHelper
85 /** For each expanded/hidden portion in the model string, there is an entry in
86 the conversion map. The first value of the ConversionMapEntry points to
87 the start position in the model string, the second value points to the
88 associated start position in the view string. The last entry in the
89 conversion map denotes the lengths of the model resp. view string.
91 struct ConversionMapEntry
93 ConversionMapEntry(sal_Int32 nModelPos, sal_Int32 nViewPos, bool bVisible)
94 : m_nModelPos(nModelPos)
95 , m_nViewPos(nViewPos)
96 , m_bVisible(bVisible)
99 sal_Int32 m_nModelPos;
100 sal_Int32 m_nViewPos;
101 bool m_bVisible;
103 typedef std::vector< ConversionMapEntry > ConversionMap;
105 ConversionMap m_aMap;
106 /// store positions of fields and footnotes for grammar checkers
107 std::vector<sal_Int32> m_FieldPositions;
108 std::vector<sal_Int32> m_FootnotePositions;
110 OUString m_aRetText;
112 public:
114 /** This struct defines a position in the model string.
116 The 'main' position is given by mnPos. If there's a field located at
117 this position, mbIsField is set and mnSubPos denotes the position inside
118 that field.
120 struct ModelPosition
122 sal_Int32 mnPos;
123 sal_Int32 mnSubPos;
124 bool mbIsField;
126 ModelPosition() : mnPos(0), mnSubPos(0), mbIsField(false) {}
129 ModelToViewHelper(const SwTextNode &rNode, SwRootFrame const* pLayout,
130 // defaults are appropriate for spell/grammar checking
131 ExpandMode eMode = ExpandMode::ExpandFields | ExpandMode::ExpandFootnote | ExpandMode::HideFieldmarkCommands | ExpandMode::ReplaceMode);
132 ModelToViewHelper() //pass through filter, view == model
136 /** Converts a model position into a view position
138 @param nPos
139 nPos denotes a position in the model string which should be
140 converted. Note that converting model positions inside fields is
141 not supported, therefore nPos is not of type ModelPosition.
143 @return
144 the position of nPos in the view string. In case the conversion
145 could not be performed (e.g., because there is not ConversionMap or
146 nPos is behind the last entry in the conversion map) nPos will
147 be returned.
149 sal_Int32 ConvertToViewPosition( sal_Int32 nModelPos ) const;
151 /** Converts a view position into a model position
153 @param nPos
154 nPos denotes a position in the view string which should be
155 converted.
157 @return
158 the position of nPos in the model string. In case the conversion
159 could not be performed (e.g., because there is not ConversionMap or
160 nPos is behind the last entry in the conversion map) a model
161 model position with mnPos = nPos and mnIsField = false will be
162 returned.
164 ModelPosition ConvertToModelPosition( sal_Int32 nViewPos ) const;
166 const OUString& getViewText() const { return m_aRetText; }
167 std::vector<sal_Int32> const& getFieldPositions() const { return m_FieldPositions; }
168 std::vector<sal_Int32> const& getFootnotePositions() const { return m_FootnotePositions;}
171 #endif
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */