//>>built
define("dojox/grid/Selection",["dojo/_base/declare","dojo/_base/array","dojo/_base/lang","dojo/dom-attr"],function(g,d,c,f){return g("dojox.grid.Selection",null,{constructor:function(a){this.grid=a;this.selected=[];this.setMode(a.selectionMode)},mode:"extended",selected:null,updating:0,selectedIndex:-1,rangeStartIndex:-1,setMode:function(a){this.selected.length&&this.deselectAll();this.mode="extended"!=a&&"multiple"!=a&&"single"!=a&&"none"!=a?"extended":a},onCanSelect:function(a){return this.grid.onCanSelect(a)},
onCanDeselect:function(a){return this.grid.onCanDeselect(a)},onSelected:function(a){},onDeselected:function(a){},onChanging:function(){},onChanged:function(){},isSelected:function(a){return"none"==this.mode?!1:this.selected[a]},getFirstSelected:function(){if(!this.selected.length||"none"==this.mode)return-1;for(var a=0,b=this.selected.length;a<b;a++)if(this.selected[a])return a;return-1},getNextSelected:function(a){if("none"==this.mode)return-1;a+=1;for(var b=this.selected.length;a<b;a++)if(this.selected[a])return a;
return-1},getSelected:function(){for(var a=[],b=0,e=this.selected.length;b<e;b++)this.selected[b]&&a.push(b);return a},getSelectedCount:function(){for(var a=0,b=0;b<this.selected.length;b++)this.selected[b]&&a++;return a},_beginUpdate:function(){if(0===this.updating)this.onChanging();this.updating++},_endUpdate:function(){this.updating--;if(0===this.updating)this.onChanged()},select:function(a){"none"!=this.mode&&("multiple"!=this.mode?(this.deselectAll(a),this.addToSelection(a)):this.toggleSelect(a))},
addToSelection:function(a){if("none"!=this.mode)if(c.isArray(a))d.forEach(a,this.addToSelection,this);else if(a=Number(a),this.selected[a])this.selectedIndex=a;else if(!1!==this.onCanSelect(a)){this.selectedIndex=a;var b=this.grid.getRowNode(a);b&&f.set(b,"aria-selected","true");this._beginUpdate();this.selected[a]=!0;this.onSelected(a);this._endUpdate()}},deselect:function(a){if("none"!=this.mode)if(c.isArray(a))d.forEach(a,this.deselect,this);else if(a=Number(a),this.selectedIndex==a&&(this.selectedIndex=
-1),this.selected[a]&&!1!==this.onCanDeselect(a)){var b=this.grid.getRowNode(a);b&&f.set(b,"aria-selected","false");this._beginUpdate();delete this.selected[a];this.onDeselected(a);this._endUpdate()}},setSelected:function(a,b){this[b?"addToSelection":"deselect"](a)},toggleSelect:function(a){c.isArray(a)?d.forEach(a,this.toggleSelect,this):this.setSelected(a,!this.selected[a])},_range:function(a,b,e){var c=0<=a?a:b;a=b;c>a&&(a=c,c=b);for(b=c;b<=a;b++)e(b)},selectRange:function(a,b){this._range(a,b,
c.hitch(this,"addToSelection"))},deselectRange:function(a,b){this._range(a,b,c.hitch(this,"deselect"))},insert:function(a){this.selected.splice(a,0,!1);this.selectedIndex>=a&&this.selectedIndex++},remove:function(a){this.selected.splice(a,1);this.selectedIndex>=a&&this.selectedIndex--},deselectAll:function(a){for(var b in this.selected)b!=a&&!0===this.selected[b]&&this.deselect(b)},clickSelect:function(a,b,c){if("none"!=this.mode){this._beginUpdate();if("extended"!=this.mode)this.select(a);else{if(!c||
0>this.rangeStartIndex)this.rangeStartIndex=a;b||this.deselectAll(a);c?this.selectRange(this.rangeStartIndex,a):b?this.toggleSelect(a):this.addToSelection(a)}this._endUpdate()}},clickSelectEvent:function(a){this.clickSelect(a.rowIndex,dojo.isCopyKey(a),a.shiftKey)},clear:function(){this._beginUpdate();this.deselectAll();this._endUpdate()}})});