TextField.cpp 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877
  1. #include "TextField.h"
  2. #include <math.h>
  3. #include "AlphaField.h"
  4. #include "Image.h"
  5. #include "Window.h"
  6. #include "Globals.h"
  7. #include "MouseEvent.h"
  8. #include "Border.h"
  9. #include "Font.h"
  10. #include "Scroll.h"
  11. #include "KeyboardEvent.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. TextField::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. TextField::TextStyleManager::~TextStyleManager()
  46. {
  47. if (renderer) renderer->release();
  48. if (text) text->release();
  49. }
  50. // Sets the style of a text section
  51. // begin: the start position of the section
  52. // end: the end position of the section (not included)
  53. void TextField::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. // search to the correct position in the style array
  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. { // append styles at the end
  81. textStyle.add(style);
  82. textStyle.add(s);
  83. }
  84. else
  85. { // insert into the middle of the style array
  86. textStyle.add(style, index);
  87. for (int i = index + 1; i < sc + 1; i++)
  88. { // remove styles that were overwritten
  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. // Removes a text section
  104. // begin: the index of the first affected character
  105. // end: the index of the first character after the section
  106. void TextField::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. // Inserts text at a specific position
  128. // pos: the position of the new text section
  129. // text: the new text
  130. void TextField::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. // Removes unnecessary duplicate styles
  147. void TextField::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. // returns a reference to the style object
  173. TextStyle& TextField::TextStyleManager::currentStyle()
  174. {
  175. return current;
  176. }
  177. // returns the current text renderer
  178. TextRenderer* TextField::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. // changes the content of the style object to the style of the next character
  187. bool TextField::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. // changes the content of the style object to the style of the specified
  196. // character
  197. // index: the index of the character to jump to
  198. // returns 0 if the character does not exist
  199. bool TextField::TextStyleManager::stepTo(int index)
  200. {
  201. resetIteration();
  202. while (this->index < index && nextStyle())
  203. ;
  204. return text && this->index == index;
  205. }
  206. // changes the content of the style object to the style of the first character
  207. void TextField::TextStyleManager::resetIteration()
  208. {
  209. index = 0;
  210. styleIndex = 0;
  211. current = textStyle.get(0);
  212. }
  213. // Returns the style of a specific character\n// index: The index of the
  214. // character
  215. TextStyle TextField::TextStyleManager::getTextStyle(int index) const
  216. {
  217. TextStyle last = textStyle.get(0);
  218. int ind = 0;
  219. for (auto i = textStyle.begin(); i && ind <= index; ind++)
  220. {
  221. if (i._.beginIndex <= ind)
  222. {
  223. last = i;
  224. i++;
  225. }
  226. }
  227. return last;
  228. }
  229. // Contents of the TextField class from TextField.h
  230. // Constructor
  231. TextField::TextField()
  232. : DrawableBackground(),
  233. tm(new TextStyleManager()),
  234. autoLineBreakSpacing(0),
  235. showChar(0),
  236. cpos(0),
  237. tickVal(0),
  238. mausKlick(0)
  239. {
  240. charEvent = 0;
  241. horizontalScrollBar = new HScrollBar();
  242. vertikalScrollBar = new VScrollBar();
  243. this->setMausEreignis(_ret1ME);
  244. this->setTastaturEreignis(_ret1TE);
  245. }
  246. // Destructor
  247. TextField::~TextField()
  248. {
  249. tm->release();
  250. if (autoLineBreakSpacing) autoLineBreakSpacing->release();
  251. }
  252. void TextField::doMausEreignis(MausEreignis& me, bool userRet) // Mouse event
  253. {
  254. if (!userRet) return;
  255. if (hatStyleNicht(Style::Editierbar))
  256. {
  257. int rbr = 0;
  258. if (rahmen) rbr = rahmen->getRBreite();
  259. if (((vertikalScrollBar && hatStyle(Style::VScroll))
  260. || (horizontalScrollBar && hatStyle(Style::HScroll)))
  261. && me.mx > rbr && me.mx < gr.x - rbr && me.my > rbr
  262. && me.my < gr.y - rbr)
  263. {
  264. me.verarbeitet |= vertikalScrollBar->doMausMessage(
  265. gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me);
  266. me.verarbeitet |= horizontalScrollBar->doMausMessage(rbr,
  267. gr.y - rbr * 2 - 15,
  268. gr.x - rbr * 2
  269. - ((vertikalScrollBar && hatStyle(Style::VScroll)) ? 15
  270. : 0),
  271. 15,
  272. me);
  273. }
  274. if (me.mx >= 0 && me.mx <= gr.x && me.my >= 0 && me.my <= gr.y
  275. && !me.verarbeitet && hatStyle(Style::Sichtbar))
  276. {
  277. int scrollHi = (vertikalScrollBar && hatStyle(Style::VScroll))
  278. ? vertikalScrollBar->getScroll()
  279. : 0;
  280. int scrollBr = (horizontalScrollBar && hatStyle(Style::HScroll))
  281. ? horizontalScrollBar->getScroll()
  282. : 0;
  283. int xxx = me.mx - rbr + scrollBr;
  284. int yyy = me.my - rbr + scrollHi;
  285. int mausChar = getTextIndexAt(xxx, yyy);
  286. if (mausChar >= 0)
  287. {
  288. TextStyle s = tm->getTextStyle(mausChar);
  289. if (charEvent && s.interactParam)
  290. charEvent(mausChar, s.interactParam, me);
  291. }
  292. if (charEvent) me.verarbeitet = 1;
  293. }
  294. mausKlick = 0;
  295. return;
  296. }
  297. if (!me.verarbeitet)
  298. {
  299. if (hatStyleNicht(Style::Fokus))
  300. {
  301. mausKlick = 0;
  302. if (me.id == Framework::ME_PLinks) addStyle(Style::Fokus);
  303. }
  304. int rbr = 0;
  305. if (rahmen) rbr = rahmen->getRBreite();
  306. if (vertikalScrollBar && hatStyle(Style::VScroll))
  307. {
  308. if (vertikalScrollBar->doMausMessage(
  309. gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me))
  310. {
  311. me.verarbeitet = 1;
  312. return;
  313. }
  314. }
  315. if (horizontalScrollBar && hatStyle(Style::HScroll))
  316. {
  317. if (horizontalScrollBar->doMausMessage(rbr,
  318. gr.y - rbr - 15,
  319. gr.x - rbr * 2
  320. - ((vertikalScrollBar && hatStyle(Style::VScroll)) ? 15
  321. : 0),
  322. 15,
  323. me))
  324. {
  325. me.verarbeitet = 1;
  326. return;
  327. }
  328. }
  329. bool shift = getTastenStand(T_Shift);
  330. bool strg = getTastenStand(T_Strg);
  331. int tbr = getTextWidth();
  332. int thi = getTextHeight();
  333. int scrollHi = (vertikalScrollBar && hatStyle(Style::VScroll))
  334. ? vertikalScrollBar->getScroll()
  335. : 0;
  336. int scrollBr = (horizontalScrollBar && hatStyle(Style::HScroll))
  337. ? horizontalScrollBar->getScroll()
  338. : 0;
  339. int xxx = me.mx - rbr + scrollBr;
  340. int yyy = me.my - rbr + scrollHi;
  341. int mausChar = getTextIndexAt(xxx, yyy);
  342. int scrollBreite = (vertikalScrollBar && hatStyle(Style::VScroll)) * 15;
  343. int scrollHeight
  344. = (horizontalScrollBar && hatStyle(Style::HScroll)) * 15;
  345. if (hatStyle(Style::HCenter))
  346. xxx -= (((gr.x - scrollBreite) / 2) - tbr / 2) - rbr;
  347. if (hatStyle(Style::VCenter) && hatStyleNicht(Style::VScroll))
  348. yyy -= (((gr.y - scrollHeight) / 2) - thi / 2) - rbr;
  349. if (mausChar >= 0)
  350. {
  351. TextStyle s = tm->getTextStyle(mausChar);
  352. if (charEvent) charEvent(mausChar, s.interactParam, me);
  353. }
  354. if (me.mx < gr.x - rbr - 15)
  355. {
  356. if (tm->renderer)
  357. {
  358. int ncpos = getCurserPosAt(xxx, yyy);
  359. if (me.id == Framework::ME_PLinks)
  360. {
  361. if (ncpos != -1)
  362. {
  363. if (shift && cpos != ncpos)
  364. addAuswahl(MIN(cpos, ncpos), MAX(cpos, ncpos));
  365. else if (!shift && !mausKlick && !strg)
  366. deselectAuswahl();
  367. cpos = ncpos;
  368. rend = 1;
  369. if (vertikalScrollBar && hatStyle(Style::VScroll))
  370. updateVScroll();
  371. if (horizontalScrollBar && hatStyle(Style::HScroll))
  372. updateHScroll();
  373. }
  374. mausKlick = 1;
  375. }
  376. if (me.id == ME_Bewegung && mausKlick)
  377. {
  378. if (ncpos != -1)
  379. {
  380. rend = 1;
  381. if (cpos != ncpos)
  382. invertAuswahl(MIN(cpos, ncpos), MAX(cpos, ncpos));
  383. cpos = ncpos;
  384. if (vertikalScrollBar && hatStyle(Style::VScroll))
  385. updateVScroll(cpos);
  386. if (horizontalScrollBar && hatStyle(Style::HScroll))
  387. updateHScroll(cpos);
  388. }
  389. }
  390. if (me.id == ME_RLinks)
  391. {
  392. if (ncpos != -1)
  393. {
  394. rend = 1;
  395. if (cpos != ncpos)
  396. invertAuswahl(MIN(cpos, ncpos), MAX(cpos, ncpos));
  397. cpos = ncpos;
  398. if (vertikalScrollBar && hatStyle(Style::VScroll))
  399. updateVScroll(cpos);
  400. if (horizontalScrollBar && hatStyle(Style::HScroll))
  401. updateHScroll(cpos);
  402. }
  403. mausKlick = 0;
  404. }
  405. }
  406. }
  407. }
  408. me.verarbeitet = 1;
  409. }
  410. int TextField::getTextHeight() const
  411. {
  412. if (!tm || !tm->text) return 0;
  413. tm->resetIteration();
  414. int th = 0;
  415. int len = tm->text->getLength();
  416. const char* text = tm->text->getText();
  417. Text txtWithLineBreaks;
  418. if (hatStyle(Style::AutoLineBreak))
  419. {
  420. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  421. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  422. text = txtWithLineBreaks;
  423. len = txtWithLineBreaks.getLength();
  424. }
  425. int max = 0;
  426. int abstand = 0;
  427. for (int i = 0; i < len; i++)
  428. {
  429. if (text[i] == '\n')
  430. {
  431. th += max + abstand;
  432. abstand = 0;
  433. max = 0;
  434. tm->nextStyle();
  435. continue;
  436. }
  437. TextRenderer* r = tm->zCurrentRenderer();
  438. if (r)
  439. {
  440. int tmp = r->getZeilenHeight();
  441. max = max >= tmp ? max : tmp;
  442. if (max == tmp) abstand = r->getZeilenAbstand();
  443. }
  444. tm->nextStyle();
  445. }
  446. if (max > 0) th += max;
  447. return th;
  448. }
  449. int TextField::getTextWidth() const
  450. {
  451. if (!tm || !tm->text) return 0;
  452. tm->resetIteration();
  453. int maxBr = 0;
  454. int len = tm->text->getLength();
  455. const char* text = tm->text->getText();
  456. Text txtWithLineBreaks;
  457. if (hatStyle(Style::AutoLineBreak))
  458. {
  459. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  460. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  461. text = txtWithLineBreaks;
  462. len = txtWithLineBreaks.getLength();
  463. }
  464. int lineBr = 0;
  465. char buff[] = {0, 0};
  466. for (int i = 0; i < len; i++)
  467. {
  468. buff[0] = text[i];
  469. if (text[i] == '\n')
  470. {
  471. maxBr = maxBr >= lineBr ? maxBr : lineBr;
  472. lineBr = 0;
  473. tm->nextStyle();
  474. continue;
  475. }
  476. TextRenderer* r = tm->zCurrentRenderer();
  477. if (r) lineBr += r->getTextBreite(buff);
  478. tm->nextStyle();
  479. }
  480. if (lineBr > 0) maxBr = maxBr >= lineBr ? maxBr : lineBr;
  481. return maxBr;
  482. }
  483. // charEvent: a function that is called when the mouse is on a
  484. // specific character and the interactParam in the style != 0
  485. // call: charEvent( charIndex, interactParam, mausEreignis );
  486. void TextField::setCharEvent(
  487. std::function<void(int, int, MausEreignis me)> charEvent)
  488. {
  489. this->charEvent = charEvent;
  490. }
  491. void TextField::setText(Text* txt) // sets the displayed text
  492. {
  493. lockDrawable();
  494. if (!tm->text) tm->text = new Text();
  495. tm->text->setText(*txt);
  496. if (hatStyle(Style::VScroll)) updateVScroll();
  497. if (hatStyle(Style::HScroll)) updateHScroll();
  498. unlockDrawable();
  499. rend = 1;
  500. txt->release();
  501. }
  502. void TextField::setTextZ(Text* txt) // sets a pointer to the displayed text
  503. {
  504. lockDrawable();
  505. if (tm->text) tm->text->release();
  506. tm->text = txt;
  507. if (hatStyle(Style::VScroll)) updateVScroll();
  508. if (hatStyle(Style::HScroll)) updateHScroll();
  509. rend = 1;
  510. unlockDrawable();
  511. }
  512. void TextField::setText(const char* txt) // sets the displayed text
  513. {
  514. lockDrawable();
  515. if (!tm->text) tm->text = new Text();
  516. tm->text->setText(txt);
  517. if (hatStyle(Style::VScroll)) updateVScroll();
  518. if (hatStyle(Style::HScroll)) updateHScroll();
  519. rend = 1;
  520. unlockDrawable();
  521. }
  522. // sets the text with styles
  523. // txt: the text
  524. // format: \x1: enables underline
  525. // \x2FF: sets the font size for the following text.
  526. // FF is a two-digit hex value
  527. // \x3AARRGGBB: sets the font color.
  528. // AARRGGBB is an 8-digit hex value with two characters each
  529. // for alpha, red, green and blue
  530. // \x4AARRGGBB: sets the color of the selected text.
  531. // AARRGGBB is an 8-digit hex value with two characters each
  532. // for alpha, red, green and blue
  533. // \x5AARRGGBB: sets the background color of the selected text.
  534. // AARRGGBB is an 8-digit hex value with two characters each
  535. // for alpha, red, green and blue
  536. // \x6FF: sets text renderer index.
  537. // FF is a two-digit hex value
  538. // \x7: deactivates underline
  539. // \x8FFFFFFFF: set interact param.
  540. // FFFFFFFF is an 8-digit hex value
  541. void TextField::setFormattedText(const char* txt)
  542. {
  543. lockDrawable();
  544. if (!tm->text) tm->text = new Text();
  545. tm->textStyle.leeren();
  546. TextStyle current;
  547. current.beginIndex = 0;
  548. current.fontColor = 0xFFFFFFFF;
  549. current.fontSize = 12;
  550. current.selected = 0;
  551. current.selectedColor = 0xFFFFFFFF;
  552. current.selectedBackcroundColor = 0xFF0000FF;
  553. current.underlined = 0;
  554. current.interactParam = 0;
  555. current.rendererIndex = 0;
  556. tm->textStyle.add(current);
  557. Text result = "";
  558. for (int i = 0; 1; i++)
  559. {
  560. bool br = 0;
  561. current.beginIndex = result.getLength();
  562. switch (txt[i])
  563. {
  564. case 0:
  565. br = 1;
  566. break;
  567. case 1:
  568. current.underlined = 1;
  569. tm->textStyle.add(current);
  570. break;
  571. case 2:
  572. {
  573. Text p = "0x";
  574. p.append(txt + i + 1, 2);
  575. current.fontSize = (unsigned char)(int)p;
  576. tm->textStyle.add(current);
  577. i += 2;
  578. break;
  579. }
  580. case 3:
  581. {
  582. Text p = "0x";
  583. p.append(txt + i + 1, 8);
  584. current.fontColor = (int)p;
  585. tm->textStyle.add(current);
  586. i += 8;
  587. }
  588. break;
  589. case 4:
  590. {
  591. Text p = "0x";
  592. p.append(txt + i + 1, 8);
  593. current.selectedColor = (int)p;
  594. tm->textStyle.add(current);
  595. i += 8;
  596. break;
  597. }
  598. case 5:
  599. {
  600. Text p = "0x";
  601. p.append(txt + i + 1, 8);
  602. current.selectedBackcroundColor = (int)p;
  603. tm->textStyle.add(current);
  604. i += 8;
  605. break;
  606. }
  607. case 6:
  608. {
  609. Text p = "0x";
  610. p.append(txt + i + 1, 2);
  611. current.rendererIndex = (unsigned char)(int)p;
  612. tm->textStyle.add(current);
  613. i += 2;
  614. }
  615. break;
  616. case 7:
  617. current.underlined = 0;
  618. tm->textStyle.add(current);
  619. break;
  620. case 8:
  621. {
  622. Text p = "0x";
  623. p.append(txt + i + 1, 8);
  624. current.interactParam = (int)p;
  625. tm->textStyle.add(current);
  626. i += 8;
  627. }
  628. break;
  629. default:
  630. result.append(txt[i]);
  631. }
  632. if (br) break;
  633. }
  634. tm->text->setText(result);
  635. tm->cleanupStyles();
  636. if (hatStyle(Style::VScroll)) updateVScroll();
  637. if (hatStyle(Style::HScroll)) updateHScroll();
  638. rend = 1;
  639. unlockDrawable();
  640. }
  641. // inserts line breaks so that the text does not exceed the width of the text
  642. // field
  643. void TextField::addLineBreaks(const char* spacing)
  644. {
  645. if (!tm->text) return;
  646. setFormattedText(addLineBreaksToText(tm->text->getText(), spacing));
  647. }
  648. Text TextField::addLineBreaksToText(
  649. const char* txt, const char* spacing, bool includeFormat) const
  650. {
  651. int lastPos = -1;
  652. int lastPos2 = -1;
  653. int x = 0;
  654. Text result = "";
  655. int len = (int)strlen(txt);
  656. int maxBr = getBreite();
  657. if (hatStyle(Style::VScroll) && vertikalScrollBar) maxBr -= 15;
  658. tm->resetIteration();
  659. TextStyle last;
  660. last.beginIndex = 0;
  661. last.fontColor = 0xFFFFFFFF;
  662. last.fontSize = 12;
  663. last.selected = 0;
  664. last.selectedColor = 0xFFFFFFFF;
  665. last.selectedBackcroundColor = 0xFF0000FF;
  666. last.underlined = 0;
  667. last.interactParam = 0;
  668. last.rendererIndex = 0;
  669. for (int i = 0; i < len; ++i)
  670. {
  671. if (last.fontSize != tm->current.fontSize && includeFormat)
  672. {
  673. Text param("\x2");
  674. param.appendHex((char)tm->current.fontSize);
  675. result += param;
  676. last.fontSize = tm->current.fontSize;
  677. }
  678. if (last.fontColor != tm->current.fontColor && includeFormat)
  679. {
  680. Text param("\x3");
  681. param.appendHex(tm->current.fontColor);
  682. result += param;
  683. last.fontColor = tm->current.fontColor;
  684. }
  685. if (last.selectedColor != tm->current.selectedColor && includeFormat)
  686. {
  687. Text param("\x4");
  688. param.appendHex(tm->current.selectedColor);
  689. result += param;
  690. last.selectedColor = tm->current.selectedColor;
  691. }
  692. if (last.selectedBackcroundColor != tm->current.selectedBackcroundColor
  693. && includeFormat)
  694. {
  695. Text param("\x5");
  696. param.appendHex(tm->current.selectedBackcroundColor);
  697. result += param;
  698. last.selectedBackcroundColor = tm->current.selectedBackcroundColor;
  699. }
  700. if (last.underlined != tm->current.underlined && includeFormat)
  701. {
  702. char tmp[2] = {tm->current.underlined ? (char)1 : (char)7, 0};
  703. result += tmp;
  704. last.underlined = tm->current.underlined;
  705. }
  706. if (last.interactParam != tm->current.interactParam && includeFormat)
  707. {
  708. Text param("\x8");
  709. param.appendHex(tm->current.interactParam);
  710. result += param;
  711. last.interactParam = tm->current.interactParam;
  712. }
  713. if (last.rendererIndex != tm->current.rendererIndex && includeFormat)
  714. {
  715. Text param("\x6");
  716. param.appendHex((char)tm->current.rendererIndex);
  717. result += param;
  718. last.rendererIndex = tm->current.rendererIndex;
  719. }
  720. if (txt[i] == ' ')
  721. {
  722. lastPos = i;
  723. lastPos2 = result.getLength();
  724. x += tm->zCurrentRenderer()->getTextBreite(" ");
  725. result += " ";
  726. tm->nextStyle();
  727. continue;
  728. }
  729. if (txt[i] == '\t')
  730. {
  731. lastPos = i;
  732. lastPos2 = result.getLength();
  733. x += tm->zCurrentRenderer()->getTextBreite("\t");
  734. result += "\t";
  735. tm->nextStyle();
  736. continue;
  737. }
  738. if (txt[i] == '\n')
  739. {
  740. x = 0;
  741. lastPos = -1;
  742. lastPos2 = -1;
  743. result += "\n";
  744. tm->nextStyle();
  745. continue;
  746. }
  747. char buff[2] = {txt[i], 0};
  748. x += tm->zCurrentRenderer()->getTextBreite(buff);
  749. result += buff;
  750. if (x > maxBr && lastPos > -1)
  751. {
  752. result.remove(lastPos2, result.getLength());
  753. result += "\n";
  754. result += spacing;
  755. x = tm->zCurrentRenderer()->getTextBreite(spacing);
  756. i = lastPos;
  757. tm->stepTo(lastPos);
  758. lastPos = -1;
  759. lastPos2 = -1;
  760. last = tm->currentStyle();
  761. }
  762. tm->nextStyle();
  763. }
  764. return result;
  765. }
  766. void TextField::setAutoLineBreakSpacing(const char* spacing)
  767. {
  768. if (!autoLineBreakSpacing) autoLineBreakSpacing = new Text();
  769. autoLineBreakSpacing->setText(spacing);
  770. }
  771. // Sets the style of a text section
  772. // begin: the start position of the section
  773. // end: the end position of the section (not included)
  774. void TextField::setTextStyle(int begin, int end, TextStyle style)
  775. {
  776. tm->setTextStyle(begin, end, style);
  777. }
  778. void TextField::addZeile(const char* zeile) // appends a line
  779. {
  780. if (tm->text)
  781. {
  782. Text* txt = new Text(zeile);
  783. if (zeile[txt->getLength() - 1] != '\n') txt->append("\n");
  784. TextRenderer* r = tm->renderer->z(0);
  785. if (tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  786. .rendererIndex
  787. < tm->renderer->getEintragAnzahl())
  788. r = tm->renderer->z(
  789. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  790. .rendererIndex);
  791. if (r)
  792. {
  793. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  794. int rbr = (rahmen && hatStyle(Style::Border)) ? rahmen->getRBreite()
  795. : 0;
  796. r->setSchriftSize(
  797. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  798. .fontSize);
  799. r->textFormatieren(txt, gr.x - ((int)vs * 15) - rbr * 2);
  800. }
  801. lockDrawable();
  802. tm->text->append(txt->getText());
  803. unlockDrawable();
  804. txt->release();
  805. if (hatStyle(Style::VScroll)) updateVScroll();
  806. if (hatStyle(Style::HScroll)) updateHScroll();
  807. rend = 1;
  808. }
  809. }
  810. // Appends a line to the text
  811. // zeile: The new line
  812. // color: The color of the line
  813. void TextField::addZeile(const char* zeile, int color)
  814. {
  815. if (tm->text)
  816. {
  817. Text* txt = new Text(zeile);
  818. if (zeile[txt->getLength() - 1] != '\n') txt->append("\n");
  819. TextRenderer* r = tm->renderer->z(0);
  820. if (tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  821. .rendererIndex
  822. < tm->renderer->getEintragAnzahl())
  823. r = tm->renderer->z(
  824. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  825. .rendererIndex);
  826. if (r)
  827. {
  828. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  829. int rbr = (rahmen && hatStyle(Style::Border)) ? rahmen->getRBreite()
  830. : 0;
  831. r->setSchriftSize(
  832. tm->textStyle.get(tm->textStyle.getEintragAnzahl() - 1)
  833. .fontSize);
  834. r->textFormatieren(txt, gr.x - ((int)vs * 15) - rbr * 2);
  835. }
  836. lockDrawable();
  837. tm->text->append(txt->getText());
  838. setSchriftFarbe(tm->text->getLength() - txt->getLength(),
  839. tm->text->getLength(),
  840. color);
  841. unlockDrawable();
  842. txt->release();
  843. if (hatStyle(Style::VScroll)) updateVScroll();
  844. if (hatStyle(Style::HScroll)) updateHScroll();
  845. rend = 1;
  846. }
  847. }
  848. // Deselects all text sections
  849. void TextField::deselectAuswahl()
  850. {
  851. for (int i = 0; i < tm->textStyle.getEintragAnzahl(); i++)
  852. {
  853. TextStyle s = tm->textStyle.get(i);
  854. if (s.selected)
  855. {
  856. s.selected = 0;
  857. tm->textStyle.set(s, i);
  858. }
  859. }
  860. tm->cleanupStyles();
  861. }
  862. void TextField::setAuswahl(int pos1, int pos2) // sets the selected text
  863. {
  864. deselectAuswahl();
  865. TextStyle s = tm->getTextStyle(pos1);
  866. s.selected = 1;
  867. tm->setTextStyle(pos1, pos2, s);
  868. }
  869. void TextField::setAuswahl(Punkt& auswahl)
  870. {
  871. deselectAuswahl();
  872. TextStyle s = tm->getTextStyle(auswahl.x);
  873. s.selected = 1;
  874. tm->setTextStyle(auswahl.x, auswahl.y, s);
  875. rend = 1;
  876. }
  877. void TextField::addAuswahl(int pos1, int pos2)
  878. {
  879. TextStyle s = tm->getTextStyle(pos1);
  880. s.selected = 1;
  881. tm->setTextStyle(pos1, pos2, s);
  882. }
  883. void TextField::addAuswahl(Punkt& auswahl)
  884. {
  885. TextStyle s = tm->getTextStyle(auswahl.x);
  886. s.selected = 1;
  887. tm->setTextStyle(auswahl.x, auswahl.y, s);
  888. rend = 1;
  889. }
  890. // Sets the selected text section
  891. // begin: The cursor position in the text
  892. // end: The position in the text up to which the text should be colored
  893. void TextField::invertAuswahl(int begin, int end)
  894. {
  895. for (int i = begin; i < end; i++)
  896. {
  897. TextStyle s = tm->getTextStyle(i);
  898. s.selected = !s.selected;
  899. tm->setTextStyle(i, i + 1, s);
  900. rend = 1;
  901. }
  902. }
  903. // replaces all selected text sections with a text
  904. // text: the new text
  905. void TextField::replaceAuswahl(const char* text)
  906. {
  907. tm->cleanupStyles();
  908. int sa = tm->textStyle.getEintragAnzahl();
  909. int last = tm->text->getLength();
  910. int si = 0;
  911. for (int i = sa - 1; i >= 0; i--)
  912. {
  913. TextStyle s = tm->textStyle.get(i);
  914. si = i;
  915. if (s.selected)
  916. {
  917. if ((i > 0 && !tm->textStyle.get(i - 1).selected) || i == 0)
  918. {
  919. s.selected = false;
  920. tm->textStyle.set(s, si);
  921. tm->removeText(s.beginIndex, last);
  922. tm->insertText(s.beginIndex, text);
  923. }
  924. }
  925. else
  926. last = s.beginIndex;
  927. }
  928. }
  929. void TextField::setTextRendererZ(TextRenderer* textRd)
  930. {
  931. if (tm->renderer)
  932. tm->renderer->leeren();
  933. else
  934. tm->renderer = new RCArray<TextRenderer>();
  935. tm->renderer->add(textRd);
  936. rend = 1;
  937. }
  938. // Adds a TextRenderer
  939. // textRd: The text renderer
  940. void TextField::addTextRendererZ(TextRenderer* textRd)
  941. {
  942. if (!tm->renderer) tm->renderer = new RCArray<TextRenderer>();
  943. tm->renderer->add(textRd);
  944. }
  945. // Sets the used TextRenderers
  946. // textRd: The text renderers
  947. void TextField::setTextRendererZ(RCArray<TextRenderer>* textRd)
  948. {
  949. if (tm->renderer) tm->renderer->release();
  950. tm->renderer = textRd;
  951. }
  952. void TextField::setFontZ(Font* schrift) // sets a pointer to the font
  953. {
  954. if (!tm->renderer) tm->renderer = new RCArray<TextRenderer>();
  955. if (!tm->renderer->getEintragAnzahl())
  956. tm->renderer->add(new TextRenderer(schrift));
  957. else
  958. tm->renderer->z(0)->setFontZ(schrift);
  959. rend = 1;
  960. }
  961. // Sets a pointer to the font
  962. // rendererIndex: The index of the renderer whose font should be set
  963. // schrift: The font to be used for text drawing.
  964. void TextField::setFontZ(int rendererIndex, Font* schrift)
  965. {
  966. if (!tm->renderer) tm->renderer = new RCArray<TextRenderer>();
  967. if (tm->renderer->getEintragAnzahl() <= rendererIndex)
  968. tm->renderer->add(new TextRenderer(schrift), rendererIndex);
  969. else
  970. tm->renderer->z(rendererIndex)->setFontZ(schrift);
  971. }
  972. void TextField::setSchriftSize(unsigned char gr) // sets the font size
  973. {
  974. TextStyle s = tm->textStyle.get(0);
  975. s.fontSize = gr;
  976. tm->textStyle.set(s, 0);
  977. rend = 1;
  978. }
  979. // Sets the font size (default: 12)
  980. // begin: The index of the first affected character
  981. // end: The index of the first unaffected character
  982. // gr: The font size to be used for text drawing
  983. void TextField::setSchriftSize(int begin, int end, unsigned char gr)
  984. {
  985. TextStyle s = tm->getTextStyle(begin);
  986. s.fontSize = gr;
  987. tm->setTextStyle(begin, end, s);
  988. rend = 1;
  989. }
  990. void TextField::setSchriftFarbe(int fc) // sets the font color
  991. {
  992. TextStyle s = tm->textStyle.get(0);
  993. s.fontColor = fc;
  994. tm->textStyle.set(s, 0);
  995. rend = 1;
  996. }
  997. // Sets the font color
  998. // begin: The index of the first affected character
  999. // end: The index of the first unaffected character
  1000. // fc: The color to be used for text drawing
  1001. void TextField::setSchriftFarbe(int begin, int end, int fc)
  1002. {
  1003. TextStyle s = tm->getTextStyle(begin);
  1004. s.fontColor = fc;
  1005. tm->setTextStyle(begin, end, s);
  1006. rend = 1;
  1007. }
  1008. void TextField::setSchowChar(unsigned char c) // for password field *
  1009. {
  1010. showChar = c;
  1011. rend = 1;
  1012. }
  1013. void TextField::setVScrollZuZeile(int zeile) // scrolls to line
  1014. {
  1015. if (vertikalScrollBar && tm->renderer && tm->renderer->getEintragAnzahl()
  1016. && tm->text && hatStyle(Style::Mehrzeilig))
  1017. {
  1018. lockDrawable();
  1019. tm->resetIteration();
  1020. int len = tm->text->getLength();
  1021. int y = 0;
  1022. int lnum = 0;
  1023. const char* text = tm->text->getText();
  1024. Text txtWithLineBreaks;
  1025. if (hatStyle(Style::AutoLineBreak))
  1026. {
  1027. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1028. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  1029. text = txtWithLineBreaks;
  1030. len = txtWithLineBreaks.getLength();
  1031. }
  1032. int max = 0;
  1033. for (int i = 0; i < len && lnum < zeile; i++)
  1034. {
  1035. if (text[i] == '\n')
  1036. {
  1037. lnum++;
  1038. y += max;
  1039. max = 0;
  1040. tm->nextStyle();
  1041. continue;
  1042. }
  1043. TextRenderer* r = tm->zCurrentRenderer();
  1044. if (r)
  1045. {
  1046. int tmp = r->getZeilenAbstand() + r->getZeilenHeight();
  1047. max = max >= tmp ? max : tmp;
  1048. }
  1049. tm->nextStyle();
  1050. }
  1051. unlockDrawable();
  1052. vertikalScrollBar->scroll(y);
  1053. rend = 1;
  1054. }
  1055. }
  1056. void TextField::updateVScroll(int pos) // scrolls down
  1057. {
  1058. if (pos == -1) pos = cpos;
  1059. if (vertikalScrollBar)
  1060. {
  1061. int sPos = 0;
  1062. int hi = 0;
  1063. int sPosZH = 0;
  1064. if (tm->text && tm->renderer)
  1065. {
  1066. if (hatStyleNicht(Style::Mehrzeilig)) tm->text->remove('\n');
  1067. hi = gr.y;
  1068. if (hatStyle(Style::Border) && rahmen)
  1069. hi -= rahmen->getRBreite() * 2;
  1070. if (hatStyle(Style::HScroll) && horizontalScrollBar) hi -= 15;
  1071. int th = 0;
  1072. lockDrawable();
  1073. tm->resetIteration();
  1074. int len = tm->text->getLength();
  1075. const char* text = tm->text->getText();
  1076. Text txtWithLineBreaks;
  1077. if (hatStyle(Style::AutoLineBreak))
  1078. {
  1079. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1080. autoLineBreakSpacing ? autoLineBreakSpacing->getText()
  1081. : "");
  1082. text = txtWithLineBreaks;
  1083. len = txtWithLineBreaks.getLength();
  1084. }
  1085. int max = 0;
  1086. int lastMax = 0;
  1087. for (int i = 0; i < len; i++)
  1088. {
  1089. if (text[i] == '\n')
  1090. {
  1091. if (i <= pos)
  1092. {
  1093. sPos += max;
  1094. sPosZH = max;
  1095. }
  1096. th += max;
  1097. lastMax = max;
  1098. max = 0;
  1099. tm->nextStyle();
  1100. continue;
  1101. }
  1102. TextRenderer* r = tm->zCurrentRenderer();
  1103. if (r)
  1104. {
  1105. int tmp = r->getZeilenAbstand() + r->getZeilenHeight();
  1106. max = max >= tmp ? max : tmp;
  1107. }
  1108. tm->nextStyle();
  1109. }
  1110. if (max != lastMax && max > 0)
  1111. {
  1112. th += max;
  1113. lastMax = max;
  1114. }
  1115. th += lastMax;
  1116. unlockDrawable();
  1117. vertikalScrollBar->update(th, hi);
  1118. }
  1119. if (sPos - sPosZH < vertikalScrollBar->getScroll())
  1120. vertikalScrollBar->scroll(sPos - sPosZH);
  1121. if (sPos + sPosZH > vertikalScrollBar->getScroll()
  1122. + vertikalScrollBar->getScrollData()->anzeige)
  1123. vertikalScrollBar->scroll(sPos + sPosZH * 2 - hi);
  1124. rend = 1;
  1125. }
  1126. }
  1127. void TextField::updateHScroll(int pos) // scrolls to cursor position
  1128. {
  1129. if (pos == -1) pos = cpos;
  1130. lockDrawable();
  1131. if (horizontalScrollBar && tm->text && tm->renderer)
  1132. {
  1133. if (hatStyleNicht(Style::Mehrzeilig)) tm->text->remove('\n');
  1134. int br = gr.x;
  1135. if (hatStyle(Style::Border) && rahmen) br -= rahmen->getRBreite() * 2;
  1136. if (hatStyle(Style::VScroll) && vertikalScrollBar) br -= 15;
  1137. tm->resetIteration();
  1138. int maxBr = 0;
  1139. int len = tm->text->getLength();
  1140. const char* text = tm->text->getText();
  1141. int lineBr = 0;
  1142. char buff[] = {0, 0};
  1143. int cbr = 0;
  1144. for (int i = 0; i < len; i++)
  1145. {
  1146. buff[0] = text[i];
  1147. if (text[i] == '\n')
  1148. {
  1149. maxBr = maxBr >= lineBr ? maxBr : lineBr;
  1150. lineBr = 0;
  1151. tm->nextStyle();
  1152. continue;
  1153. }
  1154. TextRenderer* r = tm->zCurrentRenderer();
  1155. if (r)
  1156. {
  1157. lineBr += r->getTextBreite(buff);
  1158. if (i <= pos) cbr = lineBr;
  1159. }
  1160. tm->nextStyle();
  1161. }
  1162. maxBr = maxBr >= lineBr ? maxBr : lineBr;
  1163. horizontalScrollBar->update(maxBr, br);
  1164. if (cbr > horizontalScrollBar->getScroll()
  1165. + horizontalScrollBar->getScrollData()->anzeige)
  1166. horizontalScrollBar->scroll(cbr - br);
  1167. if (cbr < horizontalScrollBar->getScroll())
  1168. horizontalScrollBar->scroll(cbr);
  1169. }
  1170. unlockDrawable();
  1171. }
  1172. // Returns the width in pixels needed to fully display the current text with
  1173. // the current styles
  1174. int TextField::getNeededWidth()
  1175. {
  1176. int maxBr = 0;
  1177. lockDrawable();
  1178. if (tm->text && tm->renderer) maxBr = getTextWidth();
  1179. unlockDrawable();
  1180. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1181. bool r = rahmen && hatStyle(Style::Border);
  1182. return maxBr + (r ? rahmen->getRBreite() * 2 : 0) + (vs ? 15 : 0);
  1183. }
  1184. // Returns the height in pixels needed to fully display the current text with
  1185. // the current styles
  1186. int TextField::getNeededHeight()
  1187. {
  1188. int th = 0;
  1189. lockDrawable();
  1190. if (tm->text && tm->renderer) th = getTextHeight();
  1191. unlockDrawable();
  1192. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1193. bool r = rahmen && hatStyle(Style::Border);
  1194. return th + (r ? rahmen->getRBreite() * 2 : 0) + (hs ? 15 : 0);
  1195. }
  1196. bool TextField::tick(double tickval) // tick
  1197. {
  1198. if (hatStyle(Style::Fokus))
  1199. {
  1200. if (tickVal < 0.5 && tickVal + tickval >= 0.5) rend = 1;
  1201. if (tickVal >= 0.5 && tickVal + tickval >= 1) rend = 1;
  1202. tickVal += tickval;
  1203. if (tickVal >= 1) tickVal -= 1;
  1204. }
  1205. return DrawableBackground::tick(tickval);
  1206. }
  1207. void TextField::doTastaturEreignis(TastaturEreignis& te)
  1208. {
  1209. bool ntakc = !te.verarbeitet;
  1210. if (te.verarbeitet || hatStyleNicht(Style::Fokus)) return;
  1211. if (!tak) return;
  1212. getThis();
  1213. if (tak(takParam, this, te))
  1214. {
  1215. if (hatStyleNicht(Style::Editierbar))
  1216. {
  1217. release();
  1218. return;
  1219. }
  1220. if (te.id == TE_Press)
  1221. {
  1222. bool shift = getTastenStand(T_Shift);
  1223. bool strg = getTastenStand(T_Strg);
  1224. switch (te.virtualKey)
  1225. {
  1226. case T_Entf:
  1227. if (!tm->getTextStyle(cpos).selected)
  1228. tm->removeText(cpos, cpos + 1);
  1229. else
  1230. {
  1231. cpos = tm->getTextStyle(cpos).beginIndex;
  1232. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1233. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1234. }
  1235. replaceAuswahl("");
  1236. deselectAuswahl();
  1237. rend = 1;
  1238. break;
  1239. case T_BackSpace:
  1240. if (!tm->getTextStyle(cpos).selected)
  1241. {
  1242. tm->removeText(cpos - 1, cpos);
  1243. cpos--;
  1244. }
  1245. else
  1246. {
  1247. cpos = tm->getTextStyle(cpos).beginIndex;
  1248. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1249. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1250. }
  1251. replaceAuswahl("");
  1252. deselectAuswahl();
  1253. rend = 1;
  1254. break;
  1255. case T_Enter:
  1256. if (hatStyle(TextField::Style::Mehrzeilig))
  1257. {
  1258. if (!tm->getTextStyle(cpos).selected)
  1259. tm->insertText(cpos, "\n");
  1260. else
  1261. {
  1262. cpos = tm->getTextStyle(cpos).beginIndex;
  1263. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1264. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1265. }
  1266. replaceAuswahl("\n");
  1267. ++cpos;
  1268. rend = 1;
  1269. }
  1270. break;
  1271. case T_Links:
  1272. if (shift)
  1273. {
  1274. if (strg)
  1275. {
  1276. int tmp = tm->text->getLKick(cpos);
  1277. invertAuswahl(tmp, cpos);
  1278. cpos = tmp;
  1279. }
  1280. else
  1281. {
  1282. invertAuswahl(cpos - 1, cpos);
  1283. --cpos;
  1284. }
  1285. }
  1286. else
  1287. {
  1288. if (strg)
  1289. cpos = tm->text->getLKick(cpos);
  1290. else
  1291. --cpos;
  1292. deselectAuswahl();
  1293. }
  1294. rend = 1;
  1295. break;
  1296. case T_Oben:
  1297. {
  1298. int tmp = tm->text->getOKick(cpos);
  1299. invertAuswahl(tmp, cpos);
  1300. cpos = tmp;
  1301. if (!shift) deselectAuswahl();
  1302. rend = 1;
  1303. break;
  1304. }
  1305. case T_Rechts:
  1306. if (shift)
  1307. {
  1308. if (strg)
  1309. {
  1310. int tmp = tm->text->getRKick(cpos);
  1311. invertAuswahl(cpos, tmp);
  1312. cpos = tmp;
  1313. }
  1314. else
  1315. {
  1316. invertAuswahl(cpos, cpos + 1);
  1317. ++cpos;
  1318. }
  1319. }
  1320. else
  1321. {
  1322. if (strg)
  1323. cpos = tm->text->getRKick(cpos);
  1324. else
  1325. ++cpos;
  1326. deselectAuswahl();
  1327. }
  1328. rend = 1;
  1329. break;
  1330. case T_Unten:
  1331. {
  1332. int tmp = tm->text->getUKick(cpos);
  1333. invertAuswahl(cpos, tmp);
  1334. cpos = tmp;
  1335. if (!shift) deselectAuswahl();
  1336. rend = 1;
  1337. break;
  1338. }
  1339. default:
  1340. if (strg && te.id == TE_Press)
  1341. {
  1342. if (te.virtualKey == 'c' || te.virtualKey == 'C')
  1343. {
  1344. int sa = tm->textStyle.getEintragAnzahl();
  1345. int length = 0;
  1346. for (int i = 0; i < sa; i++)
  1347. {
  1348. TextStyle s = tm->textStyle.get(i);
  1349. if (s.selected)
  1350. {
  1351. int max = tm->text->getLength();
  1352. if (i < sa - 1)
  1353. max = tm->textStyle.get(i + 1).beginIndex;
  1354. length += max - s.beginIndex;
  1355. }
  1356. }
  1357. if (length)
  1358. {
  1359. char* txt = new char[length + 1];
  1360. txt[length] = 0;
  1361. int index = 0;
  1362. for (int i = 0; i < sa; i++)
  1363. {
  1364. TextStyle s = tm->textStyle.get(i);
  1365. if (s.selected)
  1366. {
  1367. int max = tm->text->getLength();
  1368. if (i < sa - 1)
  1369. max = tm->textStyle.get(i + 1)
  1370. .beginIndex;
  1371. memcpy(txt + index,
  1372. tm->text->getText() + s.beginIndex,
  1373. max - s.beginIndex);
  1374. index += max - s.beginIndex;
  1375. }
  1376. }
  1377. TextKopieren(txt);
  1378. delete[] txt;
  1379. }
  1380. else
  1381. TextKopieren(tm->text->getText());
  1382. }
  1383. if (te.virtualKey == 'v' || te.virtualKey == 'V')
  1384. {
  1385. const char* txt = TextInsert();
  1386. if (!tm->getTextStyle(cpos).selected)
  1387. tm->insertText(cpos, txt);
  1388. else
  1389. {
  1390. cpos = tm->getTextStyle(cpos).beginIndex;
  1391. while (
  1392. cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1393. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1394. }
  1395. replaceAuswahl(txt);
  1396. cpos += textLength(txt);
  1397. rend = 1;
  1398. }
  1399. break;
  1400. }
  1401. if (istSchreibbar(te.taste[0]))
  1402. {
  1403. if (!tm->getTextStyle(cpos).selected)
  1404. tm->insertText(cpos, te.taste);
  1405. else
  1406. {
  1407. cpos = tm->getTextStyle(cpos).beginIndex;
  1408. while (cpos > 0 && tm->getTextStyle(cpos - 1).selected)
  1409. cpos = tm->getTextStyle(cpos - 1).beginIndex;
  1410. }
  1411. replaceAuswahl(te.taste);
  1412. ++cpos;
  1413. rend = 1;
  1414. }
  1415. break;
  1416. }
  1417. }
  1418. if (cpos < 0) cpos = 0;
  1419. if (cpos > tm->text->getLength()) cpos = tm->text->getLength();
  1420. if (hatStyle(Style::VScroll)) updateVScroll(cpos);
  1421. if (hatStyle(Style::HScroll)) updateHScroll(cpos);
  1422. te.verarbeitet = 1;
  1423. }
  1424. if (ntakc && te.verarbeitet && nTak)
  1425. te.verarbeitet = nTak(ntakParam, this, te);
  1426. release();
  1427. }
  1428. void TextField::render(Image& zRObj) // draws to zRObj
  1429. {
  1430. if (hatStyleNicht(Style::Sichtbar)) return;
  1431. DrawableBackground::render(zRObj);
  1432. if (!tm->text || !tm->renderer) return;
  1433. lockDrawable();
  1434. if (!zRObj.setDrawOptions(innenPosition, innenSize))
  1435. {
  1436. unlockDrawable();
  1437. return;
  1438. }
  1439. if (hatStyleNicht(Style::Mehrzeilig)) tm->text->remove('\n');
  1440. int tbr = getTextWidth();
  1441. int thi = getTextHeight();
  1442. int xxx = 0;
  1443. int yyy = 0;
  1444. int breite = innenSize.x;
  1445. int height = innenSize.y;
  1446. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1447. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1448. if (vs) yyy -= vertikalScrollBar->getScroll();
  1449. if (hs) xxx -= horizontalScrollBar->getScroll();
  1450. if (hatStyle(Style::HCenter) && !hs) xxx = (breite / 2) - tbr / 2;
  1451. int x = xxx;
  1452. int len = tm->text->getLength();
  1453. const char* text = tm->text->getText();
  1454. Text txtWithLineBreaks;
  1455. if (hatStyle(Style::AutoLineBreak))
  1456. {
  1457. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1458. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "",
  1459. 0);
  1460. text = txtWithLineBreaks;
  1461. len = txtWithLineBreaks.getLength();
  1462. }
  1463. lockDrawable();
  1464. tm->resetIteration();
  1465. if (thi == 0)
  1466. {
  1467. thi = tm->zCurrentRenderer()->getZeilenHeight();
  1468. }
  1469. if (hatStyle(Style::VCenter) && !vs) yyy = (height / 2) - thi / 2;
  1470. int y = yyy;
  1471. TextStyle& style = tm->currentStyle();
  1472. int maxLH = 0;
  1473. int corrector = 0;
  1474. int realLen = tm->text->getLength();
  1475. for (int i = 0; i <= len; i++)
  1476. {
  1477. int oldX = x;
  1478. if (i < len && tm->zCurrentRenderer())
  1479. tm->zCurrentRenderer()->renderChar(x,
  1480. y,
  1481. istSchreibbar(showChar) ? showChar : text[i],
  1482. zRObj,
  1483. style.selected ? style.selectedColor : style.fontColor,
  1484. style.underlined,
  1485. style.selected,
  1486. style.selectedBackcroundColor);
  1487. if (i - corrector == cpos && tickVal <= 0.5 && hatStyle(Style::Fokus)
  1488. && hatStyle(Style::Editierbar) && tm->zCurrentRenderer())
  1489. zRObj.drawLinieV(
  1490. oldX, y, tm->zCurrentRenderer()->getZeilenHeight(), 0xFFFF5555);
  1491. if (i >= realLen || text[i] != tm->text->getText()[i])
  1492. {
  1493. corrector++;
  1494. }
  1495. if (tm->zCurrentRenderer())
  1496. {
  1497. int tmp = tm->zCurrentRenderer()->getZeilenHeight()
  1498. + tm->zCurrentRenderer()->getZeilenAbstand();
  1499. maxLH = tmp > maxLH ? tmp : maxLH;
  1500. }
  1501. if (i < len && text[i] == '\n')
  1502. {
  1503. x = xxx;
  1504. y += maxLH;
  1505. }
  1506. tm->nextStyle();
  1507. }
  1508. unlockDrawable();
  1509. zRObj.releaseDrawOptions();
  1510. unlockDrawable();
  1511. }
  1512. // Constant
  1513. Text* TextField::getText() const // returns the text
  1514. {
  1515. if (!tm->text) return 0;
  1516. return dynamic_cast<Text*>(tm->text->getThis());
  1517. }
  1518. Text* TextField::zText() const // returns the text without reference counter
  1519. {
  1520. return tm->text;
  1521. }
  1522. Font* TextField::getFont() const // returns the font
  1523. {
  1524. tm->resetIteration();
  1525. return tm->zCurrentRenderer() ? tm->zCurrentRenderer()->getFont() : 0;
  1526. }
  1527. Font*
  1528. TextField::zFont() const // returns the font without reference counter
  1529. {
  1530. tm->resetIteration();
  1531. return tm->zCurrentRenderer() ? tm->zCurrentRenderer()->zFont() : 0;
  1532. }
  1533. // Returns the font.
  1534. // rendererIndex: The index of the renderer whose font should be returned
  1535. // return: 0, if the font was not set
  1536. Font* TextField::getFont(int rendererIndex) const
  1537. {
  1538. if (tm->renderer && tm->renderer->z(rendererIndex))
  1539. return tm->renderer->z(rendererIndex)->getFont();
  1540. return 0;
  1541. }
  1542. // Returns the font without increased reference counter
  1543. // rendererIndex: The index of the renderer whose font should be returned
  1544. // return: 0, if the font was not set
  1545. Font* TextField::zFont(int rendererIndex) const
  1546. {
  1547. if (tm->renderer && tm->renderer->z(rendererIndex))
  1548. return tm->renderer->z(rendererIndex)->zFont();
  1549. return 0;
  1550. }
  1551. TextRenderer* TextField::getTextRenderer() const
  1552. {
  1553. tm->resetIteration();
  1554. return dynamic_cast<TextRenderer*>(tm->zCurrentRenderer()->getThis());
  1555. }
  1556. TextRenderer* TextField::zTextRenderer() const
  1557. {
  1558. tm->resetIteration();
  1559. return tm->zCurrentRenderer();
  1560. }
  1561. // Returns the TextRenderer.
  1562. // index: The index of the renderer to be returned
  1563. // return: 0, if the TextRenderer was not set
  1564. TextRenderer* TextField::getTextRenderer(int index) const
  1565. {
  1566. if (tm->renderer && tm->renderer->z(index)) return tm->renderer->get(index);
  1567. return 0;
  1568. }
  1569. // Returns the TextRenderer without increased reference counter
  1570. // index: The index of the renderer to be returned
  1571. // return: 0, if the TextRenderer was not set
  1572. TextRenderer* TextField::zTextRenderer(int index) const
  1573. {
  1574. if (tm->renderer && tm->renderer->z(index)) return tm->renderer->z(index);
  1575. return 0;
  1576. }
  1577. unsigned char TextField::getSchriftSize() const // returns the font size
  1578. {
  1579. tm->resetIteration();
  1580. return tm->current.fontSize;
  1581. }
  1582. // Returns the font size
  1583. // index: The index of the character
  1584. unsigned char TextField::getSchriftSize(int index) const
  1585. {
  1586. tm->resetIteration();
  1587. return tm->current.fontSize;
  1588. }
  1589. int TextField::getSchriftFarbe() const // returns the font color
  1590. {
  1591. tm->resetIteration();
  1592. return tm->current.fontColor;
  1593. }
  1594. // Returns the font color in A8R8G8B8 format
  1595. // index: The index of the character
  1596. int TextField::getSchriftFarbe(int index) const
  1597. {
  1598. return tm->getTextStyle(index).fontColor;
  1599. }
  1600. unsigned char TextField::getShowChar() const // returns the display character
  1601. {
  1602. return showChar;
  1603. }
  1604. int TextField::getCursorPos() const
  1605. {
  1606. return cpos;
  1607. }
  1608. // Returns 1 if the character is selected
  1609. // index: The index of the character
  1610. bool TextField::isCharSelected(int index) const
  1611. {
  1612. return tm->getTextStyle(index).selected;
  1613. }
  1614. // Returns the index of the character located under the mouse
  1615. // mx: the x position of the mouse relative to the text field position
  1616. // my: the y position of the mouse relative to the text field position
  1617. // return: -1, if no character is at the position
  1618. int TextField::getTextIndexAt(int mx, int my) const
  1619. {
  1620. if (!tm || !tm->text || !tm->zCurrentRenderer()) return -1;
  1621. int tbr = getTextWidth();
  1622. int thi = getTextHeight();
  1623. int xxx = 0;
  1624. int yyy = 0;
  1625. int breite = innenSize.x;
  1626. int height = innenSize.y;
  1627. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1628. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1629. if (vs) yyy -= vertikalScrollBar->getScroll();
  1630. if (hs) xxx -= horizontalScrollBar->getScroll();
  1631. if (hatStyle(Style::HCenter) && !hs) xxx = (breite / 2) - tbr / 2;
  1632. if (hatStyle(Style::VCenter) && !vs) yyy = (height / 2) - thi / 2;
  1633. int x = xxx;
  1634. int y = yyy;
  1635. int len = tm->text->getLength();
  1636. const char* text = tm->text->getText();
  1637. Text txtWithLineBreaks;
  1638. if (hatStyle(Style::AutoLineBreak))
  1639. {
  1640. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1641. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  1642. text = txtWithLineBreaks;
  1643. len = txtWithLineBreaks.getLength();
  1644. }
  1645. tm->resetIteration();
  1646. int corrector = 0;
  1647. int maxLH = 0;
  1648. int realLen = tm->text->getLength();
  1649. for (int i = 0; i < len; i++)
  1650. {
  1651. if (i >= realLen || text[i] != tm->text->getText()[i])
  1652. {
  1653. corrector++;
  1654. }
  1655. char buff[2] = {istSchreibbar(showChar) ? (char)showChar : text[i], 0};
  1656. int tmpx = tm->zCurrentRenderer()->getTextBreite(buff);
  1657. int tmpy = tm->zCurrentRenderer()->getZeilenHeight();
  1658. if (mx >= x && mx < x + tmpx && my >= y && my < y + tmpy)
  1659. return i - corrector;
  1660. if (mx < x + tmpx && my < y + tmpy) return -1;
  1661. x += tmpx;
  1662. tmpy += tm->zCurrentRenderer()->getZeilenAbstand();
  1663. maxLH = tmpy > maxLH ? tmpy : maxLH;
  1664. if (text[i] == '\n')
  1665. {
  1666. x = xxx;
  1667. y += maxLH;
  1668. }
  1669. tm->nextStyle();
  1670. }
  1671. return -1;
  1672. }
  1673. // Returns the index of the character before which the cursor is placed when
  1674. // the mouse is clicked
  1675. // mx: the x position of the mouse relative to the text field position
  1676. // my: the y position of the mouse relative to the text field position
  1677. int TextField::getCurserPosAt(int mx, int my) const
  1678. {
  1679. if (!tm || !tm->text || !tm->zCurrentRenderer())
  1680. return tm->text->getLength();
  1681. int tbr = getTextWidth();
  1682. int thi = getTextHeight();
  1683. int xxx = 0;
  1684. int yyy = 0;
  1685. int breite = innenSize.x;
  1686. int height = innenSize.y;
  1687. bool hs = horizontalScrollBar && hatStyle(Style::HScroll);
  1688. bool vs = vertikalScrollBar && hatStyle(Style::VScroll);
  1689. if (vs) yyy -= vertikalScrollBar->getScroll();
  1690. if (hs) xxx -= horizontalScrollBar->getScroll();
  1691. if (hatStyle(Style::HCenter) && !hs) xxx = (breite / 2) - tbr / 2;
  1692. if (hatStyle(Style::VCenter) && !vs) yyy = (height / 2) - thi / 2;
  1693. int x = xxx;
  1694. int y = yyy;
  1695. int len = tm->text->getLength();
  1696. const char* text = tm->text->getText();
  1697. Text txtWithLineBreaks;
  1698. if (hatStyle(Style::AutoLineBreak))
  1699. {
  1700. txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
  1701. autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
  1702. text = txtWithLineBreaks;
  1703. len = txtWithLineBreaks.getLength();
  1704. }
  1705. tm->resetIteration();
  1706. int maxLH = 0;
  1707. int realLen = tm->text->getLength();
  1708. int corrector = 0;
  1709. for (int i = 0; i < len; i++)
  1710. {
  1711. if (i >= realLen || text[i] != tm->text->getText()[i])
  1712. {
  1713. corrector++;
  1714. }
  1715. int tmpx = tm->zCurrentRenderer()->getCharWidth(
  1716. istSchreibbar(showChar) ? showChar : text[i]);
  1717. int tmpy = tm->zCurrentRenderer()->getZeilenHeight()
  1718. + tm->zCurrentRenderer()->getZeilenAbstand();
  1719. if (mx < x + tmpx / 2
  1720. && my < y + tmpy - tm->zCurrentRenderer()->getZeilenAbstand() / 2)
  1721. return i - corrector;
  1722. x += tmpx + tm->zCurrentRenderer()->getZeichenAbstand();
  1723. maxLH = tmpy > maxLH ? tmpy : maxLH;
  1724. if (text[i] == '\n')
  1725. {
  1726. if (my >= y - tm->zCurrentRenderer()->getZeilenAbstand() / 2
  1727. && my < y + maxLH
  1728. - tm->zCurrentRenderer()->getZeilenAbstand() / 2)
  1729. return i - corrector;
  1730. x = xxx;
  1731. y += maxLH;
  1732. }
  1733. tm->nextStyle();
  1734. }
  1735. return tm->text->getLength();
  1736. }
  1737. // Returns the style of a specific character
  1738. // index: The index of the character
  1739. TextStyle TextField::getTextStyle(int index) const
  1740. {
  1741. return tm->getTextStyle(index);
  1742. }
  1743. // returns the string that is inserted after each line break when using
  1744. // the AutoLineBreak style
  1745. Text TextField::getAutoLineBreakSpacing() const
  1746. {
  1747. return autoLineBreakSpacing ? *autoLineBreakSpacing : Text("");
  1748. }
  1749. Drawable* TextField::dublizieren() const // Creates a copy of the drawing
  1750. {
  1751. TextField* obj = new TextField();
  1752. obj->setPosition(pos);
  1753. obj->setSize(gr);
  1754. obj->setMausEreignisParameter(makParam);
  1755. obj->setTastaturEreignisParameter(takParam);
  1756. obj->setMausEreignis(mak);
  1757. obj->setTastaturEreignis(tak);
  1758. if (toolTip) obj->setToolTipZ((ToolTip*)toolTip->dublizieren());
  1759. obj->setStyle(style);
  1760. obj->tm->renderer->release();
  1761. obj->tm->renderer
  1762. = dynamic_cast<RCArray<TextRenderer>*>(tm->renderer->getThis());
  1763. obj->tm->textStyle.leeren();
  1764. for (const auto& i : tm->textStyle)
  1765. obj->tm->textStyle.add(i);
  1766. obj->tm->index = tm->index;
  1767. obj->tm->styleIndex = tm->styleIndex;
  1768. obj->tm->current = tm->current;
  1769. if (tm->text) obj->setText(tm->text->getText());
  1770. obj->setHintergrundFarbe(hintergrundFarbe);
  1771. if (hintergrundFeld)
  1772. obj->setAlphaFeldZ((AlphaFeld*)hintergrundFeld->dublizieren());
  1773. if (rahmen) obj->setBorderZ((Border*)rahmen->dublizieren());
  1774. if (hintergrundImage)
  1775. obj->setHintergrundImage(
  1776. dynamic_cast<Image*>(hintergrundImage->getThis()));
  1777. if (vertikalScrollBar)
  1778. {
  1779. obj->setVertikalKlickScroll(vertikalScrollBar->getKlickScroll());
  1780. obj->setVertikalScrollPos(vertikalScrollBar->getScroll());
  1781. obj->setVertikalScrollFarbe(
  1782. vertikalScrollBar->getFarbe(), vertikalScrollBar->getBgFarbe());
  1783. }
  1784. if (horizontalScrollBar)
  1785. {
  1786. obj->setHorizontalKlickScroll(horizontalScrollBar->getKlickScroll());
  1787. obj->setHorizontalScrollPos(horizontalScrollBar->getScroll());
  1788. obj->setHorizontalScrollFarbe(
  1789. horizontalScrollBar->getFarbe(), horizontalScrollBar->getBgFarbe());
  1790. }
  1791. if (autoLineBreakSpacing)
  1792. {
  1793. obj->setAutoLineBreakSpacing(*autoLineBreakSpacing);
  1794. }
  1795. obj->setSchowChar(showChar);
  1796. return obj;
  1797. }