Controls.cpp 4.6 KB

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