Add some additional documentation to the file format code.

This should be helpful to users writing file format add-ins.
[Fixes bug #1181683] Fix issue with the Text Tool not redrawing properly.
[Fixes bug #1179280] Fix crash with Crop to Selection after pasting.

The Move Selected tool depends on having a set of selection polygons.
The original code cleared out the selection polygons, but created a
selection path. The Move Selected tool then cleared out the path (since
there were no selection polygons), which caused the crop tool to attempt
to crop a zero-sized rectangle.
[Fixes bug #1064283 and #1181929] Fix off-by-one error for the
invalidation rectangle when zoomed in.

The original code did not take into account that one
pixel in the image can correspond to multiple pixels on the canvas when
zoomed in. This resulted in the invalidation rectangle being slightly
too small. However, the invalidation rectangle is usually too large, so
it was hard to notice this bug in most cases.
[Fixes bug #1176847] Display the selection layer on top of the active
layer in the layers list widget.

This solution fixes the original issue (bug #1175733), and I reverted
the changes that caused a regression (bug #1176847).
[Fixes bug #1181929] Fix bug with the Pencil tool drawing on the left
side of the image when you cross the right border.

The pointer arithmetic in GetColorBgra results in some interesting
behaviour when dealing with pixels outside the canvas.
[Fixes bug #1186673] Fix crash when using the Move Selected tool without
any selection.

This was due to an overly paranoid assert I added in fa8483. The new
behaviour is to just select the whole image for the user.
[Fixes bug #1186510] Fix pasting of old clipboard images on Windows.
[Fixes bug #1181929] Fix issues with drawing off-canvas with the paintbrush.

Renamed the GetColorBgra and SetColorBgra to GetColorBgraUnchecked, etc,
to indicate that no validation is performed on the canvas coordinates.
[Fixes bug #1186785] Disable a few more menu items when no documents are open.

Also removed some duplicated code to make this easier in the future.