Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set widget properties with `enum` type like `GtkAttachOptions`? I'm trying to simulate `gtk_widget_set_vexpand` to work on `gtk2`
    primarykey
    data
    text
    <p>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 <code>gtk3</code> and <code>gtk2</code>. The project from beginning to end is based on <code>gtk3</code> and then I realized that there are employees who use a system with <code>gtk2</code> 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 <a href="http://developer.gnome.org/gtk3/3.6/GtkWidget.html#gtk-widget-get-hexpand" rel="nofollow"><code>gtk_widget_get_hexpand()</code></a> and <a href="http://developer.gnome.org/gtk3/3.6/GtkWidget.html#gtk-widget-get-vexpand" rel="nofollow"><code>gtk_widget_get_vexpand()</code></a> ... they are only in <code>gtk3</code>. For the other functions to work the same way as in <code>gtk3</code> i did something like this:</p> <pre><code>#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) </code></pre> <p>To let the application work without the <code>gtk_widget_get_hexpand()</code> and <code>gtk_widget_get_hexpand()</code> functions, simply with:</p> <pre><code>#define gtk_widget_set_hexpand(x1,x2) #define gtk_widget_set_vexpand(x1,x2) </code></pre> <p>Because is little more complex to simulate these functions with macros i tried to do something like this:</p> <pre><code>inline void gtk_widget_set_hexpand(GtkWidget* widget,gboolean expanded) { GValue value = G_VALUE_INIT; g_value_init(&amp;value,G_TYPE_ENUM); if(expanded) g_value_set_enum(&amp;value,GTK_EXPAND); else g_value_set_enum(&amp;value,GTK_FILL); gtk_container_child_set_property(GTK_CONTAINER(gtk_widget_get_parent(widget)),widget,"x-options",&amp;value); } inline void gtk_widget_set_vexpand(GtkWidget* widget,gboolean expanded) { GValue value = G_VALUE_INIT; g_value_init(&amp;value,G_TYPE_ENUM); if(expanded) g_value_set_enum(&amp;value,GTK_EXPAND); else g_value_set_enum(&amp;value,GTK_FILL); gtk_container_child_set_property(GTK_CONTAINER(gtk_widget_get_parent(widget)),widget,"y-options",&amp;value); } </code></pre> <p><a href="http://developer.gnome.org/gtk3/3.6/GtkContainer.html#gtk-container-child-set-property" rel="nofollow"><code>gtk_container_child_set_property()</code></a></p> <p>I know that it is not correct! Actually i don't know how to set the <code>child properties</code> of the <code>widgets</code> and more specific how to create a <code>GValue</code> with <code>G_TYPE_ENUM</code>. Can someone help me?</p> <p>UPDATE: @ptomato gave me a better solution on this. Actually by using the <a href="http://developer.gnome.org/gtk3/3.6/GtkContainer.html#gtk-container-child-set" rel="nofollow"><code>gtk_container_child_set()</code></a> function instead of the <code>gtk_container_child_set_property()</code> then:</p> <pre><code>#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); </code></pre> <p>does the trick successfully! Thanks to @ptomato!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload