TextFeld.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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. // Inhalt der TextFeld Klasse aus TextFeld.h
  17. // Konstruktor
  18. TextFeld::TextFeld()
  19. : ZeichnungHintergrund(),
  20. schriftSize( 12 ),
  21. schrift( 0 ),
  22. text( 0 ),
  23. sF( 0xFF000000 ),
  24. showChar( 0 ),
  25. begf( 0 ),
  26. cpos( 0 ),
  27. tickVal( 0 ),
  28. mausKlick( 0 ),
  29. ref( 1 )
  30. {
  31. horizontalScrollBar = new HScrollBar();
  32. vertikalScrollBar = new VScrollBar();
  33. style = 0;
  34. this->setMausEreignis( _ret1ME );
  35. this->setTastaturEreignis( _ret1TE );
  36. }
  37. // Destruktor
  38. TextFeld::~TextFeld()
  39. {
  40. if( schrift )
  41. schrift->release();
  42. if( text )
  43. text->release();
  44. }
  45. // nicht constant
  46. void TextFeld::setText( Text *txt ) // setzt den angezeigten Text
  47. {
  48. lockZeichnung();
  49. if( !text )
  50. text = new Text();
  51. text->setText( txt );
  52. if( hatStyle( Style::VScroll ) )
  53. updateVScroll();
  54. if( hatStyle( Style::HScroll ) )
  55. updateHScroll();
  56. unlockZeichnung();
  57. rend = 1;
  58. }
  59. void TextFeld::setTextZ( Text *txt ) // setzt einen Zeiger zum angezeigten Text
  60. {
  61. lockZeichnung();
  62. if( text )
  63. text->release();
  64. text = txt;
  65. if( hatStyle( Style::VScroll ) )
  66. updateVScroll();
  67. if( hatStyle( Style::HScroll ) )
  68. updateHScroll();
  69. rend = 1;
  70. unlockZeichnung();
  71. }
  72. void TextFeld::setText( const char *txt ) // setzt den angezeigten Text
  73. {
  74. lockZeichnung();
  75. if( !text )
  76. text = new Text();
  77. text->setText( txt );
  78. if( hatStyle( Style::VScroll ) )
  79. updateVScroll();
  80. if( hatStyle( Style::HScroll ) )
  81. updateHScroll();
  82. rend = 1;
  83. unlockZeichnung();
  84. }
  85. void TextFeld::addZeile( const char *zeile ) // fügt Zeile An
  86. {
  87. if( text )
  88. {
  89. Text *txt = new Text( zeile );
  90. txt->append( "\n" );
  91. if( schrift )
  92. {
  93. bool vs = vertikalScrollBar && hatStyle( Style::VScroll );
  94. int rbr = ( rahmen && hatStyle( Style::Rahmen ) ) ? rahmen->getRBreite() : 0;
  95. schrift->lock();
  96. schrift->setSchriftSize( schriftSize );
  97. schrift->textFormatieren( txt, gr.x - ( (int)vs * 15 ) - rbr * 2, schriftSize );
  98. schrift->unlock();
  99. }
  100. lockZeichnung();
  101. text->append( txt->getText() );
  102. unlockZeichnung();
  103. txt->release();
  104. if( hatStyle( Style::VScroll ) )
  105. updateVScroll();
  106. if( hatStyle( Style::HScroll ) )
  107. updateHScroll();
  108. rend = 1;
  109. }
  110. }
  111. void TextFeld::setAuswahl( int pos1, int pos2 ) // setzt den Ausgewählten Text
  112. {
  113. cpos = pos1;
  114. begf = pos2;
  115. rend = 1;
  116. }
  117. void TextFeld::setAuswahl( Punkt &auswahl )
  118. {
  119. cpos = auswahl.x;
  120. begf = auswahl.y;
  121. rend = 1;
  122. }
  123. void TextFeld::setSchriftZ( Schrift *schrift ) // setzt einen Zeiger zur Schrift
  124. {
  125. if( this->schrift )
  126. this->schrift->release();
  127. this->schrift = schrift;
  128. rend = 1;
  129. }
  130. void TextFeld::setSchriftSize( unsigned char gr ) // setzt die Schriftgröße
  131. {
  132. schriftSize = gr;
  133. rend = 1;
  134. }
  135. void TextFeld::setSchriftFarbe( int fc ) // setzt die Schrift Farbe
  136. {
  137. sF = fc;
  138. rend = 1;
  139. }
  140. void TextFeld::setSchowChar( unsigned char c ) // bei Passwortfeld *
  141. {
  142. showChar = c;
  143. rend = 1;
  144. }
  145. void TextFeld::setVScrollZuZeile( int zeile ) // scrollt zur Zeile
  146. {
  147. if( vertikalScrollBar && schrift && text && hatStyle( Style::Mehrzeilig ) )
  148. {
  149. schrift->lock();
  150. schrift->setSchriftSize( schriftSize );
  151. Text t = "a";
  152. vertikalScrollBar->scroll( zeile * ( schrift->getZeilenabstand() + schrift->getTextHeight( &t ) ) );
  153. schrift->unlock();
  154. rend = 1;
  155. }
  156. }
  157. void TextFeld::updateVScroll( int pos ) // scrollt nach unten
  158. {
  159. if( pos == -1 )
  160. pos = cpos;
  161. if( vertikalScrollBar )
  162. {
  163. int sPos = 0;
  164. int hi = 0;
  165. if( text && schrift )
  166. {
  167. if( hatStyleNicht( Style::Mehrzeilig ) )
  168. text->remove( '\n' );
  169. schrift->setSchriftSize( schriftSize );
  170. hi = gr.y;
  171. if( hatStyle( Style::Rahmen ) && rahmen )
  172. hi -= rahmen->getRBreite() * 2;
  173. if( hatStyle( Style::HScroll ) && horizontalScrollBar )
  174. hi -= 15;
  175. vertikalScrollBar->update( schrift->getTextHeight( text ) + schriftSize + schrift->getTextHeight( Text( "a" ).getThis() ), hi );
  176. Text t;
  177. int zh = schrift->getTextHeight( &t ) + schrift->getZeilenabstand();
  178. int l = text->getLength();
  179. for( int i = 0; i < l && ( i < pos || hatStyleNicht( Style::Erlaubt ) ); ++i )
  180. {
  181. if( text->getText()[ i ] == '\n' )
  182. sPos += zh;
  183. }
  184. }
  185. if( schrift )
  186. {
  187. if( sPos - schrift->getZeilenabstand() - schrift->getTextHeight( Text( "a" ).getThis() ) < vertikalScrollBar->getScroll() )
  188. vertikalScrollBar->scroll( sPos - schrift->getZeilenabstand() - schrift->getTextHeight( Text( "a" ).getThis() ) );
  189. if( sPos + schrift->getZeilenabstand() + schrift->getTextHeight( Text( "a" ).getThis() ) > vertikalScrollBar->getScroll() + vertikalScrollBar->getScrollData()->anzeige )
  190. vertikalScrollBar->scroll( sPos + ( schrift->getZeilenabstand() + schrift->getTextHeight( Text( "a" ).getThis() ) ) * 2 - hi );
  191. }
  192. rend = 1;
  193. }
  194. }
  195. void TextFeld::updateHScroll( int pos ) // scrollt zur Curser Position
  196. {
  197. if( pos == -1 )
  198. pos = cpos;
  199. if( horizontalScrollBar && text && schrift )
  200. {
  201. schrift->lock();
  202. schrift->setSchriftSize( schriftSize );
  203. int br = gr.x;
  204. if( hatStyle( Style::Rahmen ) && rahmen )
  205. br -= rahmen->getRBreite() * 2;
  206. if( hatStyle( Style::VScroll ) && vertikalScrollBar )
  207. br -= 15;
  208. int maxBr = schrift->getTextBreite( text ) + schriftSize;
  209. horizontalScrollBar->update( maxBr, br );
  210. if( hatStyle( Style::Erlaubt ) && maxBr > br && pos > 0 && pos < text->getLength() )
  211. {
  212. int p1 = 0;
  213. char *tmp = text->getText();
  214. for( int i = 0; i < pos; i++, tmp++ )
  215. {
  216. if( *tmp == '\n' )
  217. p1 = i + 1;
  218. }
  219. Text *t = text->getTeilText( p1, pos );
  220. int cbr = schrift->getTextBreite( t );
  221. t->release();
  222. if( cbr + schriftSize > horizontalScrollBar->getScroll() + horizontalScrollBar->getScrollData()->anzeige )
  223. horizontalScrollBar->scroll( cbr + schriftSize - br );
  224. if( cbr - schriftSize < horizontalScrollBar->getScroll() )
  225. horizontalScrollBar->scroll( cbr - schriftSize );
  226. }
  227. schrift->unlock();
  228. }
  229. }
  230. bool TextFeld::tick( double tickval ) // tick
  231. {
  232. if( hatStyle( Style::Fokus ) )
  233. {
  234. if( tickVal < 0.5 && tickVal + tickval >= 0.5 )
  235. rend = 1;
  236. if( tickVal >= 0.5 && tickVal + tickval >= 1 )
  237. rend = 1;
  238. tickVal += tickval;
  239. if( tickVal >= 1 )
  240. tickVal -= 1;
  241. }
  242. return ZeichnungHintergrund::tick( tickval );
  243. }
  244. void TextFeld::doMausEreignis( MausEreignis &me ) // Maus Ereignis
  245. {
  246. bool nmakc = !me.verarbeitet;
  247. if( hatStyleNicht( Style::Erlaubt ) || hatStyleNicht( Style::Sichtbar ) )
  248. {
  249. if( toolTip )
  250. toolTip->setMausIn( 0 );
  251. me.mx -= pos.x, me.my -= pos.y;
  252. int rbr = 0;
  253. if( rahmen )
  254. rbr = rahmen->getRBreite();
  255. if( ( ( vertikalScrollBar && hatStyle( Style::VScroll ) ) ||
  256. ( horizontalScrollBar && hatStyle( Style::HScroll ) ) ) &&
  257. me.mx > rbr && me.mx < gr.x - rbr &&
  258. me.my > rbr && me.my < gr.y - rbr )
  259. {
  260. vertikalScrollBar->doMausMessage( gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me );
  261. horizontalScrollBar->doMausMessage( rbr, gr.y - rbr * 2 - 15, gr.x - rbr * 2 - ( ( vertikalScrollBar && hatStyle( Style::VScroll ) ) ? 15 : 0 ), 15, me );
  262. me.verarbeitet = 1;
  263. }
  264. me.mx += pos.x, me.my += pos.y;
  265. mausKlick = 0;
  266. return;
  267. }
  268. bool removeFokus = 0;
  269. if( me.verarbeitet || !( me.mx >= pos.x && me.mx <= pos.x + gr.x && me.my >= pos.y && me.my <= pos.y + gr.y ) )
  270. {
  271. if( mausIn )
  272. {
  273. mausIn = 0;
  274. if( toolTip )
  275. toolTip->setMausIn( 0 );
  276. MausEreignis me2;
  277. me2.id = ME_Leaves;
  278. me2.mx = me.mx;
  279. me2.my = me.my;
  280. me2.verarbeitet = 0;
  281. doMausEreignis( me2 );
  282. return;
  283. }
  284. removeFokus = 1;
  285. }
  286. 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 )
  287. {
  288. if( removeFokus && me.id == ME_RLinks )
  289. {
  290. me.mx -= pos.x, me.my -= pos.y;
  291. if( hatStyle( Style::Fokus ) && mak && ( me.verarbeitet || mak( makParam, this, me ) ) )
  292. removeStyle( Style::Fokus );
  293. if( nmakc && me.verarbeitet && nMak )
  294. me.verarbeitet = nMak( nmakParam, this, me );
  295. me.mx += pos.x, me.my += pos.y;
  296. }
  297. if( toolTip )
  298. toolTip->setMausIn( 0 );
  299. return;
  300. }
  301. if( !mausIn && me.id != ME_Leaves )
  302. {
  303. mausIn = 1;
  304. if( toolTip )
  305. toolTip->setMausIn( 1 );
  306. MausEreignis me2;
  307. me2.id = ME_Betritt;
  308. me2.mx = me.mx;
  309. me2.my = me.my;
  310. me2.verarbeitet = 0;
  311. doMausEreignis( me2 );
  312. }
  313. me.mx -= pos.x, me.my -= pos.y;
  314. if( mak && ( me.verarbeitet || mak( makParam, this, me ) ) )
  315. {
  316. if( removeFokus && me.id == ME_RLinks )
  317. removeStyle( Style::Fokus );
  318. if( !me.verarbeitet )
  319. {
  320. if( hatStyleNicht( Style::Fokus ) )
  321. {
  322. mausKlick = 0;
  323. if( me.id == Framework::ME_PLinks )
  324. addStyle( Style::Fokus );
  325. }
  326. int rbr = 0;
  327. if( rahmen )
  328. rbr = rahmen->getRBreite();
  329. if( vertikalScrollBar && hatStyle( Style::VScroll ) )
  330. {
  331. if( vertikalScrollBar->doMausMessage( gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me ) )
  332. {
  333. if( nmakc && me.verarbeitet && nMak )
  334. me.verarbeitet = nMak( nmakParam, this, me );
  335. me.mx += pos.x, me.my += pos.y;
  336. return;
  337. }
  338. }
  339. if( horizontalScrollBar && hatStyle( Style::HScroll ) )
  340. {
  341. if( horizontalScrollBar->doMausMessage( rbr, gr.y - rbr - 15, gr.x - rbr * 2 - ( ( vertikalScrollBar && hatStyle( Style::VScroll ) ) ? 15 : 0 ), 15, me ) )
  342. {
  343. if( nmakc && me.verarbeitet && nMak )
  344. me.verarbeitet = nMak( nmakParam, this, me );
  345. me.mx += pos.x, me.my += pos.y;
  346. return;
  347. }
  348. }
  349. if( me.mx < gr.x - rbr - 15 )
  350. {
  351. if( schrift )
  352. {
  353. schrift->setSchriftSize( schriftSize );
  354. bool shift = TastenStand[ T_Shift ];
  355. if( me.id == Framework::ME_PLinks )
  356. {
  357. int tbr = schrift->getTextBreite( text );
  358. int thi = schrift->getTextHeight( text );
  359. int scrollHi = ( vertikalScrollBar && hatStyle( Style::VScroll ) ) ? vertikalScrollBar->getScroll() : 0;
  360. int scrollBr = ( horizontalScrollBar && hatStyle( Style::HScroll ) ) ? horizontalScrollBar->getScroll() : 0;
  361. int xxx = me.mx - rbr + scrollBr;
  362. int yyy = me.my - rbr + scrollHi;
  363. int scrollBreite = ( vertikalScrollBar && hatStyle( Style::VScroll ) ) * 15;
  364. if( hatStyle( Style::HCenter ) )
  365. xxx -= ( ( ( gr.x - scrollBreite ) / 2 ) - tbr / 2 ) - rbr;
  366. if( hatStyle( Style::VCenter ) && hatStyleNicht( Style::VScroll ) )
  367. yyy -= ( ( ( gr.y - scrollHi ) / 2 ) - thi / 2 ) - rbr;
  368. int pos = schrift->textPos( text, xxx, yyy );
  369. if( pos != -1 )
  370. {
  371. if( shift )
  372. begf = pos;
  373. else
  374. {
  375. cpos = pos;
  376. begf = pos;
  377. }
  378. rend = 1;
  379. if( vertikalScrollBar && hatStyle( Style::VScroll ) )
  380. updateVScroll( begf );
  381. if( horizontalScrollBar && hatStyle( Style::HScroll ) )
  382. updateHScroll( begf );
  383. }
  384. mausKlick = 1;
  385. }
  386. if( me.id == ME_Bewegung && mausKlick )
  387. {
  388. int tbr = schrift->getTextBreite( text );
  389. int thi = schrift->getTextHeight( text );
  390. int scrollHi = ( vertikalScrollBar && hatStyle( Style::VScroll ) ) ? vertikalScrollBar->getScroll() : 0;
  391. int scrollBr = ( horizontalScrollBar && hatStyle( Style::HScroll ) ) ? horizontalScrollBar->getScroll() : 0;
  392. int xxx = me.mx - rbr + scrollBr;
  393. int yyy = me.my - rbr + scrollHi;
  394. int scrollBreite = ( vertikalScrollBar && hatStyle( Style::VScroll ) ) * 15;
  395. int scrollHeight = ( horizontalScrollBar && hatStyle( Style::HScroll ) ) * 15;
  396. if( hatStyle( Style::HCenter ) )
  397. xxx -= ( ( ( gr.x - scrollBreite ) / 2 ) - tbr / 2 ) - rbr;
  398. if( hatStyle( Style::VCenter ) && hatStyleNicht( Style::VScroll ) )
  399. yyy -= ( ( ( gr.y - scrollHeight ) / 2 ) - thi / 2 ) - rbr;
  400. int pos = schrift->textPos( text, xxx, yyy );
  401. if( pos != -1 )
  402. {
  403. if( begf != pos )
  404. rend = 1;
  405. begf = pos;
  406. if( vertikalScrollBar && hatStyle( Style::VScroll ) )
  407. updateVScroll( begf );
  408. if( horizontalScrollBar && hatStyle( Style::HScroll ) )
  409. updateHScroll( begf );
  410. }
  411. }
  412. if( me.id == ME_RLinks )
  413. {
  414. if( !shift )
  415. {
  416. int tbr = schrift->getTextBreite( text );
  417. int thi = schrift->getTextHeight( text );
  418. int scrollHi = ( vertikalScrollBar && hatStyle( Style::VScroll ) ) ? vertikalScrollBar->getScroll() : 0;
  419. int scrollBr = ( horizontalScrollBar && hatStyle( Style::HScroll ) ) ? horizontalScrollBar->getScroll() : 0;
  420. int xxx = me.mx - rbr + scrollBr;
  421. int yyy = me.my - rbr + scrollHi;
  422. int scrollBreite = ( vertikalScrollBar && hatStyle( Style::VScroll ) ) * 15;
  423. int scrollHeight = ( horizontalScrollBar && hatStyle( Style::HScroll ) ) * 15;
  424. if( hatStyle( Style::HCenter ) )
  425. xxx -= ( ( ( gr.x - scrollBreite ) / 2 ) - tbr / 2 ) - rbr;
  426. if( hatStyle( Style::VCenter ) && hatStyleNicht( Style::VScroll ) )
  427. yyy -= ( ( ( gr.y - scrollHeight ) / 2 ) - thi / 2 ) - rbr;
  428. int pos = schrift->textPos( text, xxx, yyy );
  429. if( pos != -1 )
  430. {
  431. begf = pos;
  432. if( vertikalScrollBar && hatStyle( Style::VScroll ) )
  433. updateVScroll( begf );
  434. if( horizontalScrollBar && hatStyle( Style::HScroll ) )
  435. updateHScroll( begf );
  436. }
  437. rend = 1;
  438. }
  439. mausKlick = 0;
  440. }
  441. }
  442. }
  443. }
  444. me.verarbeitet = 1;
  445. }
  446. if( nmakc && me.verarbeitet && nMak )
  447. me.verarbeitet = nMak( nmakParam, this, me );
  448. me.mx += pos.x, me.my += pos.y;
  449. }
  450. void TextFeld::doTastaturEreignis( TastaturEreignis &te )
  451. {
  452. bool ntakc = !te.verarbeitet;
  453. if( te.verarbeitet || hatStyleNicht( Style::Fokus ) )
  454. return;
  455. if( !tak )
  456. return;
  457. ++ref;
  458. if( tak( takParam, this, te ) )
  459. {
  460. if( hatStyleNicht( Style::Erlaubt ) )
  461. {
  462. --ref;
  463. if( !ref )
  464. delete this;
  465. return;
  466. }
  467. if( te.id == TE_Press )
  468. {
  469. bool shift = TastenStand[ T_Shift ];
  470. bool strg = TastenStand[ T_Strg ];
  471. switch( te.taste )
  472. {
  473. case T_Entf:
  474. if( cpos != begf )
  475. text->remove( cpos, begf );
  476. else
  477. text->remove( cpos, cpos + 1 );
  478. begf = cpos;
  479. rend = 1;
  480. break;
  481. case T_BackSpace:
  482. if( cpos != begf )
  483. {
  484. text->remove( cpos, begf );
  485. if( cpos > begf )
  486. cpos -= cpos - begf;
  487. }
  488. else
  489. {
  490. text->remove( cpos - 1, cpos );
  491. --cpos;
  492. }
  493. begf = cpos;
  494. rend = 1;
  495. break;
  496. case T_Enter:
  497. if( cpos != begf )
  498. {
  499. text->remove( begf, cpos );
  500. if( cpos > begf )
  501. cpos -= cpos - begf;
  502. }
  503. text->insert( cpos, '\n' );
  504. ++cpos;
  505. begf = cpos;
  506. rend = 1;
  507. break;
  508. case T_Links:
  509. if( shift )
  510. {
  511. if( strg )
  512. begf = text->getLKick( begf );
  513. else
  514. --begf;
  515. }
  516. else
  517. {
  518. if( strg )
  519. cpos = text->getLKick( cpos );
  520. else
  521. --cpos;
  522. begf = cpos;
  523. }
  524. rend = 1;
  525. break;
  526. case T_Oben:
  527. if( shift )
  528. {
  529. begf = text->getOKick( begf );
  530. }
  531. else
  532. {
  533. cpos = text->getOKick( cpos );
  534. begf = cpos;
  535. }
  536. rend = 1;
  537. break;
  538. case T_Rechts:
  539. if( shift )
  540. {
  541. if( strg )
  542. begf = text->getRKick( begf );
  543. else
  544. ++begf;
  545. }
  546. else
  547. {
  548. if( strg )
  549. cpos = text->getRKick( cpos );
  550. else
  551. ++cpos;
  552. begf = cpos;
  553. }
  554. rend = 1;
  555. break;
  556. case T_Unten:
  557. if( shift )
  558. {
  559. begf = text->getUKick( begf );
  560. }
  561. else
  562. {
  563. cpos = text->getUKick( cpos );
  564. begf = cpos;
  565. }
  566. rend = 1;
  567. break;
  568. default:
  569. if( strg && te.id == TE_Press )
  570. {
  571. if( te.taste == 'c' || te.taste == 'C' )
  572. {
  573. if( begf != cpos )
  574. {
  575. int len = begf - cpos;
  576. if( len < 0 )
  577. len = -len;
  578. char *txt = new char[ len + 1 ];
  579. txt[ len ] = 0;
  580. int beg = begf < cpos ? begf : cpos;
  581. for( int i = beg; i < beg + len; ++i )
  582. txt[ i - beg ] = text->getText()[ i ];
  583. TextKopieren( txt );
  584. delete[] txt;
  585. }
  586. else
  587. TextKopieren( text->getText() );
  588. }
  589. if( te.taste == 'v' || te.taste == 'V' )
  590. {
  591. if( begf != cpos )
  592. {
  593. text->remove( begf, cpos );
  594. if( cpos > begf )
  595. cpos = begf;
  596. }
  597. char *txt = TextInsert();
  598. text->insert( cpos, txt );
  599. cpos += textLength( txt );
  600. begf = cpos;
  601. rend = 1;
  602. }
  603. break;
  604. }
  605. if( istSchreibbar( te.taste ) )
  606. {
  607. if( begf != cpos )
  608. {
  609. text->remove( begf, cpos );
  610. if( cpos > begf )
  611. cpos = begf;
  612. }
  613. text->insert( cpos, (char)te.taste );
  614. ++cpos;
  615. begf = cpos;
  616. rend = 1;
  617. }
  618. break;
  619. }
  620. }
  621. if( cpos < 0 )
  622. cpos = 0;
  623. if( cpos > text->getLength() )
  624. cpos = text->getLength();
  625. if( begf < 0 )
  626. begf = 0;
  627. if( begf > text->getLength() )
  628. begf = text->getLength();
  629. if( hatStyle( Style::VScroll ) )
  630. updateVScroll( begf );
  631. if( hatStyle( Style::HScroll ) )
  632. updateHScroll( begf );
  633. te.verarbeitet = 1;
  634. }
  635. --ref;
  636. if( ntakc && te.verarbeitet && nTak )
  637. te.verarbeitet = nTak( ntakParam, this, te );
  638. if( !ref )
  639. delete this;
  640. }
  641. void TextFeld::render( Bild &zRObj ) // zeichenet nach zRObj
  642. {
  643. if( hatStyleNicht( Style::Sichtbar ) )
  644. return;
  645. ZeichnungHintergrund::render( zRObj );
  646. if( !text || !schrift )
  647. return;
  648. lockZeichnung();
  649. if( !zRObj.setDrawOptions( innenPosition, innenSize ) )
  650. {
  651. unlockZeichnung();
  652. return;
  653. }
  654. if( hatStyleNicht( Style::Mehrzeilig ) )
  655. text->remove( '\n' );
  656. if( hatStyleNicht( Style::Mehrfarbig ) )
  657. {
  658. while( text->hat( '\r' ) )
  659. text->remove( text->positionVon( '\r' ), text->positionVon( '\r' ) + 11 );
  660. }
  661. schrift->setSchriftSize( schriftSize );
  662. int tbr = schrift->getTextBreite( text );
  663. int thi = schrift->getTextHeight( text );
  664. int xxx = 0;
  665. int yyy = 0;
  666. int breite = innenSize.x;
  667. int height = innenSize.y;
  668. bool hs = horizontalScrollBar && hatStyle( Style::HScroll );
  669. bool vs = vertikalScrollBar && hatStyle( Style::VScroll );
  670. if( vs )
  671. yyy -= vertikalScrollBar->getScroll();
  672. if( hs )
  673. xxx -= horizontalScrollBar->getScroll();
  674. if( hatStyle( Style::HCenter ) && !hs )
  675. xxx = ( breite / 2 ) - tbr / 2;
  676. if( hatStyle( Style::VCenter ) && !vs )
  677. yyy = ( height / 2 ) - thi / 2;
  678. schrift->setDrawPosition( xxx, yyy );
  679. if( hatStyle( Style::Fokus ) && hatStyle( Style::Erlaubt ) )
  680. {
  681. if( istSchreibbar( showChar ) )
  682. {
  683. Text rt;
  684. int len = text->getLength() - text->anzahlVon( '\n' ) - text->anzahlVon( '\r' ) * 11;
  685. rt.fillText( showChar, len );
  686. if( tickVal <= 0.5 )
  687. schrift->renderText( &rt, zRObj, cpos, 0xFFFF5555, begf, 0xFF0000FF, sF );
  688. else
  689. schrift->renderText( &rt, zRObj, cpos, 0x00000000, begf, 0xFF0000FF, sF );
  690. }
  691. else
  692. {
  693. if( tickVal <= 0.5 )
  694. schrift->renderText( text, zRObj, cpos, 0xFFFF5555, begf, 0xFF0000FF, sF );
  695. else
  696. schrift->renderText( text, zRObj, cpos, 0x00000000, begf, 0xFF0000FF, sF );
  697. }
  698. }
  699. else
  700. {
  701. if( istSchreibbar( showChar ) )
  702. {
  703. Text rt;
  704. int len = text->getLength() - text->anzahlVon( '\n' ) - text->anzahlVon( '\r' ) * 11;
  705. rt.fillText( showChar, len );
  706. schrift->renderText( &rt, zRObj, sF );
  707. }
  708. else
  709. schrift->renderText( text, zRObj, sF );
  710. }
  711. zRObj.releaseDrawOptions();
  712. unlockZeichnung();
  713. }
  714. // Konstant
  715. Text *TextFeld::getText() const // gibt vom Text zurück
  716. {
  717. if( !text )
  718. return 0;
  719. return text->getThis();
  720. }
  721. Text *TextFeld::zText() const // gibt den Text zurück
  722. {
  723. return text;
  724. }
  725. Schrift *TextFeld::getSchrift() const// gint getThis der Schrift Zurück
  726. {
  727. if( !schrift )
  728. return 0;
  729. return schrift->getThis();
  730. }
  731. Schrift *TextFeld::zSchrift() const// gibt die Schrift zurück
  732. {
  733. return schrift;
  734. }
  735. unsigned char TextFeld::getSchriftSize() const // gibt die Schriftgröße zurück
  736. {
  737. return schriftSize;
  738. }
  739. int TextFeld::getSchriftFarbe() const// gibt getThis der Schriftfarbe zurück
  740. {
  741. return sF;
  742. }
  743. unsigned char TextFeld::getShowChar() const // gibt den Anzeige Char zurück
  744. {
  745. return showChar;
  746. }
  747. int TextFeld::getCursorPos() const
  748. {
  749. return cpos;
  750. }
  751. int TextFeld::getSelectionPos() const
  752. {
  753. return begf;
  754. }
  755. Zeichnung *TextFeld::dublizieren() const // Erzeugt eine Kopie des Zeichnungs
  756. {
  757. TextFeld *obj = new TextFeld();
  758. obj->setPosition( pos );
  759. obj->setSize( gr );
  760. obj->setMausEreignisParameter( makParam );
  761. obj->setTastaturEreignisParameter( takParam );
  762. obj->setMausEreignis( mak );
  763. obj->setTastaturEreignis( tak );
  764. if( toolTip )
  765. obj->setToolTipText( toolTip->zText()->getText(), toolTip->zBildschirm() );
  766. obj->setStyle( style );
  767. obj->setSchriftSize( schriftSize );
  768. if( schrift )
  769. obj->setSchriftZ( schrift->getThis() );
  770. if( text )
  771. obj->setText( text->getText() );
  772. obj->setHintergrundFarbe( hintergrundFarbe );
  773. obj->setSchriftFarbe( sF );
  774. if( hintergrundFeld )
  775. obj->setAlphaFeldZ( (AlphaFeld*)hintergrundFeld->dublizieren() );
  776. if( rahmen )
  777. obj->setRahmenZ( (Rahmen*)rahmen->dublizieren() );
  778. if( hintergrundBild )
  779. obj->setHintergrundBild( hintergrundBild->getThis() );
  780. if( vertikalScrollBar )
  781. {
  782. obj->setVertikalKlickScroll( vertikalScrollBar->getKlickScroll() );
  783. obj->setVertikalScrollPos( vertikalScrollBar->getScroll() );
  784. obj->setVertikalScrollFarbe( vertikalScrollBar->getFarbe(), vertikalScrollBar->getBgFarbe() );
  785. }
  786. if( horizontalScrollBar )
  787. {
  788. obj->setHorizontalKlickScroll( horizontalScrollBar->getKlickScroll() );
  789. obj->setHorizontalScrollPos( horizontalScrollBar->getScroll() );
  790. obj->setHorizontalScrollFarbe( horizontalScrollBar->getFarbe(), horizontalScrollBar->getBgFarbe() );
  791. }
  792. obj->setSchowChar( showChar );
  793. obj->setAuswahl( begf, cpos );
  794. return obj;
  795. }
  796. // Reference Counting
  797. TextFeld *TextFeld::getThis()
  798. {
  799. ++ref;
  800. return this;
  801. }
  802. TextFeld *TextFeld::release()
  803. {
  804. --ref;
  805. if( ref == 0 )
  806. delete this;
  807. return 0;
  808. }