Document.cpp 3.8 KB

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