Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
9187 akron1 1
(*
9913 akron1 2
    Copyright 2016, 2017, 2020-2023 Anton Krotov
9187 akron1 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 .
18
*)
19
 
20
MODULE EditBox;
21
 
9197 akron1 22
IMPORT SYSTEM, KOSAPI, Encodings;
9187 akron1 23
 
9197 akron1 24
CONST
9187 akron1 25
 
9197 akron1 26
	MAX_LENGTH = 1024;
9913 akron1 27
	libName = "box_lib.obj";
9197 akron1 28
 
29
 
9187 akron1 30
TYPE
31
 
9210 akron1 32
	tEditBox* = RECORD
9187 akron1 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;
9210 akron1 43
		mouse_variable: INTEGER;
9208 akron1 44
		flags*: SET;
9187 akron1 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
 
9913 akron1 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;
9187 akron1 57
 
9659 akron1 58
PROCEDURE get* (text: tEditBox; VAR str: ARRAY OF CHAR);
9187 akron1 59
VAR
9659 akron1 60
	ptr, max, i: INTEGER;
9187 akron1 61
BEGIN
9659 akron1 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;
9187 akron1 73
 
74
 
9659 akron1 75
PROCEDURE set* (text: tEditBox; str: ARRAY OF WCHAR);
9197 akron1 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;
9659 akron1 86
	set_text(text, SYSTEM.ADR(temp[0]))
87
END set;
9197 akron1 88
 
89
 
9659 akron1 90
PROCEDURE create* (x, y, width, max_chars: INTEGER; VAR editbox: tEditBox);
9187 akron1 91
BEGIN
9659 akron1 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}
9187 akron1 105
END create;
106
 
107
 
108
END EditBox.