UIWidget.cpp 17 KB

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