wxWidgets 2.8 to 3.0 Migration: Converting wxString to Numbers

wxWidgets provides a set of utility methods to convert wxString to various integer types, such as ToLong(). While the documentation for those functions remained roughly the same between wxWidgets 2.8 and 3.0, the implementation did change. In wxWidgets 2.8, if the string was empty, using any of the number conversion functions would result in the value 0. But in wxWidgets 3.0, it’s different, as can be learned from the following comment in wxstring.cpp:

// notice that we return false without modifying the output parameter at all if
// nothing could be parsed but we do modify it and return false then if we did
// parse something successfully but not the entire string

This means that if you relied on ToLong() to store 0 in the pointer to long when given an empty string, in wxWidgets 3.0 you will get an uninitialized value there.

I also noticed, when comparing the code of wxString in 2.8 and 3.0, that they implemented the integer conversion functions using C macros, while in 2.8 they used templates. I wonder why it was changed, as it looks more like a regression to me.

Simple Histogram Widget for wxWidgets

When working on Open Yahtzee 1.10 (or whatever I’ll call the version after 1.9), I wrote a simple histogram widget to be part of the new statistics dialog. I should emphasize the simple part: this widget was meant to display a simple histogram without requiring any special, bloated plotting libraries. It doesn’t support all the fancy stuff, just a plain histogram.

I figured that a simple pie plot would better serve Open Yahtzee’s needs, so unfortunately this code will not be released as part of the program. While the code is not perfect, it’s functional and serves as a good example of a custom widget. So I felt pity at letting it fall into oblivion in Open Yahtzee’s SVN repository, and I thought it might come in handy to someone else (or at least to me) if it were easily accessible.

simple_histogram

Continue reading Simple Histogram Widget for wxWidgets

Setting Up OmniComplete (Autocompletion) for wxWidgets in Vim

I use Vim as my main IDE for C/C++-related development (as well as for almost all other development). If you use (or are thinking about using) Vim as an IDE, you better get some good autocompletion functionality. This kind of autocompletion is provided by OmniComplete, which has been available since Vim 7.0. Just having OmniComplete is a nice thing, but it’s much more helpful if it’s configured properly to work with the libraries you use, such as wxWidgets. In this post, I will show you how to get OmniComplete working for wxWidgets. However, the procedure I will show can be easily adapted to almost all libraries.
Continue reading Setting Up OmniComplete (Autocompletion) for wxWidgets in Vim