When I'm figuring up the cost basis, do I add in only the ordinary gains?

Don't try to make it too difficult. Your cost basis in the mutual fund is simply your purchases, plus any dividends that were reinvested. It doesn't matter whether the dividends were ordinary income or capital gains.