Mercurial > projects > dwt-addons
comparison dwtx/jface/text/hyperlink/MultipleHyperlinkPresenter.d @ 140:26688fec6d23
Following dsss compile errors
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 03:23:46 +0200 |
parents | b6bad70d540a |
children | 75302ef3f92f |
comparison
equal
deleted
inserted
replaced
139:93a6ec48fd28 | 140:26688fec6d23 |
---|---|
77 import dwtx.jface.viewers.Viewer; | 77 import dwtx.jface.viewers.Viewer; |
78 | 78 |
79 | 79 |
80 /** | 80 /** |
81 * A hyperlink presenter capable of showing multiple hyperlinks in a hover. | 81 * A hyperlink presenter capable of showing multiple hyperlinks in a hover. |
82 * | 82 * |
83 * @since 3.4 | 83 * @since 3.4 |
84 */ | 84 */ |
85 public class MultipleHyperlinkPresenter : DefaultHyperlinkPresenter { | 85 public class MultipleHyperlinkPresenter : DefaultHyperlinkPresenter { |
86 | 86 |
87 /** | 87 /** |
88 * An information control capable of showing a list of hyperlinks. The hyperlinks can be opened. | 88 * An information control capable of showing a list of hyperlinks. The hyperlinks can be opened. |
89 */ | 89 */ |
90 private static class LinkListInformationControl : AbstractInformationControl , IInformationControlExtension2 { | 90 private static class LinkListInformationControl : AbstractInformationControl , IInformationControlExtension2 { |
91 | 91 |
92 private static final class LinkContentProvider : IStructuredContentProvider { | 92 private static final class LinkContentProvider : IStructuredContentProvider { |
93 | 93 |
94 /* | 94 /* |
95 * @see dwtx.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) | 95 * @see dwtx.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
96 */ | 96 */ |
97 public Object[] getElements(Object inputElement) { | 97 public Object[] getElements(Object inputElement) { |
98 return (Object[]) inputElement; | 98 return (Object[]) inputElement; |
99 } | 99 } |
100 | 100 |
101 /* | 101 /* |
102 * @see dwtx.jface.viewers.IContentProvider#dispose() | 102 * @see dwtx.jface.viewers.IContentProvider#dispose() |
103 */ | 103 */ |
104 public void dispose() { | 104 public void dispose() { |
105 } | 105 } |
106 | 106 |
107 /* | 107 /* |
108 * @see dwtx.jface.viewers.IContentProvider#inputChanged(dwtx.jface.viewers.Viewer, java.lang.Object, java.lang.Object) | 108 * @see dwtx.jface.viewers.IContentProvider#inputChanged(dwtx.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
109 */ | 109 */ |
110 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | 110 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 private static final class LinkLabelProvider : ColumnLabelProvider { | 114 private static final class LinkLabelProvider : ColumnLabelProvider { |
115 /* | 115 /* |
116 * @see dwtx.jface.viewers.ColumnLabelProvider#getText(java.lang.Object) | 116 * @see dwtx.jface.viewers.ColumnLabelProvider#getText(java.lang.Object) |
117 */ | 117 */ |
118 public String getText(Object element) { | 118 public String getText(Object element) { |
121 if (text !is null) | 121 if (text !is null) |
122 return text; | 122 return text; |
123 return HyperlinkMessages.getString("LinkListInformationControl.unknownLink"); //$NON-NLS-1$ | 123 return HyperlinkMessages.getString("LinkListInformationControl.unknownLink"); //$NON-NLS-1$ |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 private final MultipleHyperlinkHoverManager fManager; | 127 private final MultipleHyperlinkHoverManager fManager; |
128 | 128 |
129 private IHyperlink[] fInput; | 129 private IHyperlink[] fInput; |
130 private Composite fParent; | 130 private Composite fParent; |
131 private Table fTable; | 131 private Table fTable; |
132 | 132 |
133 private Color fForegroundColor; | 133 private Color fForegroundColor; |
134 private Color fBackgroundColor; | 134 private Color fBackgroundColor; |
135 | 135 |
136 | 136 |
137 /** | 137 /** |
138 * Creates a link list information control with the given shell as parent. | 138 * Creates a link list information control with the given shell as parent. |
139 * | 139 * |
140 * @param parentShell the parent shell | 140 * @param parentShell the parent shell |
141 * @param manager the hover manager | 141 * @param manager the hover manager |
147 fManager= manager; | 147 fManager= manager; |
148 fForegroundColor= foregroundColor; | 148 fForegroundColor= foregroundColor; |
149 fBackgroundColor= backgroundColor; | 149 fBackgroundColor= backgroundColor; |
150 create(); | 150 create(); |
151 } | 151 } |
152 | 152 |
153 /* | 153 /* |
154 * @see dwtx.jface.text.IInformationControl#setInformation(java.lang.String) | 154 * @see dwtx.jface.text.IInformationControl#setInformation(java.lang.String) |
155 */ | 155 */ |
156 public void setInformation(String information) { | 156 public void setInformation(String information) { |
157 //replaced by IInformationControlExtension2#setInput(java.lang.Object) | 157 //replaced by IInformationControlExtension2#setInput(java.lang.Object) |
158 } | 158 } |
159 | 159 |
160 /* | 160 /* |
161 * @see dwtx.jface.text.IInformationControlExtension2#setInput(java.lang.Object) | 161 * @see dwtx.jface.text.IInformationControlExtension2#setInput(java.lang.Object) |
162 */ | 162 */ |
163 public void setInput(Object input) { | 163 public void setInput(Object input) { |
164 fInput= (IHyperlink[]) input; | 164 fInput= (IHyperlink[]) input; |
165 deferredCreateContent(fParent); | 165 deferredCreateContent(fParent); |
166 } | 166 } |
167 | 167 |
168 /* | 168 /* |
169 * @see dwtx.jface.text.AbstractInformationControl#createContent(dwt.widgets.Composite) | 169 * @see dwtx.jface.text.AbstractInformationControl#createContent(dwt.widgets.Composite) |
170 */ | 170 */ |
171 protected void createContent(Composite parent) { | 171 protected void createContent(Composite parent) { |
172 fParent= parent; | 172 fParent= parent; |
177 fParent.setLayout(layout); | 177 fParent.setLayout(layout); |
178 } | 178 } |
179 fParent.setForeground(fForegroundColor); | 179 fParent.setForeground(fForegroundColor); |
180 fParent.setBackground(fBackgroundColor); | 180 fParent.setBackground(fBackgroundColor); |
181 } | 181 } |
182 | 182 |
183 /* | 183 /* |
184 * @see dwtx.jface.text.AbstractInformationControl#computeSizeHint() | 184 * @see dwtx.jface.text.AbstractInformationControl#computeSizeHint() |
185 */ | 185 */ |
186 public Point computeSizeHint() { | 186 public Point computeSizeHint() { |
187 Point preferedSize= getShell().computeSize(DWT.DEFAULT, DWT.DEFAULT, true); | 187 Point preferedSize= getShell().computeSize(DWT.DEFAULT, DWT.DEFAULT, true); |
188 | 188 |
189 Point constraints= getSizeConstraints(); | 189 Point constraints= getSizeConstraints(); |
190 if (constraints is null) | 190 if (constraints is null) |
191 return preferedSize; | 191 return preferedSize; |
192 | 192 |
193 if (fTable.getVerticalBar() is null || fTable.getHorizontalBar() is null) | 193 if (fTable.getVerticalBar() is null || fTable.getHorizontalBar() is null) |
194 return Geometry.min(constraints, preferedSize); | 194 return Geometry.min(constraints, preferedSize); |
195 | 195 |
196 int scrollBarWidth= fTable.getVerticalBar().getSize().x; | 196 int scrollBarWidth= fTable.getVerticalBar().getSize().x; |
197 int scrollBarHeight= fTable.getHorizontalBar().getSize().y; | 197 int scrollBarHeight= fTable.getHorizontalBar().getSize().y; |
198 | 198 |
199 int width; | 199 int width; |
200 if (preferedSize.y - scrollBarHeight <= constraints.y) { | 200 if (preferedSize.y - scrollBarHeight <= constraints.y) { |
201 width= preferedSize.x - scrollBarWidth; | 201 width= preferedSize.x - scrollBarWidth; |
202 fTable.getVerticalBar().setVisible(false); | 202 fTable.getVerticalBar().setVisible(false); |
203 } else { | 203 } else { |
204 width= Math.min(preferedSize.x, constraints.x); | 204 width= Math.min(preferedSize.x, constraints.x); |
205 } | 205 } |
206 | 206 |
207 int height; | 207 int height; |
208 if (preferedSize.x - scrollBarWidth <= constraints.x) { | 208 if (preferedSize.x - scrollBarWidth <= constraints.x) { |
209 height= preferedSize.y - scrollBarHeight; | 209 height= preferedSize.y - scrollBarHeight; |
210 fTable.getHorizontalBar().setVisible(false); | 210 fTable.getHorizontalBar().setVisible(false); |
211 } else { | 211 } else { |
212 height= Math.min(preferedSize.y, constraints.y); | 212 height= Math.min(preferedSize.y, constraints.y); |
213 } | 213 } |
214 | 214 |
215 return new Point(width, height); | 215 return new Point(width, height); |
216 } | 216 } |
217 | 217 |
218 private void deferredCreateContent(Composite parent) { | 218 private void deferredCreateContent(Composite parent) { |
219 fTable= new Table(parent, DWT.SINGLE | DWT.FULL_SELECTION); | 219 fTable= new Table(parent, DWT.SINGLE | DWT.FULL_SELECTION); |
220 fTable.setLinesVisible(false); | 220 fTable.setLinesVisible(false); |
221 fTable.setHeaderVisible(false); | 221 fTable.setHeaderVisible(false); |
222 fTable.setForeground(fForegroundColor); | 222 fTable.setForeground(fForegroundColor); |
223 fTable.setBackground(fBackgroundColor); | 223 fTable.setBackground(fBackgroundColor); |
224 | 224 |
225 final TableViewer viewer= new TableViewer(fTable); | 225 final TableViewer viewer= new TableViewer(fTable); |
226 viewer.setContentProvider(new LinkContentProvider()); | 226 viewer.setContentProvider(new LinkContentProvider()); |
227 viewer.setLabelProvider(new LinkLabelProvider()); | 227 viewer.setLabelProvider(new LinkLabelProvider()); |
228 viewer.setInput(fInput); | 228 viewer.setInput(fInput); |
229 fTable.setSelection(0); | 229 fTable.setSelection(0); |
230 | 230 |
231 registerTableListeners(); | 231 registerTableListeners(); |
232 | 232 |
233 getShell().addShellListener(new class() ShellAdapter { | 233 getShell().addShellListener(new class() ShellAdapter { |
234 | 234 |
235 /* | 235 /* |
236 * @see dwt.events.ShellAdapter#shellActivated(dwt.events.ShellEvent) | 236 * @see dwt.events.ShellAdapter#shellActivated(dwt.events.ShellEvent) |
237 */ | 237 */ |
238 public void shellActivated(ShellEvent e) { | 238 public void shellActivated(ShellEvent e) { |
239 if (viewer.getTable().getSelectionCount() is 0) { | 239 if (viewer.getTable().getSelectionCount() is 0) { |
240 viewer.getTable().setSelection(0); | 240 viewer.getTable().setSelection(0); |
241 } | 241 } |
242 | 242 |
243 viewer.getTable().setFocus(); | 243 viewer.getTable().setFocus(); |
244 } | 244 } |
245 }); | 245 }); |
246 } | 246 } |
247 | 247 |
248 private void registerTableListeners() { | 248 private void registerTableListeners() { |
249 | 249 |
250 fTable.addMouseMoveListener(new class() MouseMoveListener { | 250 fTable.addMouseMoveListener(new class() MouseMoveListener { |
251 TableItem fLastItem= null; | 251 TableItem fLastItem= null; |
252 | 252 |
253 public void mouseMove(MouseEvent e) { | 253 public void mouseMove(MouseEvent e) { |
254 if (fTable.equals(e.getSource())) { | 254 if (fTable.equals(e.getSource())) { |
255 Object o= fTable.getItem(new Point(e.x, e.y)); | 255 Object o= fTable.getItem(new Point(e.x, e.y)); |
256 if ( cast(TableItem)o ) { | 256 if ( cast(TableItem)o ) { |
257 TableItem item= cast(TableItem) o; | 257 TableItem item= cast(TableItem) o; |
258 if (!o.equals(fLastItem)) { | 258 if (!o.equals(fLastItem)) { |
259 fLastItem= cast(TableItem) o; | 259 fLastItem= cast(TableItem) o; |
260 fTable.setSelection(new TableItem[] { fLastItem }); | 260 fTable.setSelection([ fLastItem ]); |
261 } else if (e.y < fTable.getItemHeight() / 4) { | 261 } else if (e.y < fTable.getItemHeight() / 4) { |
262 // Scroll up | 262 // Scroll up |
263 int index= fTable.indexOf(item); | 263 int index= fTable.indexOf(item); |
264 if (index > 0) { | 264 if (index > 0) { |
265 fLastItem= fTable.getItem(index - 1); | 265 fLastItem= fTable.getItem(index - 1); |
266 fTable.setSelection(new TableItem[] { fLastItem }); | 266 fTable.setSelection([ fLastItem ]); |
267 } | 267 } |
268 } else if (e.y > fTable.getBounds().height - fTable.getItemHeight() / 4) { | 268 } else if (e.y > fTable.getBounds().height - fTable.getItemHeight() / 4) { |
269 // Scroll down | 269 // Scroll down |
270 int index= fTable.indexOf(item); | 270 int index= fTable.indexOf(item); |
271 if (index < fTable.getItemCount() - 1) { | 271 if (index < fTable.getItemCount() - 1) { |
272 fLastItem= fTable.getItem(index + 1); | 272 fLastItem= fTable.getItem(index + 1); |
273 fTable.setSelection(new TableItem[] { fLastItem }); | 273 fTable.setSelection([ fLastItem ]); |
274 } | 274 } |
275 } | 275 } |
276 } | 276 } |
277 } | 277 } |
278 } | 278 } |
279 }); | 279 }); |
280 | 280 |
281 fTable.addSelectionListener(new class() SelectionAdapter { | 281 fTable.addSelectionListener(new class() SelectionAdapter { |
282 public void widgetSelected(SelectionEvent e) { | 282 public void widgetSelected(SelectionEvent e) { |
283 openSelectedLink(); | 283 openSelectedLink(); |
284 } | 284 } |
285 }); | 285 }); |
286 | 286 |
287 fTable.addMouseListener(new class() MouseAdapter { | 287 fTable.addMouseListener(new class() MouseAdapter { |
288 public void mouseUp(MouseEvent e) { | 288 public void mouseUp(MouseEvent e) { |
289 if (fTable.getSelectionCount() < 1) | 289 if (fTable.getSelectionCount() < 1) |
290 return; | 290 return; |
291 | 291 |
292 if (e.button !is 1) | 292 if (e.button !is 1) |
293 return; | 293 return; |
294 | 294 |
295 if (fTable.equals(e.getSource())) { | 295 if (fTable.equals(e.getSource())) { |
296 Object o= fTable.getItem(new Point(e.x, e.y)); | 296 Object o= fTable.getItem(new Point(e.x, e.y)); |
297 TableItem selection= fTable.getSelection()[0]; | 297 TableItem selection= fTable.getSelection()[0]; |
298 if (selection.equals(o)) | 298 if (selection.equals(o)) |
299 openSelectedLink(); | 299 openSelectedLink(); |
300 } | 300 } |
301 } | 301 } |
302 }); | 302 }); |
303 | 303 |
304 fTable.addKeyListener(new class() KeyAdapter { | 304 fTable.addKeyListener(new class() KeyAdapter { |
305 public void keyPressed(KeyEvent e) { | 305 public void keyPressed(KeyEvent e) { |
306 if (e.keyCode is 0x0D) // return | 306 if (e.keyCode is 0x0D) // return |
307 openSelectedLink(); | 307 openSelectedLink(); |
308 } | 308 } |
309 }); | 309 }); |
310 } | 310 } |
311 | 311 |
312 /* | 312 /* |
313 * @see dwtx.jface.text.IInformationControlExtension#hasContents() | 313 * @see dwtx.jface.text.IInformationControlExtension#hasContents() |
314 */ | 314 */ |
315 public bool hasContents() { | 315 public bool hasContents() { |
316 return true; | 316 return true; |
324 IHyperlink link= cast(IHyperlink)selection.getData(); | 324 IHyperlink link= cast(IHyperlink)selection.getData(); |
325 fManager.hideInformationControl(); | 325 fManager.hideInformationControl(); |
326 link.open(); | 326 link.open(); |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 private class MultipleHyperlinkHover : ITextHover, ITextHoverExtension { | 330 private class MultipleHyperlinkHover : ITextHover, ITextHoverExtension { |
331 | 331 |
332 /** | 332 /** |
333 * @see dwtx.jface.text.ITextHover#getHoverInfo(dwtx.jface.text.ITextViewer, dwtx.jface.text.IRegion) | 333 * @see dwtx.jface.text.ITextHover#getHoverInfo(dwtx.jface.text.ITextViewer, dwtx.jface.text.IRegion) |
334 * @deprecated | 334 * @deprecated |
335 */ | 335 */ |
336 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { | 336 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { |
337 return null; | 337 return null; |
338 } | 338 } |
339 | 339 |
340 /* | 340 /* |
341 * @see dwtx.jface.text.ITextHover#getHoverRegion(dwtx.jface.text.ITextViewer, int) | 341 * @see dwtx.jface.text.ITextHover#getHoverRegion(dwtx.jface.text.ITextViewer, int) |
342 */ | 342 */ |
343 public IRegion getHoverRegion(ITextViewer textViewer, int offset) { | 343 public IRegion getHoverRegion(ITextViewer textViewer, int offset) { |
344 return fSubjectRegion; | 344 return fSubjectRegion; |
345 } | 345 } |
346 | 346 |
347 /* | 347 /* |
348 * @see dwtx.jface.text.ITextHoverExtension2#getHoverInfo2(dwtx.jface.text.ITextViewer, dwtx.jface.text.IRegion) | 348 * @see dwtx.jface.text.ITextHoverExtension2#getHoverInfo2(dwtx.jface.text.ITextViewer, dwtx.jface.text.IRegion) |
349 */ | 349 */ |
350 public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { | 350 public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { |
351 return fHyperlinks; | 351 return fHyperlinks; |
352 } | 352 } |
353 | 353 |
354 /* | 354 /* |
355 * @see dwtx.jface.text.ITextHoverExtension#getHoverControlCreator() | 355 * @see dwtx.jface.text.ITextHoverExtension#getHoverControlCreator() |
356 */ | 356 */ |
357 public IInformationControlCreator getHoverControlCreator() { | 357 public IInformationControlCreator getHoverControlCreator() { |
358 return new class() IInformationControlCreator { | 358 return new class() IInformationControlCreator { |
362 return new LinkListInformationControl(parent, fManager, foregroundColor, backgroundColor); | 362 return new LinkListInformationControl(parent, fManager, foregroundColor, backgroundColor); |
363 } | 363 } |
364 }; | 364 }; |
365 } | 365 } |
366 } | 366 } |
367 | 367 |
368 private static class MultipleHyperlinkHoverManager : AbstractInformationControlManager , IWidgetTokenKeeper, IWidgetTokenKeeperExtension { | 368 private static class MultipleHyperlinkHoverManager : AbstractInformationControlManager , IWidgetTokenKeeper, IWidgetTokenKeeperExtension { |
369 | 369 |
370 private class Closer : IInformationControlCloser, Listener, KeyListener { | 370 private class Closer : IInformationControlCloser, Listener, KeyListener { |
371 | 371 |
372 private Control fSubjectControl; | 372 private Control fSubjectControl; |
373 private Display fDisplay; | 373 private Display fDisplay; |
374 private IInformationControl fControl; | 374 private IInformationControl fControl; |
375 private Rectangle fSubjectArea; | 375 private Rectangle fSubjectArea; |
376 | 376 |
377 /* | 377 /* |
378 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#setInformationControl(dwtx.jface.text.IInformationControl) | 378 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#setInformationControl(dwtx.jface.text.IInformationControl) |
379 */ | 379 */ |
380 public void setInformationControl(IInformationControl control) { | 380 public void setInformationControl(IInformationControl control) { |
381 fControl= control; | 381 fControl= control; |
382 } | 382 } |
383 | 383 |
384 /* | 384 /* |
385 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#setSubjectControl(dwt.widgets.Control) | 385 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#setSubjectControl(dwt.widgets.Control) |
386 */ | 386 */ |
387 public void setSubjectControl(Control subject) { | 387 public void setSubjectControl(Control subject) { |
388 fSubjectControl= subject; | 388 fSubjectControl= subject; |
389 } | 389 } |
390 | 390 |
391 /* | 391 /* |
392 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#start(dwt.graphics.Rectangle) | 392 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#start(dwt.graphics.Rectangle) |
393 */ | 393 */ |
394 public void start(Rectangle subjectArea) { | 394 public void start(Rectangle subjectArea) { |
395 fSubjectArea= subjectArea; | 395 fSubjectArea= subjectArea; |
396 | 396 |
397 fDisplay= fSubjectControl.getDisplay(); | 397 fDisplay= fSubjectControl.getDisplay(); |
398 if (!fDisplay.isDisposed()) { | 398 if (!fDisplay.isDisposed()) { |
399 fDisplay.addFilter(DWT.FocusOut, this); | 399 fDisplay.addFilter(DWT.FocusOut, this); |
400 fDisplay.addFilter(DWT.MouseMove, this); | 400 fDisplay.addFilter(DWT.MouseMove, this); |
401 fTextViewer.getTextWidget().addKeyListener(this); | 401 fTextViewer.getTextWidget().addKeyListener(this); |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
405 /* | 405 /* |
406 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#stop() | 406 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#stop() |
407 */ | 407 */ |
408 public void stop() { | 408 public void stop() { |
409 if (fDisplay !is null && !fDisplay.isDisposed()) { | 409 if (fDisplay !is null && !fDisplay.isDisposed()) { |
410 fDisplay.removeFilter(DWT.FocusOut, this); | 410 fDisplay.removeFilter(DWT.FocusOut, this); |
411 fDisplay.removeFilter(DWT.MouseMove, this); | 411 fDisplay.removeFilter(DWT.MouseMove, this); |
412 fTextViewer.getTextWidget().removeKeyListener(this); | 412 fTextViewer.getTextWidget().removeKeyListener(this); |
413 } | 413 } |
414 | 414 |
415 fSubjectArea= null; | 415 fSubjectArea= null; |
416 } | 416 } |
417 | 417 |
418 /* | 418 /* |
419 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event) | 419 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event) |
420 */ | 420 */ |
421 public void handleEvent(Event event) { | 421 public void handleEvent(Event event) { |
422 switch (event.type) { | 422 switch (event.type) { |
427 case DWT.MouseMove: | 427 case DWT.MouseMove: |
428 handleMouseMove(event); | 428 handleMouseMove(event); |
429 break; | 429 break; |
430 } | 430 } |
431 } | 431 } |
432 | 432 |
433 /** | 433 /** |
434 * Handle mouse movement events. | 434 * Handle mouse movement events. |
435 * | 435 * |
436 * @param event the event | 436 * @param event the event |
437 */ | 437 */ |
438 private void handleMouseMove(Event event) { | 438 private void handleMouseMove(Event event) { |
439 if (!(event.widget instanceof Control)) | 439 if (!(cast(Control)event.widget )) |
440 return; | 440 return; |
441 | 441 |
442 if (fControl.isFocusControl()) | 442 if (fControl.isFocusControl()) |
443 return; | 443 return; |
444 | 444 |
445 Control eventControl= cast(Control) event.widget; | 445 Control eventControl= cast(Control) event.widget; |
446 | 446 |
447 //transform coordinates to subject control: | 447 //transform coordinates to subject control: |
448 Point mouseLoc= event.display.map(eventControl, fSubjectControl, event.x, event.y); | 448 Point mouseLoc= event.display.map(eventControl, fSubjectControl, event.x, event.y); |
449 | 449 |
450 if (fSubjectArea.contains(mouseLoc)) | 450 if (fSubjectArea.contains(mouseLoc)) |
451 return; | 451 return; |
452 | 452 |
453 if (inKeepUpZone(mouseLoc.x, mouseLoc.y, (cast(IInformationControlExtension3) fControl).getBounds())) | 453 if (inKeepUpZone(mouseLoc.x, mouseLoc.y, (cast(IInformationControlExtension3) fControl).getBounds())) |
454 return; | 454 return; |
455 | 455 |
456 hideInformationControl(); | 456 hideInformationControl(); |
457 } | 457 } |
458 | 458 |
459 /** | 459 /** |
460 * Tests whether a given mouse location is within the keep-up zone. | 460 * Tests whether a given mouse location is within the keep-up zone. |
461 * The hover should not be hidden as long as the mouse stays inside this zone. | 461 * The hover should not be hidden as long as the mouse stays inside this zone. |
462 * | 462 * |
463 * @param x the x coordinate, relative to the <em>subject control</em> | 463 * @param x the x coordinate, relative to the <em>subject control</em> |
464 * @param y the y coordinate, relative to the <em>subject control</em> | 464 * @param y the y coordinate, relative to the <em>subject control</em> |
465 * @param controlBounds the bounds of the current control | 465 * @param controlBounds the bounds of the current control |
466 * | 466 * |
467 * @return <code>true</code> iff the mouse event occurred in the keep-up zone | 467 * @return <code>true</code> iff the mouse event occurred in the keep-up zone |
468 */ | 468 */ |
469 private bool inKeepUpZone(int x, int y, Rectangle controlBounds) { | 469 private bool inKeepUpZone(int x, int y, Rectangle controlBounds) { |
470 // +-----------+ | 470 // +-----------+ |
471 // |subjectArea| | 471 // |subjectArea| |
474 // ++-----------+-------+ | 474 // ++-----------+-------+ |
475 // | totalBounds | | 475 // | totalBounds | |
476 // +--------------------+ | 476 // +--------------------+ |
477 if (fSubjectArea.contains(x, y)) | 477 if (fSubjectArea.contains(x, y)) |
478 return true; | 478 return true; |
479 | 479 |
480 Rectangle iControlBounds= fSubjectControl.getDisplay().map(null, fSubjectControl, controlBounds); | 480 Rectangle iControlBounds= fSubjectControl.getDisplay().map(null, fSubjectControl, controlBounds); |
481 Rectangle totalBounds= Geometry.copy(iControlBounds); | 481 Rectangle totalBounds= Geometry.copy(iControlBounds); |
482 if (totalBounds.contains(x, y)) | 482 if (totalBounds.contains(x, y)) |
483 return true; | 483 return true; |
484 | 484 |
485 int keepUpY= fSubjectArea.y + fSubjectArea.height; | 485 int keepUpY= fSubjectArea.y + fSubjectArea.height; |
486 Rectangle alsoKeepUp= new Rectangle(fSubjectArea.x, keepUpY, fSubjectArea.width, totalBounds.y - keepUpY); | 486 Rectangle alsoKeepUp= new Rectangle(fSubjectArea.x, keepUpY, fSubjectArea.width, totalBounds.y - keepUpY); |
487 return alsoKeepUp.contains(x, y); | 487 return alsoKeepUp.contains(x, y); |
488 } | 488 } |
489 | 489 |
490 /* | 490 /* |
491 * @see dwt.events.KeyListener#keyPressed(dwt.events.KeyEvent) | 491 * @see dwt.events.KeyListener#keyPressed(dwt.events.KeyEvent) |
492 */ | 492 */ |
493 public void keyPressed(KeyEvent e) { | 493 public void keyPressed(KeyEvent e) { |
494 } | 494 } |
495 | 495 |
496 /* | 496 /* |
497 * @see dwt.events.KeyListener#keyReleased(dwt.events.KeyEvent) | 497 * @see dwt.events.KeyListener#keyReleased(dwt.events.KeyEvent) |
498 */ | 498 */ |
499 public void keyReleased(KeyEvent e) { | 499 public void keyReleased(KeyEvent e) { |
500 hideInformationControl(); | 500 hideInformationControl(); |
501 } | 501 } |
502 | 502 |
503 } | 503 } |
504 | 504 |
505 /** | 505 /** |
506 * Priority of the hover managed by this manager. | 506 * Priority of the hover managed by this manager. |
507 * Default value: One higher then for the hovers | 507 * Default value: One higher then for the hovers |
508 * managed by TextViewerHoverManager. | 508 * managed by TextViewerHoverManager. |
509 */ | 509 */ |
510 private static final int WIDGET_TOKEN_PRIORITY= 1; | 510 private static final int WIDGET_TOKEN_PRIORITY= 1; |
511 | 511 |
512 private final MultipleHyperlinkHover fHover; | 512 private final MultipleHyperlinkHover fHover; |
513 private final ITextViewer fTextViewer; | 513 private final ITextViewer fTextViewer; |
514 private final MultipleHyperlinkPresenter fHyperlinkPresenter; | 514 private final MultipleHyperlinkPresenter fHyperlinkPresenter; |
515 private Closer fCloser; | 515 private Closer fCloser; |
516 private bool fIsControlVisible; | 516 private bool fIsControlVisible; |
517 | 517 |
518 | 518 |
519 /** | 519 /** |
520 * Create a new MultipleHyperlinkHoverManager. The MHHM can show and hide | 520 * Create a new MultipleHyperlinkHoverManager. The MHHM can show and hide |
521 * the given MultipleHyperlinkHover inside the given ITextViewer. | 521 * the given MultipleHyperlinkHover inside the given ITextViewer. |
522 * | 522 * |
523 * @param hover the hover to manage | 523 * @param hover the hover to manage |
524 * @param viewer the viewer to show the hover in | 524 * @param viewer the viewer to show the hover in |
525 * @param hyperlinkPresenter the hyperlink presenter using this manager to present hyperlinks | 525 * @param hyperlinkPresenter the hyperlink presenter using this manager to present hyperlinks |
526 */ | 526 */ |
527 public this(MultipleHyperlinkHover hover, ITextViewer viewer, MultipleHyperlinkPresenter hyperlinkPresenter) { | 527 public this(MultipleHyperlinkHover hover, ITextViewer viewer, MultipleHyperlinkPresenter hyperlinkPresenter) { |
528 super(hover.getHoverControlCreator()); | 528 super(hover.getHoverControlCreator()); |
529 | 529 |
530 fHover= hover; | 530 fHover= hover; |
531 fTextViewer= viewer; | 531 fTextViewer= viewer; |
532 fHyperlinkPresenter= hyperlinkPresenter; | 532 fHyperlinkPresenter= hyperlinkPresenter; |
533 | 533 |
534 fCloser= new Closer(); | 534 fCloser= new Closer(); |
535 setCloser(fCloser); | 535 setCloser(fCloser); |
536 fIsControlVisible= false; | 536 fIsControlVisible= false; |
537 } | 537 } |
538 | 538 |
539 /* | 539 /* |
540 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformation() | 540 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformation() |
541 */ | 541 */ |
542 protected void computeInformation() { | 542 protected void computeInformation() { |
543 IRegion region= fHover.getHoverRegion(fTextViewer, -1); | 543 IRegion region= fHover.getHoverRegion(fTextViewer, -1); |
544 if (region is null) { | 544 if (region is null) { |
545 setInformation(null, null); | 545 setInformation(null, null); |
546 return; | 546 return; |
547 } | 547 } |
548 | 548 |
549 Rectangle area= JFaceTextUtil.computeArea(region, fTextViewer); | 549 Rectangle area= JFaceTextUtil.computeArea(region, fTextViewer); |
550 if (area is null || area.isEmpty()) { | 550 if (area is null || area.isEmpty()) { |
551 setInformation(null, null); | 551 setInformation(null, null); |
552 return; | 552 return; |
553 } | 553 } |
554 | 554 |
555 Object information= fHover.getHoverInfo2(fTextViewer, region); | 555 Object information= fHover.getHoverInfo2(fTextViewer, region); |
556 setCustomInformationControlCreator(fHover.getHoverControlCreator()); | 556 setCustomInformationControlCreator(fHover.getHoverControlCreator()); |
557 setInformation(information, area); | 557 setInformation(information, area); |
558 } | 558 } |
559 | 559 |
560 /* | 560 /* |
561 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformationControlLocation(dwt.graphics.Rectangle, dwt.graphics.Point) | 561 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformationControlLocation(dwt.graphics.Rectangle, dwt.graphics.Point) |
562 */ | 562 */ |
563 protected Point computeInformationControlLocation(Rectangle subjectArea, Point controlSize) { | 563 protected Point computeInformationControlLocation(Rectangle subjectArea, Point controlSize) { |
564 Point result= super.computeInformationControlLocation(subjectArea, controlSize); | 564 Point result= super.computeInformationControlLocation(subjectArea, controlSize); |
565 | 565 |
566 Point cursorLocation= fTextViewer.getTextWidget().getDisplay().getCursorLocation(); | 566 Point cursorLocation= fTextViewer.getTextWidget().getDisplay().getCursorLocation(); |
567 if (cursorLocation.x <= result.x + controlSize.x) | 567 if (cursorLocation.x <= result.x + controlSize.x) |
568 return result; | 568 return result; |
569 | 569 |
570 result.x= cursorLocation.x + 20 - controlSize.x; | 570 result.x= cursorLocation.x + 20 - controlSize.x; |
571 return result; | 571 return result; |
572 } | 572 } |
573 | 573 |
574 /* | 574 /* |
575 * @see dwtx.jface.text.AbstractInformationControlManager#showInformationControl(dwt.graphics.Rectangle) | 575 * @see dwtx.jface.text.AbstractInformationControlManager#showInformationControl(dwt.graphics.Rectangle) |
576 */ | 576 */ |
577 protected void showInformationControl(Rectangle subjectArea) { | 577 protected void showInformationControl(Rectangle subjectArea) { |
578 if ( cast(IWidgetTokenOwnerExtension)fTextViewer ) { | 578 if ( cast(IWidgetTokenOwnerExtension)fTextViewer ) { |
582 if ((cast(IWidgetTokenOwner) fTextViewer).requestWidgetToken(this)) | 582 if ((cast(IWidgetTokenOwner) fTextViewer).requestWidgetToken(this)) |
583 super.showInformationControl(subjectArea); | 583 super.showInformationControl(subjectArea); |
584 } else { | 584 } else { |
585 super.showInformationControl(subjectArea); | 585 super.showInformationControl(subjectArea); |
586 } | 586 } |
587 | 587 |
588 fIsControlVisible= true; | 588 fIsControlVisible= true; |
589 } | 589 } |
590 | 590 |
591 /* | 591 /* |
592 * @see dwtx.jface.text.AbstractInformationControlManager#hideInformationControl() | 592 * @see dwtx.jface.text.AbstractInformationControlManager#hideInformationControl() |
593 */ | 593 */ |
594 protected void hideInformationControl() { | 594 protected void hideInformationControl() { |
595 super.hideInformationControl(); | 595 super.hideInformationControl(); |
596 | 596 |
597 if ( cast(IWidgetTokenOwner)fTextViewer ) { | 597 if ( cast(IWidgetTokenOwner)fTextViewer ) { |
598 (cast(IWidgetTokenOwner) fTextViewer).releaseWidgetToken(this); | 598 (cast(IWidgetTokenOwner) fTextViewer).releaseWidgetToken(this); |
599 } | 599 } |
600 | 600 |
601 fIsControlVisible= false; | 601 fIsControlVisible= false; |
602 fHyperlinkPresenter.hideHyperlinks(); | 602 fHyperlinkPresenter.hideHyperlinks(); |
603 } | 603 } |
604 | 604 |
605 /* | 605 /* |
606 * @see dwtx.jface.text.AbstractInformationControlManager#disposeInformationControl() | 606 * @see dwtx.jface.text.AbstractInformationControlManager#disposeInformationControl() |
607 */ | 607 */ |
608 public void disposeInformationControl() { | 608 public void disposeInformationControl() { |
609 super.disposeInformationControl(); | 609 super.disposeInformationControl(); |
610 | 610 |
611 if ( cast(IWidgetTokenOwner)fTextViewer ) { | 611 if ( cast(IWidgetTokenOwner)fTextViewer ) { |
612 (cast(IWidgetTokenOwner) fTextViewer).releaseWidgetToken(this); | 612 (cast(IWidgetTokenOwner) fTextViewer).releaseWidgetToken(this); |
613 } | 613 } |
614 | 614 |
615 fIsControlVisible= false; | 615 fIsControlVisible= false; |
616 fHyperlinkPresenter.hideHyperlinks(); | 616 fHyperlinkPresenter.hideHyperlinks(); |
617 } | 617 } |
618 | 618 |
619 /* | 619 /* |
620 * @see dwtx.jface.text.IWidgetTokenKeeper#requestWidgetToken(dwtx.jface.text.IWidgetTokenOwner) | 620 * @see dwtx.jface.text.IWidgetTokenKeeper#requestWidgetToken(dwtx.jface.text.IWidgetTokenOwner) |
621 */ | 621 */ |
622 public bool requestWidgetToken(IWidgetTokenOwner owner) { | 622 public bool requestWidgetToken(IWidgetTokenOwner owner) { |
623 hideInformationControl(); | 623 hideInformationControl(); |
624 return true; | 624 return true; |
625 } | 625 } |
626 | 626 |
627 /* | 627 /* |
628 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#requestWidgetToken(dwtx.jface.text.IWidgetTokenOwner, int) | 628 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#requestWidgetToken(dwtx.jface.text.IWidgetTokenOwner, int) |
629 */ | 629 */ |
630 public bool requestWidgetToken(IWidgetTokenOwner owner, int priority) { | 630 public bool requestWidgetToken(IWidgetTokenOwner owner, int priority) { |
631 if (priority < WIDGET_TOKEN_PRIORITY) | 631 if (priority < WIDGET_TOKEN_PRIORITY) |
632 return false; | 632 return false; |
633 | 633 |
634 hideInformationControl(); | 634 hideInformationControl(); |
635 return true; | 635 return true; |
636 } | 636 } |
637 | 637 |
638 /* | 638 /* |
639 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#setFocus(dwtx.jface.text.IWidgetTokenOwner) | 639 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#setFocus(dwtx.jface.text.IWidgetTokenOwner) |
640 */ | 640 */ |
641 public bool setFocus(IWidgetTokenOwner owner) { | 641 public bool setFocus(IWidgetTokenOwner owner) { |
642 return false; | 642 return false; |
643 } | 643 } |
644 | 644 |
645 /** | 645 /** |
646 * Returns <code>true</code> if the information control managed by | 646 * Returns <code>true</code> if the information control managed by |
647 * this manager is visible, <code>false</code> otherwise. | 647 * this manager is visible, <code>false</code> otherwise. |
648 * | 648 * |
649 * @return <code>true</code> if information control is visible | 649 * @return <code>true</code> if information control is visible |
650 */ | 650 */ |
651 public bool isInformationControlVisible() { | 651 public bool isInformationControlVisible() { |
652 return fIsControlVisible; | 652 return fIsControlVisible; |
653 } | 653 } |
654 } | 654 } |
655 | 655 |
656 private ITextViewer fTextViewer; | 656 private ITextViewer fTextViewer; |
657 | 657 |
658 private IHyperlink[] fHyperlinks; | 658 private IHyperlink[] fHyperlinks; |
659 private Region fSubjectRegion; | 659 private Region fSubjectRegion; |
660 private MultipleHyperlinkHoverManager fManager; | 660 private MultipleHyperlinkHoverManager fManager; |
661 | 661 |
662 /** | 662 /** |
663 * Creates a new multiple hyperlink presenter which uses | 663 * Creates a new multiple hyperlink presenter which uses |
664 * {@link #HYPERLINK_COLOR} to read the color from the given preference store. | 664 * {@link #HYPERLINK_COLOR} to read the color from the given preference store. |
665 * | 665 * |
666 * @param store the preference store | 666 * @param store the preference store |
667 */ | 667 */ |
668 public this(IPreferenceStore store) { | 668 public this(IPreferenceStore store) { |
669 super(store); | 669 super(store); |
670 } | 670 } |
671 | 671 |
672 /** | 672 /** |
673 * Creates a new multiple hyperlink presenter. | 673 * Creates a new multiple hyperlink presenter. |
674 * | 674 * |
675 * @param color the hyperlink color, to be disposed by the caller | 675 * @param color the hyperlink color, to be disposed by the caller |
676 */ | 676 */ |
677 public this(RGB color) { | 677 public this(RGB color) { |
678 super(color); | 678 super(color); |
679 } | 679 } |
680 | 680 |
681 /* | 681 /* |
682 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#install(dwtx.jface.text.ITextViewer) | 682 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#install(dwtx.jface.text.ITextViewer) |
683 */ | 683 */ |
684 public void install(ITextViewer viewer) { | 684 public void install(ITextViewer viewer) { |
685 super.install(viewer); | 685 super.install(viewer); |
686 fTextViewer= viewer; | 686 fTextViewer= viewer; |
687 | 687 |
688 fManager= new MultipleHyperlinkHoverManager(new MultipleHyperlinkHover(), fTextViewer, this); | 688 fManager= new MultipleHyperlinkHoverManager(new MultipleHyperlinkHover(), fTextViewer, this); |
689 fManager.install(viewer.getTextWidget()); | 689 fManager.install(viewer.getTextWidget()); |
690 fManager.setSizeConstraints(100, 12, false, true); | 690 fManager.setSizeConstraints(100, 12, false, true); |
691 } | 691 } |
692 | 692 |
693 /* | 693 /* |
694 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#uninstall() | 694 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#uninstall() |
695 */ | 695 */ |
696 public void uninstall() { | 696 public void uninstall() { |
697 super.uninstall(); | 697 super.uninstall(); |
698 | 698 |
699 if (fTextViewer !is null) { | 699 if (fTextViewer !is null) { |
700 fManager.dispose(); | 700 fManager.dispose(); |
701 | 701 |
702 fTextViewer= null; | 702 fTextViewer= null; |
703 } | 703 } |
704 } | 704 } |
705 | 705 |
706 /* | 706 /* |
707 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#canShowMultipleHyperlinks() | 707 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#canShowMultipleHyperlinks() |
708 */ | 708 */ |
709 public bool canShowMultipleHyperlinks() { | 709 public bool canShowMultipleHyperlinks() { |
710 return true; | 710 return true; |
711 } | 711 } |
712 | 712 |
713 /* | 713 /* |
714 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#canHideHyperlinks() | 714 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#canHideHyperlinks() |
715 */ | 715 */ |
716 public bool canHideHyperlinks() { | 716 public bool canHideHyperlinks() { |
717 return !fManager.isInformationControlVisible(); | 717 return !fManager.isInformationControlVisible(); |
718 } | 718 } |
719 | 719 |
720 /* | 720 /* |
721 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#hideHyperlinks() | 721 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#hideHyperlinks() |
722 */ | 722 */ |
723 public void hideHyperlinks() { | 723 public void hideHyperlinks() { |
724 super.hideHyperlinks(); | 724 super.hideHyperlinks(); |
725 | 725 |
726 fHyperlinks= null; | 726 fHyperlinks= null; |
727 } | 727 } |
728 | 728 |
729 /* | 729 /* |
730 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#showHyperlinks(dwtx.jface.text.hyperlink.IHyperlink[]) | 730 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#showHyperlinks(dwtx.jface.text.hyperlink.IHyperlink[]) |
731 */ | 731 */ |
732 public void showHyperlinks(IHyperlink[] hyperlinks) { | 732 public void showHyperlinks(IHyperlink[] hyperlinks) { |
733 super.showHyperlinks(new IHyperlink[] { hyperlinks[0] }); | 733 super.showHyperlinks([ hyperlinks[0] ]); |
734 | 734 |
735 fSubjectRegion= null; | 735 fSubjectRegion= null; |
736 fHyperlinks= hyperlinks; | 736 fHyperlinks= hyperlinks; |
737 | 737 |
738 if (hyperlinks.length is 1) | 738 if (hyperlinks.length is 1) |
739 return; | 739 return; |
740 | 740 |
741 int start= hyperlinks[0].getHyperlinkRegion().getOffset(); | 741 int start= hyperlinks[0].getHyperlinkRegion().getOffset(); |
742 int end= start + hyperlinks[0].getHyperlinkRegion().getLength(); | 742 int end= start + hyperlinks[0].getHyperlinkRegion().getLength(); |
743 | 743 |
744 for (int i= 1; i < hyperlinks.length; i++) { | 744 for (int i= 1; i < hyperlinks.length; i++) { |
745 int hstart= hyperlinks[i].getHyperlinkRegion().getOffset(); | 745 int hstart= hyperlinks[i].getHyperlinkRegion().getOffset(); |
746 int hend= hstart + hyperlinks[i].getHyperlinkRegion().getLength(); | 746 int hend= hstart + hyperlinks[i].getHyperlinkRegion().getLength(); |
747 | 747 |
748 start= Math.min(start, hstart); | 748 start= Math.min(start, hstart); |
749 end= Math.max(end, hend); | 749 end= Math.max(end, hend); |
750 } | 750 } |
751 | 751 |
752 fSubjectRegion= new Region(start, end - start); | 752 fSubjectRegion= new Region(start, end - start); |
753 | 753 |
754 fManager.showInformation(); | 754 fManager.showInformation(); |
755 } | 755 } |
756 } | 756 } |