TextFeld.cpp 21 KB

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