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 //IAccessibility2 Implementation 2009----- 65 Positions_t aFieldPosition; 66 //-----IAccessibility2 Implementation 2009 67 Positions_t aAttrFieldType; 68 69 typedef std::vector<sal_uInt8> PortionAttrs_t; 70 PortionAttrs_t aPortionAttrs; /// additional portion attributes 71 72 Positions_t* pSentences; /// positions of sentence breaks 73 74 size_t nBeforePortions; /// # of portions before first model character 75 sal_Bool bLastIsSpecial; /// set if last portion was 'Special()' 76 77 /// returns the index of the first position whose value is smaller 78 /// or equal, and whose following value is equal or larger 79 size_t FindBreak( const Positions_t& rPositions, sal_Int32 nValue ) const; 80 81 /// like FindBreak, but finds the last equal or larger position 82 size_t FindLastBreak( const Positions_t& rPositions, sal_Int32 nValue ) const; 83 84 /// fill the boundary with the values from rPositions[nPos] 85 void FillBoundary(com::sun::star::i18n::Boundary& rBound, 86 const Positions_t& rPositions, 87 size_t nPos ) const; 88 89 /// Access to portion attributes 90 sal_Bool IsPortionAttrSet( size_t nPortionNo, sal_uInt8 nAttr ) const; 91 sal_Bool IsSpecialPortion( size_t nPortionNo ) const; 92 sal_Bool IsReadOnlyPortion( size_t nPortionNo ) const; 93 sal_Bool IsGrayPortionType( sal_uInt16 nType ) const; 94 95 // helper method for GetEditableRange(...): 96 void AdjustAndCheck( sal_Int32 nPos, size_t& nPortionNo, 97 sal_uInt16& nCorePos, sal_Bool& bEdit ) const; 98 99 public: 100 SwAccessiblePortionData( const SwTxtNode* pTxtNd, 101 const SwViewOption* pViewOpt = NULL ); 102 virtual ~SwAccessiblePortionData(); 103 104 // SwPortionHandler methods 105 virtual void Text(sal_uInt16 nLength, sal_uInt16 nType); 106 virtual void Special(sal_uInt16 nLength, const String& rText, sal_uInt16 nType); 107 virtual void LineBreak(); 108 virtual void Skip(sal_uInt16 nLength); 109 virtual void Finish(); 110 111 //IAccessibility2 Implementation 2009----- 112 virtual void SetAttrFieldType( sal_uInt16 nAttrFldType ); 113 sal_Bool FillBoundaryIFDateField( com::sun::star::i18n::Boundary& rBound, const sal_Int32 nPos ); 114 sal_Bool IsIndexInFootnode(sal_Int32 nIndex); 115 sal_Bool IsInGrayPortion( sal_Int32 nPos ); 116 sal_Int32 GetFieldIndex(sal_Int32 nPos); 117 //-----IAccessibility2 Implementation 2009 118 119 sal_Bool IsZeroCorePositionData(); 120 // access to the portion data 121 122 /// get the text string, as presented by the layout 123 const rtl::OUString& GetAccessibleString() const; 124 125 /// get the start & end positions of the sentence 126 void GetLineBoundary( com::sun::star::i18n::Boundary& rBound, 127 sal_Int32 nPos ) const; 128 129 // get start and end position of the last line 130 void GetLastLineBoundary( com::sun::star::i18n::Boundary& rBound ) const; 131 132 // --> OD 2008-05-30 #i89175# 133 sal_Int32 GetLineCount() const; 134 sal_Int32 GetLineNo( const sal_Int32 nPos ) const; 135 void GetBoundaryOfLine( const sal_Int32 nLineNo, 136 com::sun::star::i18n::Boundary& rLineBound ); 137 // <-- 138 139 /// get the position in the model string for a given 140 /// (accessibility) position 141 sal_uInt16 GetModelPosition( sal_Int32 nPos ) const; 142 143 /// get the position in the accessibility string for a given model position 144 sal_Int32 GetAccessiblePosition( sal_uInt16 nPos ) const; 145 146 /// fill a SwSpecialPos structure, suitable for calling 147 /// SwTxtFrm->GetCharRect 148 /// Returns the core position, and fills thr rpPos either with NULL or 149 /// with the &rPos, after putting the appropriate data into it. 150 sal_uInt16 FillSpecialPos( sal_Int32 nPos, 151 SwSpecialPos& rPos, 152 SwSpecialPos*& rpPos ) const; 153 154 155 // get boundaries of words/sentences. The data structures are 156 // created on-demand. 157 void GetSentenceBoundary( com::sun::star::i18n::Boundary& rBound, 158 sal_Int32 nPos ); 159 160 // get (a) boundary for attribut change 161 void GetAttributeBoundary( com::sun::star::i18n::Boundary& rBound, 162 sal_Int32 nPos ) const; 163 164 sal_uInt16 GetAttrFldType( sal_Int32 nPos ); 165 /// Convert start and end positions into core positions. 166 /// @returns true if 'special' portions are included either completely 167 /// or not at all. This can be used to test whether editing 168 /// that range would be legal 169 sal_Bool GetEditableRange( sal_Int32 nStart, sal_Int32 nEnd, 170 sal_uInt16& nCoreStart, sal_uInt16& nCoreEnd ) const; 171 172 /// Determine whether this core position is valid for these portions. 173 /// (A paragraph may be split into several frames, e.g. at page 174 /// boundaries. In this case, only part of a paragraph is represented 175 /// through this object. This method determines whether one particular 176 /// position is valid for this object or not.) 177 sal_Bool IsValidCorePosition( sal_uInt16 nPos ) const; 178 sal_uInt16 GetFirstValidCorePosition() const; 179 sal_uInt16 GetLastValidCorePosition() const; 180 //IAccessibility2 Implementation 2009----- 181 private: 182 typedef std::pair<sal_Int32,sal_Int32> PAIR_POS; 183 typedef std::vector<PAIR_POS> VEC_PAIR_POS; 184 VEC_PAIR_POS m_vecPairPos; 185 //-----IAccessibility2 Implementation 2009 186 }; 187 188 189 #endif 190 191