ElementFormControlTextArea.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019-2023 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #include "ElementFormControlTextArea.h"
  29. #include "ElementFormControl.h"
  30. #include <RmlUi/Core/Elements/ElementFormControl.h>
  31. #include <RmlUi/Lua/Utilities.h>
  32. namespace Rml {
  33. namespace Lua {
  34. // methods
  35. int ElementFormControlTextAreaSelect(lua_State* /*L*/, ElementFormControlTextArea* obj)
  36. {
  37. obj->Select();
  38. return 0;
  39. }
  40. int ElementFormControlTextAreaSetSelection(lua_State* L, ElementFormControlTextArea* obj)
  41. {
  42. int start = (int)GetIndex(L, 1);
  43. int end = (int)GetIndex(L, 2);
  44. obj->SetSelectionRange(start, end);
  45. return 0;
  46. }
  47. int ElementFormControlTextAreaGetSelection(lua_State* L, ElementFormControlTextArea* obj)
  48. {
  49. int selection_start = 0, selection_end = 0;
  50. String selected_text;
  51. obj->GetSelection(&selection_start, &selection_end, &selected_text);
  52. PushIndex(L, selection_start);
  53. PushIndex(L, selection_end);
  54. lua_pushstring(L, selected_text.c_str());
  55. return 3;
  56. }
  57. // getters
  58. int ElementFormControlTextAreaGetAttrcols(lua_State* L)
  59. {
  60. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  61. RMLUI_CHECK_OBJ(obj);
  62. lua_pushinteger(L, obj->GetNumColumns());
  63. return 1;
  64. }
  65. int ElementFormControlTextAreaGetAttrmaxlength(lua_State* L)
  66. {
  67. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  68. RMLUI_CHECK_OBJ(obj);
  69. lua_pushinteger(L, obj->GetMaxLength());
  70. return 1;
  71. }
  72. int ElementFormControlTextAreaGetAttrrows(lua_State* L)
  73. {
  74. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  75. RMLUI_CHECK_OBJ(obj);
  76. lua_pushinteger(L, obj->GetNumRows());
  77. return 1;
  78. }
  79. int ElementFormControlTextAreaGetAttrwordwrap(lua_State* L)
  80. {
  81. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  82. RMLUI_CHECK_OBJ(obj);
  83. lua_pushboolean(L, obj->GetWordWrap());
  84. return 1;
  85. }
  86. // setters
  87. int ElementFormControlTextAreaSetAttrcols(lua_State* L)
  88. {
  89. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  90. RMLUI_CHECK_OBJ(obj);
  91. int cols = (int)luaL_checkinteger(L, 2);
  92. obj->SetNumColumns(cols);
  93. return 0;
  94. }
  95. int ElementFormControlTextAreaSetAttrmaxlength(lua_State* L)
  96. {
  97. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  98. RMLUI_CHECK_OBJ(obj);
  99. int ml = (int)luaL_checkinteger(L, 2);
  100. obj->SetMaxLength(ml);
  101. return 0;
  102. }
  103. int ElementFormControlTextAreaSetAttrrows(lua_State* L)
  104. {
  105. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  106. RMLUI_CHECK_OBJ(obj);
  107. int rows = (int)luaL_checkinteger(L, 2);
  108. obj->SetNumRows(rows);
  109. return 0;
  110. }
  111. int ElementFormControlTextAreaSetAttrwordwrap(lua_State* L)
  112. {
  113. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  114. RMLUI_CHECK_OBJ(obj);
  115. bool ww = RMLUI_CHECK_BOOL(L, 2);
  116. obj->SetWordWrap(ww);
  117. return 0;
  118. }
  119. RegType<ElementFormControlTextArea> ElementFormControlTextAreaMethods[] = {
  120. RMLUI_LUAMETHOD(ElementFormControlTextArea, Select),
  121. RMLUI_LUAMETHOD(ElementFormControlTextArea, SetSelection),
  122. RMLUI_LUAMETHOD(ElementFormControlTextArea, GetSelection),
  123. {nullptr, nullptr},
  124. };
  125. luaL_Reg ElementFormControlTextAreaGetters[] = {
  126. RMLUI_LUAGETTER(ElementFormControlTextArea, cols),
  127. RMLUI_LUAGETTER(ElementFormControlTextArea, maxlength),
  128. RMLUI_LUAGETTER(ElementFormControlTextArea, rows),
  129. RMLUI_LUAGETTER(ElementFormControlTextArea, wordwrap),
  130. {nullptr, nullptr},
  131. };
  132. luaL_Reg ElementFormControlTextAreaSetters[] = {
  133. RMLUI_LUASETTER(ElementFormControlTextArea, cols),
  134. RMLUI_LUASETTER(ElementFormControlTextArea, maxlength),
  135. RMLUI_LUASETTER(ElementFormControlTextArea, rows),
  136. RMLUI_LUASETTER(ElementFormControlTextArea, wordwrap),
  137. {nullptr, nullptr},
  138. };
  139. template <>
  140. void ExtraInit<ElementFormControlTextArea>(lua_State* L, int metatable_index)
  141. {
  142. ExtraInit<ElementFormControl>(L, metatable_index);
  143. LuaType<ElementFormControl>::_regfunctions(L, metatable_index, metatable_index - 1);
  144. AddTypeToElementAsTable<ElementFormControlTextArea>(L);
  145. }
  146. RMLUI_LUATYPE_DEFINE(ElementFormControlTextArea)
  147. } // namespace Lua
  148. } // namespace Rml