fdo#39440 reduce scope of local variables

This addresses some cppcheck warnings.
in addition: simplified some simple bool checks:
    "if (!bVar)" instead of "if(bVar == false)"

Change-Id: I609b4a3ee7d43bbeeb91ba141af2c90511d0c8d7
Reviewed-on: https://gerrit.libreoffice.org/13455
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>