//-----------------------------------------------------------------------------
#include "AnalysisDataGridTable.h"
#include "DrawingCanvas.h"

//-----------------------------------------------------------------------------
AnalysisDataGridTable::AnalysisDataGridTable( ImageAnalysisPlotCanvas* pParent, long rows, long columns ) : wxGridTableBase(),
  m_pParent(pParent), m_Rows(rows), m_Columns(columns)
//-----------------------------------------------------------------------------
{

}

//-----------------------------------------------------------------------------
wxString AnalysisDataGridTable::GetValue( int row, int col )
//-----------------------------------------------------------------------------
{
	return m_pParent->GetGridValue( row, col );
}

//-----------------------------------------------------------------------------
bool AnalysisDataGridTable::UpdateRowsCols( long rows, long cols )
//-----------------------------------------------------------------------------
{
	bool updated = false;
	if( GetView() )
	{
		if( rows > m_Rows )
		{
			wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, m_Rows - 1, rows - m_Rows);
			GetView()->ProcessTableMessage( msg );
			updated = true;
		}
		else if( rows < m_Rows )
		{
			wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, m_Rows - 1, m_Rows - rows);
			GetView()->ProcessTableMessage( msg );
			updated = true;
		}

		if( cols > m_Columns )
		{
			wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_COLS_INSERTED, m_Columns - 1, cols - m_Columns);
			GetView()->ProcessTableMessage( msg );
			updated = true;
		}
		else if( cols < m_Columns )
		{
			wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_COLS_DELETED,  m_Columns - 1, m_Columns - cols);
			GetView()->ProcessTableMessage( msg );
			updated = true;
		}
	}
	m_Rows = rows;
	m_Columns = cols;
	return updated;
}
