Document.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "Document.h"
  29. #include <Rocket/Core/ElementDocument.h>
  30. #include <Rocket/Core/Context.h>
  31. #include "Element.h"
  32. #include <Rocket/Core/Lua/Utilities.h>
  33. namespace Rocket {
  34. namespace Core {
  35. namespace Lua {
  36. template<> void ExtraInit<Document>(lua_State* L, int metatable_index)
  37. {
  38. //we will inherit from Element
  39. ExtraInit<Element>(L,metatable_index);
  40. LuaType<Element>::_regfunctions(L,metatable_index,metatable_index - 1);
  41. AddTypeToElementAsTable<Document>(L);
  42. }
  43. //methods
  44. int DocumentPullToFront(lua_State* L, Document* obj)
  45. {
  46. obj->PullToFront();
  47. return 0;
  48. }
  49. int DocumentPushToBack(lua_State* L, Document* obj)
  50. {
  51. obj->PushToBack();
  52. return 0;
  53. }
  54. int DocumentShow(lua_State* L, Document* obj)
  55. {
  56. int top = lua_gettop(L);
  57. if(top == 0)
  58. obj->Show();
  59. else
  60. {
  61. int flag = luaL_checkinteger(L,1);
  62. obj->Show(flag);
  63. }
  64. return 0;
  65. }
  66. int DocumentHide(lua_State* L, Document* obj)
  67. {
  68. obj->Hide();
  69. return 0;
  70. }
  71. int DocumentClose(lua_State* L, Document* obj)
  72. {
  73. obj->Close();
  74. return 0;
  75. }
  76. int DocumentCreateElement(lua_State* L, Document* obj)
  77. {
  78. const char* tag = luaL_checkstring(L,1);
  79. Element* ele = obj->CreateElement(tag);
  80. LuaType<Element>::push(L,ele,false);
  81. return 1;
  82. }
  83. int DocumentCreateTextNode(lua_State* L, Document* obj)
  84. {
  85. //need ElementText object first
  86. const char* text = luaL_checkstring(L,1);
  87. ElementText* et = obj->CreateTextNode(text);
  88. LuaType<ElementText>::push(L, et, false);
  89. return 1;
  90. }
  91. //getters
  92. int DocumentGetAttrtitle(lua_State* L)
  93. {
  94. Document* doc = LuaType<Document>::check(L,1);
  95. LUACHECKOBJ(doc);
  96. lua_pushstring(L,doc->GetTitle().CString());
  97. return 1;
  98. }
  99. int DocumentGetAttrcontext(lua_State* L)
  100. {
  101. Document* doc = LuaType<Document>::check(L,1);
  102. LUACHECKOBJ(doc);
  103. LuaType<Context>::push(L,doc->GetContext(),false);
  104. return 1;
  105. }
  106. //setters
  107. int DocumentSetAttrtitle(lua_State* L)
  108. {
  109. Document* doc = LuaType<Document>::check(L,1);
  110. LUACHECKOBJ(doc);
  111. const char* title = luaL_checkstring(L,2);
  112. doc->SetTitle(title);
  113. return 0;
  114. }
  115. RegType<Document> DocumentMethods[] =
  116. {
  117. LUAMETHOD(Document,PullToFront)
  118. LUAMETHOD(Document,PushToBack)
  119. LUAMETHOD(Document,Show)
  120. LUAMETHOD(Document,Hide)
  121. LUAMETHOD(Document,Close)
  122. LUAMETHOD(Document,CreateElement)
  123. LUAMETHOD(Document,CreateTextNode)
  124. { NULL, NULL },
  125. };
  126. luaL_reg DocumentGetters[] =
  127. {
  128. LUAGETTER(Document,title)
  129. LUAGETTER(Document,context)
  130. { NULL, NULL },
  131. };
  132. luaL_reg DocumentSetters[] =
  133. {
  134. LUASETTER(Document,title)
  135. { NULL, NULL },
  136. };
  137. LUATYPEDEFINE(Document,true)
  138. }
  139. }
  140. }