Tips, tricks, and rants from the wxWidgets
and project management expert, Bryan Petty.
Home DeviantArt Study Gallery Anime Dump

Backporting wxFontDialog for wxMac 2.6 · 2006-10-09 20:30

If you work on a Mac OS X port of your application in wxWidgets, chances are pretty good that you’ve run into the same problem as everyone else on wxWidgets 2.6: there is no native standard font dialog. Instead, you get this really ugly generic font dialog with no option to select a font face.

No application wants to ship a product using that generic dialog, especially if you use it as much as I do. But since we’re working on Mac here, and we have to either distribute new wxWidgets dynamic libraries or statically link against our own build (to make up for the lack of 2.6 binaries on 10.4), we have the ability to change this. The latest and greatest code in wxWidgets CVS (2.7) has already solved our problem. Stefan was kind enough to put together some hacks to add OK and Cancel buttons to the native non-modal standard font dialog, and force it to behave like a modal dialog.

If you’re working on some new open source application, this is great because you’re probably just going to grab the latest testing release, build against that, and make it a minimum requirement for your application. If you’re not so lucky like me, you don’t have a choice but to stick to the latest stable release (2.6) and deal with it. I personally can’t just jump to 2.7 because we have 130k lines of code that was built specifically to run on wxWidgets 2.6 (a small portion of the code still there was even initially written for 2.4 a long time ago), and I have to carefully pick a time for pushing upgrades downstream other than around release time for any of our supported platforms so we have time to test all of our incredibly numerous and complicated features. Instead, we simply backport the new font dialog changes from 2.7 to our 2.6 copy. This is a common task I’ve run into on a few different occasions now, sometimes it’s easy, other times it can get messy.

So how do we backport wxFontDialog? Knowing it’s been fixed in CVS, you find out any information regarding how it was fixed and what issues were in the way by looking through wx-dev mailing list archives searching for posts about wxFontDialog. You will find that when it was written, it was added with the mac specific configuration option called “wxMAC_USE_EXPERIMENTAL_FONTDIALOG”. A simple command can find us everywhere in CVS that this is used thus finding all the locations where code was changed to add support for this:

tierra@aramaki ~/cvsroot/wxWidgets $ grep -rn wxMAC_USE_EXPERIMENTAL_FONTDIALOG .
./include/wx/mac/carbon/fontdlg.h:22:#ifndef wxMAC_USE_EXPERIMENTAL_FONTDIALOG
./include/wx/mac/carbon/fontdlg.h:23:#define wxMAC_USE_EXPERIMENTAL_FONTDIALOG 1
./include/wx/mac/carbon/fontdlg.h:26:#if wxMAC_USE_EXPERIMENTAL_FONTDIALOG
./include/wx/mac/carbon/fontdlg.h:48:#else // wxMAC_USE_EXPERIMENTAL_FONTDIALOG
./src/mac/carbon/fontdlg.cpp:43:#if wxMAC_USE_EXPERIMENTAL_FONTDIALOG
./src/mac/carbon/fontdlgosx.mm:40:#if wxMAC_USE_EXPERIMENTAL_FONTDIALOG

Now we just need to go through the files, diff them against our 2.6 version, make changes appropriately, and pray that there aren’t new dependancies we have to deal with. I’ll save you the suprise and let you know up front that you’ll need to change a couple “FromRGBColor” function calls back to using the old “Set” funtions used for the same purpose in 2.6. You’ll also want to add the new wxMacGetEventParamType functions needed in include/wx/mac/carbon/private.h.

  Textile Help