⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec-notebooks.html

📁 gtk 开发手册和参考文档。 包括gtk glib gdk等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
>.</P><P>To find out what the current page is in a notebook use the function:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">gint gtk_notebook_get_current_page( GtkNotebook *notebook );</PRE></TD></TR></TABLE><P>These next two functions are simple calls to move the notebook pageforward or backward. Simply provide the respective function call withthe notebook widget you wish to operate on. Note: When the NoteBook iscurrently on the last page, and gtk_notebook_next_page is called, thenotebook will wrap back to the first page. Likewise, if the NoteBookis on the first page, and gtk_notebook_prev_page is called, thenotebook will wrap to the last page.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_notebook_next_page( GtkNoteBook *notebook );void gtk_notebook_prev_page( GtkNoteBook *notebook );</PRE></TD></TR></TABLE><P>This next function sets the "active" page. If you wish the notebook tobe opened to page 5 for example, you would use this function.  Withoutusing this function, the notebook defaults to the first page.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_notebook_set_page( GtkNotebook *notebook,                            gint         page_num );</PRE></TD></TR></TABLE><P>The next two functions add or remove the notebook page tabs and thenotebook border respectively.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_notebook_set_show_tabs( GtkNotebook *notebook,                                 gboolean     show_tabs);void gtk_notebook_set_show_border( GtkNotebook *notebook,                                   gboolean     show_border );</PRE></TD></TR></TABLE><P>The next function is useful when the you have a large number of pages,and the tabs don't fit on the page. It allows the tabs to be scrolledthrough using two arrow buttons.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_notebook_set_scrollable( GtkNotebook *notebook,                                  gboolean     scrollable );</PRE></TD></TR></TABLE><P><TTCLASS="LITERAL">show_tabs</TT>, <TTCLASS="LITERAL">show_border</TT> and <TTCLASS="LITERAL">scrollable</TT> can be eitherTRUE or FALSE.</P><P>Now let's look at an example, it is expanded from the testgtk.c codethat comes with the GTK distribution. This small program creates awindow with a notebook and six buttons. The notebook contains 11pages, added in three different ways, appended, inserted, andprepended. The buttons allow you rotate the tab positions, add/removethe tabs and border, remove a page, change pages in both a forward andbackward manner, and exit the program.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">/* example-start notebook notebook.c */#include &#60;stdio.h&#62;#include &#60;gtk/gtk.h&#62;/* This function rotates the position of the tabs */void rotate_book( GtkButton   *button,                  GtkNotebook *notebook ){    gtk_notebook_set_tab_pos (notebook, (notebook-&#62;tab_pos +1) %4);}/* Add/Remove the page tabs and the borders */void tabsborder_book( GtkButton   *button,                      GtkNotebook *notebook ){    gint tval = FALSE;    gint bval = FALSE;    if (notebook-&#62;show_tabs == 0)	    tval = TRUE;     if (notebook-&#62;show_border == 0)	    bval = TRUE;        gtk_notebook_set_show_tabs (notebook, tval);    gtk_notebook_set_show_border (notebook, bval);}/* Remove a page from the notebook */void remove_book( GtkButton   *button,                  GtkNotebook *notebook ){    gint page;        page = gtk_notebook_get_current_page(notebook);    gtk_notebook_remove_page (notebook, page);    /* Need to refresh the widget --      This forces the widget to redraw itself. */    gtk_widget_draw(GTK_WIDGET(notebook), NULL);}gint delete( GtkWidget *widget,             GtkWidget *event,             gpointer   data ){    gtk_main_quit();    return(FALSE);}int main( int argc,          char *argv[] ){    GtkWidget *window;    GtkWidget *button;    GtkWidget *table;    GtkWidget *notebook;    GtkWidget *frame;    GtkWidget *label;    GtkWidget *checkbutton;    int i;    char bufferf[32];    char bufferl[32];        gtk_init (&#38;argc, &#38;argv);        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);        gtk_signal_connect (GTK_OBJECT (window), "delete_event",			GTK_SIGNAL_FUNC (delete), NULL);        gtk_container_set_border_width (GTK_CONTAINER (window), 10);    table = gtk_table_new(3,6,FALSE);    gtk_container_add (GTK_CONTAINER (window), table);        /* Create a new notebook, place the position of the tabs */    notebook = gtk_notebook_new ();    gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);    gtk_table_attach_defaults(GTK_TABLE(table), notebook, 0,6,0,1);    gtk_widget_show(notebook);        /* Let's append a bunch of pages to the notebook */    for (i=0; i &#60; 5; i++) {	sprintf(bufferf, "Append Frame %d", i+1);	sprintf(bufferl, "Page %d", i+1);		frame = gtk_frame_new (bufferf);	gtk_container_set_border_width (GTK_CONTAINER (frame), 10);	gtk_widget_set_usize (frame, 100, 75);	gtk_widget_show (frame);		label = gtk_label_new (bufferf);	gtk_container_add (GTK_CONTAINER (frame), label);	gtk_widget_show (label);		label = gtk_label_new (bufferl);	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);    }          /* Now let's add a page to a specific spot */    checkbutton = gtk_check_button_new_with_label ("Check me please!");    gtk_widget_set_usize(checkbutton, 100, 75);    gtk_widget_show (checkbutton);       label = gtk_label_new ("Add page");    gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), checkbutton, label, 2);        /* Now finally let's prepend pages to the notebook */    for (i=0; i &#60; 5; i++) {	sprintf(bufferf, "Prepend Frame %d", i+1);	sprintf(bufferl, "PPage %d", i+1);		frame = gtk_frame_new (bufferf);	gtk_container_set_border_width (GTK_CONTAINER (frame), 10);	gtk_widget_set_usize (frame, 100, 75);	gtk_widget_show (frame);		label = gtk_label_new (bufferf);	gtk_container_add (GTK_CONTAINER (frame), label);	gtk_widget_show (label);		label = gtk_label_new (bufferl);	gtk_notebook_prepend_page (GTK_NOTEBOOK(notebook), frame, label);    }        /* Set what page to start at (page 4) */    gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 3);    /* Create a bunch of buttons */    button = gtk_button_new_with_label ("close");    gtk_signal_connect_object (GTK_OBJECT (button), "clicked",			       GTK_SIGNAL_FUNC (delete), NULL);    gtk_table_attach_defaults(GTK_TABLE(table), button, 0,1,1,2);    gtk_widget_show(button);        button = gtk_button_new_with_label ("next page");    gtk_signal_connect_object (GTK_OBJECT (button), "clicked",			       (GtkSignalFunc) gtk_notebook_next_page,			       GTK_OBJECT (notebook));    gtk_table_attach_defaults(GTK_TABLE(table), button, 1,2,1,2);    gtk_widget_show(button);        button = gtk_button_new_with_label ("prev page");    gtk_signal_connect_object (GTK_OBJECT (button), "clicked",			       (GtkSignalFunc) gtk_notebook_prev_page,			       GTK_OBJECT (notebook));    gtk_table_attach_defaults(GTK_TABLE(table), button, 2,3,1,2);    gtk_widget_show(button);        button = gtk_button_new_with_label ("tab position");    gtk_signal_connect (GTK_OBJECT (button), "clicked",                        (GtkSignalFunc) rotate_book,			GTK_OBJECT(notebook));    gtk_table_attach_defaults(GTK_TABLE(table), button, 3,4,1,2);    gtk_widget_show(button);        button = gtk_button_new_with_label ("tabs/border on/off");    gtk_signal_connect (GTK_OBJECT (button), "clicked",                        (GtkSignalFunc) tabsborder_book,                        GTK_OBJECT (notebook));    gtk_table_attach_defaults(GTK_TABLE(table), button, 4,5,1,2);    gtk_widget_show(button);        button = gtk_button_new_with_label ("remove page");    gtk_signal_connect (GTK_OBJECT (button), "clicked",                        (GtkSignalFunc) remove_book,                        GTK_OBJECT(notebook));    gtk_table_attach_defaults(GTK_TABLE(table), button, 5,6,1,2);    gtk_widget_show(button);        gtk_widget_show(table);    gtk_widget_show(window);        gtk_main ();        return(0);}/* example-end */</PRE></TD></TR></TABLE><P>I hope this helps you on your way with creating notebooks for yourGTK applications.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="sec-toolbar.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="gtk-tut.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="ch-clistwidget.html">Next &#62;&#62;&#62;</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Toolbar</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-containerwidgets.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">CList Widget</TD></TR></TABLE></DIV>        </td>    </tr></table>  </td>  </tr></table></body></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -