Controls.cpp 4.5 KB

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