Search in sources :

Example 1 with BidiSegmentEvent

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());
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) BidiSegmentEvent(org.eclipse.swt.custom.BidiSegmentEvent) FillLayout(org.eclipse.swt.layout.FillLayout) Layout(org.eclipse.swt.widgets.Layout) BidiSegmentListener(org.eclipse.swt.custom.BidiSegmentListener) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 2 with BidiSegmentEvent

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;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) BidiSegmentEvent(org.eclipse.swt.custom.BidiSegmentEvent) BidiSegmentListener(org.eclipse.swt.custom.BidiSegmentListener)

Aggregations

BidiSegmentEvent (org.eclipse.swt.custom.BidiSegmentEvent)2 BidiSegmentListener (org.eclipse.swt.custom.BidiSegmentListener)2 StyledText (org.eclipse.swt.custom.StyledText)2 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Layout (org.eclipse.swt.widgets.Layout)1