ITEM: Refactor ItemType
[LibreOffice.git] / sw / source / core / access / accportions.hxx
blob01725c0007def3af4c2c56ca2f5cda90b7808913
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_SOURCE_CORE_ACCESS_ACCPORTIONS_HXX
21 #define INCLUDED_SW_SOURCE_CORE_ACCESS_ACCPORTIONS_HXX
23 #include <SwPortionHandler.hxx>
24 #include <sal/types.h>
25 #include <rtl/ustrbuf.hxx>
26 #include <memory>
27 #include <vector>
29 class SwTextFrame;
30 struct SwSpecialPos;
31 class SwViewOption;
32 namespace com::sun::star {
33 namespace i18n { struct Boundary; }
36 /**
37 * collect text portion data from the layout through SwPortionHandler interface
39 class SwAccessiblePortionData : public SwPortionHandler
41 // the frame this portion is referring to
42 SwTextFrame const* m_pTextFrame;
44 // variables used while collecting the data
45 OUStringBuffer m_aBuffer;
46 TextFrameIndex m_nViewPosition;
47 const SwViewOption* m_pViewOptions;
49 /// the accessible string
50 /// note that the content is different both from the string in the text
51 /// node(s) as well as the string in the text frame, so there are 3
52 /// different index spaces involved.
53 OUString m_sAccessibleString;
55 // positions array
56 // instances of Position_t must always include the minimum and
57 // maximum positions as first/last elements (to simplify the
58 // algorithms)
59 typedef std::vector<sal_Int32> AccessiblePositions;
60 typedef std::vector<TextFrameIndex> FramePositions;
62 AccessiblePositions m_aLineBreaks; /// position of line breaks
63 FramePositions m_ViewPositions; /// position of portion breaks in the core view
64 AccessiblePositions m_aAccessiblePositions; /// portion breaks in m_sAccessibleString
65 AccessiblePositions m_aFieldPosition;
67 std::vector<sal_uInt8> m_aPortionAttrs; /// additional portion attributes
69 std::unique_ptr<AccessiblePositions> m_pSentences; /// positions of sentence breaks
71 size_t m_nBeforePortions; /// # of portions before first core character
72 bool m_bFinished;
74 /// fill the boundary with the values from rPositions[nPos]
75 static void FillBoundary(css::i18n::Boundary& rBound,
76 const AccessiblePositions& rPositions,
77 size_t nPos );
79 /// Access to portion attributes
80 bool IsPortionAttrSet( size_t nPortionNo, sal_uInt8 nAttr ) const;
81 bool IsSpecialPortion( size_t nPortionNo ) const;
82 bool IsGrayPortionType( PortionType nType ) const;
84 // helper method for GetEditableRange(...):
85 void AdjustAndCheck( sal_Int32 nPos, size_t& nPortionNo,
86 TextFrameIndex& rCorePos, bool& bEdit) const;
88 public:
89 SwAccessiblePortionData( const SwTextFrame* pTextFrame,
90 const SwViewOption* pViewOpt );
91 virtual ~SwAccessiblePortionData() override;
93 // SwPortionHandler methods
94 virtual void Text(TextFrameIndex nLength, PortionType nType) override;
95 virtual void Special(TextFrameIndex nLength, const OUString& rText, PortionType nType) override;
96 virtual void LineBreak() override;
97 virtual void Skip(TextFrameIndex nLength) override;
98 virtual void Finish() override;
100 bool FillBoundaryIFDateField( css::i18n::Boundary& rBound, const sal_Int32 nPos );
101 bool IsIndexInFootnode(sal_Int32 nIndex);
102 bool IsInGrayPortion( sal_Int32 nPos );
103 sal_Int32 GetFieldIndex(sal_Int32 nPos) const;
105 bool IsZeroCorePositionData();
107 // access to the portion data
109 /// get the text string, as presented by the layout
110 const OUString& GetAccessibleString() const;
112 /// get the start & end positions of the sentence
113 void GetLineBoundary( css::i18n::Boundary& rBound,
114 sal_Int32 nPos ) const;
116 // get start and end position of the last line
117 void GetLastLineBoundary( css::i18n::Boundary& rBound ) const;
119 /// Determine whether this core position is valid for these portions.
120 /// (A paragraph may be split into several frames, e.g. at page
121 /// boundaries. In this case, only part of a paragraph is represented
122 /// through this object. This method determines whether one particular
123 /// position is valid for this object or not.)
124 bool IsValidCorePosition(TextFrameIndex nPos) const;
125 TextFrameIndex GetFirstValidCorePosition() const;
126 TextFrameIndex GetLastValidCorePosition() const;
128 /// get the position in the accessibility string for a given view position
129 sal_Int32 GetAccessiblePosition(TextFrameIndex nPos) const;
131 // #i89175#
132 sal_Int32 GetLineCount() const;
133 sal_Int32 GetLineNo( const sal_Int32 nPos ) const;
134 void GetBoundaryOfLine( const sal_Int32 nLineNo,
135 css::i18n::Boundary& rLineBound );
137 /// get the position in the core view string for a given
138 /// (accessibility) position
139 TextFrameIndex GetCoreViewPosition(sal_Int32 nPos) const;
141 /// fill a SwSpecialPos structure, suitable for calling
142 /// SwTextFrame->GetCharRect
143 /// Returns the core position, and fills rpPos either with NULL or
144 /// with the &rPos, after putting the appropriate data into it.
145 TextFrameIndex FillSpecialPos(sal_Int32 nPos,
146 SwSpecialPos& rPos,
147 SwSpecialPos*& rpPos ) const;
149 // get boundaries of words/sentences. The data structures are
150 // created on-demand.
151 void GetSentenceBoundary( css::i18n::Boundary& rBound,
152 sal_Int32 nPos );
154 // get (a) boundary for attribute change
155 void GetAttributeBoundary( css::i18n::Boundary& rBound,
156 sal_Int32 nPos ) const;
158 /// Convert start and end positions into core positions.
159 /// @returns true if 'special' portions are included either completely
160 /// or not at all. This can be used to test whether editing
161 /// that range would be legal
162 bool GetEditableRange( sal_Int32 nStart, sal_Int32 nEnd,
163 TextFrameIndex& rCoreStart, TextFrameIndex& rCoreEnd) const;
165 private:
166 std::vector< std::pair<sal_Int32,sal_Int32> > m_vecPairPos;
169 #endif
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */