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