TextFeld.cpp 47 KB

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