Subversion Repositories Kolibri OS

Rev

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