Просмотр исходного кода

2003-05-07 Joel Basson <[email protected]>

* Added ComboBox.Items.Add and ComboBox.Items.Add to ComboBox.cs
* FontDialog.cs
* Added new Demo2.cs test app

svn path=/trunk/mcs/; revision=14362
Joel Basson 23 лет назад
Родитель
Сommit
26d486557a

+ 38 - 8
mcs/class/System.Windows.Forms/Gtk/ComboBox.cs

@@ -9,6 +9,7 @@
 using System.Drawing;
 using System.Drawing.Printing;
 using System.ComponentModel;
+using System.Runtime.InteropServices;
 
 namespace System.Windows.Forms {
 
@@ -18,15 +19,44 @@ namespace System.Windows.Forms {
 	/// </summary>
 
 	public class ComboBox: Control{
+	
+		public ItemCollection Items = new ItemCollection(this);
+ 		GLib.List list = new GLib.List (IntPtr.Zero, typeof (string));
 
-	public ComboBox () : base ()
-	{
-	}
+		public class ItemCollection {
 
-	internal override Gtk.Widget CreateWidget () {
-		Gtk.Combo com1 = new Gtk.Combo();
-		return com1;	
-	}
+			ComboBox owner;
+			
+			public ItemCollection (ComboBox owner){
+
+				this.owner = owner;
+			}
+						
+			public void Add(String value){
+				owner.list.Append (Marshal.StringToHGlobalAnsi (value));
+				owner.Update();
+			}
+
+			public void AddRange(object[] items) {
+				foreach (object o in items)
+					{string s = (string)o;
+					owner.list.Append (Marshal.StringToHGlobalAnsi (s));}
+				owner.Update();
+			}
+		}
+
+		public ComboBox () : base (){
+		}
+
+		internal override Gtk.Widget CreateWidget () {
+			Gtk.Combo com1 = new Gtk.Combo();
+			com1.SetPopdownStrings("");		
+			return com1;	
+		}
 	
+		public void Update () {
+		((Gtk.Combo)Widget).PopdownStrings = list;		
+		}
+
 	}
-}
+}

+ 79 - 0
mcs/class/System.Windows.Forms/Gtk/Demo2.cs

@@ -0,0 +1,79 @@
+//		
+//			System.Windows.Forms Demo2 app
+//
+//			Author: 
+//						Joel Basson		([email protected])
+//
+//
+
+using System;
+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();
+			private ComboBox combo1 = new ComboBox();
+
+	    	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);    
+         	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.Enabled = true;
+				
+				combo1.Location = new Point(150, 150);
+		this.combo1.Items.AddRange(new object[] {"Item 1",
+                        "Item 2",
+                        "Item 3",
+                        "Item 4",
+                        "Item 5"});
+		
+          	this.Controls.AddRange(new System.Windows.Forms.Control[] { 
+									this.button1,
+									this.button2,
+									this.color1,
+									this.combo1});
+          this.Size = new Size(512, 250);
+    		}
+    	
+    	public GtkForm()
+    	{
+    	   	InitializeWidgets();
+
+    	}
+
+		private void button1_Click(object sender, EventArgs e){ 
+			color1.ShowDialog();		
+  		}
+
+		private void button2_Click(object sender, EventArgs e){ 
+			combo1.Items.Add("Joel");		
+  		}
+
+	 }
+	
+	public class GtkMain
+	{
+		public static void Main()
+		{
+			GtkForm form1 = new GtkForm ();
+			form1.Text = "System.Windows.Forms at work!";			
+			Application.Run(form1);
+		}
+	}
+}

+ 51 - 0
mcs/class/System.Windows.Forms/Gtk/FontDialog.cs

@@ -0,0 +1,51 @@
+//		
+//			System.Windows.Forms.FontDialog
+//
+//			Author: 
+//						Joel Basson		([email protected])
+//
+//
+
+using System.Drawing;
+using System.Drawing.Printing;
+using System.ComponentModel;
+using Gtk;
+using GtkSharp;
+
+namespace System.Windows.Forms {
+
+	/// <summary>
+	/// Represents a Windows Font Dialog.
+	///
+	/// </summary>
+
+	public class FontDialog: Control{
+		
+		//String name1; 
+		Gtk.FontSelectionDialog font1 = new Gtk.FontSelectionDialog("");
+
+	public FontDialog () : base () {
+	}
+
+	
+	public void ShowDialog () {
+		//Gtk.FontSelection file1 = new Gtk.FontSelection("");
+		//font1.OkButton.Clicked += new EventHandler (font_selection_ok);
+		//font1.CancelButton.Clicked += new EventHandler (font_selection_cancel);
+		font1.Show();
+	}	
+
+		
+	//internal void font_selection_cancel (object o, EventArgs args){
+	//
+	//		font1.Hide();
+	//} 
+		
+	//internal void font_selection_ok (object o, EventArgs args){
+	//
+	//		font1.Hide();
+	//}
+	
+	}
+	
+}

+ 6 - 0
mcs/class/System.Windows.Forms/Gtk/changelog

@@ -1,3 +1,9 @@
+2003-05-07  Joel Basson  <[email protected]>
+
+* Added ComboBox.Items.Add and ComboBox.Items.Add to ComboBox.cs
+* FontDialog.cs
+* Added new Demo2.cs test app
+
 2003-04-17	Joel Basson  <[email protected]>	
 
 * ComboBox.cs

+ 3 - 2
mcs/class/System.Windows.Forms/Gtk/makefile

@@ -1,5 +1,5 @@
 CSC=mcs
-SWFF=-r gdk-sharp -r gtk-sharp -r glib-sharp -r System.Drawing 
+SWFF=-r gdk-sharp -r gtk-sharp -r glib-sharp -r System.Drawing -r gnome-sharp 
 
 SOURCES = \
 	AnchorStyles.cs		\
@@ -25,11 +25,12 @@ SOURCES = \
 	ProgressBar.cs	\
 	PictureBox.cs	\
 	FileDialog.cs	\
+	FontDialog.cs	\
 	ColorDialog.cs	\
 	ComboBox.cs	\
 	ScrollableControl.cs
 
-all: demo.exe
+all: demo.exe 
 
 demo.exe: demo.cs System.Windows.Forms.dll
 	$(CSC) demo.cs -r System.Windows.Forms.dll -r System.Drawing