DataViewDefault.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 RMLUICOREDATAVIEWDEFAULT_H
  29. #define RMLUICOREDATAVIEWDEFAULT_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. namespace Core {
  36. class Element;
  37. class DataExpression;
  38. using DataExpressionPtr = UniquePtr<DataExpression>;
  39. class DataViewCommon : public DataView {
  40. public:
  41. DataViewCommon(Element* element, String override_modifier = String());
  42. bool Initialize(DataModel& model, Element* element, const String& expression, const String& modifier) override;
  43. StringList GetVariableNameList() 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);
  57. bool Update(DataModel& model) override;
  58. };
  59. class DataViewValue final : public DataViewAttribute {
  60. public:
  61. DataViewValue(Element* element);
  62. };
  63. class DataViewStyle final : public DataViewCommon {
  64. public:
  65. DataViewStyle(Element* element);
  66. bool Update(DataModel& model) override;
  67. };
  68. class DataViewClass final : public DataViewCommon {
  69. public:
  70. DataViewClass(Element* element);
  71. bool Update(DataModel& model) override;
  72. };
  73. class DataViewRml final : public DataViewCommon {
  74. public:
  75. DataViewRml(Element* element);
  76. bool Update(DataModel& model) override;
  77. private:
  78. String previous_rml;
  79. };
  80. class DataViewIf final : public DataViewCommon {
  81. public:
  82. DataViewIf(Element* element);
  83. bool Update(DataModel& model) override;
  84. };
  85. class DataViewVisible final : public DataViewCommon {
  86. public:
  87. DataViewVisible(Element* element);
  88. bool Update(DataModel& model) override;
  89. };
  90. class DataViewText final : public DataView {
  91. public:
  92. DataViewText(Element* in_element);
  93. bool Initialize(DataModel& model, Element* element, const String& expression, const String& modifier) override;
  94. bool Update(DataModel& model) override;
  95. StringList GetVariableNameList() const override;
  96. protected:
  97. void Release() override;
  98. private:
  99. String BuildText() const;
  100. struct DataEntry {
  101. size_t index = 0; // Index into 'text'
  102. DataExpressionPtr data_expression;
  103. String value;
  104. };
  105. String text;
  106. std::vector<DataEntry> data_entries;
  107. };
  108. class DataViewFor final : public DataView {
  109. public:
  110. DataViewFor(Element* element);
  111. bool Initialize(DataModel& model, Element* element, const String& expression, const String& inner_rml) override;
  112. bool Update(DataModel& model) override;
  113. StringList GetVariableNameList() const override;
  114. protected:
  115. void Release() override;
  116. private:
  117. DataAddress container_address;
  118. String iterator_name;
  119. String iterator_index_name;
  120. String rml_contents;
  121. ElementAttributes attributes;
  122. ElementList elements;
  123. };
  124. }
  125. }
  126. #endif