TextFeld.cpp 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885
  1. #include "TextFeld.h"
  2. #include <math.h>
  3. #include "AlphaFeld.h"
  4. #include "Bild.h"
  5. #include "Fenster.h"
  6. #include "Globals.h"
  7. #include "MausEreignis.h"
  8. #include "Rahmen.h"
  9. #include "Schrift.h"
  10. #include "Scroll.h"
  11. #include "TastaturEreignis.h"
  12. #include "Text.h"
  13. #include "ToolTip.h"
  14. using namespace Framework;
  15. #ifndef test
  16. # define test
  17. bool TextStyle::equals(const TextStyle& rhs)
  18. {
  19. return fontSize == rhs.fontSize && fontColor == rhs.fontColor
  20. && selectedColor == rhs.selectedColor
  21. && selectedBackcroundColor == rhs.selectedBackcroundColor
  22. && underlined == rhs.underlined && selected == rhs.selected
  23. && interactParam == rhs.interactParam
  24. && rendererIndex == rhs.rendererIndex;
  25. }
  26. #endif
  27. TextFeld::TextStyleManager::TextStyleManager()
  28. : ReferenceCounter(),
  29. renderer(new RCArray<TextRenderer>()),
  30. index(0),
  31. styleIndex(0),
  32. text(0)
  33. {
  34. current.beginIndex = 0;
  35. current.fontColor = 0xFFFFFFFF;
  36. current.fontSize = 12;
  37. current.selected = 0;
  38. current.selectedColor = 0xFFFFFFFF;
  39. current.selectedBackcroundColor = 0xFF0000FF;
  40. current.underlined = 0;
  41. current.interactParam = 0;
  42. current.rendererIndex = 0;
  43. textStyle.add(current);
  44. }
  45. TextFeld::TextStyleManager::~TextStyleManager()
  46. {
  47. if (renderer) renderer->release();
  48. if (text) text->release();
  49. }
  50. // Setzt den Style eines Textabschnittes
  51. // begin: die startposition des Abschnittes
  52. // end: die endposition des Abschnittes (nicht enthalten)
  53. void TextFeld::TextStyleManager::setTextStyle(
  54. int begin, int end, TextStyle style)
  55. {
  56. if (begin < 0 || begin > end || begin > text->getLength()) return;
  57. int sc = textStyle.getEintragAnzahl();
  58. int index = -1;
  59. TextStyle s = textStyle.get(0);
  60. // suche bis zur richtigen stelle im stylearray
  61. for (int i = 0; i < sc; i++)
  62. {
  63. if (textStyle.get(i).beginIndex >= begin)
  64. {
  65. index = i;
  66. if (textStyle.get(i).beginIndex > begin)
  67. s = textStyle.get(i - 1);
  68. else
  69. {
  70. s = textStyle.get(i);
  71. textStyle.remove(i);
  72. sc--;
  73. }
  74. break;
  75. }
  76. }
  77. style.beginIndex = begin;
  78. s.beginIndex = end;
  79. if (index < 0)
  80. { // hinten an styles anfügen
  81. textStyle.add(style);
  82. textStyle.add(s);
  83. }
  84. else
  85. { // in die mitte des style arrays einfügen
  86. textStyle.add(style, index);
  87. for (int i = index + 1; i < sc + 1; i++)
  88. { // styles entfernen die überschrieben wurden
  89. if (textStyle.get(i).beginIndex <= end
  90. && textStyle.get(i).beginIndex > begin)
  91. {
  92. s = textStyle.get(i);
  93. textStyle.remove(i);
  94. i--;
  95. sc--;
  96. }
  97. }
  98. s.beginIndex = end;
  99. textStyle.add(s, index + 1);
  100. }
  101. cleanupStyles();
  102. }
  103. // Entfernt einen Textabschnitt
  104. // begin: der index des ersten betroffenen zeichens
  105. // end: der index des ersten zeichens nach dem abschnitt
  106. void TextFeld::TextStyleManager::removeText(int begin, int end)
  107. {
  108. int sc = textStyle.getEintragAnzahl();
  109. for (int i = 1; i < sc; i++)
  110. {
  111. TextStyle s = textStyle.get(i);
  112. if (s.beginIndex >= begin && s.beginIndex < end)
  113. {
  114. textStyle.remove(i);
  115. i--;
  116. sc--;
  117. }
  118. if (s.beginIndex >= end)
  119. {
  120. s.beginIndex -= end - begin;
  121. textStyle.set(s, i);
  122. }
  123. }
  124. text->remove(begin, end);
  125. cleanupStyles();
  126. }
  127. // Fügt ein Text an einer bestimmten Position ein
  128. // pos: die position des neuen Textausschnitts
  129. // text: der neue Text
  130. void TextFeld::TextStyleManager::insertText(int pos, const char* text)
  131. {
  132. int len = textLength(text);
  133. this->text->insert(pos, text);
  134. int sc = textStyle.getEintragAnzahl();
  135. for (int i = 0; i < sc; i++)
  136. {
  137. TextStyle s = textStyle.get(i);
  138. if (s.beginIndex > pos)
  139. {
  140. s.beginIndex += len;
  141. textStyle.set(s, i);
  142. }
  143. }
  144. cleanupStyles();
  145. }
  146. // Entfernt nicht benötiegte gleiche styles
  147. void TextFeld::TextStyleManager::cleanupStyles()
  148. {
  149. int sc = textStyle.getEintragAnzahl();
  150. TextStyle last = textStyle.get(0);
  151. for (int i = 1; i < sc; i++)
  152. {
  153. if (textStyle.get(i).beginIndex == last.beginIndex)
  154. {
  155. last = textStyle.get(i);
  156. textStyle.remove(i - 1);
  157. i--;
  158. sc--;
  159. continue;
  160. }
  161. if (textStyle.get(i).equals(last)
  162. || (text && textStyle.get(i).beginIndex > text->getLength()))
  163. {
  164. textStyle.remove(i);
  165. i--;
  166. sc--;
  167. }
  168. else
  169. last = textStyle.get(i);
  170. }
  171. }
  172. // gibt eine referenz auf das style objekt zurück
  173. TextStyle& TextFeld::TextStyleManager::currentStyle()
  174. {
  175. return current;
  176. }
  177. // gibt den aktuellen text renderer zurück
  178. TextRenderer* TextFeld::TextStyleManager::zCurrentRenderer()
  179. {
  180. if (renderer->getEintragAnzahl() == 0) return 0;
  181. TextRenderer* tr = renderer->z(current.rendererIndex);
  182. if (!tr) tr = renderer->z(0);
  183. if (tr) tr->setSchriftSize(current.fontSize);
  184. return tr;
  185. }
  186. // ändert den inhalt des style objektes auf den style des nächsten zeichens
  187. bool TextFeld::TextStyleManager::nextStyle()
  188. {
  189. index++;
  190. if (textStyle.getEintragAnzahl() > styleIndex + 1
  191. && index >= textStyle.get(styleIndex + 1).beginIndex)
  192. current = textStyle.get(styleIndex++ + 1);
  193. return text && index < text->getLength();
  194. }
  195. // ändert den inhalt des style objektes auf den style des angegebenen zeichens
  196. // index: der Index des Zeichens zu dem gesprungen werden soll
  197. // gibt 0 zurück falls es das zeichen nicht gibt
  198. bool TextFeld::TextStyleManager::stepTo(int index)
  199. {
  200. resetIteration();
  201. while (this->index < index && nextStyle())
  202. ;
  203. return text && this->index == index;
  204. }
  205. // ändert den inhalt des style objektes auf den style des ersten zeichens
  206. void TextFeld::TextStyleManager::resetIteration()
  207. {
  208. index = 0;
  209. styleIndex = 0;
  210. current = textStyle.get(0);
  211. }
  212. // Gibt den Style eines bestimmten zeichens zurück
  213. // index: Der index des Zeichensf
  214. TextStyle TextFeld::TextStyleManager::getTextStyle(int index) const
  215. {
  216. TextStyle last = textStyle.get(0);
  217. int ind = 0;
  218. for (auto i = textStyle.begin(); i && ind <= index; ind++)
  219. {
  220. if (i._.beginIndex <= ind)
  221. {
  222. last = i;
  223. i++;
  224. }
  225. }
  226. return last;
  227. }
  228. // Inhalt der TextFeld Klasse aus TextFeld.h
  229. // Konstruktor
  230. TextFeld::TextFeld()
  231. : ZeichnungHintergrund(),
  232. tm(new TextStyleManager()),
  233. autoLineBreakSpacing(0),
  234. showChar(0),
  235. cpos(0),
  236. tickVal(0),
  237. mausKlick(0)
  238. {
  239. charEvent = 0;
  240. horizontalScrollBar = new HScrollBar();
  241. vertikalScrollBar = new VScrollBar();
  242. this->setMausEreignis(_ret1ME);
  243. this->setTastaturEreignis(_ret1TE);
  244. }
  245. // Destruktor
  246. TextFeld::~TextFeld()
  247. {
  248. tm->release();
  249. if (autoLineBreakSpacing) autoLineBreakSpacing->release();
  250. }
  251. void TextFeld::doMausEreignis(MausEreignis& me, bool userRet) // Maus Ereignis
  252. {
  253. if (!userRet) return;
  254. if (hatStyleNicht(Style::Editierbar))
  255. {
  256. int rbr = 0;
  257. if (rahmen) rbr = rahmen->getRBreite();
  258. if (((vertikalScrollBar && hatStyle(Style::VScroll))
  259. || (horizontalScrollBar && hatStyle(Style::HScroll)))
  260. && me.mx > rbr && me.mx < gr.x - rbr && me.my > rbr
  261. && me.my < gr.y - rbr)
  262. {
  263. me.verarbeitet |= vertikalScrollBar->doMausMessage(
  264. gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me);
  265. me.verarbeitet |= horizontalScrollBar->doMausMessage(rbr,
  266. gr.y - rbr * 2 - 15,
  267. gr.x - rbr * 2
  268. - ((vertikalScrollBar && hatStyle(Style::VScroll)) ? 15
  269. : 0),
  270. 15,
  271. me);
  272. }
  273. if (me.mx >= 0 && me.mx <= gr.x && me.my >= 0 && me.my <= gr.y
  274. && !me.verarbeitet && hatStyle(Style::Sichtbar))
  275. {
  276. int scrollHi = (vertikalScrollBar && hatStyle(Style::VScroll))
  277. ? vertikalScrollBar->getScroll()
  278. : 0;
  279. int scrollBr = (horizontalScrollBar && hatStyle(Style::HScroll))
  280. ? horizontalScrollBar->getScroll()
  281. : 0;
  282. int xxx = me.mx - rbr + scrollBr;
  283. int yyy = me.my - rbr + scrollHi;
  284. int mausChar = getTextIndexAt(xxx, yyy);
  285. if (mausChar >= 0)
  286. {
  287. TextStyle s = tm->getTextStyle(mausChar);
  288. if (charEvent && s.interactParam)
  289. charEvent(mausChar, s.interactParam, me);
  290. }
  291. if (charEvent) me.verarbeitet = 1;
  292. }
  293. mausKlick = 0;
  294. return;
  295. }
  296. if (!me.verarbeitet)
  297. {
  298. if (hatStyleNicht(Style::Fokus))
  299. {
  300. mausKlick = 0;
  301. if (me.id == Framework::ME_PLinks) addStyle(Style::Fokus);
  302. }
  303. int rbr = 0;
  304. if (rahmen) rbr = rahmen->getRBreite();
  305. if (vertikalScrollBar && hatStyle(Style::VScroll))
  306. {
  307. if (vertikalScrollBar->doMausMessage(
  308. gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me))
  309. {
  310. me.verarbeitet = 1;
  311. return;
  312. }
  313. }
  314. if (horizontalScrollBar && hatStyle(Style::HScroll))
  315. {
  316. if (horizontalScrollBar->doMausMessage(rbr,
  317. gr.y - rbr - 15,
  318. gr.x - rbr * 2
  319. - ((vertikalScrollBar && hatStyle(Style::VScroll)) ? 15
  320. : 0),
  321. 15,
  322. me))
  323. {
  324. me.verarbeitet = 1;
  325. return;
  326. }
  327. }
  328. bool shift = getTastenStand(T_Shift);
  329. bool strg = getTastenStand(T_Strg);
  330. int tbr = getTextWidth();
  331. int thi = getTextHeight();
  332. int scrollHi = (vertikalScrollBar && hatStyle(Style::VScroll))
  333. ? vertikalScrollBar->getScroll()
  334. : 0;
  335. int scrollBr = (horizontalScrollBar && hatStyle(Style::HScroll))
  336. ? horizontalScrollBar->getScroll()
  337. : 0;
  338. int xxx = me.mx - rbr + scrollBr;
  339. int yyy = me.my - rbr + scrollHi;
  340. int mausChar = getTextIndexAt(xxx, yyy);
  341. int scrollBreite = (vertikalScrollBar && hatStyle(Style::VScroll)) * 15;
  342. int scrollHeight
  343. = (horizontalScrollBar && hatStyle(Style::HScroll)) * 15;
  344. if (hatStyle(Style::HCenter))
  345. xxx -= (((gr.x - scrollBreite) / 2) - tbr / 2) - rbr;
  346. if (hatStyle(Style::VCenter) && hatStyleNicht(Style::VScroll))
  347. yyy -= (((gr.y - scrollHeight) / 2) - thi / 2) - rbr;
  348. if (mausChar >= 0)
  349. {
  350. TextStyle s = tm->getTextStyle(mausChar);
  351. if (charEvent) charEvent(mausChar, s.interactParam, me);
  352. }
  353. if (me.mx < gr.x - rbr - 15)
  354. {
  355. if (tm->renderer)
  356. {
  357. int ncpos = getCurserPosAt(xxx, yyy);
  358. if (me.id == Framework::ME_PLinks)
  359. {
  360. if (ncpos != -1)
  361. {
  362. if (shift && cpos != ncpos)
  363. addAuswahl(MIN(cpos, ncpos), MAX(cpos, ncpos));
  364. else if (!shift && !mausKlick && !strg)
  365. deselectAuswahl();
  366. cpos = ncpos;
  367. rend = 1;
  368. if (vertikalScrollBar && hatStyle(Style::VScroll))
  369. updateVScroll();
  370. if (horizontalScrollBar && hatStyle(Style::HScroll))
  371. updateHScroll();
  372. }
  373. mausKlick = 1;
  374. }
  375. if (me.id == ME_Bewegung && mausKlick)
  376. {
  377. if (ncpos != -1)
  378. {
  379. rend = 1;
  380. if (cpos != ncpos)
  381. invertAuswahl(MIN(cpos, ncpos), MAX(cpos, ncpos));
  382. cpos = ncpos;
  383. if (vertikalScrollBar && hatStyle(Style::VScroll))
  384. updateVScroll(cpos);
  385. if (horizontalScrollBar && hatStyle(Style::HScroll))
  386. updateHScroll(cpos);
  387. }
  388. }
  389. if (me.id == ME_RLinks)
  390. {
  391. if (ncpos != -1)
  392. {
  393. rend = 1;
  394. if (cpos != ncpos)
  395. invertAuswahl(MIN(cpos, ncpos), MAX(cpos, ncpos));
  396. cpos = ncpos;
  397. if (vertikalScrollBar && hatStyle(Style::VScroll))
  398. updateVScroll(cpos);
  399. if (horizontalScrollBar && hatStyle(Style::HScroll))
  400. updateHScroll(cpos);
  401. }
  402. mausKlick = 0;
  403. }
  404. }
  405. }
  406. }
  407. me.verarbeitet = 1;
  408. }
  409. int TextFeld::getTextHeight() const
  410. {
  411. if (!tm || !tm->text) return 0;
  412. tm->resetIteration();
  413. int th = 0;
  414. int len = tm->text->getLength();
  415. const char* text = tm->text->getText();
  416. Text txtWithLineBreaks;
  417. if (hatStyle(Style::AutoLineBreak))
  418. {
  419. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  420. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  421. text = txtWithLineBreaks;
  422. len = txtWithLineBreaks.getLength();
  423. }
  424. int max = 0;
  425. int abstand = 0;
  426. for (int i = 0; i < len; i++)
  427. {
  428. if (text[i] == '\n')
  429. {
  430. th += max + abstand;
  431. abstand = 0;
  432. max = 0;
  433. tm->nextStyle();
  434. continue;
  435. }
  436. TextRenderer* r = tm->zCurrentRenderer();
  437. if (r)
  438. {
  439. int tmp = r->getZeilenHeight();
  440. max = max >= tmp ? max : tmp;
  441. if (max == tmp) abstand = r->getZeilenAbstand();
  442. }
  443. tm->nextStyle();
  444. }
  445. if (max > 0) th += max;
  446. return th;
  447. }
  448. int TextFeld::getTextWidth() const
  449. {
  450. if (!tm || !tm->text) return 0;
  451. tm->resetIteration();
  452. int maxBr = 0;
  453. int len = tm->text->getLength();
  454. const char* text = tm->text->getText();
  455. Text txtWithLineBreaks;
  456. if (hatStyle(Style::AutoLineBreak))
  457. {
  458. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  459. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  460. text = txtWithLineBreaks;
  461. len = txtWithLineBreaks.getLength();
  462. }
  463. int lineBr = 0;
  464. char buff[] = {0, 0};
  465. for (int i = 0; i < len; i++)
  466. {
  467. buff[0] = text[i];
  468. if (text[i] == '\n')
  469. {
  470. maxBr = maxBr >= lineBr ? maxBr : lineBr;
  471. lineBr = 0;
  472. tm->nextStyle();
  473. continue;
  474. }
  475. TextRenderer* r = tm->zCurrentRenderer();
  476. if (r) lineBr += r->getTextBreite(buff);
  477. tm->nextStyle();
  478. }
  479. if (lineBr > 0) maxBr = maxBr >= lineBr ? maxBr : lineBr;
  480. return maxBr;
  481. }
  482. // charEvent: eine funktion die aufgerufen wird, wenn sich die maus auf einem
  483. // bestimmten zeichen befindet und der interactParam im style != 0 ist
  484. // aufruf: charEvent( charIndex, interactParam, mausEreignis );
  485. void TextFeld::setCharEvent(
  486. std::function<void(int, int, MausEreignis me)> charEvent)
  487. {
  488. this->charEvent = charEvent;
  489. }
  490. void TextFeld::setText(Text* txt) // setzt den angezeigten Text
  491. {
  492. lockZeichnung();
  493. if (!tm->text) tm->text = new Text();
  494. tm->text->setText(txt);
  495. if (hatStyle(Style::VScroll)) updateVScroll();
  496. if (hatStyle(Style::HScroll)) updateHScroll();
  497. unlockZeichnung();
  498. rend = 1;
  499. }
  500. void TextFeld::setTextZ(Text* txt) // setzt einen Zeiger zum angezeigten Text
  501. {
  502. lockZeichnung();
  503. if (tm->text) tm->text->release();
  504. tm->text = txt;
  505. if (hatStyle(Style::VScroll)) updateVScroll();
  506. if (hatStyle(Style::HScroll)) updateHScroll();
  507. rend = 1;
  508. unlockZeichnung();
  509. }
  510. void TextFeld::setText(const char* txt) // setzt den angezeigten Text
  511. {
  512. lockZeichnung();
  513. if (!tm->text) tm->text = new Text();
  514. tm->text->setText(txt);
  515. if (hatStyle(Style::VScroll)) updateVScroll();
  516. if (hatStyle(Style::HScroll)) updateHScroll();
  517. rend = 1;
  518. unlockZeichnung();
  519. }
  520. // setzt den Text mit styles
  521. // txt: der Text
  522. // format: \x1: aktiviert unterschtrich
  523. // \x2FF: setzt die schriftgröße für den folgenden text.
  524. // FF ist ein zweistelliger Hex Wert
  525. // \x3AARRGGBB: setzt die schriftfarbe.
  526. // AARRGGBB ist ein 8 stelliger hex wert mit jeweils zwei zeichen
  527. // für alpha, rot, grün n blau
  528. // \x4AARRGGBB: setzt die farbe des ausgewählten textes.
  529. // AARRGGBB ist ein 8 stelliger hex wert mit jeweils zwei zeichen
  530. // für alpha, rot, grün n blau
  531. // \x5AARRGGBB: setzt die hintergrundfarbe des ausgewählten textes.
  532. // AARRGGBB ist ein 8 stelliger hex wert mit jeweils zwei zeichen
  533. // für alpha, rot, grün n blau
  534. // \x6FF: setzt text renderer index.
  535. // FF ist ein zweistelliger Hex Wert
  536. // \x7: deaktiviert unterschtrich
  537. // \x8FFFFFFFF: set interact param.
  538. // FFFFFFFF ist ein 8 stelliger hex wert
  539. void TextFeld::setFormattedText(const char* txt)
  540. {
  541. lockZeichnung();
  542. if (!tm->text) tm->text = new Text();
  543. tm->textStyle.leeren();
  544. TextStyle current;
  545. current.beginIndex = 0;
  546. current.fontColor = 0xFFFFFFFF;
  547. current.fontSize = 12;
  548. current.selected = 0;
  549. current.selectedColor = 0xFFFFFFFF;
  550. current.selectedBackcroundColor = 0xFF0000FF;
  551. current.underlined = 0;
  552. current.interactParam = 0;
  553. current.rendererIndex = 0;
  554. tm->textStyle.add(current);
  555. Text result = "";
  556. for (int i = 0; 1; i++)
  557. {
  558. bool br = 0;
  559. current.beginIndex = result.getLength();
  560. switch (txt[i])
  561. {
  562. case 0:
  563. br = 1;
  564. break;
  565. case 1:
  566. current.underlined = 1;
  567. tm->textStyle.add(current);
  568. break;
  569. case 2:
  570. {
  571. Text p = "0x";
  572. p.append(txt + i + 1, 2);
  573. current.fontSize = (unsigned char)(int)p;
  574. tm->textStyle.add(current);
  575. i += 2;
  576. break;
  577. }
  578. case 3:
  579. {
  580. Text p = "0x";
  581. p.append(txt + i + 1, 8);
  582. current.fontColor = (int)p;
  583. tm->textStyle.add(current);
  584. i += 8;
  585. }
  586. break;
  587. case 4:
  588. {
  589. Text p = "0x";
  590. p.append(txt + i + 1, 8);
  591. current.selectedColor = (int)p;
  592. tm->textStyle.add(current);
  593. i += 8;
  594. break;
  595. }
  596. case 5:
  597. {
  598. Text p = "0x";
  599. p.append(txt + i + 1, 8);
  600. current.selectedBackcroundColor = (int)p;
  601. tm->textStyle.add(current);
  602. i += 8;
  603. break;
  604. }
  605. case 6:
  606. {
  607. Text p = "0x";
  608. p.append(txt + i + 1, 2);
  609. current.rendererIndex = (unsigned char)(int)p;
  610. tm->textStyle.add(current);
  611. i += 2;
  612. }
  613. break;
  614. case 7:
  615. current.underlined = 0;
  616. tm->textStyle.add(current);
  617. break;
  618. case 8:
  619. {
  620. Text p = "0x";
  621. p.append(txt + i + 1, 8);
  622. current.interactParam = (int)p;
  623. tm->textStyle.add(current);
  624. i += 8;
  625. }
  626. break;
  627. default:
  628. result.append(txt[i]);
  629. }
  630. if (br) break;
  631. }
  632. tm->text->setText(result);
  633. tm->cleanupStyles();
  634. if (hatStyle(Style::VScroll)) updateVScroll();
  635. if (hatStyle(Style::HScroll)) updateHScroll();
  636. rend = 1;
  637. unlockZeichnung();
  638. }
  639. // fügt zeilenumbrüche so ein, dass der text nicht die breite des textfeldes
  640. // überschreitet
  641. void TextFeld::addLineBreaks(const char* spacing)
  642. {
  643. if (!tm->text) return;
  644. setFormattedText(addLineBreaksToText(tm->text->getText(), spacing));
  645. }
  646. Text TextFeld::addLineBreaksToText(const char* txt, const char* spacing) const
  647. {
  648. int lastPos = -1;
  649. int lastPos2 = -1;
  650. int x = 0;
  651. Text result = "";
  652. int len = (int)strlen(txt);
  653. int maxBr = getBreite();
  654. if (hatStyle(Style::VScroll) && vertikalScrollBar) maxBr -= 15;
  655. tm->resetIteration();
  656. TextStyle last;
  657. last.beginIndex = 0;
  658. last.fontColor = 0xFFFFFFFF;
  659. last.fontSize = 12;
  660. last.selected = 0;
  661. last.selectedColor = 0xFFFFFFFF;
  662. last.selectedBackcroundColor = 0xFF0000FF;
  663. last.underlined = 0;
  664. last.interactParam = 0;
  665. last.rendererIndex = 0;
  666. for (int i = 0; i < len; ++i)
  667. {
  668. if (last.fontSize != tm->current.fontSize)
  669. {
  670. char tmp[3] = {2, (char)tm->current.fontSize, 0};
  671. result += tmp;
  672. last.fontSize = tm->current.fontSize;
  673. }
  674. if (last.fontColor != tm->current.fontColor)
  675. {
  676. char tmp[6] = {3,
  677. (char)((tm->current.fontColor >> 24) & 0xFF),
  678. (char)((tm->current.fontColor >> 16) & 0xFF),
  679. (char)((tm->current.fontColor >> 8) & 0xFF),
  680. (char)(tm->current.fontColor & 0xFF),
  681. 0};
  682. result += tmp;
  683. last.fontColor = tm->current.fontColor;
  684. }
  685. if (last.selectedColor != tm->current.selectedColor)
  686. {
  687. char tmp[6] = {4,
  688. (char)((tm->current.selectedColor >> 24) & 0xFF),
  689. (char)((tm->current.selectedColor >> 16) & 0xFF),
  690. (char)((tm->current.selectedColor >> 8) & 0xFF),
  691. (char)(tm->current.selectedColor & 0xFF),
  692. 0};
  693. result += tmp;
  694. last.selectedColor = tm->current.selectedColor;
  695. }
  696. if (last.selectedBackcroundColor != tm->current.selectedBackcroundColor)
  697. {
  698. char tmp[6] = {5,
  699. (char)((tm->current.selectedBackcroundColor >> 24) & 0xFF),
  700. (char)((tm->current.selectedBackcroundColor >> 16) & 0xFF),
  701. (char)((tm->current.selectedBackcroundColor >> 8) & 0xFF),
  702. (char)(tm->current.selectedBackcroundColor & 0xFF),
  703. 0};
  704. result += tmp;
  705. last.selectedBackcroundColor = tm->current.selectedBackcroundColor;
  706. }
  707. if (last.underlined != tm->current.underlined)
  708. {
  709. char tmp[2] = {tm->current.underlined ? (char)1 : (char)7, 0};
  710. result += tmp;
  711. last.underlined = tm->current.underlined;
  712. }
  713. if (last.interactParam != tm->current.interactParam)
  714. {
  715. char tmp[6] = {8,
  716. (char)((tm->current.interactParam >> 24) & 0xFF),
  717. (char)((tm->current.interactParam >> 16) & 0xFF),
  718. (char)((tm->current.interactParam >> 8) & 0xFF),
  719. (char)(tm->current.interactParam & 0xFF),
  720. 0};
  721. result += tmp;
  722. last.interactParam = tm->current.interactParam;
  723. }
  724. if (last.rendererIndex != tm->current.rendererIndex)
  725. {
  726. char tmp[3] = {6, (char)tm->current.rendererIndex, 0};
  727. result += tmp;
  728. last.rendererIndex = tm->current.rendererIndex;
  729. }
  730. if (txt[i] == ' ')
  731. {
  732. lastPos = i;
  733. lastPos2 = result.getLength();
  734. x += tm->zCurrentRenderer()->getTextBreite(" ");
  735. result += " ";
  736. tm->nextStyle();
  737. continue;
  738. }
  739. if (txt[i] == '\t')
  740. {
  741. lastPos = i;
  742. lastPos2 = result.getLength();
  743. x += tm->zCurrentRenderer()->getTextBreite("\t");
  744. result += "\t";
  745. tm->nextStyle();
  746. continue;
  747. }
  748. if (txt[i] == '\n')
  749. {
  750. x = 0;
  751. lastPos = -1;
  752. lastPos2 = -1;
  753. result += "\n";
  754. tm->nextStyle();
  755. continue;
  756. }
  757. char buff[2] = {txt[i], 0};
  758. x += tm->zCurrentRenderer()->getTextBreite(buff);
  759. result += buff;
  760. if (x > maxBr && lastPos > -1)
  761. {
  762. result.remove(lastPos2, result.getLength());
  763. result += "\n";
  764. result += spacing;
  765. x = tm->zCurrentRenderer()->getTextBreite(spacing);
  766. i = lastPos;
  767. tm->stepTo(lastPos);
  768. lastPos = -1;
  769. lastPos2 = -1;
  770. last = tm->currentStyle();
  771. }
  772. tm->nextStyle();
  773. }
  774. return result;
  775. }
  776. void TextFeld::setAutoLineBreakSpacing(const char* spacing)
  777. {
  778. if (!autoLineBreakSpacing) autoLineBreakSpacing = new Text();
  779. autoLineBreakSpacing->setText(spacing);
  780. }
  781. // Setzt den Style eines Textabschnittes
  782. // begin: die startposition des Abschnittes
  783. // end: die endposition des Abschnittes (nicht enthalten)
  784. void TextFeld::setTextStyle(int begin, int end, TextStyle style)
  785. {
  786. tm->setTextStyle(begin, end, style);
  787. }
  788. void TextFeld::addZeile(const char* zeile) // fügt Zeile An
  789. {
  790. if (tm->text)
  791. {
  792. Text* txt = new Text(zeile);
  793. if (zeile[txt->getLength() - 1] != '\n') txt->append("\n");
  794. TextRenderer* r = tm->renderer->z(0);
  795. if (tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  796. .rendererIndex
  797. < tm->renderer->getEintragAnzahl())
  798. r = tm->renderer->z(
  799. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  800. .rendererIndex);
  801. if (r)
  802. {
  803. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  804. int rbr = (rahmen && hatStyle(Style::Rahmen)) ? rahmen->getRBreite()
  805. : 0;
  806. r->setSchriftSize(
  807. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  808. .fontSize);
  809. r->textFormatieren(txt, gr.x - ((int)vs * 15) - rbr * 2);
  810. }
  811. lockZeichnung();
  812. tm->text->append(txt->getText());
  813. unlockZeichnung();
  814. txt->release();
  815. if (hatStyle(Style::VScroll)) updateVScroll();
  816. if (hatStyle(Style::HScroll)) updateHScroll();
  817. rend = 1;
  818. }
  819. }
  820. // Fügt eine Zeile an den Text an
  821. // zeile: Die neue Zeile
  822. // color: Die Farbe der Zeile
  823. void TextFeld::addZeile(const char* zeile, int color)
  824. {
  825. if (tm->text)
  826. {
  827. Text* txt = new Text(zeile);
  828. if (zeile[txt->getLength() - 1] != '\n') txt->append("\n");
  829. TextRenderer* r = tm->renderer->z(0);
  830. if (tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  831. .rendererIndex
  832. < tm->renderer->getEintragAnzahl())
  833. r = tm->renderer->z(
  834. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  835. .rendererIndex);
  836. if (r)
  837. {
  838. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  839. int rbr = (rahmen && hatStyle(Style::Rahmen)) ? rahmen->getRBreite()
  840. : 0;
  841. r->setSchriftSize(
  842. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  843. .fontSize);
  844. r->textFormatieren(txt, gr.x - ((int)vs * 15) - rbr * 2);
  845. }
  846. lockZeichnung();
  847. tm->text->append(txt->getText());
  848. setSchriftFarbe(tm->text->getLength() - txt->getLength(),
  849. tm->text->getLength(),
  850. color);
  851. unlockZeichnung();
  852. txt->release();
  853. if (hatStyle(Style::VScroll)) updateVScroll();
  854. if (hatStyle(Style::HScroll)) updateHScroll();
  855. rend = 1;
  856. }
  857. }
  858. // Deselectiert alle textabschnitte
  859. void TextFeld::deselectAuswahl()
  860. {
  861. for (int i = 0; i < tm->textStyle.getEintragAnzahl(); i++)
  862. {
  863. TextStyle s = tm->textStyle.get(i);
  864. if (s.selected)
  865. {
  866. s.selected = 0;
  867. tm->textStyle.set(s, i);
  868. }
  869. }
  870. tm->cleanupStyles();
  871. }
  872. void TextFeld::setAuswahl(int pos1, int pos2) // setzt den Ausgewählten Text
  873. {
  874. deselectAuswahl();
  875. TextStyle s = tm->getTextStyle(pos1);
  876. s.selected = 1;
  877. tm->setTextStyle(pos1, pos2, s);
  878. }
  879. void TextFeld::setAuswahl(Punkt& auswahl)
  880. {
  881. deselectAuswahl();
  882. TextStyle s = tm->getTextStyle(auswahl.x);
  883. s.selected = 1;
  884. tm->setTextStyle(auswahl.x, auswahl.y, s);
  885. rend = 1;
  886. }
  887. void TextFeld::addAuswahl(int pos1, int pos2)
  888. {
  889. TextStyle s = tm->getTextStyle(pos1);
  890. s.selected = 1;
  891. tm->setTextStyle(pos1, pos2, s);
  892. }
  893. void TextFeld::addAuswahl(Punkt& auswahl)
  894. {
  895. TextStyle s = tm->getTextStyle(auswahl.x);
  896. s.selected = 1;
  897. tm->setTextStyle(auswahl.x, auswahl.y, s);
  898. rend = 1;
  899. }
  900. // Setzt den ausgewählten textabschnitt fest
  901. // begin: Die Cursorposition im Text
  902. // end: Die Position im Text, bis zu der der Text eingefärbt werden soll
  903. void TextFeld::invertAuswahl(int begin, int end)
  904. {
  905. for (int i = begin; i < end; i++)
  906. {
  907. TextStyle s = tm->getTextStyle(i);
  908. s.selected = !s.selected;
  909. tm->setTextStyle(i, i + 1, s);
  910. rend = 1;
  911. }
  912. }
  913. // ersetzt alle ausgewählten Textabschnitte mit einem text
  914. // text: der neue Text
  915. void TextFeld::replaceAuswahl(const char* text)
  916. {
  917. tm->cleanupStyles();
  918. int sa = tm->textStyle.getEintragAnzahl();
  919. int last = tm->text->getLength();
  920. int si = 0;
  921. for (int i = sa - 1; i >= 0; i--)
  922. {
  923. TextStyle s = tm->textStyle.get(i);
  924. si = i;
  925. if (s.selected)
  926. {
  927. if ((i > 0 && !tm->textStyle.get(i - 1).selected) || i == 0)
  928. {
  929. s.selected = false;
  930. tm->textStyle.set(s, si);
  931. tm->removeText(s.beginIndex, last);
  932. tm->insertText(s.beginIndex, text);
  933. }
  934. }
  935. else
  936. last = s.beginIndex;
  937. }
  938. }
  939. void TextFeld::setTextRendererZ(TextRenderer* textRd)
  940. {
  941. if (tm->renderer)
  942. tm->renderer->leeren();
  943. else
  944. tm->renderer = new RCArray<TextRenderer>();
  945. tm->renderer->add(textRd);
  946. rend = 1;
  947. }
  948. // Fügt einen TextRenderer hinzu
  949. // textRd: Der Textrenderer
  950. void TextFeld::addTextRendererZ(TextRenderer* textRd)
  951. {
  952. if (!tm->renderer) tm->renderer = new RCArray<TextRenderer>();
  953. tm->renderer->add(textRd);
  954. }
  955. // Setzt die verwendeten TextRenderer
  956. // textRd: Die Textrenderer
  957. void TextFeld::setTextRendererZ(RCArray<TextRenderer>* textRd)
  958. {
  959. if (tm->renderer) tm->renderer->release();
  960. tm->renderer = textRd;
  961. }
  962. void TextFeld::setSchriftZ(Schrift* schrift) // setzt einen Zeiger zur Schrift
  963. {
  964. if (!tm->renderer) tm->renderer = new RCArray<TextRenderer>();
  965. if (!tm->renderer->getEintragAnzahl())
  966. tm->renderer->add(new TextRenderer(schrift));
  967. else
  968. tm->renderer->z(0)->setSchriftZ(schrift);
  969. rend = 1;
  970. }
  971. // Setzt einen Zeiger zur Schrift
  972. // rendererIndex: Der Index des Renderers dessen Schrift gesetzt werden soll
  973. // schrift: Die Schrift, die zum Textzeichnen verwendet werden soll.
  974. void TextFeld::setSchriftZ(int rendererIndex, Schrift* schrift)
  975. {
  976. if (!tm->renderer) tm->renderer = new RCArray<TextRenderer>();
  977. if (tm->renderer->getEintragAnzahl() <= rendererIndex)
  978. tm->renderer->add(new TextRenderer(schrift), rendererIndex);
  979. else
  980. tm->renderer->z(rendererIndex)->setSchriftZ(schrift);
  981. }
  982. void TextFeld::setSchriftSize(unsigned char gr) // setzt die Schriftgröße
  983. {
  984. TextStyle s = tm->textStyle.get(0);
  985. s.fontSize = gr;
  986. tm->textStyle.set(s, 0);
  987. rend = 1;
  988. }
  989. // Setzt die Schriftgröße (Standart: 12)
  990. // begin: Der Index des ersten betroffenen Zeichens
  991. // end: Der Index des ersten nicht betroffenen Zeichens
  992. // gr: Die Schriftgröße, die zum Textzeichnen verwendet werden soll
  993. void TextFeld::setSchriftSize(int begin, int end, unsigned char gr)
  994. {
  995. TextStyle s = tm->getTextStyle(begin);
  996. s.fontSize = gr;
  997. tm->setTextStyle(begin, end, s);
  998. rend = 1;
  999. }
  1000. void TextFeld::setSchriftFarbe(int fc) // setzt die Schrift Farbe
  1001. {
  1002. TextStyle s = tm->textStyle.get(0);
  1003. s.fontColor = fc;
  1004. tm->textStyle.set(s, 0);
  1005. rend = 1;
  1006. }
  1007. // Setzt die Schrift Farbe
  1008. // begin: Der Index des ersten betroffenen Zeichens
  1009. // end: Der Index des ersten nicht betroffenen Zeichens
  1010. // fc: Die Farbe, die zum Textzeichnen verwendet werden soll
  1011. void TextFeld::setSchriftFarbe(int begin, int end, int fc)
  1012. {
  1013. TextStyle s = tm->getTextStyle(begin);
  1014. s.fontColor = fc;
  1015. tm->setTextStyle(begin, end, s);
  1016. rend = 1;
  1017. }
  1018. void TextFeld::setSchowChar(unsigned char c) // bei Passwortfeld *
  1019. {
  1020. showChar = c;
  1021. rend = 1;
  1022. }
  1023. void TextFeld::setVScrollZuZeile(int zeile) // scrollt zur Zeile
  1024. {
  1025. if (vertikalScrollBar && tm->renderer && tm->renderer->getEintragAnzahl()
  1026. && tm->text && hatStyle(Style::Mehrzeilig))
  1027. {
  1028. lockZeichnung();
  1029. tm->resetIteration();
  1030. int len = tm->text->getLength();
  1031. int y = 0;
  1032. int lnum = 0;
  1033. const char* text = tm->text->getText();
  1034. Text txtWithLineBreaks;
  1035. if (hatStyle(Style::AutoLineBreak))
  1036. {
  1037. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1038. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  1039. text = txtWithLineBreaks;
  1040. len = txtWithLineBreaks.getLength();
  1041. }
  1042. int max = 0;
  1043. for (int i = 0; i < len && lnum < zeile; i++)
  1044. {
  1045. if (text[i] == '\n')
  1046. {
  1047. lnum++;
  1048. y += max;
  1049. max = 0;
  1050. tm->nextStyle();
  1051. continue;
  1052. }
  1053. TextRenderer* r = tm->zCurrentRenderer();
  1054. if (r)
  1055. {
  1056. int tmp = r->getZeilenabstand() + r->getZeilenHeight();
  1057. max = max >= tmp ? max : tmp;
  1058. }
  1059. tm->nextStyle();
  1060. }
  1061. unlockZeichnung();
  1062. vertikalScrollBar->scroll(y);
  1063. rend = 1;
  1064. }
  1065. }
  1066. void TextFeld::updateVScroll(int pos) // scrollt nach unten
  1067. {
  1068. if (pos == -1) pos = cpos;
  1069. if (vertikalScrollBar)
  1070. {
  1071. int sPos = 0;
  1072. int hi = 0;
  1073. int sPosZH = 0;
  1074. if (tm->text && tm->renderer)
  1075. {
  1076. if (hatStyleNicht(Style::Mehrzeilig)) tm->text->remove('\n');
  1077. hi = gr.y;
  1078. if (hatStyle(Style::Rahmen) && rahmen)
  1079. hi -= rahmen->getRBreite() * 2;
  1080. if (hatStyle(Style::HScroll) && horizontalScrollBar) hi -= 15;
  1081. int th = 0;
  1082. lockZeichnung();
  1083. tm->resetIteration();
  1084. int len = tm->text->getLength();
  1085. const char* text = tm->text->getText();
  1086. Text txtWithLineBreaks;
  1087. if (hatStyle(Style::AutoLineBreak))
  1088. {
  1089. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1090. autoLineBreakSpacing ? autoLineBreakSpacing->getText()
  1091. : "");
  1092. text = txtWithLineBreaks;
  1093. len = txtWithLineBreaks.getLength();
  1094. }
  1095. int max = 0;
  1096. int lastMax = 0;
  1097. for (int i = 0; i < len; i++)
  1098. {
  1099. if (text[i] == '\n')
  1100. {
  1101. if (i <= pos)
  1102. {
  1103. sPos += max;
  1104. sPosZH = max;
  1105. }
  1106. th += max;
  1107. lastMax = max;
  1108. max = 0;
  1109. tm->nextStyle();
  1110. continue;
  1111. }
  1112. TextRenderer* r = tm->zCurrentRenderer();
  1113. if (r)
  1114. {
  1115. int tmp = r->getZeilenabstand() + r->getZeilenHeight();
  1116. max = max >= tmp ? max : tmp;
  1117. }
  1118. tm->nextStyle();
  1119. }
  1120. if (max != lastMax && max > 0)
  1121. {
  1122. th += max;
  1123. lastMax = max;
  1124. }
  1125. th += lastMax;
  1126. unlockZeichnung();
  1127. vertikalScrollBar->update(th, hi);
  1128. }
  1129. if (sPos - sPosZH < vertikalScrollBar->getScroll())
  1130. vertikalScrollBar->scroll(sPos - sPosZH);
  1131. if (sPos + sPosZH > vertikalScrollBar->getScroll()
  1132. + vertikalScrollBar->getScrollData()->anzeige)
  1133. vertikalScrollBar->scroll(sPos + sPosZH * 2 - hi);
  1134. rend = 1;
  1135. }
  1136. }
  1137. void TextFeld::updateHScroll(int pos) // scrollt zur Curser Position
  1138. {
  1139. if (pos == -1) pos = cpos;
  1140. lockZeichnung();
  1141. if (horizontalScrollBar && tm->text && tm->renderer)
  1142. {
  1143. if (hatStyleNicht(Style::Mehrzeilig)) tm->text->remove('\n');
  1144. int br = gr.x;
  1145. if (hatStyle(Style::Rahmen) && rahmen) br -= rahmen->getRBreite() * 2;
  1146. if (hatStyle(Style::VScroll) && vertikalScrollBar) br -= 15;
  1147. tm->resetIteration();
  1148. int maxBr = 0;
  1149. int len = tm->text->getLength();
  1150. const char* text = tm->text->getText();
  1151. int lineBr = 0;
  1152. char buff[] = {0, 0};
  1153. int cbr = 0;
  1154. for (int i = 0; i < len; i++)
  1155. {
  1156. buff[0] = text[i];
  1157. if (text[i] == '\n')
  1158. {
  1159. maxBr = maxBr >= lineBr ? maxBr : lineBr;
  1160. lineBr = 0;
  1161. tm->nextStyle();
  1162. continue;
  1163. }
  1164. TextRenderer* r = tm->zCurrentRenderer();
  1165. if (r)
  1166. {
  1167. lineBr += r->getTextBreite(buff);
  1168. if (i <= pos) cbr = lineBr;
  1169. }
  1170. tm->nextStyle();
  1171. }
  1172. maxBr = maxBr >= lineBr ? maxBr : lineBr;
  1173. horizontalScrollBar->update(maxBr, br);
  1174. if (cbr > horizontalScrollBar->getScroll()
  1175. + horizontalScrollBar->getScrollData()->anzeige)
  1176. horizontalScrollBar->scroll(cbr - br);
  1177. if (cbr < horizontalScrollBar->getScroll())
  1178. horizontalScrollBar->scroll(cbr);
  1179. }
  1180. unlockZeichnung();
  1181. }
  1182. // Gibt die breite in pixeln zurück, die benötigt wird um den aktuellen text mit
  1183. // den aktuellen styles voll anzuzeigen
  1184. int TextFeld::getNeededWidth()
  1185. {
  1186. int maxBr = 0;
  1187. lockZeichnung();
  1188. if (tm->text && tm->renderer) maxBr = getTextWidth();
  1189. unlockZeichnung();
  1190. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1191. bool r = rahmen && hatStyle(Style::Rahmen);
  1192. return maxBr + (r ? rahmen->getRBreite() * 2 : 0) + (vs ? 15 : 0);
  1193. }
  1194. // Gibt die höhe in pixeln zurück, die benötigt wird um den aktuellen text mit
  1195. // den aktuellen styles voll anzuzeigen
  1196. int TextFeld::getNeededHeight()
  1197. {
  1198. int th = 0;
  1199. lockZeichnung();
  1200. if (tm->text && tm->renderer) th = getTextHeight();
  1201. unlockZeichnung();
  1202. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1203. bool r = rahmen && hatStyle(Style::Rahmen);
  1204. return th + (r ? rahmen->getRBreite() * 2 : 0) + (hs ? 15 : 0);
  1205. }
  1206. bool TextFeld::tick(double tickval) // tick
  1207. {
  1208. if (hatStyle(Style::Fokus))
  1209. {
  1210. if (tickVal < 0.5 && tickVal + tickval >= 0.5) rend = 1;
  1211. if (tickVal >= 0.5 && tickVal + tickval >= 1) rend = 1;
  1212. tickVal += tickval;
  1213. if (tickVal >= 1) tickVal -= 1;
  1214. }
  1215. return ZeichnungHintergrund::tick(tickval);
  1216. }
  1217. void TextFeld::doTastaturEreignis(TastaturEreignis& te)
  1218. {
  1219. bool ntakc = !te.verarbeitet;
  1220. if (te.verarbeitet || hatStyleNicht(Style::Fokus)) return;
  1221. if (!tak) return;
  1222. getThis();
  1223. if (tak(takParam, this, te))
  1224. {
  1225. if (hatStyleNicht(Style::Editierbar))
  1226. {
  1227. release();
  1228. return;
  1229. }
  1230. if (te.id == TE_Press)
  1231. {
  1232. bool shift = getTastenStand(T_Shift);
  1233. bool strg = getTastenStand(T_Strg);
  1234. switch (te.virtualKey)
  1235. {
  1236. case T_Entf:
  1237. if (!tm->getTextStyle(cpos).selected)
  1238. tm->removeText(cpos, cpos + 1);
  1239. else
  1240. {
  1241. cpos = tm->getTextStyle(cpos).beginIndex;
  1242. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1243. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1244. }
  1245. replaceAuswahl("");
  1246. deselectAuswahl();
  1247. rend = 1;
  1248. break;
  1249. case T_BackSpace:
  1250. if (!tm->getTextStyle(cpos).selected)
  1251. {
  1252. tm->removeText(cpos - 1, cpos);
  1253. cpos--;
  1254. }
  1255. else
  1256. {
  1257. cpos = tm->getTextStyle(cpos).beginIndex;
  1258. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1259. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1260. }
  1261. replaceAuswahl("");
  1262. deselectAuswahl();
  1263. rend = 1;
  1264. break;
  1265. case T_Enter:
  1266. if (hatStyle(TextFeld::Style::Mehrzeilig))
  1267. {
  1268. if (!tm->getTextStyle(cpos).selected)
  1269. tm->insertText(cpos, "\n");
  1270. else
  1271. {
  1272. cpos = tm->getTextStyle(cpos).beginIndex;
  1273. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1274. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1275. }
  1276. replaceAuswahl("\n");
  1277. ++cpos;
  1278. rend = 1;
  1279. }
  1280. break;
  1281. case T_Links:
  1282. if (shift)
  1283. {
  1284. if (strg)
  1285. {
  1286. int tmp = tm->text->getLKick(cpos);
  1287. invertAuswahl(tmp, cpos);
  1288. cpos = tmp;
  1289. }
  1290. else
  1291. {
  1292. invertAuswahl(cpos - 1, cpos);
  1293. --cpos;
  1294. }
  1295. }
  1296. else
  1297. {
  1298. if (strg)
  1299. cpos = tm->text->getLKick(cpos);
  1300. else
  1301. --cpos;
  1302. deselectAuswahl();
  1303. }
  1304. rend = 1;
  1305. break;
  1306. case T_Oben:
  1307. {
  1308. int tmp = tm->text->getOKick(cpos);
  1309. invertAuswahl(tmp, cpos);
  1310. cpos = tmp;
  1311. if (!shift) deselectAuswahl();
  1312. rend = 1;
  1313. break;
  1314. }
  1315. case T_Rechts:
  1316. if (shift)
  1317. {
  1318. if (strg)
  1319. {
  1320. int tmp = tm->text->getRKick(cpos);
  1321. invertAuswahl(cpos, tmp);
  1322. cpos = tmp;
  1323. }
  1324. else
  1325. {
  1326. invertAuswahl(cpos, cpos + 1);
  1327. ++cpos;
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if (strg)
  1333. cpos = tm->text->getRKick(cpos);
  1334. else
  1335. ++cpos;
  1336. deselectAuswahl();
  1337. }
  1338. rend = 1;
  1339. break;
  1340. case T_Unten:
  1341. {
  1342. int tmp = tm->text->getUKick(cpos);
  1343. invertAuswahl(cpos, tmp);
  1344. cpos = tmp;
  1345. if (!shift) deselectAuswahl();
  1346. rend = 1;
  1347. break;
  1348. }
  1349. default:
  1350. if (strg && te.id == TE_Press)
  1351. {
  1352. if (te.virtualKey == 'c' || te.virtualKey == 'C')
  1353. {
  1354. int sa = tm->textStyle.getEintragAnzahl();
  1355. int length = 0;
  1356. for (int i = 0; i < sa; i++)
  1357. {
  1358. TextStyle s = tm->textStyle.get(i);
  1359. if (s.selected)
  1360. {
  1361. int max = tm->text->getLength();
  1362. if (i < sa - 1)
  1363. max = tm->textStyle.get(i + 1).beginIndex;
  1364. length += max - s.beginIndex;
  1365. }
  1366. }
  1367. if (length)
  1368. {
  1369. char* txt = new char[length + 1];
  1370. txt[length] = 0;
  1371. int index = 0;
  1372. for (int i = 0; i < sa; i++)
  1373. {
  1374. TextStyle s = tm->textStyle.get(i);
  1375. if (s.selected)
  1376. {
  1377. int max = tm->text->getLength();
  1378. if (i < sa - 1)
  1379. max = tm->textStyle.get(i + 1)
  1380. .beginIndex;
  1381. memcpy(txt + index,
  1382. tm->text->getText() + s.beginIndex,
  1383. max - s.beginIndex);
  1384. index += max - s.beginIndex;
  1385. }
  1386. }
  1387. TextKopieren(txt);
  1388. delete[] txt;
  1389. }
  1390. else
  1391. TextKopieren(tm->text->getText());
  1392. }
  1393. if (te.virtualKey == 'v' || te.virtualKey == 'V')
  1394. {
  1395. const char* txt = TextInsert();
  1396. if (!tm->getTextStyle(cpos).selected)
  1397. tm->insertText(cpos, txt);
  1398. else
  1399. {
  1400. cpos = tm->getTextStyle(cpos).beginIndex;
  1401. while (
  1402. cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1403. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1404. }
  1405. replaceAuswahl(txt);
  1406. cpos += textLength(txt);
  1407. rend = 1;
  1408. }
  1409. break;
  1410. }
  1411. if (istSchreibbar(te.taste[0]))
  1412. {
  1413. if (!tm->getTextStyle(cpos).selected)
  1414. tm->insertText(cpos, te.taste);
  1415. else
  1416. {
  1417. cpos = tm->getTextStyle(cpos).beginIndex;
  1418. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1419. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1420. }
  1421. replaceAuswahl(te.taste);
  1422. ++cpos;
  1423. rend = 1;
  1424. }
  1425. break;
  1426. }
  1427. }
  1428. if (cpos < 0) cpos = 0;
  1429. if (cpos > tm->text->getLength()) cpos = tm->text->getLength();
  1430. if (hatStyle(Style::VScroll)) updateVScroll(cpos);
  1431. if (hatStyle(Style::HScroll)) updateHScroll(cpos);
  1432. te.verarbeitet = 1;
  1433. }
  1434. if (ntakc && te.verarbeitet && nTak)
  1435. te.verarbeitet = nTak(ntakParam, this, te);
  1436. release();
  1437. }
  1438. void TextFeld::render(Bild& zRObj) // zeichenet nach zRObj
  1439. {
  1440. if (hatStyleNicht(Style::Sichtbar)) return;
  1441. ZeichnungHintergrund::render(zRObj);
  1442. if (!tm->text || !tm->renderer) return;
  1443. lockZeichnung();
  1444. if (!zRObj.setDrawOptions(innenPosition, innenSize))
  1445. {
  1446. unlockZeichnung();
  1447. return;
  1448. }
  1449. if (hatStyleNicht(Style::Mehrzeilig)) tm->text->remove('\n');
  1450. int tbr = getTextWidth();
  1451. int thi = getTextHeight();
  1452. int xxx = 0;
  1453. int yyy = 0;
  1454. int breite = innenSize.x;
  1455. int height = innenSize.y;
  1456. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1457. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1458. if (vs) yyy -= vertikalScrollBar->getScroll();
  1459. if (hs) xxx -= horizontalScrollBar->getScroll();
  1460. if (hatStyle(Style::HCenter) && !hs) xxx = (breite / 2) - tbr / 2;
  1461. int x = xxx;
  1462. int len = tm->text->getLength();
  1463. const char* text = tm->text->getText();
  1464. Text txtWithLineBreaks;
  1465. if (hatStyle(Style::AutoLineBreak))
  1466. {
  1467. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1468. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  1469. text = txtWithLineBreaks;
  1470. len = txtWithLineBreaks.getLength();
  1471. }
  1472. lockZeichnung();
  1473. tm->resetIteration();
  1474. if (thi == 0)
  1475. {
  1476. thi = tm->zCurrentRenderer()->getZeilenHeight();
  1477. }
  1478. if (hatStyle(Style::VCenter) && !vs) yyy = (height / 2) - thi / 2;
  1479. int y = yyy;
  1480. TextStyle& style = tm->currentStyle();
  1481. int maxLH = 0;
  1482. int corrector = 0;
  1483. int realLen = tm->text->getLength();
  1484. for (int i = 0; i <= len; i++)
  1485. {
  1486. int oldX = x;
  1487. if (i < len && tm->zCurrentRenderer())
  1488. tm->zCurrentRenderer()->renderChar(x,
  1489. y,
  1490. istSchreibbar(showChar) ? showChar : text[i],
  1491. zRObj,
  1492. style.selected ? style.selectedColor : style.fontColor,
  1493. style.underlined,
  1494. style.selected,
  1495. style.selectedBackcroundColor);
  1496. if (i - corrector == cpos && tickVal <= 0.5 && hatStyle(Style::Fokus)
  1497. && hatStyle(Style::Editierbar) && tm->zCurrentRenderer())
  1498. zRObj.drawLinieV(
  1499. oldX, y, tm->zCurrentRenderer()->getZeilenHeight(), 0xFFFF5555);
  1500. if (i >= realLen || text[i] != tm->text->getText()[i])
  1501. {
  1502. corrector++;
  1503. }
  1504. if (tm->zCurrentRenderer())
  1505. {
  1506. int tmp = tm->zCurrentRenderer()->getZeilenHeight()
  1507. + tm->zCurrentRenderer()->getZeilenAbstand();
  1508. maxLH = tmp > maxLH ? tmp : maxLH;
  1509. }
  1510. if (i < len && text[i] == '\n')
  1511. {
  1512. x = xxx;
  1513. y += maxLH;
  1514. }
  1515. tm->nextStyle();
  1516. }
  1517. unlockZeichnung();
  1518. zRObj.releaseDrawOptions();
  1519. unlockZeichnung();
  1520. }
  1521. // Konstant
  1522. Text* TextFeld::getText() const // gibt vom Text zurück
  1523. {
  1524. if (!tm->text) return 0;
  1525. return dynamic_cast<Text*>(tm->text->getThis());
  1526. }
  1527. Text* TextFeld::zText() const // gibt den Text zurück
  1528. {
  1529. return tm->text;
  1530. }
  1531. Schrift* TextFeld::getSchrift() const // gint getThis der Schrift Zurück
  1532. {
  1533. tm->resetIteration();
  1534. return tm->zCurrentRenderer() ? tm->zCurrentRenderer()->getSchrift() : 0;
  1535. }
  1536. Schrift* TextFeld::zSchrift() const // gibt die Schrift zurück
  1537. {
  1538. tm->resetIteration();
  1539. return tm->zCurrentRenderer() ? tm->zCurrentRenderer()->zSchrift() : 0;
  1540. }
  1541. // Gibt die Schrift zurück.
  1542. // rendererIndex: Der Index des Renderers dessen Schrift zurückgegeben werden
  1543. // soll return: 0, falls die Schrift nicht gesetzt wurde
  1544. Schrift* TextFeld::getSchrift(int rendererIndex) const
  1545. {
  1546. if (tm->renderer && tm->renderer->z(rendererIndex))
  1547. return tm->renderer->z(rendererIndex)->getSchrift();
  1548. return 0;
  1549. }
  1550. // Gibt die Schrift ohne erhöhten Reference Counter zurük
  1551. // rendererIndex: Der Index des Renderers dessen Schrift zurückgegeben werden
  1552. // soll return: 0, falls die Schrift nicht gesetzt wurde
  1553. Schrift* TextFeld::zSchrift(int rendererIndex) const
  1554. {
  1555. if (tm->renderer && tm->renderer->z(rendererIndex))
  1556. return tm->renderer->z(rendererIndex)->zSchrift();
  1557. return 0;
  1558. }
  1559. TextRenderer* TextFeld::getTextRenderer() const
  1560. {
  1561. tm->resetIteration();
  1562. return dynamic_cast<TextRenderer*>(tm->zCurrentRenderer()->getThis());
  1563. }
  1564. TextRenderer* TextFeld::zTextRenderer() const
  1565. {
  1566. tm->resetIteration();
  1567. return tm->zCurrentRenderer();
  1568. }
  1569. // Gibt den TextRenderer zurück.
  1570. // index: Der Index des Renderers der zurückgegeben werden soll
  1571. // return: 0, falls der TextRenderer nicht gesetzt wurde
  1572. TextRenderer* TextFeld::getTextRenderer(int index) const
  1573. {
  1574. if (tm->renderer && tm->renderer->z(index)) return tm->renderer->get(index);
  1575. return 0;
  1576. }
  1577. // Gibt dien TextRenderer ohne erhöhten Reference Counter zurük
  1578. // index: Der Index des Renderers der zurückgegeben werden soll
  1579. // return: 0, falls der TextRenderer nicht gesetzt wurde
  1580. TextRenderer* TextFeld::zTextRenderer(int index) const
  1581. {
  1582. if (tm->renderer && tm->renderer->z(index)) return tm->renderer->z(index);
  1583. return 0;
  1584. }
  1585. unsigned char TextFeld::getSchriftSize() const // gibt die Schriftgröße zurück
  1586. {
  1587. tm->resetIteration();
  1588. return tm->current.fontSize;
  1589. }
  1590. // Gibt die Schriftgröße zurück
  1591. // index: Der Index des Zeichens
  1592. unsigned char TextFeld::getSchriftSize(int index) const
  1593. {
  1594. tm->resetIteration();
  1595. return tm->current.fontSize;
  1596. }
  1597. int TextFeld::getSchriftFarbe() const // gibt getThis der Schriftfarbe zurück
  1598. {
  1599. tm->resetIteration();
  1600. return tm->current.fontColor;
  1601. }
  1602. // Gibt die Schriftfarbe im A8R8G8B8 Format zurück
  1603. // index: Der Index des Zeichens
  1604. int TextFeld::getSchriftFarbe(int index) const
  1605. {
  1606. return tm->getTextStyle(index).fontColor;
  1607. }
  1608. unsigned char TextFeld::getShowChar() const // gibt den Anzeige Char zurück
  1609. {
  1610. return showChar;
  1611. }
  1612. int TextFeld::getCursorPos() const
  1613. {
  1614. return cpos;
  1615. }
  1616. // Gibt 1 zurück wenn das Zeichen ausgewählt ist
  1617. // index: Der Index des Zeichens
  1618. bool TextFeld::isCharSelected(int index) const
  1619. {
  1620. return tm->getTextStyle(index).selected;
  1621. }
  1622. // Gibt den Index des Zeichens zurück, das sich unter der Maus befindet
  1623. // mx: die x position der maus relativ zur position des textfeldes
  1624. // my: die y position der maus relativ zut position des textfeldes
  1625. // return: -1, falls sich an der Position kein zeichen befindet
  1626. int TextFeld::getTextIndexAt(int mx, int my) const
  1627. {
  1628. if (!tm || !tm->text || !tm->zCurrentRenderer()) return -1;
  1629. int tbr = getTextWidth();
  1630. int thi = getTextHeight();
  1631. int xxx = 0;
  1632. int yyy = 0;
  1633. int breite = innenSize.x;
  1634. int height = innenSize.y;
  1635. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1636. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1637. if (vs) yyy -= vertikalScrollBar->getScroll();
  1638. if (hs) xxx -= horizontalScrollBar->getScroll();
  1639. if (hatStyle(Style::HCenter) && !hs) xxx = (breite / 2) - tbr / 2;
  1640. if (hatStyle(Style::VCenter) && !vs) yyy = (height / 2) - thi / 2;
  1641. int x = xxx;
  1642. int y = yyy;
  1643. int len = tm->text->getLength();
  1644. const char* text = tm->text->getText();
  1645. Text txtWithLineBreaks;
  1646. if (hatStyle(Style::AutoLineBreak))
  1647. {
  1648. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1649. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  1650. text = txtWithLineBreaks;
  1651. len = txtWithLineBreaks.getLength();
  1652. }
  1653. tm->resetIteration();
  1654. int corrector = 0;
  1655. int maxLH = 0;
  1656. int realLen = tm->text->getLength();
  1657. for (int i = 0; i < len; i++)
  1658. {
  1659. if (i >= realLen || text[i] != tm->text->getText()[i])
  1660. {
  1661. corrector++;
  1662. }
  1663. char buff[2] = {istSchreibbar(showChar) ? (char)showChar : text[i], 0};
  1664. int tmpx = tm->zCurrentRenderer()->getTextBreite(buff);
  1665. int tmpy = tm->zCurrentRenderer()->getZeilenHeight();
  1666. if (mx >= x && mx < x + tmpx && my >= y && my < y + tmpy)
  1667. return i - corrector;
  1668. if (mx < x + tmpx && my < y + tmpy) return -1;
  1669. x += tmpx;
  1670. tmpy += tm->zCurrentRenderer()->getZeilenAbstand();
  1671. maxLH = tmpy > maxLH ? tmpy : maxLH;
  1672. if (text[i] == '\n')
  1673. {
  1674. x = xxx;
  1675. y += maxLH;
  1676. }
  1677. tm->nextStyle();
  1678. }
  1679. return -1;
  1680. }
  1681. // Gibt den Index des Zeichens zurück, vor dem der curser gesetzt wird, wenn mit
  1682. // der maus geklickt wird
  1683. // mx: die x position der maus relativ zur position des textfeldes
  1684. // my: die y position der maus relativ zut position des textfeldes
  1685. int TextFeld::getCurserPosAt(int mx, int my) const
  1686. {
  1687. if (!tm || !tm->text || !tm->zCurrentRenderer())
  1688. return tm->text->getLength();
  1689. int tbr = getTextWidth();
  1690. int thi = getTextHeight();
  1691. int xxx = 0;
  1692. int yyy = 0;
  1693. int breite = innenSize.x;
  1694. int height = innenSize.y;
  1695. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1696. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1697. if (vs) yyy -= vertikalScrollBar->getScroll();
  1698. if (hs) xxx -= horizontalScrollBar->getScroll();
  1699. if (hatStyle(Style::HCenter) && !hs) xxx = (breite / 2) - tbr / 2;
  1700. if (hatStyle(Style::VCenter) && !vs) yyy = (height / 2) - thi / 2;
  1701. int x = xxx;
  1702. int y = yyy;
  1703. int len = tm->text->getLength();
  1704. const char* text = tm->text->getText();
  1705. Text txtWithLineBreaks;
  1706. if (hatStyle(Style::AutoLineBreak))
  1707. {
  1708. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1709. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  1710. text = txtWithLineBreaks;
  1711. len = txtWithLineBreaks.getLength();
  1712. }
  1713. tm->resetIteration();
  1714. int maxLH = 0;
  1715. int realLen = tm->text->getLength();
  1716. int corrector = 0;
  1717. for (int i = 0; i < len; i++)
  1718. {
  1719. if (i >= realLen || text[i] != tm->text->getText()[i])
  1720. {
  1721. corrector++;
  1722. }
  1723. int tmpx = tm->zCurrentRenderer()->getCharWidth(
  1724. istSchreibbar(showChar) ? showChar : text[i]);
  1725. int tmpy = tm->zCurrentRenderer()->getZeilenHeight()
  1726. + tm->zCurrentRenderer()->getZeilenAbstand();
  1727. if (mx < x + tmpx / 2
  1728. && my < y + tmpy - tm->zCurrentRenderer()->getZeilenAbstand() / 2)
  1729. return i - corrector;
  1730. x += tmpx + tm->zCurrentRenderer()->getZeichenAbstand();
  1731. maxLH = tmpy > maxLH ? tmpy : maxLH;
  1732. if (text[i] == '\n')
  1733. {
  1734. if (my >= y - tm->zCurrentRenderer()->getZeilenAbstand() / 2
  1735. && my < y + maxLH
  1736. - tm->zCurrentRenderer()->getZeilenAbstand() / 2)
  1737. return i - corrector;
  1738. x = xxx;
  1739. y += maxLH;
  1740. }
  1741. tm->nextStyle();
  1742. }
  1743. return tm->text->getLength();
  1744. }
  1745. // Gibt den Style eines bestimmten zeichens zurück
  1746. // index: Der index des Zeichensf
  1747. TextStyle TextFeld::getTextStyle(int index) const
  1748. {
  1749. return tm->getTextStyle(index);
  1750. }
  1751. // gibt die Zeichenkette zurück, die bei Verwendung des Styles
  1752. // AutoLineBreak nach jedem Zeilenumbruch eingefügt wird
  1753. Text TextFeld::getAutoLineBreakSpacing() const
  1754. {
  1755. return autoLineBreakSpacing ? *autoLineBreakSpacing : Text("");
  1756. }
  1757. Zeichnung* TextFeld::dublizieren() const // Erzeugt eine Kopie des Zeichnungs
  1758. {
  1759. TextFeld* obj = new TextFeld();
  1760. obj->setPosition(pos);
  1761. obj->setSize(gr);
  1762. obj->setMausEreignisParameter(makParam);
  1763. obj->setTastaturEreignisParameter(takParam);
  1764. obj->setMausEreignis(mak);
  1765. obj->setTastaturEreignis(tak);
  1766. if (toolTip) obj->setToolTipZ((ToolTip*)toolTip->dublizieren());
  1767. obj->setStyle(style);
  1768. obj->tm->renderer->release();
  1769. obj->tm->renderer
  1770. = dynamic_cast<RCArray<TextRenderer>*>(tm->renderer->getThis());
  1771. obj->tm->textStyle.leeren();
  1772. for (const auto& i : tm->textStyle)
  1773. obj->tm->textStyle.add(i);
  1774. obj->tm->index = tm->index;
  1775. obj->tm->styleIndex = tm->styleIndex;
  1776. obj->tm->current = tm->current;
  1777. if (tm->text) obj->setText(tm->text->getText());
  1778. obj->setHintergrundFarbe(hintergrundFarbe);
  1779. if (hintergrundFeld)
  1780. obj->setAlphaFeldZ((AlphaFeld*)hintergrundFeld->dublizieren());
  1781. if (rahmen) obj->setRahmenZ((Rahmen*)rahmen->dublizieren());
  1782. if (hintergrundBild)
  1783. obj->setHintergrundBild(
  1784. dynamic_cast<Bild*>(hintergrundBild->getThis()));
  1785. if (vertikalScrollBar)
  1786. {
  1787. obj->setVertikalKlickScroll(vertikalScrollBar->getKlickScroll());
  1788. obj->setVertikalScrollPos(vertikalScrollBar->getScroll());
  1789. obj->setVertikalScrollFarbe(
  1790. vertikalScrollBar->getFarbe(), vertikalScrollBar->getBgFarbe());
  1791. }
  1792. if (horizontalScrollBar)
  1793. {
  1794. obj->setHorizontalKlickScroll(horizontalScrollBar->getKlickScroll());
  1795. obj->setHorizontalScrollPos(horizontalScrollBar->getScroll());
  1796. obj->setHorizontalScrollFarbe(
  1797. horizontalScrollBar->getFarbe(), horizontalScrollBar->getBgFarbe());
  1798. }
  1799. if (autoLineBreakSpacing)
  1800. {
  1801. obj->setAutoLineBreakSpacing(*autoLineBreakSpacing);
  1802. }
  1803. obj->setSchowChar(showChar);
  1804. return obj;
  1805. }