listselector.lzx
<library>
<include href="utils/selectionmanager.lzx"/>
<class name="listselector" extends="selectionmanager">
<attribute name="multiselect" value="false
" type="boolean"/>
<attribute name="_forcemulti" value="false
" type="boolean"/>
<method name="isRangeSelect" args="item" override="true">
return this.multiselect && super.isRangeSelect(item);
</method>
<method name="isMultiSelect" args="item" override="true">
return this._forcemulti || (this.multiselect && super.isMultiSelect(item));
</method>
<method name="select" args="item" override="true">
if (this.multiselect && item is Array) {
this._forcemulti = true;
for (var i=0; i < item.length; i++) {
super.select(item[i]);
}
this._forcemulti = false;
} else {
super.select(item);
}
</method>
<method name="getValue">
var selection = this.getSelection();
if (selection.length == 0) return null;
if ( selection.length == 1 && !multiselect) {
return selection[0].getValue();
}
var valueArray = [];
for (var i = 0; i < selection.length; i++) {
valueArray[i] = selection[i].getValue();
}
return valueArray;
</method>
<method name="getText">
var selection = this.getSelection();
if (selection.length == 0) return null;
if ( selection.length == 1 && !multiselect) {
return selection[0].text;
}
var textArray = [];
for (var i = 0; i < selection.length; i++) {
textArray[i] = selection[i].text;
}
return textArray;
</method>
<method name="getNumItems">
if (!this.immediateparent.subviews) return 0;
return this.immediateparent.subviews.length;
</method>
<method name="getNextSubview" args="s, dir=1">
// only works for toggle
if (typeof(dir) == "undefined") dir = 1;
var svs = this.immediateparent.subviews;
// check for nothing selected case
if (!s) {
if (dir>0) {
return svs[0];
} else {
return svs[svs.length-1];
}
}
var next;
var len = svs.length;
for ( var i = 0; i < len; i++ ){
var temp = svs[i];
if (temp == s) { // found view "s"
var next_index = i + dir;
if (next_index < 0) {
next = svs[0];
} else if (next_index >= len) {
next = svs[len-1];
} else {
next = svs[next_index];
}
break;
}
}
ensureItemInView(next);
return next;
</method>
<method name="ensureItemInView" args="sel">
// check for selection below interior
if (!sel) {
return;
}
// immediateparent is the list's defaultplacement view
var clipview = immediateparent.parent;
var changed = false;
if ( (sel.y+sel.height) > clipview.height - immediateparent.y ) {
var diff = clipview.height - immediateparent.y - (sel.y+sel.height);
var newY = Math.max((clipview.height - immediateparent.height),
immediateparent.y+diff);
immediateparent.setAttribute("y",newY);
changed = true;
} else
// check for selection above interior
if ( (immediateparent.y*-1) > sel.y ) {
var diff = (immediateparent.y*-1)-sel.y;
var newY = Math.min(0, (immediateparent.y+diff));
immediateparent.setAttribute("y",newY);
changed = true;
}
if (changed) {
this._updatefromscrolling = true;
}
</method>
<attribute name="_updatefromscrolling" value="false
"/>
<method name="allowhilite" args="v">
if (this._updatefromscrolling) {
if (v != null) this._updatefromscrolling = false;
return false;
}
return true;
</method>
<method name="getItemByIndex" args="index">
return this.parent._contentview.subviews[index];
</method>
</class>
</library>
Cross References
Includes
Classes