TextControls.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*
  2. * TextControls.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "TextControls.h"
  12. #include "Buttons.h"
  13. #include "Images.h"
  14. #include "../CMessage.h"
  15. #include "../CPlayerInterface.h"
  16. #include "../gui/CGuiHandler.h"
  17. #include "../widgets/AdventureMapClasses.h"
  18. #include "../../lib/CGeneralTextHandler.h" //for Unicode related stuff
  19. #ifdef VCMI_ANDROID
  20. #include "lib/CAndroidVMHelper.h"
  21. #endif
  22. #include <SDL_events.h>
  23. std::string CLabel::visibleText()
  24. {
  25. return text;
  26. }
  27. void CLabel::showAll(SDL_Surface * to)
  28. {
  29. CIntObject::showAll(to);
  30. if(!visibleText().empty())
  31. blitLine(to, pos, visibleText());
  32. }
  33. CLabel::CLabel(int x, int y, EFonts Font, ETextAlignment Align, const SDL_Color & Color, const std::string & Text)
  34. : CTextContainer(Align, Font, Color), text(Text)
  35. {
  36. type |= REDRAW_PARENT;
  37. autoRedraw = true;
  38. pos.x += x;
  39. pos.y += y;
  40. pos.w = pos.h = 0;
  41. if(alignment == ETextAlignment::TOPLEFT) // causes issues for MIDDLE
  42. {
  43. pos.w = (int)graphics->fonts[font]->getStringWidth(visibleText().c_str());
  44. pos.h = (int)graphics->fonts[font]->getLineHeight();
  45. }
  46. }
  47. Point CLabel::getBorderSize()
  48. {
  49. return Point(0, 0);
  50. }
  51. std::string CLabel::getText()
  52. {
  53. return text;
  54. }
  55. void CLabel::setAutoRedraw(bool value)
  56. {
  57. autoRedraw = value;
  58. }
  59. void CLabel::setText(const std::string & Txt)
  60. {
  61. text = Txt;
  62. if(autoRedraw)
  63. {
  64. if(background || !parent)
  65. redraw();
  66. else
  67. parent->redraw();
  68. }
  69. }
  70. void CLabel::setColor(const SDL_Color & Color)
  71. {
  72. color = Color;
  73. if(autoRedraw)
  74. {
  75. if(background || !parent)
  76. redraw();
  77. else
  78. parent->redraw();
  79. }
  80. }
  81. size_t CLabel::getWidth()
  82. {
  83. return graphics->fonts[font]->getStringWidth(visibleText());;
  84. }
  85. CMultiLineLabel::CMultiLineLabel(Rect position, EFonts Font, ETextAlignment Align, const SDL_Color & Color, const std::string & Text) :
  86. CLabel(position.x, position.y, Font, Align, Color, Text),
  87. visibleSize(0, 0, position.w, position.h)
  88. {
  89. pos.w = position.w;
  90. pos.h = position.h;
  91. splitText(Text, true);
  92. }
  93. void CMultiLineLabel::setVisibleSize(Rect visibleSize, bool redrawElement)
  94. {
  95. this->visibleSize = visibleSize;
  96. if(redrawElement)
  97. redraw();
  98. }
  99. void CMultiLineLabel::scrollTextBy(int distance)
  100. {
  101. scrollTextTo(visibleSize.y + distance);
  102. }
  103. void CMultiLineLabel::scrollTextTo(int distance, bool redrawAfterScroll)
  104. {
  105. Rect size = visibleSize;
  106. size.y = distance;
  107. setVisibleSize(size, redrawAfterScroll);
  108. }
  109. void CMultiLineLabel::setText(const std::string & Txt)
  110. {
  111. splitText(Txt, false); //setText used below can handle redraw
  112. CLabel::setText(Txt);
  113. }
  114. void CTextContainer::blitLine(SDL_Surface * to, Rect destRect, std::string what)
  115. {
  116. const auto f = graphics->fonts[font];
  117. Point where = destRect.topLeft();
  118. // input is rect in which given text should be placed
  119. // calculate proper position for top-left corner of the text
  120. if(alignment == ETextAlignment::TOPLEFT)
  121. {
  122. where.x += getBorderSize().x;
  123. where.y += getBorderSize().y;
  124. }
  125. if(alignment == ETextAlignment::CENTER)
  126. {
  127. where.x += (int(destRect.w) - int(f->getStringWidth(what))) / 2;
  128. where.y += (int(destRect.h) - int(f->getLineHeight())) / 2;
  129. }
  130. if(alignment == ETextAlignment::BOTTOMRIGHT)
  131. {
  132. where.x += getBorderSize().x + destRect.w - (int)f->getStringWidth(what);
  133. where.y += getBorderSize().y + destRect.h - (int)f->getLineHeight();
  134. }
  135. size_t begin = 0;
  136. std::string delimeters = "{}";
  137. size_t currDelimeter = 0;
  138. do
  139. {
  140. size_t end = what.find_first_of(delimeters[currDelimeter % 2], begin);
  141. if(begin != end)
  142. {
  143. std::string toPrint = what.substr(begin, end - begin);
  144. if(currDelimeter % 2) // Enclosed in {} text - set to yellow
  145. f->renderTextLeft(to, toPrint, Colors::YELLOW, where);
  146. else // Non-enclosed text, use default color
  147. f->renderTextLeft(to, toPrint, color, where);
  148. begin = end;
  149. where.x += (int)f->getStringWidth(toPrint);
  150. }
  151. currDelimeter++;
  152. } while(begin++ != std::string::npos);
  153. }
  154. CTextContainer::CTextContainer(ETextAlignment alignment, EFonts font, SDL_Color color) :
  155. alignment(alignment),
  156. font(font),
  157. color(color)
  158. {
  159. }
  160. void CMultiLineLabel::showAll(SDL_Surface * to)
  161. {
  162. CIntObject::showAll(to);
  163. const auto f = graphics->fonts[font];
  164. // calculate which lines should be visible
  165. int totalLines = static_cast<int>(lines.size());
  166. int beginLine = visibleSize.y;
  167. int endLine = getTextLocation().h + visibleSize.y;
  168. if(beginLine < 0)
  169. beginLine = 0;
  170. else
  171. beginLine /= (int)f->getLineHeight();
  172. if(endLine < 0)
  173. endLine = 0;
  174. else
  175. endLine /= (int)f->getLineHeight();
  176. endLine++;
  177. // and where they should be displayed
  178. Point lineStart = getTextLocation().topLeft() - visibleSize + Point(0, beginLine * (int)f->getLineHeight());
  179. Point lineSize = Point(getTextLocation().w, (int)f->getLineHeight());
  180. CSDL_Ext::CClipRectGuard guard(to, getTextLocation()); // to properly trim text that is too big to fit
  181. for(int i = beginLine; i < std::min(totalLines, endLine); i++)
  182. {
  183. if(!lines[i].empty()) //non-empty line
  184. blitLine(to, Rect(lineStart, lineSize), lines[i]);
  185. lineStart.y += (int)f->getLineHeight();
  186. }
  187. }
  188. void CMultiLineLabel::splitText(const std::string & Txt, bool redrawAfter)
  189. {
  190. lines.clear();
  191. const auto f = graphics->fonts[font];
  192. int lineHeight = static_cast<int>(f->getLineHeight());
  193. lines = CMessage::breakText(Txt, pos.w, font);
  194. textSize.y = lineHeight * (int)lines.size();
  195. textSize.x = 0;
  196. for(const std::string & line : lines)
  197. vstd::amax(textSize.x, f->getStringWidth(line.c_str()));
  198. if(redrawAfter)
  199. redraw();
  200. }
  201. Rect CMultiLineLabel::getTextLocation()
  202. {
  203. // this method is needed for vertical alignment alignment of text
  204. // when height of available text is smaller than height of widget
  205. // in this case - we should add proper offset to display text at required position
  206. if(pos.h <= textSize.y)
  207. return pos;
  208. Point textSize(pos.w, (int)graphics->fonts[font]->getLineHeight() * (int)lines.size());
  209. Point textOffset(pos.w - textSize.x, pos.h - textSize.y);
  210. switch(alignment)
  211. {
  212. case ETextAlignment::TOPLEFT: return Rect(pos.topLeft(), textSize);
  213. case ETextAlignment::CENTER: return Rect(pos.topLeft() + textOffset / 2, textSize);
  214. case ETextAlignment::BOTTOMRIGHT: return Rect(pos.topLeft() + textOffset, textSize);
  215. }
  216. assert(0);
  217. return Rect();
  218. }
  219. CLabelGroup::CLabelGroup(EFonts Font, ETextAlignment Align, const SDL_Color & Color)
  220. : font(Font), align(Align), color(Color)
  221. {
  222. defActions = 255 - DISPOSE;
  223. }
  224. void CLabelGroup::add(int x, int y, const std::string & text)
  225. {
  226. OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
  227. labels.push_back(std::make_shared<CLabel>(x, y, font, align, color, text));
  228. }
  229. size_t CLabelGroup::currentSize() const
  230. {
  231. return labels.size();
  232. }
  233. CTextBox::CTextBox(std::string Text, const Rect & rect, int SliderStyle, EFonts Font, ETextAlignment Align, const SDL_Color & Color) :
  234. sliderStyle(SliderStyle),
  235. slider(nullptr)
  236. {
  237. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  238. label = std::make_shared<CMultiLineLabel>(rect, Font, Align, Color);
  239. type |= REDRAW_PARENT;
  240. pos.x += rect.x;
  241. pos.y += rect.y;
  242. pos.h = rect.h;
  243. pos.w = rect.w;
  244. assert(pos.w >= 40); //we need some space
  245. setText(Text);
  246. }
  247. void CTextBox::sliderMoved(int to)
  248. {
  249. label->scrollTextTo(to);
  250. }
  251. void CTextBox::resize(Point newSize)
  252. {
  253. pos.w = newSize.x;
  254. pos.h = newSize.y;
  255. label->pos.w = pos.w;
  256. label->pos.h = pos.h;
  257. slider.reset();
  258. setText(label->getText()); // force refresh
  259. }
  260. void CTextBox::setText(const std::string & text)
  261. {
  262. label->pos.w = pos.w; // reset to default before textSize.y check
  263. label->setText(text);
  264. if(label->textSize.y <= label->pos.h && slider)
  265. {
  266. // slider is no longer needed
  267. slider.reset();
  268. }
  269. else if(slider)
  270. {
  271. // decrease width again if slider still used
  272. label->pos.w = pos.w - 32;
  273. label->setText(text);
  274. slider->setAmount(label->textSize.y);
  275. }
  276. else if(label->textSize.y > label->pos.h)
  277. {
  278. // create slider and update widget
  279. label->pos.w = pos.w - 32;
  280. label->setText(text);
  281. OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
  282. slider = std::make_shared<CSlider>(Point(pos.w - 32, 0), pos.h, std::bind(&CTextBox::sliderMoved, this, _1),
  283. label->pos.h, label->textSize.y, 0, false, CSlider::EStyle(sliderStyle));
  284. slider->setScrollStep((int)graphics->fonts[label->font]->getLineHeight());
  285. }
  286. }
  287. void CGStatusBar::setEnteringMode(bool on)
  288. {
  289. consoleText.clear();
  290. if (on)
  291. {
  292. assert(enteringText == false);
  293. alignment = ETextAlignment::TOPLEFT;
  294. CSDL_Ext::startTextInput(pos);
  295. setText(consoleText);
  296. }
  297. else
  298. {
  299. assert(enteringText == true);
  300. alignment = ETextAlignment::CENTER;
  301. CSDL_Ext::stopTextInput();
  302. setText(hoverText);
  303. }
  304. enteringText = on;
  305. }
  306. void CGStatusBar::setEnteredText(const std::string & text)
  307. {
  308. assert(enteringText == true);
  309. consoleText = text;
  310. setText(text);
  311. }
  312. void CGStatusBar::write(const std::string & Text)
  313. {
  314. hoverText = Text;
  315. if (enteringText == false)
  316. setText(hoverText);
  317. }
  318. void CGStatusBar::clearIfMatching(const std::string & Text)
  319. {
  320. if (hoverText == Text)
  321. clear();
  322. }
  323. void CGStatusBar::clear()
  324. {
  325. write({});
  326. }
  327. CGStatusBar::CGStatusBar(std::shared_ptr<CPicture> background_, EFonts Font, ETextAlignment Align, const SDL_Color & Color)
  328. : CLabel(background_->pos.x, background_->pos.y, Font, Align, Color, "")
  329. , enteringText(false)
  330. {
  331. addUsedEvents(LCLICK);
  332. background = background_;
  333. addChild(background.get());
  334. pos = background->pos;
  335. getBorderSize();
  336. autoRedraw = false;
  337. }
  338. CGStatusBar::CGStatusBar(int x, int y, std::string name, int maxw)
  339. : CLabel(x, y, FONT_SMALL, ETextAlignment::CENTER)
  340. , enteringText(false)
  341. {
  342. addUsedEvents(LCLICK);
  343. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  344. background = std::make_shared<CPicture>(name);
  345. pos = background->pos;
  346. if((unsigned)maxw < (unsigned)pos.w) //(insigned)-1 > than any correct value of pos.w
  347. {
  348. //execution of this block when maxw is incorrect breaks text centralization (issue #3151)
  349. vstd::amin(pos.w, maxw);
  350. background->srcRect = Rect(0, 0, maxw, pos.h);
  351. }
  352. autoRedraw = false;
  353. }
  354. void CGStatusBar::show(SDL_Surface * to)
  355. {
  356. showAll(to);
  357. }
  358. void CGStatusBar::init()
  359. {
  360. GH.statusbar = shared_from_this();
  361. }
  362. void CGStatusBar::clickLeft(tribool down, bool previousState)
  363. {
  364. if(!down)
  365. {
  366. if(LOCPLINT && LOCPLINT->cingconsole->active)
  367. LOCPLINT->cingconsole->startEnteringText();
  368. }
  369. }
  370. void CGStatusBar::deactivate()
  371. {
  372. if (enteringText)
  373. LOCPLINT->cingconsole->endEnteringText(false);
  374. CIntObject::deactivate();
  375. }
  376. Point CGStatusBar::getBorderSize()
  377. {
  378. //Width of borders where text should not be printed
  379. static const Point borderSize(5, 1);
  380. switch(alignment)
  381. {
  382. case ETextAlignment::TOPLEFT: return Point(borderSize.x, borderSize.y);
  383. case ETextAlignment::CENTER: return Point(pos.w / 2, pos.h / 2);
  384. case ETextAlignment::BOTTOMRIGHT: return Point(pos.w - borderSize.x, pos.h - borderSize.y);
  385. }
  386. assert(0);
  387. return Point();
  388. }
  389. CTextInput::CTextInput(const Rect & Pos, EFonts font, const CFunctionList<void(const std::string &)> & CB)
  390. : CLabel(Pos.x, Pos.y, font, ETextAlignment::CENTER),
  391. cb(CB),
  392. CFocusable(std::make_shared<CKeyboardFocusListener>(this))
  393. {
  394. type |= REDRAW_PARENT;
  395. pos.h = Pos.h;
  396. pos.w = Pos.w;
  397. captureAllKeys = true;
  398. background.reset();
  399. addUsedEvents(LCLICK | KEYBOARD | TEXTINPUT);
  400. #if !(defined(VCMI_ANDROID) || defined(VCMI_IOS))
  401. giveFocus();
  402. #endif
  403. }
  404. CTextInput::CTextInput(const Rect & Pos, const Point & bgOffset, const std::string & bgName, const CFunctionList<void(const std::string &)> & CB)
  405. :cb(CB), CFocusable(std::make_shared<CKeyboardFocusListener>(this))
  406. {
  407. pos += Pos.topLeft();
  408. pos.h = Pos.h;
  409. pos.w = Pos.w;
  410. captureAllKeys = true;
  411. OBJ_CONSTRUCTION;
  412. background = std::make_shared<CPicture>(bgName, bgOffset.x, bgOffset.y);
  413. addUsedEvents(LCLICK | KEYBOARD | TEXTINPUT);
  414. #if !(defined(VCMI_ANDROID) || defined(VCMI_IOS))
  415. giveFocus();
  416. #endif
  417. }
  418. CTextInput::CTextInput(const Rect & Pos, std::shared_ptr<IImage> srf)
  419. :CFocusable(std::make_shared<CKeyboardFocusListener>(this))
  420. {
  421. pos += Pos.topLeft();
  422. captureAllKeys = true;
  423. OBJ_CONSTRUCTION;
  424. background = std::make_shared<CPicture>(srf, Pos);
  425. pos.w = background->pos.w;
  426. pos.h = background->pos.h;
  427. background->pos = pos;
  428. addUsedEvents(LCLICK | KEYBOARD | TEXTINPUT);
  429. #if !(defined(VCMI_ANDROID) || defined(VCMI_IOS))
  430. giveFocus();
  431. #endif
  432. }
  433. std::atomic<int> CKeyboardFocusListener::usageIndex(0);
  434. CKeyboardFocusListener::CKeyboardFocusListener(CTextInput * textInput)
  435. :textInput(textInput)
  436. {
  437. }
  438. void CKeyboardFocusListener::focusGot()
  439. {
  440. CSDL_Ext::startTextInput(textInput->pos);
  441. usageIndex++;
  442. }
  443. void CKeyboardFocusListener::focusLost()
  444. {
  445. if(0 == --usageIndex)
  446. {
  447. CSDL_Ext::stopTextInput();
  448. }
  449. }
  450. std::string CTextInput::visibleText()
  451. {
  452. return focus ? text + newText + "_" : text;
  453. }
  454. void CTextInput::clickLeft(tribool down, bool previousState)
  455. {
  456. if(down && !focus)
  457. giveFocus();
  458. }
  459. void CTextInput::keyPressed(const SDL_KeyboardEvent & key)
  460. {
  461. if(!focus || key.state != SDL_PRESSED)
  462. return;
  463. if(key.keysym.sym == SDLK_TAB)
  464. {
  465. moveFocus();
  466. GH.breakEventHandling();
  467. return;
  468. }
  469. bool redrawNeeded = false;
  470. switch(key.keysym.sym)
  471. {
  472. case SDLK_DELETE: // have index > ' ' so it won't be filtered out by default section
  473. return;
  474. case SDLK_BACKSPACE:
  475. if(!newText.empty())
  476. {
  477. Unicode::trimRight(newText);
  478. redrawNeeded = true;
  479. }
  480. else if(!text.empty())
  481. {
  482. Unicode::trimRight(text);
  483. redrawNeeded = true;
  484. }
  485. break;
  486. default:
  487. break;
  488. }
  489. if(redrawNeeded)
  490. {
  491. redraw();
  492. cb(text);
  493. }
  494. }
  495. void CTextInput::setText(const std::string & nText)
  496. {
  497. setText(nText, false);
  498. }
  499. void CTextInput::setText(const std::string & nText, bool callCb)
  500. {
  501. CLabel::setText(nText);
  502. if(callCb)
  503. cb(text);
  504. }
  505. bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key)
  506. {
  507. if(key.keysym.sym == SDLK_RETURN || key.keysym.sym == SDLK_KP_ENTER || key.keysym.sym == SDLK_ESCAPE)
  508. return false;
  509. return true;
  510. }
  511. void CTextInput::textInputed(const SDL_TextInputEvent & event)
  512. {
  513. if(!focus)
  514. return;
  515. std::string oldText = text;
  516. text += event.text;
  517. filters(text, oldText);
  518. if(text != oldText)
  519. {
  520. redraw();
  521. cb(text);
  522. }
  523. newText.clear();
  524. }
  525. void CTextInput::textEdited(const SDL_TextEditingEvent & event)
  526. {
  527. if(!focus)
  528. return;
  529. newText = event.text;
  530. redraw();
  531. cb(text + newText);
  532. }
  533. void CTextInput::filenameFilter(std::string & text, const std::string &)
  534. {
  535. static const std::string forbiddenChars = "<>:\"/\\|?*\r\n"; //if we are entering a filename, some special characters won't be allowed
  536. size_t pos;
  537. while((pos = text.find_first_of(forbiddenChars)) != std::string::npos)
  538. text.erase(pos, 1);
  539. }
  540. void CTextInput::numberFilter(std::string & text, const std::string & oldText, int minValue, int maxValue)
  541. {
  542. assert(minValue < maxValue);
  543. if(text.empty())
  544. text = "0";
  545. size_t pos = 0;
  546. if(text[0] == '-') //allow '-' sign as first symbol only
  547. pos++;
  548. while(pos < text.size())
  549. {
  550. if(text[pos] < '0' || text[pos] > '9')
  551. {
  552. text = oldText;
  553. return; //new text is not number.
  554. }
  555. pos++;
  556. }
  557. try
  558. {
  559. int value = boost::lexical_cast<int>(text);
  560. if(value < minValue)
  561. text = boost::lexical_cast<std::string>(minValue);
  562. else if(value > maxValue)
  563. text = boost::lexical_cast<std::string>(maxValue);
  564. }
  565. catch(boost::bad_lexical_cast &)
  566. {
  567. //Should never happen. Unless I missed some cases
  568. logGlobal->warn("Warning: failed to convert %s to number!", text);
  569. text = oldText;
  570. }
  571. }
  572. CFocusable::CFocusable()
  573. :CFocusable(std::make_shared<IFocusListener>())
  574. {
  575. }
  576. CFocusable::CFocusable(std::shared_ptr<IFocusListener> focusListener)
  577. : focusListener(focusListener)
  578. {
  579. focus = false;
  580. focusables.push_back(this);
  581. }
  582. CFocusable::~CFocusable()
  583. {
  584. if(hasFocus())
  585. {
  586. inputWithFocus = nullptr;
  587. focusListener->focusLost();
  588. }
  589. focusables -= this;
  590. }
  591. bool CFocusable::hasFocus() const
  592. {
  593. return inputWithFocus == this;
  594. }
  595. void CFocusable::giveFocus()
  596. {
  597. focus = true;
  598. focusListener->focusGot();
  599. redraw();
  600. if(inputWithFocus)
  601. {
  602. inputWithFocus->focus = false;
  603. inputWithFocus->focusListener->focusLost();
  604. inputWithFocus->redraw();
  605. }
  606. inputWithFocus = this;
  607. }
  608. void CFocusable::moveFocus()
  609. {
  610. auto i = vstd::find(focusables, this),
  611. ourIt = i;
  612. for(i++; i != ourIt; i++)
  613. {
  614. if(i == focusables.end())
  615. i = focusables.begin();
  616. if((*i)->active)
  617. {
  618. (*i)->giveFocus();
  619. break;
  620. }
  621. }
  622. }