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