Make it possible to reuse this code for other, non-wx, windows. No real changes, this is just a pure refactoring.