summaryrefslogtreecommitdiff
path: root/src/fltk.ads
blob: 81a37634aedb4dd129656179a056b9ef9c7dbc33 (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


with

    Ada.Finalization;

private with

    Interfaces.C,
    System;


package FLTK is


    function Run return Integer;


    --  ugly implementation detail, never use this
    --  just ignore the hand moving behind the curtain
    --  (this is necessary so things like text_buffers and
    --  widgets can talk to each other behind the binding)
    type Wrapper is abstract new Ada.Finalization.Limited_Controlled with private;


    type Color is new Natural;
    type Color_Component is mod 256;
    No_Color : constant Color;


    type Alignment is private;
    Align_Center : constant Alignment;
    Align_Top    : constant Alignment;
    Align_Bottom : constant Alignment;
    Align_Left   : constant Alignment;
    Align_Right  : constant Alignment;


    type Keypress is private;
    subtype Pressable_Key is Character range Character'Val (32) .. Character'Val (126);
    function Press (Key : in Pressable_Key) return Keypress;
    Enter_Key        : constant Keypress;
    Keypad_Enter_Key : constant Keypress;
    Backspace_Key    : constant Keypress;
    Insert_Key       : constant Keypress;
    Delete_Key       : constant Keypress;
    Home_Key         : constant Keypress;
    End_Key          : constant Keypress;
    Page_Down_Key    : constant Keypress;
    Page_Up_Key      : constant Keypress;
    Down_Key         : constant Keypress;
    Left_Key         : constant Keypress;
    Right_Key        : constant Keypress;
    Up_Key           : constant Keypress;
    Escape_Key       : constant Keypress;


    type Mouse_Button is (No_Button, Left_Button, Middle_Button, Right_Button);


    type Key_Combo is private;
    function Press (Key : in Pressable_Key) return Key_Combo;
    function Press (Key : in Keypress) return Key_Combo;
    function Press (Key : in Mouse_Button) return Key_Combo;
    No_Key : constant Key_Combo;


    type Modifier is private;
    function "+" (Left, Right : in Modifier) return Modifier;
    function "+" (Left : in Modifier; Right : in Pressable_Key) return Key_Combo;
    function "+" (Left : in Modifier; Right : in Keypress) return Key_Combo;
    function "+" (Left : in Modifier; Right : in Mouse_Button) return Key_Combo;
    function "+" (Left : in Modifier; Right : in Key_Combo) return Key_Combo;
    Mod_None  : constant Modifier;
    Mod_Shift : constant Modifier;
    Mod_Ctrl  : constant Modifier;
    Mod_Alt   : constant Modifier;


    type Box_Kind is
           (No_Box,
            Flat_Box,
            Up_Box,
            Down_Box,
            Up_Frame,
            Down_Frame,
            Thin_Up_Box,
            Thin_Down_Box,
            Thin_Up_Frame,
            Thin_Down_Frame,
            Engraved_Box,
            Embossed_Box,
            Engraved_Frame,
            Embossed_Frame,
            Border_Box,
            Shadow_Box,
            Border_Frame,
            Shadow_Frame,
            Rounded_Box,
            RShadow_Box,
            Rounded_Frame,
            RFlat_Box,
            Round_Up_Box,
            Round_Down_Box,
            Diamond_Up_Box,
            Diamond_Down_Box,
            Oval_Box,
            OShadow_Box,
            Oval_Frame,
            OFlat_Box,
            Plastic_Up_Box,
            Plastic_Down_Box,
            Plastic_Up_Frame,
            Plastic_Down_Frame,
            Plastic_Thin_Up_Box,
            Plastic_Thin_Down_Box,
            Plastic_Round_Up_Box,
            Plastic_Round_Down_Box,
            Gtk_Up_Box,
            Gtk_Down_Box,
            Gtk_Up_Frame,
            Gtk_Down_Frame,
            Gtk_Thin_Up_Box,
            Gtk_Thin_Down_Box,
            Gtk_Thin_Up_Frame,
            Gtk_Thin_Down_Frame,
            Gtk_Round_Up_Box,
            Gtk_Round_Down_Box,
            Gleam_Up_Box,
            Gleam_Down_Box,
            Gleam_Up_Frame,
            Gleam_Down_Frame,
            Gleam_Thin_Up_Box,
            Gleam_Thin_Down_Box,
            Gleam_Round_Up_Box,
            Gleam_Round_Down_Box,
            Free_Box);


    type Font_Kind is
           (Helvetica,
            Helvetica_Bold,
            Helvetica_Italic,
            Helvetica_Bold_Italic,
            Courier,
            Courier_Bold,
            Courier_Italic,
            Courier_Bold_Italic,
            Times,
            Times_Bold,
            Times_Italic,
            Times_Bold_Italic,
            Symbol,
            Monospace,
            Monospace_Bold,
            Zapf_Dingbats,
            Free_Font);


    type Font_Size is new Natural;
    Normal_Size : constant Font_Size := 14;


    type Label_Kind is
           (Normal_Label,
            No_Label,
            Shadow_Label,
            Engraved_Label,
            Embossed_Label,
            Multi_Label,
            Icon_Label,
            Image_Label,
            Free_Label);


    type Event_Kind is
           (No_Event,
            Push,
            Release,
            Enter,
            Leave,
            Drag,
            Focus,
            Unfocus,
            Keydown,
            Keyup,
            Close,
            Move,
            Shortcut,
            Deactivate,
            Activate,
            Hide,
            Show,
            Paste,
            Selection_Clear,
            Mouse_Wheel,
            DnD_Enter,
            DnD_Drag,
            DnD_Leave,
            DnD_Release,
            Screen_Config_Changed,
            Fullscreen);


    type Event_Outcome is (Not_Handled, Handled);


    type Menu_Flag is private;
    function "+" (Left, Right : in Menu_Flag) return Menu_Flag;
    Flag_Normal    : constant Menu_Flag;
    Flag_Inactive  : constant Menu_Flag;
    Flag_Toggle    : constant Menu_Flag;
    Flag_Value     : constant Menu_Flag;
    Flag_Radio     : constant Menu_Flag;
    Flag_Invisible : constant Menu_Flag;
    Flag_Submenu   : constant Menu_Flag;
    Flag_Divider   : constant Menu_Flag;


private


    function Has_Valid_Ptr
           (This : in Wrapper)
        return Boolean;

    type Wrapper is abstract new Ada.Finalization.Limited_Controlled with
        record
            Void_Ptr      : System.Address;
            Needs_Dealloc : Boolean := True;
        end record;
        --  with Type_Invariant => Has_Valid_Ptr (Wrapper);

    --  unsure if the above invariant is doing what I'm after
    --  oh well, something to work on

    overriding procedure Initialize
           (This : in out Wrapper);


    No_Color : constant Color := 0;


    type Alignment is new Interfaces.Unsigned_16;
    Align_Center : constant Alignment := 0;
    Align_Top    : constant Alignment := 1;
    Align_Bottom : constant Alignment := 2;
    Align_Left   : constant Alignment := 4;
    Align_Right  : constant Alignment := 8;


    type Keypress is new Interfaces.Unsigned_16;
    type Modifier is new Interfaces.Unsigned_16;
    type Key_Combo is
        record
            Modcode   : Modifier;
            Keycode   : Keypress;
            Mousecode : Mouse_Button;
        end record;


    function To_C
           (Key : in Key_Combo)
        return Interfaces.C.unsigned_long;

    function To_Ada
           (Key : in Interfaces.C.unsigned_long)
        return Key_Combo;

    function To_C
           (Key : in Keypress)
        return Interfaces.C.unsigned_long;

    function To_Ada
           (Key : in Interfaces.C.unsigned_long)
        return Keypress;

    function To_C
           (Modi : in Modifier)
        return Interfaces.C.unsigned_long;

    function To_Ada
           (Modi : in Interfaces.C.unsigned_long)
        return Modifier;

    function To_C
           (Button : in Mouse_Button)
        return Interfaces.C.unsigned_long;

    function To_Ada
           (Button : in Interfaces.C.unsigned_long)
        return Mouse_Button;


    --  these values designed to align with FLTK enumeration types
    Mod_None  : constant Modifier := 2#00000000#;
    Mod_Shift : constant Modifier := 2#00000001#;
    Mod_Ctrl  : constant Modifier := 2#00000100#;
    Mod_Alt   : constant Modifier := 2#00001000#;


    No_Key : constant Key_Combo := (Modcode => Mod_None, Keycode => 0, Mousecode => No_Button);


    --  these values correspond to constants defined in FLTK Enumerations.H
    Enter_Key        : constant Keypress := 16#ff0d#;
    Keypad_Enter_Key : constant Keypress := 16#ff8d#;
    Backspace_Key    : constant Keypress := 16#ff08#;
    Insert_Key       : constant Keypress := 16#ff63#;
    Delete_Key       : constant Keypress := 16#ffff#;
    Home_Key         : constant Keypress := 16#ff50#;
    End_Key          : constant Keypress := 16#ff57#;
    Page_Down_Key    : constant Keypress := 16#ff56#;
    Page_Up_Key      : constant Keypress := 16#ff55#;
    Down_Key         : constant Keypress := 16#ff54#;
    Left_Key         : constant Keypress := 16#ff51#;
    Right_Key        : constant Keypress := 16#ff53#;
    Up_Key           : constant Keypress := 16#ff52#;
    Escape_Key       : constant Keypress := 16#ff1b#;


    type Menu_Flag is new Interfaces.Unsigned_8;
    Flag_Normal    : constant Menu_Flag := 2#00000000#;
    Flag_Inactive  : constant Menu_Flag := 2#00000001#;
    Flag_Toggle    : constant Menu_Flag := 2#00000010#;
    Flag_Value     : constant Menu_Flag := 2#00000100#;
    Flag_Radio     : constant Menu_Flag := 2#00001000#;
    Flag_Invisible : constant Menu_Flag := 2#00010000#;
    --  Flag_Submenu_Pointer unlikely to be used
    Flag_Submenu   : constant Menu_Flag := 2#01000000#;
    Flag_Divider   : constant Menu_Flag := 2#10000000#;


end FLTK;