ElementFormControlInput.cpp 5.8 KB

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