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;
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class InlinedAnnotationSupport method getInlinedAnnotationAtLine.
/**
* Returns the {@link AbstractInlinedAnnotation} from the given line index and null otherwise.
*
* @param viewer the source viewer
* @param lineIndex the line index.
* @return the {@link AbstractInlinedAnnotation} from the given line index and null otherwise.
*/
private static AbstractInlinedAnnotation getInlinedAnnotationAtLine(ISourceViewer viewer, int lineIndex) {
if (viewer == null) {
return null;
}
IAnnotationModel annotationModel = viewer.getAnnotationModel();
if (annotationModel == null) {
return null;
}
IDocument document = viewer.getDocument();
int lineNumber = lineIndex;
if (lineNumber > document.getNumberOfLines()) {
return null;
}
try {
if (viewer instanceof ITextViewerExtension5) {
lineNumber = ((ITextViewerExtension5) viewer).widgetLine2ModelLine(lineNumber);
}
IRegion line = document.getLineInformation(lineNumber);
return getInlinedAnnotationAtOffset(viewer, line.getOffset(), line.getLength());
} catch (BadLocationException e) {
return null;
}
}
Aggregations