The wxWidgets Architecture

team bbl


Table 1-1 shows the four conceptual layers: the wxWidgets public API, each major port, the platform API used by that port, and finally the underlying operating system.

Table 1-1. wxWidgets Ports

wxWidgets API

wxWidgets Port

wxMSW

wxGTK

wxX11

wxMotif

wxMac

wxCocoa

wxOS2

wxPalmOS

wxMGL

Platform API

Win32

GTK+

Xlib

Motif/Lesstif

Carbon

Cocoa

PM

Palm OS Protein APIs

MGL

Operating System

Windows/Windows CE

Unix/Linux

Mac OS 9/Mac OS X

Mac OS X

OS/2

Palm OS

Unix/DOS


The following are the main wxWidgets ports that exist at the time of writing.

wxMSW

This port compiles and runs on all 32-bit and 64-bit variants of the Microsoft Windows operating system, including Windows 95, Windows 98, Windows ME, Windows NT, Windows 2000, Windows XP and Windows 2003. It can also be compiled to use Winelib under Linux, and has a configuration that works on Windows CE (see "wxWinCE"). wxMSW can be configured to use the wxUniversal widgets instead of the regular Win32 ones.

wxGTK

wxWidgets for GTK+ can use versions 1.x or 2.x of the GTK+ widget set, on any Unix variant that supports X11 and GTK+ (for example, Linux, Solaris, HP-UX, IRIX, FreeBSD, OpenBSD, AIX, and others). It can also run on embedded platforms with sufficient resourcesfor example, under the GPE Palmtop Environment (see Figure 1-4). wxGTK is the recommended port for Unix-based systems.

Figure 1-4. The wxWidgets "Life!" demo under GPE on an iPAQ PDA


wxX11

wxWidgets for X11 uses the wxUniversal widget set and runs directly on Xlib with no native widget set. This makes the port suitable for embedded systems, but it can also be used for desktop applications where it is undesirable to link with GTK+. This is supported on any Unix system running X11. wxX11 is not as mature as the wxGTK port. Figure 1-5 shows the Life! demo compiled under wxX11 and running on Familiar Linux /TinyX on an iPAQ PDA.

Figure 1-5. The wxWidgets "Life!" demo running on embedded wxX11


wxMotif

This port can use Motif, OpenMotif, or Lesstif on most Unix systems. Sun Microsystems is putting its weight behind GNOME and GTK+, so Motif is no longer an attractive option for most developers and users.

wxMac

wxMac targets Mac OS 9 (from 9.1 upwards) and Mac OS X (from 10.2.8 upwards). For Mac OS 9 builds, you need the Metrowerks CodeWarrior tools, and for Mac OS X, you can use either Metrowerks CodeWarrior or Apple tools. When using Apple's tools, you should use Xcode 1.5 or higher, orif you are just using command line toolsGCC 3.3 or higher.

wxCocoa

A port in progress, this targets the Cocoa API of Mac OS X. Although the functionality of Carbon and Cocoa is similar, this port has the potential for supporting GNUStep running on platforms other than a Mac.

wxWinCE

The Windows CE port encompasses various SDKs based on the Windows CE platform, including Pocket PC and Smartphone. The bulk of this port consists of the wxMSW Win32 port, with some omissions and additions for the smaller platform. Figure 1-6 shows the wxWidgets Life! demo running on the Pocket PC 2003 emulator. Figure 1-7 shows four screens from the wxWidgets dialog demo running on Smartphone 2003 with a 176 x 220 pixel display. User interface adaptations done by wxWidgets for this restricted platform include constructing a nested menu in place of the usual menu bar because Smartphone only supports two menu buttons. Some additional application hints are required, such as calling SetLeftMenu and SetRightMenu instead of adding conventional OK and Cancel buttons to a dialog.

Figure 1-6. The wxWidgets "Life!" demo on Pocket PC 2003


Figure 1-7. The wxWidgets "dialogs" demo on Smartphone 2003


wxPalmOS

This is a port to Palm OS 6 (Cobalt). At the time of writing, the port is in its infancy but can be used to compile and run a simple sample in the Palm OS 6 simulator (see Figure 1-8).

Figure 1-8. A wxWidgets sample under Palm OS 6


wxOS2

wxOS2 is a Presentation Manager port for OS/2 or eComStation.

wxMGL

This port targets the MGL low-level graphics layer from SciTech Software, Inc., and uses the wxUniversal widget set.

Internal Organization

Internally, the wxWidgets code base is broadly separated into six layers:

  1. Common code is used in all ports. It includes data structure classes, run-time type information, and the base classes, such as wxWindowBase, which are used to factor out code common to all implementations of a class.

  2. Generic code implements advanced widgets independently of any platform, allowing emulation of controls and other functionality not present on a given platform. wxWizard and wxCalendarCtrl are examples of generic controls.

  3. wxUniversal is a set of basic widgets for those platforms that do not have their own native widget set, such as bare X11 and MGL.

  4. Platform-specific code implements classes using native functionality. An example of platform-specific code is the wxMSW implementation of wxTextCtrl wrapping the Win32 edit control.

  5. Contributed code exists in a separate hierarchy named contrib and includes non-essential but useful classes such as wxStyledTextCtrl.

  6. Third-party code comprises libraries that were developed independently of wxWidgets but are used to implement important features. Examples of third-party code include the JPEG, Zlib, PNG, and Expat libraries.

Each port takes what it needs from these layers to implement the wxWidgets API.

How does wxWidgets know which classes to use when you're compiling your application? When you include a wxWidgets header file, such as wx/textctrl.h, you're actually including a platform-specific file such as wx/msw/textctrl.h, due to directives in wx/textctrl.h that conditionally include the appropriate declarations. You then link your application against a library that has been compiled with suitable settings for the platform in question. You can have several configurations available at once, in particular Debug and Release versions, and you can normally link either statically or dynamically to the wxWidgets code. If you want, you can disable components in a wxWidgets build, or make choices such as Unicode versus ANSI, by editing the file setup.h or using configure options depending on compiler. For more details, please see Appendix A, "Installing wxWidgets."

Note that although wxWidgets is a wrapper around each native API, you are not prevented from writing platform-specific code in that native API if you need to, although this is seldom necessary.

    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