DataViewDefault.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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-2023 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/Variant.h"
  33. #include "DataView.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(), int sort_offset = 0);
  41. bool Initialize(DataModel& model, Element* element, const String& expression, const String& modifier) override;
  42. StringList GetVariableNameList() const override;
  43. bool HasAddressDependency(const DataAddress& address) const override;
  44. protected:
  45. const String& GetModifier() const;
  46. DataExpression& GetExpression();
  47. // Delete this
  48. void Release() override;
  49. private:
  50. String modifier;
  51. DataExpressionPtr expression;
  52. };
  53. class DataViewAttribute : public DataViewCommon {
  54. public:
  55. DataViewAttribute(Element* element);
  56. DataViewAttribute(Element* element, String override_attribute, int sort_offset);
  57. bool Update(DataModel& model) override;
  58. };
  59. class DataViewAttributeIf final : public DataViewCommon {
  60. public:
  61. DataViewAttributeIf(Element* element);
  62. bool Update(DataModel& model) override;
  63. };
  64. class DataViewValue final : public DataViewAttribute {
  65. public:
  66. DataViewValue(Element* element);
  67. };
  68. class DataViewChecked final : public DataViewCommon {
  69. public:
  70. DataViewChecked(Element* element);
  71. bool Update(DataModel& model) override;
  72. };
  73. class DataViewStyle final : public DataViewCommon {
  74. public:
  75. DataViewStyle(Element* element);
  76. bool Update(DataModel& model) override;
  77. };
  78. class DataViewClass final : public DataViewCommon {
  79. public:
  80. DataViewClass(Element* element);
  81. bool Update(DataModel& model) override;
  82. };
  83. class DataViewRml final : public DataViewCommon {
  84. public:
  85. DataViewRml(Element* element);
  86. bool Update(DataModel& model) override;
  87. private:
  88. String previous_rml;
  89. };
  90. class DataViewIf final : public DataViewCommon {
  91. public:
  92. DataViewIf(Element* element);
  93. bool Update(DataModel& model) override;
  94. };
  95. class DataViewVisible final : public DataViewCommon {
  96. public:
  97. DataViewVisible(Element* element);
  98. bool Update(DataModel& model) override;
  99. };
  100. class DataViewText final : public DataView {
  101. public:
  102. DataViewText(Element* in_element);
  103. bool Initialize(DataModel& model, Element* element, const String& expression, const String& modifier) override;
  104. bool Update(DataModel& model) override;
  105. StringList GetVariableNameList() const override;
  106. bool HasAddressDependency(const DataAddress& address) const override;
  107. protected:
  108. void Release() override;
  109. private:
  110. String BuildText() const;
  111. struct DataEntry {
  112. size_t index = 0; // Index into 'text'
  113. DataExpressionPtr data_expression;
  114. String value;
  115. };
  116. String text;
  117. Vector<DataEntry> data_entries;
  118. };
  119. class DataViewFor final : public DataView {
  120. public:
  121. DataViewFor(Element* element);
  122. bool Initialize(DataModel& model, Element* element, const String& expression, const String& inner_rml) override;
  123. bool Update(DataModel& model) override;
  124. StringList GetVariableNameList() const override;
  125. bool HasAddressDependency(const DataAddress& address) const override;
  126. protected:
  127. void Release() override;
  128. private:
  129. DataAddress container_address;
  130. String iterator_name;
  131. String iterator_index_name;
  132. String rml_contents;
  133. ElementAttributes attributes;
  134. ElementList elements;
  135. };
  136. class DataViewAlias final : public DataView {
  137. public:
  138. DataViewAlias(Element* element);
  139. virtual StringList GetVariableNameList() const override;
  140. bool Update(DataModel& model) override;
  141. bool Initialize(DataModel& model, Element* element, const String& expression, const String& modifier) override;
  142. bool HasAddressDependency(const DataAddress& address) const override;
  143. protected:
  144. void Release() override;
  145. private:
  146. StringList variables;
  147. };
  148. } // namespace Rml
  149. #endif