UIListView.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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 <TurboBadger/tb_menu_window.h>
  23. #include <TurboBadger/tb_select.h>
  24. #include <Atomic/IO/Log.h>
  25. #include "UI.h"
  26. #include "UIEvents.h"
  27. #include "UIListView.h"
  28. using namespace tb;
  29. namespace Atomic
  30. {
  31. class ListViewItemSource;
  32. class ListViewItemWidget;
  33. class ListViewItemWidget : public TBLayout
  34. {
  35. public:
  36. ListViewItemWidget(ListViewItem *item, ListViewItemSource *source, TBSelectItemViewer *sourceviewer, int index);
  37. virtual bool OnEvent(const TBWidgetEvent &ev);
  38. void UpdateText(const String& text)
  39. {
  40. if (textField_)
  41. textField_->SetText(text.CString());
  42. }
  43. void UpdateIcon(const String& icon)
  44. {
  45. if (icon_)
  46. icon_->SetSkinBg(TBIDC(icon.CString()));
  47. }
  48. void UpdateTextSkin(const String& skin)
  49. {
  50. if (textField_)
  51. textField_->SetSkinBg(TBIDC(skin.CString()));
  52. }
  53. void SetExpanded(bool expanded)
  54. {
  55. if (expandBox_)
  56. expandBox_->SetValue(expanded ? 1 : 0);
  57. }
  58. private:
  59. TBCheckBox* expandBox_;
  60. TBTextField* textField_;
  61. TBSkinImage* icon_;
  62. ListViewItemSource *source_;
  63. TBSelectItemViewer *sourceviewer_;
  64. int index_;
  65. ListViewItem* item_;
  66. };
  67. class ListViewItem : public TBGenericStringItem
  68. {
  69. bool expanded_;
  70. bool selected_;
  71. public:
  72. ListViewItem(const char *str, const TBID &id, const char* icon, ListViewItemSource* source)
  73. : TBGenericStringItem(str, id), source_(source), parent_(0),
  74. depth_(0), widget_(0), expanded_(false), icon_(icon), selected_(false)
  75. {
  76. }
  77. ListViewItem* AddChild(const char* text, const char* icon, const TBID &id);
  78. bool GetSelected() { return selected_; }
  79. void SetSelected(bool value)
  80. {
  81. selected_ = value;
  82. }
  83. bool GetExpanded() { return expanded_; }
  84. void GetChildren(PODVector<ListViewItem*>& children, bool recursive = false)
  85. {
  86. children += children_;
  87. if (recursive)
  88. {
  89. for (unsigned i = 0; i < children_.Size(); i++)
  90. {
  91. children_[i]->GetChildren(children, recursive);
  92. }
  93. }
  94. }
  95. void SetExpanded(bool expanded)
  96. {
  97. if (widget_)
  98. widget_->SetExpanded(expanded);
  99. expanded_ = expanded;
  100. if (!expanded_)
  101. {
  102. //for (unsigned i = 0; i < children_.Size(); i ++)
  103. // children_[i]->SetExpanded(expanded);
  104. }
  105. else
  106. {
  107. if (parent_)
  108. parent_->SetExpanded(expanded_);
  109. }
  110. }
  111. void UpdateText(const String& text);
  112. void UpdateTextSkin(const String& skin);
  113. void UpdateIcon(const String& icon);
  114. ListViewItemSource* source_;
  115. ListViewItem* parent_;
  116. int depth_;
  117. PODVector<ListViewItem*> children_;
  118. ListViewItemWidget* widget_;
  119. String icon_;
  120. String textSkin_;
  121. };
  122. class ListViewItemSource : public TBSelectItemSourceList<ListViewItem>
  123. {
  124. public:
  125. UIListView* uiListView_;
  126. ListViewItemSource(UIListView* list) : uiListView_(list) {}
  127. virtual ~ListViewItemSource() {}
  128. virtual bool Filter(int index, const char *filter);
  129. virtual TBWidget *CreateItemWidget(int index, TBSelectItemViewer *viewer);
  130. };
  131. // implementation
  132. void ListViewItem::UpdateText(const String& text)
  133. {
  134. str = text.CString();
  135. if (widget_)
  136. widget_->UpdateText(text);
  137. }
  138. void ListViewItem::UpdateIcon(const String& icon)
  139. {
  140. icon_ = icon;
  141. if (widget_)
  142. widget_->UpdateIcon(icon);
  143. }
  144. void ListViewItem::UpdateTextSkin(const String& skin)
  145. {
  146. textSkin_ = skin;
  147. if (widget_)
  148. widget_->UpdateTextSkin(skin);
  149. }
  150. ListViewItem* ListViewItem::AddChild(const char *text, const char* icon, const TBID &id)
  151. {
  152. ListViewItem* child = new ListViewItem(text, id, icon, source_);
  153. child->parent_ = this;
  154. child->depth_ = depth_ + 1;
  155. // filter, alphabetically into source
  156. ListViewItem* insert = this;
  157. int parentIndex = -1;
  158. for (int i = 0; i < source_->GetNumItems(); i++)
  159. {
  160. if (source_->GetItem(i) == this)
  161. {
  162. parentIndex = i;
  163. break;
  164. }
  165. }
  166. for (int i = parentIndex + 1; i < source_->GetNumItems(); i++)
  167. {
  168. ListViewItem* item = source_->GetItem(i);
  169. if (item->depth_ <= depth_)
  170. break;
  171. if (item->depth_ != depth_ + 1)
  172. {
  173. insert = item;
  174. continue;
  175. }
  176. if (strcmp(item->str.CStr(), text) >= 0)
  177. break;
  178. insert = item;
  179. }
  180. for (int i = 0; i < source_->GetNumItems(); i++)
  181. {
  182. if (source_->GetItem(i) == insert)
  183. {
  184. source_->AddItem(child, i + 1);
  185. break;
  186. }
  187. }
  188. children_.Push(child);
  189. return child;
  190. }
  191. ListViewItemWidget::ListViewItemWidget(ListViewItem *item, ListViewItemSource *source,
  192. TBSelectItemViewer *sourceviewer, int index)
  193. : source_(source)
  194. , sourceviewer_(sourceviewer)
  195. , index_(index)
  196. , item_(item)
  197. , expandBox_(0)
  198. , textField_(0)
  199. , icon_(0)
  200. {
  201. SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
  202. SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP);
  203. SetPaintOverflowFadeout(false);
  204. SetCapturing(false);
  205. item_->widget_ = this;
  206. for (int i = 0; i < item->depth_; i++)
  207. {
  208. LayoutParams lp;
  209. lp.SetWidth(6);
  210. lp.SetHeight(4);
  211. TBWidget* spacer = new TBWidget();
  212. spacer->SetLayoutParams(lp);
  213. GetContentRoot()->AddChild(spacer);
  214. }
  215. if (item_->children_.Size())
  216. {
  217. expandBox_ = new TBCheckBox();
  218. expandBox_->SetSkinBg(TBIDC("TBCheckBox.uilistview"));
  219. expandBox_->SetValue(item_->GetExpanded());
  220. expandBox_->SetID(item->id);
  221. GetContentRoot()->AddChild(expandBox_);
  222. }
  223. else
  224. {
  225. LayoutParams lp;
  226. lp.SetWidth(12);
  227. lp.SetHeight(4);
  228. TBWidget* spacer = new TBWidget();
  229. spacer->SetLayoutParams(lp);
  230. GetContentRoot()->AddChild(spacer);
  231. }
  232. if (item->icon_.Length())
  233. {
  234. icon_ = new TBSkinImage(TBIDC(item->icon_.CString()));
  235. icon_->SetIgnoreInput(true);
  236. GetContentRoot()->AddChild(icon_);
  237. }
  238. TBFontDescription fd;
  239. fd.SetID(TBIDC("Vera"));
  240. fd.SetSize(11);
  241. TBTextField* tfield = textField_ = new TBTextField();
  242. tfield->SetIgnoreInput(true);
  243. tfield->SetSkinBg(item->textSkin_.Length() ? TBIDC(item->textSkin_.CString()) : TBIDC("Folder"));
  244. tfield->SetText(item->str);
  245. tfield->SetFontDescription(fd);
  246. SetSkinBg(TBIDC("TBSelectItem"));
  247. GetContentRoot()->AddChild(tfield);
  248. SetID(item->id);
  249. }
  250. bool ListViewItemWidget::OnEvent(const TBWidgetEvent &ev)
  251. {
  252. if (ev.type == EVENT_TYPE_WHEEL)
  253. {
  254. return false;
  255. }
  256. if (ev.type == EVENT_TYPE_POINTER_DOWN || ev.type == EVENT_TYPE_RIGHT_POINTER_UP)
  257. {
  258. SetFocus(WIDGET_FOCUS_REASON_POINTER);
  259. TBWidget* parent = GetParent();
  260. while (parent)
  261. {
  262. if (parent->IsOfType<TBSelectList>())
  263. {
  264. TBWidgetEvent nev = ev;
  265. nev.ref_id = item_->id;
  266. parent->InvokeEvent(nev);
  267. break;
  268. }
  269. parent = parent->GetParent();
  270. }
  271. return true;
  272. }
  273. // get clicks this way, not sure we want to
  274. if (ev.type == EVENT_TYPE_CLICK && ev.target == expandBox_ && ev.target->GetID() == item_->id)
  275. {
  276. item_->SetExpanded(!item_->GetExpanded());
  277. source_->uiListView_->UpdateItemVisibility();
  278. // want to bubble
  279. return false;
  280. }
  281. return TBLayout::OnEvent(ev);
  282. }
  283. bool ListViewItemSource::Filter(int index, const char *filter)
  284. {
  285. ListViewItem* item = GetItem(index);
  286. if (!item->parent_)
  287. return true;
  288. if (item->parent_->GetExpanded())
  289. return true;
  290. return true;
  291. }
  292. TBWidget *ListViewItemSource::CreateItemWidget(int index, TBSelectItemViewer *viewer)
  293. {
  294. ListViewItem* item = GetItem(index);
  295. if (TBLayout *layout = new ListViewItemWidget(item, this, viewer, index))
  296. return layout;
  297. return nullptr;
  298. }
  299. /*
  300. static int select_list_sort_cb(TBSelectItemSource *_source, const int *a, const int *b)
  301. {
  302. ListViewItemSource* source = (ListViewItemSource*) _source;
  303. ListViewItem* itemA = source->GetItem(*a);
  304. ListViewItem* itemB = source->GetItem(*b);
  305. int value;
  306. if (itemA->depth_ == itemB->depth_)
  307. {
  308. value = strcmp(source->GetItemString(*a), source->GetItemString(*b));
  309. }
  310. else
  311. {
  312. value = itemA->depth_ > itemB->depth_ ? 1 : -1;
  313. }
  314. return source->GetSort() == TB_SORT_DESCENDING ? -value : value;
  315. }
  316. */
  317. UIListView::UIListView(Context* context, bool createWidget) :
  318. UIWidget(context, createWidget),
  319. source_(0), itemLookupId_(0), multiSelect_(false)
  320. {
  321. rootList_ = new UISelectList(context);
  322. // dummy filter so filter is called
  323. rootList_->SetFilter(" ");
  324. widget_->SetGravity(WIDGET_GRAVITY_ALL);
  325. rootList_->SetGravity(UI_GRAVITY_ALL);
  326. source_ = new ListViewItemSource(this);
  327. rootList_->GetTBSelectList()->SetSource(source_);
  328. AddChild(rootList_);
  329. }
  330. UIListView::~UIListView()
  331. {
  332. }
  333. unsigned UIListView::AddRootItem(const String& text, const String& icon, const String& id)
  334. {
  335. ListViewItem* item = new ListViewItem(text.CString(), TBID(id.CString()), icon.CString(), source_);
  336. source_->AddItem(item);
  337. itemLookup_[itemLookupId_++] = item;
  338. return itemLookupId_ - 1;
  339. }
  340. void UIListView::SetItemText(const String& id, const String& text)
  341. {
  342. TBID tbid(id.CString());
  343. for (int i = 0; i < source_->GetNumItems(); i++)
  344. {
  345. if (source_->GetItemID(i) == tbid)
  346. {
  347. ListViewItem* item = source_->GetItem(i);
  348. item->UpdateText(text);
  349. return;
  350. }
  351. }
  352. }
  353. void UIListView::SetItemTextSkin(const String& id, const String& skin)
  354. {
  355. TBID tbid(id.CString());
  356. for (int i = 0; i < source_->GetNumItems(); i++)
  357. {
  358. if (source_->GetItemID(i) == tbid)
  359. {
  360. ListViewItem* item = source_->GetItem(i);
  361. item->UpdateTextSkin(skin);
  362. return;
  363. }
  364. }
  365. }
  366. void UIListView::SetItemIcon(const String& id, const String& icon)
  367. {
  368. TBID tbid(id.CString());
  369. for (int i = 0; i < source_->GetNumItems(); i++)
  370. {
  371. if (source_->GetItemID(i) == tbid)
  372. {
  373. ListViewItem* item = source_->GetItem(i);
  374. item->UpdateIcon(icon);
  375. return;
  376. }
  377. }
  378. }
  379. void UIListView::DeleteItemByID(const String& id)
  380. {
  381. TBID tbid(id.CString());
  382. for (int i = 0; i < source_->GetNumItems(); i++)
  383. {
  384. if (source_->GetItemID(i) == tbid)
  385. {
  386. ListViewItem* item = source_->GetItem(i);
  387. if (item->parent_)
  388. item->parent_->children_.Remove(item);
  389. PODVector<ListViewItem*> children;
  390. item->GetChildren(children, true);
  391. for (unsigned j = 0; j < children.Size(); j++)
  392. {
  393. for (int k = 0; k < source_->GetNumItems(); k++)
  394. {
  395. if (children[j] == source_->GetItem(k))
  396. {
  397. source_->DeleteItem(k);
  398. break;
  399. }
  400. }
  401. }
  402. source_->DeleteItem(i);
  403. rootList_->InvalidateList();
  404. return;
  405. }
  406. }
  407. }
  408. unsigned UIListView::AddChildItem(unsigned parentItemID, const String& text, const String& icon, const String& id)
  409. {
  410. if (!itemLookup_.Contains(parentItemID))
  411. return -1;
  412. ListViewItem* item = itemLookup_[parentItemID];
  413. ListViewItem* child = item->AddChild(text.CString(), icon.CString(), TBID(id.CString()));
  414. itemLookup_[itemLookupId_++] = child;
  415. return itemLookupId_ - 1;
  416. }
  417. void UIListView::SetExpanded(unsigned itemID, bool value)
  418. {
  419. if (!itemLookup_.Contains(itemID))
  420. return;
  421. itemLookup_[itemID]->SetExpanded(value);
  422. }
  423. bool UIListView::GetExpanded(unsigned itemID)
  424. {
  425. if (!itemLookup_.Contains(itemID))
  426. return false;
  427. return itemLookup_[itemID]->GetExpanded();
  428. }
  429. bool UIListView::GetExpandable(unsigned itemID)
  430. {
  431. if (!itemLookup_.Contains(itemID))
  432. return false;
  433. return itemLookup_[itemID]->children_.Size() > 0;
  434. }
  435. void UIListView::DeleteAllItems()
  436. {
  437. itemLookup_.Clear();
  438. source_->DeleteAllItems();
  439. }
  440. void UIListView::SelectItemByID(const String& id, bool selected)
  441. {
  442. TBID tid = TBIDC(id.CString());
  443. for (int i = 0; i < source_->GetNumItems(); i++)
  444. {
  445. ListViewItem* item = source_->GetItem(i);
  446. if (tid == item->id)
  447. {
  448. if (selected)
  449. {
  450. if (item->GetSelected())
  451. return;
  452. item->SetSelected(selected);
  453. item->SetExpanded(true);
  454. SetValueFirstSelected();
  455. UpdateItemVisibility();
  456. ScrollToSelectedItem();
  457. }
  458. else
  459. {
  460. if (!item->GetSelected())
  461. return;
  462. item->SetSelected(false);
  463. UpdateItemVisibility();
  464. }
  465. return;
  466. }
  467. }
  468. }
  469. void UIListView::UpdateItemVisibility()
  470. {
  471. UI* ui = GetSubsystem<UI>();
  472. VariantMap eventData;
  473. for (int i = 0; i < source_->GetNumItems(); i++)
  474. {
  475. ListViewItem* item = source_->GetItem(i);
  476. String refid;
  477. ui->GetTBIDString(item->id, refid);
  478. eventData[UIListViewSelectionChanged::P_REFID] = refid;
  479. eventData[UIListViewSelectionChanged::P_SELECTED] = item->GetSelected();
  480. this->SendEvent(E_UILISTVIEWSELECTIONCHANGED, eventData);
  481. if (!item->widget_)
  482. continue;
  483. item->widget_->SetVisibilility(WIDGET_VISIBILITY_VISIBLE);
  484. item->widget_->SetState(WIDGET_STATE_SELECTED, item->GetSelected());
  485. ListViewItem* parent = item->parent_;
  486. while (parent)
  487. {
  488. if (!parent->GetExpanded())
  489. break;
  490. parent = parent->parent_;
  491. }
  492. if (parent)
  493. item->widget_->SetVisibilility(WIDGET_VISIBILITY_GONE);
  494. }
  495. tb::TBScrollContainer* scroll = (tb::TBScrollContainer*) rootList_->GetInternalWidget()->GetFirstChild();
  496. scroll->OnProcess();
  497. }
  498. void UIListView::ScrollToSelectedItem()
  499. {
  500. if (rootList_.Null())
  501. return;
  502. rootList_->ScrollToSelectedItem();
  503. }
  504. void UIListView::SelectAllItems(bool select)
  505. {
  506. for (int i = 0; i < source_->GetNumItems(); i++)
  507. {
  508. ListViewItem* item = source_->GetItem(i);
  509. item->SetSelected(select);
  510. }
  511. }
  512. void UIListView::SetValueFirstSelected()
  513. {
  514. int index = -1;
  515. for (int i = 0; i < source_->GetNumItems(); i++)
  516. {
  517. ListViewItem* item = source_->GetItem(i);
  518. if (item->GetSelected())
  519. {
  520. index = i;
  521. break;
  522. }
  523. }
  524. rootList_->SetValue(index);
  525. }
  526. void UIListView::SelectSingleItem(ListViewItem* item, bool expand)
  527. {
  528. SelectAllItems(false);
  529. if (expand)
  530. item->SetExpanded(true);
  531. item->SetSelected(true);
  532. UpdateItemVisibility();
  533. SetValueFirstSelected();
  534. ScrollToSelectedItem();
  535. }
  536. void UIListView::Move(tb::SPECIAL_KEY key)
  537. {
  538. // selected index
  539. int index = -1;
  540. for (int i = 0; i < source_->GetNumItems(); i++)
  541. {
  542. ListViewItem* item = source_->GetItem(i);
  543. if (item->GetSelected())
  544. {
  545. index = i;
  546. break;
  547. }
  548. }
  549. // nothing selected
  550. if (index == -1)
  551. return;
  552. if (key == TB_KEY_LEFT)
  553. {
  554. ListViewItem* item = source_->GetItem(index);
  555. if (item->children_.Size() > 0 && item->GetExpanded())
  556. {
  557. item->SetExpanded(false);
  558. UpdateItemVisibility();
  559. }
  560. else
  561. {
  562. key = TB_KEY_UP;
  563. }
  564. }
  565. if (key == TB_KEY_RIGHT)
  566. {
  567. ListViewItem* item = source_->GetItem(index);
  568. if (item->children_.Size() > 0 && !item->GetExpanded())
  569. {
  570. item->SetExpanded(true);
  571. UpdateItemVisibility();
  572. }
  573. else
  574. {
  575. key = TB_KEY_DOWN;
  576. }
  577. }
  578. if (key == TB_KEY_UP)
  579. {
  580. // can't go any further up list
  581. if (index == 0)
  582. return;
  583. for (int i = (int) (index - 1 ); i >= 0; i--)
  584. {
  585. ListViewItem* item = source_->GetItem(i);
  586. if (item->widget_ && item->widget_->GetVisibility() == WIDGET_VISIBILITY_VISIBLE)
  587. {
  588. SelectSingleItem(item, false);
  589. return;
  590. }
  591. }
  592. }
  593. if (key == TB_KEY_DOWN)
  594. {
  595. // can't go any further down list
  596. if (index == source_->GetNumItems() - 1)
  597. return;
  598. for (int i = index + 1; i < source_->GetNumItems(); i++)
  599. {
  600. ListViewItem* item = source_->GetItem(i);
  601. if (item->widget_ && item->widget_->GetVisibility() == WIDGET_VISIBILITY_VISIBLE)
  602. {
  603. SelectSingleItem(item, false);
  604. return;
  605. }
  606. }
  607. }
  608. }
  609. bool UIListView::OnEvent(const tb::TBWidgetEvent &ev)
  610. {
  611. if (ev.type == EVENT_TYPE_KEY_UP )
  612. {
  613. if (ev.special_key == TB_KEY_DOWN || ev.special_key == TB_KEY_UP || ev.special_key == TB_KEY_LEFT || ev.special_key == TB_KEY_RIGHT)
  614. {
  615. Move(ev.special_key);
  616. return true;
  617. }
  618. }
  619. if (ev.type == EVENT_TYPE_CUSTOM && ev.ref_id == TBIDC("select_list_validation_end"))
  620. {
  621. UpdateItemVisibility();
  622. return true;
  623. }
  624. if (ev.type == EVENT_TYPE_CUSTOM && ev.ref_id == TBIDC("select_list_selection_changed"))
  625. {
  626. for (int i = 0; i < source_->GetNumItems(); i++)
  627. {
  628. ListViewItem* item = source_->GetItem(i);
  629. if (item->id == ev.target->GetID())
  630. {
  631. bool multi = false;
  632. if (multiSelect_ && (ev.modifierkeys & TB_SHIFT || ev.modifierkeys & TB_CTRL || ev.modifierkeys & TB_SUPER))
  633. multi = true;
  634. if (multi)
  635. {
  636. if (item->GetSelected())
  637. {
  638. item->SetSelected(false);
  639. UpdateItemVisibility();
  640. }
  641. else {
  642. item->SetSelected(true);
  643. UpdateItemVisibility();
  644. }
  645. SetValueFirstSelected();
  646. }
  647. else
  648. {
  649. SelectSingleItem(item);
  650. }
  651. return true;
  652. }
  653. }
  654. }
  655. return UIWidget::OnEvent(ev);
  656. }
  657. }