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