Mercurial > projects > dwt-addons
annotate dwtx/jface/internal/text/html/BrowserInformationControl.d @ 160:3678e4f1a766
toHash, toString
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 02:07:22 +0200 |
parents | 25f1f92fa3df |
children | 1a5b8f8129df |
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.internal.text.html.BrowserInformationControl; | |
14 | |
131 | 15 import dwtx.jface.internal.text.html.HTML2TextReader; // packageimport |
16 import dwtx.jface.internal.text.html.HTMLPrinter; // packageimport | |
17 import dwtx.jface.internal.text.html.SubstitutionTextReader; // packageimport | |
18 import dwtx.jface.internal.text.html.HTMLTextPresenter; // packageimport | |
19 import dwtx.jface.internal.text.html.BrowserInput; // packageimport | |
20 import dwtx.jface.internal.text.html.SingleCharReader; // packageimport | |
21 import dwtx.jface.internal.text.html.BrowserInformationControlInput; // packageimport | |
22 import dwtx.jface.internal.text.html.HTMLMessages; // packageimport | |
23 | |
158 | 24 // FIXME needs Browser :/ |
25 /++ | |
129 | 26 import dwt.dwthelper.utils; |
27 | |
158 | 28 import dwtx.dwtxhelper.StringReader; |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
29 import dwtx.dwtxhelper.Collection; |
129 | 30 |
31 import dwt.DWT; | |
32 import dwt.DWTError; | |
33 import dwt.browser.Browser; | |
34 import dwt.browser.LocationListener; | |
35 import dwt.browser.ProgressAdapter; | |
36 import dwt.browser.ProgressEvent; | |
37 import dwt.custom.StyleRange; | |
38 import dwt.events.KeyEvent; | |
39 import dwt.events.KeyListener; | |
40 import dwt.graphics.Color; | |
41 import dwt.graphics.Font; | |
42 import dwt.graphics.FontData; | |
43 import dwt.graphics.GC; | |
44 import dwt.graphics.Point; | |
45 import dwt.graphics.Rectangle; | |
46 import dwt.graphics.TextLayout; | |
47 import dwt.graphics.TextStyle; | |
48 import dwt.widgets.Composite; | |
49 import dwt.widgets.Display; | |
50 import dwt.widgets.Menu; | |
51 import dwt.widgets.Shell; | |
52 import dwt.widgets.Slider; | |
53 import dwtx.core.runtime.Assert; | |
54 import dwtx.core.runtime.ListenerList; | |
55 import dwtx.jface.action.ToolBarManager; | |
56 import dwtx.jface.resource.JFaceResources; | |
57 import dwtx.jface.text.AbstractInformationControl; | |
58 import dwtx.jface.text.IDelayedInputChangeProvider; | |
59 import dwtx.jface.text.IInformationControlExtension2; | |
60 import dwtx.jface.text.IInputChangedListener; | |
61 import dwtx.jface.text.TextPresentation; | |
62 | |
63 | |
64 /** | |
65 * Displays HTML information in a {@link dwt.browser.Browser} widget. | |
66 * <p> | |
67 * This {@link IInformationControlExtension2} expects {@link #setInput(Object)} to be | |
68 * called with an argument of type {@link BrowserInformationControlInput}. | |
69 * </p> | |
70 * <p> | |
71 * Moved into this package from <code>dwtx.jface.internal.text.revisions</code>.</p> | |
72 * <p> | |
73 * This class may be instantiated; it is not intended to be subclassed.</p> | |
74 * <p> | |
75 * Current problems: | |
76 * <ul> | |
77 * <li>the size computation is too small</li> | |
78 * <li>focusLost event is not sent - see https://bugs.eclipse.org/bugs/show_bug.cgi?id=84532</li> | |
79 * </ul> | |
80 * </p> | |
150 | 81 * |
129 | 82 * @since 3.2 |
83 */ | |
84 public class BrowserInformationControl : AbstractInformationControl , IInformationControlExtension2, IDelayedInputChangeProvider { | |
85 | |
86 | |
87 /** | |
88 * Tells whether the DWT Browser widget and hence this information | |
89 * control is available. | |
90 * | |
91 * @param parent the parent component used for checking or <code>null</code> if none | |
92 * @return <code>true</code> if this control is available | |
93 */ | |
94 public static bool isAvailable(Composite parent) { | |
95 if (!fgAvailabilityChecked) { | |
96 try { | |
97 Browser browser= new Browser(parent, DWT.NONE); | |
98 browser.dispose(); | |
99 fgIsAvailable= true; | |
150 | 100 |
129 | 101 Slider sliderV= new Slider(parent, DWT.VERTICAL); |
102 Slider sliderH= new Slider(parent, DWT.HORIZONTAL); | |
103 int width= sliderV.computeSize(DWT.DEFAULT, DWT.DEFAULT).x; | |
104 int height= sliderH.computeSize(DWT.DEFAULT, DWT.DEFAULT).y; | |
105 fgScrollBarSize= new Point(width, height); | |
106 sliderV.dispose(); | |
107 sliderH.dispose(); | |
108 } catch (DWTError er) { | |
109 fgIsAvailable= false; | |
110 } finally { | |
111 fgAvailabilityChecked= true; | |
112 } | |
113 } | |
114 | |
115 return fgIsAvailable; | |
116 } | |
117 | |
118 | |
119 /** | |
120 * Minimal size constraints. | |
121 * @since 3.2 | |
122 */ | |
147 | 123 private static const int MIN_WIDTH= 80; |
124 private static const int MIN_HEIGHT= 50; | |
129 | 125 |
150 | 126 |
129 | 127 /** |
128 * Availability checking cache. | |
129 */ | |
130 private static bool fgIsAvailable= false; | |
131 private static bool fgAvailabilityChecked= false; | |
132 | |
133 /** | |
134 * Cached scroll bar width and height | |
135 * @since 3.4 | |
136 */ | |
137 private static Point fgScrollBarSize; | |
150 | 138 |
129 | 139 /** The control's browser widget */ |
140 private Browser fBrowser; | |
141 /** Tells whether the browser has content */ | |
142 private bool fBrowserHasContent; | |
143 /** Text layout used to approximate size of content when rendered in browser */ | |
144 private TextLayout fTextLayout; | |
145 /** Bold text style */ | |
146 private TextStyle fBoldStyle; | |
147 | |
148 private BrowserInformationControlInput fInput; | |
149 | |
150 /** | |
151 * <code>true</code> iff the browser has completed loading of the last | |
152 * input set via {@link #setInformation(String)}. | |
153 * @since 3.4 | |
154 */ | |
155 private bool fCompleted= false; | |
156 | |
157 /** | |
158 * The listener to be notified when a delayed location changing event happened. | |
159 * @since 3.4 | |
160 */ | |
161 private IInputChangedListener fDelayedInputChangeListener; | |
162 | |
163 /** | |
164 * The listeners to be notified when the input changed. | |
165 * @since 3.4 | |
166 */ | |
167 private ListenerList/*<IInputChangedListener>*/ fInputChangeListeners= new ListenerList(ListenerList.IDENTITY); | |
168 | |
169 /** | |
170 * The symbolic name of the font used for size computations, or <code>null</code> to use dialog font. | |
171 * @since 3.4 | |
172 */ | |
146 | 173 private const String fSymbolicFontName; |
129 | 174 |
175 | |
176 /** | |
177 * Creates a browser information control with the given shell as parent. | |
150 | 178 * |
129 | 179 * @param parent the parent shell |
180 * @param symbolicFontName the symbolic name of the font used for size computations | |
181 * @param resizable <code>true</code> if the control should be resizable | |
182 * @since 3.4 | |
183 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
184 public this(Shell parent, String symbolicFontName, bool resizable) { |
129 | 185 super(parent, resizable); |
186 fSymbolicFontName= symbolicFontName; | |
187 create(); | |
188 } | |
150 | 189 |
129 | 190 /** |
191 * Creates a browser information control with the given shell as parent. | |
150 | 192 * |
129 | 193 * @param parent the parent shell |
194 * @param symbolicFontName the symbolic name of the font used for size computations | |
195 * @param statusFieldText the text to be used in the optional status field | |
196 * or <code>null</code> if the status field should be hidden | |
197 * @since 3.4 | |
198 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
199 public this(Shell parent, String symbolicFontName, String statusFieldText) { |
129 | 200 super(parent, statusFieldText); |
201 fSymbolicFontName= symbolicFontName; | |
202 create(); | |
203 } | |
150 | 204 |
129 | 205 /** |
206 * Creates a browser information control with the given shell as parent. | |
150 | 207 * |
129 | 208 * @param parent the parent shell |
209 * @param symbolicFontName the symbolic name of the font used for size computations | |
210 * @param toolBarManager the manager or <code>null</code> if toolbar is not desired | |
211 * @since 3.4 | |
212 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
213 public this(Shell parent, String symbolicFontName, ToolBarManager toolBarManager) { |
129 | 214 super(parent, toolBarManager); |
215 fSymbolicFontName= symbolicFontName; | |
216 create(); | |
217 } | |
150 | 218 |
129 | 219 /* |
220 * @see dwtx.jface.text.AbstractInformationControl#createContent(dwt.widgets.Composite) | |
221 */ | |
222 protected void createContent(Composite parent) { | |
223 fBrowser= new Browser(parent, DWT.NONE); | |
150 | 224 |
129 | 225 Display display= getShell().getDisplay(); |
226 fBrowser.setForeground(display.getSystemColor(DWT.COLOR_INFO_FOREGROUND)); | |
227 fBrowser.setBackground(display.getSystemColor(DWT.COLOR_INFO_BACKGROUND)); | |
135 | 228 fBrowser.addKeyListener(new class() KeyListener { |
129 | 229 |
230 public void keyPressed(KeyEvent e) { | |
231 if (e.character is 0x1B) // ESC | |
232 getShell().dispose(); // XXX: Just hide? Would avoid constant recreations. | |
233 } | |
234 | |
235 public void keyReleased(KeyEvent e) {} | |
236 }); | |
237 | |
135 | 238 fBrowser.addProgressListener(new class() ProgressAdapter { |
129 | 239 public void completed(ProgressEvent event) { |
240 fCompleted= true; | |
241 } | |
242 }); | |
150 | 243 |
129 | 244 // Replace browser's built-in context menu with none |
245 fBrowser.setMenu(new Menu(getShell(), DWT.NONE)); | |
150 | 246 |
129 | 247 createTextLayout(); |
248 } | |
249 | |
250 /** | |
251 * {@inheritDoc} | |
252 * @deprecated use {@link #setInput(Object)} | |
253 */ | |
158 | 254 public void setInformation(String content) { |
255 setInput(new class(null,content) BrowserInformationControlInput { | |
256 String content_; | |
257 this(BrowserInformationControlInput input, String a){ | |
258 super(input); | |
259 content_=a; | |
260 } | |
129 | 261 public String getHtml() { |
158 | 262 return content_; |
129 | 263 } |
264 | |
265 public String getInputName() { | |
266 return ""; //$NON-NLS-1$ | |
267 } | |
268 | |
269 public Object getInputElement() { | |
158 | 270 return stringcast(content_); |
129 | 271 } |
272 }); | |
273 } | |
150 | 274 |
129 | 275 /** |
276 * {@inheritDoc} This control can handle {@link String} and | |
277 * {@link BrowserInformationControlInput}. | |
278 */ | |
279 public void setInput(Object input) { | |
150 | 280 Assert.isLegal(input is null || cast(String)input || cast(BrowserInformationControlInput)input ); |
129 | 281 |
138 | 282 if ( cast(String)input ) { |
134 | 283 setInformation(cast(String)input); |
129 | 284 return; |
285 } | |
286 | |
134 | 287 fInput= cast(BrowserInformationControlInput)input; |
150 | 288 |
129 | 289 String content= null; |
290 if (fInput !is null) | |
291 content= fInput.getHtml(); | |
150 | 292 |
129 | 293 fBrowserHasContent= content !is null && content.length() > 0; |
294 | |
295 if (!fBrowserHasContent) | |
296 content= "<html><body ></html>"; //$NON-NLS-1$ | |
297 | |
298 bool RTL= (getShell().getStyle() & DWT.RIGHT_TO_LEFT) !is 0; | |
299 bool resizable= isResizable(); | |
300 | |
301 // The default "overflow:auto" would not result in a predictable width for the client area | |
302 // and the re-wrapping would cause visual noise | |
303 String[] styles= null; | |
304 if (RTL && resizable) | |
150 | 305 styles= [ "direction:rtl;", "overflow:scroll;", "word-wrap:break-word;" ]; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
129 | 306 else if (RTL && !resizable) |
150 | 307 styles= [ "direction:rtl;", "overflow:hidden;", "word-wrap:break-word;" ]; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
129 | 308 else if (!resizable) |
309 //XXX: In IE, "word-wrap: break-word;" causes bogus wrapping even in non-broken words :-(see e.g. Javadoc of String). | |
310 // Re-check whether we really still need this now that the Javadoc Hover header already sets this style. | |
150 | 311 styles= [ "overflow:hidden;"/*, "word-wrap: break-word;"*/ ]; //$NON-NLS-1$ |
129 | 312 else |
150 | 313 styles= [ "overflow:scroll;" ]; //$NON-NLS-1$ |
314 | |
129 | 315 StringBuffer buffer= new StringBuffer(content); |
316 HTMLPrinter.insertStyles(buffer, styles); | |
317 content= buffer.toString(); | |
150 | 318 |
129 | 319 /* |
320 * XXX: Should add some JavaScript here that shows something like | |
321 * "(continued...)" or "..." at the end of the visible area when the page overflowed | |
322 * with "overflow:hidden;". | |
323 */ | |
150 | 324 |
129 | 325 fCompleted= false; |
326 fBrowser.setText(content); | |
150 | 327 |
129 | 328 Object[] listeners= fInputChangeListeners.getListeners(); |
329 for (int i= 0; i < listeners.length; i++) | |
134 | 330 (cast(IInputChangedListener)listeners[i]).inputChanged(fInput); |
129 | 331 } |
332 | |
333 /* | |
334 * @see IInformationControl#setVisible(bool) | |
335 */ | |
336 public void setVisible(bool visible) { | |
337 Shell shell= getShell(); | |
338 if (shell.isVisible() is visible) | |
339 return; | |
150 | 340 |
129 | 341 if (!visible) { |
342 super.setVisible(false); | |
343 setInput(null); | |
344 return; | |
345 } | |
150 | 346 |
129 | 347 /* |
348 * The Browser widget flickers when made visible while it is not completely loaded. | |
349 * The fix is to delay the call to setVisible until either loading is completed | |
350 * (see ProgressListener in constructor), or a timeout has been reached. | |
351 */ | |
352 final Display display= shell.getDisplay(); | |
150 | 353 |
129 | 354 // Make sure the display wakes from sleep after timeout: |
135 | 355 display.timerExec(100, new class() Runnable { |
129 | 356 public void run() { |
357 fCompleted= true; | |
358 } | |
359 }); | |
150 | 360 |
129 | 361 while (!fCompleted) { |
362 // Drive the event loop to process the events required to load the browser widget's contents: | |
363 if (!display.readAndDispatch()) { | |
364 display.sleep(); | |
365 } | |
366 } | |
150 | 367 |
129 | 368 shell= getShell(); |
369 if (shell is null || shell.isDisposed()) | |
370 return; | |
150 | 371 |
129 | 372 /* |
373 * Avoids flickering when replacing hovers, especially on Vista in ON_CLICK mode. | |
374 * Causes flickering on GTK. Carbon does not care. | |
375 */ | |
376 if ("win32".equals(DWT.getPlatform())) //$NON-NLS-1$ | |
377 shell.moveAbove(null); | |
150 | 378 |
129 | 379 super.setVisible(true); |
380 } | |
381 | |
382 /* | |
383 * @see dwtx.jface.text.AbstractInformationControl#setSize(int, int) | |
384 */ | |
385 public void setSize(int width, int height) { | |
386 fBrowser.setRedraw(false); // avoid flickering | |
387 try { | |
388 super.setSize(width, height); | |
389 } finally { | |
390 fBrowser.setRedraw(true); | |
391 } | |
392 } | |
393 | |
394 /** | |
395 * Creates and initializes the text layout used | |
396 * to compute the size hint. | |
150 | 397 * |
129 | 398 * @since 3.2 |
399 */ | |
400 private void createTextLayout() { | |
401 fTextLayout= new TextLayout(fBrowser.getDisplay()); | |
150 | 402 |
129 | 403 // Initialize fonts |
404 Font font= fSymbolicFontName is null ? JFaceResources.getDialogFont() : JFaceResources.getFont(fSymbolicFontName); | |
405 fTextLayout.setFont(font); | |
406 fTextLayout.setWidth(-1); | |
407 FontData[] fontData= font.getFontData(); | |
408 for (int i= 0; i < fontData.length; i++) | |
409 fontData[i].setStyle(DWT.BOLD); | |
410 font= new Font(getShell().getDisplay(), fontData); | |
411 fBoldStyle= new TextStyle(font, null, null); | |
150 | 412 |
129 | 413 // Compute and set tab width |
414 fTextLayout.setText(" "); //$NON-NLS-1$ | |
415 int tabWidth = fTextLayout.getBounds().width; | |
150 | 416 fTextLayout.setTabs([tabWidth]); |
129 | 417 |
418 fTextLayout.setText(""); //$NON-NLS-1$ | |
419 } | |
420 | |
421 /* | |
422 * @see IInformationControl#dispose() | |
423 */ | |
424 public void dispose() { | |
425 if (fTextLayout !is null) { | |
426 fTextLayout.dispose(); | |
427 fTextLayout= null; | |
428 } | |
429 if (fBoldStyle !is null) { | |
430 fBoldStyle.font.dispose(); | |
431 fBoldStyle= null; | |
432 } | |
433 fBrowser= null; | |
150 | 434 |
129 | 435 super.dispose(); |
436 } | |
437 | |
438 /* | |
439 * @see IInformationControl#computeSizeHint() | |
440 */ | |
441 public Point computeSizeHint() { | |
442 Point sizeConstraints= getSizeConstraints(); | |
443 Rectangle trim= computeTrim(); | |
444 int height= trim.height; | |
150 | 445 |
129 | 446 //FIXME: The HTML2TextReader does not render <p> like a browser. |
447 // Instead of inserting an empty line, it just adds a single line break. | |
448 // Furthermore, the indentation of <dl><dd> elements is too small (e.g with a long @see line) | |
449 TextPresentation presentation= new TextPresentation(); | |
450 HTML2TextReader reader= new HTML2TextReader(new StringReader(fInput.getHtml()), presentation); | |
451 String text; | |
452 try { | |
453 text= reader.getString(); | |
454 } catch (IOException e) { | |
455 text= ""; //$NON-NLS-1$ | |
456 } | |
457 | |
458 fTextLayout.setText(text); | |
459 fTextLayout.setWidth(sizeConstraints is null ? DWT.DEFAULT : sizeConstraints.x - trim.width); | |
460 Iterator iter= presentation.getAllStyleRangeIterator(); | |
461 while (iter.hasNext()) { | |
134 | 462 StyleRange sr= cast(StyleRange)iter.next(); |
129 | 463 if (sr.fontStyle is DWT.BOLD) |
464 fTextLayout.setStyle(fBoldStyle, sr.start, sr.start + sr.length - 1); | |
465 } | |
150 | 466 |
129 | 467 Rectangle bounds= fTextLayout.getBounds(); // does not return minimum width, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=217446 |
468 int lineCount= fTextLayout.getLineCount(); | |
469 int textWidth= 0; | |
470 for (int i= 0; i < lineCount; i++) { | |
471 Rectangle rect= fTextLayout.getLineBounds(i); | |
472 int lineWidth= rect.x + rect.width; | |
473 if (i is 0) | |
474 lineWidth += fInput.getLeadingImageWidth(); | |
475 textWidth= Math.max(textWidth, lineWidth); | |
476 } | |
477 bounds.width= textWidth; | |
478 fTextLayout.setText(""); //$NON-NLS-1$ | |
150 | 479 |
129 | 480 int minWidth= bounds.width; |
481 height= height + bounds.height; | |
150 | 482 |
129 | 483 // Add some air to accommodate for different browser renderings |
484 minWidth+= 15; | |
485 height+= 15; | |
486 | |
150 | 487 |
129 | 488 // Apply max size constraints |
489 if (sizeConstraints !is null) { | |
490 if (sizeConstraints.x !is DWT.DEFAULT) | |
491 minWidth= Math.min(sizeConstraints.x, minWidth + trim.width); | |
492 if (sizeConstraints.y !is DWT.DEFAULT) | |
493 height= Math.min(sizeConstraints.y, height); | |
494 } | |
495 | |
496 // Ensure minimal size | |
497 int width= Math.max(MIN_WIDTH, minWidth); | |
498 height= Math.max(MIN_HEIGHT, height); | |
150 | 499 |
129 | 500 return new Point(width, height); |
501 } | |
502 | |
503 /* | |
504 * @see dwtx.jface.text.IInformationControlExtension3#computeTrim() | |
505 */ | |
506 public Rectangle computeTrim() { | |
507 Rectangle trim= super.computeTrim(); | |
508 if (isResizable()) { | |
509 bool RTL= (getShell().getStyle() & DWT.RIGHT_TO_LEFT) !is 0; | |
150 | 510 if (RTL) { |
129 | 511 trim.x-= fgScrollBarSize.x; |
512 } | |
513 trim.width+= fgScrollBarSize.x; | |
514 trim.height+= fgScrollBarSize.y; | |
515 } | |
516 return trim; | |
517 } | |
150 | 518 |
129 | 519 /** |
520 * Adds the listener to the collection of listeners who will be | |
521 * notified when the current location has changed or is about to change. | |
150 | 522 * |
129 | 523 * @param listener the location listener |
524 * @since 3.4 | |
525 */ | |
526 public void addLocationListener(LocationListener listener) { | |
527 fBrowser.addLocationListener(listener); | |
528 } | |
529 | |
530 /* | |
531 * @see IInformationControl#setForegroundColor(Color) | |
532 */ | |
533 public void setForegroundColor(Color foreground) { | |
534 super.setForegroundColor(foreground); | |
535 fBrowser.setForeground(foreground); | |
536 } | |
537 | |
538 /* | |
539 * @see IInformationControl#setBackgroundColor(Color) | |
540 */ | |
541 public void setBackgroundColor(Color background) { | |
542 super.setBackgroundColor(background); | |
543 fBrowser.setBackground(background); | |
544 } | |
545 | |
546 /* | |
547 * @see IInformationControlExtension#hasContents() | |
548 */ | |
549 public bool hasContents() { | |
550 return fBrowserHasContent; | |
551 } | |
150 | 552 |
129 | 553 /** |
554 * Adds a listener for input changes to this input change provider. | |
555 * Has no effect if an identical listener is already registered. | |
150 | 556 * |
129 | 557 * @param inputChangeListener the listener to add |
558 * @since 3.4 | |
559 */ | |
560 public void addInputChangeListener(IInputChangedListener inputChangeListener) { | |
561 Assert.isNotNull(inputChangeListener); | |
562 fInputChangeListeners.add(inputChangeListener); | |
563 } | |
150 | 564 |
129 | 565 /** |
566 * Removes the given input change listener from this input change provider. | |
567 * Has no effect if an identical listener is not registered. | |
150 | 568 * |
129 | 569 * @param inputChangeListener the listener to remove |
570 * @since 3.4 | |
571 */ | |
572 public void removeInputChangeListener(IInputChangedListener inputChangeListener) { | |
573 fInputChangeListeners.remove(inputChangeListener); | |
574 } | |
150 | 575 |
129 | 576 /* |
577 * @see dwtx.jface.text.IDelayedInputChangeProvider#setDelayedInputChangeListener(dwtx.jface.text.IInputChangedListener) | |
578 * @since 3.4 | |
579 */ | |
580 public void setDelayedInputChangeListener(IInputChangedListener inputChangeListener) { | |
581 fDelayedInputChangeListener= inputChangeListener; | |
582 } | |
150 | 583 |
129 | 584 /** |
585 * Tells whether a delayed input change listener is registered. | |
150 | 586 * |
129 | 587 * @return <code>true</code> iff a delayed input change |
588 * listener is currently registered | |
589 * @since 3.4 | |
590 */ | |
591 public bool hasDelayedInputChangeListener() { | |
592 return fDelayedInputChangeListener !is null; | |
593 } | |
150 | 594 |
129 | 595 /** |
596 * Notifies listeners of a delayed input change. | |
150 | 597 * |
129 | 598 * @param newInput the new input, or <code>null</code> to request cancellation |
599 * @since 3.4 | |
600 */ | |
601 public void notifyDelayedInputChange(Object newInput) { | |
602 if (fDelayedInputChangeListener !is null) | |
603 fDelayedInputChangeListener.inputChanged(newInput); | |
604 } | |
150 | 605 |
129 | 606 /* |
607 * @see java.lang.Object#toString() | |
608 * @since 3.4 | |
609 */ | |
160 | 610 public override String toString() { |
129 | 611 String style= (getShell().getStyle() & DWT.RESIZE) is 0 ? "fixed" : "resizeable"; //$NON-NLS-1$ //$NON-NLS-2$ |
612 return super.toString() + " - style: " + style; //$NON-NLS-1$ | |
613 } | |
614 | |
615 /** | |
616 * @return the current browser input or <code>null</code> | |
617 */ | |
618 public BrowserInformationControlInput getInput() { | |
619 return fInput; | |
620 } | |
150 | 621 |
129 | 622 /* |
623 * @see dwtx.jface.text.IInformationControlExtension5#computeSizeConstraints(int, int) | |
624 */ | |
625 public Point computeSizeConstraints(int widthInChars, int heightInChars) { | |
626 if (fSymbolicFontName is null) | |
627 return null; | |
150 | 628 |
129 | 629 GC gc= new GC(fBrowser); |
630 Font font= fSymbolicFontName is null ? JFaceResources.getDialogFont() : JFaceResources.getFont(fSymbolicFontName); | |
631 gc.setFont(font); | |
632 int width= gc.getFontMetrics().getAverageCharWidth(); | |
633 int height= gc.getFontMetrics().getHeight(); | |
634 gc.dispose(); | |
150 | 635 |
129 | 636 return new Point(widthInChars * width, heightInChars * height); |
637 } | |
638 | |
639 } | |
158 | 640 |
160 | 641 ++/ |