Subversion Repositories Kolibri OS

Rev

Rev 9630 | Rev 9659 | 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"] _setValue (eb: tEditBox; text: INTEGER); END;
  55. PROCEDURE [stdcall, "box_lib.obj", "edit_box_key_safe"] key* (eb: tEditBox; key: INTEGER); END;
  56.  
  57. PROCEDURE getValue* (text: tEditBox; VAR str: ARRAY OF CHAR);
  58. VAR
  59.     ptr, max, i: INTEGER;
  60.  
  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 getValue;
  73.  
  74.  
  75. PROCEDURE setValue* (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.         _setValue(text, SYSTEM.ADR(temp[0]))
  87. END setValue;
  88.  
  89.  
  90. PROCEDURE create* (tlx, tly, width, max_chars: INTEGER; VAR editbox: tEditBox);
  91. BEGIN
  92.     editbox.width := width;
  93.     editbox.left := tlx;
  94.     editbox.top := tly;
  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.