2
0

DataViewDefault.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. 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, int sort_offset);
  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 DataViewChecked final : public DataViewCommon {
  68. public:
  69. DataViewChecked(Element* element);
  70. bool Update(DataModel& model) override;
  71. };
  72. class DataViewStyle final : public DataViewCommon {
  73. public:
  74. DataViewStyle(Element* element);
  75. bool Update(DataModel& model) override;
  76. };
  77. class DataViewClass final : public DataViewCommon {
  78. public:
  79. DataViewClass(Element* element);
  80. bool Update(DataModel& model) override;
  81. };
  82. class DataViewRml final : public DataViewCommon {
  83. public:
  84. DataViewRml(Element* element);
  85. bool Update(DataModel& model) override;
  86. private:
  87. String previous_rml;
  88. };
  89. class DataViewIf final : public DataViewCommon {
  90. public:
  91. DataViewIf(Element* element);
  92. bool Update(DataModel& model) override;
  93. };
  94. class DataViewVisible final : public DataViewCommon {
  95. public:
  96. DataViewVisible(Element* element);
  97. bool Update(DataModel& model) override;
  98. };
  99. class DataViewText final : public DataView {
  100. public:
  101. DataViewText(Element* in_element);
  102. bool Initialize(DataModel& model, Element* element, const String& expression, const String& modifier) override;
  103. bool Update(DataModel& model) override;
  104. StringList GetVariableNameList() const override;
  105. protected:
  106. void Release() override;
  107. private:
  108. String BuildText() const;
  109. struct DataEntry {
  110. size_t index = 0; // Index into 'text'
  111. DataExpressionPtr data_expression;
  112. String value;
  113. };
  114. String text;
  115. Vector<DataEntry> data_entries;
  116. };
  117. class DataViewFor final : public DataView {
  118. public:
  119. DataViewFor(Element* element);
  120. bool Initialize(DataModel& model, Element* element, const String& expression, const String& modifier) override;
  121. bool Update(DataModel& model) override;
  122. StringList GetVariableNameList() const override;
  123. protected:
  124. void Release() override;
  125. private:
  126. const String* RMLContents() const;
  127. DataAddress container_address;
  128. String iterator_name;
  129. String iterator_index_name;
  130. ElementAttributes attributes;
  131. ElementList elements;
  132. };
  133. class DataViewAlias final : public DataView {
  134. public:
  135. DataViewAlias(Element* element);
  136. virtual StringList GetVariableNameList() const override;
  137. bool Update(DataModel& model) override;
  138. bool Initialize(DataModel& model, Element* element, const String& expression, const String& modifier) override;
  139. protected:
  140. void Release() override;
  141. private:
  142. StringList variables;
  143. };
  144. } // namespace Rml
  145. #endif