Use gtk_container_child_set()
instead:
gtk_container_child_set(GTK_CONTAINER(gtk_widget_get_parent(widget)), widget,
"y-options", expanded? GTK_EXPAND : GTK_FILL,
NULL);
Frage
My project was to create a graphical application to help each employee to create his own list of clients in a central database and the only problem I had was with the compatibility between gtk3
and gtk2
. The project from beginning to end is based on gtk3
and then I realized that there are employees who use a system with gtk2
only. So I made some modifications to the implementation without much difficulty and works without any problem on its purpose. The last thing that I want to finish, is to simulate the function of the gtk_widget_get_hexpand()
and gtk_widget_get_vexpand()
... they are only in gtk3
. For the other functions to work the same way as in gtk3
i did something like this:
#define gtk_grid_new() gtk_table_new(1,1,false)
#define GTK_GRID(x) GTK_TABLE(x)
#define GtkGrid GtkTable
#define gtk_grid_attach(x1,x2,x3,x4,x5,x6) gtk_table_attach(x1,x2,x3,x3+x5,x4,x4+x6,GTK_FILL,GTK_FILL,0,0)
To let the application work without the gtk_widget_get_hexpand()
and gtk_widget_get_hexpand()
functions, simply with:
#define gtk_widget_set_hexpand(x1,x2)
#define gtk_widget_set_vexpand(x1,x2)
Because is little more complex to simulate these functions with macros i tried to do something like this:
inline void gtk_widget_set_hexpand(GtkWidget* widget,gboolean expanded) {
GValue value = G_VALUE_INIT;
g_value_init(&value,G_TYPE_ENUM);
if(expanded)
g_value_set_enum(&value,GTK_EXPAND);
else
g_value_set_enum(&value,GTK_FILL);
gtk_container_child_set_property(GTK_CONTAINER(gtk_widget_get_parent(widget)),widget,"x-options",&value);
}
inline void gtk_widget_set_vexpand(GtkWidget* widget,gboolean expanded) {
GValue value = G_VALUE_INIT;
g_value_init(&value,G_TYPE_ENUM);
if(expanded)
g_value_set_enum(&value,GTK_EXPAND);
else
g_value_set_enum(&value,GTK_FILL);
gtk_container_child_set_property(GTK_CONTAINER(gtk_widget_get_parent(widget)),widget,"y-options",&value);
}
gtk_container_child_set_property()
I know that it is not correct! Actually i don't know how to set the child properties
of the widgets
and more specific how to create a GValue
with G_TYPE_ENUM
. Can someone help me?
UPDATE: @ptomato gave me a better solution on this. Actually by using the gtk_container_child_set()
function instead of the gtk_container_child_set_property()
then:
#define gtk_widget_set_hexpand(x1,x2) gtk_container_child_set(GTK_CONTAINER(gtk_widget_get_parent(x1)),x1,"x-options",(x2)?(GTK_FILL|GTK_EXPAND):GTK_FILL,NULL);
#define gtk_widget_set_vexpand(x1,x2) gtk_container_child_set(GTK_CONTAINER(gtk_widget_get_parent(x1)),x1,"y-options",(x2)?(GTK_FILL|GTK_EXPAND):GTK_FILL,NULL);
does the trick successfully! Thanks to @ptomato!
Lösung
Use gtk_container_child_set()
instead:
gtk_container_child_set(GTK_CONTAINER(gtk_widget_get_parent(widget)), widget,
"y-options", expanded? GTK_EXPAND : GTK_FILL,
NULL);