2004-12-16 Mike Kestner <mkestner@novell.com>

* sample/NodeViewDemo.cs : rework of TreeViewDemo to use NodeStore.
	* sample/TreeViewDemo.cs : added some timing and node counting fu.

2004-12-16  Duncan Mak  <duncan@ximian.com>

	* gtk/Makefile.am (sources): Added NodeSelection and NodeView.
	* gtk/NodeSelection.cs: New file, an implementation of
 	TreeSelection that exposes ITreeNodes instead of TreeIters.
	* gtk/NodeStore.cs : added internal GetIter and GetPath methods for 
	NodeSelection. Reworked [TreeNodeValue] lookup logic.
 	out what the Type of data the store holds.
	* gtk/NodeView.cs: New subclass of TreeView utilizing NodeStore and
	NodeSelection.
	* gtk/TreeIter.custom : new internal UserData prop.
	* gtk/TreeNodeValueAttribute.cs: Set AllowMultiple to true.
	* gtk/TreeView.custom: Obsoleted constructor that uses a NodeStore as
 	parameter. NodeView should be used instead.

svn path=/trunk/gtk-sharp/; revision=37845
This commit is contained in:
Mike Kestner 2004-12-16 20:30:43 +00:00
parent 256bc09aee
commit 48358ccf22
14 changed files with 763 additions and 56 deletions

View file

@ -1,3 +1,23 @@
2004-12-16 Mike Kestner <mkestner@novell.com>
* sample/NodeViewDemo.cs : rework of TreeViewDemo to use NodeStore.
* sample/TreeViewDemo.cs : added some timing and node counting fu.
2004-12-16 Duncan Mak <duncan@ximian.com>
* gtk/Makefile.am (sources): Added NodeSelection and NodeView.
* gtk/NodeSelection.cs: New file, an implementation of
TreeSelection that exposes ITreeNodes instead of TreeIters.
* gtk/NodeStore.cs : added internal GetIter and GetPath methods for
NodeSelection. Reworked [TreeNodeValue] lookup logic.
out what the Type of data the store holds.
* gtk/NodeView.cs: New subclass of TreeView utilizing NodeStore and
NodeSelection.
* gtk/TreeIter.custom : new internal UserData prop.
* gtk/TreeNodeValueAttribute.cs: Set AllowMultiple to true.
* gtk/TreeView.custom: Obsoleted constructor that uses a NodeStore as
parameter. NodeView should be used instead.
2004-12-16 Tambet Ingo <tambet@ximian.com>
* glib/Opaque.cs : hold a weakref in the hash, not a strong ref.

View file

@ -0,0 +1,240 @@
<Type Name="NodeSelection" FullName="Gtk.NodeSelection">
<TypeSignature Language="C#" Value="public class NodeSelection" Maintainer="auto" />
<AssemblyInfo>
<AssemblyName>gtk-sharp</AssemblyName>
<AssemblyPublicKey>[00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4]</AssemblyPublicKey>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyCulture>neutral</AssemblyCulture>
<Attributes />
</AssemblyInfo>
<ThreadSafetyStatement>Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details.</ThreadSafetyStatement>
<Docs>
<summary>Accessing and manipulates the selected rows of a <see cref="T:Gtk.NodeView" />.</summary>
<remarks />
</Docs>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes />
<Members>
<Member MemberName="NodeIsSelected">
<MemberSignature Language="C#" Value="public bool NodeIsSelected (Gtk.ITreeNode node);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="node" Type="Gtk.ITreeNode" />
</Parameters>
<Docs>
<summary>Tests if a specified node is currently selected.</summary>
<param name="node">a <see cref="T:Gtk.ITreeNode" /></param>
<returns>a <see cref="T:System.Boolean" /></returns>
<remarks />
</Docs>
</Member>
<Member MemberName="PathIsSelected">
<MemberSignature Language="C#" Value="public bool PathIsSelected (Gtk.TreePath path);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="path" Type="Gtk.TreePath" />
</Parameters>
<Docs>
<summary>Tests if a specified path is currently selected.</summary>
<param name="path">a <see cref="T:Gtk.TreePath" /></param>
<returns>a <see cref="T:System.Boolean" /></returns>
<remarks />
</Docs>
</Member>
<Member MemberName="SelectAll">
<MemberSignature Language="C#" Value="public void SelectAll ();" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Selects all the nodes in the view.</summary>
<remarks />
</Docs>
</Member>
<Member MemberName="SelectNode">
<MemberSignature Language="C#" Value="public void SelectNode (Gtk.ITreeNode node);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="node" Type="Gtk.ITreeNode" />
</Parameters>
<Docs>
<summary>Selects a specified node in the view.</summary>
<param name="node">a <see cref="T:Gtk.ITreeNode" /></param>
<remarks />
</Docs>
</Member>
<Member MemberName="SelectPath">
<MemberSignature Language="C#" Value="public void SelectPath (Gtk.TreePath path);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="path" Type="Gtk.TreePath" />
</Parameters>
<Docs>
<summary>Selects a node by path.</summary>
<param name="path">a <see cref="T:Gtk.TreePath" /></param>
<remarks />
</Docs>
</Member>
<Member MemberName="SelectRange">
<MemberSignature Language="C#" Value="public void SelectRange (Gtk.ITreeNode begin_node, Gtk.ITreeNode end_node);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="begin_node" Type="Gtk.ITreeNode" />
<Parameter Name="end_node" Type="Gtk.ITreeNode" />
</Parameters>
<Docs>
<summary>Selects all the nodes in a specified range.</summary>
<param name="begin_node">a <see cref="T:Gtk.ITreeNode" /></param>
<param name="end_node">a <see cref="T:Gtk.ITreeNode" /></param>
<remarks />
</Docs>
</Member>
<Member MemberName="UnselectAll">
<MemberSignature Language="C#" Value="public void UnselectAll ();" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Unselects all the nodes in the view.</summary>
<remarks />
</Docs>
</Member>
<Member MemberName="UnselectNode">
<MemberSignature Language="C#" Value="public void UnselectNode (Gtk.ITreeNode node);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="node" Type="Gtk.ITreeNode" />
</Parameters>
<Docs>
<summary>Unselects a specified node.</summary>
<param name="node">a <see cref="T:Gtk.ITreeNode" /></param>
<remarks />
</Docs>
</Member>
<Member MemberName="UnselectPath">
<MemberSignature Language="C#" Value="public void UnselectPath (Gtk.TreePath path);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="path" Type="Gtk.TreePath" />
</Parameters>
<Docs>
<summary>Unselects a specified node by path.</summary>
<param name="path">a <see cref="T:Gtk.TreePath" /></param>
<remarks />
</Docs>
</Member>
<Member MemberName="UnselectRange">
<MemberSignature Language="C#" Value="public void UnselectRange (Gtk.TreePath begin, Gtk.TreePath end);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="begin" Type="Gtk.TreePath" />
<Parameter Name="end" Type="Gtk.TreePath" />
</Parameters>
<Docs>
<summary>Unselects all the nodes in a specified range.</summary>
<param name="begin">a <see cref="T:Gtk.TreePath" /></param>
<param name="end">a <see cref="T:Gtk.TreePath" /></param>
<remarks />
</Docs>
</Member>
<Member MemberName="UnselectRange">
<MemberSignature Language="C#" Value="public void UnselectRange (Gtk.ITreeNode begin_node, Gtk.ITreeNode end_node);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="begin_node" Type="Gtk.ITreeNode" />
<Parameter Name="end_node" Type="Gtk.ITreeNode" />
</Parameters>
<Docs>
<summary>Unselects all the nodes in a specified range.</summary>
<param name="begin_node">a <see cref="T:Gtk.ITreeNode" /></param>
<param name="end_node">a <see cref="T:Gtk.ITreeNode" /></param>
<remarks />
</Docs>
</Member>
<Member MemberName="Mode">
<MemberSignature Language="C#" Value="public Gtk.SelectionMode Mode { set; get; };" />
<MemberType>Property</MemberType>
<ReturnValue>
<ReturnType>Gtk.SelectionMode</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Selection mode currently is use.</summary>
<returns>a <see cref="T:Gtk.SelectionMode" /></returns>
<remarks />
</Docs>
</Member>
<Member MemberName="NodeView">
<MemberSignature Language="C#" Value="public Gtk.NodeView NodeView { get; };" />
<MemberType>Property</MemberType>
<ReturnValue>
<ReturnType>Gtk.NodeView</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>The view associated with this selection object.</summary>
<returns>a <see cref="T:Gtk.NodeView" /></returns>
<remarks />
</Docs>
</Member>
<Member MemberName="SelectedNodes">
<MemberSignature Language="C#" Value="public Gtk.ITreeNode [] SelectedNodes { get; };" />
<MemberType>Property</MemberType>
<ReturnValue>
<ReturnType>Gtk.ITreeNode[]</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>The currently selected nodes.</summary>
<returns>a <see cref="T:Gtk.ITreeNode[]" /></returns>
<remarks />
</Docs>
</Member>
<Member MemberName="Changed">
<MemberSignature Language="C#" Value="public event EventHandler Changed;" />
<MemberType>Event</MemberType>
<ReturnValue>
<ReturnType>System.EventHandler</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>The currently selected row(s) changed.</summary>
<remarks />
</Docs>
</Member>
</Members>
</Type>

72
doc/en/Gtk/NodeView.xml Normal file
View file

@ -0,0 +1,72 @@
<Type Name="NodeView" FullName="Gtk.NodeView">
<TypeSignature Language="C#" Value="public class NodeView : Gtk.TreeView, Implementor, IWrapper, IDisposable" Maintainer="auto" />
<AssemblyInfo>
<AssemblyName>gtk-sharp</AssemblyName>
<AssemblyPublicKey>[00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4]</AssemblyPublicKey>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyCulture>neutral</AssemblyCulture>
<Attributes />
</AssemblyInfo>
<ThreadSafetyStatement>Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details.</ThreadSafetyStatement>
<Docs>
<summary>Tree and List view.</summary>
<remarks />
</Docs>
<Base>
<BaseTypeName>Gtk.TreeView</BaseTypeName>
</Base>
<Interfaces>
<Interface>
<InterfaceName>Atk.Implementor</InterfaceName>
</Interface>
<Interface>
<InterfaceName>GLib.IWrapper</InterfaceName>
</Interface>
<Interface>
<InterfaceName>System.IDisposable</InterfaceName>
</Interface>
</Interfaces>
<Attributes />
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public NodeView (Gtk.NodeStore store);" />
<MemberType>Constructor</MemberType>
<ReturnValue />
<Parameters>
<Parameter Name="store" Type="Gtk.NodeStore" />
</Parameters>
<Docs>
<summary>Constructs a new view for a given <see cref="T:Gtk.NodeStore" />.</summary>
<param name="store">a <see cref="T:Gtk.NodeStore" /></param>
<returns>a <see cref="T:Gtk.NodeView" /></returns>
<remarks />
</Docs>
</Member>
<Member MemberName="NodeStore">
<MemberSignature Language="C#" Value="public Gtk.NodeStore NodeStore { get; };" />
<MemberType>Property</MemberType>
<ReturnValue>
<ReturnType>Gtk.NodeStore</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>The store containing the view's data.</summary>
<returns>a <see cref="T:Gtk.NodeStore" /></returns>
<remarks />
</Docs>
</Member>
<Member MemberName="NodeSelection">
<MemberSignature Language="C#" Value="public Gtk.NodeSelection NodeSelection { get; };" />
<MemberType>Property</MemberType>
<ReturnValue>
<ReturnType>Gtk.NodeSelection</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Used to obtain and manipulate the currently selected node(s).</summary>
<returns>a <see cref="T:Gtk.NodeSelection" /></returns>
<remarks />
</Docs>
</Member>
</Members>
</Type>

View file

@ -1795,4 +1795,4 @@ tree_view.AppendColumn ("title", text, "text", 0);
</Docs>
</Member>
</Members>
</Type>
</Type>

View file

@ -21,7 +21,9 @@ sources = \
Application.cs \
ChildPropertyAttribute.cs \
ITreeNode.cs \
NodeSelection.cs \
NodeStore.cs \
NodeView.cs \
RadioActionEntry.cs \
ThreadNotify.cs \
ToggleActionEntry.cs \

135
gtk/NodeSelection.cs Normal file
View file

@ -0,0 +1,135 @@
// NodeSelection.cs - a TreeSelection implementation that exposes ITreeNodes
//
// Author: Duncan Mak (duncan@ximian.com)
//
// Copyright (c) 2004 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
namespace Gtk {
using System;
public class NodeSelection {
private TreeSelection selection;
public event EventHandler Changed;
internal NodeSelection (TreeSelection selection)
{
this.selection = selection;
selection.Changed += new EventHandler (ChangedHandler);
}
private void ChangedHandler (object o, EventArgs args)
{
if (Changed != null)
Changed (this, args);
}
public bool NodeIsSelected (ITreeNode node)
{
return selection.IterIsSelected (NodeView.NodeStore.GetIter (node));
}
public bool PathIsSelected (TreePath path)
{
return selection.PathIsSelected (path);
}
public void SelectAll ()
{
selection.SelectAll ();
}
public void SelectNode (ITreeNode node)
{
selection.SelectIter (NodeView.NodeStore.GetIter (node));
}
public void SelectPath (TreePath path)
{
selection.SelectPath (path);
}
public void SelectRange (ITreeNode begin_node, ITreeNode end_node)
{
TreePath begin = NodeView.NodeStore.GetPath (begin_node);
TreePath end = NodeView.NodeStore.GetPath (end_node);
selection.SelectRange (begin, end);
}
public void UnselectAll ()
{
selection.UnselectAll ();
}
public void UnselectNode (ITreeNode node)
{
selection.UnselectIter (NodeView.NodeStore.GetIter (node));
}
public void UnselectPath (TreePath path)
{
selection.UnselectPath (path);
}
public void UnselectRange (TreePath begin, TreePath end)
{
selection.UnselectRange (begin, end);
}
public void UnselectRange (ITreeNode begin_node, ITreeNode end_node)
{
TreePath begin = NodeView.NodeStore.GetPath (begin_node);
TreePath end = NodeView.NodeStore.GetPath (end_node);
selection.UnselectRange (begin, end);
}
public SelectionMode Mode {
get {
return selection.Mode;
}
set {
selection.Mode = value;
}
}
public NodeView NodeView {
get {
return selection.TreeView as NodeView;
}
}
public ITreeNode[] SelectedNodes {
get {
TreeModel model;
TreePath [] paths = selection.GetSelectedRows (out model);
int length = paths.Length;
ITreeNode [] results = new ITreeNode [length];
for (int i = 0; i < length; i++)
results [i] = NodeView.NodeStore.GetNode (paths [i]);
return results;
}
}
}
}

View file

@ -80,7 +80,7 @@ namespace Gtk {
int stamp;
Hashtable node_hash = new IDHashtable ();
GLib.GType[] ctypes;
GLib.GType[] ctypes;
PropertyInfo[] getters;
int n_cols = 1;
ArrayList nodes = new ArrayList ();
@ -120,22 +120,10 @@ namespace Gtk {
IntPtr get_path_cb (int node_idx)
{
TreePath path = new TreePath ();
int idx;
ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null) throw new Exception ("Invalid Node ID");
while (node.Parent != null) {
idx = node.Parent.IndexOf (node);
if (idx < 0) throw new Exception ("Badly formed tree");
path.PrependIndex (idx);
node = node.Parent;
}
idx = Nodes.IndexOf (node);
if (idx < 0) throw new Exception ("Node not found in Nodes list");
path.PrependIndex (idx);
return path.Handle;
return GetPath (node).Handle;
}
[DllImport("libgobject-2.0-0.dll")]
@ -294,45 +282,24 @@ namespace Gtk {
void ScanType (Type type)
{
object[] attrs = type.GetCustomAttributes (false);
foreach (object attr in attrs) {
switch (attr.ToString ()) {
case "Gtk.TreeNodeAttribute":
TreeNodeAttribute tna = attr as TreeNodeAttribute;
n_cols = tna.ColumnCount;
break;
default:
Console.WriteLine ("Unknown attr: " + attr);
break;
}
}
foreach (TreeNodeAttribute attr in type.GetCustomAttributes (typeof (TreeNodeAttribute), false))
n_cols = attr.ColumnCount;
ctypes = new GLib.GType [n_cols];
getters = new PropertyInfo [n_cols];
MemberInfo[] info = type.GetMembers ();
foreach (MemberInfo mi in info) {
PropertyInfo pi;
object[] attr_info = mi.GetCustomAttributes (false);
foreach (object attr in attr_info) {
switch (attr.ToString ()) {
case "Gtk.TreeNodeValueAttribute":
TreeNodeValueAttribute tnva = attr as TreeNodeValueAttribute;
int col = tnva.Column;
pi = mi as PropertyInfo;
getters [col] = pi;
GLib.GType ctype = GLib.TypeConverter.LookupType (pi.PropertyType);
if (ctype == GLib.GType.Invalid)
throw new Exception ("Unknown type");
ctypes[col] = ctype;
break;
default:
Console.WriteLine ("Unknown custom attr: " + attr);
break;
}
foreach (PropertyInfo pi in type.GetProperties ()) {
foreach (TreeNodeValueAttribute attr in pi.GetCustomAttributes (typeof (TreeNodeValueAttribute), false)) {
int col = attr.Column;
getters [col] = pi;
GLib.GType ctype = GLib.TypeConverter.LookupType (pi.PropertyType);
if (ctype == GLib.GType.Invalid)
throw new Exception ("Unknown type");
ctypes[col] = ctype;
}
}
}
private IList Nodes {
get {
return nodes as IList;
@ -439,6 +406,30 @@ namespace Gtk {
return GetNodeAtPath (path);
}
internal TreePath GetPath (ITreeNode node)
{
TreePath path = new TreePath ();
int idx;
while (node.Parent != null) {
idx = node.Parent.IndexOf (node);
if (idx < 0) throw new Exception ("Badly formed tree");
path.PrependIndex (idx);
node = node.Parent;
}
idx = Nodes.IndexOf (node);
if (idx < 0) throw new Exception ("Node not found in Nodes list");
path.PrependIndex (idx);
return path;
}
internal TreeIter GetIter (ITreeNode node)
{
TreeIter iter = new TreeIter ();
iter.UserData = new IntPtr (node.ID);
return iter;
}
[DllImport("gtksharpglue-2")]
static extern IntPtr gtksharp_node_store_get_type ();

64
gtk/NodeView.cs Normal file
View file

@ -0,0 +1,64 @@
// NodeView.cs - a TreeView implementation that exposes ITreeNodes
//
// Author: Duncan Mak (duncan@ximian.com)
//
// Copyright (c) 2004 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.
namespace Gtk {
using System;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;
public class NodeView : TreeView {
[DllImport("libgtk-win32-2.0-0.dll")]
static extern IntPtr gtk_tree_view_new_with_model(IntPtr model);
NodeStore store;
public NodeView (NodeStore store) : base (IntPtr.Zero)
{
if (GetType() != typeof (NodeView)) {
string[] names = { "model" };
GLib.Value[] vals = { new GLib.Value (store) };
CreateNativeObject (names, vals);
vals [0].Dispose ();
} else {
Raw = gtk_tree_view_new_with_model (store.Handle);
}
this.store = store;
}
public NodeStore NodeStore {
get {
return store;
}
}
public NodeSelection NodeSelection {
get {
return new NodeSelection (Selection);
}
}
}
}

View file

@ -34,3 +34,13 @@
ti._user_data2 == _user_data2 &&
ti._user_data3 == _user_data3;
}
internal IntPtr UserData {
get {
return _user_data;
}
set {
_user_data = value;
}
}

View file

@ -23,17 +23,14 @@ namespace Gtk {
using System;
[AttributeUsage(AttributeTargets.Property)]
[AttributeUsage (AttributeTargets.Property, AllowMultiple = true)]
public sealed class TreeNodeValueAttribute : Attribute {
int col;
public int Column {
get {
return col;
}
set {
col = value;
}
get { return col; }
set { col = value; }
}
}
}

View file

@ -24,7 +24,7 @@
// Boston, MA 02111-1307, USA.
[Obsolete ("Use NodeView with NodeStores")]
public TreeView (NodeStore store) : base (IntPtr.Zero)
{
if (GetType() != typeof (TreeView)) {

View file

@ -32,7 +32,7 @@ VTE_TARGETS=
VTE_ASSEMBLY=
endif
TARGETS = custom-notebook.exe drawing-sample.exe custom-widget.exe custom-cellrenderer.exe gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe scribble-xinput.exe treeviewdemo.exe managedtreeviewdemo.exe testdnd.exe actions.exe $(GNOMEVFS_TARGETS) $(GNOME_TARGETS) $(GLADE_TARGETS) $(VTE_TARGETS)
TARGETS = custom-notebook.exe drawing-sample.exe custom-widget.exe custom-cellrenderer.exe gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe scribble-xinput.exe treeviewdemo.exe managedtreeviewdemo.exe nodeviewdemo.exe testdnd.exe actions.exe $(GNOMEVFS_TARGETS) $(GNOME_TARGETS) $(GLADE_TARGETS) $(VTE_TARGETS)
assemblies=../glib/glib-sharp.dll ../pango/pango-sharp.dll ../atk/atk-sharp.dll ../gdk/gdk-sharp.dll ../gtk/gtk-sharp.dll $(GNOMEVFS_ASSEMBLY) $(GNOME_ASSEMBLY) $(GLADE_ASSEMBLY) $(VTE_ASSEMBLY)
references=$(addprefix /r:, $(assemblies))
@ -82,6 +82,9 @@ treeviewdemo.exe: $(srcdir)/TreeViewDemo.cs $(assemblies)
managedtreeviewdemo.exe: $(srcdir)/ManagedTreeViewDemo.cs $(assemblies)
$(CSC) /out:managedtreeviewdemo.exe $(references) $(srcdir)/ManagedTreeViewDemo.cs
nodeviewdemo.exe: $(srcdir)/NodeViewDemo.cs $(assemblies)
$(CSC) /out:nodeviewdemo.exe $(references) $(srcdir)/NodeViewDemo.cs
glade-viewer.exe: $(srcdir)/GladeViewer.cs $(assemblies)
$(CSC) /out:glade-viewer.exe $(references) $(srcdir)/GladeViewer.cs
@ -130,6 +133,7 @@ EXTRA_DIST = \
ScribbleXInput.cs \
TreeViewDemo.cs \
ManagedTreeViewDemo.cs \
NodeViewDemo.cs \
GladeViewer.cs \
GladeTest.cs \
test.glade \

164
sample/NodeViewDemo.cs Normal file
View file

@ -0,0 +1,164 @@
// NodeViewDemo.cs - rework of TreeViewDemo to use NodeView.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2004 Novell, Inc.
namespace GtkSamples {
using System;
using System.Reflection;
using Gtk;
[TreeNode (ColumnCount=2)]
public class DemoTreeNode : TreeNode {
string name;
string desc;
static int count = 0;
public DemoTreeNode (string name, string desc)
{
this.name = name;
this.desc = desc;
count++;
}
[TreeNodeValue (Column=0)]
public string Name {
get { return name; }
}
[TreeNodeValue (Column=1)]
public string Description {
get { return desc; }
}
public static int Count {
get {
return count;
}
}
}
public class NodeViewDemo : Gtk.Window {
NodeStore store;
StatusDialog dialog;
public NodeViewDemo () : base ("NodeView demo")
{
DeleteEvent += new DeleteEventHandler (DeleteCB);
DefaultSize = new Gdk.Size (640,480);
ScrolledWindow sw = new ScrolledWindow ();
Add (sw);
NodeView view = new NodeView (Store);
view.HeadersVisible = true;
view.AppendColumn ("Name", new CellRendererText (), "text", 0);
view.AppendColumn ("Type", new CellRendererText (), "text", 1);
sw.Add (view);
dialog.Destroy ();
dialog = null;
}
StatusDialog Dialog {
get {
if (dialog == null)
dialog = new StatusDialog ();
return dialog;
}
}
void ProcessType (DemoTreeNode parent, System.Type t)
{
foreach (MemberInfo mi in t.GetMembers ())
parent.AddChild (new DemoTreeNode (mi.Name, mi.ToString ()));
}
void ProcessAssembly (DemoTreeNode parent, Assembly asm)
{
string asm_name = asm.GetName ().Name;
foreach (System.Type t in asm.GetTypes ()) {
Dialog.Update ("Loading from {0}:\n{1}", asm_name, t.ToString ());
DemoTreeNode node = new DemoTreeNode (t.Name, t.ToString ());
ProcessType (node, t);
parent.AddChild (node);
}
}
NodeStore Store {
get {
if (store == null) {
store = new NodeStore (typeof (DemoTreeNode));
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ()) {
Dialog.Update ("Loading {0}", asm.GetName ().Name);
DemoTreeNode node = new DemoTreeNode (asm.GetName ().Name, "Assembly");
ProcessAssembly (node, asm);
store.AddNode (node);
}
}
return store;
}
}
public static void Main (string[] args)
{
DateTime start = DateTime.Now;
Application.Init ();
Gtk.Window win = new NodeViewDemo ();
win.ShowAll ();
Console.WriteLine (DemoTreeNode.Count + " nodes created.");
Console.WriteLine ("startup time: " + DateTime.Now.Subtract (start));
Application.Run ();
}
void DeleteCB (System.Object o, DeleteEventArgs args)
{
Application.Quit ();
}
}
public class StatusDialog : Gtk.Dialog {
Label dialog_label;
public StatusDialog () : base ()
{
Title = "Loading data from assemblies...";
AddButton (Stock.Cancel, 1);
Response += new ResponseHandler (ResponseCB);
DefaultSize = new Gdk.Size (480, 100);
HBox hbox = new HBox (false, 4);
VBox.PackStart (hbox, true, true, 0);
Gtk.Image icon = new Gtk.Image (Stock.DialogInfo, IconSize.Dialog);
hbox.PackStart (icon, false, false, 0);
dialog_label = new Label ("");
hbox.PackStart (dialog_label, false, false, 0);
ShowAll ();
}
public void Update (string format, params object[] args)
{
string text = String.Format (format, args);
dialog_label.Text = text;
while (Application.EventsPending ())
Application.RunIteration ();
}
private static void ResponseCB (object obj, ResponseArgs args)
{
Application.Quit ();
System.Environment.Exit (0);
}
}
}

View file

@ -14,9 +14,12 @@ namespace GtkSamples {
private static TreeStore store = null;
private static Dialog dialog = null;
private static Label dialog_label = null;
private static int count = 0;
public TreeViewDemo ()
{
DateTime start = DateTime.Now;
Application.Init ();
PopulateStore ();
@ -42,6 +45,8 @@ namespace GtkSamples {
win.ShowAll ();
Console.WriteLine (count + " nodes added.");
Console.WriteLine ("Startup time: " + DateTime.Now.Subtract (start));
Application.Run ();
}
@ -49,6 +54,7 @@ namespace GtkSamples {
{
foreach (MemberInfo mi in t.GetMembers ()) {
store.AppendValues (parent, mi.Name, mi.ToString ());
count++;
}
}
@ -59,6 +65,7 @@ namespace GtkSamples {
foreach (System.Type t in asm.GetTypes ()) {
UpdateDialog ("Loading from {0}:\n{1}", asm_name, t.ToString ());
TreeIter iter = store.AppendValues (parent, t.Name, t.ToString ());
count++;
ProcessType (iter, t);
}
}
@ -75,6 +82,7 @@ namespace GtkSamples {
UpdateDialog ("Loading {0}", asm.GetName ().Name);
TreeIter iter = store.AppendValues (asm.GetName ().Name, "Assembly");
count++;
ProcessAssembly (iter, asm);
}
}