|
Lines 15-28
Link Here
|
| 15 |
import java.util.Vector; |
15 |
import java.util.Vector; |
| 16 |
|
16 |
|
| 17 |
import org.eclipse.rwt.Adaptable; |
17 |
import org.eclipse.rwt.Adaptable; |
| 18 |
import org.eclipse.rwt.graphics.Graphics; |
|
|
| 19 |
import org.eclipse.swt.SWT; |
18 |
import org.eclipse.swt.SWT; |
| 20 |
// RAP [if] unnecessary |
19 |
// RAP [if] unnecessary |
| 21 |
//import org.eclipse.swt.graphics.Color; |
20 |
//import org.eclipse.swt.graphics.Color; |
| 22 |
import org.eclipse.swt.graphics.Font; |
21 |
import org.eclipse.swt.graphics.Font; |
| 23 |
//RAP [if] GC/FontMetrics not supported |
22 |
import org.eclipse.swt.graphics.FontMetrics; |
| 24 |
//import org.eclipse.swt.graphics.FontMetrics; |
23 |
import org.eclipse.swt.graphics.GC; |
| 25 |
//import org.eclipse.swt.graphics.GC; |
|
|
| 26 |
import org.eclipse.swt.graphics.Point; |
24 |
import org.eclipse.swt.graphics.Point; |
| 27 |
import org.eclipse.swt.graphics.Rectangle; |
25 |
import org.eclipse.swt.graphics.Rectangle; |
| 28 |
import org.eclipse.ui.forms.internal.widgets.ITextSegmentAdapter; |
26 |
import org.eclipse.ui.forms.internal.widgets.ITextSegmentAdapter; |
|
Lines 233-261
Link Here
|
| 233 |
return new Rectangle(x, y, width, height); |
231 |
return new Rectangle(x, y, width, height); |
| 234 |
} |
232 |
} |
| 235 |
|
233 |
|
| 236 |
// RAP [if] changed method signature and implementation to cope with missing GC |
234 |
public boolean advanceLocator(GC gc, int wHint, Locator locator, |
| 237 |
// public boolean advanceLocator(GC gc, int wHint, Locator locator, |
|
|
| 238 |
public boolean advanceLocator(Font font, int wHint, Locator locator, |
| 239 |
Hashtable objectTable, boolean computeHeightOnly) { |
235 |
Hashtable objectTable, boolean computeHeightOnly) { |
| 240 |
Font gcFont = font; |
236 |
Font oldFont = null; |
| 241 |
Font oldFont = null; |
237 |
if (fontId != null) { |
| 242 |
if (fontId != null) { |
238 |
oldFont = gc.getFont(); |
| 243 |
// oldFont = gc.getFont(); |
239 |
Font newFont = (Font) objectTable.get(fontId); |
| 244 |
oldFont = gcFont; |
240 |
if (newFont != null) |
| 245 |
Font newFont = (Font) objectTable.get(fontId); |
241 |
gc.setFont(newFont); |
| 246 |
if (newFont != null) |
242 |
} |
| 247 |
// gc.setFont(newFont); |
243 |
FontMetrics fm = gc.getFontMetrics(); |
| 248 |
gcFont = newFont; |
244 |
int lineHeight = fm.getHeight(); |
| 249 |
} |
245 |
// RAP [if] fm.getLeading() is missing |
| 250 |
// FontMetrics fm = gc.getFontMetrics(); |
|
|
| 251 |
// int lineHeight = fm.getHeight(); |
| 252 |
int lineHeight = Graphics.getCharHeight( gcFont ); |
| 253 |
int lineLeading = Math.round( lineHeight / LINE_LEADING_RATIO ); |
246 |
int lineLeading = Math.round( lineHeight / LINE_LEADING_RATIO ); |
| 254 |
boolean newLine = false; |
247 |
boolean newLine = false; |
| 255 |
|
248 |
|
| 256 |
if (wHint == SWT.DEFAULT || !wrapAllowed) { |
249 |
if (wHint == SWT.DEFAULT || !wrapAllowed) { |
| 257 |
// Point extent = gc.textExtent(text); |
250 |
Point extent = gc.textExtent(text); |
| 258 |
Point extent = Graphics.stringExtent( gcFont, text ); |
|
|
| 259 |
int totalExtent = locator.x+extent.x; |
251 |
int totalExtent = locator.x+extent.x; |
| 260 |
if (isSelectable()) |
252 |
if (isSelectable()) |
| 261 |
totalExtent+=1; |
253 |
totalExtent+=1; |
|
Lines 276-288
Link Here
|
| 276 |
locator.x += width; |
268 |
locator.x += width; |
| 277 |
locator.width = locator.indent + width; |
269 |
locator.width = locator.indent + width; |
| 278 |
locator.rowHeight = Math.max(locator.rowHeight, extent.y); |
270 |
locator.rowHeight = Math.max(locator.rowHeight, extent.y); |
|
|
271 |
// RAP [if] fm.getLeading() is missing |
| 279 |
// locator.leading = Math.max(locator.leading, fm.getLeading()); |
272 |
// locator.leading = Math.max(locator.leading, fm.getLeading()); |
| 280 |
locator.leading = Math.max(locator.leading, lineLeading); |
273 |
locator.leading = Math.max(locator.leading, lineLeading); |
| 281 |
return newLine; |
274 |
return newLine; |
| 282 |
} |
275 |
} |
| 283 |
|
276 |
|
| 284 |
// computeTextFragments(gc); |
277 |
computeTextFragments(gc); |
| 285 |
computeTextFragments(gcFont); |
|
|
| 286 |
|
278 |
|
| 287 |
int width = 0; |
279 |
int width = 0; |
| 288 |
Point lineExtent = new Point(0, 0); |
280 |
Point lineExtent = new Point(0, 0); |
|
Lines 298-303
Link Here
|
| 298 |
// overflow |
290 |
// overflow |
| 299 |
int lineWidth = currentExtent; |
291 |
int lineWidth = currentExtent; |
| 300 |
locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); |
292 |
locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); |
|
|
293 |
// RAP [if] fm.getLeading() is missing |
| 301 |
// locator.leading = Math.max(locator.leading, fm.getLeading()); |
294 |
// locator.leading = Math.max(locator.leading, fm.getLeading()); |
| 302 |
locator.leading = Math.max(locator.leading, lineLeading); |
295 |
locator.leading = Math.max(locator.leading, lineLeading); |
| 303 |
if (computeHeightOnly) |
296 |
if (computeHeightOnly) |
|
Lines 320-330
Link Here
|
| 320 |
locator.x += lineWidth; |
313 |
locator.x += lineWidth; |
| 321 |
locator.width = width; |
314 |
locator.width = width; |
| 322 |
locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); |
315 |
locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); |
|
|
316 |
// RAP [if] fm.getLeading() is missing |
| 323 |
// locator.leading = Math.max(locator.leading, fm.getLeading()); |
317 |
// locator.leading = Math.max(locator.leading, fm.getLeading()); |
| 324 |
locator.leading = Math.max(locator.leading, lineLeading); |
318 |
locator.leading = Math.max(locator.leading, lineLeading); |
| 325 |
if (oldFont != null) { |
319 |
if (oldFont != null) { |
| 326 |
// gc.setFont(oldFont); |
320 |
gc.setFont(oldFont); |
| 327 |
gcFont = oldFont; |
|
|
| 328 |
} |
321 |
} |
| 329 |
return newLine; |
322 |
return newLine; |
| 330 |
} |
323 |
} |
|
Lines 340-353
Link Here
|
| 340 |
* @param lineHeight |
333 |
* @param lineHeight |
| 341 |
* @param descent |
334 |
* @param descent |
| 342 |
*/ |
335 |
*/ |
| 343 |
// RAP [if] changed method signature and implementation to cope with missing GC |
336 |
private void layoutWithoutWrapping(GC gc, int width, Locator locator, |
| 344 |
// private void layoutWithoutWrapping(GC gc, int width, Locator locator, |
337 |
boolean selected, FontMetrics fm, int lineHeight, int descent) { |
| 345 |
// boolean selected, FontMetrics fm, int lineHeight, int descent) { |
338 |
Point extent = gc.textExtent(text); |
| 346 |
private void layoutWithoutWrapping(Font font, int width, Locator locator, |
|
|
| 347 |
boolean selected, int lineHeight, int descent) { |
| 348 |
// Point extent = gc.textExtent(text); |
| 349 |
Point extent = Graphics.stringExtent( font, text ); |
| 350 |
int lineLeading = Math.round( lineHeight / LINE_LEADING_RATIO ); |
| 351 |
int ewidth = extent.x; |
339 |
int ewidth = extent.x; |
| 352 |
if (isSelectable()) |
340 |
if (isSelectable()) |
| 353 |
ewidth += 1; |
341 |
ewidth += 1; |
|
Lines 358-365
Link Here
|
| 358 |
locator.rowHeight = 0; |
346 |
locator.rowHeight = 0; |
| 359 |
locator.rowCounter++; |
347 |
locator.rowCounter++; |
| 360 |
} |
348 |
} |
|
|
349 |
// RAP [if] fm.getLeading() is missing |
| 361 |
// int ly = locator.getBaseline(fm.getHeight() - fm.getLeading()); |
350 |
// int ly = locator.getBaseline(fm.getHeight() - fm.getLeading()); |
| 362 |
int ly = locator.getBaseline(Graphics.getCharHeight( font ) - lineLeading); |
351 |
int lineLeading = Math.round( lineHeight / LINE_LEADING_RATIO ); |
|
|
352 |
int ly = locator.getBaseline(fm.getHeight() - lineLeading); |
| 363 |
//int lineY = ly + lineHeight - descent + 1; |
353 |
//int lineY = ly + lineHeight - descent + 1; |
| 364 |
Rectangle br = new Rectangle(locator.x, ly, ewidth, |
354 |
Rectangle br = new Rectangle(locator.x, ly, ewidth, |
| 365 |
lineHeight - descent + 3); |
355 |
lineHeight - descent + 3); |
|
Lines 369-384
Link Here
|
| 369 |
locator.rowHeight = Math.max(locator.rowHeight, extent.y); |
359 |
locator.rowHeight = Math.max(locator.rowHeight, extent.y); |
| 370 |
} |
360 |
} |
| 371 |
|
361 |
|
| 372 |
// RAP [if] changed method signature and implementation to cope with missing GC |
362 |
protected int convertOffsetToStringIndex(GC gc, String s, int x, |
| 373 |
// protected int convertOffsetToStringIndex(GC gc, String s, int x, |
|
|
| 374 |
protected int convertOffsetToStringIndex(Font font, String s, int x, |
| 375 |
int swidth, int selOffset) { |
363 |
int swidth, int selOffset) { |
| 376 |
int index = s.length(); |
364 |
int index = s.length(); |
| 377 |
while (index > 0 && x + swidth > selOffset) { |
365 |
while (index > 0 && x + swidth > selOffset) { |
| 378 |
index--; |
366 |
index--; |
| 379 |
String ss = s.substring(0, index); |
367 |
String ss = s.substring(0, index); |
| 380 |
// swidth = gc.textExtent(ss).x; |
368 |
swidth = gc.textExtent(ss).x; |
| 381 |
swidth = Graphics.stringExtent( font, ss ).x; |
|
|
| 382 |
} |
369 |
} |
| 383 |
return index; |
370 |
return index; |
| 384 |
} |
371 |
} |
|
Lines 479-513
Link Here
|
| 479 |
// } |
466 |
// } |
| 480 |
// } |
467 |
// } |
| 481 |
|
468 |
|
| 482 |
// RAP [if] changed method signature and implementation to cope with missing GC |
469 |
public void computeSelection(GC gc, Hashtable resourceTable, SelectionData selData) { |
| 483 |
// public void computeSelection(GC gc, Hashtable resourceTable, SelectionData selData) { |
470 |
Font oldFont = null; |
| 484 |
public void computeSelection(Font font, Hashtable resourceTable, SelectionData selData) { |
471 |
|
| 485 |
Font gcFont = font; |
472 |
if (fontId != null) { |
| 486 |
Font oldFont = null; |
473 |
oldFont = gc.getFont(); |
| 487 |
|
474 |
Font newFont = (Font) resourceTable.get(fontId); |
| 488 |
if (fontId != null) { |
475 |
if (newFont != null) |
| 489 |
// oldFont = gc.getFont(); |
476 |
gc.setFont(newFont); |
| 490 |
oldFont = gcFont; |
477 |
} |
| 491 |
Font newFont = (Font) resourceTable.get(fontId); |
|
|
| 492 |
if (newFont != null) |
| 493 |
// gc.setFont(newFont); |
| 494 |
gcFont = newFont; |
| 495 |
} |
| 496 |
|
478 |
|
| 497 |
for (int i = 0; i < areaRectangles.size(); i++) { |
479 |
for (int i = 0; i < areaRectangles.size(); i++) { |
| 498 |
AreaRectangle areaRectangle = (AreaRectangle) areaRectangles.get(i); |
480 |
AreaRectangle areaRectangle = (AreaRectangle) areaRectangles.get(i); |
| 499 |
Rectangle rect = areaRectangle.rect; |
481 |
Rectangle rect = areaRectangle.rect; |
| 500 |
String text = areaRectangle.getText(); |
482 |
String text = areaRectangle.getText(); |
| 501 |
// Point extent = gc.textExtent(text); |
483 |
Point extent = gc.textExtent(text); |
| 502 |
Point extent = Graphics.stringExtent( gcFont, text ); |
484 |
computeSelection(gc, text, extent.x, selData, |
| 503 |
// computeSelection(gc, text, extent.x, selData, |
|
|
| 504 |
computeSelection(gcFont, text, extent.x, selData, |
| 505 |
rect); |
485 |
rect); |
| 506 |
} |
486 |
} |
| 507 |
// restore GC resources |
487 |
// restore GC resources |
| 508 |
if (oldFont != null) { |
488 |
if (oldFont != null) { |
| 509 |
// gc.setFont(oldFont); |
489 |
gc.setFont(oldFont); |
| 510 |
gcFont = oldFont; |
|
|
| 511 |
} |
490 |
} |
| 512 |
} |
491 |
} |
| 513 |
|
492 |
|
|
Lines 582-590
Link Here
|
| 582 |
// } |
561 |
// } |
| 583 |
// } |
562 |
// } |
| 584 |
|
563 |
|
| 585 |
// RAP [if] changed method signature and implementation to cope with missing GC |
564 |
private void computeSelection(GC gc, String s, int swidth, SelectionData selData, Rectangle bounds) { |
| 586 |
// private void computeSelection(GC gc, String s, int swidth, SelectionData selData, Rectangle bounds) { |
|
|
| 587 |
private void computeSelection(Font font, String s, int swidth, SelectionData selData, Rectangle bounds) { |
| 588 |
int leftOffset = selData.getLeftOffset(bounds.height); |
565 |
int leftOffset = selData.getLeftOffset(bounds.height); |
| 589 |
int rightOffset = selData.getRightOffset(bounds.height); |
566 |
int rightOffset = selData.getRightOffset(bounds.height); |
| 590 |
boolean firstRow = selData.isFirstSelectionRow(bounds.y, bounds.height); |
567 |
boolean firstRow = selData.isFirstSelectionRow(bounds.y, bounds.height); |
|
Lines 595-607
Link Here
|
| 595 |
int sstop = -1; |
572 |
int sstop = -1; |
| 596 |
|
573 |
|
| 597 |
if (firstRow && bounds.x + swidth > leftOffset) { |
574 |
if (firstRow && bounds.x + swidth > leftOffset) { |
| 598 |
// sstart = convertOffsetToStringIndex(gc, s, bounds.x, swidth, |
575 |
sstart = convertOffsetToStringIndex(gc, s, bounds.x, swidth, |
| 599 |
sstart = convertOffsetToStringIndex(font, s, bounds.x, swidth, |
|
|
| 600 |
leftOffset); |
576 |
leftOffset); |
| 601 |
} |
577 |
} |
| 602 |
if (lastRow && bounds.x + swidth > rightOffset) { |
578 |
if (lastRow && bounds.x + swidth > rightOffset) { |
| 603 |
// sstop = convertOffsetToStringIndex(gc, s, bounds.x, swidth, |
579 |
sstop = convertOffsetToStringIndex(gc, s, bounds.x, swidth, |
| 604 |
sstop = convertOffsetToStringIndex(font, s, bounds.x, swidth, |
|
|
| 605 |
rightOffset); |
580 |
rightOffset); |
| 606 |
} |
581 |
} |
| 607 |
|
582 |
|
|
Lines 671-709
Link Here
|
| 671 |
* java.util.Hashtable, boolean, |
646 |
* java.util.Hashtable, boolean, |
| 672 |
* org.eclipse.ui.internal.forms.widgets.SelectionData) |
647 |
* org.eclipse.ui.internal.forms.widgets.SelectionData) |
| 673 |
*/ |
648 |
*/ |
| 674 |
// RAP [if] changed method signature and implementation to cope with missing GC |
649 |
public void layout(GC gc, int width, Locator locator, |
| 675 |
// public void layout(GC gc, int width, Locator locator, |
|
|
| 676 |
public void layout(Font font, int width, Locator locator, |
| 677 |
Hashtable resourceTable, boolean selected) { |
650 |
Hashtable resourceTable, boolean selected) { |
| 678 |
Font gcFont = font; |
651 |
Font oldFont = null; |
| 679 |
Font oldFont = null; |
652 |
|
| 680 |
|
653 |
areaRectangles.clear(); |
| 681 |
areaRectangles.clear(); |
654 |
|
| 682 |
|
655 |
if (fontId != null) { |
| 683 |
if (fontId != null) { |
656 |
oldFont = gc.getFont(); |
| 684 |
// oldFont = gc.getFont(); |
657 |
Font newFont = (Font) resourceTable.get(fontId); |
| 685 |
oldFont = gcFont; |
658 |
if (newFont != null) |
| 686 |
Font newFont = (Font) resourceTable.get(fontId); |
659 |
gc.setFont(newFont); |
| 687 |
if (newFont != null) |
660 |
} |
| 688 |
// gc.setFont(newFont); |
661 |
FontMetrics fm = gc.getFontMetrics(); |
| 689 |
gcFont = newFont; |
662 |
int lineHeight = fm.getHeight(); |
| 690 |
} |
663 |
// RAP [if] fm.getDescent() is missing |
| 691 |
// FontMetrics fm = gc.getFontMetrics(); |
664 |
// int descent = fm.getDescent(); |
| 692 |
// int lineHeight = fm.getHeight(); |
|
|
| 693 |
int lineHeight = Graphics.getCharHeight( gcFont ); |
| 694 |
int lineLeading = Math.round( lineHeight / LINE_LEADING_RATIO ); |
| 695 |
int descent = Math.round( lineHeight / LINE_DESCENT_RATIO ); |
665 |
int descent = Math.round( lineHeight / LINE_DESCENT_RATIO ); |
|
|
666 |
// RAP [if] fm.getLeading() is missing |
| 667 |
int lineLeading = Math.round( lineHeight / LINE_LEADING_RATIO ); |
| 696 |
|
668 |
|
| 697 |
if (!wrapAllowed) { |
669 |
if (!wrapAllowed) { |
| 698 |
// layoutWithoutWrapping(gc, width, locator, selected, fm, lineHeight, |
670 |
layoutWithoutWrapping(gc, width, locator, selected, fm, lineHeight, |
| 699 |
layoutWithoutWrapping(gcFont, width, locator, selected, lineHeight, |
|
|
| 700 |
descent); |
671 |
descent); |
| 701 |
} else { |
672 |
} else { |
| 702 |
int lineStart = 0; |
673 |
int lineStart = 0; |
| 703 |
int lastLoc = 0; |
674 |
int lastLoc = 0; |
| 704 |
Point lineExtent = new Point(0, 0); |
675 |
Point lineExtent = new Point(0, 0); |
| 705 |
// computeTextFragments(gc); |
676 |
computeTextFragments(gc); |
| 706 |
computeTextFragments(gcFont); |
|
|
| 707 |
int rightEdge = width-locator.marginWidth; |
677 |
int rightEdge = width-locator.marginWidth; |
| 708 |
for (int i = 0; i < textFragments.length; i++) { |
678 |
for (int i = 0; i < textFragments.length; i++) { |
| 709 |
TextFragment fragment = textFragments[i]; |
679 |
TextFragment fragment = textFragments[i]; |
|
Lines 715-720
Link Here
|
| 715 |
int lineWidth = locator.x + lineExtent.x; |
685 |
int lineWidth = locator.x + lineExtent.x; |
| 716 |
if (isSelectable()) |
686 |
if (isSelectable()) |
| 717 |
lineWidth += 1; |
687 |
lineWidth += 1; |
|
|
688 |
// RAP [if] fm.getLeading() is missing |
| 689 |
// int ly = locator.getBaseline(lineHeight - fm.getLeading()); |
| 718 |
int ly = locator.getBaseline(lineHeight - lineLeading); |
690 |
int ly = locator.getBaseline(lineHeight - lineLeading); |
| 719 |
Rectangle br = new Rectangle(isSelectable()? |
691 |
Rectangle br = new Rectangle(isSelectable()? |
| 720 |
locator.x - 1:locator.x, ly, |
692 |
locator.x - 1:locator.x, ly, |
|
Lines 739-744
Link Here
|
| 739 |
lineExtent.y = Math.max(lineHeight, lineExtent.y); |
711 |
lineExtent.y = Math.max(lineHeight, lineExtent.y); |
| 740 |
} |
712 |
} |
| 741 |
//String lastLine = text.substring(lineStart, lastLoc); |
713 |
//String lastLine = text.substring(lineStart, lastLoc); |
|
|
714 |
// RAP [if] fm.getLeading() is missing |
| 715 |
// int ly = locator.getBaseline(lineHeight - fm.getLeading()); |
| 742 |
int ly = locator.getBaseline(lineHeight - lineLeading); |
716 |
int ly = locator.getBaseline(lineHeight - lineLeading); |
| 743 |
int lastWidth = lineExtent.x; |
717 |
int lastWidth = lineExtent.x; |
| 744 |
if (isSelectable()) |
718 |
if (isSelectable()) |
|
Lines 752-765
Link Here
|
| 752 |
locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); |
726 |
locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); |
| 753 |
} |
727 |
} |
| 754 |
if (oldFont != null) { |
728 |
if (oldFont != null) { |
| 755 |
// gc.setFont(oldFont); |
729 |
gc.setFont(oldFont); |
| 756 |
gcFont = oldFont; |
|
|
| 757 |
} |
730 |
} |
| 758 |
} |
731 |
} |
| 759 |
|
732 |
|
| 760 |
// RAP [if] changed method signature and implementation to cope with missing GC |
733 |
private void computeTextFragments(GC gc) { |
| 761 |
// private void computeTextFragments(GC gc) { |
|
|
| 762 |
private void computeTextFragments(Font font) { |
| 763 |
if (textFragments != null) |
734 |
if (textFragments != null) |
| 764 |
return; |
735 |
return; |
| 765 |
ArrayList list = new ArrayList(); |
736 |
ArrayList list = new ArrayList(); |
|
Lines 770-777
Link Here
|
| 770 |
if (loc == 0) |
741 |
if (loc == 0) |
| 771 |
continue; |
742 |
continue; |
| 772 |
String word = text.substring(cursor, loc); |
743 |
String word = text.substring(cursor, loc); |
| 773 |
// Point extent = gc.textExtent(word); |
744 |
Point extent = gc.textExtent(word); |
| 774 |
Point extent = Graphics.stringExtent( font, word ); |
|
|
| 775 |
list.add(new TextFragment((short) loc, (short) extent.x)); |
745 |
list.add(new TextFragment((short) loc, (short) extent.x)); |
| 776 |
cursor = loc; |
746 |
cursor = loc; |
| 777 |
} |
747 |
} |