TextFeld.cpp 59 KB

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