1 // Gtk.TreeView.cs - Gtk TreeView class customizations
2 //
3 // Authors:
4 //	Kristian Rietveld <kris@gtk.org>
5 //	Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // Copyright (c) 2002 Kristian Rietveld
8 // Copyright (c) 2003 Ximian, Inc. (http://www.ximian.com)
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of version 2 of the Lesser GNU General
12 // Public License as published by the Free Software Foundation.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this program; if not, write to the
21 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 // Boston, MA 02111-1307, USA.
23 
24 namespace Gtk {
25 
26 	using System;
27 	using System.Runtime.InteropServices;
28 
29 	public partial class TreeView {
30 
31 		public Gdk.Color OddRowColor {
32 			get {
33 				GLib.Value value = StyleGetPropertyValue ("odd-row-color");
34 				Gdk.Color ret = (Gdk.Color)value;
35 				value.Dispose ();
36 				return ret;
37 			}
38 		}
39 
40 		public Gdk.Color EvenRowColor {
41 			get {
42 				GLib.Value value = StyleGetPropertyValue ("even-row-color");
43 				Gdk.Color ret = (Gdk.Color)value;
44 				value.Dispose ();
45 				return ret;
46 			}
47 		}
48 
49 		[DllImport (Global.GtkNativeDll, CallingConvention = CallingConvention.Cdecl)]
gtk_tree_view_get_path_at_pos(IntPtr raw, int x, int y, out IntPtr path, out IntPtr column, out int cell_x, out int cell_y)50 		static extern bool gtk_tree_view_get_path_at_pos (IntPtr raw,
51 								  int x,
52 								  int y,
53 								  out IntPtr path,
54 								  out IntPtr column,
55 								  out int cell_x,
56 								  out int cell_y);
57 
58 		[DllImport (Global.GtkNativeDll, EntryPoint="gtk_tree_view_get_path_at_pos", CallingConvention = CallingConvention.Cdecl)]
gtk_tree_view_get_path_at_pos_intptr(IntPtr raw, int x, int y, out IntPtr path, out IntPtr column, IntPtr cell_x, IntPtr cell_y)59 		static extern bool gtk_tree_view_get_path_at_pos_intptr (IntPtr raw,
60 								  int x,
61 								  int y,
62 								  out IntPtr path,
63 								  out IntPtr column,
64 								  IntPtr cell_x,
65 								  IntPtr cell_y);
66 
GetPathAtPos(int x, int y, out Gtk.TreePath path, out Gtk.TreeViewColumn column, out int cell_x, out int cell_y)67 		public bool GetPathAtPos (int x, int y, out Gtk.TreePath path, out Gtk.TreeViewColumn column, out int cell_x, out int cell_y)
68 		{
69 			IntPtr pathHandle;
70 			IntPtr columnHandle;
71 			bool raw_ret = gtk_tree_view_get_path_at_pos (Handle, x, y, out pathHandle, out columnHandle, out cell_x, out cell_y);
72 			if (raw_ret) {
73 				column = (Gtk.TreeViewColumn) GLib.Object.GetObject (columnHandle, false);
74 				path = (Gtk.TreePath) GLib.Opaque.GetOpaque (pathHandle, typeof (Gtk.TreePath), true);
75 			} else {
76 				path = null;
77 				column = null;
78 			}
79 
80 			return raw_ret;
81 		}
82 
83 
GetPathAtPos(int x, int y, out Gtk.TreePath path)84 		public bool GetPathAtPos (int x, int y, out Gtk.TreePath path)
85 		{
86 			IntPtr pathHandle;
87 			IntPtr columnHandle;
88 			bool raw_ret = gtk_tree_view_get_path_at_pos_intptr (Handle, x, y, out pathHandle, out columnHandle, IntPtr.Zero, IntPtr.Zero);
89 			if (raw_ret)
90 				path = (Gtk.TreePath) GLib.Opaque.GetOpaque (pathHandle, typeof (Gtk.TreePath), true);
91 			else
92 				path = null;
93 
94 			return raw_ret;
95 		}
96 
GetPathAtPos(int x, int y, out Gtk.TreePath path, out Gtk.TreeViewColumn column)97 		public bool GetPathAtPos (int x, int y, out Gtk.TreePath path, out Gtk.TreeViewColumn column)
98 		{
99 			IntPtr pathHandle;
100 			IntPtr columnHandle;
101 			bool raw_ret = gtk_tree_view_get_path_at_pos_intptr (Handle, x, y, out pathHandle, out columnHandle, IntPtr.Zero, IntPtr.Zero);
102 			if (raw_ret) {
103 				path = (Gtk.TreePath) GLib.Opaque.GetOpaque (pathHandle, typeof (Gtk.TreePath), true);
104 				column = (Gtk.TreeViewColumn) GLib.Object.GetObject (columnHandle, false);
105 			} else {
106 				path = null;
107 				column = null;
108 			}
109 
110 			return raw_ret;
111 		}
112 
AppendColumn(string title, CellRenderer cell, TreeCellDataFunc cell_data)113 		public TreeViewColumn AppendColumn (string title, CellRenderer cell, TreeCellDataFunc cell_data)
114 		{
115 			Gtk.TreeViewColumn col = new Gtk.TreeViewColumn ();
116 			col.Title = title;
117 			col.PackStart (cell, true);
118 			col.SetCellDataFunc (cell, cell_data);
119 
120 			AppendColumn (col);
121 			return col;
122 		}
123 
AppendColumn(string title, CellRenderer cell, CellLayoutDataFunc cell_data)124 		public TreeViewColumn AppendColumn (string title, CellRenderer cell, CellLayoutDataFunc cell_data) {
125 			Gtk.TreeViewColumn col = new Gtk.TreeViewColumn ();
126 			col.Title = title;
127 			col.PackStart (cell, true);
128 			col.SetCellDataFunc (cell, cell_data);
129 
130 			AppendColumn (col);
131 			return col;
132 		}
133 
AppendColumn(string title, Gtk.CellRenderer cell, params object[] attrs)134 		public Gtk.TreeViewColumn AppendColumn (string title, Gtk.CellRenderer cell, params object[] attrs) {
135 			Gtk.TreeViewColumn col = new Gtk.TreeViewColumn (title, cell, attrs);
136 			AppendColumn (col);
137 			return col;
138 		}
139 
InsertColumn(int pos, string title, CellRenderer cell, CellLayoutDataFunc cell_data)140 		public int InsertColumn (int pos, string title, CellRenderer cell, CellLayoutDataFunc cell_data)
141 		{
142 			TreeViewColumn col = new TreeViewColumn ();
143 			col.Title = title;
144 			col.PackStart (cell, true);
145 			col.SetCellDataFunc (cell, cell_data);
146 			return InsertColumn (col, pos);
147 		}
148 
InsertColumn(int pos, string title, CellRenderer cell, params object[] attrs)149 		public int InsertColumn (int pos, string title, CellRenderer cell, params object[] attrs)
150 		{
151 			TreeViewColumn col = new TreeViewColumn (title, cell, attrs);
152 			return InsertColumn (col, pos);
153 		}
154 	}
155 }
156