UIWidget.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. //--player --editor-resource-paths "/Users/josh/Dev/atomic/AtomicGameEngine/Data/AtomicPlayer/Resources/CoreData!/Users/josh/Dev/atomic/AtomicGameEngine/Data/AtomicPlayer/Resources/PlayerData!/Users/josh/Dev/atomic/AtomicExamples/UIExample/Resources"
  23. #include "../IO/Log.h"
  24. #include "../Input/InputEvents.h"
  25. #include "UIEvents.h"
  26. #include "UI.h"
  27. #include "UIWidget.h"
  28. #include "UILayout.h"
  29. #include "UIFontDescription.h"
  30. #include "UIView.h"
  31. using namespace tb;
  32. namespace Atomic
  33. {
  34. UIWidget::UIWidget(Context* context, bool createWidget) : Object(context),
  35. widget_(0),
  36. preferredSize_(new UIPreferredSize()),
  37. multiTouch_(false)
  38. {
  39. AddRef();
  40. if (createWidget)
  41. {
  42. widget_ = new TBWidget();
  43. widget_->SetDelegate(this);
  44. GetSubsystem<UI>()->WrapWidget(this, widget_);
  45. }
  46. }
  47. UIWidget::~UIWidget()
  48. {
  49. }
  50. void UIWidget::SetIsFocusable(bool value)
  51. {
  52. if (!widget_)
  53. return;
  54. widget_->SetIsFocusable(value);
  55. }
  56. bool UIWidget::Load(const String& filename)
  57. {
  58. UI* ui = GetSubsystem<UI>();
  59. if (!ui->LoadResourceFile(widget_ , filename))
  60. return false;
  61. VariantMap eventData;
  62. eventData[WidgetLoaded::P_WIDGET] = this;
  63. SendEvent(E_WIDGETLOADED, eventData);
  64. return true;
  65. }
  66. UIPreferredSize* UIWidget::GetPreferredSize()
  67. {
  68. // error
  69. if (!widget_)
  70. return preferredSize_;
  71. preferredSize_->SetFromTBPreferredSize(widget_->GetPreferredSize());
  72. return preferredSize_;
  73. }
  74. UIWidget* UIWidget::GetWidget(const String& id)
  75. {
  76. if (!widget_)
  77. return 0;
  78. TBWidget* child = widget_->GetWidgetByID(TBID(id.CString()));
  79. if (!child)
  80. return 0;
  81. UI* ui = GetSubsystem<UI>();
  82. return ui->WrapWidget(child);
  83. }
  84. void UIWidget::SetWidget(tb::TBWidget* widget)
  85. {
  86. widget_ = widget;
  87. widget_->SetDelegate(this);
  88. }
  89. /*
  90. enum SPECIAL_KEY
  91. {
  92. TB_KEY_UNDEFINED = 0,
  93. TB_KEY_UP, TB_KEY_DOWN, TB_KEY_LEFT, TB_KEY_RIGHT,
  94. TB_KEY_PAGE_UP, TB_KEY_PAGE_DOWN, TB_KEY_HOME, TB_KEY_END,
  95. TB_KEY_TAB, TB_KEY_BACKSPACE, TB_KEY_INSERT, TB_KEY_DELETE,
  96. TB_KEY_ENTER, TB_KEY_ESC,
  97. TB_KEY_F1, TB_KEY_F2, TB_KEY_F3, TB_KEY_F4, TB_KEY_F5, TB_KEY_F6,
  98. TB_KEY_F7, TB_KEY_F8, TB_KEY_F9, TB_KEY_F10, TB_KEY_F11, TB_KEY_F12
  99. };
  100. */
  101. void UIWidget::ConvertEvent(UIWidget *handler, UIWidget* target, const tb::TBWidgetEvent &ev, VariantMap& data)
  102. {
  103. UI* ui = GetSubsystem<UI>();
  104. String refid;
  105. ui->GetTBIDString(ev.ref_id, refid);
  106. int key = ev.key;
  107. if (ev.special_key)
  108. {
  109. switch (ev.special_key)
  110. {
  111. case TB_KEY_ENTER:
  112. key = KEY_RETURN;
  113. break;
  114. case TB_KEY_BACKSPACE:
  115. key = KEY_BACKSPACE;
  116. break;
  117. case TB_KEY_DELETE:
  118. key = KEY_DELETE;
  119. break;
  120. case TB_KEY_DOWN:
  121. key = KEY_DOWN;
  122. break;
  123. case TB_KEY_UP:
  124. key = KEY_UP;
  125. break;
  126. case TB_KEY_LEFT:
  127. key = KEY_LEFT;
  128. break;
  129. case TB_KEY_RIGHT:
  130. key = KEY_RIGHT;
  131. break;
  132. default:
  133. break;
  134. }
  135. }
  136. unsigned modifierKeys = 0;
  137. if( ev.special_key && TB_SHIFT)
  138. modifierKeys |= QUAL_SHIFT;
  139. if( ev.special_key && TB_CTRL)
  140. modifierKeys |= QUAL_CTRL;
  141. if( ev.special_key && TB_ALT)
  142. modifierKeys |= QUAL_ALT;
  143. using namespace WidgetEvent;
  144. data[P_HANDLER] = handler;
  145. data[P_TARGET] = target;
  146. data[P_TYPE] = (unsigned) ev.type;
  147. data[P_X] = ev.target_x;
  148. data[P_Y] = ev.target_y;
  149. data[P_DELTAX] = ev.delta_x;
  150. data[P_DELTAY] = ev.delta_y;
  151. data[P_COUNT] = ev.count;
  152. data[P_KEY] = key;
  153. data[P_SPECIALKEY] = (unsigned) ev.special_key;
  154. data[P_MODIFIERKEYS] = modifierKeys;
  155. data[P_REFID] = refid;
  156. data[P_TOUCH] = (unsigned) ev.touch;
  157. }
  158. void UIWidget::OnDelete()
  159. {
  160. if (widget_)
  161. {
  162. // if we don't have a UI subsystem, we are exiting
  163. UI* ui = GetSubsystem<UI>();
  164. if (ui)
  165. ui->UnwrapWidget(widget_);
  166. }
  167. widget_ = 0;
  168. VariantMap eventData;
  169. eventData[WidgetDeleted::P_WIDGET] = this;
  170. SendEvent(E_WIDGETDELETED, eventData);
  171. UnsubscribeFromAllEvents();
  172. ReleaseRef();
  173. }
  174. void UIWidget::AddChildAfter(UIWidget* child, UIWidget* otherChild)
  175. {
  176. if (!widget_ || !child || !child->widget_ || !otherChild || !otherChild->widget_)
  177. return;
  178. widget_->AddChildRelative(child->widget_, tb::WIDGET_Z_REL_AFTER, otherChild->widget_);
  179. }
  180. void UIWidget::AddChildBefore(UIWidget* child, UIWidget* otherChild)
  181. {
  182. if (!widget_ || !child || !child->widget_ || !otherChild || !otherChild->widget_)
  183. return;
  184. widget_->AddChildRelative(child->widget_, tb::WIDGET_Z_REL_BEFORE, otherChild->widget_);
  185. }
  186. void UIWidget::AddChild(UIWidget* child)
  187. {
  188. if (!widget_ || !child || !child->widget_)
  189. return;
  190. widget_->AddChild(child->widget_);
  191. }
  192. void UIWidget::AddChildRelative(UIWidget* child, UI_WIDGET_Z_REL z, UIWidget* reference)
  193. {
  194. if (!widget_ || !child || !child->widget_ || !reference || !reference->widget_)
  195. return;
  196. widget_->AddChildRelative(child->widget_, (WIDGET_Z_REL) z, reference->widget_);
  197. }
  198. String UIWidget::GetText()
  199. {
  200. if (!widget_)
  201. return String::EMPTY;
  202. return widget_->GetText().CStr();
  203. }
  204. void UIWidget::SetText(const String& text)
  205. {
  206. if (!widget_)
  207. return;
  208. widget_->SetText(text.CString());
  209. }
  210. void UIWidget::SetGravity(UI_GRAVITY gravity)
  211. {
  212. if (!widget_)
  213. return;
  214. widget_->SetGravity((WIDGET_GRAVITY) gravity);
  215. }
  216. void UIWidget::SetAxis(UI_AXIS axis)
  217. {
  218. if (!widget_)
  219. return;
  220. widget_->SetAxis((AXIS) axis);
  221. }
  222. bool UIWidget::IsAncestorOf(UIWidget* widget)
  223. {
  224. if (!widget_ || !widget || !widget->widget_)
  225. return false;
  226. return widget_->IsAncestorOf(widget->widget_);
  227. }
  228. void UIWidget::SetPosition(int x, int y)
  229. {
  230. if (!widget_)
  231. return;
  232. widget_->SetPosition(TBPoint(x, y));
  233. }
  234. IntRect UIWidget::GetRect()
  235. {
  236. IntRect rect(0, 0, 0, 0);
  237. if (!widget_)
  238. return rect;
  239. tb::TBRect tbrect = widget_->GetRect();
  240. rect.top_ = tbrect.y;
  241. rect.left_ = tbrect.x;
  242. rect.right_ = tbrect.x + tbrect.w;
  243. rect.bottom_ = tbrect.y + tbrect.h;
  244. return rect;
  245. }
  246. void UIWidget::SetRect(IntRect rect)
  247. {
  248. if (!widget_)
  249. return;
  250. tb::TBRect tbrect;
  251. tbrect.y = rect.top_;
  252. tbrect.x = rect.left_;
  253. tbrect.w = rect.right_ - rect.left_;
  254. tbrect.h = rect.bottom_ - rect.top_;
  255. widget_->SetRect(tbrect);
  256. }
  257. void UIWidget::SetSize(int width, int height)
  258. {
  259. if (!widget_)
  260. return;
  261. widget_->SetSize(width, height);
  262. }
  263. void UIWidget::Invalidate()
  264. {
  265. if (!widget_)
  266. return;
  267. widget_->Invalidate();
  268. }
  269. void UIWidget::Center()
  270. {
  271. if (!widget_)
  272. return;
  273. TBRect rect = widget_->GetRect();
  274. TBWidget* root = widget_->GetParent();
  275. if (!root)
  276. {
  277. UI* ui = GetSubsystem<UI>();
  278. root = ui->GetRootWidget();
  279. }
  280. TBRect bounds(0, 0, root->GetRect().w, root->GetRect().h);
  281. widget_->SetRect(rect.CenterIn(bounds).MoveIn(bounds).Clip(bounds));
  282. }
  283. UIWidget* UIWidget::GetParent()
  284. {
  285. if (!widget_)
  286. return 0;
  287. TBWidget* parent = widget_->GetParent();
  288. if (!parent)
  289. return 0;
  290. UI* ui = GetSubsystem<UI>();
  291. return ui->WrapWidget(parent);
  292. }
  293. UIWidget* UIWidget::GetContentRoot()
  294. {
  295. if (!widget_)
  296. return 0;
  297. TBWidget* root = widget_->GetContentRoot();
  298. if (!root)
  299. return 0;
  300. UI* ui = GetSubsystem<UI>();
  301. return ui->WrapWidget(root);
  302. }
  303. void UIWidget::Die()
  304. {
  305. if (!widget_)
  306. return;
  307. // clear delegate
  308. widget_->SetDelegate(NULL);
  309. // explictly die (can trigger an animation)
  310. widget_->Die();
  311. // call OnDelete, which unwraps the widget and does some bookkeeping
  312. OnDelete();
  313. }
  314. void UIWidget::SetLayoutParams(UILayoutParams* params)
  315. {
  316. if (!widget_)
  317. return;
  318. widget_->SetLayoutParams(*(params->GetTBLayoutParams()));
  319. }
  320. void UIWidget::SetFontDescription(UIFontDescription* fd)
  321. {
  322. if (!widget_)
  323. return;
  324. widget_->SetFontDescription(*(fd->GetTBFontDescription()));
  325. }
  326. void UIWidget::DeleteAllChildren()
  327. {
  328. if (!widget_)
  329. return;
  330. widget_->DeleteAllChildren();
  331. }
  332. void UIWidget::SetSkinBg(const String& id)
  333. {
  334. if (!widget_)
  335. return;
  336. widget_->SetSkinBg(TBIDC(id.CString()));
  337. }
  338. void UIWidget::Remove()
  339. {
  340. if (!widget_ || !widget_->GetParent())
  341. return;
  342. widget_->GetParent()->RemoveChild(widget_);
  343. }
  344. void UIWidget::RemoveChild(UIWidget* child, bool cleanup)
  345. {
  346. if (!widget_ || !child)
  347. return;
  348. TBWidget* childw = child->GetInternalWidget();
  349. if (!childw)
  350. return;
  351. widget_->RemoveChild(childw);
  352. if (cleanup)
  353. delete childw;
  354. }
  355. const String& UIWidget::GetId()
  356. {
  357. if (!widget_ || !widget_->GetID())
  358. {
  359. if (id_.Length())
  360. id_.Clear();
  361. return id_;
  362. }
  363. if (id_.Length())
  364. return id_;
  365. UI* ui = GetSubsystem<UI>();
  366. ui->GetTBIDString(widget_->GetID(), id_);
  367. return id_;
  368. }
  369. void UIWidget::SetId(const String& id)
  370. {
  371. if (!widget_)
  372. {
  373. if (id_.Length())
  374. id_.Clear();
  375. return;
  376. }
  377. id_ = id;
  378. widget_->SetID(TBIDC(id.CString()));
  379. }
  380. void UIWidget::SetState(UI_WIDGET_STATE state, bool on)
  381. {
  382. if (!widget_)
  383. return;
  384. widget_->SetState((WIDGET_STATE) state, on);
  385. }
  386. void UIWidget::SetFocus()
  387. {
  388. if (!widget_)
  389. return;
  390. widget_->SetFocus(WIDGET_FOCUS_REASON_UNKNOWN);
  391. }
  392. bool UIWidget::GetFocus()
  393. {
  394. if (!widget_)
  395. return false;
  396. return widget_->GetIsFocused();
  397. }
  398. void UIWidget::SetFocusRecursive()
  399. {
  400. if (!widget_)
  401. return;
  402. widget_->SetFocusRecursive(WIDGET_FOCUS_REASON_UNKNOWN);
  403. }
  404. void UIWidget::SetVisibility(UI_WIDGET_VISIBILITY visibility)
  405. {
  406. if (!widget_)
  407. return;
  408. widget_->SetVisibilility((WIDGET_VISIBILITY) visibility);
  409. }
  410. UI_WIDGET_VISIBILITY UIWidget::GetVisibility()
  411. {
  412. if (!widget_)
  413. return UI_WIDGET_VISIBILITY_GONE;
  414. return (UI_WIDGET_VISIBILITY) widget_->GetVisibility();
  415. }
  416. UIWidget* UIWidget::GetFirstChild()
  417. {
  418. if (!widget_)
  419. return NULL;
  420. return GetSubsystem<UI>()->WrapWidget(widget_->GetFirstChild());
  421. }
  422. UIWidget* UIWidget::GetNext()
  423. {
  424. if (!widget_)
  425. return NULL;
  426. return GetSubsystem<UI>()->WrapWidget(widget_->GetNext());
  427. }
  428. void UIWidget::SetValue(double value)
  429. {
  430. if (!widget_)
  431. return;
  432. widget_->SetValueDouble(value);
  433. }
  434. double UIWidget::GetValue()
  435. {
  436. if (!widget_)
  437. return 0.0;
  438. return widget_->GetValueDouble();
  439. }
  440. bool UIWidget::GetState(UI_WIDGET_STATE state)
  441. {
  442. if (!widget_)
  443. return false;
  444. return widget_->GetState((WIDGET_STATE) state);
  445. }
  446. void UIWidget::SetStateRaw(UI_WIDGET_STATE state)
  447. {
  448. if (!widget_)
  449. return;
  450. widget_->SetStateRaw((WIDGET_STATE) state);
  451. }
  452. UI_WIDGET_STATE UIWidget::GetStateRaw()
  453. {
  454. if (!widget_)
  455. return UI_WIDGET_STATE_NONE;
  456. return (UI_WIDGET_STATE) widget_->GetStateRaw();
  457. }
  458. UIView* UIWidget::GetView()
  459. {
  460. if (!widget_)
  461. return 0;
  462. if (GetType() == UIView::GetTypeStatic())
  463. return (UIView*) this;
  464. TBWidget* tbw = widget_->GetParent();
  465. while(tbw)
  466. {
  467. TBWidgetDelegate* delegate = tbw->GetDelegate();
  468. if (delegate)
  469. {
  470. UIWidget* d = (UIWidget*) delegate;
  471. if (d->GetType() == UIView::GetTypeStatic())
  472. return (UIView*) d;
  473. }
  474. tbw = tbw->GetParent();
  475. }
  476. return 0;
  477. }
  478. void UIWidget::OnFocusChanged(bool focused)
  479. {
  480. using namespace WidgetFocusChanged;
  481. VariantMap eventData;
  482. eventData[P_WIDGET] = this;
  483. eventData[P_FOCUSED] = focused;
  484. SendEvent(E_WIDGETFOCUSCHANGED, eventData);
  485. }
  486. bool UIWidget::OnEvent(const tb::TBWidgetEvent &ev)
  487. {
  488. UI* ui = GetSubsystem<UI>();
  489. if ((ev.type == EVENT_TYPE_CHANGED && !ui->GetBlockChangedEvents()) || ev.type == EVENT_TYPE_KEY_UP)
  490. {
  491. if (!ev.target || ui->IsWidgetWrapped(ev.target))
  492. {
  493. VariantMap eventData;
  494. ConvertEvent(this, ui->WrapWidget(ev.target), ev, eventData);
  495. SendEvent(E_WIDGETEVENT, eventData);
  496. if (eventData[WidgetEvent::P_HANDLED].GetBool())
  497. return true;
  498. }
  499. }
  500. else if (ev.type == EVENT_TYPE_RIGHT_POINTER_UP)
  501. {
  502. if (!ev.target || ui->IsWidgetWrapped(ev.target))
  503. {
  504. VariantMap eventData;
  505. ConvertEvent(this, ui->WrapWidget(ev.target), ev, eventData);
  506. SendEvent(E_WIDGETEVENT, eventData);
  507. if (eventData[WidgetEvent::P_HANDLED].GetBool())
  508. return true;
  509. }
  510. }
  511. else if (ev.type == EVENT_TYPE_POINTER_DOWN)
  512. {
  513. if (!ev.target || ui->IsWidgetWrapped(ev.target))
  514. {
  515. VariantMap eventData;
  516. ConvertEvent(this, ui->WrapWidget(ev.target), ev, eventData);
  517. SendEvent(E_WIDGETEVENT, eventData);
  518. if (eventData[WidgetEvent::P_HANDLED].GetBool())
  519. return true;
  520. }
  521. }
  522. else if (ev.type == EVENT_TYPE_SHORTCUT)
  523. {
  524. if (!ev.target || ui->IsWidgetWrapped(ev.target))
  525. {
  526. VariantMap eventData;
  527. ConvertEvent(this, ui->WrapWidget(ev.target), ev, eventData);
  528. SendEvent(E_WIDGETEVENT, eventData);
  529. if (eventData[WidgetEvent::P_HANDLED].GetBool())
  530. return true;
  531. }
  532. }
  533. else if (ev.type == EVENT_TYPE_TAB_CHANGED)
  534. {
  535. if (!ev.target || ui->IsWidgetWrapped(ev.target))
  536. {
  537. VariantMap eventData;
  538. ConvertEvent(this, ui->WrapWidget(ev.target), ev, eventData);
  539. SendEvent(E_WIDGETEVENT, eventData);
  540. if (eventData[WidgetEvent::P_HANDLED].GetBool())
  541. return true;
  542. }
  543. }
  544. else if (ev.type == EVENT_TYPE_CLICK)
  545. {
  546. if (ev.target && ev.target->GetID() == TBID("__popup-menu"))
  547. {
  548. // popup menu
  549. if (JSGetHeapPtr())
  550. {
  551. VariantMap eventData;
  552. eventData[PopupMenuSelect::P_BUTTON] = this;
  553. String id;
  554. ui->GetTBIDString(ev.ref_id, id);
  555. eventData[PopupMenuSelect::P_REFID] = id;
  556. SendEvent(E_POPUPMENUSELECT, eventData);
  557. }
  558. return true;
  559. }
  560. else
  561. {
  562. if (!ev.target || ui->IsWidgetWrapped(ev.target))
  563. {
  564. VariantMap eventData;
  565. ConvertEvent(this, ui->WrapWidget(ev.target), ev, eventData);
  566. SendEvent(E_WIDGETEVENT, eventData);
  567. if (eventData[WidgetEvent::P_HANDLED].GetBool())
  568. return true;
  569. }
  570. }
  571. }
  572. if (ev.type == EVENT_TYPE_CUSTOM)
  573. {
  574. if (!ev.target || ui->IsWidgetWrapped(ev.target))
  575. {
  576. VariantMap eventData;
  577. ConvertEvent(this, ui->WrapWidget(ev.target), ev, eventData);
  578. SendEvent(E_WIDGETEVENT, eventData);
  579. if (eventData[WidgetEvent::P_HANDLED].GetBool())
  580. return true;
  581. }
  582. }
  583. return false;
  584. }
  585. bool UIWidget::GetCaptured()
  586. {
  587. if (!widget_)
  588. return false;
  589. return widget_->IsCaptured();
  590. }
  591. void UIWidget::SetCapturing(bool capturing)
  592. {
  593. if (!widget_)
  594. return;
  595. widget_->SetCapturing(capturing);
  596. }
  597. bool UIWidget::GetCapturing()
  598. {
  599. if (!widget_)
  600. return false;
  601. return widget_->GetCapturing();
  602. }
  603. void UIWidget::InvalidateLayout()
  604. {
  605. if (!widget_)
  606. return;
  607. widget_->InvalidateLayout(tb::TBWidget::INVALIDATE_LAYOUT_TARGET_ONLY);
  608. }
  609. void UIWidget::InvokeShortcut(const String& shortcut)
  610. {
  611. TBWidgetEvent ev(EVENT_TYPE_SHORTCUT);
  612. ev.ref_id = TBIDC(shortcut.CString());
  613. widget_->OnEvent(ev);
  614. }
  615. bool UIWidget::GetShortened()
  616. {
  617. if (!widget_)
  618. return false;
  619. return widget_->GetShortened();
  620. }
  621. void UIWidget::SetShortened(bool shortened)
  622. {
  623. if (!widget_)
  624. return;
  625. widget_->SetShortened(shortened);
  626. }
  627. String UIWidget::GetTooltip()
  628. {
  629. if (!widget_)
  630. return String::EMPTY;
  631. return widget_->GetTooltip().CStr();
  632. }
  633. void UIWidget::SetTooltip(const String& tooltip)
  634. {
  635. if (!widget_)
  636. return;
  637. widget_->SetTooltip(tooltip.CString());
  638. }
  639. }