Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
9187 akron1 1
(*
9577 akron1 2
    Copyright 2016, 2017, 2020-2022 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;
27
 
28
 
9187 akron1 29
TYPE
30
 
9210 akron1 31
	tEditBox* = RECORD
9187 akron1 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;
9210 akron1 42
		mouse_variable: INTEGER;
9208 akron1 43
		flags*: SET;
9187 akron1 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
 
9645 akron1 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;
9659 akron1 54
PROCEDURE [stdcall, "box_lib.obj", "edit_box_set_text"] set_text (eb: tEditBox; text: INTEGER); END;
9645 akron1 55
PROCEDURE [stdcall, "box_lib.obj", "edit_box_key_safe"] key* (eb: tEditBox; key: INTEGER); END;
9187 akron1 56
 
9659 akron1 57
PROCEDURE get* (text: tEditBox; VAR str: ARRAY OF CHAR);
9187 akron1 58
VAR
9659 akron1 59
	ptr, max, i: INTEGER;
9187 akron1 60
BEGIN
9659 akron1 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;
9187 akron1 72
 
73
 
9659 akron1 74
PROCEDURE set* (text: tEditBox; str: ARRAY OF WCHAR);
9197 akron1 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;
9659 akron1 85
	set_text(text, SYSTEM.ADR(temp[0]))
86
END set;
9197 akron1 87
 
88
 
9659 akron1 89
PROCEDURE create* (x, y, width, max_chars: INTEGER; VAR editbox: tEditBox);
9187 akron1 90
BEGIN
9659 akron1 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}
9187 akron1 104
END create;
105
 
106
 
107
END EditBox.