xref: /trunk/main/sw/source/core/access/accportions.hxx (revision 4d7c9de0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _ACCPORTIONS_HXX
24 #define _ACCPORTIONS_HXX
25 #include <SwPortionHandler.hxx>
26 #include <sal/types.h>
27 #include <rtl/ustrbuf.hxx>
28 #include <vector>
29 
30 class String;
31 class SwTxtNode;
32 struct SwSpecialPos;
33 class SwViewOption;
34 namespace com { namespace sun { namespace star {
35     namespace i18n { struct Boundary; }
36 } } }
37 
38 /**
39  * collect text portion data from the layout through SwPortionHandler interface
40  */
41 class SwAccessiblePortionData : public SwPortionHandler
42 {
43     // the node this portion is referring to
44     const SwTxtNode* pTxtNode;
45 
46     // variables used while collecting the data
47     rtl::OUStringBuffer aBuffer;
48     sal_Int32 nModelPosition;
49     sal_Bool bFinished;
50     const SwViewOption* pViewOptions;
51 
52     // the accessible string
53     rtl::OUString sAccessibleString;
54 
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> Positions_t;
60 
61     Positions_t aLineBreaks;        /// position of line breaks
62     Positions_t aModelPositions;    /// position of portion breaks in the model
63     Positions_t aAccessiblePositions;   /// portion breaks in sAccessibleString
64     Positions_t aFieldPosition;
65     Positions_t aAttrFieldType;
66 
67     typedef std::vector<sal_uInt8> PortionAttrs_t;
68     PortionAttrs_t aPortionAttrs;   /// additional portion attributes
69 
70     Positions_t* pSentences;    /// positions of sentence breaks
71 
72     size_t nBeforePortions;     /// # of portions before first model character
73     sal_Bool bLastIsSpecial;    /// set if last portion was 'Special()'
74 
75     /// returns the index of the first position whose value is smaller
76     /// or equal, and whose following value is equal or larger
77     size_t FindBreak( const Positions_t& rPositions, sal_Int32 nValue ) const;
78 
79     /// like FindBreak, but finds the last equal or larger position
80     size_t FindLastBreak( const Positions_t& rPositions, sal_Int32 nValue ) const;
81 
82     /// fill the boundary with the values from rPositions[nPos]
83     void FillBoundary(com::sun::star::i18n::Boundary& rBound,
84                       const Positions_t& rPositions,
85                       size_t nPos ) const;
86 
87     /// Access to portion attributes
88     sal_Bool IsPortionAttrSet( size_t nPortionNo, sal_uInt8 nAttr ) const;
89     sal_Bool IsSpecialPortion( size_t nPortionNo ) const;
90     sal_Bool IsReadOnlyPortion( size_t nPortionNo ) const;
91     sal_Bool IsGrayPortionType( sal_uInt16 nType ) const;
92 
93     // helper method for GetEditableRange(...):
94     void AdjustAndCheck( sal_Int32 nPos, size_t& nPortionNo,
95                          sal_uInt16& nCorePos, sal_Bool& bEdit ) const;
96 
97 public:
98     SwAccessiblePortionData( const SwTxtNode* pTxtNd,
99                              const SwViewOption* pViewOpt = NULL );
100     virtual ~SwAccessiblePortionData();
101 
102     // SwPortionHandler methods
103     virtual void Text(sal_uInt16 nLength, sal_uInt16 nType);
104     virtual void Special(sal_uInt16 nLength, const String& rText, sal_uInt16 nType);
105     virtual void LineBreak();
106     virtual void Skip(sal_uInt16 nLength);
107     virtual void Finish();
108 
109     virtual void SetAttrFieldType( sal_uInt16 nAttrFldType );
110     sal_Bool FillBoundaryIFDateField( com::sun::star::i18n::Boundary& rBound, const sal_Int32 nPos );
111 	sal_Bool IsIndexInFootnode(sal_Int32 nIndex);
112 	sal_Bool IsInGrayPortion( sal_Int32 nPos );
113 	sal_Int32 GetFieldIndex(sal_Int32 nPos);
114 
115     sal_Bool IsZeroCorePositionData();
116     // access to the portion data
117 
118     /// get the text string, as presented by the layout
119     const rtl::OUString& GetAccessibleString() const;
120 
121     /// get the start & end positions of the sentence
122     void GetLineBoundary( com::sun::star::i18n::Boundary& rBound,
123                           sal_Int32 nPos ) const;
124 
125 	// get start and end position of the last line
126     void GetLastLineBoundary( com::sun::star::i18n::Boundary& rBound ) const;
127 
128     // --> OD 2008-05-30 #i89175#
129     sal_Int32 GetLineCount() const;
130     sal_Int32 GetLineNo( const sal_Int32 nPos ) const;
131     void GetBoundaryOfLine( const sal_Int32 nLineNo,
132                             com::sun::star::i18n::Boundary& rLineBound );
133     // <--
134 
135     /// get the position in the model string for a given
136     /// (accessibility) position
137     sal_uInt16 GetModelPosition( sal_Int32 nPos ) const;
138 
139     /// get the position in the accessibility string for a given model position
140     sal_Int32 GetAccessiblePosition( sal_uInt16 nPos ) const;
141 
142     /// fill a SwSpecialPos structure, suitable for calling
143     /// SwTxtFrm->GetCharRect
144     /// Returns the core position, and fills thr rpPos either with NULL or
145     /// with the &rPos, after putting the appropriate data into it.
146     sal_uInt16 FillSpecialPos( sal_Int32 nPos,
147                            SwSpecialPos& rPos,
148                            SwSpecialPos*& rpPos ) const;
149 
150 
151     // get boundaries of words/sentences. The data structures are
152     // created on-demand.
153     void GetSentenceBoundary( com::sun::star::i18n::Boundary& rBound,
154                               sal_Int32 nPos );
155 
156     // get (a) boundary for attribut change
157     void GetAttributeBoundary( com::sun::star::i18n::Boundary& rBound,
158                                sal_Int32 nPos ) const;
159 
160     sal_uInt16 GetAttrFldType( sal_Int32 nPos );
161     /// Convert start and end positions into core positions.
162     /// @returns true if 'special' portions are included either completely
163     ///          or not at all. This can be used to test whether editing
164     ///          that range would be legal
165     sal_Bool GetEditableRange( sal_Int32 nStart, sal_Int32 nEnd,
166                                sal_uInt16& nCoreStart, sal_uInt16& nCoreEnd ) const;
167 
168     /// Determine whether this core position is valid for these portions.
169     /// (A paragraph may be split into several frames, e.g. at page
170     ///  boundaries. In this case, only part of a paragraph is represented
171     ///  through this object. This method determines whether one particular
172     ///  position is valid for this object or not.)
173     sal_Bool IsValidCorePosition( sal_uInt16 nPos ) const;
174     sal_uInt16 GetFirstValidCorePosition() const;
175     sal_uInt16 GetLastValidCorePosition() const;
176 private:
177 	typedef std::pair<sal_Int32,sal_Int32> PAIR_POS;
178 	typedef std::vector<PAIR_POS> VEC_PAIR_POS;
179 	VEC_PAIR_POS m_vecPairPos;
180 };
181 
182 
183 #endif
184 
185