Subversion Repositories Kolibri OS

Rev

Rev 9174 | Rev 9410 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9060 leency 1
(*
9050 leency 2
    Copyright 2021 Anton Krotov
3
 
4
    This file is part of CEdit.
5
 
6
    CEdit is free software: you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation, either version 3 of the License, or
9
    (at your option) any later version.
10
 
11
    CEdit is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
 
16
    You should have received a copy of the GNU General Public License
17
    along with CEdit. If not, see .
18
*)
19
 
20
MODULE Tabs;
21
 
22
IMPORT List, K := KolibriOS, RW;
23
 
24
CONST
25
 
26
    btnID* = 100;
27
    tabHeight* = 22;
28
    curTabHeight = 26;
9174 akron1 29
    scrWidth = 15;
9050 leency 30
 
31
TYPE
32
 
33
    tItem = POINTER TO RECORD (List.tItem)
34
 
35
        val: RW.tFileName
36
 
37
    END;
38
 
39
    tTabs* = POINTER TO RECORD
40
 
41
        strings: List.tList;
42
        first, current: INTEGER;
43
        width, height: INTEGER;
44
        x, y: INTEGER
45
 
46
    END;
47
 
48
 
49
PROCEDURE drawTab (t: tTabs; id, x, y, width, height: INTEGER; s: ARRAY OF CHAR);
50
VAR
9060 leency 51
    x2, y2, color: INTEGER;
9050 leency 52
BEGIN
53
    IF id = t.current THEN
54
        INC(height, curTabHeight - tabHeight);
9060 leency 55
        DEC(y, curTabHeight - tabHeight);
9175 akron1 56
        color := K.lightColor
9060 leency 57
    ELSE
9175 akron1 58
        color := K.winColor
9050 leency 59
    END;
9060 leency 60
    DEC(x); INC(width);
9050 leency 61
    x2 := x + width - 1;
62
    y2 := y + height - 1;
9060 leency 63
 
64
    K.DrawRect(x, y, width, height,color);
9050 leency 65
    K.DrawLine(x, y, x2, y, K.borderColor);
66
    K.DrawLine(x2, y, x2, y2, K.borderColor);
9060 leency 67
    IF id # t.current THEN
68
        K.DrawLine(x2 - 1, y2, x, y2, K.borderColor);
69
    END;
9050 leency 70
    K.DrawLine(x, y2, x, y, K.borderColor);
9060 leency 71
    K.DrawText866bk(x + K.fontWidth, y + (height - K.fontHeight) DIV 2, K.textColor, color, s);
9073 leency 72
    K.CreateButton(id + ORD({30}) + btnID, x + 1, y - 1, width - 1, height - 1, color, "");
9050 leency 73
END drawTab;
74
 
75
 
76
PROCEDURE tabWidth (tab: tItem): INTEGER;
77
    RETURN (LENGTH(tab.val) + 2)*K.fontWidth
78
END tabWidth;
79
 
80
 
81
PROCEDURE Width (t: tTabs; pos, n: INTEGER): INTEGER;
82
VAR
83
    res, i: INTEGER;
84
    item: List.tItem;
85
BEGIN
86
    res := 0;
87
    i := pos;
88
    item := List.getItem(t.strings, i);
89
    WHILE (item # NIL) & (i <= n) DO
90
        INC(res, tabWidth(item(tItem)));
91
        item := item.next;
92
        INC(i)
93
    END
94
    RETURN res
95
END Width;
96
 
97
 
98
PROCEDURE draw* (t: tTabs);
99
VAR
100
    x, y, xmax, n, width: INTEGER;
101
    item: List.tItem;
9060 leency 102
    scroll: BOOLEAN;
9050 leency 103
BEGIN
104
    y := t.y;
105
    x := t.x;
9174 akron1 106
    K.DrawRect(x, y - (curTabHeight - tabHeight), t.width + (2*scrWidth + 2), t.height + (curTabHeight - tabHeight) - 1, K.winColor);
9050 leency 107
    IF Width(t, 0, t.strings.count - 1) > t.width THEN
108
        INC(x, 2*scrWidth);
109
        K.CreateButton(btnID - 1, t.x, t.y, scrWidth, t.height - 1, K.btnColor, "<");
9060 leency 110
        K.CreateButton(btnID - 2, t.x + scrWidth, t.y, scrWidth, t.height - 1, K.btnColor, ">");
111
        scroll := TRUE
9050 leency 112
    ELSE
9060 leency 113
        t.first := 0;
114
        scroll := FALSE
9050 leency 115
    END;
116
    xmax := x + t.width - 1;
117
 
118
    n := t.strings.count - 1;
119
    WHILE (n >= 0) & (Width(t, n, t.strings.count - 1) <= t.width) DO
120
        DEC(n)
121
    END;
122
    IF n < 0 THEN
123
        n := 0
124
    ELSE
125
        INC(n)
126
    END;
127
    IF n < t.first THEN
128
        t.first := n
129
    END;
130
 
9060 leency 131
    K.DrawRect(x, y, t.width, t.height - 1, K.winColor);
132
    K.DrawLine(x, y + tabHeight - 1, x + t.width - 1 + 2*scrWidth*(1 - ORD(scroll)), y + tabHeight - 1, K.borderColor);
9050 leency 133
    item := List.getItem(t.strings, t.first);
134
    n := t.first;
135
    WHILE (item # NIL) & (x <= xmax) DO
136
        width := tabWidth(item(tItem));
137
        IF x + width - 1 <= xmax THEN
9060 leency 138
            drawTab(t, n, x + 1, y, width, t.height, item(tItem).val)
9050 leency 139
        END;
140
        INC(n);
141
        INC(x, width);
142
        item := item.next
143
    END
144
END draw;
145
 
146
 
147
PROCEDURE add* (t: tTabs; s: ARRAY OF CHAR);
148
VAR
149
    item: tItem;
150
BEGIN
151
    NEW(item);
152
    item.val := s;
153
    List.append(t.strings, item);
154
END add;
155
 
156
 
157
PROCEDURE rename* (t: tTabs; n: INTEGER; s: ARRAY OF CHAR);
158
VAR
159
    item: List.tItem;
160
BEGIN
161
    item := List.getItem(t.strings, n);
162
    item(tItem).val := s
163
END rename;
164
 
165
 
166
PROCEDURE delete* (t: tTabs; n: INTEGER);
167
VAR
168
    item: List.tItem;
169
BEGIN
170
    item := List.getItem(t.strings, n);
171
    List.delete(t.strings, item)
172
END delete;
173
 
174
 
175
PROCEDURE scroll* (t: tTabs; n: INTEGER);
176
VAR
177
    pos: INTEGER;
178
BEGIN
179
    pos := t.first + n;
180
    IF pos < 0 THEN
181
        pos := 0
182
    ELSIF pos >= t.strings.count THEN
183
        pos := t.strings.count - 1
184
    END;
185
    t.first := pos
186
END scroll;
187
 
188
 
189
PROCEDURE switch* (t: tTabs; n: INTEGER);
190
BEGIN
191
    IF (0 <= n) & (n < t.strings.count) THEN
192
        t.current := n;
193
        IF n < t.first THEN
194
            t.first := 0
195
        END;
196
        WHILE Width(t, t.first, n) > t.width DO
197
            INC(t.first)
198
        END
199
    END
200
END switch;
201
 
202
 
203
PROCEDURE setArea* (t: tTabs; x, y, width, height: INTEGER);
204
BEGIN
205
    t.x := x;
206
    t.y := y;
9060 leency 207
    t.width := width - 2*scrWidth;
9050 leency 208
    t.height := height
209
END setArea;
210
 
211
 
212
PROCEDURE create* (): tTabs;
213
VAR
214
    res: tTabs;
215
BEGIN
216
    NEW(res);
217
    res.strings := List.create(NIL);
218
    res.current := 0;
219
    res.first := 0
220
    RETURN res
221
END create;
222
 
223
 
224
END Tabs.