ElementFormControlInput.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "precompiled.h"
  28. #include "ElementFormControlInput.h"
  29. #include <Rocket/Controls/ElementFormControl.h>
  30. #include "ElementFormControl.h"
  31. #include <Rocket/Core/Lua/Utilities.h>
  32. namespace Rocket {
  33. namespace Controls {
  34. namespace Lua {
  35. //getters
  36. int ElementFormControlInputGetAttrchecked(lua_State* L)
  37. {
  38. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  39. LUACHECKOBJ(obj);
  40. lua_pushboolean(L,obj->HasAttribute("checked"));
  41. return 1;
  42. }
  43. int ElementFormControlInputGetAttrmaxlength(lua_State* L)
  44. {
  45. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  46. LUACHECKOBJ(obj);
  47. lua_pushinteger(L,obj->GetAttribute<int>("maxlength",-1));
  48. return 1;
  49. }
  50. int ElementFormControlInputGetAttrsize(lua_State* L)
  51. {
  52. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  53. LUACHECKOBJ(obj);
  54. lua_pushinteger(L,obj->GetAttribute<int>("size",20));
  55. return 1;
  56. }
  57. int ElementFormControlInputGetAttrmax(lua_State* L)
  58. {
  59. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  60. LUACHECKOBJ(obj);
  61. lua_pushinteger(L,obj->GetAttribute<int>("max",100));
  62. return 1;
  63. }
  64. int ElementFormControlInputGetAttrmin(lua_State* L)
  65. {
  66. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  67. LUACHECKOBJ(obj);
  68. lua_pushinteger(L,obj->GetAttribute<int>("min",0));
  69. return 1;
  70. }
  71. int ElementFormControlInputGetAttrstep(lua_State* L)
  72. {
  73. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  74. LUACHECKOBJ(obj);
  75. lua_pushinteger(L,obj->GetAttribute<int>("step",1));
  76. return 1;
  77. }
  78. //setters
  79. int ElementFormControlInputSetAttrchecked(lua_State* L)
  80. {
  81. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  82. LUACHECKOBJ(obj);
  83. bool checked = CHECK_BOOL(L,2);
  84. if(checked)
  85. obj->SetAttribute("checked",true);
  86. else
  87. obj->RemoveAttribute("checked");
  88. return 0;
  89. }
  90. int ElementFormControlInputSetAttrmaxlength(lua_State* L)
  91. {
  92. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  93. LUACHECKOBJ(obj);
  94. int maxlength = luaL_checkinteger(L,2);
  95. obj->SetAttribute("maxlength",maxlength);
  96. return 0;
  97. }
  98. int ElementFormControlInputSetAttrsize(lua_State* L)
  99. {
  100. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  101. LUACHECKOBJ(obj);
  102. int size = luaL_checkinteger(L,2);
  103. obj->SetAttribute("size",size);
  104. return 0;
  105. }
  106. int ElementFormControlInputSetAttrmax(lua_State* L)
  107. {
  108. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  109. LUACHECKOBJ(obj);
  110. int max = luaL_checkinteger(L,2);
  111. obj->SetAttribute("max",max);
  112. return 0;
  113. }
  114. int ElementFormControlInputSetAttrmin(lua_State* L)
  115. {
  116. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  117. LUACHECKOBJ(obj);
  118. int min = luaL_checkinteger(L,2);
  119. obj->SetAttribute("min",min);
  120. return 0;
  121. }
  122. int ElementFormControlInputSetAttrstep(lua_State* L)
  123. {
  124. ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
  125. LUACHECKOBJ(obj);
  126. int step = luaL_checkinteger(L,2);
  127. obj->SetAttribute("step",step);
  128. return 0;
  129. }
  130. Rocket::Core::Lua::RegType<ElementFormControlInput> ElementFormControlInputMethods[] =
  131. {
  132. {NULL,NULL},
  133. };
  134. luaL_Reg ElementFormControlInputGetters[] =
  135. {
  136. LUAGETTER(ElementFormControlInput,checked)
  137. LUAGETTER(ElementFormControlInput,maxlength)
  138. LUAGETTER(ElementFormControlInput,size)
  139. LUAGETTER(ElementFormControlInput,max)
  140. LUAGETTER(ElementFormControlInput,min)
  141. LUAGETTER(ElementFormControlInput,step)
  142. {NULL,NULL},
  143. };
  144. luaL_Reg ElementFormControlInputSetters[] =
  145. {
  146. LUASETTER(ElementFormControlInput,checked)
  147. LUASETTER(ElementFormControlInput,maxlength)
  148. LUASETTER(ElementFormControlInput,size)
  149. LUASETTER(ElementFormControlInput,max)
  150. LUASETTER(ElementFormControlInput,min)
  151. LUASETTER(ElementFormControlInput,step)
  152. {NULL,NULL},
  153. };
  154. }
  155. }
  156. }
  157. namespace Rocket {
  158. namespace Core {
  159. namespace Lua {
  160. template<> void ExtraInit<Rocket::Controls::ElementFormControlInput>(lua_State* L, int metatable_index)
  161. {
  162. ExtraInit<Rocket::Controls::ElementFormControl>(L,metatable_index);
  163. LuaType<Rocket::Controls::ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
  164. AddTypeToElementAsTable<Rocket::Controls::ElementFormControlInput>(L);
  165. }
  166. using Rocket::Controls::ElementFormControlInput;
  167. LUACONTROLSTYPEDEFINE(ElementFormControlInput,true)
  168. }
  169. }
  170. }