summaryrefslogtreecommitdiff
path: root/src/fltk-widgets-groups-browsers-textline-file.adb
blob: c73e5e4d9f1715ae83c921f7872ae4ea3d671666 (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


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


with

    Interfaces.C.Strings;

use type

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


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


    ------------------------
    --  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 filename_dname
           (L : in Storage.Integer_Address;
            N : in Interfaces.C.int)
        return Interfaces.C.Strings.chars_ptr;
    pragma Import (C, filename_dname, "filename_dname");
    pragma Inline (filename_dname);




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

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




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




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

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

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

    procedure fl_file_browser_set_filter
           (B : in Storage.Integer_Address;
            F : in Interfaces.C.char_array);
    pragma Import (C, fl_file_browser_set_filter, "fl_file_browser_set_filter");
    pragma Inline (fl_file_browser_set_filter);

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

    procedure fl_file_browser_set_iconsize
           (B : in Storage.Integer_Address;
            I : in Interfaces.C.unsigned_char);
    pragma Import (C, fl_file_browser_set_iconsize, "fl_file_browser_set_iconsize");
    pragma Inline (fl_file_browser_set_iconsize);

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

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




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

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

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

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

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

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

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

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

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

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

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

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





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

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

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

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




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

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

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

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




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

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

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

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




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




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

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

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

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

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




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

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




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

    procedure Extra_Final
           (This : in out File_Browser) is
    begin
        Extra_Final (Textline_Browser (This));
    end Extra_Final;


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




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

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


    procedure Initialize
           (This : in out File_Browser) is
    begin
        This.Item_Override_Ptrs :=
           (Item_Width_Ptr    => fl_file_browser_item_width'Address,
            Item_Height_Ptr   => fl_file_browser_item_height'Address,
            Item_First_Ptr    => fl_file_browser_item_first'Address,
            Item_Last_Ptr     => fl_file_browser_item_last'Address,
            Item_Next_Ptr     => fl_file_browser_item_next'Address,
            Item_Previous_Ptr => fl_file_browser_item_prev'Address,
            Item_At_Ptr       => fl_file_browser_item_at'Address,
            Item_Select_Ptr   => fl_file_browser_item_select'Address,
            Item_Selected_Ptr => fl_file_browser_item_selected'Address,
            Item_Swap_Ptr     => fl_file_browser_item_swap'Address,
            Item_Text_Ptr     => fl_file_browser_item_text'Address,
            Item_Draw_Ptr     => fl_file_browser_item_draw'Address);
        This.Item_Inherit_Ptrs :=
           (Current_Selection_Ptr => fl_file_browser_selection'Address,
            Is_Displayed_Ptr      => fl_file_browser_displayed2'Address,
            Find_Item_Ptr         => fl_file_browser_find_item'Address,
            Top_Item_Ptr          => fl_file_browser_top'Address);
        This.Redrawing_Ptrs :=
           (Bounding_Box_Ptr => fl_file_browser_bbox'Address,
            Left_Edge_Ptr    => fl_file_browser_leftedge'Address,
            Redraw_Line_Ptr  => fl_file_browser_redraw_line'Address,
            Redraw_List_Ptr  => fl_file_browser_redraw_lines'Address);
        This.Wide_High_Ptrs :=
           (Full_List_Width_Ptr     => fl_file_browser_full_width'Address,
            Full_List_Height_Ptr    => fl_file_browser_full_height'Address,
            Average_Item_Height_Ptr => fl_file_browser_incr_height'Address,
            Item_Quick_Height_Ptr   => fl_file_browser_item_quick_height'Address);
        This.Cache_Ptrs :=
           (New_List_Ptr  => fl_file_browser_new_list'Address,
            Inserting_Ptr => fl_file_browser_inserting'Address,
            Deleting_Ptr  => fl_file_browser_deleting'Address,
            Replacing_Ptr => fl_file_browser_replacing'Address,
            Swapping_Ptr  => fl_file_browser_swapping'Address);
        This.Draw_Ptr := fl_file_browser_draw'Address;
        This.Handle_Ptr := fl_file_browser_handle'Address;
        This.Line_Number_Ptr := fl_file_browser_lineno'Address;
    end Initialize;


    package body Forge is

        function Create
               (X, Y, W, H : in Integer;
                Text       : in String := "")
            return File_Browser is
        begin
            return This : File_Browser do
                This.Void_Ptr := new_fl_file_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  --
    -----------------------

    Current_Sort : FLTK.Filenames.Compare_Function;

    function Compare_Hook
           (DA, DB : in Storage.Integer_Address)
        return Interfaces.C.int;

    pragma Convention (C, Compare_Hook);

    function Compare_Hook
           (DA, DB : in Storage.Integer_Address)
        return Interfaces.C.int
    is
        Result : FLTK.Filenames.Comparison := Current_Sort
           (Interfaces.C.Strings.Value (filename_dname (DA, 0)),
            Interfaces.C.Strings.Value (filename_dname (DB, 0)));
    begin
        return FLTK.Filenames.Comparison'Pos (Result) - 1;
    end Compare_Hook;


    function Load
           (This : in out File_Browser;
            Dir  : in     String;
            Sort : in not null FLTK.Filenames.Compare_Function :=
                FLTK.Filenames.Numeric_Sort'Access)
        return Natural
    is
        Msg  : Interfaces.C.Strings.chars_ptr;
        Code : Interfaces.C.int;
    begin
        Current_Sort := Sort;
        Code := fl_file_browser_load
           (This.Void_Ptr,
            Interfaces.C.To_C (Dir),
            Storage.To_Integer (Compare_Hook'Address));
        if Code = 0 then
            Msg := get_error_message;
            if Msg /= Interfaces.C.Strings.Null_Ptr then
                raise Browser_Load_Error with Interfaces.C.Strings.Value (Msg);
            end if;
        end if;
        return Natural (Code);
    end Load;


    procedure Load
           (This : in out File_Browser;
            Dir  : in     String;
            Sort : in not null FLTK.Filenames.Compare_Function :=
                FLTK.Filenames.Numeric_Sort'Access)
    is
        Result : Natural := This.Load (Dir, Sort);
    begin
        null;
    end Load;




    function Get_File_Kind
           (This : in File_Browser)
        return File_Kind
    is
        Code : Interfaces.C.int := fl_file_browser_get_filetype (This.Void_Ptr);
    begin
        if Code not in File_Kind'Pos (File_Kind'First) .. File_Kind'Pos (File_Kind'Last) then
            raise Internal_FLTK_Error;
        end if;
        return File_Kind'Val (Code);
    end Get_File_Kind;


    procedure Set_File_Kind
           (This  : in out File_Browser;
            Value : in     File_Kind) is
    begin
        fl_file_browser_set_filetype (This.Void_Ptr, File_Kind'Pos (Value));
    end Set_File_Kind;


    function Get_Filter
           (This : in File_Browser)
        return String
    is
        Result : Interfaces.C.Strings.chars_ptr := fl_file_browser_get_filter (This.Void_Ptr);
    begin
        if Result = Interfaces.C.Strings.Null_Ptr then
            return "";
        else
            return Interfaces.C.Strings.Value (Result);
        end if;
    end Get_Filter;


    procedure Set_Filter
           (This  : in out File_Browser;
            Value : in     String) is
    begin
        fl_file_browser_set_filter (This.Void_Ptr, Interfaces.C.To_C (Value));
    end Set_Filter;


    function Get_Icon_Size
           (This : in File_Browser)
        return Icon_Size is
    begin
        return Icon_Size (fl_file_browser_get_iconsize (This.Void_Ptr));
    end Get_Icon_Size;


    procedure Set_Icon_Size
           (This  : in out File_Browser;
            Value : in     Icon_Size) is
    begin
        fl_file_browser_set_iconsize (This.Void_Ptr, Interfaces.C.unsigned_char (Value));
    end Set_Icon_Size;


    function Get_Text_Size
           (This : in File_Browser)
        return Font_Size is
    begin
        return Font_Size (fl_file_browser_get_textsize (This.Void_Ptr));
    end Get_Text_Size;


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


end FLTK.Widgets.Groups.Browsers.Textline.File;