Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
9060 leency 1
(*
9628 akron1 2
    Copyright 2021, 2022 Anton Krotov
9050 leency 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
 
9431 akron1 22
IMPORT List, K := KolibriOS, RW, U := Utils;
9050 leency 23
 
24
CONST
25
 
26
    btnID* = 100;
9730 akron1 27
    btnClose* = btnID + 100;
9448 akron1 28
    btnLeft* = btnID - 1;
29
	btnRight* = btnID - 2;
9050 leency 30
    tabHeight* = 22;
31
    curTabHeight = 26;
9174 akron1 32
    scrWidth = 15;
9730 akron1 33
    btnCloseColor* = 0EF999FH;
9050 leency 34
 
35
TYPE
36
 
37
    tItem = POINTER TO RECORD (List.tItem)
38
 
9410 akron1 39
        val: RW.tFileName;
40
        modified: BOOLEAN
9050 leency 41
 
42
    END;
43
 
44
    tTabs* = POINTER TO RECORD
45
 
46
        strings: List.tList;
47
        first, current: INTEGER;
48
        width, height: INTEGER;
9431 akron1 49
        x, y, freeX: INTEGER
9050 leency 50
 
51
    END;
52
 
53
 
9431 akron1 54
PROCEDURE DblClicked* (t: tTabs; x, y: INTEGER): BOOLEAN;
55
	RETURN (x > t.freeX) & U.between(t.y, y, t.y + t.height - 1)
56
END DblClicked;
57
 
58
 
9410 akron1 59
PROCEDURE drawTab (t: tTabs; id, x, y, width, height: INTEGER; s: ARRAY OF CHAR; modified: BOOLEAN);
9730 akron1 60
CONST
61
	btnCloseSize = 14;
9050 leency 62
VAR
9060 leency 63
    x2, y2, color: INTEGER;
9730 akron1 64
    left, top: INTEGER;
9050 leency 65
BEGIN
66
    IF id = t.current THEN
67
        INC(height, curTabHeight - tabHeight);
9060 leency 68
        DEC(y, curTabHeight - tabHeight);
9628 akron1 69
        color := K.colors.light
9060 leency 70
    ELSE
9628 akron1 71
        color := K.colors.work
9050 leency 72
    END;
9060 leency 73
    DEC(x); INC(width);
9050 leency 74
    x2 := x + width - 1;
75
    y2 := y + height - 1;
9060 leency 76
 
9526 akron1 77
    K.DrawRect(x, y, width, height, color);
9628 akron1 78
    K.DrawLine(x, y, x2, y, K.colors.line);
79
    K.DrawLine(x2, y, x2, y2, K.colors.line);
9730 akron1 80
 
81
    top := y + 3;
9060 leency 82
    IF id # t.current THEN
9730 akron1 83
        K.DrawLine(x2 - 1, y2, x, y2, K.colors.line)
84
    ELSE
85
    	INC(top, (curTabHeight - tabHeight) DIV 2)
9060 leency 86
    END;
9628 akron1 87
    K.DrawLine(x, y2, x, y, K.colors.line);
9410 akron1 88
 
9628 akron1 89
    K.DrawText866bk(x + K.fontWidth + K.fontWidth DIV 2, y + (height - K.fontHeight) DIV 2, K.colors.work_text, color, s);
9410 akron1 90
    IF modified THEN
9628 akron1 91
    	K.DrawText866bk(x + K.fontWidth DIV 2, y + (height - K.fontHeight) DIV 2, K.colors.work_text, color, "*")
9410 akron1 92
    END;
9730 akron1 93
    K.CreateButton(id + ORD({30}) + btnID, x + 1, y - 1, width - 1, height - 1, 0, "");
94
    left := x + width - btnCloseSize - 5;
95
    K.CreateButton(id + btnClose, left, top, btnCloseSize, btnCloseSize,  btnCloseColor, "");
96
    K.DrawLine(left + 5, top + 4, left + btnCloseSize - 4, top + btnCloseSize - 5, 0FFFFFFH);
97
    K.DrawLine(left + 4, top + 4, left + btnCloseSize - 4, top + btnCloseSize - 4, 0FFFFFFH);
98
    K.DrawLine(left + 4, top + 5, left + btnCloseSize - 5, top + btnCloseSize - 4, 0FFFFFFH);
99
    K.DrawLine(left + 4, top + btnCloseSize - 4, left + btnCloseSize - 4, top + 4, 0FFFFFFH);
100
    K.DrawLine(left + 4, top + btnCloseSize - 5, left + btnCloseSize - 5, top + 4, 0FFFFFFH);
101
    K.DrawLine(left + 5, top + btnCloseSize - 4, left + btnCloseSize - 4, top + 5, 0FFFFFFH);
9050 leency 102
END drawTab;
103
 
104
 
105
PROCEDURE tabWidth (tab: tItem): INTEGER;
9730 akron1 106
    RETURN (LENGTH(tab.val) + 5)*K.fontWidth
9050 leency 107
END tabWidth;
108
 
109
 
110
PROCEDURE Width (t: tTabs; pos, n: INTEGER): INTEGER;
111
VAR
112
    res, i: INTEGER;
113
    item: List.tItem;
114
BEGIN
115
    res := 0;
116
    i := pos;
117
    item := List.getItem(t.strings, i);
118
    WHILE (item # NIL) & (i <= n) DO
119
        INC(res, tabWidth(item(tItem)));
120
        item := item.next;
121
        INC(i)
122
    END
123
    RETURN res
124
END Width;
125
 
126
 
127
PROCEDURE draw* (t: tTabs);
128
VAR
9431 akron1 129
    x, y, xmax, n, width, i: INTEGER;
9050 leency 130
    item: List.tItem;
9060 leency 131
    scroll: BOOLEAN;
9050 leency 132
BEGIN
133
    y := t.y;
134
    x := t.x;
9628 akron1 135
    K.DrawRect(x, y - (curTabHeight - tabHeight), t.width + (2*scrWidth + 2), t.height + (curTabHeight - tabHeight) - 1, K.colors.work);
9050 leency 136
    IF Width(t, 0, t.strings.count - 1) > t.width THEN
137
        INC(x, 2*scrWidth);
9448 akron1 138
        K.DeleteButton(btnLeft);
139
        K.DeleteButton(btnRight);
9628 akron1 140
        K.CreateButton(btnLeft, t.x, y, scrWidth, t.height - 1, K.colors.button, "<");
141
        K.CreateButton(btnRight, t.x + scrWidth, y, scrWidth, t.height - 1, K.colors.button, ">");
9060 leency 142
        scroll := TRUE
9050 leency 143
    ELSE
9060 leency 144
        t.first := 0;
145
        scroll := FALSE
9050 leency 146
    END;
147
    xmax := x + t.width - 1;
148
 
149
    n := t.strings.count - 1;
9431 akron1 150
    FOR i := 0 TO n DO
151
    	K.DeleteButton(i + btnID)
152
    END;
9050 leency 153
    WHILE (n >= 0) & (Width(t, n, t.strings.count - 1) <= t.width) DO
154
        DEC(n)
155
    END;
156
    IF n < 0 THEN
157
        n := 0
158
    ELSE
159
        INC(n)
160
    END;
161
    IF n < t.first THEN
162
        t.first := n
163
    END;
164
 
9628 akron1 165
    K.DrawRect(x, y, t.width, t.height - 1, K.colors.work);
166
    K.DrawLine(x, y + tabHeight - 1, x + t.width - 1 + 2*scrWidth*(1 - ORD(scroll)), y + tabHeight - 1, K.colors.line);
9050 leency 167
    item := List.getItem(t.strings, t.first);
168
    n := t.first;
169
    WHILE (item # NIL) & (x <= xmax) DO
170
        width := tabWidth(item(tItem));
171
        IF x + width - 1 <= xmax THEN
9431 akron1 172
            drawTab(t, n, x + 1, y, width, t.height, item(tItem).val, item(tItem).modified);
173
        	INC(n);
174
        	INC(x, width);
175
        	item := item.next
176
        ELSE
177
        	item := NIL
178
        END
179
    END;
180
    t.freeX := x
9050 leency 181
END draw;
182
 
183
 
184
PROCEDURE add* (t: tTabs; s: ARRAY OF CHAR);
185
VAR
186
    item: tItem;
187
BEGIN
188
    NEW(item);
189
    item.val := s;
9410 akron1 190
    item.modified := FALSE;
9050 leency 191
    List.append(t.strings, item);
192
END add;
193
 
194
 
9410 akron1 195
PROCEDURE modify* (t: tTabs; n: INTEGER; val: BOOLEAN);
196
VAR
197
    item: List.tItem;
198
BEGIN
199
	item := List.getItem(t.strings, n);
200
	IF item(tItem).modified # val THEN
201
		item(tItem).modified := val;
202
		draw(t)
203
	END
204
END modify;
205
 
206
 
9050 leency 207
PROCEDURE rename* (t: tTabs; n: INTEGER; s: ARRAY OF CHAR);
208
VAR
209
    item: List.tItem;
210
BEGIN
211
    item := List.getItem(t.strings, n);
212
    item(tItem).val := s
213
END rename;
214
 
215
 
216
PROCEDURE delete* (t: tTabs; n: INTEGER);
217
VAR
218
    item: List.tItem;
219
BEGIN
220
    item := List.getItem(t.strings, n);
9448 akron1 221
    List.delete(t.strings, item);
222
    DISPOSE(item)
9050 leency 223
END delete;
224
 
225
 
9648 akron1 226
PROCEDURE scroll* (t: tTabs; btn: INTEGER);
9050 leency 227
VAR
228
    pos: INTEGER;
229
BEGIN
9648 akron1 230
    pos := t.first + ORD(btn = btnRight) - ORD(btn = btnLeft);
9050 leency 231
    IF pos < 0 THEN
232
        pos := 0
233
    ELSIF pos >= t.strings.count THEN
234
        pos := t.strings.count - 1
235
    END;
236
    t.first := pos
237
END scroll;
238
 
239
 
240
PROCEDURE switch* (t: tTabs; n: INTEGER);
241
BEGIN
242
    IF (0 <= n) & (n < t.strings.count) THEN
243
        t.current := n;
244
        IF n < t.first THEN
245
            t.first := 0
246
        END;
247
        WHILE Width(t, t.first, n) > t.width DO
248
            INC(t.first)
249
        END
250
    END
251
END switch;
252
 
253
 
254
PROCEDURE setArea* (t: tTabs; x, y, width, height: INTEGER);
255
BEGIN
256
    t.x := x;
257
    t.y := y;
9060 leency 258
    t.width := width - 2*scrWidth;
9050 leency 259
    t.height := height
260
END setArea;
261
 
262
 
263
PROCEDURE create* (): tTabs;
264
VAR
265
    res: tTabs;
266
BEGIN
267
    NEW(res);
268
    res.strings := List.create(NIL);
269
    res.current := 0;
270
    res.first := 0
271
    RETURN res
272
END create;
273
 
274
 
275
END Tabs.