View | Details | Raw Unified | Return to bug 45001
Collapse All | Expand All

(-)poi-3.1-beta1/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java (+10 lines)
Lines 294-299 Link Here
294
      _longHandler.setLong(FIBLongHandler.CBMAC, cbMac);
294
      _longHandler.setLong(FIBLongHandler.CBMAC, cbMac);
295
    }
295
    }
296
296
297
	public int getCcpText()
298
	{
299
	  return _longHandler.getLong(FIBLongHandler.CCPTEXT);
300
	}
301
302
	public void setCcpText(int ccpText)
303
	{
304
	  _longHandler.setLong(FIBLongHandler.CCPTEXT, ccpText);
305
	}
306
297
    public void clearOffsetsSizes()
307
    public void clearOffsetsSizes()
298
    {
308
    {
299
      _fieldHandler.clearFields();
309
      _fieldHandler.clearFields();
(-)poi-3.1-beta1/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java (+8 lines)
Lines 90-101 Link Here
90
90
91
   public void adjustForDelete(int start, int length)
91
   public void adjustForDelete(int start, int length)
92
   {
92
   {
93
94
	   if (usesUnicode()) {
95
96
		   start /= 2;
97
		   length /= 2;
98
	   }
99
93
	   int myStart = getStart();
100
	   int myStart = getStart();
94
	   int myEnd = getEnd();
101
	   int myEnd = getEnd();
95
	   int end = start + length;
102
	   int end = start + length;
96
103
97
	   /* do we have to delete from this text piece? */
104
	   /* do we have to delete from this text piece? */
98
	   if (start <= myEnd && end >= myStart) {
105
	   if (start <= myEnd && end >= myStart) {
106
99
		   /* find where the deleted area overlaps with this text piece */
107
		   /* find where the deleted area overlaps with this text piece */
100
		   int overlapStart = Math.max(myStart, start);
108
		   int overlapStart = Math.max(myStart, start);
101
		   int overlapEnd = Math.min(myEnd, end);
109
		   int overlapEnd = Math.min(myEnd, end);
(-)poi-3.1-beta1/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java (+56 lines)
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
}

Return to bug 45001