From 8930314f11c47964fb03e9660652fe1628968c68 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Mon, 7 Nov 2005 22:37:30 +0000 Subject: [PATCH] Patch from tmastran@gmail.com svn path=/trunk/gtk-sharp/; revision=52668 --- doc/en/Gtk/CellRenderer.xml | 60 +++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/doc/en/Gtk/CellRenderer.xml b/doc/en/Gtk/CellRenderer.xml index 504be470e..1bbc93eca 100644 --- a/doc/en/Gtk/CellRenderer.xml +++ b/doc/en/Gtk/CellRenderer.xml @@ -466,7 +466,63 @@ a a a - Some cell renderers may use events; for example, toggles when it gets a mouse click. + Some cell renderers may use events; for example, toggles when it gets a mouse click. + +The following example illustrates a CellRenderText derived class that implements auto-completion in the entry widget. + + +public class CellRendererCompletion : CellRendererText +{ + public delegate ListStore CompletionStoreNeededDelegate(TreeView tree, out int textColumn); + + // Delegate that is called to obtain a ListStore that contains entries + // for the column being editted. TreeView.GetCursor(out path, out column) + // can be used to determine the column being editted. + public static CompletionStoreNeededDelegate CompletionStoreNeededEventHandler; + + // Required constructor that may be called by the framework. + public CellRendererCompletion(System.IntPtr raw) : base(raw) + { + } + + public CellRendererCompletion() + { + } + + public override CellEditable StartEditing(Gdk.Event evnt, Widget widget, string path, + Gdk.Rectangle background_area, Gdk.Rectangle cell_area, CellRendererState flags) + { + // get the entry widget + Entry entry = base.StartEditing (evnt, widget, path, background_area, cell_area, flags) as Gtk.Entry; + + // make it auto-complete + TreeView treeview = widget as TreeView; + int textColumn = 0; + + entry.Completion = new EntryCompletion(); + entry.Completion.Model = CreateCompletionModel(treeview, out textColumn); + entry.Completion.TextColumn = textColumn; + + return entry; + } + + // Gets the ListStore that contains the auto-complete entries + // to be shown when editting this cell. Typical use might use + // TreeView.GetCursor(out path, out column) to get the column name + // being editted to build an appropriate list. + private static TreeModel CreateCompletionModel(TreeView treeview, out int textColumn) + { + textColumn = 0; + + if (CompletionStoreNeededEventHandler != null) + return CompletionStoreNeededEventHandler(treeview, out textColumn); + + return null; + } + +} + + @@ -612,4 +668,4 @@ - + \ No newline at end of file