ElementFormControlInput.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. //getters
  35. int ElementFormControlInputGetAttrchecked(lua_State* L)
  36. {
  37. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  38. RMLUI_CHECK_OBJ(obj);
  39. lua_pushboolean(L,obj->HasAttribute("checked"));
  40. return 1;
  41. }
  42. int ElementFormControlInputGetAttrmaxlength(lua_State* L)
  43. {
  44. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  45. RMLUI_CHECK_OBJ(obj);
  46. lua_pushinteger(L,obj->GetAttribute<int>("maxlength",-1));
  47. return 1;
  48. }
  49. int ElementFormControlInputGetAttrsize(lua_State* L)
  50. {
  51. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  52. RMLUI_CHECK_OBJ(obj);
  53. lua_pushinteger(L,obj->GetAttribute<int>("size",20));
  54. return 1;
  55. }
  56. int ElementFormControlInputGetAttrmax(lua_State* L)
  57. {
  58. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  59. RMLUI_CHECK_OBJ(obj);
  60. lua_pushinteger(L,obj->GetAttribute<int>("max",100));
  61. return 1;
  62. }
  63. int ElementFormControlInputGetAttrmin(lua_State* L)
  64. {
  65. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  66. RMLUI_CHECK_OBJ(obj);
  67. lua_pushinteger(L,obj->GetAttribute<int>("min",0));
  68. return 1;
  69. }
  70. int ElementFormControlInputGetAttrstep(lua_State* L)
  71. {
  72. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  73. RMLUI_CHECK_OBJ(obj);
  74. lua_pushinteger(L,obj->GetAttribute<int>("step",1));
  75. return 1;
  76. }
  77. //setters
  78. int ElementFormControlInputSetAttrchecked(lua_State* L)
  79. {
  80. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  81. RMLUI_CHECK_OBJ(obj);
  82. bool checked = RMLUI_CHECK_BOOL(L,2);
  83. if(checked)
  84. obj->SetAttribute("checked",true);
  85. else
  86. obj->RemoveAttribute("checked");
  87. return 0;
  88. }
  89. int ElementFormControlInputSetAttrmaxlength(lua_State* L)
  90. {
  91. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  92. RMLUI_CHECK_OBJ(obj);
  93. int maxlength = (int)luaL_checkinteger(L,2);
  94. obj->SetAttribute("maxlength",maxlength);
  95. return 0;
  96. }
  97. int ElementFormControlInputSetAttrsize(lua_State* L)
  98. {
  99. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  100. RMLUI_CHECK_OBJ(obj);
  101. int size = (int)luaL_checkinteger(L,2);
  102. obj->SetAttribute("size",size);
  103. return 0;
  104. }
  105. int ElementFormControlInputSetAttrmax(lua_State* L)
  106. {
  107. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  108. RMLUI_CHECK_OBJ(obj);
  109. int max = (int)luaL_checkinteger(L,2);
  110. obj->SetAttribute("max",max);
  111. return 0;
  112. }
  113. int ElementFormControlInputSetAttrmin(lua_State* L)
  114. {
  115. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  116. RMLUI_CHECK_OBJ(obj);
  117. int min = (int)luaL_checkinteger(L,2);
  118. obj->SetAttribute("min",min);
  119. return 0;
  120. }
  121. int ElementFormControlInputSetAttrstep(lua_State* L)
  122. {
  123. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  124. RMLUI_CHECK_OBJ(obj);
  125. int step = (int)luaL_checkinteger(L,2);
  126. obj->SetAttribute("step",step);
  127. return 0;
  128. }
  129. RegType<ElementFormControlInput> ElementFormControlInputMethods[] =
  130. {
  131. {nullptr,nullptr},
  132. };
  133. luaL_Reg ElementFormControlInputGetters[] =
  134. {
  135. RMLUI_LUAGETTER(ElementFormControlInput,checked)
  136. RMLUI_LUAGETTER(ElementFormControlInput,maxlength)
  137. RMLUI_LUAGETTER(ElementFormControlInput,size)
  138. RMLUI_LUAGETTER(ElementFormControlInput,max)
  139. RMLUI_LUAGETTER(ElementFormControlInput,min)
  140. RMLUI_LUAGETTER(ElementFormControlInput,step)
  141. {nullptr,nullptr},
  142. };
  143. luaL_Reg ElementFormControlInputSetters[] =
  144. {
  145. RMLUI_LUASETTER(ElementFormControlInput,checked)
  146. RMLUI_LUASETTER(ElementFormControlInput,maxlength)
  147. RMLUI_LUASETTER(ElementFormControlInput,size)
  148. RMLUI_LUASETTER(ElementFormControlInput,max)
  149. RMLUI_LUASETTER(ElementFormControlInput,min)
  150. RMLUI_LUASETTER(ElementFormControlInput,step)
  151. {nullptr,nullptr},
  152. };
  153. template<> void ExtraInit<ElementFormControlInput>(lua_State* L, int metatable_index)
  154. {
  155. ExtraInit<ElementFormControl>(L,metatable_index);
  156. LuaType<ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
  157. AddTypeToElementAsTable<ElementFormControlInput>(L);
  158. }
  159. RMLUI_LUATYPE_DEFINE(ElementFormControlInput)
  160. } // namespace Lua
  161. } // namespace Rml