ElementFormControlSelect.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "precompiled.h"
  2. #include "ElementFormControlSelect.h"
  3. #include "SelectOptionsProxy.h"
  4. #include <Rocket/Controls/ElementFormControlSelect.h>
  5. #include <Rocket/Controls/ElementFormControl.h>
  6. #include <Rocket/Core/Element.h>
  7. using Rocket::Controls::ElementFormControlSelect;
  8. using Rocket::Controls::ElementFormControl;
  9. namespace Rocket {
  10. namespace Core {
  11. namespace Lua {
  12. //inherits from ElementFormControl which inherits from Element
  13. //methods
  14. int ElementFormControlSelectAdd(lua_State* L, ElementFormControlSelect* obj)
  15. {
  16. const char* rml = luaL_checkstring(L,1);
  17. const char* value = luaL_checkstring(L,2);
  18. int before = -1; //default
  19. if(lua_gettop(L) >= 3)
  20. before = luaL_checkint(L,3);
  21. int index = obj->Add(rml,value,before);
  22. lua_pushinteger(L,index);
  23. return 1;
  24. }
  25. int ElementFormControlSelectRemove(lua_State* L, ElementFormControlSelect* obj)
  26. {
  27. int index = luaL_checkint(L,1);
  28. obj->Remove(index);
  29. return 0;
  30. }
  31. int ElementFormControlSelectGetOption(lua_State* L, ElementFormControlSelect* obj)
  32. {
  33. int index = luaL_checkint(L,1);
  34. Rocket::Controls::SelectOption* opt = obj->GetOption(index);
  35. lua_newtable(L);
  36. LuaType<Element>::push(L,opt->GetElement(),false);
  37. lua_setfield(L,-2,"element");
  38. lua_pushstring(L,opt->GetValue().CString());
  39. lua_setfield(L,-2,"value");
  40. return 1;
  41. }
  42. //getters
  43. int ElementFormControlSelectGetAttroptions(lua_State* L)
  44. {
  45. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  46. LUACHECKOBJ(obj);
  47. SelectOptionsProxy* proxy = new SelectOptionsProxy();
  48. proxy->owner = obj;
  49. LuaType<SelectOptionsProxy>::push(L,proxy,true);
  50. return 1;
  51. }
  52. int ElementFormControlSelectGetAttrselection(lua_State* L)
  53. {
  54. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  55. LUACHECKOBJ(obj);
  56. int selection = obj->GetSelection();
  57. lua_pushinteger(L,selection);
  58. return 1;
  59. }
  60. //setter
  61. int ElementFormControlSelectSetAttrselection(lua_State* L)
  62. {
  63. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  64. LUACHECKOBJ(obj);
  65. int selection = luaL_checkint(L,2);
  66. obj->SetSelection(selection);
  67. return 0;
  68. }
  69. RegType<ElementFormControlSelect> ElementFormControlSelectMethods[] =
  70. {
  71. LUAMETHOD(ElementFormControlSelect,Add)
  72. LUAMETHOD(ElementFormControlSelect,Remove)
  73. LUAMETHOD(ElementFormControlSelect,GetOption)
  74. { NULL, NULL },
  75. };
  76. luaL_reg ElementFormControlSelectGetters[] =
  77. {
  78. LUAGETTER(ElementFormControlSelect,options)
  79. LUAGETTER(ElementFormControlSelect,selection)
  80. { NULL, NULL },
  81. };
  82. luaL_reg ElementFormControlSelectSetters[] =
  83. {
  84. LUASETTER(ElementFormControlSelect,selection)
  85. { NULL, NULL },
  86. };
  87. /*
  88. template<> const char* GetTClassName<ElementFormControlSelect>() { return "ElementFormControlSelect"; }
  89. template<> RegType<ElementFormControlSelect>* GetMethodTable<ElementFormControlSelect>() { return ElementFormControlSelectMethods; }
  90. template<> luaL_reg* GetAttrTable<ElementFormControlSelect>() { return ElementFormControlSelectGetters; }
  91. template<> luaL_reg* SetAttrTable<ElementFormControlSelect>() { return ElementFormControlSelectSetters; }
  92. */
  93. }
  94. }
  95. }