2
0

ElementFormControlTextArea.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include "ElementFormControlTextArea.h"
  2. #include "ElementFormControl.h"
  3. #include <RmlUi/Core/Elements/ElementFormControl.h>
  4. #include <RmlUi/Lua/Utilities.h>
  5. namespace Rml {
  6. namespace Lua {
  7. // methods
  8. int ElementFormControlTextAreaSelect(lua_State* /*L*/, ElementFormControlTextArea* obj)
  9. {
  10. obj->Select();
  11. return 0;
  12. }
  13. int ElementFormControlTextAreaSetSelection(lua_State* L, ElementFormControlTextArea* obj)
  14. {
  15. int start = (int)GetIndex(L, 1);
  16. int end = (int)GetIndex(L, 2);
  17. obj->SetSelectionRange(start, end);
  18. return 0;
  19. }
  20. int ElementFormControlTextAreaGetSelection(lua_State* L, ElementFormControlTextArea* obj)
  21. {
  22. int selection_start = 0, selection_end = 0;
  23. String selected_text;
  24. obj->GetSelection(&selection_start, &selection_end, &selected_text);
  25. PushIndex(L, selection_start);
  26. PushIndex(L, selection_end);
  27. lua_pushstring(L, selected_text.c_str());
  28. return 3;
  29. }
  30. // getters
  31. int ElementFormControlTextAreaGetAttrcols(lua_State* L)
  32. {
  33. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  34. RMLUI_CHECK_OBJ(obj);
  35. lua_pushinteger(L, obj->GetNumColumns());
  36. return 1;
  37. }
  38. int ElementFormControlTextAreaGetAttrmaxlength(lua_State* L)
  39. {
  40. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  41. RMLUI_CHECK_OBJ(obj);
  42. lua_pushinteger(L, obj->GetMaxLength());
  43. return 1;
  44. }
  45. int ElementFormControlTextAreaGetAttrrows(lua_State* L)
  46. {
  47. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  48. RMLUI_CHECK_OBJ(obj);
  49. lua_pushinteger(L, obj->GetNumRows());
  50. return 1;
  51. }
  52. int ElementFormControlTextAreaGetAttrwordwrap(lua_State* L)
  53. {
  54. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  55. RMLUI_CHECK_OBJ(obj);
  56. lua_pushboolean(L, obj->GetWordWrap());
  57. return 1;
  58. }
  59. // setters
  60. int ElementFormControlTextAreaSetAttrcols(lua_State* L)
  61. {
  62. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  63. RMLUI_CHECK_OBJ(obj);
  64. int cols = (int)luaL_checkinteger(L, 2);
  65. obj->SetNumColumns(cols);
  66. return 0;
  67. }
  68. int ElementFormControlTextAreaSetAttrmaxlength(lua_State* L)
  69. {
  70. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  71. RMLUI_CHECK_OBJ(obj);
  72. int ml = (int)luaL_checkinteger(L, 2);
  73. obj->SetMaxLength(ml);
  74. return 0;
  75. }
  76. int ElementFormControlTextAreaSetAttrrows(lua_State* L)
  77. {
  78. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  79. RMLUI_CHECK_OBJ(obj);
  80. int rows = (int)luaL_checkinteger(L, 2);
  81. obj->SetNumRows(rows);
  82. return 0;
  83. }
  84. int ElementFormControlTextAreaSetAttrwordwrap(lua_State* L)
  85. {
  86. ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L, 1);
  87. RMLUI_CHECK_OBJ(obj);
  88. bool ww = RMLUI_CHECK_BOOL(L, 2);
  89. obj->SetWordWrap(ww);
  90. return 0;
  91. }
  92. RegType<ElementFormControlTextArea> ElementFormControlTextAreaMethods[] = {
  93. RMLUI_LUAMETHOD(ElementFormControlTextArea, Select),
  94. RMLUI_LUAMETHOD(ElementFormControlTextArea, SetSelection),
  95. RMLUI_LUAMETHOD(ElementFormControlTextArea, GetSelection),
  96. {nullptr, nullptr},
  97. };
  98. luaL_Reg ElementFormControlTextAreaGetters[] = {
  99. RMLUI_LUAGETTER(ElementFormControlTextArea, cols),
  100. RMLUI_LUAGETTER(ElementFormControlTextArea, maxlength),
  101. RMLUI_LUAGETTER(ElementFormControlTextArea, rows),
  102. RMLUI_LUAGETTER(ElementFormControlTextArea, wordwrap),
  103. {nullptr, nullptr},
  104. };
  105. luaL_Reg ElementFormControlTextAreaSetters[] = {
  106. RMLUI_LUASETTER(ElementFormControlTextArea, cols),
  107. RMLUI_LUASETTER(ElementFormControlTextArea, maxlength),
  108. RMLUI_LUASETTER(ElementFormControlTextArea, rows),
  109. RMLUI_LUASETTER(ElementFormControlTextArea, wordwrap),
  110. {nullptr, nullptr},
  111. };
  112. template <>
  113. void ExtraInit<ElementFormControlTextArea>(lua_State* L, int metatable_index)
  114. {
  115. ExtraInit<ElementFormControl>(L, metatable_index);
  116. LuaType<ElementFormControl>::_regfunctions(L, metatable_index, metatable_index - 1);
  117. AddTypeToElementAsTable<ElementFormControlTextArea>(L);
  118. }
  119. RMLUI_LUATYPE_DEFINE(ElementFormControlTextArea)
  120. } // namespace Lua
  121. } // namespace Rml