Ryujinx-GtkSharp/sample/ManagedTreeViewDemo.cs
Rachel Hestilow f1a77c0e62 2003-05-19 Rachel Hestilow <rachel@nullenvoid.com>
* glib/ManagedValue.cs, TypeConverter.cs: Added.
	* glib/Value.cs: Make Value inherit from IDisposable, and
	move dtor to Dispose. Add generic object constructor
	with support for ManagedValue. Add a new Val property
	which will call the appropriate explicit cast.

	* glue/value.c: Add new glue function
	gtksharp_value_get_value_type.

	* gtk/TreeViewColumn.custom: Added.
	* gtk/ListStore.custom, TreeStore.custom: Add a number
	of SetValue overloads. Add convenience functtion
	AppendValues. Add new ctor that takes System.Type instead
	of GLib.TypeFundamentals. Add a GetValue convenience wrapper.
	* gtk/TreeView.custom: Add AppendColumn convenience
	functions.

	* sample/ManagedTreeViewDemo.cs: Added.
	* sample/Makefile.in: Update.
	* sample/TreeViewDemo.cs: Update to use new convenience
	APIs.

svn path=/trunk/gtk-sharp/; revision=14691
2003-05-19 07:18:52 +00:00

83 lines
2.0 KiB
C#

// ManagedTreeViewDemo.cs - Another TreeView demo
//
// Author: Rachel Hestilow <hestilow@ximian.com>
//
// (c) 2003 Rachel Hestilow
namespace GtkSamples {
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Gtk;
using GtkSharp;
public class TreeViewDemo {
private static ListStore store = null;
private class Pair {
public string a, b;
public Pair (string a, string b) {
this.a = a;
this.b = b;
}
}
private static void PopulateStore ()
{
store = new ListStore (typeof (Pair));
string[] combs = {"foo", "bar", "baz", "quux"};
foreach (string a in combs) {
foreach (string b in combs) {
store.AppendValues (new Pair (a, b));
}
}
}
private static void CellDataA (Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
{
Pair val = (Pair) store.GetValue (iter, 0);
((CellRendererText) cell).Text = val.a;
}
private static void CellDataB (Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
{
Pair val = (Pair) store.GetValue (iter, 0);
((CellRendererText) cell).Text = val.b;
}
[DllImport("gtk-x11-2.0")]
static extern void gtk_init (ref int argc, ref String[] argv);
public static void Main (string[] args)
{
Application.Init ();
PopulateStore ();
Window win = new Window ("TreeView demo");
win.DeleteEvent += new DeleteEventHandler (DeleteCB);
win.DefaultSize = new Size (320,480);
ScrolledWindow sw = new ScrolledWindow ();
win.Add (sw);
TreeView tv = new TreeView (store);
tv.HeadersVisible = true;
tv.AppendColumn ("One", new CellRendererText (), new TreeCellDataFunc (CellDataA));
tv.AppendColumn ("Two", new CellRendererText (), new TreeCellDataFunc (CellDataB));
sw.Add (tv);
win.ShowAll ();
Application.Run ();
}
private static void DeleteCB (System.Object o, DeleteEventArgs args)
{
Application.Quit ();
}
}
}