UIMLView.cpp 51 KB

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