fix combobox signal handling

This commit is contained in:
Vadim Lopatin 2016-01-12 13:27:56 +03:00
parent c9c9837da5
commit 007784cfb4
2 changed files with 13 additions and 4 deletions

View File

@ -128,13 +128,15 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
_popupList = null;
};
_popupList.itemSelected = delegate(Widget source, int index) {
selectedItemIndex = index;
//selectedItemIndex = index;
return true;
};
_popupList.itemClick = delegate(Widget source, int index) {
selectedItemIndex = index;
if (_popup !is null)
if (_popup !is null) {
_popup.close();
_popup = null;
}
return true;
};
_popupList.setFocus();
@ -214,7 +216,8 @@ class ComboBox : ComboBoxBase {
@property void items(dstring[] items) {
setAdapter(new StringListAdapter(items));
if(items.length > 0) {
selectedItemIndex = 0;
if (selectedItemIndex == -1 || selectedItemIndex > items.length)
selectedItemIndex = 0;
}
requestLayout();
}
@ -276,6 +279,11 @@ class ComboBox : ComboBoxBase {
return super.selectedItemIndex(index);
}
/** Selected item index. */
override @property int selectedItemIndex() {
return super.selectedItemIndex;
}
override void initialize() {
super.initialize();
_body.focusable = false;

View File

@ -1094,6 +1094,7 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler {
itemrc.top += rc.top - scrollOffset.y;
itemrc.bottom += rc.top - scrollOffset.y;
if (itemrc.isPointInside(Point(event.x, event.y))) {
//Log.d("mouse event action=", event.action, " button=", event.button, " flags=", event.flags);
if ((event.flags & (MouseFlag.LButton || MouseFlag.RButton)) || _selectOnHover) {
if (_selectedItemIndex != i && itemEnabled(i)) {
int prevSelection = _selectedItemIndex;
@ -1105,7 +1106,7 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler {
if (itemEnabled(i))
setHoverItem(i);
}
if (event.button == MouseFlag.LButton || event.button == MouseFlag.RButton) {
if (event.button == MouseButton.Left || event.button == MouseButton.Right) {
if ((_clickOnButtonDown && event.action == MouseAction.ButtonDown) || (!_clickOnButtonDown && event.action == MouseAction.ButtonUp)) {
if (itemEnabled(i)) {
itemClicked(i);