WxWidgets Source Oddities

From WxWiki
Jump to: navigation, search

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, these macros ensure that your strings (or chars) are defined correctly in respect to the current compilation mode.

When to use: Always. (unless your string must be explicitly either Unicode or ANSI)

Where to use: On every literal string.

Sample code:

    wxLogError(wxT("Could not determine member gender (coitus.cpp)"));

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.


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"

in the .cpp (implementation) files:
    #ifdef __GNUG__
        #pragma implementation "listctrl.h"

Defined in: Defined by the compiler.

Remarks: For more information see the gcc section in Compiler Issues.


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))


Defined in: defs.h