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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775 | -- --
-- package Copyright (c) Dmitry A. Kazakov --
-- Gtk.Tree_Model.Extension_Store Luebeck --
-- Implementation Autumn, 2007 --
-- --
-- Last revision : 22:45 07 Apr 2016 --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public License as --
-- published by the Free Software Foundation; either version 2 of --
-- the License, or (at your option) any later version. This library --
-- is distributed in the hope that it will be useful, but WITHOUT --
-- ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from --
-- this unit, or you link this unit with other files to produce an --
-- executable, this unit does not by itself cause the resulting --
-- executable to be covered by the GNU General Public License. This --
-- exception does not however invalidate any other reasons why the --
-- executable file might be covered by the GNU Public License. --
--____________________________________________________________________--
with Ada.Exceptions; use Ada.Exceptions;
with GLib.Messages; use GLib.Messages;
with Gtk.Missed; use Gtk.Missed;
with System; use System;
with Ada.Unchecked_Deallocation;
with Ada.Unchecked_Conversion;
with GNAT.Traceback.Symbolic;
with System.Address_To_Access_Conversions;
package body Gtk.Tree_Model.Extension_Store is
GTK_Type : GType := GType_Invalid;
function Where (Text : String) return String is
begin
return " in Gtk.Tree_Model.Extension_Store." & Text;
end Where;
procedure Free is
new Ada.Unchecked_Deallocation
( Gtk_Extension_Store_Record'Class,
Gtk_Extension_Store
);
subtype Flat_GInt_Array is GInt_Array (Natural'Range);
package Address_To_GInt_Array is
new System.Address_To_Access_Conversions (Flat_GInt_Array);
function From_Extension
( Model : not null access Gtk_Extension_Store_Record;
Iter : Gtk_Tree_Iter
) return Gtk_Tree_Iter is
begin
if Iter = Null_Iter then
return Null_Iter;
else
declare
Path : constant Gtk_Tree_Path :=
Model.Columns.Get_Path (Iter);
Result : Gtk_Tree_Iter;
begin
if Path = Null_Gtk_Tree_Path then
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
"Invalid iterator" & Where ("From_Extension")
);
return Null_Iter;
else
Result := Get_Iter (Model.Reference, Path);
if Result = Null_Iter then
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
( "Path "
& To_String (Path)
& " has no iterator"
& Where ("From_Extension")
) );
end if;
Path_Free (Path);
return Result;
end if;
end;
end if;
end From_Extension;
function From_Extension
( Model : not null access Gtk_Extension_Store_Record;
Path : Gtk_Tree_Path
) return Gtk_Tree_Path is
begin
if Path = Null_Gtk_Tree_Path then
return Null_Gtk_Tree_Path;
else
return Copy (Path);
end if;
end From_Extension;
procedure Changed
( Model : not null access Gtk_Extension_Store_Record;
Path : Gtk_Tree_Path;
Iter : Gtk_Tree_Iter
) is
begin
if Get_Depth (Path) > 0 then
Row_Changed
( To_Interface (Model),
Path,
Model.Columns.Get_Iter (Path)
);
end if;
end Changed;
function Children
( Model : not null access Gtk_Extension_Store_Record;
Parent : Gtk_Tree_Iter
) return Gtk_Tree_Iter is
begin
return Model.Columns.Children (Parent);
end Children;
procedure Deleted
( Model : not null access Gtk_Extension_Store_Record;
Path : Gtk_Tree_Path
) is
begin
if Path /= Null_Gtk_Tree_Path and then Get_Depth (Path) > 0 then
Row_Deleted (To_Interface (Model), Path);
end if;
end Deleted;
procedure Deleting
( Model : not null access Gtk_Extension_Store_Record;
Path : Gtk_Tree_Path;
Iter : Gtk_Tree_Iter
) is
begin
null;
end Deleting;
procedure Erase (Model : access Gtk_Extension_Store_Record'Class) is
Path : Gtk_Tree_Path;
procedure Remove (Row : Gtk_Tree_Iter) is
begin
for Count in reverse 0..Model.Columns.N_Children (Row) - 1
loop
Append_Index (Path, Count);
Remove (Model.Columns.Nth_Child (Row, Count));
if Up (Path) then
null;
end if;
end loop;
if Row /= Null_Iter then
declare
Removed : Gtk_Tree_Iter := Row;
begin
Model.Deleting (Path, Row);
Model.Columns.Remove (Removed);
Row_Deleted (To_Interface (Model), Path);
end;
end if;
end Remove;
begin
Gtk_New (Path);
Remove (Null_Iter);
Path_Free (Path);
end Erase;
procedure Finalize
( Model : not null access Gtk_Extension_Store_Record
) is
begin
Unref (-Model.Reference);
Model.Columns.Unref;
end Finalize;
function Get_Column_Type
( Model : not null access Gtk_Extension_Store_Record;
Index : GInt
) return GType is
begin
if Index < Model.Offset then
return Get_Column_Type (Model.Reference, Index);
else
return Model.Columns.Get_Column_Type (Index - Model.Offset);
end if;
end Get_Column_Type;
function Get_Extension_Types
( Model : not null access Gtk_Extension_Store_Record
) return GType_Array is
Length : constant GInt := Model.Columns.Get_N_Columns;
begin
if Length = 0 then
return (1..0 => GType_Invalid);
else
declare
Result : GType_Array
( GUInt (Model.Offset)
.. GUInt (Model.Offset + Length - 1)
);
begin
for Index in Result'Range loop
Result (Index) :=
Model.Columns.Get_Column_Type
( GInt (Index) - Model.Offset
);
end loop;
return Result;
end;
end if;
end Get_Extension_Types;
function Get_Flags
( Model : not null access Gtk_Extension_Store_Record
) return Tree_Model_Flags is
begin
return Get_Flags (Model.Reference);
end Get_Flags;
function Get_Iter
( Model : not null access Gtk_Extension_Store_Record;
Path : Gtk_Tree_Path
) return Gtk_Tree_Iter is
begin
if Path = Null_Gtk_Tree_Path or else Get_Depth (Path) = 0 then
return Null_Iter;
else
return Model.Columns.Get_Iter (Path);
end if;
end Get_Iter;
function Get_N_Columns
( Model : not null access Gtk_Extension_Store_Record
) return GInt is
begin
return Model.Columns.Get_N_Columns + Model.Offset;
end Get_N_Columns;
function Get_Path
( Model : not null access Gtk_Extension_Store_Record;
Iter : Gtk_Tree_Iter
) return Gtk_Tree_Path is
begin
if Iter = Null_Iter then
return Null_Gtk_Tree_Path;
else
return Model.Columns.Get_Path (Iter);
end if;
end Get_Path;
function Get_Reference
( Model : not null access Gtk_Extension_Store_Record
) return Gtk_Tree_Model is
begin
return Model.Reference;
end Get_Reference;
procedure Get_Value
( Model : not null access Gtk_Extension_Store_Record;
Iter : Gtk_Tree_Iter;
Column : GInt;
Value : out GValue
) is
begin
if Iter = Null_Iter then
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
( "Null extension model iterator"
& GInt'Image (Column)
& Where ("Get_Value")
) );
elsif Column < Model.Offset then
declare
Row : constant Gtk_Tree_Iter :=
From_Extension (Model, Iter);
begin
if Row = Null_Iter then
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
( "Null iterator of the reference column"
& GInt'Image (Column)
& Where ("Get_Value")
) );
Init (Value, GType_Invalid);
else
Get_Value (Model.Reference, Row, Column, Value);
end if;
end;
else
Model.Columns.Get_Value (Iter, Column - Model.Offset, Value);
end if;
end Get_Value;
procedure Gtk_New
( Model : out Gtk_Extension_Store;
Reference : not null access
Gtk_Root_Tree_Model_Record'Class;
Types : GType_Array
) is
begin
Model := new Gtk_Extension_Store_Record;
Initialize (Model, Reference, Types);
exception
when others =>
Free (Model);
raise;
end Gtk_New;
procedure Gtk_New
( Model : out Gtk_Extension_Store;
Types : GType_Array
) is
begin
Model := new Gtk_Extension_Store_Record;
Gtk.Tree_Model.Extension_Store.Initialize (Model, Types);
exception
when others =>
Free (Model);
raise;
end Gtk_New;
function Has_Child
( Model : not null access Gtk_Extension_Store_Record;
Iter : Gtk_Tree_Iter
) return Boolean is
begin
return Model.Columns.Has_Child (Iter);
end Has_Child;
procedure Initial_Sync
( Model : not null access
Gtk_Extension_Store_Record'Class;
Ref_Parent : Gtk_Tree_Iter;
Ext_Parent : Gtk_Tree_Iter
) is
Ref_Child : Gtk_Tree_Iter;
Ext_Child : Gtk_Tree_Iter;
Position : GInt := 0;
begin
if Ref_Parent = Null_Iter then
Ref_Child := Get_Iter_First (Model.Reference);
else
Ref_Child := Children (Model.Reference, Ref_Parent);
end if;
while Ref_Child /= Null_Iter loop
Model.Columns.Insert (Ext_Child, Ext_Parent, Position);
Position := Position + 1;
Initial_Sync (Model, Ref_Child, Ext_Child);
Next (Model.Reference, Ref_Child);
end loop;
end Initial_Sync;
procedure Initialize
( Model : not null access
Gtk_Extension_Store_Record'Class;
Reference : not null access
Gtk_Root_Tree_Model_Record'Class;
Types : GType_Array
) is
begin
Initialize (Model, Types);
Set_Reference (Model, Reference);
end Initialize;
procedure Initialize
( Model : not null access
Gtk_Extension_Store_Record'Class;
Types : GType_Array
) is
begin
if GTK_Type = GType_Invalid then
GTK_Type := Register ("GtkExtensionStore");
end if;
Initialize (Model, GTK_Type);
Gtk.Tree_Store.Gtk_New (Model.Columns, Types);
Tree_Handlers.Connect
( Model.Columns,
"rows-reordered",
On_Rows_Reordered'Access,
Model.all'Access
);
end Initialize;
procedure Inserted
( Model : not null access Gtk_Extension_Store_Record;
Path : Gtk_Tree_Path;
Iter : Gtk_Tree_Iter
) is
begin
if Path /= Null_Gtk_Tree_Path and then Get_Depth (Path) > 0 then
Row_Inserted (To_Interface (Model), Path, Iter);
end if;
end Inserted;
procedure Next
( Model : not null access Gtk_Extension_Store_Record;
Iter : in out Gtk_Tree_Iter
) is
begin
Model.Columns.Next (Iter);
end Next;
function Nth_Child
( Model : not null access Gtk_Extension_Store_Record;
Parent : Gtk_Tree_Iter;
N : GInt
) return Gtk_Tree_Iter is
begin
return Model.Columns.Nth_Child (Parent, N);
end Nth_Child;
function N_Children
( Model : not null access Gtk_Extension_Store_Record;
Iter : Gtk_Tree_Iter := Null_Iter
) return GInt is
begin
return Model.Columns.N_Children (Iter);
end N_Children;
procedure On_Changed_Row
( Reference : access Gtk_Root_Tree_Model_Record'Class;
Params : GValues;
Model : Gtk_Extension_Store
) is
Path : constant Gtk_Tree_Path :=
Convert (Get_Address (Nth (Params, 1)));
Row : Gtk_Tree_Iter;
begin
if Path /= Null_Gtk_Tree_Path and then Get_Depth (Path) > 0 then
Row := Model.Columns.Get_Iter (Path);
if Row = Null_Iter then
On_Row_Inserted (Reference, Params, Model);
end if;
Changed (Model, Path, Row);
end if;
exception
when Error : others =>
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
( "Fault: "
& Exception_Information (Error)
& Where ("On_Changed_Row")
) );
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
GNAT.Traceback.Symbolic.Symbolic_Traceback (Error)
);
end On_Changed_Row;
procedure On_Deleted_Row
( Reference : access Gtk_Root_Tree_Model_Record'Class;
Params : GValues;
Model : Gtk_Extension_Store
) is
Path : constant Gtk_Tree_Path :=
Convert (Get_Address (Nth (Params, 1)));
Row : Gtk_Tree_Iter;
begin
if Path /= Null_Gtk_Tree_Path and then Get_Depth (Path) > 0 then
Row := Model.Columns.Get_Iter (Path);
if Row /= Null_Iter then
Deleting (Model, Path, Row);
Model.Columns.Remove (Row);
Row_Deleted (To_Interface (Model), Path);
end if;
end if;
exception
when Error : others =>
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
( "Fault: "
& Exception_Information (Error)
& Where ("On_Deleted_Row")
) );
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
GNAT.Traceback.Symbolic.Symbolic_Traceback (Error)
);
end On_Deleted_Row;
procedure On_Row_Has_Child_Toggled
( Reference : access Gtk_Root_Tree_Model_Record'Class;
Params : GValues;
Model : Gtk_Extension_Store
) is
Path : constant Gtk_Tree_Path :=
Convert (Get_Address (Nth (Params, 1)));
begin
Row_Has_Child_Toggled
( To_Interface (Model),
Path,
Model.Columns.Get_Iter (Path)
);
exception
when Error : others =>
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
( "Fault: "
& Exception_Information (Error)
& Where ("On_Row_Has_Child_Toggled")
) );
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
GNAT.Traceback.Symbolic.Symbolic_Traceback (Error)
);
end On_Row_Has_Child_Toggled;
procedure On_Row_Inserted
( Reference : access Gtk_Root_Tree_Model_Record'Class;
Params : GValues;
Model : Gtk_Extension_Store
) is
Path : constant Gtk_Tree_Path :=
Convert (Get_Address (Nth (Params, 1)));
No : constant GInt :=
GInt'Max
( 0,
Get_Row_No (To_Interface (Model.Columns), Path)
);
This : constant Gtk_Tree_Path := Copy (Path);
Row : Gtk_Tree_Iter;
begin
if Up (This) and then Get_Depth (This) > 0 then
Model.Columns.Insert
( Row,
Model.Columns.Get_Iter (This),
No
);
else
Model.Columns.Insert (Row, Null_Iter, No);
end if;
if This /= Null_Gtk_Tree_Path then
Path_Free (This);
end if;
Inserted (Model, Path, Row);
exception
when Error : others =>
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
( "Fault: "
& Exception_Information (Error)
& Where ("On_Row_Inserted")
) );
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
GNAT.Traceback.Symbolic.Symbolic_Traceback (Error)
);
end On_Row_Inserted;
procedure On_Rows_Reordered
( Reference : access Gtk_Root_Tree_Model_Record'Class;
Params : GValues;
Model : Gtk_Extension_Store
) is
use Address_To_GInt_Array;
Path : constant Gtk_Tree_Path :=
Convert (Get_Address (Nth (Params, 1)));
Indices : GInt_Array renames
To_Pointer (Get_Address (Nth (Params, 3))).all;
begin
Model.Columns.Reorder
( Model.Columns.Get_Iter (Path),
Indices
);
exception
when Error : others =>
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
( "Fault: "
& Exception_Information (Error)
& Where ("On_Rows_Reordered")
) );
Log
( GtkAda_Contributions_Domain,
Log_Level_Critical,
GNAT.Traceback.Symbolic.Symbolic_Traceback (Error)
);
end On_Rows_Reordered;
function Parent
( Model : not null access Gtk_Extension_Store_Record;
Child : Gtk_Tree_Iter
) return Gtk_Tree_Iter is
begin
return Model.Columns.Parent (Child);
end Parent;
procedure Previous
( Model : not null access Gtk_Extension_Store_Record;
Iter : in out Gtk_Tree_Iter
) is
begin
Model.Columns.Previous (Iter);
end Previous;
procedure Ref_Node
( Model : not null access Gtk_Extension_Store_Record;
Iter : Gtk_Tree_Iter
) is
begin
Ref_Node (Model.Reference, From_Extension (Model, Iter));
Ref_Node (Model.Reference, Iter);
end Ref_Node;
procedure Set_Null_Reference
( Model : not null access Gtk_Extension_Store_Record
) is
begin
if Model.Reference /= Null_Gtk_Tree_Model then
-- Disconnect callbacks
for Index in Model.Callbacks'Range loop
Disconnect (-Model.Reference, Model.Callbacks (Index));
end loop;
Erase (Model);
Unref (-Model.Reference);
Model.Reference := Null_Gtk_Tree_Model;
end if;
end Set_Null_Reference;
procedure Set_Reference
( Model : not null access Gtk_Extension_Store_Record;
Reference : not null access
Gtk_Root_Tree_Model_Record'Class
) is
begin
Ref (Reference);
Set_Null_Reference (Model);
Model.Reference := To_Interface (Reference);
Model.Offset := Get_N_Columns (Model.Reference);
Initial_Sync (Model, Null_Iter, Null_Iter);
Model.Callbacks (Changed) :=
Tree_Handlers.Connect
( Reference,
"row-changed",
On_Changed_Row'Access,
Model.all'Access,
True
);
Model.Callbacks (Deleted) :=
Tree_Handlers.Connect
( Reference,
"row-deleted",
On_Deleted_Row'Access,
Model.all'Access,
True
);
Model.Callbacks (Inserted) :=
Tree_Handlers.Connect
( Reference,
"row-inserted",
On_Row_Inserted'Access,
Model.all'Access,
True
);
exception
when others =>
Model.Reference := Null_Gtk_Tree_Model;
Unref (Reference);
raise;
end Set_Reference;
procedure Unref_Node
( Model : not null access Gtk_Extension_Store_Record;
Iter : Gtk_Tree_Iter
) is
begin
Unref_Node (Model.Reference, From_Extension (Model, Iter));
Model.Columns.Unref_Node (Iter);
end Unref_Node;
function To_Extension
( Model : not null access Gtk_Extension_Store_Record;
Iter : Gtk_Tree_Iter
) return Gtk_Tree_Iter is
begin
if Iter = Null_Iter then
return Null_Iter;
else
declare
Path : constant Gtk_Tree_Path :=
Get_Path (Model.Reference, Iter);
Result : Gtk_Tree_Iter := Null_Iter;
begin
if Path /= Null_Gtk_Tree_Path then
if Get_Depth (Path) = 0 then
Result := Null_Iter;
else
Result := Model.Columns.Get_Iter (Path);
end if;
Path_Free (Path);
end if;
return Result;
end;
end if;
end To_Extension;
function To_Extension
( Model : not null access Gtk_Extension_Store_Record;
Path : Gtk_Tree_Path
) return Gtk_Tree_Path is
begin
if Path = Null_Gtk_Tree_Path then
return Null_Gtk_Tree_Path;
else
return Copy (Path);
end if;
end To_Extension;
procedure Set_Extension
( Model : not null access
Gtk_Extension_Store_Record'Class;
Iter : Gtk_Tree_Iter;
Column : Positive;
Value : Boolean
) is
begin
Model.Columns.Set (Iter, GInt (Column) - 1, Value);
end Set_Extension;
procedure Set_Extension
( Model : not null access
Gtk_Extension_Store_Record'Class;
Iter : Gtk_Tree_Iter;
Column : Positive;
Value : GInt
) is
begin
Model.Columns.Set (Iter, GInt (Column) - 1, Value);
end Set_Extension;
procedure Set_Extension
( Model : not null access
Gtk_Extension_Store_Record'Class;
Iter : Gtk_Tree_Iter;
Column : Positive;
Value : UTF8_String
) is
begin
Model.Columns.Set (Iter, GInt (Column) - 1, Value);
end Set_Extension;
procedure Set_Extension
( Model : not null access
Gtk_Extension_Store_Record'Class;
Iter : Gtk_Tree_Iter;
Column : Positive;
Value : GValue
) is
begin
Model.Columns.Set_Value (Iter, GInt (Column) - 1, Value);
end Set_Extension;
end Gtk.Tree_Model.Extension_Store;
|