Restore app keyboard focus after dismissing dialogs on OSX

This closes #2318

This also makes all of the new native window and context getters into virtual functions.

cc @arturoc @ofTheo