Subversion Repositories Kolibri OS

Rev

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