Unicode

Regular ASCII character codes use values 0..255 (char datatype). This is good for english letters (there are 26 lower case, 26 upper case, 10 numbers, and some symbols), but it is inappropriate for languages like chinese.

Therefore a larger character set was defined by the UNICODE consortium. (see www.unicode.org). In unicode, each character uses 4 (sometimes 2) bytes. Modern GUI toolkits should provide support for unicode.

When compiling wxWidgets, you have a choice to do so. If you have the Mac OS X version of you have compiled it with my instructions, your wxWidgets is the unicode version.

Unfortunately, when we define a string using "" it is by default the old version of the string (an array of char). So we need a way to convert from classical strings to unicode strings. We use the wxT() macro to do so. Example: wxT("Hello") would result in a unicode-string representing Hello.

To represent unicode characters, use the wxChar datatype.

To represent unicode strings, use the wxString datatype. It behaves almost the same as the STL string datatype.

Short rules:

  • Always use wxChar instead of char.

  • Always enclose literal string constants in wxT() macro unless they're already converted to the right representation or you intend to pass the constant directly to an external function which doesn't accept wide-character strings.

  • Use wxString instead of C style strings.

Please note: If you have compiled wxWidgets yourself, you version may not use unicode. In this case, the above macros will still work, and default to the non-unicode version. (e.g. wxT() will not do anything). However, I will test your program on an unicode version! So unless you have the wxT() macros, you I will get compiler errors and you loose points. Please either recompile wxWidgets or test your program in the lab!