|
Lines 804-818
Link Here
|
| 804 |
} |
804 |
} |
| 805 |
|
805 |
|
| 806 |
/** |
806 |
/** |
| 807 |
* Translates a given y-coordinate of this ruler into the corresponding |
807 |
* Translates a given y-coordinate of this ruler into the corresponding document lines. The |
| 808 |
* document lines. The number of lines depends on the concrete scaling |
808 |
* number of lines depends on the concrete scaling given as the ration between the height of |
| 809 |
* given as the ration between the height of this ruler and the length |
809 |
* this ruler and the length of the document. |
| 810 |
* of the document. |
810 |
* |
| 811 |
* |
811 |
* When restrictForAnnotation is true, then line number calculation is done only for the height |
|
|
812 |
* of the annotation, else it will be done for the entire lenght of the line. |
| 813 |
* |
| 812 |
* @param y_coordinate the y-coordinate |
814 |
* @param y_coordinate the y-coordinate |
|
|
815 |
* @param restrictForAnnotation <code>true</code> if calculation is for annotation |
| 813 |
* @return the corresponding document lines |
816 |
* @return the corresponding document lines |
| 814 |
*/ |
817 |
*/ |
| 815 |
private int[] toLineNumbers(int y_coordinate) { |
818 |
private int[] toLineNumbers(int y_coordinate, boolean restrictForAnnotation) { |
| 816 |
|
819 |
|
| 817 |
StyledText textWidget= fTextViewer.getTextWidget(); |
820 |
StyledText textWidget= fTextViewer.getTextWidget(); |
| 818 |
int maxLines= textWidget.getContent().getLineCount(); |
821 |
int maxLines= textWidget.getContent().getLineCount(); |
|
Lines 832-839
Link Here
|
| 832 |
int pixel1= Math.min(rulerLength, y_coordinate + 1); |
835 |
int pixel1= Math.min(rulerLength, y_coordinate + 1); |
| 833 |
rulerLength= Math.max(rulerLength, 1); |
836 |
rulerLength= Math.max(rulerLength, 1); |
| 834 |
|
837 |
|
| 835 |
lines[0]= (pixel0 * maxLines) / rulerLength; |
838 |
// if the ruler is very big, rounding off is heavy |
| 836 |
lines[1]= (pixel1 * maxLines) / rulerLength; |
839 |
if(rulerLength > maxLines){ |
|
|
840 |
lines[0]= (int)(pixel0 * (maxLines / (double)rulerLength)); |
| 841 |
lines[1]= (int)(pixel1 * (maxLines / (double)rulerLength)); |
| 842 |
}else{ |
| 843 |
lines[0]= pixel0 * (maxLines / rulerLength); |
| 844 |
lines[1]= pixel1 * (maxLines / rulerLength); |
| 845 |
} |
| 846 |
|
| 847 |
if (restrictForAnnotation) { |
| 848 |
// hit test should be only for the annotation height - not for the entire line length |
| 849 |
if (y_coordinate > (((lines[0] * rulerLength) / maxLines) + fAnnotationHeight)) |
| 850 |
return new int[] { -1, -1 }; |
| 851 |
} |
| 837 |
|
852 |
|
| 838 |
if (fTextViewer instanceof ITextViewerExtension5) { |
853 |
if (fTextViewer instanceof ITextViewerExtension5) { |
| 839 |
ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer; |
854 |
ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer; |
|
Lines 937-943
Link Here
|
| 937 |
*/ |
952 |
*/ |
| 938 |
private void handleMouseDown(MouseEvent event) { |
953 |
private void handleMouseDown(MouseEvent event) { |
| 939 |
if (fTextViewer != null) { |
954 |
if (fTextViewer != null) { |
| 940 |
int[] lines= toLineNumbers(event.y); |
955 |
int[] lines= toLineNumbers(event.y, false); |
| 941 |
Position p= getAnnotationPosition(lines); |
956 |
Position p= getAnnotationPosition(lines); |
| 942 |
if (p == null && event.button == 1) { |
957 |
if (p == null && event.button == 1) { |
| 943 |
try { |
958 |
try { |
|
Lines 962-968
Link Here
|
| 962 |
*/ |
977 |
*/ |
| 963 |
private void handleMouseMove(MouseEvent event) { |
978 |
private void handleMouseMove(MouseEvent event) { |
| 964 |
if (fTextViewer != null) { |
979 |
if (fTextViewer != null) { |
| 965 |
int[] lines= toLineNumbers(event.y); |
980 |
int[] lines= toLineNumbers(event.y, true); |
| 966 |
Position p= getAnnotationPosition(lines); |
981 |
Position p= getAnnotationPosition(lines); |
| 967 |
Cursor cursor= (p != null ? fHitDetectionCursor : null); |
982 |
Cursor cursor= (p != null ? fHitDetectionCursor : null); |
| 968 |
if (cursor != fLastCursor) { |
983 |
if (cursor != fLastCursor) { |
|
Lines 1216-1222
Link Here
|
| 1216 |
if (fTextViewer == null || y_coordinate == -1) |
1231 |
if (fTextViewer == null || y_coordinate == -1) |
| 1217 |
return -1; |
1232 |
return -1; |
| 1218 |
|
1233 |
|
| 1219 |
int[] lineNumbers= toLineNumbers(y_coordinate); |
1234 |
int[] lineNumbers= toLineNumbers(y_coordinate, false); |
| 1220 |
int bestLine= findBestMatchingLineNumber(lineNumbers); |
1235 |
int bestLine= findBestMatchingLineNumber(lineNumbers); |
| 1221 |
if (bestLine == -1 && lineNumbers.length > 0) |
1236 |
if (bestLine == -1 && lineNumbers.length > 0) |
| 1222 |
return lineNumbers[0]; |
1237 |
return lineNumbers[0]; |
|
Lines 1241-1247
Link Here
|
| 1241 |
* @see org.eclipse.jface.text.source.IOverviewRuler#hasAnnotation(int) |
1256 |
* @see org.eclipse.jface.text.source.IOverviewRuler#hasAnnotation(int) |
| 1242 |
*/ |
1257 |
*/ |
| 1243 |
public boolean hasAnnotation(int y) { |
1258 |
public boolean hasAnnotation(int y) { |
| 1244 |
return findBestMatchingLineNumber(toLineNumbers(y)) != -1; |
1259 |
return findBestMatchingLineNumber(toLineNumbers(y, true)) != -1; |
| 1245 |
} |
1260 |
} |
| 1246 |
|
1261 |
|
| 1247 |
/* |
1262 |
/* |