I'll follow up, in case this helps out anyone else, to mention that we have found a local work-around for this issue that works at least with wxGTK built against GTK+ version 2 libraries. That workaround is to add some calls in our code to the gtk_rc_parse_string() function, which can be used to supplement or even override the various gtkrc files that GTK libraries read by default.
(As this function evidently modifies global state of GTK+ libraries, it presumably must be called only while the application is still known to be in a single-threaded region.)
Point the first, this can be used to force buttons not to be rendered using the "pixmap" engine provided by the Adwaita theme (or other themes that might explicitly set button images) as follows, thereby letting our calls to SetBackgroundColour() be effective.
(As I comment below, I had hoped to be able to target this more precisely using the "widget_class" or "widget" selectors combined with some appropriate calls like gtk_widget_set_name(wxwindow->GetHandle(), "specific_name"), as described at [1], but I couldn't get anything of that nature to work in practice at all.)
[1]
http://stackoverflow.com/a/14894222#ifdef __WXGTK__
// Docs:
https://developer.gnome.org/gtk2/stable/gtk2-Resource-Files.html gtk_rc_parse_string(
"style \"our_button\" {\n"
// This disables any engines that may be setting button
// background images:
" engine \"\" {}\n"
// This should disable any other theme settings for button
// background images:
" bg_pixmap[NORMAL] = \"<none>\"\n"
" bg_pixmap[ACTIVE] = \"<none>\"\n"
" bg_pixmap[PRELIGHT] = \"<none>\"\n"
" bg_pixmap[SELECTED] = \"<none>\"\n"
" bg_pixmap[INSENSITIVE] = \"<none>\"\n"
"}\n"
// Make the above style apply to all GtkButtons and derived classes.
// In theory there should be a way to target this in a more focused
// way only at widgets with a specific name, e.g. "Color", and set
// that name on the desired widgets (or perhaps their parent) with
// gtk_widget_set_name(). In practice I have not been able to make
// that work at all. -- KBM 2016-12-21
"class \"GtkButton\" style : highest \"our_button\"\n"
);
#endif
One could, of course, go the extra mile to factor out this string into yet another gtkrc file at for instance /opt/MyApplication/etc/gtkrc, and run gtk_rc_parse_string() on the contents of that file instead of hard-coding the string into the C++, if for some reason one wished to let this be amenable to edits by the local sysadmin.
Point the second, this mechanism can also be used to override the extremely frustrating GTK+ changes of a few years ago that cause menu icons and button icons (on labeled buttons) to be hidden by default, as follows:
// Make sure button and menu icons are visible.
gtk_rc_parse_string(
"gtk-button-images = 1\n"
"gtk-menu-images = 1\n"
);
This was quite a nice discovery for us, since a lot of our GUIs rely on menu icons to convey information to users in addition to the menu item text.
I note that this call to gtk_rc_parse_string() probably has to be done in one's override of wxApp::OnInit() in order to be effective. If it comes before that (e.g. in the constructor of one's wxApp-derived class) it runs the risk that the GTK libraries parse their own gtkrc files *after* this call, thereby possibly undoing our settings of gtk-menu-images=1 etc.
Presumably something similar can be done with wxGTK-using modules where WX was built against GTK+ version 3, as noted at the above stackoverflow link.
This is all very hacky of course so I certainly wouldn't expect anything like this to be added into WX library code! But maybe it's useful to others who are writing WX-based applications and need fine control over UI details.
--
Kevin B. McCarty
<
kmcc...@gmail.com>