几封有趣的邮件

http://mail.gnome.org/archives/gtk-app-devel-list/2003-April/msg00204.html

Page numbers in GtkNotebook


  • From: Manu C S
  • To: gtk-app-devel-list gnome org
  • Subject: Page numbers in GtkNotebook
  • Date: Tue, 15 Apr 2003 12:50:21 -0500 (CDT)

Hi,How does one find out the page numbers of tabs in GtkNotebook?I tried gtk_notebook_get_current_page() in a callback forswitch page signal, but the page number I get from this varies

each time.

I want to be able to do something like this in my code:

-------------------------------------------------------------

#define PAGE_0  0

#define PAGE_1  1

#define PAGE_2  2

...

on_top_switch_page (GtkNotebook* notebook, ....)

{

curr_page = gtk_notebook_get_current_page(notebook);

switch (curr_page) {

case PAGE_0:

break;

case PAGE_1:

break;

....

}

}

-------------------------------------------------------------

I found this question asked in the archives (2000-Jul), but

I couldn't locate any suitable answers.

Can anyone please help? It's rather urgent.

Thanks,

Manu

Re: Page numbers in GtkNotebook


  • From: “Audrey Vernon”
  • To: “Manu C S” ,
  • Subject: Re: Page numbers in GtkNotebook
  • Date: Tue, 15 Apr 2003 23:34:55 -0600

The page number depends on its location in the graph notebook I believe, so if you delete tabs before it the number will change. This works fine for things like removing: gint page; page = gtk\_notebook\_get\_current\_page (myGraphData->notebook); gtk\_notebook\_remove\_page (myGraphData->notebook, page); But what I did when I needed a specific tab was the following: // Get the current notebook tab int currentPageIndex = gtk\_notebook\_get\_current\_page(myData->notebook); GtkFrame *currentPage = GTK\_FRAME(gtk\_notebook\_get\_nth\_page (myData->notebook, currentPageIndex)); Then you can get the notebook label or the widget name or something else to uniquely identify which tab is actually open. I’m not sure if this is ideal, but it worked for me. Audrey —– Original Message —– From: “Manu C S” To: Sent: Tuesday, April 15, 2003 11:50 AM Subject: Page numbers in GtkNotebook

Re: Page numbers in GtkNotebook


  • From: Manu C S
  • To: Audrey Vernon
  • Cc: gtk-app-devel-list gnome org
  • Subject: Re: Page numbers in GtkNotebook
  • Date: Wed, 16 Apr 2003 15:47:20 -0500 (CDT)

Dear Audrey,>Then you can get the notebook label or the widget name or something else to>uniquely identify which tab is actually open.>

>I'm not sure if this is ideal, but it worked for me.

It works for me too!

Also, while working on your solution I found that

if I use

g_signal_connect_after(...switch_page...)

instead of

g_signal_connect(...switch_page...)

then in the callback for switch_page I can do:

on_nb1_main_options_switch_page (GtkNotebook     *notebook,

GtkNotebookPage *page,

guint            page_num,

gpointer         user_data)

{

switch (page_num) {

case 0:

break;

case 1:

break;

...

}

}

where page_num is the correct ascending ordered page

number I want!

For example, if my notebook looks like this:

+---+---+---+---+--------------------------

| A | B | C | D | ....

+---+---+---+---+--------------------------

then page_num will be 0 for A, 1 for B, 2 for C and so on...!

Thank you so much.

Regards,

Manu
updatedupdated2022-02-222022-02-22