2
0

PluginRegistry.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 "PluginRegistry.h"
  29. #include "../../Include/RmlUi/Core/Plugin.h"
  30. namespace Rml {
  31. typedef Vector< Plugin* > PluginList;
  32. static PluginList basic_plugins;
  33. static PluginList document_plugins;
  34. static PluginList element_plugins;
  35. PluginRegistry::PluginRegistry()
  36. {
  37. }
  38. void PluginRegistry::RegisterPlugin(Plugin* plugin)
  39. {
  40. int event_classes = plugin->GetEventClasses();
  41. if (event_classes & Plugin::EVT_BASIC)
  42. basic_plugins.push_back(plugin);
  43. if (event_classes & Plugin::EVT_DOCUMENT)
  44. document_plugins.push_back(plugin);
  45. if (event_classes & Plugin::EVT_ELEMENT)
  46. element_plugins.push_back(plugin);
  47. }
  48. // Calls OnInitialise() on all plugins.
  49. void PluginRegistry::NotifyInitialise()
  50. {
  51. for (size_t i = 0; i < basic_plugins.size(); ++i)
  52. basic_plugins[i]->OnInitialise();
  53. }
  54. // Calls OnShutdown() on all plugins.
  55. void PluginRegistry::NotifyShutdown()
  56. {
  57. while (!basic_plugins.empty())
  58. {
  59. basic_plugins.back()->OnShutdown();
  60. basic_plugins.pop_back();
  61. }
  62. document_plugins.clear();
  63. element_plugins.clear();
  64. }
  65. // Calls OnContextCreate() on all plugins.
  66. void PluginRegistry::NotifyContextCreate(Context* context)
  67. {
  68. for (size_t i = 0; i < basic_plugins.size(); ++i)
  69. basic_plugins[i]->OnContextCreate(context);
  70. }
  71. // Calls OnContextDestroy() on all plugins.
  72. void PluginRegistry::NotifyContextDestroy(Context* context)
  73. {
  74. for (size_t i = 0; i < basic_plugins.size(); ++i)
  75. basic_plugins[i]->OnContextDestroy(context);
  76. }
  77. // Calls OnDocumentOpen() on all plugins.
  78. void PluginRegistry::NotifyDocumentOpen(Context* context, const String& document_path)
  79. {
  80. for (size_t i = 0; i < document_plugins.size(); ++i)
  81. document_plugins[i]->OnDocumentOpen(context, document_path);
  82. }
  83. // Calls OnDocumentLoad() on all plugins.
  84. void PluginRegistry::NotifyDocumentLoad(ElementDocument* document)
  85. {
  86. for (size_t i = 0; i < document_plugins.size(); ++i)
  87. document_plugins[i]->OnDocumentLoad(document);
  88. }
  89. // Calls OnDocumentUnload() on all plugins.
  90. void PluginRegistry::NotifyDocumentUnload(ElementDocument* document)
  91. {
  92. for (size_t i = 0; i < document_plugins.size(); ++i)
  93. document_plugins[i]->OnDocumentUnload(document);
  94. }
  95. // Calls OnElementCreate() on all plugins.
  96. void PluginRegistry::NotifyElementCreate(Element* element)
  97. {
  98. for (size_t i = 0; i < element_plugins.size(); ++i)
  99. element_plugins[i]->OnElementCreate(element);
  100. }
  101. // Calls OnElementDestroy() on all plugins.
  102. void PluginRegistry::NotifyElementDestroy(Element* element)
  103. {
  104. for (size_t i = 0; i < element_plugins.size(); ++i)
  105. element_plugins[i]->OnElementDestroy(element);
  106. }
  107. } // namespace Rml