gtk-sharp0.0.0.0neutralGtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details.A widget for displaying both trees and lists.
Widget that displays any object that implements the
interface.
To create a tree or list in GTK#, you need to use the interface, in conjunction with the
widget. This widget is designed around a
Model/View/Controller design and consists of four major parts:
, the tree view widget
, the view column.
The cell renderers ( and others)., the model interface.
The View is composed of the first three, while the last is the
Model. One of the prime benefits of the MVC design is that
multiple views can be created of a single model. For example,
a model mapping the file system could be created for a file
manager. Many views could be created to display various parts
of the file system, but only one copy need be kept in memory.
The purpose of the cell renderers is to provide extensibility
to the widget and to allow multiple ways of rendering the same
type of data. For example, consider how to render a boolean
variable. Should you render it as a string of "True" or
"False", "On" or "Off", or should you render it as a checkbox?
A simple list:
using System;
using Gtk;
public class TreeViewSample {
public static void Main (string [] args)
{
Application.Init ();
TreeStore store = new TreeStore (typeof (string), typeof (string));
for (int i=0; i < 5; i++)
{
TreeIter iter = store.AppendValues ("Demo " + i, "Data " + i);
}
Window win = new Window ("TreeView List Demo");
win.DeleteEvent += new DeleteEventHandler (delete_cb);
win.SetDefaultSize (400,250);
ScrolledWindow sw = new ScrolledWindow ();
win.Add (sw);
TreeView tv = new TreeView ();
tv.Model = store;
tv.HeadersVisible = true;
tv.AppendColumn ("Demo", new CellRendererText (), "text", 0);
tv.AppendColumn ("Data", new CellRendererText (), "text", 1);
sw.Add (tv);
sw.Show ();
win.ShowAll ();
Application.Run ();
}
private static void delete_cb (System.Object o, DeleteEventArgs args)
{
Application.Quit ();
args.RetVal = true;
}
}
A more advanced example:
using System;
using System.Reflection;
using Gtk;
public class TreeViewDemo {
private static TreeStore store = null;
private static Dialog dialog = null;
private static Label dialog_label = null;
public TreeViewDemo ()
{
Application.Init ();
PopulateStore ();
Window win = new Window ("TreeView demo");
win.DeleteEvent += new DeleteEventHandler (DeleteCB);
win.SetDefaultSize (640,480);
ScrolledWindow sw = new ScrolledWindow ();
win.Add (sw);
TreeView tv = new TreeView (store);
tv.HeadersVisible = true;
tv.AppendColumn ("Name", new CellRendererText (), "text", 0);
tv.AppendColumn ("Type", new CellRendererText (), "text", 1);
sw.Add (tv);
dialog.Destroy ();
dialog = null;
win.ShowAll ();
Application.Run ();
}
private static void ProcessType (TreeIter parent, System.Type t)
{
foreach (MemberInfo mi in t.GetMembers ()) {
store.AppendValues (parent, mi.Name, mi.ToString ());
}
}
private static void ProcessAssembly (TreeIter parent, Assembly asm)
{
string asm_name = asm.GetName ().Name;
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 ());
ProcessType (iter, t);
}
}
private static void PopulateStore ()
{
if (store != null)
return;
store = new TreeStore (typeof (string), typeof (string));
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ()) {
UpdateDialog ("Loading {0}", asm.GetName ().Name);
TreeIter iter = store.AppendValues (asm.GetName ().Name, "Assembly");
ProcessAssembly (iter, asm);
}
}
public static void Main (string[] args)
{
new TreeViewDemo ();
}
private static void DeleteCB (System.Object o, DeleteEventArgs args)
{
Application.Quit ();
}
private static void UpdateDialog (string format, params object[] args)
{
string text = String.Format (format, args);
if (dialog == null)
{
dialog = new Dialog ();
dialog.Title = "Loading data from assemblies...";
dialog.AddButton (Stock.Cancel, 1);
dialog.Response += new ResponseHandler (ResponseCB);
dialog.SetDefaultSize (480, 100);
VBox vbox = dialog.VBox;
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 (text);
hbox.PackStart (dialog_label, false, false, 0);
dialog.ShowAll ();
} else {
dialog_label.Text = text;
while (Application.EventsPending ())
Application.RunIteration ();
}
}
private static void ResponseCB (object obj, ResponseArgs args)
{
Application.Quit ();
System.Environment.Exit (0);
}
}
Gtk.ContainerAtk.ImplementorGLib.IWrapperGLib.IWrapperSystem.IDisposableMethodSystem.Int32Removes from .
an object of type an object of type MethodSystem.VoidSets a user function for determining where a column may be dropped when dragged.
an object of type
an object of type
an object of type This function is called on every column pair in turn at the beginning of a column drag to determine where a drop can take place. If is set to be , then reverts to the default behavior of allowing all columns to be dropped everywhere.MethodSystem.VoidMoves the alignments of the to the position specified by and .
an object of type
an object of type
an object of type
an object of type
an object of type
If is , then no horizontal scrolling occurs. Likewise, if is no vertical scrolling occurs. At a minimum, one of or need to be non-. determines where the row is placed, and determines where the column is placed. Both are expected to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means center.
If is , then the alignment arguments are ignored, and the tree does the minimum amount of work to scroll the cell onto the screen. This means that the cell will be scrolled to the edge closest to its current position. If the cell is currently visible on the screen, nothing is done.
This function only works if the model is set, and is a valid row on the model. If the model changes before the is realized, the centered path will be modified to reflect this change.
MethodGdk.PixmapThis image is used for a drag icon.
an object of type an object of type Creates a representation of the row at .MethodSystem.VoidRecursively collapses all visible and expanded nodes.MethodSystem.VoidMoves to be after to .
an object of type
an object of type If is , then is placed in the first position.MethodSystem.VoidSets the current keyboard focus to be at , and selects it.
an object of type
an object of type
an object of type This is useful when you want to focus the attention of the user on a particular row. If is not , then focus is given to the column specified by it. Additionally, if is specified, and is , then editing should be started in the specified cell. This function is often followed by in order to give keyboard focus to the widget. Please note that editing can only happen when the widget is realized.MethodSystem.VoidFills with the currently-visible region of the buffer, in tree coordinates.
an object of type Convert to widget coordinates with . Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire scrollable area of the tree.MethodSystem.Int32This inserts the into the at .
an object of type
an object of type an object of type If is -1, then the is inserted at the end.MethodSystem.VoidActivates the cell determined by and .
an object of type
an object of type MethodSystem.BooleanReturns if the node pointed to by is expanded.
an object of type an object of type MethodSystem.VoidThis function should almost never be used.
an object of type
an object of type
an object of type It is meant for private use by Atk for determining the number of visible children that are removed when the user collapses a row, or a row is deleted.MethodSystem.VoidSets the compare function for the interactive search capabilities.
The wich represents the node
an object of type
an object of type MethodSystem.VoidTests if the node represented by the given path is openTo be addedMethodSystem.Int32Appends to the list of columns.
an object of type an object of type MethodSystem.VoidTo be added
an object of type
an object of type To be addedMethodSystem.VoidTo be addedTo be addedMethodSystem.BooleanCollapses a row (hides its child rows, if they exist).
an object of type an object of type MethodSystem.VoidRecursively expands all nodes.MethodSystem.VoidTo be added
an object of type To be addedMethodSystem.VoidScrolls the such that the top-left corner of the visible area is , , where and are specified in tree window coordinates.
an object of type
an object of type The must be realized before this function is called. If it is not, you probably want to be using .MethodGtk.TreeViewColumnGets the at the given position in the .
an object of type an object of type MethodSystem.BooleanOpens the row so its children are visible.
an object of type
an object of type an object of type MethodSystem.VoidResizes all columns to their optimal width.Only works after the has been realized.MethodSystem.VoidDisposes the resources associated with the object.ConstructorInternal constructor
Pointer to the C object.
An instance of TreeView, wrapping the C object.This is an internal constructor, and should not be used by user code.ConstructorCreates a new object.an object of type This is the default constructor for ConstructorCreates a new object.
an object of type an object of type In this constructor the is set from .PropertyGtk.TreeModelThe model for the TreeView.
an object of type an object of type PropertyGtk.TreeSelectionGets the associated with the TreeView.an object of type PropertyGdk.WindowTo be addedan object of type To be addedPropertySystem.BooleanWhether to display alternating, shaded rows in the .
an object of type an object of type Setting to sets a hint to the theme engine to draw rows in alternating colors.PropertySystem.BooleanView allows user to search through columns interactively.
an object of type an object of type PropertySystem.BooleanShow the column header buttons.
an object of type an object of type PropertyGtk.TreeViewColumnSet the column for the expander column.
an object of type an object of type PropertySystem.BooleanView is reorderable.
an object of type an object of type PropertyGtk.AdjustmentHorizontal Adjustment for the widget.
an object of type an object of type PropertySystem.BooleanColumn headers respond to click events.
an object of type an object of type PropertyGtk.AdjustmentVertical Adjustment for the widget.
an object of type an object of type PropertySystem.Int32Model column to search through when searching through code.
an object of type an object of type EventGtk.ScrollAdjustmentsSetHandlerTo be addedTo be addedEventGtk.RowExpandedHandlerTo be addedTo be addedEventGtk.MoveCursorHandlerTo be addedTo be addedEventGtk.TestExpandRowHandlerTo be addedTo be addedEventGtk.SelectCursorRowHandlerTo be addedTo be addedEventGtk.RowCollapsedHandlerTo be addedTo be addedEventSystem.EventHandlerTo be addedTo be addedEventGtk.ExpandCollapseCursorRowHandlerTo be addedTo be addedEventGtk.RowActivatedHandlerTo be addedTo be addedEventGtk.TestCollapseRowHandlerTo be addedTo be addedEventSystem.EventHandlerTo be addedTo be addedMethodSystem.BooleanFinds the path at the point (x, y), relative to widget coordinates.
an object of type
an object of type
an object of type an object of type It is primarily for things like popup menus. If is non-, then it will be filled with the at that point. If is non-, then it will be filled with the at that point. This function is only meaningful if TreeView is realized.MethodSystem.VoidConverts widget coordinates to coordinates for the tree window (the full scrollable area of the tree).
an object of type
an object of type
an object of type
an object of type EventGtk.ToggleCursorRowHandlerTo be addedTo be addedEventGtk.StartInteractiveSearchHandlerTo be addedTo be addedEventGtk.SelectAllHandlerTo be addedTo be addedEventGtk.SelectCursorParentHandlerTo be addedTo be addedEventGtk.UnselectAllHandlerTo be addedTo be addedMethodGtk.TreeViewColumnAdds a with a specific column title and attributes.
column title
cell renderer
attributes
The appended This function is used to append a new subclass with specific attributes to the .
The following code sample will append a new to an existing and use column 0 from the as the text to render.
CellRendererText text = new CellRendererText ();
tree_view.AppendColumn ("title", text, "text", 0);
MethodGtk.TreeViewColumnTo be added
a
a
a a To be addedMethodSystem.VoidTo be added
a
a
a
a To be addedMethodSystem.VoidExpands the treeview so the Path specified is visible. to expand to.
MethodSystem.VoidTo be added
a
a To be addedMethodSystem.VoidTo be added
a
a To be addedMethodSystem.BooleanTo be added
a
a
a
a a To be addedMethodSystem.VoidTo be added
a
a
a
a To be addedConstructorTreeView constructor
a a Creates a with as
its .
MethodSystem.VoidTo be added
a
a
a To be addedMethodSystem.VoidTo be added
a
a To be addedPropertyGLib.GTypeGType Property.a Returns the native value for .MethodGLib.GTypeTo be addeda To be addedMethodSystem.VoidDefault handler for the event.Override this method in a subclass to provide a default handler for the event.MethodSystem.BooleanDefault handler for the event.
a
a a Override this method in a subclass to provide a default handler for the event.MethodSystem.VoidDefault handler for the event.
a
a Override this method in a subclass to provide a default handler for the event.MethodSystem.BooleanDefault handler for the event.
a
a
a a Override this method in a subclass to provide a default handler for the event.MethodSystem.VoidDefault handler for the event.Override this method in a subclass to provide a default handler for the event.MethodSystem.BooleanDefault handler for the event.a Override this method in a subclass to provide a default handler for the event.MethodSystem.BooleanDefault handler for the event.a Override this method in a subclass to provide a default handler for the event.MethodSystem.VoidDefault handler for the event.
a
a Override this method in a subclass to provide a default handler for the event.MethodSystem.BooleanDefault handler for the event.a Override this method in a subclass to provide a default handler for the event.MethodSystem.BooleanDefault handler for the event.
a a Override this method in a subclass to provide a default handler for the event.MethodSystem.BooleanDefault handler for the event.
a
a a Override this method in a subclass to provide a default handler for the event.MethodSystem.BooleanDefault handler for the event.a Override this method in a subclass to provide a default handler for the event.MethodSystem.BooleanDefault handler for the event.
a
a a Override this method in a subclass to provide a default handler for the event.MethodSystem.VoidDefault handler for the event.
a
a Override this method in a subclass to provide a default handler for the event.MethodSystem.BooleanDefault handler for the event.a Override this method in a subclass to provide a default handler for the event.MethodSystem.VoidDefault handler for the event.
a
a Override this method in a subclass to provide a default handler for the event.ConstructorProtected Constructor.
a a Chain to this constructor if you have manually registered a native value for your subclass.PropertyGtk.TreeViewColumn[]To be addeda To be addedMethodGdk.RectangleFills the bounding rectangle in tree window coordinates for the cell at the row specified by and the column specified by .
a
a a
If is , or points to a path not currently displayed, the y and height fields of the rectangle will be filled with 0. If is , the x and width fields will be filled with 0. The sum of all cell rects does not cover the entire tree; there are extra pixels in between rows, for example. This function is only valid if is realized.
MethodGdk.RectangleFills the bounding rectangle in tree window coordinates for the cell at the row specified by and the column specified by .
a
a a
If is , or points to a node not found in the tree, the y and height fields of the rectangle will be filled with 0. If is , the x and width fields will be filled with 0. The returned rectangle is equivalent to the passed to . These background areas tile to cover the entire tree window (except for the area used for header buttons). Contrast with the , returned by , which returns only the cell itself, excluding surrounding borders and the tree expander area.
MethodSystem.BooleanFinds the path at the point (x, y), relative to widget coordinates.
a
a
a
a
a
a a To be addedMethodSystem.BooleanTo be added
a
a
a
a a To be added