wxWidgets Symbols and Headers

team bbl


Although wxWidgets defines a lot of symbols, there is only a handful that you are likely to need to use in your projects. Sometimes, it may be necessary to execute certain code only on certain platforms or under certain conditions, such as the following:

 #ifdef __WXMAC__ // Do something Mac-only #endif 

For your convenience, Table B-4 lists the common symbols and when they are defined. Additional symbols may be defined by the ports not covered in this book (such OS/2, Palm, and Cocoa).

Table B-4. Platform and Toolkit Symbols

Platform and Toolkit Symbols

__WXMSW__

Microsoft Windows

__WXWINCE__

Microsoft Windows CE

__WXMAC__

Mac OS X

__WXGTK__

Using the GTK library, version 1 or 2

__WXGTK20__

Using the GTK library, version 2

__UNIX__

Unix-based platform (for example, Linux, Mac OS X, HP-UX)

__DARWIN__

Open-source BSD variant used by Mac OS X

_LINUX__

Any Linux-based platform

Library / Build Options

wxUSE_UNICODE

Enable string Unicode support.

__WXDEBUG__

Library compiled with debugging support.

WX_PRECOMP

Use pre-compiled headers.


The use of defined symbols ties in very closely to wxWidgets' directory structure, as discussed in Appendix A. Consider for a moment that you can include a single file, regardless of the target platform, and yet wxWidgets always uses the correct platform information. Nearly all of the header files in include/wx have a block like the following (taken from combobox.h):

 #if defined(__WXUNIVERSAL__)     #include "wx/univ/combobox.h" #elif defined(__WXMSW__)     #include "wx/msw/combobox.h" #elif defined(__WXMOTIF__)     #include "wx/motif/combobox.h" #elif defined(__WXGTK__)     #include "wx/gtk/combobox.h" #elif defined(__WXMAC__)     #include "wx/mac/combobox.h" #elif defined(__WXCOCOA__)     #include "wx/cocoa/combobox.h" #elif defined(__WXPM__)     #include "wx/os2/combobox.h" #endif 

By using the symbols defined for various platforms or toolkits, one common header file can include the correct platform-specific header without you needing to perform these tedious checks yourself. Simply include the correct header in include/wx, and wxWidgets does the rest. For example, you would only need to use one line to add the necessary headers to support combo boxes:

 #include "wx/combobox.h" 

However, it would still be very tedious to add the headers for all of the wxWidgets classes that you use in each source file. wxWidgets provides include/wx/wx.h, which itself includes many of the commonly used class headers. There is also include/wx/wxprec.h, which you need to include when using precompiled headers on supported platforms. For example:

 // For compilers that support precompilation, includes "wx.h". #include <wx/wxprec.h> #ifndef WX_PRECOMP // Include your minimal set of headers here, or wx.h #include <wx/wx.h> #endif ... now your other include files ... 

If your code must work across different versions of wxWidgets, it's useful to know about the macro wxCHECK_VERSION(major, minor, release). It succeeds if the version that the source is being compiled against is at least the version specified. For example:

 #if wxCHECK_VERSION(2,5,5)     // Anything for wxWidgets 2.5.5 and above #else     // Anything for wxWidgets 2.5.4 and below #endif 

    team bbl



    Cross-Platform GUI Programming with wxWidgets
    Cross-Platform GUI Programming with wxWidgets
    ISBN: 0131473816
    EAN: 2147483647
    Year: 2005
    Pages: 262

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net