Mercurial > projects > dwt-addons
annotate dwtx/jface/text/source/VerticalRuler.d @ 135:65801ad2b265
Regex fix for anon classes
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 01:52:31 +0200 |
parents | 51e6e63f930e |
children | b6bad70d540a |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.text.source.VerticalRuler; | |
14 | |
131 | 15 import dwtx.jface.text.source.ISharedTextColors; // packageimport |
16 import dwtx.jface.text.source.ILineRange; // packageimport | |
17 import dwtx.jface.text.source.IAnnotationPresentation; // packageimport | |
18 import dwtx.jface.text.source.IVerticalRulerInfoExtension; // packageimport | |
19 import dwtx.jface.text.source.ICharacterPairMatcher; // packageimport | |
20 import dwtx.jface.text.source.TextInvocationContext; // packageimport | |
21 import dwtx.jface.text.source.LineChangeHover; // packageimport | |
22 import dwtx.jface.text.source.IChangeRulerColumn; // packageimport | |
23 import dwtx.jface.text.source.IAnnotationMap; // packageimport | |
24 import dwtx.jface.text.source.IAnnotationModelListenerExtension; // packageimport | |
25 import dwtx.jface.text.source.ISourceViewerExtension2; // packageimport | |
26 import dwtx.jface.text.source.IAnnotationHover; // packageimport | |
27 import dwtx.jface.text.source.ContentAssistantFacade; // packageimport | |
28 import dwtx.jface.text.source.IAnnotationAccess; // packageimport | |
29 import dwtx.jface.text.source.IVerticalRulerExtension; // packageimport | |
30 import dwtx.jface.text.source.IVerticalRulerColumn; // packageimport | |
31 import dwtx.jface.text.source.LineNumberRulerColumn; // packageimport | |
32 import dwtx.jface.text.source.MatchingCharacterPainter; // packageimport | |
33 import dwtx.jface.text.source.IAnnotationModelExtension; // packageimport | |
34 import dwtx.jface.text.source.ILineDifferExtension; // packageimport | |
35 import dwtx.jface.text.source.DefaultCharacterPairMatcher; // packageimport | |
36 import dwtx.jface.text.source.LineNumberChangeRulerColumn; // packageimport | |
37 import dwtx.jface.text.source.IAnnotationAccessExtension; // packageimport | |
38 import dwtx.jface.text.source.ISourceViewer; // packageimport | |
39 import dwtx.jface.text.source.AnnotationModel; // packageimport | |
40 import dwtx.jface.text.source.ILineDifferExtension2; // packageimport | |
41 import dwtx.jface.text.source.IAnnotationModelListener; // packageimport | |
42 import dwtx.jface.text.source.IVerticalRuler; // packageimport | |
43 import dwtx.jface.text.source.DefaultAnnotationHover; // packageimport | |
44 import dwtx.jface.text.source.SourceViewer; // packageimport | |
45 import dwtx.jface.text.source.SourceViewerConfiguration; // packageimport | |
46 import dwtx.jface.text.source.AnnotationBarHoverManager; // packageimport | |
47 import dwtx.jface.text.source.CompositeRuler; // packageimport | |
48 import dwtx.jface.text.source.ImageUtilities; // packageimport | |
49 import dwtx.jface.text.source.VisualAnnotationModel; // packageimport | |
50 import dwtx.jface.text.source.IAnnotationModel; // packageimport | |
51 import dwtx.jface.text.source.ISourceViewerExtension3; // packageimport | |
52 import dwtx.jface.text.source.ILineDiffInfo; // packageimport | |
53 import dwtx.jface.text.source.VerticalRulerEvent; // packageimport | |
54 import dwtx.jface.text.source.ChangeRulerColumn; // packageimport | |
55 import dwtx.jface.text.source.ILineDiffer; // packageimport | |
56 import dwtx.jface.text.source.AnnotationModelEvent; // packageimport | |
57 import dwtx.jface.text.source.AnnotationColumn; // packageimport | |
58 import dwtx.jface.text.source.AnnotationRulerColumn; // packageimport | |
59 import dwtx.jface.text.source.IAnnotationHoverExtension; // packageimport | |
60 import dwtx.jface.text.source.AbstractRulerColumn; // packageimport | |
61 import dwtx.jface.text.source.ISourceViewerExtension; // packageimport | |
62 import dwtx.jface.text.source.AnnotationMap; // packageimport | |
63 import dwtx.jface.text.source.IVerticalRulerInfo; // packageimport | |
64 import dwtx.jface.text.source.IAnnotationModelExtension2; // packageimport | |
65 import dwtx.jface.text.source.LineRange; // packageimport | |
66 import dwtx.jface.text.source.IAnnotationAccessExtension2; // packageimport | |
67 import dwtx.jface.text.source.JFaceTextMessages; // packageimport | |
68 import dwtx.jface.text.source.IOverviewRuler; // packageimport | |
69 import dwtx.jface.text.source.Annotation; // packageimport | |
70 import dwtx.jface.text.source.IVerticalRulerListener; // packageimport | |
71 import dwtx.jface.text.source.ISourceViewerExtension4; // packageimport | |
72 import dwtx.jface.text.source.AnnotationPainter; // packageimport | |
73 import dwtx.jface.text.source.IAnnotationHoverExtension2; // packageimport | |
74 import dwtx.jface.text.source.OverviewRuler; // packageimport | |
75 import dwtx.jface.text.source.OverviewRulerHoverManager; // packageimport | |
76 | |
77 | |
129 | 78 import dwt.dwthelper.utils; |
79 | |
80 | |
81 import java.util.Iterator; | |
82 | |
83 import dwt.DWT; | |
84 import dwt.custom.StyledText; | |
85 import dwt.events.DisposeEvent; | |
86 import dwt.events.DisposeListener; | |
87 import dwt.events.MouseEvent; | |
88 import dwt.events.MouseListener; | |
89 import dwt.events.PaintEvent; | |
90 import dwt.events.PaintListener; | |
91 import dwt.graphics.Font; | |
92 import dwt.graphics.GC; | |
93 import dwt.graphics.Image; | |
94 import dwt.graphics.Point; | |
95 import dwt.graphics.Rectangle; | |
96 import dwt.widgets.Canvas; | |
97 import dwt.widgets.Composite; | |
98 import dwt.widgets.Control; | |
99 import dwt.widgets.Display; | |
100 import dwtx.jface.text.BadLocationException; | |
101 import dwtx.jface.text.IDocument; | |
102 import dwtx.jface.text.IRegion; | |
103 import dwtx.jface.text.ITextListener; | |
104 import dwtx.jface.text.ITextViewer; | |
105 import dwtx.jface.text.ITextViewerExtension5; | |
106 import dwtx.jface.text.IViewportListener; | |
107 import dwtx.jface.text.JFaceTextUtil; | |
108 import dwtx.jface.text.Position; | |
109 import dwtx.jface.text.Region; | |
110 import dwtx.jface.text.TextEvent; | |
111 | |
112 | |
113 /** | |
114 * A vertical ruler which is connected to a text viewer. Single column standard | |
115 * implementation of {@link dwtx.jface.text.source.IVerticalRuler}. | |
116 * <p> | |
117 * The same can be achieved by using <code>CompositeRuler</code> configured | |
118 * with an <code>AnnotationRulerColumn</code>. Clients may use this class as | |
119 * is. | |
120 * | |
121 * @see dwtx.jface.text.ITextViewer | |
122 */ | |
123 public final class VerticalRuler : IVerticalRuler, IVerticalRulerExtension { | |
124 | |
125 /** | |
126 * Internal listener class. | |
127 */ | |
128 class InternalListener : IViewportListener, IAnnotationModelListener, ITextListener { | |
129 | |
130 /* | |
131 * @see IViewportListener#viewportChanged(int) | |
132 */ | |
133 public void viewportChanged(int verticalPosition) { | |
134 if (verticalPosition !is fScrollPos) | |
135 redraw(); | |
136 } | |
137 | |
138 /* | |
139 * @see IAnnotationModelListener#modelChanged(IAnnotationModel) | |
140 */ | |
141 public void modelChanged(IAnnotationModel model) { | |
142 update(); | |
143 } | |
144 | |
145 /* | |
146 * @see ITextListener#textChanged(TextEvent) | |
147 */ | |
148 public void textChanged(TextEvent e) { | |
149 if (fTextViewer !is null && e.getViewerRedrawState()) | |
150 redraw(); | |
151 } | |
152 } | |
153 | |
154 /** The vertical ruler's text viewer */ | |
155 private ITextViewer fTextViewer; | |
156 /** The ruler's canvas */ | |
157 private Canvas fCanvas; | |
158 /** The vertical ruler's model */ | |
159 private IAnnotationModel fModel; | |
160 /** Cache for the actual scroll position in pixels */ | |
161 private int fScrollPos; | |
162 /** The buffer for double buffering */ | |
163 private Image fBuffer; | |
164 /** The line of the last mouse button activity */ | |
165 private int fLastMouseButtonActivityLine= -1; | |
166 /** The internal listener */ | |
167 private InternalListener fInternalListener= new InternalListener(); | |
168 /** The width of this vertical ruler */ | |
169 private int fWidth; | |
170 /** | |
171 * The annotation access of this vertical ruler | |
172 * @since 3.0 | |
173 */ | |
174 private IAnnotationAccess fAnnotationAccess; | |
175 | |
176 /** | |
177 * Constructs a vertical ruler with the given width. | |
178 * | |
179 * @param width the width of the vertical ruler | |
180 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
181 public this(int width) { |
129 | 182 this(width, null); |
183 } | |
184 | |
185 /** | |
186 * Constructs a vertical ruler with the given width and the given annotation | |
187 * access. | |
188 * | |
189 * @param width the width of the vertical ruler | |
190 * @param annotationAcccess the annotation access | |
191 * @since 3.0 | |
192 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
193 public this(int width, IAnnotationAccess annotationAcccess) { |
129 | 194 fWidth= width; |
195 fAnnotationAccess= annotationAcccess; | |
196 } | |
197 | |
198 /* | |
199 * @see IVerticalRuler#getControl() | |
200 */ | |
201 public Control getControl() { | |
202 return fCanvas; | |
203 } | |
204 | |
205 /* | |
206 * @see IVerticalRuler#createControl(Composite, ITextViewer) | |
207 */ | |
208 public Control createControl(Composite parent, ITextViewer textViewer) { | |
209 | |
210 fTextViewer= textViewer; | |
211 | |
212 fCanvas= new Canvas(parent, DWT.NO_BACKGROUND); | |
213 | |
135 | 214 fCanvas.addPaintListener(new class() PaintListener { |
129 | 215 public void paintControl(PaintEvent event) { |
216 if (fTextViewer !is null) | |
217 doubleBufferPaint(event.gc); | |
218 } | |
219 }); | |
220 | |
135 | 221 fCanvas.addDisposeListener(new class() DisposeListener { |
129 | 222 public void widgetDisposed(DisposeEvent e) { |
223 handleDispose(); | |
224 fTextViewer= null; | |
225 } | |
226 }); | |
227 | |
135 | 228 fCanvas.addMouseListener(new class() MouseListener { |
129 | 229 public void mouseUp(MouseEvent event) { |
230 } | |
231 | |
232 public void mouseDown(MouseEvent event) { | |
233 fLastMouseButtonActivityLine= toDocumentLineNumber(event.y); | |
234 } | |
235 | |
236 public void mouseDoubleClick(MouseEvent event) { | |
237 fLastMouseButtonActivityLine= toDocumentLineNumber(event.y); | |
238 } | |
239 }); | |
240 | |
241 if (fTextViewer !is null) { | |
242 fTextViewer.addViewportListener(fInternalListener); | |
243 fTextViewer.addTextListener(fInternalListener); | |
244 } | |
245 | |
246 return fCanvas; | |
247 } | |
248 | |
249 /** | |
250 * Disposes the ruler's resources. | |
251 */ | |
252 private void handleDispose() { | |
253 | |
254 if (fTextViewer !is null) { | |
255 fTextViewer.removeViewportListener(fInternalListener); | |
256 fTextViewer.removeTextListener(fInternalListener); | |
257 fTextViewer= null; | |
258 } | |
259 | |
260 if (fModel !is null) | |
261 fModel.removeAnnotationModelListener(fInternalListener); | |
262 | |
263 if (fBuffer !is null) { | |
264 fBuffer.dispose(); | |
265 fBuffer= null; | |
266 } | |
267 } | |
268 | |
269 | |
270 /** | |
271 * Double buffer drawing. | |
272 * | |
273 * @param dest the GC to draw into | |
274 */ | |
275 private void doubleBufferPaint(GC dest) { | |
276 | |
277 Point size= fCanvas.getSize(); | |
278 | |
279 if (size.x <= 0 || size.y <= 0) | |
280 return; | |
281 | |
282 if (fBuffer !is null) { | |
283 Rectangle r= fBuffer.getBounds(); | |
284 if (r.width !is size.x || r.height !is size.y) { | |
285 fBuffer.dispose(); | |
286 fBuffer= null; | |
287 } | |
288 } | |
289 if (fBuffer is null) | |
290 fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); | |
291 | |
292 GC gc= new GC(fBuffer); | |
293 gc.setFont(fTextViewer.getTextWidget().getFont()); | |
294 try { | |
295 gc.setBackground(fCanvas.getBackground()); | |
296 gc.fillRectangle(0, 0, size.x, size.y); | |
297 | |
298 if (fTextViewer instanceof ITextViewerExtension5) | |
299 doPaint1(gc); | |
300 else | |
301 doPaint(gc); | |
302 | |
303 } finally { | |
304 gc.dispose(); | |
305 } | |
306 | |
307 dest.drawImage(fBuffer, 0, 0); | |
308 } | |
309 | |
310 /** | |
311 * Returns the document offset of the upper left corner of the | |
312 * widgets view port, possibly including partially visible lines. | |
313 * | |
314 * @return the document offset of the upper left corner including partially visible lines | |
315 * @since 2.0 | |
316 */ | |
317 private int getInclusiveTopIndexStartOffset() { | |
318 | |
319 StyledText textWidget= fTextViewer.getTextWidget(); | |
320 if (textWidget !is null && !textWidget.isDisposed()) { | |
321 int top= JFaceTextUtil.getPartialTopIndex(fTextViewer); | |
322 try { | |
323 IDocument document= fTextViewer.getDocument(); | |
324 return document.getLineOffset(top); | |
325 } catch (BadLocationException x) { | |
326 } | |
327 } | |
328 | |
329 return -1; | |
330 } | |
331 | |
332 | |
333 | |
334 /** | |
335 * Draws the vertical ruler w/o drawing the Canvas background. | |
336 * | |
337 * @param gc the GC to draw into | |
338 */ | |
339 protected void doPaint(GC gc) { | |
340 | |
341 if (fModel is null || fTextViewer is null) | |
342 return; | |
343 | |
344 IAnnotationAccessExtension annotationAccessExtension= null; | |
345 if (fAnnotationAccess instanceof IAnnotationAccessExtension) | |
134 | 346 annotationAccessExtension= cast(IAnnotationAccessExtension) fAnnotationAccess; |
129 | 347 |
348 StyledText styledText= fTextViewer.getTextWidget(); | |
349 IDocument doc= fTextViewer.getDocument(); | |
350 | |
351 int topLeft= getInclusiveTopIndexStartOffset(); | |
352 int bottomRight= fTextViewer.getBottomIndexEndOffset(); | |
353 int viewPort= bottomRight - topLeft; | |
354 | |
355 Point d= fCanvas.getSize(); | |
356 fScrollPos= styledText.getTopPixel(); | |
357 | |
358 int topLine= -1, bottomLine= -1; | |
359 try { | |
360 IRegion region= fTextViewer.getVisibleRegion(); | |
361 topLine= doc.getLineOfOffset(region.getOffset()); | |
362 bottomLine= doc.getLineOfOffset(region.getOffset() + region.getLength()); | |
363 } catch (BadLocationException x) { | |
364 return; | |
365 } | |
366 | |
367 // draw Annotations | |
368 Rectangle r= new Rectangle(0, 0, 0, 0); | |
369 int maxLayer= 1; // loop at least once though layers. | |
370 | |
371 for (int layer= 0; layer < maxLayer; layer++) { | |
372 Iterator iter= fModel.getAnnotationIterator(); | |
373 while (iter.hasNext()) { | |
374 IAnnotationPresentation annotationPresentation= null; | |
134 | 375 Annotation annotation= cast(Annotation) iter.next(); |
129 | 376 |
377 int lay= IAnnotationAccessExtension.DEFAULT_LAYER; | |
378 if (annotationAccessExtension !is null) | |
379 lay= annotationAccessExtension.getLayer(annotation); | |
380 else if (annotation instanceof IAnnotationPresentation) { | |
134 | 381 annotationPresentation= cast(IAnnotationPresentation)annotation; |
129 | 382 lay= annotationPresentation.getLayer(); |
383 } | |
384 maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum | |
385 if (lay !is layer) // wrong layer: skip annotation | |
386 continue; | |
387 | |
388 Position position= fModel.getPosition(annotation); | |
389 if (position is null) | |
390 continue; | |
391 | |
392 if (!position.overlapsWith(topLeft, viewPort)) | |
393 continue; | |
394 | |
395 try { | |
396 | |
397 int offset= position.getOffset(); | |
398 int length= position.getLength(); | |
399 | |
400 int startLine= doc.getLineOfOffset(offset); | |
401 if (startLine < topLine) | |
402 startLine= topLine; | |
403 | |
404 int endLine= startLine; | |
405 if (length > 0) | |
406 endLine= doc.getLineOfOffset(offset + length - 1); | |
407 if (endLine > bottomLine) | |
408 endLine= bottomLine; | |
409 | |
410 startLine -= topLine; | |
411 endLine -= topLine; | |
412 | |
413 r.x= 0; | |
414 r.y= JFaceTextUtil.computeLineHeight(styledText, 0, startLine, startLine) - fScrollPos; | |
415 | |
416 r.width= d.x; | |
417 int lines= endLine - startLine; | |
418 | |
419 r.height= JFaceTextUtil.computeLineHeight(styledText, startLine, endLine + 1, (lines+1)); | |
420 | |
421 if (r.y < d.y && annotationAccessExtension !is null) // annotation within visible area | |
422 annotationAccessExtension.paint(annotation, gc, fCanvas, r); | |
423 else if (annotationPresentation !is null) | |
424 annotationPresentation.paint(gc, fCanvas, r); | |
425 | |
426 } catch (BadLocationException e) { | |
427 } | |
428 } | |
429 } | |
430 } | |
431 | |
432 /** | |
433 * Draws the vertical ruler w/o drawing the Canvas background. Uses | |
434 * <code>ITextViewerExtension5</code> for its implementation. Will replace | |
435 * <code>doPaint(GC)</code>. | |
436 * | |
437 * @param gc the GC to draw into | |
438 */ | |
439 protected void doPaint1(GC gc) { | |
440 | |
441 if (fModel is null || fTextViewer is null) | |
442 return; | |
443 | |
444 IAnnotationAccessExtension annotationAccessExtension= null; | |
445 if (fAnnotationAccess instanceof IAnnotationAccessExtension) | |
134 | 446 annotationAccessExtension= cast(IAnnotationAccessExtension) fAnnotationAccess; |
129 | 447 |
134 | 448 ITextViewerExtension5 extension= cast(ITextViewerExtension5) fTextViewer; |
129 | 449 StyledText textWidget= fTextViewer.getTextWidget(); |
450 | |
451 fScrollPos= textWidget.getTopPixel(); | |
452 Point dimension= fCanvas.getSize(); | |
453 | |
454 // draw Annotations | |
455 Rectangle r= new Rectangle(0, 0, 0, 0); | |
456 int maxLayer= 1; // loop at least once through layers. | |
457 | |
458 for (int layer= 0; layer < maxLayer; layer++) { | |
459 Iterator iter= fModel.getAnnotationIterator(); | |
460 while (iter.hasNext()) { | |
461 IAnnotationPresentation annotationPresentation= null; | |
134 | 462 Annotation annotation= cast(Annotation) iter.next(); |
129 | 463 |
464 int lay= IAnnotationAccessExtension.DEFAULT_LAYER; | |
465 if (annotationAccessExtension !is null) | |
466 lay= annotationAccessExtension.getLayer(annotation); | |
467 else if (annotation instanceof IAnnotationPresentation) { | |
134 | 468 annotationPresentation= cast(IAnnotationPresentation)annotation; |
129 | 469 lay= annotationPresentation.getLayer(); |
470 } | |
471 maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum | |
472 if (lay !is layer) // wrong layer: skip annotation | |
473 continue; | |
474 | |
475 Position position= fModel.getPosition(annotation); | |
476 if (position is null) | |
477 continue; | |
478 | |
479 IRegion widgetRegion= extension.modelRange2WidgetRange(new Region(position.getOffset(), position.getLength())); | |
480 if (widgetRegion is null) | |
481 continue; | |
482 | |
483 int startLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset()); | |
484 if (startLine is -1) | |
485 continue; | |
486 | |
487 int endLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset() + Math.max(widgetRegion.getLength() -1, 0)); | |
488 if (endLine is -1) | |
489 continue; | |
490 | |
491 r.x= 0; | |
492 r.y= JFaceTextUtil.computeLineHeight(textWidget, 0, startLine, startLine) - fScrollPos; | |
493 | |
494 r.width= dimension.x; | |
495 int lines= endLine - startLine; | |
496 | |
497 r.height= JFaceTextUtil.computeLineHeight(textWidget, startLine, endLine + 1, lines+1); | |
498 | |
499 if (r.y < dimension.y && annotationAccessExtension !is null) // annotation within visible area | |
500 annotationAccessExtension.paint(annotation, gc, fCanvas, r); | |
501 else if (annotationPresentation !is null) | |
502 annotationPresentation.paint(gc, fCanvas, r); | |
503 } | |
504 } | |
505 } | |
506 | |
507 /** | |
508 * Thread-safe implementation. | |
509 * Can be called from any thread. | |
510 */ | |
511 /* | |
512 * @see IVerticalRuler#update() | |
513 */ | |
514 public void update() { | |
515 if (fCanvas !is null && !fCanvas.isDisposed()) { | |
516 Display d= fCanvas.getDisplay(); | |
517 if (d !is null) { | |
135 | 518 d.asyncExec(new class() Runnable { |
129 | 519 public void run() { |
520 redraw(); | |
521 } | |
522 }); | |
523 } | |
524 } | |
525 } | |
526 | |
527 /** | |
528 * Redraws the vertical ruler. | |
529 */ | |
530 private void redraw() { | |
531 if (fCanvas !is null && !fCanvas.isDisposed()) { | |
532 GC gc= new GC(fCanvas); | |
533 doubleBufferPaint(gc); | |
534 gc.dispose(); | |
535 } | |
536 } | |
537 | |
538 /* | |
539 * @see IVerticalRuler#setModel(IAnnotationModel) | |
540 */ | |
541 public void setModel(IAnnotationModel model) { | |
542 if (model !is fModel) { | |
543 | |
544 if (fModel !is null) | |
545 fModel.removeAnnotationModelListener(fInternalListener); | |
546 | |
547 fModel= model; | |
548 | |
549 if (fModel !is null) | |
550 fModel.addAnnotationModelListener(fInternalListener); | |
551 | |
552 update(); | |
553 } | |
554 } | |
555 | |
556 /* | |
557 * @see IVerticalRuler#getModel() | |
558 */ | |
559 public IAnnotationModel getModel() { | |
560 return fModel; | |
561 } | |
562 | |
563 /* | |
564 * @see IVerticalRulerInfo#getWidth() | |
565 */ | |
566 public int getWidth() { | |
567 return fWidth; | |
568 } | |
569 | |
570 /* | |
571 * @see IVerticalRulerInfo#getLineOfLastMouseButtonActivity() | |
572 */ | |
573 public int getLineOfLastMouseButtonActivity() { | |
574 IDocument doc= fTextViewer.getDocument(); | |
575 if (doc is null || fLastMouseButtonActivityLine >= fTextViewer.getDocument().getNumberOfLines()) | |
576 fLastMouseButtonActivityLine= -1; | |
577 return fLastMouseButtonActivityLine; | |
578 } | |
579 | |
580 /* | |
581 * @see IVerticalRulerInfo#toDocumentLineNumber(int) | |
582 */ | |
583 public int toDocumentLineNumber(int y_coordinate) { | |
584 if (fTextViewer is null || y_coordinate is -1) | |
585 return -1; | |
586 | |
587 StyledText text= fTextViewer.getTextWidget(); | |
588 int line= text.getLineIndex(y_coordinate); | |
589 | |
590 if (line is text.getLineCount() - 1) { | |
591 // check whether y_coordinate exceeds last line | |
592 if (y_coordinate > text.getLinePixel(line + 1)) | |
593 return -1; | |
594 } | |
595 | |
596 return widgetLine2ModelLine(fTextViewer, line); | |
597 } | |
598 | |
599 /** | |
600 * Returns the line of the viewer's document that corresponds to the given widget line. | |
601 * | |
602 * @param viewer the viewer | |
603 * @param widgetLine the widget line | |
604 * @return the corresponding line of the viewer's document | |
605 * @since 2.1 | |
606 */ | |
607 protected final static int widgetLine2ModelLine(ITextViewer viewer, int widgetLine) { | |
608 | |
609 if (viewer instanceof ITextViewerExtension5) { | |
134 | 610 ITextViewerExtension5 extension= cast(ITextViewerExtension5) viewer; |
129 | 611 return extension.widgetLine2ModelLine(widgetLine); |
612 } | |
613 | |
614 try { | |
615 IRegion r= viewer.getVisibleRegion(); | |
616 IDocument d= viewer.getDocument(); | |
617 return widgetLine += d.getLineOfOffset(r.getOffset()); | |
618 } catch (BadLocationException x) { | |
619 } | |
620 return widgetLine; | |
621 } | |
622 | |
623 /* | |
624 * @see IVerticalRulerExtension#setFont(Font) | |
625 * @since 2.0 | |
626 */ | |
627 public void setFont(Font font) { | |
628 } | |
629 | |
630 /* | |
631 * @see IVerticalRulerExtension#setLocationOfLastMouseButtonActivity(int, int) | |
632 * @since 2.0 | |
633 */ | |
634 public void setLocationOfLastMouseButtonActivity(int x, int y) { | |
635 fLastMouseButtonActivityLine= toDocumentLineNumber(y); | |
636 } | |
637 | |
638 /** | |
639 * Adds the given mouse listener. | |
640 * | |
641 * @param listener the listener to be added | |
642 * @deprecated will be removed | |
643 * @since 2.0 | |
644 */ | |
645 public void addMouseListener(MouseListener listener) { | |
646 if (fCanvas !is null && !fCanvas.isDisposed()) | |
647 fCanvas.addMouseListener(listener); | |
648 } | |
649 | |
650 /** | |
651 * Removes the given mouse listener. | |
652 * | |
653 * @param listener the listener to be removed | |
654 * @deprecated will be removed | |
655 * @since 2.0 | |
656 */ | |
657 public void removeMouseListener(MouseListener listener) { | |
658 if (fCanvas !is null && !fCanvas.isDisposed()) | |
659 fCanvas.removeMouseListener(listener); | |
660 } | |
661 } |