[r7693]: rexxgtk / trunk / grxtreemodel.cpp Maximize Restore History

Download this file

grxtreemodel.cpp    616 lines (554 with data), 18.9 kB

  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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) 2007-2008 Rexx Language Association. All rights reserved. */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the Common Public License v1.0 which accompanies this */
/* distribution. A copy is also available at the following address: */
/* http://www.oorexx.org/license.html */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* Redistributions of source code must retain the above copyright */
/* notice, this list of conditions and the following disclaimer. */
/* Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in */
/* the documentation and/or other materials provided with the distribution. */
/* */
/* Neither the name of Rexx Language Association nor the names */
/* of its contributors may be used to endorse or promote products */
/* derived from this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* */
/* Authors; */
/* W. David Ashley <dashley@us.ibm.com> */
/* */
/*----------------------------------------------------------------------------*/
/* include the linux headers and our local stuff */
#include "rexxgtk.h"
/*----------------------------------------------------------------------------*/
/* Global variables */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* Local Definitions */
/*----------------------------------------------------------------------------*/
/*============================================================================*/
/* Private Functions */
/*============================================================================*/
/*============================================================================*/
/* Public Functions */
/*============================================================================*/
/**
* Method: init
*
* Create a tree path.
*
* @param spath The path string
*
* @return Zero.
**/
RexxMethod2(int, // Return type
GrxTreePathNew, // Object_method name
OPTIONAL_RexxObjectPtr, spath, // Path string
OSELF, self) // Self
{
GtkTreePath *path;
if (spath == NULL) {
path = gtk_tree_path_new();
}
else if (context->IsOfType(spath, "String")) {
path = gtk_tree_path_new_from_string(context->ObjectToStringValue(spath));
}
else if (context->IsOfType(spath, "Pointer")) {
path = (GtkTreePath *)context->PointerValue((RexxPointerObject)spath);
}
else {
context->RaiseException2(Rexx_Error_Incorrect_method_noclass,
context->WholeNumberToObject(1),
context->NewStringFromAsciiz("String"));
return 0;
}
// Save ourself
context->SetObjectVariable("CSELF", context->NewPointer(path));
return 0;
}
/**
* Method: to_string
*
* Convert a path to a string.
*
* @return Path string
**/
RexxMethod1(RexxObjectPtr, // Return type
GrxTreePathToString, // Object_method name
CSELF, self) // GTK self
{
char * spath;
spath = gtk_tree_path_to_string((GtkTreePath *)self);
return (RexxObjectPtr)context->NewStringFromAsciiz(spath);
}
/**
* Method: up
*
* Move up the tree.
*
* @return Zero
**/
RexxMethod1(logical_t, // Return type
GrxTreePathUp, // Object_method name
CSELF, self) // GTK self
{
return gtk_tree_path_up((GtkTreePath *)self);
}
/**
* Method: down
*
* Move down the tree.
*
* @return Zero
**/
RexxMethod1(int, // Return type
GrxTreePathDown, // Object_method name
CSELF, self) // GTK self
{
gtk_tree_path_down((GtkTreePath *)self);
return 0;
}
/**
* Method: prev
*
* Move to the previous node.
*
* @return Boolean
**/
RexxMethod1(logical_t, // Return type
GrxTreePathPrev, // Object_method name
CSELF, self) // GTK self
{
return gtk_tree_path_prev((GtkTreePath *)self);
}
/**
* Method: next
*
* Move to the next node.
*
* @return Boolean
**/
RexxMethod1(int, // Return type
GrxTreePathNext, // Object_method name
CSELF, self) // GTK self
{
gtk_tree_path_next((GtkTreePath *)self);
return 0;
}
/**
* Method: prepend_index
*
* Prepend an index.
*
* @param idx The index
*
* @return Zero
**/
RexxMethod2(int, // Return type
GrxTreePathPrependIndex, // Object_method name
int, idx, // Index
CSELF, self) // GTK self
{
gtk_tree_path_prepend_index((GtkTreePath *)self, idx);
return 0;
}
/**
* Method: append_index
*
* Append an index.
*
* @param idx The index
*
* @return Zero
**/
RexxMethod2(int, // Return type
GrxTreePathAppendIndex, // Object_method name
int, idx, // Index
CSELF, self) // GTK self
{
gtk_tree_path_append_index((GtkTreePath *)self, idx);
return 0;
}
/**
* Method: get_depth
*
* Get the depth.
*
* @return Zero
**/
RexxMethod1(int, // Return type
GrxTreePathGetDepth, // Object_method name
CSELF, self) // GTK self
{
return gtk_tree_path_get_depth((GtkTreePath *)self);
}
/**
* Method: is_ancestor
*
* Is a node an ancestor.
*
* @param node The node to test
*
* @return Boolean
**/
RexxMethod2(logical_t, // Return type
GrxTreePathIsAncestor, // Object_method name
RexxObjectPtr, obj, // Node to test
CSELF, self) // GTK self
{
if (!context->IsOfType(obj, "GtkTreePath")) {
context->RaiseException2(Rexx_Error_Incorrect_method_noclass,
context->WholeNumberToObject(1),
context->NewStringFromAsciiz("GtkTreePath"));
return 0;
}
GtkTreePath *node = (GtkTreePath *)context->ObjectToCSelf(obj);
return gtk_tree_path_is_ancestor((GtkTreePath *)self, node);
}
/**
* Method: is_descendant
*
* Is a node an descendant.
*
* @param node The node to test
*
* @return Boolean
**/
RexxMethod2(logical_t, // Return type
GrxTreePathIsDescendant, // Object_method name
RexxObjectPtr, obj, // Node to test
CSELF, self) // GTK self
{
if (!context->IsOfType(obj, "GtkTreePath")) {
context->RaiseException2(Rexx_Error_Incorrect_method_noclass,
context->WholeNumberToObject(1),
context->NewStringFromAsciiz("GtkTreePath"));
return 0;
}
GtkTreePath *node = (GtkTreePath *)context->ObjectToCSelf(obj);
return gtk_tree_path_is_descendant((GtkTreePath *)self, node);
}
/**
* Method: init
*
* Create a tree row reference.
*
* @param pointer The pointer
*
* @return Zero.
**/
RexxMethod3(int, // Return type
GrxTreeRowReferenceNew, // Object_method name
RexxObjectPtr, modelobj, // Model pointer
OPTIONAL_RexxObjectPtr, pathobj, // Path pointer
OSELF, self) // Self
{
GtkTreeRowReference *ref;
if (pathobj == NULL) {
if (context->IsOfType(modelobj, "Pointer")) {
// Save ourself
context->SetObjectVariable("CSELF", modelobj);
}
else {
context->RaiseException2(Rexx_Error_Incorrect_method_noclass,
context->WholeNumberToObject(1),
context->NewStringFromAsciiz("Pointer"));
return 0;
}
}
else {
if (!context->IsOfType(modelobj, "GtkTreeModel")) {
context->RaiseException2(Rexx_Error_Incorrect_method_noclass,
context->WholeNumberToObject(1),
context->NewStringFromAsciiz("GtkTreeModel"));
return 0;
}
GtkTreeModel *model = (GtkTreeModel *)context->ObjectToCSelf(modelobj);
if (!context->IsOfType(pathobj, "GtkTreePath")) {
context->RaiseException2(Rexx_Error_Incorrect_method_noclass,
context->WholeNumberToObject(1),
context->NewStringFromAsciiz("GtkTreePath"));
return 0;
}
GtkTreePath *path = (GtkTreePath *)context->ObjectToCSelf(pathobj);
ref = gtk_tree_row_reference_new(model, path);
// Save ourself
context->SetObjectVariable("CSELF", context->NewPointer(ref));
}
return 0;
}
/**
* Method: valid
*
* Is the row reference valid.
*
* @return Boolean
**/
RexxMethod1(logical_t, // Return type
GrxTreeRowReferenceValid, // Object_method name
CSELF, self) // GTK self
{
return gtk_tree_row_reference_valid((GtkTreeRowReference *)self);
}
/**
* Method: get_path
*
* Get the path from an a row reference.
*
* @return Path pointer
**/
RexxMethod2(RexxObjectPtr, // Return type
GrxTreeRowReferenceGetPath, // Object_method name
OSELF, oself, // Self
CSELF, cself) // Self
{
GtkTreePath *path = gtk_tree_row_reference_get_path((GtkTreeRowReference *)cself);
return context->SendMessage1(oself, "create_tree_path", context->NewPointer(path));
}
/**
* Method: init
*
* Create a tree model.
*
* @param pointer The pointer
*
* @return Zero.
**/
RexxMethod2(int, // Return type
GrxTreeModelNew, // Object_method name
POINTER, ptr, // Pointer
OSELF, self) // Self
{
// Save ourself
context->SetObjectVariable("CSELF", context->NewPointer(ptr));
return 0;
}
/**
* Method: get_n_columns
*
* Get the number of columns.
*
* @return Zero.
**/
RexxMethod1(int, // Return type
GrxTreeModelGetNColumns, // Object_method name
CSELF, self) // Self
{
return gtk_tree_model_get_n_columns((GtkTreeModel *)self);
}
/**
* Method: get_column_type
*
* Get the column type.
*
* @param idx The column index
*
* @return Zero.
**/
RexxMethod2(int, // Return type
GrxTreeModelGetColumnType, // Object_method name
int, idx, // Column index
CSELF, self) // Self
{
return gtk_tree_model_get_column_type((GtkTreeModel *)self, idx);
}
/**
* Method: get_iter
*
* Get an iterator from a path.
*
* @param path The path
*
* @return Iter pointer
**/
RexxMethod2(POINTER, // Return type
GrxTreeModelGetIter, // Object_method name
RexxObjectPtr, pathobj, // The path
CSELF, self) // Self
{
GtkTreeIter iter;
if (!context->IsOfType(pathobj, "GtkTreePath")) {
context->RaiseException2(Rexx_Error_Incorrect_method_noclass,
context->WholeNumberToObject(1),
context->NewStringFromAsciiz("GtkTreePath"));
return 0;
}
GtkTreePath *path = (GtkTreePath *)context->ObjectToCSelf(pathobj);
gboolean retc = gtk_tree_model_get_iter((GtkTreeModel *)self, &iter, path);
if (retc) {
return gtk_tree_iter_copy(&iter);
}
return NULL;
}
/**
* Method: get_iter_from_string
*
* Get an iterator from a string.
*
* @param str The string
*
* @return Iter pointer
**/
RexxMethod2(POINTER, // Return type
GrxTreeModelGetIterFromString, // Object_method name
CSTRING, str, // The string
CSELF, self) // Self
{
GtkTreeIter iter;
gboolean retc = gtk_tree_model_get_iter_from_string((GtkTreeModel *)self, &iter, str);
if (retc) {
return gtk_tree_iter_copy(&iter);
}
return NULL;
}
/**
* Method: get_value
*
* Get the value in a column.
*
* @param iter The iterator
*
* @param col The column number
*
* @return Value
**/
RexxMethod3(RexxObjectPtr, // Return type
GrxTreeModelGetValue, // Object_method name
POINTER, rxiter, // Row iterator
int, col, // Column number
CSELF, self) // GTK self
{
GtkTreeIter *iter = (GtkTreeIter *)rxiter;
GType type = gtk_tree_model_get_column_type(GTK_TREE_MODEL(self), col);
long long coldata;
gtk_tree_model_get(GTK_TREE_MODEL(self), iter, col, &coldata, -1);
switch (type) {
case G_TYPE_POINTER:
case G_TYPE_STRING:
case G_TYPE_OBJECT:
return (RexxObjectPtr)context->NewStringFromAsciiz((char *)coldata);
break;
case G_TYPE_INT:
case G_TYPE_BOOLEAN:
case G_TYPE_LONG:
case G_TYPE_ENUM:
case G_TYPE_FLAGS:
case G_TYPE_CHAR:
case G_TYPE_UCHAR:
return (RexxObjectPtr)context->Int32ToObject((gint)coldata);
break;
case G_TYPE_UINT:
case G_TYPE_ULONG:
return (RexxObjectPtr)context->UnsignedInt32ToObject((guint)coldata);
break;
case G_TYPE_INT64:
return (RexxObjectPtr)context->Int64ToObject((long long)coldata);
break;
case G_TYPE_UINT64:
return (RexxObjectPtr)context->UnsignedInt64ToObject((unsigned long long)coldata);
break;
case G_TYPE_DOUBLE:
return (RexxObjectPtr)context->DoubleToObject((double)coldata);
break;
default:
break;
}
return context->Nil();
}
/**
* Method: iter_next
*
* Move the iterator to the next entry
*
* @param rxiter The iter pointer
*
* @return Iter pointer
**/
RexxMethod2(POINTER, // Return type
GrxTreeModelIterNext, // Object_method name
POINTER, rxiter, // The iter
CSELF, self) // Self
{
GtkTreeIter *iter = (GtkTreeIter *)rxiter;
gboolean retc = gtk_tree_model_iter_next((GtkTreeModel *)self, iter);
if (retc) {
return iter;
}
gtk_tree_iter_free(iter);
return NULL;
}
/**
* Method: get_path
*
* Get the path from an iter.
*
* @param rxiter The iter pointer
*
* @return Path pointer
**/
RexxMethod3(RexxObjectPtr, // Return type
GrxTreeModelGetPath, // Object_method name
CSELF, cself, // Self
POINTER, rxiter, // The iter
OSELF, oself) // Self
{
GtkTreeIter *iter = (GtkTreeIter *)rxiter;
GtkTreePath *path = gtk_tree_model_get_path((GtkTreeModel *)cself, iter);
return context->SendMessage1(oself, "create_tree_path", context->NewPointer(path));
}
/**
* Method: has_parent
*
* Return boolean true if the iter has a parent.
*
* @param rxiter The iter pointer
*
* @return Path pointer
**/
RexxMethod2(logical_t, // Return type
GrxTreeModelHasParent, // Object_method name
POINTER, rxiter, // The iter
CSELF, self) // Self
{
GtkTreeIter *iter = (GtkTreeIter *)rxiter;
GtkTreeIter parent;
return gtk_tree_model_iter_parent((GtkTreeModel *)self, &parent, iter);
}
/**
* Method: get_parent
*
* Return the parent.
*
* @param rxiter The iter pointer
*
* @return Object
**/
RexxMethod2(POINTER, // Return type
GrxTreeModelGetParent, // Object_method name
POINTER, rxiter, // The iter
CSELF, self) // Self
{
GtkTreeIter *iter = (GtkTreeIter *)rxiter;
GtkTreeIter parent;
gtk_tree_model_iter_parent((GtkTreeModel *)self, &parent, iter);
return gtk_tree_iter_copy(&parent);
}