Theory of Resonant Inelastic X-Ray Scattering by Collective Magnetic Excitations