WxWidgets Source Oddities
Whilst browsing the wx sources, you probably came across some weird macros or some non-trivial motifs. This page reveals the ideas behind these source oddities, along with usage guidelines for developers.
wxT() and _T()
Meaning: "T" stands for "text", not "translate"
Intent: Unicode support.
Motivation: wxWidgets supports either Unicode or ANSI compilations, in the past these macros were used to ensure that your strings (or chars) are defined correctly in respect to the current compilation mode.
When to use: Virtually never. (Unless you are using wxWidgets 2.8.x or older.) In any case, prefer wxT() to _T() if you do use it.
Where to use: Virtually nowhere in new code.
Sample code:
wxLogError(wxT("Could not determine current location."));
Defined in: wxchar.h
Remarks: See Unicode support in wxWidgets for more information.
_()
Synonym: wxGetTranslation().
Intent: Translation of strings into non-English language. (Internationalization)
Motivation: This macro translates strings into other languages based on a translation catalog.
When to use: Whenever your application should support multi-language support.
Where to use: On strings that should be translated.
Sample code:
wxLogError(_("Macro name is too detailed."));
Defined in: intl.h
Remarks: _() is a superset of _T(), so _(_T("str")) should be written just _("str"). See Internationalization for more information.
__GNUG__
Intent: To improve GCC compilation performances.
Motivation: As above.
When to use: Always.
Where to use: On the top of every source file.
Sample code:
- in the .h (interface) files:
#ifdef __GNUG__ #pragma interface "listctrl.h" #endif
- in the .cpp (implementation) files:
#ifdef __GNUG__ #pragma implementation "listctrl.h" #endif
Defined in: Defined by the compiler.
Remarks: For more information see the gcc section in Compiler Issues.
WXUNUSED()
Intent: To reduce compiler warnings.
Motivation: Some compilers shout when a function makes no use of one of its parameters.
When to use: Whenever your function does not use one of its parameters.
Where to use: On the unused parameter.
Sample code:
bool wxListCtrl::SetItemImage(long item, int image, int WXUNUSED(selImage)) { ... }
Related macros: WXUNUSED_UNLESS_DEBUG.
Defined in: defs.h
DECLARE_DYNAMIC_CLASS() and IMPLEMENT_DYNAMIC_CLASS( , )
See: DYNAMIC CLASS Macros