/************************************************************************* 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; } }
/************************************************************************* Set the select state of an attached ListboxItem. *************************************************************************/ void Combobox::setItemSelectState(size_t item_index, bool state) { ComboDropList* droplist = getDropList(); ListboxItem* item = (droplist->getItemCount() > item_index) ? droplist->getListboxItemFromIndex(item_index) : 0; bool was_selected = (item && item->isSelected()); droplist->setItemSelectState(item_index, state); itemSelectChangeTextUpdate(item, state, was_selected); }