|
Lines 822-836
Link Here
|
| 822 |
} |
822 |
} |
| 823 |
|
823 |
|
| 824 |
/** |
824 |
/** |
| 825 |
* Translates a given y-coordinate of this ruler into the corresponding |
825 |
* Translates a given y-coordinate of this ruler into the corresponding document lines. The |
| 826 |
* document lines. The number of lines depends on the concrete scaling |
826 |
* number of lines depends on the concrete scaling given as the ration between the height of |
| 827 |
* given as the ration between the height of this ruler and the length |
827 |
* this ruler and the length of the document. |
| 828 |
* of the document. |
828 |
* |
| 829 |
* |
829 |
* When restrictForAnnotation is true, then line number calculation is done only for the height |
|
|
830 |
* of the annotation, else it will be done for the entire lenght of the line. |
| 831 |
* |
| 830 |
* @param y_coordinate the y-coordinate |
832 |
* @param y_coordinate the y-coordinate |
|
|
833 |
* @param restrictForAnnotation <code>true</code> if calculation is for annotation |
| 831 |
* @return the corresponding document lines |
834 |
* @return the corresponding document lines |
| 832 |
*/ |
835 |
*/ |
| 833 |
private int[] toLineNumbers(int y_coordinate) { |
836 |
private int[] toLineNumbers(int y_coordinate, boolean restrictForAnnotation) { |
| 834 |
|
837 |
|
| 835 |
StyledText textWidget= fTextViewer.getTextWidget(); |
838 |
StyledText textWidget= fTextViewer.getTextWidget(); |
| 836 |
int maxLines= textWidget.getContent().getLineCount(); |
839 |
int maxLines= textWidget.getContent().getLineCount(); |
|
Lines 850-857
Link Here
|
| 850 |
int pixel1= Math.min(rulerLength, y_coordinate + 1); |
853 |
int pixel1= Math.min(rulerLength, y_coordinate + 1); |
| 851 |
rulerLength= Math.max(rulerLength, 1); |
854 |
rulerLength= Math.max(rulerLength, 1); |
| 852 |
|
855 |
|
| 853 |
lines[0]= (pixel0 * maxLines) / rulerLength; |
856 |
// if the ruler is very big, rounding off is heavy |
| 854 |
lines[1]= (pixel1 * maxLines) / rulerLength; |
857 |
if(rulerLength > maxLines){ |
|
|
858 |
lines[0]= (int)(pixel0 * (maxLines / (double)rulerLength)); |
| 859 |
lines[1]= (int)(pixel1 * (maxLines / (double)rulerLength)); |
| 860 |
}else{ |
| 861 |
lines[0]= pixel0 * (maxLines / rulerLength); |
| 862 |
lines[1]= pixel1 * (maxLines / rulerLength); |
| 863 |
} |
| 864 |
|
| 865 |
if (restrictForAnnotation) { |
| 866 |
// hit test should be only for the annotation height - not for the entire line length |
| 867 |
if (y_coordinate > (((lines[0] * rulerLength) / maxLines) + fAnnotationHeight)) |
| 868 |
return new int[] { -1, -1 }; |
| 869 |
} |
| 855 |
|
870 |
|
| 856 |
if (fTextViewer instanceof ITextViewerExtension5) { |
871 |
if (fTextViewer instanceof ITextViewerExtension5) { |
| 857 |
ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer; |
872 |
ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer; |
|
Lines 955-961
Link Here
|
| 955 |
*/ |
970 |
*/ |
| 956 |
private void handleMouseDown(MouseEvent event) { |
971 |
private void handleMouseDown(MouseEvent event) { |
| 957 |
if (fTextViewer != null) { |
972 |
if (fTextViewer != null) { |
| 958 |
int[] lines= toLineNumbers(event.y); |
973 |
int[] lines= toLineNumbers(event.y, false); |
| 959 |
Position p= getAnnotationPosition(lines); |
974 |
Position p= getAnnotationPosition(lines); |
| 960 |
if (p == null && event.button == 1) { |
975 |
if (p == null && event.button == 1) { |
| 961 |
try { |
976 |
try { |
|
Lines 980-986
Link Here
|
| 980 |
*/ |
995 |
*/ |
| 981 |
private void handleMouseMove(MouseEvent event) { |
996 |
private void handleMouseMove(MouseEvent event) { |
| 982 |
if (fTextViewer != null) { |
997 |
if (fTextViewer != null) { |
| 983 |
int[] lines= toLineNumbers(event.y); |
998 |
int[] lines= toLineNumbers(event.y, true); |
| 984 |
Position p= getAnnotationPosition(lines); |
999 |
Position p= getAnnotationPosition(lines); |
| 985 |
Cursor cursor= (p != null ? fHitDetectionCursor : null); |
1000 |
Cursor cursor= (p != null ? fHitDetectionCursor : null); |
| 986 |
if (cursor != fLastCursor) { |
1001 |
if (cursor != fLastCursor) { |
|
Lines 1234-1240
Link Here
|
| 1234 |
if (fTextViewer == null || y_coordinate == -1) |
1249 |
if (fTextViewer == null || y_coordinate == -1) |
| 1235 |
return -1; |
1250 |
return -1; |
| 1236 |
|
1251 |
|
| 1237 |
int[] lineNumbers= toLineNumbers(y_coordinate); |
1252 |
int[] lineNumbers= toLineNumbers(y_coordinate, false); |
| 1238 |
int bestLine= findBestMatchingLineNumber(lineNumbers); |
1253 |
int bestLine= findBestMatchingLineNumber(lineNumbers); |
| 1239 |
if (bestLine == -1 && lineNumbers.length > 0) |
1254 |
if (bestLine == -1 && lineNumbers.length > 0) |
| 1240 |
return lineNumbers[0]; |
1255 |
return lineNumbers[0]; |
|
Lines 1259-1265
Link Here
|
| 1259 |
* @see org.eclipse.jface.text.source.IOverviewRuler#hasAnnotation(int) |
1274 |
* @see org.eclipse.jface.text.source.IOverviewRuler#hasAnnotation(int) |
| 1260 |
*/ |
1275 |
*/ |
| 1261 |
public boolean hasAnnotation(int y) { |
1276 |
public boolean hasAnnotation(int y) { |
| 1262 |
return findBestMatchingLineNumber(toLineNumbers(y)) != -1; |
1277 |
return findBestMatchingLineNumber(toLineNumbers(y, true)) != -1; |
| 1263 |
} |
1278 |
} |
| 1264 |
|
1279 |
|
| 1265 |
/* |
1280 |
/* |