Merge pull request #12 from bl8/combobox-entry

gtk: Facilitate use of ComboBox and ComboBoxText with an Entry
This commit is contained in:
Mike Kestner 2011-07-16 10:59:24 -07:00
commit c098797e7b
4 changed files with 44 additions and 8 deletions

View File

@ -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)

View File

@ -1,8 +1,8 @@
// Gtk.ComboBoxEntry.custom - Gtk ComboBoxEntry customizations
// ComboBoxText.cs - Gtk ComboBoxText customizations
//
// Authors: Mike Kestner <mkestner@novell.com>
// Authors: Bertrand Lorentz <bertrand.lorentz@gmail.com>
//
// 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,24 @@
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
public ComboBoxEntry (string[] entries) : this (new ListStore (typeof (string)), 0)
namespace Gtk {
using System;
public partial class ComboBoxText {
protected ComboBoxText (bool has_entry) : base (IntPtr.Zero)
{
foreach (string entry in entries)
AppendText (entry);
if (GetType () != typeof (ComboBoxText)) {
CreateNativeObject (new string[] { "has-entry" }, new GLib.Value[] { new GLib.Value (has_entry) });
return;
}
if (has_entry) {
Raw = gtk_combo_box_text_new_with_entry ();
} else {
Raw = gtk_combo_box_text_new ();
}
}
public Gtk.Entry Entry {
@ -29,3 +43,5 @@
return (Gtk.Entry)Child;
}
}
}
}

View File

@ -16,6 +16,7 @@ sources = \
BindingAttribute.cs \
CellAreaBox.cs \
ChildPropertyAttribute.cs \
ComboBoxText.cs \
Global.cs \
ITreeNode.cs \
Key.cs \
@ -54,7 +55,6 @@ customs = \
ColorSelection.custom \
ColorSelectionDialog.custom \
ComboBox.custom \
ComboBoxEntry.custom \
Container.custom \
Dialog.custom \
Drag.custom \

View File

@ -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 ();