[Mono-list] some WinForms additions
Remco de Jong
rdj@rdj.cg.nu
07 Aug 2002 00:26:26 +0200
--=-zybZQT3rHA77GoPLgWK5
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi,
I don't know how to include all the new files in a patch so I added them
as attachments. They belong in the mcs/class/System.Windows.Forms/Gtk
directory, the patch should be applied here too. It adds a ProgressBar
and a TextBox, neither one of them is fully complete though, it's work
in progress. I'll probably resend a more complete patch later, but for
those interested, here it is.
--
Remco de Jong <rdj@rdj.cg.nu>
--=-zybZQT3rHA77GoPLgWK5
Content-Disposition: attachment; filename=HorizontalAlignment.cs
Content-Type: text/plain; name=HorizontalAlignment.cs; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
//
// System.Windows.Forms.HorizontalAlignment.cs
//
// Author:
// Dennis Hayes (dennish@raytek.com)
// (C) 2002 Ximian, Inc. http://www.ximian.com
//
using System;
namespace System.Windows.Forms {
/// <summary>
/// </summary>
public enum HorizontalAlignment {
Center = 2,
Left = 0,
Right = 1
}
}
--=-zybZQT3rHA77GoPLgWK5
Content-Disposition: attachment; filename=ProgressBar.cs
Content-Type: text/plain; name=ProgressBar.cs; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
//
// System.Windows.Forms.ProgressBar
//
// Author:
// stubbed out by Jaak Simm (jaaksimm@firm.ee)
// Remco de Jong (rdj@rdj.cg.nu)
//
// (C) Ximian, Inc., 2002
//
using System.Drawing;
using System.Drawing.Printing;
using System.ComponentModel;
namespace System.Windows.Forms {
/// <summary>
/// Represents a Windows progress bar control.
///
/// </summary>
[MonoTODO]
public sealed class ProgressBar : Control {
#region Fields
private int maximum;
private int minimum;
private int step;
private int val;
#endregion
#region Constructor
[MonoTODO]
public ProgressBar()
{
maximum=100;
minimum=0;
step=10;
val=0;
}
#endregion
internal override Gtk.Widget CreateWidget () {
Gtk.ProgressBar pbar = new Gtk.ProgressBar ();
return pbar;
}
/* #region Properties
[MonoTODO]
public override bool AllowDrop {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
[MonoTODO]
public override Color BackColor {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
[MonoTODO]
public override Color ForeColor {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
[MonoTODO]
public override Image BackgroundImage {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
*/
/// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
/// public new bool CausesValidation {get; set;}
/* [MonoTODO]
protected override CreateParams CreateParams {
get { throw new NotImplementedException (); }
}
[MonoTODO]
protected override ImeMode DefaultImeMode {
get { throw new NotImplementedException (); }
}
[MonoTODO]
protected override Size DefaultSize {
get { throw new NotImplementedException (); }
}
[MonoTODO]
public override Font Font {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
*/
/// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
/// public new ImeMode ImeMode {get; set;}
public int Maximum {
get {
return maximum;
}
set {
maximum=value;
}
}
public int Minimum {
get {
return minimum;
}
set {
minimum=value;
}
}
/// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
/// public new bool TabStop {get; set;}
/* [MonoTODO]
public override RightToLeft RightToLeft {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
*/
public int Step {
get {
return step;
}
set {
step=value;
}
}
protected override void OnTextChanged(EventArgs e)
{
((Gtk.ProgressBar)Widget).Text = Text;
}
public int Value {
get {
return val;
}
set {
if (val <= maximum) {
val=value;
float fraction = ((float) val / (float) maximum);
((Gtk.ProgressBar)Widget).Fraction = fraction;
}
}
}
// #endregion
/* #region Methods
[MonoTODO]
protected override void CreateHandle()
{
throw new NotImplementedException ();
}
*/
[MonoTODO]
public void Increment(int value)
{
Value += value;
}
/* [MonoTODO]
protected override void OnHandleCreated(EventArgs e)
{
throw new NotImplementedException ();
}
*/
[MonoTODO]
public void PerformStep()
{
Value += step;
}
[MonoTODO]
public override string ToString()
{
throw new NotImplementedException ();
}
// #endregion
#region Events
/*
* This member supports the .NET Framework infrastructure and is not intended to be used directly from your code:
public new event EventHandler DoubleClick;
public new event EventHandler Enter;
public new event KeyEventHandler KeyDown;
public new event KeyPressEventHandler KeyPress;
public new event KeyEventHandler KeyUp;
public new event EventHandler Leave;
public new event PaintEventHandler Paint;
*/
#endregion
}
}
--=-zybZQT3rHA77GoPLgWK5
Content-Disposition: attachment; filename=ScrollBars.cs
Content-Type: text/plain; name=ScrollBars.cs; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
//
// System.Windows.Forms.ScrollBars.cs
//
// Author:
// Dennis Hayes (dennish@raytek.com)
// (C) 2002 Ximian, Inc. http://www.ximian.com
//
using System;
namespace System.Windows.Forms {
/// <summary>
/// </summary>
public enum ScrollBars {
Both = 3,
Horizontal = 1,
None = 0,
Vertical = 2
}
}
--=-zybZQT3rHA77GoPLgWK5
Content-Disposition: attachment; filename=TextBox.cs
Content-Type: text/plain; name=TextBox.cs; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
//
// System.Windows.Forms.TextBox
//
// Author:
// stubbed out by Jackson Harper (jackson@latitudegeo.com)
// Dennis Hayes (dennish@raytek.com)
// Remco de Jong (rdj@rdj.cg.nu)
//
// (C) 2002 Ximian, Inc
//
namespace System.Windows.Forms {
// <summary>
// This is only a template. Nothing is implemented yet.
//
// </summary>
public class TextBox : TextBoxBase {
private Gtk.TextView textview;
private ScrollBars scrollbars;
private HorizontalAlignment textalign;
private bool wordwrap;
//
// --- Public Constructor
//
public TextBox() {
scrollbars = ScrollBars.None;
}
internal override Gtk.Widget CreateWidget () {
// needs to initialized with a textbuffer from TextBoxBase
// we need default adjustments, but the scrolledwindow constructor does not take null as argument
Gtk.ScrolledWindow window = new Gtk.ScrolledWindow (new Gtk.Adjustment (IntPtr.Zero), new Gtk.Adjustment (IntPtr.Zero));
window.SetPolicy(Gtk.PolicyType.Never, Gtk.PolicyType.Never);
window.AddWithViewport(TextView);
return window;
}
// --- Public Properties
public override bool ReadOnly {
get
{
return !TextView.Editable;
}
set
{
if (value == TextView.Editable) { // only change if value is different, correct behaviour?
TextView.Editable = !value;
OnReadOnlyChanged(EventArgs.Empty);
}
}
}
[MonoTODO]
public bool AcceptsReturn {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
[MonoTODO]
/* public CharacterCasing CharacterCasing {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
*/ [MonoTODO]
public char PasswordChar {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
public ScrollBars ScrollBars {
get {
return scrollbars;
}
set {
scrollbars = value;
Gtk.PolicyType vpolicy = Gtk.PolicyType.Never; // correct behaviour?
Gtk.PolicyType hpolicy = Gtk.PolicyType.Never;
if (scrollbars == ScrollBars.Both) {
vpolicy = Gtk.PolicyType.Always;
hpolicy = Gtk.PolicyType.Always;
}
else if (scrollbars == ScrollBars.Horizontal) {
hpolicy = Gtk.PolicyType.Always;
}
else if (scrollbars == ScrollBars.Vertical) {
vpolicy = Gtk.PolicyType.Always;
}
((Gtk.ScrolledWindow) Widget).SetPolicy(hpolicy, vpolicy);
}
}
public HorizontalAlignment TextAlign {
get
{
return textalign;
}
set
{
Gtk.Justification justification = Gtk.Justification.Left;
if (value == HorizontalAlignment.Center) {
justification = Gtk.Justification.Center;
}
else if (value == HorizontalAlignment.Right) {
justification = Gtk.Justification.Right;
}
TextView.Justification = justification;
textalign = value;
OnTextAlignChanged(EventArgs.Empty);
}
}
public override bool WordWrap {
get
{
return wordwrap;
}
set
{
Gtk.WrapMode wrapmode = Gtk.WrapMode.None;
wordwrap = value;
if (wordwrap)
wrapmode = Gtk.WrapMode.Word;
TextView.WrapMode = wrapmode;
}
}
// --- Public Events
public event EventHandler TextAlignChanged;
// --- Protected Properties
/* [MonoTODO]
protected override CreateParams CreateParams {
get
{
throw new NotImplementedException ();
}
}
[MonoTODO]
protected override ImeMode DefaultImeMode {
get
{
throw new NotImplementedException ();
}
}
*/
// --- Protected Members
protected Gtk.TextView TextView {
get {
if (textview == null) {
textview = new Gtk.TextView(TextBuffer);
textview.Show();
}
return textview;
}
}
/* protected override bool IsInputKey(Keys keyData)
{
throw new NotImplementedException ();
}
[MonoTODO]
protected override void OnHandleCreated(EventArgs e)
{
throw new NotImplementedException ();
}
[MonoTODO]
protected override void OnMouseUp(MouseEventArgs mevent)
{
throw new NotImplementedException ();
}
*/
protected virtual void OnTextAlignChanged(EventArgs e)
{
if (TextAlignChanged != null)
TextAlignChanged (this, e);
}
/* [MonoTODO]
protected override void WndProc(ref Message m)
{
throw new NotImplementedException ();
}
*/ }
}
--=-zybZQT3rHA77GoPLgWK5
Content-Disposition: attachment; filename=TextBoxBase.cs
Content-Type: text/plain; name=TextBoxBase.cs; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
//
// System.Windows.Forms.TextBoxBase
//
// Author:
// stubbed out by Jackson Harper (jackson@latitudegeo.com)
// Dennis Hayes (dennish@raytek.com)
// Remco de Jong (rdj@rdj.cg.nu)
//
// (C) 2002 Ximian, Inc
//
using System.Drawing;
namespace System.Windows.Forms {
// <summary>
// This is only a template. Nothing is implemented yet.
//
// </summary>
public class TextBoxBase : Control {
private int maxlength = 0;
private Gtk.TextTagTable tagtable;
private Gtk.TextBuffer textbuffer = null;
//
// --- Public Properties
//
public TextBoxBase () {
}
protected Gtk.TextBuffer TextBuffer {
get {
if (textbuffer == null) {
tagtable = new Gtk.TextTagTable ();
textbuffer = new Gtk.TextBuffer (tagtable);
// attach events
textbuffer.ModifiedChanged += new EventHandler (modified_changed_cb);
}
return textbuffer;
}
}
protected override void OnTextChanged(EventArgs e)
{
TextBuffer.SetText(Text, Text.Length);
}
[MonoTODO]
public bool AcceptsTab {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
[MonoTODO]
public virtual bool AutoSize {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
/* [MonoTODO]
public override Color BackColor {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
[MonoTODO]
public override Color ForeColor {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
[MonoTODO]
public override Image BackgroundImage {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
[MonoTODO]
public BorderStyle BorderStyle {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
*/ [MonoTODO]
public bool CanUndo {
get
{
throw new NotImplementedException ();
}
}
[MonoTODO]
public bool HideSelection {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
[MonoTODO]
public string[] Lines {
get
{
throw new NotImplementedException ();
}
set
{
Clear ();
foreach (String s in value) {
AppendText (s + "\n");
}
}
}
[MonoTODO]
public virtual int MaxLength {
get
{
return maxlength;
}
set
{
maxlength = value;
}
}
public bool Modified {
get
{
return TextBuffer.Modified;
}
set
{
if (TextBuffer.Modified != value) { // only call if it has really been changed since this will trigger an event, is this correct behavior?
TextBuffer.Modified = value;
}
}
}
[MonoTODO]
public virtual bool Multiline {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
[MonoTODO]
public int PreferredHeight {
get
{
throw new NotImplementedException ();
}
}
public virtual bool ReadOnly {
// needs to be overwritten by child classes
get { return false; }
set {}
}
[MonoTODO]
public virtual string SelectedText {
get
{
String selection = "";
Gtk.TextIter start;
Gtk.TextIter end;
if (TextBuffer.GetSelectionBounds(ref start, ref end))
selection = TextBuffer.GetText(start, end, true);
return selection;
}
set
{
// paste text over selection
}
}
[MonoTODO]
public virtual int SelectionLength {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
[MonoTODO]
public int SelectionStart {
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
[MonoTODO]
public virtual int TextLength {
get
{
return Text.Length;
}
}
[MonoTODO]
public virtual bool WordWrap {
get
{
return false;
}
set
{
}
}
// --- Public Methods
public void AppendText(string text)
{
Text += text;
}
public void Clear()
{
TextBuffer.SetText("", 0);
}
[MonoTODO]
public void ClearUndo()
{
throw new NotImplementedException ();
}
[MonoTODO]
public void Copy()
{
throw new NotImplementedException ();
}
[MonoTODO]
public void Cut()
{
throw new NotImplementedException ();
}
[MonoTODO]
public void Paste()
{
throw new NotImplementedException ();
}
[MonoTODO]
public void ScrollToCaret()
{
throw new NotImplementedException ();
}
[MonoTODO]
public void Select(int start, int length)
{
throw new NotImplementedException ();
}
[MonoTODO]
public void SelectAll()
{
throw new NotImplementedException ();
}
[MonoTODO]
public override string ToString()
{
throw new NotImplementedException ();
}
[MonoTODO]
public void Undo()
{
throw new NotImplementedException ();
}
// --- Internal Events (Gtk)
internal protected void modified_changed_cb (object o, EventArgs args)
{
OnModifiedChanged (EventArgs.Empty);
}
// --- Public Events
[MonoTODO]
public event EventHandler AcceptsTabChanged;
[MonoTODO]
public event EventHandler AutoSizeChanged;
[MonoTODO]
public event EventHandler BorderStyleChanged;
[MonoTODO]
//public override event EventHandler Click;
[MonoTODO]
public event EventHandler HideSelectionChanged;
public event EventHandler ModifiedChanged;
[MonoTODO]
public event EventHandler MultilineChanged;
public event EventHandler ReadOnlyChanged;
// --- Protected Properties
/*
[MonoTODO]
protected override CreateParams CreateParams {
get
{
throw new NotImplementedException ();
}
}
[MonoTODO]
protected override Size DefaultSize {
get
{
throw new NotImplementedException ();
}
}
// --- Protected Methods
[MonoTODO]
protected override void CreateHandle()
{
throw new NotImplementedException ();
}
*/
[MonoTODO]
/* protected override bool IsInputKey(Keys keyData)
{
throw new NotImplementedException ();
}
*/ [MonoTODO]
protected virtual void OnAcceptsTabChanged(EventArgs e)
{
throw new NotImplementedException ();
}
[MonoTODO]
protected virtual void OnAutoSizeChanged(EventArgs e)
{
throw new NotImplementedException ();
}
[MonoTODO]
protected virtual void OnBorderStyleChanged(EventArgs e)
{
throw new NotImplementedException ();
}
/*
[MonoTODO]
protected override void OnFontChanged(EventArgs e)
{
throw new NotImplementedException ();
}
[MonoTODO]
protected override void OnHandleCreated(EventArgs e)
{
throw new NotImplementedException ();
}
[MonoTODO]
protected override void OnHandleDestroyed(EventArgs e)
{
throw new NotImplementedException ();
}
*/
[MonoTODO]
protected virtual void OnHideSelectionChanged(EventArgs e)
{
throw new NotImplementedException ();
}
[MonoTODO]
protected virtual void OnModifiedChanged(EventArgs e)
{
if (ModifiedChanged != null)
ModifiedChanged (this, e);
}
[MonoTODO]
protected virtual void OnMultilineChanged(EventArgs e)
{
throw new NotImplementedException ();
}
protected virtual void OnReadOnlyChanged(EventArgs e)
{
if (ReadOnlyChanged != null)
ReadOnlyChanged (this, e);
}
/* [MonoTODO]
protected override bool ProcessDialogKey(Keys keyData)
{
throw new NotImplementedException ();
}
[MonoTODO]
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
throw new NotImplementedException ();
}
[MonoTODO]
protected override void WndProc(ref Message m)
{
throw new NotImplementedException ();
}
*/ }
}
--=-zybZQT3rHA77GoPLgWK5
Content-Disposition: attachment; filename=winforms.patch
Content-Type: text/plain; name=winforms.patch; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
? HorizontalAlignment.cs
? ProgressBar.cs
? ScrollBars.cs
? TextBox.cs
? TextBoxBase.cs
Index: Control.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/Gtk/Control.cs,v
retrieving revision 1.3
diff -u -r1.3 Control.cs
--- Control.cs 30 Jun 2002 21:21:54 -0000 1.3
+++ Control.cs 6 Aug 2002 21:57:20 -0000
@@ -19,12 +19,15 @@
public class Control : Component {
internal Widget widget;
Control parent;
- string text;
- int left, top, width, height;
+ private string text;
+ private int left, top, width, height;
ControlCollection controls = CreateControlsInstance ();
Point location = new Point (0, 0);
Gtk.Layout layout = null;
AnchorStyles anchor = AnchorStyles.Top|AnchorStyles.Left;
+ private Color backcolor;
+ private Color forecolor;
+ private Image backgroundimage;
static int init_me;
@@ -155,6 +158,26 @@
return layout;
}
+ public int Width {
+ get {
+ return width;
+ }
+ set {
+ width = value;
+ Widget.WidthRequest = width;
+ }
+ }
+
+ public int Height {
+ get {
+ return height;
+ }
+ set {
+ width = value;
+ Widget.HeightRequest = width;
+ }
+ }
+
public virtual string Text {
get {
return text;
@@ -235,6 +258,21 @@
ControlRemoved (this, e);
}
+ public virtual Image BackgroundImage {
+ get { return backgroundimage; }
+ set { backgroundimage = value; }
+ }
+
+ public virtual Color BackColor {
+ get { return backcolor; }
+ set { backcolor = value; }
+ }
+
+ public virtual Color ForeColor {
+ get { return forecolor; }
+ set { forecolor = value; }
+ }
+
public Point Location {
get { return location; }
set {
@@ -261,6 +299,7 @@
public virtual AnchorStyles Anchor {
get { return anchor; }
set { anchor=value; }
- }
+ }
+
}
}
Index: demo.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/Gtk/demo.cs,v
retrieving revision 1.4
diff -u -r1.4 demo.cs
--- demo.cs 30 Jun 2002 21:21:55 -0000 1.4
+++ demo.cs 6 Aug 2002 21:57:21 -0000
@@ -3,9 +3,15 @@
using System.Windows.Forms;
class X {
+
+ public static ProgressBar p;
+ public static TextBox tb;
+
static void Clicked (object o, EventArgs args)
{
- Console.WriteLine ("the button was clicked");
+ p.PerformStep();
+ if (tb.SelectedText.Length > 0)
+ Console.WriteLine(tb.SelectedText);
}
static void Demo_Window ()
@@ -24,6 +30,26 @@
b.Location = new Point (20, 60);
b.Click += new EventHandler (Clicked);
form.Controls.Add (b);
+
+ p = new ProgressBar();
+ p.Location = new Point(20, 100);
+ p.Text = "a progressbar";
+ p.Maximum = 20;
+ p.Step = 1;
+ p.Value = 0;
+ form.Controls.Add(p);
+
+ tb = new TextBox();
+ tb.Location = new Point(20, 140);
+ tb.Width = 200;
+ tb.Height = 100;
+ tb.Text = "a TextBox\n";
+ tb.AppendText("This is a somewhat long line with a lot of useless words so it will wrap");
+ tb.ScrollBars = ScrollBars.Vertical;
+ tb.ReadOnly = false;
+ tb.WordWrap = true;
+ tb.TextAlign = HorizontalAlignment.Center;
+ form.Controls.Add(tb);
form.Visible = true;
Index: makefile
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/Gtk/makefile,v
retrieving revision 1.3
diff -u -r1.3 makefile
--- makefile 30 Jun 2002 21:21:55 -0000 1.3
+++ makefile 6 Aug 2002 21:57:21 -0000
@@ -2,6 +2,11 @@
SWFF=-r gtk-sharp -r glib-sharp -r System.Drawing
SOURCES = \
+ ScrollBars.cs \
+ TextBoxBase.cs \
+ TextBox.cs \
+ HorizontalAlignment.cs \
+ ProgressBar.cs \
AnchorStyles.cs \
Application.cs \
ContainerControl.cs \
--=-zybZQT3rHA77GoPLgWK5--