use of org.eclipse.swt.custom.BidiSegmentEvent in project egit by eclipse.
the class SpellcheckableMessageArea method configureHardWrap.
private void configureHardWrap() {
if (shouldHardWrap()) {
if (hardWrapSegmentListener == null) {
final StyledText textWidget = getTextWidget();
hardWrapSegmentListener = new BidiSegmentListener() {
@Override
public void lineGetSegments(BidiSegmentEvent e) {
if (e.widget == textWidget) {
int footerOffset = CommonUtils.getFooterOffset(textWidget.getText());
if (footerOffset >= 0 && e.lineOffset >= footerOffset) {
return;
}
}
int[] segments = calculateWrapOffsets(e.lineText, MAX_LINE_WIDTH);
if (segments != null) {
char[] segmentsChars = new char[segments.length];
Arrays.fill(segmentsChars, '\n');
e.segments = segments;
e.segmentsChars = segmentsChars;
}
}
};
textWidget.addBidiSegmentListener(hardWrapSegmentListener);
// XXX: workaround for https://bugs.eclipse.org/384886
textWidget.setText(textWidget.getText());
if (brokenBidiPlatformTextWidth != -1) {
Layout restrictedWidthLayout = new Layout() {
@Override
protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
Point size = SpellcheckableMessageArea.this.getSize();
Rectangle trim = SpellcheckableMessageArea.this.computeTrim(0, 0, 0, 0);
size.x -= trim.width;
size.y -= trim.height;
if (size.x > brokenBidiPlatformTextWidth)
size.x = brokenBidiPlatformTextWidth;
return size;
}
@Override
protected void layout(Composite composite, boolean flushCache) {
Point size = computeSize(composite, SWT.DEFAULT, SWT.DEFAULT, flushCache);
textWidget.setBounds(0, 0, size.x, size.y);
}
};
setLayout(restrictedWidthLayout);
}
}
} else if (hardWrapSegmentListener != null) {
StyledText textWidget = getTextWidget();
textWidget.removeBidiSegmentListener(hardWrapSegmentListener);
// XXX: workaround for https://bugs.eclipse.org/384886
textWidget.setText(textWidget.getText());
hardWrapSegmentListener = null;
if (brokenBidiPlatformTextWidth != -1)
setLayout(new FillLayout());
}
}
use of org.eclipse.swt.custom.BidiSegmentEvent in project egit by eclipse.
the class SpellcheckableMessageArea method computeBrokenBidiPlatformTextWidth.
private void computeBrokenBidiPlatformTextWidth(int textWidth) {
class BidiSegmentListenerTester implements BidiSegmentListener {
boolean called;
@Override
public void lineGetSegments(BidiSegmentEvent event) {
called = true;
}
}
BidiSegmentListenerTester tester = new BidiSegmentListenerTester();
StyledText textWidget = getTextWidget();
textWidget.addBidiSegmentListener(tester);
// $NON-NLS-1$
textWidget.setText(" ");
textWidget.computeSize(SWT.DEFAULT, SWT.DEFAULT);
textWidget.removeBidiSegmentListener(tester);
brokenBidiPlatformTextWidth = tester.called ? -1 : textWidth;
}
Aggregations