UIMLView.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #pragma once
  2. #include "Array.h"
  3. #include "Trie.h"
  4. #include "UIInitialization.h"
  5. #include "Zeichnung.h"
  6. namespace Framework
  7. {
  8. class Text;
  9. class ObjTabelle;
  10. class Schrift;
  11. class Bildschirm;
  12. class UIMLContainer;
  13. namespace XML
  14. {
  15. class Element;
  16. }
  17. class UIMLElement : public virtual ReferenceCounter
  18. {
  19. public:
  20. DLLEXPORT UIMLElement();
  21. DLLEXPORT virtual ~UIMLElement();
  22. //! prüft, ob dieses UIML Element für ein bestimmtes xml Element
  23. //! zuständig ist
  24. virtual bool isApplicableFor(XML::Element& element) = 0;
  25. //! erstellt eine neue Zeichnung zu einem gegebenen xml Element
  26. virtual Zeichnung* parseElement(
  27. XML::Element& element, UIMLContainer& generalFactory)
  28. = 0;
  29. //! wendet die layout parameter zu einer Zeichnung an
  30. DLLEXPORT virtual void layout(XML::Element& element,
  31. Zeichnung& z,
  32. int pWidth,
  33. int pHeight,
  34. UIMLContainer& generalLayouter);
  35. };
  36. class UIMLContainer : public UIMLElement
  37. {
  38. public:
  39. DLLEXPORT UIMLContainer();
  40. DLLEXPORT virtual ~UIMLContainer();
  41. virtual Zeichnung* zZeichnungById(const char* id) = 0;
  42. virtual Zeichnung* getZeichnungById(const char* id) = 0;
  43. virtual const UIInit& getFactory() = 0;
  44. };
  45. class UIMLTextField : public UIMLElement
  46. {
  47. public:
  48. DLLEXPORT UIMLTextField();
  49. DLLEXPORT bool isApplicableFor(XML::Element& element) override;
  50. DLLEXPORT Zeichnung* parseElement(
  51. XML::Element& element, UIMLContainer& generalFactory) override;
  52. DLLEXPORT void layout(XML::Element& element,
  53. Zeichnung& z,
  54. int pWidth,
  55. int pHeight,
  56. UIMLContainer& generalLayouter) override;
  57. };
  58. class UIMLButton : public UIMLElement
  59. {
  60. public:
  61. DLLEXPORT UIMLButton();
  62. DLLEXPORT bool isApplicableFor(XML::Element& element) override;
  63. DLLEXPORT Zeichnung* parseElement(
  64. XML::Element& element, UIMLContainer& generalFactory) override;
  65. DLLEXPORT void layout(XML::Element& element,
  66. Zeichnung& z,
  67. int pWidth,
  68. int pHeight,
  69. UIMLContainer& generalLayouter) override;
  70. };
  71. class UIMLCheck : public UIMLElement
  72. {
  73. public:
  74. DLLEXPORT UIMLCheck();
  75. DLLEXPORT bool isApplicableFor(XML::Element& element) override;
  76. DLLEXPORT Zeichnung* parseElement(
  77. XML::Element& element, UIMLContainer& generalFactory) override;
  78. DLLEXPORT void layout(XML::Element& element,
  79. Zeichnung& z,
  80. int pWidth,
  81. int pHeight,
  82. UIMLContainer& generalLayouter) override;
  83. };
  84. class UIMLText : public UIMLElement
  85. {
  86. public:
  87. DLLEXPORT UIMLText();
  88. DLLEXPORT bool isApplicableFor(XML::Element& element) override;
  89. DLLEXPORT Zeichnung* parseElement(
  90. XML::Element& element, UIMLContainer& generalFactory) override;
  91. DLLEXPORT void layout(XML::Element& element,
  92. Zeichnung& z,
  93. int pWidth,
  94. int pHeight,
  95. UIMLContainer& generalLayouter) override;
  96. };
  97. class UIMLTextArea : public UIMLElement
  98. {
  99. public:
  100. DLLEXPORT UIMLTextArea();
  101. DLLEXPORT bool isApplicableFor(XML::Element& element) override;
  102. DLLEXPORT Zeichnung* parseElement(
  103. XML::Element& element, UIMLContainer& generalFactory) override;
  104. DLLEXPORT void layout(XML::Element& element,
  105. Zeichnung& z,
  106. int pWidth,
  107. int pHeight,
  108. UIMLContainer& generalLayouter) override;
  109. };
  110. class UIMLTable : public UIMLElement
  111. {
  112. public:
  113. DLLEXPORT UIMLTable();
  114. DLLEXPORT bool isApplicableFor(XML::Element& element) override;
  115. DLLEXPORT Zeichnung* parseElement(
  116. XML::Element& element, UIMLContainer& generalFactory) override;
  117. DLLEXPORT void layout(XML::Element& element,
  118. Zeichnung& z,
  119. int pWidth,
  120. int pHeight,
  121. UIMLContainer& generalLayouter) override;
  122. };
  123. class UIMLFrame : public UIMLElement
  124. {
  125. public:
  126. DLLEXPORT UIMLFrame();
  127. DLLEXPORT bool isApplicableFor(XML::Element& element) override;
  128. DLLEXPORT Zeichnung* parseElement(
  129. XML::Element& element, UIMLContainer& generalFactory) override;
  130. DLLEXPORT void layout(XML::Element& element,
  131. Zeichnung& z,
  132. int pWidth,
  133. int pHeight,
  134. UIMLContainer& generalLayouter) override;
  135. };
  136. /**
  137. KSG UIML Standart
  138. possible XML elements:
  139. - uimlview (the root element of uiml),
  140. - class (only as direct child of uimlview),
  141. - textfield,
  142. - button,
  143. - check, (KontrollKnopf)
  144. - text,
  145. - textarea,
  146. - table (allowed child elements: tr),
  147. - tr (allowed child elements: textfield, button, table, text, textarea,
  148. frame),
  149. - frame (allowed child elements: textfield, button, table, text,
  150. textarea, frame).
  151. possible global XML attributes:
  152. - id (string should be unique),
  153. - x (integer, optional % char at end),
  154. - y (integer, optional % char at end),
  155. - width (integer, optional % char at end) or auto keyword,
  156. - height (integer, optional % char at end) or auto keyword,
  157. - margin (integer, optional % char at end),
  158. - margin-left (integer, optional % char at end),
  159. - margin-top (integer, optional % char at end),
  160. - margin-right (integer, optional % char at end),
  161. - margin-bottom (integer, optional % char at end),
  162. - align-left (string (id values of other elements or keywords: start,
  163. end, center)),
  164. - align-top (string (id values of other elements or keywords: start,
  165. end, center)),
  166. - align-bottom ((string (id values of other elements or keywords: start,
  167. end, center)),
  168. - align-right (string (id values of other elements or keywords: start,
  169. end, center)),
  170. - tooltip (string),
  171. - style (hex __int64),
  172. - class (string (id of class element))
  173. attribute die sich gegenseitig ausschließen:
  174. - align-left / align-right
  175. - align-top / align-bottom
  176. spezific attributes:
  177. - font-size (textfield, text, textarea, button)
  178. - text-align (textfield, text, textarea)
  179. - text-align-horizontal (textfield, text, textarea)
  180. - text-align-vertical (textfield, text, textarea)
  181. example:
  182. \code
  183. <view>
  184. <textfield id="element_at_top_left" align-left="start",
  185. align-top="start", margin-left="5", margin-top="5" width="90%"
  186. height="30"/> <table id="element_below_textfield" align-left="start",
  187. aliign-top="element_at_top_left", margin-left="5", margin-top="5"
  188. width="90%" height="300"> <tr> <button id="a_button_in_a_table"/>
  189. <textfield id="a_textfield_in_a_table"/>
  190. </tr>
  191. </table>
  192. </view>
  193. \endcode
  194. */
  195. class UIMLView : public ZeichnungHintergrund,
  196. public UIMLContainer
  197. {
  198. private:
  199. RCArray<UIMLElement> knownElements;
  200. UIInit init;
  201. RCTrie<Zeichnung>* members;
  202. XML::Element* dom;
  203. int nextId;
  204. //! Verarbeitet ein Maus Ereignis. Wird vom Framework automatisch
  205. //! aufgerufen. \param me Das Ereignis
  206. DLLEXPORT virtual void doMausEreignis(
  207. MausEreignis& me, bool userRet) override;
  208. public:
  209. //! Erstellt eine UIML View
  210. DLLEXPORT UIMLView();
  211. //! Erstellt eine UIML View zu einem UIML Text
  212. //! \param uiml Ein xml element gemät des KSG UIML standarts
  213. //! \param screen Ein zeiger für den Belschirm auf dem die tooltips
  214. //! angezeigt werden sollen \param schrift Die schrift mit der der Text
  215. //! gezeichnet werden soll
  216. DLLEXPORT UIMLView(XML::Element* uiml, UIInit& init);
  217. //! Erstellt eine UIML View zu einem UIML Text
  218. //! \param uiml Ein xml text gemät des KSG UIML standarts
  219. //! \param screen Ein zeiger für den Belschirm auf dem die tooltips
  220. //! angezeigt werden sollen \param schrift Die schrift mit der der Text
  221. //! gezeichnet werden soll
  222. DLLEXPORT UIMLView(Text uiml, UIInit& init);
  223. DLLEXPORT ~UIMLView();
  224. //! entfernt alle bekannten elemente, die im uiml verwendet werden
  225. //! können
  226. DLLEXPORT void removeAllKnownElements();
  227. //! fügt ein neues bekanntes element hinzu, dass danach im uiml
  228. //! verwendet werden kann.
  229. DLLEXPORT void addKnownElement(UIMLElement* element);
  230. //! prüft, ob ein xml Element ein bekanntes uiml Element ist;
  231. DLLEXPORT bool isKnownElement(XML::Element* zElement);
  232. //! setzt den inhalt der view
  233. //! \param uiml Ein xml element gemät des KSG UIML standarts
  234. DLLEXPORT void setUIML(XML::Element* uiml);
  235. //! setzt den inhalt der view
  236. //! \param uiml Ein xml text gemät des KSG UIML standarts
  237. DLLEXPORT void setUIML(Text uiml);
  238. //! aktualisiert größe und position aller Zeichnungen gemäß den
  239. //! spezifikationen in UIML
  240. DLLEXPORT void layout();
  241. //! fügt ein element hinzu
  242. //! \param uiml Ein xml text gemät des KSG UIML standarts, welcher das
  243. //! neue Objekt darstellt \return id des neuen Elements
  244. DLLEXPORT Text addMember(Text uiml);
  245. //! fügt ein element zu einem Elternelement hinzu (funktioniert momentan
  246. //! nur mit frame Objekten) \param uiml Ein xml text gemät des KSG UIML
  247. //! standarts, welcher das neue Objekt darstellt \return id des neuen
  248. //! Elements
  249. DLLEXPORT Text addMember(Text uiml, Text parentId);
  250. //! entfernt ein element
  251. //! \param id id des Elements
  252. DLLEXPORT void removeMember(Text id);
  253. //! Gibt eine zeichnung zurück, welche in uiml eine bestimmte id hat
  254. //! \param id die id der Zeichnung
  255. DLLEXPORT Zeichnung* zZeichnungById(const char* id) override;
  256. //! Gibt eine zeichnung zurück, welche in uiml eine bestimmte id hat
  257. //! \param id die id der Zeichnung
  258. DLLEXPORT Zeichnung* getZeichnungById(const char* id) override;
  259. //! Verarbeitet ein Tastatur Ereignis. Wird vom Framework automatisch
  260. //! aufgerufen \param te Das Ereignis
  261. DLLEXPORT virtual void doTastaturEreignis(TastaturEreignis& te);
  262. //! Updated den Zeichenhintergrund
  263. //! \param tickVal Die vergangene Zeit in Sekunden, die seit dem Letzten
  264. //! Aufruf dieser Funktion verstrichen ist \return 1, wenn das Bild neu
  265. //! gezeichnet werden muss. 0 sonnst
  266. DLLEXPORT bool tick(double tickVal) override;
  267. //! Zeichnet den Hintergrund eines Zeichnunges nach rObj
  268. DLLEXPORT void render(Bild& rObj) override;
  269. //! Gibt den Dom Tree ohne erhöhten reference counter zurück
  270. //! Änderungen am Dom Tree sollten vermieden werden (nur änderungen von
  271. //! attributen einzelner elemente sind erlaubt)
  272. DLLEXPORT XML::Element* zDom() const;
  273. //! Gibt den Dom Tree zurück
  274. //! Änderungen am Dom Tree sollten vermieden werden (nur änderungen von
  275. //! attributen einzelner elemente sind erlaubt)
  276. DLLEXPORT XML::Element* getDom() const;
  277. DLLEXPORT bool isApplicableFor(XML::Element& element) override;
  278. DLLEXPORT Zeichnung* parseElement(
  279. XML::Element& element, UIMLContainer& generalFactory) override;
  280. DLLEXPORT void layout(XML::Element& element,
  281. Zeichnung& z,
  282. int pWidth,
  283. int pHeight,
  284. UIMLContainer& generalLayouter) override;
  285. DLLEXPORT const UIInit& getFactory() override;
  286. //! calculates the needed size for all content elements to be visible
  287. DLLEXPORT Punkt calculateContentSize();
  288. };
  289. } // namespace Framework