Subversion Repositories Kolibri OS

Rev

Rev 9659 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. (*
  2.     Copyright 2016, 2017, 2020-2023 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 EditBox;
  21.  
  22. IMPORT SYSTEM, KOSAPI, Encodings;
  23.  
  24. CONST
  25.  
  26.         MAX_LENGTH = 1024;
  27.         libName = "box_lib.obj";
  28.  
  29.  
  30. TYPE
  31.  
  32.         tEditBox* = RECORD
  33.                 width*,
  34.                 left*,
  35.                 top*,
  36.                 color*,
  37.                 shift_color,
  38.                 focus_border_color,
  39.                 blur_border_color,
  40.                 text_color*,
  41.                 max: INTEGER;
  42.                 text*: INTEGER;
  43.                 mouse_variable: INTEGER;
  44.                 flags*: SET;
  45.  
  46.                 size,
  47.                 pos: INTEGER;
  48.                 (* The following struct members are not used by the users of API *)
  49.                 offset, cl_curs_x, cl_curs_y, shift, shift_old, height, char_width: INTEGER
  50.         END;
  51.  
  52.  
  53. PROCEDURE [stdcall, libName, "edit_box_draw"]     draw* (eb: tEditBox); END;
  54. PROCEDURE [stdcall, libName, "edit_box_mouse"]    mouse* (eb: tEditBox); END;
  55. PROCEDURE [stdcall, libName, "edit_box_set_text"] set_text (eb: tEditBox; text: INTEGER); END;
  56. PROCEDURE [stdcall, libName, "edit_box_key_safe"] key* (eb: tEditBox; key: INTEGER); END;
  57.  
  58. PROCEDURE get* (text: tEditBox; VAR str: ARRAY OF CHAR);
  59. VAR
  60.         ptr, max, i: INTEGER;
  61. BEGIN
  62.         ptr := text.text;
  63.         max := text.max;
  64.         ASSERT(max < LEN(str));
  65.         i := 0;
  66.         REPEAT
  67.                 SYSTEM.GET(ptr, str[i]);
  68.                 INC(i);
  69.                 INC(ptr)
  70.         UNTIL (str[i - 1] = 0X) OR (i = max);
  71.         str[i] := 0X
  72. END get;
  73.  
  74.  
  75. PROCEDURE set* (text: tEditBox; str: ARRAY OF WCHAR);
  76. VAR
  77.         i: INTEGER;
  78.         temp: ARRAY MAX_LENGTH OF CHAR;
  79. BEGIN
  80.         ASSERT(LENGTH(str) < LEN(temp));
  81.         i := 0;
  82.         REPEAT
  83.                 temp[i] := CHR(Encodings.UNI[ORD(str[i]), Encodings.CP866] MOD 256);
  84.                 INC(i)
  85.         UNTIL str[i - 1] = 0X;
  86.         set_text(text, SYSTEM.ADR(temp[0]))
  87. END set;
  88.  
  89.  
  90. PROCEDURE create* (x, y, width, max_chars: INTEGER; VAR editbox: tEditBox);
  91. BEGIN
  92.         editbox.width := width;
  93.         editbox.left := x;
  94.         editbox.top := y;
  95.         editbox.color := 0FFFFFFH;
  96.         editbox.shift_color := 06A9480H;
  97.         editbox.focus_border_color := 0;
  98.         editbox.blur_border_color := 06A9480H;
  99.         editbox.text_color := 30000000H;
  100.         editbox.max := max_chars;
  101.         editbox.text := KOSAPI.malloc(max_chars + 2);
  102.         ASSERT(editbox.text # 0);
  103.         editbox.mouse_variable := 0;
  104.         editbox.flags := {14}
  105. END create;
  106.  
  107.  
  108. END EditBox.