UIMLView.cpp 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  1. #include "UIMLView.h"
  2. #include "Bild.h"
  3. #include "Bildschirm.h"
  4. #include "Fenster.h"
  5. #include "Knopf.h"
  6. #include "Rahmen.h"
  7. #include "RCPointer.h"
  8. #include "Schrift.h"
  9. #include "Scroll.h"
  10. #include "Tabelle.h"
  11. #include "TextFeld.h"
  12. #include "XML.h"
  13. using namespace Framework;
  14. UIMLElement::UIMLElement()
  15. : ReferenceCounter()
  16. {}
  17. UIMLElement::~UIMLElement() {}
  18. //! wendet die layout parameter zu einer Zeichnung an
  19. void UIMLElement::layout(XML::Element& element,
  20. Zeichnung& z,
  21. int pWidth,
  22. int pHeight,
  23. UIMLContainer& generalLayouter)
  24. {
  25. int width = z.getBreite();
  26. int height = z.getHeight();
  27. if (element.hasAttribute("width"))
  28. {
  29. Text w = element.getAttributeValue("width");
  30. if (!w.istGleich("auto"))
  31. {
  32. width = (int)w;
  33. if (w.getText()[w.getLength() - 1] == '%')
  34. width = (int)((pWidth / 100.0) * width);
  35. }
  36. }
  37. if (element.hasAttribute("height"))
  38. {
  39. Text h = element.getAttributeValue("height");
  40. if (!h.istGleich("auto"))
  41. {
  42. height = (int)h;
  43. if (h.getText()[h.getLength() - 1] == '%')
  44. height = (int)((pHeight / 100.0) * height);
  45. }
  46. }
  47. z.setSize(width, height);
  48. if (element.hasAttribute("align-left"))
  49. {
  50. Text la = element.getAttributeValue("align-left");
  51. int x = 0;
  52. if (la.istGleich("start"))
  53. x = 0;
  54. else if (la.istGleich("end"))
  55. x = pWidth;
  56. else if (la.istGleich("center"))
  57. x = pWidth / 2 - width / 2;
  58. else
  59. {
  60. XML::Editor ed
  61. = element.zParent()->selectChildsByAttribute("id", la);
  62. generalLayouter.layout(*ed.begin().val(),
  63. *generalLayouter.zZeichnungById(la),
  64. pWidth,
  65. pHeight,
  66. generalLayouter);
  67. Zeichnung* laz = generalLayouter.zZeichnungById(la);
  68. if (laz) x = laz->getX() + laz->getBreite();
  69. }
  70. if (element.hasAttribute("margin-left"))
  71. {
  72. Text mt = element.getAttributeValue("margin-left");
  73. int m = (int)mt;
  74. if (mt.getText()[mt.getLength() - 1] == '%')
  75. m = (int)((pWidth / 100.0) * m);
  76. x += m;
  77. }
  78. z.setX(x);
  79. }
  80. else if (element.hasAttribute("align-right"))
  81. {
  82. Text ra = element.getAttributeValue("align-right");
  83. int x = 0;
  84. if (ra.istGleich("start"))
  85. x = -z.getBreite();
  86. else if (ra.istGleich("end"))
  87. x = pWidth - z.getBreite();
  88. else if (ra.istGleich("center"))
  89. x = pWidth / 2 - width / 2;
  90. else
  91. {
  92. XML::Editor ed
  93. = element.zParent()->selectChildsByAttribute("id", ra);
  94. generalLayouter.layout(*ed.begin().val(),
  95. *generalLayouter.zZeichnungById(ra),
  96. pWidth,
  97. pHeight,
  98. generalLayouter);
  99. Zeichnung* raz = generalLayouter.zZeichnungById(ra);
  100. if (raz) x = raz->getX() - z.getBreite();
  101. }
  102. if (element.hasAttribute("margin-right"))
  103. {
  104. Text mt = element.getAttributeValue("margin-right");
  105. int m = (int)mt;
  106. if (mt.getText()[mt.getLength() - 1] == '%')
  107. m = (int)((pWidth / 100.0) * m);
  108. x -= m;
  109. }
  110. z.setX(x);
  111. }
  112. if (element.hasAttribute("align-top"))
  113. {
  114. Text ta = element.getAttributeValue("align-top");
  115. int y = 0;
  116. if (ta.istGleich("start"))
  117. y = 0;
  118. else if (ta.istGleich("end"))
  119. y = pHeight;
  120. else if (ta.istGleich("center"))
  121. y = pHeight / 2 - height / 2;
  122. else
  123. {
  124. XML::Editor ed
  125. = element.zParent()->selectChildsByAttribute("id", ta);
  126. generalLayouter.layout(*ed.begin().val(),
  127. *generalLayouter.zZeichnungById(ta),
  128. pWidth,
  129. pHeight,
  130. generalLayouter);
  131. Zeichnung* taz = generalLayouter.zZeichnungById(ta);
  132. if (taz) y = taz->getY() + taz->getHeight();
  133. }
  134. if (element.hasAttribute("margin-top"))
  135. {
  136. Text mt = element.getAttributeValue("margin-top");
  137. int m = (int)mt;
  138. if (mt.getText()[mt.getLength() - 1] == '%')
  139. m = (int)((pHeight / 100.0) * m);
  140. y += m;
  141. }
  142. z.setY(y);
  143. }
  144. else if (element.hasAttribute("align-bottom"))
  145. {
  146. Text ba = element.getAttributeValue("align-bottom");
  147. int y = 0;
  148. if (ba.istGleich("start"))
  149. y = -z.getHeight();
  150. else if (ba.istGleich("end"))
  151. y = pHeight - z.getHeight();
  152. else if (ba.istGleich("center"))
  153. y = pHeight / 2 - height / 2;
  154. else
  155. {
  156. XML::Editor ed
  157. = element.zParent()->selectChildsByAttribute("id", ba);
  158. generalLayouter.layout(*ed.begin().val(),
  159. *generalLayouter.zZeichnungById(ba),
  160. pWidth,
  161. pHeight,
  162. generalLayouter);
  163. Zeichnung* baz = generalLayouter.zZeichnungById(ba);
  164. if (baz) y = baz->getY() - z.getHeight();
  165. }
  166. if (element.hasAttribute("margin-bottom"))
  167. {
  168. Text mt = element.getAttributeValue("margin-bottom");
  169. int m = (int)mt;
  170. if (mt.getText()[mt.getLength() - 1] == '%')
  171. m = (int)((pHeight / 100.0) * m);
  172. y -= m;
  173. }
  174. z.setY(y);
  175. }
  176. int x = z.getX();
  177. int y = z.getY();
  178. if (element.hasAttribute("x"))
  179. {
  180. Text xt = element.getAttributeValue("x");
  181. x = (int)xt;
  182. if (xt.getText()[xt.getLength() - 1] == '%')
  183. x = (int)((pWidth / 100.0) * x);
  184. }
  185. if (element.hasAttribute("y"))
  186. {
  187. Text yt = element.getAttributeValue("y");
  188. y = (int)yt;
  189. if (yt.getText()[yt.getLength() - 1] == '%')
  190. y = (int)((pHeight / 100.0) * y);
  191. }
  192. z.setPosition(x, y);
  193. pWidth = z.getInnenBreite();
  194. pHeight = z.getInnenHeight();
  195. // recursive layout
  196. for (auto i = element.getChilds(); i; i++)
  197. {
  198. Zeichnung* z = 0;
  199. if (i->hasAttribute("id"))
  200. {
  201. z = generalLayouter.zZeichnungById(i->getAttributeValue("id"));
  202. }
  203. if (z)
  204. {
  205. generalLayouter.layout(
  206. *i.val(), *z, pWidth, pHeight, generalLayouter);
  207. }
  208. }
  209. }
  210. UIMLContainer::UIMLContainer()
  211. : UIMLElement()
  212. {}
  213. UIMLContainer::~UIMLContainer() {}
  214. UIMLTextField::UIMLTextField()
  215. : UIMLElement()
  216. {}
  217. bool UIMLTextField::isApplicableFor(XML::Element& element)
  218. {
  219. return element.getName().istGleich("textfield");
  220. }
  221. Zeichnung* UIMLTextField::parseElement(
  222. XML::Element& element, UIMLContainer& generalFactory)
  223. {
  224. TextFeld* t = generalFactory.getFactory().createTextFeld(
  225. generalFactory.getFactory().initParam);
  226. updateElement(element, *t, generalFactory);
  227. return t;
  228. }
  229. bool Framework::UIMLTextField::updateElement(
  230. XML::Element& element, Zeichnung& z, UIMLContainer& generalFactory)
  231. {
  232. TextFeld* t = dynamic_cast<TextFeld*>(&z);
  233. if (!t) return false;
  234. if (element.hasAttribute("style"))
  235. {
  236. Text style = element.getAttributeValue("style");
  237. if (!style.hatAt(0, "0x"))
  238. {
  239. style.insert(0, "0x");
  240. }
  241. t->setStyle((int)style);
  242. }
  243. else
  244. {
  245. TextFeld* tmp = generalFactory.getFactory().createTextFeld(
  246. generalFactory.getFactory().initParam);
  247. tmp->addStyle(TextFeld::Style::TextFeld);
  248. t->setStyle(tmp->getStyles());
  249. tmp->release();
  250. }
  251. return true;
  252. }
  253. void UIMLTextField::layout(XML::Element& element,
  254. Zeichnung& z,
  255. int pWidth,
  256. int pHeight,
  257. UIMLContainer& generalLayouter)
  258. {
  259. if (element.hasAttribute("text-align-horizontal"))
  260. z.setStyle(TextFeld::Style::HCenter,
  261. element.getAttributeValue("text-align-horizontal")
  262. .istGleich("center"));
  263. if (element.hasAttribute("text-align-vertical"))
  264. z.setStyle(TextFeld::Style::VCenter,
  265. element.getAttributeValue("text-align-vertical")
  266. .istGleich("center"));
  267. if (element.hasAttribute("font-size"))
  268. ((TextFeld*)&z)
  269. ->setSchriftSize(
  270. (unsigned char)(int)element.getAttributeValue("font-size"));
  271. if (element.hasAttribute("disabled"))
  272. z.removeStyle(TextFeld::Style::Editierbar);
  273. ((TextFeld*)&z)->setText(element.getText());
  274. if (element.hasAttribute("width"))
  275. {
  276. Text w = element.getAttributeValue("width");
  277. if (w.istGleich("auto"))
  278. {
  279. z.setWidth(((TextFeld*)&z)->getNeededWidth());
  280. }
  281. }
  282. if (element.hasAttribute("height"))
  283. {
  284. Text h = element.getAttributeValue("height");
  285. if (h.istGleich("auto"))
  286. {
  287. z.setHeight(((TextFeld*)&z)->getNeededHeight());
  288. }
  289. }
  290. UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
  291. }
  292. UIMLButton::UIMLButton()
  293. : UIMLElement()
  294. {}
  295. bool UIMLButton::isApplicableFor(XML::Element& element)
  296. {
  297. return element.getName().istGleich("button");
  298. }
  299. Zeichnung* UIMLButton::parseElement(
  300. XML::Element& element, UIMLContainer& generalFactory)
  301. {
  302. Knopf* k = generalFactory.getFactory().createKnopf(
  303. generalFactory.getFactory().initParam);
  304. updateElement(element, *k, generalFactory);
  305. return k;
  306. }
  307. bool Framework::UIMLButton::updateElement(
  308. XML::Element& element, Zeichnung& z, UIMLContainer& generalFactory)
  309. {
  310. Knopf* k = dynamic_cast<Knopf*>(&z);
  311. if (!k) return false;
  312. if (element.hasAttribute("style"))
  313. {
  314. Text style = element.getAttributeValue("style");
  315. if (!style.hatAt(0, "0x"))
  316. {
  317. style.insert(0, "0x");
  318. }
  319. k->setStyle((int)style);
  320. }
  321. else
  322. {
  323. Knopf* tmp = generalFactory.getFactory().createKnopf(
  324. generalFactory.getFactory().initParam);
  325. k->setStyle(tmp->getStyles());
  326. tmp->release();
  327. }
  328. return true;
  329. }
  330. void UIMLButton::layout(XML::Element& element,
  331. Zeichnung& z,
  332. int pWidth,
  333. int pHeight,
  334. UIMLContainer& generalLayouter)
  335. {
  336. if (element.hasAttribute("font-size"))
  337. ((Knopf*)&z)
  338. ->setSchriftSize(
  339. (unsigned char)(int)element.getAttributeValue("font-size"));
  340. ((Knopf*)&z)->setText(element.getText());
  341. UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
  342. }
  343. UIMLCheck::UIMLCheck()
  344. : UIMLElement()
  345. {}
  346. bool UIMLCheck::isApplicableFor(XML::Element& element)
  347. {
  348. return element.getName().istGleich("check");
  349. }
  350. Zeichnung* UIMLCheck::parseElement(
  351. XML::Element& element, UIMLContainer& generalFactory)
  352. {
  353. KontrollKnopf* k = generalFactory.getFactory().createKontrollKnopf(
  354. generalFactory.getFactory().initParam);
  355. updateElement(element, *k, generalFactory);
  356. return k;
  357. }
  358. bool Framework::UIMLCheck::updateElement(
  359. XML::Element& element, Zeichnung& z, UIMLContainer& generalFactory)
  360. {
  361. KontrollKnopf* k = dynamic_cast<KontrollKnopf*>(&z);
  362. if (!k) return false;
  363. if (element.hasAttribute("style"))
  364. {
  365. Text style = element.getAttributeValue("style");
  366. if (!style.hatAt(0, "0x"))
  367. {
  368. style.insert(0, "0x");
  369. }
  370. k->setStyle((int)style);
  371. }
  372. else
  373. {
  374. KontrollKnopf* tmp = generalFactory.getFactory().createKontrollKnopf(
  375. generalFactory.getFactory().initParam);
  376. k->setStyle(tmp->getStyles());
  377. tmp->release();
  378. }
  379. return true;
  380. }
  381. void UIMLCheck::layout(XML::Element& element,
  382. Zeichnung& z,
  383. int pWidth,
  384. int pHeight,
  385. UIMLContainer& generalLayouter)
  386. {
  387. ((KontrollKnopf*)&z)->setText(element.getText());
  388. ((KontrollKnopf*)&z)->setSText(element.getText());
  389. z.setStyle(
  390. KontrollKnopf::Style::Selected, element.hasAttribute("selected"));
  391. if (element.hasAttribute("font-size"))
  392. ((KontrollKnopf*)&z)
  393. ->setSSize(
  394. (unsigned char)(int)element.getAttributeValue("font-size"));
  395. UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
  396. }
  397. UIMLText::UIMLText()
  398. : UIMLElement()
  399. {}
  400. bool UIMLText::isApplicableFor(XML::Element& element)
  401. {
  402. return element.getName().istGleich("text");
  403. }
  404. Zeichnung* UIMLText::parseElement(
  405. XML::Element& element, UIMLContainer& generalFactory)
  406. {
  407. TextFeld* t = generalFactory.getFactory().createTextFeld(
  408. generalFactory.getFactory().initParam);
  409. updateElement(element, *t, generalFactory);
  410. return t;
  411. }
  412. bool Framework::UIMLText::updateElement(
  413. XML::Element& element, Zeichnung& z, UIMLContainer& generalFactory)
  414. {
  415. TextFeld* t = dynamic_cast<TextFeld*>(&z);
  416. if (!t) return false;
  417. if (element.hasAttribute("style"))
  418. {
  419. Text style = element.getAttributeValue("style");
  420. if (!style.hatAt(0, "0x"))
  421. {
  422. style.insert(0, "0x");
  423. }
  424. t->setStyle((int)style);
  425. }
  426. else
  427. {
  428. TextFeld* tmp = generalFactory.getFactory().createTextFeld(
  429. generalFactory.getFactory().initParam);
  430. tmp->addStyle(TextFeld::Style::Text);
  431. t->setStyle(tmp->getStyles());
  432. tmp->release();
  433. }
  434. return true;
  435. }
  436. void UIMLText::layout(XML::Element& element,
  437. Zeichnung& z,
  438. int pWidth,
  439. int pHeight,
  440. UIMLContainer& generalLayouter)
  441. {
  442. if (element.hasAttribute("text-align-horizontal"))
  443. z.setStyle(TextFeld::Style::HCenter,
  444. element.getAttributeValue("text-align-horizontal")
  445. .istGleich("center"));
  446. if (element.hasAttribute("text-align-vertical"))
  447. z.setStyle(TextFeld::Style::VCenter,
  448. element.getAttributeValue("text-align-vertical")
  449. .istGleich("center"));
  450. if (element.hasAttribute("font-size"))
  451. ((TextFeld*)&z)
  452. ->setSchriftSize(
  453. (unsigned char)(int)element.getAttributeValue("font-size"));
  454. if (element.hasAttribute("disabled"))
  455. z.removeStyle(TextFeld::Style::Editierbar);
  456. ((TextFeld*)&z)->setText(element.getText());
  457. if (element.hasAttribute("width"))
  458. {
  459. Text w = element.getAttributeValue("width");
  460. if (w.istGleich("auto"))
  461. {
  462. z.setWidth(((TextFeld*)&z)->getNeededWidth());
  463. }
  464. }
  465. if (element.hasAttribute("height"))
  466. {
  467. Text h = element.getAttributeValue("height");
  468. if (h.istGleich("auto"))
  469. {
  470. z.setHeight(((TextFeld*)&z)->getNeededHeight());
  471. }
  472. }
  473. UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
  474. }
  475. UIMLTextArea::UIMLTextArea()
  476. : UIMLElement()
  477. {}
  478. bool UIMLTextArea::isApplicableFor(XML::Element& element)
  479. {
  480. return element.getName().istGleich("textarea");
  481. }
  482. Zeichnung* UIMLTextArea::parseElement(
  483. XML::Element& element, UIMLContainer& generalFactory)
  484. {
  485. TextFeld* t = generalFactory.getFactory().createTextFeld(
  486. generalFactory.getFactory().initParam);
  487. updateElement(element, *t, generalFactory);
  488. return t;
  489. }
  490. bool Framework::UIMLTextArea::updateElement(
  491. XML::Element& element, Zeichnung& z, UIMLContainer& generalFactory)
  492. {
  493. TextFeld* t = dynamic_cast<TextFeld*>(&z);
  494. if (!t) return false;
  495. if (element.hasAttribute("style"))
  496. {
  497. Text style = element.getAttributeValue("style");
  498. if (!style.hatAt(0, "0x"))
  499. {
  500. style.insert(0, "0x");
  501. }
  502. t->setStyle((int)style);
  503. }
  504. else
  505. {
  506. TextFeld* tmp = generalFactory.getFactory().createTextFeld(
  507. generalFactory.getFactory().initParam);
  508. tmp->addStyle(TextFeld::Style::TextGebiet);
  509. t->setStyle(tmp->getStyles());
  510. tmp->release();
  511. }
  512. return true;
  513. }
  514. void UIMLTextArea::layout(XML::Element& element,
  515. Zeichnung& z,
  516. int pWidth,
  517. int pHeight,
  518. UIMLContainer& generalLayouter)
  519. {
  520. if (element.hasAttribute("text-align-horizontal"))
  521. z.setStyle(TextFeld::Style::HCenter,
  522. element.getAttributeValue("text-align-horizontal")
  523. .istGleich("center"));
  524. if (element.hasAttribute("text-align-vertical"))
  525. z.setStyle(TextFeld::Style::VCenter,
  526. element.getAttributeValue("text-align-vertical")
  527. .istGleich("center"));
  528. if (element.hasAttribute("font-size"))
  529. ((TextFeld*)&z)
  530. ->setSchriftSize(
  531. (unsigned char)(int)element.getAttributeValue("font-size"));
  532. if (element.hasAttribute("disabled"))
  533. z.removeStyle(TextFeld::Style::Editierbar);
  534. ((TextFeld*)&z)->setText(element.getText());
  535. ((TextFeld*)&z)
  536. ->zTextRenderer()
  537. ->textFormatieren(((TextFeld*)&z)->zText(), z.getInnenBreite());
  538. if (element.hasAttribute("width"))
  539. {
  540. Text w = element.getAttributeValue("width");
  541. if (w.istGleich("auto"))
  542. {
  543. z.setWidth(((TextFeld*)&z)->getNeededWidth());
  544. }
  545. }
  546. if (element.hasAttribute("height"))
  547. {
  548. Text h = element.getAttributeValue("height");
  549. if (h.istGleich("auto"))
  550. {
  551. z.setHeight(((TextFeld*)&z)->getNeededHeight());
  552. }
  553. }
  554. UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
  555. }
  556. UIMLTable::UIMLTable()
  557. : UIMLElement()
  558. {}
  559. bool UIMLTable::isApplicableFor(XML::Element& element)
  560. {
  561. return element.getName().istGleich("table");
  562. }
  563. Zeichnung* UIMLTable::parseElement(
  564. XML::Element& element, UIMLContainer& generalFactory)
  565. {
  566. ObjTabelle* t = generalFactory.getFactory().createObjTabelle(
  567. generalFactory.getFactory().initParam);
  568. updateElement(element, *t, generalFactory);
  569. return t;
  570. }
  571. DLLEXPORT bool Framework::UIMLTable::updateElement(
  572. XML::Element& element, Zeichnung& z, UIMLContainer& generalFactory)
  573. {
  574. ObjTabelle* t = dynamic_cast<ObjTabelle*>(&z);
  575. if (!t) return false;
  576. int index = 0;
  577. int linePos = 0;
  578. int numCols = 0;
  579. for (auto i = element.getChilds(); i; i++)
  580. {
  581. Text id;
  582. if (i->hasAttribute("id"))
  583. id = i->getAttributeValue("id");
  584. else
  585. {
  586. id = Text("_") += index++;
  587. i->setAttribute("id", id);
  588. }
  589. if (i->getName().istGleich("tr"))
  590. {
  591. if (t->getZeilenNummer(id) == -1) t->addZeile(id);
  592. t->setZeilePosition(id, linePos);
  593. int c = 1;
  594. for (auto j = i->getChilds(); j; j++)
  595. {
  596. if (t->getSpaltenAnzahl() < c) t->addSpalte(Text(c - 1));
  597. if (numCols < c) numCols = c;
  598. Zeichnung* z = t->zZeichnung(Text(c - 1), id);
  599. if (!z
  600. || !generalFactory.updateElement(
  601. element, *z, generalFactory))
  602. {
  603. if (z) generalFactory.removeZeichnung(*z);
  604. z = generalFactory.parseElement(*i.val(), generalFactory);
  605. if (z) t->setZeichnungZ(Text(c - 1), id, z);
  606. }
  607. c++;
  608. }
  609. }
  610. linePos++;
  611. }
  612. for (int i = 0; i < t->getZeilenAnzahl(); i++)
  613. { // remove all lines that are not in the xml
  614. if (!element.selectChildsByName("tr")
  615. .whereAttributeEquals("id", *t->zZeilenName(i))
  616. .exists())
  617. {
  618. for (int j = 0; j < t->getSpaltenAnzahl(); j++)
  619. {
  620. Zeichnung* z = t->zZeichnung(j, i);
  621. if (z) generalFactory.removeZeichnung(*z);
  622. }
  623. t->removeZeile(i);
  624. i--;
  625. }
  626. }
  627. for (int i = numCols; i < t->getSpaltenAnzahl(); i++)
  628. { // remove all columns that are not in the xml
  629. for (int j = 0; j < t->getZeilenAnzahl(); j++)
  630. {
  631. Zeichnung* z = t->zZeichnung(i, j);
  632. if (z) generalFactory.removeZeichnung(*z);
  633. }
  634. t->removeSpalte(i);
  635. i--;
  636. }
  637. if (element.hasAttribute("style"))
  638. {
  639. Text style = element.getAttributeValue("style");
  640. if (!style.hatAt(0, "0x"))
  641. {
  642. style.insert(0, "0x");
  643. }
  644. t->setStyle((int)style);
  645. }
  646. else
  647. {
  648. ObjTabelle* tmp = generalFactory.getFactory().createObjTabelle(
  649. generalFactory.getFactory().initParam);
  650. t->setStyle(tmp->getStyles());
  651. tmp->release();
  652. }
  653. return true;
  654. }
  655. void UIMLTable::layout(XML::Element& element,
  656. Zeichnung& z,
  657. int pWidth,
  658. int pHeight,
  659. UIMLContainer& generalLayouter)
  660. {
  661. if (element.hasAttribute("scroll"))
  662. {
  663. z.setStyle(ObjTabelle::Style::HScroll,
  664. element.getAttributeValue("scroll").istGleich("horizontal"));
  665. z.setStyle(ObjTabelle::Style::VScroll,
  666. element.getAttributeValue("scroll").istGleich("vertical"));
  667. z.setStyle(ObjTabelle::Style::scroll,
  668. element.getAttributeValue("scroll").istGleich("both"));
  669. }
  670. UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
  671. ObjTabelle* objT = (ObjTabelle*)&z;
  672. if (objT->getZeilenAnzahl() > 0)
  673. {
  674. if (element.hasAttribute("line-height"))
  675. {
  676. int height = (int)element.getAttributeValue("line-height");
  677. for (int i = 0; i < objT->getZeilenAnzahl(); i++)
  678. objT->setZeilenHeight(i, height);
  679. }
  680. for (int i = 0; i < objT->getSpaltenAnzahl(); i++)
  681. {
  682. if (objT->zZeichnung(i, 0))
  683. objT->setSpaltenBreite(i, objT->zZeichnung(i, 0)->getBreite());
  684. }
  685. }
  686. }
  687. UIMLFrame::UIMLFrame()
  688. : UIMLElement()
  689. {}
  690. bool UIMLFrame::isApplicableFor(XML::Element& element)
  691. {
  692. return element.getName().istGleich("frame");
  693. }
  694. Zeichnung* UIMLFrame::parseElement(
  695. XML::Element& element, UIMLContainer& generalFactory)
  696. {
  697. Fenster* f = generalFactory.getFactory().createFenster(
  698. generalFactory.getFactory().initParam);
  699. updateElement(element, *f, generalFactory);
  700. return f;
  701. }
  702. bool Framework::UIMLFrame::updateElement(
  703. XML::Element& element, Zeichnung& z, UIMLContainer& generalFactory)
  704. {
  705. Fenster* f = dynamic_cast<Fenster*>(&z);
  706. if (!f) return false;
  707. for (auto member = f->getMembers().begin(); member; member++)
  708. { // remove all members that are not in the xml
  709. if (!element
  710. .selectChildsByAttribute(
  711. "id", generalFactory.getZeichnungId(*member.val()))
  712. .exists())
  713. {
  714. member.remove();
  715. f->setRender();
  716. }
  717. }
  718. int index = 0;
  719. for (auto i = element.getChilds(); i; i++)
  720. {
  721. Text id = element.getAttributeValue("id");
  722. Zeichnung* z = generalFactory.zZeichnungById(id);
  723. if (!id.getLength() || !z || f->getMembers().indexOf(z) < 0
  724. || !generalFactory.updateElement(*i.val(), *z, generalFactory))
  725. {
  726. if (z) generalFactory.removeZeichnung(*z);
  727. z = generalFactory.parseElement(*i.val(), generalFactory);
  728. if (z) f->addMember(z);
  729. }
  730. if (z) f->setMemberIndex(z, index++);
  731. }
  732. if (element.hasAttribute("style"))
  733. {
  734. Text style = element.getAttributeValue("style");
  735. if (!style.hatAt(0, "0x"))
  736. {
  737. style.insert(0, "0x");
  738. }
  739. f->setStyle((int)style);
  740. }
  741. else
  742. {
  743. Fenster* tmp = generalFactory.getFactory().createFenster(
  744. generalFactory.getFactory().initParam);
  745. f->setStyle(tmp->getStyles());
  746. tmp->release();
  747. }
  748. return true;
  749. }
  750. void UIMLFrame::layout(XML::Element& element,
  751. Zeichnung& z,
  752. int pWidth,
  753. int pHeight,
  754. UIMLContainer& generalLayouter)
  755. {
  756. if (element.hasAttribute("title"))
  757. ((Fenster*)&z)->setTitel(element.getAttributeValue("title"));
  758. if (element.hasAttribute("title-height"))
  759. ((Fenster*)&z)
  760. ->zTTextFeld()
  761. ->setSize(((Fenster*)&z)->zTTextFeld()->getBreite(),
  762. (int)element.getAttributeValue("title-height"));
  763. UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
  764. }
  765. // Erstellt eine UIML View
  766. UIMLView::UIMLView()
  767. : ZeichnungHintergrund()
  768. {
  769. style = Style::MEIgnoreInside | Style::MEIgnoreParentInside
  770. | Style::MEIgnoreSichtbar | Style::MEIgnoreVerarbeitet;
  771. members = new RCTrie<Zeichnung>();
  772. dom = 0;
  773. nextId = 0;
  774. memset(&init, 0, sizeof(UIInit));
  775. addKnownElement(new UIMLTextField());
  776. addKnownElement(new UIMLButton());
  777. addKnownElement(new UIMLCheck());
  778. addKnownElement(new UIMLText());
  779. addKnownElement(new UIMLTextArea());
  780. addKnownElement(new UIMLTable());
  781. addKnownElement(new UIMLFrame());
  782. }
  783. // Erstellt eine UIML View zu einem UIML Text
  784. // uiml: Ein xml element gemät des ksg uiml standarts
  785. UIMLView::UIMLView(XML::Element* uiml, UIInit& init)
  786. : UIMLView()
  787. {
  788. this->init = init;
  789. setUIML(uiml);
  790. }
  791. // Erstellt eine UIML View zu einem UIML Text
  792. // uiml: Ein xml text gemät des ksg uiml standarts
  793. UIMLView::UIMLView(Text uiml, UIInit& init)
  794. : UIMLView()
  795. {
  796. this->init = init;
  797. setUIML(uiml);
  798. }
  799. UIMLView::~UIMLView()
  800. {
  801. if (dom) dom->release();
  802. members->release();
  803. }
  804. // Verarbeitet ein Maus Ereignis. Wird vom Framework automatisch aufgerufen.
  805. // me: Das Ereignis
  806. void UIMLView::doMausEreignis(MausEreignis& me, bool userRet)
  807. {
  808. if (dom)
  809. {
  810. bool verarbeitet = me.verarbeitet;
  811. me.verarbeitet |= hatStyleNicht(Style::Sichtbar);
  812. bool insideParent = me.insideParent;
  813. if (!hatStyle(Style::Sichtbar) || !me.insideParent || me.verarbeitet
  814. || me.mx < 0 || me.my < 0 || me.mx >= gr.x || me.my >= gr.y
  815. || !userRet)
  816. me.insideParent = 0;
  817. int rbr = 0;
  818. if (hatStyle(Style::Rahmen) && rahmen) rbr = rahmen->getRBreite();
  819. me.mx -= rbr;
  820. me.my -= rbr;
  821. if (hatStyle(Style::VScroll) && vertikalScrollBar)
  822. me.my += vertikalScrollBar->getScroll();
  823. if (hatStyle(Style::HScroll) && horizontalScrollBar)
  824. me.mx += horizontalScrollBar->getScroll();
  825. if (dom)
  826. {
  827. for (auto i = dom->getChilds(); i; i++)
  828. { // TODO render elements backwards
  829. Zeichnung* z = members->z(i->getAttributeValue("id"),
  830. i->getAttributeValue("id").getLength());
  831. if (z) z->doPublicMausEreignis(me);
  832. }
  833. }
  834. me.mx += rbr;
  835. me.my += rbr;
  836. if (hatStyle(Style::VScroll) && vertikalScrollBar)
  837. me.my -= vertikalScrollBar->getScroll();
  838. if (hatStyle(Style::HScroll) && horizontalScrollBar)
  839. me.mx -= horizontalScrollBar->getScroll();
  840. if (!hatStyle(Style::Sichtbar) || !me.insideParent || me.verarbeitet
  841. || me.mx < 0 || me.my < 0 || me.mx >= gr.x || me.my >= gr.y
  842. || !userRet)
  843. me.insideParent = insideParent;
  844. else
  845. me.verarbeitet = 1;
  846. if (hatStyleNicht(Style::Sichtbar)) me.verarbeitet = verarbeitet;
  847. }
  848. }
  849. void Framework::UIMLView::setOnMemberMouseEvent(std::function<bool(
  850. XML::Element& element, Zeichnung& member, MausEreignis me)>
  851. onEventAction)
  852. {
  853. onMemberMouseEvent = onEventAction;
  854. }
  855. void Framework::UIMLView::setOnMemberKeyboardEvent(std::function<bool(
  856. XML::Element& element, Zeichnung& member, TastaturEreignis te)>
  857. onEventAction)
  858. {
  859. onMemberKeyboardEvent = onEventAction;
  860. }
  861. //! entfernt alle bekannten elemente, die im uiml verwendet werden können
  862. void UIMLView::removeAllKnownElements()
  863. {
  864. knownElements.leeren();
  865. }
  866. //! fügt ein neues bekanntes element hinzu, dass danach im uiml verwendet werden
  867. //! kann.
  868. void UIMLView::addKnownElement(UIMLElement* element)
  869. {
  870. knownElements.add(element);
  871. }
  872. //! prüft, ob ein xml Element ein bekanntes uiml Element ist;
  873. bool UIMLView::isKnownElement(XML::Element* zElement)
  874. {
  875. for (UIMLElement* element : knownElements)
  876. {
  877. if (element->isApplicableFor(*zElement)) return 1;
  878. }
  879. return 0;
  880. }
  881. // setzt den inhalt der view
  882. // uiml: Ein xml element gemät des ksg uiml standarts
  883. void UIMLView::setUIML(XML::Element* uiml)
  884. {
  885. if (dom)
  886. { // update dom and members
  887. dom = uiml;
  888. update();
  889. }
  890. else
  891. { // initialize dom and members
  892. dom = uiml;
  893. for (auto i = dom->getChilds(); i; i++)
  894. {
  895. Zeichnung* z = parseElement(*i.val(), *this);
  896. if (z) z->release();
  897. }
  898. }
  899. }
  900. // setzt den inhalt der view
  901. // uiml: Ein xml text gemät des ksg uiml standarts
  902. void UIMLView::setUIML(Text uiml)
  903. {
  904. setUIML(new XML::Element(uiml));
  905. }
  906. // Gibt eine zeichnung zurück, welche in uiml eine bestimmte id hat
  907. // id: die id der Zeichnung
  908. Zeichnung* UIMLView::zZeichnungById(const char* id)
  909. {
  910. return members->z(id, textLength(id));
  911. }
  912. // Gibt eine zeichnung zurück, welche in uiml eine bestimmte id hat
  913. // id: die id der Zeichnung
  914. Zeichnung* UIMLView::getZeichnungById(const char* id)
  915. {
  916. return members->get(id, textLength(id));
  917. }
  918. void Framework::UIMLView::update()
  919. {
  920. for (auto i = dom->getChilds(); i; i++)
  921. {
  922. Text id = i->getAttributeValue("id");
  923. Zeichnung* z = zZeichnungById(id);
  924. if (!id.getLength() || !z || !updateElement(*i.val(), *z, *this))
  925. {
  926. if (z) removeZeichnung(*z);
  927. z = parseElement(*i.val(), *this);
  928. if (z) z->release();
  929. }
  930. }
  931. }
  932. // aktualisiert größe und position aller Zeichnungen gemäß den spezifikationen
  933. // in UIML
  934. void UIMLView::layout()
  935. {
  936. if (dom)
  937. {
  938. for (auto i = dom->getChilds(); i; i++)
  939. {
  940. Text id = i->getAttributeValue("id");
  941. Zeichnung* z = zZeichnungById(id);
  942. if (z)
  943. {
  944. layout(*i.val(),
  945. *z,
  946. this->getInnenBreite(),
  947. this->getInnenHeight(),
  948. *this);
  949. }
  950. }
  951. }
  952. }
  953. // fügt ein element hinzu
  954. // uiml: Ein xml text gemät des KSG UIML standarts, welcher das neue Objekt
  955. // darstellt
  956. Text UIMLView::addMember(Text uiml)
  957. {
  958. XML::Element* e = new XML::Element(uiml);
  959. Zeichnung* z = parseElement(*e, *this);
  960. if (z)
  961. {
  962. dom->addChildAtFront(e);
  963. z->release();
  964. }
  965. return e->getAttributeValue("id");
  966. }
  967. // fügt ein element zu einem Elternelement hinzu (funktioniert momentan nur mit
  968. // frame Objekten)
  969. // uiml: Ein xml text gemät des KSG UIML standarts, welcher das neue Objekt
  970. // darstellt
  971. Text UIMLView::addMember(Text uiml, Text parentId)
  972. {
  973. XML::Element* e = new XML::Element(uiml);
  974. XML::Editor ed = dom->selectChildren();
  975. while (ed.begin())
  976. {
  977. XML::Editor ed2 = ed.whereAttributeEquals("id", parentId);
  978. if (ed2.begin())
  979. {
  980. if (ed2.begin()->getName().istGleich("frame"))
  981. {
  982. Zeichnung* z = parseElement(*e, *this);
  983. if (z)
  984. {
  985. dynamic_cast<Fenster*>(
  986. members->z(parentId, parentId.getLength()))
  987. ->addMember(z);
  988. ed2.begin()->addChild(e);
  989. }
  990. return e->getAttributeValue("id");
  991. }
  992. }
  993. ed = ed.selectChildren();
  994. }
  995. e->release();
  996. return "";
  997. }
  998. // entfernt ein element
  999. // id: id des Elements
  1000. void UIMLView::removeMember(Text id)
  1001. {
  1002. XML::Editor e = dom->selectChildsByAttribute("id", id);
  1003. e.remove();
  1004. members->remove(id, id.getLength());
  1005. }
  1006. // Verarbeitet ein Tastatur Ereignis. Wird vom Framework automatisch aufgerufen
  1007. // te: Das Ereignis
  1008. void UIMLView::doTastaturEreignis(TastaturEreignis& te)
  1009. {
  1010. bool verarbeitet = te.verarbeitet;
  1011. ZeichnungHintergrund::doTastaturEreignis(te);
  1012. te.verarbeitet = verarbeitet;
  1013. if (dom)
  1014. {
  1015. for (auto i = dom->getChilds(); i; i++)
  1016. { // TODO render elements backwards
  1017. Zeichnung* z = members->z(i->getAttributeValue("id"),
  1018. i->getAttributeValue("id").getLength());
  1019. if (z) z->doTastaturEreignis(te);
  1020. }
  1021. }
  1022. }
  1023. // Updated den Zeichenhintergrund
  1024. // tickVal: Die vergangene Zeit in Sekunden, die seit dem Letzten Aufruf dieser
  1025. // Funktion verstrichen ist return: 1, wenn das Bild neu gezeichnet werden
  1026. // muss. 0 sonnst
  1027. bool UIMLView::tick(double tickVal)
  1028. {
  1029. if (dom)
  1030. {
  1031. for (auto i = dom->getChilds(); i; i++)
  1032. { // TODO render elements backwards
  1033. Zeichnung* z = members->z(i->getAttributeValue("id"),
  1034. i->getAttributeValue("id").getLength());
  1035. if (z) rend |= z->tick(tickVal);
  1036. }
  1037. }
  1038. return ZeichnungHintergrund::tick(tickVal);
  1039. }
  1040. // Zeichnet den Hintergrund eines Zeichnunges nach rObj
  1041. void UIMLView::render(Bild& rObj)
  1042. {
  1043. if (hatStyle(Zeichnung::Style::Sichtbar))
  1044. {
  1045. ZeichnungHintergrund::render(rObj);
  1046. if (dom)
  1047. {
  1048. if (!rObj.setDrawOptions(pos.x + getRahmenBreite(),
  1049. pos.y + getRahmenBreite(),
  1050. gr.x + getRahmenBreite() * 2,
  1051. gr.y + getRahmenBreite() * 2))
  1052. return;
  1053. bool vSc = hatStyle(Style::VScroll) && vertikalScrollBar;
  1054. bool hSc = hatStyle(Style::HScroll) && horizontalScrollBar;
  1055. rObj.addScrollOffset(hSc ? horizontalScrollBar->getScroll() : 0,
  1056. vSc ? vertikalScrollBar->getScroll() : 0);
  1057. for (int i = dom->getChildCount() - 1; i >= 0; i--)
  1058. { // TODO render elements backwards
  1059. XML::Element* e = dom->zChild(i);
  1060. Zeichnung* z = members->z(e->getAttributeValue("id"),
  1061. e->getAttributeValue("id").getLength());
  1062. if (z) z->render(rObj);
  1063. }
  1064. rObj.releaseDrawOptions();
  1065. }
  1066. }
  1067. }
  1068. // Gibt den Dom Tree ohne erhöhten reference counter zurück
  1069. // Änderungen am Dom Tree sollten vermieden werden (nur änderungen von
  1070. // attributen einzelner elemente sind erlaubt)
  1071. XML::Element* UIMLView::zDom() const
  1072. {
  1073. return dom;
  1074. }
  1075. // Gibt den Dom Tree zurück
  1076. // Änderungen am Dom Tree sollten vermieden werden (nur änderungen von
  1077. // attributen einzelner elemente sind erlaubt)
  1078. XML::Element* UIMLView::getDom() const
  1079. {
  1080. return dom ? dynamic_cast<XML::Element*>(dom->getThis()) : 0;
  1081. }
  1082. bool UIMLView::isApplicableFor(XML::Element& element)
  1083. {
  1084. for (UIMLElement* e : knownElements)
  1085. {
  1086. if (e->isApplicableFor(element)) return 1;
  1087. }
  1088. return 0;
  1089. }
  1090. Zeichnung* UIMLView::parseElement(
  1091. XML::Element& element, UIMLContainer& generalFactory)
  1092. {
  1093. Text id;
  1094. if (element.hasAttribute("id"))
  1095. id = element.getAttributeValue("id");
  1096. else
  1097. {
  1098. id = Text("_") += nextId++;
  1099. element.setAttribute("id", id);
  1100. }
  1101. Zeichnung* z = members->z(id, id.getLength());
  1102. if (!z)
  1103. {
  1104. // precompute attributes
  1105. if (element.hasAttribute("margin"))
  1106. {
  1107. Text m = element.getAttributeValue("margin");
  1108. if (!element.hasAttribute("margin-left"))
  1109. element.setAttribute("margin-left", m);
  1110. if (!element.hasAttribute("margin-top"))
  1111. element.setAttribute("margin-top", m);
  1112. if (!element.hasAttribute("margin-right"))
  1113. element.setAttribute("margin-right", m);
  1114. if (!element.hasAttribute("margin-bottom"))
  1115. element.setAttribute("margin-bottom", m);
  1116. }
  1117. if (element.hasAttribute("class"))
  1118. {
  1119. Text c = element.getAttributeValue("class");
  1120. while (1)
  1121. {
  1122. Text* t;
  1123. if (c.hat(","))
  1124. t = c.getTeilText(0, c.positionVon(','));
  1125. else
  1126. t = new Text(c);
  1127. XML::Editor ce
  1128. = dom->selectChildsByName("class").whereAttributeEquals(
  1129. "id", *t);
  1130. for (auto i = ce.begin(); i; i++)
  1131. {
  1132. for (auto j = i->getAttributeNames(),
  1133. k = i->getAttributeValues();
  1134. j && k;
  1135. j++, k++)
  1136. {
  1137. if (!element.hasAttribute(j->getText()))
  1138. element.setAttribute(j->getText(), i->getText());
  1139. }
  1140. }
  1141. t->release();
  1142. if (c.hat(","))
  1143. c.remove(0, c.positionVon(',' + 1));
  1144. else
  1145. break;
  1146. }
  1147. }
  1148. if (element.hasAttribute("text-align"))
  1149. {
  1150. if (!element.hasAttribute("text-align-horizontal"))
  1151. element.setAttribute("text-align-horizontal",
  1152. element.getAttributeValue("text-align"));
  1153. if (!element.hasAttribute("text-align-vertical"))
  1154. element.setAttribute("text-align-vertical",
  1155. element.getAttributeValue("text-align"));
  1156. }
  1157. // create objects
  1158. for (UIMLElement* e : knownElements)
  1159. {
  1160. if (e->isApplicableFor(element))
  1161. {
  1162. z = e->parseElement(element, *this);
  1163. break;
  1164. }
  1165. }
  1166. if (z)
  1167. {
  1168. if (hatStyle(Style::GlobalMouseEvent))
  1169. {
  1170. z->addMausEreignis(
  1171. [this, z](void* p, void* o, MausEreignis me) {
  1172. return dom->selectChildren()
  1173. .selectAllElements()
  1174. .whereAttributeEquals("id", getZeichnungId(*z))
  1175. .getFirstElement()
  1176. .map<bool>([this, &me, z](
  1177. RCPointer<XML::Element> element) {
  1178. return onMemberMouseEvent
  1179. ? onMemberMouseEvent(*element, *z, me)
  1180. : 0;
  1181. })
  1182. .orElse(0);
  1183. });
  1184. }
  1185. if (hatStyle(Style::GlobalTastaturEvent))
  1186. {
  1187. z->addTastaturEreignis(
  1188. [this, z](void* p, void* o, TastaturEreignis te) {
  1189. return dom->selectChildren()
  1190. .selectAllElements()
  1191. .whereAttributeEquals("id", getZeichnungId(*z))
  1192. .getFirstElement()
  1193. .map<bool>([this, &te, z](
  1194. RCPointer<XML::Element> element) {
  1195. return onMemberKeyboardEvent
  1196. ? onMemberKeyboardEvent(
  1197. *element, *z, te)
  1198. : 0;
  1199. })
  1200. .orElse(0);
  1201. });
  1202. }
  1203. members->set(
  1204. id, id.getLength(), dynamic_cast<Zeichnung*>(z->getThis()));
  1205. idList.add(new Text(id));
  1206. memberList.add(z);
  1207. }
  1208. }
  1209. else
  1210. z->getThis();
  1211. return z;
  1212. }
  1213. bool Framework::UIMLView::updateElement(
  1214. XML::Element& element, Zeichnung& z, UIMLContainer& generalFactory)
  1215. {
  1216. for (UIMLElement* e : knownElements)
  1217. {
  1218. if (e->isApplicableFor(element))
  1219. {
  1220. return e->updateElement(element, z, *this);
  1221. }
  1222. }
  1223. return false;
  1224. }
  1225. void UIMLView::layout(XML::Element& element,
  1226. Zeichnung& z,
  1227. int pWidth,
  1228. int pHeight,
  1229. UIMLContainer& generalLayouter)
  1230. {
  1231. for (UIMLElement* e : knownElements)
  1232. {
  1233. if (e->isApplicableFor(element))
  1234. {
  1235. e->layout(element, z, pWidth, pHeight, *this);
  1236. break;
  1237. }
  1238. }
  1239. }
  1240. Text Framework::UIMLView::getZeichnungId(Zeichnung& z)
  1241. {
  1242. int index = memberList.getWertIndex(&z);
  1243. if (index >= 0) return *idList.z(index);
  1244. return "";
  1245. }
  1246. void Framework::UIMLView::removeZeichnung(Zeichnung& z)
  1247. {
  1248. int index = memberList.getWertIndex(&z);
  1249. if (index >= 0)
  1250. {
  1251. Text id = *idList.z(index);
  1252. idList.remove(index);
  1253. memberList.remove(index);
  1254. members->remove(id, id.getLength());
  1255. }
  1256. }
  1257. bool Framework::UIMLView::registerZeichnung(const char* id, Zeichnung* z)
  1258. {
  1259. Zeichnung* existing = members->z(id, textLength(id));
  1260. if (existing)
  1261. {
  1262. z->release();
  1263. return 0;
  1264. }
  1265. members->set(id, textLength(id), z);
  1266. return 1;
  1267. }
  1268. const UIInit& UIMLView::getFactory()
  1269. {
  1270. return init;
  1271. }
  1272. //! calculates the needed size for all content elements to be visible
  1273. Punkt UIMLView::calculateContentSize()
  1274. {
  1275. Punkt maxP(0, 0);
  1276. for (int i = dom->getChildCount() - 1; i >= 0; i--)
  1277. { // TODO render elements backwards
  1278. XML::Element* e = dom->zChild(i);
  1279. Zeichnung* z = members->z(
  1280. e->getAttributeValue("id"), e->getAttributeValue("id").getLength());
  1281. if (z)
  1282. {
  1283. maxP.x = MAX(maxP.x, z->getPosition().x + z->getBreite());
  1284. maxP.y = MAX(maxP.y, z->getPosition().y + z->getHeight());
  1285. }
  1286. }
  1287. maxP.x += 2 * getRahmenBreite();
  1288. maxP.y += 2 * getRahmenBreite();
  1289. return maxP;
  1290. }