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

View File

@ -1094,6 +1094,7 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler {
itemrc.top += rc.top - scrollOffset.y; itemrc.top += rc.top - scrollOffset.y;
itemrc.bottom += rc.top - scrollOffset.y; itemrc.bottom += rc.top - scrollOffset.y;
if (itemrc.isPointInside(Point(event.x, event.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 ((event.flags & (MouseFlag.LButton || MouseFlag.RButton)) || _selectOnHover) {
if (_selectedItemIndex != i && itemEnabled(i)) { if (_selectedItemIndex != i && itemEnabled(i)) {
int prevSelection = _selectedItemIndex; int prevSelection = _selectedItemIndex;
@ -1105,7 +1106,7 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler {
if (itemEnabled(i)) if (itemEnabled(i))
setHoverItem(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 ((_clickOnButtonDown && event.action == MouseAction.ButtonDown) || (!_clickOnButtonDown && event.action == MouseAction.ButtonUp)) {
if (itemEnabled(i)) { if (itemEnabled(i)) {
itemClicked(i); itemClicked(i);