ElementFormControlSelect.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. using Rocket::Controls::ElementFormControlSelect;
  34. using Rocket::Controls::ElementFormControl;
  35. namespace Rocket {
  36. namespace Core {
  37. namespace Lua {
  38. //inherits from ElementFormControl which inherits from Element
  39. //methods
  40. int ElementFormControlSelectAdd(lua_State* L, ElementFormControlSelect* obj)
  41. {
  42. const char* rml = luaL_checkstring(L,1);
  43. const char* value = luaL_checkstring(L,2);
  44. int before = -1; //default
  45. if(lua_gettop(L) >= 3)
  46. before = luaL_checkint(L,3);
  47. int index = obj->Add(rml,value,before);
  48. lua_pushinteger(L,index);
  49. return 1;
  50. }
  51. int ElementFormControlSelectRemove(lua_State* L, ElementFormControlSelect* obj)
  52. {
  53. int index = luaL_checkint(L,1);
  54. obj->Remove(index);
  55. return 0;
  56. }
  57. int ElementFormControlSelectGetOption(lua_State* L, ElementFormControlSelect* obj)
  58. {
  59. int index = luaL_checkint(L,1);
  60. Rocket::Controls::SelectOption* opt = obj->GetOption(index);
  61. lua_newtable(L);
  62. LuaType<Element>::push(L,opt->GetElement(),false);
  63. lua_setfield(L,-2,"element");
  64. lua_pushstring(L,opt->GetValue().CString());
  65. lua_setfield(L,-2,"value");
  66. return 1;
  67. }
  68. //getters
  69. int ElementFormControlSelectGetAttroptions(lua_State* L)
  70. {
  71. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  72. LUACHECKOBJ(obj);
  73. SelectOptionsProxy* proxy = new SelectOptionsProxy();
  74. proxy->owner = obj;
  75. LuaType<SelectOptionsProxy>::push(L,proxy,true);
  76. return 1;
  77. }
  78. int ElementFormControlSelectGetAttrselection(lua_State* L)
  79. {
  80. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  81. LUACHECKOBJ(obj);
  82. int selection = obj->GetSelection();
  83. lua_pushinteger(L,selection);
  84. return 1;
  85. }
  86. //setter
  87. int ElementFormControlSelectSetAttrselection(lua_State* L)
  88. {
  89. ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
  90. LUACHECKOBJ(obj);
  91. int selection = luaL_checkint(L,2);
  92. obj->SetSelection(selection);
  93. return 0;
  94. }
  95. RegType<ElementFormControlSelect> ElementFormControlSelectMethods[] =
  96. {
  97. LUAMETHOD(ElementFormControlSelect,Add)
  98. LUAMETHOD(ElementFormControlSelect,Remove)
  99. LUAMETHOD(ElementFormControlSelect,GetOption)
  100. { NULL, NULL },
  101. };
  102. luaL_reg ElementFormControlSelectGetters[] =
  103. {
  104. LUAGETTER(ElementFormControlSelect,options)
  105. LUAGETTER(ElementFormControlSelect,selection)
  106. { NULL, NULL },
  107. };
  108. luaL_reg ElementFormControlSelectSetters[] =
  109. {
  110. LUASETTER(ElementFormControlSelect,selection)
  111. { NULL, NULL },
  112. };
  113. /*
  114. template<> const char* GetTClassName<ElementFormControlSelect>() { return "ElementFormControlSelect"; }
  115. template<> RegType<ElementFormControlSelect>* GetMethodTable<ElementFormControlSelect>() { return ElementFormControlSelectMethods; }
  116. template<> luaL_reg* GetAttrTable<ElementFormControlSelect>() { return ElementFormControlSelectGetters; }
  117. template<> luaL_reg* SetAttrTable<ElementFormControlSelect>() { return ElementFormControlSelectSetters; }
  118. */
  119. }
  120. }
  121. }