summaryrefslogtreecommitdiff
path: root/src/fltk-widgets-groups-browsers-textline.adb
blob: 8c684203e46a78cf7f8c7caaf477da53af13e98b (plain)
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
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161


--  Programmed by Jedidiah Barber
--  Released into the public domain


with

    Ada.Assertions,
    Ada.Unchecked_Deallocation,
    FLTK.Images,
    Interfaces.C.Strings;

use type

    Interfaces.C.int,
    Interfaces.C.Strings.chars_ptr;


package body FLTK.Widgets.Groups.Browsers.Textline is


    package Chk renames Ada.Assertions;




    ------------------------
    --  Functions From C  --
    ------------------------

    function get_error_message
        return Interfaces.C.Strings.chars_ptr;
    pragma Import (C, get_error_message, "get_error_message");
    pragma Inline (get_error_message);




    function new_fl_browser
           (X, Y, W, H : in Interfaces.C.int;
            Text       : in Interfaces.C.char_array)
        return Storage.Integer_Address;
    pragma Import (C, new_fl_browser, "new_fl_browser");
    pragma Inline (new_fl_browser);

    procedure free_fl_browser
           (B : in Storage.Integer_Address);
    pragma Import (C, free_fl_browser, "free_fl_browser");
    pragma Inline (free_fl_browser);




    procedure fl_browser_add
           (B : in Storage.Integer_Address;
            T : in Interfaces.C.char_array;
            D : in Storage.Integer_Address);
    pragma Import (C, fl_browser_add, "fl_browser_add");
    pragma Inline (fl_browser_add);

    procedure fl_browser_insert
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int;
            T : in Interfaces.C.char_array;
            D : in Storage.Integer_Address);
    pragma Import (C, fl_browser_insert, "fl_browser_insert");
    pragma Inline (fl_browser_insert);

    procedure fl_browser_move
           (B    : in Storage.Integer_Address;
            T, F : in Interfaces.C.int);
    pragma Import (C, fl_browser_move, "fl_browser_move");
    pragma Inline (fl_browser_move);

    procedure fl_browser_swap
           (B    : in Storage.Integer_Address;
            X, Y : in Interfaces.C.int);
    pragma Import (C, fl_browser_swap, "fl_browser_swap");
    pragma Inline (fl_browser_swap);

    procedure fl_browser_remove
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int);
    pragma Import (C, fl_browser_remove, "fl_browser_remove");
    pragma Inline (fl_browser_remove);

    procedure fl_browser_clear
           (B : in Storage.Integer_Address);
    pragma Import (C, fl_browser_clear, "fl_browser_clear");
    pragma Inline (fl_browser_clear);

    function fl_browser_size
           (B : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_size, "fl_browser_size");
    pragma Inline (fl_browser_size);




    function fl_browser_load
           (B : in Storage.Integer_Address;
            F : in Interfaces.C.char_array)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_load, "fl_browser_load");
    pragma Inline (fl_browser_load);

    function fl_browser_get_text
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int)
        return Interfaces.C.Strings.chars_ptr;
    pragma Import (C, fl_browser_get_text, "fl_browser_get_text");
    pragma Inline (fl_browser_get_text);

    procedure fl_browser_set_text
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int;
            T : in Interfaces.C.char_array);
    pragma Import (C, fl_browser_set_text, "fl_browser_set_text");
    pragma Inline (fl_browser_set_text);

    function fl_browser_get_textsize
           (B : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_get_textsize, "fl_browser_get_textsize");
    pragma Inline (fl_browser_get_textsize);

    procedure fl_browser_set_textsize
           (B : in Storage.Integer_Address;
            S : in Interfaces.C.int);
    pragma Import (C, fl_browser_set_textsize, "fl_browser_set_textsize");
    pragma Inline (fl_browser_set_textsize);




    function fl_browser_get_column_char
           (B : in Storage.Integer_Address)
        return Interfaces.C.char;
    pragma Import (C, fl_browser_get_column_char, "fl_browser_get_column_char");
    pragma Inline (fl_browser_get_column_char);

    procedure fl_browser_set_column_char
           (B : in Storage.Integer_Address;
            C : in Interfaces.C.char);
    pragma Import (C, fl_browser_set_column_char, "fl_browser_set_column_char");
    pragma Inline (fl_browser_set_column_char);

    procedure fl_browser_set_column_widths
           (B, W : in Storage.Integer_Address);
    pragma Import (C, fl_browser_set_column_widths, "fl_browser_set_column_widths");
    pragma Inline (fl_browser_set_column_widths);

    function fl_browser_get_format_char
           (B : in Storage.Integer_Address)
        return Interfaces.C.char;
    pragma Import (C, fl_browser_get_format_char, "fl_browser_get_format_char");
    pragma Inline (fl_browser_get_format_char);

    procedure fl_browser_set_format_char
           (B : in Storage.Integer_Address;
            C : in Interfaces.C.char);
    pragma Import (C, fl_browser_set_format_char, "fl_browser_set_format_char");
    pragma Inline (fl_browser_set_format_char);




    function fl_browser_get_topline
           (B : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_get_topline, "fl_browser_get_topline");
    pragma Inline (fl_browser_get_topline);

    procedure fl_browser_set_topline
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int);
    pragma Import (C, fl_browser_set_topline, "fl_browser_set_topline");
    pragma Inline (fl_browser_set_topline);

    procedure fl_browser_middleline
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int);
    pragma Import (C, fl_browser_middleline, "fl_browser_middleline");
    pragma Inline (fl_browser_middleline);

    procedure fl_browser_bottomline
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int);
    pragma Import (C, fl_browser_bottomline, "fl_browser_bottomline");
    pragma Inline (fl_browser_bottomline);

    procedure fl_browser_lineposition
           (B    : in Storage.Integer_Address;
            L, P : in Interfaces.C.int);
    pragma Import (C, fl_browser_lineposition, "fl_browser_lineposition");
    pragma Inline (fl_browser_lineposition);




    function fl_browser_select
           (B    : in Storage.Integer_Address;
            L, V : in Interfaces.C.int)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_select, "fl_browser_select");
    pragma Inline (fl_browser_select);

    function fl_browser_selected
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_selected, "fl_browser_selected");
    pragma Inline (fl_browser_selected);

    function fl_browser_value
           (B : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_value, "fl_browser_value");
    pragma Inline (fl_browser_value);




    function fl_browser_visible
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_visible, "fl_browser_visible");
    pragma Inline (fl_browser_visible);

    procedure fl_browser_make_visible
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int);
    pragma Import (C, fl_browser_make_visible, "fl_browser_make_visible");
    pragma Inline (fl_browser_make_visible);

    function fl_browser_displayed
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_displayed, "fl_browser_displayed");
    pragma Inline (fl_browser_displayed);

    procedure fl_browser_show_line
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int);
    pragma Import (C, fl_browser_show_line, "fl_browser_show_line");
    pragma Inline (fl_browser_show_line);

    procedure fl_browser_hide_line
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int);
    pragma Import (C, fl_browser_hide_line, "fl_browser_hide_line");
    pragma Inline (fl_browser_hide_line);

    procedure fl_browser_show
           (B : in Storage.Integer_Address);
    pragma Import (C, fl_browser_show, "fl_browser_show");
    pragma Inline (fl_browser_show);

    procedure fl_browser_hide
           (B : in Storage.Integer_Address);
    pragma Import (C, fl_browser_hide, "fl_browser_hide");
    pragma Inline (fl_browser_hide);




    procedure fl_browser_set_icon
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int;
            C : in Storage.Integer_Address);
    pragma Import (C, fl_browser_set_icon, "fl_browser_set_icon");
    pragma Inline (fl_browser_set_icon);

    procedure fl_browser_remove_icon
           (B : in Storage.Integer_Address;
            L : in Interfaces.C.int);
    pragma Import (C, fl_browser_remove_icon, "fl_browser_remove_icon");
    pragma Inline (fl_browser_remove_icon);




    function fl_browser_item_width
           (B, I : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_item_width, "fl_browser_item_width");
    pragma Inline (fl_browser_item_width);

    function fl_browser_item_height
           (B, I : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_item_height, "fl_browser_item_height");
    pragma Inline (fl_browser_item_height);

    function fl_browser_item_first
           (B : in Storage.Integer_Address)
        return Storage.Integer_Address;
    pragma Import (C, fl_browser_item_first, "fl_browser_item_first");
    pragma Inline (fl_browser_item_first);

    function fl_browser_item_last
           (B : in Storage.Integer_Address)
        return Storage.Integer_Address;
    pragma Import (C, fl_browser_item_last, "fl_browser_item_last");
    pragma Inline (fl_browser_item_last);

    function fl_browser_item_next
           (B, I : in Storage.Integer_Address)
        return Storage.Integer_Address;
    pragma Import (C, fl_browser_item_next, "fl_browser_item_next");
    pragma Inline (fl_browser_item_next);

    function fl_browser_item_prev
           (B, I : in Storage.Integer_Address)
        return Storage.Integer_Address;
    pragma Import (C, fl_browser_item_prev, "fl_browser_item_prev");
    pragma Inline (fl_browser_item_prev);

    function fl_browser_item_at
           (B : in Storage.Integer_Address;
            N : in Interfaces.C.int)
        return Storage.Integer_Address;
    pragma Import (C, fl_browser_item_at, "fl_browser_item_at");
    pragma Inline (fl_browser_item_at);

    procedure fl_browser_item_select
           (B, I : in Storage.Integer_Address;
            V    : in Interfaces.C.int);
    pragma Import (C, fl_browser_item_select, "fl_browser_item_select");
    pragma Inline (fl_browser_item_select);

    function fl_browser_item_selected
           (B, I : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_item_selected, "fl_browser_item_selected");
    pragma Inline (fl_browser_item_selected);

    procedure fl_browser_item_swap
           (B, X, Y : in Storage.Integer_Address);
    pragma Import (C, fl_browser_item_swap, "fl_browser_item_swap");
    pragma Inline (fl_browser_item_swap);

    function fl_browser_item_text
           (B, I : in Storage.Integer_Address)
        return Interfaces.C.Strings.chars_ptr;
    pragma Import (C, fl_browser_item_text, "fl_browser_item_text");
    pragma Inline (fl_browser_item_text);

    procedure fl_browser_item_draw
           (B, I       : in Storage.Integer_Address;
            X, Y, W, H : in Interfaces.C.int);
    pragma Import (C, fl_browser_item_draw, "fl_browser_item_draw");
    pragma Inline (fl_browser_item_draw);




    function fl_browser_full_width
           (B : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_full_width, "fl_browser_full_width");
    pragma Inline (fl_browser_full_width);

    function fl_browser_full_height
           (B : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_full_height, "fl_browser_full_height");
    pragma Inline (fl_browser_full_height);

    function fl_browser_incr_height
           (B : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_incr_height, "fl_browser_incr_height");
    pragma Inline (fl_browser_incr_height);

    function fl_browser_item_quick_height
           (B, I : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_item_quick_height, "fl_browser_item_quick_height");
    pragma Inline (fl_browser_item_quick_height);




    function fl_browser_lineno
           (B, I : in Storage.Integer_Address)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_lineno, "fl_browser_lineno");
    pragma Inline (fl_browser_lineno);




    procedure fl_browser_draw
           (B : in Storage.Integer_Address);
    pragma Import (C, fl_browser_draw, "fl_browser_draw");
    pragma Inline (fl_browser_draw);

    function fl_browser_handle
           (B : in Storage.Integer_Address;
            E : in Interfaces.C.int)
        return Interfaces.C.int;
    pragma Import (C, fl_browser_handle, "fl_browser_handle");
    pragma Inline (fl_browser_handle);




    -------------------
    --  Destructors  --
    -------------------

    procedure Free is new Ada.Unchecked_Deallocation
       (Object => C_Col_Widths,
        Name   => C_Col_Widths_Access);

    procedure Free is new Ada.Unchecked_Deallocation
       (Object => FLTK.Images.Image'Class,
        Name   => Image_Access);


    procedure Extra_Final
           (This : in out Textline_Browser) is
    begin
        Free (This.Columns);
        for Icon_Ptr of This.Icons loop
            Free (Icon_Ptr);
        end loop;
        Extra_Final (Browser (This));
    end Extra_Final;


    procedure Finalize
           (This : in out Textline_Browser) is
    begin
        Extra_Final (This);
        if This.Void_Ptr /= Null_Pointer and This.Needs_Dealloc then
            free_fl_browser (This.Void_Ptr);
            This.Void_Ptr := Null_Pointer;
        end if;
    end Finalize;




    --------------------
    --  Constructors  --
    --------------------

    procedure Extra_Init
           (This       : in out Textline_Browser;
            X, Y, W, H : in     Integer;
            Text       : in     String) is
    begin
        Extra_Init (Browser (This), X, Y, W, H, Text);
    end Extra_Init;


    procedure Initialize
           (This : in out Textline_Browser) is
    begin
        This.Item_Override_Ptrs :=
           (Item_Width_Ptr    => fl_browser_item_width'Address,
            Item_Height_Ptr   => fl_browser_item_height'Address,
            Item_First_Ptr    => fl_browser_item_first'Address,
            Item_Last_Ptr     => fl_browser_item_last'Address,
            Item_Next_Ptr     => fl_browser_item_next'Address,
            Item_Previous_Ptr => fl_browser_item_prev'Address,
            Item_At_Ptr       => fl_browser_item_at'Address,
            Item_Select_Ptr   => fl_browser_item_select'Address,
            Item_Selected_Ptr => fl_browser_item_selected'Address,
            Item_Swap_Ptr     => fl_browser_item_swap'Address,
            Item_Text_Ptr     => fl_browser_item_text'Address,
            Item_Draw_Ptr     => fl_browser_item_draw'Address);
        This.Wide_High_Ptrs :=
           (Full_List_Width_Ptr     => fl_browser_full_width'Address,
            Full_List_Height_Ptr    => fl_browser_full_height'Address,
            Average_Item_Height_Ptr => fl_browser_incr_height'Address,
            Item_Quick_Height_Ptr   => fl_browser_item_quick_height'Address);
        This.Draw_Ptr := fl_browser_draw'Address;
        This.Handle_Ptr := fl_browser_handle'Address;
    end Initialize;


    package body Forge is

        function Create
               (X, Y, W, H : in Integer;
                Text       : in String := "")
            return Textline_Browser is
        begin
            return This : Textline_Browser do
                This.Void_Ptr := new_fl_browser
                   (Interfaces.C.int (X),
                    Interfaces.C.int (Y),
                    Interfaces.C.int (W),
                    Interfaces.C.int (H),
                    Interfaces.C.To_C (Text));
                Extra_Init (This, X, Y, W, H, Text);
            end return;
        end Create;

    end Forge;




    -----------------------
    --  API Subprograms  --
    -----------------------

    procedure Add
           (This : in out Textline_Browser;
            Text : in     String) is
    begin
        fl_browser_add
           (This.Void_Ptr,
            Interfaces.C.To_C (Text),
            Null_Pointer);
    end Add;


    procedure Insert
           (This  : in out Textline_Browser;
            Above : in     Positive;
            Text  : in     String) is
    begin
        fl_browser_insert
           (This.Void_Ptr,
            Interfaces.C.int (Above),
            Interfaces.C.To_C (Text),
            Null_Pointer);
    end Insert;


    procedure Move
           (This     : in out Textline_Browser;
            From, To : in     Positive) is
    begin
        fl_browser_move
           (This.Void_Ptr,
            Interfaces.C.int (To),
            Interfaces.C.int (From));
    end Move;


    procedure Swap
           (This : in out Textline_Browser;
            A, B : in     Positive) is
    begin
        fl_browser_swap
           (This.Void_Ptr,
            Interfaces.C.int (A),
            Interfaces.C.int (B));
    end Swap;


    procedure Remove
           (This : in out Textline_Browser;
            Line : in     Positive) is
    begin
        fl_browser_remove
           (This.Void_Ptr,
            Interfaces.C.int (Line));
    end Remove;


    procedure Clear
           (This : in out Textline_Browser) is
    begin
        fl_browser_clear (This.Void_Ptr);
    end Clear;


    function Number_Of_Lines
           (This : in Textline_Browser)
        return Natural is
    begin
        return Natural (fl_browser_size (This.Void_Ptr));
    end Number_Of_Lines;




    procedure Load
           (This : in out Textline_Browser;
            File : in     String)
    is
        Msg  : Interfaces.C.Strings.chars_ptr;
        Code : Interfaces.C.int := fl_browser_load (This.Void_Ptr, Interfaces.C.To_C (File));
    begin
        if Code = 0 then
            Msg := get_error_message;
            if Msg = Interfaces.C.Strings.Null_Ptr then
                raise Browser_Load_Error;
            else
                raise Browser_Load_Error with Interfaces.C.Strings.Value (Msg);
            end if;
        else
            pragma Assert (Code = 1);
        end if;
    exception
    when Chk.Assertion_Error => raise Internal_FLTK_Error;
    end Load;


    function Get_Line_Text
           (This : in Textline_Browser;
            Line : in Positive)
        return String
    is
        Ptr : Interfaces.C.Strings.chars_ptr := fl_browser_get_text
           (This.Void_Ptr,
            Interfaces.C.int (Line));
    begin
        if Ptr = Interfaces.C.Strings.Null_Ptr then
            return "";
        else
            return Interfaces.C.Strings.Value (Ptr);
        end if;
    end Get_Line_Text;


    procedure Set_Line_Text
           (This : in out Textline_Browser;
            Line : in     Positive;
            Text : in     String) is
    begin
        fl_browser_set_text
           (This.Void_Ptr,
            Interfaces.C.int (Line),
            Interfaces.C.To_C (Text));
    end Set_Line_Text;


    function Get_Text_Size
           (This : in Textline_Browser)
        return Font_Size is
    begin
        return Font_Size (fl_browser_get_textsize (This.Void_Ptr));
    end Get_Text_Size;


    procedure Set_Text_Size
           (This : in out Textline_Browser;
            Size : in     Font_Size) is
    begin
        fl_browser_set_textsize (This.Void_Ptr, Interfaces.C.int (Size));
    end Set_Text_Size;




    function Get_Column_Character
           (This : in Textline_Browser)
        return Character is
    begin
        return Interfaces.C.To_Ada (fl_browser_get_column_char (This.Void_Ptr));
    end Get_Column_Character;


    procedure Set_Column_Character
           (This  : in out Textline_Browser;
            Value : in     Character) is
    begin
        fl_browser_set_column_char (This.Void_Ptr, Interfaces.C.To_C (Value));
    end Set_Column_Character;


    function Get_Column_Widths
           (This : in Textline_Browser)
        return Column_Widths is
    begin
        if This.Columns = null then
            return Result : Column_Widths (1 .. 0);
        else
            return Result : Column_Widths (This.Columns'First .. This.Columns'Last - 1) do
                for Index in Result'Range loop
                    Result (Index) := Integer (This.Columns (Index));
                end loop;
            end return;
        end if;
    end Get_Column_Widths;


    procedure Set_Column_Widths
           (This   : in out Textline_Browser;
            Widths : in     Column_Widths) is
    begin
        Free (This.Columns);
        This.Columns := new C_Col_Widths (1 .. Widths'Length + 1);
        for Index in This.Columns'Range loop
            This.Columns (Index) := Interfaces.C.int (Widths (Widths'First + Index - 1));
        end loop;
        This.Columns (This.Columns'Last) := 0;
        fl_browser_set_column_widths (This.Void_Ptr, Storage.To_Integer (This.Columns.all'Address));
    end Set_Column_Widths;


    function Get_Format_Character
           (This : in Textline_Browser)
        return Character is
    begin
        return Interfaces.C.To_Ada (fl_browser_get_format_char (This.Void_Ptr));
    end Get_Format_Character;


    procedure Set_Format_Character
           (This  : in out Textline_Browser;
            Value : in     Character) is
    begin
        fl_browser_set_format_char (This.Void_Ptr, Interfaces.C.To_C (Value));
    end Set_Format_Character;




    function Get_Top_Line
           (This : in Textline_Browser)
        return Positive is
    begin
        return Positive (fl_browser_get_topline (This.Void_Ptr));
    end Get_Top_Line;


    procedure Set_Top_Line
           (This : in out Textline_Browser;
            Line : in     Positive) is
    begin
        fl_browser_set_topline (This.Void_Ptr, Interfaces.C.int (Line));
    end Set_Top_Line;


    procedure Set_Middle_Line
           (This : in out Textline_Browser;
            Line : in     Positive) is
    begin
        fl_browser_middleline (This.Void_Ptr, Interfaces.C.int (Line));
    end Set_Middle_Line;


    procedure Set_Bottom_Line
           (This : in out Textline_Browser;
            Line : in     Positive) is
    begin
        fl_browser_bottomline (This.Void_Ptr, Interfaces.C.int (Line));
    end Set_Bottom_Line;


    procedure Set_Line_Position
           (This  : in out Textline_Browser;
            Line  : in     Positive;
            Place : in     Line_Position) is
    begin
        fl_browser_lineposition (This.Void_Ptr, Interfaces.C.int (Line), Line_Position'Pos (Place));
    end Set_Line_Position;




    function Set_Select
           (This  : in out Textline_Browser;
            Line  : in     Positive;
            State : in     Boolean := True)
        return Boolean
    is
        Code : Interfaces.C.int := fl_browser_select
           (This.Void_Ptr,
            Interfaces.C.int (Line),
            Boolean'Pos (State));
    begin
        pragma Assert (Code in 0 .. 1);
        return Boolean'Val (Code);
    exception
    when Chk.Assertion_Error => raise Internal_FLTK_Error;
    end Set_Select;


    procedure Set_Select
           (This  : in out Textline_Browser;
            Line  : in     Positive;
            State : in     Boolean := True)
    is
        Code : Interfaces.C.int := fl_browser_select
           (This.Void_Ptr,
            Interfaces.C.int (Line),
            Boolean'Pos (State));
    begin
        pragma Assert (Code in 0 .. 1);
    exception
    when Chk.Assertion_Error => raise Internal_FLTK_Error;
    end Set_Select;


    function Is_Selected
           (This : in Textline_Browser;
            Line : in Positive)
        return Boolean
    is
        Code : Interfaces.C.int := fl_browser_selected
           (This.Void_Ptr,
            Interfaces.C.int (Line));
    begin
        pragma Assert (Code in 0 .. 1);
        return Boolean'Val (Code);
    exception
    when Chk.Assertion_Error => raise Internal_FLTK_Error;
    end Is_Selected;


    function Selected_Index
           (This : in Textline_Browser)
        return Natural is
    begin
        return Natural (fl_browser_value (This.Void_Ptr));
    end Selected_Index;




    function Is_Visible
           (This : in Textline_Browser;
            Line : in Positive)
        return Boolean is
    begin
        return fl_browser_visible (This.Void_Ptr, Interfaces.C.int (Line)) /= 0;
    end Is_Visible;


    procedure Make_Visible
           (This : in out Textline_Browser;
            Line : in     Positive) is
    begin
        fl_browser_make_visible (This.Void_Ptr, Interfaces.C.int (Line));
    end Make_Visible;


    function Is_Displayed
           (This : in Textline_Browser;
            Line : in Positive)
        return Boolean
    is
        Code : Interfaces.C.int := fl_browser_displayed
           (This.Void_Ptr,
            Interfaces.C.int (Line));
    begin
        pragma Assert (Code in 0 .. 1);
        return Boolean'Val (Code);
    exception
    when Chk.Assertion_Error => raise Internal_FLTK_Error;
    end Is_Displayed;


    procedure Show_Line
           (This : in out Textline_Browser;
            Line : in     Positive) is
    begin
        fl_browser_show_line (This.Void_Ptr, Interfaces.C.int (Line));
    end Show_Line;


    procedure Hide_Line
           (This : in out Textline_Browser;
            Line : in     Positive) is
    begin
        fl_browser_hide_line (This.Void_Ptr, Interfaces.C.int (Line));
    end Hide_Line;


    procedure Show
           (This : in out Textline_Browser) is
    begin
        fl_browser_show (This.Void_Ptr);
    end Show;


    procedure Hide
           (This : in out Textline_Browser) is
    begin
        fl_browser_hide (This.Void_Ptr);
    end Hide;




    function Has_Icon
           (This : in Textline_Browser;
            Line : in Positive)
        return Boolean is
    begin
        return Line <= This.Icons.Last_Index and then This.Icons.Element (Line) /= null;
    end Has_Icon;


    function Get_Icon
           (This : in Textline_Browser;
            Line : in Positive)
        return FLTK.Images.Image_Reference is
    begin
        return Ref : FLTK.Images.Image_Reference (Data => This.Icons.Element (Line));
    end Get_Icon;


    procedure Set_Icon
           (This : in out Textline_Browser;
            Line : in     Positive;
            Icon : in     FLTK.Images.Image'Class) is
    begin
        fl_browser_set_icon (This.Void_Ptr, Interfaces.C.int (Line), Wrapper (Icon).Void_Ptr);
        if Line > This.Icons.Last_Index then
            This.Icons.Append (null, Ada.Containers.Count_Type (Line - This.Icons.Last_Index - 1));
            This.Icons.Append (new FLTK.Images.Image);
            Wrapper (This.Icons.Element (Line).all).Needs_Dealloc := False;
        elsif This.Icons.Element (Line) = null then
            This.Icons.Replace_Element (Line, new FLTK.Images.Image);
            Wrapper (This.Icons.Element (Line).all).Needs_Dealloc := False;
        end if;
        Wrapper (This.Icons.Element (Line).all).Void_Ptr := Wrapper (Icon).Void_Ptr;
    end Set_Icon;


    procedure Remove_Icon
           (This : in out Textline_Browser;
            Line : in     Positive)
    is
        Ptr : Image_Access;
    begin
        fl_browser_remove_icon (This.Void_Ptr, Interfaces.C.int (Line));
        if Line <= This.Icons.Last_Index then
            Ptr := This.Icons.Element (Line);
            Free (Ptr);
            This.Icons.Replace_Element (Line, null);
        end if;
    end Remove_Icon;




    function Full_List_Height
           (This : in Textline_Browser)
        return Integer is
    begin
        return Browser (This).Full_List_Height;
    end Full_List_Height;


    function Average_Item_Height
           (This : in Textline_Browser)
        return Integer is
    begin
        return Browser (This).Average_Item_Height;
    end Average_Item_Height;




    function Item_Width
           (This : in Textline_Browser;
            Item : in Item_Cursor)
        return Integer
    is
        function my_item_width
               (B, I : in Storage.Integer_Address)
            return Interfaces.C.int;
        for my_item_width'Address use This.Item_Override_Ptrs (Item_Width_Ptr);
        pragma Import (Ada, my_item_width);
    begin
        return Integer (my_item_width (This.Void_Ptr, Cursor_To_Address (Item)));
    end Item_Width;


    function Item_Height
           (This : in Textline_Browser;
            Item : in Item_Cursor)
        return Integer
    is
        function my_item_height
               (B, I : in Storage.Integer_Address)
            return Interfaces.C.int;
        for my_item_height'Address use This.Item_Override_Ptrs (Item_Height_Ptr);
        pragma Import (Ada, my_item_height);
    begin
        return Integer (my_item_height (This.Void_Ptr, Cursor_To_Address (Item)));
    end Item_Height;


    function Item_First
           (This : in Textline_Browser)
        return Item_Cursor
    is
        function my_item_first
               (B : in Storage.Integer_Address)
            return Storage.Integer_Address;
        for my_item_first'Address use This.Item_Override_Ptrs (Item_First_Ptr);
        pragma Import (Ada, my_item_first);
    begin
        return Address_To_Cursor (my_item_first (This.Void_Ptr));
    end Item_First;


    function Item_Last
           (This : in Textline_Browser)
        return Item_Cursor
    is
        function my_item_last
               (B : in Storage.Integer_Address)
            return Storage.Integer_Address;
        for my_item_last'Address use This.Item_Override_Ptrs (Item_Last_Ptr);
        pragma Import (Ada, my_item_last);
    begin
        return Address_To_Cursor (my_item_last (This.Void_Ptr));
    end Item_Last;


    function Item_Next
           (This : in Textline_Browser;
            Item : in Item_Cursor)
        return Item_Cursor
    is
        function my_item_next
               (B, I : in Storage.Integer_Address)
            return Storage.Integer_Address;
        for my_item_next'Address use This.Item_Override_Ptrs (Item_Next_Ptr);
        pragma Import (Ada, my_item_next);
    begin
        return Address_To_Cursor (my_item_next (This.Void_Ptr, Cursor_To_Address (Item)));
    end Item_Next;


    function Item_Previous
           (This : in Textline_Browser;
            Item : in Item_Cursor)
        return Item_Cursor
    is
        function my_item_prev
               (B, I : in Storage.Integer_Address)
            return Storage.Integer_Address;
        for my_item_prev'Address use This.Item_Override_Ptrs (Item_Previous_Ptr);
        pragma Import (Ada, my_item_prev);
    begin
        return Address_To_Cursor (my_item_prev (This.Void_Ptr, Cursor_To_Address (Item)));
    end Item_Previous;


    function Item_At
           (This  : in Textline_Browser;
            Index : in Positive)
        return Item_Cursor
    is
        function my_item_at
               (B : in Storage.Integer_Address;
                N : in Interfaces.C.int)
            return Storage.Integer_Address;
        for my_item_at'Address use This.Item_Override_Ptrs (Item_At_Ptr);
        pragma Import (Ada, my_item_at);
    begin
        return Address_To_Cursor (my_item_at (This.Void_Ptr, Interfaces.C.int (Index)));
    end Item_At;


    procedure Item_Select
           (This  : in out Textline_Browser;
            Item  : in     Item_Cursor;
            State : in     Boolean := True)
    is
        procedure my_item_select
               (B, I : in Storage.Integer_Address;
                V    : in Interfaces.C.int);
        for my_item_select'Address use This.Item_Override_Ptrs (Item_Select_Ptr);
        pragma Import (Ada, my_item_select);
    begin
        my_item_select (This.Void_Ptr, Cursor_To_Address (Item), Boolean'Pos (State));
    end Item_Select;


    function Item_Selected
           (This : in Textline_Browser;
            Item : in Item_Cursor)
        return Boolean
    is
        function my_item_selected
               (B, I : in Storage.Integer_Address)
            return Interfaces.C.int;
        for my_item_selected'Address use This.Item_Override_Ptrs (Item_Selected_Ptr);
        pragma Import (Ada, my_item_selected);
        Code : Interfaces.C.int := my_item_selected (This.Void_Ptr, Cursor_To_Address (Item));
    begin
        pragma Assert (Code in 0 .. 1);
        return Boolean'Val (Code);
    exception
    when Chk.Assertion_Error => raise Internal_FLTK_Error;
    end Item_Selected;


    procedure Item_Swap
           (This : in out Textline_Browser;
            A, B : in     Item_Cursor)
    is
        procedure my_item_swap
               (B, X, Y : in Storage.Integer_Address);
        for my_item_swap'Address use This.Item_Override_Ptrs (Item_Swap_Ptr);
        pragma Import (Ada, my_item_swap);
    begin
        my_item_swap (This.Void_Ptr, Cursor_To_Address (A), Cursor_To_Address (B));
    end Item_Swap;


    function Item_Text
           (This : in Textline_Browser;
            Item : in Item_Cursor)
        return String
    is
        function my_item_text
               (B, I : in Storage.Integer_Address)
            return Interfaces.C.Strings.chars_ptr;
        for my_item_text'Address use This.Item_Override_Ptrs (Item_Text_Ptr);
        pragma Import (Ada, my_item_text);
    begin
        return Interfaces.C.Strings.Value (my_item_text (This.Void_Ptr, Cursor_To_Address (Item)));
    end Item_Text;


    procedure Item_Draw
           (This       : in Textline_Browser;
            Item       : in Item_Cursor;
            X, Y, W, H : in Integer)
    is
        procedure my_item_draw
               (B, I       : in Storage.Integer_Address;
                X, Y, W, H : in Interfaces.C.int);
        for my_item_draw'Address use This.Item_Override_Ptrs (Item_Draw_Ptr);
        pragma Import (Ada, my_item_draw);
    begin
        my_item_draw
           (This.Void_Ptr,
            Cursor_To_Address (Item),
            Interfaces.C.int (X),
            Interfaces.C.int (Y),
            Interfaces.C.int (W),
            Interfaces.C.int (H));
    end Item_Draw;




    function Line_Number
           (This : in Textline_Browser;
            Item : in Item_Cursor)
        return Natural is
    begin
        return Natural (fl_browser_lineno (This.Void_Ptr, Cursor_To_Address (Item)));
    end Line_Number;


end FLTK.Widgets.Groups.Browsers.Textline;