The interaction of planetary nebulae and their asymptotic giant branch progenitors with the interstellar medium