ElementFormControlSelect.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 "ElementFormControlSelect.h"
  29. #include "SelectOptionsProxy.h"
  30. #include <Rocket/Controls/ElementFormControlSelect.h>
  31. #include <Rocket/Controls/ElementFormControl.h>
  32. #include <Rocket/Core/Element.h>
  33. #include "ElementFormControl.h"
  34. #include <Rocket/Core/Lua/Utilities.h>
  35. namespace Rocket {
  36. namespace Controls {
  37. namespace Lua {
  38. //methods
  39. int ElementFormControlSelectAdd(lua_State* L, ElementFormControlSelect* obj)
  40. {
  41. const char* rml = luaL_checkstring(L,1);
  42. const char* value = luaL_checkstring(L,2);
  43. int before = -1; //default
  44. if(lua_gettop(L) >= 3)
  45. before = luaL_checkint(L,3);
  46. int index = obj->Add(rml,value,before);
  47. lua_pushinteger(L,index);
  48. return 1;
  49. }
  50. int ElementFormControlSelectRemove(lua_State* L, ElementFormControlSelect* obj)
  51. {
  52. int index = luaL_checkint(L,1);
  53. obj->Remove(index);
  54. return 0;
  55. }
  56. //getters
  57. int ElementFormControlSelectGetAttroptions(lua_State* L)
  58. {
  59. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  60. LUACHECKOBJ(obj);
  61. SelectOptionsProxy* proxy = new SelectOptionsProxy();
  62. proxy->owner = obj;
  63. LuaType<SelectOptionsProxy>::push(L,proxy,true);
  64. return 1;
  65. }
  66. int ElementFormControlSelectGetAttrselection(lua_State* L)
  67. {
  68. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  69. LUACHECKOBJ(obj);
  70. int selection = obj->GetSelection();
  71. lua_pushinteger(L,selection);
  72. return 1;
  73. }
  74. //setter
  75. int ElementFormControlSelectSetAttrselection(lua_State* L)
  76. {
  77. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  78. LUACHECKOBJ(obj);
  79. int selection = luaL_checkint(L,2);
  80. obj->SetSelection(selection);
  81. return 0;
  82. }
  83. Rocket::Core::Lua::RegType<ElementFormControlSelect> ElementFormControlSelectMethods[] =
  84. {
  85. LUAMETHOD(ElementFormControlSelect,Add)
  86. LUAMETHOD(ElementFormControlSelect,Remove)
  87. { NULL, NULL },
  88. };
  89. luaL_Reg ElementFormControlSelectGetters[] =
  90. {
  91. LUAGETTER(ElementFormControlSelect,options)
  92. LUAGETTER(ElementFormControlSelect,selection)
  93. { NULL, NULL },
  94. };
  95. luaL_Reg ElementFormControlSelectSetters[] =
  96. {
  97. LUASETTER(ElementFormControlSelect,selection)
  98. { NULL, NULL },
  99. };
  100. }
  101. }
  102. }
  103. namespace Rocket {
  104. namespace Core {
  105. namespace Lua {
  106. //inherits from ElementFormControl which inherits from Element
  107. template<> void ExtraInit<Rocket::Controls::ElementFormControlSelect>(lua_State* L, int metatable_index)
  108. {
  109. //init whatever elementformcontrol did extra, like inheritance
  110. ExtraInit<Rocket::Controls::ElementFormControl>(L,metatable_index);
  111. //then inherit from elementformcontrol
  112. LuaType<Rocket::Controls::ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
  113. AddTypeToElementAsTable<Rocket::Controls::ElementFormControlSelect>(L);
  114. }
  115. using Rocket::Controls::ElementFormControlSelect;
  116. LUACONTROLSTYPEDEFINE(ElementFormControlSelect,true)
  117. }
  118. }
  119. }