Theory of capillary condensation