Blame docs/tutorial/html/x1335.html

Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>Paned Window Widgets
Packit 98cdb6
>
Packit 98cdb6
NAME="GENERATOR"
Packit 98cdb6
CONTENT="Modular DocBook HTML Stylesheet Version 1.79">
Packit 98cdb6
REL="HOME"
Packit 98cdb6
TITLE="GTK+ 2.0 Tutorial"
Packit 98cdb6
HREF="book1.html">
Packit 98cdb6
REL="UP"
Packit 98cdb6
TITLE="Container Widgets"
Packit 98cdb6
HREF="c1226.html">
Packit 98cdb6
REL="PREVIOUS"
Packit 98cdb6
TITLE="Aspect Frames"
Packit 98cdb6
HREF="x1317.html">
Packit 98cdb6
REL="NEXT"
Packit 98cdb6
TITLE="Viewports"
Packit 98cdb6
HREF="x1352.html">
Packit 98cdb6
>
Packit 98cdb6
CLASS="SECT1"
Packit 98cdb6
BGCOLOR="#FFFFFF"
Packit 98cdb6
TEXT="#000000"
Packit 98cdb6
LINK="#0000FF"
Packit 98cdb6
VLINK="#840084"
Packit 98cdb6
ALINK="#0000FF"
Packit 98cdb6
>
Packit 98cdb6
CLASS="NAVHEADER"
Packit 98cdb6
>
Packit 98cdb6
SUMMARY="Header navigation table"
Packit 98cdb6
WIDTH="100%"
Packit 98cdb6
BORDER="0"
Packit 98cdb6
CELLPADDING="0"
Packit 98cdb6
CELLSPACING="0"
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
COLSPAN="3"
Packit 98cdb6
ALIGN="center"
Packit 98cdb6
>GTK+ 2.0 Tutorial
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="10%"
Packit 98cdb6
ALIGN="left"
Packit 98cdb6
VALIGN="bottom"
Packit 98cdb6
>
Packit 98cdb6
HREF="x1317.html"
Packit 98cdb6
ACCESSKEY="P"
Packit 98cdb6
><<< Previous
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="80%"
Packit 98cdb6
ALIGN="center"
Packit 98cdb6
VALIGN="bottom"
Packit 98cdb6
>Container Widgets
Packit 98cdb6
>
Packit 98cdb6
WIDTH="10%"
Packit 98cdb6
ALIGN="right"
Packit 98cdb6
VALIGN="bottom"
Packit 98cdb6
>
Packit 98cdb6
HREF="x1352.html"
Packit 98cdb6
ACCESSKEY="N"
Packit 98cdb6
>Next >>>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
ALIGN="LEFT"
Packit 98cdb6
WIDTH="100%">
Packit 98cdb6
>
Packit 98cdb6
CLASS="SECT1"
Packit 98cdb6
>
Packit 98cdb6
CLASS="SECT1"
Packit 98cdb6
>
Packit 98cdb6
NAME="SEC-PANEDWINDOWWIDGETS"
Packit 98cdb6
>Paned Window Widgets
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>The paned window widgets are useful when you want to divide an area
Packit 98cdb6
into two parts, with the relative size of the two parts controlled by
Packit 98cdb6
the user. A groove is drawn between the two portions with a handle
Packit 98cdb6
that the user can drag to change the ratio. The division can either be
Packit 98cdb6
horizontal (HPaned) or vertical (VPaned).
Packit 98cdb6
>
Packit 98cdb6
>To create a new paned window, call one of:
Packit 98cdb6
>
Packit 98cdb6
BORDER="0"
Packit 98cdb6
BGCOLOR="#E0E0E0"
Packit 98cdb6
WIDTH="100%"
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
CLASS="PROGRAMLISTING"
Packit 98cdb6
>GtkWidget *gtk_hpaned_new (void);
Packit 98cdb6
Packit 98cdb6
GtkWidget *gtk_vpaned_new (void);
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>After creating the paned window widget, you need to add child widgets
Packit 98cdb6
to its two halves. To do this, use the functions:
Packit 98cdb6
>
Packit 98cdb6
BORDER="0"
Packit 98cdb6
BGCOLOR="#E0E0E0"
Packit 98cdb6
WIDTH="100%"
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
CLASS="PROGRAMLISTING"
Packit 98cdb6
>void gtk_paned_add1 (GtkPaned *paned, GtkWidget *child);
Packit 98cdb6
Packit 98cdb6
void gtk_paned_add2 (GtkPaned *paned, GtkWidget *child);
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
CLASS="LITERAL"
Packit 98cdb6
>gtk_paned_add1()
Packit 98cdb6
> adds the child widget to the left or top half of
Packit 98cdb6
the paned window. 
Packit 98cdb6
CLASS="LITERAL"
Packit 98cdb6
>gtk_paned_add2()
Packit 98cdb6
> adds the child widget to the
Packit 98cdb6
right or bottom half of the paned window.
Packit 98cdb6
>
Packit 98cdb6
>As an example, we will create part of the user interface of an
Packit 98cdb6
imaginary email program. A window is divided into two portions
Packit 98cdb6
vertically, with the top portion being a list of email messages and
Packit 98cdb6
the bottom portion the text of the email message. Most of the program
Packit 98cdb6
is pretty straightforward. A couple of points to note: text can't be
Packit 98cdb6
added to a Text widget until it is realized. This could be done by
Packit 98cdb6
calling gtk_widget_realize(), but as a demonstration of an
Packit 98cdb6
alternate technique, we connect a handler to the "realize" signal to
Packit 98cdb6
add the text. Also, we need to add the 
Packit 98cdb6
CLASS="LITERAL"
Packit 98cdb6
>GTK_SHRINK
Packit 98cdb6
> option to some
Packit 98cdb6
of the items in the table containing the text window and its
Packit 98cdb6
scrollbars, so that when the bottom portion is made smaller, the
Packit 98cdb6
correct portions shrink instead of being pushed off the bottom of the
Packit 98cdb6
window.
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
CLASS="INLINEMEDIAOBJECT"
Packit 98cdb6
>
Packit 98cdb6
SRC="images/paned.png">
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
BORDER="0"
Packit 98cdb6
BGCOLOR="#E0E0E0"
Packit 98cdb6
WIDTH="100%"
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
CLASS="PROGRAMLISTING"
Packit 98cdb6
>
#include <stdio.h>
Packit 98cdb6
#include <gtk/gtk.h>
Packit 98cdb6
   
Packit 98cdb6
/* Create the list of "messages" */
Packit 98cdb6
static GtkWidget *create_list( void )
Packit 98cdb6
{
Packit 98cdb6
Packit 98cdb6
    GtkWidget *scrolled_window;
Packit 98cdb6
    GtkWidget *tree_view;
Packit 98cdb6
    GtkListStore *model;
Packit 98cdb6
    GtkTreeIter iter;
Packit 98cdb6
    GtkCellRenderer *cell;
Packit 98cdb6
    GtkTreeViewColumn *column;
Packit 98cdb6
Packit 98cdb6
    int i;
Packit 98cdb6
   
Packit 98cdb6
    /* Create a new scrolled window, with scrollbars only if needed */
Packit 98cdb6
    scrolled_window = gtk_scrolled_window_new (NULL, NULL);
Packit 98cdb6
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
Packit 98cdb6
				    GTK_POLICY_AUTOMATIC, 
Packit 98cdb6
				    GTK_POLICY_AUTOMATIC);
Packit 98cdb6
   
Packit 98cdb6
    model = gtk_list_store_new (1, G_TYPE_STRING);
Packit 98cdb6
    tree_view = gtk_tree_view_new ();
Packit 98cdb6
    gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
Packit 98cdb6
    gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model));
Packit 98cdb6
    gtk_widget_show (tree_view);
Packit 98cdb6
   
Packit 98cdb6
    /* Add some messages to the window */
Packit 98cdb6
    for (i = 0; i < 10; i++) {
Packit 98cdb6
        gchar *msg = g_strdup_printf ("Message #%d", i);
Packit 98cdb6
        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
Packit 98cdb6
        gtk_list_store_set (GTK_LIST_STORE (model), 
Packit 98cdb6
	                    &iter,
Packit 98cdb6
                            0, msg,
Packit 98cdb6
	                    -1);
Packit 98cdb6
	g_free (msg);
Packit 98cdb6
    }
Packit 98cdb6
   
Packit 98cdb6
    cell = gtk_cell_renderer_text_new ();
Packit 98cdb6
Packit 98cdb6
    column = gtk_tree_view_column_new_with_attributes ("Messages",
Packit 98cdb6
                                                       cell,
Packit 98cdb6
                                                       "text", 0,
Packit 98cdb6
                                                       NULL);
Packit 98cdb6
  
Packit 98cdb6
    gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view),
Packit 98cdb6
	  		         GTK_TREE_VIEW_COLUMN (column));
Packit 98cdb6
Packit 98cdb6
    return scrolled_window;
Packit 98cdb6
}
Packit 98cdb6
   
Packit 98cdb6
/* Add some text to our text widget - this is a callback that is invoked
Packit 98cdb6
when our window is realized. We could also force our window to be
Packit 98cdb6
realized with gtk_widget_realize, but it would have to be part of
Packit 98cdb6
a hierarchy first */
Packit 98cdb6
Packit 98cdb6
static void insert_text( GtkTextBuffer *buffer )
Packit 98cdb6
{
Packit 98cdb6
   GtkTextIter iter;
Packit 98cdb6
 
Packit 98cdb6
   gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
Packit 98cdb6
Packit 98cdb6
   gtk_text_buffer_insert (buffer, &iter,   
Packit 98cdb6
    "From: pathfinder@nasa.gov\n"
Packit 98cdb6
    "To: mom@nasa.gov\n"
Packit 98cdb6
    "Subject: Made it!\n"
Packit 98cdb6
    "\n"
Packit 98cdb6
    "We just got in this morning. The weather has been\n"
Packit 98cdb6
    "great - clear but cold, and there are lots of fun sights.\n"
Packit 98cdb6
    "Sojourner says hi. See you soon.\n"
Packit 98cdb6
    " -Path\n", -1);
Packit 98cdb6
}
Packit 98cdb6
   
Packit 98cdb6
/* Create a scrolled text area that displays a "message" */
Packit 98cdb6
static GtkWidget *create_text( void )
Packit 98cdb6
{
Packit 98cdb6
   GtkWidget *scrolled_window;
Packit 98cdb6
   GtkWidget *view;
Packit 98cdb6
   GtkTextBuffer *buffer;
Packit 98cdb6
Packit 98cdb6
   view = gtk_text_view_new ();
Packit 98cdb6
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
Packit 98cdb6
Packit 98cdb6
   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
Packit 98cdb6
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
Packit 98cdb6
		   	           GTK_POLICY_AUTOMATIC,
Packit 98cdb6
				   GTK_POLICY_AUTOMATIC);
Packit 98cdb6
Packit 98cdb6
   gtk_container_add (GTK_CONTAINER (scrolled_window), view);
Packit 98cdb6
   insert_text (buffer);
Packit 98cdb6
Packit 98cdb6
   gtk_widget_show_all (scrolled_window);
Packit 98cdb6
Packit 98cdb6
   return scrolled_window;
Packit 98cdb6
}
Packit 98cdb6
   
Packit 98cdb6
int main( int   argc,
Packit 98cdb6
          char *argv[] )
Packit 98cdb6
{
Packit 98cdb6
    GtkWidget *window;
Packit 98cdb6
    GtkWidget *vpaned;
Packit 98cdb6
    GtkWidget *list;
Packit 98cdb6
    GtkWidget *text;
Packit 98cdb6
Packit 98cdb6
    gtk_init (&argc, &argv);
Packit 98cdb6
   
Packit 98cdb6
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
Packit 98cdb6
    gtk_window_set_title (GTK_WINDOW (window), "Paned Windows");
Packit 98cdb6
    g_signal_connect (window, "destroy",
Packit 98cdb6
	              G_CALLBACK (gtk_main_quit), NULL);
Packit 98cdb6
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
Packit 98cdb6
    gtk_widget_set_size_request (GTK_WIDGET (window), 450, 400);
Packit 98cdb6
Packit 98cdb6
    /* create a vpaned widget and add it to our toplevel window */
Packit 98cdb6
   
Packit 98cdb6
    vpaned = gtk_vpaned_new ();
Packit 98cdb6
    gtk_container_add (GTK_CONTAINER (window), vpaned);
Packit 98cdb6
    gtk_widget_show (vpaned);
Packit 98cdb6
   
Packit 98cdb6
    /* Now create the contents of the two halves of the window */
Packit 98cdb6
   
Packit 98cdb6
    list = create_list ();
Packit 98cdb6
    gtk_paned_add1 (GTK_PANED (vpaned), list);
Packit 98cdb6
    gtk_widget_show (list);
Packit 98cdb6
   
Packit 98cdb6
    text = create_text ();
Packit 98cdb6
    gtk_paned_add2 (GTK_PANED (vpaned), text);
Packit 98cdb6
    gtk_widget_show (text);
Packit 98cdb6
    gtk_widget_show (window);
Packit 98cdb6
Packit 98cdb6
    gtk_main ();
Packit 98cdb6
Packit 98cdb6
    return 0;
Packit 98cdb6
}
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
CLASS="NAVFOOTER"
Packit 98cdb6
>
Packit 98cdb6
ALIGN="LEFT"
Packit 98cdb6
WIDTH="100%">
Packit 98cdb6
SUMMARY="Footer navigation table"
Packit 98cdb6
WIDTH="100%"
Packit 98cdb6
BORDER="0"
Packit 98cdb6
CELLPADDING="0"
Packit 98cdb6
CELLSPACING="0"
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="33%"
Packit 98cdb6
ALIGN="left"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>
Packit 98cdb6
HREF="x1317.html"
Packit 98cdb6
ACCESSKEY="P"
Packit 98cdb6
><<< Previous
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="34%"
Packit 98cdb6
ALIGN="center"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>
Packit 98cdb6
HREF="book1.html"
Packit 98cdb6
ACCESSKEY="H"
Packit 98cdb6
>Home
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="33%"
Packit 98cdb6
ALIGN="right"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>
Packit 98cdb6
HREF="x1352.html"
Packit 98cdb6
ACCESSKEY="N"
Packit 98cdb6
>Next >>>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="33%"
Packit 98cdb6
ALIGN="left"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>Aspect Frames
Packit 98cdb6
>
Packit 98cdb6
WIDTH="34%"
Packit 98cdb6
ALIGN="center"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>
Packit 98cdb6
HREF="c1226.html"
Packit 98cdb6
ACCESSKEY="U"
Packit 98cdb6
>Up
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
WIDTH="33%"
Packit 98cdb6
ALIGN="right"
Packit 98cdb6
VALIGN="top"
Packit 98cdb6
>Viewports
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>
Packit 98cdb6
>