ElementFormControlSelect.cpp 4.2 KB

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