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

📄 sec-panedwindowwidgets.html

📁 gtk的教材和问答集
💻 HTML
字号:
<HTML><HEAD><TITLE>Paned Window Widgets</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="Container Widgets"HREF="ch-containerwidgets.html"><LINKREL="PREVIOUS"TITLE="Aspect Frames"HREF="sec-aspectframes.html"><LINKREL="NEXT"TITLE="Viewports"HREF="sec-viewports.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%">  <tr>    <td bgcolor="#FFFFFF" valign=top nowrap>    <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A>      <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR>      </td>  <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sec-aspectframes.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 10. Container Widgets</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-viewports.html">Next &#62;&#62;&#62;</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-PANEDWINDOWWIDGETS">10.7. Paned Window Widgets</A></H1><P>The paned window widgets are useful when you want to divide an areainto two parts, with the relative size of the two parts controlled bythe user. A groove is drawn between the two portions with a handlethat the user can drag to change the ratio. The division can either behorizontal (HPaned) or vertical (VPaned).</P><P>To create a new paned window, call one of:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget *gtk_hpaned_new (void);GtkWidget *gtk_vpaned_new (void);</PRE></TD></TR></TABLE><P>After creating the paned window widget, you need to add child widgetsto its two halves. To do this, use the functions:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_paned_add1 (GtkPaned *paned, GtkWidget *child);void gtk_paned_add2 (GtkPaned *paned, GtkWidget *child);</PRE></TD></TR></TABLE><P><TTCLASS="LITERAL">gtk_paned_add1()</TT> adds the child widget to the left or top half ofthe paned window. <TTCLASS="LITERAL">gtk_paned_add2()</TT> adds the child widget to theright or bottom half of the paned window.</P><P>A paned widget can be changed visually using the following twofunctions.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_paned_set_handle_size( GtkPaned *paned,                                guint16   size);void gtk_paned_set_gutter_size( GtkPaned *paned,                                guint16   size);</PRE></TD></TR></TABLE><P>The first of these sets the size of the handle and the second sets thesize of the gutter that is between the two parts of the paned window.</P><P>As an example, we will create part of the user interface of animaginary email program. A window is divided into two portionsvertically, with the top portion being a list of email messages andthe bottom portion the text of the email message. Most of the programis pretty straightforward. A couple of points to note: text can't beadded to a Text widget until it is realized. This could be done bycalling <TTCLASS="LITERAL">gtk_widget_realize()</TT>, but as a demonstration of analternate technique, we connect a handler to the "realize" signal toadd the text. Also, we need to add the <TTCLASS="LITERAL">GTK_SHRINK</TT> option to someof the items in the table containing the text window and itsscrollbars, so that when the bottom portion is made smaller, thecorrect portions shrink instead of being pushed off the bottom of thewindow.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">/* example-start paned paned.c */#include &#60;stdio.h&#62;#include &#60;gtk/gtk.h&#62;   /* Create the list of "messages" */GtkWidget *create_list( void ){    GtkWidget *scrolled_window;    GtkWidget *list;    GtkWidget *list_item;       int i;    char buffer[16];       /* Create a new scrolled window, with scrollbars only if needed */    scrolled_window = gtk_scrolled_window_new (NULL, NULL);    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),				    GTK_POLICY_AUTOMATIC, 				    GTK_POLICY_AUTOMATIC);       /* Create a new list and put it in the scrolled window */    list = gtk_list_new ();    gtk_scrolled_window_add_with_viewport (               GTK_SCROLLED_WINDOW (scrolled_window), list);    gtk_widget_show (list);       /* Add some messages to the window */    for (i=0; i&#60;10; i++) {    	sprintf(buffer,"Message #%d",i);    	list_item = gtk_list_item_new_with_label (buffer);    	gtk_container_add (GTK_CONTAINER(list), list_item);    	gtk_widget_show (list_item);    }       return scrolled_window;}   /* Add some text to our text widget - this is a callback that is invokedwhen our window is realized. We could also force our window to berealized with gtk_widget_realize, but it would have to be part ofa hierarchy first */void realize_text( GtkWidget *text,                   gpointer data ){    gtk_text_freeze (GTK_TEXT (text));    gtk_text_insert (GTK_TEXT (text), NULL, &#38;text-&#62;style-&#62;black, NULL,    "From: pathfinder@nasa.gov\n"    "To: mom@nasa.gov\n"    "Subject: Made it!\n"    "\n"    "We just got in this morning. The weather has been\n"    "great - clear but cold, and there are lots of fun sights.\n"    "Sojourner says hi. See you soon.\n"    " -Path\n", -1);       gtk_text_thaw (GTK_TEXT (text));}   /* Create a scrolled text area that displays a "message" */GtkWidget *create_text( void ){    GtkWidget *table;    GtkWidget *text;    GtkWidget *hscrollbar;    GtkWidget *vscrollbar;       /* Create a table to hold the text widget and scrollbars */    table = gtk_table_new (2, 2, FALSE);       /* Put a text widget in the upper left hand corner. Note the use of     * GTK_SHRINK in the y direction */    text = gtk_text_new (NULL, NULL);    gtk_table_attach (GTK_TABLE (table), text, 0, 1, 0, 1,		      GTK_FILL | GTK_EXPAND,		      GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);    gtk_widget_show (text);       /* Put a HScrollbar in the lower left hand corner */    hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)-&#62;hadj);    gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,		      GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);    gtk_widget_show (hscrollbar);       /* And a VScrollbar in the upper right */    vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)-&#62;vadj);    gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,		      GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0);    gtk_widget_show (vscrollbar);       /* Add a handler to put a message in the text widget when it is realized */    gtk_signal_connect (GTK_OBJECT (text), "realize",			GTK_SIGNAL_FUNC (realize_text), NULL);       return table;}   int main( int   argc,          char *argv[] ){    GtkWidget *window;    GtkWidget *vpaned;    GtkWidget *list;    GtkWidget *text;    gtk_init (&#38;argc, &#38;argv);       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);    gtk_window_set_title (GTK_WINDOW (window), "Paned Windows");    gtk_signal_connect (GTK_OBJECT (window), "destroy",			GTK_SIGNAL_FUNC (gtk_main_quit), NULL);    gtk_container_set_border_width (GTK_CONTAINER (window), 10);    gtk_widget_set_usize (GTK_WIDGET(window), 450, 400);    /* create a vpaned widget and add it to our toplevel window */       vpaned = gtk_vpaned_new ();    gtk_container_add (GTK_CONTAINER(window), vpaned);    gtk_paned_set_handle_size (GTK_PANED(vpaned),                               10);    gtk_paned_set_gutter_size (GTK_PANED(vpaned),                               15);                           gtk_widget_show (vpaned);       /* Now create the contents of the two halves of the window */       list = create_list ();    gtk_paned_add1 (GTK_PANED(vpaned), list);    gtk_widget_show (list);       text = create_text ();    gtk_paned_add2 (GTK_PANED(vpaned), text);    gtk_widget_show (text);    gtk_widget_show (window);    gtk_main ();    return 0;}/* example-end */</PRE></TD></TR></TABLE></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="sec-aspectframes.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="sec-viewports.html">Next &#62;&#62;&#62;</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Aspect Frames</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-containerwidgets.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Viewports</TD></TR></TABLE></DIV>        </td>    </tr></table>  </td>  </tr></table></body></BODY></HTML>

⌨️ 快捷键说明

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