Subversion Repositories Kolibri OS

Rev

Rev 9060 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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