aboutsummaryrefslogtreecommitdiff
path: root/doc/menu_lua_api.txt
blob: 423b8bb9c90555260f3b541576f7952cd34ebdbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
Minetest Lua Mainmenu API Reference 0.4.15
========================================

Introduction
-------------
The main menu is defined as a formspec by Lua in builtin/mainmenu/
Description of formspec language to show your menu is in lua_api.txt

Callbacks
---------
core.buttonhandler(fields): called when a button is pressed.
^ fields = {name1 = value1, name2 = value2, ...}
core.event_handler(event)
^ event: "MenuQuit", "KeyEnter", "ExitButton" or "EditBoxEnter"

Gamedata
--------
The "gamedata" table is read when calling core.start(). It should contain:
{
	playername     = <name>,
	password       = <password>,
	address        = <IP/adress>,
	port           = <port>,
	selected_world = <index>, -- 0 for client mode
	singleplayer   = <true/false>,
}

Functions
---------
core.start()
core.close()

Filesystem:
core.get_builtin_path()
^ returns path to builtin root
core.get_modpath() (possible in async calls)
^ returns path to global modpath
core.get_modstore_details(modid) (possible in async calls)
^ modid numeric id of mod in modstore
^ returns {
	id			= <numeric id of mod in modstore>,
	title		= <human readable title>,
	basename	= <basename for mod>,
	description = <description of mod>,
	author		= <author of mod>,
	download_url= <best match download url>,
	license		= <short description of license>,
	rating		= <float value of current rating>
}
core.get_modstore_list() (possible in async calls)
^ returns {
	[1] = {
		id		 = <numeric id of mod in modstore>,
		title	 = <human readable title>,
		basename = <basename for mod>
	}
}
core.get_gamepath() (possible in async calls)
^ returns path to global gamepath
core.get_texturepath() (possible in async calls)
^ returns path to default textures
core.create_dir(absolute_path) (possible in async calls)
^ absolute_path to directory to create (needs to be absolute)
^ returns true/false
core.delete_dir(absolute_path) (possible in async calls)
^ absolute_path to directory to delete (needs to be absolute)
^ returns true/false
core.copy_dir(source,destination,keep_soure) (possible in async calls)
^ source folder
^ destination folder
^ keep_source DEFAULT true --> if set to false source is deleted after copying
^ returns true/false
core.extract_zip(zipfile,destination) [unzip within path required]
^ zipfile to extract
^ destination folder to extract to
^ returns true/false
core.download_file(url,target) (possible in async calls)
^ url to download
^ target to store to
^ returns true/false
core.get_version() (possible in async calls)
^ returns current core version
core.sound_play(spec, looped) -> handle
^ spec = SimpleSoundSpec (see lua-api.txt)
^ looped = bool
core.sound_stop(handle)
core.get_video_drivers()
^ get list of video drivers supported by engine (not all modes are guaranteed to work)
^ returns list of available video drivers' settings name and 'friendly' display name
^ e.g. { {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }
^ first element of returned list is guaranteed to be the NULL driver

Formspec:
core.update_formspec(formspec)
core.get_table_index(tablename) -> index
^ can also handle textlists
core.formspec_escape(string) -> string
^ escapes characters [ ] \ , ; that can not be used in formspecs
core.explode_table_event(string) -> table
^ returns e.g. {type="CHG", row=1, column=2}
^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
core.explode_textlist_event(string) -> table
^ returns e.g. {type="CHG", index=1}
^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)

GUI:
core.set_background(type, texturepath,[tile],[minsize])
^ type: "background", "overlay", "header" or "footer"
^ tile: tile the image instead of scaling (background only)
^ minsize: minimum tile size, images are scaled to at least this size prior
^   doing tiling (background only)
core.set_clouds(<true/false>)
core.set_topleft_text(text)
core.show_keys_menu()
core.file_open_dialog(formname,caption)
^ shows a file open dialog
^ formname is base name of dialog response returned in fields
^     -if dialog was accepted "_accepted"
^^       will be added to fieldname containing the path
^     -if dialog was canceled "_cancelled"
^        will be added to fieldname value is set to formname itself
^ returns nil or selected file/folder
core.get_screen_info()
^ returns {
	density         = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
	display_width   = <width of display>,
	display_height  = <height of display>,
	window_width    = <current window width>,
	window_height   = <current window height>
	}

Games:
core.get_game(index)
^ returns {
	id               = <id>,
	path             = <full path to game>,
	gamemods_path    = <path>,
	name             = <name of game>,
	menuicon_path    = <full path to menuicon>,
	DEPRECATED:
	addon_mods_paths = {[1] = <path>,},
}
core.get_games() -> table of all games in upper format (possible in async calls)
core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
    registered in the core (possible in async calls)

Favorites:
core.get_favorites(location) -> list of favorites (possible in async calls)
^ location: "local" or "online"
^ returns {
	[1] = {
	clients       = <number of clients/nil>,
	clients_max   = <maximum number of clients/nil>,
	version       = <server version/nil>,
	password      = <true/nil>,
	creative      = <true/nil>,
	damage        = <true/nil>,
	pvp           = <true/nil>,
	description   = <server description/nil>,
	name          = <server name/nil>,
	address       = <address of server/nil>,
	port          = <port>
	},
}
core.delete_favorite(id, location) -> success

Logging:
core.debug(line) (possible in async calls)
^ Always printed to stderr and logfile (print() is redirected here)
core.log(line) (possible in async calls)
core.log(loglevel, line) (possible in async calls)
^ loglevel one of "error", "action", "info", "verbose"

Settings:
core.setting_set(name, value)
core.setting_get(name) -> string or nil (possible in async calls)
core.setting_setbool(name, value)
core.setting_getbool(name) -> bool or nil (possible in async calls)
core.setting_save() -> nil, save all settings to config file

Worlds:
core.get_worlds() -> list of worlds (possible in async calls)
^ returns {
	[1] = {
	path   = <full path to world>,
	name   = <name of world>,
	gameid = <gameid of world>,
	},
}
core.create_world(worldname, gameid)
core.delete_world(index)

Helpers:
core.get_us_time()
^ returns time with microsecond precision
core.gettext(string) -> string
^ look up the translation of a string in the gettext message catalog
fgettext_ne(string, ...)
^ call core.gettext(string), replace "$1"..."$9" with the given
^ extra arguments and return the result
fgettext(string, ...) -> string
^ same as fgettext_ne(), but calls core.formspec_escape before returning result
core.parse_json(string[, nullvalue]) -> something (possible in async calls)
^ see core.parse_json (lua_api.txt)
dump(obj, dumped={})
^ Return object serialized as a string
string:split(separator)
^ eg. string:split("a,b", ",") == {"a","b"}
string:trim()
^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
core.is_yes(arg) (possible in async calls)
^ returns whether arg can be interpreted as yes
minetest.encode_base64(string) (possible in async calls)
^ Encodes a string in base64.
minetest.decode_base64(string) (possible in async calls)
^ Decodes a string encoded in base64.

Version compat:
core.get_min_supp_proto()
^ returns the minimum supported network protocol version
core.get_max_supp_proto()
^ returns the maximum supported network protocol version

Async:
core.handle_async(async_job,parameters,finished)
^ execute a function asynchronously
^ async_job is a function receiving one parameter and returning one parameter
^ parameters parameter table passed to async_job
^ finished function to be called once async_job has finished
^    the result of async_job is passed to this function

Limitations of Async operations
 -No access to global lua variables, don't even try
 -Limited set of available functions
	e.g. No access to functions modifying menu like core.start,core.close,
	core.file_open_dialog
			

Class reference
----------------
Settings: see lua_api.txt
04 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// Modified by Mustapha T.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#include "guiEditBoxWithScrollbar.h"

#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IGUIFont.h"
#include "IVideoDriver.h"
#include "rect.h"
#include "porting.h"
#include "Keycodes.h"

/*
todo:
optional scrollbars [done]
ctrl+left/right to select word
double click/ctrl click: word select + drag to select whole words, triple click to select line
optional? dragging selected text
numerical
*/


//! constructor
GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t* text, bool border,
	IGUIEnvironment* environment, IGUIElement* parent, s32 id,
	const core::rect<s32>& rectangle, bool writable, bool has_vscrollbar)
	: IGUIEditBox(environment, parent, id, rectangle), m_mouse_marking(false),
	m_border(border), m_background(true), m_override_color_enabled(false), m_mark_begin(0), m_mark_end(0),
	m_override_color(video::SColor(101, 255, 255, 255)), m_override_font(0), m_last_break_font(0),
	m_operator(0), m_blink_start_time(0), m_cursor_pos(0), m_hscroll_pos(0), m_vscroll_pos(0), m_max(0),
	m_word_wrap(false), m_multiline(false), m_autoscroll(true), m_passwordbox(false),
	m_passwordchar(L'*'), m_halign(EGUIA_UPPERLEFT), m_valign(EGUIA_CENTER),
	m_current_text_rect(0, 0, 1, 1), m_frame_rect(rectangle),
	m_scrollbar_width(0), m_vscrollbar(NULL), m_writable(writable),
	m_bg_color_used(false)
{
#ifdef _DEBUG
	setDebugName("GUIEditBoxWithScrollBar");
#endif


	Text = text;

	if (Environment)
		m_operator = Environment->getOSOperator();

	if (m_operator)
		m_operator->grab();

	// this element can be tabbed to
	setTabStop(true);
	setTabOrder(-1);

	if (has_vscrollbar) {
		createVScrollBar();
	}

	calculateFrameRect();
	breakText();

	calculateScrollPos();
	setWritable(writable);
}


//! destructor
GUIEditBoxWithScrollBar::~GUIEditBoxWithScrollBar()
{
	if (m_override_font)
		m_override_font->drop();

	if (m_operator)
		m_operator->drop();

	if (m_vscrollbar)
		m_vscrollbar->drop();
}


//! Sets another skin independent font.
void GUIEditBoxWithScrollBar::setOverrideFont(IGUIFont* font)
{
	if (m_override_font == font)
		return;

	if (m_override_font)
		m_override_font->drop();

	m_override_font = font;

	if (m_override_font)
		m_override_font->grab();

	breakText();
}

//! Gets the override font (if any)
IGUIFont * GUIEditBoxWithScrollBar::getOverrideFont() const
{
	return m_override_font;
}

//! Get the font which is used right now for drawing
IGUIFont* GUIEditBoxWithScrollBar::getActiveFont() const
{
	if (m_override_font)
		return m_override_font;
	IGUISkin* skin = Environment->getSkin();
	if (skin)
		return skin->getFont();
	return 0;
}

//! Sets another color for the text.
void GUIEditBoxWithScrollBar::setOverrideColor(video::SColor color)
{
	m_override_color = color;
	m_override_color_enabled = true;
}


video::SColor GUIEditBoxWithScrollBar::getOverrideColor() const
{
	return m_override_color;
}


//! Turns the border on or off
void GUIEditBoxWithScrollBar::setDrawBorder(bool border)
{
	m_border = border;
}

//! Sets whether to draw the background
void GUIEditBoxWithScrollBar::setDrawBackground(bool draw)
{
	m_background = draw;
}

//! Sets if the text should use the overide color or the color in the gui skin.
void GUIEditBoxWithScrollBar::enableOverrideColor(bool enable)
{
	m_override_color_enabled = enable;
}

bool GUIEditBoxWithScrollBar::isOverrideColorEnabled() const
{
	return m_override_color_enabled;
}

//! Enables or disables word wrap
void GUIEditBoxWithScrollBar::setWordWrap(bool enable)
{
	m_word_wrap = enable;
	breakText();
}


void GUIEditBoxWithScrollBar::updateAbsolutePosition()
{
	core::rect<s32> old_absolute_rect(AbsoluteRect);
	IGUIElement::updateAbsolutePosition();
	if (old_absolute_rect != AbsoluteRect) {
		calculateFrameRect();
		breakText();
		calculateScrollPos();
	}
}

//! Checks if word wrap is enabled
bool GUIEditBoxWithScrollBar::isWordWrapEnabled() const
{
	return m_word_wrap;
}


//! Enables or disables newlines.
void GUIEditBoxWithScrollBar::setMultiLine(bool enable)
{
	m_multiline = enable;
}


//! Checks if multi line editing is enabled
bool GUIEditBoxWithScrollBar::isMultiLineEnabled() const
{
	return m_multiline;
}


void GUIEditBoxWithScrollBar::setPasswordBox(bool password_box, wchar_t password_char)
{
	m_passwordbox = password_box;
	if (m_passwordbox) {
		m_passwordchar = password_char;
		setMultiLine(false);
		setWordWrap(false);
		m_broken_text.clear();
	}
}


bool GUIEditBoxWithScrollBar::isPasswordBox() const
{
	return m_passwordbox;
}


//! Sets text justification
void GUIEditBoxWithScrollBar::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical)
{
	m_halign = horizontal;
	m_valign = vertical;
}


//! called if an event happened.
bool GUIEditBoxWithScrollBar::OnEvent(const SEvent& event)
{
	if (isEnabled()) {
		switch (event.EventType)
		{
		case EET_GUI_EVENT:
			if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) {
				if (event.GUIEvent.Caller == this) {
					m_mouse_marking = false;
					setTextMarkers(0, 0);
				}
			}
			break;
		case EET_KEY_INPUT_EVENT:
			if (processKey(event))
				return true;
			break;
		case EET_MOUSE_INPUT_EVENT:
			if (processMouse(event))
				return true;
			break;
		default:
			break;
		}
	}

	return IGUIElement::OnEvent(event);
}


bool GUIEditBoxWithScrollBar::processKey(const SEvent& event)
{
	if (!m_writable) {
		return false;
	}

	if (!event.KeyInput.PressedDown)
		return false;

	bool text_changed = false;
	s32 new_mark_begin = m_mark_begin;
	s32 new_mark_end = m_mark_end;

	// control shortcut handling

	if (event.KeyInput.Control) {

		// german backlash '\' entered with control + '?'
		if (event.KeyInput.Char == '\\') {
			inputChar(event.KeyInput.Char);
			return true;
		}

		switch (event.KeyInput.Key) {
		case KEY_KEY_A:
			// select all
			new_mark_begin = 0;
			new_mark_end = Text.size();
			break;
		case KEY_KEY_C:
			// copy to clipboard
			if (!m_passwordbox && m_operator && m_mark_begin != m_mark_end)
			{
				const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
				const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;

				core::stringc s;
				s = Text.subString(realmbgn, realmend - realmbgn).c_str();
				m_operator->copyToClipboard(s.c_str());
			}
			break;
		case KEY_KEY_X:
			// cut to the clipboard
			if (!m_passwordbox && m_operator && m_mark_begin != m_mark_end) {
				const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
				const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;

				// copy
				core::stringc sc;
				sc = Text.subString(realmbgn, realmend - realmbgn).c_str();
				m_operator->copyToClipboard(sc.c_str());

				if (isEnabled())
				{
					// delete
					core::stringw s;
					s = Text.subString(0, realmbgn);
					s.append(Text.subString(realmend, Text.size() - realmend));
					Text = s;

					m_cursor_pos = realmbgn;
					new_mark_begin = 0;
					new_mark_end = 0;
					text_changed = true;
				}
			}
			break;
		case KEY_KEY_V:
			if (!isEnabled())
				break;

			// paste from the clipboard
			if (m_operator) {
				const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
				const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;

				// add new character
				const c8* p = m_operator->getTextFromClipboard();
				if (p) {
					if (m_mark_begin == m_mark_end) {
						// insert text
						core::stringw s = Text.subString(0, m_cursor_pos);
						s.append(p);
						s.append(Text.subString(m_cursor_pos, Text.size() - m_cursor_pos));

						if (!m_max || s.size() <= m_max) // thx to Fish FH for fix
						{
							Text = s;
							s = p;
							m_cursor_pos += s.size();
						}
					} else {
						// replace text

						core::stringw s = Text.subString(0, realmbgn);
						s.append(p);
						s.append(Text.subString(realmend, Text.size() - realmend));

						if (!m_max || s.size() <= m_max)  // thx to Fish FH for fix
						{
							Text = s;
							s = p;
							m_cursor_pos = realmbgn + s.size();
						}
					}
				}

				new_mark_begin = 0;
				new_mark_end = 0;
				text_changed = true;
			}
			break;
		case KEY_HOME:
			// move/highlight to start of text
			if (event.KeyInput.Shift) {
				new_mark_end = m_cursor_pos;
				new_mark_begin = 0;
				m_cursor_pos = 0;
			} else {
				m_cursor_pos = 0;
				new_mark_begin = 0;
				new_mark_end = 0;
			}
			break;
		case KEY_END:
			// move/highlight to end of text
			if (event.KeyInput.Shift) {
				new_mark_begin = m_cursor_pos;
				new_mark_end = Text.size();
				m_cursor_pos = 0;
			} else {
				m_cursor_pos = Text.size();
				new_mark_begin = 0;
				new_mark_end = 0;
			}
			break;
		default:
			return false;
		}
	}
	// default keyboard handling
	else
		switch (event.KeyInput.Key)	{
		case KEY_END:
		{
			s32 p = Text.size();
			if (m_word_wrap || m_multiline) {
				p = getLineFromPos(m_cursor_pos);
				p = m_broken_text_positions[p] + (s32)m_broken_text[p].size();
				if (p > 0 && (Text[p - 1] == L'\r' || Text[p - 1] == L'\n'))
					p -= 1;
			}

			if (event.KeyInput.Shift) {
				if (m_mark_begin == m_mark_end)
					new_mark_begin = m_cursor_pos;

				new_mark_end = p;
			} else {
				new_mark_begin = 0;
				new_mark_end = 0;
			}
			m_cursor_pos = p;
			m_blink_start_time = porting::getTimeMs();
		}
		break;
		case KEY_HOME:
		{

			s32 p = 0;
			if (m_word_wrap || m_multiline) {
				p = getLineFromPos(m_cursor_pos);
				p = m_broken_text_positions[p];
			}

			if (event.KeyInput.Shift) {
				if (m_mark_begin == m_mark_end)
					new_mark_begin = m_cursor_pos;
				new_mark_end = p;
			} else {
				new_mark_begin = 0;
				new_mark_end = 0;
			}
			m_cursor_pos = p;
			m_blink_start_time = porting::getTimeMs();
		}
		break;
		case KEY_RETURN:
			if (m_multiline) {
				inputChar(L'\n');
			} else {
				calculateScrollPos();
				sendGuiEvent(EGET_EDITBOX_ENTER);
			}
			return true;
		case KEY_LEFT:

			if (event.KeyInput.Shift) {
				if (m_cursor_pos > 0) {
					if (m_mark_begin == m_mark_end)
						new_mark_begin = m_cursor_pos;

					new_mark_end = m_cursor_pos - 1;
				}
			} else {
				new_mark_begin = 0;
				new_mark_end = 0;
			}

			if (m_cursor_pos > 0)
				m_cursor_pos--;
			m_blink_start_time = porting::getTimeMs();
			break;

		case KEY_RIGHT:
			if (event.KeyInput.Shift) {
				if (Text.size() > (u32)m_cursor_pos) {
					if (m_mark_begin == m_mark_end)
						new_mark_begin = m_cursor_pos;

					new_mark_end = m_cursor_pos + 1;
				}
			} else {
				new_mark_begin = 0;
				new_mark_end = 0;
			}

			if (Text.size() > (u32)m_cursor_pos)
				m_cursor_pos++;
			m_blink_start_time = porting::getTimeMs();
			break;
		case KEY_UP:
			if (m_multiline || (m_word_wrap && m_broken_text.size() > 1)) {
				s32 lineNo = getLineFromPos(m_cursor_pos);
				s32 mb = (m_mark_begin == m_mark_end) ? m_cursor_pos : (m_mark_begin > m_mark_end ? m_mark_begin : m_mark_end);
				if (lineNo > 0)	{
					s32 cp = m_cursor_pos - m_broken_text_positions[lineNo];
					if ((s32)m_broken_text[lineNo - 1].size() < cp)
						m_cursor_pos = m_broken_text_positions[lineNo - 1] + core::max_((u32)1, m_broken_text[lineNo - 1].size()) - 1;
					else
						m_cursor_pos = m_broken_text_positions[lineNo - 1] + cp;
				}

				if (event.KeyInput.Shift) {
					new_mark_begin = mb;
					new_mark_end = m_cursor_pos;
				} else {
					new_mark_begin = 0;
					new_mark_end = 0;
				}
			} else {
				return false;
			}
			break;
		case KEY_DOWN:
			if (m_multiline || (m_word_wrap && m_broken_text.size() > 1)) {
				s32 lineNo = getLineFromPos(m_cursor_pos);
				s32 mb = (m_mark_begin == m_mark_end) ? m_cursor_pos : (m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end);
				if (lineNo < (s32)m_broken_text.size() - 1)
				{
					s32 cp = m_cursor_pos - m_broken_text_positions[lineNo];
					if ((s32)m_broken_text[lineNo + 1].size() < cp)
						m_cursor_pos = m_broken_text_positions[lineNo + 1] + core::max_((u32)1, m_broken_text[lineNo + 1].size()) - 1;
					else
						m_cursor_pos = m_broken_text_positions[lineNo + 1] + cp;
				}

				if (event.KeyInput.Shift) {
					new_mark_begin = mb;
					new_mark_end = m_cursor_pos;
				} else {
					new_mark_begin = 0;
					new_mark_end = 0;
				}

			} else {
				return false;
			}
			break;

		case KEY_BACK:
			if (!isEnabled())
				break;

			if (Text.size()) {
				core::stringw s;

				if (m_mark_begin != m_mark_end) {
					// delete marked text
					const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
					const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;

					s = Text.subString(0, realmbgn);
					s.append(Text.subString(realmend, Text.size() - realmend));
					Text = s;

					m_cursor_pos = realmbgn;
				} else {
					// delete text behind cursor
					if (m_cursor_pos > 0)
						s = Text.subString(0, m_cursor_pos - 1);
					else
						s = L"";
					s.append(Text.subString(m_cursor_pos, Text.size() - m_cursor_pos));