use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class LineNumberRulerColumn method handleMouseScrolled.
/**
* Handles mouse scrolled events on the ruler by forwarding them to the text widget.
*
* @param e the mouse event
* @since 3.10
*/
void handleMouseScrolled(MouseEvent e) {
if (fCachedTextViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) fCachedTextViewer;
StyledText textWidget = fCachedTextViewer.getTextWidget();
int topIndex = textWidget.getTopIndex();
int newTopIndex = Math.max(0, topIndex - e.count);
fCachedTextViewer.setTopIndex(extension.widgetLine2ModelLine(newTopIndex));
} else {
int topIndex = fCachedTextViewer.getTopIndex();
int newTopIndex = Math.max(0, topIndex - e.count);
fCachedTextViewer.setTopIndex(newTopIndex);
}
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class OverviewRuler method toLineNumbers.
/**
* Translates a given y-coordinate of this ruler into the corresponding
* document lines. The number of lines depends on the concrete scaling
* given as the ration between the height of this ruler and the length
* of the document.
*
* @param y_coordinate the y-coordinate
* @param annotationRect <code>true</code> to only consider the position of a drawn annotation rectangle,
* <code>false</code> to consider the whole line
* @return the corresponding document lines as {firstLine, lastLine}, or {-1, -1} if no lines correspond to the y-coordinate
*/
private int[] toLineNumbers(int y_coordinate, boolean annotationRect) {
// this is the inverse of #computeY(int, WidgetInfos)
WidgetInfos infos = new WidgetInfos(fTextViewer.getTextWidget(), fCanvas);
if (y_coordinate >= infos.writable || y_coordinate >= infos.bounds.height || y_coordinate < 0)
return new int[] { -1, -1 };
if (annotationRect && ANNOTATION_HEIGHT >= infos.bounds.height / infos.maxLines)
annotationRect = false;
int[] lines = new int[2];
int[] pixels;
int pixelEnd = Math.min(infos.bounds.height, y_coordinate + ANNOTATION_HEIGHT / 2 + 1);
if (annotationRect) {
pixels = new int[] { pixelEnd };
} else {
int pixelStart = Math.max(y_coordinate - ANNOTATION_HEIGHT / 2 + 1, 0);
pixels = new int[] { pixelStart, pixelEnd };
}
if (infos.bounds.height > infos.writable || infos.invisibleLines <= 0) {
// yy = Math.max(0, (2 * startLine + 1) * infos.writable / (infos.maxLines * 2) - infos.bounds.y);
for (int i = 0; i < pixels.length; i++) lines[i] = (int) ((pixels[i] + infos.bounds.y) * infos.maxLines / (double) infos.writable);
if (DEBUG_TO_DOCUMENT_LINE_NUMBER)
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
System.out.println("static y: " + y_coordinate + " => [" + lines[0] + ", " + lines[1] + "]");
} else if (y_coordinate < infos.thumbHeight / 2) {
// yy= (int) (startLine * infos.thumbHeight / infos.visibleLines);
for (int i = 0; i < pixels.length; i++) lines[i] = (int) (pixels[i] * infos.visibleLines / infos.thumbHeight);
if (DEBUG_TO_DOCUMENT_LINE_NUMBER)
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
System.out.println("start y: " + y_coordinate + " => [" + lines[0] + ", " + lines[1] + "]");
} else if (infos.bounds.height - 1 - infos.thumbHeight / 2 < y_coordinate) {
// yy= (int) (infos.bounds.height-1 - (double)infos.thumbHeight / 2 + (startLine - (infos.maxLines - infos.visibleLines / 2) + 1) * infos.thumbHeight / infos.visibleLines);
for (int i = 0; i < pixels.length; i++) lines[i] = (int) ((pixels[i] - (infos.bounds.height - 1) + (double) infos.thumbHeight / 2) * infos.visibleLines / infos.thumbHeight - 1 + (infos.maxLines - infos.visibleLines / 2));
if (DEBUG_TO_DOCUMENT_LINE_NUMBER)
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
System.out.println("end y: " + y_coordinate + " => [" + lines[0] + ", " + lines[1] + "]");
} else {
// yy= (int) ((double)infos.thumbHeight/2 + (startLine + 1 - infos.visibleLines / 2) * (infos.bounds.height-1 - infos.thumbHeight) / infos.invisibleLines);
for (int i = 0; i < pixels.length; i++) lines[i] = (int) ((pixels[i] - (double) infos.thumbHeight / 2) * infos.invisibleLines / (infos.bounds.height - 1 - infos.thumbHeight) - 1 + infos.visibleLines / 2);
if (DEBUG_TO_DOCUMENT_LINE_NUMBER)
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
System.out.println("middle y: " + y_coordinate + " => [" + lines[0] + ", " + lines[1] + "]");
}
if (y_coordinate < ANNOTATION_HEIGHT && y_coordinate < infos.bounds.y)
lines[0] = 0;
else if (lines[0] < 0)
lines[0] = 0;
if (annotationRect) {
int y0 = computeY(lines[0], infos);
if (y_coordinate < y0 || y0 + ANNOTATION_HEIGHT < y_coordinate) {
lines[0] = -1;
lines[1] = -1;
return lines;
} else {
lines[1] = lines[0];
}
}
if (lines[1] > infos.maxLines)
lines[1] = infos.maxLines;
if (fTextViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
lines[0] = extension.widgetLine2ModelLine(lines[0]);
lines[1] = extension.widgetLine2ModelLine(lines[1]);
} else {
try {
IRegion visible = fTextViewer.getVisibleRegion();
int lineNumber = fTextViewer.getDocument().getLineOfOffset(visible.getOffset());
lines[0] += lineNumber;
lines[1] += lineNumber;
} catch (BadLocationException x) {
}
}
if (DEBUG_TO_DOCUMENT_LINE_NUMBER)
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
System.out.println("result: [" + lines[0] + ", " + lines[1] + "]");
return lines;
}
Aggregations