Search code examples
c++cross-platformwxwidgets

wxWidgets Windows->MacOS or Linux


I did a C++ code whose GUI is implemented with wxWidgets 3.1, and which I run on Windows. Being a cross-platform solution, I tried compiling the project on MacOS. I'm running into several issues:

  • wxWindow::SetDoubleBuffered does not seem to be implemented on MacOS (is-it also the case on Linux ?). I can go around and turn off double buffering at the expense of some flickering in my drawings for Mac users. That's not ideal: is-there something equivalent for Mac / Linux ?
  • The constructor wxBitmap(const wxImage &image, const wxDC &dc) doesn't seem to exist either on MacOS. I use it to be able to use "dc.DrawBitmap" (combined with dc.SetUserScale) on a wxImage created from a C-style array of RGB triples. How do Mac users display pixel arrays on screen using wxWidgets ?
  • Apparently there is no wxString to std::string conversion on MacOS (no viable conversion from 'wxString' to 'std::string' error). How is it even OS specific ?
  • (minor detail) : error: use of undeclared identifier 'sample_xpm' : SetIcon(wxICON(sample)); It seems sample_xpm is a default icon that is available on Windows and not MacOS.... (?).

Thanks for your help!


Solution

  • It would be better to ask separate questions separately, as things risk getting confusing if we try discussing all them together, but here are the basic answers:

    1. wxWindow::SetDoubleBuffered() is not provided in wxOSX because all windows are double-buffered there. A stub for it should still be arguably provided, for portability, but it will still do nothing and not calling it shouldn't result in any flickering.
    2. wxBitmap ctor with this signature is not documented on purpose, it doesn't really make sense for the non-MSW platforms. Just use the ctor without the dc parameter instead.
    3. Conversion from wxString to std::string is not OS-specific but depends on your build options: it is implicitly provided only if you build with wxUSE_STL=1 set in your setup.h (or --enable-stl configure option). To avoid relying on this, you can always use ToStdString() explicitly. Or ensure that you build with the same options under all platforms.
    4. This error is, presumably, in your own code and must be due to not including the XPM file. There is nothing platform-specific about this and you actually usually do not need XPMs under MSW so I'm not sure what you did there -- but just look at how and where do you include it.