5
// Lluis Sanchez <lluis@xamarin.com>
7
// Copyright (c) 2011 Xamarin Inc
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32
namespace Xwt.GtkBackend
34
class IterPos: TreePosition
40
public IterPos (int treeVersion, Gtk.TreeIter iter)
43
this.Version = treeVersion;
46
public Gtk.TreeIter Iter;
47
public Gtk.TreeIter LastChildIter;
48
public int LastChildIndex = -1;
49
public int ChildrenCount = -1;
53
public class TreeStoreBackend: TableStoreBackend, ITreeStoreBackend
58
public Gtk.TreeStore Tree {
59
get { return (Gtk.TreeStore) Store; }
62
public override Gtk.TreeModel InitializeModel (Type[] columnTypes)
64
this.columnTypes = columnTypes;
65
return new Gtk.TreeStore (columnTypes);
68
public event EventHandler<TreeNodeEventArgs> NodeInserted;
69
public event EventHandler<TreeNodeChildEventArgs> NodeDeleted;
70
public event EventHandler<TreeNodeEventArgs> NodeChanged;
71
public event EventHandler<TreeNodeOrderEventArgs> NodesReordered;
73
IterPos GetIterPos (TreePosition pos)
75
IterPos tpos = (IterPos) pos;
76
if (tpos != null && tpos.Version != version) {
77
tpos.LastChildIndex = -1;
78
tpos.ChildrenCount = -1;
89
public TreePosition GetChild (TreePosition pos, int index)
91
IterPos tpos = GetIterPos (pos);
92
if (tpos != null && tpos.LastChildIndex == index)
93
return new IterPos (version, tpos.LastChildIter);
97
if (Tree.IterChildren (out it, tpos.Iter)) {
98
tpos.LastChildIter = it;
99
tpos.LastChildIndex = 0;
100
return new IterPos (version, it);
104
if (Tree.GetIterFirst (out it))
105
return new IterPos (version, it);
112
if (Tree.IterNthChild (out it, index))
113
return new IterPos (version, it);
118
if (tpos.LastChildIndex == -1 || tpos.LastChildIndex > index) {
120
if (Tree.IterNthChild (out it, tpos.Iter, index)) {
121
tpos.LastChildIter = it;
122
tpos.LastChildIndex = index;
123
return new IterPos (version, it);
128
// tpos.LastChildIndex < index
130
Gtk.TreeIter iter = tpos.LastChildIter;
131
for (int n = tpos.LastChildIndex; n < index; n++) {
132
if (!Tree.IterNext (ref iter))
135
tpos.LastChildIter = iter;
136
tpos.LastChildIndex = index;
137
return new IterPos (version, iter);
140
public int GetChildrenCount (TreePosition pos)
143
return Tree.IterNChildren ();
145
IterPos tpos = GetIterPos (pos);
147
if (tpos.ChildrenCount != -1)
148
return tpos.ChildrenCount;
150
return tpos.ChildrenCount = Tree.IterNChildren (tpos.Iter);
153
public void SetValue (TreePosition pos, int column, object value)
155
IterPos tpos = GetIterPos (pos);
156
SetValue (tpos.Iter, column, value);
159
public object GetValue (TreePosition pos, int column)
161
IterPos tpos = GetIterPos (pos);
162
return GetValue (tpos.Iter, column);
165
public TreePosition InsertBefore (TreePosition pos)
168
IterPos tpos = GetIterPos (pos);
169
var p = Tree.InsertNodeBefore (tpos.Iter);
170
return new IterPos (version, p);
173
public TreePosition InsertAfter (TreePosition pos)
176
IterPos tpos = GetIterPos (pos);
177
var p = Tree.InsertNodeAfter (tpos.Iter);
178
return new IterPos (version, p);
181
public TreePosition AddChild (TreePosition pos)
184
IterPos tpos = GetIterPos (pos);
187
it = Tree.AppendNode ();
189
it = Tree.AppendNode (tpos.Iter);
190
return new IterPos (version, it);
193
public void Remove (TreePosition pos)
196
IterPos tpos = GetIterPos (pos);
197
Gtk.TreeIter it = tpos.Iter;
198
Tree.Remove (ref it);
201
public TreePosition GetNext (TreePosition pos)
203
IterPos tpos = GetIterPos (pos);
204
Gtk.TreeIter it = tpos.Iter;
205
if (!Tree.IterNext (ref it))
207
return new IterPos (version, it);
210
public TreePosition GetPrevious (TreePosition pos)
212
throw new NotImplementedException ();
215
public TreePosition GetParent (TreePosition pos)
217
IterPos tpos = GetIterPos (pos);
219
if (!Tree.IterParent (out it, tpos.Iter))
221
return new IterPos (version, it);
224
public Type[] ColumnTypes {
230
public void EnableEvent (object eventId)
234
public void DisableEvent (object eventId)