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


with

    Interfaces.C.Strings,
    System.Address_To_Access_Conversions,
    FLTK.Widgets.Groups,
    FLTK.Images;

use type

    Interfaces.C.int,
    Interfaces.C.unsigned,
    System.Address;


package body FLTK.Widgets is


    package Group_Convert is new
        System.Address_To_Access_Conversions (FLTK.Widgets.Groups.Group'Class);




    procedure widget_set_draw_hook
           (W, D : in System.Address);
    pragma Import (C, widget_set_draw_hook, "widget_set_draw_hook");

    procedure widget_set_handle_hook
           (W, H : in System.Address);
    pragma Import (C, widget_set_handle_hook, "widget_set_handle_hook");




    function new_fl_widget
           (X, Y, W, H : in Interfaces.C.int;
            Text       : in Interfaces.C.char_array)
        return System.Address;
    pragma Import (C, new_fl_widget, "new_fl_widget");

    procedure free_fl_widget
           (F : in System.Address);
    pragma Import (C, free_fl_widget, "free_fl_widget");




    procedure fl_widget_activate
           (W : in System.Address);
    pragma Import (C, fl_widget_activate, "fl_widget_activate");

    procedure fl_widget_deactivate
           (W : in System.Address);
    pragma Import (C, fl_widget_deactivate, "fl_widget_deactivate");

    function fl_widget_active
           (W : in System.Address)
        return Interfaces.C.int;
    pragma Import (C, fl_widget_active, "fl_widget_active");

    function fl_widget_active_r
           (W : in System.Address)
        return Interfaces.C.int;
    pragma Import (C, fl_widget_active_r, "fl_widget_active_r");

    procedure fl_widget_clear_active
           (W : in System.Address);
    pragma Import (C, fl_widget_clear_active, "fl_widget_clear_active");




    function fl_widget_changed
           (W : in System.Address)
        return Interfaces.C.unsigned;
    pragma Import (C, fl_widget_changed, "fl_widget_changed");

    procedure fl_widget_clear_changed
           (W : in System.Address);
    pragma Import (C, fl_widget_clear_changed, "fl_widget_clear_changed");




    function fl_widget_get_parent
           (W : in System.Address)
        return System.Address;
    pragma Import (C, fl_widget_get_parent, "fl_widget_get_parent");

    function fl_widget_contains
           (W, I : in System.Address)
        return Interfaces.C.int;
    pragma Import (C, fl_widget_contains, "fl_widget_contains");




    function fl_widget_get_align
           (W : in System.Address)
        return Interfaces.C.unsigned;
    pragma Import (C, fl_widget_get_align, "fl_widget_get_align");

    procedure fl_widget_set_align
           (W : in System.Address;
            A : in Interfaces.C.unsigned);
    pragma Import (C, fl_widget_set_align, "fl_widget_set_align");

    function fl_widget_get_box
           (W : in System.Address)
        return Interfaces.C.int;
    pragma Import (C, fl_widget_get_box, "fl_widget_get_box");

    procedure fl_widget_set_box
           (W : in System.Address;
            B : in Interfaces.C.int);
    pragma Import (C, fl_widget_set_box, "fl_widget_set_box");

    function fl_widget_get_label
           (W : in System.Address)
        return Interfaces.C.Strings.chars_ptr;
    pragma Import (C, fl_widget_get_label, "fl_widget_get_label");

    procedure fl_widget_set_label
           (W : in System.Address;
            T : in Interfaces.C.char_array);
    pragma Import (C, fl_widget_set_label, "fl_widget_set_label");

    function fl_widget_get_label_font
           (W : in System.Address)
        return Interfaces.C.int;
    pragma Import (C, fl_widget_get_label_font, "fl_widget_get_label_font");

    procedure fl_widget_set_label_font
           (W : in System.Address;
            F : in Interfaces.C.int);
    pragma Import (C, fl_widget_set_label_font, "fl_widget_set_label_font");

    function fl_widget_get_label_size
           (W : in System.Address)
        return Interfaces.C.int;
    pragma Import (C, fl_widget_get_label_size, "fl_widget_get_label_size");

    procedure fl_widget_set_label_size
           (W : in System.Address;
            S : in Interfaces.C.int);
    pragma Import (C, fl_widget_set_label_size, "fl_widget_set_label_size");

    function fl_widget_get_label_type
           (W : in System.Address)
        return Interfaces.C.int;
    pragma Import (C, fl_widget_get_label_type, "fl_widget_get_label_type");

    procedure fl_widget_set_label_type
           (W : in System.Address;
            L : in Interfaces.C.int);
    pragma Import (C, fl_widget_set_label_type, "fl_widget_set_label_type");

    procedure fl_widget_set_callback
           (W, C : in System.Address);
    pragma Import (C, fl_widget_set_callback, "fl_widget_set_callback");




    function fl_widget_get_x
           (W : in System.Address)
        return Interfaces.C.int;
    pragma Import (C, fl_widget_get_x, "fl_widget_get_x");

    function fl_widget_get_y
           (W : in System.Address)
        return Interfaces.C.int;
    pragma Import (C, fl_widget_get_y, "fl_widget_get_y");

    function fl_widget_get_w
           (W : in System.Address)
        return Interfaces.C.int;
    pragma Import (C, fl_widget_get_w, "fl_widget_get_w");

    function fl_widget_get_h
           (W : in System.Address)
        return Interfaces.C.int;
    pragma Import (C, fl_widget_get_h, "fl_widget_get_h");

    procedure fl_widget_size
           (W    : in System.Address;
            D, H : in Interfaces.C.int);
    pragma Import (C, fl_widget_size, "fl_widget_size");

    procedure fl_widget_position
           (W    : in System.Address;
            X, Y : in Interfaces.C.int);
    pragma Import (C, fl_widget_position, "fl_widget_position");




    procedure fl_widget_set_image
           (W, I : in System.Address);
    pragma Import (C, fl_widget_set_image, "fl_widget_set_image");




    procedure fl_widget_redraw
           (W : in System.Address);
    pragma Import (C, fl_widget_redraw, "fl_widget_redraw");

    procedure fl_widget_redraw_label
           (W : in System.Address);
    pragma Import (C, fl_widget_redraw_label, "fl_widget_redraw_label");




    procedure Callback_Hook
           (W, U : in System.Address)
    is
        Ada_Widget : access Widget'Class :=
            Widget_Convert.To_Pointer (U);
    begin
        Ada_Widget.Callback.all (Ada_Widget.all);
    end Callback_Hook;


    procedure Draw_Hook
           (U : in System.Address)
    is
        Ada_Widget : access Widget'Class :=
            Widget_Convert.To_Pointer (U);
    begin
        Ada_Widget.Draw;
    end Draw_Hook;


    function Handle_Hook
           (U : in System.Address;
            E : in Interfaces.C.int)
        return Interfaces.C.int
    is
        Ada_Widget : access Widget'Class :=
            Widget_Convert.To_Pointer (U);
    begin
        return Event_Outcome'Pos (Ada_Widget.Handle (Event_Kind'Val (E)));
    end Handle_Hook;




    procedure Finalize
           (This : in out Widget) is
    begin
        if  This.Void_Ptr /= System.Null_Address and then
            This in Widget'Class
        then
            free_fl_widget (This.Void_Ptr);
            This.Void_Ptr := System.Null_Address;
        end if;
    end Finalize;




    function Create
           (X, Y, W, H : in Integer;
            Text       : in String)
        return Widget is
    begin
        return This : Widget do
            This.Void_Ptr := new_fl_widget
                   (Interfaces.C.int (X),
                    Interfaces.C.int (Y),
                    Interfaces.C.int (W),
                    Interfaces.C.int (H),
                    Interfaces.C.To_C (Text));
            fl_widget_set_user_data
                   (This.Void_Ptr,
                    Widget_Convert.To_Address (This'Unchecked_Access));
            widget_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
            widget_set_handle_hook (This.Void_Ptr, Handle_Hook'Address);
        end return;
    end Create;




    procedure Activate
           (This : in out Widget) is
    begin
        fl_widget_activate (This.Void_Ptr);
    end Activate;


    procedure Deactivate
           (This : in out Widget) is
    begin
        fl_widget_deactivate (This.Void_Ptr);
    end Deactivate;


    function Is_Active
           (This : in Widget)
        return Boolean is
    begin
        return fl_widget_active (This.Void_Ptr) /= 0;
    end Is_Active;


    function Is_Tree_Active
           (This : in Widget)
        return Boolean is
    begin
        return fl_widget_active_r (This.Void_Ptr) /= 0;
    end Is_Tree_Active;


    procedure Clear_Active
           (This : in out Widget) is
    begin
        fl_widget_clear_active (This.Void_Ptr);
    end Clear_Active;




    function Has_Changed
           (This : in Widget)
        return Boolean is
    begin
        return fl_widget_changed (This.Void_Ptr) /= 0;
    end Has_Changed;


    procedure Clear_Changed
           (This : in out Widget) is
    begin
        fl_widget_clear_changed (This.Void_Ptr);
    end Clear_Changed;




    function Parent
           (This : in Widget)
        return access FLTK.Widgets.Groups.Group'Class
    is
        Parent_Ptr : System.Address;
        Actual_Parent : access FLTK.Widgets.Groups.Group'Class;
    begin
        Parent_Ptr := fl_widget_get_parent (This.Void_Ptr);
        if Parent_Ptr /= System.Null_Address then
            Actual_Parent := Group_Convert.To_Pointer (fl_widget_get_user_data (Parent_Ptr));
        end if;
        return Actual_Parent;
    end Parent;


    function Contains
           (This : in Widget;
            Item : in Widget'Class)
        return Boolean is
    begin
        return fl_widget_contains (This.Void_Ptr, Item.Void_Ptr) /= 0;
    end Contains;




    function Get_Alignment
           (This : in Widget)
        return Alignment is
    begin
        return Alignment (fl_widget_get_align (This.Void_Ptr));
    end Get_Alignment;


    procedure Set_Alignment
           (This      : in out Widget;
            New_Align : in     Alignment) is
    begin
        fl_widget_set_align (This.Void_Ptr, Interfaces.C.unsigned (New_Align));
    end Set_Alignment;


    function Get_Box
           (This : in Widget)
        return Box_Kind is
    begin
        return Box_Kind'Val (fl_widget_get_box (This.Void_Ptr));
    end Get_Box;


    procedure Set_Box
           (This : in out Widget;
            Box  : in     Box_Kind) is
    begin
        fl_widget_set_box (This.Void_Ptr, Box_Kind'Pos (Box));
    end Set_Box;


    function Get_Label
           (This : in out Widget)
        return String is
    begin
        return Interfaces.C.Strings.Value (fl_widget_get_label (This.Void_Ptr));
    end Get_Label;


    procedure Set_Label
           (This : in out Widget;
            Text : in     String) is
    begin
        fl_widget_set_label (This.Void_Ptr, Interfaces.C.To_C (Text));
    end Set_Label;


    function Get_Label_Font
           (This : in Widget)
        return Font_Kind is
    begin
        return Font_Kind'Val (fl_widget_get_label_font (This.Void_Ptr));
    end Get_Label_Font;


    procedure Set_Label_Font
           (This : in out Widget;
            Font : in     Font_Kind) is
    begin
        fl_widget_set_label_font (This.Void_Ptr, Font_Kind'Pos (Font));
    end Set_Label_Font;


    function Get_Label_Size
           (This : in Widget)
        return Font_Size is
    begin
        return Font_Size (fl_widget_get_label_size (This.Void_Ptr));
    end Get_Label_Size;


    procedure Set_Label_Size
           (This : in out Widget;
            Size : in     Font_Size) is
    begin
        fl_widget_set_label_size (This.Void_Ptr, Interfaces.C.int (Size));
    end Set_Label_Size;


    function Get_Label_Type
           (This : in Widget)
        return Label_Kind is
    begin
        return Label_Kind'Val (fl_widget_get_label_type (This.Void_Ptr));
    end Get_Label_Type;


    procedure Set_Label_Type
           (This  : in out Widget;
            Label : in     Label_Kind) is
    begin
        fl_widget_set_label_type (This.Void_Ptr, Label_Kind'Pos (Label));
    end Set_Label_Type;


    function Get_Callback
           (This : in Widget)
        return Widget_Callback is
    begin
        return This.Callback;
    end Get_Callback;


    procedure Set_Callback
           (This : in out Widget;
            Func : in     Widget_Callback) is
    begin
        if Func /= null then
            This.Callback := Func;
            fl_widget_set_callback (This.Void_Ptr, Callback_Hook'Address);
        end if;
    end Set_Callback;




    function Get_X
           (This : in Widget)
        return Integer is
    begin
        return Integer (fl_widget_get_x (This.Void_Ptr));
    end Get_X;


    function Get_Y
           (This : in Widget)
        return Integer is
    begin
        return Integer (fl_widget_get_y (This.Void_Ptr));
    end Get_Y;


    function Get_W
           (This : in Widget)
        return Integer is
    begin
        return Integer (fl_widget_get_w (This.Void_Ptr));
    end Get_W;


    function Get_H
           (This : in Widget)
        return Integer is
    begin
        return Integer (fl_widget_get_h (This.Void_Ptr));
    end Get_H;


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


    procedure Reposition
           (This : in out Widget;
            X, Y : in     Integer) is
    begin
        fl_widget_position
               (This.Void_Ptr,
                Interfaces.C.int (X),
                Interfaces.C.int (Y));
    end Reposition;




    function Get_Image
           (This : in Widget)
        return access FLTK.Images.Image'Class is
    begin
        return This.Current_Image;
    end Get_Image;


    procedure Set_Image
           (This : in out Widget;
            Pic  : in out FLTK.Images.Image'Class) is
    begin
        This.Current_Image := Pic'Unchecked_Access;
        fl_widget_set_image
               (This.Void_Ptr,
                Wrapper (Pic).Void_Ptr);
    end Set_Image;




    procedure Redraw
           (This : in out Widget) is
    begin
        fl_widget_redraw (This.Void_Ptr);
    end Redraw;


    procedure Redraw_Label
           (This : in out Widget) is
    begin
        fl_widget_redraw_label (This.Void_Ptr);
    end Redraw_Label;


    function Handle
           (This  : in out Widget;
            Event : in     Event_Kind)
        return Event_Outcome is
    begin
        return Not_Handled;
    end Handle;


end FLTK.Widgets;