LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-19-2006, 05:34 PM   #1
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Rep: Reputation: 30
GTK Bug?


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

Last edited by bendeco13; 04-19-2006 at 05:37 PM.
 
Old 04-19-2006, 06:52 PM   #2
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
Ok I fixed it, I don't know why this works, but after trying EVERYTHING I ended up changing these lines:
Code:
static gboolean Test_RowClicked(GtkWidget *tree, GdkEventButton *event, gpointer menu)
{
    if ((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) {
       cout << "Right Clicked" << endl;
       return TRUE;
    }
    else {
       cout << "Selection Changed" << endl;
    }
    return FALSE;
}

Last edited by bendeco13; 04-19-2006 at 06:53 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GTK+ programs on Windows without having to install GTK+, GLib, etc Nylex Programming 2 02-19-2006 01:33 PM
Freerock uninstall stole GTK looking for up-to-date pango, atk, gtk, glib and xft tgz Oholiab Slackware 8 09-18-2005 11:57 AM
GTK source install doesn't give gtk-config Feebles Linux - Software 4 06-15-2005 12:51 PM
cant find gtk-config file or gtk-devel to install happychappy Linux - Software 2 02-16-2005 12:46 AM
Free86 bug or nVidia bug?? ProtoformX Linux - Software 2 05-12-2004 02:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration