summaryrefslogtreecommitdiff
path: root/src/fltk-widgets-groups-help_views.adb
blob: 715e2caaa92fdb9bd648ab3abc53f68d95ec45ce (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


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


with

    Interfaces.C.Strings,
    System.Address_To_Access_Conversions;

use type

    Interfaces.C.int;


package body FLTK.Widgets.Groups.Help_Views is


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

    procedure help_view_set_draw_hook
           (V, D : in Storage.Integer_Address);
    pragma Import (C, help_view_set_draw_hook, "help_view_set_draw_hook");
    pragma Inline (help_view_set_draw_hook);

    procedure help_view_set_handle_hook
           (V, H : in Storage.Integer_Address);
    pragma Import (C, help_view_set_handle_hook, "help_view_set_handle_hook");
    pragma Inline (help_view_set_handle_hook);




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

    procedure free_fl_help_view
           (V : in Storage.Integer_Address);
    pragma Import (C, free_fl_help_view, "free_fl_help_view");
    pragma Inline (free_fl_help_view);




    procedure fl_help_view_clear_selection
           (V : in Storage.Integer_Address);
    pragma Import (C, fl_help_view_clear_selection, "fl_help_view_clear_selection");
    pragma Inline (fl_help_view_clear_selection);

    procedure fl_help_view_select_all
           (V : in Storage.Integer_Address);
    pragma Import (C, fl_help_view_select_all, "fl_help_view_select_all");
    pragma Inline (fl_help_view_select_all);




    function fl_help_view_find
           (V : in Storage.Integer_Address;
            S : in Interfaces.C.char_array;
            P : in Interfaces.C.int)
        return Interfaces.C.int;
    pragma Import (C, fl_help_view_find, "fl_help_view_find");
    pragma Inline (fl_help_view_find);

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

    procedure fl_help_view_set_leftline
           (V : in Storage.Integer_Address;
            T : in Interfaces.C.int);
    pragma Import (C, fl_help_view_set_leftline, "fl_help_view_set_leftline");
    pragma Inline (fl_help_view_set_leftline);

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

    procedure fl_help_view_set_topline
           (V : in Storage.Integer_Address;
            T : in Interfaces.C.int);
    pragma Import (C, fl_help_view_set_topline, "fl_help_view_set_topline");
    pragma Inline (fl_help_view_set_topline);

    procedure fl_help_view_set_topline_target
           (V : in Storage.Integer_Address;
            T : in Interfaces.C.char_array);
    pragma Import (C, fl_help_view_set_topline_target, "fl_help_view_set_topline_target");
    pragma Inline (fl_help_view_set_topline_target);




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

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

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

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

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

    procedure fl_help_view_set_value
           (V : in Storage.Integer_Address;
            T : in Interfaces.C.char_array);
    pragma Import (C, fl_help_view_set_value, "fl_help_view_set_value");
    pragma Inline (fl_help_view_set_value);

    procedure fl_help_view_link
           (V, F : in Storage.Integer_Address);
    pragma Import (C, fl_help_view_link, "fl_help_view_link");
    pragma Inline (fl_help_view_link);




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

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

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

    procedure fl_help_view_set_size
           (V    : in Storage.Integer_Address;
            W, H : in Interfaces.C.int);
    pragma Import (C, fl_help_view_set_size, "fl_help_view_set_size");
    pragma Inline (fl_help_view_set_size);

    function fl_help_view_get_textcolor
           (V : in Storage.Integer_Address)
        return Interfaces.C.unsigned;
    pragma Import (C, fl_help_view_get_textcolor, "fl_help_view_get_textcolor");
    pragma Inline (fl_help_view_get_textcolor);

    procedure fl_help_view_set_textcolor
           (V : in Storage.Integer_Address;
            C : in Interfaces.C.unsigned);
    pragma Import (C, fl_help_view_set_textcolor, "fl_help_view_set_textcolor");
    pragma Inline (fl_help_view_set_textcolor);

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

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

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

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




    procedure fl_help_view_draw
           (V : in Storage.Integer_Address);
    pragma Import (C, fl_help_view_draw, "fl_help_view_draw");
    pragma Inline (fl_help_view_draw);

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




    ----------------------
    --  Callback Hooks  --
    ----------------------

    package Help_View_Convert is new System.Address_To_Access_Conversions (Help_View'Class);

    function Link_Callback_Hook
           (V : in Storage.Integer_Address;
            S : in Interfaces.C.Strings.chars_ptr)
        return Interfaces.C.Strings.chars_ptr;

    pragma Convention (C, Link_Callback_Hook);

    function Link_Callback_Hook
           (V : in Storage.Integer_Address;
            S : in Interfaces.C.Strings.chars_ptr)
        return Interfaces.C.Strings.chars_ptr
    is
        Ada_Help_View : access Help_View'Class :=
            Help_View_Convert.To_Pointer (Storage.To_Address (fl_widget_get_user_data (V)));
    begin
        if Ada_Help_View.Zelda = null then
            return S;
        end if;
        Interfaces.C.Strings.Free (Ada_Help_View.Hilda);
        Ada_Help_View.Hilda := Interfaces.C.Strings.New_String
           (Ada_Help_View.Zelda (Ada_Help_View.all, Interfaces.C.Strings.Value (S)));
        if Interfaces.C.Strings.Value (Ada_Help_View.Hilda) = "" then
            return Interfaces.C.Strings.Null_Ptr;
        else
            return Ada_Help_View.Hilda;
        end if;
    end Link_Callback_Hook;




    -----------------------------------
    --  Controlled Type Subprograms  --
    -----------------------------------

    procedure Extra_Final
           (This : in out Help_View) is
    begin
        Interfaces.C.Strings.Free (This.Hilda);
        Extra_Final (Group (This));
    end Extra_Final;


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




    ---------------------
    --  Help_View API  --
    ---------------------

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


    package body Forge is

        function Create
               (X, Y, W, H : in Integer;
                Text       : in String := "")
            return Help_View is
        begin
            return This : Help_View do
                This.Void_Ptr := new_fl_help_view
                   (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);
                help_view_set_draw_hook (This.Void_Ptr, Storage.To_Integer (Draw_Hook'Address));
                help_view_set_handle_hook (This.Void_Ptr, Storage.To_Integer (Handle_Hook'Address));
                fl_help_view_link (This.Void_Ptr, Storage.To_Integer (Link_Callback_Hook'Address));
            end return;
        end Create;

    end Forge;




    procedure Clear_Selection
           (This : in out Help_View) is
    begin
        fl_help_view_clear_selection (This.Void_Ptr);
    end Clear_Selection;


    procedure Select_All
           (This : in out Help_View) is
    begin
        fl_help_view_select_all (This.Void_Ptr);
    end Select_All;




    function Find
           (This : in Help_View;
            Item : in String;
            From : in Position := 1)
        return Extended_Position is
    begin
        return Extended_Position (fl_help_view_find
           (This.Void_Ptr,
            Interfaces.C.To_C (Item),
            Interfaces.C.int (From) - 1) + 1);
    end Find;


    function Get_Leftline_Pixel
           (This : in Help_View)
        return Natural is
    begin
        return Natural (fl_help_view_get_leftline (This.Void_Ptr));
    end Get_Leftline_Pixel;


    procedure Set_Leftline_Pixel
           (This  : in out Help_View;
            Value : in     Natural) is
    begin
        fl_help_view_set_leftline (This.Void_Ptr, Interfaces.C.int (Value));
    end Set_Leftline_Pixel;


    function Get_Topline_Pixel
           (This : in Help_View)
        return Natural is
    begin
        return Natural (fl_help_view_get_topline (This.Void_Ptr));
    end Get_Topline_Pixel;


    procedure Set_Topline_Pixel
           (This  : in out Help_View;
            Value : in     Natural) is
    begin
        fl_help_view_set_topline (This.Void_Ptr, Interfaces.C.int (Value));
    end Set_Topline_Pixel;


    procedure Set_Topline_Target
           (This  : in out Help_View;
            Value : in     String) is
    begin
        fl_help_view_set_topline_target (This.Void_Ptr, Interfaces.C.To_C (Value));
    end Set_Topline_Target;




    function Current_Directory
           (This : in Help_View)
        return String is
    begin
        return Interfaces.C.Strings.Value (fl_help_view_directory (This.Void_Ptr));
    end Current_Directory;


    function Current_File
           (This : in Help_View)
        return String is
    begin
        return Interfaces.C.Strings.Value (fl_help_view_filename (This.Void_Ptr));
    end Current_File;


    procedure Load
           (This : in out Help_View;
            Name : in     String)
    is
        Code : Interfaces.C.int := fl_help_view_load (This.Void_Ptr, Interfaces.C.To_C (Name));
    begin
        if Code = -1 then
            raise Load_Help_Error;
        elsif Code /= 0 then
            raise Internal_FLTK_Error;
        end if;
    end Load;


    function Document_Title
           (This : in Help_View)
        return String
    is
        Raw_Chars : Interfaces.C.Strings.chars_ptr := fl_help_view_title (This.Void_Ptr);
        use type Interfaces.C.Strings.chars_ptr;
    begin
        if Raw_Chars = Interfaces.C.Strings.Null_Ptr then
            return "";
        else
            return Interfaces.C.Strings.Value (Raw_Chars);
        end if;
    end Document_Title;


    function Get_Content
           (This : in Help_View)
        return String
    is
        Raw_Chars : Interfaces.C.Strings.chars_ptr := fl_help_view_get_value (This.Void_Ptr);
        use type Interfaces.C.Strings.chars_ptr;
    begin
        if Raw_Chars = Interfaces.C.Strings.Null_Ptr then
            return "";
        else
            return Interfaces.C.Strings.Value (Raw_Chars);
        end if;
    end Get_Content;


    procedure Set_Content
           (This  : in out Help_View;
            Value : in     String) is
    begin
        fl_help_view_set_value (This.Void_Ptr, Interfaces.C.To_C (Value));
    end Set_Content;


    procedure Set_Link_Callback
           (This : in out Help_View;
            Func : in     Link_Callback) is
    begin
        This.Zelda := Func;
    end Set_Link_Callback;




    function Get_Scrollbar_Size
           (This : in Help_View)
        return Natural is
    begin
        return Natural (fl_help_view_get_scrollbar_size (This.Void_Ptr));
    end Get_Scrollbar_Size;


    procedure Set_Scrollbar_Size
           (This  : in out Help_View;
            Value : in     Natural) is
    begin
        fl_help_view_set_scrollbar_size (This.Void_Ptr, Interfaces.C.int (Value));
    end Set_Scrollbar_Size;


    function Get_Size
           (This : in Help_View)
        return Integer is
    begin
        return Integer (fl_help_view_get_size (This.Void_Ptr));
    end Get_Size;


    procedure Resize
           (This : in out Help_View;
            W, H : in     Integer) is
    begin
        fl_help_view_set_size
           (This.Void_Ptr,
            Interfaces.C.int (W),
            Interfaces.C.int (H));
    end Resize;


    function Get_Text_Color
           (This : in Help_View)
        return Color is
    begin
        return Color (fl_help_view_get_textcolor (This.Void_Ptr));
    end Get_Text_Color;


    procedure Set_Text_Color
           (This  : in out Help_View;
            Value : in     Color) is
    begin
        fl_help_view_set_textcolor (This.Void_Ptr, Interfaces.C.unsigned (Value));
    end Set_Text_Color;


    function Get_Text_Font
           (This : in Help_View)
        return Font_Kind is
    begin
        return Font_Kind'Val (fl_help_view_get_textfont (This.Void_Ptr));
    end Get_Text_Font;


    procedure Set_Text_Font
           (This : in out Help_View;
            Font : in     Font_Kind) is
    begin
        fl_help_view_set_textfont (This.Void_Ptr, Font_Kind'Pos (Font));
    end Set_Text_Font;


    function Get_Text_Size
           (This : in Help_View)
        return Font_Size is
    begin
        return Font_Size (fl_help_view_get_textsize (This.Void_Ptr));
    end Get_Text_Size;


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




    procedure Draw
           (This : in out Help_View) is
    begin
        fl_help_view_draw (This.Void_Ptr);
    end Draw;


    function Handle
           (This  : in out Help_View;
            Event : in     Event_Kind)
        return Event_Outcome is
    begin
        return Event_Outcome'Val
           (fl_help_view_handle (This.Void_Ptr, Event_Kind'Pos (Event)));
    end Handle;


end FLTK.Widgets.Groups.Help_Views;