Fix UI scroll lockup.

Patch by Richard Barlow.
The attached patch fixes the UI lock up originally reported.
There are still some issues in that you can get into the state
where the layout is panning even though you're not holding the
mouse button down, but you can now exit this by clicking on
the layout.