ListView.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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 = GetRoot();
  74. XMLElement itemElem = element.GetChild("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.GetNext("listitem");
  86. }
  87. }
  88. }
  89. if (element.HasChild("highlight"))
  90. {
  91. String highlight = element.GetChild("highlight").GetStringLower("value");
  92. SetHighlightMode((HighlightMode)GetStringListIndex(highlight, highlightModes, HM_FOCUS));
  93. }
  94. if (element.HasChild("multiselect"))
  95. SetMultiselect(element.GetChild("multiselect").GetBool("enable"));
  96. if (element.HasChild("hierarchy"))
  97. SetHierarchyMode(element.GetChild("hierarchy").GetBool("enable"));
  98. if (element.HasChild("clearselection"))
  99. SetClearSelectionOnDefocus(element.GetChild("clearselection").GetBool("enable"));
  100. if (element.HasChild("doubleclickinterval"))
  101. SetDoubleClickInterval(element.GetChild("doubleclickinterval").GetFloat("value"));
  102. XMLElement selectionElem = element.GetChild("selection");
  103. while (selectionElem)
  104. {
  105. AddSelection(selectionElem.GetInt("value"));
  106. selectionElem = selectionElem.GetNext("selection");
  107. }
  108. // Set the container's layout border to match scroll panel clipping, so that elements are not left partially hidden
  109. contentElement_->SetLayoutBorder(scrollPanel_->GetClipBorder());
  110. }
  111. void ListView::Update(float timeStep)
  112. {
  113. if (doubleClickTimer_ > 0.0f)
  114. doubleClickTimer_ = Max(doubleClickTimer_ - timeStep, 0.0f);
  115. }
  116. void ListView::OnKey(int key, int buttons, int qualifiers)
  117. {
  118. // If no selection, can not move with keys
  119. unsigned numItems = GetNumItems();
  120. unsigned selection = GetSelection();
  121. if (selection != M_MAX_UNSIGNED && numItems)
  122. {
  123. // If either shift or ctrl held down, add to selection if multiselect enabled
  124. bool additive = multiselect_ && qualifiers != 0;
  125. switch (key)
  126. {
  127. case KEY_LEFT:
  128. if (hierarchyMode_)
  129. {
  130. SetChildItemsVisible(selection, false);
  131. return;
  132. }
  133. break;
  134. case KEY_RIGHT:
  135. if (hierarchyMode_)
  136. {
  137. SetChildItemsVisible(selection, true);
  138. return;
  139. }
  140. break;
  141. case KEY_RETURN:
  142. if (hierarchyMode_)
  143. {
  144. ToggleChildItemsVisible(selection);
  145. return;
  146. }
  147. break;
  148. case KEY_UP:
  149. ChangeSelection(-1, additive);
  150. return;
  151. case KEY_DOWN:
  152. ChangeSelection(1, additive);
  153. return;
  154. case KEY_PAGEUP:
  155. {
  156. // Convert page step to pixels and see how many items have to be skipped to reach that many pixels
  157. int stepPixels = ((int)(pageStep_ * scrollPanel_->GetHeight())) - GetSelectedItem()->GetHeight();
  158. unsigned newSelection = selection;
  159. unsigned okSelection = selection;
  160. while (newSelection < numItems)
  161. {
  162. UIElement* item = GetItem(newSelection);
  163. int height = 0;
  164. if (item->IsVisible())
  165. {
  166. height = item->GetHeight();
  167. okSelection = newSelection;
  168. }
  169. if (stepPixels < height)
  170. break;
  171. stepPixels -= height;
  172. --newSelection;
  173. }
  174. if (!additive)
  175. SetSelection(okSelection);
  176. else
  177. AddSelection(okSelection);
  178. }
  179. return;
  180. case KEY_PAGEDOWN:
  181. {
  182. int stepPixels = ((int)(pageStep_ * scrollPanel_->GetHeight())) - GetSelectedItem()->GetHeight();
  183. unsigned newSelection = selection;
  184. unsigned okSelection = selection;
  185. while (newSelection < numItems)
  186. {
  187. UIElement* item = GetItem(newSelection);
  188. int height = 0;
  189. if (item->IsVisible())
  190. {
  191. height = item->GetHeight();
  192. okSelection = newSelection;
  193. }
  194. if (stepPixels < height)
  195. break;
  196. stepPixels -= height;
  197. ++newSelection;
  198. }
  199. if (!additive)
  200. SetSelection(okSelection);
  201. else
  202. AddSelection(okSelection);
  203. }
  204. return;
  205. case KEY_HOME:
  206. ChangeSelection(-(int)GetNumItems(), additive);
  207. return;
  208. case KEY_END:
  209. ChangeSelection(GetNumItems(), additive);
  210. return;
  211. }
  212. }
  213. using namespace UnhandledKey;
  214. VariantMap eventData;
  215. eventData[P_ELEMENT] = (void*)this;
  216. eventData[P_KEY] = key;
  217. eventData[P_BUTTONS] = buttons;
  218. eventData[P_QUALIFIERS] = qualifiers;
  219. SendEvent(E_UNHANDLEDKEY, eventData);
  220. }
  221. void ListView::OnResize()
  222. {
  223. ScrollView::OnResize();
  224. // Set the content element width to match the scrollpanel
  225. contentElement_->SetWidth(scrollPanel_->GetWidth());
  226. }
  227. void ListView::OnFocus()
  228. {
  229. UpdateSelectionEffect();
  230. }
  231. void ListView::OnDefocus()
  232. {
  233. if (clearSelectionOnDefocus_)
  234. ClearSelection();
  235. UpdateSelectionEffect();
  236. }
  237. void ListView::AddItem(UIElement* item)
  238. {
  239. InsertItem(contentElement_->GetNumChildren(), item);
  240. }
  241. void ListView::InsertItem(unsigned index, UIElement* item)
  242. {
  243. if (!item || item->GetParent() == contentElement_)
  244. return;
  245. // Enable input so that clicking the item can be detected
  246. item->SetActive(true);
  247. item->SetSelected(false);
  248. contentElement_->InsertChild(index, item);
  249. // If necessary, shift the following selections
  250. Set<unsigned> prevSelections;
  251. selections_.Clear();
  252. for (Set<unsigned>::Iterator j = prevSelections.Begin(); j != prevSelections.End(); ++j)
  253. {
  254. if (*j >= index)
  255. selections_.Insert(*j + 1);
  256. else
  257. selections_.Insert(*j);
  258. }
  259. UpdateSelectionEffect();
  260. }
  261. void ListView::RemoveItem(UIElement* item)
  262. {
  263. unsigned numItems = GetNumItems();
  264. for (unsigned i = 0; i < numItems; ++i)
  265. {
  266. if (GetItem(i) == item)
  267. {
  268. item->SetSelected(false);
  269. selections_.Erase(i);
  270. // Remove any child items in hierarchy mode
  271. unsigned removed = 1;
  272. if (hierarchyMode_)
  273. {
  274. int baseIndent = GetItemIndent(item);
  275. int j = i + 1;
  276. for (;;)
  277. {
  278. UIElement* childItem = GetItem(i + 1);
  279. if (!childItem)
  280. break;
  281. if (GetItemIndent(childItem) > baseIndent)
  282. {
  283. childItem->SetSelected(false);
  284. selections_.Erase(j);
  285. contentElement_->RemoveChild(childItem);
  286. ++removed;
  287. }
  288. else
  289. break;
  290. ++j;
  291. }
  292. }
  293. // If necessary, shift the following selections
  294. Set<unsigned> prevSelections;
  295. selections_.Clear();
  296. for (Set<unsigned>::Iterator j = prevSelections.Begin(); j != prevSelections.End(); ++j)
  297. {
  298. if (*j > i)
  299. selections_.Insert(*j - removed);
  300. else
  301. selections_.Insert(*j);
  302. }
  303. UpdateSelectionEffect();
  304. break;
  305. }
  306. }
  307. contentElement_->RemoveChild(item);
  308. }
  309. void ListView::RemoveItem(unsigned index)
  310. {
  311. RemoveItem(GetItem(index));
  312. }
  313. void ListView::RemoveAllItems()
  314. {
  315. unsigned numItems = GetNumItems();
  316. for (unsigned i = 0; i < numItems; ++i)
  317. contentElement_->GetChild(i)->SetSelected(false);
  318. contentElement_->RemoveAllChildren();
  319. ClearSelection();
  320. }
  321. void ListView::SetSelection(unsigned index)
  322. {
  323. Set<unsigned> indices;
  324. indices.Insert(index);
  325. SetSelections(indices);
  326. EnsureItemVisibility(index);
  327. }
  328. void ListView::SetSelections(const Set<unsigned>& indices)
  329. {
  330. unsigned numItems = GetNumItems();
  331. // Remove first items that should no longer be selected
  332. for (Set<unsigned>::Iterator i = selections_.Begin(); i != selections_.End();)
  333. {
  334. unsigned index = *i;
  335. if (indices.Find(index) == indices.End())
  336. {
  337. Set<unsigned>::Iterator current = i++;
  338. selections_.Erase(current);
  339. using namespace Iteselected_;
  340. VariantMap eventData;
  341. eventData[P_ELEMENT] = (void*)this;
  342. eventData[P_SELECTION] = index;
  343. SendEvent(E_ITEMDESELECTED, eventData);
  344. }
  345. else
  346. ++i;
  347. }
  348. // Then add missing items
  349. for (Set<unsigned>::ConstIterator i = indices.Begin(); i != indices.End(); ++i)
  350. {
  351. unsigned index = *i;
  352. if (index < numItems)
  353. {
  354. // In singleselect mode, resend the event even for the same selection
  355. if (selections_.Find(index) == selections_.End() || !multiselect_)
  356. {
  357. selections_.Insert(*i);
  358. using namespace Iteselected_;
  359. VariantMap eventData;
  360. eventData[P_ELEMENT] = (void*)this;
  361. eventData[P_SELECTION] = *i;
  362. SendEvent(E_ITEMSELECTED, eventData);
  363. }
  364. }
  365. // If no multiselect enabled, allow setting only one item
  366. if (!multiselect_)
  367. break;
  368. }
  369. UpdateSelectionEffect();
  370. }
  371. void ListView::AddSelection(unsigned index)
  372. {
  373. if (!multiselect_)
  374. SetSelection(index);
  375. else
  376. {
  377. if (index >= GetNumItems())
  378. return;
  379. Set<unsigned> newSelections = selections_;
  380. newSelections.Insert(index);
  381. SetSelections(newSelections);
  382. EnsureItemVisibility(index);
  383. }
  384. }
  385. void ListView::RemoveSelection(unsigned index)
  386. {
  387. if (index >= GetNumItems())
  388. return;
  389. Set<unsigned> newSelections = selections_;
  390. newSelections.Erase(index);
  391. SetSelections(newSelections);
  392. EnsureItemVisibility(index);
  393. }
  394. void ListView::ToggleSelection(unsigned index)
  395. {
  396. unsigned numItems = GetNumItems();
  397. if (index >= numItems)
  398. return;
  399. if (selections_.Find(index) != selections_.End())
  400. RemoveSelection(index);
  401. else
  402. AddSelection(index);
  403. }
  404. void ListView::ChangeSelection(int delta, bool additive)
  405. {
  406. if (selections_.Empty())
  407. return;
  408. if (!multiselect_)
  409. additive = false;
  410. // If going downwards, use the last selection as a base. Otherwise use first
  411. unsigned selection = delta > 0 ? selections_.Back() : selections_.Front();
  412. unsigned numItems = GetNumItems();
  413. unsigned newSelection = selection;
  414. unsigned okSelection = selection;
  415. while (delta != 0)
  416. {
  417. if (delta > 0)
  418. {
  419. ++newSelection;
  420. if (newSelection >= numItems)
  421. break;
  422. }
  423. if (delta < 0)
  424. {
  425. --newSelection;
  426. if (newSelection >= numItems)
  427. break;
  428. }
  429. UIElement* item = GetItem(newSelection);
  430. if (item->IsVisible())
  431. {
  432. okSelection = newSelection;
  433. if (delta > 0)
  434. --delta;
  435. if (delta < 0)
  436. ++delta;
  437. }
  438. }
  439. if (!additive)
  440. SetSelection(okSelection);
  441. else
  442. AddSelection(okSelection);
  443. }
  444. void ListView::ClearSelection()
  445. {
  446. SetSelections(Set<unsigned>());
  447. UpdateSelectionEffect();
  448. }
  449. void ListView::SetHighlightMode(HighlightMode mode)
  450. {
  451. highlightMode_ = mode;
  452. UpdateSelectionEffect();
  453. }
  454. void ListView::SetMultiselect(bool enable)
  455. {
  456. multiselect_ = enable;
  457. }
  458. void ListView::SetHierarchyMode(bool enable)
  459. {
  460. hierarchyMode_ = enable;
  461. }
  462. void ListView::SetClearSelectionOnDefocus(bool enable)
  463. {
  464. clearSelectionOnDefocus_ = enable;
  465. }
  466. void ListView::SetDoubleClickInterval(float interval)
  467. {
  468. doubleClickInterval_ = interval;
  469. }
  470. void ListView::SetChildItemsVisible(unsigned index, bool enable)
  471. {
  472. unsigned numItems = GetNumItems();
  473. if (!hierarchyMode_ || index >= numItems)
  474. return;
  475. int baseIndent = GetItemIndent(GetItem(index));
  476. for (unsigned i = index + 1; i < numItems; ++i)
  477. {
  478. UIElement* item = GetItem(i);
  479. if (GetItemIndent(item) > baseIndent)
  480. item->SetVisible(enable);
  481. else
  482. break;
  483. }
  484. }
  485. void ListView::SetChildItemsVisible(bool enable)
  486. {
  487. unsigned numItems = GetNumItems();
  488. for (unsigned i = 0; i < numItems; ++i)
  489. {
  490. if (!GetItemIndent(GetItem(i)))
  491. SetChildItemsVisible(i, enable);
  492. }
  493. if (GetSelections().Size() == 1)
  494. EnsureItemVisibility(GetSelection());
  495. }
  496. void ListView::ToggleChildItemsVisible(unsigned index)
  497. {
  498. unsigned numItems = GetNumItems();
  499. if (!hierarchyMode_ || index >= numItems)
  500. return;
  501. int baseIndent = GetItemIndent(GetItem(index));
  502. bool firstChild = true;
  503. UIElement* prevItem = 0;
  504. for (unsigned i = index + 1; i < numItems; ++i)
  505. {
  506. UIElement* item = GetItem(i);
  507. if (GetItemIndent(item) > baseIndent)
  508. {
  509. if (firstChild)
  510. {
  511. item->SetVisible(!item->IsVisible());
  512. firstChild = false;
  513. }
  514. else
  515. item->SetVisible(prevItem->IsVisible());
  516. }
  517. else
  518. break;
  519. prevItem = item;
  520. }
  521. }
  522. unsigned ListView::GetNumItems() const
  523. {
  524. return contentElement_->GetNumChildren();
  525. }
  526. UIElement* ListView::GetItem(unsigned index) const
  527. {
  528. return contentElement_->GetChild(index);
  529. }
  530. PODVector<UIElement*> ListView::GetItems() const
  531. {
  532. return contentElement_->GetChildren();
  533. }
  534. unsigned ListView::GetSelection() const
  535. {
  536. if (selections_.Empty())
  537. return M_MAX_UNSIGNED;
  538. else
  539. return *selections_.Begin();
  540. }
  541. UIElement* ListView::GetSelectedItem() const
  542. {
  543. return contentElement_->GetChild(GetSelection());
  544. }
  545. PODVector<UIElement*> ListView::GetSelectedItems() const
  546. {
  547. PODVector<UIElement*> ret;
  548. for (Set<unsigned>::ConstIterator i = selections_.Begin(); i != selections_.End(); ++i)
  549. {
  550. UIElement* item = GetItem(*i);
  551. if (item)
  552. ret.Push(item);
  553. }
  554. return ret;
  555. }
  556. void ListView::UpdateSelectionEffect()
  557. {
  558. unsigned numItems = GetNumItems();
  559. for (unsigned i = 0; i < numItems; ++i)
  560. {
  561. UIElement* item = GetItem(i);
  562. if (highlightMode_ != HM_NEVER && selections_.Find(i) != selections_.End())
  563. item->SetSelected(focus_ || highlightMode_ == HM_ALWAYS);
  564. else
  565. item->SetSelected(false);
  566. }
  567. }
  568. void ListView::EnsureItemVisibility(unsigned index)
  569. {
  570. UIElement* item = GetItem(index);
  571. if (!item || !item->IsVisible())
  572. return;
  573. IntVector2 currentOffset = item->GetScreenPosition() - scrollPanel_->GetScreenPosition() - contentElement_->GetPosition();
  574. IntVector2 newView = GetViewPosition();
  575. const IntRect& clipBorder = scrollPanel_->GetClipBorder();
  576. IntVector2 windowSize(scrollPanel_->GetWidth() - clipBorder.left_ - clipBorder.right_, scrollPanel_->GetHeight() -
  577. clipBorder.top_ - clipBorder.bottom_);
  578. if (currentOffset.y_ < 0)
  579. newView.y_ += currentOffset.y_;
  580. if (currentOffset.y_ + item->GetHeight() > windowSize.y_)
  581. newView.y_ += currentOffset.y_ + item->GetHeight() - windowSize.y_;
  582. SetViewPosition(newView);
  583. }
  584. void ListView::HandleUIMouseClick(StringHash eventType, VariantMap& eventData)
  585. {
  586. if (eventData[UIMouseClick::P_BUTTON].GetInt() != MOUSEB_LEFT)
  587. return;
  588. int qualifiers = eventData[UIMouseClick::P_QUALIFIERS].GetInt();
  589. UIElement* element = static_cast<UIElement*>(eventData[UIMouseClick::P_ELEMENT].GetPtr());
  590. unsigned numItems = GetNumItems();
  591. for (unsigned i = 0; i < numItems; ++i)
  592. {
  593. if (element == GetItem(i))
  594. {
  595. // Check doubleclick
  596. bool isDoubleClick = false;
  597. if (!multiselect_ || !qualifiers)
  598. {
  599. if (doubleClickTimer_ > 0.0f && lastClickedItem_ == i)
  600. {
  601. isDoubleClick = true;
  602. doubleClickTimer_ = 0.0f;
  603. }
  604. else
  605. {
  606. doubleClickTimer_ = doubleClickInterval_;
  607. lastClickedItem_ = i;
  608. }
  609. SetSelection(i);
  610. }
  611. // Check multiselect with shift & ctrl
  612. if (multiselect_)
  613. {
  614. if (qualifiers & QUAL_SHIFT)
  615. {
  616. if (selections_.Empty())
  617. SetSelection(i);
  618. else
  619. {
  620. unsigned first = selections_.Front();
  621. unsigned last = selections_.Back();
  622. Set<unsigned> newSelections = selections_;
  623. if (i == first || i == last)
  624. {
  625. for (unsigned j = first; j <= last; ++j)
  626. newSelections.Insert(j);
  627. }
  628. else if (i < first)
  629. {
  630. for (unsigned j = i; j <= first; ++j)
  631. newSelections.Insert(j);
  632. }
  633. else if (i < last)
  634. {
  635. if ((abs((int)i - (int)first)) <= (abs((int)i - (int)last)))
  636. {
  637. for (unsigned j = first; j <= i; ++j)
  638. newSelections.Insert(j);
  639. }
  640. else
  641. {
  642. for (unsigned j = i; j <= last; ++j)
  643. newSelections.Insert(j);
  644. }
  645. }
  646. else if (i > last)
  647. {
  648. for (unsigned j = last; j <= i; ++j)
  649. newSelections.Insert(j);
  650. }
  651. SetSelections(newSelections);
  652. }
  653. }
  654. else if (qualifiers & QUAL_CTRL)
  655. ToggleSelection(i);
  656. }
  657. if (isDoubleClick)
  658. {
  659. if (hierarchyMode_)
  660. ToggleChildItemsVisible(i);
  661. VariantMap eventData;
  662. eventData[ItemDoubleClicked::P_ELEMENT] = (void*)this;
  663. eventData[ItemDoubleClicked::P_SELECTION] = i;
  664. SendEvent(E_ITEMDOUBLECLICKED, eventData);
  665. }
  666. return;
  667. }
  668. }
  669. }