ListView.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "BorderImage.h"
  25. #include "Context.h"
  26. #include "InputEvents.h"
  27. #include "ListView.h"
  28. #include "Log.h"
  29. #include "StringUtils.h"
  30. #include "UIEvents.h"
  31. #include "DebugNew.h"
  32. static const ShortStringHash indentHash("Indent");
  33. static const String highlightModes[] =
  34. {
  35. "never",
  36. "focus",
  37. "always",
  38. ""
  39. };
  40. int GetItemIndent(UIElement* item)
  41. {
  42. if (!item)
  43. return 0;
  44. return item->vars_[indentHash].GetInt();
  45. }
  46. OBJECTTYPESTATIC(ListView);
  47. ListView::ListView(Context* context) :
  48. ScrollView(context),
  49. highlightMode_(HM_FOCUS),
  50. multiselect_(false),
  51. hierarchyMode_(false),
  52. clearSelectionOnDefocus_(false),
  53. doubleClickInterval_(0.5f),
  54. doubleClickTimer_(0.0f),
  55. lastClickedItem_(M_MAX_UNSIGNED)
  56. {
  57. UIElement* container = new UIElement(context_);
  58. container->SetActive(true);
  59. container->SetLayout(LM_VERTICAL);
  60. SetContentElement(container);
  61. SubscribeToEvent(E_UIMOUSECLICK, HANDLER(ListView, HandleUIMouseClick));
  62. }
  63. ListView::~ListView()
  64. {
  65. }
  66. void ListView::RegisterObject(Context* context)
  67. {
  68. context->RegisterFactory<ListView>();
  69. }
  70. void ListView::SetStyle(const XMLElement& element)
  71. {
  72. ScrollView::SetStyle(element);
  73. UIElement* root = GetRootElement();
  74. XMLElement itemElem = element.GetChildElement("listitem");
  75. if (root)
  76. {
  77. while (itemElem)
  78. {
  79. if (itemElem.HasAttribute("name"))
  80. {
  81. UIElement* item = root->GetChild(itemElem.GetString("name"), true);
  82. AddItem(item);
  83. if (itemElem.HasAttribute("indent"))
  84. item->vars_[indentHash] = itemElem.GetInt("indent");
  85. itemElem = itemElem.GetNextElement("listitem");
  86. }
  87. }
  88. }
  89. if (element.HasChildElement("highlight"))
  90. {
  91. String highlight = element.GetChildElement("highlight").GetStringLower("value");
  92. SetHighlightMode((HighlightMode)GetStringListIndex(highlight, highlightModes, HM_FOCUS));
  93. }
  94. if (element.HasChildElement("multiselect"))
  95. SetMultiselect(element.GetChildElement("multiselect").GetBool("enable"));
  96. if (element.HasChildElement("hierarchy"))
  97. SetHierarchyMode(element.GetChildElement("hierarchy").GetBool("enable"));
  98. if (element.HasChildElement("clearselection"))
  99. SetClearSelectionOnDefocus(element.GetChildElement("clearselection").GetBool("enable"));
  100. if (element.HasChildElement("doubleclickinterval"))
  101. SetDoubleClickInterval(element.GetChildElement("doubleclickinterval").GetFloat("value"));
  102. XMLElement selectionElem = element.GetChildElement("selection");
  103. while (selectionElem)
  104. {
  105. AddSelection(selectionElem.GetInt("value"));
  106. selectionElem = selectionElem.GetNextElement("selection");
  107. }
  108. }
  109. void ListView::Update(float timeStep)
  110. {
  111. if (doubleClickTimer_ > 0.0f)
  112. doubleClickTimer_ = Max(doubleClickTimer_ - timeStep, 0.0f);
  113. }
  114. void ListView::OnKey(int key, int buttons, int qualifiers)
  115. {
  116. // If no selection, can not move with keys
  117. unsigned numItems = GetNumItems();
  118. unsigned selection = GetSelection();
  119. if ((selection != M_MAX_UNSIGNED) && (numItems))
  120. {
  121. // If either shift or ctrl held down, add to selection if multiselect enabled
  122. bool additive = (multiselect_) && (qualifiers != 0);
  123. switch (key)
  124. {
  125. case KEY_LEFT:
  126. if (hierarchyMode_)
  127. {
  128. SetChildItemsVisible(selection, false);
  129. return;
  130. }
  131. break;
  132. case KEY_RIGHT:
  133. if (hierarchyMode_)
  134. {
  135. SetChildItemsVisible(selection, true);
  136. return;
  137. }
  138. break;
  139. case KEY_RETURN:
  140. if (hierarchyMode_)
  141. {
  142. ToggleChildItemsVisible(selection);
  143. return;
  144. }
  145. break;
  146. case KEY_UP:
  147. ChangeSelection(-1, additive);
  148. return;
  149. case KEY_DOWN:
  150. ChangeSelection(1, additive);
  151. return;
  152. case KEY_PAGEUP:
  153. {
  154. // Convert page step to pixels and see how many items have to be skipped to reach that many pixels
  155. int stepPixels = ((int)(pageStep_ * scrollPanel_->GetHeight())) - GetSelectedItem()->GetHeight();
  156. unsigned newSelection = selection;
  157. unsigned okSelection = selection;
  158. while (newSelection < numItems)
  159. {
  160. UIElement* item = GetItem(newSelection);
  161. int height = 0;
  162. if (item->IsVisible())
  163. {
  164. height = item->GetHeight();
  165. okSelection = newSelection;
  166. }
  167. if (stepPixels < height)
  168. break;
  169. stepPixels -= height;
  170. --newSelection;
  171. }
  172. if (!additive)
  173. SetSelection(okSelection);
  174. else
  175. AddSelection(okSelection);
  176. }
  177. return;
  178. case KEY_PAGEDOWN:
  179. {
  180. int stepPixels = ((int)(pageStep_ * scrollPanel_->GetHeight())) - GetSelectedItem()->GetHeight();
  181. unsigned newSelection = selection;
  182. unsigned okSelection = selection;
  183. while (newSelection < numItems)
  184. {
  185. UIElement* item = GetItem(newSelection);
  186. int height = 0;
  187. if (item->IsVisible())
  188. {
  189. height = item->GetHeight();
  190. okSelection = newSelection;
  191. }
  192. if (stepPixels < height)
  193. break;
  194. stepPixels -= height;
  195. ++newSelection;
  196. }
  197. if (!additive)
  198. SetSelection(okSelection);
  199. else
  200. AddSelection(okSelection);
  201. }
  202. return;
  203. case KEY_HOME:
  204. ChangeSelection(-(int)GetNumItems(), additive);
  205. return;
  206. case KEY_END:
  207. ChangeSelection(GetNumItems(), additive);
  208. return;
  209. }
  210. }
  211. using namespace UnhandledKey;
  212. VariantMap eventData;
  213. eventData[P_ELEMENT] = (void*)this;
  214. eventData[P_KEY] = key;
  215. eventData[P_BUTTONS] = buttons;
  216. eventData[P_QUALIFIERS] = qualifiers;
  217. SendEvent(E_UNHANDLEDKEY, eventData);
  218. }
  219. void ListView::OnResize()
  220. {
  221. ScrollView::OnResize();
  222. // Set the content element width to match the scrollpanel
  223. const IntRect& clipBorder = scrollPanel_->GetClipBorder();
  224. contentElement_->SetWidth(scrollPanel_->GetWidth() - clipBorder.left_ - clipBorder.right_);
  225. }
  226. void ListView::OnFocus()
  227. {
  228. UpdateSelectionEffect();
  229. }
  230. void ListView::OnDefocus()
  231. {
  232. if (clearSelectionOnDefocus_)
  233. ClearSelection();
  234. UpdateSelectionEffect();
  235. }
  236. void ListView::AddItem(UIElement* item)
  237. {
  238. InsertItem(contentElement_->GetNumChildren(), item);
  239. }
  240. void ListView::InsertItem(unsigned index, UIElement* item)
  241. {
  242. if ((!item) || (item->GetParent() == contentElement_))
  243. return;
  244. // Enable input so that clicking the item can be detected
  245. item->SetActive(true);
  246. item->SetSelected(false);
  247. contentElement_->InsertChild(index, item);
  248. // If necessary, shift the following selections
  249. Set<unsigned> prevSelections;
  250. selections_.Clear();
  251. for (Set<unsigned>::Iterator j = prevSelections.Begin(); j != prevSelections.End(); ++j)
  252. {
  253. if (*j >= index)
  254. selections_.Insert(*j + 1);
  255. else
  256. selections_.Insert(*j);
  257. }
  258. UpdateSelectionEffect();
  259. }
  260. void ListView::RemoveItem(UIElement* item)
  261. {
  262. unsigned numItems = GetNumItems();
  263. for (unsigned i = 0; i < numItems; ++i)
  264. {
  265. if (GetItem(i) == item)
  266. {
  267. item->SetSelected(false);
  268. selections_.Erase(i);
  269. // Remove any child items in hierarchy mode
  270. unsigned removed = 1;
  271. if (hierarchyMode_)
  272. {
  273. int baseIndent = GetItemIndent(item);
  274. int j = i + 1;
  275. for (;;)
  276. {
  277. UIElement* childItem = GetItem(i + 1);
  278. if (!childItem)
  279. break;
  280. if (GetItemIndent(childItem) > baseIndent)
  281. {
  282. childItem->SetSelected(false);
  283. selections_.Erase(j);
  284. contentElement_->RemoveChild(childItem);
  285. ++removed;
  286. }
  287. else
  288. break;
  289. ++j;
  290. }
  291. }
  292. // If necessary, shift the following selections
  293. Set<unsigned> prevSelections;
  294. selections_.Clear();
  295. for (Set<unsigned>::Iterator j = prevSelections.Begin(); j != prevSelections.End(); ++j)
  296. {
  297. if (*j > i)
  298. selections_.Insert(*j - removed);
  299. else
  300. selections_.Insert(*j);
  301. }
  302. UpdateSelectionEffect();
  303. break;
  304. }
  305. }
  306. contentElement_->RemoveChild(item);
  307. }
  308. void ListView::RemoveItem(unsigned index)
  309. {
  310. RemoveItem(GetItem(index));
  311. }
  312. void ListView::RemoveAllItems()
  313. {
  314. unsigned numItems = GetNumItems();
  315. for (unsigned i = 0; i < numItems; ++i)
  316. contentElement_->GetChild(i)->SetSelected(false);
  317. contentElement_->RemoveAllChildren();
  318. ClearSelection();
  319. }
  320. void ListView::SetSelection(unsigned index)
  321. {
  322. Set<unsigned> indices;
  323. indices.Insert(index);
  324. SetSelections(indices);
  325. EnsureItemVisibility(index);
  326. }
  327. void ListView::SetSelections(const Set<unsigned>& indices)
  328. {
  329. unsigned numItems = GetNumItems();
  330. // Remove first items that should no longer be selected
  331. for (Set<unsigned>::Iterator i = selections_.Begin(); i != selections_.End();)
  332. {
  333. unsigned index = *i;
  334. if (indices.Find(index) == indices.End())
  335. {
  336. Set<unsigned>::Iterator current = i++;
  337. selections_.Erase(current);
  338. using namespace Iteselected_;
  339. VariantMap eventData;
  340. eventData[P_ELEMENT] = (void*)this;
  341. eventData[P_SELECTION] = index;
  342. SendEvent(E_ITEMDESELECTED, eventData);
  343. }
  344. else
  345. ++i;
  346. }
  347. // Then add missing items
  348. for (Set<unsigned>::ConstIterator i = indices.Begin(); i != indices.End(); ++i)
  349. {
  350. unsigned index = *i;
  351. if (index < numItems)
  352. {
  353. // In singleselect mode, resend the event even for the same selection
  354. if ((selections_.Find(index) == selections_.End()) || (!multiselect_))
  355. {
  356. selections_.Insert(*i);
  357. using namespace Iteselected_;
  358. VariantMap eventData;
  359. eventData[P_ELEMENT] = (void*)this;
  360. eventData[P_SELECTION] = *i;
  361. SendEvent(E_ITEMSELECTED, eventData);
  362. }
  363. }
  364. // If no multiselect enabled, allow setting only one item
  365. if (!multiselect_)
  366. break;
  367. }
  368. UpdateSelectionEffect();
  369. }
  370. void ListView::AddSelection(unsigned index)
  371. {
  372. if (!multiselect_)
  373. SetSelection(index);
  374. else
  375. {
  376. if (index >= GetNumItems())
  377. return;
  378. Set<unsigned> newSelections = selections_;
  379. newSelections.Insert(index);
  380. SetSelections(newSelections);
  381. EnsureItemVisibility(index);
  382. }
  383. }
  384. void ListView::RemoveSelection(unsigned index)
  385. {
  386. if (index >= GetNumItems())
  387. return;
  388. Set<unsigned> newSelections = selections_;
  389. newSelections.Erase(index);
  390. SetSelections(newSelections);
  391. EnsureItemVisibility(index);
  392. }
  393. void ListView::ToggleSelection(unsigned index)
  394. {
  395. unsigned numItems = GetNumItems();
  396. if (index >= numItems)
  397. return;
  398. if (selections_.Find(index) != selections_.End())
  399. RemoveSelection(index);
  400. else
  401. AddSelection(index);
  402. }
  403. void ListView::ChangeSelection(int delta, bool additive)
  404. {
  405. if (selections_.Empty())
  406. return;
  407. if (!multiselect_)
  408. additive = false;
  409. // If going downwards, use the last selection as a base. Otherwise use first
  410. unsigned selection = delta > 0 ? selections_.Back() : selections_.Front();
  411. unsigned numItems = GetNumItems();
  412. unsigned newSelection = selection;
  413. unsigned okSelection = selection;
  414. while (delta != 0)
  415. {
  416. if (delta > 0)
  417. {
  418. ++newSelection;
  419. if (newSelection >= numItems)
  420. break;
  421. }
  422. if (delta < 0)
  423. {
  424. --newSelection;
  425. if (newSelection >= numItems)
  426. break;
  427. }
  428. UIElement* item = GetItem(newSelection);
  429. if (item->IsVisible())
  430. {
  431. okSelection = newSelection;
  432. if (delta > 0)
  433. --delta;
  434. if (delta < 0)
  435. ++delta;
  436. }
  437. }
  438. if (!additive)
  439. SetSelection(okSelection);
  440. else
  441. AddSelection(okSelection);
  442. }
  443. void ListView::ClearSelection()
  444. {
  445. SetSelections(Set<unsigned>());
  446. UpdateSelectionEffect();
  447. }
  448. void ListView::SetHighlightMode(HighlightMode mode)
  449. {
  450. highlightMode_ = mode;
  451. UpdateSelectionEffect();
  452. }
  453. void ListView::SetMultiselect(bool enable)
  454. {
  455. multiselect_ = enable;
  456. }
  457. void ListView::SetHierarchyMode(bool enable)
  458. {
  459. hierarchyMode_ = enable;
  460. }
  461. void ListView::SetClearSelectionOnDefocus(bool enable)
  462. {
  463. clearSelectionOnDefocus_ = enable;
  464. }
  465. void ListView::SetDoubleClickInterval(float interval)
  466. {
  467. doubleClickInterval_ = interval;
  468. }
  469. void ListView::SetChildItemsVisible(unsigned index, bool enable)
  470. {
  471. unsigned numItems = GetNumItems();
  472. if ((!hierarchyMode_) || (index >= numItems))
  473. return;
  474. int baseIndent = GetItemIndent(GetItem(index));
  475. for (unsigned i = index + 1; i < numItems; ++i)
  476. {
  477. UIElement* item = GetItem(i);
  478. if (GetItemIndent(item) > baseIndent)
  479. item->SetVisible(enable);
  480. else
  481. break;
  482. }
  483. }
  484. void ListView::SetChildItemsVisible(bool enable)
  485. {
  486. unsigned numItems = GetNumItems();
  487. for (unsigned i = 0; i < numItems; ++i)
  488. {
  489. if (!GetItemIndent(GetItem(i)))
  490. SetChildItemsVisible(i, enable);
  491. }
  492. if (GetSelections().Size() == 1)
  493. EnsureItemVisibility(GetSelection());
  494. }
  495. void ListView::ToggleChildItemsVisible(unsigned index)
  496. {
  497. unsigned numItems = GetNumItems();
  498. if ((!hierarchyMode_) || (index >= numItems))
  499. return;
  500. int baseIndent = GetItemIndent(GetItem(index));
  501. bool firstChild = true;
  502. UIElement* prevItem = 0;
  503. for (unsigned i = index + 1; i < numItems; ++i)
  504. {
  505. UIElement* item = GetItem(i);
  506. if (GetItemIndent(item) > baseIndent)
  507. {
  508. if (firstChild)
  509. {
  510. item->SetVisible(!item->IsVisible());
  511. firstChild = false;
  512. }
  513. else
  514. item->SetVisible(prevItem->IsVisible());
  515. }
  516. else
  517. break;
  518. prevItem = item;
  519. }
  520. }
  521. unsigned ListView::GetNumItems() const
  522. {
  523. return contentElement_->GetNumChildren();
  524. }
  525. UIElement* ListView::GetItem(unsigned index) const
  526. {
  527. return contentElement_->GetChild(index);
  528. }
  529. PODVector<UIElement*> ListView::GetItems() const
  530. {
  531. return contentElement_->GetChildren();
  532. }
  533. unsigned ListView::GetSelection() const
  534. {
  535. if (selections_.Empty())
  536. return M_MAX_UNSIGNED;
  537. else
  538. return *selections_.Begin();
  539. }
  540. UIElement* ListView::GetSelectedItem() const
  541. {
  542. return contentElement_->GetChild(GetSelection());
  543. }
  544. PODVector<UIElement*> ListView::GetSelectedItems() const
  545. {
  546. PODVector<UIElement*> ret;
  547. for (Set<unsigned>::ConstIterator i = selections_.Begin(); i != selections_.End(); ++i)
  548. {
  549. UIElement* item = GetItem(*i);
  550. if (item)
  551. ret.Push(item);
  552. }
  553. return ret;
  554. }
  555. void ListView::UpdateSelectionEffect()
  556. {
  557. unsigned numItems = GetNumItems();
  558. for (unsigned i = 0; i < numItems; ++i)
  559. {
  560. UIElement* item = GetItem(i);
  561. if ((highlightMode_ != HM_NEVER) && (selections_.Find(i) != selections_.End()))
  562. item->SetSelected((focus_) || (highlightMode_ == HM_ALWAYS));
  563. else
  564. item->SetSelected(false);
  565. }
  566. }
  567. void ListView::EnsureItemVisibility(unsigned index)
  568. {
  569. UIElement* item = GetItem(index);
  570. if ((!item) || (!item->IsVisible()))
  571. return;
  572. IntVector2 currentOffset = item->GetScreenPosition() - scrollPanel_->GetScreenPosition() - contentElement_->GetPosition();
  573. IntVector2 newView = GetViewPosition();
  574. const IntRect& clipBorder = scrollPanel_->GetClipBorder();
  575. IntVector2 windowSize(scrollPanel_->GetWidth() - clipBorder.left_ - clipBorder.right_, scrollPanel_->GetHeight() -
  576. clipBorder.top_ - clipBorder.bottom_);
  577. if (currentOffset.y_ < 0)
  578. newView.y_ += currentOffset.y_;
  579. if (currentOffset.y_ + item->GetHeight() > windowSize.y_)
  580. newView.y_ += currentOffset.y_ + item->GetHeight() - windowSize.y_;
  581. SetViewPosition(newView);
  582. }
  583. void ListView::HandleUIMouseClick(StringHash eventType, VariantMap& eventData)
  584. {
  585. if (eventData[UIMouseClick::P_BUTTON].GetInt() != MOUSEB_LEFT)
  586. return;
  587. int qualifiers = eventData[UIMouseClick::P_QUALIFIERS].GetInt();
  588. UIElement* element = static_cast<UIElement*>(eventData[UIMouseClick::P_ELEMENT].GetPtr());
  589. unsigned numItems = GetNumItems();
  590. for (unsigned i = 0; i < numItems; ++i)
  591. {
  592. if (element == GetItem(i))
  593. {
  594. // Check doubleclick
  595. bool isDoubleClick = false;
  596. if ((!multiselect_) || (!qualifiers))
  597. {
  598. if ((doubleClickTimer_ > 0.0f) && (lastClickedItem_ == i))
  599. {
  600. isDoubleClick = true;
  601. doubleClickTimer_ = 0.0f;
  602. }
  603. else
  604. {
  605. doubleClickTimer_ = doubleClickInterval_;
  606. lastClickedItem_ = i;
  607. }
  608. SetSelection(i);
  609. }
  610. // Check multiselect with shift & ctrl
  611. if (multiselect_)
  612. {
  613. if (qualifiers & QUAL_SHIFT)
  614. {
  615. if (selections_.Empty())
  616. SetSelection(i);
  617. else
  618. {
  619. unsigned first = selections_.Front();
  620. unsigned last = selections_.Back();
  621. Set<unsigned> newSelections = selections_;
  622. if ((i == first) || (i == last))
  623. {
  624. for (unsigned j = first; j <= last; ++j)
  625. newSelections.Insert(j);
  626. }
  627. else if (i < first)
  628. {
  629. for (unsigned j = i; j <= first; ++j)
  630. newSelections.Insert(j);
  631. }
  632. else if (i < last)
  633. {
  634. if ((abs((int)i - (int)first)) <= (abs((int)i - (int)last)))
  635. {
  636. for (unsigned j = first; j <= i; ++j)
  637. newSelections.Insert(j);
  638. }
  639. else
  640. {
  641. for (unsigned j = i; j <= last; ++j)
  642. newSelections.Insert(j);
  643. }
  644. }
  645. else if (i > last)
  646. {
  647. for (unsigned j = last; j <= i; ++j)
  648. newSelections.Insert(j);
  649. }
  650. SetSelections(newSelections);
  651. }
  652. }
  653. else if (qualifiers & QUAL_CTRL)
  654. ToggleSelection(i);
  655. }
  656. if (isDoubleClick)
  657. {
  658. if (hierarchyMode_)
  659. ToggleChildItemsVisible(i);
  660. VariantMap eventData;
  661. eventData[ItemDoubleClicked::P_ELEMENT] = (void*)this;
  662. eventData[ItemDoubleClicked::P_SELECTION] = i;
  663. SendEvent(E_ITEMDOUBLECLICKED, eventData);
  664. }
  665. return;
  666. }
  667. }
  668. }