DataViewDefault.h 4.2 KB

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