Subversion Repositories Kolibri OS

Rev

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

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