Fixed crash on OSX when changing focus while the app is being closed (#327).
Fixed focus on the editor after closing a dialog on OSX (fixes #328).
Added a workaround for focus switching between controls on OSX (#89, #327).

This is a more complete workaround for missing KILL_FOCUS event on OSX (an
incomplete workaround was removed by a315b1a8).