summaryrefslogtreecommitdiff
path: root/src/windows-editor.adb
blob: 7f303fe479ed7b05c547c32e0ab7ff1981806450 (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


with FLTK.Enums; use FLTK.Enums;
with FLTK.Widgets.Groups.Windows.Double;
with FLTK.Widgets.Groups.Text_Displays.Text_Editors;
with FLTK.Widgets.Menus;
with FLTK.Widgets.Menus.Menu_Bars;
with FLTK.Text_Buffers;


package body Windows.Editor is


    package WD renames FLTK.Widgets.Groups.Windows.Double;
    package TE renames FLTK.Widgets.Groups.Text_Displays.Text_Editors;
    package MB renames FLTK.Widgets.Menus.Menu_Bars;




    function Create
           (X, Y, W, H : in Integer;
            Label_Text : in String)
        return Editor_Window
    is
        Width       : Integer := Min_Editor_Width;
        Height      : Integer := Min_Editor_Height;
        Menu_Height : Integer := 22;
    begin
        if Width < W then
            Width := W;
        end if;

        if Height < H then
            Height := H;
        end if;

        return This : Editor_Window :=
                   (WD.Double_Window'(WD.Create (X, Y, Width, Height, Label_Text)) with

                    Editor => TE.Text_Editor'(TE.Create
                        (0, Menu_Height, Width, Height - Menu_Height, "")),
                    Bar => MB.Menu_Bar'(MB.Create
                        (0, 0, Width, Menu_Height, ""))) do

            This.Add (This.Editor);
            This.Add (This.Bar);
            This.Bar.Set_Box (No_Box);
            This.Editor.Set_Text_Font (Courier);
            This.Set_Resizable (This.Editor);
            This.Set_Size_Range (Min_Editor_Width, Min_Editor_Height);
            This.Set_Icon (Logo);
        end return;
    end Create;




    function Create
           (W, H : in Integer)
        return Editor_Window is
    begin
        return Create (0, 0, W, H, "(Untitled)");
    end Create;




    function Get_Buffer
           (This : in Editor_Window)
        return FLTK.Text_Buffers.Text_Buffer_Cursor is
    begin
        return This.Editor.Get_Buffer;
    end Get_Buffer;




    procedure Set_Buffer
           (This : in out Editor_Window;
            Buff : in out FLTK.Text_Buffers.Text_Buffer) is
    begin
        This.Editor.Set_Buffer (Buff);
    end Set_Buffer;




    function Get_Menu
           (This : in out Editor_Window)
        return FLTK.Widgets.Menus.Menu_Cursor is
    begin
        return Ref : FLTK.Widgets.Menus.Menu_Cursor (This.Bar'Access);
    end Get_Menu;




    procedure Undo
           (This : in out Editor_Window) is
    begin
        This.Editor.Undo;
    end Undo;




    procedure Cut
           (This : in out Editor_Window) is
    begin
        This.Editor.Cut;
    end Cut;




    procedure Copy
           (This : in out Editor_Window) is
    begin
        This.Editor.Copy;
    end Copy;




    procedure Paste
           (This : in out Editor_Window) is
    begin
        This.Editor.Paste;
    end Paste;




    procedure Delete
           (This : in out Editor_Window) is
    begin
        This.Editor.Delete;
    end Delete;




    function Get_Insert_Position
           (This : in Editor_Window)
        return Natural is
    begin
        return This.Editor.Get_Insert_Position;
    end Get_Insert_Position;




    procedure Set_Insert_Position
           (This : in out Editor_Window;
            Pos  : in     Natural) is
    begin
        This.Editor.Set_Insert_Position (Pos);
    end Set_Insert_Position;




    procedure Show_Insert_Position
           (This : in out Editor_Window) is
    begin
        This.Editor.Show_Insert_Position;
    end Show_Insert_Position;


end Windows.Editor;