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
This commit is contained in:
parent
b2dabc1322
commit
f1a77c0e62
12 changed files with 598 additions and 45 deletions
24
ChangeLog
24
ChangeLog
|
@ -1,3 +1,27 @@
|
|||
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.
|
||||
|
||||
2003-05-18 Mike Kestner <mkestner@speakeasy.net>
|
||||
|
||||
* generator/CallbackGen.cs : use non-static symtab, kill doc comments
|
||||
|
|
94
glib/ManagedValue.cs
Normal file
94
glib/ManagedValue.cs
Normal file
|
@ -0,0 +1,94 @@
|
|||
// GLib.ManagedValue.cs : Managed types boxer
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@ximian.com>
|
||||
//
|
||||
// (c) 2002 Rachel Hestilow
|
||||
|
||||
namespace GLibSharp {
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <summary>
|
||||
/// Managed types boxer
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Utility class for creating GBoxed wrappers around managed types
|
||||
/// </remarks>
|
||||
|
||||
// FIXME:
|
||||
// This used to use GCHandles, but I rewrote it to debug
|
||||
// some odd interactions. Since the boxed code in GLib is designed
|
||||
// to not interact directly with the pointers, just using our own
|
||||
// arbitrary pointer values is fine. Still, it might be useful
|
||||
// to use GCHandle later on.
|
||||
|
||||
public class ManagedValue {
|
||||
private class ValueHolder {
|
||||
public object val;
|
||||
public int ref_count;
|
||||
}
|
||||
|
||||
private delegate IntPtr CopyFunc (IntPtr ptr);
|
||||
private delegate void FreeFunc (IntPtr ptr);
|
||||
|
||||
private static Hashtable pointers = new Hashtable ();
|
||||
private static IntPtr cur_ptr = IntPtr.Zero;
|
||||
private static CopyFunc copy;
|
||||
private static FreeFunc free;
|
||||
private static uint boxed_type = 0;
|
||||
|
||||
[DllImport("gobject-2.0")]
|
||||
private static extern uint g_boxed_type_register_static (string typename, CopyFunc copy_func, FreeFunc free_func);
|
||||
|
||||
public static uint GType {
|
||||
get {
|
||||
if (boxed_type == 0) {
|
||||
copy = new CopyFunc (Copy);
|
||||
free = new FreeFunc (Free);
|
||||
|
||||
boxed_type = g_boxed_type_register_static ("GtkSharpValue", copy, free);
|
||||
}
|
||||
|
||||
return boxed_type;
|
||||
}
|
||||
}
|
||||
|
||||
public static IntPtr Copy (IntPtr ptr)
|
||||
{
|
||||
ValueHolder holder = (ValueHolder) pointers[ptr];
|
||||
holder.ref_count++;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
public static void Free (IntPtr ptr)
|
||||
{
|
||||
ValueHolder holder = (ValueHolder) pointers[ptr];
|
||||
holder.ref_count--;
|
||||
if (holder.ref_count < 1)
|
||||
pointers.Remove (ptr);
|
||||
}
|
||||
|
||||
public static IntPtr WrapObject (object obj)
|
||||
{
|
||||
ValueHolder holder = new ValueHolder ();
|
||||
holder.val = obj;
|
||||
holder.ref_count = 1;
|
||||
cur_ptr = new IntPtr (((int) cur_ptr) + 1);
|
||||
pointers[cur_ptr] = holder;
|
||||
return cur_ptr;
|
||||
}
|
||||
|
||||
public static object ObjectForWrapper (IntPtr ptr)
|
||||
{
|
||||
if (!pointers.Contains (ptr))
|
||||
return null;
|
||||
|
||||
ValueHolder holder = (ValueHolder) pointers[ptr];
|
||||
return holder.val;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
51
glib/TypeConverter.cs
Normal file
51
glib/TypeConverter.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
// GLib.TypeConverter.cs : Convert between fundamental and .NET types
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@ximian.com>
|
||||
//
|
||||
// (c) 2002 Rachel Hestilow
|
||||
|
||||
namespace GLibSharp {
|
||||
using System;
|
||||
using System.Collections;
|
||||
using GLib;
|
||||
|
||||
/// <summary>
|
||||
/// Fundamental type converter
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Utilities for converting between TypeFundamentals and System.Type
|
||||
/// </remarks>
|
||||
public class TypeConverter {
|
||||
public static TypeFundamentals LookupType (System.Type type)
|
||||
{
|
||||
if (type.Equals (typeof (string)))
|
||||
return TypeFundamentals.TypeString;
|
||||
|
||||
if (!type.IsValueType) {
|
||||
if (type.IsSubclassOf (typeof (GLib.Object)))
|
||||
return TypeFundamentals.TypeObject;
|
||||
else if (type.IsSubclassOf (typeof (GLib.Boxed)))
|
||||
return TypeFundamentals.TypeBoxed;
|
||||
else
|
||||
return TypeFundamentals.TypeNone;
|
||||
}
|
||||
|
||||
if (type.Equals (typeof (bool)))
|
||||
return TypeFundamentals.TypeBoolean;
|
||||
if (type.Equals (typeof (int)))
|
||||
return TypeFundamentals.TypeInt;
|
||||
if (type.Equals (typeof (double)))
|
||||
return TypeFundamentals.TypeDouble;
|
||||
if (type.Equals (typeof (float)))
|
||||
return TypeFundamentals.TypeFloat;
|
||||
if (type.Equals (typeof (char)))
|
||||
return TypeFundamentals.TypeChar;
|
||||
if (type.Equals (typeof (uint)))
|
||||
return TypeFundamentals.TypeUInt;
|
||||
|
||||
return TypeFundamentals.TypeInvalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
113
glib/Value.cs
113
glib/Value.cs
|
@ -8,6 +8,7 @@ namespace GLib {
|
|||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using GLibSharp;
|
||||
|
||||
/// <summary>
|
||||
/// Value Class
|
||||
|
@ -18,7 +19,7 @@ namespace GLib {
|
|||
/// to get and set properties on Objects.
|
||||
/// </remarks>
|
||||
|
||||
public class Value {
|
||||
public class Value : IDisposable {
|
||||
|
||||
IntPtr _val;
|
||||
|
||||
|
@ -31,7 +32,19 @@ namespace GLib {
|
|||
|
||||
~Value ()
|
||||
{
|
||||
g_free (_val);
|
||||
Dispose ();
|
||||
}
|
||||
|
||||
public void Dispose () {
|
||||
if (_val != IntPtr.Zero) {
|
||||
uint type = gtksharp_value_get_value_type (_val);
|
||||
if (type == ManagedValue.GType) {
|
||||
ManagedValue.Free (g_value_get_boxed (_val));
|
||||
}
|
||||
|
||||
g_free (_val);
|
||||
_val = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -262,6 +275,8 @@ namespace GLib {
|
|||
static extern void g_value_set_enum (IntPtr val, int data);
|
||||
[DllImport("libgobject-2.0-0.dll")]
|
||||
static extern void g_value_set_flags (IntPtr val, uint data);
|
||||
[DllImport("gobject-2.0")]
|
||||
static extern void g_value_set_char (IntPtr val, char data);
|
||||
|
||||
/// <summary>
|
||||
/// Value Constructor
|
||||
|
@ -280,6 +295,66 @@ namespace GLib {
|
|||
g_value_set_enum (_val, (int) wrap);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Value Constructor
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Constructs a Value from any object, including a managed
|
||||
/// type.
|
||||
/// </remarks>
|
||||
|
||||
[DllImport("gobject-2.0")]
|
||||
static extern void g_value_set_boxed_take_ownership (IntPtr val, IntPtr data);
|
||||
|
||||
public Value (object obj)
|
||||
{
|
||||
TypeFundamentals type = TypeConverter.LookupType (obj.GetType ());
|
||||
if (type == TypeFundamentals.TypeNone) {
|
||||
_val = gtksharp_value_create (ManagedValue.GType);
|
||||
} else if (type == TypeFundamentals.TypeObject) {
|
||||
_val = gtksharp_value_create (((GLib.Object) obj).GetGType ());
|
||||
} else if (type == TypeFundamentals.TypeInvalid) {
|
||||
throw new Exception ("Unknown type");
|
||||
} else {
|
||||
_val = gtksharp_value_create ((uint) type);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case TypeFundamentals.TypeNone:
|
||||
g_value_set_boxed_take_ownership (_val, ManagedValue.WrapObject (obj));
|
||||
break;
|
||||
case TypeFundamentals.TypeString:
|
||||
g_value_set_string (_val, (string) obj);
|
||||
break;
|
||||
case TypeFundamentals.TypeBoolean:
|
||||
g_value_set_boolean (_val, (bool) obj);
|
||||
break;
|
||||
case TypeFundamentals.TypeInt:
|
||||
g_value_set_int (_val, (int) obj);
|
||||
break;
|
||||
case TypeFundamentals.TypeDouble:
|
||||
g_value_set_double (_val, (double) obj);
|
||||
break;
|
||||
case TypeFundamentals.TypeFloat:
|
||||
g_value_set_float (_val, (float) obj);
|
||||
break;
|
||||
case TypeFundamentals.TypeChar:
|
||||
g_value_set_char (_val, (char) obj);
|
||||
break;
|
||||
case TypeFundamentals.TypeUInt:
|
||||
g_value_set_uint (_val, (uint) obj);
|
||||
break;
|
||||
case TypeFundamentals.TypeObject:
|
||||
g_value_set_object (_val, ((GLib.Object) obj).Handle);
|
||||
break;
|
||||
default:
|
||||
throw new Exception ("Unknown type");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[DllImport("libgobject-2.0-0.dll")]
|
||||
static extern bool g_value_get_boolean (IntPtr val);
|
||||
|
||||
|
@ -521,6 +596,40 @@ namespace GLib {
|
|||
return new EnumWrapper (g_value_get_enum (val._val), false);
|
||||
}
|
||||
|
||||
[DllImport("gtksharpglue")]
|
||||
static extern uint gtksharp_value_get_value_type (IntPtr val);
|
||||
|
||||
public object Val
|
||||
{
|
||||
get {
|
||||
uint type = gtksharp_value_get_value_type (_val);
|
||||
if (type == ManagedValue.GType) {
|
||||
return ManagedValue.ObjectForWrapper (g_value_get_boxed (_val));
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case TypeFundamentals.TypeString:
|
||||
return (string) this;
|
||||
case TypeFundamentals.TypeBoolean:
|
||||
return (bool) this;
|
||||
case TypeFundamentals.TypeInt:
|
||||
return (int) this;
|
||||
case TypeFundamentals.TypeDouble:
|
||||
return (double) this;
|
||||
case TypeFundamentals.TypeFloat:
|
||||
return (float) this;
|
||||
case TypeFundamentals.TypeChar:
|
||||
return (char) this;
|
||||
case TypeFundamentals.TypeUInt:
|
||||
return (uint) this;
|
||||
case TypeFundamentals.TypeObject:
|
||||
return (GLib.Object) this;
|
||||
default:
|
||||
throw new Exception ("Unknown type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle Property
|
||||
/// </summary>
|
||||
|
|
|
@ -29,3 +29,10 @@ gtksharp_value_create_from_property (GObject *obj, const gchar* name)
|
|||
return gtksharp_value_create (spec->value_type);
|
||||
}
|
||||
|
||||
GType
|
||||
gtksharp_value_get_value_type (GValue *value) {
|
||||
g_return_val_if_fail (value != NULL, G_TYPE_INVALID);
|
||||
g_return_val_if_fail (G_IS_VALUE (value), G_TYPE_INVALID);
|
||||
return G_VALUE_TYPE (value);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,3 +34,84 @@
|
|||
{
|
||||
SetColumnTypes (types.Length, types);
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, bool value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, double value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, int value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, string value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, float value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, uint value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, object value) {
|
||||
GLib.Value val = new GLib.Value (value);
|
||||
SetValue (iter, column, val);
|
||||
val.Dispose ();
|
||||
}
|
||||
|
||||
public Gtk.TreeIter AppendValues (Array values) {
|
||||
Gtk.TreeIter iter;
|
||||
Append (out iter);
|
||||
|
||||
int col = 0;
|
||||
foreach (object value in values) {
|
||||
if (value != null) {
|
||||
GLib.Value val = new GLib.Value (value);
|
||||
SetValue (iter, col, val);
|
||||
val.Dispose ();
|
||||
}
|
||||
col++;
|
||||
}
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
public Gtk.TreeIter AppendValues (params object[] values) {
|
||||
return AppendValues ((Array) values);
|
||||
}
|
||||
|
||||
public ListStore (params Type[] types)
|
||||
{
|
||||
uint[] ctypes = new uint[types.Length];
|
||||
int i = 0;
|
||||
foreach (Type type in types) {
|
||||
GLib.TypeFundamentals ctype = GLibSharp.TypeConverter.LookupType (type);
|
||||
if (ctype == GLib.TypeFundamentals.TypeNone) {
|
||||
ctypes[i] = GLibSharp.ManagedValue.GType;
|
||||
} else if (ctype == GLib.TypeFundamentals.TypeInvalid) {
|
||||
throw new Exception ("Unknown type");
|
||||
} else {
|
||||
ctypes[i] = (uint) ctype;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
Raw = gtk_list_store_newv (ctypes.Length, ctypes);
|
||||
}
|
||||
|
||||
public object GetValue(Gtk.TreeIter iter, int column) {
|
||||
GLib.Value val;
|
||||
GetValue (iter, column, out val);
|
||||
object ret = val.Val;
|
||||
val.Dispose ();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -114,3 +114,91 @@
|
|||
{
|
||||
SetColumnTypes (types.Length, types);
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, bool value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, double value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, int value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, string value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, float value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, uint value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
public void SetValue (Gtk.TreeIter iter, int column, object value) {
|
||||
SetValue (iter, column, new GLib.Value (value));
|
||||
}
|
||||
|
||||
private void _AppendValues (Gtk.TreeIter iter, Array values) {
|
||||
int col = 0;
|
||||
foreach (object value in values) {
|
||||
if (value != null)
|
||||
SetValue (iter, col, new GLib.Value (value));
|
||||
col++;
|
||||
}
|
||||
}
|
||||
|
||||
public Gtk.TreeIter AppendValues (Gtk.TreeIter parent, Array values) {
|
||||
Gtk.TreeIter iter;
|
||||
Append (out iter, parent);
|
||||
_AppendValues (iter, values);
|
||||
return iter;
|
||||
}
|
||||
|
||||
public Gtk.TreeIter AppendValues (Gtk.TreeIter parent, params object[] values) {
|
||||
return AppendValues (parent, (Array) values);
|
||||
}
|
||||
|
||||
public Gtk.TreeIter AppendValues (Array values) {
|
||||
Gtk.TreeIter iter;
|
||||
Append (out iter);
|
||||
_AppendValues (iter, values);
|
||||
return iter;
|
||||
}
|
||||
|
||||
public Gtk.TreeIter AppendValues (params object[] values) {
|
||||
return AppendValues ((Array) values);
|
||||
}
|
||||
|
||||
public TreeStore (params Type[] types)
|
||||
{
|
||||
uint[] ctypes = new uint[types.Length];
|
||||
int i = 0;
|
||||
foreach (Type type in types) {
|
||||
GLib.TypeFundamentals ctype = GLibSharp.TypeConverter.LookupType (type);
|
||||
if (ctype == GLib.TypeFundamentals.TypeNone) {
|
||||
ctypes[i] = GLibSharp.ManagedValue.GType;
|
||||
} else if (ctype == GLib.TypeFundamentals.TypeInvalid) {
|
||||
throw new Exception ("Unknown type");
|
||||
} else {
|
||||
ctypes[i] = (uint) ctype;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
Raw = gtk_tree_store_newv (ctypes.Length, ctypes);
|
||||
}
|
||||
|
||||
public object GetValue (Gtk.TreeIter iter, int column) {
|
||||
GLib.Value val;
|
||||
GetValue (iter, column, out val);
|
||||
object ret = val.Val;
|
||||
val.Dispose ();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -95,3 +95,19 @@
|
|||
return raw_ret;
|
||||
}
|
||||
|
||||
public Gtk.TreeViewColumn AppendColumn (string title, Gtk.CellRenderer cell, Gtk.TreeCellDataFunc cell_data) {
|
||||
Gtk.TreeViewColumn col = new Gtk.TreeViewColumn ();
|
||||
col.Title = title;
|
||||
col.PackStart (cell, true);
|
||||
col.SetCellDataFunc (cell, cell_data);
|
||||
|
||||
AppendColumn (col);
|
||||
return col;
|
||||
}
|
||||
|
||||
public Gtk.TreeViewColumn AppendColumn (string title, Gtk.CellRenderer cell, params object[] attrs) {
|
||||
Gtk.TreeViewColumn col = new Gtk.TreeViewColumn (title, cell, attrs);
|
||||
AppendColumn (col);
|
||||
return col;
|
||||
}
|
||||
|
||||
|
|
34
gtk/TreeViewColumn.custom
Normal file
34
gtk/TreeViewColumn.custom
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Gtk.TreeViewColumn.Custom - Gtk TreeViewColumn class customizations
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@ximian.com>
|
||||
//
|
||||
// (c) 2003 Rachel Hestilow
|
||||
//
|
||||
// This code is inserted after the automatically generated code.
|
||||
|
||||
|
||||
public void SetCellDataFunc(Gtk.CellRenderer cell_renderer, Gtk.TreeCellDataFunc func) {
|
||||
GtkSharp.TreeCellDataFuncWrapper func_wrapper = null;
|
||||
func_wrapper = new GtkSharp.TreeCellDataFuncWrapper (func, this);
|
||||
gtk_tree_view_column_set_cell_data_func(Handle, cell_renderer.Handle, func_wrapper.NativeDelegate, IntPtr.Zero, null);
|
||||
}
|
||||
|
||||
private void _NewWithAttributes (string title, Gtk.CellRenderer cell, Array attrs) {
|
||||
Title = title;
|
||||
PackStart (cell, true);
|
||||
for (int i = 0; (i + 1) < attrs.Length; i += 2) {
|
||||
AddAttribute (cell, (string) attrs[i], (int) attrs[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
public TreeViewColumn (string title, Gtk.CellRenderer cell, Array attrs) {
|
||||
Raw = gtk_tree_view_column_new ();
|
||||
_NewWithAttributes (title, cell, attrs);
|
||||
}
|
||||
|
||||
public TreeViewColumn (string title, Gtk.CellRenderer cell, params object[] attrs)
|
||||
{
|
||||
Raw = gtk_tree_view_column_new ();
|
||||
_NewWithAttributes (title, cell, attrs);
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ windows:
|
|||
$(CSC) /unsafe /out:gtk-hello-world.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-sharp.dll /r:../gdk/gdk-sharp.dll HelloWorld.cs
|
||||
$(CSC) /unsafe /out:button.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-sharp.dll ButtonApp.cs
|
||||
|
||||
linux: gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe treeviewdemo.exe $(GNOME_TARGETS) $(GLADE_TARGETS)
|
||||
linux: gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe treeviewdemo.exe managedtreeviewdemo.exe $(GNOME_TARGETS) $(GLADE_TARGETS)
|
||||
@ENABLE_GNOME_TRUE@ $(MAKE) -C gconf
|
||||
@ENABLE_GNOME_TRUE@ $(MAKE) -C rsvg
|
||||
|
||||
|
@ -55,6 +55,9 @@ scribble.exe: Scribble.cs
|
|||
treeviewdemo.exe: TreeViewDemo.cs
|
||||
$(MCS) --unsafe -o treeviewdemo.exe $(local_paths) $(all_assemblies) TreeViewDemo.cs
|
||||
|
||||
managedtreeviewdemo.exe: ManagedTreeViewDemo.cs
|
||||
$(MCS) --unsafe -o managedtreeviewdemo.exe $(local_paths) $(all_assemblies) ManagedTreeViewDemo.cs
|
||||
|
||||
glade-viewer.exe: GladeViewer.cs
|
||||
$(MCS) --unsafe -o glade-viewer.exe $(local_paths) $(all_assemblies) GladeViewer.cs
|
||||
|
||||
|
|
82
sample/ManagedTreeViewDemo.cs
Normal file
82
sample/ManagedTreeViewDemo.cs
Normal file
|
@ -0,0 +1,82 @@
|
|||
// 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 ();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,35 +20,20 @@ namespace GtkSamples {
|
|||
|
||||
private static void ProcessType (TreeIter parent, System.Type t)
|
||||
{
|
||||
TreeIter iter = new TreeIter ();
|
||||
|
||||
// .GetMembers() won't work due to unimplemented
|
||||
// scary classes.
|
||||
foreach (MemberInfo mi in t.GetMethods ()) {
|
||||
GLib.Value Name = new GLib.Value (mi.Name);
|
||||
GLib.Value Type = new GLib.Value (mi.ToString ());
|
||||
|
||||
store.Append (out iter, parent);
|
||||
store.SetValue (iter, 0, Name);
|
||||
store.SetValue (iter, 1, Type);
|
||||
store.AppendValues (parent, mi.Name, mi.ToString ());
|
||||
}
|
||||
}
|
||||
|
||||
private static void ProcessAssembly (TreeIter parent, Assembly asm)
|
||||
{
|
||||
TreeIter iter = new TreeIter ();
|
||||
string asm_name = asm.GetName ().Name;
|
||||
|
||||
foreach (System.Type t in asm.GetTypes ()) {
|
||||
UpdateDialog ("Loading from {0}:\n{1}", asm_name, t.ToString ());
|
||||
|
||||
GLib.Value Name = new GLib.Value (t.Name);
|
||||
GLib.Value Type = new GLib.Value (t.ToString ());
|
||||
|
||||
store.Append (out iter, parent);
|
||||
store.SetValue (iter, 0, Name);
|
||||
store.SetValue (iter, 1, Type);
|
||||
|
||||
TreeIter iter = store.AppendValues (parent, t.Name, t.ToString ());
|
||||
ProcessType (iter, t);
|
||||
}
|
||||
}
|
||||
|
@ -58,10 +43,7 @@ namespace GtkSamples {
|
|||
if (store != null)
|
||||
return;
|
||||
|
||||
store = new TreeStore ((int)TypeFundamentals.TypeString,
|
||||
(int)TypeFundamentals.TypeString);
|
||||
|
||||
TreeIter iter = new TreeIter ();
|
||||
store = new TreeStore (typeof (string), typeof (string));
|
||||
|
||||
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ()) {
|
||||
// we can't show corlib due to some unimplemented
|
||||
|
@ -70,13 +52,7 @@ namespace GtkSamples {
|
|||
|
||||
UpdateDialog ("Loading {0}", asm.GetName ().Name);
|
||||
|
||||
GLib.Value Name = new GLib.Value (asm.GetName ().Name);
|
||||
GLib.Value Type = new GLib.Value ("Assembly");
|
||||
|
||||
store.Append (out iter);
|
||||
store.SetValue (iter, 0, Name);
|
||||
store.SetValue (iter, 1, Type);
|
||||
|
||||
TreeIter iter = store.AppendValues (asm.GetName ().Name, "Assembly");
|
||||
ProcessAssembly (iter, asm);
|
||||
}
|
||||
}
|
||||
|
@ -104,19 +80,8 @@ namespace GtkSamples {
|
|||
TreeView tv = new TreeView (store);
|
||||
tv.HeadersVisible = true;
|
||||
|
||||
TreeViewColumn NameCol = new TreeViewColumn ();
|
||||
CellRenderer NameRenderer = new CellRendererText ();
|
||||
NameCol.Title = "Name";
|
||||
NameCol.PackStart (NameRenderer, true);
|
||||
NameCol.AddAttribute (NameRenderer, "text", 0);
|
||||
tv.AppendColumn (NameCol);
|
||||
|
||||
TreeViewColumn TypeCol = new TreeViewColumn ();
|
||||
CellRenderer TypeRenderer = new CellRendererText ();
|
||||
TypeCol.Title = "Type";
|
||||
TypeCol.PackStart (TypeRenderer, false);
|
||||
TypeCol.AddAttribute (TypeRenderer, "text", 1);
|
||||
tv.AppendColumn (TypeCol);
|
||||
tv.AppendColumn ("Name", new CellRendererText (), "text", 0);
|
||||
tv.AppendColumn ("Type", new CellRendererText (), "text", 1);
|
||||
|
||||
sw.Add (tv);
|
||||
|
||||
|
@ -130,7 +95,6 @@ namespace GtkSamples {
|
|||
private static void DeleteCB (System.Object o, DeleteEventArgs args)
|
||||
{
|
||||
Application.Quit ();
|
||||
args.RetVal = true;
|
||||
}
|
||||
|
||||
private static void UpdateDialog (string format, params object[] args)
|
||||
|
|
Loading…
Add table
Reference in a new issue