Mercurial > projects > dwt-addons
comparison dwtx/jface/text/source/OverviewRulerHoverManager.d @ 129:eb30df5ca28b
Added JFace Text sources
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 23 Aug 2008 19:10:48 +0200 |
parents | |
children | c4fb132a086c |
comparison
equal
deleted
inserted
replaced
128:8df1d4193877 | 129:eb30df5ca28b |
---|---|
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.OverviewRulerHoverManager; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 | |
18 | |
19 import dwt.custom.StyledText; | |
20 import dwt.graphics.Point; | |
21 import dwt.graphics.Rectangle; | |
22 import dwt.widgets.ScrollBar; | |
23 import dwtx.jface.text.IInformationControlCreator; | |
24 | |
25 /** | |
26 * This manager controls the layout, content, and visibility of an information | |
27 * control in reaction to mouse hover events issued by the overview ruler of a | |
28 * source viewer. | |
29 * | |
30 * @since 2.1 | |
31 */ | |
32 class OverviewRulerHoverManager : AnnotationBarHoverManager { | |
33 | |
34 /** | |
35 * Creates an overview hover manager with the given parameters. In addition, | |
36 * the hovers anchor is RIGHT and the margin is 5 points to the right. | |
37 * | |
38 * @param ruler the overview ruler this manager connects to | |
39 * @param sourceViewer the source viewer this manager connects to | |
40 * @param annotationHover the annotation hover providing the information to be displayed | |
41 * @param creator the information control creator | |
42 */ | |
43 public OverviewRulerHoverManager(IOverviewRuler ruler, ISourceViewer sourceViewer, IAnnotationHover annotationHover, IInformationControlCreator creator) { | |
44 super(ruler, sourceViewer, annotationHover, creator); | |
45 setAnchor(ANCHOR_LEFT); | |
46 StyledText textWidget= sourceViewer.getTextWidget(); | |
47 if (textWidget !is null) { | |
48 ScrollBar verticalBar= textWidget.getVerticalBar(); | |
49 if (verticalBar !is null) | |
50 setMargins(verticalBar.getSize().x, 5); | |
51 } | |
52 } | |
53 | |
54 /* | |
55 * @see AbstractHoverInformationControlManager#computeInformation() | |
56 */ | |
57 protected void computeInformation() { | |
58 Point location= getHoverEventLocation(); | |
59 int line= getVerticalRulerInfo().toDocumentLineNumber(location.y); | |
60 IAnnotationHover hover= getAnnotationHover(); | |
61 | |
62 IInformationControlCreator controlCreator= null; | |
63 if (hover instanceof IAnnotationHoverExtension) | |
64 controlCreator= ((IAnnotationHoverExtension)hover).getHoverControlCreator(); | |
65 setCustomInformationControlCreator(controlCreator); | |
66 | |
67 setInformation(hover.getHoverInfo(getSourceViewer(), line), computeArea(location.y)); | |
68 } | |
69 | |
70 /** | |
71 * Determines graphical area covered for which the hover is valid. | |
72 * | |
73 * @param y y-coordinate in the vertical ruler | |
74 * @return the graphical extend where the hover is valid | |
75 */ | |
76 private Rectangle computeArea(int y) { | |
77 // This is OK (see constructor) | |
78 IOverviewRuler overviewRuler= (IOverviewRuler) getVerticalRulerInfo(); | |
79 | |
80 int hover_height= overviewRuler.getAnnotationHeight(); | |
81 int hover_width= getVerticalRulerInfo().getControl().getSize().x; | |
82 | |
83 // Calculate y-coordinate for hover | |
84 int hover_y= y; | |
85 bool hasAnnotation= true; | |
86 while (hasAnnotation && hover_y > y - hover_height) { | |
87 hover_y--; | |
88 hasAnnotation= overviewRuler.hasAnnotation(hover_y); | |
89 } | |
90 hover_y++; | |
91 | |
92 return new Rectangle(0, hover_y, hover_width, hover_height); | |
93 } | |
94 } |