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 131920 - gtkNotebook sends incorrect switch_page value
gtkNotebook sends incorrect switch_page value
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkNotebook
2.2.x
Other Linux
: Normal normal
: Small fix
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2004-01-19 14:01 UTC by David Menendez
Modified: 2008-06-08 21:43 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Standalone compilable test case - press button to delete the ntbk page; outputs index of page deleted as well as new page index reported to the switch_page sig handler (75.66 KB, application/octet-stream)
2004-03-12 21:33 UTC, David Menendez
  Details
Fixes switch_page signal and tab behaviour (924 bytes, patch)
2007-01-21 00:42 UTC, Samuel Fogh
committed Details | Review

Description David Menendez 2004-01-19 14:01:40 UTC
Create a notebook with multiple tabs (>2).  Attach a handler for the
switch_page signal.  Remove the leftmost tab using
gtk_notebook_remove_page().  The signal handler will be invoked, however,
the value sent in for page_num will be 1, rather than 0, even though the
leftmost tab (index 0) is still the new active tab.

When any other tab is removed, the correct index of the new active tab is
passed in to the switch_page signal handler.
Comment 1 Owen Taylor 2004-03-12 19:53:10 UTC
Standalone compilable test case would be useful.
Comment 2 David Menendez 2004-03-12 21:33:43 UTC
Created attachment 25581 [details]
Standalone compilable test case - press button to delete the ntbk page; outputs index of page deleted as well as new page index reported to the switch_page sig handler
Comment 3 Elijah Newren 2004-06-19 18:46:15 UTC
Mass changing gtk+ bugs with target milestone of 2.4.2 to target 2.4.4, as
Matthias said he was trying to do himself on IRC and was asking for help with. 
If you see this message, it means I was successful at fixing the borken-ness in
bugzilla :)  Sorry for the spam; just query on this message and delete all
emails you get with this message, since there will probably be a lot.
Comment 4 Samuel Fogh 2007-01-21 00:42:42 UTC
Created attachment 80785 [details] [review]
Fixes switch_page signal and tab behaviour

I've made a patch against SVN /trunk/gtk/gtknotebook.c 17095

I just unliked the current page GList element as soon as it is no longer used and before any signal is send.

I've also taken the liberty to patch the behaviour of tabs when one is removed.

The logical behaviour would be to STEP_NEXT for all tabs except the last tab and the rightmost tab.
Comment 5 Philip Withnall 2007-05-26 16:33:58 UTC
Patch 80785 applies cleanly. Reviewing it would take little time.

(Working on http://mail.gnome.org/archives/gtk-devel-list/2007-March/msg00148.html)
Comment 6 Murray Cumming 2008-04-01 07:04:48 UTC
Could a maintainer please review this patch? A year is an unfair amount of time to wait.
Comment 7 Björn Lindqvist 2008-06-08 21:43:10 UTC
The patch works, so committed in r20339:

2008-06-08  Björn Lindqvist  <bjourne@gmail.com>

	Bug 131920 – gtkNotebook sends incorrect switch_page value

	* gtk/gtknotebook.c (gtk_notebook_real_remove): Make switch-page
	signal send correct page index when page index 0 is active and
	removed. (#131920, Samuel Fogh)

And here is the test case that verifies that the bug vanishes:

    num_in_cb = ['other']
    def switch_page_cb(notebook, page, page_num):
        num_in_cb[0] = page_num

    book = gtk.Notebook()
    for x in range(5):
        page = gtk.Label('page-%d' % x)
        page.show()
        book.append_page(page, gtk.Label('page-%d' % x))
    book.connect('switch-page', switch_page_cb)
    book.remove_page(0)

    assert num_in_cb[0] == 0