/* * Copyright 2009 (c) ViZiO 360ยบ, simone@vizio360.co.uk * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ package { import fl.controls.TileList; import fl.controls.listClasses.ICellRenderer; import fl.core.InvalidationType; import fl.events.ListEvent; import flash.events.Event; import flash.events.MouseEvent; /** * Extensions of the Basic Adobe TileList component to be able * to deselect an item and have no items selected when not * in multiple selection mode. * * * @author Simone Vicentini * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ public class AllowNoSelectionTileList extends TileList { /** enable in single item selection the ability to toggle the item */ public var allowNoSelection:Boolean = false; /** * Class constructor */ public function AllowNoSelectionTileList() { super(); } /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ override protected function handleCellRendererClick(event:MouseEvent):void { if (!_enabled) { return; } var renderer:ICellRenderer = event.currentTarget as ICellRenderer; var itemIndex:uint = renderer.listData.index; // this event is cancellable: if (!dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK, false, true, renderer.listData.column, renderer.listData.row, itemIndex, renderer.data)) || !_selectable) { return; } var selectIndex:int = selectedIndices.indexOf(itemIndex); var i:int; if (!_allowMultipleSelection) { //ALLOW NO SELECTION CHECK if (!allowNoSelection) { //NORMAL BEHAVIOUR if (selectIndex != -1) { return; } else { renderer.selected = true; _selectedIndices = [itemIndex]; } } else { //MODIFIED BEHAVIOUR TO ENABLE NO SELECTION renderer.selected = !renderer.selected; if (renderer.selected) { _selectedIndices = [itemIndex]; } else { _selectedIndices = []; itemIndex = 0; } } lastCaretIndex = caretIndex = itemIndex; } else { if (event.shiftKey) { var oldIndex:uint = (_selectedIndices.length > 0) ? _selectedIndices[0] : itemIndex; _selectedIndices = []; if (oldIndex > itemIndex) { for (i = oldIndex; i >= itemIndex; i--) _selectedIndices.push(i); } else { for (i = oldIndex; i <= itemIndex; i++) _selectedIndices.push(i); } caretIndex = itemIndex; } else if (event.ctrlKey) { if (selectIndex != -1) { renderer.selected = false; _selectedIndices.splice(selectIndex,1); } else { renderer.selected = true; _selectedIndices.push(itemIndex); } caretIndex = itemIndex; } else { _selectedIndices = [itemIndex]; lastCaretIndex = caretIndex = itemIndex; } } dispatchEvent(new Event(Event.CHANGE)); invalidate(InvalidationType.DATA); } } }