/************************************************************************* Set the select state of an attached ListboxItem. *************************************************************************/ void Listbox::setItemSelectState(size_t item_index, bool state) { if (item_index < getItemCount()) { // only do this if the setting is changing if (d_listItems[item_index]->isSelected() != state) { // conditions apply for single-select mode if (state && !d_multiselect) { clearAllSelections_impl(); } d_listItems[item_index]->setSelected(state); WindowEventArgs args(this); onSelectionChanged(args); } } else { CEGUI_THROW(InvalidRequestException("Listbox::setItemSelectState - the value passed in the 'item_index' parameter is out of range for this Listbox.")); } }
/************************************************************************* Clear the selected state for all items. *************************************************************************/ void Tree::clearAllSelections(void) { // only fire events and update if we actually made any changes if (clearAllSelections_impl()) { TreeEventArgs args(this); onSelectionChanged(args); } }
/************************************************************************* Handler for when mouse button is pressed *************************************************************************/ void Listbox::onMouseButtonDown(MouseEventArgs& e) { // base class processing Window::onMouseButtonDown(e); if (e.button == LeftButton) { bool modified = false; // clear old selections if no control key is pressed or if multi-select is off if (!(e.sysKeys & Control) || !d_multiselect) { modified = clearAllSelections_impl(); } Point localPos(screenToWindow(e.position)); if (getMetricsMode() == Relative) { localPos = relativeToAbsolute(localPos); } ListboxItem* item = getItemAtPoint(localPos); if (item != NULL) { modified = true; // select range or item, depending upon keys and last selected item if (((e.sysKeys & Shift) && (d_lastSelected != NULL)) && d_multiselect) { selectRange(getItemIndex(item), getItemIndex(d_lastSelected)); } else { item->setSelected(item->isSelected() ^ true); } // update last selected item d_lastSelected = item->isSelected() ? item : NULL; } // fire event if needed if (modified) { WindowEventArgs args(this); onSelectionChanged(args); } e.handled = true; } }
/************************************************************************* Handler for when input capture is lost *************************************************************************/ void ComboDropList::onCaptureLost(WindowEventArgs& e) { Listbox::onCaptureLost(e); d_armed = false; hide(); ++e.handled; // ensure 'sticky' selection remains. if ((d_lastClickSelected) && !d_lastClickSelected->isSelected()) { clearAllSelections_impl(); setItemSelectState(d_lastClickSelected, true); } }
/************************************************************************* Set the select state of an attached TreeItem. *************************************************************************/ void Tree::setItemSelectState(TreeItem* item, bool state) { if (containsOpenItemRecursive(d_listItems, item)) { TreeEventArgs args(this); args.treeItem = item; if (state && !d_multiselect) clearAllSelections_impl(); item->setSelected(state); d_lastSelected = item->isSelected() ? item : 0; onSelectionChanged(args); } else { CEGUI_THROW(InvalidRequestException("the specified TreeItem is not " "attached to this Tree or not visible.")); } }
/************************************************************************* Handler for when mouse button is pressed *************************************************************************/ void Tree::onMouseButtonDown(MouseEventArgs& e) { // base class processing // populateGeometryBuffer(); Window::onMouseButtonDown(e); if (e.button == LeftButton) { //bool modified = false; Vector2f localPos(CoordConverter::screenToWindow(*this, e.position)); // Point localPos(screenToWindow(e.position)); TreeItem* item = getItemAtPoint(localPos); if (item != 0) { //modified = true; TreeEventArgs args(this); args.treeItem = item; populateGeometryBuffer(); Rectf buttonLocation = item->getButtonLocation(); if ((localPos.d_x >= buttonLocation.left()) && (localPos.d_x <= buttonLocation.right()) && (localPos.d_y >= buttonLocation.top()) && (localPos.d_y <= buttonLocation.bottom())) { item->toggleIsOpen(); if (item->getIsOpen()) { TreeItem *lastItemInList = item->getTreeItemFromIndex(item->getItemCount() - 1); ensureItemIsVisible(lastItemInList); ensureItemIsVisible(item); onBranchOpened(args); } else { onBranchClosed(args); } // Update the item screen locations, needed to update the scrollbars. // populateGeometryBuffer(); // Opened or closed a tree branch, so must update scrollbars. configureScrollbars(); } else { // clear old selections if no control key is pressed or if multi-select is off if (!(e.sysKeys & Control) || !d_multiselect) clearAllSelections_impl(); // select range or item, depending upon keys and last selected item #if 0 // TODO: fix this if (((e.sysKeys & Shift) && (d_lastSelected != 0)) && d_multiselect) selectRange(getItemIndex(item), getItemIndex(d_lastSelected)); else #endif item->setSelected(item->isSelected() ^ true); // update last selected item d_lastSelected = item->isSelected() ? item : 0; onSelectionChanged(args); } } else { // clear old selections if no control key is pressed or if multi-select is off if (!(e.sysKeys & Control) || !d_multiselect) { if (clearAllSelections_impl()) { // Changes to the selections were actually made TreeEventArgs args(this); args.treeItem = item; onSelectionChanged(args); } } } ++e.handled; } }