本文整理汇总了C++中ListboxItem::setSelected方法的典型用法代码示例。如果您正苦于以下问题:C++ ListboxItem::setSelected方法的具体用法?C++ ListboxItem::setSelected怎么用?C++ ListboxItem::setSelected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListboxItem
的用法示例。
在下文中一共展示了ListboxItem::setSelected方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setMultiselectEnabled
/*************************************************************************
Set whether the list should allow multiple selections or just a
single selection
*************************************************************************/
void Listbox::setMultiselectEnabled(bool setting)
{
// only react if the setting is changed
if (d_multiselect != setting)
{
d_multiselect = setting;
// if we change to single-select, deselect all except the first selected item.
WindowEventArgs args(this);
if ((!d_multiselect) && (getSelectedCount() > 1))
{
ListboxItem* itm = getFirstSelectedItem();
while ((itm = getNextSelected(itm)))
{
itm->setSelected(false);
}
onSelectionChanged(args);
}
onMultiselectModeChanged(args);
}
}
示例2: onMouseButtonDown
/*************************************************************************
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;
}
}