1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
212
  
213
  
214
  
215
  
216
  
217
  
218
  
219
  
220
  
221
  
222
  
223
  
224
  
225
  
226
  
227
  
228
  
229
  
230
  
231
  
232
  
233
  
234
  
235
  
236
  
237
  
238
  
239
  
240
  
241
  
242
  
243
  
244
  
245
  
246
  
247
  
248
  
249
  
250
  
251
  
252
  
253
  
254
  
255
  
256
  
257
  
258
  
259
  
260
  
261
  
262
  
263
  
264
  
265
  
266
  
267
  
268
  
269
  
270
  
271
  
272
  
273
  
274
  
275
  
276
  
277
  
278
  
279
  
280
  
281
  
282
  
283
  
284
  
285
  
286
  
287
  
288
  
289
  
290
  
291
  
292
  
293
  
294
  
295
  
296
  
297
  
298
  
299
  
300
  
301
  
302
  
303
  
304
  
305
  
306
  
307
  
308
  
309
  
310
  
311
  
312
  
313
  
314
  
315
  
316
  
317
  
318
  
319
  
320
  
321
  
322
  
323
  
324
  
325
  
326
  
327
  
328
  
329
  
330
  
331
  
332
  
333
  
334
  
335
  
336
  
337
  
338
  
339
  
340
  
341
  
342
  
343
  
344
  
345
  
346
  
347
  
348
  
349
  
350
  
351
  
352
  
353
  
354
  
355
  
356
  
357
  
358
  
359
  
360
  
361
  
362
  
363
  
364
  
365
  
366
  
/* -*- C -*- */ 
class GTK2.TreeStore; 
inherit G.Object; 
inherit GTK2.TreeModel; 
inherit GTK2.TreeSortable; 
inherit GTK2.TreeDragSource; 
inherit GTK2.TreeDragDest; 
 
//! A tree-like data structure that can be used with W(TreeView). 
 
void create(array(mixed) types) 
//! Create a new tree store with as many columns as there are items in the 
//! array. A type is either a string representing a type name, such as "int" or 
//! "float", or an actual widget.  If it is a widget, the column in question 
//! should be a widget of the same type that you would like this column to 
//! represent. 
{ 
  pgtk2_verify_not_inited(); 
  pgtk2_verify_setup(); 
  { 
/*    GType *types; */ 
    struct array *a; 
    struct store_data *sd; 
    int i; 
    get_all_args(NULL,args,"%A",&a); 
    if (a==NULL) 
      Pike_error("Invalid argument.\n"); 
    if (a->size) { 
      sd=(struct store_data *)g_malloc(sizeof(struct store_data)); 
      if (sd==NULL) 
        SIMPLE_OUT_OF_MEMORY_ERROR("create",sizeof(struct store_data)); 
      sd->types=g_malloc(sizeof(GType)*a->size); 
      if (sd->types==NULL) { 
        g_free(sd); 
        SIMPLE_OUT_OF_MEMORY_ERROR("create",sizeof(GType)*a->size); 
      } 
    } else 
      Pike_error("Invalid size of array.\n"); 
    for (i=sd->n_cols=0; i<a->size; i++) { 
      if (TYPEOF(ITEM(a)[i]) == PIKE_T_STRING) { 
        const struct pike_string *str = (ITEM(a)+i)->u.string; 
        if (str == literal_int_string) { 
          sd->types[sd->n_cols++]=G_TYPE_INT; 
        } else if (is_same_string(_STR("uint"),str)) { 
          sd->types[sd->n_cols++]=G_TYPE_UINT; 
        } else if (str == literal_float_string) { 
          sd->types[sd->n_cols++]=G_TYPE_FLOAT; 
        } else if (is_same_string(_STR("double"),str)) { 
          sd->types[sd->n_cols++]=G_TYPE_DOUBLE; 
        } else if (is_same_string(_STR("boolean"),str)) { 
          sd->types[sd->n_cols++]=G_TYPE_BOOLEAN; 
        } else if (is_same_string(_STR("long"),str)) { 
          sd->types[sd->n_cols++]=G_TYPE_LONG; 
        } else if (is_same_string(_STR("ulong"),str)) { 
          sd->types[sd->n_cols++]=G_TYPE_ULONG; 
        } else if (str == literal_string_string) { 
          sd->types[sd->n_cols++]=G_TYPE_STRING; 
        } else if (is_same_string(_STR("char"),str)) { 
          sd->types[sd->n_cols++]=G_TYPE_CHAR; 
        } else if (is_same_string(_STR("uchar"),str)) { 
          sd->types[sd->n_cols++]=G_TYPE_UCHAR; 
        } else if (str == literal_object_string) { 
          sd->types[sd->n_cols++]=G_TYPE_POINTER; 
        } else { 
          sd->types[sd->n_cols]=g_type_from_name(CGSTR0((ITEM(a)+i)->u.string)); 
          if (sd->types[sd->n_cols]==0) 
            break; 
          sd->n_cols++; 
        } 
      } else if (TYPEOF(ITEM(a)[i]) == PIKE_T_OBJECT) { 
        struct object *o1=(ITEM(a)+i)->u.object; 
        sd->types[sd->n_cols++]=G_OBJECT_TYPE(get_gobject(o1)); 
      } 
    } 
    if (sd->n_cols) { 
      GtkTreeStore *gt; 
      gt=gtk_tree_store_newv(sd->n_cols,sd->types); 
      THIS->obj=G_OBJECT(gt); 
      g_object_set_data_full(THIS->obj,"store-data",sd, 
                (GDestroyNotify)pgtk2_destroy_store_data); 
    } else { 
      Pike_error("No valid types\n"); 
    } 
  } 
  pgtk2_pop_n_elems(args); 
  pgtk2__init_this_object(); 
} 
 
void set_row(GTK2.TreeIter iter, array(mixed) values) 
//! Set the data in an entire row. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1; 
    struct array *a; 
    struct store_data *sd; 
    GValue gv={0}; 
    struct svalue *sv; 
    int i; 
    get_all_args(NULL,args,"%o%A",&o1,&a); 
    if (a==NULL) 
      Pike_error("Invalid array.\n"); 
    sd=g_object_get_data(G_OBJECT(THIS->obj),"store-data"); 
    if (!sd) 
      Pike_error("store-data not found.\n"); 
    for (i=0; i<(a->size>sd->n_cols?sd->n_cols:a->size); i++) { 
/* 
      if (TYPEOF(ITEM(a)[i]) == PIKE_T_STRING) 
        fprintf(stderr,"set_row: val==%s\n",STR0((ITEM(a)+i)->u.string)); 
*/ 
      pgtk2_set_gvalue(&gv,sd->types[i],(ITEM(a)+i)); 
      gtk_tree_store_set_value(GTK_TREE_STORE(THIS->obj), 
        (GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program),i,&gv); 
      g_value_unset(&gv); 
    } 
  } 
  RETURN_THIS(); 
} 
 
void set_value(GTK2.TreeIter iter, int column, mixed value) 
//! Set the data in the cell specified by iter and column. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1; 
    INT_TYPE col; 
    struct svalue *sv; 
    struct store_data *sd; 
    GValue gv={0}; 
    get_all_args(NULL,args,"%o%i%*",&o1,&col,&sv); 
    sd=g_object_get_data(G_OBJECT(THIS->obj),"store-data"); 
    if (!sd) 
      Pike_error("store-data not found.\n"); 
     
    pgtk2_set_gvalue(&gv,sd->types[col],sv); 
 
    gtk_tree_store_set_value(GTK_TREE_STORE(THIS->obj), 
        (GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program), 
        col,&gv); 
    g_value_unset(&gv); 
  } 
  RETURN_THIS(); 
} 
 
void remove(GTK2.TreeIter iter) 
//! Remove iter. 
//! iter is set to the next valid row at that level, 
//! or invalidated if it was the last one. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1; 
    get_all_args(NULL,args,"%o",&o1); 
    gtk_tree_store_remove(GTK_TREE_STORE(THIS->obj), 
        (GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program)); 
  } 
  RETURN_THIS(); 
} 
 
+GTK2.TreeIter insert(GTK2.TreeIter parent, int position) 
//! Insert a row at position.  If parent is valid, will create as child, 
//! otherwise at top level.  If position is larger than then number 
//! of rows at that level, it will be added to the end of the list. 
//! iter will be changed to point to the new row. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1; 
    INT_TYPE pos; 
    GtkTreeIter *gt; 
    get_all_args(NULL,args,"%o%i",&o1,&pos); 
    gt=(GtkTreeIter *)g_malloc(sizeof(GtkTreeIter)); 
    if (gt==NULL) 
      SIMPLE_OUT_OF_MEMORY_ERROR("insert",sizeof(GtkTreeIter)); 
    gtk_tree_store_insert(GTK_TREE_STORE(THIS->obj), 
        gt,(GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program),pos); 
    pgtk2_pop_n_elems(args); 
    push_pgdk2object(gt,pgtk2_tree_iter_program,1); 
  } 
} 
 
+GTK2.TreeIter insert_before(?GTK2.TreeIter parent, ?GTK2.TreeIter sibling) 
//! Insert a row before sibling.  If sibling is 0, then the 
//! row will be appended to parent's children.  If parent and 
//! sibling are 0, then the row will be appended to the toplevel. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1,*o2; 
    GtkTreeIter *gt; 
    o1=o2=NULL; 
    get_all_args(NULL,args,"%o.%o",&o1,&o2); 
    gt=(GtkTreeIter *)g_malloc(sizeof(GtkTreeIter)); 
    if (gt==NULL) 
      SIMPLE_OUT_OF_MEMORY_ERROR("insert_before",sizeof(GtkTreeIter)); 
    gtk_tree_store_insert_before(GTK_TREE_STORE(THIS->obj), 
        gt, 
        (GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program), 
        (GtkTreeIter *)get_pg2object(o2,pgtk2_tree_iter_program)); 
    pgtk2_pop_n_elems(args); 
    push_pgdk2object(gt,pgtk2_tree_iter_program,1); 
  } 
} 
 
+GTK2.TreeIter insert_after(?GTK2.TreeIter parent, ?GTK2.TreeIter sibling) 
//! Insert a new row after sibling.  If sibling is 0, then the row 
//! will be prepended to parent's children.  If parent and sibling 
//! are both 0, then the row will be prepended to the toplevel. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1,*o2; 
    GtkTreeIter *gt; 
    o1=o2=NULL; 
    get_all_args(NULL,args,"%o.%o",&o1,&o2); 
    gt=(GtkTreeIter *)g_malloc(sizeof(GtkTreeIter)); 
    if (gt==NULL) 
      SIMPLE_OUT_OF_MEMORY_ERROR("insert_after",sizeof(GtkTreeIter)); 
    gtk_tree_store_insert_before(GTK_TREE_STORE(THIS->obj), 
        gt, 
        (GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program), 
        (GtkTreeIter *)get_pg2object(o2,pgtk2_tree_iter_program)); 
    pgtk2_pop_n_elems(args); 
    push_pgdk2object(gt,pgtk2_tree_iter_program,1); 
  } 
} 
 
+GTK2.TreeIter prepend(?GTK2.TreeIter parent) 
//! Prepend a new row. If parent is valid, then it will prepend 
//! the new row before the first child of parent, otherwise it will 
//! prepend a new row to the toplevel. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1=NULL; 
    GtkTreeIter *gt; 
    get_all_args(NULL,args,".%o",&o1); 
    gt=(GtkTreeIter *)g_malloc(sizeof(GtkTreeIter)); 
    if (gt==NULL) 
      SIMPLE_OUT_OF_MEMORY_ERROR("prepend",sizeof(GtkTreeIter)); 
    gtk_tree_store_prepend(GTK_TREE_STORE(THIS->obj), 
        gt, (GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program)); 
    pgtk2_pop_n_elems(args); 
    push_pgdk2object(gt,pgtk2_tree_iter_program,1); 
  } 
} 
 
+GTK2.TreeIter append(?GTK2.TreeIter parent) 
//! Append a new row.  If parent is valid, then it will append 
//! the new row after the last child, otherwise it will append 
//! a row to the toplevel. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1=NULL; 
    GtkTreeIter *gt; 
    get_all_args(NULL,args,".%o",&o1); 
    gt=(GtkTreeIter *)g_malloc(sizeof(GtkTreeIter)); 
    if (gt==NULL) 
      SIMPLE_OUT_OF_MEMORY_ERROR("append",sizeof(GtkTreeIter)); 
    gtk_tree_store_append(GTK_TREE_STORE(THIS->obj), 
        gt,(GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program)); 
    pgtk2_pop_n_elems(args); 
    push_pgdk2object(gt,pgtk2_tree_iter_program,1); 
  } 
} 
 
int is_ancestor(GTK2.TreeIter iter, GTK2.TreeIter descendant) 
//!  Returns true if iter is an ancestor of descendant. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1,*o2; 
    int res; 
    get_all_args(NULL,args,"%o%o",&o1,&o2); 
    res=gtk_tree_store_is_ancestor(GTK_TREE_STORE(THIS->obj), 
        (GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program), 
        (GtkTreeIter *)get_pg2object(o2,pgtk2_tree_iter_program)); 
    pgtk2_pop_n_elems(args); 
    if (res) 
      push_int(1); 
    else 
      push_int(0); 
  } 
} 
 
int iter_depth(GTK2.TreeIter iter) 
//! Get the depth of iter.  This will be 0 for anything 
//! on the root level, 1 for anything down a level, and 
//! so on. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1; 
    int res; 
    get_all_args(NULL,args,"%o",&o1); 
    res=gtk_tree_store_iter_depth(GTK_TREE_STORE(THIS->obj), 
                (GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program)); 
    pgtk2_pop_n_elems(args); 
    if (res) 
      push_int(res); 
    else 
      push_int(-1); 
  } 
} 
 
void clear() 
//! Removes all rows. 
{ 
  pgtk2_verify_inited(); 
  gtk_tree_store_clear(GTK_TREE_STORE(THIS->obj)); 
  RETURN_THIS(); 
} 
 
require gtk22; 
void swap(GTK2.TreeIter a, GTK2.TreeIter b) 
//! Swap 2 rows.  Only works if this store is unsorted. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1,*o2; 
    get_all_args(NULL,args,"%o%o",&o1,&o2); 
    gtk_tree_store_swap(GTK_TREE_STORE(THIS->obj), 
        (GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program), 
        (GtkTreeIter *)get_pg2object(o2,pgtk2_tree_iter_program)); 
  } 
  RETURN_THIS(); 
} 
 
void move_before(GTK2.TreeIter iter, ?GTK2.TreeIter position) 
//! Moves iter to before position.  These should be at the 
//! same level.  This only works if the store is unsorted. 
//! If position is omitted, iter will be moved to the end 
//! of the level. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1,*o2; 
    o2=NULL; 
    get_all_args(NULL,args,"%o.%o",&o1,&o2); 
    gtk_tree_store_move_before(GTK_TREE_STORE(THIS->obj), 
        (GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program), 
        (GtkTreeIter *)get_pg2object(o2,pgtk2_tree_iter_program)); 
  } 
  RETURN_THIS(); 
} 
 
void move_after(GTK2.TreeIter iter, ?GTK2.TreeIter position) 
//! Moves iter to after position.  These should be at the 
//! same level.  This only works if the store is unsorted. 
//! If position is omitted, iter will be moved to the start 
//! of the level. 
{ 
  pgtk2_verify_inited(); 
  { 
    struct object *o1,*o2; 
    o2=NULL; 
    get_all_args(NULL,args,"%o.%o",&o1,&o2); 
    gtk_tree_store_move_after(GTK_TREE_STORE(THIS->obj), 
        (GtkTreeIter *)get_pg2object(o1,pgtk2_tree_iter_program), 
        (GtkTreeIter *)get_pg2object(o2,pgtk2_tree_iter_program)); 
  } 
  RETURN_THIS(); 
} 
endrequire;