Fix several size calculation issues in Window and Dialog