|
|
@@ -226,6 +226,25 @@ public class Range |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Does any <code>TextPiece</code> in this Range use unicode? |
|
|
|
* |
|
|
|
* @return true if it does and false if it doesn't |
|
|
|
*/ |
|
|
|
public boolean usesUnicode() { |
|
|
|
|
|
|
|
initText(); |
|
|
|
|
|
|
|
for (int i = _textStart; i < _textEnd; i++) |
|
|
|
{ |
|
|
|
TextPiece piece = (TextPiece)_text.get(i); |
|
|
|
if (piece.usesUnicode()) |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Gets the text that this Range contains. |
|
|
|
* |
|
|
@@ -306,13 +325,19 @@ public class Range |
|
|
|
// Since this is the first item in our list, it is safe to assume that |
|
|
|
// _start >= tp.getStart() |
|
|
|
int insertIndex = _start - tp.getStart(); |
|
|
|
if (tp.usesUnicode()) |
|
|
|
insertIndex /= 2; |
|
|
|
sb.insert(insertIndex, text); |
|
|
|
|
|
|
|
int adjustedLength = _doc.getTextTable().adjustForInsert(_textStart, text.length()); |
|
|
|
_doc.getCharacterTable().adjustForInsert(_charStart, adjustedLength); |
|
|
|
_doc.getParagraphTable().adjustForInsert(_parStart, adjustedLength); |
|
|
|
_doc.getSectionTable().adjustForInsert(_sectionStart, adjustedLength); |
|
|
|
adjustForInsert(text.length()); |
|
|
|
|
|
|
|
// update the FIB.CCPText field |
|
|
|
adjustFIB(text.length()); |
|
|
|
|
|
|
|
return getCharacterRun(0); |
|
|
|
} |
|
|
|
|
|
|
@@ -489,6 +514,7 @@ public class Range |
|
|
|
|
|
|
|
public void delete() |
|
|
|
{ |
|
|
|
|
|
|
|
initAll(); |
|
|
|
|
|
|
|
int numSections = _sections.size(); |
|
|
@@ -519,6 +545,12 @@ public class Range |
|
|
|
TextPiece piece = (TextPiece)_text.get(x); |
|
|
|
piece.adjustForDelete(_start, _end - _start); |
|
|
|
} |
|
|
|
|
|
|
|
// update the FIB.CCPText field |
|
|
|
if (usesUnicode()) |
|
|
|
adjustFIB(-((_end - _start) / 2)); |
|
|
|
else |
|
|
|
adjustFIB(-(_end - _start)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -827,6 +859,19 @@ public class Range |
|
|
|
_sectionRangeFound = false; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Adjust the value of <code>FIB.CCPText</code> after an insert or a delete... |
|
|
|
* |
|
|
|
* @param adjustment The (signed) value that should be added to <code>FIB.CCPText</code> |
|
|
|
*/ |
|
|
|
protected void adjustFIB(int adjustment) { |
|
|
|
|
|
|
|
// update the FIB.CCPText field (this should happen once per adjustment, so we don't want it in |
|
|
|
// adjustForInsert() or it would get updated multiple times if the range has a parent) |
|
|
|
// without this, OpenOffice.org (v. 2.2.x) does not see all the text in the document |
|
|
|
_doc.getFileInformationBlock().setCcpText(_doc.getFileInformationBlock().getCcpText() + adjustment); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* adjust this range after an insert happens. |
|
|
|
* @param length the length to adjust for |
|
|
@@ -834,6 +879,7 @@ public class Range |
|
|
|
private void adjustForInsert(int length) |
|
|
|
{ |
|
|
|
_end += length; |
|
|
|
|
|
|
|
reset(); |
|
|
|
Range parent = (Range)_parent.get(); |
|
|
|
if (parent != null) |
|
|
@@ -842,4 +888,14 @@ public class Range |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getStartOffset() { |
|
|
|
|
|
|
|
return _start; |
|
|
|
} |
|
|
|
|
|
|
|
public int getEndOffset() { |
|
|
|
|
|
|
|
return _end; |
|
|
|
} |
|
|
|
} |