I have the following GTK+ program which uses an Glade generated XML file to construct its GUI.
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
////////////////////////////////////////////////////
// Example can be compiled with:
// gcc gui.c `pkg-config --cflags --libs gtk+-2.0`
//
// GUI file from glade must be in same folder from
// which the compiled binary is called.
////////////////////////////////////////////////////
int main(int argc, char* argv[]) {
GtkBuilder* gtkBuilder = gtk_builder_new();
gtk_init(&argc, &argv);
gtk_builder_add_from_file(gtkBuilder, "gui.glade", NULL);
GtkTreeStore* treestore = GTK_TREE_STORE(gtk_builder_get_object(gtkBuilder, "treestore"));
GtkTreeIter iterChild;
gtk_tree_store_append(treestore, &iterChild, NULL);
gtk_tree_store_set(treestore, &iterChild, 0, "a", -1);
gtk_tree_store_append(treestore, &iterChild, NULL);
gtk_tree_store_set(treestore, &iterChild, 0, "b", -1);
gtk_tree_store_append(treestore, &iterChild, NULL);
gtk_tree_store_set(treestore, &iterChild, 0, "m", -1);
gtk_tree_store_append(treestore, &iterChild, NULL);
gtk_tree_store_set(treestore, &iterChild, 0, "k", -1);
gtk_tree_store_append(treestore, &iterChild, NULL);
gtk_tree_store_set(treestore, &iterChild, 0, "g", -1);
gtk_builder_connect_signals(gtkBuilder, NULL);
gtk_widget_show(GTK_WIDGET(gtk_builder_get_object(gtkBuilder, "main")));
g_object_unref(G_OBJECT(gtkBuilder));
gtk_main();
return 0;
}
The XML Glade file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkTreeStore" id="treestore">
<columns>
<!-- column-name col -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkWindow" id="main">
<property name="can_focus">False</property>
<property name="default_width">690</property>
<property name="default_height">500</property>
<signal name="destroy" handler="gtk_main_quit" swapped="no"/>
<child>
<object class="GtkTreeView" id="treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">treestore</property>
<property name="reorderable">True</property>
<property name="level_indentation">1</property>
<property name="enable_tree_lines">True</property>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">column</property>
<property name="clickable">True</property>
<property name="sort_indicator">True</property>
<property name="sort_column_id">0</property>
<child>
<object class="GtkCellRendererText" id="treeviewrenderer">
<property name="height">30</property>
</object>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
When the application starts the rows can be reordered by Drag 'n' Drop. After the column header is clicked the rows will be sorted. Afterwards they can not be rearranged by Drag 'n' Drop anymore.
Is there any way to reactivate manual reordering after the rows have been sorted?
I have tried, e.g., calling gtk_tree_view_set_reorderable()
from within a callback function (callback was on_cursor_moved()
) but this did not work.
Is it possible at all to switch between sorted and reorderable rows when using a Glade XML file to construct the GUI?