"Linux Gazette...making Linux just a little more fun!"


Portable GUI C++ Libraries

By Sean C. Starkey


Most well-written, non-graphics C++ code is portable, but major problems occur when one tries to write portable applications for graphical user interfaces. On Linux, the X Window System is used as the major graphical user interface. GUI code written on Linux will not work on MS Windows. Even though we all know that Linux is the better of the two, some Linux developers would like to also support MS Windows with its large number of users.

With a portable GUI C++ library, source code developed under Linux and X can be compiled for other platforms, including MS Windows. Quite a few GUI C++ libraries are available at this time, including MFC and OWL for MS Windows. Unfortunately, none of these libraries are portable to both X and MS Windows.

Desirable features in a portable GUI library include the following:

Other desirable features which are not GUI related are portable network functionality, file I/O capabilities and some good container classes.

What are some of the problems faced by a portable GUI library? One is that GUI code on different platforms varies widely. To create a new window, MS Windows uses a completely different command than X, even though the code uses the same programming language in both. Another problem is subtle changes in event handling. All GUI applications are event driven, but the events are different on different platforms. The portable GUI library must take all of these differences into consideration and supply a common interface for all platforms.

I have reviewed three different GUI C++ libraries which support both X and MS Windows. All are free of charge with no royalties. The source code for these libraries is available on the web sites cited in Resources.

Since these libraries are written in C++, you have all the advantages of object-oriented design. To create a new window, you derive your own window class from the main window class. After adding the appropriate code to handle events in your window, it is finished.

wxWindows

wxWindows is by far the most active of the libraries available. wxWindows was originally developed by Julian Smart, but has received contributions from many others. The version of wxWindows reviewed in this article is 1.68B. Version 2.0, a major rewrite of the library, is rumored to be available in ``the near future''.

wxWindows is a very modular project. The main version is available on the web site. In addition to the main version, there are also many subprojects. Some of these subprojects include additional widgets, an Xlib library port, a Macintosh port and many others. These subprojects are described on the wxWindows web site (see Resources).

Note that the main version of wxWindows requires the Motif toolkit. Motif is not free; therefore, most Linux installations do not include it. Lesstif, a popular Motif clone, compiles and works with wxWindows. There is also a side project which uses only standard Xlib libraries so that wxWindows does not need Motif.

wxWindows has many features. Figure 1 is a screen capture of the sample program distributed with wxWindows running on a Linux system. Notice all of the widgets available to the programmer. More screen shots are available on the wxWindows web site.

Figure 1

One of best features of wxWindows is the on-line documentation. The documentation comes in HTML, LaTeX and MS Windows help format. There is also a very active mailing list for wxWindows, where many questions can be answered. Trying to learn all of these new classes can be confusing, and wxWindows does a good job of describing them.

If you don't want to download all of the wxWindows source code, a distribution on CD is available. See the web site for more details.

V

V is another freely available library, and was developed by Dr. Bruce E. Wampler. [See ``V--A Free C++ GUI Framework for X'', Linux Journal, December 1996.] It is able to compile on X and MS Windows. It is a complete library, but does not have all of the fancy controls that wxWindows has. Although not as fancy, in my opinion, V's source code is better written and easier to understand than wxWindows.

V does not require the Motif libraries to build and run. All V source code uses pure Xlib library calls, so it should be able to compile on any Linux system with no difficulty.

V has quite a few widgets available as well. Figure 2 is a screen shot of an example program distributed with the library. This look is consistent on all platforms.

Figure 2

YACL

Another library worth looking at is YACL (Yet Another Class Library). The author, M. A. Sridhar, reports that YACL can compile on X, MS Windows and OS/2. Unfortunately, it looks as if progress on YACL has been nonexistent since late 1996. The current version of YACL, 1.60, is close to complete with a good set of classes and widgets.

Figure 3

Figure 3 shows a screen shot of an example program distributed with the library. This example shows some of the graphics primitives available with YACL. YACL also has all of your basic widgets, such as buttons, menus, choices and radio buttons.

One of YACL's biggest drawbacks is a lack of documentation. There is a book about YACL: Building Portable C++ Applications with YACL, Addison-Wesley, 1996. I would suspect this book has more information than the documentation distributed with the library.

If you would like more information on any of these libraries, please see their web page listed in the Resources table.

Resources

wxWindows: http://web.online.co.uk/julian.smart/wxwin/

V: http://www.objectcentral.com/vgui/vgui.htm

YACL: http://www.cs.sc.edu/~sridhar/yacl/

User Interface Software Tools: http://www.cs.cmu.edu/afs/cs/user/bam/www/toolnames.html
A good page for some other GUI libraries that are not necessarily free, in C++ or supportive of the X Window System.


Copyright © 1998, Sean C. Starkey
Published in Issue 30 of Linux Gazette, July 1998


[ TABLE OF CONTENTS ] [ FRONT PAGE ]  Back  Next