Element.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #ifndef ROCKETCORELUAELEMENT_H
  28. #define ROCKETCORELUAELEMENT_H
  29. /*
  30. This defines the Element type in the Lua global namespace
  31. A few classes "inherit" from Element, such as Document. Document will call
  32. LuaType<Element>::_regfunctions to put all of these functions in its own table, and
  33. will be used with the same syntax except it will be from a Document object. It isn't true
  34. inheritance, but it is a fair enough emulation. Any functions in the child class that have
  35. the same name as the function in Element will overwrite the one in Element.
  36. Here, I will be showing usage of the API, and it will show the type names rather than the regular
  37. local var = foo that is Lua. If you need info on the purpose of the functions, see the python docs
  38. //methods that need to be called from an Element object using the colon syntax
  39. noreturn Element:AddEventListener(string event, ? see footnote 1, [bool capture])
  40. noreturn Element:AppendChild(Element child)
  41. noreturn Element:Blur()
  42. noreturn Element:Click()
  43. noreturn Element:DispatchEvent(string event, {} params) --in params, keys have to be a string and value can be number,bool,string,userdata,lightuserdata
  44. noreturn Element:Focus()
  45. [int,float,Colourb,Colourf,string,Vector2f,lightuserdata] Element:GetAttribute(string name) --will return one of those types
  46. Element Element:GetElementById(string id)
  47. {}of elements Element:GetElementsByTagName(string tag)
  48. bool Element:HasAttribute(string name)
  49. bool Element:HasChildNodes()
  50. noreturn Element:InsertBefore(Element child,Element adjacent)
  51. bool Element:IsClassSet(string name)
  52. noreturn Element:RemoveAttribute(string name)
  53. bool Element:RemoveChild(Element child)
  54. bool Element:ReplaceChild(Element inserted,Element replaced)
  55. noreturn Element:ScrollIntoView(bool align_with_top)
  56. noreturn Element:SetAttribute(string name,string value)
  57. noreturn Element:SetClass(string name, bool activate)
  58. %type% Element.As.%type%(Element obj) --see footnote 2
  59. //getters accessed by the period syntax from an element object
  60. --for attributes, if you save it to a local/global variable and try to modify that variable,
  61. --your changes will not be saved. You will have to use Element:SetAttribute
  62. {} of [key=string,value=int,float,Colourb,Colourf,string,Vector2f,lightuserdata] Element.attributes
  63. {} of Element Element.child_nodes
  64. string Element.class_name
  65. float Element.client_left
  66. float Element.client_height
  67. float Element.client_top
  68. float Element.client_width
  69. Element Element.first_child
  70. string Element.id
  71. string Element.inner_rml
  72. Element Element.last_child
  73. Element Element.next_sibling
  74. float Element.offset_height
  75. float Element.offset_left
  76. Element Element.offset_parent
  77. float Element.offset_top
  78. float Element.offset_width
  79. Document Element.owner_document
  80. Element Element.parent_nod
  81. Element Element.previous_sibling
  82. float Element.scroll_height
  83. float Element.scroll_left
  84. float Element.scroll_top
  85. float Element.scroll_width
  86. ElementStyle Element.style --see ElementStyle.h documentation
  87. string Element.tag_name
  88. //setters to be used with a dot syntax on an Element object
  89. Element.class_name = string
  90. Element.id = string
  91. Element.inner_rml = string
  92. Element.scroll_left = float
  93. Element.scroll_top = float
  94. footnote 1: for Element:AddEventListener(string,?,bool)
  95. The ? can be either a string or a function.
  96. In the string, you can be guaranteed that you will have the
  97. named variables 'event','element','document' available to you, and they mean the same as if you were to put
  98. the string as onclick="string" in a .rml file.
  99. If you give it a function, the function will be called every time that C++ EventListener::ProcessEvent would
  100. would be called. In this case, it will call the function, and you can decide the name of the parameters, however
  101. it is in a specific order. The order is event,element,document. So:
  102. function foo(l,q,e) end element:AddEventListener("click",foo,true) is the correct syntax, and puts l=event,q=element,e=document
  103. They are terrible names, but it is to make a point.
  104. footnote 2: For Element.As used for casting an Element object to a more derived class.
  105. If you are using RocketControls, it will be filled with those types. For instance, you would say
  106. local input_element = Element.As.ElementFormControlInput(element) --where element is an Element object
  107. */
  108. #include <Rocket/Core/Lua/LuaType.h>
  109. #include <Rocket/Core/Lua/lua.hpp>
  110. #include <Rocket/Core/Element.h>
  111. namespace Rocket {
  112. namespace Core {
  113. namespace Lua {
  114. template<> ROCKETLUA_API void ExtraInit<Element>(lua_State* L, int metatable_index);
  115. //methods
  116. int ElementAddEventListener(lua_State* L, Element* obj);
  117. int ElementAppendChild(lua_State* L, Element* obj);
  118. int ElementBlur(lua_State* L, Element* obj);
  119. int ElementClick(lua_State* L, Element* obj);
  120. int ElementDispatchEvent(lua_State* L, Element* obj);
  121. int ElementFocus(lua_State* L, Element* obj);
  122. int ElementGetAttribute(lua_State* L, Element* obj);
  123. int ElementGetElementById(lua_State* L, Element* obj);
  124. int ElementGetElementsByTagName(lua_State* L, Element* obj);
  125. int ElementHasAttribute(lua_State* L, Element* obj);
  126. int ElementHasChildNodes(lua_State* L, Element* obj);
  127. int ElementInsertBefore(lua_State* L, Element* obj);
  128. int ElementIsClassSet(lua_State* L, Element* obj);
  129. int ElementRemoveAttribute(lua_State* L, Element* obj);
  130. int ElementRemoveChild(lua_State* L, Element* obj);
  131. int ElementReplaceChild(lua_State* L, Element* obj);
  132. int ElementScrollIntoView(lua_State* L, Element* obj);
  133. int ElementSetAttribute(lua_State* L, Element* obj);
  134. int ElementSetClass(lua_State* L, Element* obj);
  135. int ElementAsType(lua_State* L, Element* obj);
  136. //getters
  137. int ElementGetAttrattributes(lua_State* L);
  138. int ElementGetAttrchild_nodes(lua_State* L);
  139. int ElementGetAttrclass_name(lua_State* L);
  140. int ElementGetAttrclient_left(lua_State* L);
  141. int ElementGetAttrclient_height(lua_State* L);
  142. int ElementGetAttrclient_top(lua_State* L);
  143. int ElementGetAttrclient_width(lua_State* L);
  144. int ElementGetAttrfirst_child(lua_State* L);
  145. int ElementGetAttrid(lua_State* L);
  146. int ElementGetAttrinner_rml(lua_State* L);
  147. int ElementGetAttrlast_child(lua_State* L);
  148. int ElementGetAttrnext_sibling(lua_State* L);
  149. int ElementGetAttroffset_height(lua_State* L);
  150. int ElementGetAttroffset_left(lua_State* L);
  151. int ElementGetAttroffset_parent(lua_State* L);
  152. int ElementGetAttroffset_top(lua_State* L);
  153. int ElementGetAttroffset_width(lua_State* L);
  154. int ElementGetAttrowner_document(lua_State* L);
  155. int ElementGetAttrparent_node(lua_State* L);
  156. int ElementGetAttrprevious_sibling(lua_State* L);
  157. int ElementGetAttrscroll_height(lua_State* L);
  158. int ElementGetAttrscroll_left(lua_State* L);
  159. int ElementGetAttrscroll_top(lua_State* L);
  160. int ElementGetAttrscroll_width(lua_State* L);
  161. int ElementGetAttrstyle(lua_State* L);
  162. int ElementGetAttrtag_name(lua_State* L);
  163. //setters
  164. int ElementSetAttrclass_name(lua_State* L);
  165. int ElementSetAttrid(lua_State* L);
  166. int ElementSetAttrinner_rml(lua_State* L);
  167. int ElementSetAttrscroll_left(lua_State* L);
  168. int ElementSetAttrscroll_top(lua_State* L);
  169. RegType<Element> ElementMethods[];
  170. luaL_reg ElementGetters[];
  171. luaL_reg ElementSetters[];
  172. LUATYPEDECLARE(Element)
  173. }
  174. }
  175. }
  176. #endif