Mercurial > projects > dwt-addons
view dwtx/ui/forms/widgets/ScrolledFormText.d @ 77:26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 24 May 2008 06:59:31 +0200 |
parents | 5d489b9f966c |
children |
line wrap: on
line source
/******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * Port to the D programming language: * Frank Benoit <benoit@tionex.de> *******************************************************************************/ module dwtx.ui.forms.widgets.ScrolledFormText; import dwtx.ui.forms.widgets.SharedScrolledComposite; import dwtx.ui.forms.widgets.FormText; import dwt.DWT; import dwt.graphics.Color; import dwt.widgets.Composite; import dwt.widgets.Control; import dwt.dwthelper.utils; import dwt.dwthelper.InputStream; /** * ScrolledFormText is a control that is capable of scrolling an instance of * the FormText class. It should be created in a parent that will allow it to * use all the available area (for example, a shell, a view or an editor). The * form text can be created by the class itself, or set from outside. In the * later case, the form text instance must be a direct child of the * ScrolledFormText instance. * <p> * The class assumes that text to be rendered contains formatting tags. In case * of a string, it will enclose the text in 'form' root element if missing from * the text as a convinience. For example: * * <pre> * ftext.setText("<p>Some text here</>"); * </pre> * * will not cause an error. The same behavior does not exist for content from * the input stream, however - it must be well formed in that case. * </p> * @since 3.0 * @see FormText */ public class ScrolledFormText : SharedScrolledComposite { private FormText content; private String text; /** * Creates the new scrolled text instance in the provided parent * * @param parent * the parent composite * @param createFormText * if <code>true</code>, enclosing form text instance will be * created in this constructor. */ public this(Composite parent, bool createFormText) { this(parent, DWT.V_SCROLL | DWT.H_SCROLL, createFormText); } /** * Creates the new scrolled text instance in the provided parent * * @param parent * the parent composite * @param style * the style to pass to the scrolled composite * @param createFormText * if <code>true</code>, enclosing form text instance will be * created in this constructor. */ public this(Composite parent, int style, bool createFormText) { super(parent, style); if (createFormText) setFormText(new FormText(this, DWT.NULL)); } /** * Sets the form text to be managed by this scrolled form text. The * instance must be a direct child of this class. If this method is used, * <code>false</code> must be passed in either of the constructors to * avoid creating form text instance. * * @param formText * the form text instance to use. */ public void setFormText(FormText formText) { this.content = formText; super.setContent(content); content.setMenu(getMenu()); if (text !is null) loadText(text); } /** * Sets the foreground color of the scrolled form text. * * @param fg * the foreground color */ public void setForeground(Color fg) { super.setForeground(fg); if (content !is null) content.setForeground(fg); } /** * Sets the background color of the scrolled form text. * * @param bg * the background color */ public void setBackground(Color bg) { super.setBackground(bg); if (content !is null) content.setBackground(bg); } /** * The class sets the content widget. This method should not be called by * classes that instantiate this widget. * * @param c * content control */ public final void setContent(Control c) { } /** * Sets the text to be rendered in the scrolled form text. The text must * contain formatting tags. * * @param text * the text to be rendered */ public void setText(String text) { this.text = text; loadText(text); reflow(true); } /** * Sets the contents to rendered in the scrolled form text. The stream must * contain formatting tags. The caller is responsible for closing the input * stream. The call may be long running. For best results, call this method * from another thread and call 'reflow' when done (but make both calls * using 'Display.asyncExec' because these calls must be made in the event * dispatching thread). * * @param is * content input stream */ public void setContents(InputStream is_) { loadContents(is_); } /** * Returns the instance of the form text. * * @return the form text instance */ public FormText getFormText() { return content; } private void loadText(String text) { if (content !is null) { String markup = text; if (!markup.startsWith("<form>")) //$NON-NLS-1$ markup = "<form>" ~ text ~ "</form>"; //$NON-NLS-1$//$NON-NLS-2$ content.setText(markup, true, false); } } private void loadContents(InputStream is_) { if (content !is null) { content.setContents(is_, false); } } }