TextFeld.cpp 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872
  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. txt->release();
  500. }
  501. void TextFeld::setTextZ(Text* txt) // setzt einen Zeiger zum angezeigten Text
  502. {
  503. lockZeichnung();
  504. if (tm->text) tm->text->release();
  505. tm->text = txt;
  506. if (hatStyle(Style::VScroll)) updateVScroll();
  507. if (hatStyle(Style::HScroll)) updateHScroll();
  508. rend = 1;
  509. unlockZeichnung();
  510. }
  511. void TextFeld::setText(const char* txt) // setzt den angezeigten Text
  512. {
  513. lockZeichnung();
  514. if (!tm->text) tm->text = new Text();
  515. tm->text->setText(txt);
  516. if (hatStyle(Style::VScroll)) updateVScroll();
  517. if (hatStyle(Style::HScroll)) updateHScroll();
  518. rend = 1;
  519. unlockZeichnung();
  520. }
  521. // setzt den Text mit styles
  522. // txt: der Text
  523. // format: \x1: aktiviert unterschtrich
  524. // \x2FF: setzt die schriftgröße für den folgenden text.
  525. // FF ist ein zweistelliger Hex Wert
  526. // \x3AARRGGBB: setzt die schriftfarbe.
  527. // AARRGGBB ist ein 8 stelliger hex wert mit jeweils zwei zeichen
  528. // für alpha, rot, grün n blau
  529. // \x4AARRGGBB: setzt die farbe des ausgewählten textes.
  530. // AARRGGBB ist ein 8 stelliger hex wert mit jeweils zwei zeichen
  531. // für alpha, rot, grün n blau
  532. // \x5AARRGGBB: setzt die hintergrundfarbe des ausgewählten textes.
  533. // AARRGGBB ist ein 8 stelliger hex wert mit jeweils zwei zeichen
  534. // für alpha, rot, grün n blau
  535. // \x6FF: setzt text renderer index.
  536. // FF ist ein zweistelliger Hex Wert
  537. // \x7: deaktiviert unterschtrich
  538. // \x8FFFFFFFF: set interact param.
  539. // FFFFFFFF ist ein 8 stelliger hex wert
  540. void TextFeld::setFormattedText(const char* txt)
  541. {
  542. lockZeichnung();
  543. if (!tm->text) tm->text = new Text();
  544. tm->textStyle.leeren();
  545. TextStyle current;
  546. current.beginIndex = 0;
  547. current.fontColor = 0xFFFFFFFF;
  548. current.fontSize = 12;
  549. current.selected = 0;
  550. current.selectedColor = 0xFFFFFFFF;
  551. current.selectedBackcroundColor = 0xFF0000FF;
  552. current.underlined = 0;
  553. current.interactParam = 0;
  554. current.rendererIndex = 0;
  555. tm->textStyle.add(current);
  556. Text result = "";
  557. for (int i = 0; 1; i++)
  558. {
  559. bool br = 0;
  560. current.beginIndex = result.getLength();
  561. switch (txt[i])
  562. {
  563. case 0:
  564. br = 1;
  565. break;
  566. case 1:
  567. current.underlined = 1;
  568. tm->textStyle.add(current);
  569. break;
  570. case 2:
  571. {
  572. Text p = "0x";
  573. p.append(txt + i + 1, 2);
  574. current.fontSize = (unsigned char)(int)p;
  575. tm->textStyle.add(current);
  576. i += 2;
  577. break;
  578. }
  579. case 3:
  580. {
  581. Text p = "0x";
  582. p.append(txt + i + 1, 8);
  583. current.fontColor = (int)p;
  584. tm->textStyle.add(current);
  585. i += 8;
  586. }
  587. break;
  588. case 4:
  589. {
  590. Text p = "0x";
  591. p.append(txt + i + 1, 8);
  592. current.selectedColor = (int)p;
  593. tm->textStyle.add(current);
  594. i += 8;
  595. break;
  596. }
  597. case 5:
  598. {
  599. Text p = "0x";
  600. p.append(txt + i + 1, 8);
  601. current.selectedBackcroundColor = (int)p;
  602. tm->textStyle.add(current);
  603. i += 8;
  604. break;
  605. }
  606. case 6:
  607. {
  608. Text p = "0x";
  609. p.append(txt + i + 1, 2);
  610. current.rendererIndex = (unsigned char)(int)p;
  611. tm->textStyle.add(current);
  612. i += 2;
  613. }
  614. break;
  615. case 7:
  616. current.underlined = 0;
  617. tm->textStyle.add(current);
  618. break;
  619. case 8:
  620. {
  621. Text p = "0x";
  622. p.append(txt + i + 1, 8);
  623. current.interactParam = (int)p;
  624. tm->textStyle.add(current);
  625. i += 8;
  626. }
  627. break;
  628. default:
  629. result.append(txt[i]);
  630. }
  631. if (br) break;
  632. }
  633. tm->text->setText(result);
  634. tm->cleanupStyles();
  635. if (hatStyle(Style::VScroll)) updateVScroll();
  636. if (hatStyle(Style::HScroll)) updateHScroll();
  637. rend = 1;
  638. unlockZeichnung();
  639. }
  640. // fügt zeilenumbrüche so ein, dass der text nicht die breite des textfeldes
  641. // überschreitet
  642. void TextFeld::addLineBreaks(const char* spacing)
  643. {
  644. if (!tm->text) return;
  645. setFormattedText(addLineBreaksToText(tm->text->getText(), spacing));
  646. }
  647. Text TextFeld::addLineBreaksToText(const char* txt, const char* spacing) const
  648. {
  649. int lastPos = -1;
  650. int lastPos2 = -1;
  651. int x = 0;
  652. Text result = "";
  653. int len = (int)strlen(txt);
  654. int maxBr = getBreite();
  655. if (hatStyle(Style::VScroll) && vertikalScrollBar) maxBr -= 15;
  656. tm->resetIteration();
  657. TextStyle last;
  658. last.beginIndex = 0;
  659. last.fontColor = 0xFFFFFFFF;
  660. last.fontSize = 12;
  661. last.selected = 0;
  662. last.selectedColor = 0xFFFFFFFF;
  663. last.selectedBackcroundColor = 0xFF0000FF;
  664. last.underlined = 0;
  665. last.interactParam = 0;
  666. last.rendererIndex = 0;
  667. for (int i = 0; i < len; ++i)
  668. {
  669. if (last.fontSize != tm->current.fontSize)
  670. {
  671. Text param("\x2");
  672. param.appendHex((char)tm->current.fontSize);
  673. result += param;
  674. last.fontSize = tm->current.fontSize;
  675. }
  676. if (last.fontColor != tm->current.fontColor)
  677. {
  678. Text param("\x3");
  679. param.appendHex(tm->current.fontColor);
  680. result += param;
  681. last.fontColor = tm->current.fontColor;
  682. }
  683. if (last.selectedColor != tm->current.selectedColor)
  684. {
  685. Text param("\x4");
  686. param.appendHex(tm->current.selectedColor);
  687. result += param;
  688. last.selectedColor = tm->current.selectedColor;
  689. }
  690. if (last.selectedBackcroundColor != tm->current.selectedBackcroundColor)
  691. {
  692. Text param("\x5");
  693. param.appendHex(tm->current.selectedBackcroundColor);
  694. result += param;
  695. last.selectedBackcroundColor = tm->current.selectedBackcroundColor;
  696. }
  697. if (last.underlined != tm->current.underlined)
  698. {
  699. char tmp[2] = {tm->current.underlined ? (char)1 : (char)7, 0};
  700. result += tmp;
  701. last.underlined = tm->current.underlined;
  702. }
  703. if (last.interactParam != tm->current.interactParam)
  704. {
  705. Text param("\x8");
  706. param.appendHex(tm->current.interactParam);
  707. result += param;
  708. last.interactParam = tm->current.interactParam;
  709. }
  710. if (last.rendererIndex != tm->current.rendererIndex)
  711. {
  712. Text param("\x6");
  713. param.appendHex((char)tm->current.rendererIndex);
  714. result += param;
  715. last.rendererIndex = tm->current.rendererIndex;
  716. }
  717. if (txt[i] == ' ')
  718. {
  719. lastPos = i;
  720. lastPos2 = result.getLength();
  721. x += tm->zCurrentRenderer()->getTextBreite(" ");
  722. result += " ";
  723. tm->nextStyle();
  724. continue;
  725. }
  726. if (txt[i] == '\t')
  727. {
  728. lastPos = i;
  729. lastPos2 = result.getLength();
  730. x += tm->zCurrentRenderer()->getTextBreite("\t");
  731. result += "\t";
  732. tm->nextStyle();
  733. continue;
  734. }
  735. if (txt[i] == '\n')
  736. {
  737. x = 0;
  738. lastPos = -1;
  739. lastPos2 = -1;
  740. result += "\n";
  741. tm->nextStyle();
  742. continue;
  743. }
  744. char buff[2] = {txt[i], 0};
  745. x += tm->zCurrentRenderer()->getTextBreite(buff);
  746. result += buff;
  747. if (x > maxBr && lastPos > -1)
  748. {
  749. result.remove(lastPos2, result.getLength());
  750. result += "\n";
  751. result += spacing;
  752. x = tm->zCurrentRenderer()->getTextBreite(spacing);
  753. i = lastPos;
  754. tm->stepTo(lastPos);
  755. lastPos = -1;
  756. lastPos2 = -1;
  757. last = tm->currentStyle();
  758. }
  759. tm->nextStyle();
  760. }
  761. return result;
  762. }
  763. void TextFeld::setAutoLineBreakSpacing(const char* spacing)
  764. {
  765. if (!autoLineBreakSpacing) autoLineBreakSpacing = new Text();
  766. autoLineBreakSpacing->setText(spacing);
  767. }
  768. // Setzt den Style eines Textabschnittes
  769. // begin: die startposition des Abschnittes
  770. // end: die endposition des Abschnittes (nicht enthalten)
  771. void TextFeld::setTextStyle(int begin, int end, TextStyle style)
  772. {
  773. tm->setTextStyle(begin, end, style);
  774. }
  775. void TextFeld::addZeile(const char* zeile) // fügt Zeile An
  776. {
  777. if (tm->text)
  778. {
  779. Text* txt = new Text(zeile);
  780. if (zeile[txt->getLength() - 1] != '\n') txt->append("\n");
  781. TextRenderer* r = tm->renderer->z(0);
  782. if (tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  783. .rendererIndex
  784. < tm->renderer->getEintragAnzahl())
  785. r = tm->renderer->z(
  786. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  787. .rendererIndex);
  788. if (r)
  789. {
  790. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  791. int rbr = (rahmen && hatStyle(Style::Rahmen)) ? rahmen->getRBreite()
  792. : 0;
  793. r->setSchriftSize(
  794. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  795. .fontSize);
  796. r->textFormatieren(txt, gr.x - ((int)vs * 15) - rbr * 2);
  797. }
  798. lockZeichnung();
  799. tm->text->append(txt->getText());
  800. unlockZeichnung();
  801. txt->release();
  802. if (hatStyle(Style::VScroll)) updateVScroll();
  803. if (hatStyle(Style::HScroll)) updateHScroll();
  804. rend = 1;
  805. }
  806. }
  807. // Fügt eine Zeile an den Text an
  808. // zeile: Die neue Zeile
  809. // color: Die Farbe der Zeile
  810. void TextFeld::addZeile(const char* zeile, int color)
  811. {
  812. if (tm->text)
  813. {
  814. Text* txt = new Text(zeile);
  815. if (zeile[txt->getLength() - 1] != '\n') txt->append("\n");
  816. TextRenderer* r = tm->renderer->z(0);
  817. if (tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  818. .rendererIndex
  819. < tm->renderer->getEintragAnzahl())
  820. r = tm->renderer->z(
  821. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  822. .rendererIndex);
  823. if (r)
  824. {
  825. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  826. int rbr = (rahmen && hatStyle(Style::Rahmen)) ? rahmen->getRBreite()
  827. : 0;
  828. r->setSchriftSize(
  829. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  830. .fontSize);
  831. r->textFormatieren(txt, gr.x - ((int)vs * 15) - rbr * 2);
  832. }
  833. lockZeichnung();
  834. tm->text->append(txt->getText());
  835. setSchriftFarbe(tm->text->getLength() - txt->getLength(),
  836. tm->text->getLength(),
  837. color);
  838. unlockZeichnung();
  839. txt->release();
  840. if (hatStyle(Style::VScroll)) updateVScroll();
  841. if (hatStyle(Style::HScroll)) updateHScroll();
  842. rend = 1;
  843. }
  844. }
  845. // Deselectiert alle textabschnitte
  846. void TextFeld::deselectAuswahl()
  847. {
  848. for (int i = 0; i < tm->textStyle.getEintragAnzahl(); i++)
  849. {
  850. TextStyle s = tm->textStyle.get(i);
  851. if (s.selected)
  852. {
  853. s.selected = 0;
  854. tm->textStyle.set(s, i);
  855. }
  856. }
  857. tm->cleanupStyles();
  858. }
  859. void TextFeld::setAuswahl(int pos1, int pos2) // setzt den Ausgewählten Text
  860. {
  861. deselectAuswahl();
  862. TextStyle s = tm->getTextStyle(pos1);
  863. s.selected = 1;
  864. tm->setTextStyle(pos1, pos2, s);
  865. }
  866. void TextFeld::setAuswahl(Punkt& auswahl)
  867. {
  868. deselectAuswahl();
  869. TextStyle s = tm->getTextStyle(auswahl.x);
  870. s.selected = 1;
  871. tm->setTextStyle(auswahl.x, auswahl.y, s);
  872. rend = 1;
  873. }
  874. void TextFeld::addAuswahl(int pos1, int pos2)
  875. {
  876. TextStyle s = tm->getTextStyle(pos1);
  877. s.selected = 1;
  878. tm->setTextStyle(pos1, pos2, s);
  879. }
  880. void TextFeld::addAuswahl(Punkt& auswahl)
  881. {
  882. TextStyle s = tm->getTextStyle(auswahl.x);
  883. s.selected = 1;
  884. tm->setTextStyle(auswahl.x, auswahl.y, s);
  885. rend = 1;
  886. }
  887. // Setzt den ausgewählten textabschnitt fest
  888. // begin: Die Cursorposition im Text
  889. // end: Die Position im Text, bis zu der der Text eingefärbt werden soll
  890. void TextFeld::invertAuswahl(int begin, int end)
  891. {
  892. for (int i = begin; i < end; i++)
  893. {
  894. TextStyle s = tm->getTextStyle(i);
  895. s.selected = !s.selected;
  896. tm->setTextStyle(i, i + 1, s);
  897. rend = 1;
  898. }
  899. }
  900. // ersetzt alle ausgewählten Textabschnitte mit einem text
  901. // text: der neue Text
  902. void TextFeld::replaceAuswahl(const char* text)
  903. {
  904. tm->cleanupStyles();
  905. int sa = tm->textStyle.getEintragAnzahl();
  906. int last = tm->text->getLength();
  907. int si = 0;
  908. for (int i = sa - 1; i >= 0; i--)
  909. {
  910. TextStyle s = tm->textStyle.get(i);
  911. si = i;
  912. if (s.selected)
  913. {
  914. if ((i > 0 && !tm->textStyle.get(i - 1).selected) || i == 0)
  915. {
  916. s.selected = false;
  917. tm->textStyle.set(s, si);
  918. tm->removeText(s.beginIndex, last);
  919. tm->insertText(s.beginIndex, text);
  920. }
  921. }
  922. else
  923. last = s.beginIndex;
  924. }
  925. }
  926. void TextFeld::setTextRendererZ(TextRenderer* textRd)
  927. {
  928. if (tm->renderer)
  929. tm->renderer->leeren();
  930. else
  931. tm->renderer = new RCArray<TextRenderer>();
  932. tm->renderer->add(textRd);
  933. rend = 1;
  934. }
  935. // Fügt einen TextRenderer hinzu
  936. // textRd: Der Textrenderer
  937. void TextFeld::addTextRendererZ(TextRenderer* textRd)
  938. {
  939. if (!tm->renderer) tm->renderer = new RCArray<TextRenderer>();
  940. tm->renderer->add(textRd);
  941. }
  942. // Setzt die verwendeten TextRenderer
  943. // textRd: Die Textrenderer
  944. void TextFeld::setTextRendererZ(RCArray<TextRenderer>* textRd)
  945. {
  946. if (tm->renderer) tm->renderer->release();
  947. tm->renderer = textRd;
  948. }
  949. void TextFeld::setSchriftZ(Schrift* schrift) // setzt einen Zeiger zur Schrift
  950. {
  951. if (!tm->renderer) tm->renderer = new RCArray<TextRenderer>();
  952. if (!tm->renderer->getEintragAnzahl())
  953. tm->renderer->add(new TextRenderer(schrift));
  954. else
  955. tm->renderer->z(0)->setSchriftZ(schrift);
  956. rend = 1;
  957. }
  958. // Setzt einen Zeiger zur Schrift
  959. // rendererIndex: Der Index des Renderers dessen Schrift gesetzt werden soll
  960. // schrift: Die Schrift, die zum Textzeichnen verwendet werden soll.
  961. void TextFeld::setSchriftZ(int rendererIndex, Schrift* schrift)
  962. {
  963. if (!tm->renderer) tm->renderer = new RCArray<TextRenderer>();
  964. if (tm->renderer->getEintragAnzahl() <= rendererIndex)
  965. tm->renderer->add(new TextRenderer(schrift), rendererIndex);
  966. else
  967. tm->renderer->z(rendererIndex)->setSchriftZ(schrift);
  968. }
  969. void TextFeld::setSchriftSize(unsigned char gr) // setzt die Schriftgröße
  970. {
  971. TextStyle s = tm->textStyle.get(0);
  972. s.fontSize = gr;
  973. tm->textStyle.set(s, 0);
  974. rend = 1;
  975. }
  976. // Setzt die Schriftgröße (Standart: 12)
  977. // begin: Der Index des ersten betroffenen Zeichens
  978. // end: Der Index des ersten nicht betroffenen Zeichens
  979. // gr: Die Schriftgröße, die zum Textzeichnen verwendet werden soll
  980. void TextFeld::setSchriftSize(int begin, int end, unsigned char gr)
  981. {
  982. TextStyle s = tm->getTextStyle(begin);
  983. s.fontSize = gr;
  984. tm->setTextStyle(begin, end, s);
  985. rend = 1;
  986. }
  987. void TextFeld::setSchriftFarbe(int fc) // setzt die Schrift Farbe
  988. {
  989. TextStyle s = tm->textStyle.get(0);
  990. s.fontColor = fc;
  991. tm->textStyle.set(s, 0);
  992. rend = 1;
  993. }
  994. // Setzt die Schrift Farbe
  995. // begin: Der Index des ersten betroffenen Zeichens
  996. // end: Der Index des ersten nicht betroffenen Zeichens
  997. // fc: Die Farbe, die zum Textzeichnen verwendet werden soll
  998. void TextFeld::setSchriftFarbe(int begin, int end, int fc)
  999. {
  1000. TextStyle s = tm->getTextStyle(begin);
  1001. s.fontColor = fc;
  1002. tm->setTextStyle(begin, end, s);
  1003. rend = 1;
  1004. }
  1005. void TextFeld::setSchowChar(unsigned char c) // bei Passwortfeld *
  1006. {
  1007. showChar = c;
  1008. rend = 1;
  1009. }
  1010. void TextFeld::setVScrollZuZeile(int zeile) // scrollt zur Zeile
  1011. {
  1012. if (vertikalScrollBar && tm->renderer && tm->renderer->getEintragAnzahl()
  1013. && tm->text && hatStyle(Style::Mehrzeilig))
  1014. {
  1015. lockZeichnung();
  1016. tm->resetIteration();
  1017. int len = tm->text->getLength();
  1018. int y = 0;
  1019. int lnum = 0;
  1020. const char* text = tm->text->getText();
  1021. Text txtWithLineBreaks;
  1022. if (hatStyle(Style::AutoLineBreak))
  1023. {
  1024. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1025. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  1026. text = txtWithLineBreaks;
  1027. len = txtWithLineBreaks.getLength();
  1028. }
  1029. int max = 0;
  1030. for (int i = 0; i < len && lnum < zeile; i++)
  1031. {
  1032. if (text[i] == '\n')
  1033. {
  1034. lnum++;
  1035. y += max;
  1036. max = 0;
  1037. tm->nextStyle();
  1038. continue;
  1039. }
  1040. TextRenderer* r = tm->zCurrentRenderer();
  1041. if (r)
  1042. {
  1043. int tmp = r->getZeilenAbstand() + r->getZeilenHeight();
  1044. max = max >= tmp ? max : tmp;
  1045. }
  1046. tm->nextStyle();
  1047. }
  1048. unlockZeichnung();
  1049. vertikalScrollBar->scroll(y);
  1050. rend = 1;
  1051. }
  1052. }
  1053. void TextFeld::updateVScroll(int pos) // scrollt nach unten
  1054. {
  1055. if (pos == -1) pos = cpos;
  1056. if (vertikalScrollBar)
  1057. {
  1058. int sPos = 0;
  1059. int hi = 0;
  1060. int sPosZH = 0;
  1061. if (tm->text && tm->renderer)
  1062. {
  1063. if (hatStyleNicht(Style::Mehrzeilig)) tm->text->remove('\n');
  1064. hi = gr.y;
  1065. if (hatStyle(Style::Rahmen) && rahmen)
  1066. hi -= rahmen->getRBreite() * 2;
  1067. if (hatStyle(Style::HScroll) && horizontalScrollBar) hi -= 15;
  1068. int th = 0;
  1069. lockZeichnung();
  1070. tm->resetIteration();
  1071. int len = tm->text->getLength();
  1072. const char* text = tm->text->getText();
  1073. Text txtWithLineBreaks;
  1074. if (hatStyle(Style::AutoLineBreak))
  1075. {
  1076. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1077. autoLineBreakSpacing ? autoLineBreakSpacing->getText()
  1078. : "");
  1079. text = txtWithLineBreaks;
  1080. len = txtWithLineBreaks.getLength();
  1081. }
  1082. int max = 0;
  1083. int lastMax = 0;
  1084. for (int i = 0; i < len; i++)
  1085. {
  1086. if (text[i] == '\n')
  1087. {
  1088. if (i <= pos)
  1089. {
  1090. sPos += max;
  1091. sPosZH = max;
  1092. }
  1093. th += max;
  1094. lastMax = max;
  1095. max = 0;
  1096. tm->nextStyle();
  1097. continue;
  1098. }
  1099. TextRenderer* r = tm->zCurrentRenderer();
  1100. if (r)
  1101. {
  1102. int tmp = r->getZeilenAbstand() + r->getZeilenHeight();
  1103. max = max >= tmp ? max : tmp;
  1104. }
  1105. tm->nextStyle();
  1106. }
  1107. if (max != lastMax && max > 0)
  1108. {
  1109. th += max;
  1110. lastMax = max;
  1111. }
  1112. th += lastMax;
  1113. unlockZeichnung();
  1114. vertikalScrollBar->update(th, hi);
  1115. }
  1116. if (sPos - sPosZH < vertikalScrollBar->getScroll())
  1117. vertikalScrollBar->scroll(sPos - sPosZH);
  1118. if (sPos + sPosZH > vertikalScrollBar->getScroll()
  1119. + vertikalScrollBar->getScrollData()->anzeige)
  1120. vertikalScrollBar->scroll(sPos + sPosZH * 2 - hi);
  1121. rend = 1;
  1122. }
  1123. }
  1124. void TextFeld::updateHScroll(int pos) // scrollt zur Curser Position
  1125. {
  1126. if (pos == -1) pos = cpos;
  1127. lockZeichnung();
  1128. if (horizontalScrollBar && tm->text && tm->renderer)
  1129. {
  1130. if (hatStyleNicht(Style::Mehrzeilig)) tm->text->remove('\n');
  1131. int br = gr.x;
  1132. if (hatStyle(Style::Rahmen) && rahmen) br -= rahmen->getRBreite() * 2;
  1133. if (hatStyle(Style::VScroll) && vertikalScrollBar) br -= 15;
  1134. tm->resetIteration();
  1135. int maxBr = 0;
  1136. int len = tm->text->getLength();
  1137. const char* text = tm->text->getText();
  1138. int lineBr = 0;
  1139. char buff[] = {0, 0};
  1140. int cbr = 0;
  1141. for (int i = 0; i < len; i++)
  1142. {
  1143. buff[0] = text[i];
  1144. if (text[i] == '\n')
  1145. {
  1146. maxBr = maxBr >= lineBr ? maxBr : lineBr;
  1147. lineBr = 0;
  1148. tm->nextStyle();
  1149. continue;
  1150. }
  1151. TextRenderer* r = tm->zCurrentRenderer();
  1152. if (r)
  1153. {
  1154. lineBr += r->getTextBreite(buff);
  1155. if (i <= pos) cbr = lineBr;
  1156. }
  1157. tm->nextStyle();
  1158. }
  1159. maxBr = maxBr >= lineBr ? maxBr : lineBr;
  1160. horizontalScrollBar->update(maxBr, br);
  1161. if (cbr > horizontalScrollBar->getScroll()
  1162. + horizontalScrollBar->getScrollData()->anzeige)
  1163. horizontalScrollBar->scroll(cbr - br);
  1164. if (cbr < horizontalScrollBar->getScroll())
  1165. horizontalScrollBar->scroll(cbr);
  1166. }
  1167. unlockZeichnung();
  1168. }
  1169. // Gibt die breite in pixeln zurück, die benötigt wird um den aktuellen text mit
  1170. // den aktuellen styles voll anzuzeigen
  1171. int TextFeld::getNeededWidth()
  1172. {
  1173. int maxBr = 0;
  1174. lockZeichnung();
  1175. if (tm->text && tm->renderer) maxBr = getTextWidth();
  1176. unlockZeichnung();
  1177. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1178. bool r = rahmen && hatStyle(Style::Rahmen);
  1179. return maxBr + (r ? rahmen->getRBreite() * 2 : 0) + (vs ? 15 : 0);
  1180. }
  1181. // Gibt die höhe in pixeln zurück, die benötigt wird um den aktuellen text mit
  1182. // den aktuellen styles voll anzuzeigen
  1183. int TextFeld::getNeededHeight()
  1184. {
  1185. int th = 0;
  1186. lockZeichnung();
  1187. if (tm->text && tm->renderer) th = getTextHeight();
  1188. unlockZeichnung();
  1189. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1190. bool r = rahmen && hatStyle(Style::Rahmen);
  1191. return th + (r ? rahmen->getRBreite() * 2 : 0) + (hs ? 15 : 0);
  1192. }
  1193. bool TextFeld::tick(double tickval) // tick
  1194. {
  1195. if (hatStyle(Style::Fokus))
  1196. {
  1197. if (tickVal < 0.5 && tickVal + tickval >= 0.5) rend = 1;
  1198. if (tickVal >= 0.5 && tickVal + tickval >= 1) rend = 1;
  1199. tickVal += tickval;
  1200. if (tickVal >= 1) tickVal -= 1;
  1201. }
  1202. return ZeichnungHintergrund::tick(tickval);
  1203. }
  1204. void TextFeld::doTastaturEreignis(TastaturEreignis& te)
  1205. {
  1206. bool ntakc = !te.verarbeitet;
  1207. if (te.verarbeitet || hatStyleNicht(Style::Fokus)) return;
  1208. if (!tak) return;
  1209. getThis();
  1210. if (tak(takParam, this, te))
  1211. {
  1212. if (hatStyleNicht(Style::Editierbar))
  1213. {
  1214. release();
  1215. return;
  1216. }
  1217. if (te.id == TE_Press)
  1218. {
  1219. bool shift = getTastenStand(T_Shift);
  1220. bool strg = getTastenStand(T_Strg);
  1221. switch (te.virtualKey)
  1222. {
  1223. case T_Entf:
  1224. if (!tm->getTextStyle(cpos).selected)
  1225. tm->removeText(cpos, cpos + 1);
  1226. else
  1227. {
  1228. cpos = tm->getTextStyle(cpos).beginIndex;
  1229. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1230. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1231. }
  1232. replaceAuswahl("");
  1233. deselectAuswahl();
  1234. rend = 1;
  1235. break;
  1236. case T_BackSpace:
  1237. if (!tm->getTextStyle(cpos).selected)
  1238. {
  1239. tm->removeText(cpos - 1, cpos);
  1240. cpos--;
  1241. }
  1242. else
  1243. {
  1244. cpos = tm->getTextStyle(cpos).beginIndex;
  1245. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1246. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1247. }
  1248. replaceAuswahl("");
  1249. deselectAuswahl();
  1250. rend = 1;
  1251. break;
  1252. case T_Enter:
  1253. if (hatStyle(TextFeld::Style::Mehrzeilig))
  1254. {
  1255. if (!tm->getTextStyle(cpos).selected)
  1256. tm->insertText(cpos, "\n");
  1257. else
  1258. {
  1259. cpos = tm->getTextStyle(cpos).beginIndex;
  1260. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1261. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1262. }
  1263. replaceAuswahl("\n");
  1264. ++cpos;
  1265. rend = 1;
  1266. }
  1267. break;
  1268. case T_Links:
  1269. if (shift)
  1270. {
  1271. if (strg)
  1272. {
  1273. int tmp = tm->text->getLKick(cpos);
  1274. invertAuswahl(tmp, cpos);
  1275. cpos = tmp;
  1276. }
  1277. else
  1278. {
  1279. invertAuswahl(cpos - 1, cpos);
  1280. --cpos;
  1281. }
  1282. }
  1283. else
  1284. {
  1285. if (strg)
  1286. cpos = tm->text->getLKick(cpos);
  1287. else
  1288. --cpos;
  1289. deselectAuswahl();
  1290. }
  1291. rend = 1;
  1292. break;
  1293. case T_Oben:
  1294. {
  1295. int tmp = tm->text->getOKick(cpos);
  1296. invertAuswahl(tmp, cpos);
  1297. cpos = tmp;
  1298. if (!shift) deselectAuswahl();
  1299. rend = 1;
  1300. break;
  1301. }
  1302. case T_Rechts:
  1303. if (shift)
  1304. {
  1305. if (strg)
  1306. {
  1307. int tmp = tm->text->getRKick(cpos);
  1308. invertAuswahl(cpos, tmp);
  1309. cpos = tmp;
  1310. }
  1311. else
  1312. {
  1313. invertAuswahl(cpos, cpos + 1);
  1314. ++cpos;
  1315. }
  1316. }
  1317. else
  1318. {
  1319. if (strg)
  1320. cpos = tm->text->getRKick(cpos);
  1321. else
  1322. ++cpos;
  1323. deselectAuswahl();
  1324. }
  1325. rend = 1;
  1326. break;
  1327. case T_Unten:
  1328. {
  1329. int tmp = tm->text->getUKick(cpos);
  1330. invertAuswahl(cpos, tmp);
  1331. cpos = tmp;
  1332. if (!shift) deselectAuswahl();
  1333. rend = 1;
  1334. break;
  1335. }
  1336. default:
  1337. if (strg && te.id == TE_Press)
  1338. {
  1339. if (te.virtualKey == 'c' || te.virtualKey == 'C')
  1340. {
  1341. int sa = tm->textStyle.getEintragAnzahl();
  1342. int length = 0;
  1343. for (int i = 0; i < sa; i++)
  1344. {
  1345. TextStyle s = tm->textStyle.get(i);
  1346. if (s.selected)
  1347. {
  1348. int max = tm->text->getLength();
  1349. if (i < sa - 1)
  1350. max = tm->textStyle.get(i + 1).beginIndex;
  1351. length += max - s.beginIndex;
  1352. }
  1353. }
  1354. if (length)
  1355. {
  1356. char* txt = new char[length + 1];
  1357. txt[length] = 0;
  1358. int index = 0;
  1359. for (int i = 0; i < sa; i++)
  1360. {
  1361. TextStyle s = tm->textStyle.get(i);
  1362. if (s.selected)
  1363. {
  1364. int max = tm->text->getLength();
  1365. if (i < sa - 1)
  1366. max = tm->textStyle.get(i + 1)
  1367. .beginIndex;
  1368. memcpy(txt + index,
  1369. tm->text->getText() + s.beginIndex,
  1370. max - s.beginIndex);
  1371. index += max - s.beginIndex;
  1372. }
  1373. }
  1374. TextKopieren(txt);
  1375. delete[] txt;
  1376. }
  1377. else
  1378. TextKopieren(tm->text->getText());
  1379. }
  1380. if (te.virtualKey == 'v' || te.virtualKey == 'V')
  1381. {
  1382. const char* txt = TextInsert();
  1383. if (!tm->getTextStyle(cpos).selected)
  1384. tm->insertText(cpos, txt);
  1385. else
  1386. {
  1387. cpos = tm->getTextStyle(cpos).beginIndex;
  1388. while (
  1389. cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1390. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1391. }
  1392. replaceAuswahl(txt);
  1393. cpos += textLength(txt);
  1394. rend = 1;
  1395. }
  1396. break;
  1397. }
  1398. if (istSchreibbar(te.taste[0]))
  1399. {
  1400. if (!tm->getTextStyle(cpos).selected)
  1401. tm->insertText(cpos, te.taste);
  1402. else
  1403. {
  1404. cpos = tm->getTextStyle(cpos).beginIndex;
  1405. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1406. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1407. }
  1408. replaceAuswahl(te.taste);
  1409. ++cpos;
  1410. rend = 1;
  1411. }
  1412. break;
  1413. }
  1414. }
  1415. if (cpos < 0) cpos = 0;
  1416. if (cpos > tm->text->getLength()) cpos = tm->text->getLength();
  1417. if (hatStyle(Style::VScroll)) updateVScroll(cpos);
  1418. if (hatStyle(Style::HScroll)) updateHScroll(cpos);
  1419. te.verarbeitet = 1;
  1420. }
  1421. if (ntakc && te.verarbeitet && nTak)
  1422. te.verarbeitet = nTak(ntakParam, this, te);
  1423. release();
  1424. }
  1425. void TextFeld::render(Bild& zRObj) // zeichenet nach zRObj
  1426. {
  1427. if (hatStyleNicht(Style::Sichtbar)) return;
  1428. ZeichnungHintergrund::render(zRObj);
  1429. if (!tm->text || !tm->renderer) return;
  1430. lockZeichnung();
  1431. if (!zRObj.setDrawOptions(innenPosition, innenSize))
  1432. {
  1433. unlockZeichnung();
  1434. return;
  1435. }
  1436. if (hatStyleNicht(Style::Mehrzeilig)) tm->text->remove('\n');
  1437. int tbr = getTextWidth();
  1438. int thi = getTextHeight();
  1439. int xxx = 0;
  1440. int yyy = 0;
  1441. int breite = innenSize.x;
  1442. int height = innenSize.y;
  1443. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1444. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1445. if (vs) yyy -= vertikalScrollBar->getScroll();
  1446. if (hs) xxx -= horizontalScrollBar->getScroll();
  1447. if (hatStyle(Style::HCenter) && !hs) xxx = (breite / 2) - tbr / 2;
  1448. int x = xxx;
  1449. int len = tm->text->getLength();
  1450. const char* text = tm->text->getText();
  1451. Text txtWithLineBreaks;
  1452. if (hatStyle(Style::AutoLineBreak))
  1453. {
  1454. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1455. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  1456. text = txtWithLineBreaks;
  1457. len = txtWithLineBreaks.getLength();
  1458. }
  1459. lockZeichnung();
  1460. tm->resetIteration();
  1461. if (thi == 0)
  1462. {
  1463. thi = tm->zCurrentRenderer()->getZeilenHeight();
  1464. }
  1465. if (hatStyle(Style::VCenter) && !vs) yyy = (height / 2) - thi / 2;
  1466. int y = yyy;
  1467. TextStyle& style = tm->currentStyle();
  1468. int maxLH = 0;
  1469. int corrector = 0;
  1470. int realLen = tm->text->getLength();
  1471. for (int i = 0; i <= len; i++)
  1472. {
  1473. int oldX = x;
  1474. if (i < len && tm->zCurrentRenderer())
  1475. tm->zCurrentRenderer()->renderChar(x,
  1476. y,
  1477. istSchreibbar(showChar) ? showChar : text[i],
  1478. zRObj,
  1479. style.selected ? style.selectedColor : style.fontColor,
  1480. style.underlined,
  1481. style.selected,
  1482. style.selectedBackcroundColor);
  1483. if (i - corrector == cpos && tickVal <= 0.5 && hatStyle(Style::Fokus)
  1484. && hatStyle(Style::Editierbar) && tm->zCurrentRenderer())
  1485. zRObj.drawLinieV(
  1486. oldX, y, tm->zCurrentRenderer()->getZeilenHeight(), 0xFFFF5555);
  1487. if (i >= realLen || text[i] != tm->text->getText()[i])
  1488. {
  1489. corrector++;
  1490. }
  1491. if (tm->zCurrentRenderer())
  1492. {
  1493. int tmp = tm->zCurrentRenderer()->getZeilenHeight()
  1494. + tm->zCurrentRenderer()->getZeilenAbstand();
  1495. maxLH = tmp > maxLH ? tmp : maxLH;
  1496. }
  1497. if (i < len && text[i] == '\n')
  1498. {
  1499. x = xxx;
  1500. y += maxLH;
  1501. }
  1502. tm->nextStyle();
  1503. }
  1504. unlockZeichnung();
  1505. zRObj.releaseDrawOptions();
  1506. unlockZeichnung();
  1507. }
  1508. // Konstant
  1509. Text* TextFeld::getText() const // gibt vom Text zurück
  1510. {
  1511. if (!tm->text) return 0;
  1512. return dynamic_cast<Text*>(tm->text->getThis());
  1513. }
  1514. Text* TextFeld::zText() const // gibt den Text zurück
  1515. {
  1516. return tm->text;
  1517. }
  1518. Schrift* TextFeld::getSchrift() const // gint getThis der Schrift Zurück
  1519. {
  1520. tm->resetIteration();
  1521. return tm->zCurrentRenderer() ? tm->zCurrentRenderer()->getSchrift() : 0;
  1522. }
  1523. Schrift* TextFeld::zSchrift() const // gibt die Schrift zurück
  1524. {
  1525. tm->resetIteration();
  1526. return tm->zCurrentRenderer() ? tm->zCurrentRenderer()->zSchrift() : 0;
  1527. }
  1528. // Gibt die Schrift zurück.
  1529. // rendererIndex: Der Index des Renderers dessen Schrift zurückgegeben werden
  1530. // soll return: 0, falls die Schrift nicht gesetzt wurde
  1531. Schrift* TextFeld::getSchrift(int rendererIndex) const
  1532. {
  1533. if (tm->renderer && tm->renderer->z(rendererIndex))
  1534. return tm->renderer->z(rendererIndex)->getSchrift();
  1535. return 0;
  1536. }
  1537. // Gibt die Schrift ohne erhöhten Reference Counter zurük
  1538. // rendererIndex: Der Index des Renderers dessen Schrift zurückgegeben werden
  1539. // soll return: 0, falls die Schrift nicht gesetzt wurde
  1540. Schrift* TextFeld::zSchrift(int rendererIndex) const
  1541. {
  1542. if (tm->renderer && tm->renderer->z(rendererIndex))
  1543. return tm->renderer->z(rendererIndex)->zSchrift();
  1544. return 0;
  1545. }
  1546. TextRenderer* TextFeld::getTextRenderer() const
  1547. {
  1548. tm->resetIteration();
  1549. return dynamic_cast<TextRenderer*>(tm->zCurrentRenderer()->getThis());
  1550. }
  1551. TextRenderer* TextFeld::zTextRenderer() const
  1552. {
  1553. tm->resetIteration();
  1554. return tm->zCurrentRenderer();
  1555. }
  1556. // Gibt den TextRenderer zurück.
  1557. // index: Der Index des Renderers der zurückgegeben werden soll
  1558. // return: 0, falls der TextRenderer nicht gesetzt wurde
  1559. TextRenderer* TextFeld::getTextRenderer(int index) const
  1560. {
  1561. if (tm->renderer && tm->renderer->z(index)) return tm->renderer->get(index);
  1562. return 0;
  1563. }
  1564. // Gibt dien TextRenderer ohne erhöhten Reference Counter zurük
  1565. // index: Der Index des Renderers der zurückgegeben werden soll
  1566. // return: 0, falls der TextRenderer nicht gesetzt wurde
  1567. TextRenderer* TextFeld::zTextRenderer(int index) const
  1568. {
  1569. if (tm->renderer && tm->renderer->z(index)) return tm->renderer->z(index);
  1570. return 0;
  1571. }
  1572. unsigned char TextFeld::getSchriftSize() const // gibt die Schriftgröße zurück
  1573. {
  1574. tm->resetIteration();
  1575. return tm->current.fontSize;
  1576. }
  1577. // Gibt die Schriftgröße zurück
  1578. // index: Der Index des Zeichens
  1579. unsigned char TextFeld::getSchriftSize(int index) const
  1580. {
  1581. tm->resetIteration();
  1582. return tm->current.fontSize;
  1583. }
  1584. int TextFeld::getSchriftFarbe() const // gibt getThis der Schriftfarbe zurück
  1585. {
  1586. tm->resetIteration();
  1587. return tm->current.fontColor;
  1588. }
  1589. // Gibt die Schriftfarbe im A8R8G8B8 Format zurück
  1590. // index: Der Index des Zeichens
  1591. int TextFeld::getSchriftFarbe(int index) const
  1592. {
  1593. return tm->getTextStyle(index).fontColor;
  1594. }
  1595. unsigned char TextFeld::getShowChar() const // gibt den Anzeige Char zurück
  1596. {
  1597. return showChar;
  1598. }
  1599. int TextFeld::getCursorPos() const
  1600. {
  1601. return cpos;
  1602. }
  1603. // Gibt 1 zurück wenn das Zeichen ausgewählt ist
  1604. // index: Der Index des Zeichens
  1605. bool TextFeld::isCharSelected(int index) const
  1606. {
  1607. return tm->getTextStyle(index).selected;
  1608. }
  1609. // Gibt den Index des Zeichens zurück, das sich unter der Maus befindet
  1610. // mx: die x position der maus relativ zur position des textfeldes
  1611. // my: die y position der maus relativ zut position des textfeldes
  1612. // return: -1, falls sich an der Position kein zeichen befindet
  1613. int TextFeld::getTextIndexAt(int mx, int my) const
  1614. {
  1615. if (!tm || !tm->text || !tm->zCurrentRenderer()) return -1;
  1616. int tbr = getTextWidth();
  1617. int thi = getTextHeight();
  1618. int xxx = 0;
  1619. int yyy = 0;
  1620. int breite = innenSize.x;
  1621. int height = innenSize.y;
  1622. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1623. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1624. if (vs) yyy -= vertikalScrollBar->getScroll();
  1625. if (hs) xxx -= horizontalScrollBar->getScroll();
  1626. if (hatStyle(Style::HCenter) && !hs) xxx = (breite / 2) - tbr / 2;
  1627. if (hatStyle(Style::VCenter) && !vs) yyy = (height / 2) - thi / 2;
  1628. int x = xxx;
  1629. int y = yyy;
  1630. int len = tm->text->getLength();
  1631. const char* text = tm->text->getText();
  1632. Text txtWithLineBreaks;
  1633. if (hatStyle(Style::AutoLineBreak))
  1634. {
  1635. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1636. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  1637. text = txtWithLineBreaks;
  1638. len = txtWithLineBreaks.getLength();
  1639. }
  1640. tm->resetIteration();
  1641. int corrector = 0;
  1642. int maxLH = 0;
  1643. int realLen = tm->text->getLength();
  1644. for (int i = 0; i < len; i++)
  1645. {
  1646. if (i >= realLen || text[i] != tm->text->getText()[i])
  1647. {
  1648. corrector++;
  1649. }
  1650. char buff[2] = {istSchreibbar(showChar) ? (char)showChar : text[i], 0};
  1651. int tmpx = tm->zCurrentRenderer()->getTextBreite(buff);
  1652. int tmpy = tm->zCurrentRenderer()->getZeilenHeight();
  1653. if (mx >= x && mx < x + tmpx && my >= y && my < y + tmpy)
  1654. return i - corrector;
  1655. if (mx < x + tmpx && my < y + tmpy) return -1;
  1656. x += tmpx;
  1657. tmpy += tm->zCurrentRenderer()->getZeilenAbstand();
  1658. maxLH = tmpy > maxLH ? tmpy : maxLH;
  1659. if (text[i] == '\n')
  1660. {
  1661. x = xxx;
  1662. y += maxLH;
  1663. }
  1664. tm->nextStyle();
  1665. }
  1666. return -1;
  1667. }
  1668. // Gibt den Index des Zeichens zurück, vor dem der curser gesetzt wird, wenn mit
  1669. // der maus geklickt wird
  1670. // mx: die x position der maus relativ zur position des textfeldes
  1671. // my: die y position der maus relativ zut position des textfeldes
  1672. int TextFeld::getCurserPosAt(int mx, int my) const
  1673. {
  1674. if (!tm || !tm->text || !tm->zCurrentRenderer())
  1675. return tm->text->getLength();
  1676. int tbr = getTextWidth();
  1677. int thi = getTextHeight();
  1678. int xxx = 0;
  1679. int yyy = 0;
  1680. int breite = innenSize.x;
  1681. int height = innenSize.y;
  1682. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1683. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1684. if (vs) yyy -= vertikalScrollBar->getScroll();
  1685. if (hs) xxx -= horizontalScrollBar->getScroll();
  1686. if (hatStyle(Style::HCenter) && !hs) xxx = (breite / 2) - tbr / 2;
  1687. if (hatStyle(Style::VCenter) && !vs) yyy = (height / 2) - thi / 2;
  1688. int x = xxx;
  1689. int y = yyy;
  1690. int len = tm->text->getLength();
  1691. const char* text = tm->text->getText();
  1692. Text txtWithLineBreaks;
  1693. if (hatStyle(Style::AutoLineBreak))
  1694. {
  1695. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1696. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  1697. text = txtWithLineBreaks;
  1698. len = txtWithLineBreaks.getLength();
  1699. }
  1700. tm->resetIteration();
  1701. int maxLH = 0;
  1702. int realLen = tm->text->getLength();
  1703. int corrector = 0;
  1704. for (int i = 0; i < len; i++)
  1705. {
  1706. if (i >= realLen || text[i] != tm->text->getText()[i])
  1707. {
  1708. corrector++;
  1709. }
  1710. int tmpx = tm->zCurrentRenderer()->getCharWidth(
  1711. istSchreibbar(showChar) ? showChar : text[i]);
  1712. int tmpy = tm->zCurrentRenderer()->getZeilenHeight()
  1713. + tm->zCurrentRenderer()->getZeilenAbstand();
  1714. if (mx < x + tmpx / 2
  1715. && my < y + tmpy - tm->zCurrentRenderer()->getZeilenAbstand() / 2)
  1716. return i - corrector;
  1717. x += tmpx + tm->zCurrentRenderer()->getZeichenAbstand();
  1718. maxLH = tmpy > maxLH ? tmpy : maxLH;
  1719. if (text[i] == '\n')
  1720. {
  1721. if (my >= y - tm->zCurrentRenderer()->getZeilenAbstand() / 2
  1722. && my < y + maxLH
  1723. - tm->zCurrentRenderer()->getZeilenAbstand() / 2)
  1724. return i - corrector;
  1725. x = xxx;
  1726. y += maxLH;
  1727. }
  1728. tm->nextStyle();
  1729. }
  1730. return tm->text->getLength();
  1731. }
  1732. // Gibt den Style eines bestimmten zeichens zurück
  1733. // index: Der index des Zeichensf
  1734. TextStyle TextFeld::getTextStyle(int index) const
  1735. {
  1736. return tm->getTextStyle(index);
  1737. }
  1738. // gibt die Zeichenkette zurück, die bei Verwendung des Styles
  1739. // AutoLineBreak nach jedem Zeilenumbruch eingefügt wird
  1740. Text TextFeld::getAutoLineBreakSpacing() const
  1741. {
  1742. return autoLineBreakSpacing ? *autoLineBreakSpacing : Text("");
  1743. }
  1744. Zeichnung* TextFeld::dublizieren() const // Erzeugt eine Kopie des Zeichnungs
  1745. {
  1746. TextFeld* obj = new TextFeld();
  1747. obj->setPosition(pos);
  1748. obj->setSize(gr);
  1749. obj->setMausEreignisParameter(makParam);
  1750. obj->setTastaturEreignisParameter(takParam);
  1751. obj->setMausEreignis(mak);
  1752. obj->setTastaturEreignis(tak);
  1753. if (toolTip) obj->setToolTipZ((ToolTip*)toolTip->dublizieren());
  1754. obj->setStyle(style);
  1755. obj->tm->renderer->release();
  1756. obj->tm->renderer
  1757. = dynamic_cast<RCArray<TextRenderer>*>(tm->renderer->getThis());
  1758. obj->tm->textStyle.leeren();
  1759. for (const auto& i : tm->textStyle)
  1760. obj->tm->textStyle.add(i);
  1761. obj->tm->index = tm->index;
  1762. obj->tm->styleIndex = tm->styleIndex;
  1763. obj->tm->current = tm->current;
  1764. if (tm->text) obj->setText(tm->text->getText());
  1765. obj->setHintergrundFarbe(hintergrundFarbe);
  1766. if (hintergrundFeld)
  1767. obj->setAlphaFeldZ((AlphaFeld*)hintergrundFeld->dublizieren());
  1768. if (rahmen) obj->setRahmenZ((Rahmen*)rahmen->dublizieren());
  1769. if (hintergrundBild)
  1770. obj->setHintergrundBild(
  1771. dynamic_cast<Bild*>(hintergrundBild->getThis()));
  1772. if (vertikalScrollBar)
  1773. {
  1774. obj->setVertikalKlickScroll(vertikalScrollBar->getKlickScroll());
  1775. obj->setVertikalScrollPos(vertikalScrollBar->getScroll());
  1776. obj->setVertikalScrollFarbe(
  1777. vertikalScrollBar->getFarbe(), vertikalScrollBar->getBgFarbe());
  1778. }
  1779. if (horizontalScrollBar)
  1780. {
  1781. obj->setHorizontalKlickScroll(horizontalScrollBar->getKlickScroll());
  1782. obj->setHorizontalScrollPos(horizontalScrollBar->getScroll());
  1783. obj->setHorizontalScrollFarbe(
  1784. horizontalScrollBar->getFarbe(), horizontalScrollBar->getBgFarbe());
  1785. }
  1786. if (autoLineBreakSpacing)
  1787. {
  1788. obj->setAutoLineBreakSpacing(*autoLineBreakSpacing);
  1789. }
  1790. obj->setSchowChar(showChar);
  1791. return obj;
  1792. }