comparison dwtx/jface/internal/text/StickyHoverManager.d @ 150:5cf141e43417

...
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 23:05:26 +0200
parents b411f1c62131
children 1a5b8f8129df
comparison
equal deleted inserted replaced
149:b411f1c62131 150:5cf141e43417
82 * and closes the information control when necessary. 82 * and closes the information control when necessary.
83 */ 83 */
84 class Closer : IInformationControlCloser, ControlListener, MouseListener, IViewportListener, KeyListener, FocusListener, Listener { 84 class Closer : IInformationControlCloser, ControlListener, MouseListener, IViewportListener, KeyListener, FocusListener, Listener {
85 //TODO: Catch 'Esc' key in fInformationControlToClose: Don't dispose, just hideInformationControl(). 85 //TODO: Catch 'Esc' key in fInformationControlToClose: Don't dispose, just hideInformationControl().
86 // This would allow to reuse the information control also when the user explicitly closes it. 86 // This would allow to reuse the information control also when the user explicitly closes it.
87 87
88 //TODO: if subject control is a Scrollable, should add selection listeners to both scroll bars 88 //TODO: if subject control is a Scrollable, should add selection listeners to both scroll bars
89 // (and remove the ViewPortListener, which only listens to vertical scrolling) 89 // (and remove the ViewPortListener, which only listens to vertical scrolling)
90 90
91 /** The subject control. */ 91 /** The subject control. */
92 private Control fSubjectControl; 92 private Control fSubjectControl;
123 fSubjectControl.addMouseListener(this); 123 fSubjectControl.addMouseListener(this);
124 fSubjectControl.addKeyListener(this); 124 fSubjectControl.addKeyListener(this);
125 } 125 }
126 126
127 fTextViewer.addViewportListener(this); 127 fTextViewer.addViewportListener(this);
128 128
129 IInformationControl fInformationControlToClose= getCurrentInformationControl2(); 129 IInformationControl fInformationControlToClose= getCurrentInformationControl2();
130 if (fInformationControlToClose !is null) 130 if (fInformationControlToClose !is null)
131 fInformationControlToClose.addFocusListener(this); 131 fInformationControlToClose.addFocusListener(this);
132 132
133 fDisplay= fSubjectControl.getDisplay(); 133 fDisplay= fSubjectControl.getDisplay();
151 if (fSubjectControl !is null && !fSubjectControl.isDisposed()) { 151 if (fSubjectControl !is null && !fSubjectControl.isDisposed()) {
152 fSubjectControl.removeControlListener(this); 152 fSubjectControl.removeControlListener(this);
153 fSubjectControl.removeMouseListener(this); 153 fSubjectControl.removeMouseListener(this);
154 fSubjectControl.removeKeyListener(this); 154 fSubjectControl.removeKeyListener(this);
155 } 155 }
156 156
157 IInformationControl fInformationControlToClose= getCurrentInformationControl2(); 157 IInformationControl fInformationControlToClose= getCurrentInformationControl2();
158 if (fInformationControlToClose !is null) 158 if (fInformationControlToClose !is null)
159 fInformationControlToClose.removeFocusListener(this); 159 fInformationControlToClose.removeFocusListener(this);
160 160
161 if (fDisplay !is null && !fDisplay.isDisposed()) { 161 if (fDisplay !is null && !fDisplay.isDisposed()) {
162 fDisplay.removeFilter(DWT.MouseMove, this); 162 fDisplay.removeFilter(DWT.MouseMove, this);
163 fDisplay.removeFilter(DWT.FocusOut, this); 163 fDisplay.removeFilter(DWT.FocusOut, this);
164 } 164 }
165 165
217 /* 217 /*
218 * @see KeyListener#keyReleased(KeyEvent) 218 * @see KeyListener#keyReleased(KeyEvent)
219 */ 219 */
220 public void keyReleased(KeyEvent e) { 220 public void keyReleased(KeyEvent e) {
221 } 221 }
222 222
223 /* 223 /*
224 * @see dwt.events.FocusListener#focusGained(dwt.events.FocusEvent) 224 * @see dwt.events.FocusListener#focusGained(dwt.events.FocusEvent)
225 */ 225 */
226 public void focusGained(FocusEvent e) { 226 public void focusGained(FocusEvent e) {
227 } 227 }
228 228
229 /* 229 /*
230 * @see dwt.events.FocusListener#focusLost(dwt.events.FocusEvent) 230 * @see dwt.events.FocusListener#focusLost(dwt.events.FocusEvent)
231 */ 231 */
232 public void focusLost(FocusEvent e) { 232 public void focusLost(FocusEvent e) {
233 if cast(DEBUG) System.out_.println("StickyHoverManager.Closer.focusLost(): " + e); //$NON-NLS-1$ 233 if (DEBUG) System.out_.println("StickyHoverManager.Closer.focusLost(): " + e); //$NON-NLS-1$
234 Display d= fSubjectControl.getDisplay(); 234 Display d= fSubjectControl.getDisplay();
235 d.asyncExec(new class() Runnable { 235 d.asyncExec(new class() Runnable {
236 // Without the asyncExec, mouse clicks to the workbench window are swallowed. 236 // Without the asyncExec, mouse clicks to the workbench window are swallowed.
237 public void run() { 237 public void run() {
238 hideInformationControl(); 238 hideInformationControl();
239 } 239 }
240 }); 240 });
241 } 241 }
242 242
243 /* 243 /*
244 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event) 244 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event)
245 */ 245 */
246 public void handleEvent(Event event) { 246 public void handleEvent(Event event) {
247 if (event.type is DWT.MouseMove) { 247 if (event.type is DWT.MouseMove) {
248 if (!( cast(Control)event.widget ) || event.widget.isDisposed()) 248 if (!( cast(Control)event.widget ) || event.widget.isDisposed())
249 return; 249 return;
250 250
251 IInformationControl infoControl= getCurrentInformationControl2(); 251 IInformationControl infoControl= getCurrentInformationControl2();
252 if (infoControl !is null && !infoControl.isFocusControl() && cast(IInformationControlExtension3)infoControl ) { 252 if (infoControl !is null && !infoControl.isFocusControl() && cast(IInformationControlExtension3)infoControl ) {
253 // if cast(DEBUG) System.out_.println("StickyHoverManager.Closer.handleEvent(): activeShell= " + fDisplay.getActiveShell()); //$NON-NLS-1$ 253 // if (DEBUG) System.out_.println("StickyHoverManager.Closer.handleEvent(): activeShell= " + fDisplay.getActiveShell()); //$NON-NLS-1$
254 IInformationControlExtension3 iControl3= cast(IInformationControlExtension3) infoControl; 254 IInformationControlExtension3 iControl3= cast(IInformationControlExtension3) infoControl;
255 Rectangle controlBounds= iControl3.getBounds(); 255 Rectangle controlBounds= iControl3.getBounds();
256 if (controlBounds !is null) { 256 if (controlBounds !is null) {
257 Point mouseLoc= event.display.map(cast(Control) event.widget, null, event.x, event.y); 257 Point mouseLoc= event.display.map(cast(Control) event.widget, null, event.x, event.y);
258 int margin= getKeepUpMargin(); 258 int margin= getKeepUpMargin();
259 Geometry.expand(controlBounds, margin, margin, margin, margin); 259 Geometry.expand(controlBounds, margin, margin, margin, margin);
260 if (!controlBounds.contains(mouseLoc)) { 260 if (!controlBounds.contains(mouseLoc)) {
261 hideInformationControl(); 261 hideInformationControl();
262 } 262 }
263 } 263 }
264 264
265 } else { 265 } else {
266 /* 266 /*
267 * TODO: need better understanding of why/if this is needed. 267 * TODO: need better understanding of why/if this is needed.
268 * Looks like the same panic code we have in dwtx.jface.text.AbstractHoverInformationControlManager.Closer.handleMouseMove(Event) 268 * Looks like the same panic code we have in dwtx.jface.text.AbstractHoverInformationControlManager.Closer.handleMouseMove(Event)
269 */ 269 */
270 if (fDisplay !is null && !fDisplay.isDisposed()) 270 if (fDisplay !is null && !fDisplay.isDisposed())
271 fDisplay.removeFilter(DWT.MouseMove, this); 271 fDisplay.removeFilter(DWT.MouseMove, this);
272 } 272 }
273 273
274 } else if (event.type is DWT.FocusOut) { 274 } else if (event.type is DWT.FocusOut) {
275 if cast(DEBUG) System.out_.println("StickyHoverManager.Closer.handleEvent(): focusOut: " + event); //$NON-NLS-1$ 275 if (DEBUG) System.out_.println("StickyHoverManager.Closer.handleEvent(): focusOut: " + event); //$NON-NLS-1$
276 IInformationControl iControl= getCurrentInformationControl2(); 276 IInformationControl iControl= getCurrentInformationControl2();
277 if (iControl !is null && ! iControl.isFocusControl()) 277 if (iControl !is null && ! iControl.isFocusControl())
278 hideInformationControl(); 278 hideInformationControl();
279 } 279 }
280 } 280 }
281 } 281 }
282 282
283 283
284 private const TextViewer fTextViewer; 284 private const TextViewer fTextViewer;
285 285
286 286
287 /** 287 /**
288 * Creates a new sticky hover manager. 288 * Creates a new sticky hover manager.
289 * 289 *
290 * @param textViewer the text viewer 290 * @param textViewer the text viewer
291 */ 291 */
292 public this(TextViewer textViewer) { 292 public this(TextViewer textViewer) {
293 super(new DefaultInformationControlCreator()); 293 super(new DefaultInformationControlCreator());
294 294
295 fTextViewer= textViewer; 295 fTextViewer= textViewer;
296 setCloser(new Closer()); 296 setCloser(new Closer());
297 297
298 install(fTextViewer.getTextWidget()); 298 install(fTextViewer.getTextWidget());
299 } 299 }
300 300
301 /* 301 /*
302 * @see AbstractInformationControlManager#showInformationControl(Rectangle) 302 * @see AbstractInformationControlManager#showInformationControl(Rectangle)
303 */ 303 */
304 protected void showInformationControl(Rectangle subjectArea) { 304 protected void showInformationControl(Rectangle subjectArea) {
305 if (fTextViewer !is null && fTextViewer.requestWidgetToken(this, WIDGET_PRIORITY)) 305 if (fTextViewer !is null && fTextViewer.requestWidgetToken(this, WIDGET_PRIORITY))
306 super.showInformationControl(subjectArea); 306 super.showInformationControl(subjectArea);
307 else 307 else
308 if cast(DEBUG) 308 if (DEBUG)
309 System.out_.println("cancelled StickyHoverManager.showInformationControl(..): did not get widget token (with prio)"); //$NON-NLS-1$ 309 System.out_.println("cancelled StickyHoverManager.showInformationControl(..): did not get widget token (with prio)"); //$NON-NLS-1$
310 } 310 }
311 311
312 /* 312 /*
313 * @see AbstractInformationControlManager#hideInformationControl() 313 * @see AbstractInformationControlManager#hideInformationControl()
336 /* 336 /*
337 * @see dwtx.jface.text.IWidgetTokenKeeper#requestWidgetToken(IWidgetTokenOwner) 337 * @see dwtx.jface.text.IWidgetTokenKeeper#requestWidgetToken(IWidgetTokenOwner)
338 */ 338 */
339 public bool requestWidgetToken(IWidgetTokenOwner owner) { 339 public bool requestWidgetToken(IWidgetTokenOwner owner) {
340 hideInformationControl(); 340 hideInformationControl();
341 if cast(DEBUG) 341 if (DEBUG)
342 System.out_.println("StickyHoverManager gave up widget token (no prio)"); //$NON-NLS-1$ 342 System.out_.println("StickyHoverManager gave up widget token (no prio)"); //$NON-NLS-1$
343 return true; 343 return true;
344 } 344 }
345 345
346 /* 346 /*
347 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#requestWidgetToken(dwtx.jface.text.IWidgetTokenOwner, int) 347 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#requestWidgetToken(dwtx.jface.text.IWidgetTokenOwner, int)
348 */ 348 */
349 public bool requestWidgetToken(IWidgetTokenOwner owner, int priority) { 349 public bool requestWidgetToken(IWidgetTokenOwner owner, int priority) {
350 if (getCurrentInformationControl2() !is null) { 350 if (getCurrentInformationControl2() !is null) {
351 if (getCurrentInformationControl2().isFocusControl()) { 351 if (getCurrentInformationControl2().isFocusControl()) {
352 if cast(DEBUG) 352 if (DEBUG)
353 System.out_.println("StickyHoverManager kept widget token (focused)"); //$NON-NLS-1$ 353 System.out_.println("StickyHoverManager kept widget token (focused)"); //$NON-NLS-1$
354 return false; 354 return false;
355 } else if (priority > WIDGET_PRIORITY) { 355 } else if (priority > WIDGET_PRIORITY) {
356 hideInformationControl(); 356 hideInformationControl();
357 if cast(DEBUG) 357 if (DEBUG)
358 System.out_.println("StickyHoverManager gave up widget token (prio)"); //$NON-NLS-1$ 358 System.out_.println("StickyHoverManager gave up widget token (prio)"); //$NON-NLS-1$
359 return true; 359 return true;
360 } else { 360 } else {
361 if cast(DEBUG) 361 if (DEBUG)
362 System.out_.println("StickyHoverManager kept widget token (prio)"); //$NON-NLS-1$ 362 System.out_.println("StickyHoverManager kept widget token (prio)"); //$NON-NLS-1$
363 return false; 363 return false;
364 } 364 }
365 } 365 }
366 if cast(DEBUG) 366 if (DEBUG)
367 System.out_.println("StickyHoverManager gave up widget token (no iControl)"); //$NON-NLS-1$ 367 System.out_.println("StickyHoverManager gave up widget token (no iControl)"); //$NON-NLS-1$
368 return true; 368 return true;
369 } 369 }
370 370
371 /* 371 /*
382 return false; 382 return false;
383 } 383 }
384 iControl.setFocus(); 384 iControl.setFocus();
385 return iControl.isFocusControl(); 385 return iControl.isFocusControl();
386 } 386 }
387 387
388 } 388 }