Subversion Repositories Kolibri OS

Rev

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