'GTK+2 to GTK+3 conversion
I'm trying to convert the GTK+2 code to compile and run on GTK+3. In the old code I have following:
gtk_widget_push_composite_child()/gtk_widget_pop_composite_child()
Now GTK+3 states that instead I should first call gtk_widget_init_template() and then gtk_widget_class_set_template()/gtk_widget_class_set_template_from_resource().
Now, those 2 functions use an XML template to build the composite widget from. Unfortunately there is no example on how to make one and what to pass to those function(s).
Do I pass the XML file name? The XML tree root node? The schema verification? Trying to google for the code example didn't yield anything useful.
Can anyone shed some light on this please?
Solution 1:[1]
There is an old blog post "Announcing Composite Widget Templates" that explains how it works. Usually taking a look at gtk3-demo should shed some light (better to run it).
To pass the name, you call it in the init method, as the example in the blog post:
static void
my_widget_class_init (MyWidgetClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
/* Setup the template GtkBuilder xml for this class
*/
gtk_widget_class_set_template_from_resource (widget_class, "/org/foo/my/mywidget.ui");
}
static void
my_widget_init (MyWidget *widget)
{
/* Initialize the template for this instance */
gtk_widget_init_template (GTK_WIDGET (widget));
}
The resources' files would look something like:
<gresources>
<gresource prefix="/org/foo/my">
<file alias="ui/password-view.ui" compressed="true" preprocess="xml-stripblanks">myapp-mywidget.ui</file>
</gresource>
</gresources>
In some part of your code, you will need to load the resources' file, where myapp-mywidget.ui is the actual filename with the UI file. You can have one file per template, and all of them listed in the resources' file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | gpoo |
