Subversion Repositories Kolibri OS

Rev

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