TextFeld.cpp 47 KB

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