 /**
  *  DataGridAccImpl is a subclass of AccessibilityImplementation
  *  which implements accessibility for the DataGrid class.
- *  
+ *
  *  @langversion 3.0
  *  @playerversion Flash 10
  *  @playerversion AIR 1.5

        }
        else // row mode
        {
			items = dgAccInfo.dataGrid.selectedIndices;
			n = items.length;
            for (i = 0; i < n; i++)
            {
				// This time we just need rowIndex (0-based) + headerCount + 1.
                accSelection[i] = items[i] + dgAccInfo.headerCount + 1;
            }
        
        }

        return accSelection;

    }

	//--------------------------------------------------------------------------
	//
	//  Overridden event handlers: AccImpl
	//
	//--------------------------------------------------------------------------

	/**
	 *  @private
	 *  Override the generic event handler.
	 *  All AccImpl must implement this to listen
	 *  for events from its master component. 
	 */
	override protected function eventHandler(event:Event):void
	{
		// Let AccImpl class handle the events
		// that all accessible UIComponents understand.
		$eventHandler(event);

		dgAccInfo.setup(master, 0);
		if (!dgAccInfo.dataGrid.columns)
			return;

		var childID:uint;
        switch (event.type)
        {
            case GridCaretEvent.CARET_CHANGE:
            {
                var index:int;
                if (dgAccInfo.isCellMode)
                {
                    index = int(GridCaretEvent(event).newRowIndex)
                    * dgAccInfo.columnCount+int(GridCaretEvent(event).newColumnIndex);
                    focusedCell.rowIndex = GridCaretEvent(event).newRowIndex;
                    focusedCell.columnIndex = GridCaretEvent(event).newColumnIndex;
                }
                else // row mode
                {
                    focusedCell.rowIndex = GridCaretEvent(event).newRowIndex;              
                    index = focusedCell.rowIndex;
                }
                if (index >= 0)
                {
                    childID = index + 1 + dgAccInfo.headerCount;

                    Accessibility.sendEvent(dgAccInfo.dataGrid, childID,
                                            AccConst.EVENT_OBJECT_FOCUS);
                }
                break;
            }
            case GridSelectionEvent.SELECTION_CHANGING:
            {
                if (dgAccInfo.isCellMode)
                    index = GridSelectionEvent(event).selectionChange.rowIndex*dgAccInfo.columnCount + GridSelectionEvent(event).selectionChange.columnIndex;
                else
                    index = GridSelectionEvent(event).selectionChange.rowIndex;
                    
                if (index >= 0)
                {
                    childID = index + 1 + dgAccInfo.headerCount;                
                    Accessibility.sendEvent(dgAccInfo.dataGrid, childID,
                                            AccConst.EVENT_OBJECT_SELECTION);
                }
                break;
            }
        }
	}

	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------

	/**
	 *  @private
	 */
	private function cellName(rowObject:Object, columnIndex:int):String
	{
		var item:Object = rowObject;
		if (item is String)
			return "" + item;
		var dataGrid:DataGrid = DataGrid(master);
		var columns:IList = dataGrid.columns;
        if (!columns)
			return null;
		var column:Object = columns.getItemAt(columnIndex);
		if (!column)
			return null;
		return column.itemToLabel(rowObject);
	}

    /**
     *  @private
     *  Returns true if the given row is above or below the viewable area.
     */
    private function rowIndexIsScrolledOffScreen(rowIndex: int): Boolean
	{
		var dataGrid:DataGrid = DataGrid(master);
		var vpos:int = dataGrid.scroller.viewport.verticalScrollPosition;
        if (rowIndex < vpos
		|| rowIndex >= vpos + dataGrid.dataProvider.length)
			return true;
		return false;
	}

}


import mx.resources.ResourceManager;
import mx.resources.IResourceManager;
import spark.components.DataGrid;
import spark.components.Grid;
import spark.components.supportClasses.GridSelectionMode;
import spark.components.supportClasses.CellPosition;
import spark.events.GridEvent;
import spark.events.GridCaretEvent;
import spark.events.GridSelectionEvent;
import spark.events.GridSelectionEventKind;
import spark.skins.spark.DefaultGridItemRenderer;

use namespace mx_internal;
