From db4c8f1c2d6bf4cfb9b6ab5b1b58eb3ac3f04fe5 Mon Sep 17 00:00:00 2001 From: Rachel Hestilow Date: Sat, 10 Aug 2002 23:40:20 +0000 Subject: [PATCH] Forgot to cvs add, mike :-) svn path=/trunk/gtk-sharp/; revision=6577 --- gtk/ListStore.custom | 31 ++++++++++ gtk/TreeModel.custom | 20 +++++++ gtk/TreeModelSort.custom | 31 ++++++++++ gtk/TreeStore.custom | 111 +++++++++++++++++++++++++++++++++++ gtk/TreeView.custom | 22 +++++++ sample/TreeViewDemo.cs | 124 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 339 insertions(+) create mode 100644 gtk/ListStore.custom create mode 100644 gtk/TreeModel.custom create mode 100644 gtk/TreeModelSort.custom create mode 100644 gtk/TreeStore.custom create mode 100644 gtk/TreeView.custom create mode 100644 sample/TreeViewDemo.cs diff --git a/gtk/ListStore.custom b/gtk/ListStore.custom new file mode 100644 index 000000000..b3e2d32cb --- /dev/null +++ b/gtk/ListStore.custom @@ -0,0 +1,31 @@ +// Gtk.ListStore.Custom - Gtk ListStore class customizations +// +// Author: Kristian Rietveld +// +// (c) 2002 Kristian Rietveld +// +// This code is inserted after the automatically generated code. + + [DllImport("gtk-x11-2.0")] + static extern bool gtk_tree_model_iter_children (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent); + public bool IterChildren (out Gtk.TreeIter iter) { + bool raw_ret = gtk_tree_model_iter_children (Handle, out iter, IntPtr.Zero); + bool ret = raw_ret; + return ret; + } + + [DllImport("gtk-x11-2.0")] + static extern int gtk_tree_model_iter_n_children (IntPtr raw, IntPtr iter); + public int IterNChildren () { + int raw_ret = gtk_tree_model_iter_n_children (Handle, IntPtr.Zero); + int ret = raw_ret; + return ret; + } + + [DllImport("gtk-x11-2.0")] + static extern bool gtk_tree_model_iter_nth_child (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent, int n); + public bool IterNthChild (out Gtk.TreeIter iter, int n) { + bool raw_ret = gtk_tree_model_iter_nth_child (Handle, out iter, IntPtr.Zero, n); + bool ret = raw_ret; + return ret; + } diff --git a/gtk/TreeModel.custom b/gtk/TreeModel.custom new file mode 100644 index 000000000..1e4eed9ba --- /dev/null +++ b/gtk/TreeModel.custom @@ -0,0 +1,20 @@ +// Gtk.TreeModel.Custom - Gtk TreeModel interface customizations +// +// Author: Kristian Rietveld +// +// (c) 2002 Kristian Rietveld +// +// This code is inserted after the automatically generated code. + + /// IterChildren Method + /// To be completed + bool IterChildren (out Gtk.TreeIter iter); + + /// IterNChildren Method + /// To be completed + int IterNChildren (); + + /// IterNthChild Method + /// To be completed + bool IterNthChild (out Gtk.TreeIter iter, int n); + diff --git a/gtk/TreeModelSort.custom b/gtk/TreeModelSort.custom new file mode 100644 index 000000000..5a6f01b8a --- /dev/null +++ b/gtk/TreeModelSort.custom @@ -0,0 +1,31 @@ +// Gtk.TreeModelSort.Custom - Gtk TreeModelSort class customizations +// +// Author: Kristian Rietveld +// +// (c) 2002 Kristian Rietveld +// +// This code is inserted after the automatically generated code. + + [DllImport("gtk-x11-2.0")] + static extern bool gtk_tree_model_iter_children (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent); + public bool IterChildren (out Gtk.TreeIter iter) { + bool raw_ret = gtk_tree_model_iter_children (Handle, out iter, IntPtr.Zero); + bool ret = raw_ret; + return ret; + } + + [DllImport("gtk-x11-2.0")] + static extern int gtk_tree_model_iter_n_children (IntPtr raw, IntPtr iter); + public int IterNChildren () { + int raw_ret = gtk_tree_model_iter_n_children (Handle, IntPtr.Zero); + int ret = raw_ret; + return ret; + } + + [DllImport("gtk-x11-2.0")] + static extern bool gtk_tree_model_iter_nth_child (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent, int n); + public bool IterNthChild (out Gtk.TreeIter iter, int n) { + bool raw_ret = gtk_tree_model_iter_nth_child (Handle, out iter, IntPtr.Zero, n); + bool ret = raw_ret; + return ret; + } diff --git a/gtk/TreeStore.custom b/gtk/TreeStore.custom new file mode 100644 index 000000000..350c1f924 --- /dev/null +++ b/gtk/TreeStore.custom @@ -0,0 +1,111 @@ +// Gtk.TreeStore.Custom - Gtk TreeStore class customizations +// +// Author: Kristian Rietveld +// +// (c) 2002 Kristian Rietveld +// +// This code is inserted after the automatically generated code. + + + /// + /// Appends a row. + /// + /// + /// + /// Appends a row to the root level of the TreeStore. + /// + + [DllImport ("gtk-x11-2.0")] + static extern void gtk_tree_store_append (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent); + + public void Append (out Gtk.TreeIter iter) { + gtk_tree_store_append (Handle, out iter, IntPtr.Zero); + } + + /// + /// Inserts a row. + /// + /// + /// + /// Inserts a row in the root level of the TreeStore at + /// the given position. + /// + + [DllImport ("gtk-x11-2.0")] + static extern void gtk_tree_store_insert (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent, int position); + + public void Insert (out Gtk.TreeIter iter, int position) { + gtk_tree_store_insert (Handle, out iter, IntPtr.Zero, position); + } + + /// + /// Prepends a row. + /// + /// + /// + /// Prepends a row to the root level of the TreeStore. + /// + + [DllImport ("gtk-x11-2.0")] + static extern void gtk_tree_store_prepend (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent); + + public void Prepend (out Gtk.TreeIter iter) { + gtk_tree_store_append (Handle, out iter, IntPtr.Zero); + } + + /// + /// Inserts a row. + /// + /// + /// + /// Inserts a row in the root level of TreeStore before the + /// given sibling. + /// + + [DllImport ("gtk-x11-2.0")] + static extern void gtk_tree_store_insert_before (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent, ref Gtk.TreeIter sibling); + + public void InsertBefore (out Gtk.TreeIter iter, Gtk.TreeIter sibling) { + gtk_tree_store_insert_before (Handle, out iter, IntPtr.Zero, ref sibling); + } + + /// + /// Inserts a row. + /// + /// + /// + /// Inserts a row in the root level of TreeStore before the + /// given sibling. + /// + + [DllImport ("gtk-x11-2.0")] + static extern void gtk_tree_store_insert_after (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent, ref Gtk.TreeIter sibling); + + public void InsertAfter (out Gtk.TreeIter iter, Gtk.TreeIter sibling) { + gtk_tree_store_insert_after (Handle, out iter, IntPtr.Zero, ref sibling); + } + + + [DllImport("gtk-x11-2.0")] + static extern bool gtk_tree_model_iter_children (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent); + public bool IterChildren (out Gtk.TreeIter iter) { + bool raw_ret = gtk_tree_model_iter_children (Handle, out iter, IntPtr.Zero); + bool ret = raw_ret; + return ret; + } + + [DllImport("gtk-x11-2.0")] + static extern int gtk_tree_model_iter_n_children (IntPtr raw, IntPtr iter); + public int IterNChildren () { + int raw_ret = gtk_tree_model_iter_n_children (Handle, IntPtr.Zero); + int ret = raw_ret; + return ret; + } + + [DllImport("gtk-x11-2.0")] + static extern bool gtk_tree_model_iter_nth_child (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent, int n); + public bool IterNthChild (out Gtk.TreeIter iter, int n) { + bool raw_ret = gtk_tree_model_iter_nth_child (Handle, out iter, IntPtr.Zero, n); + bool ret = raw_ret; + return ret; + } diff --git a/gtk/TreeView.custom b/gtk/TreeView.custom new file mode 100644 index 000000000..b12afff2e --- /dev/null +++ b/gtk/TreeView.custom @@ -0,0 +1,22 @@ +// Gtk.TreeView.Custom - Gtk TreeView class customizations +// +// Author: Kristian Rietveld +// +// (c) 2002 Kristian Rietveld +// +// This code is inserted after the automatically generated code. + + + [DllImport("gtk-x11-2.0")] + static extern IntPtr gtk_tree_view_get_model (IntPtr raw); + + /// Model Property + /// Gets the model being displayed by the TreeView + /// + public Gtk.TreeModel Model { + get { + IntPtr raw_ret = gtk_tree_view_get_model (Handle); + Gtk.TreeModel ret = (Gtk.TreeModel) GLib.Object.GetObject (raw_ret); + return ret; + } + } diff --git a/sample/TreeViewDemo.cs b/sample/TreeViewDemo.cs new file mode 100644 index 000000000..449ca1317 --- /dev/null +++ b/sample/TreeViewDemo.cs @@ -0,0 +1,124 @@ +// TreeView.cs - Fun TreeView demo +// +// Author: Kristian Rietveld +// +// (c) 2002 Kristian Rietveld + +namespace GtkSamples { + using System; + using System.Drawing; + using System.Reflection; + using System.AppDomain; + + using GLib; + using Gtk; + using GtkSharp; + + public class TreeViewDemo { + private static TreeStore store = null; + + private static void ProcessType (TreeIter parent, 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); + } + } + + private static void ProcessAssembly (TreeIter parent, Assembly asm) + { + TreeIter iter = new TreeIter (); + + foreach (Type t in asm.GetTypes ()) { + 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); + + ProcessType (iter, t); + } + } + + private static void PopulateStore () + { + if (store != null) + return; + + Console.WriteLine ("Loading data from assemblies..."); + + store = new TreeStore ((int)TypeFundamentals.TypeString, + (int)TypeFundamentals.TypeString); + + TreeIter iter = new TreeIter (); + + foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ()) { + // we can't show corlib due to some unimplemented + // stuff in some scary class. + if (asm.GetName ().Name == "mscorlib") continue; + + 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); + + ProcessAssembly (iter, asm); + } + } + + public static void Main (string[] args) + { + Application.Init (); + + Window win = new Window ("TreeView demo"); + win.DeleteEvent += new EventHandler (DeleteCB); + win.DefaultSize = new Size (640,480); + + ScrolledWindow sw = new ScrolledWindow (); + win.Add (sw); + + PopulateStore (); + + 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); + + sw.Add (tv); + + win.ShowAll (); + + Application.Run (); + } + + private static void DeleteCB (Object o, EventArgs args) + { + SignalArgs sa = (SignalArgs) args; + Application.Quit (); + sa.RetVal = true; + } + } +}