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.AnnotationBarHoverManager;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import java.util.Iterator;
|
|
18
|
|
19 import dwt.DWT;
|
|
20 import dwt.custom.StyledText;
|
|
21 import dwt.events.ControlEvent;
|
|
22 import dwt.events.ControlListener;
|
|
23 import dwt.events.DisposeEvent;
|
|
24 import dwt.events.DisposeListener;
|
|
25 import dwt.events.KeyEvent;
|
|
26 import dwt.events.KeyListener;
|
|
27 import dwt.events.MouseEvent;
|
|
28 import dwt.events.MouseListener;
|
|
29 import dwt.events.MouseMoveListener;
|
|
30 import dwt.events.MouseTrackAdapter;
|
|
31 import dwt.events.ShellEvent;
|
|
32 import dwt.events.ShellListener;
|
|
33 import dwt.graphics.Point;
|
|
34 import dwt.graphics.Rectangle;
|
|
35 import dwt.widgets.Control;
|
|
36 import dwt.widgets.Display;
|
|
37 import dwt.widgets.Event;
|
|
38 import dwt.widgets.Listener;
|
|
39 import dwtx.core.runtime.Assert;
|
|
40 import dwtx.jface.internal.text.InformationControlReplacer;
|
|
41 import dwtx.jface.internal.text.InternalAccessor;
|
|
42 import dwtx.jface.text.AbstractHoverInformationControlManager;
|
|
43 import dwtx.jface.text.AbstractInformationControlManager;
|
|
44 import dwtx.jface.text.BadLocationException;
|
|
45 import dwtx.jface.text.IDocument;
|
|
46 import dwtx.jface.text.IInformationControl;
|
|
47 import dwtx.jface.text.IInformationControlCreator;
|
|
48 import dwtx.jface.text.IRegion;
|
|
49 import dwtx.jface.text.ITextViewerExtension5;
|
|
50 import dwtx.jface.text.JFaceTextUtil;
|
|
51 import dwtx.jface.text.Region;
|
|
52 import dwtx.jface.text.TextUtilities;
|
|
53 import dwtx.jface.text.ITextViewerExtension8.EnrichMode;
|
|
54
|
|
55
|
|
56 /**
|
|
57 * This manager controls the layout, content, and visibility of an information
|
|
58 * control in reaction to mouse hover events issued by the vertical ruler of a
|
|
59 * source viewer.
|
|
60 * @since 2.0
|
|
61 */
|
|
62 public class AnnotationBarHoverManager : AbstractHoverInformationControlManager {
|
|
63
|
|
64 /**
|
|
65 * The information control closer for the hover information. Closes the information control as soon as the mouse pointer leaves the subject area, a mouse button is pressed, the user presses a key, or the subject control is resized or moved.
|
|
66 *
|
|
67 * @since 3.0
|
|
68 * @deprecated As of 3.4, no longer used as closer from super class is used
|
|
69 */
|
|
70 protected class Closer : MouseTrackAdapter , IInformationControlCloser, MouseListener, MouseMoveListener, ControlListener, KeyListener, DisposeListener, ShellListener, Listener {
|
|
71
|
|
72 /** The closer's subject control */
|
|
73 private Control fSubjectControl;
|
|
74 /** The subject area */
|
|
75 private Rectangle fSubjectArea;
|
|
76 /** Indicates whether this closer is active */
|
|
77 private bool fIsActive= false;
|
|
78 /** The information control. */
|
|
79 private IInformationControl fInformationControlToClose;
|
|
80 /**
|
|
81 * <code>true</code> if a wheel handler is installed.
|
|
82 * @since 3.2
|
|
83 */
|
|
84 private bool fHasWheelFilter= false;
|
|
85 /**
|
|
86 * The cached display.
|
|
87 * @since 3.2
|
|
88 */
|
|
89 private Display fDisplay;
|
|
90
|
|
91
|
|
92 /**
|
|
93 * Creates a new information control closer.
|
|
94 */
|
|
95 public Closer() {
|
|
96 }
|
|
97
|
|
98 /*
|
|
99 * @see IInformationControlCloser#setSubjectControl(Control)
|
|
100 */
|
|
101 public void setSubjectControl(Control control) {
|
|
102 fSubjectControl= control;
|
|
103 }
|
|
104
|
|
105 /*
|
|
106 * @see IInformationControlCloser#setHoverControl(IHoverControl)
|
|
107 */
|
|
108 public void setInformationControl(IInformationControl control) {
|
|
109 fInformationControlToClose= control;
|
|
110 }
|
|
111
|
|
112 /*
|
|
113 * @see IInformationControlCloser#start(Rectangle)
|
|
114 */
|
|
115 public void start(Rectangle subjectArea) {
|
|
116
|
|
117 if (fIsActive) return;
|
|
118 fIsActive= true;
|
|
119
|
|
120 fSubjectArea= subjectArea;
|
|
121
|
|
122 fInformationControlToClose.addDisposeListener(this);
|
|
123 if (fSubjectControl !is null && !fSubjectControl.isDisposed()) {
|
|
124 fSubjectControl.addMouseListener(this);
|
|
125 fSubjectControl.addMouseMoveListener(this);
|
|
126 fSubjectControl.addMouseTrackListener(this);
|
|
127 fSubjectControl.getShell().addShellListener(this);
|
|
128 fSubjectControl.addControlListener(this);
|
|
129 fSubjectControl.addKeyListener(this);
|
|
130
|
|
131 fDisplay= fSubjectControl.getDisplay();
|
|
132 if (!fDisplay.isDisposed() && fHideOnMouseWheel) {
|
|
133 fHasWheelFilter= true;
|
|
134 fDisplay.addFilter(DWT.MouseWheel, this);
|
|
135 }
|
|
136 }
|
|
137 }
|
|
138
|
|
139 /*
|
|
140 * @see IInformationControlCloser#stop()
|
|
141 */
|
|
142 public void stop() {
|
|
143
|
|
144 if (!fIsActive)
|
|
145 return;
|
|
146 fIsActive= false;
|
|
147
|
|
148 if (fSubjectControl !is null && !fSubjectControl.isDisposed()) {
|
|
149 fSubjectControl.removeMouseListener(this);
|
|
150 fSubjectControl.removeMouseMoveListener(this);
|
|
151 fSubjectControl.removeMouseTrackListener(this);
|
|
152 fSubjectControl.getShell().removeShellListener(this);
|
|
153 fSubjectControl.removeControlListener(this);
|
|
154 fSubjectControl.removeKeyListener(this);
|
|
155 }
|
|
156
|
|
157 if (fDisplay !is null && !fDisplay.isDisposed() && fHasWheelFilter)
|
|
158 fDisplay.removeFilter(DWT.MouseWheel, this);
|
|
159 fHasWheelFilter= false;
|
|
160
|
|
161 fDisplay= null;
|
|
162
|
|
163 }
|
|
164
|
|
165 /**
|
|
166 * Stops the information control and if <code>delayRestart</code> is set allows restart only after a certain delay.
|
|
167 *
|
|
168 * @param delayRestart <code>true</code> if restart should be delayed
|
|
169 * @deprecated As of 3.4, replaced by {@link #stop()}. Note that <code>delayRestart</code> was never honored.
|
|
170 */
|
|
171 protected void stop(bool delayRestart) {
|
|
172 stop();
|
|
173 }
|
|
174
|
|
175 /*
|
|
176 * @see dwt.events.MouseMoveListener#mouseMove(dwt.events.MouseEvent)
|
|
177 */
|
|
178 public void mouseMove(MouseEvent event) {
|
|
179 if (!fSubjectArea.contains(event.x, event.y))
|
|
180 hideInformationControl();
|
|
181 }
|
|
182
|
|
183 /*
|
|
184 * @see dwt.events.MouseListener#mouseUp(dwt.events.MouseEvent)
|
|
185 */
|
|
186 public void mouseUp(MouseEvent event) {
|
|
187 }
|
|
188
|
|
189 /*
|
|
190 * @see MouseListener#mouseDown(MouseEvent)
|
|
191 */
|
|
192 public void mouseDown(MouseEvent event) {
|
|
193 hideInformationControl();
|
|
194 }
|
|
195
|
|
196 /*
|
|
197 * @see MouseListener#mouseDoubleClick(MouseEvent)
|
|
198 */
|
|
199 public void mouseDoubleClick(MouseEvent event) {
|
|
200 hideInformationControl();
|
|
201 }
|
|
202
|
|
203 /*
|
|
204 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event)
|
|
205 * @since 3.2
|
|
206 */
|
|
207 public void handleEvent(Event event) {
|
|
208 if (event.type is DWT.MouseWheel)
|
|
209 hideInformationControl();
|
|
210 }
|
|
211
|
|
212 /*
|
|
213 * @see MouseTrackAdapter#mouseExit(MouseEvent)
|
|
214 */
|
|
215 public void mouseExit(MouseEvent event) {
|
|
216 if (!fAllowMouseExit)
|
|
217 hideInformationControl();
|
|
218 }
|
|
219
|
|
220 /*
|
|
221 * @see ControlListener#controlResized(ControlEvent)
|
|
222 */
|
|
223 public void controlResized(ControlEvent event) {
|
|
224 hideInformationControl();
|
|
225 }
|
|
226
|
|
227 /*
|
|
228 * @see ControlListener#controlMoved(ControlEvent)
|
|
229 */
|
|
230 public void controlMoved(ControlEvent event) {
|
|
231 hideInformationControl();
|
|
232 }
|
|
233
|
|
234 /*
|
|
235 * @see KeyListener#keyReleased(KeyEvent)
|
|
236 */
|
|
237 public void keyReleased(KeyEvent event) {
|
|
238 }
|
|
239
|
|
240 /*
|
|
241 * @see KeyListener#keyPressed(KeyEvent)
|
|
242 */
|
|
243 public void keyPressed(KeyEvent event) {
|
|
244 hideInformationControl();
|
|
245 }
|
|
246
|
|
247 /*
|
|
248 * @see dwt.events.ShellListener#shellActivated(dwt.events.ShellEvent)
|
|
249 * @since 3.1
|
|
250 */
|
|
251 public void shellActivated(ShellEvent e) {
|
|
252 }
|
|
253
|
|
254 /*
|
|
255 * @see dwt.events.ShellListener#shellClosed(dwt.events.ShellEvent)
|
|
256 * @since 3.1
|
|
257 */
|
|
258 public void shellClosed(ShellEvent e) {
|
|
259 }
|
|
260
|
|
261 /*
|
|
262 * @see dwt.events.ShellListener#shellDeactivated(dwt.events.ShellEvent)
|
|
263 * @since 3.1
|
|
264 */
|
|
265 public void shellDeactivated(ShellEvent e) {
|
|
266 hideInformationControl();
|
|
267 }
|
|
268
|
|
269 /*
|
|
270 * @see dwt.events.ShellListener#shellDeiconified(dwt.events.ShellEvent)
|
|
271 * @since 3.1
|
|
272 */
|
|
273 public void shellDeiconified(ShellEvent e) {
|
|
274 }
|
|
275
|
|
276 /*
|
|
277 * @see dwt.events.ShellListener#shellIconified(dwt.events.ShellEvent)
|
|
278 * @since 3.1
|
|
279 */
|
|
280 public void shellIconified(ShellEvent e) {
|
|
281 }
|
|
282
|
|
283 /*
|
|
284 * @see dwt.events.DisposeListener#widgetDisposed(dwt.events.DisposeEvent)
|
|
285 */
|
|
286 public void widgetDisposed(DisposeEvent e) {
|
|
287 hideInformationControl();
|
|
288 }
|
|
289 }
|
|
290
|
|
291 /** The source viewer the manager is connected to */
|
|
292 private ISourceViewer fSourceViewer;
|
|
293 /** The vertical ruler the manager is registered with */
|
|
294 private IVerticalRulerInfo fVerticalRulerInfo;
|
|
295 /** The annotation hover the manager uses to retrieve the information to display. Can be <code>null</code>. */
|
|
296 private IAnnotationHover fAnnotationHover;
|
|
297 /**
|
|
298 * Indicates whether the mouse cursor is allowed to leave the subject area without closing the hover.
|
|
299 * @since 3.0
|
|
300 */
|
|
301 protected bool fAllowMouseExit= false;
|
|
302 /**
|
|
303 * Whether we should hide the over on mouse wheel action.
|
|
304 *
|
|
305 * @since 3.2
|
|
306 */
|
|
307 private bool fHideOnMouseWheel= true;
|
|
308
|
|
309 /**
|
|
310 * The current annotation hover.
|
|
311 * @since 3.2
|
|
312 */
|
|
313 private IAnnotationHover fCurrentHover;
|
|
314
|
|
315 /**
|
|
316 * Creates an annotation hover manager with the given parameters. In addition,
|
|
317 * the hovers anchor is RIGHT and the margin is 5 points to the right.
|
|
318 *
|
|
319 * @param sourceViewer the source viewer this manager connects to
|
|
320 * @param ruler the vertical ruler this manager connects to
|
|
321 * @param annotationHover the annotation hover providing the information to be displayed
|
|
322 * @param creator the information control creator
|
|
323 * @deprecated As of 2.1, replaced by {@link AnnotationBarHoverManager#AnnotationBarHoverManager(IVerticalRulerInfo, ISourceViewer, IAnnotationHover, IInformationControlCreator)}
|
|
324 */
|
|
325 public AnnotationBarHoverManager(ISourceViewer sourceViewer, IVerticalRuler ruler, IAnnotationHover annotationHover, IInformationControlCreator creator) {
|
|
326 this(ruler, sourceViewer, annotationHover, creator);
|
|
327 }
|
|
328
|
|
329 /**
|
|
330 * Creates an annotation hover manager with the given parameters. In addition,
|
|
331 * the hovers anchor is RIGHT and the margin is 5 points to the right.
|
|
332 *
|
|
333 * @param rulerInfo the vertical ruler this manager connects to
|
|
334 * @param sourceViewer the source viewer this manager connects to
|
|
335 * @param annotationHover the annotation hover providing the information to be displayed or <code>null</code> if none
|
|
336 * @param creator the information control creator
|
|
337 * @since 2.1
|
|
338 */
|
|
339 public AnnotationBarHoverManager(IVerticalRulerInfo rulerInfo, ISourceViewer sourceViewer, IAnnotationHover annotationHover, IInformationControlCreator creator) {
|
|
340 super(creator);
|
|
341
|
|
342 Assert.isNotNull(sourceViewer);
|
|
343
|
|
344 fSourceViewer= sourceViewer;
|
|
345 fVerticalRulerInfo= rulerInfo;
|
|
346 fAnnotationHover= annotationHover;
|
|
347
|
|
348 setAnchor(ANCHOR_RIGHT);
|
|
349 setMargins(5, 0);
|
|
350 // use closer from super class
|
|
351 }
|
|
352
|
|
353 /*
|
|
354 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformation()
|
|
355 */
|
|
356 protected void computeInformation() {
|
|
357 fAllowMouseExit= false;
|
|
358 MouseEvent event= getHoverEvent();
|
|
359 IAnnotationHover hover= getHover(event);
|
|
360 if (hover is null) {
|
|
361 setInformation(null, null);
|
|
362 return;
|
|
363 }
|
|
364
|
|
365 int line= getHoverLine(event);
|
|
366
|
|
367 if (hover instanceof IAnnotationHoverExtension) {
|
|
368 IAnnotationHoverExtension extension= (IAnnotationHoverExtension) hover;
|
|
369 ILineRange range= extension.getHoverLineRange(fSourceViewer, line);
|
|
370 setCustomInformationControlCreator(extension.getHoverControlCreator());
|
|
371 range= adaptLineRange(range, line);
|
|
372 if (range !is null)
|
|
373 setInformation(extension.getHoverInfo(fSourceViewer, range, computeNumberOfVisibleLines()), computeArea(range));
|
|
374 else
|
|
375 setInformation(null, null);
|
|
376
|
|
377 } else {
|
|
378 setCustomInformationControlCreator(null);
|
|
379 setInformation(hover.getHoverInfo(fSourceViewer, line), computeArea(line));
|
|
380 }
|
|
381
|
|
382 }
|
|
383
|
|
384 /*
|
|
385 * @see dwtx.jface.text.AbstractInformationControlManager#showInformationControl(dwt.graphics.Rectangle)
|
|
386 * @since 3.2
|
|
387 */
|
|
388 protected void showInformationControl(Rectangle subjectArea) {
|
|
389 super.showInformationControl(subjectArea);
|
|
390 fCurrentHover= getHover(getHoverEvent());
|
|
391 }
|
|
392
|
|
393 /*
|
|
394 * @see dwtx.jface.text.AbstractInformationControlManager#hideInformationControl()
|
|
395 * @since 3.2
|
|
396 */
|
|
397 protected void hideInformationControl() {
|
|
398 fCurrentHover= null;
|
|
399 super.hideInformationControl();
|
|
400 }
|
|
401
|
|
402 /**
|
|
403 * Adapts a given line range so that the result is a line range that does
|
|
404 * not overlap with any collapsed region and fits into the view port of the
|
|
405 * attached viewer.
|
|
406 *
|
|
407 * @param lineRange the original line range
|
|
408 * @param line the anchor line
|
|
409 * @return the adapted line range
|
|
410 * @since 3.0
|
|
411 */
|
|
412 private ILineRange adaptLineRange(ILineRange lineRange, int line) {
|
|
413 if (lineRange !is null) {
|
|
414 lineRange= adaptLineRangeToFolding(lineRange, line);
|
|
415 if (lineRange !is null)
|
|
416 return adaptLineRangeToViewport(lineRange);
|
|
417 }
|
|
418 return null;
|
|
419 }
|
|
420
|
|
421 /**
|
|
422 * Adapts a given line range so that the result is a line range that does
|
|
423 * not overlap with any collapsed region of the attached viewer.
|
|
424 *
|
|
425 * @param lineRange the original line range
|
|
426 * @param line the anchor line
|
|
427 * @return the adapted line range
|
|
428 * @since 3.0
|
|
429 */
|
|
430 private ILineRange adaptLineRangeToFolding(ILineRange lineRange, int line) {
|
|
431
|
|
432 if (fSourceViewer instanceof ITextViewerExtension5) {
|
|
433 ITextViewerExtension5 extension= (ITextViewerExtension5) fSourceViewer;
|
|
434
|
|
435 try {
|
|
436 IRegion region= convertToRegion(lineRange);
|
|
437 IRegion[] coverage= extension.getCoveredModelRanges(region);
|
|
438 if (coverage !is null && coverage.length > 0) {
|
|
439 IRegion container= findRegionContainingLine(coverage, line);
|
|
440 if (container !is null)
|
|
441 return convertToLineRange(container);
|
|
442 }
|
|
443
|
|
444 } catch (BadLocationException x) {
|
|
445 }
|
|
446
|
|
447 return null;
|
|
448 }
|
|
449
|
|
450 return lineRange;
|
|
451 }
|
|
452
|
|
453 /**
|
|
454 * Adapts a given line range so that the result is a line range that fits
|
|
455 * into the view port of the attached viewer.
|
|
456 *
|
|
457 * @param lineRange the original line range
|
|
458 * @return the adapted line range
|
|
459 * @since 3.0
|
|
460 */
|
|
461 private ILineRange adaptLineRangeToViewport(ILineRange lineRange) {
|
|
462
|
|
463 try {
|
|
464 StyledText text= fSourceViewer.getTextWidget();
|
|
465
|
|
466 int topLine= text.getTopIndex();
|
|
467 int rangeTopLine= getWidgetLineNumber(lineRange.getStartLine());
|
|
468 int topDelta= Math.max(topLine - rangeTopLine, 0);
|
|
469
|
|
470 Rectangle size= text.getClientArea();
|
|
471 Rectangle trim= text.computeTrim(0, 0, 0, 0);
|
|
472 int height= size.height - trim.height;
|
|
473
|
|
474 int lines= JFaceTextUtil.getLineIndex(text, height) - text.getTopIndex();
|
|
475
|
|
476 int bottomLine= topLine + lines;
|
|
477
|
|
478 int rangeBottomLine= getWidgetLineNumber(lineRange.getStartLine() + lineRange.getNumberOfLines() - 1);
|
|
479 int bottomDelta= Math.max(rangeBottomLine - bottomLine, 0);
|
|
480
|
|
481 return new LineRange(lineRange.getStartLine() + topDelta, lineRange.getNumberOfLines() - bottomDelta - topDelta);
|
|
482
|
|
483 } catch (BadLocationException ex) {
|
|
484 }
|
|
485
|
|
486 return null;
|
|
487 }
|
|
488
|
|
489 /**
|
|
490 * Converts a line range into a character range.
|
|
491 *
|
|
492 * @param lineRange the line range
|
|
493 * @return the corresponding character range
|
|
494 * @throws BadLocationException in case the given line range is invalid
|
|
495 */
|
|
496 private IRegion convertToRegion(ILineRange lineRange) throws BadLocationException {
|
|
497 IDocument document= fSourceViewer.getDocument();
|
|
498 int startOffset= document.getLineOffset(lineRange.getStartLine());
|
|
499 int endLine= lineRange.getStartLine() + Math.max(0, lineRange.getNumberOfLines() - 1);
|
|
500 IRegion lineInfo= document.getLineInformation(endLine);
|
|
501 int endOffset= lineInfo.getOffset() + lineInfo.getLength();
|
|
502 return new Region(startOffset, endOffset - startOffset);
|
|
503 }
|
|
504
|
|
505 /**
|
|
506 * Returns the region out of the given set that contains the given line or
|
|
507 * <code>null</code>.
|
|
508 *
|
|
509 * @param regions the set of regions
|
|
510 * @param line the line
|
|
511 * @return the region of the set that contains the line
|
|
512 * @throws BadLocationException in case line is invalid
|
|
513 */
|
|
514 private IRegion findRegionContainingLine(IRegion[] regions, int line) throws BadLocationException {
|
|
515 IDocument document= fSourceViewer.getDocument();
|
|
516 IRegion lineInfo= document.getLineInformation(line);
|
|
517 for (int i= 0; i < regions.length; i++) {
|
|
518 if (TextUtilities.overlaps(regions[i], lineInfo))
|
|
519 return regions[i];
|
|
520 }
|
|
521 return null;
|
|
522 }
|
|
523
|
|
524 /**
|
|
525 * Converts a given character region into a line range.
|
|
526 *
|
|
527 * @param region the character region
|
|
528 * @return the corresponding line range
|
|
529 * @throws BadLocationException in case the given region in invalid
|
|
530 */
|
|
531 private ILineRange convertToLineRange(IRegion region) throws BadLocationException {
|
|
532 IDocument document= fSourceViewer.getDocument();
|
|
533 int startLine= document.getLineOfOffset(region.getOffset());
|
|
534 int endLine= document.getLineOfOffset(region.getOffset() + region.getLength());
|
|
535 return new LineRange(startLine, endLine - startLine + 1);
|
|
536 }
|
|
537
|
|
538 /**
|
|
539 * Returns the visible area of the vertical ruler covered by the given line
|
|
540 * range.
|
|
541 *
|
|
542 * @param lineRange the line range
|
|
543 * @return the visible area
|
|
544 */
|
|
545 private Rectangle computeArea(ILineRange lineRange) {
|
|
546 try {
|
|
547 StyledText text= fSourceViewer.getTextWidget();
|
|
548 final int startLine= getWidgetLineNumber(lineRange.getStartLine());
|
|
549 int y= JFaceTextUtil.computeLineHeight(text, 0, startLine, startLine) - text.getTopPixel();
|
|
550 int height= JFaceTextUtil.computeLineHeight(text, startLine, startLine + lineRange.getNumberOfLines(), lineRange.getNumberOfLines());
|
|
551 Point size= fVerticalRulerInfo.getControl().getSize();
|
|
552 return new Rectangle(0, y, size.x, height);
|
|
553 } catch (BadLocationException x) {
|
|
554 }
|
|
555 return null;
|
|
556 }
|
|
557
|
|
558 /**
|
|
559 * Returns the number of the currently visible lines.
|
|
560 *
|
|
561 * @return the number of the currently visible lines
|
|
562 * @deprecated to avoid deprecation warning
|
|
563 */
|
|
564 private int computeNumberOfVisibleLines() {
|
|
565 // Hack to reduce amount of copied code.
|
|
566 return LineNumberRulerColumn.getVisibleLinesInViewport(fSourceViewer.getTextWidget());
|
|
567 }
|
|
568
|
|
569 /**
|
|
570 * Determines the hover to be used to display information based on the source of the
|
|
571 * mouse hover event. If <code>fVerticalRulerInfo</code> is not a composite ruler, the
|
|
572 * standard hover is returned.
|
|
573 *
|
|
574 * @param event the source of the mouse hover event
|
|
575 * @return the hover depending on <code>source</code>, or <code>fAnnotationHover</code> if none can be found.
|
|
576 * @since 3.0
|
|
577 */
|
|
578 private IAnnotationHover getHover(MouseEvent event) {
|
|
579 if (event is null || event.getSource() is null)
|
|
580 return fAnnotationHover;
|
|
581
|
|
582 if (fVerticalRulerInfo instanceof CompositeRuler) {
|
|
583 CompositeRuler comp= (CompositeRuler) fVerticalRulerInfo;
|
|
584 for (Iterator it= comp.getDecoratorIterator(); it.hasNext();) {
|
|
585 Object o= it.next();
|
|
586 if (o instanceof IVerticalRulerInfoExtension && o instanceof IVerticalRulerInfo) {
|
|
587 if (((IVerticalRulerInfo) o).getControl() is event.getSource()) {
|
|
588 IAnnotationHover hover= ((IVerticalRulerInfoExtension) o).getHover();
|
|
589 if (hover !is null)
|
|
590 return hover;
|
|
591 }
|
|
592 }
|
|
593 }
|
|
594 }
|
|
595 return fAnnotationHover;
|
|
596 }
|
|
597
|
|
598 /**
|
|
599 * Returns the line of interest deduced from the mouse hover event.
|
|
600 *
|
|
601 * @param event a mouse hover event that triggered hovering
|
|
602 * @return the document model line number on which the hover event occurred or <code>-1</code> if there is no event
|
|
603 * @since 3.0
|
|
604 */
|
|
605 private int getHoverLine(MouseEvent event) {
|
|
606 return event is null ? -1 : fVerticalRulerInfo.toDocumentLineNumber(event.y);
|
|
607 }
|
|
608
|
|
609 /**
|
|
610 * Returns for the widget line number for the given document line number.
|
|
611 *
|
|
612 * @param line the absolute line number
|
|
613 * @return the line number relative to the viewer's visible region
|
|
614 * @throws BadLocationException if <code>line</code> is not valid in the viewer's document
|
|
615 */
|
|
616 private int getWidgetLineNumber(int line) throws BadLocationException {
|
|
617 if (fSourceViewer instanceof ITextViewerExtension5) {
|
|
618 ITextViewerExtension5 extension= (ITextViewerExtension5) fSourceViewer;
|
|
619 return extension.modelLine2WidgetLine(line);
|
|
620 }
|
|
621
|
|
622 IRegion region= fSourceViewer.getVisibleRegion();
|
|
623 int firstLine= fSourceViewer.getDocument().getLineOfOffset(region.getOffset());
|
|
624 return line - firstLine;
|
|
625 }
|
|
626
|
|
627 /**
|
|
628 * Determines graphical area covered by the given line.
|
|
629 *
|
|
630 * @param line the number of the line in the viewer whose graphical extend in the vertical ruler must be computed
|
|
631 * @return the graphical extend of the given line
|
|
632 */
|
|
633 private Rectangle computeArea(int line) {
|
|
634 try {
|
|
635 StyledText text= fSourceViewer.getTextWidget();
|
|
636 int widgetLine= getWidgetLineNumber(line);
|
|
637 int y= JFaceTextUtil.computeLineHeight(text, 0, widgetLine, widgetLine) - text.getTopPixel();
|
|
638 Point size= fVerticalRulerInfo.getControl().getSize();
|
|
639 return new Rectangle(0, y, size.x, text.getLineHeight(text.getOffsetAtLine(widgetLine)));
|
|
640 } catch (IllegalArgumentException ex) {
|
|
641 } catch (BadLocationException ex) {
|
|
642 }
|
|
643 return null;
|
|
644 }
|
|
645
|
|
646 /**
|
|
647 * Returns the annotation hover for this hover manager.
|
|
648 *
|
|
649 * @return the annotation hover for this hover manager or <code>null</code> if none
|
|
650 * @since 2.1
|
|
651 */
|
|
652 protected IAnnotationHover getAnnotationHover() {
|
|
653 return fAnnotationHover;
|
|
654 }
|
|
655
|
|
656 /**
|
|
657 * Returns the source viewer for this hover manager.
|
|
658 *
|
|
659 * @return the source viewer for this hover manager
|
|
660 * @since 2.1
|
|
661 */
|
|
662 protected ISourceViewer getSourceViewer() {
|
|
663 return fSourceViewer;
|
|
664 }
|
|
665
|
|
666 /**
|
|
667 * Returns the vertical ruler info for this hover manager
|
|
668 *
|
|
669 * @return the vertical ruler info for this hover manager
|
|
670 * @since 2.1
|
|
671 */
|
|
672 protected IVerticalRulerInfo getVerticalRulerInfo() {
|
|
673 return fVerticalRulerInfo;
|
|
674 }
|
|
675
|
|
676 /*
|
|
677 * @see dwtx.jface.text.AbstractInformationControlManager#computeSizeConstraints(dwt.widgets.Control, dwt.graphics.Rectangle, dwtx.jface.text.IInformationControl)
|
|
678 * @since 3.0
|
|
679 */
|
|
680 protected Point computeSizeConstraints(Control subjectControl, Rectangle subjectArea, IInformationControl informationControl) {
|
|
681
|
|
682 Point constraints= super.computeSizeConstraints(subjectControl, subjectArea, informationControl);
|
|
683
|
|
684 // make as big as text area, if possible
|
|
685 StyledText styledText= fSourceViewer.getTextWidget();
|
|
686 if (styledText !is null) {
|
|
687 Rectangle r= styledText.getClientArea();
|
|
688 if (r !is null) {
|
|
689 constraints.x= r.width;
|
|
690 constraints.y= r.height;
|
|
691 }
|
|
692 }
|
|
693
|
|
694 return constraints;
|
|
695 }
|
|
696
|
|
697 /*
|
|
698 * @see dwtx.jface.text.AbstractInformationControlManager#computeLocation(dwt.graphics.Rectangle, dwt.graphics.Point, dwtx.jface.text.AbstractInformationControlManager.Anchor)
|
|
699 * @since 3.0
|
|
700 */
|
|
701 protected Point computeLocation(Rectangle subjectArea, Point controlSize, Anchor anchor) {
|
|
702 MouseEvent event= getHoverEvent();
|
|
703 IAnnotationHover hover= getHover(event);
|
|
704
|
|
705 bool allowMouseExit= false;
|
|
706 if (hover instanceof IAnnotationHoverExtension) {
|
|
707 IAnnotationHoverExtension extension= (IAnnotationHoverExtension) hover;
|
|
708 allowMouseExit= extension.canHandleMouseCursor();
|
|
709 }
|
|
710 bool hideOnMouseWheel= true;
|
|
711 if (hover instanceof IAnnotationHoverExtension2) {
|
|
712 IAnnotationHoverExtension2 extension= (IAnnotationHoverExtension2) hover;
|
|
713 hideOnMouseWheel= !extension.canHandleMouseWheel();
|
|
714 }
|
|
715 fHideOnMouseWheel= hideOnMouseWheel;
|
|
716
|
|
717 if (allowMouseExit) {
|
|
718 fAllowMouseExit= true;
|
|
719
|
|
720 Control subjectControl= getSubjectControl();
|
|
721 // return a location that just overlaps the annotation on the bar
|
|
722 if (anchor is AbstractInformationControlManager.ANCHOR_RIGHT)
|
|
723 return subjectControl.toDisplay(subjectArea.x - 4, subjectArea.y - 2);
|
|
724 else if (anchor is AbstractInformationControlManager.ANCHOR_LEFT)
|
|
725 return subjectControl.toDisplay(subjectArea.x + subjectArea.width - controlSize.x + 4, subjectArea.y - 2);
|
|
726 }
|
|
727
|
|
728 fAllowMouseExit= false;
|
|
729 return super.computeLocation(subjectArea, controlSize, anchor);
|
|
730 }
|
|
731
|
|
732 /**
|
|
733 * Returns the currently shown annotation hover or <code>null</code> if none
|
|
734 * hover is shown.
|
|
735 *
|
|
736 * @return the currently shown annotation hover or <code>null</code>
|
|
737 * @since 3.2
|
|
738 */
|
|
739 public IAnnotationHover getCurrentAnnotationHover() {
|
|
740 return fCurrentHover;
|
|
741 }
|
|
742
|
|
743 /**
|
|
744 * Returns an adapter that gives access to internal methods.
|
|
745 * <p>
|
|
746 * <strong>Note:</strong> This method is not intended to be referenced or overridden by clients.
|
|
747 * </p>
|
|
748 *
|
|
749 * @return the replaceable information control accessor
|
|
750 * @since 3.4
|
|
751 * @noreference This method is not intended to be referenced by clients.
|
|
752 * @nooverride This method is not intended to be re-implemented or extended by clients.
|
|
753 */
|
|
754 public InternalAccessor getInternalAccessor() {
|
|
755 return new InternalAccessor() {
|
|
756 public IInformationControl getCurrentInformationControl() {
|
|
757 return AnnotationBarHoverManager.super.getInternalAccessor().getCurrentInformationControl();
|
|
758 }
|
|
759
|
|
760 public void setInformationControlReplacer(InformationControlReplacer replacer) {
|
|
761 AnnotationBarHoverManager.super.getInternalAccessor().setInformationControlReplacer(replacer);
|
|
762 }
|
|
763
|
|
764 public InformationControlReplacer getInformationControlReplacer() {
|
|
765 return AnnotationBarHoverManager.super.getInternalAccessor().getInformationControlReplacer();
|
|
766 }
|
|
767
|
|
768 public bool canReplace(IInformationControl control) {
|
|
769 return AnnotationBarHoverManager.super.getInternalAccessor().canReplace(control);
|
|
770 }
|
|
771
|
|
772 public bool isReplaceInProgress() {
|
|
773 return AnnotationBarHoverManager.super.getInternalAccessor().isReplaceInProgress();
|
|
774 }
|
|
775
|
|
776 public void replaceInformationControl(bool takeFocus) {
|
|
777 AnnotationBarHoverManager.super.getInternalAccessor().replaceInformationControl(takeFocus);
|
|
778 }
|
|
779
|
|
780 public void cropToClosestMonitor(Rectangle bounds) {
|
|
781 AnnotationBarHoverManager.super.getInternalAccessor().cropToClosestMonitor(bounds);
|
|
782 }
|
|
783
|
|
784 public void setHoverEnrichMode(EnrichMode mode) {
|
|
785 AnnotationBarHoverManager.super.getInternalAccessor().setHoverEnrichMode(mode);
|
|
786 }
|
|
787
|
|
788 public bool getAllowMouseExit() {
|
|
789 return fAllowMouseExit;
|
|
790 }
|
|
791 };
|
|
792 }
|
|
793 }
|
|
794
|