Controls.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 "../../Include/Rocket/Controls/Controls.h"
  28. #include "../../Include/Rocket/Core/ElementInstancerGeneric.h"
  29. #include "../../Include/Rocket/Core/Factory.h"
  30. #include "../../Include/Rocket/Core/StyleSheetSpecification.h"
  31. #include "../../Include/Rocket/Core/XMLParser.h"
  32. #include "../../Include/Rocket/Core/Plugin.h"
  33. #include "../../Include/Rocket/Core/Core.h"
  34. #include "ElementTextSelection.h"
  35. #include "XMLNodeHandlerDataGrid.h"
  36. #include "XMLNodeHandlerTabSet.h"
  37. #include "XMLNodeHandlerTextArea.h"
  38. #include "../../Include/Rocket/Controls/ElementFormControlInput.h"
  39. namespace Rocket {
  40. namespace Controls {
  41. // Registers the custom element instancers.
  42. void RegisterElementInstancers()
  43. {
  44. Core::ElementInstancer* instancer = new Core::ElementInstancerGeneric< ElementForm >();
  45. Core::Factory::RegisterElementInstancer("form", instancer);
  46. instancer->RemoveReference();
  47. instancer = new Core::ElementInstancerGeneric< ElementFormControlInput >();
  48. Core::Factory::RegisterElementInstancer("input", instancer);
  49. instancer->RemoveReference();
  50. instancer = new Core::ElementInstancerGeneric< ElementFormControlDataSelect >();
  51. instancer = Core::Factory::RegisterElementInstancer("dataselect", instancer);
  52. instancer->RemoveReference();
  53. instancer = new Core::ElementInstancerGeneric< ElementFormControlSelect >();
  54. Core::Factory::RegisterElementInstancer("select", instancer);
  55. instancer->RemoveReference();
  56. instancer = new Core::ElementInstancerGeneric< ElementFormControlTextArea >();
  57. Core::Factory::RegisterElementInstancer("textarea", instancer);
  58. instancer->RemoveReference();
  59. instancer = new Core::ElementInstancerGeneric< ElementTextSelection >();
  60. Core::Factory::RegisterElementInstancer("#selection", instancer);
  61. instancer->RemoveReference();
  62. instancer = new Core::ElementInstancerGeneric< ElementTabSet >();
  63. Core::Factory::RegisterElementInstancer("tabset", instancer);
  64. instancer->RemoveReference();
  65. instancer = new Core::ElementInstancerGeneric< ElementDataGrid >();
  66. Core::Factory::RegisterElementInstancer("datagrid", instancer);
  67. instancer->RemoveReference();
  68. instancer = new Core::ElementInstancerGeneric< ElementDataGridExpandButton >();
  69. Core::Factory::RegisterElementInstancer("datagridexpand", instancer);
  70. instancer->RemoveReference();
  71. instancer = new Core::ElementInstancerGeneric< ElementDataGridCell >();
  72. Core::Factory::RegisterElementInstancer("#rktctl_datagridcell", instancer);
  73. instancer->RemoveReference();
  74. instancer = new Core::ElementInstancerGeneric< ElementDataGridRow >();
  75. Core::Factory::RegisterElementInstancer("#rktctl_datagridrow", instancer);
  76. instancer->RemoveReference();
  77. }
  78. void RegisterXMLNodeHandlers()
  79. {
  80. Core::XMLNodeHandler* node_handler = new XMLNodeHandlerDataGrid();
  81. Core::XMLParser::RegisterNodeHandler("datagrid", node_handler);
  82. node_handler->RemoveReference();
  83. node_handler = new XMLNodeHandlerTabSet();
  84. Core::XMLParser::RegisterNodeHandler("tabset", node_handler);
  85. node_handler->RemoveReference();
  86. node_handler = new XMLNodeHandlerTextArea();
  87. Core::XMLParser::RegisterNodeHandler("textarea", node_handler);
  88. node_handler->RemoveReference();
  89. }
  90. static bool initialised = false;
  91. class ControlsPlugin : public Rocket::Core::Plugin
  92. {
  93. public:
  94. void OnShutdown()
  95. {
  96. initialised = false;
  97. delete this;
  98. }
  99. int GetEventClasses()
  100. {
  101. return Rocket::Core::Plugin::EVT_BASIC;
  102. }
  103. };
  104. void Initialise()
  105. {
  106. // Prevent double initialisation
  107. if (!initialised)
  108. {
  109. Core::StyleSheetSpecification::RegisterProperty("min-rows", "0", false, false).AddParser("number");
  110. // Register the element instancers for our custom elements.
  111. RegisterElementInstancers();
  112. // Register the XML node handlers for our elements that require special parsing.
  113. RegisterXMLNodeHandlers();
  114. // Register the controls plugin, so we'll be notified on Shutdown
  115. Rocket::Core::RegisterPlugin(new ControlsPlugin());
  116. initialised = true;
  117. }
  118. }
  119. }
  120. }