summaryrefslogtreecommitdiff
path: root/src/adapad.adb
blob: f1425f90deb31d0bda893987019b82182cca0da0 (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


with FLTK;
with Editors;
use Editors;
with FLTK.Text_Buffers;
use FLTK.Text_Buffers;
with FLTK.Widgets;
use FLTK.Widgets;
with FLTK.Widgets.Menus;
use FLTK.Widgets.Menus;


with Ada.Text_IO;


function AdaPad return Integer is


    Pad : aliased Editor_Window := Create (0, 0, 640, 400, "AdaPad");
    Buff : aliased Text_Buffer := Create;




    type Editor_Callback is abstract new Widget_Callback with
        record
            Editor : access Editor_Window := Pad'Access;
            Buffer : access Text_Buffer := Buff'Access;
        end record;




    type New_Callback is new Editor_Callback with null record;
    New_CB : aliased New_Callback;


    overriding procedure Call
           (This : in     New_Callback;
            Item : in out Widget'Class) is
    begin
        Ada.Text_IO.Put_Line ("New callback executed.");
    end Call;




    type Open_Callback is new Editor_Callback with null record;
    Open_CB : aliased Open_Callback;


    overriding procedure Call
           (This : in     Open_Callback;
            Item : in out Widget'Class) is
    begin
        Ada.Text_IO.Put_Line ("Open callback executed.");
    end Call;




    type Save_Callback is new Editor_Callback with null record;
    Save_CB : aliased Save_Callback;


    overriding procedure Call
           (This : in     Save_Callback;
            Item : in out Widget'Class) is
    begin
        Ada.Text_IO.Put_Line ("Save callback executed.");
    end Call;




    type Save_As_Callback is new Editor_Callback with null record;
    Save_As_CB : aliased Save_As_Callback;


    overriding procedure Call
           (This : in     Save_As_Callback;
            Item : in out Widget'Class) is
    begin
        Ada.Text_IO.Put_Line ("Save As callback executed.");
    end Call;




    type Quit_Callback is new Editor_Callback with null record;
    Quit_CB : aliased Quit_Callback;


    overriding procedure Call
           (This : in     Quit_Callback;
            Item : in out Widget'Class) is
    begin
        Ada.Text_IO.Put_Line ("Quit callback executed.");
    end Call;




    type Undo_Callback is new Editor_Callback with null record;
    Undo_CB : aliased Undo_Callback;


    overriding procedure Call
           (This : in     Undo_Callback;
            Item : in out Widget'Class) is
    begin
        Ada.Text_IO.Put_Line ("Undo callback executed.");
    end Call;




    type Cut_Callback is new Editor_Callback with null record;
    Cut_CB : aliased Cut_Callback;


    overriding procedure Call
           (This : in     Cut_Callback;
            Item : in out Widget'Class) is
    begin
        This.Editor.Cut;
    end Call;




    type Copy_Callback is new Editor_Callback with null record;
    Copy_CB : aliased Copy_Callback;


    overriding procedure Call
           (This : in     Copy_Callback;
            Item : in out Widget'Class) is
    begin
        This.Editor.Copy;
    end Call;




    type Paste_Callback is new Editor_Callback with null record;
    Paste_CB : aliased Paste_Callback;


    overriding procedure Call
           (This : in     Paste_Callback;
            Item : in out Widget'Class) is
    begin
        This.Editor.Paste;
    end Call;




    type Delete_Callback is new Editor_Callback with null record;
    Delete_CB : aliased Delete_Callback;


    overriding procedure Call
           (This : in     Delete_Callback;
            Item : in out Widget'Class) is
    begin
        This.Editor.Delete;
    end Call;




    type Find_Callback is new Editor_Callback with null record;
    Find_CB : aliased Find_Callback;


    overriding procedure Call
           (This : in     Find_Callback;
            Item : in out Widget'Class) is
    begin
        Ada.Text_IO.Put_Line ("Find callback executed.");
    end Call;




    type Replace_Callback is new Editor_Callback with null record;
    Replace_CB : aliased Replace_Callback;


    overriding procedure Call
           (This : in     Replace_Callback;
            Item : in out Widget'Class) is
    begin
        Ada.Text_IO.Put_Line ("Replace callback executed.");
    end Call;




    type About_Callback is new Editor_Callback with null record;
    About_CB : aliased About_Callback;


    overriding procedure Call
           (This : in     About_Callback;
            Item : in out Widget'Class) is
    begin
        Ada.Text_IO.Put_Line ("About callback executed.");
    end Call;




    type Mod_Callback is new Modify_Callback with null record;
    Mod_CB : aliased Mod_Callback;


    overriding procedure Call
           (This         : in Mod_Callback;
            Action       : in Modification;
            Place        : in Position;
            Length       : in Natural;
            Deleted_Text : in String) is
    begin
        Ada.Text_IO.Put_Line ("Modify of Type: " & Modification'Image (Action) &
                              " Place: " & Position'Image (Place) &
                              " Length: " & Integer'Image (Length));
    end Call;




    type Pre_Callback is new Predelete_Callback with null record;
    Pre_CB : aliased Pre_Callback;


    overriding procedure Call
           (This   : in Pre_Callback;
            Place  : in Position;
            Length : in Natural) is
    begin
        Ada.Text_IO.Put_Line ("Predelete at Place: " & Position'Image (Place) &
                              " Length: " & Integer'Image (Length));
    end Call;


begin


    Buff.Add_Modify_Callback (Mod_CB'Access);
    Buff.Add_Predelete_Callback (Pre_CB'Access);


    declare
        Bar : Menu_Cursor := Pad.Get_Menu;
    begin
        Bar.Add (Text => "&File", Shortcut => Mod_Alt + 'f', Flags => Flag_Submenu);
        Bar.Add ("File/&New",          New_CB'Access,      Mod_Ctrl + 'n');
        Bar.Add ("File/&Open...",      Open_CB'Access,     Mod_Ctrl + 'o');
        Bar.Add ("File/&Save",         Save_CB'Access,     Mod_Ctrl + 's');
        Bar.Add ("File/Save &As...",   Save_As_CB'Access,  Mod_Shift + Mod_Ctrl + 's');
        Bar.Add ("File/&Quit",         Quit_CB'Access,     Mod_Ctrl + 'q');

        Bar.Add (Text => "&Edit", Shortcut => Mod_Alt + 'e', Flags => Flag_Submenu);
        Bar.Add ("Edit/&Undo",         Undo_CB'Access,     Mod_Ctrl + 'z');
        Bar.Add ("Edit/Cu&t",          Cut_CB'Access,      Mod_Ctrl + 'x');
        Bar.Add ("Edit/&Copy",         Copy_CB'Access,     Mod_Ctrl + 'c');
        Bar.Add ("Edit/&Paste",        Paste_CB'Access,    Mod_Ctrl + 'v');
        Bar.Add ("Edit/&Delete",       Delete_CB'Access);

        Bar.Add (Text => "&Search", Shortcut => Mod_Alt + 's', Flags => Flag_Submenu);
        Bar.Add ("Search/&Find...",    Find_CB'Access,     Mod_Ctrl + 'f');
        Bar.Add ("Search/&Replace...", Replace_CB'Access,  Mod_Ctrl + 'h');

        Bar.Add (Text => "&Help", Shortcut => Mod_Alt + 'h', Flags => Flag_Submenu);
        Bar.Add ("Help/&About",        About_CB'Access);
    end;


    Pad.Set_Buffer (Buff);
    Pad.Show;
    return FLTK.Run;


end AdaPad;