UIMLView.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. public:
  229. class Style : public ZeichnungHintergrund::Style
  230. {
  231. public:
  232. /// <summary>
  233. /// if this style is set, then the mause event action will be
  234. /// overwritten for all member views. The onMemberMouseEvent
  235. /// function will be executed instead. The style needs to be set
  236. /// before the uiml is parsed
  237. /// </summary>
  238. static const int GlobalMouseEvent = 0x01000;
  239. /// <summary>
  240. /// if this style is set, then the keyvord event action will be
  241. /// overwritten for all member views. The onMemberKeybordEvent
  242. /// function will be executed instead. The style needs to be set
  243. /// before the uiml is parsed
  244. /// </summary>
  245. static const int GlobalTastaturEvent = 0x01000;
  246. };
  247. private:
  248. RCArray<UIMLElement> knownElements;
  249. UIInit init;
  250. RCTrie<Zeichnung>* members;
  251. Array<Zeichnung*> memberList;
  252. RCArray<Text> idList;
  253. XML::Element* dom;
  254. int nextId;
  255. std::function<bool(
  256. XML::Element& element, Zeichnung& member, MausEreignis me)>
  257. onMemberMouseEvent;
  258. std::function<bool(
  259. XML::Element& element, Zeichnung& member, TastaturEreignis te)>
  260. onMemberKeyboardEvent;
  261. //! Verarbeitet ein Maus Ereignis. Wird vom Framework automatisch
  262. //! aufgerufen. \param me Das Ereignis
  263. DLLEXPORT virtual void doMausEreignis(
  264. MausEreignis& me, bool userRet) override;
  265. public:
  266. //! Erstellt eine UIML View
  267. DLLEXPORT UIMLView();
  268. //! Erstellt eine UIML View zu einem UIML Text
  269. //! \param uiml Ein xml element gemät des KSG UIML standarts
  270. //! \param screen Ein zeiger für den Belschirm auf dem die tooltips
  271. //! angezeigt werden sollen \param schrift Die schrift mit der der Text
  272. //! gezeichnet werden soll
  273. DLLEXPORT UIMLView(XML::Element* uiml, UIInit& init);
  274. //! Erstellt eine UIML View zu einem UIML Text
  275. //! \param uiml Ein xml text gemät des KSG UIML standarts
  276. //! \param screen Ein zeiger für den Belschirm auf dem die tooltips
  277. //! angezeigt werden sollen \param schrift Die schrift mit der der Text
  278. //! gezeichnet werden soll
  279. DLLEXPORT UIMLView(Text uiml, UIInit& init);
  280. DLLEXPORT ~UIMLView();
  281. /// <summary>
  282. /// sets a function that is executed if a mouse event on a member view
  283. /// occures and the style Style::GlobalMouseEvent is set.
  284. /// The mouse event will be ignored by the view if false is returned.
  285. /// </summary>
  286. /// <param name="onEventAction">the function to execute if a mouse event
  287. /// occures</param>
  288. DLLEXPORT void setOnMemberMouseEvent(std::function<bool(
  289. XML::Element& element, Zeichnung& member, MausEreignis me)>
  290. onEventAction);
  291. /// <summary>
  292. /// sets a function that is executed if a mouse event on a member view
  293. /// occures and the style Style::GlobalTastaturEvent is set.
  294. /// The mouse event will be ignored by the view if false is returned.
  295. /// </summary>
  296. /// <param name="onEventAction">the function to execute if a mouse event
  297. /// occures</param>
  298. DLLEXPORT void setOnMemberKeyboardEvent(std::function<bool(
  299. XML::Element& element, Zeichnung& member, TastaturEreignis te)>
  300. onEventAction);
  301. //! entfernt alle bekannten elemente, die im uiml verwendet werden
  302. //! können
  303. DLLEXPORT void removeAllKnownElements();
  304. //! fügt ein neues bekanntes element hinzu, dass danach im uiml
  305. //! verwendet werden kann.
  306. DLLEXPORT void addKnownElement(UIMLElement* element);
  307. //! prüft, ob ein xml Element ein bekanntes uiml Element ist;
  308. DLLEXPORT bool isKnownElement(XML::Element* zElement);
  309. //! setzt den inhalt der view
  310. //! \param uiml Ein xml element gemät des KSG UIML standarts
  311. DLLEXPORT void setUIML(XML::Element* uiml);
  312. //! setzt den inhalt der view
  313. //! \param uiml Ein xml text gemät des KSG UIML standarts
  314. DLLEXPORT void setUIML(Text uiml);
  315. //! aktualisiert alles zeichnungen gemäß den spezifikationen in UIML.
  316. //! Zeichnungen von entfernten elementen werden entfernt und neue
  317. //! Zeichnungen für neue Elemente werden erstellt
  318. DLLEXPORT void update();
  319. //! aktualisiert größe und position aller Zeichnungen gemäß den
  320. //! spezifikationen in UIML
  321. DLLEXPORT void layout();
  322. //! fügt ein element hinzu
  323. //! \param uiml Ein xml text gemät des KSG UIML standarts, welcher das
  324. //! neue Objekt darstellt \return id des neuen Elements
  325. DLLEXPORT Text addMember(Text uiml);
  326. //! fügt ein element zu einem Elternelement hinzu (funktioniert momentan
  327. //! nur mit frame Objekten) \param uiml Ein xml text gemät des KSG UIML
  328. //! standarts, welcher das neue Objekt darstellt \return id des neuen
  329. //! Elements
  330. DLLEXPORT Text addMember(Text uiml, Text parentId);
  331. //! entfernt ein element
  332. //! \param id id des Elements
  333. DLLEXPORT void removeMember(Text id);
  334. //! Gibt eine zeichnung zurück, welche in uiml eine bestimmte id hat
  335. //! \param id die id der Zeichnung
  336. DLLEXPORT Zeichnung* zZeichnungById(const char* id) override;
  337. //! Gibt eine zeichnung zurück, welche in uiml eine bestimmte id hat
  338. //! \param id die id der Zeichnung
  339. DLLEXPORT Zeichnung* getZeichnungById(const char* id) override;
  340. //! Verarbeitet ein Tastatur Ereignis. Wird vom Framework automatisch
  341. //! aufgerufen \param te Das Ereignis
  342. DLLEXPORT virtual void doTastaturEreignis(TastaturEreignis& te);
  343. //! Updated den Zeichenhintergrund
  344. //! \param tickVal Die vergangene Zeit in Sekunden, die seit dem Letzten
  345. //! Aufruf dieser Funktion verstrichen ist \return 1, wenn das Bild neu
  346. //! gezeichnet werden muss. 0 sonnst
  347. DLLEXPORT bool tick(double tickVal) override;
  348. //! Zeichnet den Hintergrund eines Zeichnunges nach rObj
  349. DLLEXPORT void render(Bild& rObj) override;
  350. //! Gibt den Dom Tree ohne erhöhten reference counter zurück
  351. //! Änderungen am Dom Tree sollten vermieden werden (nur änderungen von
  352. //! attributen einzelner elemente sind erlaubt)
  353. DLLEXPORT XML::Element* zDom() const;
  354. //! Gibt den Dom Tree zurück
  355. //! Änderungen am Dom Tree sollten vermieden werden (nur änderungen von
  356. //! attributen einzelner elemente sind erlaubt)
  357. DLLEXPORT XML::Element* getDom() const;
  358. DLLEXPORT bool isApplicableFor(XML::Element& element) override;
  359. DLLEXPORT Zeichnung* parseElement(
  360. XML::Element& element, UIMLContainer& generalFactory) override;
  361. DLLEXPORT bool updateElement(XML::Element& element,
  362. Zeichnung& z,
  363. UIMLContainer& generalFactory) override;
  364. DLLEXPORT void layout(XML::Element& element,
  365. Zeichnung& z,
  366. int pWidth,
  367. int pHeight,
  368. UIMLContainer& generalLayouter) override;
  369. DLLEXPORT Text getZeichnungId(Zeichnung& z) override;
  370. DLLEXPORT void removeZeichnung(Zeichnung& z) override;
  371. DLLEXPORT bool registerZeichnung(const char* id, Zeichnung* z) override;
  372. DLLEXPORT const UIInit& getFactory() override;
  373. //! calculates the needed size for all content elements to be visible
  374. DLLEXPORT Punkt calculateContentSize();
  375. };
  376. } // namespace Framework