def getSelectedCells(grid):
    """Get list of (row, col) pairs of all selected cells.
    Unlike grid.GetSelectedCells this returns them all no matter
    how they were selected.
    """
    rows = grid.GetNumberRows()
    cols = grid.GetNumberCols()
    allrows = range(rows)
    allcols = range(cols)
    rcset = set()
    for r in grid.GetSelectedRows():
        rcset.update(zip(cols * [r], allcols))
    for c in grid.GetSelectedCols():
        rcset.update(zip(allrows, rows * [c]))
    blocks = zip(grid.GetSelectionBlockTopLeft(), grid.
        GetSelectionBlockBottomRight())
    for tl, br in blocks:
        brows = range(tl[0], br[0] + 1)
        bcols = range(tl[1], br[1] + 1)
        rcset.update((r, c) for r in brows for c in bcols)
    rcset.update(grid.GetSelectedCells())
    rv = sorted(rcset)
    return rv
