% Author: Matthew Dawson matthew@mjdsystems.ca
% Organization: McMaster Centre for Software Certification
function add_column( object, after_cell_index )
%ADD_COLUMN Add a column to the grid.  If there are no rows, then no new
%cells will be added.
%   This function adds a new cell such that after_cell_index is the next
%   column index after the new cell.  If no rows exist, then it only stores
%   the count of columns.  If after_cell_index is either [] or equal to the
%   number of columns+1, append.

    object.width = object.width + 1;

    if object.height ~= 0
        if isempty(after_cell_index)
            object.grid(object.height, object.width) = TableGridCell();
            after_cell_index = object.width;
        else
            tmp(object.height, 1) = TableGridCell();
            object.grid = [ object.grid(:, 1:(after_cell_index-1)) tmp object.grid(:, after_cell_index:size(object.grid, 2)) ];
        end
    end
    notify(object, 'AddedColumn', GridSingleColumnEventDetails(after_cell_index));

    notify(object, 'StructureChanged');
end

