use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class TextViewerDeleteLineTarget method clipToVisibleRegion.
/**
* Clips the given start and end offset to the visible viewer region.
*
* @param startOffset the start offset
* @param endOffset the end offset
* @return the clipped region
* @since 3.3.2
*/
private IRegion clipToVisibleRegion(int startOffset, int endOffset) {
ITextViewer viewer = fClipboard.getViewer();
IRegion visibleRegion;
if (viewer instanceof ITextViewerExtension5)
visibleRegion = ((ITextViewerExtension5) viewer).getModelCoverage();
else
visibleRegion = viewer.getVisibleRegion();
int visibleStart = visibleRegion.getOffset();
int visibleLength = visibleRegion.getLength();
startOffset = Math.max(startOffset, visibleStart);
endOffset = Math.min(endOffset, visibleStart + visibleLength);
return new Region(startOffset, endOffset - startOffset);
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method getOffset.
/**
* Returns the document relative offset from the text widget relative point
*
* @param document the document
* @param textWidget the text widget
* @param point the point for which to get the offset
* @return the offset
* @throws BadLocationException if the document is accessed with an invalid line
*/
private int getOffset(IDocument document, StyledText textWidget, Point point) throws BadLocationException {
int widgetCaret = fViewer.getTextWidget().getCaretOffset();
if (fViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 ext = (ITextViewerExtension5) fViewer;
int widgetOffset = textWidget.getOffsetAtPoint(point);
int offset = widgetOffset != -1 ? ext.widgetOffset2ModelOffset(textWidget.getOffsetAtPoint(point)) : -1;
if (offset == -1) {
int docLineIndex = ext.widgetLine2ModelLine(textWidget.getLineIndex(point.y));
String lineDelimiter = document.getLineDelimiter(docLineIndex);
int delimLength = lineDelimiter == null ? 0 : lineDelimiter.length();
return document.getLineOffset(docLineIndex) + document.getLineLength(docLineIndex) - delimLength;
}
return offset;
}
IRegion visible = fViewer.getVisibleRegion();
return widgetCaret + visible.getOffset();
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class OverviewRuler method handleMouseScrolled.
/**
* Handles mouse scrolls.
*
* @param event the mouse scrolled event
*/
private void handleMouseScrolled(MouseEvent event) {
if (fTextViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
StyledText textWidget = fTextViewer.getTextWidget();
int topIndex = textWidget.getTopIndex();
int newTopIndex = Math.max(0, topIndex - event.count);
fTextViewer.setTopIndex(extension.widgetLine2ModelLine(newTopIndex));
} else if (fTextViewer != null) {
int topIndex = fTextViewer.getTopIndex();
int newTopIndex = Math.max(0, topIndex - event.count);
fTextViewer.setTopIndex(newTopIndex);
}
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class VerticalRuler method doubleBufferPaint.
/**
* Double buffer drawing.
*
* @param dest the GC to draw into
*/
private void doubleBufferPaint(GC dest) {
Point size = fCanvas.getSize();
if (size.x <= 0 || size.y <= 0)
return;
if (fBuffer != null) {
Rectangle r = fBuffer.getBounds();
if (r.width != size.x || r.height != size.y) {
fBuffer.dispose();
fBuffer = null;
}
}
if (fBuffer == null)
fBuffer = new Image(fCanvas.getDisplay(), size.x, size.y);
GC gc = new GC(fBuffer);
gc.setFont(fTextViewer.getTextWidget().getFont());
try {
gc.setBackground(fCanvas.getBackground());
gc.fillRectangle(0, 0, size.x, size.y);
if (fTextViewer instanceof ITextViewerExtension5)
doPaint1(gc);
else
doPaint(gc);
} finally {
gc.dispose();
}
dest.drawImage(fBuffer, 0, 0);
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class VerticalRuler method widgetLine2ModelLine.
/**
* Returns the line of the viewer's document that corresponds to the given widget line.
*
* @param viewer the viewer
* @param widgetLine the widget line
* @return the corresponding line of the viewer's document
* @since 2.1
*/
protected static final int widgetLine2ModelLine(ITextViewer viewer, int widgetLine) {
if (viewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
return extension.widgetLine2ModelLine(widgetLine);
}
try {
IRegion r = viewer.getVisibleRegion();
IDocument d = viewer.getDocument();
return widgetLine += d.getLineOfOffset(r.getOffset());
} catch (BadLocationException x) {
}
return widgetLine;
}
Aggregations