UIMLView.h 14 KB

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