summaryrefslogtreecommitdiff
path: root/src/fltk-widgets-groups-text_displays-text_editors.ads
blob: b21cc3b6a337b8f83307c2fded14760aa1ea2b9c (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


private with

    Interfaces.C,
    Ada.Containers.Vectors;


package FLTK.Widgets.Groups.Text_Displays.Text_Editors is


    type Text_Editor is new Text_Display with private;

    type Insert_Mode is (Before, After);
    --  type Tab_Navigation is (Insert_Char, Widget_Focus);

    type Key_Func is access procedure
           (This : in out Text_Editor'Class);

    type Default_Key_Func is access procedure
           (This : in out Text_Editor'Class;
            Key  : in     Shortcut_Key);

    type Key_Binding is record
        Key  : Shortcut_Key;
        Func : Key_Func;
    end record;

    type Key_Binding_List is array (Positive range <>) of Key_Binding;




    function Create
           (X, Y, W, H : in Integer;
            Text       : in String)
        return Text_Editor;




    procedure Default
           (This : in out Text_Editor'Class;
            Key  : in     Shortcut_Key);




    procedure Undo
           (This : in out Text_Editor'Class);

    procedure Cut
           (This : in out Text_Editor'Class);

    procedure Copy
           (This : in out Text_Editor'Class);

    procedure Paste
           (This : in out Text_Editor'Class);

    procedure Delete
           (This : in out Text_Editor'Class);

    procedure Select_All
           (This : in out Text_Editor'Class);




    procedure KF_Backspace
           (This : in out Text_Editor'Class);

    procedure KF_Insert
           (This : in out Text_Editor'Class);

    procedure KF_Enter
           (This : in out Text_Editor'Class);

    procedure KF_Ignore
           (This : in out Text_Editor'Class);




    procedure KF_Home
           (This : in out Text_Editor'Class);

    procedure KF_End
           (This : in out Text_Editor'Class);

    procedure KF_Page_Down
           (This : in out Text_Editor'Class);

    procedure KF_Page_Up
           (This : in out Text_Editor'Class);

    procedure KF_Down
           (This : in out Text_Editor'Class);

    procedure KF_Left
           (This : in out Text_Editor'Class);

    procedure KF_Right
           (This : in out Text_Editor'Class);

    procedure KF_Up
           (This : in out Text_Editor'Class);




    procedure KF_Shift_Home
           (This : in out Text_Editor'Class);

    procedure KF_Shift_End
           (This : in out Text_Editor'Class);

    procedure KF_Shift_Page_Down
           (This : in out Text_Editor'Class);

    procedure KF_Shift_Page_Up
           (This : in out Text_Editor'Class);

    procedure KF_Shift_Down
           (This : in out Text_Editor'Class);

    procedure KF_Shift_Left
           (This : in out Text_Editor'Class);

    procedure KF_Shift_Right
           (This : in out Text_Editor'Class);

    procedure KF_Shift_Up
           (This : in out Text_Editor'Class);




    procedure KF_Ctrl_Home
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_End
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Page_Down
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Page_Up
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Down
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Left
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Right
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Up
           (This : in out Text_Editor'Class);




    procedure KF_Ctrl_Shift_Home
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Shift_End
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Shift_Page_Down
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Shift_Page_Up
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Shift_Down
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Shift_Left
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Shift_Right
           (This : in out Text_Editor'Class);

    procedure KF_Ctrl_Shift_Up
           (This : in out Text_Editor'Class);




    Default_Key_Bindings : constant Key_Binding_List :=
           ((Enter_Key,        KF_Enter'Access),
            (Keypad_Enter_Key, KF_Enter'Access),
            (Backspace_Key,    KF_Backspace'Access),
            (Insert_Key,       KF_Insert'Access),

            (Delete_Key,     Delete'Access),
            (Mod_Ctrl + 'c', Copy'Access),
            (Mod_Ctrl + 'v', Paste'Access),
            (Mod_Ctrl + 'x', Cut'Access),
            (Mod_Ctrl + 'z', Undo'Access),
            (Mod_Ctrl + 'a', Select_All'Access),

            (Home_Key,      KF_Home'Access),
            (End_Key,       KF_End'Access),
            (Page_Down_Key, KF_Page_Down'Access),
            (Page_Up_Key,   KF_Page_Up'Access),
            (Down_Key,      KF_Down'Access),
            (Left_Key,      KF_Left'Access),
            (Right_Key,     KF_Right'Access),
            (Up_Key,        KF_Up'Access),

            (Mod_Shift + Home_Key,      KF_Shift_Home'Access),
            (Mod_Shift + End_Key,       KF_Shift_End'Access),
            (Mod_Shift + Page_Down_Key, KF_Shift_Page_Down'Access),
            (Mod_Shift + Page_Up_Key,   KF_Shift_Page_Up'Access),
            (Mod_Shift + Down_Key,      KF_Shift_Down'Access),
            (Mod_Shift + Left_Key,      KF_Shift_Left'Access),
            (Mod_Shift + Right_Key,     KF_Shift_Right'Access),
            (Mod_Shift + Up_Key,        KF_Shift_Up'Access),

            (Mod_Ctrl + Home_Key,      KF_Ctrl_Home'Access),
            (Mod_Ctrl + End_Key,       KF_Ctrl_End'Access),
            (Mod_Ctrl + Page_Down_Key, KF_Ctrl_Page_Down'Access),
            (Mod_Ctrl + Page_Up_Key,   KF_Ctrl_Page_Up'Access),
            (Mod_Ctrl + Down_Key,      KF_Ctrl_Down'Access),
            (Mod_Ctrl + Left_Key,      KF_Ctrl_Left'Access),
            (Mod_Ctrl + Right_Key,     KF_Ctrl_Right'Access),
            (Mod_Ctrl + Up_Key,        KF_Ctrl_Up'Access),

            (Mod_Ctrl + Mod_Shift + Home_Key,      KF_Ctrl_Shift_Home'Access),
            (Mod_Ctrl + Mod_Shift + End_Key,       KF_Ctrl_Shift_End'Access),
            (Mod_Ctrl + Mod_Shift + Page_Down_Key, KF_Ctrl_Shift_Page_Down'Access),
            (Mod_Ctrl + Mod_Shift + Page_Up_Key,   KF_Ctrl_Shift_Page_Up'Access),
            (Mod_Ctrl + Mod_Shift + Down_Key,      KF_Ctrl_Shift_Down'Access),
            (Mod_Ctrl + Mod_Shift + Left_Key,      KF_Ctrl_Shift_Left'Access),
            (Mod_Ctrl + Mod_Shift + Right_Key,     KF_Ctrl_Shift_Right'Access),
            (Mod_Ctrl + Mod_Shift + Up_Key,        KF_Ctrl_Shift_Up'Access));




    --  NOTE NOTE NOTE NOTE NOTE
    --
    --  Changing the keybindings for Shortcut_Keys that include modifiers
    --  currently does not work due to some bugbear in the FLTK side of things.
    --
    --  Until that's fixed, the default keybindings for those key combinations
    --  that include modifiers have been left in place.
    --
    --  NOTE NOTE NOTE NOTE NOTE




    procedure Add_Key_Binding
           (This : in out Text_Editor;
            Key  : in     Shortcut_Key;
            Func : in     Key_Func);

    procedure Add_Key_Binding
           (This : in out Text_Editor;
            Bind : in     Key_Binding);

    function Get_Bound_Key_Function
           (This : in Text_Editor;
            Key  : in Shortcut_Key)
        return Key_Func;

    procedure Remove_Key_Binding
           (This : in out Text_Editor;
            Key  : in     Shortcut_Key);

    procedure Remove_Key_Binding
           (This : in out Text_Editor;
            Bind : in     Key_Binding);

    procedure Remove_All_Key_Bindings
           (This : in out Text_Editor);

    function Get_Default_Key_Function
           (This : in Text_Editor)
        return Default_Key_Func;

    procedure Set_Default_Key_Function
           (This : in out Text_Editor;
            Func : in     Default_Key_Func);




    function Get_Insert_Mode
           (This : in Text_Editor)
        return Insert_Mode;

    procedure Set_Insert_Mode
           (This : in out Text_Editor;
            To   : in     Insert_Mode);




    --  function Get_Tab_Nav_Mode
    --         (This : in Text_Editor)
    --      return Tab_Navigation;

    --  procedure Set_Tab_Nav_Mode
    --         (This : in out Text_Editor;
    --          To   : in     Tab_Navigation);




    procedure Draw
           (This : in out Text_Editor);

    function Handle
           (This  : in out Text_Editor;
            Event : in     Event_Kind)
        return Event_Outcome;


private


    package Binding_Vectors is new Ada.Containers.Vectors
           (Index_Type => Positive, Element_Type => Key_Binding);




    type Text_Editor is new Text_Display with
        record
            Bindings     : Binding_Vectors.Vector;
            Default_Func : Default_Key_Func;
        end record;

    overriding procedure Finalize
           (This : in out Text_Editor);




    function Key_Func_Hook
           (K : in Interfaces.C.int;
            E : in System.Address)
        return Interfaces.C.int;
    pragma Convention (C, Key_Func_Hook);




    package Editor_Convert is new System.Address_To_Access_Conversions (Text_Editor'Class);


end FLTK.Widgets.Groups.Text_Displays.Text_Editors;