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


private with Ada.Containers.Vectors;
private with System.Address_To_Access_Conversions;


package FLTK.Text_Buffers is


    type Text_Buffer is new Wrapper with private;
    type Text_Buffer_Cursor (Data : access Text_Buffer'Class) is limited null record
        with Implicit_Dereference => Data;


    type Position is new Natural;
    type Modification is (Insert, Restyle, Delete, None);


    type Modify_Callback is access procedure
           (Action       : in Modification;
            Place        : in Position;
            Length       : in Natural;
            Deleted_Text : in String);


    type Predelete_Callback is access procedure
           (Place  : in Position;
            Length : in Natural);


    function Create
           (Requested_Size     : in Natural := 0;
            Preferred_Gap_Size : in Natural := 1024)
        return Text_Buffer;


    procedure Add_Modify_Callback
           (This : in out Text_Buffer;
            Func : in     Modify_Callback);


    procedure Add_Predelete_Callback
           (This : in out Text_Buffer;
            Func : in     Predelete_Callback);


    procedure Call_Modify_Callbacks
           (This : in out Text_Buffer);


    procedure Call_Predelete_Callbacks
           (This : in out Text_Buffer);


    procedure Enable_Callbacks
           (This : in out Text_Buffer);


    procedure Disable_Callbacks
           (This : in out Text_Buffer);


    procedure Insert_Text
           (This : in out Text_Buffer;
            Pos  : in     Natural;
            Item : in     String);


    procedure Remove_Text
           (This          : in out Text_Buffer;
            Start, Finish : in     Natural);


    function Length
           (This : in Text_Buffer)
        return Natural;


    procedure Load_File
           (This : in Text_Buffer;
            Name : in String);


    procedure Remove_Selected_Text
           (This : in out Text_Buffer);


    procedure Save_File
           (This : in Text_Buffer;
            Name : in String);


    function Search_Forward
           (This       : in     Text_Buffer;
            Start_At   : in     Natural;
            Item       : in     String;
            Found_At   :    out Natural;
            Match_Case : in     Boolean)
        return Boolean;


    function Search_Backward
           (This       : in     Text_Buffer;
            Start_At   : in     Natural;
            Item       : in     String;
            Found_At   :    out Natural;
            Match_Case : in     Boolean)
        return Boolean;


    procedure Set_Selection
           (This          : in out Text_Buffer;
            Start, Finish : in     Natural);


    function Get_Selection
           (This          : in     Text_Buffer;
            Start, Finish :    out Natural)
        return Boolean;


    function Has_Selection
           (This : in Text_Buffer)
        return Boolean;


    --  only takes into account newline characters, not word wrap
    function Skip_Lines
           (This         : in out Text_Buffer;
            Start, Lines : in     Natural)
        return Natural;


    --  only takes into account newline characters, not word wrap
    function Rewind_Lines
           (This         : in out Text_Buffer;
            Start, Lines : in     Natural)
        return Natural;


    function Character_At
           (This : in Text_Buffer;
            Pos  : in Natural)
        return Character;


    function Text_At
           (This          : in Text_Buffer;
            Start, Finish : in Natural)
        return String;


private


    package Modify_Vectors is new Ada.Containers.Vectors
           (Index_Type => Positive,
            Element_Type => Modify_Callback);
    package Predelete_Vectors is new Ada.Containers.Vectors
           (Index_Type => Positive,
            Element_Type => Predelete_Callback);


    type Text_Buffer is new Wrapper with
        record
            CB_Active     : Boolean;
            Modify_CBs    : Modify_Vectors.Vector;
            Predelete_CBs : Predelete_Vectors.Vector;
        end record;


    overriding procedure Finalize
           (This : in out Text_Buffer);


    package Text_Buffer_Convert is new System.Address_To_Access_Conversions (Text_Buffer);


end FLTK.Text_Buffers;