TextControls.cpp 16 KB

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