TextFeld.cpp 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489
  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 = 0; 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. for( int i = sa - 1; i >= 0; i-- )
  439. {
  440. TextStyle s = tm->textStyle.get( i );
  441. if( s.selected )
  442. {
  443. if( ( i > 0 && !tm->textStyle.get( i - 1 ).selected ) || i == 0 )
  444. {
  445. tm->removeText( s.beginIndex, last );
  446. tm->insertText( s.beginIndex, text );
  447. }
  448. }
  449. else
  450. last = s.beginIndex;
  451. }
  452. }
  453. void TextFeld::setTextRendererZ( TextRenderer *textRd )
  454. {
  455. if( tm->renderer )
  456. tm->renderer->leeren();
  457. else
  458. tm->renderer = new RCArray< TextRenderer >();
  459. tm->renderer->add( textRd );
  460. rend = 1;
  461. }
  462. // Fügt einen TextRenderer hinzu
  463. // textRd: Der Textrenderer
  464. void TextFeld::addTextRendererZ( TextRenderer *textRd )
  465. {
  466. if( !tm->renderer )
  467. tm->renderer = new RCArray< TextRenderer >();
  468. tm->renderer->add( textRd );
  469. }
  470. // Setzt die verwendeten TextRenderer
  471. // textRd: Die Textrenderer
  472. void TextFeld::setTextRendererZ( RCArray< TextRenderer > *textRd )
  473. {
  474. if( tm->renderer )
  475. tm->renderer->release();
  476. tm->renderer = textRd;
  477. }
  478. void TextFeld::setSchriftZ( Schrift *schrift ) // setzt einen Zeiger zur Schrift
  479. {
  480. if( !tm->renderer )
  481. tm->renderer = new RCArray< TextRenderer >();
  482. if( !tm->renderer->getEintragAnzahl() )
  483. tm->renderer->add( new TextRenderer( schrift ) );
  484. else
  485. tm->renderer->z( 0 )->setSchriftZ( schrift );
  486. rend = 1;
  487. }
  488. // Setzt einen Zeiger zur Schrift
  489. // rendererIndex: Der Index des Renderers dessen Schrift gesetzt werden soll
  490. // schrift: Die Schrift, die zum Textzeichnen verwendet werden soll.
  491. void TextFeld::setSchriftZ( int rendererIndex, Schrift *schrift )
  492. {
  493. if( !tm->renderer )
  494. tm->renderer = new RCArray< TextRenderer >();
  495. if( tm->renderer->getEintragAnzahl() <= rendererIndex )
  496. tm->renderer->add( new TextRenderer( schrift ), rendererIndex );
  497. else
  498. tm->renderer->z( rendererIndex )->setSchriftZ( schrift );
  499. }
  500. void TextFeld::setSchriftSize( unsigned char gr ) // setzt die Schriftgröße
  501. {
  502. TextStyle s = tm->textStyle.get( 0 );
  503. s.fontSize = gr;
  504. tm->textStyle.set( s, 0 );
  505. rend = 1;
  506. }
  507. // Setzt die Schriftgröße (Standart: 12)
  508. // begin: Der Index des ersten betroffenen Zeichens
  509. // end: Der Index des ersten nicht betroffenen Zeichens
  510. // gr: Die Schriftgröße, die zum Textzeichnen verwendet werden soll
  511. void TextFeld::setSchriftSize( int begin, int end, unsigned char gr )
  512. {
  513. TextStyle s = tm->getTextStyle( begin );
  514. s.fontSize = gr;
  515. tm->setTextStyle( begin, end, s );
  516. rend = 1;
  517. }
  518. void TextFeld::setSchriftFarbe( int fc ) // setzt die Schrift Farbe
  519. {
  520. TextStyle s = tm->textStyle.get( 0 );
  521. s.fontColor = fc;
  522. tm->textStyle.set( s, 0 );
  523. rend = 1;
  524. }
  525. // Setzt die Schrift Farbe
  526. // begin: Der Index des ersten betroffenen Zeichens
  527. // end: Der Index des ersten nicht betroffenen Zeichens
  528. // fc: Die Farbe, die zum Textzeichnen verwendet werden soll
  529. void TextFeld::setSchriftFarbe( int begin, int end, int fc )
  530. {
  531. TextStyle s = tm->getTextStyle( begin );
  532. s.fontColor = fc;
  533. tm->setTextStyle( begin, end, s );
  534. rend = 1;
  535. }
  536. void TextFeld::setSchowChar( unsigned char c ) // bei Passwortfeld *
  537. {
  538. showChar = c;
  539. rend = 1;
  540. }
  541. void TextFeld::setVScrollZuZeile( int zeile ) // scrollt zur Zeile
  542. {
  543. if( vertikalScrollBar && tm->renderer && tm->renderer->getEintragAnzahl() && tm->text && hatStyle( Style::Mehrzeilig ) )
  544. {
  545. lockZeichnung();
  546. tm->resetIteration();
  547. int len = tm->text->getLength();
  548. int y = 0;
  549. int lnum = 0;
  550. char *text = tm->text->getText();
  551. int max = 0;
  552. for( int i = 0; i < len && lnum < zeile; i++ )
  553. {
  554. if( text[ i ] == '\n' )
  555. {
  556. lnum++;
  557. y += max;
  558. max = 0;
  559. tm->nextStyle();
  560. continue;
  561. }
  562. TextRenderer *r = tm->zCurrentRenderer();
  563. if( r )
  564. {
  565. int tmp = r->getZeilenabstand() + r->getZeilenHeight();
  566. max = max >= tmp ? max : tmp;
  567. }
  568. tm->nextStyle();
  569. }
  570. unlockZeichnung();
  571. vertikalScrollBar->scroll( y );
  572. rend = 1;
  573. }
  574. }
  575. void TextFeld::updateVScroll( int pos ) // scrollt nach unten
  576. {
  577. if( pos == -1 )
  578. pos = cpos;
  579. if( vertikalScrollBar )
  580. {
  581. int sPos = 0;
  582. int hi = 0;
  583. int sPosZH = 0;
  584. if( tm->text && tm->renderer )
  585. {
  586. if( hatStyleNicht( Style::Mehrzeilig ) )
  587. tm->text->remove( '\n' );
  588. hi = gr.y;
  589. if( hatStyle( Style::Rahmen ) && rahmen )
  590. hi -= rahmen->getRBreite() * 2;
  591. if( hatStyle( Style::HScroll ) && horizontalScrollBar )
  592. hi -= 15;
  593. int th = 0;
  594. lockZeichnung();
  595. tm->resetIteration();
  596. int len = tm->text->getLength();
  597. char *text = tm->text->getText();
  598. int max = 0;
  599. int lastMax = 0;
  600. for( int i = 0; i < len; i++ )
  601. {
  602. if( text[ i ] == '\n' )
  603. {
  604. if( i <= pos )
  605. {
  606. sPos += max;
  607. sPosZH = max;
  608. }
  609. th += max;
  610. lastMax = max;
  611. max = 0;
  612. tm->nextStyle();
  613. continue;
  614. }
  615. TextRenderer *r = tm->zCurrentRenderer();
  616. if( r )
  617. {
  618. int tmp = r->getZeilenabstand() + r->getZeilenHeight();
  619. max = max >= tmp ? max : tmp;
  620. }
  621. tm->nextStyle();
  622. }
  623. if( max != lastMax && max > 0 )
  624. {
  625. th += max;
  626. lastMax = max;
  627. }
  628. th += lastMax;
  629. unlockZeichnung();
  630. vertikalScrollBar->update( th, hi );
  631. }
  632. if( sPos - sPosZH < vertikalScrollBar->getScroll() )
  633. vertikalScrollBar->scroll( sPos - sPosZH );
  634. if( sPos + sPosZH > vertikalScrollBar->getScroll() + vertikalScrollBar->getScrollData()->anzeige )
  635. vertikalScrollBar->scroll( sPos + sPosZH * 2 - hi );
  636. rend = 1;
  637. }
  638. }
  639. void TextFeld::updateHScroll( int pos ) // scrollt zur Curser Position
  640. {
  641. if( pos == -1 )
  642. pos = cpos;
  643. if( horizontalScrollBar && tm->text && tm->renderer )
  644. {
  645. if( hatStyleNicht( Style::Mehrzeilig ) )
  646. tm->text->remove( '\n' );
  647. int br = gr.x;
  648. if( hatStyle( Style::Rahmen ) && rahmen )
  649. br -= rahmen->getRBreite() * 2;
  650. if( hatStyle( Style::VScroll ) && vertikalScrollBar )
  651. br -= 15;
  652. int maxBr = 0;
  653. int len = tm->text->getLength();
  654. char *text = tm->text->getText();
  655. int lineBr = 0;
  656. char buff[] = { 0,0 };
  657. int cbr = 0;
  658. for( int i = 0; i < len; i++ )
  659. {
  660. buff[ 0 ] = text[ i ];
  661. if( text[ i ] == '\n' )
  662. {
  663. maxBr = maxBr >= lineBr ? maxBr : lineBr;
  664. lineBr = 0;
  665. tm->nextStyle();
  666. continue;
  667. }
  668. TextRenderer *r = tm->zCurrentRenderer();
  669. if( r )
  670. {
  671. lineBr += r->getTextBreite( buff );
  672. if( i <= pos )
  673. cbr = lineBr;
  674. }
  675. tm->nextStyle();
  676. }
  677. horizontalScrollBar->update( maxBr, br );
  678. if( cbr > horizontalScrollBar->getScroll() + horizontalScrollBar->getScrollData()->anzeige )
  679. horizontalScrollBar->scroll( cbr - br );
  680. if( cbr < horizontalScrollBar->getScroll() )
  681. horizontalScrollBar->scroll( cbr );
  682. }
  683. }
  684. bool TextFeld::tick( double tickval ) // tick
  685. {
  686. if( hatStyle( Style::Fokus ) )
  687. {
  688. if( tickVal < 0.5 && tickVal + tickval >= 0.5 )
  689. rend = 1;
  690. if( tickVal >= 0.5 && tickVal + tickval >= 1 )
  691. rend = 1;
  692. tickVal += tickval;
  693. if( tickVal >= 1 )
  694. tickVal -= 1;
  695. }
  696. return ZeichnungHintergrund::tick( tickval );
  697. }
  698. void TextFeld::doMausEreignis( MausEreignis &me ) // Maus Ereignis
  699. {
  700. bool nmakc = !me.verarbeitet;
  701. if( hatStyleNicht( Style::Erlaubt ) || hatStyleNicht( Style::Sichtbar ) )
  702. {
  703. if( toolTip )
  704. toolTip->setMausIn( 0 );
  705. me.mx -= pos.x, me.my -= pos.y;
  706. int rbr = 0;
  707. if( rahmen )
  708. rbr = rahmen->getRBreite();
  709. if( ( ( vertikalScrollBar && hatStyle( Style::VScroll ) ) ||
  710. ( horizontalScrollBar && hatStyle( Style::HScroll ) ) ) &&
  711. me.mx > rbr && me.mx < gr.x - rbr &&
  712. me.my > rbr && me.my < gr.y - rbr )
  713. {
  714. vertikalScrollBar->doMausMessage( gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me );
  715. horizontalScrollBar->doMausMessage( rbr, gr.y - rbr * 2 - 15, gr.x - rbr * 2 - ( ( vertikalScrollBar && hatStyle( Style::VScroll ) ) ? 15 : 0 ), 15, me );
  716. me.verarbeitet = 1;
  717. }
  718. me.mx += pos.x, me.my += pos.y;
  719. mausKlick = 0;
  720. return;
  721. }
  722. bool removeFokus = 0;
  723. if( me.verarbeitet || !( me.mx >= pos.x && me.mx <= pos.x + gr.x && me.my >= pos.y && me.my <= pos.y + gr.y ) )
  724. {
  725. if( mausIn )
  726. {
  727. mausIn = 0;
  728. if( toolTip )
  729. toolTip->setMausIn( 0 );
  730. MausEreignis me2;
  731. me2.id = ME_Leaves;
  732. me2.mx = me.mx;
  733. me2.my = me.my;
  734. me2.verarbeitet = 0;
  735. doMausEreignis( me2 );
  736. return;
  737. }
  738. removeFokus = 1;
  739. }
  740. 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 )
  741. {
  742. if( removeFokus && me.id == ME_RLinks )
  743. {
  744. me.mx -= pos.x, me.my -= pos.y;
  745. if( hatStyle( Style::Fokus ) && mak && ( me.verarbeitet || mak( makParam, this, me ) ) )
  746. removeStyle( Style::Fokus );
  747. if( nmakc && me.verarbeitet && nMak )
  748. me.verarbeitet = nMak( nmakParam, this, me );
  749. me.mx += pos.x, me.my += pos.y;
  750. }
  751. if( toolTip )
  752. toolTip->setMausIn( 0 );
  753. return;
  754. }
  755. if( !mausIn && me.id != ME_Leaves )
  756. {
  757. mausIn = 1;
  758. if( toolTip )
  759. toolTip->setMausIn( 1 );
  760. MausEreignis me2;
  761. me2.id = ME_Betritt;
  762. me2.mx = me.mx;
  763. me2.my = me.my;
  764. me2.verarbeitet = 0;
  765. doMausEreignis( me2 );
  766. }
  767. me.mx -= pos.x, me.my -= pos.y;
  768. if( mak && ( me.verarbeitet || mak( makParam, this, me ) ) )
  769. {
  770. if( removeFokus && me.id == ME_RLinks )
  771. removeStyle( Style::Fokus );
  772. if( !me.verarbeitet )
  773. {
  774. if( hatStyleNicht( Style::Fokus ) )
  775. {
  776. mausKlick = 0;
  777. if( me.id == Framework::ME_PLinks )
  778. addStyle( Style::Fokus );
  779. }
  780. int rbr = 0;
  781. if( rahmen )
  782. rbr = rahmen->getRBreite();
  783. if( vertikalScrollBar && hatStyle( Style::VScroll ) )
  784. {
  785. if( vertikalScrollBar->doMausMessage( gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me ) )
  786. {
  787. if( nmakc && me.verarbeitet && nMak )
  788. me.verarbeitet = nMak( nmakParam, this, me );
  789. me.mx += pos.x, me.my += pos.y;
  790. return;
  791. }
  792. }
  793. if( horizontalScrollBar && hatStyle( Style::HScroll ) )
  794. {
  795. if( horizontalScrollBar->doMausMessage( rbr, gr.y - rbr - 15, gr.x - rbr * 2 - ( ( vertikalScrollBar && hatStyle( Style::VScroll ) ) ? 15 : 0 ), 15, me ) )
  796. {
  797. if( nmakc && me.verarbeitet && nMak )
  798. me.verarbeitet = nMak( nmakParam, this, me );
  799. me.mx += pos.x, me.my += pos.y;
  800. return;
  801. }
  802. }
  803. bool shift = TastenStand[ T_Shift ];
  804. bool strg = TastenStand[ T_Strg ];
  805. int tbr = getTextWidth();
  806. int thi = getTextHeight();
  807. int scrollHi = ( vertikalScrollBar && hatStyle( Style::VScroll ) ) ? vertikalScrollBar->getScroll() : 0;
  808. int scrollBr = ( horizontalScrollBar && hatStyle( Style::HScroll ) ) ? horizontalScrollBar->getScroll() : 0;
  809. int xxx = me.mx - rbr + scrollBr;
  810. int yyy = me.my - rbr + scrollHi;
  811. int mausChar = getTextIndexAt( xxx, yyy );
  812. int scrollBreite = ( vertikalScrollBar && hatStyle( Style::VScroll ) ) * 15;
  813. int scrollHeight = ( horizontalScrollBar && hatStyle( Style::HScroll ) ) * 15;
  814. if( hatStyle( Style::HCenter ) )
  815. xxx -= ( ( ( gr.x - scrollBreite ) / 2 ) - tbr / 2 ) - rbr;
  816. if( hatStyle( Style::VCenter ) && hatStyleNicht( Style::VScroll ) )
  817. yyy -= ( ( ( gr.y - scrollHeight ) / 2 ) - thi / 2 ) - rbr;
  818. if( mausChar >= 0 )
  819. {
  820. TextStyle s = tm->getTextStyle( mausChar );
  821. if( s.onClick )
  822. s.onClick( 0, this, me );
  823. }
  824. if( me.mx < gr.x - rbr - 15 )
  825. {
  826. if( tm->renderer )
  827. {
  828. int ncpos = getCurserPosAt( xxx, yyy );
  829. if( me.id == Framework::ME_PLinks )
  830. {
  831. if( ncpos != -1 )
  832. {
  833. if( shift && cpos != ncpos )
  834. addAuswahl( MIN( cpos, ncpos ), MAX( cpos, ncpos ) );
  835. else if( !shift && !mausKlick && !strg )
  836. deselectAuswahl();
  837. cpos = ncpos;
  838. rend = 1;
  839. if( vertikalScrollBar && hatStyle( Style::VScroll ) )
  840. updateVScroll();
  841. if( horizontalScrollBar && hatStyle( Style::HScroll ) )
  842. updateHScroll();
  843. }
  844. mausKlick = 1;
  845. }
  846. if( me.id == ME_Bewegung && mausKlick )
  847. {
  848. if( ncpos != -1 )
  849. {
  850. rend = 1;
  851. if( cpos != ncpos )
  852. invertAuswahl( MIN( cpos, ncpos ), MAX( cpos, ncpos ) );
  853. cpos = ncpos;
  854. if( vertikalScrollBar && hatStyle( Style::VScroll ) )
  855. updateVScroll( cpos );
  856. if( horizontalScrollBar && hatStyle( Style::HScroll ) )
  857. updateHScroll( cpos );
  858. }
  859. }
  860. if( me.id == ME_RLinks )
  861. {
  862. if( ncpos != -1 )
  863. {
  864. rend = 1;
  865. if( cpos != ncpos )
  866. invertAuswahl( MIN( cpos, ncpos ), MAX( cpos, ncpos ) );
  867. cpos = ncpos;
  868. if( vertikalScrollBar && hatStyle( Style::VScroll ) )
  869. updateVScroll( cpos );
  870. if( horizontalScrollBar && hatStyle( Style::HScroll ) )
  871. updateHScroll( cpos );
  872. }
  873. mausKlick = 0;
  874. }
  875. }
  876. }
  877. }
  878. me.verarbeitet = 1;
  879. }
  880. if( nmakc && me.verarbeitet && nMak )
  881. me.verarbeitet = nMak( nmakParam, this, me );
  882. me.mx += pos.x, me.my += pos.y;
  883. }
  884. void TextFeld::doTastaturEreignis( TastaturEreignis &te )
  885. {
  886. bool ntakc = !te.verarbeitet;
  887. if( te.verarbeitet || hatStyleNicht( Style::Fokus ) )
  888. return;
  889. if( !tak )
  890. return;
  891. ++ref;
  892. if( tak( takParam, this, te ) )
  893. {
  894. if( hatStyleNicht( Style::Erlaubt ) )
  895. {
  896. --ref;
  897. if( !ref )
  898. delete this;
  899. return;
  900. }
  901. if( te.id == TE_Press )
  902. {
  903. bool shift = TastenStand[ T_Shift ];
  904. bool strg = TastenStand[ T_Strg ];
  905. switch( te.taste )
  906. {
  907. case T_Entf:
  908. if( !tm->getTextStyle( cpos ).selected )
  909. tm->removeText( cpos, cpos + 1 );
  910. else
  911. {
  912. cpos = tm->getTextStyle( cpos ).beginIndex;
  913. while( cpos > 0 && tm->getTextStyle( cpos - 1 ).selected )
  914. cpos = tm->getTextStyle( cpos - 1 ).beginIndex;
  915. }
  916. replaceAuswahl( "" );
  917. deselectAuswahl();
  918. rend = 1;
  919. break;
  920. case T_BackSpace:
  921. if( !tm->getTextStyle( cpos ).selected )
  922. {
  923. tm->removeText( cpos - 1, cpos );
  924. cpos--;
  925. }
  926. else
  927. {
  928. cpos = tm->getTextStyle( cpos ).beginIndex;
  929. while( cpos > 0 && tm->getTextStyle( cpos - 1 ).selected )
  930. cpos = tm->getTextStyle( cpos - 1 ).beginIndex;
  931. }
  932. replaceAuswahl( "" );
  933. deselectAuswahl();
  934. rend = 1;
  935. break;
  936. case T_Enter:
  937. if( !tm->getTextStyle( cpos ).selected )
  938. tm->insertText( cpos, "\n" );
  939. else
  940. {
  941. cpos = tm->getTextStyle( cpos ).beginIndex;
  942. while( cpos > 0 && tm->getTextStyle( cpos - 1 ).selected )
  943. cpos = tm->getTextStyle( cpos - 1 ).beginIndex;
  944. }
  945. replaceAuswahl( "\n" );
  946. ++cpos;
  947. rend = 1;
  948. break;
  949. case T_Links:
  950. if( shift )
  951. {
  952. if( strg )
  953. {
  954. int tmp = tm->text->getLKick( cpos );
  955. invertAuswahl( tmp, cpos );
  956. cpos = tmp;
  957. }
  958. else
  959. {
  960. invertAuswahl( cpos - 1, cpos );
  961. --cpos;
  962. }
  963. }
  964. else
  965. {
  966. if( strg )
  967. cpos = tm->text->getLKick( cpos );
  968. else
  969. --cpos;
  970. deselectAuswahl();
  971. }
  972. rend = 1;
  973. break;
  974. case T_Oben:
  975. {
  976. int tmp = tm->text->getOKick( cpos );
  977. invertAuswahl( tmp, cpos );
  978. cpos = tmp;
  979. if( !shift )
  980. deselectAuswahl();
  981. rend = 1;
  982. break;
  983. }
  984. case T_Rechts:
  985. if( shift )
  986. {
  987. if( strg )
  988. {
  989. int tmp = tm->text->getRKick( cpos );
  990. invertAuswahl( cpos, tmp );
  991. cpos = tmp;
  992. }
  993. else
  994. {
  995. invertAuswahl( cpos, cpos + 1 );
  996. ++cpos;
  997. }
  998. }
  999. else
  1000. {
  1001. if( strg )
  1002. cpos = tm->text->getRKick( cpos );
  1003. else
  1004. ++cpos;
  1005. deselectAuswahl();
  1006. }
  1007. rend = 1;
  1008. break;
  1009. case T_Unten:
  1010. {
  1011. int tmp = tm->text->getUKick( cpos );
  1012. invertAuswahl( cpos, tmp );
  1013. cpos = tmp;
  1014. if( !shift )
  1015. deselectAuswahl();
  1016. rend = 1;
  1017. break;
  1018. }
  1019. default:
  1020. if( strg && te.id == TE_Press )
  1021. {
  1022. if( te.taste == 'c' || te.taste == 'C' )
  1023. {
  1024. int sa = tm->textStyle.getEintragAnzahl();
  1025. int length = 0;
  1026. for( int i = 0; i < sa; i++ )
  1027. {
  1028. TextStyle s = tm->textStyle.get( i );
  1029. if( s.selected )
  1030. {
  1031. int max = tm->text->getLength();
  1032. if( i < sa - 1 )
  1033. max = tm->textStyle.get( i + 1 ).beginIndex;
  1034. length += max - s.beginIndex;
  1035. }
  1036. }
  1037. if( length )
  1038. {
  1039. char *txt = new char[ length + 1 ];
  1040. txt[ length ] = 0;
  1041. int index = 0;
  1042. for( int i = 0; i < sa; i++ )
  1043. {
  1044. TextStyle s = tm->textStyle.get( i );
  1045. if( s.selected )
  1046. {
  1047. int max = tm->text->getLength();
  1048. if( i < sa - 1 )
  1049. max = tm->textStyle.get( i + 1 ).beginIndex;
  1050. memcpy( txt + index, tm->text->getText() + s.beginIndex, max - s.beginIndex );
  1051. index += max - s.beginIndex;
  1052. }
  1053. }
  1054. TextKopieren( txt );
  1055. delete[] txt;
  1056. }
  1057. else
  1058. TextKopieren( tm->text->getText() );
  1059. }
  1060. if( te.taste == 'v' || te.taste == 'V' )
  1061. {
  1062. char *txt = TextInsert();
  1063. if( !tm->getTextStyle( cpos ).selected )
  1064. tm->insertText( cpos, txt );
  1065. else
  1066. {
  1067. cpos = tm->getTextStyle( cpos ).beginIndex;
  1068. while( cpos > 0 && tm->getTextStyle( cpos - 1 ).selected )
  1069. cpos = tm->getTextStyle( cpos - 1 ).beginIndex;
  1070. }
  1071. replaceAuswahl( txt );
  1072. cpos += textLength( txt );
  1073. rend = 1;
  1074. }
  1075. break;
  1076. }
  1077. if( istSchreibbar( te.taste ) )
  1078. {
  1079. char buff[] = { (char)te.taste, 0 };
  1080. if( !tm->getTextStyle( cpos ).selected )
  1081. tm->insertText( cpos, buff );
  1082. else
  1083. {
  1084. cpos = tm->getTextStyle( cpos ).beginIndex;
  1085. while( cpos > 0 && tm->getTextStyle( cpos - 1 ).selected )
  1086. cpos = tm->getTextStyle( cpos - 1 ).beginIndex;
  1087. }
  1088. replaceAuswahl( buff );
  1089. ++cpos;
  1090. rend = 1;
  1091. }
  1092. break;
  1093. }
  1094. }
  1095. if( cpos < 0 )
  1096. cpos = 0;
  1097. if( cpos > tm->text->getLength() )
  1098. cpos = tm->text->getLength();
  1099. if( hatStyle( Style::VScroll ) )
  1100. updateVScroll( cpos );
  1101. if( hatStyle( Style::HScroll ) )
  1102. updateHScroll( cpos );
  1103. te.verarbeitet = 1;
  1104. }
  1105. --ref;
  1106. if( ntakc && te.verarbeitet && nTak )
  1107. te.verarbeitet = nTak( ntakParam, this, te );
  1108. if( !ref )
  1109. delete this;
  1110. }
  1111. void TextFeld::render( Bild &zRObj ) // zeichenet nach zRObj
  1112. {
  1113. if( hatStyleNicht( Style::Sichtbar ) )
  1114. return;
  1115. ZeichnungHintergrund::render( zRObj );
  1116. if( !tm->text || !tm->renderer )
  1117. return;
  1118. lockZeichnung();
  1119. if( !zRObj.setDrawOptions( innenPosition, innenSize ) )
  1120. {
  1121. unlockZeichnung();
  1122. return;
  1123. }
  1124. if( hatStyleNicht( Style::Mehrzeilig ) )
  1125. tm->text->remove( '\n' );
  1126. int tbr = getTextWidth();
  1127. int thi = getTextHeight();
  1128. int xxx = 0;
  1129. int yyy = 0;
  1130. int breite = innenSize.x;
  1131. int height = innenSize.y;
  1132. bool hs = horizontalScrollBar && hatStyle( Style::HScroll );
  1133. bool vs = vertikalScrollBar && hatStyle( Style::VScroll );
  1134. if( vs )
  1135. yyy -= vertikalScrollBar->getScroll();
  1136. if( hs )
  1137. xxx -= horizontalScrollBar->getScroll();
  1138. if( hatStyle( Style::HCenter ) && !hs )
  1139. xxx = ( breite / 2 ) - tbr / 2;
  1140. if( hatStyle( Style::VCenter ) && !vs )
  1141. yyy = ( height / 2 ) - thi / 2;
  1142. int x = xxx;
  1143. int y = yyy;
  1144. int len = tm->text->getLength();
  1145. char *text = tm->text->getText();
  1146. lockZeichnung();
  1147. tm->resetIteration();
  1148. TextStyle &style = tm->currentStyle();
  1149. int maxLH = 0;
  1150. for( int i = 0; i <= len; i++ )
  1151. {
  1152. int oldX = x;
  1153. if( i < len )
  1154. tm->zCurrentRenderer()->renderChar( x, y, istSchreibbar( showChar ) ? showChar : text[ i ], zRObj, style.selected ? style.selectedColor : style.fontColor, style.underlined, style.selected, style.selectedBackcroundColor );
  1155. if( i == cpos && tickVal <= 0.5 && hatStyle( Style::Fokus ) && hatStyle( Style::Erlaubt ) )
  1156. zRObj.drawLinieV( oldX, y, tm->zCurrentRenderer()->getZeilenHeight(), 0xFFFF5555 );
  1157. int tmp = tm->zCurrentRenderer()->getZeilenHeight() + tm->zCurrentRenderer()->getZeilenAbstand();
  1158. maxLH = tmp > maxLH ? tmp : maxLH;
  1159. if( i < len && text[ i ] == '\n' )
  1160. {
  1161. x = xxx;
  1162. y += maxLH;
  1163. }
  1164. tm->nextStyle();
  1165. }
  1166. unlockZeichnung();
  1167. zRObj.releaseDrawOptions();
  1168. unlockZeichnung();
  1169. }
  1170. // Konstant
  1171. Text *TextFeld::getText() const // gibt vom Text zurück
  1172. {
  1173. if( !tm->text )
  1174. return 0;
  1175. return tm->text->getThis();
  1176. }
  1177. Text *TextFeld::zText() const // gibt den Text zurück
  1178. {
  1179. return tm->text;
  1180. }
  1181. Schrift *TextFeld::getSchrift() const// gint getThis der Schrift Zurück
  1182. {
  1183. tm->resetIteration();
  1184. return tm->zCurrentRenderer()->getSchrift();
  1185. }
  1186. Schrift *TextFeld::zSchrift() const// gibt die Schrift zurück
  1187. {
  1188. tm->resetIteration();
  1189. return tm->zCurrentRenderer()->zSchrift();
  1190. }
  1191. // Gibt die Schrift zurück.
  1192. // rendererIndex: Der Index des Renderers dessen Schrift zurückgegeben werden soll
  1193. // return: 0, falls die Schrift nicht gesetzt wurde
  1194. Schrift *TextFeld::getSchrift( int rendererIndex ) const
  1195. {
  1196. if( tm->renderer && tm->renderer->z( rendererIndex ) )
  1197. return tm->renderer->z( rendererIndex )->getSchrift();
  1198. return 0;
  1199. }
  1200. // Gibt die Schrift ohne erhöhten Reference Counter zurük
  1201. // rendererIndex: Der Index des Renderers dessen Schrift zurückgegeben werden soll
  1202. // return: 0, falls die Schrift nicht gesetzt wurde
  1203. Schrift *TextFeld::zSchrift( int rendererIndex ) const
  1204. {
  1205. if( tm->renderer && tm->renderer->z( rendererIndex ) )
  1206. return tm->renderer->z( rendererIndex )->zSchrift();
  1207. return 0;
  1208. }
  1209. TextRenderer *TextFeld::getTextRenderer() const
  1210. {
  1211. tm->resetIteration();
  1212. return tm->zCurrentRenderer()->getThis();
  1213. }
  1214. TextRenderer *TextFeld::zTextRenderer() const
  1215. {
  1216. tm->resetIteration();
  1217. return tm->zCurrentRenderer();
  1218. }
  1219. // Gibt den TextRenderer zurück.
  1220. // index: Der Index des Renderers der zurückgegeben werden soll
  1221. // return: 0, falls der TextRenderer nicht gesetzt wurde
  1222. TextRenderer *TextFeld::getTextRenderer( int index ) const
  1223. {
  1224. if( tm->renderer && tm->renderer->z( index ) )
  1225. return tm->renderer->get( index );
  1226. return 0;
  1227. }
  1228. // Gibt dien TextRenderer ohne erhöhten Reference Counter zurük
  1229. // index: Der Index des Renderers der zurückgegeben werden soll
  1230. // return: 0, falls der TextRenderer nicht gesetzt wurde
  1231. TextRenderer *TextFeld::zTextRenderer( int index ) const
  1232. {
  1233. if( tm->renderer && tm->renderer->z( index ) )
  1234. return tm->renderer->z( index );
  1235. return 0;
  1236. }
  1237. unsigned char TextFeld::getSchriftSize() const // gibt die Schriftgröße zurück
  1238. {
  1239. tm->resetIteration();
  1240. return tm->current.fontSize;
  1241. }
  1242. // Gibt die Schriftgröße zurück
  1243. // index: Der Index des Zeichens
  1244. unsigned char TextFeld::getSchriftSize( int index ) const
  1245. {
  1246. tm->resetIteration();
  1247. return tm->current.fontSize;
  1248. }
  1249. int TextFeld::getSchriftFarbe() const// gibt getThis der Schriftfarbe zurück
  1250. {
  1251. tm->resetIteration();
  1252. return tm->current.fontColor;
  1253. }
  1254. // Gibt die Schriftfarbe im A8R8G8B8 Format zurück
  1255. // index: Der Index des Zeichens
  1256. int TextFeld::getSchriftFarbe( int index ) const
  1257. {
  1258. return tm->getTextStyle( index ).fontColor;
  1259. }
  1260. unsigned char TextFeld::getShowChar() const // gibt den Anzeige Char zurück
  1261. {
  1262. return showChar;
  1263. }
  1264. int TextFeld::getCursorPos() const
  1265. {
  1266. return cpos;
  1267. }
  1268. // Gibt 1 zurück wenn das Zeichen ausgewählt ist
  1269. // index: Der Index des Zeichens
  1270. bool TextFeld::isCharSelected( int index ) const
  1271. {
  1272. return tm->getTextStyle( index ).selected;
  1273. }
  1274. // Gibt den Index des Zeichens zurück, das sich unter der Maus befindet
  1275. // mx: die x position der maus relativ zur position des textfeldes
  1276. // my: die y position der maus relativ zut position des textfeldes
  1277. // return: -1, falls sich an der Position kein zeichen befindet
  1278. int TextFeld::getTextIndexAt( int mx, int my ) const
  1279. {
  1280. int tbr = getTextWidth();
  1281. int thi = getTextHeight();
  1282. int xxx = 0;
  1283. int yyy = 0;
  1284. int breite = innenSize.x;
  1285. int height = innenSize.y;
  1286. bool hs = horizontalScrollBar && hatStyle( Style::HScroll );
  1287. bool vs = vertikalScrollBar && hatStyle( Style::VScroll );
  1288. if( vs )
  1289. yyy -= vertikalScrollBar->getScroll();
  1290. if( hs )
  1291. xxx -= horizontalScrollBar->getScroll();
  1292. if( hatStyle( Style::HCenter ) && !hs )
  1293. xxx = ( breite / 2 ) - tbr / 2;
  1294. if( hatStyle( Style::VCenter ) && !vs )
  1295. yyy = ( height / 2 ) - thi / 2;
  1296. int x = xxx;
  1297. int y = yyy;
  1298. int len = tm->text->getLength();
  1299. char *text = tm->text->getText();
  1300. tm->resetIteration();
  1301. int maxLH = 0;
  1302. for( int i = 0; i < len; i++ )
  1303. {
  1304. int tmpx = tm->zCurrentRenderer()->getCharWidth( istSchreibbar( showChar ) ? showChar : text[ i ] );
  1305. int tmpy = tm->zCurrentRenderer()->getZeilenHeight();
  1306. if( mx >= x && mx < x + tmpx && my >= y && my < maxLH + tmpy )
  1307. return i;
  1308. if( mx < x + tmpx && my < maxLH + tmpy )
  1309. return -1;
  1310. x += tmpx + tm->zCurrentRenderer()->getZeichenAbstand();
  1311. tmpy += tm->zCurrentRenderer()->getZeilenAbstand();
  1312. maxLH = tmpy > maxLH ? tmpy : maxLH;
  1313. if( text[ i ] == '\n' )
  1314. {
  1315. x = xxx;
  1316. y += maxLH;
  1317. }
  1318. tm->nextStyle();
  1319. }
  1320. return -1;
  1321. }
  1322. // Gibt den Index des Zeichens zurück, vor dem der curser gesetzt wird, wenn mit der maus geklickt wird
  1323. // mx: die x position der maus relativ zur position des textfeldes
  1324. // my: die y position der maus relativ zut position des textfeldes
  1325. int TextFeld::getCurserPosAt( int mx, int my ) const
  1326. {
  1327. int tbr = getTextWidth();
  1328. int thi = getTextHeight();
  1329. int xxx = 0;
  1330. int yyy = 0;
  1331. int breite = innenSize.x;
  1332. int height = innenSize.y;
  1333. bool hs = horizontalScrollBar && hatStyle( Style::HScroll );
  1334. bool vs = vertikalScrollBar && hatStyle( Style::VScroll );
  1335. if( vs )
  1336. yyy -= vertikalScrollBar->getScroll();
  1337. if( hs )
  1338. xxx -= horizontalScrollBar->getScroll();
  1339. if( hatStyle( Style::HCenter ) && !hs )
  1340. xxx = ( breite / 2 ) - tbr / 2;
  1341. if( hatStyle( Style::VCenter ) && !vs )
  1342. yyy = ( height / 2 ) - thi / 2;
  1343. int x = xxx;
  1344. int y = yyy;
  1345. int len = tm->text->getLength();
  1346. char *text = tm->text->getText();
  1347. tm->resetIteration();
  1348. int maxLH = 0;
  1349. for( int i = 0; i < len; i++ )
  1350. {
  1351. int tmpx = tm->zCurrentRenderer()->getCharWidth( istSchreibbar( showChar ) ? showChar : text[ i ] );
  1352. int tmpy = tm->zCurrentRenderer()->getZeilenHeight() + tm->zCurrentRenderer()->getZeilenAbstand();
  1353. if( mx < x + tmpx / 2 && my < y + tmpy - tm->zCurrentRenderer()->getZeilenAbstand() / 2 )
  1354. return i;
  1355. x += tmpx + tm->zCurrentRenderer()->getZeichenAbstand();
  1356. maxLH = tmpy > maxLH ? tmpy : maxLH;
  1357. if( text[ i ] == '\n' )
  1358. {
  1359. if( my >= y - tm->zCurrentRenderer()->getZeilenAbstand() / 2 && my < y + maxLH - tm->zCurrentRenderer()->getZeilenAbstand() / 2 )
  1360. return i;
  1361. x = xxx;
  1362. y += maxLH;
  1363. }
  1364. tm->nextStyle();
  1365. }
  1366. return tm->text->getLength();
  1367. }
  1368. // Gibt den Style eines bestimmten zeichens zurück
  1369. // index: Der index des Zeichensf
  1370. TextFeld::TextStyle TextFeld::getTextStyle( int index ) const
  1371. {
  1372. return tm->getTextStyle( index );
  1373. }
  1374. Zeichnung *TextFeld::dublizieren() const // Erzeugt eine Kopie des Zeichnungs
  1375. {
  1376. TextFeld *obj = new TextFeld();
  1377. obj->setPosition( pos );
  1378. obj->setSize( gr );
  1379. obj->setMausEreignisParameter( makParam );
  1380. obj->setTastaturEreignisParameter( takParam );
  1381. obj->setMausEreignis( mak );
  1382. obj->setTastaturEreignis( tak );
  1383. if( toolTip )
  1384. obj->setToolTipZ( (ToolTip*)toolTip->dublizieren() );
  1385. obj->setStyle( style );
  1386. obj->tm->renderer->release();
  1387. obj->tm->renderer = tm->renderer->getThis();
  1388. obj->tm->textStyle.leeren();
  1389. for( auto i = tm->textStyle.getIterator(); i; i++ )
  1390. obj->tm->textStyle.add( i._ );
  1391. obj->tm->index = tm->index;
  1392. obj->tm->styleIndex = tm->styleIndex;
  1393. obj->tm->current = tm->current;
  1394. if( tm->text )
  1395. obj->setText( tm->text->getText() );
  1396. obj->setHintergrundFarbe( hintergrundFarbe );
  1397. if( hintergrundFeld )
  1398. obj->setAlphaFeldZ( (AlphaFeld*)hintergrundFeld->dublizieren() );
  1399. if( rahmen )
  1400. obj->setRahmenZ( (Rahmen*)rahmen->dublizieren() );
  1401. if( hintergrundBild )
  1402. obj->setHintergrundBild( hintergrundBild->getThis() );
  1403. if( vertikalScrollBar )
  1404. {
  1405. obj->setVertikalKlickScroll( vertikalScrollBar->getKlickScroll() );
  1406. obj->setVertikalScrollPos( vertikalScrollBar->getScroll() );
  1407. obj->setVertikalScrollFarbe( vertikalScrollBar->getFarbe(), vertikalScrollBar->getBgFarbe() );
  1408. }
  1409. if( horizontalScrollBar )
  1410. {
  1411. obj->setHorizontalKlickScroll( horizontalScrollBar->getKlickScroll() );
  1412. obj->setHorizontalScrollPos( horizontalScrollBar->getScroll() );
  1413. obj->setHorizontalScrollFarbe( horizontalScrollBar->getFarbe(), horizontalScrollBar->getBgFarbe() );
  1414. }
  1415. obj->setSchowChar( showChar );
  1416. return obj;
  1417. }