According to Hoyle...
Cross-Platform Software Development from a Macintosh Perspective: wxWidgets
Two months ago, we began our series on cross-platform software development for the Macintosh. Our goal is to examine the many solutions available to the Mac programmer, whether he be a professional developer or just a hobbyist. We started first by examining cross-platform C++ frameworks, with a review of Qt last month. This month, we will review another C++ framework, the open source project wxWidgets.
wxWidgets History & Overview
Through most of its history, this framework was known as wxWindows. In early 2004, Microsoft applied legal pressure against the organization alleging copyright infingement to their Microsoft Windows product name. Although it would be ludicrous to think anyone could confuse these two products, the decision was to bypass legal battles by renaming the project as wxWidgets. Frivolous lawsuits notwithstanding, wxWidgets' user base has remained fiercely loyal, making it a popular alternative to the commercial Qt.
wxWidgets began in 1992 by Julian Smart, in an attempt to create an open source GUI framework for cross-platform development, targeting (at the time) the Windows and Linux operating systems. In 1998, Stefan Csomor began the initial Macintosh port (called wxMac), and over the course of time the Mac port slowly matured. Until fairly recently, wxMac remained somewhat buggy and was not truly available for prime time. In 2004, version 2.6 of wxWidgets was released, which was a very stable and functional release. Version 2.6.2 was released this summer, which updated wxMac for compatibility with Intel-based Macintoshes. It was also announced that 2.6.x will be the final versions supporting Classic/Mac OS 9.
Creating Applications with wxWidgets
wxWidgets is a very large and fairly complete application framework. It comprises several hundred C++ classes abstracting away OS-specific implementations. Although wxMac is written to the Carbon API specification, there is a separate initiative called wxCocoa, which is an implementation of wxWidgets written to the Cocoa API. (Since this latter framework is still under development, we will be focusing on the former only.) wxMac can be compiled under either Xcode or CodeWarrior, the latter being required for Classic support. When compiling under Xcode 2.1 or higher, wxMac can be compiled as a Universal Binary (that is, to run on both PowerPC and Intel-based Macintoshes).
Unfortunately, application development with wxWidgets is tailored more for Windows MFC programmers than it is for Mac developers. Its set of classes have almost a one-to-one mapping with equivalents in MFC; most in fact have the identical name, save for the "wx" prefix. The similarity is quite obvious, down to the very Windows-oriented wxTaskBarIcon class. Even ugly MFC macros have been duplicated here. The wxWidget class heierarchy can be viewed here. Although Stefan Csomor has worked very hard to try to bring wxWidgets to a comfortable user experience on the Mac, it is still feels very much like a Windows product. It's clear that the decision early on was to design wxWidgets for ease of portability of MFC applications, rather than designing from scratch what the best cross-platform approach should be. For this reason, I recommend for anyone choosing to use wxWidgets as a solution to not go it alone and pick up the book Cross-Platform GUI Programming with wxWidgets.
For GUI design, Mac OS X users are accustomed to creating nib files with Interface Builder. Unfortunately, there is no facility in wxWidgets to import such files. There are however some GUI generating tools available for wxWidgets, including wxDesigner and DialogBlocks. Although they pale in comparison to Interface Builder's user experience, they do have the benefit of being cross-platform. The very un-Mac like feel is evident from this screenshot from wxDesigner:
wxWidgets is not nearly as well known as Qt, yet a surprising number of projects have adopted its use. Some notable applications written with wxWidgets include AOL Communicator, AVG Anti-Virus and Xerox's VIPP PostScript Printware. There are a number of wxWidgets games as well, such as Hugo, Chess Commander, and Nyko AirFlo. Corporate users include AMD, CalTech, Lockheed Martin, the US Navy, NASA and many others.
Without question, wxWidgets is a huge open source success story. With community help wxWidgets has the widest support base of any C++ framework. It supports not only Mac OS 9/X and Windows, but also various flavors of Linux, Solaris, AIX, HP-UX, Irix, SCO Unix, FreeBSD, OpenVMS, 16-bit Windows and 64-bit Windows. It even supports OS/2. Embedded systems are currently being targeted, which include Windows CE and Palm OS. For a complete list of supported platforms, visit http://www.wxwidgets.org/platform.htm. Compiler support is also impressively complete, supporting CodeWarrior, Xcode, Visual C++, Borland C++ and a number of the Linux compilers.
wxWidgets' licensing is also extremely generous. First of all, it is open source, and therefore perfectly cost-free. And unlike Qt's restrictive GPL licensing, wxWidgets' license allows you to use it for commercial development, with no requirement to release your source code. There are no costs, royalties or any hidden charges anywhere. About the only thing you can't do with it is repackage it and claim it as your own.
The newsgroup comp.soft-sys.wxwindows is actively monitored and responses are given in a very timely fashion. Being part of the Open Source community, wxWidgets source code is available for all to see, and bug reports and fixes are submitted continually. In addition, commercial support is available to those who wish to have it. Also on the web site are bug "bounties", in which developers are offered money to submit fixes (many of these bounties are priced in the $200 range).
wxWidgets is free, unrestricted and can target more platforms than you could possibly wish for. In this way, wxWidgets seems almost too good to be true. Unfortunately, the significant down side to it is its very poor Macintosh user experience. Furthermore, wxWidgets is not quite as rich in capabilities as Qt, and you can expect to run into more bugs along the way than you would in Qt. For this reason, GPL developers using Qt's Open Source Edition would probably not have any reason to switch to wxWidgets. For commercial development, there are a number of inexpensive cross-platform solutions which are much more Macintosh-friendly. In light of that, it hardly seems worth the effort to learn wxWidgets, in spite of the fact it is free. If your needs are a free cross-platform environment, then wxWidgets is your best and only solution. However, for under $100, you can find a cross-platform environment with a much better Macintosh user experience than wxWidgets.
Coming Up Next: CPLAT!