Optical forces in the T-matrix formalism