DataViewDefault.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #ifndef RMLUI_CORE_DATAVIEWDEFAULT_H
  29. #define RMLUI_CORE_DATAVIEWDEFAULT_H
  30. #include "../../Include/RmlUi/Core/Header.h"
  31. #include "../../Include/RmlUi/Core/Types.h"
  32. #include "../../Include/RmlUi/Core/DataView.h"
  33. #include "../../Include/RmlUi/Core/Variant.h"
  34. namespace Rml {
  35. class Element;
  36. class DataExpression;
  37. using DataExpressionPtr = UniquePtr<DataExpression>;
  38. class DataViewCommon : public DataView {
  39. public:
  40. DataViewCommon(Element* element, String override_modifier = String());
  41. bool Initialize(DataModel& model, Element* element, const String& expression, const String& modifier) override;
  42. StringList GetVariableNameList() const override;
  43. protected:
  44. const String& GetModifier() const;
  45. DataExpression& GetExpression();
  46. // Delete this
  47. void Release() override;
  48. private:
  49. String modifier;
  50. DataExpressionPtr expression;
  51. };
  52. class DataViewAttribute : public DataViewCommon {
  53. public:
  54. DataViewAttribute(Element* element);
  55. DataViewAttribute(Element* element, String override_attribute);
  56. bool Update(DataModel& model) override;
  57. };
  58. class DataViewAttributeIf final : public DataViewCommon {
  59. public:
  60. DataViewAttributeIf(Element* element);
  61. bool Update(DataModel& model) override;
  62. };
  63. class DataViewValue final : public DataViewAttribute {
  64. public:
  65. DataViewValue(Element* element);
  66. };
  67. class DataViewStyle final : public DataViewCommon {
  68. public:
  69. DataViewStyle(Element* element);
  70. bool Update(DataModel& model) override;
  71. };
  72. class DataViewClass final : public DataViewCommon {
  73. public:
  74. DataViewClass(Element* element);
  75. bool Update(DataModel& model) override;
  76. };
  77. class DataViewRml final : public DataViewCommon {
  78. public:
  79. DataViewRml(Element* element);
  80. bool Update(DataModel& model) override;
  81. private:
  82. String previous_rml;
  83. };
  84. class DataViewIf final : public DataViewCommon {
  85. public:
  86. DataViewIf(Element* element);
  87. bool Update(DataModel& model) override;
  88. };
  89. class DataViewVisible final : public DataViewCommon {
  90. public:
  91. DataViewVisible(Element* element);
  92. bool Update(DataModel& model) override;
  93. };
  94. class DataViewText final : public DataView {
  95. public:
  96. DataViewText(Element* in_element);
  97. bool Initialize(DataModel& model, Element* element, const String& expression, const String& modifier) override;
  98. bool Update(DataModel& model) override;
  99. StringList GetVariableNameList() const override;
  100. protected:
  101. void Release() override;
  102. private:
  103. String BuildText() const;
  104. struct DataEntry {
  105. size_t index = 0; // Index into 'text'
  106. DataExpressionPtr data_expression;
  107. String value;
  108. };
  109. String text;
  110. Vector<DataEntry> data_entries;
  111. };
  112. class DataViewFor final : public DataView {
  113. public:
  114. DataViewFor(Element* element);
  115. bool Initialize(DataModel& model, Element* element, const String& expression, const String& inner_rml) override;
  116. bool Update(DataModel& model) override;
  117. StringList GetVariableNameList() const override;
  118. protected:
  119. void Release() override;
  120. private:
  121. DataAddress container_address;
  122. String iterator_name;
  123. String iterator_index_name;
  124. String rml_contents;
  125. ElementAttributes attributes;
  126. ElementList elements;
  127. };
  128. } // namespace Rml
  129. #endif