From bef589e8366c47d3a330ecc80f537abb30a0614b Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sat, 16 Jul 2011 14:46:35 +0200 Subject: [PATCH 1/3] gtk: Facilitate use of ComboBox and ComboBoxText with an Entry Add ComboBox[Text] (bool with_entry) protected constructors to allow subclasses with an Entry. Add an Entry property for easy access to the Entry child widget. Also remove the unused gtk/ComboBoxEntry.custom. --- gtk/ComboBox.custom | 20 ++++++++++++++++++ ...mboBoxEntry.custom => ComboBoxText.custom} | 21 +++++++++++++------ gtk/Makefile.am | 2 +- sample/test/TestComboBox.cs | 2 +- 4 files changed, 37 insertions(+), 8 deletions(-) rename gtk/{ComboBoxEntry.custom => ComboBoxText.custom} (61%) diff --git a/gtk/ComboBox.custom b/gtk/ComboBox.custom index c41b473de..cf5040453 100644 --- a/gtk/ComboBox.custom +++ b/gtk/ComboBox.custom @@ -30,6 +30,26 @@ store.AppendValues (entry); } + protected ComboBox (bool with_entry) : base (IntPtr.Zero) + { + if (GetType () != typeof (ComboBox)) { + CreateNativeObject (new string [0], new GLib.Value[0]); + return; + } + + if (with_entry) { + Raw = gtk_combo_box_new_with_entry (); + } else { + Raw = gtk_combo_box_new (); + } + } + + public Gtk.Entry Entry { + get { + return (Gtk.Entry)Child; + } + } + public void SetAttributes (CellRenderer cell, params object[] attrs) { if (attrs.Length % 2 != 0) diff --git a/gtk/ComboBoxEntry.custom b/gtk/ComboBoxText.custom similarity index 61% rename from gtk/ComboBoxEntry.custom rename to gtk/ComboBoxText.custom index 7593ceb82..c891084a3 100644 --- a/gtk/ComboBoxEntry.custom +++ b/gtk/ComboBoxText.custom @@ -1,8 +1,8 @@ -// Gtk.ComboBoxEntry.custom - Gtk ComboBoxEntry customizations +// ComboBoxText.custom - Gtk ComboBoxText customizations // -// Authors: Mike Kestner +// Authors: Bertrand Lorentz // -// Copyright (c) 2005 Novell, Inc. +// Copyright (c) 2011 Bertrand Lorentz // // This program is free software; you can redistribute it and/or // modify it under the terms of version 2 of the Lesser GNU General @@ -18,10 +18,18 @@ // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. - public ComboBoxEntry (string[] entries) : this (new ListStore (typeof (string)), 0) + protected ComboBoxText (bool with_entry) : base (IntPtr.Zero) { - foreach (string entry in entries) - AppendText (entry); + if (GetType () != typeof (ComboBoxText)) { + CreateNativeObject (new string [0], new GLib.Value[0]); + return; + } + + if (with_entry) { + Raw = gtk_combo_box_text_new_with_entry (); + } else { + Raw = gtk_combo_box_text_new (); + } } public Gtk.Entry Entry { @@ -29,3 +37,4 @@ return (Gtk.Entry)Child; } } + diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 47aa6edd4..c3cb221cd 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -54,7 +54,7 @@ customs = \ ColorSelection.custom \ ColorSelectionDialog.custom \ ComboBox.custom \ - ComboBoxEntry.custom \ + ComboBoxText.custom \ Container.custom \ Dialog.custom \ Drag.custom \ diff --git a/sample/test/TestComboBox.cs b/sample/test/TestComboBox.cs index a48a54ca3..5ec5c60e3 100644 --- a/sample/test/TestComboBox.cs +++ b/sample/test/TestComboBox.cs @@ -29,7 +29,7 @@ namespace WidgetViewer { combo.AppendText ("Foo"); combo.AppendText ("Bar"); combo.Changed += new EventHandler (OnComboActivated); - ((Entry)combo.Child).Changed += new EventHandler (OnComboEntryChanged); + combo.Entry.Changed += new EventHandler (OnComboEntryChanged); box2.PackStart (combo, true, true, 0); HSeparator separator = new HSeparator (); From 9463e98ca22a387eceb1689ccf25efa259adacba Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sat, 16 Jul 2011 17:53:21 +0200 Subject: [PATCH 2/3] gtk: move ComboBoxText custom code to a partial class Also rename the constructor parameter to has_entry and pass its value to CreateNativeObject. --- gtk/{ComboBoxText.custom => ComboBoxText.cs} | 15 ++++++++++----- gtk/Makefile.am | 1 - 2 files changed, 10 insertions(+), 6 deletions(-) rename gtk/{ComboBoxText.custom => ComboBoxText.cs} (77%) diff --git a/gtk/ComboBoxText.custom b/gtk/ComboBoxText.cs similarity index 77% rename from gtk/ComboBoxText.custom rename to gtk/ComboBoxText.cs index c891084a3..a5f4c0914 100644 --- a/gtk/ComboBoxText.custom +++ b/gtk/ComboBoxText.cs @@ -1,4 +1,4 @@ -// ComboBoxText.custom - Gtk ComboBoxText customizations +// ComboBoxText.cs - Gtk ComboBoxText customizations // // Authors: Bertrand Lorentz // @@ -18,14 +18,18 @@ // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. - protected ComboBoxText (bool with_entry) : base (IntPtr.Zero) +namespace Gtk { + + public partial class ComboBoxText { + + protected ComboBoxText (bool has_entry) : base (IntPtr.Zero) { if (GetType () != typeof (ComboBoxText)) { - CreateNativeObject (new string [0], new GLib.Value[0]); + CreateNativeObject (new string[] { "has-entry" }, new GLib.Value[] { new GLib.Value (has_entry) }); return; } - if (with_entry) { + if (has_entry) { Raw = gtk_combo_box_text_new_with_entry (); } else { Raw = gtk_combo_box_text_new (); @@ -37,4 +41,5 @@ return (Gtk.Entry)Child; } } - + } +} diff --git a/gtk/Makefile.am b/gtk/Makefile.am index c3cb221cd..c9e2c4837 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -54,7 +54,6 @@ customs = \ ColorSelection.custom \ ColorSelectionDialog.custom \ ComboBox.custom \ - ComboBoxText.custom \ Container.custom \ Dialog.custom \ Drag.custom \ From b0768d35f668db190a2e12805436dd264e4984ad Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sat, 16 Jul 2011 18:18:14 +0200 Subject: [PATCH 3/3] gtk: Include ComboBoxText.cs in the build Also add missing using statement. --- gtk/ComboBoxText.cs | 2 ++ gtk/Makefile.am | 1 + 2 files changed, 3 insertions(+) diff --git a/gtk/ComboBoxText.cs b/gtk/ComboBoxText.cs index a5f4c0914..e4a6e68eb 100644 --- a/gtk/ComboBoxText.cs +++ b/gtk/ComboBoxText.cs @@ -20,6 +20,8 @@ namespace Gtk { + using System; + public partial class ComboBoxText { protected ComboBoxText (bool has_entry) : base (IntPtr.Zero) diff --git a/gtk/Makefile.am b/gtk/Makefile.am index c9e2c4837..b9b0e5429 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -16,6 +16,7 @@ sources = \ BindingAttribute.cs \ CellAreaBox.cs \ ChildPropertyAttribute.cs \ + ComboBoxText.cs \ Global.cs \ ITreeNode.cs \ Key.cs \