ElementFormControlInput.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 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 "ElementFormControlInput.h"
  29. #include <RmlUi/Core/Elements/ElementFormControl.h>
  30. #include "ElementFormControl.h"
  31. #include <RmlUi/Lua/Utilities.h>
  32. namespace Rml {
  33. namespace Lua {
  34. //methods
  35. int ElementFormControlInputSelect(lua_State* /*L*/, ElementFormControlInput* obj)
  36. {
  37. obj->Select();
  38. return 0;
  39. }
  40. int ElementFormControlInputSetSelection(lua_State* L, ElementFormControlInput* obj)
  41. {
  42. int start = (int)luaL_checkinteger(L, 1);
  43. int end = (int)luaL_checkinteger(L, 2);
  44. obj->SetSelectionRange(start, end);
  45. return 0;
  46. }
  47. int ElementFormControlInputGetSelection(lua_State* L, ElementFormControlInput* obj)
  48. {
  49. int selection_start = 0, selection_end = 0;
  50. String selected_text;
  51. obj->GetSelection(&selection_start, &selection_end, &selected_text);
  52. lua_pushinteger(L, selection_start);
  53. lua_pushinteger(L, selection_end);
  54. lua_pushstring(L, selected_text.c_str());
  55. return 3;
  56. }
  57. //getters
  58. int ElementFormControlInputGetAttrchecked(lua_State* L)
  59. {
  60. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  61. RMLUI_CHECK_OBJ(obj);
  62. lua_pushboolean(L,obj->HasAttribute("checked"));
  63. return 1;
  64. }
  65. int ElementFormControlInputGetAttrmaxlength(lua_State* L)
  66. {
  67. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  68. RMLUI_CHECK_OBJ(obj);
  69. lua_pushinteger(L,obj->GetAttribute<int>("maxlength",-1));
  70. return 1;
  71. }
  72. int ElementFormControlInputGetAttrsize(lua_State* L)
  73. {
  74. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  75. RMLUI_CHECK_OBJ(obj);
  76. lua_pushinteger(L,obj->GetAttribute<int>("size",20));
  77. return 1;
  78. }
  79. int ElementFormControlInputGetAttrmax(lua_State* L)
  80. {
  81. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  82. RMLUI_CHECK_OBJ(obj);
  83. lua_pushinteger(L,obj->GetAttribute<int>("max",100));
  84. return 1;
  85. }
  86. int ElementFormControlInputGetAttrmin(lua_State* L)
  87. {
  88. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  89. RMLUI_CHECK_OBJ(obj);
  90. lua_pushinteger(L,obj->GetAttribute<int>("min",0));
  91. return 1;
  92. }
  93. int ElementFormControlInputGetAttrstep(lua_State* L)
  94. {
  95. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  96. RMLUI_CHECK_OBJ(obj);
  97. lua_pushinteger(L,obj->GetAttribute<int>("step",1));
  98. return 1;
  99. }
  100. //setters
  101. int ElementFormControlInputSetAttrchecked(lua_State* L)
  102. {
  103. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  104. RMLUI_CHECK_OBJ(obj);
  105. bool checked = RMLUI_CHECK_BOOL(L,2);
  106. if(checked)
  107. obj->SetAttribute("checked",true);
  108. else
  109. obj->RemoveAttribute("checked");
  110. return 0;
  111. }
  112. int ElementFormControlInputSetAttrmaxlength(lua_State* L)
  113. {
  114. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  115. RMLUI_CHECK_OBJ(obj);
  116. int maxlength = (int)luaL_checkinteger(L,2);
  117. obj->SetAttribute("maxlength",maxlength);
  118. return 0;
  119. }
  120. int ElementFormControlInputSetAttrsize(lua_State* L)
  121. {
  122. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  123. RMLUI_CHECK_OBJ(obj);
  124. int size = (int)luaL_checkinteger(L,2);
  125. obj->SetAttribute("size",size);
  126. return 0;
  127. }
  128. int ElementFormControlInputSetAttrmax(lua_State* L)
  129. {
  130. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  131. RMLUI_CHECK_OBJ(obj);
  132. int max = (int)luaL_checkinteger(L,2);
  133. obj->SetAttribute("max",max);
  134. return 0;
  135. }
  136. int ElementFormControlInputSetAttrmin(lua_State* L)
  137. {
  138. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  139. RMLUI_CHECK_OBJ(obj);
  140. int min = (int)luaL_checkinteger(L,2);
  141. obj->SetAttribute("min",min);
  142. return 0;
  143. }
  144. int ElementFormControlInputSetAttrstep(lua_State* L)
  145. {
  146. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  147. RMLUI_CHECK_OBJ(obj);
  148. int step = (int)luaL_checkinteger(L,2);
  149. obj->SetAttribute("step",step);
  150. return 0;
  151. }
  152. RegType<ElementFormControlInput> ElementFormControlInputMethods[] =
  153. {
  154. RMLUI_LUAMETHOD(ElementFormControlInput,Select)
  155. RMLUI_LUAMETHOD(ElementFormControlInput,SetSelection)
  156. RMLUI_LUAMETHOD(ElementFormControlInput,GetSelection)
  157. {nullptr,nullptr},
  158. };
  159. luaL_Reg ElementFormControlInputGetters[] =
  160. {
  161. RMLUI_LUAGETTER(ElementFormControlInput,checked)
  162. RMLUI_LUAGETTER(ElementFormControlInput,maxlength)
  163. RMLUI_LUAGETTER(ElementFormControlInput,size)
  164. RMLUI_LUAGETTER(ElementFormControlInput,max)
  165. RMLUI_LUAGETTER(ElementFormControlInput,min)
  166. RMLUI_LUAGETTER(ElementFormControlInput,step)
  167. {nullptr,nullptr},
  168. };
  169. luaL_Reg ElementFormControlInputSetters[] =
  170. {
  171. RMLUI_LUASETTER(ElementFormControlInput,checked)
  172. RMLUI_LUASETTER(ElementFormControlInput,maxlength)
  173. RMLUI_LUASETTER(ElementFormControlInput,size)
  174. RMLUI_LUASETTER(ElementFormControlInput,max)
  175. RMLUI_LUASETTER(ElementFormControlInput,min)
  176. RMLUI_LUASETTER(ElementFormControlInput,step)
  177. {nullptr,nullptr},
  178. };
  179. template<> void ExtraInit<ElementFormControlInput>(lua_State* L, int metatable_index)
  180. {
  181. ExtraInit<ElementFormControl>(L,metatable_index);
  182. LuaType<ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
  183. AddTypeToElementAsTable<ElementFormControlInput>(L);
  184. }
  185. RMLUI_LUATYPE_DEFINE(ElementFormControlInput)
  186. } // namespace Lua
  187. } // namespace Rml