ref #8146 Fix potential class cast exceptions
ref #7923 Set character representation during creation
ref #7923 Use character transfer instead of LocalSelectionTransfer