I've been working on a program for about a year. It's pretty large and I have just completed it, except I still have ONE problem. Everytime that I try to resize the treeview columns in my program, the mouse hangs up and I have to use Alt-F4 to close the window and revive the mouse. I've wrote a barebone, well almost, sample of what my problem is. I've traced the problem all the way down to one line, but I don't know what could actually be wrong with it. Heres the sample code. If you want to test it, copy it to a file and compile, but if you try to resize the columns, get ready to Alt-F4.
I used the following command to compile it:
g++ test.cpp -o test -lz `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
Code:
#include <iostream>
#include <string>
#include <vector>
#include <gtk/gtk.h>
using namespace std;
static void AddListstoreData(GtkListStore *store) {
int a;
GtkTreeIter tempiter;
char buff[2];
string num, datal, datar;
for (a=0; a<10; a++) {
sprintf(buff, "%d", a);
num = buff;
datal = "Left:" + num;
datar = "Right:" + num;
gtk_list_store_append(GTK_LIST_STORE(store), &tempiter);
gtk_list_store_set(GTK_LIST_STORE(store), &tempiter, 0, datal.c_str(), 1, datar.c_str(), -1);
}
}
static void Test_RowClicked(GtkWidget *tree, GdkEventButton *event, gpointer menu)
{
cout << "Row Clicked" << endl;
}
int Test_Main()
{
int a;
GtkWidget *window;
GtkWidget *treeview;
GtkListStore *liststore;
vector<const gchar*> column_names;
column_names.push_back("Left");
column_names.push_back("Right");
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Treeview Test");
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect_swapped(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), G_OBJECT(window));
GtkWidget *main_vbox = gtk_vbox_new(FALSE, 0);
liststore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
treeview = gtk_tree_view_new();
gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(liststore));
g_signal_connect(G_OBJECT(treeview), "button-release-event", G_CALLBACK(Test_RowClicked), NULL); /*FIXXXXXXXXXXX*/
GtkTreeViewColumn* column;
vector<GtkCellRenderer*> cells;
for (a=0; a<column_names.size(); a++) {
cells.push_back(gtk_cell_renderer_text_new());
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), a, column_names[a], cells[a], "text", a, NULL);
column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), a);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_sort_column_id(column, a);
g_object_set(GTK_CELL_RENDERER(cells[a]), "size-points", (double)12, NULL);
gtk_tree_view_column_set_fixed_width(column, 150);
}
AddListstoreData(liststore);
GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(scrolledwindow), treeview);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_box_pack_start(GTK_BOX(main_vbox), scrolledwindow, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(window), main_vbox);
gtk_window_resize(GTK_WINDOW(window), 345, 200);
gtk_widget_show_all(window);
return 0;
}
int Test_Done()
{
gtk_main();
return 0;
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
Test_Main();
Test_Done();
return 0;
}
Notice the line:
g_signal_connect(G_OBJECT(treeview), "button-release-event", G_CALLBACK(Test_RowClicked), NULL); /*FIXXXXXXXXXXX*/
When I remove this callback, all goes well.
This signal,
g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(Test_RowClicked), NULL);
does work, but it only works for double clicks and it is mandatory that I recieve the signal on each SINGLE click.
I also need to know which row and which mouse button was clicked.
Does anyone know what the problem could be, or know of a different approach?
Thanks in advance,
Bendeco