Browse Source

Added statusbar support and fixed the vbox used for packing the menu and other special Controls

svn path=/trunk/mcs/; revision=15828
Philip Van Hoof 22 years ago
parent
commit
8a1df3bec7

+ 1 - 1
mcs/class/System.Windows.Forms/Gtk/ContainerControl.cs

@@ -111,4 +111,4 @@ namespace System.Windows.Forms
 //			throw new NotImplementedException ();
 //		}
 	}
-}
+}

+ 29 - 11
mcs/class/System.Windows.Forms/Gtk/Control.cs

@@ -30,6 +30,7 @@ namespace System.Windows.Forms {
 		bool tabStop=true;
 		static int init_me;
 		RightToLeft rightToLeft;
+		protected Gtk.VBox vbox = null;
 
 		public class ControlCollection : IList, ICollection, IEnumerable, ICloneable 
 		{
@@ -46,21 +47,38 @@ namespace System.Windows.Forms {
 			}
 
 			// ControlCollection
-			public virtual void Add (Control value, bool doevent) {
-				if (doevent == true) {
-					this.Add (value);
-					return;
+			public virtual void Add (Control value)
+			{
+				if (value.GetType() == typeof(System.Windows.Forms.StatusBar))
+				{
+					this.owner.vbox.PackEnd(value.widget, false, false, 0);
+					// this.vbox.ReorderChild (value.widget, 0);
+					this.owner.vbox.ShowAll();
+					list.Add (value);
+				}
+				else if (value.GetType() == typeof(System.Windows.Forms.MainMenu))
+				{
+					MainMenu m = (MainMenu)value;
+					this.owner.vbox.PackStart(m.mb, false, false, 0);
+					m.mb.ShowAll();
+					this.owner.vbox.ReorderChild (m.mb, 0);
+					this.owner.vbox.ShowAll();
+					list.Add (value);
+				}
+				else {
+					list.Add (value);
+					owner.OnControlAdded (new ControlEventArgs (value));
 				}
-				list.Add(value);
-			}
-			public virtual void Add (Control value) {
-				list.Add (value);
-				owner.OnControlAdded (new ControlEventArgs (value));
 			}
 			public virtual void AddRange (Control[] controls) {
-				list.AddRange (controls);
+				// Because we really do have to check for a few
+				// special cases we cannot use the AddRange and
+				// will have to check each Control that we add
+
+				// list.AddRange (controls);
 				foreach (Control c in controls) 
-					owner.OnControlAdded (new ControlEventArgs (c));
+					this.Add (c);
+				// owner.OnControlAdded (new ControlEventArgs (c));
 			}
 			
 			public bool Contains (Control value) { return list.Contains (value); }

+ 51 - 42
mcs/class/System.Windows.Forms/Gtk/Demo2.cs

@@ -7,14 +7,14 @@
 //
 
 using System;
-using System.Drawing;
-using System.Windows.Forms;
- 
-namespace demo2
-{
-	
-	public class GtkForm : System.Windows.Forms.Form
-	{
+using System.Drawing;
+using System.Windows.Forms;
+ 
+namespace demo2
+{
+	
+	public class GtkForm : System.Windows.Forms.Form
+	{
 		private Button button1 = new Button(); 
 		private Button button2 = new Button();
 		private ColorDialog color1 = new ColorDialog();
@@ -25,21 +25,28 @@ namespace demo2
 		private MenuItem menuItem3 = new MenuItem();
 		private MenuItem menuItem4 = new MenuItem();
 		private MenuItem menuItem5 = new MenuItem();
- 
-		private void InitializeWidgets()
-		{
-			button1.Location = new Point(150, 28);
-			button1.Name = "button1";
-			button1.Size = new Size(128, 44);
-			button1.Text = "Color";
-			button1.Click += new EventHandler(this.button1_Click);    
+		private StatusBar statusBar1 = new StatusBar();
+
+		private void InitializeWidgets()
+		{
+                        this.statusBar1.Location = new System.Drawing.Point(0, 251);
+                        this.statusBar1.Name = "statusBar1";
+                        this.statusBar1.Size = new System.Drawing.Size(292, 22);
+                        this.statusBar1.TabIndex = 0;
+                        this.statusBar1.Text = "statusBar1";
+
+			button1.Location = new Point(150, 28);
+			button1.Name = "button1";
+			button1.Size = new Size(128, 44);
+			button1.Text = "Color";
+			button1.Click += new EventHandler(this.button1_Click);    
 		 	button1.Enabled = true;
 
-			button2.Location = new Point(150, 80);
-			button2.Name = "button2";
-			button2.Size = new Size(128, 44);
-			button2.Text = "Add to ComboBox";
-			button2.Click += new EventHandler(this.button2_Click);    
+			button2.Location = new Point(150, 80);
+			button2.Name = "button2";
+			button2.Size = new Size(128, 44);
+			button2.Text = "Add to ComboBox";
+			button2.Click += new EventHandler(this.button2_Click);    
 		 	button2.Enabled = true;
 
 			menuItem1.Text = "File";
@@ -68,25 +75,26 @@ namespace demo2
 									    this.button1,
 									    this.button2,
 									    this.color1,
-									    this.combo1});
-
+									    this.combo1, 
+									    this.statusBar1});
+
 			this.Size = new Size(512, 250);
-			this.Menu = mainMenu1;
-		}
-
-		public GtkForm()
-		{
+			this.Menu = mainMenu1;
+		}
+
+		public GtkForm()
+		{
 			InitializeWidgets();
-		}
-
+		}
+
 		private void button1_Click(object sender, EventArgs e){ 
-			color1.ShowDialog();			
+			color1.ShowDialog();			
   		}
 
 		private void button2_Click(object sender, EventArgs e){ 
 			combo1.BeginUpdate();
 			for (int i = 1; i < 5; i++) {combo1.Items.Add("Joel");}
-			combo1.EndUpdate();	
+			combo1.EndUpdate();	
   		}
 		private void  menuItem2_Click (object sender, EventArgs e){
 			MessageBox.Show("You clicked Exit");
@@ -97,14 +105,15 @@ namespace demo2
 		}
 
 	}
-	
-	public class GtkMain
-	{
-		public static void Main()
-		{
-			GtkForm form1 = new GtkForm ();
-			form1.Text = "System.Windows.Forms at work!";			
-			Application.Run(form1);
-		}
-	}
+	
+	public class GtkMain
+	{
+		[STAThread]
+		public static void Main()
+		{
+			GtkForm form1 = new GtkForm ();
+			form1.Text = "System.Windows.Forms at work!";			
+			Application.Run(form1);
+		}
+	}
 }

+ 8 - 10
mcs/class/System.Windows.Forms/Gtk/Form.cs

@@ -22,7 +22,6 @@ namespace System.Windows.Forms {
 		// if the application has a menu and/or a statusbar
 		// then this menu should be added to the vbox before
 		// the layout and the statusbar after the layout
-		Gtk.VBox vbox = null;
 		Control menu = null;
 
 		public Form () : base ()
@@ -31,6 +30,7 @@ namespace System.Windows.Forms {
 
 		static Form ()
 		{
+			// this happens to late (added this to Control's static constructor)
 			Gtk.Application.Init ();
 		}
 		
@@ -53,7 +53,7 @@ namespace System.Windows.Forms {
 			win.Title = Text;
 			vbox = new Gtk.VBox(false, 0);
 			win.Add (vbox);
-			vbox.Show ();
+			vbox.ShowAll ();
 			vbox.PackStart(contents, true, true, 0);
 			return (Widget) win;
 		}
@@ -268,12 +268,7 @@ namespace System.Windows.Forms {
 			}
 			set {
 				this.menu = value;
-				MainMenu m = (MainMenu)value;
-				this.vbox.PackStart(m.mb, false, false, 0);
-
-				m.mb.Show();
-				this.vbox.ReorderChild (m.mb, 0);
-				Control.Controls.Add(this.menu, false);
+				Control.Controls.Add(this.menu);
 			}
 		}
 		// [MonoTODO]
@@ -469,13 +464,16 @@ namespace System.Windows.Forms {
 		// [MonoTODO]
 		 public void SuspendLayout()
 		 {
-				throw new NotImplementedException ();
 		 }
 		// [MonoTODO]
 		 public void ResumeLayout()
 		 {
-				throw new NotImplementedException ();
 		 }
+
+		public void ResumeLayout (bool performLayout)
+		{
+		}
+
 		// [MonoTODO]
 		// public void Scale(float f)
 		// {

+ 0 - 1
mcs/class/System.Windows.Forms/Gtk/ScrollableControl.cs

@@ -15,7 +15,6 @@ using GtkSharp;
 
 namespace System.Windows.Forms {
 	public class ScrollableControl : Control {
-
 		//
 		//  --- Constructor
 		//

+ 1 - 0
mcs/class/System.Windows.Forms/Gtk/demo.cs

@@ -206,6 +206,7 @@ namespace demo
 	
 	public class GtkMain
 	{
+		[STAThread]
 		public static void Main()
 		{
 			GtkForm form1 = new GtkForm ();