TextFeld.cpp 56 KB

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