4
votes

My question is concerned with GTK2 and wxWidgets (actually wxGTK).

In wxGTK all controls have grey background by default and it is impossible to remove it. I have a textured panel with custom child controls and each of my controls has an ugly grey border which I can't remove. I can only set some background color and make the panel's color the same. So I need a kind of "backgroundless" control in wxGTK.

I have many years of MS Windows experience before Linux. As far as I remember, in MS Windows each windowed control (i.e. widget) receives a WM_ERASEBKGND message (event) and then WM_PAINT message. The background is drawn in WM_ERASEBKGND event handler, so you can easily leave the parent control's background untouched and paint all of widget's elements on top of it by simply rewriting this handler.

That's not the case with wxGTK (and GTK2)!

Actually all widgets in wxGTK are based on custom "wxPizza" GTK widget, which is derived from GtkFixed widget. Any of wxPizza widgets has its own gdk window, so it is impossible to implement custom windowless widgets using standard wxGTK controls, based on "wxPizza" widget.

So I decided to implement another one GTK2 widget to make "backgroundless" controls available to wxWidgets. I implemented a windowless GTK2 widget, derived from GtkFixed. To make it windowless I used gtk_widget_set_has_window function (another way is to set a GTK_NO_WINDOW flag).

Everything works, except for draw coordinates, which are in parent window coordinate space. So the widget's elements are drawn at the parent window's top left position. That's the problem that I can't resolve. Maybe I need to add a GtkEventBox to my custom widget?

Maybe there are another ways to implement such functionality (backgroundless widgets) in GTK2? What do you think about that?

Thanks in advance, Ilya

1
Sounds like Gtkfixed is throwing a wrench. Could you add an +x_offset (from the x coordinate) +y_offset (from the y coordinate) to the draw coordinates. But then I still use a modified glade-2.12.2 to build my interfaces directly in C without Wx and control a lot of the "look" with a custom gtkrc file.technosaurus

1 Answers

4
votes

Your question is pretty old, but as there is now a trivial solution, it is better to write about it here, use the following code before your Create() call:

SetBackgroundStyle(wxBG_STYLE_TRANSPARENT);

We got this into wxWidgets 2.9.4 I believe.