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.
This commit is contained in:
Bertrand Lorentz 2011-07-16 14:46:35 +02:00
parent c28312f826
commit bef589e836
4 changed files with 37 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.custom - 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,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;
}
}

View File

@ -54,7 +54,7 @@ customs = \
ColorSelection.custom \
ColorSelectionDialog.custom \
ComboBox.custom \
ComboBoxEntry.custom \
ComboBoxText.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 ();