Mercurial > projects > dwt-addons
diff dwtx/jface/internal/text/html/BrowserInformationControl.d @ 150:5cf141e43417
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 23:05:26 +0200 |
parents | 000f9136b8f7 |
children | f70d9508c95c |
line wrap: on
line diff
--- a/dwtx/jface/internal/text/html/BrowserInformationControl.d Sun Aug 24 22:41:48 2008 +0200 +++ b/dwtx/jface/internal/text/html/BrowserInformationControl.d Sun Aug 24 23:05:26 2008 +0200 @@ -78,7 +78,7 @@ * <li>focusLost event is not sent - see https://bugs.eclipse.org/bugs/show_bug.cgi?id=84532</li> * </ul> * </p> - * + * * @since 3.2 */ public class BrowserInformationControl : AbstractInformationControl , IInformationControlExtension2, IDelayedInputChangeProvider { @@ -97,7 +97,7 @@ Browser browser= new Browser(parent, DWT.NONE); browser.dispose(); fgIsAvailable= true; - + Slider sliderV= new Slider(parent, DWT.VERTICAL); Slider sliderH= new Slider(parent, DWT.HORIZONTAL); int width= sliderV.computeSize(DWT.DEFAULT, DWT.DEFAULT).x; @@ -123,7 +123,7 @@ private static const int MIN_WIDTH= 80; private static const int MIN_HEIGHT= 50; - + /** * Availability checking cache. */ @@ -135,7 +135,7 @@ * @since 3.4 */ private static Point fgScrollBarSize; - + /** The control's browser widget */ private Browser fBrowser; /** Tells whether the browser has content */ @@ -175,7 +175,7 @@ /** * Creates a browser information control with the given shell as parent. - * + * * @param parent the parent shell * @param symbolicFontName the symbolic name of the font used for size computations * @param resizable <code>true</code> if the control should be resizable @@ -186,10 +186,10 @@ fSymbolicFontName= symbolicFontName; create(); } - + /** * Creates a browser information control with the given shell as parent. - * + * * @param parent the parent shell * @param symbolicFontName the symbolic name of the font used for size computations * @param statusFieldText the text to be used in the optional status field @@ -201,10 +201,10 @@ fSymbolicFontName= symbolicFontName; create(); } - + /** * Creates a browser information control with the given shell as parent. - * + * * @param parent the parent shell * @param symbolicFontName the symbolic name of the font used for size computations * @param toolBarManager the manager or <code>null</code> if toolbar is not desired @@ -215,13 +215,13 @@ fSymbolicFontName= symbolicFontName; create(); } - + /* * @see dwtx.jface.text.AbstractInformationControl#createContent(dwt.widgets.Composite) */ protected void createContent(Composite parent) { fBrowser= new Browser(parent, DWT.NONE); - + Display display= getShell().getDisplay(); fBrowser.setForeground(display.getSystemColor(DWT.COLOR_INFO_FOREGROUND)); fBrowser.setBackground(display.getSystemColor(DWT.COLOR_INFO_BACKGROUND)); @@ -240,10 +240,10 @@ fCompleted= true; } }); - + // Replace browser's built-in context menu with none fBrowser.setMenu(new Menu(getShell(), DWT.NONE)); - + createTextLayout(); } @@ -266,13 +266,13 @@ } }); } - + /** * {@inheritDoc} This control can handle {@link String} and * {@link BrowserInformationControlInput}. */ public void setInput(Object input) { - Assert.isLegal(input is null || cast(String)input || input instanceof BrowserInformationControlInput); + Assert.isLegal(input is null || cast(String)input || cast(BrowserInformationControlInput)input ); if ( cast(String)input ) { setInformation(cast(String)input); @@ -280,11 +280,11 @@ } fInput= cast(BrowserInformationControlInput)input; - + String content= null; if (fInput !is null) content= fInput.getHtml(); - + fBrowserHasContent= content !is null && content.length() > 0; if (!fBrowserHasContent) @@ -297,29 +297,29 @@ // and the re-wrapping would cause visual noise String[] styles= null; if (RTL && resizable) - styles= new String[] { "direction:rtl;", "overflow:scroll;", "word-wrap:break-word;" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + styles= [ "direction:rtl;", "overflow:scroll;", "word-wrap:break-word;" ]; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ else if (RTL && !resizable) - styles= new String[] { "direction:rtl;", "overflow:hidden;", "word-wrap:break-word;" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + styles= [ "direction:rtl;", "overflow:hidden;", "word-wrap:break-word;" ]; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ else if (!resizable) //XXX: In IE, "word-wrap: break-word;" causes bogus wrapping even in non-broken words :-(see e.g. Javadoc of String). // Re-check whether we really still need this now that the Javadoc Hover header already sets this style. - styles= new String[] { "overflow:hidden;"/*, "word-wrap: break-word;"*/ }; //$NON-NLS-1$ + styles= [ "overflow:hidden;"/*, "word-wrap: break-word;"*/ ]; //$NON-NLS-1$ else - styles= new String[] { "overflow:scroll;" }; //$NON-NLS-1$ - + styles= [ "overflow:scroll;" ]; //$NON-NLS-1$ + StringBuffer buffer= new StringBuffer(content); HTMLPrinter.insertStyles(buffer, styles); content= buffer.toString(); - + /* * XXX: Should add some JavaScript here that shows something like * "(continued...)" or "..." at the end of the visible area when the page overflowed * with "overflow:hidden;". */ - + fCompleted= false; fBrowser.setText(content); - + Object[] listeners= fInputChangeListeners.getListeners(); for (int i= 0; i < listeners.length; i++) (cast(IInputChangedListener)listeners[i]).inputChanged(fInput); @@ -332,45 +332,45 @@ Shell shell= getShell(); if (shell.isVisible() is visible) return; - + if (!visible) { super.setVisible(false); setInput(null); return; } - + /* * The Browser widget flickers when made visible while it is not completely loaded. * The fix is to delay the call to setVisible until either loading is completed * (see ProgressListener in constructor), or a timeout has been reached. */ final Display display= shell.getDisplay(); - + // Make sure the display wakes from sleep after timeout: display.timerExec(100, new class() Runnable { public void run() { fCompleted= true; } }); - + while (!fCompleted) { // Drive the event loop to process the events required to load the browser widget's contents: if (!display.readAndDispatch()) { display.sleep(); } } - + shell= getShell(); if (shell is null || shell.isDisposed()) return; - + /* * Avoids flickering when replacing hovers, especially on Vista in ON_CLICK mode. * Causes flickering on GTK. Carbon does not care. */ if ("win32".equals(DWT.getPlatform())) //$NON-NLS-1$ shell.moveAbove(null); - + super.setVisible(true); } @@ -389,12 +389,12 @@ /** * Creates and initializes the text layout used * to compute the size hint. - * + * * @since 3.2 */ private void createTextLayout() { fTextLayout= new TextLayout(fBrowser.getDisplay()); - + // Initialize fonts Font font= fSymbolicFontName is null ? JFaceResources.getDialogFont() : JFaceResources.getFont(fSymbolicFontName); fTextLayout.setFont(font); @@ -404,11 +404,11 @@ fontData[i].setStyle(DWT.BOLD); font= new Font(getShell().getDisplay(), fontData); fBoldStyle= new TextStyle(font, null, null); - + // Compute and set tab width fTextLayout.setText(" "); //$NON-NLS-1$ int tabWidth = fTextLayout.getBounds().width; - fTextLayout.setTabs(new int[] {tabWidth}); + fTextLayout.setTabs([tabWidth]); fTextLayout.setText(""); //$NON-NLS-1$ } @@ -426,7 +426,7 @@ fBoldStyle= null; } fBrowser= null; - + super.dispose(); } @@ -437,7 +437,7 @@ Point sizeConstraints= getSizeConstraints(); Rectangle trim= computeTrim(); int height= trim.height; - + //FIXME: The HTML2TextReader does not render <p> like a browser. // Instead of inserting an empty line, it just adds a single line break. // Furthermore, the indentation of <dl><dd> elements is too small (e.g with a long @see line) @@ -458,7 +458,7 @@ if (sr.fontStyle is DWT.BOLD) fTextLayout.setStyle(fBoldStyle, sr.start, sr.start + sr.length - 1); } - + Rectangle bounds= fTextLayout.getBounds(); // does not return minimum width, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=217446 int lineCount= fTextLayout.getLineCount(); int textWidth= 0; @@ -471,15 +471,15 @@ } bounds.width= textWidth; fTextLayout.setText(""); //$NON-NLS-1$ - + int minWidth= bounds.width; height= height + bounds.height; - + // Add some air to accommodate for different browser renderings minWidth+= 15; height+= 15; - + // Apply max size constraints if (sizeConstraints !is null) { if (sizeConstraints.x !is DWT.DEFAULT) @@ -491,7 +491,7 @@ // Ensure minimal size int width= Math.max(MIN_WIDTH, minWidth); height= Math.max(MIN_HEIGHT, height); - + return new Point(width, height); } @@ -502,7 +502,7 @@ Rectangle trim= super.computeTrim(); if (isResizable()) { bool RTL= (getShell().getStyle() & DWT.RIGHT_TO_LEFT) !is 0; - if cast(RTL) { + if (RTL) { trim.x-= fgScrollBarSize.x; } trim.width+= fgScrollBarSize.x; @@ -510,11 +510,11 @@ } return trim; } - + /** * Adds the listener to the collection of listeners who will be * notified when the current location has changed or is about to change. - * + * * @param listener the location listener * @since 3.4 */ @@ -544,11 +544,11 @@ public bool hasContents() { return fBrowserHasContent; } - + /** * Adds a listener for input changes to this input change provider. * Has no effect if an identical listener is already registered. - * + * * @param inputChangeListener the listener to add * @since 3.4 */ @@ -556,18 +556,18 @@ Assert.isNotNull(inputChangeListener); fInputChangeListeners.add(inputChangeListener); } - + /** * Removes the given input change listener from this input change provider. * Has no effect if an identical listener is not registered. - * + * * @param inputChangeListener the listener to remove * @since 3.4 */ public void removeInputChangeListener(IInputChangedListener inputChangeListener) { fInputChangeListeners.remove(inputChangeListener); } - + /* * @see dwtx.jface.text.IDelayedInputChangeProvider#setDelayedInputChangeListener(dwtx.jface.text.IInputChangedListener) * @since 3.4 @@ -575,10 +575,10 @@ public void setDelayedInputChangeListener(IInputChangedListener inputChangeListener) { fDelayedInputChangeListener= inputChangeListener; } - + /** * Tells whether a delayed input change listener is registered. - * + * * @return <code>true</code> iff a delayed input change * listener is currently registered * @since 3.4 @@ -586,10 +586,10 @@ public bool hasDelayedInputChangeListener() { return fDelayedInputChangeListener !is null; } - + /** * Notifies listeners of a delayed input change. - * + * * @param newInput the new input, or <code>null</code> to request cancellation * @since 3.4 */ @@ -597,7 +597,7 @@ if (fDelayedInputChangeListener !is null) fDelayedInputChangeListener.inputChanged(newInput); } - + /* * @see java.lang.Object#toString() * @since 3.4 @@ -613,21 +613,21 @@ public BrowserInformationControlInput getInput() { return fInput; } - + /* * @see dwtx.jface.text.IInformationControlExtension5#computeSizeConstraints(int, int) */ public Point computeSizeConstraints(int widthInChars, int heightInChars) { if (fSymbolicFontName is null) return null; - + GC gc= new GC(fBrowser); Font font= fSymbolicFontName is null ? JFaceResources.getDialogFont() : JFaceResources.getFont(fSymbolicFontName); gc.setFont(font); int width= gc.getFontMetrics().getAverageCharWidth(); int height= gc.getFontMetrics().getHeight(); gc.dispose(); - + return new Point(widthInChars * width, heightInChars * height); }