After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 113904 - GtkTreeView, dialogs and the activate signal
GtkTreeView, dialogs and the activate signal
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTreeView
2.2.x
Other Linux
: Normal normal
: ---
Assigned To: gtktreeview-bugs
gtktreeview-bugs
: 116263 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2003-05-28 14:19 UTC by René Seindal
Modified: 2011-02-04 16:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
propsed patch (1.03 KB, patch)
2003-06-26 14:03 UTC, Kristian Rietveld
none Details | Review

Description René Seindal 2003-05-28 14:19:53 UTC
I have run into a problem with a GtkTreeView.  A small demonstration
program is included below.

I have a GtkTreeView which is reorderable.  I have attached a function
to the row_activated signal that pops up a dialog.  When the dialog is
closed and the mouse re-enteres the TreeView, it behaves as if a drag
has been initated to reorder the entries of the view.

I have tried running the dialog from an idle function, and it makes no
difference.  Apparently the idle function gets to run before the button
release is sent to the TreeView, enticing the view to think a draw has been
initiated.

I have also tried with a timeout, and it seems to work if the timeout is
on the order of 100ms, but that is going to be dependent on computer
speed and load.

Also it doesn't matter if the dialog is modal or not.

On a side note, the rows-reordered does not appear to be emitted on the
model when the view is reordered.

This is with gtk+ 2.2.1 from Debian testing/unstable.

Demonstration program:
------------------------------------------------------------------------
#include <gtk/gtk.h>
#include <stdio.h>

enum {STRING_COLUMN=0};

static GtkTreeModel * FillStore(void) {
    GtkTreeModel *result = GTK_TREE_MODEL(gtk_list_store_new(1,
G_TYPE_STRING));
    GtkTreeIter iter;
    char tmp[4];
    int i;

    for (i=0; i<50; i+=5){
        snprintf((char*)tmp, 4, "%d", i);
        gtk_list_store_append(GTK_LIST_STORE(result), &iter);
        gtk_list_store_set(GTK_LIST_STORE(result), &iter,
                           STRING_COLUMN, tmp, -1);
    } return result;
}

void callback(GtkTreeModel *treemodel, GtkTreePath *arg1, GtkTreeIter
*arg2, gpointer arg3, gpointer user_data) {
    printf("Callback\n");
}

void activate(GtkTreeView *tree_view, gpointer user_data) {
    GtkWidget *dialog = gtk_dialog_new_with_buttons ("My dialog",
                                                     NULL,
                                                     GTK_DIALOG_MODAL,
                                                     GTK_STOCK_OK,
                                                     GTK_RESPONSE_ACCEPT,
                                                     GTK_STOCK_CANCEL,
                                                     GTK_RESPONSE_REJECT,
                                                     NULL);
    gint result = gtk_dialog_run (GTK_DIALOG (dialog));
    switch (result)
    {
    case GTK_RESPONSE_ACCEPT:
        printf("DIALOG Accept\n");
        break;
    default:
        printf("DIALOG Cancel\n");
        break;
    }
    gtk_widget_destroy (dialog);
}


int main (int argc, char *argv[]) {
    GtkWidget *window = NULL;
    GtkWidget *tree_view = NULL;
    GtkWidget *vb = NULL;
    GtkWidget *sw = NULL;
    GtkCellRenderer *renderer = NULL;
    GtkTreeViewColumn *column = NULL;
    GtkTreeModel * model;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request(window, 150, 200);
    vb = gtk_vbox_new (FALSE, 8);
    gtk_container_add (GTK_CONTAINER (window), vb);
    sw = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
GTK_SHADOW_ETCHED_IN);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
    gtk_box_pack_start (GTK_BOX (vb), sw, TRUE, TRUE, 0);


    model = FillStore ();
    tree_view=gtk_tree_view_new_with_model(model);
    g_signal_connect (G_OBJECT (tree_view), "row_activated", G_CALLBACK
(activate), NULL);

    gtk_tree_view_set_reorderable (GTK_TREE_VIEW(tree_view), TRUE);
    g_signal_connect (G_OBJECT (model), "rows-reordered", G_CALLBACK
(callback), NULL);

    // gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), 0);
    gtk_container_set_border_width(GTK_CONTAINER(window), 3);
    gtk_container_add(GTK_CONTAINER(sw), tree_view);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes ("Some numbers",
renderer, "text",
                                                       STRING_COLUMN, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);

    gtk_widget_show_all(window);
    gtk_main();
    return 0;

}


------------------------------------------------------------------------
Comment 1 Kristian Rietveld 2003-06-26 01:12:20 UTC
> On a side note, the rows-reordered does not appear to be emitted on
> the model when the view is reordered.

When a row is moved using a drag, the row will be deleted and
re-inserted internally, so you won't get a rows-reordered signal but a
row-deleted/row-inserted pair. The rows-reordered signal is used when
sorting.

Other issue will be hopefully fixed for 2.2.3.
Comment 2 Kristian Rietveld 2003-06-26 14:03:06 UTC
Created attachment 17806 [details] [review]
propsed patch
Comment 3 Kristian Rietveld 2003-06-26 14:18:45 UTC
Doh, there's a silly typo in the patch. The "=" in the first if should
of course be "==". Also with this change the patch works.
Comment 4 Kristian Rietveld 2003-07-02 18:10:56 UTC
*** Bug 116263 has been marked as a duplicate of this bug. ***
Comment 5 Kristian Rietveld 2003-07-12 13:58:29 UTC
Committed on gtk-2-2 and HEAD.