Bug#301610: libgtk2.0-0: The number of selected rows is incorrect in "cursor-changed" callback.

Igor Belyi Igor Belyi <belyi@users.sourceforge.net>, 301610@bugs.debian.org
Sat, 26 Mar 2005 23:08:41 -0500


This is a multi-part MIME message sent by reportbug.

--===============0551852410==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Package: libgtk2.0-0
Version: 2.6.2-4
Severity: important

The number of selected rows in a GtkTreeVew is incorrect in "cursor-changed"
callback when rows are selected with a modefier - Ctrl or Shift.
This problem does not happen when rows are selected without a modifier
or when number of selected rows is reported in another callback.

By the look of it, when modifiers are used the selection is made before the
collback but GtkTreeSelection of the GtkTreeView is updated after.
Unfortunately, I'm not familiar with libgtk2.0 internals to know for sure.

Attached is a small program showing the problem.

Hope it helps,
Igor


-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.11
Locale: LANG=C, LC_CTYPE=ru_RU.KOI8-R (charmap=KOI8-R)

Versions of packages libgtk2.0-0 depends on:
ii  libatk1.0-0          1.8.0-4             The ATK accessibility toolkit
ii  libc6                2.3.2.ds1-20        GNU C Library: Shared libraries an
ii  libfontconfig1       2.3.1-2             generic font configuration library
ii  libfreetype6         2.1.7-2.3           FreeType 2 font engine, shared lib
ii  libglib2.0-0         2.6.3-1             The GLib library of C routines
ii  libgtk2.0-bin        2.6.2-4             The programs for the GTK+ graphica
ii  libgtk2.0-common     2.6.2-4             Common files for the GTK+ graphica
ii  libjpeg62            6b-10               The Independent JPEG Group's JPEG 
ii  libpango1.0-0        1.8.1-1             Layout and rendering of internatio
ii  libpng12-0           1.2.8rel-1          PNG library - runtime
ii  libtiff4             3.7.2-1             Tag Image File Format (TIFF) libra
ii  libx11-6             4.3.0.dfsg.1-12.0.1 X Window System protocol client li
ii  libxcursor1          1.1.3-1             X cursor management library
ii  libxext6             4.3.0.dfsg.1-12.0.1 X Window System miscellaneous exte
ii  libxft2              2.1.2-6             FreeType-based font drawing librar
ii  libxi6               4.3.0.dfsg.1-12.0.1 X Window System Input extension li
ii  libxrandr2           4.3.0.dfsg.1-12.0.1 X Window System Resize, Rotate and
ii  libxrender1          0.8.3-7             X Rendering Extension client libra
ii  xlibs                4.3.0.dfsg.1-12     X Keyboard Extension (XKB) configu
ii  zlib1g               1:1.2.2-4           compression library - runtime

-- no debconf information

--===============0551852410==
Content-Type: text/x-c; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="treeview-bug.c"

/* 
 * Compilation instruction:
 * gcc -o treeview-bug treeview-bug.c `pkg-config --cflags --libs gtk+-2.0`
 * 
 * Bug reproduction:
 * Hold <Ctrl> or <Shift> and click mouse buttons to select columns.
 * Compare the number of selected columns you see with the print out
 * from the "cursor-changed" callback.
 */

#include <stdio.h>
#include <gtk/gtk.h>

static void show_rows(GtkTreeView *treeview, gpointer data) {
  GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
  printf("Selected %d rows\n",
	 gtk_tree_selection_count_selected_rows(selection));
}

int main(int argc, char *argv[]) {
  GtkWidget *window;
  GtkListStore *liststore;
  GtkTreeIter iter;
  GtkCellRenderer *renderer;
  GtkTreeViewColumn *column;
  GtkWidget *treeview;

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "Bug report");
  g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

  liststore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
  gtk_list_store_append(liststore, &iter);
  gtk_list_store_set(liststore, &iter, 0, "One", 1, "Over there", -1);
  gtk_list_store_append(liststore, &iter);
  gtk_list_store_set(liststore, &iter, 0, "Two", 1, "Right here", -1);

  treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore));
  g_signal_connect(treeview, "cursor-changed", G_CALLBACK(show_rows), NULL);
  gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)),
			      GTK_SELECTION_MULTIPLE);

  renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes("What",
						    renderer,
						    "text", 0,
						    NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
  renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes("Where",
						    renderer,
						    "text", 1,
						    NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);

  gtk_container_add(GTK_CONTAINER(window), treeview);
  gtk_widget_show_all(window);
  gtk_main();

  return 0;
}

--===============0551852410==--