TextFeld.cpp 59 KB

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