From a0912263e2e37457881ed5cc1103ec2070d3d643 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Tue, 28 Jun 2005 16:35:36 +0000 Subject: [PATCH] 2005-06-28 Mike Kestner * gtk/ComboBox.custom : add ctor (string[]). * gtk/ComboBoxEntry.custom : add ctor (string[]). * sample/test/TestComboBox.cs : simple new ComboBox tester. * sample/test/WidgetViewer.cs : button for simple new ComboBox tester. svn path=/trunk/gtk-sharp/; revision=46657 --- ChangeLog | 7 +++++ doc/en/Gtk/ComboBox.xml | 12 +++++++ doc/en/Gtk/ComboBoxEntry.xml | 12 +++++++ gtk/ComboBox.custom | 8 +++++ gtk/ComboBoxEntry.custom | 26 +++++++++++++++ gtk/Makefile.am | 1 + sample/test/Makefile.am | 1 + sample/test/TestComboBox.cs | 61 ++++++++++++++++++++++++++++++++++++ sample/test/WidgetViewer.cs | 6 ++++ 9 files changed, 134 insertions(+) create mode 100644 gtk/ComboBoxEntry.custom create mode 100644 sample/test/TestComboBox.cs diff --git a/ChangeLog b/ChangeLog index de9539b30..088ac8f67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-06-28 Mike Kestner + + * gtk/ComboBox.custom : add ctor (string[]). + * gtk/ComboBoxEntry.custom : add ctor (string[]). + * sample/test/TestComboBox.cs : simple new ComboBox tester. + * sample/test/WidgetViewer.cs : button for simple new ComboBox tester. + 2005-06-27 Mike Kestner * gnome/CanvasBpath.custom : a BPath property to wrap the ugly Bpath diff --git a/doc/en/Gtk/ComboBox.xml b/doc/en/Gtk/ComboBox.xml index fd958a31b..d4a8ee726 100644 --- a/doc/en/Gtk/ComboBox.xml +++ b/doc/en/Gtk/ComboBox.xml @@ -791,5 +791,17 @@ Default value: 0 + + + Constructor + + + + + A list of string values for the combo entries. + Creates a Combo box from a list of values. + + + diff --git a/doc/en/Gtk/ComboBoxEntry.xml b/doc/en/Gtk/ComboBoxEntry.xml index 2d2e5310a..ee4e063e4 100644 --- a/doc/en/Gtk/ComboBoxEntry.xml +++ b/doc/en/Gtk/ComboBoxEntry.xml @@ -117,5 +117,17 @@ + + + Constructor + + + + + a list of strings for the dropdown list. + Creates a combo entry from a list of entries. + + + diff --git a/gtk/ComboBox.custom b/gtk/ComboBox.custom index bd5d8d8c6..d7b8f7b2e 100644 --- a/gtk/ComboBox.custom +++ b/gtk/ComboBox.custom @@ -20,6 +20,14 @@ // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. + public ComboBox (string[] entries) : this (new ListStore (typeof (string))) + { + CellRendererText cell = new CellRendererText (); + PackStart (cell, true); + SetAttributes (cell, "text", 0); + foreach (string entry in entries) + AppendText (entry); + } public void SetAttributes (CellRenderer cell, params object[] attrs) { diff --git a/gtk/ComboBoxEntry.custom b/gtk/ComboBoxEntry.custom new file mode 100644 index 000000000..a5d4d8522 --- /dev/null +++ b/gtk/ComboBoxEntry.custom @@ -0,0 +1,26 @@ +// Gtk.ComboBoxEntry.custom - Gtk ComboBoxEntry customizations +// +// Authors: Mike Kestner +// +// Copyright (c) 2005 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + public ComboBoxEntry (string[] entries) : this (new ListStore (typeof (string)), 0) + { + foreach (string entry in entries) + AppendText (entry); + } + diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 2759e7d86..a1b0e730c 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -48,6 +48,7 @@ customs = \ ColorSelectionDialog.custom \ Combo.custom \ ComboBox.custom \ + ComboBoxEntry.custom \ Container.custom \ Dialog.custom \ Entry.custom \ diff --git a/sample/test/Makefile.am b/sample/test/Makefile.am index 6b3b2b8f0..c795a62e4 100644 --- a/sample/test/Makefile.am +++ b/sample/test/Makefile.am @@ -18,6 +18,7 @@ sources = \ TestFlipping.cs \ TestSizeGroup.cs \ TestCombo.cs \ + TestComboBox.cs \ WidgetViewer.cs build_sources = $(addprefix $(srcdir)/, $(sources)) diff --git a/sample/test/TestComboBox.cs b/sample/test/TestComboBox.cs new file mode 100644 index 000000000..94f37e12f --- /dev/null +++ b/sample/test/TestComboBox.cs @@ -0,0 +1,61 @@ +// TestCombo.cs +// +// Author: Mike Kestner (mkestner@novell.com) +// +// Copyright (c) 2005, Novell, Inc. +// + +using System; +using Gtk; + +namespace WidgetViewer { + public class TestComboBox + { + static Window window = null; + + public static Gtk.Window Create () + { + window = new Window ("GtkComboBox"); + window.SetDefaultSize (200, 100); + + VBox box1 = new VBox (false, 0); + window.Add (box1); + + VBox box2 = new VBox (false, 10); + box2.BorderWidth = 10; + box1.PackStart (box2, true, true, 0); + + ComboBoxEntry combo = new Gtk.ComboBoxEntry (new string[] {"Foo", "Bar"}); + combo.Changed += new EventHandler (OnComboActivated); + box2.PackStart (combo, true, true, 0); + + HSeparator separator = new HSeparator (); + + box1.PackStart (separator, false, false, 0); + + box2 = new VBox (false, 10); + box2.BorderWidth = 10; + box1.PackStart (box2, false, false, 0); + + Button button = new Button (Stock.Close); + button.Clicked += new EventHandler (OnCloseClicked); + button.CanDefault = true; + + box2.PackStart (button, true, true, 0); + button.GrabDefault (); + return window; + } + + static void OnCloseClicked (object o, EventArgs args) + { + window.Destroy (); + } + + static void OnComboActivated (object o, EventArgs args) + { + Console.WriteLine ((o as ComboBox).ActiveText); + } + } +} + + diff --git a/sample/test/WidgetViewer.cs b/sample/test/WidgetViewer.cs index b1224ac14..a3cdd8165 100644 --- a/sample/test/WidgetViewer.cs +++ b/sample/test/WidgetViewer.cs @@ -41,6 +41,7 @@ namespace WidgetViewer { AddButton ("Check Buttons", new EventHandler (Check_Buttons)); AddButton ("Color Selection", new EventHandler (Color_Selection)); AddButton ("Combo Box", new EventHandler (Combo_Box)); + AddButton ("New Combo Box", new EventHandler (New_Combo_Box)); AddButton ("Dialog", new EventHandler (Dialog)); AddButton ("File Selection", new EventHandler (File_Selection)); AddButton ("Menus", new EventHandler (Menus)); @@ -151,6 +152,11 @@ namespace WidgetViewer { AddWindow (TestSizeGroup.Create ()); } + static void New_Combo_Box (object o, EventArgs args) + { + AddWindow (TestComboBox.Create ()); + } + static void Combo_Box (object o, EventArgs args) { AddWindow (TestCombo.Create ());