I guess for now the only thing to comment here is the purpose LeaveGMutexAll... "GMutex" (mutex for GUI) is designed to work recursively, means Lock/Unlock can be nested in single thread. GMutex keeps 'level' of those locks/unlocks.
Then in ICall we need to "completely unlock" GMutex, so that if called from another thread than non-main, main thread can lock GMutex regardless of how many times it was locked in that another thread. So LeaveGMutexAll unlocks 'level' times and returns level, so that after finishing the function in the main thread, it can be locked that many times again (and gui locking in other thread is not corrupted).