Lines 227-232
Link Here
|
227 |
} |
227 |
} |
228 |
|
228 |
|
229 |
/** |
229 |
/** |
|
|
230 |
* Does any <code>TextPiece</code> in this Range use unicode? |
231 |
* |
232 |
* @return true if it does and false if it doesn't |
233 |
*/ |
234 |
public boolean usesUnicode() { |
235 |
|
236 |
initText(); |
237 |
|
238 |
for (int i = _textStart; i < _textEnd; i++) |
239 |
{ |
240 |
TextPiece piece = (TextPiece)_text.get(i); |
241 |
if (piece.usesUnicode()) |
242 |
return true; |
243 |
} |
244 |
|
245 |
return false; |
246 |
} |
247 |
|
248 |
/** |
230 |
* Gets the text that this Range contains. |
249 |
* Gets the text that this Range contains. |
231 |
* |
250 |
* |
232 |
* @return The text for this range. |
251 |
* @return The text for this range. |
Lines 306-318
Link Here
|
306 |
// Since this is the first item in our list, it is safe to assume that |
325 |
// Since this is the first item in our list, it is safe to assume that |
307 |
// _start >= tp.getStart() |
326 |
// _start >= tp.getStart() |
308 |
int insertIndex = _start - tp.getStart(); |
327 |
int insertIndex = _start - tp.getStart(); |
|
|
328 |
if (tp.usesUnicode()) |
329 |
insertIndex /= 2; |
309 |
sb.insert(insertIndex, text); |
330 |
sb.insert(insertIndex, text); |
|
|
331 |
|
310 |
int adjustedLength = _doc.getTextTable().adjustForInsert(_textStart, text.length()); |
332 |
int adjustedLength = _doc.getTextTable().adjustForInsert(_textStart, text.length()); |
311 |
_doc.getCharacterTable().adjustForInsert(_charStart, adjustedLength); |
333 |
_doc.getCharacterTable().adjustForInsert(_charStart, adjustedLength); |
312 |
_doc.getParagraphTable().adjustForInsert(_parStart, adjustedLength); |
334 |
_doc.getParagraphTable().adjustForInsert(_parStart, adjustedLength); |
313 |
_doc.getSectionTable().adjustForInsert(_sectionStart, adjustedLength); |
335 |
_doc.getSectionTable().adjustForInsert(_sectionStart, adjustedLength); |
314 |
adjustForInsert(text.length()); |
336 |
adjustForInsert(text.length()); |
315 |
|
337 |
|
|
|
338 |
// update the FIB.CCPText field |
339 |
adjustFIB(text.length()); |
340 |
|
316 |
return getCharacterRun(0); |
341 |
return getCharacterRun(0); |
317 |
} |
342 |
} |
318 |
|
343 |
|
Lines 489-494
Link Here
|
489 |
|
514 |
|
490 |
public void delete() |
515 |
public void delete() |
491 |
{ |
516 |
{ |
|
|
517 |
|
492 |
initAll(); |
518 |
initAll(); |
493 |
|
519 |
|
494 |
int numSections = _sections.size(); |
520 |
int numSections = _sections.size(); |
Lines 519-524
Link Here
|
519 |
TextPiece piece = (TextPiece)_text.get(x); |
545 |
TextPiece piece = (TextPiece)_text.get(x); |
520 |
piece.adjustForDelete(_start, _end - _start); |
546 |
piece.adjustForDelete(_start, _end - _start); |
521 |
} |
547 |
} |
|
|
548 |
|
549 |
// update the FIB.CCPText field |
550 |
if (usesUnicode()) |
551 |
adjustFIB(-((_end - _start) / 2)); |
552 |
else |
553 |
adjustFIB(-(_end - _start)); |
522 |
} |
554 |
} |
523 |
|
555 |
|
524 |
/** |
556 |
/** |
Lines 828-839
Link Here
|
828 |
} |
860 |
} |
829 |
|
861 |
|
830 |
/** |
862 |
/** |
|
|
863 |
* Adjust the value of <code>FIB.CCPText</code> after an insert or a delete... |
864 |
* |
865 |
* @param adjustment The (signed) value that should be added to <code>FIB.CCPText</code> |
866 |
*/ |
867 |
protected void adjustFIB(int adjustment) { |
868 |
|
869 |
// update the FIB.CCPText field (this should happen once per adjustment, so we don't want it in |
870 |
// adjustForInsert() or it would get updated multiple times if the range has a parent) |
871 |
// without this, OpenOffice.org (v. 2.2.x) does not see all the text in the document |
872 |
_doc.getFileInformationBlock().setCcpText(_doc.getFileInformationBlock().getCcpText() + adjustment); |
873 |
} |
874 |
|
875 |
/** |
831 |
* adjust this range after an insert happens. |
876 |
* adjust this range after an insert happens. |
832 |
* @param length the length to adjust for |
877 |
* @param length the length to adjust for |
833 |
*/ |
878 |
*/ |
834 |
private void adjustForInsert(int length) |
879 |
private void adjustForInsert(int length) |
835 |
{ |
880 |
{ |
836 |
_end += length; |
881 |
_end += length; |
|
|
882 |
|
837 |
reset(); |
883 |
reset(); |
838 |
Range parent = (Range)_parent.get(); |
884 |
Range parent = (Range)_parent.get(); |
839 |
if (parent != null) |
885 |
if (parent != null) |
Lines 842-845
Link Here
|
842 |
} |
888 |
} |
843 |
} |
889 |
} |
844 |
|
890 |
|
|
|
891 |
|
892 |
public int getStartOffset() { |
893 |
|
894 |
return _start; |
895 |
} |
896 |
|
897 |
public int getEndOffset() { |
898 |
|
899 |
return _end; |
900 |
} |
845 |
} |
901 |
} |