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