Subversion Repositories Kolibri OS

Rev

Rev 9628 | 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. VAR
  53.  
  54.         draw      *: PROCEDURE (eb: tEditBox);
  55.         mouse     *: PROCEDURE (eb: tEditBox);
  56.         _setValue  : PROCEDURE (eb: tEditBox; text: INTEGER);
  57.         key       *: PROCEDURE (eb: tEditBox; key: INTEGER);
  58.  
  59.  
  60. PROCEDURE getValue* (text: tEditBox; VAR str: ARRAY OF CHAR);
  61. VAR
  62.     ptr, max, i: INTEGER;
  63.  
  64. BEGIN
  65.     ptr := text.text;
  66.     max := text.max;
  67.     ASSERT(max < LEN(str));
  68.     i := 0;
  69.     REPEAT
  70.         SYSTEM.GET(ptr, str[i]);
  71.         INC(i);
  72.         INC(ptr)
  73.     UNTIL (str[i - 1] = 0X) OR (i = max);
  74.     str[i] := 0X
  75. END getValue;
  76.  
  77.  
  78. PROCEDURE setValue* (text: tEditBox; str: ARRAY OF WCHAR);
  79. VAR
  80.         i: INTEGER;
  81.         temp: ARRAY MAX_LENGTH OF CHAR;
  82. BEGIN
  83.         ASSERT(LENGTH(str) < LEN(temp));
  84.         i := 0;
  85.         REPEAT
  86.                 temp[i] := CHR(Encodings.UNI[ORD(str[i]), Encodings.CP866] MOD 256);
  87.                 INC(i)
  88.         UNTIL str[i - 1] = 0X;
  89.         _setValue(text, SYSTEM.ADR(temp[0]))
  90. END setValue;
  91.  
  92.  
  93. PROCEDURE create* (tlx, tly, width, max_chars: INTEGER; VAR editbox: tEditBox);
  94. BEGIN
  95.     editbox.width := width;
  96.     editbox.left := tlx;
  97.     editbox.top := tly;
  98.     editbox.color := 0FFFFFFH;
  99.     editbox.shift_color := 06A9480H;
  100.     editbox.focus_border_color := 0;
  101.     editbox.blur_border_color := 06A9480H;
  102.     editbox.text_color := 30000000H;
  103.     editbox.max := max_chars;
  104.     editbox.text := KOSAPI.malloc(max_chars + 2);
  105.     ASSERT(editbox.text # 0);
  106.     editbox.mouse_variable := 0;
  107.     editbox.flags := {14}
  108. END create;
  109.  
  110.  
  111. PROCEDURE GetProc (Lib, v: INTEGER; name: ARRAY OF CHAR);
  112. VAR
  113.         a: INTEGER;
  114. BEGIN
  115.         a := KOSAPI.GetProcAdr(name, Lib);
  116.         ASSERT(a # 0);
  117.         SYSTEM.PUT(v, a)
  118. END GetProc;
  119.  
  120.  
  121. PROCEDURE main;
  122. VAR
  123.         Lib: INTEGER;
  124. BEGIN
  125.         Lib := KOSAPI.LoadLib("/sys/lib/box_lib.obj");
  126.         ASSERT(Lib # 0);
  127.         GetProc(Lib, SYSTEM.ADR(draw),      "edit_box_draw");
  128.         GetProc(Lib, SYSTEM.ADR(key),       "edit_box_key_safe");
  129.         GetProc(Lib, SYSTEM.ADR(mouse),     "edit_box_mouse");
  130.         GetProc(Lib, SYSTEM.ADR(_setValue), "edit_box_set_text");
  131. END main;
  132.  
  133.  
  134. BEGIN
  135.         main
  136. END EditBox.