1 /* AbiWord
2 * Copyright (C) 1998 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20
21 #include "ut_types.h"
22 #include "pt_Types.h"
23 #include "px_ChangeRecord.h"
24 #include "px_CR_Span.h"
25 #include "fd_Field.h"
26
PX_ChangeRecord_Span(PXType type,PT_DocPosition position,PT_AttrPropIndex indexNewAP,PT_BufIndex bufIndex,UT_uint32 length,PT_BlockOffset blockOffset,fd_Field * pField)27 PX_ChangeRecord_Span::PX_ChangeRecord_Span(PXType type,
28 PT_DocPosition position,
29 PT_AttrPropIndex indexNewAP,
30 PT_BufIndex bufIndex,
31 UT_uint32 length,
32 PT_BlockOffset blockOffset,
33 fd_Field * pField)
34 : PX_ChangeRecord(type, position, indexNewAP, 0)
35 {
36 UT_return_if_fail (length > 0);
37
38 m_bufIndex = bufIndex;
39 m_length = length;
40 m_blockOffset = blockOffset;
41 m_pField = pField;
42 }
43
~PX_ChangeRecord_Span()44 PX_ChangeRecord_Span::~PX_ChangeRecord_Span()
45 {
46 }
47
reverse(void) const48 PX_ChangeRecord * PX_ChangeRecord_Span::reverse(void) const
49 {
50 PX_ChangeRecord_Span * pcr
51 = new PX_ChangeRecord_Span(getRevType(),m_position,m_indexAP,
52 m_bufIndex,m_length,m_blockOffset,
53 m_pField);
54 UT_ASSERT_HARMLESS(pcr);
55 return pcr;
56 }
57
getLength(void) const58 UT_uint32 PX_ChangeRecord_Span::getLength(void) const
59 {
60 return m_length;
61 }
62
getBufIndex(void) const63 PT_BufIndex PX_ChangeRecord_Span::getBufIndex(void) const
64 {
65 return m_bufIndex;
66 }
67
getBlockOffset(void) const68 PT_BlockOffset PX_ChangeRecord_Span::getBlockOffset(void) const
69 {
70 return m_blockOffset;
71 }
72
coalesce(const PX_ChangeRecord_Span * pcr)73 void PX_ChangeRecord_Span::coalesce(const PX_ChangeRecord_Span * pcr)
74 {
75 // append the effect of the given pcr onto the end of us.
76
77 // some quick sanity checks. our caller is supposed to have already verified this
78
79 UT_return_if_fail (getType() == pcr->getType());
80 UT_return_if_fail (getIndexAP() == pcr->getIndexAP());
81
82 m_length += pcr->getLength();
83
84 if (pcr->getPosition() < getPosition()) // if we have a prepend (like a backspace)
85 {
86 m_position = pcr->getPosition();
87 m_bufIndex = pcr->getBufIndex();
88 m_blockOffset = pcr->getBlockOffset();
89 }
90
91 return;
92 }
93
94