00001 /* AbiWord 00002 * Copyright (C) 1998 AbiSource, Inc. 00003 * Updates by Ben Martin in 2011. 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00018 * 02110-1301 USA. 00019 */ 00020 00021 00022 #ifndef PF_FRAG_H 00023 #define PF_FRAG_H 00024 00025 #include <stdio.h> 00026 #include "ut_types.h" 00027 #include "pt_Types.h" 00028 #include "pf_Fragments.h" 00029 #include <string> 00030 00031 class pt_PieceTable; 00032 class PX_ChangeRecord; 00033 class fd_Field; 00034 class pf_Frag_Strux; 00035 00036 00048 class ABI_EXPORT pf_Frag 00049 { 00050 friend class pf_Fragments; 00051 public: 00052 typedef enum _PFType { PFT_Text = 0, PFT_Object, PFT_Strux, PFT_EndOfDoc, PFT_FmtMark } PFType; 00053 00054 pf_Frag(pt_PieceTable * pPT, PFType type, UT_uint32 length); 00055 virtual ~pf_Frag(); 00056 00057 inline PFType getType(void) const { return m_type; } 00058 pf_Frag * getNext(void) const; 00059 pf_Frag * getPrev(void) const; 00060 pf_Frag_Strux* getNextStrux(PTStruxType t) const; 00061 pf_Frag_Strux* tryDownCastStrux(PTStruxType t) const; 00062 00063 inline UT_uint32 getLength(void) const { return m_length; } 00064 inline void zero(void) 00065 { m_length = 0;} 00066 00067 pt_PieceTable * getPieceTable(void) const { return m_pPieceTable;} 00068 fd_Field * getField(void) const; 00069 PT_DocPosition getPos(void) const; 00070 void lengthChanged(UT_sint32 delta); 00071 PT_DocPosition getLeftTreeLength(void) const { return m_leftTreeLength; } 00072 void setLeftTreeLength(PT_DocPosition length) const { m_leftTreeLength = length;} 00073 00074 /* We need the following function to accumulate left tree length */ 00075 void accLeftTreeLength(PT_DocPosition length); 00076 00077 inline PT_AttrPropIndex getIndexAP(void) const {return m_indexAP;} 00078 virtual void setIndexAP(PT_AttrPropIndex indexNewAP) {m_indexAP = indexNewAP;} 00079 00080 // createSpecialChangeRecord() constructs a change 00081 // record which describes the fragment itself and 00082 // not an actual change (editing) operation. the 00083 // is used to initialize the listeners. 00084 virtual bool createSpecialChangeRecord(PX_ChangeRecord ** ppcr, 00085 PT_DocPosition dpos) const; 00086 00087 // compare contents of two fragments, ignoring format 00088 bool isContentEqual(const pf_Frag & f2) const; 00089 00090 UT_uint32 getXID() const {return m_iXID;} 00091 void setXID(UT_uint32 xid) {m_iXID = xid;} 00092 00093 // I would much prefer if this was a pure vitual, but we do not have Eod frag 00094 virtual bool usesXID() const {return false;} 00095 00096 // compare contents and format of two fragments 00097 bool operator == (const pf_Frag & f2) const; 00098 00099 std::string getXMLID() const; 00100 00101 #ifdef PT_TEST 00102 virtual void __dump(FILE * fp) const; 00103 #endif 00104 00105 00106 protected: 00128 virtual bool _isContentEqual(const pf_Frag & /*f2*/) const {return true;} 00129 00130 PFType m_type; 00131 00132 fd_Field * m_pField; 00133 pt_PieceTable * m_pPieceTable; 00134 PT_AttrPropIndex m_indexAP; 00135 00136 /* in PT_DocPosition-space - gives length of this fragment */ 00137 UT_uint32 m_length; 00138 00139 private: 00140 void _setNode(pf_Fragments::Node * pNode); 00141 pf_Fragments::Node * _getNode(void) const; 00142 /* In PT_DocPosition space - specifies size of left subtree */ 00143 mutable UT_uint32 m_leftTreeLength; 00144 UT_uint32 m_iXID; 00145 pf_Fragments::Node * m_pMyNode; 00146 }; 00147 00148 // This is like pf->tryDownCastStrux() but you can pass a null pf as arg1 00149 // safely. 00150 pf_Frag_Strux* tryDownCastStrux( pf_Frag* pf, PTStruxType t); 00151 00152 #endif /* PF_FRAG_H */
1.7.1